warp-lang 1.9.1__py3-none-manylinux_2_34_aarch64.whl → 1.10.0rc2__py3-none-manylinux_2_34_aarch64.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.so +0 -0
  92. warp/bin/warp.so +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/render/render_usd.py CHANGED
@@ -1,4 +1,4 @@
1
- # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,925 +13,12 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- from __future__ import annotations
16
+ # TODO: Remove after cleaning up the public API.
17
17
 
18
- import numpy as np
18
+ from warp._src.render import render_usd as _render_usd
19
19
 
20
- import warp as wp
21
20
 
22
- UP_AXIS_TOKEN = ("X", "Y", "Z")
23
- UP_AXIS_VEC = (
24
- np.array((1.0, 0.0, 0.0), dtype=float),
25
- np.array((0.0, 1.0, 0.0), dtype=float),
26
- np.array((0.0, 0.0, 1.0), dtype=float),
27
- )
21
+ def __getattr__(name):
22
+ from warp._src.utils import get_deprecated_api
28
23
 
29
-
30
- def _usd_add_xform(prim):
31
- from pxr import UsdGeom
32
-
33
- prim = UsdGeom.Xform(prim)
34
- prim.ClearXformOpOrder()
35
-
36
- prim.AddTranslateOp()
37
- prim.AddOrientOp()
38
- prim.AddScaleOp()
39
-
40
-
41
- def _usd_set_xform(
42
- xform,
43
- pos: tuple | None = None,
44
- rot: tuple | None = None,
45
- scale: tuple | None = None,
46
- time: float = 0.0,
47
- ):
48
- from pxr import Gf, UsdGeom
49
-
50
- xform = UsdGeom.Xform(xform)
51
-
52
- xform_ops = xform.GetOrderedXformOps()
53
-
54
- if pos is not None:
55
- xform_ops[0].Set(Gf.Vec3d(float(pos[0]), float(pos[1]), float(pos[2])), time)
56
- if rot is not None:
57
- xform_ops[1].Set(Gf.Quatf(float(rot[3]), float(rot[0]), float(rot[1]), float(rot[2])), time)
58
- if scale is not None:
59
- xform_ops[2].Set(Gf.Vec3d(float(scale[0]), float(scale[1]), float(scale[2])), time)
60
-
61
-
62
- # transforms a cylinder such that it connects the two points pos0, pos1
63
- def _compute_segment_xform(pos0, pos1):
64
- from pxr import Gf
65
-
66
- mid = (pos0 + pos1) * 0.5
67
- height = (pos1 - pos0).GetLength()
68
-
69
- dir = (pos1 - pos0) / height
70
-
71
- rot = Gf.Rotation()
72
- rot.SetRotateInto((0.0, 0.0, 1.0), Gf.Vec3d(dir))
73
-
74
- scale = Gf.Vec3f(1.0, 1.0, height)
75
-
76
- return (mid, Gf.Quath(rot.GetQuat()), scale)
77
-
78
-
79
- class UsdRenderer:
80
- """A USD renderer"""
81
-
82
- def __init__(self, stage, up_axis="Y", fps=60, scaling=1.0):
83
- """Construct a UsdRenderer object.
84
-
85
- Args:
86
- model: A simulation model
87
- stage (str/Usd.Stage): A USD stage (either in memory or on disk)
88
- up_axis (str): The upfacing axis of the stage
89
- fps: The number of frames per second to use in the USD file
90
- scaling: Scaling factor to use for the entities in the scene
91
- """
92
- try:
93
- from pxr import Gf, Sdf, Usd, UsdGeom, UsdLux
94
- except ImportError as e:
95
- raise ImportError("Failed to import pxr. Please install USD (e.g. via `pip install usd-core`).") from e
96
-
97
- if isinstance(stage, str):
98
- self.stage = stage = Usd.Stage.CreateNew(stage)
99
- elif isinstance(stage, Usd.Stage):
100
- self.stage = stage
101
- else:
102
- print("Failed to create stage in renderer. Please construct with stage path or stage object.")
103
- self.up_axis = up_axis.upper()
104
- self.fps = float(fps)
105
- self.time = 0.0
106
-
107
- self.draw_points = True
108
- self.draw_springs = False
109
- self.draw_triangles = False
110
-
111
- self.root = UsdGeom.Xform.Define(stage, "/root")
112
-
113
- # mapping from shape ID to UsdGeom class
114
- self._shape_constructors = {}
115
- # optional scaling applied to shape instances (e.g. cubes)
116
- self._shape_custom_scale = {}
117
-
118
- # apply scaling
119
- self.root.ClearXformOpOrder()
120
- s = self.root.AddScaleOp()
121
- s.Set(Gf.Vec3d(float(scaling), float(scaling), float(scaling)), 0.0)
122
-
123
- self.stage.SetDefaultPrim(self.root.GetPrim())
124
- self.stage.SetStartTimeCode(0.0)
125
- self.stage.SetEndTimeCode(0.0)
126
- self.stage.SetFramesPerSecond(self.fps)
127
-
128
- if up_axis == "X":
129
- UsdGeom.SetStageUpAxis(self.stage, UsdGeom.Tokens.x)
130
- elif up_axis == "Y":
131
- UsdGeom.SetStageUpAxis(self.stage, UsdGeom.Tokens.y)
132
- elif up_axis == "Z":
133
- UsdGeom.SetStageUpAxis(self.stage, UsdGeom.Tokens.z)
134
-
135
- dome_light = UsdLux.DomeLight.Define(stage, "/dome_light")
136
- dome_light.AddRotateXYZOp().Set((-90.0, -30.0, 0.0))
137
- dome_light.GetEnableColorTemperatureAttr().Set(True)
138
- dome_light.GetColorTemperatureAttr().Set(6150.0)
139
- dome_light.GetIntensityAttr().Set(1.0)
140
- dome_light.GetExposureAttr().Set(9.0)
141
- dome_light.GetPrim().CreateAttribute("visibleInPrimaryRay", Sdf.ValueTypeNames.Bool).Set(False)
142
-
143
- distant_light = UsdLux.DistantLight.Define(stage, "/distant_light")
144
- distant_light.AddRotateXYZOp().Set((-35.0, 45.0, 0.0))
145
- distant_light.GetEnableColorTemperatureAttr().Set(True)
146
- distant_light.GetColorTemperatureAttr().Set(7250.0)
147
- distant_light.GetIntensityAttr().Set(1.0)
148
- distant_light.GetExposureAttr().Set(10.0)
149
-
150
- def begin_frame(self, time):
151
- self.time = round(time * self.fps)
152
- self.stage.SetEndTimeCode(self.time)
153
-
154
- def end_frame(self):
155
- pass
156
-
157
- def register_body(self, body_name):
158
- from pxr import UsdGeom
159
-
160
- xform = UsdGeom.Xform.Define(self.stage, self.root.GetPath().AppendChild(body_name))
161
-
162
- _usd_add_xform(xform)
163
-
164
- def _resolve_path(self, name, parent_body=None, is_template=False):
165
- # resolve the path to the prim with the given name and optional parent body
166
- if is_template:
167
- return self.root.GetPath().AppendChild("_template_shapes").AppendChild(name)
168
- if parent_body is None:
169
- return self.root.GetPath().AppendChild(name)
170
- else:
171
- return self.root.GetPath().AppendChild(parent_body).AppendChild(name)
172
-
173
- def add_shape_instance(
174
- self,
175
- name: str,
176
- shape: int,
177
- body,
178
- pos: tuple,
179
- rot: tuple,
180
- scale: tuple = (1.0, 1.0, 1.0),
181
- color1=None,
182
- color2=None,
183
- custom_index: int = -1,
184
- visible: bool = True,
185
- ):
186
- if not visible:
187
- return
188
- sdf_path = self._resolve_path(name, body)
189
- instance = self._shape_constructors[shape.name].Define(self.stage, sdf_path)
190
- instance.GetPrim().GetReferences().AddInternalReference(shape)
191
-
192
- _usd_add_xform(instance)
193
- if shape.name in self._shape_custom_scale:
194
- cs = self._shape_custom_scale[shape.name]
195
- scale = (scale[0] * cs[0], scale[1] * cs[1], scale[2] * cs[2])
196
- _usd_set_xform(instance, pos, rot, scale, self.time)
197
-
198
- def render_plane(
199
- self,
200
- name: str,
201
- pos: tuple,
202
- rot: tuple,
203
- width: float,
204
- length: float,
205
- color: tuple[float, float, float] = (1.0, 1.0, 1.0),
206
- color2=None,
207
- parent_body: str | None = None,
208
- is_template: bool = False,
209
- u_scaling: float = 1.0,
210
- v_scaling: float = 1.0,
211
- visible: bool = True,
212
- ):
213
- """Render a plane with the given dimensions.
214
-
215
- Args:
216
- name: Name of the plane
217
- pos: Position of the plane
218
- rot: Rotation of the plane
219
- width: Width of the plane
220
- length: Length of the plane
221
- color: Color of the plane
222
- parent_body: Name of the parent body
223
- is_template: Whether the plane is a template
224
- """
225
- from pxr import Sdf, UsdGeom
226
-
227
- if is_template:
228
- prim_path = self._resolve_path(name, parent_body, is_template)
229
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
230
- blueprint_prim = blueprint.GetPrim()
231
- blueprint_prim.SetInstanceable(True)
232
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
233
- plane_path = prim_path.AppendChild("plane")
234
- else:
235
- plane_path = self._resolve_path(name, parent_body)
236
- prim_path = plane_path
237
-
238
- plane = UsdGeom.Mesh.Get(self.stage, plane_path)
239
- if not plane:
240
- plane = UsdGeom.Mesh.Define(self.stage, plane_path)
241
- plane.CreateDoubleSidedAttr().Set(True)
242
-
243
- width = width if width > 0.0 else 100.0
244
- length = length if length > 0.0 else 100.0
245
- points = ((-width, 0.0, -length), (width, 0.0, -length), (width, 0.0, length), (-width, 0.0, length))
246
- normals = ((0.0, 1.0, 0.0), (0.0, 1.0, 0.0), (0.0, 1.0, 0.0), (0.0, 1.0, 0.0))
247
- counts = (4,)
248
- indices = [0, 1, 2, 3]
249
-
250
- plane.GetPointsAttr().Set(points)
251
- plane.GetNormalsAttr().Set(normals)
252
- plane.GetFaceVertexCountsAttr().Set(counts)
253
- plane.GetFaceVertexIndicesAttr().Set(indices)
254
- _usd_add_xform(plane)
255
-
256
- self._shape_constructors[name] = UsdGeom.Mesh
257
-
258
- if not is_template:
259
- _usd_set_xform(plane, pos, rot, (1.0, 1.0, 1.0), 0.0)
260
-
261
- plane.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
262
- return prim_path
263
-
264
- def render_ground(self, size: float = 100.0, plane=None):
265
- from pxr import UsdGeom
266
-
267
- mesh = UsdGeom.Mesh.Define(self.stage, self.root.GetPath().AppendChild("ground"))
268
- mesh.CreateDoubleSidedAttr().Set(True)
269
-
270
- if self.up_axis == "X":
271
- points = ((0.0, size, -size), (0.0, -size, -size), (0.0, size, size), (0.0, -size, size))
272
- normals = ((1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 0.0, 0.0))
273
- elif self.up_axis == "Y":
274
- points = ((-size, 0.0, -size), (size, 0.0, -size), (-size, 0.0, size), (size, 0.0, size))
275
- normals = ((0.0, 1.0, 0.0), (0.0, 1.0, 0.0), (0.0, 1.0, 0.0), (0.0, 1.0, 0.0))
276
- elif self.up_axis == "Z":
277
- points = ((-size, size, 0.0), (size, size, 0.0), (-size, -size, 0.0), (size, -size, 0.0))
278
- normals = ((0.0, 0.0, 1.0), (0.0, 0.0, 1.0), (0.0, 0.0, 1.0), (0.0, 0.0, 1.0))
279
- if plane is not None:
280
- normal = np.array(plane[:3])
281
- normal /= np.linalg.norm(normal)
282
- pos = plane[3] * normal
283
- axis_up = [0.0, 0.0, 0.0]
284
- axis_up["XYZ".index(self.up_axis)] = 1.0
285
- if np.allclose(normal, axis_up):
286
- # no rotation necessary
287
- q = (0.0, 0.0, 0.0, 1.0)
288
- else:
289
- c = np.cross(normal, axis_up)
290
- angle = np.arcsin(np.linalg.norm(c))
291
- axis = np.abs(c) / np.linalg.norm(c)
292
- q = wp.quat_from_axis_angle(axis, angle)
293
- tf = wp.transform(pos, q)
294
- points = [wp.transform_point(tf, wp.vec3(p)) for p in points]
295
- normals = [wp.transform_vector(tf, wp.vec3(n)) for n in normals]
296
- counts = (4,)
297
- indices = [0, 2, 3, 1]
298
-
299
- mesh.GetPointsAttr().Set(points)
300
- mesh.GetNormalsAttr().Set(normals)
301
- mesh.GetFaceVertexCountsAttr().Set(counts)
302
- mesh.GetFaceVertexIndicesAttr().Set(indices)
303
-
304
- def render_sphere(
305
- self,
306
- name: str,
307
- pos: tuple,
308
- rot: tuple,
309
- radius: float,
310
- parent_body: str | None = None,
311
- is_template: bool = False,
312
- color: tuple[float, float, float] | None = None,
313
- visible: bool = True,
314
- ):
315
- """Debug helper to add a sphere for visualization
316
-
317
- Args:
318
- pos: The position of the sphere
319
- radius: The radius of the sphere
320
- name: A name for the USD prim on the stage
321
- color: The color of the sphere
322
- """
323
-
324
- from pxr import Gf, Sdf, UsdGeom
325
-
326
- if is_template:
327
- prim_path = self._resolve_path(name, parent_body, is_template)
328
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
329
- blueprint_prim = blueprint.GetPrim()
330
- blueprint_prim.SetInstanceable(True)
331
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
332
- sphere_path = prim_path.AppendChild("sphere")
333
- else:
334
- sphere_path = self._resolve_path(name, parent_body)
335
- prim_path = sphere_path
336
-
337
- sphere = UsdGeom.Sphere.Get(self.stage, sphere_path)
338
- if not sphere:
339
- sphere = UsdGeom.Sphere.Define(self.stage, sphere_path)
340
- _usd_add_xform(sphere)
341
-
342
- sphere.GetRadiusAttr().Set(radius, self.time)
343
-
344
- if color is not None:
345
- sphere.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
346
-
347
- self._shape_constructors[name] = UsdGeom.Sphere
348
-
349
- if not is_template:
350
- _usd_set_xform(sphere, pos, rot, (1.0, 1.0, 1.0), self.time)
351
-
352
- sphere.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
353
- return prim_path
354
-
355
- def render_capsule(
356
- self,
357
- name: str,
358
- pos: tuple,
359
- rot: tuple,
360
- radius: float,
361
- half_height: float,
362
- parent_body: str | None = None,
363
- is_template: bool = False,
364
- up_axis: int = 1,
365
- color: tuple[float, float, float] | None = None,
366
- visible: bool = True,
367
- ):
368
- """Debug helper to add a capsule for visualization
369
-
370
- Args:
371
- pos: The position of the capsule
372
- radius: The radius of the capsule
373
- half_height: The half height of the capsule
374
- name: A name for the USD prim on the stage
375
- color: The color of the capsule
376
- """
377
-
378
- from pxr import Gf, Sdf, UsdGeom
379
-
380
- if is_template:
381
- prim_path = self._resolve_path(name, parent_body, is_template)
382
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
383
- blueprint_prim = blueprint.GetPrim()
384
- blueprint_prim.SetInstanceable(True)
385
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
386
- capsule_path = prim_path.AppendChild("capsule")
387
- else:
388
- capsule_path = self._resolve_path(name, parent_body)
389
- prim_path = capsule_path
390
-
391
- capsule = UsdGeom.Capsule.Get(self.stage, capsule_path)
392
- if not capsule:
393
- capsule = UsdGeom.Capsule.Define(self.stage, capsule_path)
394
- _usd_add_xform(capsule)
395
-
396
- capsule.GetRadiusAttr().Set(float(radius))
397
- capsule.GetHeightAttr().Set(float(half_height * 2.0))
398
- capsule.GetAxisAttr().Set(UP_AXIS_TOKEN[up_axis])
399
-
400
- if color is not None:
401
- capsule.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
402
-
403
- self._shape_constructors[name] = UsdGeom.Capsule
404
-
405
- if not is_template:
406
- _usd_set_xform(capsule, pos, rot, (1.0, 1.0, 1.0), self.time)
407
-
408
- capsule.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
409
- return prim_path
410
-
411
- def render_cylinder(
412
- self,
413
- name: str,
414
- pos: tuple,
415
- rot: tuple,
416
- radius: float,
417
- half_height: float,
418
- parent_body: str | None = None,
419
- is_template: bool = False,
420
- up_axis: int = 1,
421
- color: tuple[float, float, float] | None = None,
422
- visible: bool = True,
423
- ):
424
- """Debug helper to add a cylinder for visualization
425
-
426
- Args:
427
- pos: The position of the cylinder
428
- radius: The radius of the cylinder
429
- half_height: The half height of the cylinder
430
- name: A name for the USD prim on the stage
431
- color: The color of the cylinder
432
- """
433
-
434
- from pxr import Gf, Sdf, UsdGeom
435
-
436
- if is_template:
437
- prim_path = self._resolve_path(name, parent_body, is_template)
438
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
439
- blueprint_prim = blueprint.GetPrim()
440
- blueprint_prim.SetInstanceable(True)
441
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
442
- cylinder_path = prim_path.AppendChild("cylinder")
443
- else:
444
- cylinder_path = self._resolve_path(name, parent_body)
445
- prim_path = cylinder_path
446
-
447
- cylinder = UsdGeom.Cylinder.Get(self.stage, cylinder_path)
448
- if not cylinder:
449
- cylinder = UsdGeom.Cylinder.Define(self.stage, cylinder_path)
450
- _usd_add_xform(cylinder)
451
-
452
- cylinder.GetRadiusAttr().Set(float(radius))
453
- cylinder.GetHeightAttr().Set(float(half_height * 2.0))
454
- cylinder.GetAxisAttr().Set(UP_AXIS_TOKEN[up_axis])
455
-
456
- if color is not None:
457
- cylinder.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
458
-
459
- self._shape_constructors[name] = UsdGeom.Cylinder
460
-
461
- if not is_template:
462
- _usd_set_xform(cylinder, pos, rot, (1.0, 1.0, 1.0), self.time)
463
-
464
- cylinder.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
465
- return prim_path
466
-
467
- def render_cone(
468
- self,
469
- name: str,
470
- pos: tuple,
471
- rot: tuple,
472
- radius: float,
473
- half_height: float,
474
- parent_body: str | None = None,
475
- is_template: bool = False,
476
- up_axis: int = 1,
477
- color: tuple[float, float, float] | None = None,
478
- visible: bool = True,
479
- ):
480
- """Debug helper to add a cone for visualization
481
-
482
- Args:
483
- pos: The position of the cone
484
- radius: The radius of the cone
485
- half_height: The half height of the cone
486
- name: A name for the USD prim on the stage
487
- color: The color of the cone
488
- """
489
-
490
- from pxr import Gf, Sdf, UsdGeom
491
-
492
- if is_template:
493
- prim_path = self._resolve_path(name, parent_body, is_template)
494
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
495
- blueprint_prim = blueprint.GetPrim()
496
- blueprint_prim.SetInstanceable(True)
497
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
498
- cone_path = prim_path.AppendChild("cone")
499
- else:
500
- cone_path = self._resolve_path(name, parent_body)
501
- prim_path = cone_path
502
-
503
- cone = UsdGeom.Cone.Get(self.stage, cone_path)
504
- if not cone:
505
- cone = UsdGeom.Cone.Define(self.stage, cone_path)
506
- _usd_add_xform(cone)
507
-
508
- cone.GetRadiusAttr().Set(float(radius))
509
- cone.GetHeightAttr().Set(float(half_height * 2.0))
510
- cone.GetAxisAttr().Set(UP_AXIS_TOKEN[up_axis])
511
-
512
- if color is not None:
513
- cone.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
514
-
515
- self._shape_constructors[name] = UsdGeom.Cone
516
-
517
- if not is_template:
518
- _usd_set_xform(cone, pos, rot, (1.0, 1.0, 1.0), self.time)
519
-
520
- cone.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
521
- return prim_path
522
-
523
- def render_box(
524
- self,
525
- name: str,
526
- pos: tuple,
527
- rot: tuple,
528
- extents: tuple,
529
- parent_body: str | None = None,
530
- is_template: bool = False,
531
- color: tuple[float, float, float] | None = None,
532
- visible: bool = True,
533
- ):
534
- """Debug helper to add a box for visualization
535
-
536
- Args:
537
- pos: The position of the box
538
- extents: The radius of the box
539
- name: A name for the USD prim on the stage
540
- color: The color of the box
541
- """
542
-
543
- from pxr import Gf, Sdf, UsdGeom
544
-
545
- if is_template:
546
- prim_path = self._resolve_path(name, parent_body, is_template)
547
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
548
- blueprint_prim = blueprint.GetPrim()
549
- blueprint_prim.SetInstanceable(True)
550
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
551
- cube_path = prim_path.AppendChild("cube")
552
- else:
553
- cube_path = self._resolve_path(name, parent_body)
554
- prim_path = cube_path
555
-
556
- cube = UsdGeom.Cube.Get(self.stage, cube_path)
557
- if not cube:
558
- cube = UsdGeom.Cube.Define(self.stage, cube_path)
559
- _usd_add_xform(cube)
560
-
561
- if color is not None:
562
- cube.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
563
-
564
- self._shape_constructors[name] = UsdGeom.Cube
565
- self._shape_custom_scale[name] = extents
566
-
567
- if not is_template:
568
- _usd_set_xform(cube, pos, rot, extents, self.time)
569
-
570
- cube.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
571
- return prim_path
572
-
573
- def render_ref(self, name: str, path: str, pos: tuple, rot: tuple, scale: tuple, color: tuple | None = None):
574
- from pxr import Gf, Usd, UsdGeom
575
-
576
- ref_path = "/root/" + name
577
-
578
- ref = UsdGeom.Xform.Get(self.stage, ref_path)
579
- if not ref:
580
- ref = UsdGeom.Xform.Define(self.stage, ref_path)
581
- ref.GetPrim().GetReferences().AddReference(path)
582
- _usd_add_xform(ref)
583
-
584
- # update transform
585
- _usd_set_xform(ref, pos, rot, scale, self.time)
586
-
587
- if color is not None:
588
- it = iter(Usd.PrimRange(ref.GetPrim()))
589
- for prim in it:
590
- if prim.IsA(UsdGeom.Gprim):
591
- UsdGeom.Gprim(prim).GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
592
- it.PruneChildren()
593
-
594
- def render_mesh(
595
- self,
596
- name: str,
597
- points,
598
- indices,
599
- colors=None,
600
- pos=(0.0, 0.0, 0.0),
601
- rot=(0.0, 0.0, 0.0, 1.0),
602
- scale=(1.0, 1.0, 1.0),
603
- update_topology=False,
604
- parent_body: str | None = None,
605
- is_template: bool = False,
606
- smooth_shading: bool = True,
607
- visible: bool = True,
608
- ):
609
- from pxr import Sdf, UsdGeom
610
-
611
- if is_template:
612
- prim_path = self._resolve_path(name, parent_body, is_template)
613
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
614
- blueprint_prim = blueprint.GetPrim()
615
- blueprint_prim.SetInstanceable(True)
616
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
617
- mesh_path = prim_path.AppendChild("mesh")
618
- else:
619
- mesh_path = self._resolve_path(name, parent_body)
620
- prim_path = mesh_path
621
-
622
- mesh = UsdGeom.Mesh.Get(self.stage, mesh_path)
623
- if not mesh:
624
- mesh = UsdGeom.Mesh.Define(self.stage, mesh_path)
625
- if colors is not None and len(colors) == 3:
626
- color_interp = "constant"
627
- else:
628
- color_interp = "vertex"
629
-
630
- UsdGeom.Primvar(mesh.GetDisplayColorAttr()).SetInterpolation(color_interp)
631
- _usd_add_xform(mesh)
632
-
633
- # force topology update on first frame
634
- update_topology = True
635
-
636
- mesh.GetPointsAttr().Set(points, self.time)
637
-
638
- if update_topology:
639
- idxs = np.array(indices).reshape(-1, 3)
640
- mesh.GetFaceVertexIndicesAttr().Set(idxs, self.time)
641
- mesh.GetFaceVertexCountsAttr().Set([3] * len(idxs), self.time)
642
-
643
- if colors is not None:
644
- if len(colors) == 3:
645
- colors = (colors,)
646
-
647
- mesh.GetDisplayColorAttr().Set(colors, self.time)
648
-
649
- self._shape_constructors[name] = UsdGeom.Mesh
650
- self._shape_custom_scale[name] = scale
651
-
652
- if not is_template:
653
- _usd_set_xform(mesh, pos, rot, scale, self.time)
654
-
655
- mesh.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
656
- return prim_path
657
-
658
- def render_arrow(
659
- self,
660
- name: str,
661
- pos: tuple,
662
- rot: tuple,
663
- base_radius: float,
664
- base_height: float,
665
- cap_radius: float | None = None,
666
- cap_height: float | None = None,
667
- parent_body: str | None = None,
668
- is_template: bool = False,
669
- up_axis: int = 1,
670
- color: tuple[float, float, float] | None = None,
671
- visible: bool = True,
672
- ):
673
- from pxr import Gf, Sdf, UsdGeom
674
-
675
- if is_template:
676
- prim_path = self._resolve_path(name, parent_body, is_template)
677
- blueprint = UsdGeom.Scope.Define(self.stage, prim_path)
678
- blueprint_prim = blueprint.GetPrim()
679
- blueprint_prim.SetInstanceable(True)
680
- blueprint_prim.SetSpecifier(Sdf.SpecifierClass)
681
- arrow_path = prim_path.AppendChild("arrow")
682
- else:
683
- arrow_path = self._resolve_path(name, parent_body)
684
- prim_path = arrow_path
685
-
686
- arrow = UsdGeom.Xform.Get(self.stage, arrow_path)
687
- if not arrow:
688
- arrow = UsdGeom.Xform.Define(self.stage, arrow_path)
689
- _usd_add_xform(arrow)
690
-
691
- base_path = arrow_path.AppendChild("base")
692
- base = UsdGeom.Xform.Get(self.stage, base_path)
693
- if not base:
694
- base = UsdGeom.Cylinder.Define(self.stage, base_path)
695
- _usd_add_xform(base)
696
-
697
- base.GetRadiusAttr().Set(float(base_radius))
698
- base.GetHeightAttr().Set(float(base_height))
699
- base.GetAxisAttr().Set(UP_AXIS_TOKEN[up_axis])
700
- _usd_set_xform(base, UP_AXIS_VEC[up_axis] * base_height * 0.5)
701
-
702
- cap_path = arrow_path.AppendChild("cap")
703
- cap = UsdGeom.Xform.Get(self.stage, cap_path)
704
- if not cap:
705
- cap = UsdGeom.Cone.Define(self.stage, arrow_path.AppendChild("cap"))
706
- _usd_add_xform(cap)
707
-
708
- cap.GetRadiusAttr().Set(float(cap_radius))
709
- cap.GetHeightAttr().Set(float(cap_height))
710
- cap.GetAxisAttr().Set(UP_AXIS_TOKEN[up_axis])
711
- _usd_set_xform(cap, UP_AXIS_VEC[up_axis] * (base_height + cap_height * 0.5))
712
-
713
- if color is not None:
714
- base.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
715
- cap.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
716
-
717
- self._shape_constructors[name] = UsdGeom.Xform
718
-
719
- if not is_template:
720
- _usd_set_xform(arrow, pos, rot, (1.0, 1.0, 1.0), self.time)
721
-
722
- arrow.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
723
- return prim_path
724
-
725
- def render_line_list(
726
- self,
727
- name: str,
728
- vertices,
729
- indices,
730
- color: tuple[float, float, float] | None = None,
731
- radius: float = 0.01,
732
- visible: bool = True,
733
- ):
734
- """Debug helper to add a line list as a set of capsules
735
-
736
- Args:
737
- vertices: The vertices of the line-strip
738
- color: The color of the line
739
- time: The time to update at
740
- """
741
-
742
- from pxr import Gf, UsdGeom
743
-
744
- num_lines = int(len(indices) / 2)
745
-
746
- if num_lines < 1:
747
- return
748
-
749
- # look up rope point instancer
750
- instancer_path = self.root.GetPath().AppendChild(name)
751
- instancer = UsdGeom.PointInstancer.Get(self.stage, instancer_path)
752
-
753
- if not instancer:
754
- instancer = UsdGeom.PointInstancer.Define(self.stage, instancer_path)
755
- instancer_capsule = UsdGeom.Capsule.Define(self.stage, instancer.GetPath().AppendChild("capsule"))
756
- instancer_capsule.GetRadiusAttr().Set(radius)
757
- instancer.CreatePrototypesRel().SetTargets([instancer_capsule.GetPath()])
758
- # instancer.CreatePrimvar("displayColor", Sdf.ValueTypeNames.Float3Array, "constant", 1)
759
-
760
- line_positions = []
761
- line_rotations = []
762
- line_scales = []
763
-
764
- for i in range(num_lines):
765
- pos0 = vertices[indices[i * 2 + 0]]
766
- pos1 = vertices[indices[i * 2 + 1]]
767
-
768
- (pos, rot, scale) = _compute_segment_xform(
769
- Gf.Vec3f(float(pos0[0]), float(pos0[1]), float(pos0[2])),
770
- Gf.Vec3f(float(pos1[0]), float(pos1[1]), float(pos1[2])),
771
- )
772
-
773
- line_positions.append(pos)
774
- line_rotations.append(rot)
775
- line_scales.append(scale)
776
- # line_colors.append(Gf.Vec3f((float(i)/num_lines, 0.5, 0.5)))
777
-
778
- instancer.GetPositionsAttr().Set(line_positions, self.time)
779
- instancer.GetOrientationsAttr().Set(line_rotations, self.time)
780
- instancer.GetScalesAttr().Set(line_scales, self.time)
781
- instancer.GetProtoIndicesAttr().Set([0] * num_lines, self.time)
782
-
783
- # instancer.GetPrimvar("displayColor").Set(line_colors, time)
784
-
785
- instancer.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
786
-
787
- def render_line_strip(
788
- self,
789
- name: str,
790
- vertices,
791
- color: tuple[float, float, float] | None = None,
792
- radius: float = 0.01,
793
- visible: bool = True,
794
- ):
795
- from pxr import Gf, UsdGeom
796
-
797
- num_lines = int(len(vertices) - 1)
798
-
799
- if num_lines < 1:
800
- return
801
-
802
- # look up rope point instancer
803
- instancer_path = self.root.GetPath().AppendChild(name)
804
- instancer = UsdGeom.PointInstancer.Get(self.stage, instancer_path)
805
-
806
- if not instancer:
807
- instancer = UsdGeom.PointInstancer.Define(self.stage, instancer_path)
808
- instancer_capsule = UsdGeom.Capsule.Define(self.stage, instancer.GetPath().AppendChild("capsule"))
809
- instancer_capsule.GetRadiusAttr().Set(radius)
810
- instancer.CreatePrototypesRel().SetTargets([instancer_capsule.GetPath()])
811
-
812
- line_positions = []
813
- line_rotations = []
814
- line_scales = []
815
-
816
- for i in range(num_lines):
817
- pos0 = vertices[i]
818
- pos1 = vertices[i + 1]
819
-
820
- (pos, rot, scale) = _compute_segment_xform(
821
- Gf.Vec3f(float(pos0[0]), float(pos0[1]), float(pos0[2])),
822
- Gf.Vec3f(float(pos1[0]), float(pos1[1]), float(pos1[2])),
823
- )
824
-
825
- line_positions.append(pos)
826
- line_rotations.append(rot)
827
- line_scales.append(scale)
828
-
829
- instancer.GetPositionsAttr().Set(line_positions, self.time)
830
- instancer.GetOrientationsAttr().Set(line_rotations, self.time)
831
- instancer.GetScalesAttr().Set(line_scales, self.time)
832
- instancer.GetProtoIndicesAttr().Set([0] * num_lines, self.time)
833
-
834
- instancer_capsule = UsdGeom.Capsule.Get(self.stage, instancer.GetPath().AppendChild("capsule"))
835
- instancer_capsule.GetDisplayColorAttr().Set([Gf.Vec3f(color)], self.time)
836
-
837
- instancer.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
838
-
839
- def render_points(self, name: str, points, radius, colors=None, as_spheres: bool = True, visible: bool = True):
840
- from pxr import Sdf, UsdGeom, Vt
841
-
842
- instancer_path = self._resolve_path(name)
843
-
844
- if np.isscalar(radius):
845
- radius_interp = "constant"
846
- else:
847
- radius_interp = "vertex"
848
-
849
- if colors is None:
850
- color_interp = "constant"
851
- elif len(colors) == 3 and all(np.isscalar(x) for x in colors):
852
- color_interp = "constant"
853
- is_single_color = True
854
- else:
855
- color_interp = "vertex"
856
- is_single_color = False
857
-
858
- if as_spheres:
859
- instancer = UsdGeom.PointInstancer.Get(self.stage, instancer_path)
860
- if not instancer:
861
- instancer = UsdGeom.PointInstancer.Define(self.stage, instancer_path)
862
- sphere = UsdGeom.Sphere.Define(self.stage, instancer.GetPath().AppendChild("sphere"))
863
- primvar_api = UsdGeom.PrimvarsAPI(instancer)
864
-
865
- instancer.CreatePrototypesRel().SetTargets((sphere.GetPath(),))
866
- instancer.CreateProtoIndicesAttr().Set(Vt.IntArray((0,) * len(points)))
867
-
868
- if colors is not None:
869
- primvar_api.CreatePrimvar("displayColor", Sdf.ValueTypeNames.Color3fArray, color_interp, 1)
870
-
871
- instancer.GetPositionsAttr().Set(points, self.time)
872
-
873
- if radius_interp == "constant":
874
- radius = np.tile(radius, (3, len(points))).T
875
- else:
876
- radius = np.tile(radius, (3, 1)).T
877
-
878
- instancer.GetScalesAttr().Set(radius, self.time)
879
-
880
- if colors is not None:
881
- if is_single_color:
882
- colors = (colors,)
883
-
884
- primvar_api = UsdGeom.PrimvarsAPI(instancer)
885
- primvar_api.GetPrimvar("displayColor").Set(colors, self.time)
886
- else:
887
- instancer = UsdGeom.Points.Get(self.stage, instancer_path)
888
- if not instancer:
889
- instancer = UsdGeom.Points.Define(self.stage, instancer_path)
890
-
891
- UsdGeom.Primvar(instancer.GetWidthsAttr()).SetInterpolation(radius_interp)
892
- UsdGeom.Primvar(instancer.GetDisplayColorAttr()).SetInterpolation(color_interp)
893
-
894
- instancer.GetPointsAttr().Set(points, self.time)
895
-
896
- if np.isscalar(radius):
897
- widths = (radius * 2.0,)
898
- else:
899
- widths = np.array(radius) * 2.0
900
-
901
- instancer.GetWidthsAttr().Set(widths, self.time)
902
-
903
- if colors is not None:
904
- if len(colors) == 3:
905
- colors = (colors,)
906
-
907
- instancer.GetDisplayColorAttr().Set(colors, self.time)
908
-
909
- instancer.GetVisibilityAttr().Set("inherited" if visible else "invisible", self.time)
910
- return instancer.GetPath()
911
-
912
- def update_body_transforms(self, body_q):
913
- from pxr import Sdf, UsdGeom
914
-
915
- if isinstance(body_q, wp.array):
916
- body_q = body_q.numpy()
917
-
918
- with Sdf.ChangeBlock():
919
- for b in range(self.model.body_count):
920
- node_name = self.body_names[b]
921
- node = UsdGeom.Xform(self.stage.GetPrimAtPath(self.root.GetPath().AppendChild(node_name)))
922
-
923
- # unpack rigid transform
924
- X_sb = wp.transform_expand(body_q[b])
925
-
926
- _usd_set_xform(node, X_sb.p, X_sb.q, (1.0, 1.0, 1.0), self.time)
927
-
928
- def save(self):
929
- try:
930
- self.stage.Save()
931
- except Exception as e:
932
- print("Failed to save USD stage:", e)
933
- return False
934
-
935
- file_path = self.stage.GetRootLayer().realPath
936
- print(f"Saved the USD stage file at `{file_path}`")
937
- return True
24
+ return get_deprecated_api(_render_usd, "wp.render", name)