Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Guidelines for modifications:
* Vladimir Fokow
* Wei Yang
* Xavier Nal
* Xudong Han
* Yang Jin
* Yujian Zhang
* Zhengyu Zhang
Expand Down
8 changes: 8 additions & 0 deletions docs/source/api/lab/isaaclab.sim.spawners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Meshes
MeshCuboidCfg
MeshCylinderCfg
MeshSphereCfg
MeshFileCfg

.. autoclass:: MeshCfg
:members:
Expand Down Expand Up @@ -150,6 +151,13 @@ Meshes
:show-inheritance:
:exclude-members: __init__, func

.. autofunction:: spawn_mesh_file

.. autoclass:: MeshFileCfg
:members:
:show-inheritance:
:exclude-members: __init__, func

Lights
------

Expand Down
2 changes: 1 addition & 1 deletion source/isaaclab/isaaclab/sim/spawners/meshes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"""

from .meshes import spawn_mesh_capsule, spawn_mesh_cone, spawn_mesh_cuboid, spawn_mesh_cylinder, spawn_mesh_sphere
from .meshes_cfg import MeshCapsuleCfg, MeshCfg, MeshConeCfg, MeshCuboidCfg, MeshCylinderCfg, MeshSphereCfg
from .meshes_cfg import MeshCapsuleCfg, MeshCfg, MeshConeCfg, MeshCuboidCfg, MeshCylinderCfg, MeshFileCfg, MeshSphereCfg
37 changes: 37 additions & 0 deletions source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,43 @@ def spawn_mesh_cone(
return prim_utils.get_prim_at_path(prim_path)


@clone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm from original design, this spawning function should be inside the from_files.py sub-module. Could you please move it there?

def spawn_mesh_file(
prim_path: str,
cfg: meshes_cfg.MeshFileCfg,
translation: tuple[float, float, float] | None = None,
orientation: tuple[float, float, float, float] | None = None,
) -> Usd.Prim:
"""Create a USD-Mesh prim from the given mesh file.

.. note::
This function is decorated with :func:`clone` that resolves prim path into list of paths
if the input prim path is a regex pattern. This is done to support spawning multiple assets
from a single and cloning the USD prim at the given path expression.

Args:
prim_path: The prim path or pattern to spawn the asset at. If the prim path is a regex pattern,
then the asset is spawned at all the matching prim paths.
cfg: The configuration instance.
translation: The translation to apply to the prim w.r.t. its parent prim. Defaults to None, in which case
this is set to the origin.
orientation: The orientation in (w, x, y, z) to apply to the prim w.r.t. its parent prim. Defaults to None,
in which case this is set to identity.

Returns:
The created prim.

Raises:
ValueError: If a prim already exists at the given path.
"""
# load the mesh from file
mesh = trimesh.load_mesh(cfg.file_path)
# spawn mesh if it doesn't exist.
_spawn_mesh_geom_from_mesh(prim_path, cfg, mesh, translation, orientation, cfg.scale)
# return the prim
return prim_utils.get_prim_at_path(prim_path)


"""
Helper functions.
"""
Expand Down
15 changes: 15 additions & 0 deletions source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,18 @@ class MeshConeCfg(MeshCfg):
"""Height of the v (in m)."""
axis: Literal["X", "Y", "Z"] = "Z"
"""Axis of the cone. Defaults to "Z"."""


@configclass
class MeshFileCfg(MeshCfg):
"""Configuration parameters for a mesh prim with deformable properties.

See :meth:`spawn_mesh_file` for more information.
"""

func: Callable = meshes.spawn_mesh_file

file_path: str = MISSING
"""Path to the mesh file (in OBJ, STL, or FBX format)."""
scale: tuple[float, float, float] = (1.0, 1.0, 1.0)
"""Scale of the mesh (in m)."""
15 changes: 15 additions & 0 deletions source/isaaclab/test/sim/test_spawn_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ def test_spawn_sphere(self):
# Check properties
prim = prim_utils.get_prim_at_path("/World/Sphere/geometry/mesh")
self.assertEqual(prim.GetPrimTypeInfo().GetTypeName(), "Mesh")

def test_spawn_meshfile(self):
"""Test spawning of UsdGeomMesh as a mesh prim from file."""
# Spawn mesh
cfg = sim_utils.MeshFileCfg(
file_path="_isaac_sim/standalone_examples/data/torus/torus.stl"
)
prim = cfg.func("/World/Torus", cfg)
# Check validity
self.assertTrue(prim.IsValid())
self.assertTrue(prim_utils.is_prim_path_valid("/World/Torus"))
self.assertEqual(prim.GetPrimTypeInfo().GetTypeName(), "Xform")
# Check properties
prim = prim_utils.get_prim_at_path("/World/Torus/geometry/mesh")
self.assertEqual(prim.GetPrimTypeInfo().GetTypeName(), "Mesh")

"""
Physics properties.
Expand Down