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.
- warp/__init__.py +301 -287
- warp/__init__.pyi +794 -305
- warp/_src/__init__.py +14 -0
- warp/_src/autograd.py +1075 -0
- warp/_src/build.py +618 -0
- warp/_src/build_dll.py +640 -0
- warp/{builtins.py → _src/builtins.py} +1382 -377
- warp/_src/codegen.py +4359 -0
- warp/{config.py → _src/config.py} +178 -169
- warp/_src/constants.py +57 -0
- warp/_src/context.py +8294 -0
- warp/_src/dlpack.py +462 -0
- warp/_src/fabric.py +355 -0
- warp/_src/fem/__init__.py +14 -0
- warp/_src/fem/adaptivity.py +508 -0
- warp/_src/fem/cache.py +687 -0
- warp/_src/fem/dirichlet.py +188 -0
- warp/{fem → _src/fem}/domain.py +40 -30
- warp/_src/fem/field/__init__.py +131 -0
- warp/_src/fem/field/field.py +701 -0
- warp/{fem → _src/fem}/field/nodal_field.py +30 -15
- warp/{fem → _src/fem}/field/restriction.py +1 -1
- warp/{fem → _src/fem}/field/virtual.py +53 -27
- warp/_src/fem/geometry/__init__.py +32 -0
- warp/{fem → _src/fem}/geometry/adaptive_nanogrid.py +77 -163
- warp/_src/fem/geometry/closest_point.py +97 -0
- warp/{fem → _src/fem}/geometry/deformed_geometry.py +14 -22
- warp/{fem → _src/fem}/geometry/element.py +32 -10
- warp/{fem → _src/fem}/geometry/geometry.py +48 -20
- warp/{fem → _src/fem}/geometry/grid_2d.py +12 -23
- warp/{fem → _src/fem}/geometry/grid_3d.py +12 -23
- warp/{fem → _src/fem}/geometry/hexmesh.py +40 -63
- warp/{fem → _src/fem}/geometry/nanogrid.py +255 -248
- warp/{fem → _src/fem}/geometry/partition.py +121 -63
- warp/{fem → _src/fem}/geometry/quadmesh.py +26 -45
- warp/{fem → _src/fem}/geometry/tetmesh.py +40 -63
- warp/{fem → _src/fem}/geometry/trimesh.py +26 -45
- warp/{fem → _src/fem}/integrate.py +164 -158
- warp/_src/fem/linalg.py +383 -0
- warp/_src/fem/operator.py +396 -0
- warp/_src/fem/polynomial.py +229 -0
- warp/{fem → _src/fem}/quadrature/pic_quadrature.py +15 -20
- warp/{fem → _src/fem}/quadrature/quadrature.py +95 -47
- warp/_src/fem/space/__init__.py +248 -0
- warp/{fem → _src/fem}/space/basis_function_space.py +20 -11
- warp/_src/fem/space/basis_space.py +679 -0
- warp/{fem → _src/fem}/space/dof_mapper.py +3 -3
- warp/{fem → _src/fem}/space/function_space.py +14 -13
- warp/{fem → _src/fem}/space/grid_2d_function_space.py +4 -7
- warp/{fem → _src/fem}/space/grid_3d_function_space.py +4 -4
- warp/{fem → _src/fem}/space/hexmesh_function_space.py +4 -10
- warp/{fem → _src/fem}/space/nanogrid_function_space.py +3 -9
- warp/{fem → _src/fem}/space/partition.py +117 -60
- warp/{fem → _src/fem}/space/quadmesh_function_space.py +4 -10
- warp/{fem → _src/fem}/space/restriction.py +66 -33
- warp/_src/fem/space/shape/__init__.py +152 -0
- warp/{fem → _src/fem}/space/shape/cube_shape_function.py +9 -9
- warp/{fem → _src/fem}/space/shape/shape_function.py +8 -9
- warp/{fem → _src/fem}/space/shape/square_shape_function.py +6 -6
- warp/{fem → _src/fem}/space/shape/tet_shape_function.py +3 -3
- warp/{fem → _src/fem}/space/shape/triangle_shape_function.py +3 -3
- warp/{fem → _src/fem}/space/tetmesh_function_space.py +3 -9
- warp/_src/fem/space/topology.py +459 -0
- warp/{fem → _src/fem}/space/trimesh_function_space.py +3 -9
- warp/_src/fem/types.py +112 -0
- warp/_src/fem/utils.py +486 -0
- warp/_src/jax.py +186 -0
- warp/_src/jax_experimental/__init__.py +14 -0
- warp/_src/jax_experimental/custom_call.py +387 -0
- warp/_src/jax_experimental/ffi.py +1284 -0
- warp/_src/jax_experimental/xla_ffi.py +656 -0
- warp/_src/marching_cubes.py +708 -0
- warp/_src/math.py +414 -0
- warp/_src/optim/__init__.py +14 -0
- warp/_src/optim/adam.py +163 -0
- warp/_src/optim/linear.py +1606 -0
- warp/_src/optim/sgd.py +112 -0
- warp/_src/paddle.py +406 -0
- warp/_src/render/__init__.py +14 -0
- warp/_src/render/imgui_manager.py +289 -0
- warp/_src/render/render_opengl.py +3636 -0
- warp/_src/render/render_usd.py +937 -0
- warp/_src/render/utils.py +160 -0
- warp/_src/sparse.py +2716 -0
- warp/_src/tape.py +1206 -0
- warp/{thirdparty → _src/thirdparty}/unittest_parallel.py +9 -2
- warp/_src/torch.py +391 -0
- warp/_src/types.py +5870 -0
- warp/_src/utils.py +1693 -0
- warp/autograd.py +12 -1054
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/build.py +8 -588
- warp/build_dll.py +6 -721
- warp/codegen.py +6 -4251
- warp/constants.py +6 -39
- warp/context.py +12 -8062
- warp/dlpack.py +6 -444
- warp/examples/distributed/example_jacobi_mpi.py +4 -5
- warp/examples/fem/example_adaptive_grid.py +1 -1
- warp/examples/fem/example_apic_fluid.py +1 -1
- warp/examples/fem/example_burgers.py +8 -8
- warp/examples/fem/example_diffusion.py +1 -1
- warp/examples/fem/example_distortion_energy.py +1 -1
- warp/examples/fem/example_mixed_elasticity.py +2 -2
- warp/examples/fem/example_navier_stokes.py +1 -1
- warp/examples/fem/example_nonconforming_contact.py +7 -7
- warp/examples/fem/example_stokes.py +1 -1
- warp/examples/fem/example_stokes_transfer.py +1 -1
- warp/examples/fem/utils.py +2 -2
- warp/examples/interop/example_jax_callable.py +1 -1
- warp/examples/interop/example_jax_ffi_callback.py +1 -1
- warp/examples/interop/example_jax_kernel.py +1 -1
- warp/examples/tile/example_tile_mcgp.py +191 -0
- warp/fabric.py +6 -337
- warp/fem/__init__.py +159 -97
- warp/fem/adaptivity.py +7 -489
- warp/fem/cache.py +9 -648
- warp/fem/dirichlet.py +6 -184
- warp/fem/field/__init__.py +8 -109
- warp/fem/field/field.py +7 -652
- warp/fem/geometry/__init__.py +7 -18
- warp/fem/geometry/closest_point.py +11 -77
- warp/fem/linalg.py +18 -366
- warp/fem/operator.py +11 -369
- warp/fem/polynomial.py +9 -209
- warp/fem/space/__init__.py +5 -211
- warp/fem/space/basis_space.py +6 -662
- warp/fem/space/shape/__init__.py +41 -118
- warp/fem/space/topology.py +6 -437
- warp/fem/types.py +6 -81
- warp/fem/utils.py +11 -444
- warp/jax.py +8 -165
- warp/jax_experimental/__init__.py +14 -1
- warp/jax_experimental/custom_call.py +8 -365
- warp/jax_experimental/ffi.py +17 -873
- warp/jax_experimental/xla_ffi.py +5 -605
- warp/marching_cubes.py +5 -689
- warp/math.py +16 -393
- warp/native/array.h +385 -37
- warp/native/builtin.h +314 -37
- warp/native/bvh.cpp +43 -9
- warp/native/bvh.cu +62 -27
- warp/native/bvh.h +310 -309
- warp/native/clang/clang.cpp +102 -97
- warp/native/coloring.cpp +0 -1
- warp/native/crt.h +208 -0
- warp/native/exports.h +156 -0
- warp/native/hashgrid.cu +2 -0
- warp/native/intersect.h +24 -1
- warp/native/intersect_tri.h +44 -35
- warp/native/mat.h +1456 -276
- warp/native/mesh.cpp +4 -4
- warp/native/mesh.cu +4 -2
- warp/native/mesh.h +176 -61
- warp/native/quat.h +0 -52
- warp/native/scan.cu +2 -0
- warp/native/sparse.cu +7 -3
- warp/native/spatial.h +12 -0
- warp/native/tile.h +681 -89
- warp/native/tile_radix_sort.h +1 -1
- warp/native/tile_reduce.h +394 -46
- warp/native/tile_scan.h +4 -4
- warp/native/vec.h +469 -0
- warp/native/version.h +23 -0
- warp/native/volume.cpp +1 -1
- warp/native/volume.cu +1 -0
- warp/native/volume.h +1 -1
- warp/native/volume_builder.cu +2 -0
- warp/native/warp.cpp +57 -29
- warp/native/warp.cu +253 -171
- warp/native/warp.h +11 -8
- warp/optim/__init__.py +6 -3
- warp/optim/adam.py +6 -145
- warp/optim/linear.py +14 -1585
- warp/optim/sgd.py +6 -94
- warp/paddle.py +6 -388
- warp/render/__init__.py +8 -4
- warp/render/imgui_manager.py +7 -267
- warp/render/render_opengl.py +6 -3618
- warp/render/render_usd.py +6 -919
- warp/render/utils.py +6 -142
- warp/sparse.py +37 -2563
- warp/tape.py +6 -1188
- warp/tests/__main__.py +1 -1
- warp/tests/cuda/test_async.py +4 -4
- warp/tests/cuda/test_conditional_captures.py +1 -1
- warp/tests/cuda/test_multigpu.py +1 -1
- warp/tests/cuda/test_streams.py +58 -1
- warp/tests/geometry/test_bvh.py +157 -22
- warp/tests/geometry/test_marching_cubes.py +0 -1
- warp/tests/geometry/test_mesh.py +5 -3
- warp/tests/geometry/test_mesh_query_aabb.py +5 -12
- warp/tests/geometry/test_mesh_query_point.py +5 -2
- warp/tests/geometry/test_mesh_query_ray.py +15 -3
- warp/tests/geometry/test_volume_write.py +5 -5
- warp/tests/interop/test_dlpack.py +14 -14
- warp/tests/interop/test_jax.py +772 -49
- warp/tests/interop/test_paddle.py +1 -1
- warp/tests/test_adam.py +0 -1
- warp/tests/test_arithmetic.py +9 -9
- warp/tests/test_array.py +527 -100
- warp/tests/test_array_reduce.py +3 -3
- warp/tests/test_atomic.py +12 -8
- warp/tests/test_atomic_bitwise.py +209 -0
- warp/tests/test_atomic_cas.py +4 -4
- warp/tests/test_bool.py +2 -2
- warp/tests/test_builtins_resolution.py +5 -571
- warp/tests/test_codegen.py +33 -14
- warp/tests/test_conditional.py +1 -1
- warp/tests/test_context.py +6 -6
- warp/tests/test_copy.py +242 -161
- warp/tests/test_ctypes.py +3 -3
- warp/tests/test_devices.py +24 -2
- warp/tests/test_examples.py +16 -84
- warp/tests/test_fabricarray.py +35 -35
- warp/tests/test_fast_math.py +0 -2
- warp/tests/test_fem.py +56 -10
- warp/tests/test_fixedarray.py +3 -3
- warp/tests/test_func.py +8 -5
- warp/tests/test_generics.py +1 -1
- warp/tests/test_indexedarray.py +24 -24
- warp/tests/test_intersect.py +39 -9
- warp/tests/test_large.py +1 -1
- warp/tests/test_lerp.py +3 -1
- warp/tests/test_linear_solvers.py +1 -1
- warp/tests/test_map.py +35 -4
- warp/tests/test_mat.py +52 -62
- warp/tests/test_mat_constructors.py +4 -5
- warp/tests/test_mat_lite.py +1 -1
- warp/tests/test_mat_scalar_ops.py +121 -121
- warp/tests/test_math.py +34 -0
- warp/tests/test_module_aot.py +4 -4
- warp/tests/test_modules_lite.py +28 -2
- warp/tests/test_print.py +11 -11
- warp/tests/test_quat.py +93 -58
- warp/tests/test_runlength_encode.py +1 -1
- warp/tests/test_scalar_ops.py +38 -10
- warp/tests/test_smoothstep.py +1 -1
- warp/tests/test_sparse.py +126 -15
- warp/tests/test_spatial.py +105 -87
- warp/tests/test_special_values.py +6 -6
- warp/tests/test_static.py +7 -7
- warp/tests/test_struct.py +13 -2
- warp/tests/test_triangle_closest_point.py +48 -1
- warp/tests/test_types.py +27 -15
- warp/tests/test_utils.py +52 -52
- warp/tests/test_vec.py +29 -29
- warp/tests/test_vec_constructors.py +5 -5
- warp/tests/test_vec_scalar_ops.py +97 -97
- warp/tests/test_version.py +75 -0
- warp/tests/tile/test_tile.py +178 -0
- warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
- warp/tests/tile/test_tile_cholesky.py +7 -4
- warp/tests/tile/test_tile_load.py +26 -2
- warp/tests/tile/test_tile_mathdx.py +3 -3
- warp/tests/tile/test_tile_matmul.py +1 -1
- warp/tests/tile/test_tile_mlp.py +2 -4
- warp/tests/tile/test_tile_reduce.py +214 -13
- warp/tests/unittest_suites.py +6 -14
- warp/tests/unittest_utils.py +10 -9
- warp/tests/walkthrough_debug.py +3 -1
- warp/torch.py +6 -373
- warp/types.py +29 -5764
- warp/utils.py +10 -1659
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/METADATA +46 -99
- warp_lang-1.10.0rc2.dist-info/RECORD +468 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
- warp/examples/assets/cartpole.urdf +0 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/nv_ant.xml +0 -92
- warp/examples/assets/nv_humanoid.xml +0 -183
- warp/examples/assets/quadruped.urdf +0 -268
- warp/examples/optim/example_bounce.py +0 -266
- warp/examples/optim/example_cloth_throw.py +0 -228
- warp/examples/optim/example_drone.py +0 -870
- warp/examples/optim/example_inverse_kinematics.py +0 -182
- warp/examples/optim/example_inverse_kinematics_torch.py +0 -191
- warp/examples/optim/example_softbody_properties.py +0 -400
- warp/examples/optim/example_spring_cage.py +0 -245
- warp/examples/optim/example_trajectory.py +0 -227
- warp/examples/sim/example_cartpole.py +0 -143
- warp/examples/sim/example_cloth.py +0 -225
- warp/examples/sim/example_cloth_self_contact.py +0 -316
- warp/examples/sim/example_granular.py +0 -130
- warp/examples/sim/example_granular_collision_sdf.py +0 -202
- warp/examples/sim/example_jacobian_ik.py +0 -244
- warp/examples/sim/example_particle_chain.py +0 -124
- warp/examples/sim/example_quadruped.py +0 -203
- warp/examples/sim/example_rigid_chain.py +0 -203
- warp/examples/sim/example_rigid_contact.py +0 -195
- warp/examples/sim/example_rigid_force.py +0 -133
- warp/examples/sim/example_rigid_gyroscopic.py +0 -115
- warp/examples/sim/example_rigid_soft_contact.py +0 -140
- warp/examples/sim/example_soft_body.py +0 -196
- warp/examples/tile/example_tile_walker.py +0 -327
- warp/sim/__init__.py +0 -74
- warp/sim/articulation.py +0 -793
- warp/sim/collide.py +0 -2570
- warp/sim/graph_coloring.py +0 -307
- warp/sim/import_mjcf.py +0 -791
- warp/sim/import_snu.py +0 -227
- warp/sim/import_urdf.py +0 -579
- warp/sim/import_usd.py +0 -898
- warp/sim/inertia.py +0 -357
- warp/sim/integrator.py +0 -245
- warp/sim/integrator_euler.py +0 -2000
- warp/sim/integrator_featherstone.py +0 -2101
- warp/sim/integrator_vbd.py +0 -2487
- warp/sim/integrator_xpbd.py +0 -3295
- warp/sim/model.py +0 -4821
- warp/sim/particles.py +0 -121
- warp/sim/render.py +0 -431
- warp/sim/utils.py +0 -431
- warp/tests/sim/disabled_kinematics.py +0 -244
- warp/tests/sim/test_cloth.py +0 -863
- warp/tests/sim/test_collision.py +0 -743
- warp/tests/sim/test_coloring.py +0 -347
- warp/tests/sim/test_inertia.py +0 -161
- warp/tests/sim/test_model.py +0 -226
- warp/tests/sim/test_sim_grad.py +0 -287
- warp/tests/sim/test_sim_grad_bounce_linear.py +0 -212
- warp/tests/sim/test_sim_kinematics.py +0 -98
- warp/thirdparty/__init__.py +0 -0
- warp_lang-1.9.1.dist-info/RECORD +0 -456
- /warp/{fem → _src/fem}/quadrature/__init__.py +0 -0
- /warp/{tests/sim → _src/thirdparty}/__init__.py +0 -0
- /warp/{thirdparty → _src/thirdparty}/appdirs.py +0 -0
- /warp/{thirdparty → _src/thirdparty}/dlpack.py +0 -0
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/WHEEL +0 -0
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/licenses/LICENSE.md +0 -0
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/top_level.txt +0 -0
warp/sim/import_usd.py
DELETED
|
@@ -1,898 +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
|
-
from __future__ import annotations
|
|
17
|
-
|
|
18
|
-
import re
|
|
19
|
-
|
|
20
|
-
import numpy as np
|
|
21
|
-
|
|
22
|
-
import warp as wp
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def parse_usd(
|
|
26
|
-
source,
|
|
27
|
-
builder,
|
|
28
|
-
default_density=1.0e3,
|
|
29
|
-
only_load_enabled_rigid_bodies=False,
|
|
30
|
-
only_load_enabled_joints=True,
|
|
31
|
-
contact_ke=1e5,
|
|
32
|
-
contact_kd=250.0,
|
|
33
|
-
contact_kf=500.0,
|
|
34
|
-
contact_ka=0.0,
|
|
35
|
-
contact_mu=0.6,
|
|
36
|
-
contact_restitution=0.0,
|
|
37
|
-
contact_thickness=0.0,
|
|
38
|
-
joint_limit_ke=100.0,
|
|
39
|
-
joint_limit_kd=10.0,
|
|
40
|
-
armature=0.0,
|
|
41
|
-
invert_rotations=False,
|
|
42
|
-
verbose=False,
|
|
43
|
-
ignore_paths=None,
|
|
44
|
-
):
|
|
45
|
-
"""
|
|
46
|
-
Parses a Universal Scene Description (USD) stage containing UsdPhysics schema definitions for rigid-body articulations and adds the bodies, shapes and joints to the given ModelBuilder.
|
|
47
|
-
|
|
48
|
-
The USD description has to be either a path (file name or URL), or an existing USD stage instance that implements the `UsdStage <https://openusd.org/dev/api/class_usd_stage.html>`_ interface.
|
|
49
|
-
|
|
50
|
-
Args:
|
|
51
|
-
source (str | pxr.UsdStage): The file path to the USD file, or an existing USD stage instance.
|
|
52
|
-
builder (ModelBuilder): The :class:`ModelBuilder` to add the bodies and joints to.
|
|
53
|
-
default_density (float): The default density to use for bodies without a density attribute.
|
|
54
|
-
only_load_enabled_rigid_bodies (bool): If True, only rigid bodies which do not have `physics:rigidBodyEnabled` set to False are loaded.
|
|
55
|
-
only_load_enabled_joints (bool): If True, only joints which do not have `physics:jointEnabled` set to False are loaded.
|
|
56
|
-
contact_ke (float): The default contact stiffness to use, only considered by the Euler integrators.
|
|
57
|
-
contact_kd (float): The default contact damping to use, only considered by the Euler integrators.
|
|
58
|
-
contact_kf (float): The default friction stiffness to use, only considered by the Euler integrators.
|
|
59
|
-
contact_ka (float): The default adhesion distance to use, only considered by the Euler integrators.
|
|
60
|
-
contact_mu (float): The default friction coefficient to use if a shape has not friction coefficient defined.
|
|
61
|
-
contact_restitution (float): The default coefficient of restitution to use if a shape has not coefficient of restitution defined.
|
|
62
|
-
contact_thickness (float): The thickness to add to the shape geometry.
|
|
63
|
-
joint_limit_ke (float): The default stiffness to use for joint limits, only considered by the Euler integrators.
|
|
64
|
-
joint_limit_kd (float): The default damping to use for joint limits, only considered by the Euler integrators.
|
|
65
|
-
armature (float): The armature to use for the bodies.
|
|
66
|
-
invert_rotations (bool): If True, inverts any rotations defined in the shape transforms.
|
|
67
|
-
verbose (bool): If True, print additional information about the parsed USD file.
|
|
68
|
-
ignore_paths (List[str]): A list of regular expressions matching prim paths to ignore.
|
|
69
|
-
|
|
70
|
-
Returns:
|
|
71
|
-
dict: Dictionary with the following entries:
|
|
72
|
-
|
|
73
|
-
.. list-table::
|
|
74
|
-
:widths: 25 75
|
|
75
|
-
|
|
76
|
-
* - "fps"
|
|
77
|
-
- USD stage frames per second
|
|
78
|
-
* - "duration"
|
|
79
|
-
- Difference between end time code and start time code of the USD stage
|
|
80
|
-
* - "up_axis"
|
|
81
|
-
- Upper-case string of the stage's up axis ("X", "Y", or "Z")
|
|
82
|
-
* - "path_shape_map"
|
|
83
|
-
- Mapping from prim path (str) of the UsdGeom to the respective shape index in :class:`ModelBuilder`
|
|
84
|
-
* - "path_body_map"
|
|
85
|
-
- Mapping from prim path (str) of a rigid body prim (e.g. that implements the PhysicsRigidBodyAPI) to the respective body index in :class:`ModelBuilder`
|
|
86
|
-
* - "path_shape_scale"
|
|
87
|
-
- Mapping from prim path (str) of the UsdGeom to its respective 3D world scale
|
|
88
|
-
* - "mass_unit"
|
|
89
|
-
- The stage's Kilograms Per Unit (KGPU) definition (1.0 by default)
|
|
90
|
-
* - "linear_unit"
|
|
91
|
-
- The stage's Meters Per Unit (MPU) definition (1.0 by default)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
Note:
|
|
95
|
-
This importer is experimental and only supports a subset of the USD Physics schema. Please report any issues you encounter.
|
|
96
|
-
"""
|
|
97
|
-
try:
|
|
98
|
-
from pxr import Usd, UsdGeom, UsdPhysics
|
|
99
|
-
except ImportError as e:
|
|
100
|
-
raise ImportError("Failed to import pxr. Please install USD (e.g. via `pip install usd-core`).") from e
|
|
101
|
-
|
|
102
|
-
if ignore_paths is None:
|
|
103
|
-
ignore_paths = []
|
|
104
|
-
|
|
105
|
-
def get_attribute(prim, name):
|
|
106
|
-
if "*" in name:
|
|
107
|
-
regex = name.replace("*", ".*")
|
|
108
|
-
for attr in prim.GetAttributes():
|
|
109
|
-
if re.match(regex, attr.GetName()):
|
|
110
|
-
return attr
|
|
111
|
-
else:
|
|
112
|
-
return prim.GetAttribute(name)
|
|
113
|
-
|
|
114
|
-
def has_attribute(prim, name):
|
|
115
|
-
attr = get_attribute(prim, name)
|
|
116
|
-
return attr.IsValid() and attr.HasAuthoredValue()
|
|
117
|
-
|
|
118
|
-
def parse_float(prim, name, default=None):
|
|
119
|
-
attr = get_attribute(prim, name)
|
|
120
|
-
if not attr or not attr.HasAuthoredValue():
|
|
121
|
-
return default
|
|
122
|
-
val = attr.Get()
|
|
123
|
-
if np.isfinite(val):
|
|
124
|
-
return val
|
|
125
|
-
return default
|
|
126
|
-
|
|
127
|
-
def parse_quat(prim, name, default=None):
|
|
128
|
-
attr = get_attribute(prim, name)
|
|
129
|
-
if not attr or not attr.HasAuthoredValue():
|
|
130
|
-
return default
|
|
131
|
-
val = attr.Get()
|
|
132
|
-
if invert_rotations:
|
|
133
|
-
quat = wp.quat(*val.imaginary, -val.real)
|
|
134
|
-
else:
|
|
135
|
-
quat = wp.quat(*val.imaginary, val.real)
|
|
136
|
-
l = wp.length(quat)
|
|
137
|
-
if np.isfinite(l) and l > 0.0:
|
|
138
|
-
return quat
|
|
139
|
-
return default
|
|
140
|
-
|
|
141
|
-
def parse_vec(prim, name, default=None):
|
|
142
|
-
attr = get_attribute(prim, name)
|
|
143
|
-
if not attr or not attr.HasAuthoredValue():
|
|
144
|
-
return default
|
|
145
|
-
val = attr.Get()
|
|
146
|
-
if np.isfinite(val).all():
|
|
147
|
-
return np.array(val, dtype=np.float32)
|
|
148
|
-
return default
|
|
149
|
-
|
|
150
|
-
def parse_generic(prim, name, default=None):
|
|
151
|
-
attr = get_attribute(prim, name)
|
|
152
|
-
if not attr or not attr.HasAuthoredValue():
|
|
153
|
-
return default
|
|
154
|
-
return attr.Get()
|
|
155
|
-
|
|
156
|
-
def str2axis(s: str) -> np.ndarray:
|
|
157
|
-
axis = np.zeros(3, dtype=np.float32)
|
|
158
|
-
axis["XYZ".index(s.upper())] = 1.0
|
|
159
|
-
return axis
|
|
160
|
-
|
|
161
|
-
if isinstance(source, str):
|
|
162
|
-
stage = Usd.Stage.Open(source, Usd.Stage.LoadAll)
|
|
163
|
-
else:
|
|
164
|
-
stage = source
|
|
165
|
-
|
|
166
|
-
mass_unit = 1.0
|
|
167
|
-
try:
|
|
168
|
-
if UsdPhysics.StageHasAuthoredKilogramsPerUnit(stage):
|
|
169
|
-
mass_unit = UsdPhysics.GetStageKilogramsPerUnit(stage)
|
|
170
|
-
except Exception as e:
|
|
171
|
-
if verbose:
|
|
172
|
-
print(f"Failed to get mass unit: {e}")
|
|
173
|
-
linear_unit = 1.0
|
|
174
|
-
try:
|
|
175
|
-
if UsdGeom.StageHasAuthoredMetersPerUnit(stage):
|
|
176
|
-
linear_unit = UsdGeom.GetStageMetersPerUnit(stage)
|
|
177
|
-
except Exception as e:
|
|
178
|
-
if verbose:
|
|
179
|
-
print(f"Failed to get linear unit: {e}")
|
|
180
|
-
|
|
181
|
-
def parse_xform(prim):
|
|
182
|
-
xform = UsdGeom.Xform(prim)
|
|
183
|
-
mat = np.array(xform.GetLocalTransformation(), dtype=np.float32)
|
|
184
|
-
if invert_rotations:
|
|
185
|
-
rot = wp.quat_from_matrix(wp.mat33(mat[:3, :3].T.flatten()))
|
|
186
|
-
else:
|
|
187
|
-
rot = wp.quat_from_matrix(wp.mat33(mat[:3, :3].flatten()))
|
|
188
|
-
pos = mat[3, :3] * linear_unit
|
|
189
|
-
scale = np.ones(3, dtype=np.float32)
|
|
190
|
-
for op in xform.GetOrderedXformOps():
|
|
191
|
-
if op.GetOpType() == UsdGeom.XformOp.TypeScale:
|
|
192
|
-
scale = np.array(op.Get(), dtype=np.float32)
|
|
193
|
-
return wp.transform(pos, rot), scale
|
|
194
|
-
|
|
195
|
-
def parse_axis(prim, type, joint_data, is_angular, axis=None):
|
|
196
|
-
# parse joint axis data
|
|
197
|
-
schemas = prim.GetAppliedSchemas()
|
|
198
|
-
schemas_str = "".join(schemas)
|
|
199
|
-
if f"DriveAPI:{type}" not in schemas_str and f"PhysicsLimitAPI:{type}" not in schemas_str:
|
|
200
|
-
return
|
|
201
|
-
drive_type = parse_generic(prim, f"drive:{type}:physics:type", "force")
|
|
202
|
-
if drive_type != "force":
|
|
203
|
-
print(f"Warning: only force drive type is supported, ignoring drive:{type} for joint {path}")
|
|
204
|
-
return
|
|
205
|
-
stiffness = parse_float(prim, f"drive:{type}:physics:stiffness", 0.0)
|
|
206
|
-
damping = parse_float(prim, f"drive:{type}:physics:damping", 0.0)
|
|
207
|
-
low = parse_float(prim, f"limit:{type}:physics:low")
|
|
208
|
-
high = parse_float(prim, f"limit:{type}:physics:high")
|
|
209
|
-
target_pos = parse_float(prim, f"drive:{type}:physics:targetPosition")
|
|
210
|
-
target_vel = parse_float(prim, f"drive:{type}:physics:targetVelocity")
|
|
211
|
-
if is_angular:
|
|
212
|
-
stiffness *= mass_unit * linear_unit**2
|
|
213
|
-
stiffness = np.deg2rad(stiffness)
|
|
214
|
-
damping *= mass_unit * linear_unit**2
|
|
215
|
-
damping = np.deg2rad(damping)
|
|
216
|
-
if target_pos is not None:
|
|
217
|
-
target_pos = np.deg2rad(target_pos)
|
|
218
|
-
if target_vel is not None:
|
|
219
|
-
target_vel = np.deg2rad(target_vel)
|
|
220
|
-
if low is None:
|
|
221
|
-
low = joint_data["lowerLimit"]
|
|
222
|
-
else:
|
|
223
|
-
low = np.deg2rad(low)
|
|
224
|
-
if high is None:
|
|
225
|
-
high = joint_data["upperLimit"]
|
|
226
|
-
else:
|
|
227
|
-
high = np.deg2rad(high)
|
|
228
|
-
else:
|
|
229
|
-
stiffness *= mass_unit
|
|
230
|
-
damping *= mass_unit
|
|
231
|
-
if target_pos is not None:
|
|
232
|
-
target_pos *= linear_unit
|
|
233
|
-
if target_vel is not None:
|
|
234
|
-
target_vel *= linear_unit
|
|
235
|
-
if low is None:
|
|
236
|
-
low = joint_data["lowerLimit"]
|
|
237
|
-
else:
|
|
238
|
-
low *= linear_unit
|
|
239
|
-
if high is None:
|
|
240
|
-
high = joint_data["upperLimit"]
|
|
241
|
-
else:
|
|
242
|
-
high *= linear_unit
|
|
243
|
-
|
|
244
|
-
mode = wp.sim.JOINT_MODE_FORCE
|
|
245
|
-
if f"DriveAPI:{type}" in schemas_str:
|
|
246
|
-
if target_vel is not None and target_vel != 0.0:
|
|
247
|
-
mode = wp.sim.JOINT_MODE_TARGET_VELOCITY
|
|
248
|
-
else:
|
|
249
|
-
mode = wp.sim.JOINT_MODE_TARGET_POSITION
|
|
250
|
-
if low > high:
|
|
251
|
-
low = (low + high) / 2
|
|
252
|
-
high = low
|
|
253
|
-
axis = wp.sim.JointAxis(
|
|
254
|
-
axis=(axis or joint_data["axis"]),
|
|
255
|
-
limit_lower=low,
|
|
256
|
-
limit_upper=high,
|
|
257
|
-
action=(target_pos or target_vel or (low + high) / 2),
|
|
258
|
-
target_ke=stiffness,
|
|
259
|
-
target_kd=damping,
|
|
260
|
-
mode=mode,
|
|
261
|
-
limit_ke=joint_limit_ke,
|
|
262
|
-
limit_kd=joint_limit_kd,
|
|
263
|
-
)
|
|
264
|
-
if is_angular:
|
|
265
|
-
joint_data["angular_axes"].append(axis)
|
|
266
|
-
else:
|
|
267
|
-
joint_data["linear_axes"].append(axis)
|
|
268
|
-
|
|
269
|
-
axis_str = "Y"
|
|
270
|
-
try:
|
|
271
|
-
axis_str = UsdGeom.GetStageUpAxis(stage)
|
|
272
|
-
except Exception as e:
|
|
273
|
-
if verbose:
|
|
274
|
-
print(f"Failed to parse stage up axis: {e}")
|
|
275
|
-
upaxis = str2axis(axis_str)
|
|
276
|
-
|
|
277
|
-
shape_types = {"Cube", "Sphere", "Mesh", "Capsule", "Plane", "Cylinder", "Cone"}
|
|
278
|
-
|
|
279
|
-
path_body_map = {}
|
|
280
|
-
path_shape_map = {}
|
|
281
|
-
path_shape_scale = {}
|
|
282
|
-
# maps prim path name to its world transform
|
|
283
|
-
path_world_poses = {}
|
|
284
|
-
# transform from body frame to where the actual joint child frame is
|
|
285
|
-
# so that the link's children will use the right parent tf for the joint
|
|
286
|
-
prim_joint_xforms = {}
|
|
287
|
-
path_collision_filters = set()
|
|
288
|
-
no_collision_shapes = set()
|
|
289
|
-
|
|
290
|
-
body_density = {} # mapping from body ID to defined density
|
|
291
|
-
|
|
292
|
-
# first find all joints and materials
|
|
293
|
-
joint_data = {} # mapping from path of child link to joint USD settings
|
|
294
|
-
materials = {} # mapping from material path to material USD settings
|
|
295
|
-
joint_parents = set() # paths of joint parents
|
|
296
|
-
for prim in stage.Traverse():
|
|
297
|
-
type_name = str(prim.GetTypeName())
|
|
298
|
-
path = str(prim.GetPath())
|
|
299
|
-
# if verbose:
|
|
300
|
-
# print(path, type_name)
|
|
301
|
-
if type_name.endswith("Joint"):
|
|
302
|
-
# the type name can sometimes be "DistancePhysicsJoint" or "PhysicsDistanceJoint" ...
|
|
303
|
-
type_name = type_name.replace("Physics", "").replace("Joint", "")
|
|
304
|
-
child = str(prim.GetRelationship("physics:body1").GetTargets()[0])
|
|
305
|
-
pos0 = parse_vec(prim, "physics:localPos0", np.zeros(3, dtype=np.float32)) * linear_unit
|
|
306
|
-
pos1 = parse_vec(prim, "physics:localPos1", np.zeros(3, dtype=np.float32)) * linear_unit
|
|
307
|
-
rot0 = parse_quat(prim, "physics:localRot0", wp.quat_identity())
|
|
308
|
-
rot1 = parse_quat(prim, "physics:localRot1", wp.quat_identity())
|
|
309
|
-
joint_data[child] = {
|
|
310
|
-
"type": type_name,
|
|
311
|
-
"name": str(prim.GetName()),
|
|
312
|
-
"parent_tf": wp.transform(pos0, rot0),
|
|
313
|
-
"child_tf": wp.transform(pos1, rot1),
|
|
314
|
-
"enabled": parse_generic(prim, "physics:jointEnabled", True),
|
|
315
|
-
"collisionEnabled": parse_generic(prim, "physics:collisionEnabled", False),
|
|
316
|
-
"excludeFromArticulation": parse_generic(prim, "physics:excludeFromArticulation", False),
|
|
317
|
-
"axis": str2axis(parse_generic(prim, "physics:axis", "X")),
|
|
318
|
-
"breakForce": parse_float(prim, "physics:breakForce", np.inf),
|
|
319
|
-
"breakTorque": parse_float(prim, "physics:breakTorque", np.inf),
|
|
320
|
-
"linear_axes": [],
|
|
321
|
-
"angular_axes": [],
|
|
322
|
-
}
|
|
323
|
-
if only_load_enabled_joints and not joint_data[child]["enabled"]:
|
|
324
|
-
print("Skipping disabled joint", path)
|
|
325
|
-
continue
|
|
326
|
-
# parse joint limits
|
|
327
|
-
lower = parse_float(prim, "physics:lowerLimit", -np.inf)
|
|
328
|
-
upper = parse_float(prim, "physics:upperLimit", np.inf)
|
|
329
|
-
if type_name == "Distance":
|
|
330
|
-
# if distance is negative the joint is not limited
|
|
331
|
-
joint_data[child]["lowerLimit"] = parse_float(prim, "physics:minDistance", -1.0) * linear_unit
|
|
332
|
-
joint_data[child]["upperLimit"] = parse_float(prim, "physics:maxDistance", -1.0) * linear_unit
|
|
333
|
-
elif type_name == "Prismatic":
|
|
334
|
-
joint_data[child]["lowerLimit"] = lower * linear_unit
|
|
335
|
-
joint_data[child]["upperLimit"] = upper * linear_unit
|
|
336
|
-
else:
|
|
337
|
-
joint_data[child]["lowerLimit"] = np.deg2rad(lower) if np.isfinite(lower) else lower
|
|
338
|
-
joint_data[child]["upperLimit"] = np.deg2rad(upper) if np.isfinite(upper) else upper
|
|
339
|
-
|
|
340
|
-
if joint_data[child]["lowerLimit"] > joint_data[child]["upperLimit"]:
|
|
341
|
-
joint_data[child]["lowerLimit"] = (
|
|
342
|
-
joint_data[child]["lowerLimit"] + joint_data[child]["upperLimit"]
|
|
343
|
-
) / 2
|
|
344
|
-
joint_data[child]["upperLimit"] = joint_data[child]["lowerLimit"]
|
|
345
|
-
parents = prim.GetRelationship("physics:body0").GetTargets()
|
|
346
|
-
if len(parents) > 0:
|
|
347
|
-
parent_path = str(parents[0])
|
|
348
|
-
joint_data[child]["parent"] = parent_path
|
|
349
|
-
joint_parents.add(parent_path)
|
|
350
|
-
else:
|
|
351
|
-
joint_data[child]["parent"] = None
|
|
352
|
-
|
|
353
|
-
# parse joint drive
|
|
354
|
-
parse_axis(prim, "angular", joint_data[child], is_angular=True)
|
|
355
|
-
parse_axis(prim, "rotX", joint_data[child], is_angular=True, axis=(1.0, 0.0, 0.0))
|
|
356
|
-
parse_axis(prim, "rotY", joint_data[child], is_angular=True, axis=(0.0, 1.0, 0.0))
|
|
357
|
-
parse_axis(prim, "rotZ", joint_data[child], is_angular=True, axis=(0.0, 0.0, 1.0))
|
|
358
|
-
parse_axis(prim, "linear", joint_data[child], is_angular=False)
|
|
359
|
-
parse_axis(prim, "transX", joint_data[child], is_angular=False, axis=(1.0, 0.0, 0.0))
|
|
360
|
-
parse_axis(prim, "transY", joint_data[child], is_angular=False, axis=(0.0, 1.0, 0.0))
|
|
361
|
-
parse_axis(prim, "transZ", joint_data[child], is_angular=False, axis=(0.0, 0.0, 1.0))
|
|
362
|
-
|
|
363
|
-
elif type_name == "Material":
|
|
364
|
-
material = {}
|
|
365
|
-
if has_attribute(prim, "physics:density"):
|
|
366
|
-
material["density"] = parse_float(prim, "physics:density") * mass_unit # / (linear_unit**3)
|
|
367
|
-
if has_attribute(prim, "physics:restitution"):
|
|
368
|
-
material["restitution"] = parse_float(prim, "physics:restitution", contact_restitution)
|
|
369
|
-
if has_attribute(prim, "physics:staticFriction"):
|
|
370
|
-
material["staticFriction"] = parse_float(prim, "physics:staticFriction", contact_mu)
|
|
371
|
-
if has_attribute(prim, "physics:dynamicFriction"):
|
|
372
|
-
material["dynamicFriction"] = parse_float(prim, "physics:dynamicFriction", contact_mu)
|
|
373
|
-
materials[path] = material
|
|
374
|
-
|
|
375
|
-
elif type_name == "PhysicsScene":
|
|
376
|
-
try:
|
|
377
|
-
scene = UsdPhysics.Scene(prim)
|
|
378
|
-
g_vec = scene.GetGravityDirectionAttr()
|
|
379
|
-
g_mag = scene.GetGravityMagnitudeAttr()
|
|
380
|
-
if g_mag.HasAuthoredValue() and np.isfinite(g_mag.Get()):
|
|
381
|
-
builder.gravity = -np.abs(g_mag.Get() * linear_unit)
|
|
382
|
-
if g_vec.HasAuthoredValue() and np.linalg.norm(g_vec.Get()) > 0.0:
|
|
383
|
-
builder.up_vector = np.array(g_vec.Get(), dtype=np.float32)
|
|
384
|
-
if np.any(builder.up_vector < 0.0):
|
|
385
|
-
builder.up_vector = -builder.up_vector
|
|
386
|
-
else:
|
|
387
|
-
builder.up_vector = upaxis
|
|
388
|
-
except Exception as e:
|
|
389
|
-
if verbose:
|
|
390
|
-
print(f"Failed to parse physics scene: {e}")
|
|
391
|
-
|
|
392
|
-
def parse_prim(prim, incoming_xform, incoming_scale, parent_body: int = -1):
|
|
393
|
-
nonlocal builder
|
|
394
|
-
nonlocal joint_data
|
|
395
|
-
nonlocal path_body_map
|
|
396
|
-
nonlocal path_shape_map
|
|
397
|
-
nonlocal path_shape_scale
|
|
398
|
-
nonlocal path_world_poses
|
|
399
|
-
nonlocal prim_joint_xforms
|
|
400
|
-
nonlocal path_collision_filters
|
|
401
|
-
nonlocal no_collision_shapes
|
|
402
|
-
nonlocal body_density
|
|
403
|
-
|
|
404
|
-
path = str(prim.GetPath())
|
|
405
|
-
for pattern in ignore_paths:
|
|
406
|
-
if re.match(pattern, path):
|
|
407
|
-
return
|
|
408
|
-
|
|
409
|
-
type_name = str(prim.GetTypeName())
|
|
410
|
-
if type_name.endswith("Joint") or type_name.endswith("Light") or type_name.endswith("Material"):
|
|
411
|
-
return
|
|
412
|
-
if verbose:
|
|
413
|
-
print(f"parse_prim {prim.GetPath()} ({type_name})")
|
|
414
|
-
if type_name == "PhysicsScene":
|
|
415
|
-
# in case the PhysicsScene has bodies as children...
|
|
416
|
-
for child in prim.GetChildren():
|
|
417
|
-
parse_prim(child, incoming_xform, incoming_scale, parent_body)
|
|
418
|
-
|
|
419
|
-
schemas = set(prim.GetAppliedSchemas())
|
|
420
|
-
children_refs = prim.GetChildren()
|
|
421
|
-
|
|
422
|
-
prim_joint_xforms[path] = wp.transform()
|
|
423
|
-
|
|
424
|
-
local_xform, scale = parse_xform(prim)
|
|
425
|
-
scale = incoming_scale * scale
|
|
426
|
-
xform = wp.mul(incoming_xform, local_xform)
|
|
427
|
-
path_world_poses[path] = xform
|
|
428
|
-
|
|
429
|
-
geo_tf = local_xform
|
|
430
|
-
body_id = parent_body
|
|
431
|
-
is_rigid_body = "PhysicsRigidBodyAPI" in schemas and parent_body == -1
|
|
432
|
-
create_rigid_body = is_rigid_body or path in joint_parents
|
|
433
|
-
if create_rigid_body:
|
|
434
|
-
body_id = builder.add_body(
|
|
435
|
-
origin=xform,
|
|
436
|
-
name=prim.GetName(),
|
|
437
|
-
armature=armature,
|
|
438
|
-
)
|
|
439
|
-
path_body_map[path] = body_id
|
|
440
|
-
body_density[body_id] = 0.0
|
|
441
|
-
|
|
442
|
-
parent_body = body_id
|
|
443
|
-
|
|
444
|
-
geo_tf = wp.transform()
|
|
445
|
-
|
|
446
|
-
# set up joints between rigid bodies after the children have been added
|
|
447
|
-
if path in joint_data:
|
|
448
|
-
joint = joint_data[path]
|
|
449
|
-
|
|
450
|
-
joint_params = {
|
|
451
|
-
"child": body_id,
|
|
452
|
-
"linear_axes": joint["linear_axes"],
|
|
453
|
-
"angular_axes": joint["angular_axes"],
|
|
454
|
-
"name": joint["name"],
|
|
455
|
-
"enabled": joint["enabled"],
|
|
456
|
-
"parent_xform": joint["parent_tf"],
|
|
457
|
-
"child_xform": joint["child_tf"],
|
|
458
|
-
"armature": armature,
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
parent_path = joint["parent"]
|
|
462
|
-
if parent_path is None:
|
|
463
|
-
joint_params["parent"] = -1
|
|
464
|
-
parent_tf = wp.transform()
|
|
465
|
-
else:
|
|
466
|
-
joint_params["parent"] = path_body_map[parent_path]
|
|
467
|
-
parent_tf = path_world_poses[parent_path]
|
|
468
|
-
|
|
469
|
-
# the joint to which we are connected will transform this body already
|
|
470
|
-
geo_tf = wp.transform()
|
|
471
|
-
|
|
472
|
-
if verbose:
|
|
473
|
-
print(f"Adding joint {joint['name']} between {joint['parent']} and {path}")
|
|
474
|
-
print(" parent_xform", joint["parent_tf"])
|
|
475
|
-
print(" child_xform ", joint["child_tf"])
|
|
476
|
-
print(" parent_tf ", parent_tf)
|
|
477
|
-
print(f" geo_tf at {path} = {geo_tf} (xform was {xform})")
|
|
478
|
-
|
|
479
|
-
if joint["type"] == "Revolute":
|
|
480
|
-
joint_params["joint_type"] = wp.sim.JOINT_REVOLUTE
|
|
481
|
-
if len(joint_params["angular_axes"]) == 0:
|
|
482
|
-
joint_params["angular_axes"].append(
|
|
483
|
-
wp.sim.JointAxis(
|
|
484
|
-
joint["axis"],
|
|
485
|
-
limit_lower=joint["lowerLimit"],
|
|
486
|
-
limit_upper=joint["upperLimit"],
|
|
487
|
-
limit_ke=joint_limit_ke,
|
|
488
|
-
limit_kd=joint_limit_kd,
|
|
489
|
-
)
|
|
490
|
-
)
|
|
491
|
-
elif joint["type"] == "Prismatic":
|
|
492
|
-
joint_params["joint_type"] = wp.sim.JOINT_PRISMATIC
|
|
493
|
-
if len(joint_params["linear_axes"]) == 0:
|
|
494
|
-
joint_params["linear_axes"].append(
|
|
495
|
-
wp.sim.JointAxis(
|
|
496
|
-
joint["axis"],
|
|
497
|
-
limit_lower=joint["lowerLimit"],
|
|
498
|
-
limit_upper=joint["upperLimit"],
|
|
499
|
-
limit_ke=joint_limit_ke,
|
|
500
|
-
limit_kd=joint_limit_kd,
|
|
501
|
-
)
|
|
502
|
-
)
|
|
503
|
-
elif joint["type"] == "Spherical":
|
|
504
|
-
joint_params["joint_type"] = wp.sim.JOINT_BALL
|
|
505
|
-
elif joint["type"] == "Fixed":
|
|
506
|
-
joint_params["joint_type"] = wp.sim.JOINT_FIXED
|
|
507
|
-
elif joint["type"] == "Distance":
|
|
508
|
-
joint_params["joint_type"] = wp.sim.JOINT_DISTANCE
|
|
509
|
-
# we have to add a dummy linear X axis to define the joint limits
|
|
510
|
-
joint_params["linear_axes"].append(
|
|
511
|
-
wp.sim.JointAxis(
|
|
512
|
-
(1.0, 0.0, 0.0),
|
|
513
|
-
limit_lower=joint["lowerLimit"],
|
|
514
|
-
limit_upper=joint["upperLimit"],
|
|
515
|
-
limit_ke=joint_limit_ke,
|
|
516
|
-
limit_kd=joint_limit_kd,
|
|
517
|
-
)
|
|
518
|
-
)
|
|
519
|
-
elif joint["type"] == "":
|
|
520
|
-
joint_params["joint_type"] = wp.sim.JOINT_D6
|
|
521
|
-
else:
|
|
522
|
-
print(f"Warning: unsupported joint type {joint['type']} for {path}")
|
|
523
|
-
|
|
524
|
-
builder.add_joint(**joint_params)
|
|
525
|
-
|
|
526
|
-
elif is_rigid_body:
|
|
527
|
-
builder.add_joint_free(child=body_id)
|
|
528
|
-
# free joint; we set joint_q/qd, not body_q/qd since eval_fk is used after model creation
|
|
529
|
-
builder.joint_q[-4:] = xform.q
|
|
530
|
-
builder.joint_q[-7:-4] = xform.p
|
|
531
|
-
linear_vel = parse_vec(prim, "physics:velocity", np.zeros(3, dtype=np.float32)) * linear_unit
|
|
532
|
-
angular_vel = parse_vec(prim, "physics:angularVelocity", np.zeros(3, dtype=np.float32)) * linear_unit
|
|
533
|
-
builder.joint_qd[-6:-3] = angular_vel
|
|
534
|
-
builder.joint_qd[-3:] = linear_vel
|
|
535
|
-
|
|
536
|
-
if verbose:
|
|
537
|
-
print(f"added {type_name} body {body_id} ({path}) at {xform}")
|
|
538
|
-
|
|
539
|
-
density = None
|
|
540
|
-
|
|
541
|
-
material = None
|
|
542
|
-
if prim.HasRelationship("material:binding:physics"):
|
|
543
|
-
other_paths = prim.GetRelationship("material:binding:physics").GetTargets()
|
|
544
|
-
if len(other_paths) > 0:
|
|
545
|
-
material = materials[str(other_paths[0])]
|
|
546
|
-
if material is not None:
|
|
547
|
-
if "density" in material:
|
|
548
|
-
density = material["density"]
|
|
549
|
-
if has_attribute(prim, "physics:density"):
|
|
550
|
-
d = parse_float(prim, "physics:density")
|
|
551
|
-
density = d * mass_unit # / (linear_unit**3)
|
|
552
|
-
|
|
553
|
-
# assert prim.GetAttribute('orientation').Get() == "rightHanded", "Only right-handed orientations are supported."
|
|
554
|
-
enabled = parse_generic(prim, "physics:rigidBodyEnabled", True)
|
|
555
|
-
if only_load_enabled_rigid_bodies and not enabled:
|
|
556
|
-
if verbose:
|
|
557
|
-
print("Skipping disabled rigid body", path)
|
|
558
|
-
return
|
|
559
|
-
mass = parse_float(prim, "physics:mass")
|
|
560
|
-
if is_rigid_body:
|
|
561
|
-
if density is None:
|
|
562
|
-
density = default_density
|
|
563
|
-
body_density[body_id] = density
|
|
564
|
-
elif density is None:
|
|
565
|
-
if body_id >= 0:
|
|
566
|
-
density = body_density[body_id]
|
|
567
|
-
else:
|
|
568
|
-
density = 0.0
|
|
569
|
-
|
|
570
|
-
com = parse_vec(prim, "physics:centerOfMass", np.zeros(3, dtype=np.float32))
|
|
571
|
-
i_diag = parse_vec(prim, "physics:diagonalInertia", np.zeros(3, dtype=np.float32))
|
|
572
|
-
i_rot = parse_quat(prim, "physics:principalAxes", wp.quat_identity())
|
|
573
|
-
|
|
574
|
-
# parse children
|
|
575
|
-
if type_name == "Xform":
|
|
576
|
-
if prim.IsInstance():
|
|
577
|
-
proto = prim.GetPrototype()
|
|
578
|
-
for child in proto.GetChildren():
|
|
579
|
-
parse_prim(child, xform, scale, parent_body)
|
|
580
|
-
else:
|
|
581
|
-
for child in children_refs:
|
|
582
|
-
parse_prim(child, xform, scale, parent_body)
|
|
583
|
-
elif type_name == "Scope":
|
|
584
|
-
for child in children_refs:
|
|
585
|
-
parse_prim(child, incoming_xform, incoming_scale, parent_body)
|
|
586
|
-
elif type_name in shape_types:
|
|
587
|
-
# parse shapes
|
|
588
|
-
shape_params = {
|
|
589
|
-
"ke": contact_ke,
|
|
590
|
-
"kd": contact_kd,
|
|
591
|
-
"kf": contact_kf,
|
|
592
|
-
"ka": contact_ka,
|
|
593
|
-
"mu": contact_mu,
|
|
594
|
-
"restitution": contact_restitution,
|
|
595
|
-
}
|
|
596
|
-
if material is not None:
|
|
597
|
-
if "restitution" in material:
|
|
598
|
-
shape_params["restitution"] = material["restitution"]
|
|
599
|
-
if "dynamicFriction" in material:
|
|
600
|
-
shape_params["mu"] = material["dynamicFriction"]
|
|
601
|
-
|
|
602
|
-
if has_attribute(prim, "doubleSided") and not prim.GetAttribute("doubleSided").Get():
|
|
603
|
-
print(f"Warning: treating {path} as double-sided because single-sided collisions are not supported.")
|
|
604
|
-
|
|
605
|
-
if type_name == "Cube":
|
|
606
|
-
size = parse_float(prim, "size", 2.0)
|
|
607
|
-
if has_attribute(prim, "extents"):
|
|
608
|
-
extents = parse_vec(prim, "extents") * scale
|
|
609
|
-
# TODO position geom at extents center?
|
|
610
|
-
# geo_pos = 0.5 * (extents[0] + extents[1])
|
|
611
|
-
extents = extents[1] - extents[0]
|
|
612
|
-
else:
|
|
613
|
-
extents = scale * size
|
|
614
|
-
shape_id = builder.add_shape_box(
|
|
615
|
-
body_id,
|
|
616
|
-
geo_tf.p,
|
|
617
|
-
geo_tf.q,
|
|
618
|
-
hx=extents[0] / 2,
|
|
619
|
-
hy=extents[1] / 2,
|
|
620
|
-
hz=extents[2] / 2,
|
|
621
|
-
density=density,
|
|
622
|
-
thickness=contact_thickness,
|
|
623
|
-
**shape_params,
|
|
624
|
-
)
|
|
625
|
-
elif type_name == "Sphere":
|
|
626
|
-
if not (scale[0] == scale[1] == scale[2]):
|
|
627
|
-
print("Warning: Non-uniform scaling of spheres is not supported.")
|
|
628
|
-
if has_attribute(prim, "extents"):
|
|
629
|
-
extents = parse_vec(prim, "extents") * scale
|
|
630
|
-
# TODO position geom at extents center?
|
|
631
|
-
# geo_pos = 0.5 * (extents[0] + extents[1])
|
|
632
|
-
extents = extents[1] - extents[0]
|
|
633
|
-
if not (extents[0] == extents[1] == extents[2]):
|
|
634
|
-
print("Warning: Non-uniform extents of spheres are not supported.")
|
|
635
|
-
radius = extents[0]
|
|
636
|
-
else:
|
|
637
|
-
radius = parse_float(prim, "radius", 1.0) * scale[0]
|
|
638
|
-
shape_id = builder.add_shape_sphere(
|
|
639
|
-
body_id, geo_tf.p, geo_tf.q, radius, density=density, **shape_params
|
|
640
|
-
)
|
|
641
|
-
elif type_name == "Plane":
|
|
642
|
-
normal_str = parse_generic(prim, "axis", "Z").upper()
|
|
643
|
-
geo_rot = geo_tf.q
|
|
644
|
-
if normal_str != "Y":
|
|
645
|
-
normal = str2axis(normal_str)
|
|
646
|
-
c = np.cross(normal, (0.0, 1.0, 0.0))
|
|
647
|
-
angle = np.arcsin(np.linalg.norm(c))
|
|
648
|
-
axis = c / np.linalg.norm(c)
|
|
649
|
-
geo_rot = wp.mul(geo_rot, wp.quat_from_axis_angle(axis, angle))
|
|
650
|
-
width = parse_float(prim, "width", 0.0) * scale[0]
|
|
651
|
-
length = parse_float(prim, "length", 0.0) * scale[1]
|
|
652
|
-
shape_id = builder.add_shape_plane(
|
|
653
|
-
body=body_id,
|
|
654
|
-
pos=geo_tf.p,
|
|
655
|
-
rot=geo_rot,
|
|
656
|
-
width=width,
|
|
657
|
-
length=length,
|
|
658
|
-
thickness=contact_thickness,
|
|
659
|
-
**shape_params,
|
|
660
|
-
)
|
|
661
|
-
elif type_name == "Capsule":
|
|
662
|
-
axis_str = parse_generic(prim, "axis", "Z").upper()
|
|
663
|
-
radius = parse_float(prim, "radius", 0.5) * scale[0]
|
|
664
|
-
half_height = parse_float(prim, "height", 2.0) / 2 * scale[1]
|
|
665
|
-
assert not has_attribute(prim, "extents"), "Capsule extents are not supported."
|
|
666
|
-
shape_id = builder.add_shape_capsule(
|
|
667
|
-
body_id,
|
|
668
|
-
geo_tf.p,
|
|
669
|
-
geo_tf.q,
|
|
670
|
-
radius,
|
|
671
|
-
half_height,
|
|
672
|
-
density=density,
|
|
673
|
-
up_axis="XYZ".index(axis_str),
|
|
674
|
-
**shape_params,
|
|
675
|
-
)
|
|
676
|
-
elif type_name == "Cylinder":
|
|
677
|
-
axis_str = parse_generic(prim, "axis", "Z").upper()
|
|
678
|
-
radius = parse_float(prim, "radius", 0.5) * scale[0]
|
|
679
|
-
half_height = parse_float(prim, "height", 2.0) / 2 * scale[1]
|
|
680
|
-
assert not has_attribute(prim, "extents"), "Cylinder extents are not supported."
|
|
681
|
-
shape_id = builder.add_shape_cylinder(
|
|
682
|
-
body_id,
|
|
683
|
-
geo_tf.p,
|
|
684
|
-
geo_tf.q,
|
|
685
|
-
radius,
|
|
686
|
-
half_height,
|
|
687
|
-
density=density,
|
|
688
|
-
up_axis="XYZ".index(axis_str),
|
|
689
|
-
**shape_params,
|
|
690
|
-
)
|
|
691
|
-
elif type_name == "Cone":
|
|
692
|
-
axis_str = parse_generic(prim, "axis", "Z").upper()
|
|
693
|
-
radius = parse_float(prim, "radius", 0.5) * scale[0]
|
|
694
|
-
half_height = parse_float(prim, "height", 2.0) / 2 * scale[1]
|
|
695
|
-
assert not has_attribute(prim, "extents"), "Cone extents are not supported."
|
|
696
|
-
shape_id = builder.add_shape_cone(
|
|
697
|
-
body_id,
|
|
698
|
-
geo_tf.p,
|
|
699
|
-
geo_tf.q,
|
|
700
|
-
radius,
|
|
701
|
-
half_height,
|
|
702
|
-
density=density,
|
|
703
|
-
up_axis="XYZ".index(axis_str),
|
|
704
|
-
**shape_params,
|
|
705
|
-
)
|
|
706
|
-
elif type_name == "Mesh":
|
|
707
|
-
mesh = UsdGeom.Mesh(prim)
|
|
708
|
-
points = np.array(mesh.GetPointsAttr().Get(), dtype=np.float32)
|
|
709
|
-
indices = np.array(mesh.GetFaceVertexIndicesAttr().Get(), dtype=np.float32)
|
|
710
|
-
counts = mesh.GetFaceVertexCountsAttr().Get()
|
|
711
|
-
faces = []
|
|
712
|
-
face_id = 0
|
|
713
|
-
for count in counts:
|
|
714
|
-
if count == 3:
|
|
715
|
-
faces.append(indices[face_id : face_id + 3])
|
|
716
|
-
elif count == 4:
|
|
717
|
-
faces.append(indices[face_id : face_id + 3])
|
|
718
|
-
faces.append(indices[[face_id, face_id + 2, face_id + 3]])
|
|
719
|
-
else:
|
|
720
|
-
# assert False, f"Error while parsing USD mesh {path}: encountered polygon with {count} vertices, but only triangles and quads are supported."
|
|
721
|
-
continue
|
|
722
|
-
face_id += count
|
|
723
|
-
m = wp.sim.Mesh(points, np.array(faces, dtype=np.int32).flatten())
|
|
724
|
-
shape_id = builder.add_shape_mesh(
|
|
725
|
-
body_id,
|
|
726
|
-
geo_tf.p,
|
|
727
|
-
geo_tf.q,
|
|
728
|
-
scale=scale,
|
|
729
|
-
mesh=m,
|
|
730
|
-
density=density,
|
|
731
|
-
thickness=contact_thickness,
|
|
732
|
-
**shape_params,
|
|
733
|
-
)
|
|
734
|
-
else:
|
|
735
|
-
print(f"Warning: Unsupported geometry type {type_name} at {path}.")
|
|
736
|
-
return
|
|
737
|
-
|
|
738
|
-
path_body_map[path] = body_id
|
|
739
|
-
path_shape_map[path] = shape_id
|
|
740
|
-
path_shape_scale[path] = scale
|
|
741
|
-
|
|
742
|
-
if prim.HasRelationship("physics:filteredPairs"):
|
|
743
|
-
other_paths = prim.GetRelationship("physics:filteredPairs").GetTargets()
|
|
744
|
-
for other_path in other_paths:
|
|
745
|
-
path_collision_filters.add((path, str(other_path)))
|
|
746
|
-
|
|
747
|
-
if "PhysicsCollisionAPI" not in schemas or not parse_generic(prim, "physics:collisionEnabled", True):
|
|
748
|
-
no_collision_shapes.add(shape_id)
|
|
749
|
-
|
|
750
|
-
else:
|
|
751
|
-
print(f"Warning: encountered unsupported prim type {type_name}")
|
|
752
|
-
|
|
753
|
-
# update mass properties of rigid bodies in cases where properties are defined with higher precedence
|
|
754
|
-
if body_id >= 0:
|
|
755
|
-
com = parse_vec(prim, "physics:centerOfMass")
|
|
756
|
-
if com is not None:
|
|
757
|
-
# overwrite COM
|
|
758
|
-
builder.body_com[body_id] = com * scale
|
|
759
|
-
|
|
760
|
-
if mass is not None and not (is_rigid_body and mass == 0.0):
|
|
761
|
-
mass_ratio = mass / builder.body_mass[body_id]
|
|
762
|
-
# mass has precedence over density, so we overwrite the mass computed from density
|
|
763
|
-
builder.body_mass[body_id] = mass * mass_unit
|
|
764
|
-
if mass > 0.0:
|
|
765
|
-
builder.body_inv_mass[body_id] = 1.0 / builder.body_mass[body_id]
|
|
766
|
-
else:
|
|
767
|
-
builder.body_inv_mass[body_id] = 0.0
|
|
768
|
-
# update inertia
|
|
769
|
-
builder.body_inertia[body_id] *= mass_ratio
|
|
770
|
-
if np.array(builder.body_inertia[body_id]).any():
|
|
771
|
-
builder.body_inv_inertia[body_id] = wp.inverse(builder.body_inertia[body_id])
|
|
772
|
-
else:
|
|
773
|
-
builder.body_inv_inertia[body_id] = wp.mat33(*np.zeros((3, 3), dtype=np.float32))
|
|
774
|
-
|
|
775
|
-
if np.linalg.norm(i_diag) > 0.0:
|
|
776
|
-
rot = np.array(wp.quat_to_matrix(i_rot), dtype=np.float32).reshape(3, 3)
|
|
777
|
-
inertia = rot @ np.diag(i_diag) @ rot.T
|
|
778
|
-
builder.body_inertia[body_id] = inertia
|
|
779
|
-
if inertia.any():
|
|
780
|
-
builder.body_inv_inertia[body_id] = wp.inverse(wp.mat33(*inertia))
|
|
781
|
-
else:
|
|
782
|
-
builder.body_inv_inertia[body_id] = wp.mat33(*np.zeros((3, 3), dtype=np.float32))
|
|
783
|
-
|
|
784
|
-
parse_prim(
|
|
785
|
-
stage.GetDefaultPrim(), incoming_xform=wp.transform(), incoming_scale=np.ones(3, dtype=np.float32) * linear_unit
|
|
786
|
-
)
|
|
787
|
-
|
|
788
|
-
shape_count = len(builder.shape_geo_type)
|
|
789
|
-
|
|
790
|
-
# apply collision filters now that we have added all shapes
|
|
791
|
-
for path1, path2 in path_collision_filters:
|
|
792
|
-
shape1 = path_shape_map[path1]
|
|
793
|
-
shape2 = path_shape_map[path2]
|
|
794
|
-
builder.shape_collision_filter_pairs.add((shape1, shape2))
|
|
795
|
-
|
|
796
|
-
# apply collision filters to all shapes that have no collision
|
|
797
|
-
for shape_id in no_collision_shapes:
|
|
798
|
-
for other_shape_id in range(shape_count):
|
|
799
|
-
if other_shape_id != shape_id:
|
|
800
|
-
builder.shape_collision_filter_pairs.add((shape_id, other_shape_id))
|
|
801
|
-
|
|
802
|
-
# return stage parameters
|
|
803
|
-
return {
|
|
804
|
-
"fps": stage.GetFramesPerSecond(),
|
|
805
|
-
"duration": stage.GetEndTimeCode() - stage.GetStartTimeCode(),
|
|
806
|
-
"up_axis": UsdGeom.GetStageUpAxis(stage).upper(),
|
|
807
|
-
"path_shape_map": path_shape_map,
|
|
808
|
-
"path_body_map": path_body_map,
|
|
809
|
-
"path_shape_scale": path_shape_scale,
|
|
810
|
-
"mass_unit": mass_unit,
|
|
811
|
-
"linear_unit": linear_unit,
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
def resolve_usd_from_url(url: str, target_folder_name: str | None = None, export_usda: bool = False) -> str:
|
|
816
|
-
"""Download a USD file from a URL and resolves all references to other USD files to be downloaded to the given target folder.
|
|
817
|
-
|
|
818
|
-
Args:
|
|
819
|
-
url: URL to the USD file.
|
|
820
|
-
target_folder_name: Target folder name. If ``None``, a time-stamped
|
|
821
|
-
folder will be created in the current directory.
|
|
822
|
-
export_usda: If ``True``, converts each downloaded USD file to USDA and
|
|
823
|
-
saves the additional USDA file in the target folder with the same
|
|
824
|
-
base name as the original USD file.
|
|
825
|
-
|
|
826
|
-
Returns:
|
|
827
|
-
File path to the downloaded USD file.
|
|
828
|
-
"""
|
|
829
|
-
import datetime
|
|
830
|
-
import os
|
|
831
|
-
|
|
832
|
-
import requests
|
|
833
|
-
|
|
834
|
-
try:
|
|
835
|
-
from pxr import Usd
|
|
836
|
-
except ImportError as e:
|
|
837
|
-
raise ImportError("Failed to import pxr. Please install USD (e.g. via `pip install usd-core`).") from e
|
|
838
|
-
|
|
839
|
-
response = requests.get(url, allow_redirects=True)
|
|
840
|
-
if response.status_code != 200:
|
|
841
|
-
raise RuntimeError(f"Failed to download USD file. Status code: {response.status_code}")
|
|
842
|
-
file = response.content
|
|
843
|
-
dot = os.path.extsep
|
|
844
|
-
base = os.path.basename(url)
|
|
845
|
-
url_folder = os.path.dirname(url)
|
|
846
|
-
base_name = dot.join(base.split(dot)[:-1])
|
|
847
|
-
if target_folder_name is None:
|
|
848
|
-
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
|
849
|
-
target_folder_name = os.path.join(".usd_cache", f"{base_name}_{timestamp}")
|
|
850
|
-
os.makedirs(target_folder_name, exist_ok=True)
|
|
851
|
-
target_filename = os.path.join(target_folder_name, base)
|
|
852
|
-
with open(target_filename, "wb") as f:
|
|
853
|
-
f.write(file)
|
|
854
|
-
|
|
855
|
-
stage = Usd.Stage.Open(target_filename, Usd.Stage.LoadNone)
|
|
856
|
-
stage_str = stage.GetRootLayer().ExportToString()
|
|
857
|
-
print(f"Downloaded USD file to {target_filename}.")
|
|
858
|
-
if export_usda:
|
|
859
|
-
usda_filename = os.path.join(target_folder_name, base_name + ".usda")
|
|
860
|
-
with open(usda_filename, "w") as f:
|
|
861
|
-
f.write(stage_str)
|
|
862
|
-
print(f"Exported USDA file to {usda_filename}.")
|
|
863
|
-
|
|
864
|
-
# parse referenced USD files like `references = @./franka_collisions.usd@`
|
|
865
|
-
downloaded = set()
|
|
866
|
-
for match in re.finditer(r"references.=.@(.*?)@", stage_str):
|
|
867
|
-
refname = match.group(1)
|
|
868
|
-
if refname.startswith("./"):
|
|
869
|
-
refname = refname[2:]
|
|
870
|
-
if refname in downloaded:
|
|
871
|
-
continue
|
|
872
|
-
try:
|
|
873
|
-
response = requests.get(f"{url_folder}/{refname}", allow_redirects=True)
|
|
874
|
-
if response.status_code != 200:
|
|
875
|
-
print(f"Failed to download reference {refname}. Status code: {response.status_code}")
|
|
876
|
-
continue
|
|
877
|
-
file = response.content
|
|
878
|
-
refdir = os.path.dirname(refname)
|
|
879
|
-
if refdir:
|
|
880
|
-
os.makedirs(os.path.join(target_folder_name, refdir), exist_ok=True)
|
|
881
|
-
ref_filename = os.path.join(target_folder_name, refname)
|
|
882
|
-
if not os.path.exists(ref_filename):
|
|
883
|
-
with open(ref_filename, "wb") as f:
|
|
884
|
-
f.write(file)
|
|
885
|
-
downloaded.add(refname)
|
|
886
|
-
print(f"Downloaded USD reference {refname} to {ref_filename}.")
|
|
887
|
-
if export_usda:
|
|
888
|
-
ref_stage = Usd.Stage.Open(ref_filename, Usd.Stage.LoadNone)
|
|
889
|
-
ref_stage_str = ref_stage.GetRootLayer().ExportToString()
|
|
890
|
-
base = os.path.basename(ref_filename)
|
|
891
|
-
base_name = dot.join(base.split(dot)[:-1])
|
|
892
|
-
usda_filename = os.path.join(target_folder_name, base_name + ".usda")
|
|
893
|
-
with open(usda_filename, "w") as f:
|
|
894
|
-
f.write(ref_stage_str)
|
|
895
|
-
print(f"Exported USDA file to {usda_filename}.")
|
|
896
|
-
except Exception:
|
|
897
|
-
print(f"Failed to download {refname}.")
|
|
898
|
-
return target_filename
|