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_mjcf.py
DELETED
|
@@ -1,791 +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 math
|
|
19
|
-
import os
|
|
20
|
-
import re
|
|
21
|
-
import xml.etree.ElementTree as ET
|
|
22
|
-
|
|
23
|
-
import numpy as np
|
|
24
|
-
|
|
25
|
-
import warp as wp
|
|
26
|
-
from warp.sim.model import Mesh
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def parse_mjcf(
|
|
30
|
-
mjcf_filename,
|
|
31
|
-
builder,
|
|
32
|
-
xform=None,
|
|
33
|
-
floating=False,
|
|
34
|
-
base_joint: dict | str | None = None,
|
|
35
|
-
density=1000.0,
|
|
36
|
-
stiffness=100.0,
|
|
37
|
-
damping=10.0,
|
|
38
|
-
armature=0.0,
|
|
39
|
-
armature_scale=1.0,
|
|
40
|
-
contact_ke=1.0e4,
|
|
41
|
-
contact_kd=1.0e3,
|
|
42
|
-
contact_kf=1.0e2,
|
|
43
|
-
contact_ka=0.0,
|
|
44
|
-
contact_mu=0.25,
|
|
45
|
-
contact_restitution=0.5,
|
|
46
|
-
contact_thickness=0.0,
|
|
47
|
-
limit_ke=100.0,
|
|
48
|
-
limit_kd=10.0,
|
|
49
|
-
joint_limit_lower=-1e6,
|
|
50
|
-
joint_limit_upper=1e6,
|
|
51
|
-
scale=1.0,
|
|
52
|
-
hide_visuals=False,
|
|
53
|
-
parse_visuals_as_colliders=False,
|
|
54
|
-
parse_meshes=True,
|
|
55
|
-
up_axis="Z",
|
|
56
|
-
ignore_names=(),
|
|
57
|
-
ignore_classes=None,
|
|
58
|
-
visual_classes=("visual",),
|
|
59
|
-
collider_classes=("collision",),
|
|
60
|
-
no_class_as_colliders=True,
|
|
61
|
-
force_show_colliders=False,
|
|
62
|
-
enable_self_collisions=False,
|
|
63
|
-
ignore_inertial_definitions=True,
|
|
64
|
-
ensure_nonstatic_links=True,
|
|
65
|
-
static_link_mass=1e-2,
|
|
66
|
-
collapse_fixed_joints=False,
|
|
67
|
-
verbose=False,
|
|
68
|
-
):
|
|
69
|
-
"""
|
|
70
|
-
Parses MuJoCo XML (MJCF) file and adds the bodies and joints to the given ModelBuilder.
|
|
71
|
-
|
|
72
|
-
Args:
|
|
73
|
-
mjcf_filename (str): The filename of the MuJoCo file to parse.
|
|
74
|
-
builder (ModelBuilder): The :class:`ModelBuilder` to add the bodies and joints to.
|
|
75
|
-
xform (:ref:`transform <transform>`): The transform to apply to the imported mechanism.
|
|
76
|
-
floating (bool): If True, the root body is a free joint. If False, the root body is connected via a fixed joint to the world, unless a `base_joint` is defined.
|
|
77
|
-
base_joint (Union[str, dict]): The joint by which the root body is connected to the world. This can be either a string defining the joint axes of a D6 joint with comma-separated positional and angular axis names (e.g. "px,py,rz" for a D6 joint with linear axes in x, y and an angular axis in z) or a dict with joint parameters (see :meth:`ModelBuilder.add_joint`).
|
|
78
|
-
density (float): The density of the shapes in kg/m^3 which will be used to calculate the body mass and inertia.
|
|
79
|
-
stiffness (float): The stiffness of the joints.
|
|
80
|
-
damping (float): The damping of the joints.
|
|
81
|
-
armature (float): Default joint armature to use if `armature` has not been defined for a joint in the MJCF.
|
|
82
|
-
armature_scale (float): Scaling factor to apply to the MJCF-defined joint armature values.
|
|
83
|
-
contact_ke (float): The stiffness of the shape contacts.
|
|
84
|
-
contact_kd (float): The damping of the shape contacts.
|
|
85
|
-
contact_kf (float): The friction stiffness of the shape contacts.
|
|
86
|
-
contact_ka (float): The adhesion distance of the shape contacts.
|
|
87
|
-
contact_mu (float): The friction coefficient of the shape contacts.
|
|
88
|
-
contact_restitution (float): The restitution coefficient of the shape contacts.
|
|
89
|
-
contact_thickness (float): The thickness to add to the shape geometry.
|
|
90
|
-
limit_ke (float): The stiffness of the joint limits.
|
|
91
|
-
limit_kd (float): The damping of the joint limits.
|
|
92
|
-
joint_limit_lower (float): The default lower joint limit if not specified in the MJCF.
|
|
93
|
-
joint_limit_upper (float): The default upper joint limit if not specified in the MJCF.
|
|
94
|
-
scale (float): The scaling factor to apply to the imported mechanism.
|
|
95
|
-
hide_visuals (bool): If True, hide visual shapes.
|
|
96
|
-
parse_visuals_as_colliders (bool): If True, the geometry defined under the `visual_classes` tags is used for collision handling instead of the `collider_classes` geometries.
|
|
97
|
-
parse_meshes (bool): Whether geometries of type `"mesh"` should be parsed. If False, geometries of type `"mesh"` are ignored.
|
|
98
|
-
up_axis (str): The up axis of the mechanism. Can be either `"X"`, `"Y"` or `"Z"`. The default is `"Z"`.
|
|
99
|
-
ignore_names (List[str]): A list of regular expressions. Bodies and joints with a name matching one of the regular expressions will be ignored.
|
|
100
|
-
ignore_classes (List[str]): A list of regular expressions. Bodies and joints with a class matching one of the regular expressions will be ignored.
|
|
101
|
-
visual_classes (List[str]): A list of regular expressions. Visual geometries with a class matching one of the regular expressions will be parsed.
|
|
102
|
-
collider_classes (List[str]): A list of regular expressions. Collision geometries with a class matching one of the regular expressions will be parsed.
|
|
103
|
-
no_class_as_colliders: If True, geometries without a class are parsed as collision geometries. If False, geometries without a class are parsed as visual geometries.
|
|
104
|
-
force_show_colliders (bool): If True, the collision shapes are always shown, even if there are visual shapes.
|
|
105
|
-
enable_self_collisions (bool): If True, self-collisions are enabled.
|
|
106
|
-
ignore_inertial_definitions (bool): If True, the inertial parameters defined in the MJCF are ignored and the inertia is calculated from the shape geometry.
|
|
107
|
-
ensure_nonstatic_links (bool): If True, links with zero mass are given a small mass (see `static_link_mass`) to ensure they are dynamic.
|
|
108
|
-
static_link_mass (float): The mass to assign to links with zero mass (if `ensure_nonstatic_links` is set to True).
|
|
109
|
-
collapse_fixed_joints (bool): If True, fixed joints are removed and the respective bodies are merged.
|
|
110
|
-
verbose (bool): If True, print additional information about parsing the MJCF.
|
|
111
|
-
"""
|
|
112
|
-
if xform is None:
|
|
113
|
-
xform = wp.transform()
|
|
114
|
-
|
|
115
|
-
if ignore_classes is None:
|
|
116
|
-
ignore_classes = []
|
|
117
|
-
|
|
118
|
-
mjcf_dirname = os.path.dirname(mjcf_filename)
|
|
119
|
-
file = ET.parse(mjcf_filename)
|
|
120
|
-
root = file.getroot()
|
|
121
|
-
|
|
122
|
-
contact_vars = {
|
|
123
|
-
"ke": contact_ke,
|
|
124
|
-
"kd": contact_kd,
|
|
125
|
-
"kf": contact_kf,
|
|
126
|
-
"ka": contact_ka,
|
|
127
|
-
"mu": contact_mu,
|
|
128
|
-
"restitution": contact_restitution,
|
|
129
|
-
"thickness": contact_thickness,
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
use_degrees = True # angles are in degrees by default
|
|
133
|
-
euler_seq = [0, 1, 2] # XYZ by default
|
|
134
|
-
|
|
135
|
-
compiler = root.find("compiler")
|
|
136
|
-
if compiler is not None:
|
|
137
|
-
use_degrees = compiler.attrib.get("angle", "degree").lower() == "degree"
|
|
138
|
-
euler_seq = ["xyz".index(c) for c in compiler.attrib.get("eulerseq", "xyz").lower()]
|
|
139
|
-
mesh_dir = compiler.attrib.get("meshdir", ".")
|
|
140
|
-
else:
|
|
141
|
-
mesh_dir = "."
|
|
142
|
-
|
|
143
|
-
mesh_assets = {}
|
|
144
|
-
for asset in root.findall("asset"):
|
|
145
|
-
for mesh in asset.findall("mesh"):
|
|
146
|
-
if "file" in mesh.attrib:
|
|
147
|
-
fname = os.path.join(mesh_dir, mesh.attrib["file"])
|
|
148
|
-
# handle stl relative paths
|
|
149
|
-
if not os.path.isabs(fname):
|
|
150
|
-
fname = os.path.abspath(os.path.join(mjcf_dirname, fname))
|
|
151
|
-
name = mesh.attrib.get("name", ".".join(os.path.basename(fname).split(".")[:-1]))
|
|
152
|
-
s = mesh.attrib.get("scale", "1.0 1.0 1.0")
|
|
153
|
-
s = np.fromstring(s, sep=" ", dtype=np.float32)
|
|
154
|
-
mesh_assets[name] = {"file": fname, "scale": s}
|
|
155
|
-
|
|
156
|
-
class_parent = {}
|
|
157
|
-
class_children = {}
|
|
158
|
-
class_defaults = {"__all__": {}}
|
|
159
|
-
|
|
160
|
-
def get_class(element):
|
|
161
|
-
return element.get("class", "__all__")
|
|
162
|
-
|
|
163
|
-
def parse_default(node, parent):
|
|
164
|
-
nonlocal class_parent
|
|
165
|
-
nonlocal class_children
|
|
166
|
-
nonlocal class_defaults
|
|
167
|
-
class_name = "__all__"
|
|
168
|
-
if "class" in node.attrib:
|
|
169
|
-
class_name = node.attrib["class"]
|
|
170
|
-
class_parent[class_name] = parent
|
|
171
|
-
parent = parent or "__all__"
|
|
172
|
-
if parent not in class_children:
|
|
173
|
-
class_children[parent] = []
|
|
174
|
-
class_children[parent].append(class_name)
|
|
175
|
-
|
|
176
|
-
if class_name not in class_defaults:
|
|
177
|
-
class_defaults[class_name] = {}
|
|
178
|
-
for child in node:
|
|
179
|
-
if child.tag == "default":
|
|
180
|
-
parse_default(child, node.get("class"))
|
|
181
|
-
else:
|
|
182
|
-
class_defaults[class_name][child.tag] = child.attrib
|
|
183
|
-
|
|
184
|
-
for default in root.findall("default"):
|
|
185
|
-
parse_default(default, None)
|
|
186
|
-
|
|
187
|
-
def merge_attrib(default_attrib: dict, incoming_attrib: dict):
|
|
188
|
-
attrib = default_attrib.copy()
|
|
189
|
-
attrib.update(incoming_attrib)
|
|
190
|
-
return attrib
|
|
191
|
-
|
|
192
|
-
if isinstance(up_axis, str):
|
|
193
|
-
up_axis = "XYZ".index(up_axis.upper())
|
|
194
|
-
sqh = np.sqrt(0.5)
|
|
195
|
-
if up_axis == 0:
|
|
196
|
-
xform = wp.transform(xform.p, wp.quat(0.0, 0.0, -sqh, sqh) * xform.q)
|
|
197
|
-
elif up_axis == 2:
|
|
198
|
-
xform = wp.transform(xform.p, wp.quat(sqh, 0.0, 0.0, -sqh) * xform.q)
|
|
199
|
-
# do not apply scaling to the root transform
|
|
200
|
-
xform = wp.transform(np.array(xform.p) / scale, xform.q)
|
|
201
|
-
|
|
202
|
-
def parse_float(attrib, key, default):
|
|
203
|
-
if key in attrib:
|
|
204
|
-
return float(attrib[key])
|
|
205
|
-
else:
|
|
206
|
-
return default
|
|
207
|
-
|
|
208
|
-
def parse_vec(attrib, key, default):
|
|
209
|
-
if key in attrib:
|
|
210
|
-
out = np.fromstring(attrib[key], sep=" ", dtype=np.float32)
|
|
211
|
-
else:
|
|
212
|
-
out = np.array(default, dtype=np.float32)
|
|
213
|
-
|
|
214
|
-
length = len(out)
|
|
215
|
-
if length == 1:
|
|
216
|
-
return wp.vec(len(default), wp.float32)(out[0], out[0], out[0])
|
|
217
|
-
|
|
218
|
-
return wp.vec(length, wp.float32)(out)
|
|
219
|
-
|
|
220
|
-
def parse_orientation(attrib):
|
|
221
|
-
if "quat" in attrib:
|
|
222
|
-
wxyz = np.fromstring(attrib["quat"], sep=" ")
|
|
223
|
-
return wp.normalize(wp.quat(*wxyz[1:], wxyz[0]))
|
|
224
|
-
if "euler" in attrib:
|
|
225
|
-
euler = np.fromstring(attrib["euler"], sep=" ")
|
|
226
|
-
if use_degrees:
|
|
227
|
-
euler *= np.pi / 180
|
|
228
|
-
return wp.sim.quat_from_euler(wp.vec3(euler), *euler_seq)
|
|
229
|
-
if "axisangle" in attrib:
|
|
230
|
-
axisangle = np.fromstring(attrib["axisangle"], sep=" ")
|
|
231
|
-
angle = axisangle[3]
|
|
232
|
-
if use_degrees:
|
|
233
|
-
angle *= np.pi / 180
|
|
234
|
-
axis = wp.normalize(wp.vec3(*axisangle[:3]))
|
|
235
|
-
return wp.quat_from_axis_angle(axis, float(angle))
|
|
236
|
-
if "xyaxes" in attrib:
|
|
237
|
-
xyaxes = np.fromstring(attrib["xyaxes"], sep=" ")
|
|
238
|
-
xaxis = wp.normalize(wp.vec3(*xyaxes[:3]))
|
|
239
|
-
zaxis = wp.normalize(wp.vec3(*xyaxes[3:]))
|
|
240
|
-
yaxis = wp.normalize(wp.cross(zaxis, xaxis))
|
|
241
|
-
rot_matrix = np.array([xaxis, yaxis, zaxis]).T
|
|
242
|
-
return wp.quat_from_matrix(rot_matrix)
|
|
243
|
-
if "zaxis" in attrib:
|
|
244
|
-
zaxis = np.fromstring(attrib["zaxis"], sep=" ")
|
|
245
|
-
zaxis = wp.normalize(wp.vec3(*zaxis))
|
|
246
|
-
xaxis = wp.normalize(wp.cross(wp.vec3(0, 0, 1), zaxis))
|
|
247
|
-
yaxis = wp.normalize(wp.cross(zaxis, xaxis))
|
|
248
|
-
rot_matrix = np.array([xaxis, yaxis, zaxis]).T
|
|
249
|
-
return wp.quat_from_matrix(rot_matrix)
|
|
250
|
-
return wp.quat_identity()
|
|
251
|
-
|
|
252
|
-
def parse_shapes(defaults, body_name, link, geoms, density, visible=True, just_visual=False, incoming_xform=None):
|
|
253
|
-
shapes = []
|
|
254
|
-
for geo_count, geom in enumerate(geoms):
|
|
255
|
-
geom_defaults = defaults
|
|
256
|
-
if "class" in geom.attrib:
|
|
257
|
-
geom_class = geom.attrib["class"]
|
|
258
|
-
ignore_geom = False
|
|
259
|
-
for pattern in ignore_classes:
|
|
260
|
-
if re.match(pattern, geom_class):
|
|
261
|
-
ignore_geom = True
|
|
262
|
-
break
|
|
263
|
-
if ignore_geom:
|
|
264
|
-
continue
|
|
265
|
-
if geom_class in class_defaults:
|
|
266
|
-
geom_defaults = merge_attrib(defaults, class_defaults[geom_class])
|
|
267
|
-
if "geom" in geom_defaults:
|
|
268
|
-
geom_attrib = merge_attrib(geom_defaults["geom"], geom.attrib)
|
|
269
|
-
else:
|
|
270
|
-
geom_attrib = geom.attrib
|
|
271
|
-
|
|
272
|
-
geom_name = geom_attrib.get("name", f"{body_name}_geom_{geo_count}{'_visual' if just_visual else ''}")
|
|
273
|
-
geom_type = geom_attrib.get("type", "sphere")
|
|
274
|
-
if "mesh" in geom_attrib:
|
|
275
|
-
geom_type = "mesh"
|
|
276
|
-
|
|
277
|
-
ignore_geom = False
|
|
278
|
-
for pattern in ignore_names:
|
|
279
|
-
if re.match(pattern, geom_name):
|
|
280
|
-
ignore_geom = True
|
|
281
|
-
break
|
|
282
|
-
if ignore_geom:
|
|
283
|
-
continue
|
|
284
|
-
|
|
285
|
-
geom_size = parse_vec(geom_attrib, "size", [1.0, 1.0, 1.0]) * scale
|
|
286
|
-
geom_pos = parse_vec(geom_attrib, "pos", (0.0, 0.0, 0.0)) * scale
|
|
287
|
-
geom_rot = parse_orientation(geom_attrib)
|
|
288
|
-
geom_density = parse_float(geom_attrib, "density", density)
|
|
289
|
-
|
|
290
|
-
if incoming_xform is not None:
|
|
291
|
-
geom_pos = wp.transform_point(incoming_xform, geom_pos)
|
|
292
|
-
geom_rot = incoming_xform.q * geom_rot
|
|
293
|
-
|
|
294
|
-
if geom_type == "sphere":
|
|
295
|
-
s = builder.add_shape_sphere(
|
|
296
|
-
link,
|
|
297
|
-
pos=geom_pos,
|
|
298
|
-
rot=geom_rot,
|
|
299
|
-
radius=geom_size[0],
|
|
300
|
-
density=geom_density,
|
|
301
|
-
is_visible=visible,
|
|
302
|
-
has_ground_collision=not just_visual,
|
|
303
|
-
has_shape_collision=not just_visual,
|
|
304
|
-
**contact_vars,
|
|
305
|
-
)
|
|
306
|
-
shapes.append(s)
|
|
307
|
-
|
|
308
|
-
elif geom_type == "box":
|
|
309
|
-
s = builder.add_shape_box(
|
|
310
|
-
link,
|
|
311
|
-
pos=geom_pos,
|
|
312
|
-
rot=geom_rot,
|
|
313
|
-
hx=geom_size[0],
|
|
314
|
-
hy=geom_size[1],
|
|
315
|
-
hz=geom_size[2],
|
|
316
|
-
density=geom_density,
|
|
317
|
-
is_visible=visible,
|
|
318
|
-
has_ground_collision=not just_visual,
|
|
319
|
-
has_shape_collision=not just_visual,
|
|
320
|
-
**contact_vars,
|
|
321
|
-
)
|
|
322
|
-
shapes.append(s)
|
|
323
|
-
|
|
324
|
-
elif geom_type == "mesh" and parse_meshes:
|
|
325
|
-
import trimesh
|
|
326
|
-
|
|
327
|
-
# use force='mesh' to load the mesh as a trimesh object
|
|
328
|
-
# with baked in transforms, e.g. from COLLADA files
|
|
329
|
-
stl_file = mesh_assets[geom_attrib["mesh"]]["file"]
|
|
330
|
-
m = trimesh.load(stl_file, force="mesh")
|
|
331
|
-
if "mesh" in geom_defaults:
|
|
332
|
-
mesh_scale = parse_vec(geom_defaults["mesh"], "scale", mesh_assets[geom_attrib["mesh"]]["scale"])
|
|
333
|
-
else:
|
|
334
|
-
mesh_scale = mesh_assets[geom_attrib["mesh"]]["scale"]
|
|
335
|
-
scaling = np.array(mesh_scale) * scale
|
|
336
|
-
# as per the Mujoco XML reference, ignore geom size attribute
|
|
337
|
-
assert len(geom_size) == 3, "need to specify size for mesh geom"
|
|
338
|
-
|
|
339
|
-
if hasattr(m, "geometry"):
|
|
340
|
-
# multiple meshes are contained in a scene
|
|
341
|
-
for m_geom in m.geometry.values():
|
|
342
|
-
m_vertices = np.array(m_geom.vertices, dtype=np.float32) * scaling
|
|
343
|
-
m_faces = np.array(m_geom.faces.flatten(), dtype=np.int32)
|
|
344
|
-
m_mesh = Mesh(m_vertices, m_faces)
|
|
345
|
-
s = builder.add_shape_mesh(
|
|
346
|
-
body=link,
|
|
347
|
-
pos=geom_pos,
|
|
348
|
-
rot=geom_rot,
|
|
349
|
-
mesh=m_mesh,
|
|
350
|
-
density=density,
|
|
351
|
-
is_visible=visible,
|
|
352
|
-
has_ground_collision=not just_visual,
|
|
353
|
-
has_shape_collision=not just_visual,
|
|
354
|
-
**contact_vars,
|
|
355
|
-
)
|
|
356
|
-
shapes.append(s)
|
|
357
|
-
else:
|
|
358
|
-
# a single mesh
|
|
359
|
-
m_vertices = np.array(m.vertices, dtype=np.float32) * scaling
|
|
360
|
-
m_faces = np.array(m.faces.flatten(), dtype=np.int32)
|
|
361
|
-
m_mesh = Mesh(m_vertices, m_faces)
|
|
362
|
-
s = builder.add_shape_mesh(
|
|
363
|
-
body=link,
|
|
364
|
-
pos=geom_pos,
|
|
365
|
-
rot=geom_rot,
|
|
366
|
-
mesh=m_mesh,
|
|
367
|
-
density=density,
|
|
368
|
-
is_visible=visible,
|
|
369
|
-
has_ground_collision=not just_visual,
|
|
370
|
-
has_shape_collision=not just_visual,
|
|
371
|
-
**contact_vars,
|
|
372
|
-
)
|
|
373
|
-
shapes.append(s)
|
|
374
|
-
|
|
375
|
-
elif geom_type in {"capsule", "cylinder"}:
|
|
376
|
-
if "fromto" in geom_attrib:
|
|
377
|
-
geom_fromto = parse_vec(geom_attrib, "fromto", (0.0, 0.0, 0.0, 1.0, 0.0, 0.0))
|
|
378
|
-
|
|
379
|
-
start = wp.vec3(geom_fromto[0:3]) * scale
|
|
380
|
-
end = wp.vec3(geom_fromto[3:6]) * scale
|
|
381
|
-
|
|
382
|
-
# compute rotation to align the Warp capsule (along x-axis), with mjcf fromto direction
|
|
383
|
-
axis = wp.normalize(end - start)
|
|
384
|
-
angle = math.acos(wp.dot(axis, wp.vec3(0.0, 1.0, 0.0)))
|
|
385
|
-
axis = wp.normalize(wp.cross(axis, wp.vec3(0.0, 1.0, 0.0)))
|
|
386
|
-
|
|
387
|
-
geom_pos = (start + end) * 0.5
|
|
388
|
-
geom_rot = wp.quat_from_axis_angle(axis, -angle)
|
|
389
|
-
|
|
390
|
-
geom_radius = geom_size[0]
|
|
391
|
-
geom_height = wp.length(end - start) * 0.5
|
|
392
|
-
geom_up_axis = 1
|
|
393
|
-
|
|
394
|
-
else:
|
|
395
|
-
geom_radius = geom_size[0]
|
|
396
|
-
geom_height = geom_size[1]
|
|
397
|
-
geom_up_axis = up_axis
|
|
398
|
-
|
|
399
|
-
if geom_type == "cylinder":
|
|
400
|
-
s = builder.add_shape_cylinder(
|
|
401
|
-
link,
|
|
402
|
-
pos=geom_pos,
|
|
403
|
-
rot=geom_rot,
|
|
404
|
-
radius=geom_radius,
|
|
405
|
-
half_height=geom_height,
|
|
406
|
-
density=density,
|
|
407
|
-
up_axis=geom_up_axis,
|
|
408
|
-
is_visible=visible,
|
|
409
|
-
has_ground_collision=not just_visual,
|
|
410
|
-
has_shape_collision=not just_visual,
|
|
411
|
-
**contact_vars,
|
|
412
|
-
)
|
|
413
|
-
shapes.append(s)
|
|
414
|
-
else:
|
|
415
|
-
s = builder.add_shape_capsule(
|
|
416
|
-
link,
|
|
417
|
-
pos=geom_pos,
|
|
418
|
-
rot=geom_rot,
|
|
419
|
-
radius=geom_radius,
|
|
420
|
-
half_height=geom_height,
|
|
421
|
-
density=density,
|
|
422
|
-
up_axis=geom_up_axis,
|
|
423
|
-
is_visible=visible,
|
|
424
|
-
has_ground_collision=not just_visual,
|
|
425
|
-
has_shape_collision=not just_visual,
|
|
426
|
-
**contact_vars,
|
|
427
|
-
)
|
|
428
|
-
shapes.append(s)
|
|
429
|
-
|
|
430
|
-
elif geom_type == "plane":
|
|
431
|
-
normal = wp.quat_rotate(geom_rot, wp.vec3(0.0, 0.0, 1.0))
|
|
432
|
-
p = wp.dot(geom_pos, normal)
|
|
433
|
-
s = builder.add_shape_plane(
|
|
434
|
-
body=link,
|
|
435
|
-
plane=(*normal, p),
|
|
436
|
-
width=geom_size[0],
|
|
437
|
-
length=geom_size[1],
|
|
438
|
-
is_visible=visible,
|
|
439
|
-
has_ground_collision=False,
|
|
440
|
-
has_shape_collision=not just_visual,
|
|
441
|
-
**contact_vars,
|
|
442
|
-
)
|
|
443
|
-
shapes.append(s)
|
|
444
|
-
|
|
445
|
-
else:
|
|
446
|
-
if verbose:
|
|
447
|
-
print(f"MJCF parsing shape {geom_name} issue: geom type {geom_type} is unsupported")
|
|
448
|
-
|
|
449
|
-
return shapes
|
|
450
|
-
|
|
451
|
-
def parse_body(body, parent, incoming_defaults: dict, childclass: str | None = None):
|
|
452
|
-
body_class = body.get("class")
|
|
453
|
-
if body_class is None:
|
|
454
|
-
body_class = childclass
|
|
455
|
-
defaults = incoming_defaults
|
|
456
|
-
else:
|
|
457
|
-
for pattern in ignore_classes:
|
|
458
|
-
if re.match(pattern, body_class):
|
|
459
|
-
return
|
|
460
|
-
defaults = merge_attrib(incoming_defaults, class_defaults[body_class])
|
|
461
|
-
if "body" in defaults:
|
|
462
|
-
body_attrib = merge_attrib(defaults["body"], body.attrib)
|
|
463
|
-
else:
|
|
464
|
-
body_attrib = body.attrib
|
|
465
|
-
body_name = body_attrib["name"]
|
|
466
|
-
body_name = body_name.replace("-", "_") # ensure valid USD path
|
|
467
|
-
body_pos = parse_vec(body_attrib, "pos", (0.0, 0.0, 0.0))
|
|
468
|
-
body_ori = parse_orientation(body_attrib)
|
|
469
|
-
if parent == -1:
|
|
470
|
-
body_pos = wp.transform_point(xform, body_pos)
|
|
471
|
-
body_ori = xform.q * body_ori
|
|
472
|
-
body_pos *= scale
|
|
473
|
-
|
|
474
|
-
joint_armature = []
|
|
475
|
-
joint_name = []
|
|
476
|
-
joint_pos = []
|
|
477
|
-
|
|
478
|
-
linear_axes = []
|
|
479
|
-
angular_axes = []
|
|
480
|
-
joint_type = None
|
|
481
|
-
|
|
482
|
-
freejoint_tags = body.findall("freejoint")
|
|
483
|
-
if len(freejoint_tags) > 0:
|
|
484
|
-
joint_type = wp.sim.JOINT_FREE
|
|
485
|
-
joint_name.append(freejoint_tags[0].attrib.get("name", f"{body_name}_freejoint"))
|
|
486
|
-
joint_armature.append(0.0)
|
|
487
|
-
else:
|
|
488
|
-
joints = body.findall("joint")
|
|
489
|
-
for _i, joint in enumerate(joints):
|
|
490
|
-
joint_defaults = defaults
|
|
491
|
-
if "class" in joint.attrib:
|
|
492
|
-
joint_class = joint.attrib["class"]
|
|
493
|
-
if joint_class in class_defaults:
|
|
494
|
-
joint_defaults = merge_attrib(joint_defaults, class_defaults[joint_class])
|
|
495
|
-
if "joint" in joint_defaults:
|
|
496
|
-
joint_attrib = merge_attrib(joint_defaults["joint"], joint.attrib)
|
|
497
|
-
else:
|
|
498
|
-
joint_attrib = joint.attrib
|
|
499
|
-
|
|
500
|
-
# default to hinge if not specified
|
|
501
|
-
joint_type_str = joint_attrib.get("type", "hinge")
|
|
502
|
-
|
|
503
|
-
joint_name.append(joint_attrib["name"])
|
|
504
|
-
joint_pos.append(parse_vec(joint_attrib, "pos", (0.0, 0.0, 0.0)) * scale)
|
|
505
|
-
joint_range = parse_vec(joint_attrib, "range", (joint_limit_lower, joint_limit_upper))
|
|
506
|
-
joint_armature.append(parse_float(joint_attrib, "armature", armature) * armature_scale)
|
|
507
|
-
|
|
508
|
-
if joint_type_str == "free":
|
|
509
|
-
joint_type = wp.sim.JOINT_FREE
|
|
510
|
-
break
|
|
511
|
-
if joint_type_str == "fixed":
|
|
512
|
-
joint_type = wp.sim.JOINT_FIXED
|
|
513
|
-
break
|
|
514
|
-
is_angular = joint_type_str == "hinge"
|
|
515
|
-
mode = wp.sim.JOINT_MODE_FORCE
|
|
516
|
-
if stiffness > 0.0 or "stiffness" in joint_attrib:
|
|
517
|
-
mode = wp.sim.JOINT_MODE_TARGET_POSITION
|
|
518
|
-
axis_vec = parse_vec(joint_attrib, "axis", (0.0, 0.0, 0.0))
|
|
519
|
-
limit_lower = np.deg2rad(joint_range[0]) if is_angular and use_degrees else joint_range[0]
|
|
520
|
-
limit_upper = np.deg2rad(joint_range[1]) if is_angular and use_degrees else joint_range[1]
|
|
521
|
-
ax = wp.sim.JointAxis(
|
|
522
|
-
axis=axis_vec,
|
|
523
|
-
limit_lower=limit_lower,
|
|
524
|
-
limit_upper=limit_upper,
|
|
525
|
-
target_ke=parse_float(joint_attrib, "stiffness", stiffness),
|
|
526
|
-
target_kd=parse_float(joint_attrib, "damping", damping),
|
|
527
|
-
limit_ke=limit_ke,
|
|
528
|
-
limit_kd=limit_kd,
|
|
529
|
-
mode=mode,
|
|
530
|
-
)
|
|
531
|
-
if is_angular:
|
|
532
|
-
angular_axes.append(ax)
|
|
533
|
-
else:
|
|
534
|
-
linear_axes.append(ax)
|
|
535
|
-
|
|
536
|
-
link = builder.add_body(
|
|
537
|
-
origin=wp.transform(body_pos, body_ori), # will be evaluated in fk()
|
|
538
|
-
armature=joint_armature[0] if len(joint_armature) > 0 else armature,
|
|
539
|
-
name=body_name,
|
|
540
|
-
)
|
|
541
|
-
|
|
542
|
-
if joint_type is None:
|
|
543
|
-
if len(linear_axes) == 0:
|
|
544
|
-
if len(angular_axes) == 0:
|
|
545
|
-
joint_type = wp.sim.JOINT_FIXED
|
|
546
|
-
elif len(angular_axes) == 1:
|
|
547
|
-
joint_type = wp.sim.JOINT_REVOLUTE
|
|
548
|
-
elif len(angular_axes) == 2:
|
|
549
|
-
joint_type = wp.sim.JOINT_UNIVERSAL
|
|
550
|
-
elif len(angular_axes) == 3:
|
|
551
|
-
joint_type = wp.sim.JOINT_COMPOUND
|
|
552
|
-
elif len(linear_axes) == 1 and len(angular_axes) == 0:
|
|
553
|
-
joint_type = wp.sim.JOINT_PRISMATIC
|
|
554
|
-
else:
|
|
555
|
-
joint_type = wp.sim.JOINT_D6
|
|
556
|
-
|
|
557
|
-
if len(freejoint_tags) > 0 and parent == -1 and (base_joint is not None or floating is not None):
|
|
558
|
-
joint_pos = joint_pos[0] if len(joint_pos) > 0 else (0.0, 0.0, 0.0)
|
|
559
|
-
_xform = wp.transform(body_pos + joint_pos, body_ori)
|
|
560
|
-
|
|
561
|
-
if base_joint is not None:
|
|
562
|
-
# in case of a given base joint, the position is applied first, the rotation only
|
|
563
|
-
# after the base joint itself to not rotate its axis
|
|
564
|
-
base_parent_xform = wp.transform(_xform.p, wp.quat_identity())
|
|
565
|
-
base_child_xform = wp.transform((0.0, 0.0, 0.0), wp.quat_inverse(_xform.q))
|
|
566
|
-
if isinstance(base_joint, str):
|
|
567
|
-
axes = base_joint.lower().split(",")
|
|
568
|
-
axes = [ax.strip() for ax in axes]
|
|
569
|
-
linear_axes = [ax[-1] for ax in axes if ax[0] in {"l", "p"}]
|
|
570
|
-
angular_axes = [ax[-1] for ax in axes if ax[0] in {"a", "r"}]
|
|
571
|
-
axes = {
|
|
572
|
-
"x": [1.0, 0.0, 0.0],
|
|
573
|
-
"y": [0.0, 1.0, 0.0],
|
|
574
|
-
"z": [0.0, 0.0, 1.0],
|
|
575
|
-
}
|
|
576
|
-
builder.add_joint_d6(
|
|
577
|
-
linear_axes=[wp.sim.JointAxis(axes[a]) for a in linear_axes],
|
|
578
|
-
angular_axes=[wp.sim.JointAxis(axes[a]) for a in angular_axes],
|
|
579
|
-
parent_xform=base_parent_xform,
|
|
580
|
-
child_xform=base_child_xform,
|
|
581
|
-
parent=-1,
|
|
582
|
-
child=link,
|
|
583
|
-
name="base_joint",
|
|
584
|
-
)
|
|
585
|
-
elif isinstance(base_joint, dict):
|
|
586
|
-
base_joint["parent"] = -1
|
|
587
|
-
base_joint["child"] = root
|
|
588
|
-
base_joint["parent_xform"] = base_parent_xform
|
|
589
|
-
base_joint["child_xform"] = base_child_xform
|
|
590
|
-
base_joint["name"] = "base_joint"
|
|
591
|
-
builder.add_joint(**base_joint)
|
|
592
|
-
else:
|
|
593
|
-
raise ValueError(
|
|
594
|
-
"base_joint must be a comma-separated string of joint axes or a dict with joint parameters"
|
|
595
|
-
)
|
|
596
|
-
elif floating:
|
|
597
|
-
builder.add_joint_free(link, name="floating_base")
|
|
598
|
-
|
|
599
|
-
# set dofs to transform
|
|
600
|
-
start = builder.joint_q_start[link]
|
|
601
|
-
|
|
602
|
-
builder.joint_q[start + 0] = _xform.p[0]
|
|
603
|
-
builder.joint_q[start + 1] = _xform.p[1]
|
|
604
|
-
builder.joint_q[start + 2] = _xform.p[2]
|
|
605
|
-
|
|
606
|
-
builder.joint_q[start + 3] = _xform.q[0]
|
|
607
|
-
builder.joint_q[start + 4] = _xform.q[1]
|
|
608
|
-
builder.joint_q[start + 5] = _xform.q[2]
|
|
609
|
-
builder.joint_q[start + 6] = _xform.q[3]
|
|
610
|
-
else:
|
|
611
|
-
builder.add_joint_fixed(-1, link, parent_xform=_xform, name="fixed_base")
|
|
612
|
-
|
|
613
|
-
else:
|
|
614
|
-
joint_pos = joint_pos[0] if len(joint_pos) > 0 else (0.0, 0.0, 0.0)
|
|
615
|
-
if len(joint_name) == 0:
|
|
616
|
-
joint_name = [f"{body_name}_joint"]
|
|
617
|
-
builder.add_joint(
|
|
618
|
-
joint_type,
|
|
619
|
-
parent,
|
|
620
|
-
link,
|
|
621
|
-
linear_axes,
|
|
622
|
-
angular_axes,
|
|
623
|
-
name="_".join(joint_name),
|
|
624
|
-
parent_xform=wp.transform(body_pos + joint_pos, body_ori),
|
|
625
|
-
child_xform=wp.transform(joint_pos, wp.quat_identity()),
|
|
626
|
-
armature=joint_armature[0] if len(joint_armature) > 0 else armature,
|
|
627
|
-
)
|
|
628
|
-
|
|
629
|
-
# -----------------
|
|
630
|
-
# add shapes
|
|
631
|
-
|
|
632
|
-
geoms = body.findall("geom")
|
|
633
|
-
visuals = []
|
|
634
|
-
colliders = []
|
|
635
|
-
for geo_count, geom in enumerate(geoms):
|
|
636
|
-
geom_defaults = defaults
|
|
637
|
-
if "class" in geom.attrib:
|
|
638
|
-
geom_class = geom.attrib["class"]
|
|
639
|
-
ignore_geom = False
|
|
640
|
-
for pattern in ignore_classes:
|
|
641
|
-
if re.match(pattern, geom_class):
|
|
642
|
-
ignore_geom = True
|
|
643
|
-
break
|
|
644
|
-
if ignore_geom:
|
|
645
|
-
continue
|
|
646
|
-
if geom_class in class_defaults:
|
|
647
|
-
geom_defaults = merge_attrib(defaults, class_defaults[geom_class])
|
|
648
|
-
if "geom" in geom_defaults:
|
|
649
|
-
geom_attrib = merge_attrib(geom_defaults["geom"], geom.attrib)
|
|
650
|
-
else:
|
|
651
|
-
geom_attrib = geom.attrib
|
|
652
|
-
|
|
653
|
-
geom_name = geom_attrib.get("name", f"{body_name}_geom_{geo_count}")
|
|
654
|
-
|
|
655
|
-
if "class" in geom.attrib:
|
|
656
|
-
for pattern in visual_classes:
|
|
657
|
-
if re.match(pattern, geom_class):
|
|
658
|
-
visuals.append(geom)
|
|
659
|
-
break
|
|
660
|
-
for pattern in collider_classes:
|
|
661
|
-
if re.match(pattern, geom_class):
|
|
662
|
-
colliders.append(geom)
|
|
663
|
-
break
|
|
664
|
-
else:
|
|
665
|
-
no_class_class = "collision" if no_class_as_colliders else "visual"
|
|
666
|
-
if verbose:
|
|
667
|
-
print(f"MJCF parsing shape {geom_name} issue: no class defined for geom, assuming {no_class_class}")
|
|
668
|
-
if no_class_as_colliders:
|
|
669
|
-
colliders.append(geom)
|
|
670
|
-
else:
|
|
671
|
-
visuals.append(geom)
|
|
672
|
-
|
|
673
|
-
if parse_visuals_as_colliders:
|
|
674
|
-
colliders = visuals
|
|
675
|
-
else:
|
|
676
|
-
s = parse_shapes(
|
|
677
|
-
defaults, body_name, link, visuals, density=0.0, just_visual=True, visible=not hide_visuals
|
|
678
|
-
)
|
|
679
|
-
visual_shapes.extend(s)
|
|
680
|
-
|
|
681
|
-
show_colliders = force_show_colliders
|
|
682
|
-
if parse_visuals_as_colliders:
|
|
683
|
-
show_colliders = True
|
|
684
|
-
elif len(visuals) == 0:
|
|
685
|
-
# we need to show the collision shapes since there are no visual shapes
|
|
686
|
-
show_colliders = True
|
|
687
|
-
|
|
688
|
-
parse_shapes(defaults, body_name, link, colliders, density, visible=show_colliders)
|
|
689
|
-
|
|
690
|
-
m = builder.body_mass[link]
|
|
691
|
-
if not ignore_inertial_definitions and body.find("inertial") is not None:
|
|
692
|
-
inertial = body.find("inertial")
|
|
693
|
-
if "inertial" in defaults:
|
|
694
|
-
inertial_attrib = merge_attrib(defaults["inertial"], inertial.attrib)
|
|
695
|
-
else:
|
|
696
|
-
inertial_attrib = inertial.attrib
|
|
697
|
-
# overwrite inertial parameters if defined
|
|
698
|
-
inertial_pos = parse_vec(inertial_attrib, "pos", (0.0, 0.0, 0.0)) * scale
|
|
699
|
-
inertial_rot = parse_orientation(inertial_attrib)
|
|
700
|
-
|
|
701
|
-
inertial_frame = wp.transform(inertial_pos, inertial_rot)
|
|
702
|
-
com = inertial_frame.p
|
|
703
|
-
if inertial_attrib.get("diaginertia") is not None:
|
|
704
|
-
diaginertia = parse_vec(inertial_attrib, "diaginertia", None)
|
|
705
|
-
I_m = np.zeros((3, 3))
|
|
706
|
-
I_m[0, 0] = diaginertia[0] * scale**2
|
|
707
|
-
I_m[1, 1] = diaginertia[1] * scale**2
|
|
708
|
-
I_m[2, 2] = diaginertia[2] * scale**2
|
|
709
|
-
else:
|
|
710
|
-
fullinertia = inertial_attrib.get("fullinertia")
|
|
711
|
-
assert fullinertia is not None
|
|
712
|
-
fullinertia = np.fromstring(fullinertia, sep=" ", dtype=np.float32)
|
|
713
|
-
I_m = np.zeros((3, 3))
|
|
714
|
-
I_m[0, 0] = fullinertia[0] * scale**2
|
|
715
|
-
I_m[1, 1] = fullinertia[1] * scale**2
|
|
716
|
-
I_m[2, 2] = fullinertia[2] * scale**2
|
|
717
|
-
I_m[0, 1] = fullinertia[3] * scale**2
|
|
718
|
-
I_m[0, 2] = fullinertia[4] * scale**2
|
|
719
|
-
I_m[1, 2] = fullinertia[5] * scale**2
|
|
720
|
-
I_m[1, 0] = I_m[0, 1]
|
|
721
|
-
I_m[2, 0] = I_m[0, 2]
|
|
722
|
-
I_m[2, 1] = I_m[1, 2]
|
|
723
|
-
rot = wp.quat_to_matrix(inertial_frame.q)
|
|
724
|
-
I_m = rot @ wp.mat33(I_m)
|
|
725
|
-
m = float(inertial_attrib.get("mass", "0"))
|
|
726
|
-
builder.body_mass[link] = m
|
|
727
|
-
builder.body_inv_mass[link] = 1.0 / m if m > 0.0 else 0.0
|
|
728
|
-
builder.body_com[link] = com
|
|
729
|
-
builder.body_inertia[link] = I_m
|
|
730
|
-
if any(x for x in I_m):
|
|
731
|
-
builder.body_inv_inertia[link] = wp.inverse(I_m)
|
|
732
|
-
else:
|
|
733
|
-
builder.body_inv_inertia[link] = I_m
|
|
734
|
-
if m == 0.0 and ensure_nonstatic_links:
|
|
735
|
-
# set the mass to something nonzero to ensure the body is dynamic
|
|
736
|
-
m = static_link_mass
|
|
737
|
-
# cube with side length 0.5
|
|
738
|
-
I_m = wp.mat33(np.eye(3)) * m / 12.0 * (0.5 * scale) ** 2 * 2.0
|
|
739
|
-
I_m += wp.mat33(armature * np.eye(3))
|
|
740
|
-
builder.body_mass[link] = m
|
|
741
|
-
builder.body_inv_mass[link] = 1.0 / m
|
|
742
|
-
builder.body_inertia[link] = I_m
|
|
743
|
-
builder.body_inv_inertia[link] = wp.inverse(I_m)
|
|
744
|
-
|
|
745
|
-
# -----------------
|
|
746
|
-
# recurse
|
|
747
|
-
|
|
748
|
-
for child in body.findall("body"):
|
|
749
|
-
_childclass = body.get("childclass")
|
|
750
|
-
if _childclass is None:
|
|
751
|
-
_childclass = childclass
|
|
752
|
-
_incoming_defaults = defaults
|
|
753
|
-
else:
|
|
754
|
-
_incoming_defaults = merge_attrib(defaults, class_defaults[_childclass])
|
|
755
|
-
parse_body(child, link, _incoming_defaults, childclass=_childclass)
|
|
756
|
-
|
|
757
|
-
# -----------------
|
|
758
|
-
# start articulation
|
|
759
|
-
|
|
760
|
-
visual_shapes = []
|
|
761
|
-
start_shape_count = len(builder.shape_geo_type)
|
|
762
|
-
builder.add_articulation()
|
|
763
|
-
|
|
764
|
-
world = root.find("worldbody")
|
|
765
|
-
world_class = get_class(world)
|
|
766
|
-
world_defaults = merge_attrib(class_defaults["__all__"], class_defaults.get(world_class, {}))
|
|
767
|
-
|
|
768
|
-
# -----------------
|
|
769
|
-
# add bodies
|
|
770
|
-
|
|
771
|
-
for body in world.findall("body"):
|
|
772
|
-
parse_body(body, -1, world_defaults)
|
|
773
|
-
|
|
774
|
-
# -----------------
|
|
775
|
-
# add static geoms
|
|
776
|
-
|
|
777
|
-
parse_shapes(world_defaults, "world", -1, world.findall("geom"), density, incoming_xform=xform)
|
|
778
|
-
|
|
779
|
-
end_shape_count = len(builder.shape_geo_type)
|
|
780
|
-
|
|
781
|
-
for i in range(start_shape_count, end_shape_count):
|
|
782
|
-
for j in visual_shapes:
|
|
783
|
-
builder.shape_collision_filter_pairs.add((i, j))
|
|
784
|
-
|
|
785
|
-
if not enable_self_collisions:
|
|
786
|
-
for i in range(start_shape_count, end_shape_count):
|
|
787
|
-
for j in range(i + 1, end_shape_count):
|
|
788
|
-
builder.shape_collision_filter_pairs.add((i, j))
|
|
789
|
-
|
|
790
|
-
if collapse_fixed_joints:
|
|
791
|
-
builder.collapse_fixed_joints()
|