Skip to content

Commit 5497685

Browse files
authored
Tests material binding inside stage in memory test (#4347)
# Description Previously the stage in memory test did not check if material binding worked correctly. During my debugging, I saw that the `bind_visual_material` command was failing. This MR adds a fix for it and makes the test check for mateiral binding as well. Requires merging: #4337 ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there
1 parent 76a6e3c commit 5497685

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

source/isaaclab/isaaclab/sim/simulation_context.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from isaacsim.core.api.simulation_context import SimulationContext as _SimulationContext
2828
from isaacsim.core.simulation_manager import SimulationManager
2929
from isaacsim.core.utils.viewports import set_camera_view
30-
from pxr import Gf, PhysxSchema, Sdf, Usd, UsdPhysics
30+
from pxr import Gf, PhysxSchema, Sdf, Usd, UsdPhysics, UsdUtils
3131

3232
import isaaclab.sim as sim_utils
3333
from isaaclab.utils.logger import configure_logging
@@ -146,6 +146,11 @@ def __init__(self, cfg: SimulationCfg | None = None):
146146
self._initial_stage = sim_utils.create_new_stage_in_memory()
147147
else:
148148
self._initial_stage = omni.usd.get_context().get_stage()
149+
# cache stage if it is not already cached
150+
stage_cache = UsdUtils.StageCache.Get()
151+
stage_id = stage_cache.GetId(self._initial_stage).ToLongInt()
152+
if stage_id < 0:
153+
stage_cache.Insert(self._initial_stage)
149154

150155
# acquire settings interface
151156
self.carb_settings = carb.settings.get_settings()

source/isaaclab/isaaclab/sim/utils/prims.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ def delete_prim(prim_path: str | Sequence[str], stage: Usd.Stage | None = None)
206206
prim_path = [prim_path]
207207
# get stage handle
208208
stage = get_current_stage() if stage is None else stage
209+
# FIXME: We should not need to cache the stage here. It should
210+
# happen at the creation of the stage.
209211
# the prim command looks for the stage ID in the stage cache
210212
# so we need to ensure the stage is cached
211213
stage_cache = UsdUtils.StageCache.Get()

source/isaaclab/test/sim/test_simulation_stage_in_memory.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,35 @@ def test_stage_in_memory_with_shapes(sim):
7171
sim_utils.ConeCfg(
7272
radius=0.3,
7373
height=0.6,
74+
visual_material=sim_utils.PreviewSurfaceCfg(diffuse_color=(0.0, 1.0, 0.0)),
75+
physics_material=sim_utils.RigidBodyMaterialCfg(
76+
friction_combine_mode="multiply",
77+
restitution_combine_mode="multiply",
78+
static_friction=1.0,
79+
dynamic_friction=1.0,
80+
),
7481
),
75-
sim_utils.CuboidCfg(
82+
sim_utils.MeshCuboidCfg(
7683
size=(0.3, 0.3, 0.3),
84+
visual_material=sim_utils.MdlFileCfg(
85+
mdl_path=f"{ISAACLAB_NUCLEUS_DIR}/Materials/TilesMarbleSpiderWhiteBrickBondHoned/TilesMarbleSpiderWhiteBrickBondHoned.mdl",
86+
project_uvw=True,
87+
texture_scale=(0.25, 0.25),
88+
),
7789
),
7890
sim_utils.SphereCfg(
7991
radius=0.3,
92+
visual_material=sim_utils.MdlFileCfg(
93+
mdl_path=f"{ISAACLAB_NUCLEUS_DIR}/Materials/TilesMarbleSpiderWhiteBrickBondHoned/TilesMarbleSpiderWhiteBrickBondHoned.mdl",
94+
project_uvw=True,
95+
texture_scale=(0.25, 0.25),
96+
),
97+
physics_material=sim_utils.RigidBodyMaterialCfg(
98+
friction_combine_mode="multiply",
99+
restitution_combine_mode="multiply",
100+
static_friction=1.0,
101+
dynamic_friction=1.0,
102+
),
80103
),
81104
],
82105
random_choice=True,

0 commit comments

Comments
 (0)