Skip to content

Commit 20f7707

Browse files
authored
Add check to avoid creating transforms for non-xformable prims (#4348)
# Description This MR ensures we don't try setting transforms for non-xformable prims (Scopes, Materials, Shaders). Previously, they were not being set but an error was being thrown. ## 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` - [x] 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 b13f045 commit 20f7707

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def create_prim(
161161
if semantic_label is not None:
162162
add_labels(prim, labels=[semantic_label], instance_name=semantic_type)
163163

164+
# check if prim type is Xformable
165+
if not prim.IsA(UsdGeom.Xformable):
166+
logger.debug(
167+
f"Prim at path '{prim.GetPath().pathString}' is of type '{prim.GetTypeName()}', "
168+
"which is not an Xformable. Transform operations will not be standardized. "
169+
"This is expected for material, shader, and scope prims."
170+
)
171+
return prim
172+
164173
# convert input arguments to tuples
165174
position = _to_tuple(position) if position is not None else None
166175
translation = _to_tuple(translation) if translation is not None else None

source/isaaclab/isaaclab/sim/utils/transforms.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ def standardize_xform_ops(
130130

131131
# Check if prim is an Xformable
132132
if not prim.IsA(UsdGeom.Xformable):
133-
logger.error(f"Prim at path '{prim.GetPath()}' is not an Xformable.")
133+
logger.error(
134+
f"Prim at path '{prim.GetPath().pathString}' is of type '{prim.GetTypeName()}', "
135+
"which is not an Xformable. Transform operations will not be standardized. "
136+
"This is expected for material, shader, and scope prims."
137+
)
134138
return False
135139

136140
# Create xformable interface

source/isaaclab/test/sim/test_utils_prims.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,61 @@ def test_create_prim_with_world_position_different_types(input_type: str):
249249
assert quat_match or quat_match_neg
250250

251251

252+
def test_create_prim_non_xformable():
253+
"""Test create_prim() with non-Xformable prim types (Material, Shader, Scope).
254+
255+
This test verifies that prims which are not Xformable (like Material, Shader, Scope)
256+
are created successfully but transform operations are not applied to them.
257+
This is expected behavior as documented in the create_prim function.
258+
"""
259+
# obtain stage handle
260+
stage = sim_utils.get_current_stage()
261+
262+
# Test with Material prim (not Xformable)
263+
material_prim = sim_utils.create_prim(
264+
"/World/TestMaterial",
265+
"Material",
266+
stage=stage,
267+
translation=(1.0, 2.0, 3.0), # These should be ignored
268+
orientation=(1.0, 0.0, 0.0, 0.0), # These should be ignored
269+
scale=(2.0, 2.0, 2.0), # These should be ignored
270+
)
271+
272+
# Verify prim was created
273+
assert material_prim.IsValid()
274+
assert material_prim.GetPrimPath() == "/World/TestMaterial"
275+
assert material_prim.GetTypeName() == "Material"
276+
277+
# Verify that it's not Xformable
278+
assert not material_prim.IsA(UsdGeom.Xformable)
279+
280+
# Verify that no xform operations were applied (Material prims don't support these)
281+
assert not material_prim.HasAttribute("xformOp:translate")
282+
assert not material_prim.HasAttribute("xformOp:orient")
283+
assert not material_prim.HasAttribute("xformOp:scale")
284+
285+
# Test with Scope prim (not Xformable)
286+
scope_prim = sim_utils.create_prim(
287+
"/World/TestScope",
288+
"Scope",
289+
stage=stage,
290+
translation=(5.0, 6.0, 7.0), # These should be ignored
291+
)
292+
293+
# Verify prim was created
294+
assert scope_prim.IsValid()
295+
assert scope_prim.GetPrimPath() == "/World/TestScope"
296+
assert scope_prim.GetTypeName() == "Scope"
297+
298+
# Verify that it's not Xformable
299+
assert not scope_prim.IsA(UsdGeom.Xformable)
300+
301+
# Verify that no xform operations were applied (Scope prims don't support these)
302+
assert not scope_prim.HasAttribute("xformOp:translate")
303+
assert not scope_prim.HasAttribute("xformOp:orient")
304+
assert not scope_prim.HasAttribute("xformOp:scale")
305+
306+
252307
def test_delete_prim():
253308
"""Test delete_prim() function."""
254309
# obtain stage handle

0 commit comments

Comments
 (0)