warp-lang 1.9.1__py3-none-win_amd64.whl → 1.10.0rc2__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

Files changed (346) hide show
  1. warp/__init__.py +301 -287
  2. warp/__init__.pyi +794 -305
  3. warp/_src/__init__.py +14 -0
  4. warp/_src/autograd.py +1075 -0
  5. warp/_src/build.py +618 -0
  6. warp/_src/build_dll.py +640 -0
  7. warp/{builtins.py → _src/builtins.py} +1382 -377
  8. warp/_src/codegen.py +4359 -0
  9. warp/{config.py → _src/config.py} +178 -169
  10. warp/_src/constants.py +57 -0
  11. warp/_src/context.py +8294 -0
  12. warp/_src/dlpack.py +462 -0
  13. warp/_src/fabric.py +355 -0
  14. warp/_src/fem/__init__.py +14 -0
  15. warp/_src/fem/adaptivity.py +508 -0
  16. warp/_src/fem/cache.py +687 -0
  17. warp/_src/fem/dirichlet.py +188 -0
  18. warp/{fem → _src/fem}/domain.py +40 -30
  19. warp/_src/fem/field/__init__.py +131 -0
  20. warp/_src/fem/field/field.py +701 -0
  21. warp/{fem → _src/fem}/field/nodal_field.py +30 -15
  22. warp/{fem → _src/fem}/field/restriction.py +1 -1
  23. warp/{fem → _src/fem}/field/virtual.py +53 -27
  24. warp/_src/fem/geometry/__init__.py +32 -0
  25. warp/{fem → _src/fem}/geometry/adaptive_nanogrid.py +77 -163
  26. warp/_src/fem/geometry/closest_point.py +97 -0
  27. warp/{fem → _src/fem}/geometry/deformed_geometry.py +14 -22
  28. warp/{fem → _src/fem}/geometry/element.py +32 -10
  29. warp/{fem → _src/fem}/geometry/geometry.py +48 -20
  30. warp/{fem → _src/fem}/geometry/grid_2d.py +12 -23
  31. warp/{fem → _src/fem}/geometry/grid_3d.py +12 -23
  32. warp/{fem → _src/fem}/geometry/hexmesh.py +40 -63
  33. warp/{fem → _src/fem}/geometry/nanogrid.py +255 -248
  34. warp/{fem → _src/fem}/geometry/partition.py +121 -63
  35. warp/{fem → _src/fem}/geometry/quadmesh.py +26 -45
  36. warp/{fem → _src/fem}/geometry/tetmesh.py +40 -63
  37. warp/{fem → _src/fem}/geometry/trimesh.py +26 -45
  38. warp/{fem → _src/fem}/integrate.py +164 -158
  39. warp/_src/fem/linalg.py +383 -0
  40. warp/_src/fem/operator.py +396 -0
  41. warp/_src/fem/polynomial.py +229 -0
  42. warp/{fem → _src/fem}/quadrature/pic_quadrature.py +15 -20
  43. warp/{fem → _src/fem}/quadrature/quadrature.py +95 -47
  44. warp/_src/fem/space/__init__.py +248 -0
  45. warp/{fem → _src/fem}/space/basis_function_space.py +20 -11
  46. warp/_src/fem/space/basis_space.py +679 -0
  47. warp/{fem → _src/fem}/space/dof_mapper.py +3 -3
  48. warp/{fem → _src/fem}/space/function_space.py +14 -13
  49. warp/{fem → _src/fem}/space/grid_2d_function_space.py +4 -7
  50. warp/{fem → _src/fem}/space/grid_3d_function_space.py +4 -4
  51. warp/{fem → _src/fem}/space/hexmesh_function_space.py +4 -10
  52. warp/{fem → _src/fem}/space/nanogrid_function_space.py +3 -9
  53. warp/{fem → _src/fem}/space/partition.py +117 -60
  54. warp/{fem → _src/fem}/space/quadmesh_function_space.py +4 -10
  55. warp/{fem → _src/fem}/space/restriction.py +66 -33
  56. warp/_src/fem/space/shape/__init__.py +152 -0
  57. warp/{fem → _src/fem}/space/shape/cube_shape_function.py +9 -9
  58. warp/{fem → _src/fem}/space/shape/shape_function.py +8 -9
  59. warp/{fem → _src/fem}/space/shape/square_shape_function.py +6 -6
  60. warp/{fem → _src/fem}/space/shape/tet_shape_function.py +3 -3
  61. warp/{fem → _src/fem}/space/shape/triangle_shape_function.py +3 -3
  62. warp/{fem → _src/fem}/space/tetmesh_function_space.py +3 -9
  63. warp/_src/fem/space/topology.py +459 -0
  64. warp/{fem → _src/fem}/space/trimesh_function_space.py +3 -9
  65. warp/_src/fem/types.py +112 -0
  66. warp/_src/fem/utils.py +486 -0
  67. warp/_src/jax.py +186 -0
  68. warp/_src/jax_experimental/__init__.py +14 -0
  69. warp/_src/jax_experimental/custom_call.py +387 -0
  70. warp/_src/jax_experimental/ffi.py +1284 -0
  71. warp/_src/jax_experimental/xla_ffi.py +656 -0
  72. warp/_src/marching_cubes.py +708 -0
  73. warp/_src/math.py +414 -0
  74. warp/_src/optim/__init__.py +14 -0
  75. warp/_src/optim/adam.py +163 -0
  76. warp/_src/optim/linear.py +1606 -0
  77. warp/_src/optim/sgd.py +112 -0
  78. warp/_src/paddle.py +406 -0
  79. warp/_src/render/__init__.py +14 -0
  80. warp/_src/render/imgui_manager.py +289 -0
  81. warp/_src/render/render_opengl.py +3636 -0
  82. warp/_src/render/render_usd.py +937 -0
  83. warp/_src/render/utils.py +160 -0
  84. warp/_src/sparse.py +2716 -0
  85. warp/_src/tape.py +1206 -0
  86. warp/{thirdparty → _src/thirdparty}/unittest_parallel.py +9 -2
  87. warp/_src/torch.py +391 -0
  88. warp/_src/types.py +5870 -0
  89. warp/_src/utils.py +1693 -0
  90. warp/autograd.py +12 -1054
  91. warp/bin/warp-clang.dll +0 -0
  92. warp/bin/warp.dll +0 -0
  93. warp/build.py +8 -588
  94. warp/build_dll.py +6 -721
  95. warp/codegen.py +6 -4251
  96. warp/constants.py +6 -39
  97. warp/context.py +12 -8062
  98. warp/dlpack.py +6 -444
  99. warp/examples/distributed/example_jacobi_mpi.py +4 -5
  100. warp/examples/fem/example_adaptive_grid.py +1 -1
  101. warp/examples/fem/example_apic_fluid.py +1 -1
  102. warp/examples/fem/example_burgers.py +8 -8
  103. warp/examples/fem/example_diffusion.py +1 -1
  104. warp/examples/fem/example_distortion_energy.py +1 -1
  105. warp/examples/fem/example_mixed_elasticity.py +2 -2
  106. warp/examples/fem/example_navier_stokes.py +1 -1
  107. warp/examples/fem/example_nonconforming_contact.py +7 -7
  108. warp/examples/fem/example_stokes.py +1 -1
  109. warp/examples/fem/example_stokes_transfer.py +1 -1
  110. warp/examples/fem/utils.py +2 -2
  111. warp/examples/interop/example_jax_callable.py +1 -1
  112. warp/examples/interop/example_jax_ffi_callback.py +1 -1
  113. warp/examples/interop/example_jax_kernel.py +1 -1
  114. warp/examples/tile/example_tile_mcgp.py +191 -0
  115. warp/fabric.py +6 -337
  116. warp/fem/__init__.py +159 -97
  117. warp/fem/adaptivity.py +7 -489
  118. warp/fem/cache.py +9 -648
  119. warp/fem/dirichlet.py +6 -184
  120. warp/fem/field/__init__.py +8 -109
  121. warp/fem/field/field.py +7 -652
  122. warp/fem/geometry/__init__.py +7 -18
  123. warp/fem/geometry/closest_point.py +11 -77
  124. warp/fem/linalg.py +18 -366
  125. warp/fem/operator.py +11 -369
  126. warp/fem/polynomial.py +9 -209
  127. warp/fem/space/__init__.py +5 -211
  128. warp/fem/space/basis_space.py +6 -662
  129. warp/fem/space/shape/__init__.py +41 -118
  130. warp/fem/space/topology.py +6 -437
  131. warp/fem/types.py +6 -81
  132. warp/fem/utils.py +11 -444
  133. warp/jax.py +8 -165
  134. warp/jax_experimental/__init__.py +14 -1
  135. warp/jax_experimental/custom_call.py +8 -365
  136. warp/jax_experimental/ffi.py +17 -873
  137. warp/jax_experimental/xla_ffi.py +5 -605
  138. warp/marching_cubes.py +5 -689
  139. warp/math.py +16 -393
  140. warp/native/array.h +385 -37
  141. warp/native/builtin.h +314 -37
  142. warp/native/bvh.cpp +43 -9
  143. warp/native/bvh.cu +62 -27
  144. warp/native/bvh.h +310 -309
  145. warp/native/clang/clang.cpp +102 -97
  146. warp/native/coloring.cpp +0 -1
  147. warp/native/crt.h +208 -0
  148. warp/native/exports.h +156 -0
  149. warp/native/hashgrid.cu +2 -0
  150. warp/native/intersect.h +24 -1
  151. warp/native/intersect_tri.h +44 -35
  152. warp/native/mat.h +1456 -276
  153. warp/native/mesh.cpp +4 -4
  154. warp/native/mesh.cu +4 -2
  155. warp/native/mesh.h +176 -61
  156. warp/native/quat.h +0 -52
  157. warp/native/scan.cu +2 -0
  158. warp/native/sparse.cu +7 -3
  159. warp/native/spatial.h +12 -0
  160. warp/native/tile.h +681 -89
  161. warp/native/tile_radix_sort.h +1 -1
  162. warp/native/tile_reduce.h +394 -46
  163. warp/native/tile_scan.h +4 -4
  164. warp/native/vec.h +469 -0
  165. warp/native/version.h +23 -0
  166. warp/native/volume.cpp +1 -1
  167. warp/native/volume.cu +1 -0
  168. warp/native/volume.h +1 -1
  169. warp/native/volume_builder.cu +2 -0
  170. warp/native/warp.cpp +57 -29
  171. warp/native/warp.cu +253 -171
  172. warp/native/warp.h +11 -8
  173. warp/optim/__init__.py +6 -3
  174. warp/optim/adam.py +6 -145
  175. warp/optim/linear.py +14 -1585
  176. warp/optim/sgd.py +6 -94
  177. warp/paddle.py +6 -388
  178. warp/render/__init__.py +8 -4
  179. warp/render/imgui_manager.py +7 -267
  180. warp/render/render_opengl.py +6 -3618
  181. warp/render/render_usd.py +6 -919
  182. warp/render/utils.py +6 -142
  183. warp/sparse.py +37 -2563
  184. warp/tape.py +6 -1188
  185. warp/tests/__main__.py +1 -1
  186. warp/tests/cuda/test_async.py +4 -4
  187. warp/tests/cuda/test_conditional_captures.py +1 -1
  188. warp/tests/cuda/test_multigpu.py +1 -1
  189. warp/tests/cuda/test_streams.py +58 -1
  190. warp/tests/geometry/test_bvh.py +157 -22
  191. warp/tests/geometry/test_marching_cubes.py +0 -1
  192. warp/tests/geometry/test_mesh.py +5 -3
  193. warp/tests/geometry/test_mesh_query_aabb.py +5 -12
  194. warp/tests/geometry/test_mesh_query_point.py +5 -2
  195. warp/tests/geometry/test_mesh_query_ray.py +15 -3
  196. warp/tests/geometry/test_volume_write.py +5 -5
  197. warp/tests/interop/test_dlpack.py +14 -14
  198. warp/tests/interop/test_jax.py +772 -49
  199. warp/tests/interop/test_paddle.py +1 -1
  200. warp/tests/test_adam.py +0 -1
  201. warp/tests/test_arithmetic.py +9 -9
  202. warp/tests/test_array.py +527 -100
  203. warp/tests/test_array_reduce.py +3 -3
  204. warp/tests/test_atomic.py +12 -8
  205. warp/tests/test_atomic_bitwise.py +209 -0
  206. warp/tests/test_atomic_cas.py +4 -4
  207. warp/tests/test_bool.py +2 -2
  208. warp/tests/test_builtins_resolution.py +5 -571
  209. warp/tests/test_codegen.py +33 -14
  210. warp/tests/test_conditional.py +1 -1
  211. warp/tests/test_context.py +6 -6
  212. warp/tests/test_copy.py +242 -161
  213. warp/tests/test_ctypes.py +3 -3
  214. warp/tests/test_devices.py +24 -2
  215. warp/tests/test_examples.py +16 -84
  216. warp/tests/test_fabricarray.py +35 -35
  217. warp/tests/test_fast_math.py +0 -2
  218. warp/tests/test_fem.py +56 -10
  219. warp/tests/test_fixedarray.py +3 -3
  220. warp/tests/test_func.py +8 -5
  221. warp/tests/test_generics.py +1 -1
  222. warp/tests/test_indexedarray.py +24 -24
  223. warp/tests/test_intersect.py +39 -9
  224. warp/tests/test_large.py +1 -1
  225. warp/tests/test_lerp.py +3 -1
  226. warp/tests/test_linear_solvers.py +1 -1
  227. warp/tests/test_map.py +35 -4
  228. warp/tests/test_mat.py +52 -62
  229. warp/tests/test_mat_constructors.py +4 -5
  230. warp/tests/test_mat_lite.py +1 -1
  231. warp/tests/test_mat_scalar_ops.py +121 -121
  232. warp/tests/test_math.py +34 -0
  233. warp/tests/test_module_aot.py +4 -4
  234. warp/tests/test_modules_lite.py +28 -2
  235. warp/tests/test_print.py +11 -11
  236. warp/tests/test_quat.py +93 -58
  237. warp/tests/test_runlength_encode.py +1 -1
  238. warp/tests/test_scalar_ops.py +38 -10
  239. warp/tests/test_smoothstep.py +1 -1
  240. warp/tests/test_sparse.py +126 -15
  241. warp/tests/test_spatial.py +105 -87
  242. warp/tests/test_special_values.py +6 -6
  243. warp/tests/test_static.py +7 -7
  244. warp/tests/test_struct.py +13 -2
  245. warp/tests/test_triangle_closest_point.py +48 -1
  246. warp/tests/test_types.py +27 -15
  247. warp/tests/test_utils.py +52 -52
  248. warp/tests/test_vec.py +29 -29
  249. warp/tests/test_vec_constructors.py +5 -5
  250. warp/tests/test_vec_scalar_ops.py +97 -97
  251. warp/tests/test_version.py +75 -0
  252. warp/tests/tile/test_tile.py +178 -0
  253. warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
  254. warp/tests/tile/test_tile_cholesky.py +7 -4
  255. warp/tests/tile/test_tile_load.py +26 -2
  256. warp/tests/tile/test_tile_mathdx.py +3 -3
  257. warp/tests/tile/test_tile_matmul.py +1 -1
  258. warp/tests/tile/test_tile_mlp.py +2 -4
  259. warp/tests/tile/test_tile_reduce.py +214 -13
  260. warp/tests/unittest_suites.py +6 -14
  261. warp/tests/unittest_utils.py +10 -9
  262. warp/tests/walkthrough_debug.py +3 -1
  263. warp/torch.py +6 -373
  264. warp/types.py +29 -5764
  265. warp/utils.py +10 -1659
  266. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/METADATA +46 -99
  267. warp_lang-1.10.0rc2.dist-info/RECORD +468 -0
  268. warp_lang-1.10.0rc2.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
  269. warp_lang-1.10.0rc2.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
  270. warp_lang-1.10.0rc2.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
  271. warp_lang-1.10.0rc2.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
  272. warp_lang-1.10.0rc2.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
  273. warp_lang-1.10.0rc2.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
  274. warp_lang-1.10.0rc2.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
  275. warp_lang-1.10.0rc2.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
  276. warp_lang-1.10.0rc2.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
  277. warp_lang-1.10.0rc2.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
  278. warp_lang-1.10.0rc2.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
  279. warp_lang-1.10.0rc2.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
  280. warp_lang-1.10.0rc2.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
  281. warp_lang-1.10.0rc2.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
  282. warp_lang-1.10.0rc2.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
  283. warp/examples/assets/cartpole.urdf +0 -110
  284. warp/examples/assets/crazyflie.usd +0 -0
  285. warp/examples/assets/nv_ant.xml +0 -92
  286. warp/examples/assets/nv_humanoid.xml +0 -183
  287. warp/examples/assets/quadruped.urdf +0 -268
  288. warp/examples/optim/example_bounce.py +0 -266
  289. warp/examples/optim/example_cloth_throw.py +0 -228
  290. warp/examples/optim/example_drone.py +0 -870
  291. warp/examples/optim/example_inverse_kinematics.py +0 -182
  292. warp/examples/optim/example_inverse_kinematics_torch.py +0 -191
  293. warp/examples/optim/example_softbody_properties.py +0 -400
  294. warp/examples/optim/example_spring_cage.py +0 -245
  295. warp/examples/optim/example_trajectory.py +0 -227
  296. warp/examples/sim/example_cartpole.py +0 -143
  297. warp/examples/sim/example_cloth.py +0 -225
  298. warp/examples/sim/example_cloth_self_contact.py +0 -316
  299. warp/examples/sim/example_granular.py +0 -130
  300. warp/examples/sim/example_granular_collision_sdf.py +0 -202
  301. warp/examples/sim/example_jacobian_ik.py +0 -244
  302. warp/examples/sim/example_particle_chain.py +0 -124
  303. warp/examples/sim/example_quadruped.py +0 -203
  304. warp/examples/sim/example_rigid_chain.py +0 -203
  305. warp/examples/sim/example_rigid_contact.py +0 -195
  306. warp/examples/sim/example_rigid_force.py +0 -133
  307. warp/examples/sim/example_rigid_gyroscopic.py +0 -115
  308. warp/examples/sim/example_rigid_soft_contact.py +0 -140
  309. warp/examples/sim/example_soft_body.py +0 -196
  310. warp/examples/tile/example_tile_walker.py +0 -327
  311. warp/sim/__init__.py +0 -74
  312. warp/sim/articulation.py +0 -793
  313. warp/sim/collide.py +0 -2570
  314. warp/sim/graph_coloring.py +0 -307
  315. warp/sim/import_mjcf.py +0 -791
  316. warp/sim/import_snu.py +0 -227
  317. warp/sim/import_urdf.py +0 -579
  318. warp/sim/import_usd.py +0 -898
  319. warp/sim/inertia.py +0 -357
  320. warp/sim/integrator.py +0 -245
  321. warp/sim/integrator_euler.py +0 -2000
  322. warp/sim/integrator_featherstone.py +0 -2101
  323. warp/sim/integrator_vbd.py +0 -2487
  324. warp/sim/integrator_xpbd.py +0 -3295
  325. warp/sim/model.py +0 -4821
  326. warp/sim/particles.py +0 -121
  327. warp/sim/render.py +0 -431
  328. warp/sim/utils.py +0 -431
  329. warp/tests/sim/disabled_kinematics.py +0 -244
  330. warp/tests/sim/test_cloth.py +0 -863
  331. warp/tests/sim/test_collision.py +0 -743
  332. warp/tests/sim/test_coloring.py +0 -347
  333. warp/tests/sim/test_inertia.py +0 -161
  334. warp/tests/sim/test_model.py +0 -226
  335. warp/tests/sim/test_sim_grad.py +0 -287
  336. warp/tests/sim/test_sim_grad_bounce_linear.py +0 -212
  337. warp/tests/sim/test_sim_kinematics.py +0 -98
  338. warp/thirdparty/__init__.py +0 -0
  339. warp_lang-1.9.1.dist-info/RECORD +0 -456
  340. /warp/{fem → _src/fem}/quadrature/__init__.py +0 -0
  341. /warp/{tests/sim → _src/thirdparty}/__init__.py +0 -0
  342. /warp/{thirdparty → _src/thirdparty}/appdirs.py +0 -0
  343. /warp/{thirdparty → _src/thirdparty}/dlpack.py +0 -0
  344. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/WHEEL +0 -0
  345. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/licenses/LICENSE.md +0 -0
  346. {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/top_level.txt +0 -0
warp/sim/import_urdf.py DELETED
@@ -1,579 +0,0 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
- # SPDX-License-Identifier: Apache-2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- import os
17
- import xml.etree.ElementTree as ET
18
- from typing import Union
19
-
20
- import numpy as np
21
-
22
- import warp as wp
23
- from warp.sim.model import Mesh
24
-
25
-
26
- def parse_urdf(
27
- urdf_filename,
28
- builder,
29
- xform=None,
30
- floating=False,
31
- base_joint: Union[dict, str, None] = None,
32
- density=1000.0,
33
- stiffness=100.0,
34
- damping=10.0,
35
- armature=0.0,
36
- contact_ke=1.0e4,
37
- contact_kd=1.0e3,
38
- contact_kf=1.0e2,
39
- contact_ka=0.0,
40
- contact_mu=0.25,
41
- contact_restitution=0.5,
42
- contact_thickness=0.0,
43
- limit_ke=100.0,
44
- limit_kd=10.0,
45
- joint_limit_lower=-1e6,
46
- joint_limit_upper=1e6,
47
- scale=1.0,
48
- hide_visuals=False,
49
- parse_visuals_as_colliders=False,
50
- force_show_colliders=False,
51
- enable_self_collisions=True,
52
- ignore_inertial_definitions=True,
53
- ensure_nonstatic_links=True,
54
- static_link_mass=1e-2,
55
- collapse_fixed_joints=False,
56
- ):
57
- """
58
- Parses a URDF file and adds the bodies and joints to the given ModelBuilder.
59
-
60
- Args:
61
- urdf_filename (str): The filename of the URDF file to parse.
62
- builder (ModelBuilder): The :class:`ModelBuilder` to add the bodies and joints to.
63
- xform (:ref:`transform <transform>`): The transform to apply to the root body.
64
- floating (bool): If True, the root body is a free joint. If False, the root body is connected via a fixed joint to the world, unless a `base_joint` is defined.
65
- base_joint (Union[str, dict]): The joint by which the root body is connected to the world. This can be either a string defining the joint axes of a D6 joint with comma-separated positional and angular axis names (e.g. "px,py,rz" for a D6 joint with linear axes in x, y and an angular axis in z) or a dict with joint parameters (see :meth:`ModelBuilder.add_joint`).
66
- density (float): The density of the shapes in kg/m^3 which will be used to calculate the body mass and inertia.
67
- stiffness (float): The stiffness of the joints.
68
- damping (float): The damping of the joints.
69
- armature (float): The armature of the joints (bias to add to the inertia diagonals that may stabilize the simulation).
70
- contact_ke (float): The stiffness of the shape contacts (used by the Euler integrators).
71
- contact_kd (float): The damping of the shape contacts (used by the Euler integrators).
72
- contact_kf (float): The friction stiffness of the shape contacts (used by the Euler integrators).
73
- contact_ka (float): The adhesion distance of the shape contacts (used by the Euler integrators).
74
- contact_mu (float): The friction coefficient of the shape contacts.
75
- contact_restitution (float): The restitution coefficient of the shape contacts.
76
- contact_thickness (float): The thickness to add to the shape geometry.
77
- limit_ke (float): The stiffness of the joint limits (used by the Euler integrators).
78
- limit_kd (float): The damping of the joint limits (used by the Euler integrators).
79
- joint_limit_lower (float): The default lower joint limit if not specified in the URDF.
80
- joint_limit_upper (float): The default upper joint limit if not specified in the URDF.
81
- scale (float): The scaling factor to apply to the imported mechanism.
82
- hide_visuals (bool): If True, hide visual shapes.
83
- parse_visuals_as_colliders (bool): If True, the geometry defined under the `<visual>` tags is used for collision handling instead of the `<collision>` geometries.
84
- force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
85
- enable_self_collisions (bool): If True, self-collisions are enabled.
86
- ignore_inertial_definitions (bool): If True, the inertial parameters defined in the URDF are ignored and the inertia is calculated from the shape geometry.
87
- ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
88
- static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
89
- collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
90
- """
91
- if xform is None:
92
- xform = wp.transform()
93
-
94
- file = ET.parse(urdf_filename)
95
- root = file.getroot()
96
-
97
- contact_vars = {
98
- "ke": contact_ke,
99
- "kd": contact_kd,
100
- "kf": contact_kf,
101
- "ka": contact_ka,
102
- "mu": contact_mu,
103
- "restitution": contact_restitution,
104
- "thickness": contact_thickness,
105
- }
106
-
107
- def parse_transform(element):
108
- if element is None or element.find("origin") is None:
109
- return wp.transform()
110
- origin = element.find("origin")
111
- xyz = origin.get("xyz") or "0 0 0"
112
- rpy = origin.get("rpy") or "0 0 0"
113
- xyz = [float(x) * scale for x in xyz.split()]
114
- rpy = [float(x) for x in rpy.split()]
115
- return wp.transform(xyz, wp.quat_rpy(*rpy))
116
-
117
- def parse_shapes(link, geoms, density, incoming_xform=None, visible=True, just_visual=False):
118
- shapes = []
119
- # add geometry
120
- for geom_group in geoms:
121
- geo = geom_group.find("geometry")
122
- if geo is None:
123
- continue
124
-
125
- tf = parse_transform(geom_group)
126
- if incoming_xform is not None:
127
- tf = incoming_xform * tf
128
-
129
- for box in geo.findall("box"):
130
- size = box.get("size") or "1 1 1"
131
- size = [float(x) for x in size.split()]
132
- s = builder.add_shape_box(
133
- body=link,
134
- pos=wp.vec3(tf.p),
135
- rot=wp.quat(tf.q),
136
- hx=size[0] * 0.5 * scale,
137
- hy=size[1] * 0.5 * scale,
138
- hz=size[2] * 0.5 * scale,
139
- density=density,
140
- is_visible=visible,
141
- has_ground_collision=not just_visual,
142
- has_shape_collision=not just_visual,
143
- **contact_vars,
144
- )
145
- shapes.append(s)
146
-
147
- for sphere in geo.findall("sphere"):
148
- s = builder.add_shape_sphere(
149
- body=link,
150
- pos=wp.vec3(tf.p),
151
- rot=wp.quat(tf.q),
152
- radius=float(sphere.get("radius") or "1") * scale,
153
- density=density,
154
- is_visible=visible,
155
- has_ground_collision=not just_visual,
156
- has_shape_collision=not just_visual,
157
- **contact_vars,
158
- )
159
- shapes.append(s)
160
-
161
- for cylinder in geo.findall("cylinder"):
162
- s = builder.add_shape_capsule(
163
- body=link,
164
- pos=wp.vec3(tf.p),
165
- rot=wp.quat(tf.q),
166
- radius=float(cylinder.get("radius") or "1") * scale,
167
- half_height=float(cylinder.get("length") or "1") * 0.5 * scale,
168
- density=density,
169
- up_axis=2, # cylinders in URDF are aligned with z-axis
170
- is_visible=visible,
171
- has_ground_collision=not just_visual,
172
- has_shape_collision=not just_visual,
173
- **contact_vars,
174
- )
175
- shapes.append(s)
176
-
177
- for capsule in geo.findall("capsule"):
178
- s = builder.add_shape_capsule(
179
- body=link,
180
- pos=wp.vec3(tf.p),
181
- rot=wp.quat(tf.q),
182
- radius=float(capsule.get("radius") or "1") * scale,
183
- half_height=float(capsule.get("height") or "1") * 0.5 * scale,
184
- density=density,
185
- up_axis=2, # capsules in URDF are aligned with z-axis
186
- is_visible=visible,
187
- has_ground_collision=not just_visual,
188
- has_shape_collision=not just_visual,
189
- **contact_vars,
190
- )
191
- shapes.append(s)
192
-
193
- for mesh in geo.findall("mesh"):
194
- filename = mesh.get("filename")
195
- if filename is None:
196
- continue
197
- if filename.startswith("package://"):
198
- fn = filename.replace("package://", "")
199
- package_name = fn.split("/")[0]
200
- urdf_folder = os.path.dirname(urdf_filename)
201
- # resolve file path from package name, i.e. find
202
- # the package folder from the URDF folder
203
- if package_name in urdf_folder:
204
- filename = os.path.join(urdf_folder[: urdf_folder.index(package_name)], fn)
205
- else:
206
- wp.utils.warn(
207
- f'Warning: package "{package_name}" not found in URDF folder while loading mesh at "{filename}"'
208
- )
209
- elif filename.startswith("http://") or filename.startswith("https://"):
210
- # download mesh
211
- import shutil
212
- import tempfile
213
-
214
- import requests
215
-
216
- with tempfile.TemporaryDirectory() as tmpdir:
217
- # get filename extension
218
- extension = os.path.splitext(filename)[1]
219
- tmpfile = os.path.join(tmpdir, "mesh" + extension)
220
- with requests.get(filename, stream=True) as r:
221
- with open(tmpfile, "wb") as f:
222
- shutil.copyfileobj(r.raw, f)
223
- filename = tmpfile
224
- else:
225
- filename = os.path.join(os.path.dirname(urdf_filename), filename)
226
- if not os.path.exists(filename):
227
- wp.utils.warn(f"Warning: mesh file {filename} does not exist")
228
- continue
229
-
230
- import trimesh
231
-
232
- # use force='mesh' to load the mesh as a trimesh object
233
- # with baked in transforms, e.g. from COLLADA files
234
- m = trimesh.load(filename, force="mesh")
235
- scaling = mesh.get("scale") or "1 1 1"
236
- scaling = np.array([float(x) * scale for x in scaling.split()])
237
- if hasattr(m, "geometry"):
238
- # multiple meshes are contained in a scene
239
- for m_geom in m.geometry.values():
240
- m_vertices = np.array(m_geom.vertices, dtype=np.float32) * scaling
241
- m_faces = np.array(m_geom.faces.flatten(), dtype=np.int32)
242
- m_mesh = Mesh(m_vertices, m_faces)
243
- s = builder.add_shape_mesh(
244
- body=link,
245
- pos=wp.vec3(tf.p),
246
- rot=wp.quat(tf.q),
247
- mesh=m_mesh,
248
- density=density,
249
- is_visible=visible,
250
- has_ground_collision=not just_visual,
251
- has_shape_collision=not just_visual,
252
- **contact_vars,
253
- )
254
- shapes.append(s)
255
- else:
256
- # a single mesh
257
- m_vertices = np.array(m.vertices, dtype=np.float32) * scaling
258
- m_faces = np.array(m.faces.flatten(), dtype=np.int32)
259
- m_mesh = Mesh(m_vertices, m_faces)
260
- s = builder.add_shape_mesh(
261
- body=link,
262
- pos=wp.vec3(tf.p),
263
- rot=wp.quat(tf.q),
264
- mesh=m_mesh,
265
- density=density,
266
- is_visible=visible,
267
- has_ground_collision=not just_visual,
268
- has_shape_collision=not just_visual,
269
- **contact_vars,
270
- )
271
- shapes.append(s)
272
-
273
- return shapes
274
-
275
- # maps from link name -> link index
276
- link_index = {}
277
-
278
- visual_shapes = []
279
-
280
- builder.add_articulation()
281
-
282
- start_shape_count = len(builder.shape_geo_type)
283
-
284
- # add links
285
- for _i, urdf_link in enumerate(root.findall("link")):
286
- name = urdf_link.get("name")
287
- link = builder.add_body(origin=wp.transform_identity(), armature=armature, name=name)
288
-
289
- # add ourselves to the index
290
- link_index[name] = link
291
-
292
- visuals = urdf_link.findall("visual")
293
- colliders = urdf_link.findall("collision")
294
-
295
- if parse_visuals_as_colliders:
296
- colliders = visuals
297
- else:
298
- s = parse_shapes(link, visuals, density=0.0, just_visual=True, visible=not hide_visuals)
299
- visual_shapes.extend(s)
300
-
301
- show_colliders = force_show_colliders
302
- if parse_visuals_as_colliders:
303
- show_colliders = True
304
- elif len(visuals) == 0:
305
- # we need to show the collision shapes since there are no visual shapes
306
- show_colliders = True
307
-
308
- parse_shapes(link, colliders, density=density, visible=show_colliders)
309
- m = builder.body_mass[link]
310
- if not ignore_inertial_definitions and urdf_link.find("inertial") is not None:
311
- # overwrite inertial parameters if defined
312
- inertial = urdf_link.find("inertial")
313
- inertial_frame = parse_transform(inertial)
314
- com = inertial_frame.p
315
- I_m = np.zeros((3, 3))
316
- I_m[0, 0] = float(inertial.find("inertia").get("ixx") or "0") * scale**2
317
- I_m[1, 1] = float(inertial.find("inertia").get("iyy") or "0") * scale**2
318
- I_m[2, 2] = float(inertial.find("inertia").get("izz") or "0") * scale**2
319
- I_m[0, 1] = float(inertial.find("inertia").get("ixy") or "0") * scale**2
320
- I_m[0, 2] = float(inertial.find("inertia").get("ixz") or "0") * scale**2
321
- I_m[1, 2] = float(inertial.find("inertia").get("iyz") or "0") * scale**2
322
- I_m[1, 0] = I_m[0, 1]
323
- I_m[2, 0] = I_m[0, 2]
324
- I_m[2, 1] = I_m[1, 2]
325
- rot = wp.quat_to_matrix(inertial_frame.q)
326
- I_m = rot @ wp.mat33(I_m)
327
- m = float(inertial.find("mass").get("value") or "0")
328
- builder.body_mass[link] = m
329
- builder.body_inv_mass[link] = 1.0 / m if m > 0.0 else 0.0
330
- builder.body_com[link] = com
331
- builder.body_inertia[link] = I_m
332
- if any(x for x in I_m):
333
- builder.body_inv_inertia[link] = wp.inverse(I_m)
334
- else:
335
- builder.body_inv_inertia[link] = I_m
336
- if m == 0.0 and ensure_nonstatic_links:
337
- # set the mass to something nonzero to ensure the body is dynamic
338
- m = static_link_mass
339
- # cube with side length 0.5
340
- I_m = wp.mat33(np.eye(3)) * m / 12.0 * (0.5 * scale) ** 2 * 2.0
341
- I_m += wp.mat33(armature * np.eye(3))
342
- builder.body_mass[link] = m
343
- builder.body_inv_mass[link] = 1.0 / m
344
- builder.body_inertia[link] = I_m
345
- builder.body_inv_inertia[link] = wp.inverse(I_m)
346
-
347
- end_shape_count = len(builder.shape_geo_type)
348
-
349
- # find joints per body
350
- body_children = {name: [] for name in link_index.keys()}
351
- # mapping from parent, child link names to joint
352
- parent_child_joint = {}
353
-
354
- joints = []
355
- for joint in root.findall("joint"):
356
- parent = joint.find("parent").get("link")
357
- child = joint.find("child").get("link")
358
- body_children[parent].append(child)
359
- joint_data = {
360
- "name": joint.get("name"),
361
- "parent": parent,
362
- "child": child,
363
- "type": joint.get("type"),
364
- "origin": parse_transform(joint),
365
- "damping": damping,
366
- "friction": 0.0,
367
- "limit_lower": joint_limit_lower,
368
- "limit_upper": joint_limit_upper,
369
- }
370
- if joint.find("axis") is not None:
371
- joint_data["axis"] = joint.find("axis").get("xyz")
372
- joint_data["axis"] = np.array([float(x) for x in joint_data["axis"].split()])
373
- if joint.find("dynamics") is not None:
374
- dynamics = joint.find("dynamics")
375
- joint_data["damping"] = float(dynamics.get("damping") or str(damping))
376
- joint_data["friction"] = float(dynamics.get("friction") or "0")
377
- if joint.find("limit") is not None:
378
- limit = joint.find("limit")
379
- joint_data["limit_lower"] = float(limit.get("lower") or "-1e6")
380
- joint_data["limit_upper"] = float(limit.get("upper") or "1e6")
381
- if joint.find("mimic") is not None:
382
- mimic = joint.find("mimic")
383
- joint_data["mimic_joint"] = mimic.get("joint")
384
- joint_data["mimic_multiplier"] = float(mimic.get("multiplier") or "1")
385
- joint_data["mimic_offset"] = float(mimic.get("offset") or "0")
386
-
387
- parent_child_joint[(parent, child)] = joint_data
388
- joints.append(joint_data)
389
-
390
- # topological sorting of joints because the FK solver will resolve body transforms
391
- # in joint order and needs the parent link transform to be resolved before the child
392
- visited = dict.fromkeys(link_index.keys(), False)
393
- sorted_joints = []
394
-
395
- # depth-first search
396
- def dfs(joint):
397
- link = joint["child"]
398
- if visited[link]:
399
- return
400
- visited[link] = True
401
-
402
- for child in body_children[link]:
403
- if not visited[child]:
404
- dfs(parent_child_joint[(link, child)])
405
-
406
- sorted_joints.insert(0, joint)
407
-
408
- # start DFS from each unvisited joint
409
- for joint in joints:
410
- if not visited[joint["parent"]]:
411
- dfs(joint)
412
-
413
- # add base joint
414
- if len(sorted_joints) > 0:
415
- base_link_name = sorted_joints[0]["parent"]
416
- else:
417
- base_link_name = next(iter(link_index.keys()))
418
- root = link_index[base_link_name]
419
- if base_joint is not None:
420
- # in case of a given base joint, the position is applied first, the rotation only
421
- # after the base joint itself to not rotate its axis
422
- base_parent_xform = wp.transform(xform.p, wp.quat_identity())
423
- base_child_xform = wp.transform((0.0, 0.0, 0.0), wp.quat_inverse(xform.q))
424
- if isinstance(base_joint, str):
425
- axes = base_joint.lower().split(",")
426
- axes = [ax.strip() for ax in axes]
427
- linear_axes = [ax[-1] for ax in axes if ax[0] in {"l", "p"}]
428
- angular_axes = [ax[-1] for ax in axes if ax[0] in {"a", "r"}]
429
- axes = {
430
- "x": [1.0, 0.0, 0.0],
431
- "y": [0.0, 1.0, 0.0],
432
- "z": [0.0, 0.0, 1.0],
433
- }
434
- builder.add_joint_d6(
435
- linear_axes=[wp.sim.JointAxis(axes[a]) for a in linear_axes],
436
- angular_axes=[wp.sim.JointAxis(axes[a]) for a in angular_axes],
437
- parent_xform=base_parent_xform,
438
- child_xform=base_child_xform,
439
- parent=-1,
440
- child=root,
441
- name="base_joint",
442
- )
443
- elif isinstance(base_joint, dict):
444
- base_joint["parent"] = -1
445
- base_joint["child"] = root
446
- base_joint["parent_xform"] = base_parent_xform
447
- base_joint["child_xform"] = base_child_xform
448
- base_joint["name"] = "base_joint"
449
- builder.add_joint(**base_joint)
450
- else:
451
- raise ValueError(
452
- "base_joint must be a comma-separated string of joint axes or a dict with joint parameters"
453
- )
454
- elif floating:
455
- builder.add_joint_free(root, name="floating_base")
456
-
457
- # set dofs to transform
458
- start = builder.joint_q_start[root]
459
-
460
- builder.joint_q[start + 0] = xform.p[0]
461
- builder.joint_q[start + 1] = xform.p[1]
462
- builder.joint_q[start + 2] = xform.p[2]
463
-
464
- builder.joint_q[start + 3] = xform.q[0]
465
- builder.joint_q[start + 4] = xform.q[1]
466
- builder.joint_q[start + 5] = xform.q[2]
467
- builder.joint_q[start + 6] = xform.q[3]
468
- else:
469
- builder.add_joint_fixed(-1, root, parent_xform=xform, name="fixed_base")
470
-
471
- # add joints, in topological order starting from root body
472
- for joint in sorted_joints:
473
- parent = link_index[joint["parent"]]
474
- child = link_index[joint["child"]]
475
- if child == -1:
476
- # we skipped the insertion of the child body
477
- continue
478
-
479
- lower = joint["limit_lower"]
480
- upper = joint["limit_upper"]
481
- joint_damping = joint["damping"]
482
-
483
- parent_xform = joint["origin"]
484
- child_xform = wp.transform_identity()
485
-
486
- joint_mode = wp.sim.JOINT_MODE_FORCE
487
- if stiffness > 0.0:
488
- joint_mode = wp.sim.JOINT_MODE_TARGET_POSITION
489
-
490
- joint_params = {
491
- "parent": parent,
492
- "child": child,
493
- "parent_xform": parent_xform,
494
- "child_xform": child_xform,
495
- "name": joint["name"],
496
- "armature": armature,
497
- }
498
-
499
- if joint["type"] == "revolute" or joint["type"] == "continuous":
500
- builder.add_joint_revolute(
501
- axis=joint["axis"],
502
- target_ke=stiffness,
503
- target_kd=joint_damping,
504
- limit_lower=lower,
505
- limit_upper=upper,
506
- limit_ke=limit_ke,
507
- limit_kd=limit_kd,
508
- mode=joint_mode,
509
- **joint_params,
510
- )
511
- elif joint["type"] == "prismatic":
512
- builder.add_joint_prismatic(
513
- axis=joint["axis"],
514
- target_ke=stiffness,
515
- target_kd=joint_damping,
516
- limit_lower=lower * scale,
517
- limit_upper=upper * scale,
518
- limit_ke=limit_ke,
519
- limit_kd=limit_kd,
520
- mode=joint_mode,
521
- **joint_params,
522
- )
523
- elif joint["type"] == "fixed":
524
- builder.add_joint_fixed(**joint_params)
525
- elif joint["type"] == "floating":
526
- builder.add_joint_free(**joint_params)
527
- elif joint["type"] == "planar":
528
- # find plane vectors perpendicular to axis
529
- axis = np.array(joint["axis"])
530
- axis /= np.linalg.norm(axis)
531
-
532
- # create helper vector that is not parallel to the axis
533
- helper = np.array([1, 0, 0]) if np.allclose(axis, [0, 1, 0]) else np.array([0, 1, 0])
534
-
535
- u = np.cross(helper, axis)
536
- u /= np.linalg.norm(u)
537
-
538
- v = np.cross(axis, u)
539
- v /= np.linalg.norm(v)
540
-
541
- builder.add_joint_d6(
542
- linear_axes=[
543
- wp.sim.JointAxis(
544
- u,
545
- limit_lower=lower * scale,
546
- limit_upper=upper * scale,
547
- limit_ke=limit_ke,
548
- limit_kd=limit_kd,
549
- target_ke=stiffness,
550
- target_kd=joint_damping,
551
- mode=joint_mode,
552
- ),
553
- wp.sim.JointAxis(
554
- v,
555
- limit_lower=lower * scale,
556
- limit_upper=upper * scale,
557
- limit_ke=limit_ke,
558
- limit_kd=limit_kd,
559
- target_ke=stiffness,
560
- target_kd=joint_damping,
561
- mode=joint_mode,
562
- ),
563
- ],
564
- **joint_params,
565
- )
566
- else:
567
- raise Exception("Unsupported joint type: " + joint["type"])
568
-
569
- for i in range(start_shape_count, end_shape_count):
570
- for j in visual_shapes:
571
- builder.shape_collision_filter_pairs.add((i, j))
572
-
573
- if not enable_self_collisions:
574
- for i in range(start_shape_count, end_shape_count):
575
- for j in range(i + 1, end_shape_count):
576
- builder.shape_collision_filter_pairs.add((i, j))
577
-
578
- if collapse_fixed_joints:
579
- builder.collapse_fixed_joints()