From 182dcb92b1a305d69013eb91b34fa84c44696356 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Sat, 27 Jun 2026 23:19:52 -0700 Subject: [PATCH 01/19] Add rigid-body physics-material schema fragments Convert rigid-body physics materials to the single-namespace "fragment" model used by the other schema families. Add RigidBodyMaterialFragment and the solver-common UsdPhysicsRigidBodyMaterialCfg (physics:* friction / restitution) in core, and PhysxMaterialCfg (physxMaterial:* compliant contact + combine modes) in the PhysX extension. A material is spawned as a separate UsdShade.Material prim and bound, so the family writer spawn_rigid_body_material_from_fragments spawns the prim, applies the UsdPhysics.MaterialAPI anchor, and dispatches each fragment. Spawner physics_material slots now accept a list of fragments alongside the legacy material cfg, dispatched through spawn_physics_material; the legacy single-cfg path is unchanged. --- .../vidurv-schema-frag-materials.minor.rst | 11 ++ .../sim/spawners/from_files/from_files.py | 7 +- .../sim/spawners/from_files/from_files_cfg.py | 10 +- .../sim/spawners/materials/__init__.pyi | 13 +- .../spawners/materials/physics_materials.py | 77 ++++++++++ .../materials/physics_materials_cfg.py | 40 +++++ .../isaaclab/sim/spawners/meshes/meshes.py | 5 +- .../sim/spawners/meshes/meshes_cfg.py | 10 +- .../isaaclab/sim/spawners/shapes/shapes.py | 5 +- .../sim/spawners/shapes/shapes_cfg.py | 11 +- .../test/sim/test_material_fragments.py | 137 ++++++++++++++++++ .../vidurv-schema-frag-materials.minor.rst | 6 + .../sim/spawners/materials/__init__.pyi | 2 + .../materials/physics_materials_cfg.py | 38 +++++ 14 files changed, 361 insertions(+), 11 deletions(-) create mode 100644 source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst create mode 100644 source/isaaclab/test/sim/test_material_fragments.py create mode 100644 source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst new file mode 100644 index 000000000000..f6f3a5101fd4 --- /dev/null +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -0,0 +1,11 @@ +Added +^^^^^ + +* Added the rigid-body physics-material "fragment" classes + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (marker base) and + :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg` (solver-common + ``physics:*`` friction/restitution), plus the family writer + :func:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material_from_fragments` and the slot + dispatcher :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`. Spawner + ``physics_material`` slots now accept a list of single-namespace fragments in addition to the + legacy material cfg. diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py index d9f789b666f3..1a1805f9fb8c 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py @@ -16,6 +16,7 @@ from isaaclab.sim import converters, schemas from isaaclab.sim.spawners.materials import SurfaceDeformableBodyMaterialBaseCfg +from isaaclab.sim.spawners.materials.physics_materials import spawn_physics_material from isaaclab.sim.utils import ( add_labels, bind_physics_material, @@ -211,7 +212,7 @@ def spawn_ground_plane( # Create physics material if cfg.physics_material is not None: - cfg.physics_material.func(f"{prim_path}/physicsMaterial", cfg.physics_material) + spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material) # Apply physics material to ground plane collision_prim = get_first_matching_child_prim( prim_path, @@ -478,8 +479,8 @@ def _spawn_from_usd_file( material_path = f"{prim_path}/{cfg.physics_material_path}" else: material_path = cfg.physics_material_path - # create material - cfg.physics_material.func(material_path, cfg.physics_material) + # create material (accepts a legacy material cfg or rigid-body fragment(s)) + spawn_physics_material(material_path, cfg.physics_material, stage=stage) # apply material bind_physics_material(prim_path, material_path, stage=stage) diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py index ea2cfe9b6c9f..229dbd04cb33 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py @@ -106,9 +106,17 @@ class FileCfg(RigidObjectSpawnerCfg, DeformableObjectSpawnerCfg): This parameter is ignored if `physics_material` is not None. """ - physics_material: materials.PhysicsMaterialCfg | None = None + physics_material: ( + materials.PhysicsMaterialCfg + | materials.RigidBodyMaterialFragment + | list[materials.RigidBodyMaterialFragment] + | None + ) = None """Physics material properties. + Accepts either a legacy material cfg or a list of single-namespace + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + Note: If None, then no custom physics material will be added. """ diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/__init__.pyi b/source/isaaclab/isaaclab/sim/spawners/materials/__init__.pyi index 7ce7815955c2..305c980d2312 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/__init__.pyi +++ b/source/isaaclab/isaaclab/sim/spawners/materials/__init__.pyi @@ -5,9 +5,13 @@ __all__ = [ "spawn_rigid_body_material", + "spawn_rigid_body_material_from_fragments", + "spawn_physics_material", "spawn_deformable_body_material", "PhysicsMaterialCfg", "RigidBodyMaterialBaseCfg", + "RigidBodyMaterialFragment", + "UsdPhysicsRigidBodyMaterialCfg", "DeformableBodyMaterialBaseCfg", "DeformableBodyMaterialCfg", "SurfaceDeformableBodyMaterialBaseCfg", @@ -20,10 +24,17 @@ __all__ = [ "VisualMaterialCfg", ] -from .physics_materials import spawn_rigid_body_material, spawn_deformable_body_material +from .physics_materials import ( + spawn_deformable_body_material, + spawn_physics_material, + spawn_rigid_body_material, + spawn_rigid_body_material_from_fragments, +) from .physics_materials_cfg import ( PhysicsMaterialCfg, RigidBodyMaterialBaseCfg, + RigidBodyMaterialFragment, + UsdPhysicsRigidBodyMaterialCfg, DeformableBodyMaterialBaseCfg, DeformableBodyMaterialCfg, SurfaceDeformableBodyMaterialBaseCfg, diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index 8c12bee9442d..2c51e737ee05 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -12,10 +12,87 @@ from isaaclab.sim.schemas.schemas import _apply_namespaced_schemas from isaaclab.sim.utils import clone from isaaclab.sim.utils.stage import get_current_stage +from isaaclab.utils.string import string_to_callable from . import physics_materials_cfg +def spawn_rigid_body_material_from_fragments( + prim_path: str, + fragments: physics_materials_cfg.RigidBodyMaterialFragment | list[physics_materials_cfg.RigidBodyMaterialFragment], + stage: Usd.Stage | None = None, +) -> Usd.Prim: + """Spawn a rigid-body physics material from a list of single-namespace fragments. + + Creates (or reuses) the ``UsdShade.Material`` prim at ``prim_path``, applies the standard + ``UsdPhysics.MaterialAPI`` anchor, then dispatches each fragment via its + :attr:`~isaaclab.sim.schemas.SchemaFragment.func` to author its namespace onto the material prim. + Backend fragments carry backend-specific namespaces (e.g. PhysX ``physxMaterial:*``) without core + importing a backend. + + Args: + prim_path: The prim path to spawn the material at. + fragments: A single :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list + of them. + stage: The stage to spawn on. Defaults to None, in which case the current stage is used. + + Returns: + The spawned rigid body material prim. + + Raises: + ValueError: When a prim already exists at the path and is not a material. + """ + if stage is None: + stage = get_current_stage() + if not isinstance(fragments, (list, tuple)): + fragments = [fragments] + + # create the material prim if none exists yet + if not stage.GetPrimAtPath(prim_path).IsValid(): + UsdShade.Material.Define(stage, prim_path) + prim = stage.GetPrimAtPath(prim_path) + if not prim.IsA(UsdShade.Material): + raise ValueError(f"A prim already exists at path: '{prim_path}' but is not a material.") + + # apply the standard UsdPhysics MaterialAPI anchor (the defining schema for a physics material) + if not UsdPhysics.MaterialAPI(prim): + UsdPhysics.MaterialAPI.Apply(prim) + + # dispatch each fragment's applier (writes its single namespace onto the material prim) + for cfg in fragments: + func = cfg.func if callable(cfg.func) else string_to_callable(cfg.func) + func(cfg, prim_path, stage) + return prim + + +def spawn_physics_material( + prim_path: str, + material, + stage: Usd.Stage | None = None, +) -> Usd.Prim: + """Spawn a physics material from a spawner ``physics_material`` slot value. + + Dispatches the two accepted slot forms: a list of (or single) rigid-body fragments is spawned via + :func:`spawn_rigid_body_material_from_fragments`; otherwise the value is a legacy material cfg and is + spawned via its own :attr:`func`. Lets spawners accept both the fragment and the legacy interface + from one call site. + + Args: + prim_path: The prim path to spawn the material at. + material: A :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or list of + them), or a legacy material cfg carrying a :attr:`func`. + stage: The stage to spawn on. Defaults to None, in which case the current stage is used. + + Returns: + The spawned material prim. + """ + fragments = material if isinstance(material, (list, tuple)) else [material] + if fragments and all(isinstance(f, physics_materials_cfg.RigidBodyMaterialFragment) for f in fragments): + return spawn_rigid_body_material_from_fragments(prim_path, list(fragments), stage) + # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``) + return material.func(prim_path, material) + + @clone def spawn_rigid_body_material(prim_path: str, cfg: physics_materials_cfg.RigidBodyMaterialBaseCfg) -> Usd.Prim: """Create material with rigid-body physics properties. diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py index 5c88731cf8d5..1e60101563d0 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py @@ -9,6 +9,7 @@ from dataclasses import MISSING from typing import ClassVar +from isaaclab.sim.schemas.schemas_cfg import SchemaFragment from isaaclab.utils.configclass import configclass # Names that moved out of this submodule into ``isaaclab_physx.sim.spawners.materials.physics_materials_cfg``. @@ -89,6 +90,45 @@ class RigidBodyMaterialBaseCfg(PhysicsMaterialCfg): """The restitution coefficient. Defaults to 0.0.""" +@configclass +class RigidBodyMaterialFragment(SchemaFragment): + """Marker base for rigid-body physics-material fragments; types the ``physics_material`` slot. + + A rigid-body physics material is a single ``UsdShade.Material`` prim that carries one or more + physics-material schemas. The fragments author single namespaces onto that prim: the solver-common + ``physics:*`` friction/restitution (:class:`UsdPhysicsRigidBodyMaterialCfg`) and any backend-specific + namespace (e.g. PhysX ``physxMaterial:*`` via :class:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg`). + The defining ``UsdPhysics.MaterialAPI`` anchor is applied by the family writer + (:func:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material_from_fragments`). + """ + + pass + + +@configclass +class UsdPhysicsRigidBodyMaterialCfg(RigidBodyMaterialFragment): + """``physics:*`` rigid-body material attributes from `UsdPhysics.MaterialAPI`_. + + The ``UsdPhysics.MaterialAPI`` schema is applied as the implicit anchor by the rigid-body material + family writer, so this fragment owns no applied schema of its own. ``None`` fields are left + unchanged on the material prim. + + .. _UsdPhysics.MaterialAPI: https://openusd.org/dev/api/class_usd_physics_material_a_p_i.html + """ + + _usd_namespace: ClassVar[str | None] = "physics" + _usd_applied_schema: ClassVar[str | None] = None # MaterialAPI applied by the family writer + + static_friction: float | None = None + """The static friction coefficient. Writes ``physics:staticFriction``.""" + + dynamic_friction: float | None = None + """The dynamic friction coefficient. Writes ``physics:dynamicFriction``.""" + + restitution: float | None = None + """The restitution coefficient. Writes ``physics:restitution``.""" + + @configclass class DeformableBodyMaterialBaseCfg(PhysicsMaterialCfg): """Base physics material parameters for volume deformable bodies. diff --git a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py index bf0df38db129..c169e536e5e6 100644 --- a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py +++ b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py @@ -17,6 +17,7 @@ from isaaclab.sim.utils import bind_physics_material, bind_visual_material, clone, create_prim, get_current_stage from ..materials import DeformableBodyMaterialBaseCfg, RigidBodyMaterialCfg, SurfaceDeformableBodyMaterialBaseCfg +from ..materials.physics_materials import spawn_physics_material if TYPE_CHECKING: from . import meshes_cfg @@ -439,8 +440,8 @@ def _spawn_mesh_geom_from_mesh( material_path = f"{geom_prim_path}/{cfg.physics_material_path}" else: material_path = cfg.physics_material_path - # create material - cfg.physics_material.func(material_path, cfg.physics_material) + # create material (accepts a legacy material cfg or rigid-body fragment(s)) + spawn_physics_material(material_path, cfg.physics_material, stage=stage) # apply material bind_physics_material(prim_path, material_path, stage=stage) diff --git a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py index c6eb26507d3a..50f0a8075515 100644 --- a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py @@ -57,9 +57,17 @@ class MeshCfg(RigidObjectSpawnerCfg, DeformableObjectSpawnerCfg): This parameter is ignored if `physics_material` is not None. """ - physics_material: materials.PhysicsMaterialCfg | None = None + physics_material: ( + materials.PhysicsMaterialCfg + | materials.RigidBodyMaterialFragment + | list[materials.RigidBodyMaterialFragment] + | None + ) = None """Physics material properties. + Accepts either a legacy material cfg or a list of single-namespace + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + Note: If None, then no physics material will be added. """ diff --git a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py index 2d1b721e9567..2b8177423a88 100644 --- a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py +++ b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py @@ -10,6 +10,7 @@ from pxr import Usd from isaaclab.sim import schemas +from isaaclab.sim.spawners.materials.physics_materials import spawn_physics_material from isaaclab.sim.utils import bind_physics_material, bind_visual_material, clone, create_prim, get_current_stage if TYPE_CHECKING: @@ -316,8 +317,8 @@ def _spawn_geom_from_prim_type( material_path = f"{geom_prim_path}/{cfg.physics_material_path}" else: material_path = cfg.physics_material_path - # create material - cfg.physics_material.func(material_path, cfg.physics_material) + # create material (accepts a legacy material cfg or rigid-body fragment(s)) + spawn_physics_material(material_path, cfg.physics_material, stage=stage) # apply material bind_physics_material(mesh_prim_path, material_path, stage=stage) diff --git a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py index b111bdbb2bf3..83f0bf25c7a0 100644 --- a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py @@ -37,9 +37,18 @@ class ShapeCfg(RigidObjectSpawnerCfg): If the path is relative, then it will be relative to the prim's path. This parameter is ignored if `physics_material` is not None. """ - physics_material: materials.PhysicsMaterialCfg | None = None + physics_material: ( + materials.PhysicsMaterialCfg + | materials.RigidBodyMaterialFragment + | list[materials.RigidBodyMaterialFragment] + | None + ) = None """Physics material properties. + Accepts either a legacy material cfg (e.g. + :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`) or a list of + single-namespace :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + Note: If None, then no physics material will be added. """ diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py new file mode 100644 index 000000000000..049ee8444ef8 --- /dev/null +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -0,0 +1,137 @@ +# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Launch Isaac Sim Simulator first.""" + +from isaaclab.app import AppLauncher + +# launch omniverse app +simulation_app = AppLauncher(headless=True).app + +"""Rest everything follows.""" + +import pytest + +from pxr import UsdPhysics, UsdShade + +import isaaclab.sim as sim_utils +from isaaclab.sim import SimulationCfg, SimulationContext + + +# ------------------------------------------------------------------------------------- +# RigidBodyMaterialFragment marker + metadata +# ------------------------------------------------------------------------------------- + + +def test_rigid_body_material_fragment_metadata_defaults(): + from isaaclab.sim.schemas import SchemaFragment + from isaaclab.sim.spawners.materials.physics_materials_cfg import ( + RigidBodyMaterialFragment, + UsdPhysicsRigidBodyMaterialCfg, + ) + + cfg = UsdPhysicsRigidBodyMaterialCfg(static_friction=0.7) + assert isinstance(cfg, RigidBodyMaterialFragment) and isinstance(cfg, SchemaFragment) + assert type(cfg)._usd_namespace == "physics" + assert type(cfg)._usd_applied_schema is None # MaterialAPI applied by the family writer + assert cfg.func == "isaaclab.sim.schemas:apply_namespaced" + assert cfg.static_friction == 0.7 and cfg.dynamic_friction is None + + +def test_physx_material_fragment_metadata_defaults(): + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialFragment + + cfg = PhysxMaterialCfg(compliant_contact_stiffness=100.0) + assert isinstance(cfg, RigidBodyMaterialFragment) + assert type(cfg)._usd_namespace == "physxMaterial" + assert type(cfg)._usd_applied_schema == "PhysxMaterialAPI" + assert cfg.func == "isaaclab.sim.schemas:apply_namespaced" + + +# ------------------------------------------------------------------------------------- +# spawn_rigid_body_material_from_fragments: spawn prim + anchor + multi-namespace compose +# ------------------------------------------------------------------------------------- + + +def test_spawn_rigid_body_material_from_fragments_composes_namespaces(): + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + prim = spawn_rigid_body_material_from_fragments( + "/World/Mat", + [ + UsdPhysicsRigidBodyMaterialCfg(static_friction=0.7, dynamic_friction=0.6, restitution=0.1), + PhysxMaterialCfg(compliant_contact_stiffness=100.0, friction_combine_mode="max"), + ], + stage, + ) + assert prim.IsA(UsdShade.Material) + assert bool(UsdPhysics.MaterialAPI(prim)) # neutral anchor applied by the writer + assert prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.7) + assert prim.GetAttribute("physics:dynamicFriction").Get() == pytest.approx(0.6) + assert prim.GetAttribute("physics:restitution").Get() == pytest.approx(0.1) + # the PhysX fragment applied its own schema and namespace + assert "PhysxMaterialAPI" in prim.GetAppliedSchemas() + assert prim.GetAttribute("physxMaterial:compliantContactStiffness").Get() == pytest.approx(100.0) + assert prim.GetAttribute("physxMaterial:frictionCombineMode").Get() == "max" + + +def test_spawn_rigid_body_material_from_fragments_accepts_single_fragment(): + from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + prim = spawn_rigid_body_material_from_fragments( + "/World/Mat2", UsdPhysicsRigidBodyMaterialCfg(static_friction=0.3), stage + ) + assert prim.IsA(UsdShade.Material) + assert bool(UsdPhysics.MaterialAPI(prim)) + assert prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.3) + + +def test_spawn_physics_material_dispatches_fragments_and_legacy(): + """The shared slot dispatcher handles both forms a spawner ``physics_material`` slot accepts: a + rigid-body fragment list, and a legacy material cfg carrying its own ``func``.""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials import spawn_physics_material + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + + # fragment-list form + frag_prim = spawn_physics_material("/World/MatA", [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4)]) + assert bool(UsdPhysics.MaterialAPI(frag_prim)) + assert frag_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.4) + + # legacy single-cfg form (RigidBodyMaterialBaseCfg subclass with its own spawner func) + legacy_prim = spawn_physics_material("/World/MatB", PhysxRigidBodyMaterialCfg(static_friction=0.9)) + assert bool(UsdPhysics.MaterialAPI(legacy_prim)) + assert legacy_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.9) + + +def test_spawn_rigid_body_material_from_fragments_leaves_none_fields_unwritten(): + from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + prim = spawn_rigid_body_material_from_fragments( + "/World/Mat3", [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.5)], stage + ) + # only the authored field is written; None fields are left unauthored (partial update) + assert prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.5) + assert not prim.GetAttribute("physics:dynamicFriction").HasAuthoredValue() diff --git a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst new file mode 100644 index 000000000000..76a9944f0d6e --- /dev/null +++ b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -0,0 +1,6 @@ +Added +^^^^^ + +* Added :class:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg`, a single-namespace + ``physxMaterial`` rigid-body physics-material fragment (compliant-contact spring stiffness/damping + and the friction/restitution combine-mode tokens) backing ``PhysxMaterialAPI``. diff --git a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/__init__.pyi b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/__init__.pyi index 315458ea5d24..7a018a14ecd6 100644 --- a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/__init__.pyi +++ b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/__init__.pyi @@ -7,6 +7,7 @@ __all__ = [ "DeformableBodyMaterialCfg", "PhysXDeformableMaterialCfg", "PhysxDeformableBodyMaterialCfg", + "PhysxMaterialCfg", "PhysxRigidBodyMaterialCfg", "PhysxSurfaceDeformableBodyMaterialCfg", "RigidBodyMaterialCfg", @@ -17,6 +18,7 @@ from .physics_materials_cfg import ( DeformableBodyMaterialCfg, PhysXDeformableMaterialCfg, PhysxDeformableBodyMaterialCfg, + PhysxMaterialCfg, PhysxRigidBodyMaterialCfg, PhysxSurfaceDeformableBodyMaterialCfg, RigidBodyMaterialCfg, diff --git a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py index 345fadc88704..26c0ae38a13b 100644 --- a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py @@ -12,6 +12,7 @@ from isaaclab.sim.spawners.materials.physics_materials_cfg import ( DeformableBodyMaterialBaseCfg, RigidBodyMaterialBaseCfg, + RigidBodyMaterialFragment, SurfaceDeformableBodyMaterialBaseCfg, ) from isaaclab.utils.configclass import configclass @@ -203,6 +204,43 @@ class PhysxRigidBodyMaterialCfg(RigidBodyMaterialBaseCfg): """ +@configclass +class PhysxMaterialCfg(RigidBodyMaterialFragment): + """``physxMaterial:*`` rigid-body material attributes from `PhysxMaterialAPI`_. + + Single-namespace fragment (see :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`) + for the PhysX-only material knobs: compliant-contact spring (stiffness/damping) and the + friction/restitution combine-mode tokens. The ``PhysxMaterialAPI`` schema is applied (and the + ``physxMaterial:*`` attributes authored) by the generic + :func:`~isaaclab.sim.schemas.apply_namespaced` writer. ``None`` fields are left unchanged. + + .. _PhysxMaterialAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/104.2/class_physx_schema_physx_material_a_p_i.html + """ + + _usd_namespace: ClassVar[str | None] = "physxMaterial" + _usd_applied_schema: ClassVar[str | None] = "PhysxMaterialAPI" + + compliant_contact_stiffness: float | None = None + """Spring stiffness for a compliant contact model using implicit springs. + + A higher stiffness results in behavior closer to a rigid contact. The compliant contact model is + only enabled if the stiffness is larger than 0. Writes ``physxMaterial:compliantContactStiffness``. + """ + + compliant_contact_damping: float | None = None + """Damping coefficient for a compliant contact model using implicit springs. + + Irrelevant if compliant contacts are disabled (``compliant_contact_stiffness`` is zero). Writes + ``physxMaterial:compliantContactDamping``. + """ + + friction_combine_mode: Literal["average", "min", "multiply", "max"] | None = None + """How friction is combined during collisions. Writes ``physxMaterial:frictionCombineMode``.""" + + restitution_combine_mode: Literal["average", "min", "multiply", "max"] | None = None + """How restitution is combined during collisions. Writes ``physxMaterial:restitutionCombineMode``.""" + + @configclass class RigidBodyMaterialCfg(PhysxRigidBodyMaterialCfg): """Deprecated: use :class:`PhysxRigidBodyMaterialCfg` or From 17d7c0a5e644740538c576d3c047597aa5a8350d Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Sat, 27 Jun 2026 23:59:50 -0700 Subject: [PATCH 02/19] Fix pre-commit lint in material fragment test Rename test prim paths MatA/MatB to MaterialA/MaterialB so codespell no longer flags the truncated tokens, and drop a stray blank line per ruff. --- source/isaaclab/test/sim/test_material_fragments.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 049ee8444ef8..aaab0ea851f0 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -19,7 +19,6 @@ import isaaclab.sim as sim_utils from isaaclab.sim import SimulationCfg, SimulationContext - # ------------------------------------------------------------------------------------- # RigidBodyMaterialFragment marker + metadata # ------------------------------------------------------------------------------------- @@ -112,12 +111,12 @@ def test_spawn_physics_material_dispatches_fragments_and_legacy(): SimulationContext(SimulationCfg(dt=0.01)) # fragment-list form - frag_prim = spawn_physics_material("/World/MatA", [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4)]) + frag_prim = spawn_physics_material("/World/MaterialA", [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4)]) assert bool(UsdPhysics.MaterialAPI(frag_prim)) assert frag_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.4) # legacy single-cfg form (RigidBodyMaterialBaseCfg subclass with its own spawner func) - legacy_prim = spawn_physics_material("/World/MatB", PhysxRigidBodyMaterialCfg(static_friction=0.9)) + legacy_prim = spawn_physics_material("/World/MaterialB", PhysxRigidBodyMaterialCfg(static_friction=0.9)) assert bool(UsdPhysics.MaterialAPI(legacy_prim)) assert legacy_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.9) From b8ba64ea9c29206242a96d31593e836ab18d36d2 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Sun, 28 Jun 2026 00:07:19 -0700 Subject: [PATCH 03/19] Clarify physics-material dispatcher stage and regex semantics Annotate the spawn_physics_material material parameter with its accepted union, document that the legacy dispatch path intentionally does not forward stage (legacy funcs resolve the stage internally), and note that the fragment writer expects a concrete prim path rather than a regex pattern. --- .../sim/spawners/materials/physics_materials.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index 2c51e737ee05..c56a9a057f52 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -30,6 +30,12 @@ def spawn_rigid_body_material_from_fragments( Backend fragments carry backend-specific namespaces (e.g. PhysX ``physxMaterial:*``) without core importing a backend. + .. note:: + Unlike the ``@clone``-decorated :func:`spawn_rigid_body_material`, this writer expects a + concrete ``prim_path`` and does not resolve regex prim-path patterns. Physics materials are + spawned at a single derived path by :func:`spawn_physics_material` and the spawner internals, + so regex resolution does not apply here. + Args: prim_path: The prim path to spawn the material at. fragments: A single :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list @@ -67,7 +73,9 @@ def spawn_rigid_body_material_from_fragments( def spawn_physics_material( prim_path: str, - material, + material: physics_materials_cfg.PhysicsMaterialCfg + | physics_materials_cfg.RigidBodyMaterialFragment + | list[physics_materials_cfg.RigidBodyMaterialFragment], stage: Usd.Stage | None = None, ) -> Usd.Prim: """Spawn a physics material from a spawner ``physics_material`` slot value. @@ -89,7 +97,10 @@ def spawn_physics_material( fragments = material if isinstance(material, (list, tuple)) else [material] if fragments and all(isinstance(f, physics_materials_cfg.RigidBodyMaterialFragment) for f in fragments): return spawn_rigid_body_material_from_fragments(prim_path, list(fragments), stage) - # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``) + # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``). + # NOTE: legacy material funcs take only ``(prim_path, cfg)`` and resolve the stage internally via + # ``get_current_stage()``; they have no ``stage`` parameter, so ``stage`` is intentionally not + # forwarded here. This is invisible in single-stage workflows (the only ones materials are used in). return material.func(prim_path, material) From bbf9c71bbac54097804da75868dffa844f7aec97 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Sun, 28 Jun 2026 00:26:42 -0700 Subject: [PATCH 04/19] Validate physics-material fragment lists in dispatcher Reject an empty list (ValueError) and a list containing non-fragment entries (TypeError) in spawn_physics_material, so a malformed slot value surfaces a clear error instead of an opaque AttributeError on the legacy path. Route a lone fragment through the fragment writer explicitly. Add a regression test for the empty and mixed-type cases. --- .../spawners/materials/physics_materials.py | 22 ++++++++++++++++--- .../test/sim/test_material_fragments.py | 20 +++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index c56a9a057f52..6bfaaebedbe4 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -93,10 +93,26 @@ def spawn_physics_material( Returns: The spawned material prim. + + Raises: + ValueError: When ``material`` is an empty list. + TypeError: When ``material`` is a list containing anything other than + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. """ - fragments = material if isinstance(material, (list, tuple)) else [material] - if fragments and all(isinstance(f, physics_materials_cfg.RigidBodyMaterialFragment) for f in fragments): - return spawn_rigid_body_material_from_fragments(prim_path, list(fragments), stage) + # a list/tuple slot value is the fragment-list form; validate it up front so a malformed list + # surfaces a clear error here rather than an opaque ``AttributeError`` on the legacy path below + if isinstance(material, (list, tuple)): + if not material: + raise ValueError(f"Cannot spawn a physics material at '{prim_path}' from an empty fragment list.") + if not all(isinstance(f, physics_materials_cfg.RigidBodyMaterialFragment) for f in material): + raise TypeError( + "A physics-material fragment list must contain only RigidBodyMaterialFragment instances; got" + f" {[type(f).__name__ for f in material]}." + ) + return spawn_rigid_body_material_from_fragments(prim_path, list(material), stage) + # a lone fragment routes through the fragment writer too + if isinstance(material, physics_materials_cfg.RigidBodyMaterialFragment): + return spawn_rigid_body_material_from_fragments(prim_path, [material], stage) # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``). # NOTE: legacy material funcs take only ``(prim_path, cfg)`` and resolve the stage internally via # ``get_current_stage()``; they have no ``stage`` parameter, so ``stage`` is intentionally not diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index aaab0ea851f0..11e46310465b 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -121,6 +121,26 @@ def test_spawn_physics_material_dispatches_fragments_and_legacy(): assert legacy_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.9) +def test_spawn_physics_material_rejects_empty_and_mixed_lists(): + """A malformed fragment list surfaces a clear error rather than an opaque AttributeError.""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials import spawn_physics_material + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + + with pytest.raises(ValueError): + spawn_physics_material("/World/MatEmpty", []) + # a list mixing a fragment with a legacy cfg is not a valid fragment list + with pytest.raises(TypeError): + spawn_physics_material( + "/World/MatMixed", + [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4), PhysxRigidBodyMaterialCfg(static_friction=0.9)], + ) + + def test_spawn_rigid_body_material_from_fragments_leaves_none_fields_unwritten(): from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg From a8bc6aab4f252b8a6cbbae67e5e95aab1d2ec0db Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Wed, 1 Jul 2026 09:22:00 -0700 Subject: [PATCH 05/19] Complete rigid-body material fragment family Address maintainer review on the physics-material fragment PR: - Add physics:density to UsdPhysicsRigidBodyMaterialCfg, completing its coverage of UsdPhysics.MaterialAPI's four attributes. - Add the two missing PhysxMaterialCfg fields (damping combine mode, compliant-contact acceleration spring) so the fragment covers all six PhysxMaterialAPI attributes; refresh the stale Kit 104.2 schema doc link to the current one. - Add a Newton rigid-body material fragment (NewtonMaterialCfg) for backend symmetry with the PhysX fragment, so torsional/rolling friction can compose in a fragment list alongside other backends. - Widen the mesh spawner's rigid-vs-deformable physics_material guard to accept fragments and fragment lists, not just the legacy cfg. - Widen GroundPlaneCfg.physics_material to the same fragment-aware union FileCfg already uses; its spawner already routed through the shared dispatcher, so only the annotation was stale. --- .../vidurv-schema-frag-materials.minor.rst | 13 ++ .../sim/spawners/from_files/from_files_cfg.py | 10 +- .../materials/physics_materials_cfg.py | 7 + .../isaaclab/sim/spawners/meshes/meshes.py | 17 ++- .../test/sim/test_material_fragments.py | 122 ++++++++++++++++++ .../vidurv-schema-frag-materials.minor.rst | 8 ++ .../isaaclab_newton/sim/__init__.pyi | 2 + .../sim/spawners/materials/__init__.pyi | 2 + .../materials/physics_materials_cfg.py | 35 +++++ .../test/sim/test_newton_schemas.py | 25 ++++ .../vidurv-schema-frag-materials.minor.rst | 6 + .../materials/physics_materials_cfg.py | 23 +++- 12 files changed, 264 insertions(+), 6 deletions(-) create mode 100644 source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst index f6f3a5101fd4..37160a947b6f 100644 --- a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -9,3 +9,16 @@ Added dispatcher :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`. Spawner ``physics_material`` slots now accept a list of single-namespace fragments in addition to the legacy material cfg. +* Added :attr:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg.density` (writes + ``physics:density``), completing the fragment's coverage of ``UsdPhysics.MaterialAPI``. + +Changed +^^^^^^^ + +* Widened the mesh spawner's rigid-vs-deformable physics-material guard in + :mod:`isaaclab.sim.spawners.meshes` to accept a + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list of them (previously + only the legacy rigid-body material cfg was accepted). +* Widened :attr:`~isaaclab.sim.spawners.from_files.GroundPlaneCfg.physics_material` to accept a + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list of them, matching + :attr:`~isaaclab.sim.spawners.from_files.FileCfg.physics_material`. diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py index 229dbd04cb33..7486a15bc0e5 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py @@ -267,5 +267,11 @@ class GroundPlaneCfg(SpawnerCfg): size: tuple[float, float] = (100.0, 100.0) """The size of the ground plane. Defaults to 100 m x 100 m.""" - physics_material: materials.RigidBodyMaterialCfg = materials.RigidBodyMaterialCfg() - """Physics material properties. Defaults to the default rigid body material.""" + physics_material: ( + materials.PhysicsMaterialCfg | materials.RigidBodyMaterialFragment | list[materials.RigidBodyMaterialFragment] + ) = materials.RigidBodyMaterialCfg() + """Physics material properties. Defaults to the default rigid body material. + + Accepts either a legacy material cfg or a list of single-namespace + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + """ diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py index 1e60101563d0..f3d3affdf63c 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py @@ -128,6 +128,13 @@ class UsdPhysicsRigidBodyMaterialCfg(RigidBodyMaterialFragment): restitution: float | None = None """The restitution coefficient. Writes ``physics:restitution``.""" + density: float | None = None + """The material density [kg/m^3]. Writes ``physics:density``. + + Participates in mass computation via material binding when the owning rigid body does not + define an explicit mass. + """ + @configclass class DeformableBodyMaterialBaseCfg(PhysicsMaterialCfg): diff --git a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py index c169e536e5e6..b08fc505cadf 100644 --- a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py +++ b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py @@ -16,7 +16,12 @@ from isaaclab.sim import schemas from isaaclab.sim.utils import bind_physics_material, bind_visual_material, clone, create_prim, get_current_stage -from ..materials import DeformableBodyMaterialBaseCfg, RigidBodyMaterialCfg, SurfaceDeformableBodyMaterialBaseCfg +from ..materials import ( + DeformableBodyMaterialBaseCfg, + RigidBodyMaterialCfg, + RigidBodyMaterialFragment, + SurfaceDeformableBodyMaterialBaseCfg, +) from ..materials.physics_materials import spawn_physics_material if TYPE_CHECKING: @@ -368,7 +373,15 @@ def _spawn_mesh_geom_from_mesh( if not isinstance(cfg.physics_material, DeformableBodyMaterialBaseCfg): raise ValueError("Deformable properties require a deformable physics material.") if cfg.rigid_props is not None and cfg.physics_material is not None: - if not isinstance(cfg.physics_material, RigidBodyMaterialCfg): + # accept anything spawn_physics_material accepts for the rigid case: a legacy rigid-body + # material cfg, a single fragment, or a list/tuple of fragments + physics_material_frags = ( + cfg.physics_material if isinstance(cfg.physics_material, (list, tuple)) else [cfg.physics_material] + ) + is_rigid_material = isinstance(cfg.physics_material, RigidBodyMaterialCfg) or all( + isinstance(frag, RigidBodyMaterialFragment) for frag in physics_material_frags + ) + if not is_rigid_material: raise ValueError("Rigid properties require a rigid physics material.") # create all the paths we need for clarity diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 11e46310465b..2468a00b13d0 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -154,3 +154,125 @@ def test_spawn_rigid_body_material_from_fragments_leaves_none_fields_unwritten() # only the authored field is written; None fields are left unauthored (partial update) assert prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.5) assert not prim.GetAttribute("physics:dynamicFriction").HasAuthoredValue() + + +# ------------------------------------------------------------------------------------- +# UsdPhysicsRigidBodyMaterialCfg: density round-trip + physics:* schema parity +# ------------------------------------------------------------------------------------- + + +def test_usd_physics_rigid_body_material_density_round_trips(): + """``physics:density`` participates in mass computation via material binding; it must author + the same as the other ``UsdPhysics.MaterialAPI`` friction/restitution fields.""" + from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + prim = spawn_rigid_body_material_from_fragments( + "/World/MatDensity", [UsdPhysicsRigidBodyMaterialCfg(density=1200.0)], stage + ) + assert prim.GetAttribute("physics:density").Get() == pytest.approx(1200.0) + + +def test_usd_physics_rigid_body_material_fragment_matches_material_api_schema(): + """Schema-parity guard: the set of ``physics:*`` attrs the neutral fragment can author must + equal the attribute set on ``UsdPhysics.MaterialAPI`` (4 attrs: static/dynamic friction, + restitution, density). Catches drift if the schema gains/loses an attribute.""" + import dataclasses + + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + from isaaclab.utils.string import to_camel_case + + fragment_fields = {f.name for f in dataclasses.fields(UsdPhysicsRigidBodyMaterialCfg) if f.name != "func"} + schema_attr_names = {name.split(":", 1)[1] for name in UsdPhysics.MaterialAPI.GetSchemaAttributeNames()} + fragment_attr_names = {to_camel_case(name, "cC") for name in fragment_fields} + assert fragment_attr_names == schema_attr_names + + +# ------------------------------------------------------------------------------------- +# PhysxMaterialCfg: damping-combine-mode + compliant-contact-acceleration-spring +# ------------------------------------------------------------------------------------- + + +def test_physx_material_fragment_authors_damping_combine_mode_and_acceleration_spring(): + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + prim = spawn_rigid_body_material_from_fragments( + "/World/MatPhysxExtra", + [PhysxMaterialCfg(damping_combine_mode="min", compliant_contact_acceleration_spring=True)], + stage, + ) + assert "PhysxMaterialAPI" in prim.GetAppliedSchemas() + assert prim.GetAttribute("physxMaterial:dampingCombineMode").Get() == "min" + assert prim.GetAttribute("physxMaterial:compliantContactAccelerationSpring").Get() is True + + +# ------------------------------------------------------------------------------------- +# Finding 4: mesh spawner must accept a fragment list for a rigid physics_material +# ------------------------------------------------------------------------------------- + + +def test_spawn_mesh_with_rigid_props_accepts_fragment_list_physics_material(): + """Regression test: the rigid-vs-deformable material guard in the mesh spawner used to reject + a fragment / fragment-list ``physics_material`` outright. A rigid-body fragment list must spawn + and bind successfully.""" + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + from isaaclab.sim.spawners.meshes.meshes_cfg import MeshCuboidCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + cfg = MeshCuboidCfg( + size=(1.0, 1.0, 1.0), + rigid_props=sim_utils.RigidBodyPropertiesCfg(), + collision_props=sim_utils.CollisionPropertiesCfg(), + physics_material=[UsdPhysicsRigidBodyMaterialCfg(static_friction=0.65, dynamic_friction=0.55)], + ) + prim = cfg.func("/World/MeshCubeFrag", cfg, stage=stage) + assert prim.IsValid() + material_prim = stage.GetPrimAtPath("/World/MeshCubeFrag/geometry/material") + assert material_prim.IsValid() + assert bool(UsdPhysics.MaterialAPI(material_prim)) + assert material_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.65) + # material binding: the mesh prim carries a physics-purpose material binding + binding_api = UsdShade.MaterialBindingAPI(stage.GetPrimAtPath("/World/MeshCubeFrag/geometry/mesh")) + bound_material, _ = binding_api.ComputeBoundMaterial(materialPurpose="physics") + assert bound_material.GetPath() == material_prim.GetPath() + + +# ------------------------------------------------------------------------------------- +# Finding 5: ground-plane spawner must accept a fragment-list physics_material +# ------------------------------------------------------------------------------------- + + +def test_spawn_ground_plane_accepts_fragment_list_physics_material(): + from isaaclab.sim.spawners.from_files.from_files_cfg import GroundPlaneCfg + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + cfg = GroundPlaneCfg(physics_material=[UsdPhysicsRigidBodyMaterialCfg(static_friction=0.42)]) + prim = cfg.func("/World/groundPlane", cfg) + assert prim.IsValid() + material_prim = stage.GetPrimAtPath("/World/groundPlane/physicsMaterial") + assert material_prim.IsValid() + assert bool(UsdPhysics.MaterialAPI(material_prim)) + assert material_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.42) + # the collision (Plane) prim under the ground plane must bind to the spawned material + from isaaclab.sim.utils import get_first_matching_child_prim + + collision_prim = get_first_matching_child_prim( + "/World/groundPlane", predicate=lambda _prim: _prim.GetTypeName() == "Plane", stage=stage + ) + assert collision_prim is not None + binding_api = UsdShade.MaterialBindingAPI(collision_prim) + bound_material, _ = binding_api.ComputeBoundMaterial(materialPurpose="physics") + assert bound_material.GetPath() == material_prim.GetPath() diff --git a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst new file mode 100644 index 000000000000..fafdcab16045 --- /dev/null +++ b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -0,0 +1,8 @@ +Added +^^^^^ + +* Added :class:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg`, a single-namespace + ``newton`` rigid-body physics-material fragment (torsional and rolling friction) backing + ``NewtonMaterialAPI``. Composes with other rigid-body material fragments (e.g. + :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in a fragment list. The + legacy :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` is unchanged. diff --git a/source/isaaclab_newton/isaaclab_newton/sim/__init__.pyi b/source/isaaclab_newton/isaaclab_newton/sim/__init__.pyi index 27677fbd6dbf..1e684304e810 100644 --- a/source/isaaclab_newton/isaaclab_newton/sim/__init__.pyi +++ b/source/isaaclab_newton/isaaclab_newton/sim/__init__.pyi @@ -7,6 +7,7 @@ __all__ = [ "NewtonDeformableBodyPropertiesCfg", "NewtonDeformableBodyMaterialCfg", "NewtonDeformableMaterialCfg", + "NewtonMaterialCfg", "NewtonSurfaceDeformableBodyMaterialCfg", "MPMGridCfg", "MPMParticleMaterialCfg", @@ -22,6 +23,7 @@ from .schemas import NewtonDeformableBodyPropertiesCfg from .spawners.materials import ( NewtonDeformableBodyMaterialCfg, NewtonDeformableMaterialCfg, + NewtonMaterialCfg, NewtonSurfaceDeformableBodyMaterialCfg, ) from .spawners.mpm import MPMGridCfg, MPMParticleMaterialCfg, MPMParticleSpawnerCfg, MPMPointsCfg diff --git a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/__init__.pyi b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/__init__.pyi index c3f13216f781..5ee626b240bd 100644 --- a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/__init__.pyi +++ b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/__init__.pyi @@ -7,6 +7,7 @@ __all__ = [ "spawn_deformable_body_material", "NewtonDeformableBodyMaterialCfg", "NewtonDeformableMaterialCfg", + "NewtonMaterialCfg", "NewtonSurfaceDeformableBodyMaterialCfg", ] @@ -14,5 +15,6 @@ from .physics_materials import spawn_deformable_body_material from .physics_materials_cfg import ( NewtonDeformableBodyMaterialCfg, NewtonDeformableMaterialCfg, + NewtonMaterialCfg, NewtonSurfaceDeformableBodyMaterialCfg, ) diff --git a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py index f7b63a8701c6..dd1be2a3d4dd 100644 --- a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py @@ -10,6 +10,7 @@ from isaaclab.sim.spawners.materials.physics_materials_cfg import ( DeformableBodyMaterialBaseCfg, + RigidBodyMaterialFragment, SurfaceDeformableBodyMaterialBaseCfg, ) from isaaclab.utils.configclass import configclass @@ -77,3 +78,37 @@ class NewtonSurfaceDeformableBodyMaterialCfg(SurfaceDeformableBodyMaterialBaseCf edge_kd: float = 1e-2 """Bending damping [N*m*s]. Used by Newton backend for cloth meshes.""" + + +@configclass +class NewtonMaterialCfg(RigidBodyMaterialFragment): + """``newton:*`` rigid-body material attributes from ``NewtonMaterialAPI``. + + Single-namespace fragment (see + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`) for the Newton-only + friction knobs: torsional and rolling friction. The ``NewtonMaterialAPI`` schema is applied + (and the ``newton:*`` attributes authored) by the generic + :func:`~isaaclab.sim.schemas.apply_namespaced` writer. ``None`` fields are left unchanged. + + Composes with other rigid-body material fragments (e.g. + :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in the same fragment + list passed to + :func:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material_from_fragments`. For the + legacy (non-fragment) equivalent, see + :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg`. + """ + + _usd_namespace: ClassVar[str | None] = "newton" + _usd_applied_schema: ClassVar[str | None] = "NewtonMaterialAPI" + + torsional_friction: float | None = None + """Torsional friction coefficient (resistance to spinning at a contact point) [dimensionless]. + + Writes ``newton:torsionalFriction``. Range: [0, inf). + """ + + rolling_friction: float | None = None + """Rolling friction coefficient (resistance to rolling motion) [dimensionless]. + + Writes ``newton:rollingFriction``. Range: [0, inf). + """ diff --git a/source/isaaclab_newton/test/sim/test_newton_schemas.py b/source/isaaclab_newton/test/sim/test_newton_schemas.py index 1774792d3d03..2c4113c90b95 100644 --- a/source/isaaclab_newton/test/sim/test_newton_schemas.py +++ b/source/isaaclab_newton/test/sim/test_newton_schemas.py @@ -164,6 +164,31 @@ def test_newton_material_no_schema_when_none(setup_sim): assert "NewtonMaterialAPI" not in prim.GetAppliedSchemas() +@pytest.mark.isaacsim_ci +def test_newton_material_fragment_composes_with_usd_physics_fragment(setup_sim): + """NewtonMaterialCfg is a rigid-body material fragment (backend symmetry with the PhysX + fragment): it must compose in a fragment list with UsdPhysicsRigidBodyMaterialCfg and author + both the ``newton:*`` and solver-common ``physics:*`` namespaces on the same material prim.""" + from isaaclab_newton.sim.spawners.materials import NewtonMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials import spawn_rigid_body_material_from_fragments + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + prim = spawn_rigid_body_material_from_fragments( + "/World/newton_mat_frag", + [ + UsdPhysicsRigidBodyMaterialCfg(static_friction=0.6, dynamic_friction=0.5), + NewtonMaterialCfg(torsional_friction=0.3, rolling_friction=0.001), + ], + ) + assert bool(UsdPhysics.MaterialAPI(prim)) + assert prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.6) + assert prim.GetAttribute("physics:dynamicFriction").Get() == pytest.approx(0.5) + assert "NewtonMaterialAPI" in prim.GetAppliedSchemas() + assert prim.GetAttribute("newton:torsionalFriction").Get() == pytest.approx(0.3) + assert prim.GetAttribute("newton:rollingFriction").Get() == pytest.approx(0.001) + + # --------------------------------------------------------------------------- # Newton articulation root # --------------------------------------------------------------------------- diff --git a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst index 76a9944f0d6e..b580d3ad6316 100644 --- a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -4,3 +4,9 @@ Added * Added :class:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg`, a single-namespace ``physxMaterial`` rigid-body physics-material fragment (compliant-contact spring stiffness/damping and the friction/restitution combine-mode tokens) backing ``PhysxMaterialAPI``. +* Added :attr:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg.damping_combine_mode` (writes + ``physxMaterial:dampingCombineMode``) and + :attr:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg.compliant_contact_acceleration_spring` + (writes ``physxMaterial:compliantContactAccelerationSpring``), completing the fragment's coverage + of ``PhysxMaterialAPI``. Also added the same two fields to the legacy + :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. diff --git a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py index 26c0ae38a13b..2fba37b40e61 100644 --- a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py @@ -160,7 +160,7 @@ class PhysxRigidBodyMaterialCfg(RigidBodyMaterialBaseCfg): See :meth:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material` for more information. - .. _PhysxMaterialAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/104.2/class_physx_schema_physx_material_a_p_i.html + .. _PhysxMaterialAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/latest/class_physx_schema_physx_material_a_p_i.html """ # -- Class metadata (not dataclass fields) -- @@ -214,7 +214,7 @@ class PhysxMaterialCfg(RigidBodyMaterialFragment): ``physxMaterial:*`` attributes authored) by the generic :func:`~isaaclab.sim.schemas.apply_namespaced` writer. ``None`` fields are left unchanged. - .. _PhysxMaterialAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/104.2/class_physx_schema_physx_material_a_p_i.html + .. _PhysxMaterialAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/latest/class_physx_schema_physx_material_a_p_i.html """ _usd_namespace: ClassVar[str | None] = "physxMaterial" @@ -234,12 +234,31 @@ class PhysxMaterialCfg(RigidBodyMaterialFragment): ``physxMaterial:compliantContactDamping``. """ + compliant_contact_acceleration_spring: bool | None = None + """Whether the compliant contact spring is formulated in acceleration (rather than force) units. + + Writes ``physxMaterial:compliantContactAccelerationSpring``. Only relevant when compliant + contacts are enabled (:attr:`compliant_contact_stiffness` is non-zero). + """ + friction_combine_mode: Literal["average", "min", "multiply", "max"] | None = None """How friction is combined during collisions. Writes ``physxMaterial:frictionCombineMode``.""" restitution_combine_mode: Literal["average", "min", "multiply", "max"] | None = None """How restitution is combined during collisions. Writes ``physxMaterial:restitutionCombineMode``.""" + damping_combine_mode: Literal["average", "min", "multiply", "max"] | None = None + """How the (compliant-contact) damping coefficient is combined during collisions. + + Writes ``physxMaterial:dampingCombineMode``. + + .. attention:: + + When two physics materials with different combine modes collide, the combine mode with + the higher priority will be used. The priority order is provided `here + `__. + """ + @configclass class RigidBodyMaterialCfg(PhysxRigidBodyMaterialCfg): From 2d70ad4a37df844f3981f7f936133fc6869be643 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 09:11:35 -0700 Subject: [PATCH 06/19] Fix rigid-material guard bugs from prior review fix The mesh spawner's rigid-vs-deformable guard checked isinstance against the deprecated RigidBodyMaterialCfg leaf alias instead of the neutral RigidBodyMaterialBaseCfg, wrongly rejecting the canonical PhysxRigidBodyMaterialCfg and Newton's legacy NewtonMaterialPropertiesCfg. GroundPlaneCfg.physics_material was widened to the common PhysicsMaterialCfg base, which also advertises deformable materials on a rigid-only ground plane. Narrow both to RigidBodyMaterialBaseCfg. Also close two gaps flagged in review: add the four newton:* contact attributes (contactStiffness/contactDamping/contactFrictionGain/ contactAdhesion) that Newton's pinned-commit USD schema resolver reads in place of the deprecated per-shape ke/kd/kf/ka parameters, and add damping_combine_mode / compliant_contact_acceleration_spring to the legacy PhysxRigidBodyMaterialCfg so it matches the changelog's existing claim of parity with the PhysxMaterialCfg fragment. --- .../vidurv-schema-frag-materials.minor.rst | 12 +-- .../sim/spawners/from_files/from_files_cfg.py | 9 +- .../isaaclab/sim/spawners/meshes/meshes.py | 4 +- .../test/sim/test_material_fragments.py | 87 +++++++++++++++++++ .../vidurv-schema-frag-materials.minor.rst | 7 ++ .../materials/physics_materials_cfg.py | 44 +++++++++- .../test/sim/test_newton_schemas.py | 32 +++++++ .../materials/physics_materials_cfg.py | 17 ++++ 8 files changed, 198 insertions(+), 14 deletions(-) diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst index 37160a947b6f..18764b2957fe 100644 --- a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -16,9 +16,11 @@ Changed ^^^^^^^ * Widened the mesh spawner's rigid-vs-deformable physics-material guard in - :mod:`isaaclab.sim.spawners.meshes` to accept a - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list of them (previously - only the legacy rigid-body material cfg was accepted). + :mod:`isaaclab.sim.spawners.meshes` to accept any + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` (legacy cfg) or + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or a list of the latter), + instead of only the deprecated ``RigidBodyMaterialCfg`` alias. * Widened :attr:`~isaaclab.sim.spawners.from_files.GroundPlaneCfg.physics_material` to accept a - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list of them, matching - :attr:`~isaaclab.sim.spawners.from_files.FileCfg.physics_material`. + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` (legacy cfg) or a + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or a list of the latter), + since the ground plane only spawns a rigid collision plane. diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py index 7486a15bc0e5..4276c0880a1f 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py @@ -268,10 +268,13 @@ class GroundPlaneCfg(SpawnerCfg): """The size of the ground plane. Defaults to 100 m x 100 m.""" physics_material: ( - materials.PhysicsMaterialCfg | materials.RigidBodyMaterialFragment | list[materials.RigidBodyMaterialFragment] + materials.RigidBodyMaterialBaseCfg + | materials.RigidBodyMaterialFragment + | list[materials.RigidBodyMaterialFragment] ) = materials.RigidBodyMaterialCfg() """Physics material properties. Defaults to the default rigid body material. - Accepts either a legacy material cfg or a list of single-namespace - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + The ground plane only spawns a collision plane, so this only accepts rigid-body materials: a + legacy :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` or a list of + single-namespace :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. """ diff --git a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py index b08fc505cadf..f46d06c68560 100644 --- a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py +++ b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py @@ -18,7 +18,7 @@ from ..materials import ( DeformableBodyMaterialBaseCfg, - RigidBodyMaterialCfg, + RigidBodyMaterialBaseCfg, RigidBodyMaterialFragment, SurfaceDeformableBodyMaterialBaseCfg, ) @@ -378,7 +378,7 @@ def _spawn_mesh_geom_from_mesh( physics_material_frags = ( cfg.physics_material if isinstance(cfg.physics_material, (list, tuple)) else [cfg.physics_material] ) - is_rigid_material = isinstance(cfg.physics_material, RigidBodyMaterialCfg) or all( + is_rigid_material = isinstance(cfg.physics_material, RigidBodyMaterialBaseCfg) or all( isinstance(frag, RigidBodyMaterialFragment) for frag in physics_material_frags ) if not is_rigid_material: diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 2468a00b13d0..0688ae6eadae 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -276,3 +276,90 @@ def test_spawn_ground_plane_accepts_fragment_list_physics_material(): binding_api = UsdShade.MaterialBindingAPI(collision_prim) bound_material, _ = binding_api.ComputeBoundMaterial(materialPurpose="physics") assert bound_material.GetPath() == material_prim.GetPath() + + +# ------------------------------------------------------------------------------------- +# Regression: the mesh spawner's rigid-material guard must also accept legacy (non-fragment) +# rigid-body material cfgs, not just the deprecated ``RigidBodyMaterialCfg`` alias. +# ------------------------------------------------------------------------------------- + + +def test_spawn_mesh_with_rigid_props_accepts_legacy_physx_rigid_body_material(): + """Regression test: the mesh guard used to check ``isinstance(cfg.physics_material, + RigidBodyMaterialCfg)`` -- the deprecated PhysX leaf alias -- which rejected the canonical + legacy :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg` even though + :func:`~isaaclab.sim.spawners.materials.spawn_physics_material` accepts it.""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg + + from isaaclab.sim.spawners.meshes.meshes_cfg import MeshCuboidCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + cfg = MeshCuboidCfg( + size=(1.0, 1.0, 1.0), + rigid_props=sim_utils.RigidBodyPropertiesCfg(), + collision_props=sim_utils.CollisionPropertiesCfg(), + physics_material=PhysxRigidBodyMaterialCfg(static_friction=0.65, dynamic_friction=0.55), + ) + prim = cfg.func("/World/MeshCubeLegacyPhysx", cfg, stage=stage) + assert prim.IsValid() + material_prim = stage.GetPrimAtPath("/World/MeshCubeLegacyPhysx/geometry/material") + assert material_prim.IsValid() + assert bool(UsdPhysics.MaterialAPI(material_prim)) + assert material_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.65) + binding_api = UsdShade.MaterialBindingAPI(stage.GetPrimAtPath("/World/MeshCubeLegacyPhysx/geometry/mesh")) + bound_material, _ = binding_api.ComputeBoundMaterial(materialPurpose="physics") + assert bound_material.GetPath() == material_prim.GetPath() + + +def test_spawn_mesh_with_rigid_props_accepts_legacy_newton_material(): + """Same regression as above for Newton's legacy rigid-body material cfg, which also derives + from :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` (not the deprecated + PhysX ``RigidBodyMaterialCfg`` alias) and must not be rejected by the mesh guard.""" + from isaaclab_newton.sim.schemas import NewtonMaterialPropertiesCfg + + from isaaclab.sim.spawners.meshes.meshes_cfg import MeshCuboidCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() + cfg = MeshCuboidCfg( + size=(1.0, 1.0, 1.0), + rigid_props=sim_utils.RigidBodyPropertiesCfg(), + collision_props=sim_utils.CollisionPropertiesCfg(), + physics_material=NewtonMaterialPropertiesCfg(torsional_friction=0.3, rolling_friction=0.001), + ) + prim = cfg.func("/World/MeshCubeLegacyNewton", cfg, stage=stage) + assert prim.IsValid() + material_prim = stage.GetPrimAtPath("/World/MeshCubeLegacyNewton/geometry/material") + assert material_prim.IsValid() + assert bool(UsdPhysics.MaterialAPI(material_prim)) + assert material_prim.GetAttribute("newton:torsionalFriction").Get() == pytest.approx(0.3) + assert material_prim.GetAttribute("newton:rollingFriction").Get() == pytest.approx(0.001) + binding_api = UsdShade.MaterialBindingAPI(stage.GetPrimAtPath("/World/MeshCubeLegacyNewton/geometry/mesh")) + bound_material, _ = binding_api.ComputeBoundMaterial(materialPurpose="physics") + assert bound_material.GetPath() == material_prim.GetPath() + + +# ------------------------------------------------------------------------------------- +# PhysxRigidBodyMaterialCfg (legacy): damping-combine-mode + compliant-contact-acceleration-spring +# ------------------------------------------------------------------------------------- + + +def test_legacy_physx_rigid_body_material_authors_damping_combine_mode_and_acceleration_spring(): + """The legacy :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg` must + author the same two ``physxMaterial:*`` attributes as the + :class:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg` fragment, since the legacy + spawner is metadata-driven off the same ``physxMaterial`` namespace.""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg + + from isaaclab.sim.spawners.materials import spawn_rigid_body_material + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + cfg = PhysxRigidBodyMaterialCfg(damping_combine_mode="min", compliant_contact_acceleration_spring=True) + prim = spawn_rigid_body_material("/World/MatLegacyPhysxExtra", cfg) + assert "PhysxMaterialAPI" in prim.GetAppliedSchemas() + assert prim.GetAttribute("physxMaterial:dampingCombineMode").Get() == "min" + assert prim.GetAttribute("physxMaterial:compliantContactAccelerationSpring").Get() is True diff --git a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst index fafdcab16045..57eaf596d27a 100644 --- a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -6,3 +6,10 @@ Added ``NewtonMaterialAPI``. Composes with other rigid-body material fragments (e.g. :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in a fragment list. The legacy :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` is unchanged. +* Added :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_stiffness`, + :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_damping`, + :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_friction_gain`, and + :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_adhesion` (writing + ``newton:contactStiffness``, ``newton:contactDamping``, ``newton:contactFrictionGain``, and + ``newton:contactAdhesion``), matching the per-material contact attributes Newton's USD schema + resolver reads in place of the deprecated per-shape ``ke``/``kd``/``kf``/``ka`` parameters. diff --git a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py index dd1be2a3d4dd..451964d4c2ce 100644 --- a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py @@ -82,13 +82,20 @@ class NewtonSurfaceDeformableBodyMaterialCfg(SurfaceDeformableBodyMaterialBaseCf @configclass class NewtonMaterialCfg(RigidBodyMaterialFragment): - """``newton:*`` rigid-body material attributes from ``NewtonMaterialAPI``. + """``newton:*`` rigid-body material attributes read by Newton's USD material schema resolver. Single-namespace fragment (see :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`) for the Newton-only - friction knobs: torsional and rolling friction. The ``NewtonMaterialAPI`` schema is applied - (and the ``newton:*`` attributes authored) by the generic - :func:`~isaaclab.sim.schemas.apply_namespaced` writer. ``None`` fields are left unchanged. + friction knobs (torsional and rolling friction) and the per-material contact model (contact + stiffness/damping, friction gain, adhesion) that replaces the deprecated per-shape + ``ke``/``kd``/``kf``/``ka`` parameters. The ``NewtonMaterialAPI`` schema is applied (and the + ``newton:*`` attributes authored) by the generic :func:`~isaaclab.sim.schemas.apply_namespaced` + writer. ``None`` fields are left unchanged. + + .. note:: + The generated ``NewtonMaterialAPI`` USD schema currently only declares the two friction + attributes; the four contact attributes are still authored as raw ``newton:*`` USD + attributes and are read directly by Newton's schema resolver. Composes with other rigid-body material fragments (e.g. :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in the same fragment @@ -112,3 +119,32 @@ class NewtonMaterialCfg(RigidBodyMaterialFragment): Writes ``newton:rollingFriction``. Range: [0, inf). """ + + contact_stiffness: float | None = None + """Contact normal-force stiffness [N/m]. + + Writes ``newton:contactStiffness``. Replaces the deprecated per-shape ``ke`` contact parameter; + used by the SemiImplicit, Featherstone, MuJoCo, and VBD solvers. + """ + + contact_damping: float | None = None + """Contact normal-force damping coefficient [N·s/m]. + + Writes ``newton:contactDamping``. Replaces the deprecated per-shape ``kd`` contact parameter; + used by the SemiImplicit, Featherstone, MuJoCo, and VBD solvers. + """ + + contact_friction_gain: float | None = None + """Friction-force stiffness gain used by the tangential (friction) contact response [N/m]. + + Writes ``newton:contactFrictionGain``. Replaces the deprecated per-shape ``kf`` contact + parameter; used by the SemiImplicit and Featherstone solvers. + """ + + contact_adhesion: float | None = None + """Contact adhesion distance: shapes closer than this threshold experience an attractive + (adhesive) force [m]. + + Writes ``newton:contactAdhesion``. Replaces the deprecated per-shape ``ka`` contact parameter; + used by the SemiImplicit and Featherstone solvers. + """ diff --git a/source/isaaclab_newton/test/sim/test_newton_schemas.py b/source/isaaclab_newton/test/sim/test_newton_schemas.py index 2c4113c90b95..57e0f57e3f63 100644 --- a/source/isaaclab_newton/test/sim/test_newton_schemas.py +++ b/source/isaaclab_newton/test/sim/test_newton_schemas.py @@ -189,6 +189,38 @@ def test_newton_material_fragment_composes_with_usd_physics_fragment(setup_sim): assert prim.GetAttribute("newton:rollingFriction").Get() == pytest.approx(0.001) +@pytest.mark.isaacsim_ci +def test_newton_material_fragment_authors_all_six_newton_attrs(setup_sim): + """Regression test: Newton's USD material schema resolver (``SchemaResolverNewton``) reads six + ``newton:*`` material attributes -- the two friction knobs plus four contact-model attributes + (``contactStiffness``/``contactDamping``/``contactFrictionGain``/``contactAdhesion``) that + replace the deprecated per-shape ``ke``/``kd``/``kf``/``ka`` parameters. All six must round-trip + through :class:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg`, even though the + generated ``NewtonMaterialAPI`` schema currently only declares the two friction attributes.""" + from isaaclab_newton.sim.spawners.materials import NewtonMaterialCfg + + from isaaclab.sim.spawners.materials import spawn_rigid_body_material_from_fragments + + prim = spawn_rigid_body_material_from_fragments( + "/World/newton_mat_contact", + NewtonMaterialCfg( + torsional_friction=0.3, + rolling_friction=0.001, + contact_stiffness=2500.0, + contact_damping=100.0, + contact_friction_gain=1000.0, + contact_adhesion=0.01, + ), + ) + assert "NewtonMaterialAPI" in prim.GetAppliedSchemas() + assert prim.GetAttribute("newton:torsionalFriction").Get() == pytest.approx(0.3) + assert prim.GetAttribute("newton:rollingFriction").Get() == pytest.approx(0.001) + assert prim.GetAttribute("newton:contactStiffness").Get() == pytest.approx(2500.0) + assert prim.GetAttribute("newton:contactDamping").Get() == pytest.approx(100.0) + assert prim.GetAttribute("newton:contactFrictionGain").Get() == pytest.approx(1000.0) + assert prim.GetAttribute("newton:contactAdhesion").Get() == pytest.approx(0.01) + + # --------------------------------------------------------------------------- # Newton articulation root # --------------------------------------------------------------------------- diff --git a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py index 2fba37b40e61..9914563e7a17 100644 --- a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py @@ -183,6 +183,13 @@ class PhysxRigidBodyMaterialCfg(RigidBodyMaterialBaseCfg): to zero and rigid contacts are active. PhysX-only; not consumed by Newton. """ + compliant_contact_acceleration_spring: bool | None = None + """Whether the compliant contact spring is formulated in acceleration (rather than force) units. + + Only relevant when compliant contacts are enabled (:attr:`compliant_contact_stiffness` is + non-zero). PhysX-only; not consumed by Newton. + """ + friction_combine_mode: Literal["average", "min", "multiply", "max"] | None = None """Determines the way friction will be combined during collisions. @@ -203,6 +210,16 @@ class PhysxRigidBodyMaterialCfg(RigidBodyMaterialBaseCfg): `__. """ + damping_combine_mode: Literal["average", "min", "multiply", "max"] | None = None + """Determines the way the (compliant-contact) damping coefficient is combined during collisions. + + .. attention:: + + When two physics materials with different combine modes collide, the combine mode with + the higher priority will be used. The priority order is provided `here + `__. + """ + @configclass class PhysxMaterialCfg(RigidBodyMaterialFragment): From bb3226f2d2178dfd6c6647e925d3f05dde6e9076 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 22:44:37 -0700 Subject: [PATCH 07/19] Add density to the legacy rigid material base cfg RigidBodyMaterialBaseCfg previously exposed only friction and restitution, while the newer UsdPhysicsRigidBodyMaterialCfg fragment also authors density. This left the legacy and fragment paths non-interchangeable and meant Newton's importer, which reads material density, silently ignored it when configs used the legacy base class. --- .../materials/physics_materials_cfg.py | 7 +++++++ .../test/sim/test_material_fragments.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py index f3d3affdf63c..e97138389545 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py @@ -89,6 +89,13 @@ class RigidBodyMaterialBaseCfg(PhysicsMaterialCfg): restitution: float = 0.0 """The restitution coefficient. Defaults to 0.0.""" + density: float | None = None + """The material density [kg/m^3]. Defaults to None, in which case it is not authored. + + Writes ``physics:density``. When authored, this overrides body-level density for computing + the mass of collision shapes bound to this material. + """ + @configclass class RigidBodyMaterialFragment(SchemaFragment): diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 0688ae6eadae..e6555d0225e6 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -363,3 +363,21 @@ def test_legacy_physx_rigid_body_material_authors_damping_combine_mode_and_accel assert "PhysxMaterialAPI" in prim.GetAppliedSchemas() assert prim.GetAttribute("physxMaterial:dampingCombineMode").Get() == "min" assert prim.GetAttribute("physxMaterial:compliantContactAccelerationSpring").Get() is True + + +def test_legacy_base_cfg_authors_density(): + """The legacy rigid material base authors ``physics:density``, matching the USD fragment. + + ``UsdPhysics.MaterialAPI`` defines four properties; the legacy base must author all four so + fragment and legacy paths stay interchangeable (Newton's importer reads material density). + """ + from isaaclab.sim.spawners.materials import spawn_rigid_body_material + from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialBaseCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + prim = spawn_rigid_body_material("/World/LegacyDensity", RigidBodyMaterialBaseCfg(density=800.0)) + assert prim.GetAttribute("physics:density").Get() == pytest.approx(800.0) + # None default -> unauthored (backward compatible) + prim2 = spawn_rigid_body_material("/World/LegacyDensityNone", RigidBodyMaterialBaseCfg()) + assert not prim2.GetAttribute("physics:density").HasAuthoredValue() From 85592afc4fe3da86776d0ae34f0c0f74dea76fd1 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 22:49:30 -0700 Subject: [PATCH 08/19] Add Newton contact attrs to the legacy material cfg Give NewtonMaterialPropertiesCfg the same four contact-model attributes (stiffness, damping, friction gain, adhesion) already authored by the NewtonMaterialCfg fragment, keeping the legacy and fragment configs in parity. Also corrects the contact_friction_gain docstring unit from N/m to N*s/m in both classes. --- .../sim/schemas/schemas_cfg.py | 29 +++++++++++++++++++ .../materials/physics_materials_cfg.py | 2 +- .../test/sim/test_newton_schemas.py | 13 +++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/source/isaaclab_newton/isaaclab_newton/sim/schemas/schemas_cfg.py b/source/isaaclab_newton/isaaclab_newton/sim/schemas/schemas_cfg.py index 05d63921efde..86485af3aa7f 100644 --- a/source/isaaclab_newton/isaaclab_newton/sim/schemas/schemas_cfg.py +++ b/source/isaaclab_newton/isaaclab_newton/sim/schemas/schemas_cfg.py @@ -501,6 +501,35 @@ class NewtonMaterialPropertiesCfg(RigidBodyMaterialBaseCfg): Range: [0, inf). """ + contact_stiffness: float | None = None + """Contact normal-force stiffness [N/m]. + + Writes ``newton:contactStiffness``. Replaces the deprecated per-shape ``ke`` contact parameter; + used by the SemiImplicit, Featherstone, MuJoCo, and VBD solvers. + """ + + contact_damping: float | None = None + """Contact normal-force damping coefficient [N·s/m]. + + Writes ``newton:contactDamping``. Replaces the deprecated per-shape ``kd`` contact parameter; + used by the SemiImplicit, Featherstone, MuJoCo, and VBD solvers. + """ + + contact_friction_gain: float | None = None + """Friction-force stiffness gain used by the tangential (friction) contact response [N·s/m]. + + Writes ``newton:contactFrictionGain``. Replaces the deprecated per-shape ``kf`` contact + parameter; used by the SemiImplicit and Featherstone solvers. + """ + + contact_adhesion: float | None = None + """Contact adhesion distance: shapes closer than this threshold experience an attractive + (adhesive) force [m]. + + Writes ``newton:contactAdhesion``. Replaces the deprecated per-shape ``ka`` contact parameter; + used by the SemiImplicit and Featherstone solvers. + """ + @configclass class MujocoFixedTendonCfg(FixedTendonFragment): diff --git a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py index 451964d4c2ce..e0027a815530 100644 --- a/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_newton/isaaclab_newton/sim/spawners/materials/physics_materials_cfg.py @@ -135,7 +135,7 @@ class NewtonMaterialCfg(RigidBodyMaterialFragment): """ contact_friction_gain: float | None = None - """Friction-force stiffness gain used by the tangential (friction) contact response [N/m]. + """Friction-force stiffness gain used by the tangential (friction) contact response [N·s/m]. Writes ``newton:contactFrictionGain``. Replaces the deprecated per-shape ``kf`` contact parameter; used by the SemiImplicit and Featherstone solvers. diff --git a/source/isaaclab_newton/test/sim/test_newton_schemas.py b/source/isaaclab_newton/test/sim/test_newton_schemas.py index 57e0f57e3f63..237d40795e55 100644 --- a/source/isaaclab_newton/test/sim/test_newton_schemas.py +++ b/source/isaaclab_newton/test/sim/test_newton_schemas.py @@ -404,3 +404,16 @@ def test_newton_mesh_collision_mixed_namespace_write(setup_sim): applied = prim.GetAppliedSchemas() assert "NewtonCollisionAPI" in applied assert "NewtonMeshCollisionAPI" in applied + + +@pytest.mark.isaacsim_ci +def test_newton_legacy_cfg_authors_contact_attrs(setup_sim): + """The legacy Newton material cfg authors all newton:* attributes the fragment authors.""" + mat_cfg = NewtonMaterialPropertiesCfg( + contact_stiffness=1.0e4, contact_damping=250.0, contact_friction_gain=40.0, contact_adhesion=0.02 + ) + prim = spawn_rigid_body_material("/World/newton_mat_contact", mat_cfg) + assert prim.GetAttribute("newton:contactStiffness").Get() == pytest.approx(1.0e4) + assert prim.GetAttribute("newton:contactDamping").Get() == pytest.approx(250.0) + assert prim.GetAttribute("newton:contactFrictionGain").Get() == pytest.approx(40.0) + assert prim.GetAttribute("newton:contactAdhesion").Get() == pytest.approx(0.02) From 435240ed3f401c57041d90f07fb161f58c392d0c Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 22:56:19 -0700 Subject: [PATCH 09/19] Route generated-terrain material through the dispatcher Generated-terrain mesh spawning called the physics material cfg's func directly, crashing with AttributeError when given a fragment list. Route it through spawn_physics_material instead, and widen TerrainImporterCfg.physics_material to accept a legacy cfg, a single fragment, or a fragment list. --- .../isaaclab/terrains/terrain_importer_cfg.py | 9 +++++- source/isaaclab/isaaclab/terrains/utils.py | 11 +++---- .../test/sim/test_material_fragments.py | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py b/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py index db34c9a17195..4ead3e39e8d5 100644 --- a/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py +++ b/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py @@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Literal import isaaclab.sim as sim_utils +from isaaclab.sim.spawners import materials from isaaclab.utils.configclass import configclass if TYPE_CHECKING: @@ -87,13 +88,19 @@ class TerrainImporterCfg: to the grid color of the imported ground plane. """ - physics_material: sim_utils.RigidBodyMaterialCfg = sim_utils.RigidBodyMaterialCfg() + physics_material: ( + materials.RigidBodyMaterialBaseCfg + | materials.RigidBodyMaterialFragment + | list[materials.RigidBodyMaterialFragment] + ) = materials.RigidBodyMaterialBaseCfg() """The physics material of the terrain. Defaults to a default physics material. The material is created at the path: ``{prim_path}/physicsMaterial``. .. note:: This parameter is used only when the ``terrain_type`` is "generator" or "plane". + + Accepts a legacy rigid material cfg or a list of rigid-material fragments. """ max_init_terrain_level: int | None = None diff --git a/source/isaaclab/isaaclab/terrains/utils.py b/source/isaaclab/isaaclab/terrains/utils.py index 739f80940021..1d708dfe2dcc 100644 --- a/source/isaaclab/isaaclab/terrains/utils.py +++ b/source/isaaclab/isaaclab/terrains/utils.py @@ -14,6 +14,7 @@ from pxr import UsdGeom import isaaclab.sim as sim_utils +from isaaclab.sim.spawners.materials import spawn_physics_material from isaaclab.utils.warp import raycast_mesh @@ -80,7 +81,8 @@ def create_prim_from_mesh(prim_path: str, mesh: trimesh.Trimesh, **kwargs): translation: The translation of the terrain. Defaults to None. orientation: The orientation of the terrain. Defaults to None. visual_material: The visual material to apply. Defaults to None. - physics_material: The physics material to apply. Defaults to None. + physics_material: The physics material to apply. Defaults to None. Accepts a legacy rigid + material cfg or a list of rigid-material fragments. """ # create parent prim sim_utils.create_prim(prim_path, "Xform") @@ -122,10 +124,9 @@ def create_prim_from_mesh(prim_path: str, mesh: trimesh.Trimesh, **kwargs): visual_material_cfg.func(f"{prim_path}/visualMaterial", visual_material_cfg) sim_utils.bind_visual_material(prim.GetPrimPath(), f"{prim_path}/visualMaterial") # create physics material - if kwargs.get("physics_material") is not None: - physics_material_cfg: sim_utils.RigidBodyMaterialCfg = kwargs.get("physics_material") - # spawn the material - physics_material_cfg.func(f"{prim_path}/physicsMaterial", physics_material_cfg) + physics_material = kwargs.get("physics_material") + if physics_material is not None: + spawn_physics_material(f"{prim_path}/physicsMaterial", physics_material) sim_utils.bind_physics_material(prim.GetPrimPath(), f"{prim_path}/physicsMaterial") diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index e6555d0225e6..25d17672c8ec 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -365,6 +365,35 @@ def test_legacy_physx_rigid_body_material_authors_damping_combine_mode_and_accel assert prim.GetAttribute("physxMaterial:compliantContactAccelerationSpring").Get() is True +# ------------------------------------------------------------------------------------- +# Generated-terrain routing: create_prim_from_mesh must accept a fragment-list physics_material +# ------------------------------------------------------------------------------------- + + +def test_create_prim_from_mesh_accepts_fragment_list(): + """Generated terrain routes its material through the dispatcher, so a fragment list works + end-to-end instead of crashing on the legacy-only spawn path.""" + import trimesh + from isaaclab_newton.sim.spawners.materials.physics_materials_cfg import NewtonMaterialCfg + + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + from isaaclab.terrains.utils import create_prim_from_mesh + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + mesh = trimesh.creation.box(extents=(1.0, 1.0, 0.2)) + create_prim_from_mesh( + "/World/terrainFrag", + mesh, + physics_material=[UsdPhysicsRigidBodyMaterialCfg(static_friction=0.9), NewtonMaterialCfg(rolling_friction=0.1)], + ) + stage = sim_utils.get_current_stage() + mat = stage.GetPrimAtPath("/World/terrainFrag/physicsMaterial") + assert mat.IsValid() + assert mat.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.9) + assert mat.GetAttribute("newton:rollingFriction").Get() == pytest.approx(0.1) + + def test_legacy_base_cfg_authors_density(): """The legacy rigid material base authors ``physics:density``, matching the USD fragment. From e0e647d78b2f73a20f77b491b8c3791462aff15d Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:08:20 -0700 Subject: [PATCH 10/19] Route the default physics material through the dispatcher Widen SimulationCfg.physics_material to accept the fragment forms (a single rigid-body fragment or list of them) in addition to a legacy material cfg, and have the PhysX manager spawn it through spawn_physics_material instead of calling the legacy .func directly. Also swap the default instance from the deprecated RigidBodyMaterialCfg to its base RigidBodyMaterialBaseCfg, verified to author identical USD. --- .../isaaclab/isaaclab/sim/simulation_cfg.py | 13 ++++-- .../test/sim/test_material_fragments.py | 43 +++++++++++++++++++ .../isaaclab_physx/physics/physx_manager.py | 8 ++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/source/isaaclab/isaaclab/sim/simulation_cfg.py b/source/isaaclab/isaaclab/sim/simulation_cfg.py index 2c71c724ad3d..41b4413fbfe5 100644 --- a/source/isaaclab/isaaclab/sim/simulation_cfg.py +++ b/source/isaaclab/isaaclab/sim/simulation_cfg.py @@ -14,7 +14,10 @@ from typing import Any, Literal # Literal used by RenderCfg from isaaclab.physics import PhysicsCfg -from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialCfg +from isaaclab.sim.spawners.materials.physics_materials_cfg import ( + RigidBodyMaterialBaseCfg, + RigidBodyMaterialFragment, +) from isaaclab.utils.configclass import configclass from isaaclab.visualizers import VisualizerCfg @@ -250,13 +253,17 @@ class SimulationCfg: physics_prim_path: str = "/physicsScene" """The prim path where the USD PhysicsScene is created. Default is "/physicsScene".""" - physics_material: RigidBodyMaterialCfg = RigidBodyMaterialCfg() - """Default physics material settings for rigid bodies. Default is RigidBodyMaterialCfg. + physics_material: RigidBodyMaterialBaseCfg | RigidBodyMaterialFragment | list[RigidBodyMaterialFragment] = ( + RigidBodyMaterialBaseCfg() + ) + """Default physics material settings for rigid bodies. Default is RigidBodyMaterialBaseCfg. The physics engine defaults to this physics material for all the rigid body prims that do not have any physics material specified on them. The material is created at the path: ``{physics_prim_path}/defaultMaterial``. + + A single rigid-body material fragment, or a list of them, is also accepted. """ use_fabric: bool = True diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 25d17672c8ec..046732b308b3 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -410,3 +410,46 @@ def test_legacy_base_cfg_authors_density(): # None default -> unauthored (backward compatible) prim2 = spawn_rigid_body_material("/World/LegacyDensityNone", RigidBodyMaterialBaseCfg()) assert not prim2.GetAttribute("physics:density").HasAuthoredValue() + + +# ------------------------------------------------------------------------------------- +# Sim-wide default material: SimulationCfg.physics_material routed through the dispatcher +# ------------------------------------------------------------------------------------- + + +def test_simulation_default_material_accepts_fragment_list(): + """The sim-wide default material honors the fragment-list form of SimulationCfg.physics_material.""" + from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg + + sim_utils.create_new_stage() + # SimulationContext is a process-wide singleton; other tests in this module construct one + # without tearing it down, so force a real re-init here to exercise physics-manager configuration + # (including default-material spawning) against this test's own cfg and stage. + SimulationContext.clear_instance() + SimulationContext(SimulationCfg(dt=0.01, physics_material=[UsdPhysicsRigidBodyMaterialCfg(static_friction=0.8)])) + stage = sim_utils.get_current_stage() + mat = stage.GetPrimAtPath("/physicsScene/defaultMaterial") + assert mat.IsValid() + assert mat.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.8) + + +def test_default_material_base_cfg_matches_deprecated_leaf(): + """RigidBodyMaterialBaseCfg() authors byte-identical USD to the deprecated RigidBodyMaterialCfg() + default it replaces (the leaf's solver-specific fields default to None and author nothing).""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialCfg + + from isaaclab.sim.spawners.materials import spawn_rigid_body_material + from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialBaseCfg + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + old = spawn_rigid_body_material("/World/DefaultOld", RigidBodyMaterialCfg()) + new = spawn_rigid_body_material("/World/DefaultNew", RigidBodyMaterialBaseCfg()) + + def authored(prim): + return ( + {a.GetName(): a.Get() for a in prim.GetAttributes() if a.HasAuthoredValue()}, + set(prim.GetAppliedSchemas()), + ) + + assert authored(old) == authored(new) diff --git a/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py b/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py index d399d95546be..1524a8566707 100644 --- a/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py +++ b/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py @@ -655,11 +655,13 @@ def _configure_physics(cls) -> None: # default physics material (from SimulationCfg, or create default if None) physics_material = sim_cfg.physics_material if physics_material is None: - from isaaclab.sim.spawners.materials import RigidBodyMaterialCfg + from isaaclab.sim.spawners.materials import RigidBodyMaterialBaseCfg - physics_material = RigidBodyMaterialCfg() + physics_material = RigidBodyMaterialBaseCfg() mat_path = f"{sim_cfg.physics_prim_path}/defaultMaterial" - physics_material.func(mat_path, physics_material) + from isaaclab.sim.spawners.materials import spawn_physics_material + + spawn_physics_material(mat_path, physics_material) sim_utils.bind_physics_material(sim_cfg.physics_prim_path, mat_path) # warnings From 31abf2c31edef7f7c0dbfae9392bf0f2acf73703 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:15:05 -0700 Subject: [PATCH 11/19] Spawn compliant-contact material via the dispatcher Route the compliant-contact USD spawner's material creation through spawn_physics_material instead of calling the legacy cfg's .func directly, keeping it consistent with the other USD spawner call sites. Also pass the stage to the ground-plane physics-material call, matching its sibling call sites in the same file. --- .../sim/spawners/from_files/from_files.py | 4 +- .../test/sim/test_material_fragments.py | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py index 1a1805f9fb8c..a574e1a34318 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py @@ -212,7 +212,7 @@ def spawn_ground_plane( # Create physics material if cfg.physics_material is not None: - spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material) + spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material, stage=stage) # Apply physics material to ground plane collision_prim = get_first_matching_child_prim( prim_path, @@ -548,7 +548,7 @@ def spawn_from_usd_with_compliant_contact_material( material_path = f"{rigid_body_prim_path}/compliant_material" # spawn physics material - material_cfg.func(material_path, material_cfg) + spawn_physics_material(material_path, material_cfg) bind_physics_material( rigid_body_prim_path, diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 046732b308b3..e2d79af73c6a 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -453,3 +453,40 @@ def authored(prim): ) assert authored(old) == authored(new) + + +# ------------------------------------------------------------------------------------- +# Compliant-contact USD spawner: material spawn must route through the shared dispatcher +# ------------------------------------------------------------------------------------- + + +def test_compliant_contact_spawner_authors_material(tmp_path): + """The compliant-contact USD spawner authors its PhysX material via the shared dispatcher.""" + import os + + from pxr import Usd, UsdGeom, UsdPhysics + + from isaaclab.sim.spawners.from_files.from_files import spawn_from_usd_with_compliant_contact_material + from isaaclab.sim.spawners.from_files.from_files_cfg import UsdFileWithCompliantContactCfg + + usd_path = os.path.join(tmp_path, "asset.usda") + asset_stage = Usd.Stage.CreateNew(usd_path) + robot = UsdGeom.Xform.Define(asset_stage, "/Robot") + base = UsdGeom.Xform.Define(asset_stage, "/Robot/base").GetPrim() + UsdPhysics.RigidBodyAPI.Apply(base) + asset_stage.SetDefaultPrim(robot.GetPrim()) + asset_stage.Save() + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + cfg = UsdFileWithCompliantContactCfg( + usd_path=usd_path, + physics_material_prim_path="base", + compliant_contact_stiffness=1.0e5, + compliant_contact_damping=200.0, + ) + spawn_from_usd_with_compliant_contact_material("/World/Compliant", cfg) + stage = sim_utils.get_current_stage() + mat = stage.GetPrimAtPath("/World/Compliant/base/compliant_material") + assert mat.IsValid() + assert mat.GetAttribute("physxMaterial:compliantContactStiffness").Get() == pytest.approx(1.0e5) From c84801e75dba1ed2ef73f49daa536bacebf448b5 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:20:47 -0700 Subject: [PATCH 12/19] Narrow shape spawner material slot to rigid materials Shapes are rigid-only spawners, so the physics_material slot now accepts the rigid material base class or rigid-material fragments, and no longer advertises deformable material configurations. --- .../isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py index 83f0bf25c7a0..04d0bc42a764 100644 --- a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes_cfg.py @@ -38,16 +38,16 @@ class ShapeCfg(RigidObjectSpawnerCfg): This parameter is ignored if `physics_material` is not None. """ physics_material: ( - materials.PhysicsMaterialCfg + materials.RigidBodyMaterialBaseCfg | materials.RigidBodyMaterialFragment | list[materials.RigidBodyMaterialFragment] | None ) = None """Physics material properties. - Accepts either a legacy material cfg (e.g. - :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`) or a list of - single-namespace :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + Since shapes are rigid-only spawners, this slot accepts the rigid material base class or + rigid-material fragments (single-namespace :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` + instances or lists thereof). Note: If None, then no physics material will be added. From ffa19f3c12f05c43cc06536b99c437af3c1d4bc7 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:25:06 -0700 Subject: [PATCH 13/19] Reject non-current stage on legacy material path Legacy material cfgs resolve the stage internally via get_current_stage() and ignore the explicit stage argument, so an explicit non-current stage was silently authoring on the wrong stage instead of on the one the caller asked for. Raise ValueError in that case; passing None or the current stage explicitly still works, which keeps the in-tree spawners that pass stage=stage unconditionally working unchanged. --- .../spawners/materials/physics_materials.py | 19 ++++++++++++---- .../test/sim/test_material_fragments.py | 22 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index 6bfaaebedbe4..2b11a1042bdf 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -89,13 +89,17 @@ def spawn_physics_material( prim_path: The prim path to spawn the material at. material: A :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or list of them), or a legacy material cfg carrying a :attr:`func`. - stage: The stage to spawn on. Defaults to None, in which case the current stage is used. + stage: The stage to spawn on. Defaults to None, in which case the current stage is used. A + legacy material cfg only supports the current stage (or None); passing a different + stage raises. Returns: The spawned material prim. Raises: ValueError: When ``material`` is an empty list. + ValueError: When ``material`` is a legacy material cfg and ``stage`` is neither ``None`` + nor the current stage. TypeError: When ``material`` is a list containing anything other than :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. """ @@ -114,9 +118,16 @@ def spawn_physics_material( if isinstance(material, physics_materials_cfg.RigidBodyMaterialFragment): return spawn_rigid_body_material_from_fragments(prim_path, [material], stage) # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``). - # NOTE: legacy material funcs take only ``(prim_path, cfg)`` and resolve the stage internally via - # ``get_current_stage()``; they have no ``stage`` parameter, so ``stage`` is intentionally not - # forwarded here. This is invisible in single-stage workflows (the only ones materials are used in). + # Legacy material funcs take only ``(prim_path, cfg)`` and resolve the stage internally via + # ``get_current_stage()`` (their path matching is also current-stage-bound), so an explicit + # different stage cannot be honored on this path -- reject it loudly rather than authoring on + # the wrong stage. The fragment path above supports explicit stages. + if stage is not None and stage != get_current_stage(): + raise ValueError( + f"Legacy material cfg '{type(material).__name__}' can only be spawned on the current" + " stage. Pass the current stage (or None), or use the fragment-based API for" + " explicit-stage authoring." + ) return material.func(prim_path, material) diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index e2d79af73c6a..3f098c5ad5f4 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -121,6 +121,28 @@ def test_spawn_physics_material_dispatches_fragments_and_legacy(): assert legacy_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.9) +def test_spawn_physics_material_rejects_non_current_stage_for_legacy(): + """The legacy path is current-stage-bound; an explicit different stage raises instead of + silently authoring on the current stage. Passing the current stage explicitly stays valid + (the in-tree spawners do so unconditionally).""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg + + from pxr import Usd + + from isaaclab.sim.spawners.materials import spawn_physics_material + + sim_utils.create_new_stage() + SimulationContext(SimulationCfg(dt=0.01)) + other = Usd.Stage.CreateInMemory() + with pytest.raises(ValueError, match="current stage"): + spawn_physics_material("/World/MatOther", PhysxRigidBodyMaterialCfg(), stage=other) + # nothing leaked onto the current stage + assert not sim_utils.get_current_stage().GetPrimAtPath("/World/MatOther").IsValid() + # explicit current stage remains supported + prim = spawn_physics_material("/World/MatCurrent", PhysxRigidBodyMaterialCfg(), stage=sim_utils.get_current_stage()) + assert prim.IsValid() + + def test_spawn_physics_material_rejects_empty_and_mixed_lists(): """A malformed fragment list surfaces a clear error rather than an opaque AttributeError.""" from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg From 1983a592a469bc1f5e2ea5093b4a2d5ebd0ecabd Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:37:12 -0700 Subject: [PATCH 14/19] Add structural parity and slot-typing tests Adds two enforcement tests: one asserts each backend's fragment dataclass authors exactly the same fields as its legacy cfg counterpart, and one asserts each material slot's type union matches whether its spawner is rigid-only or also spawns deformables. These catch field or slot-typing drift structurally instead of relying on manual review. --- .../test/sim/test_material_fragments.py | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 3f098c5ad5f4..947452a1a57a 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -512,3 +512,70 @@ def test_compliant_contact_spawner_authors_material(tmp_path): mat = stage.GetPrimAtPath("/World/Compliant/base/compliant_material") assert mat.IsValid() assert mat.GetAttribute("physxMaterial:compliantContactStiffness").Get() == pytest.approx(1.0e5) + + +# ------------------------------------------------------------------------------------- +# Structural enforcement: fragment/legacy field parity + slot-typing contract +# ------------------------------------------------------------------------------------- + + +def test_fragment_legacy_field_parity(): + """Structural parity: each backend's fragment authors exactly the fields its legacy cfg + authors (minus the inherited base for backend subclasses). Field drift fails here instead of + surfacing in review.""" + import dataclasses + + from isaaclab_newton.sim.schemas import NewtonMaterialPropertiesCfg + from isaaclab_newton.sim.spawners.materials.physics_materials_cfg import NewtonMaterialCfg + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import ( + PhysxMaterialCfg, + PhysxRigidBodyMaterialCfg, + ) + + from isaaclab.sim.spawners.materials.physics_materials_cfg import ( + RigidBodyMaterialBaseCfg, + UsdPhysicsRigidBodyMaterialCfg, + ) + + def fields(cls): + return {f.name for f in dataclasses.fields(cls) if f.name != "func"} + + base = fields(RigidBodyMaterialBaseCfg) + assert fields(UsdPhysicsRigidBodyMaterialCfg) == base + assert fields(PhysxMaterialCfg) == fields(PhysxRigidBodyMaterialCfg) - base + assert fields(NewtonMaterialCfg) == fields(NewtonMaterialPropertiesCfg) - base + + +def test_material_slot_unions_match_spawner_kind(): + """Structural slot typing: rigid-only spawner slots admit the rigid base + fragments and + exclude the deformable-admitting root; mixed spawners keep the broad root. New slots added + to this list keep the contract enforced.""" + import sys + import typing + + from isaaclab.sim.simulation_cfg import SimulationCfg as _SimCfg + from isaaclab.sim.spawners.from_files.from_files_cfg import FileCfg, GroundPlaneCfg + from isaaclab.sim.spawners.materials import physics_materials_cfg as mats + from isaaclab.sim.spawners.meshes.meshes_cfg import MeshCfg + from isaaclab.sim.spawners.shapes.shapes_cfg import ShapeCfg + from isaaclab.terrains.terrain_importer_cfg import TerrainImporterCfg + + def union_args(cls): + # typing.get_type_hints(cls) resolves annotations across the whole MRO, including the + # inherited ``func: Callable[..., Usd.Prim]`` from ``SpawnerCfg``, whose ``Usd`` import is + # TYPE_CHECKING-only and unresolvable at runtime. Evaluate the ``physics_material`` + # annotation directly against its declaring class's module globals instead -- each class + # in this list declares the field itself, so this never needs the base class's namespace. + annotation = cls.__dict__["__annotations__"]["physics_material"] + resolved = eval(annotation, vars(sys.modules[cls.__module__])) + return set(typing.get_args(resolved)) + + for cls in (ShapeCfg, GroundPlaneCfg, TerrainImporterCfg, _SimCfg): + args = union_args(cls) + assert mats.RigidBodyMaterialBaseCfg in args, f"{cls.__name__} must admit the rigid base" + assert mats.RigidBodyMaterialFragment in args, f"{cls.__name__} must admit fragments" + assert mats.PhysicsMaterialCfg not in args, f"{cls.__name__} is rigid-only" + for cls in (FileCfg, MeshCfg): + args = union_args(cls) + assert mats.PhysicsMaterialCfg in args, f"{cls.__name__} spawns deformables too" + assert mats.RigidBodyMaterialFragment in args From 9553f387251264afcf39d07398ecd76750825b9b Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:48:13 -0700 Subject: [PATCH 15/19] Update material changelog for slot and parity fixes Backfill changelog fragments for the density parity, Newton contact attribute parity, terrain/default-material/compliant-contact routing, ShapeCfg narrowing, and stage-rejection changes, and correct the mesh-spawner rigid-material guard entry from a widening to a fix (the deprecated-leaf-class check was rejecting valid rigid materials). --- .../vidurv-schema-frag-materials.minor.rst | 37 ++++++++++++++----- .../vidurv-schema-frag-materials.minor.rst | 10 ++++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst index 18764b2957fe..fbde5686f720 100644 --- a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -11,16 +11,35 @@ Added legacy material cfg. * Added :attr:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg.density` (writes ``physics:density``), completing the fragment's coverage of ``UsdPhysics.MaterialAPI``. +* Added :attr:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg.density`, so the legacy + rigid material base authors every attribute the fragment authors. Changed ^^^^^^^ -* Widened the mesh spawner's rigid-vs-deformable physics-material guard in - :mod:`isaaclab.sim.spawners.meshes` to accept any - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` (legacy cfg) or - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or a list of the latter), - instead of only the deprecated ``RigidBodyMaterialCfg`` alias. -* Widened :attr:`~isaaclab.sim.spawners.from_files.GroundPlaneCfg.physics_material` to accept a - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` (legacy cfg) or a - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or a list of the latter), - since the ground plane only spawns a rigid collision plane. +* Changed rigid-only ``physics_material`` slots + (:class:`~isaaclab.sim.spawners.ShapeCfg`, :class:`~isaaclab.sim.spawners.GroundPlaneCfg`, + :class:`~isaaclab.terrains.TerrainImporterCfg`, :class:`~isaaclab.sim.SimulationCfg`) to accept + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` or a list of + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances, and no longer + advertise deformable material configs on rigid-only spawners. Deformable materials remain + accepted where deformables can spawn (:class:`~isaaclab.sim.spawners.FileCfg`, + :class:`~isaaclab.sim.spawners.MeshCfg`). +* Changed the generated-terrain, simulation default-material, and compliant-contact material paths + to spawn through :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`, so fragment + lists work at every ``physics_material`` entry point. +* Changed :func:`~isaaclab.sim.spawners.materials.spawn_physics_material` to raise ``ValueError`` + when a legacy material cfg is given an explicit stage other than the current stage (previously + the stage was silently ignored and authored on the wrong stage). Callers that already pass the + current stage (or ``None``) are unaffected; callers that need an explicit non-current stage + should switch the material to the fragment-based API, which supports it. + +Fixed +^^^^^ + +* Fixed mesh spawners rejecting valid rigid physics materials: the rigid-material check compared + against the deprecated leaf class, so canonical + :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg` and + :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` instances raised + ``ValueError`` on rigid meshes. The check now accepts any + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`. diff --git a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst index 57eaf596d27a..6c5ebb12aabe 100644 --- a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -5,7 +5,8 @@ Added ``newton`` rigid-body physics-material fragment (torsional and rolling friction) backing ``NewtonMaterialAPI``. Composes with other rigid-body material fragments (e.g. :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in a fragment list. The - legacy :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` is unchanged. + legacy :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` gains the same contact + attributes below, keeping the two configs in parity. * Added :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_stiffness`, :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_damping`, :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_friction_gain`, and @@ -13,3 +14,10 @@ Added ``newton:contactStiffness``, ``newton:contactDamping``, ``newton:contactFrictionGain``, and ``newton:contactAdhesion``), matching the per-material contact attributes Newton's USD schema resolver reads in place of the deprecated per-shape ``ke``/``kd``/``kf``/``ka`` parameters. +* Added the same four contact attributes + (:attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_stiffness`, + :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_damping`, + :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_friction_gain`, and + :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_adhesion`) to the legacy + :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg`, so it authors every attribute + the fragment authors. From 21b2a5eef17a2c3370accf9fc6dcc587ca2ffde7 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Thu, 2 Jul 2026 23:56:43 -0700 Subject: [PATCH 16/19] Note PhysX default-material change in changelog Document the behavior change where PhysX's default physics-material spawn now goes through the unified spawn_physics_material function, enabling list-of-fragments support in SimulationCfg. --- .../changelog.d/vidurv-schema-frag-materials.minor.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst index b580d3ad6316..e18911adeb3e 100644 --- a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -10,3 +10,12 @@ Added (writes ``physxMaterial:compliantContactAccelerationSpring``), completing the fragment's coverage of ``PhysxMaterialAPI``. Also added the same two fields to the legacy :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. + +Changed +^^^^^^^ + +* Changed the default physics-material spawn in the PhysX backend to go through + :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`, so a list of + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances assigned to + :attr:`~isaaclab.sim.SimulationCfg.physics_material` now works when PhysX is the active backend + (previously only a legacy single cfg was accepted there). From 3c86ca6c0025d61cc9aa98900173a6c0d21b6ec5 Mon Sep 17 00:00:00 2001 From: Vidur Vij Date: Fri, 3 Jul 2026 00:14:00 -0700 Subject: [PATCH 17/19] Document default material type change as breaking The physics_material defaults on SimulationCfg, TerrainImporterCfg, and GroundPlaneCfg were switched from the deprecated PhysX leaf RigidBodyMaterialCfg to the core RigidBodyMaterialBaseCfg. The authored USD is unchanged, but downstream code that mutates the default material in place to set PhysX-only fields (e.g. combine modes) would now silently author nothing since those fields no longer exist on the base class. Call this out as a breaking change in the changelog, with migration guidance to assign a PhysxRigidBodyMaterialCfg instance instead. Also fix GroundPlaneCfg itself, which still constructed the deprecated leaf class as its default despite already accepting the base class in its type union. Also clean up stale docstrings that predate the density field, and tighten changelog wording: spell out the three accepted forms for physics_material slots, mark the stage-rejection change as breaking, and reword the Newton material parity entry to be self-contained instead of pointing at another bullet. --- .../vidurv-schema-frag-materials.minor.rst | 22 +++++++++++++------ .../sim/spawners/from_files/from_files_cfg.py | 2 +- .../spawners/materials/physics_materials.py | 8 +++---- .../materials/physics_materials_cfg.py | 6 ++--- .../vidurv-schema-frag-materials.minor.rst | 12 +++++----- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst index fbde5686f720..cb06b9ad03ae 100644 --- a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -7,8 +7,8 @@ Added ``physics:*`` friction/restitution), plus the family writer :func:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material_from_fragments` and the slot dispatcher :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`. Spawner - ``physics_material`` slots now accept a list of single-namespace fragments in addition to the - legacy material cfg. + ``physics_material`` slots now accept a legacy rigid material cfg, a single fragment, or a list of + fragments. * Added :attr:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg.density` (writes ``physics:density``), completing the fragment's coverage of ``UsdPhysics.MaterialAPI``. * Added :attr:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg.density`, so the legacy @@ -28,11 +28,19 @@ Changed * Changed the generated-terrain, simulation default-material, and compliant-contact material paths to spawn through :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`, so fragment lists work at every ``physics_material`` entry point. -* Changed :func:`~isaaclab.sim.spawners.materials.spawn_physics_material` to raise ``ValueError`` - when a legacy material cfg is given an explicit stage other than the current stage (previously - the stage was silently ignored and authored on the wrong stage). Callers that already pass the - current stage (or ``None``) are unaffected; callers that need an explicit non-current stage - should switch the material to the fragment-based API, which supports it. +* **Breaking:** Changed :func:`~isaaclab.sim.spawners.materials.spawn_physics_material` to raise + ``ValueError`` when a legacy material cfg is given an explicit stage other than the current stage + (previously the stage was silently ignored and authored on the wrong stage). Callers that already + pass the current stage (or ``None``) are unaffected; callers that need an explicit non-current + stage should switch the material to the fragment-based API, which supports it. +* **Breaking:** Changed the default value of :attr:`~isaaclab.sim.SimulationCfg.physics_material`, + :attr:`~isaaclab.terrains.TerrainImporterCfg.physics_material`, and + :attr:`~isaaclab.sim.spawners.GroundPlaneCfg.physics_material` from the deprecated + :class:`~isaaclab_physx.sim.spawners.materials.RigidBodyMaterialCfg` to + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`. The authored USD defaults are + identical, but PhysX-only fields (e.g. combine modes) no longer exist on the default object. If you + set PhysX-only fields on the default material in place, assign a + :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg` instance instead. Fixed ^^^^^ diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py index 4276c0880a1f..32a15f99b193 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py @@ -271,7 +271,7 @@ class GroundPlaneCfg(SpawnerCfg): materials.RigidBodyMaterialBaseCfg | materials.RigidBodyMaterialFragment | list[materials.RigidBodyMaterialFragment] - ) = materials.RigidBodyMaterialCfg() + ) = materials.RigidBodyMaterialBaseCfg() """Physics material properties. Defaults to the default rigid body material. The ground plane only spawns a collision plane, so this only accepts rigid-body materials: a diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index 2b11a1042bdf..81d0012f9f09 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -141,10 +141,10 @@ def spawn_rigid_body_material(prim_path: str, cfg: physics_materials_cfg.RigidBo PxMaterial `_. The writer is metadata-driven: it always applies the standard ``UsdPhysics.MaterialAPI`` and - writes the friction/restitution fields, then reads ``_usd_applied_schema``, ``_usd_namespace``, - and ``_usd_attr_name_map`` from the cfg to author solver-specific attributes. The applied - schema (e.g. ``PhysxMaterialAPI``) is added only when at least one solver-specific field has a - non-``None`` value at the instance level. + writes the friction/restitution/density fields, then reads ``_usd_applied_schema``, + ``_usd_namespace``, and ``_usd_attr_name_map`` from the cfg to author solver-specific attributes. + The applied schema (e.g. ``PhysxMaterialAPI``) is added only when at least one solver-specific + field has a non-``None`` value at the instance level. .. note:: This function is decorated with :func:`clone` that resolves prim path into list of paths diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py index e97138389545..ff5c147ae122 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py @@ -61,9 +61,9 @@ class PhysicsMaterialCfg: class RigidBodyMaterialBaseCfg(PhysicsMaterialCfg): """Solver-common physics-material parameters for rigid bodies. - Contains the friction and restitution fields from the `UsdPhysics.MaterialAPI`_ that are common - across all simulation backends. For PhysX-only material properties (compliant-contact spring, - combine modes), use :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. + Contains the friction, restitution, and density fields from the `UsdPhysics.MaterialAPI`_ that + are common across all simulation backends. For PhysX-only material properties (compliant-contact + spring, combine modes), use :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. See :meth:`spawn_rigid_body_material` for more information. diff --git a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst index 6c5ebb12aabe..977d1590eca7 100644 --- a/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab_newton/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -4,9 +4,7 @@ Added * Added :class:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg`, a single-namespace ``newton`` rigid-body physics-material fragment (torsional and rolling friction) backing ``NewtonMaterialAPI``. Composes with other rigid-body material fragments (e.g. - :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in a fragment list. The - legacy :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` gains the same contact - attributes below, keeping the two configs in parity. + :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg`) in a fragment list. * Added :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_stiffness`, :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_damping`, :attr:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg.contact_friction_gain`, and @@ -14,10 +12,10 @@ Added ``newton:contactStiffness``, ``newton:contactDamping``, ``newton:contactFrictionGain``, and ``newton:contactAdhesion``), matching the per-material contact attributes Newton's USD schema resolver reads in place of the deprecated per-shape ``ke``/``kd``/``kf``/``ka`` parameters. -* Added the same four contact attributes +* Added the contact attributes (:attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_stiffness`, :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_damping`, :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_friction_gain`, and - :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_adhesion`) to the legacy - :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg`, so it authors every attribute - the fragment authors. + :attr:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg.contact_adhesion`) to + :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg`, matching + :class:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg`. From e1bb60b816cf230d82c5ba15bacc92c8044dbe9c Mon Sep 17 00:00:00 2001 From: Octi Zhang Date: Fri, 3 Jul 2026 17:18:45 -0700 Subject: [PATCH 18/19] Tighten material fragment integration boundaries --- docs/source/api/lab/isaaclab.sim.spawners.rst | 22 +++ .../isaaclab_newton.sim.spawners.rst | 9 + .../lab_physx/isaaclab_physx.sim.spawners.rst | 15 ++ .../vidurv-schema-frag-materials.minor.rst | 51 +++--- .../isaaclab/isaaclab/sim/simulation_cfg.py | 13 +- .../sim/spawners/from_files/from_files.py | 4 +- .../sim/spawners/from_files/from_files_cfg.py | 12 +- .../spawners/materials/physics_materials.py | 73 +++++--- .../materials/physics_materials_cfg.py | 20 ++- .../sim/spawners/meshes/meshes_cfg.py | 5 +- .../isaaclab/sim/spawners/shapes/shapes.py | 2 +- .../isaaclab/terrains/terrain_importer_cfg.py | 5 +- source/isaaclab/isaaclab/terrains/utils.py | 4 +- .../test/sim/test_material_fragments.py | 158 ++++++------------ .../test/sim/test_newton_schemas.py | 21 ++- .../vidurv-schema-frag-materials.minor.rst | 9 - .../isaaclab_physx/physics/physx_manager.py | 8 +- .../materials/physics_materials_cfg.py | 20 ++- 18 files changed, 231 insertions(+), 220 deletions(-) diff --git a/docs/source/api/lab/isaaclab.sim.spawners.rst b/docs/source/api/lab/isaaclab.sim.spawners.rst index d42fa13e524e..ce82c003e8e5 100644 --- a/docs/source/api/lab/isaaclab.sim.spawners.rst +++ b/docs/source/api/lab/isaaclab.sim.spawners.rst @@ -267,6 +267,9 @@ Materials MdlFileCfg GlassMdlCfg PhysicsMaterialCfg + RigidBodyMaterialBaseCfg + RigidBodyMaterialFragment + UsdPhysicsRigidBodyMaterialCfg RigidBodyMaterialCfg DeformableBodyMaterialBaseCfg SurfaceDeformableBodyMaterialBaseCfg @@ -303,8 +306,27 @@ Physical Materials :members: :exclude-members: __init__, func +.. autofunction:: spawn_physics_material + .. autofunction:: spawn_rigid_body_material +.. autoclass:: RigidBodyMaterialBaseCfg + :members: + :show-inheritance: + :exclude-members: __init__, func + +.. autofunction:: spawn_rigid_body_material_from_fragments + +.. autoclass:: RigidBodyMaterialFragment + :members: + :show-inheritance: + :exclude-members: __init__, func + +.. autoclass:: UsdPhysicsRigidBodyMaterialCfg + :members: + :show-inheritance: + :exclude-members: __init__, func + .. autoclass:: RigidBodyMaterialCfg :members: :exclude-members: __init__, func diff --git a/docs/source/api/lab_newton/isaaclab_newton.sim.spawners.rst b/docs/source/api/lab_newton/isaaclab_newton.sim.spawners.rst index f42cef3d8167..2db0a1622814 100644 --- a/docs/source/api/lab_newton/isaaclab_newton.sim.spawners.rst +++ b/docs/source/api/lab_newton/isaaclab_newton.sim.spawners.rst @@ -7,10 +7,19 @@ isaaclab_newton.sim.spawners .. autosummary:: + NewtonMaterialCfg NewtonDeformableBodyMaterialCfg NewtonDeformableMaterialCfg NewtonSurfaceDeformableBodyMaterialCfg +Rigid Materials +--------------- + +.. autoclass:: NewtonMaterialCfg + :members: + :show-inheritance: + :exclude-members: __init__, func + Deformable Materials -------------------- diff --git a/docs/source/api/lab_physx/isaaclab_physx.sim.spawners.rst b/docs/source/api/lab_physx/isaaclab_physx.sim.spawners.rst index 7a2ace2a33ff..3e2355d141e2 100644 --- a/docs/source/api/lab_physx/isaaclab_physx.sim.spawners.rst +++ b/docs/source/api/lab_physx/isaaclab_physx.sim.spawners.rst @@ -7,12 +7,27 @@ isaaclab_physx.sim.spawners .. autosummary:: + PhysxRigidBodyMaterialCfg + PhysxMaterialCfg PhysxDeformableBodyMaterialCfg PhysxSurfaceDeformableBodyMaterialCfg PhysXDeformableMaterialCfg DeformableBodyMaterialCfg SurfaceDeformableBodyMaterialCfg +Rigid Materials +--------------- + +.. autoclass:: PhysxRigidBodyMaterialCfg + :members: + :show-inheritance: + :exclude-members: __init__, func + +.. autoclass:: PhysxMaterialCfg + :members: + :show-inheritance: + :exclude-members: __init__, func + Deformable Materials -------------------- diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst index cb06b9ad03ae..e92dd8ba79ca 100644 --- a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -4,11 +4,13 @@ Added * Added the rigid-body physics-material "fragment" classes :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (marker base) and :class:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg` (solver-common - ``physics:*`` friction/restitution), plus the family writer + ``physics:*`` friction/restitution/density), plus the family writer :func:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material_from_fragments` and the slot - dispatcher :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`. Spawner - ``physics_material`` slots now accept a legacy rigid material cfg, a single fragment, or a list of - fragments. + dispatcher :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`. Relevant + ``physics_material`` slots now accept a single fragment or list alongside their legacy cfg form. + Legacy material cfgs are current-stage-only: the dispatcher raises ``ValueError`` for an explicit + non-current stage, while fragment-based materials support explicit-stage authoring. + * Added :attr:`~isaaclab.sim.spawners.materials.UsdPhysicsRigidBodyMaterialCfg.density` (writes ``physics:density``), completing the fragment's coverage of ``UsdPhysics.MaterialAPI``. * Added :attr:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg.density`, so the legacy @@ -17,30 +19,18 @@ Added Changed ^^^^^^^ -* Changed rigid-only ``physics_material`` slots - (:class:`~isaaclab.sim.spawners.ShapeCfg`, :class:`~isaaclab.sim.spawners.GroundPlaneCfg`, - :class:`~isaaclab.terrains.TerrainImporterCfg`, :class:`~isaaclab.sim.SimulationCfg`) to accept - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` or a list of - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances, and no longer - advertise deformable material configs on rigid-only spawners. Deformable materials remain - accepted where deformables can spawn (:class:`~isaaclab.sim.spawners.FileCfg`, - :class:`~isaaclab.sim.spawners.MeshCfg`). -* Changed the generated-terrain, simulation default-material, and compliant-contact material paths - to spawn through :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`, so fragment - lists work at every ``physics_material`` entry point. -* **Breaking:** Changed :func:`~isaaclab.sim.spawners.materials.spawn_physics_material` to raise - ``ValueError`` when a legacy material cfg is given an explicit stage other than the current stage - (previously the stage was silently ignored and authored on the wrong stage). Callers that already - pass the current stage (or ``None``) are unaffected; callers that need an explicit non-current - stage should switch the material to the fragment-based API, which supports it. -* **Breaking:** Changed the default value of :attr:`~isaaclab.sim.SimulationCfg.physics_material`, - :attr:`~isaaclab.terrains.TerrainImporterCfg.physics_material`, and - :attr:`~isaaclab.sim.spawners.GroundPlaneCfg.physics_material` from the deprecated - :class:`~isaaclab_physx.sim.spawners.materials.RigidBodyMaterialCfg` to - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`. The authored USD defaults are - identical, but PhysX-only fields (e.g. combine modes) no longer exist on the default object. If you - set PhysX-only fields on the default material in place, assign a - :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg` instance instead. +* Narrowed :attr:`~isaaclab.sim.spawners.ShapeCfg.physics_material` from the broad + :class:`~isaaclab.sim.spawners.materials.PhysicsMaterialCfg` to the rigid material base, a single + rigid-material fragment, or a list of fragments. +* Extended the already rigid-only :attr:`~isaaclab.sim.spawners.GroundPlaneCfg.physics_material` + and :attr:`~isaaclab.terrains.TerrainImporterCfg.physics_material` slots from the legacy + :class:`~isaaclab_physx.sim.spawners.materials.RigidBodyMaterialCfg` type to + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`, a single + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`, or a list of fragments. + Deformable materials remain accepted where deformables can spawn + (:class:`~isaaclab.sim.spawners.FileCfg` and :class:`~isaaclab.sim.spawners.MeshCfg`). +* Changed the generated-terrain material path to use + :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`, enabling fragment lists there. Fixed ^^^^^ @@ -51,3 +41,8 @@ Fixed :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` instances raised ``ValueError`` on rigid meshes. The check now accepts any :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`. +* Fixed rigid-only shape, ground-plane, and generated-terrain material slots accepting legacy + deformable-material configs at runtime. The dispatcher now rejects those configs before creating + a material prim. +* Fixed malformed fragment inputs reaching an opaque legacy ``func`` call. Direct and dispatched + fragment calls now reject empty, mixed, and non-fragment inputs before creating a material prim. diff --git a/source/isaaclab/isaaclab/sim/simulation_cfg.py b/source/isaaclab/isaaclab/sim/simulation_cfg.py index 41b4413fbfe5..2c71c724ad3d 100644 --- a/source/isaaclab/isaaclab/sim/simulation_cfg.py +++ b/source/isaaclab/isaaclab/sim/simulation_cfg.py @@ -14,10 +14,7 @@ from typing import Any, Literal # Literal used by RenderCfg from isaaclab.physics import PhysicsCfg -from isaaclab.sim.spawners.materials.physics_materials_cfg import ( - RigidBodyMaterialBaseCfg, - RigidBodyMaterialFragment, -) +from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialCfg from isaaclab.utils.configclass import configclass from isaaclab.visualizers import VisualizerCfg @@ -253,17 +250,13 @@ class SimulationCfg: physics_prim_path: str = "/physicsScene" """The prim path where the USD PhysicsScene is created. Default is "/physicsScene".""" - physics_material: RigidBodyMaterialBaseCfg | RigidBodyMaterialFragment | list[RigidBodyMaterialFragment] = ( - RigidBodyMaterialBaseCfg() - ) - """Default physics material settings for rigid bodies. Default is RigidBodyMaterialBaseCfg. + physics_material: RigidBodyMaterialCfg = RigidBodyMaterialCfg() + """Default physics material settings for rigid bodies. Default is RigidBodyMaterialCfg. The physics engine defaults to this physics material for all the rigid body prims that do not have any physics material specified on them. The material is created at the path: ``{physics_prim_path}/defaultMaterial``. - - A single rigid-body material fragment, or a list of them, is also accepted. """ use_fabric: bool = True diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py index a574e1a34318..9d8ed0bf6470 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py @@ -212,7 +212,7 @@ def spawn_ground_plane( # Create physics material if cfg.physics_material is not None: - spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material, stage=stage) + spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material, stage=stage, require_rigid=True) # Apply physics material to ground plane collision_prim = get_first_matching_child_prim( prim_path, @@ -548,7 +548,7 @@ def spawn_from_usd_with_compliant_contact_material( material_path = f"{rigid_body_prim_path}/compliant_material" # spawn physics material - spawn_physics_material(material_path, material_cfg) + material_cfg.func(material_path, material_cfg) bind_physics_material( rigid_body_prim_path, diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py index 32a15f99b193..1c9c26e02525 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files_cfg.py @@ -114,8 +114,9 @@ class FileCfg(RigidObjectSpawnerCfg, DeformableObjectSpawnerCfg): ) = None """Physics material properties. - Accepts either a legacy material cfg or a list of single-namespace - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + Accepts either a legacy material cfg, a single + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`, or a list of such + single-namespace fragments. Note: If None, then no custom physics material will be added. @@ -271,10 +272,11 @@ class GroundPlaneCfg(SpawnerCfg): materials.RigidBodyMaterialBaseCfg | materials.RigidBodyMaterialFragment | list[materials.RigidBodyMaterialFragment] - ) = materials.RigidBodyMaterialBaseCfg() + ) = materials.RigidBodyMaterialCfg() """Physics material properties. Defaults to the default rigid body material. The ground plane only spawns a collision plane, so this only accepts rigid-body materials: a - legacy :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` or a list of - single-namespace :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + legacy :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`, a single + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`, or a list of such + single-namespace fragments. """ diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index 81d0012f9f09..be0381d26671 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -19,10 +19,12 @@ def spawn_rigid_body_material_from_fragments( prim_path: str, - fragments: physics_materials_cfg.RigidBodyMaterialFragment | list[physics_materials_cfg.RigidBodyMaterialFragment], + fragments: physics_materials_cfg.RigidBodyMaterialFragment + | list[physics_materials_cfg.RigidBodyMaterialFragment] + | tuple[physics_materials_cfg.RigidBodyMaterialFragment, ...], stage: Usd.Stage | None = None, ) -> Usd.Prim: - """Spawn a rigid-body physics material from a list of single-namespace fragments. + """Spawn a rigid-body physics material from one or more single-namespace fragments. Creates (or reuses) the ``UsdShade.Material`` prim at ``prim_path``, applies the standard ``UsdPhysics.MaterialAPI`` anchor, then dispatches each fragment via its @@ -38,20 +40,36 @@ def spawn_rigid_body_material_from_fragments( Args: prim_path: The prim path to spawn the material at. - fragments: A single :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` or a list - of them. + fragments: A single :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`, + or a list/tuple of them. stage: The stage to spawn on. Defaults to None, in which case the current stage is used. Returns: The spawned rigid body material prim. Raises: + ValueError: When ``fragments`` is empty. ValueError: When a prim already exists at the path and is not a material. + TypeError: When an item is not a rigid-body material fragment. """ - if stage is None: - stage = get_current_stage() if not isinstance(fragments, (list, tuple)): fragments = [fragments] + else: + fragments = list(fragments) + if not fragments: + raise ValueError(f"Cannot spawn a physics material at '{prim_path}' from an empty fragment collection.") + invalid_types = [ + type(fragment).__name__ + for fragment in fragments + if not isinstance(fragment, physics_materials_cfg.RigidBodyMaterialFragment) + ] + if invalid_types: + raise TypeError( + "A physics-material fragment collection must contain only RigidBodyMaterialFragment instances; got" + f" {invalid_types}." + ) + if stage is None: + stage = get_current_stage() # create the material prim if none exists yet if not stage.GetPrimAtPath(prim_path).IsValid(): @@ -75,48 +93,51 @@ def spawn_physics_material( prim_path: str, material: physics_materials_cfg.PhysicsMaterialCfg | physics_materials_cfg.RigidBodyMaterialFragment - | list[physics_materials_cfg.RigidBodyMaterialFragment], + | list[physics_materials_cfg.RigidBodyMaterialFragment] + | tuple[physics_materials_cfg.RigidBodyMaterialFragment, ...], stage: Usd.Stage | None = None, + *, + require_rigid: bool = False, ) -> Usd.Prim: """Spawn a physics material from a spawner ``physics_material`` slot value. - Dispatches the two accepted slot forms: a list of (or single) rigid-body fragments is spawned via + Dispatches the two accepted slot forms: a single rigid-body fragment or list/tuple is spawned via :func:`spawn_rigid_body_material_from_fragments`; otherwise the value is a legacy material cfg and is spawned via its own :attr:`func`. Lets spawners accept both the fragment and the legacy interface from one call site. Args: prim_path: The prim path to spawn the material at. - material: A :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or list of - them), or a legacy material cfg carrying a :attr:`func`. + material: A :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` (or list/tuple + of them), or a legacy material cfg carrying a :attr:`func`. stage: The stage to spawn on. Defaults to None, in which case the current stage is used. A legacy material cfg only supports the current stage (or None); passing a different stage raises. + require_rigid: Whether to reject legacy deformable-material configs. Fragment inputs are + always rigid-body materials. Defaults to False for mixed rigid/deformable slots. Returns: The spawned material prim. Raises: - ValueError: When ``material`` is an empty list. + ValueError: When ``material`` is an empty fragment collection. ValueError: When ``material`` is a legacy material cfg and ``stage`` is neither ``None`` nor the current stage. - TypeError: When ``material`` is a list containing anything other than + ValueError: When ``require_rigid`` is True and ``material`` is a deformable-material cfg. + TypeError: When ``material`` is a fragment collection containing anything other than :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + TypeError: When ``material`` is neither a physics-material cfg nor a rigid-body fragment. """ - # a list/tuple slot value is the fragment-list form; validate it up front so a malformed list - # surfaces a clear error here rather than an opaque ``AttributeError`` on the legacy path below - if isinstance(material, (list, tuple)): - if not material: - raise ValueError(f"Cannot spawn a physics material at '{prim_path}' from an empty fragment list.") - if not all(isinstance(f, physics_materials_cfg.RigidBodyMaterialFragment) for f in material): - raise TypeError( - "A physics-material fragment list must contain only RigidBodyMaterialFragment instances; got" - f" {[type(f).__name__ for f in material]}." - ) - return spawn_rigid_body_material_from_fragments(prim_path, list(material), stage) - # a lone fragment routes through the fragment writer too - if isinstance(material, physics_materials_cfg.RigidBodyMaterialFragment): - return spawn_rigid_body_material_from_fragments(prim_path, [material], stage) + # The family writer owns fragment validation so direct and dispatched calls have one contract. + if isinstance(material, (list, tuple, physics_materials_cfg.RigidBodyMaterialFragment)): + return spawn_rigid_body_material_from_fragments(prim_path, material, stage) + if not isinstance(material, physics_materials_cfg.PhysicsMaterialCfg): + raise TypeError( + "A physics material must be a PhysicsMaterialCfg or rigid-body material fragment; got" + f" '{type(material).__name__}'." + ) + if require_rigid and not isinstance(material, physics_materials_cfg.RigidBodyMaterialBaseCfg): + raise ValueError(f"A rigid-only material slot cannot use '{type(material).__name__}'.") # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``). # Legacy material funcs take only ``(prim_path, cfg)`` and resolve the stage internally via # ``get_current_stage()`` (their path matching is also current-stage-bound), so an explicit diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py index ff5c147ae122..6dbe000e773f 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials_cfg.py @@ -62,8 +62,9 @@ class RigidBodyMaterialBaseCfg(PhysicsMaterialCfg): """Solver-common physics-material parameters for rigid bodies. Contains the friction, restitution, and density fields from the `UsdPhysics.MaterialAPI`_ that - are common across all simulation backends. For PhysX-only material properties (compliant-contact - spring, combine modes), use :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. + are common across all simulation backends. For properties in the ``physxMaterial`` namespace + (compliant-contact spring and combine modes), use + :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. See :meth:`spawn_rigid_body_material` for more information. @@ -92,8 +93,8 @@ class RigidBodyMaterialBaseCfg(PhysicsMaterialCfg): density: float | None = None """The material density [kg/m^3]. Defaults to None, in which case it is not authored. - Writes ``physics:density``. When authored, this overrides body-level density for computing - the mass of collision shapes bound to this material. + Writes ``physics:density``. It is a fallback for collision shapes bound to this material; + explicitly authored rigid-body mass or density takes precedence. """ @@ -102,9 +103,10 @@ class RigidBodyMaterialFragment(SchemaFragment): """Marker base for rigid-body physics-material fragments; types the ``physics_material`` slot. A rigid-body physics material is a single ``UsdShade.Material`` prim that carries one or more - physics-material schemas. The fragments author single namespaces onto that prim: the solver-common - ``physics:*`` friction/restitution (:class:`UsdPhysicsRigidBodyMaterialCfg`) and any backend-specific - namespace (e.g. PhysX ``physxMaterial:*`` via :class:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg`). + physics-material schemas. The fragments author single namespaces onto that prim: the + solver-common ``physics:*`` friction/restitution/density + (:class:`UsdPhysicsRigidBodyMaterialCfg`) and any backend-specific namespace (e.g. PhysX + ``physxMaterial:*`` via :class:`~isaaclab_physx.sim.spawners.materials.PhysxMaterialCfg`). The defining ``UsdPhysics.MaterialAPI`` anchor is applied by the family writer (:func:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material_from_fragments`). """ @@ -138,8 +140,8 @@ class UsdPhysicsRigidBodyMaterialCfg(RigidBodyMaterialFragment): density: float | None = None """The material density [kg/m^3]. Writes ``physics:density``. - Participates in mass computation via material binding when the owning rigid body does not - define an explicit mass. + Participates in mass computation via material binding when no explicit rigid-body mass or + density takes precedence. """ diff --git a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py index 50f0a8075515..aafd4d3cd7e0 100644 --- a/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py +++ b/source/isaaclab/isaaclab/sim/spawners/meshes/meshes_cfg.py @@ -65,8 +65,9 @@ class MeshCfg(RigidObjectSpawnerCfg, DeformableObjectSpawnerCfg): ) = None """Physics material properties. - Accepts either a legacy material cfg or a list of single-namespace - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. + Accepts either a legacy material cfg, a single + :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`, or a list of such + single-namespace fragments. Note: If None, then no physics material will be added. diff --git a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py index 2b8177423a88..da1f6560e3d5 100644 --- a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py +++ b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py @@ -318,7 +318,7 @@ def _spawn_geom_from_prim_type( else: material_path = cfg.physics_material_path # create material (accepts a legacy material cfg or rigid-body fragment(s)) - spawn_physics_material(material_path, cfg.physics_material, stage=stage) + spawn_physics_material(material_path, cfg.physics_material, stage=stage, require_rigid=True) # apply material bind_physics_material(mesh_prim_path, material_path, stage=stage) diff --git a/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py b/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py index 4ead3e39e8d5..d457c1606c83 100644 --- a/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py +++ b/source/isaaclab/isaaclab/terrains/terrain_importer_cfg.py @@ -92,7 +92,7 @@ class TerrainImporterCfg: materials.RigidBodyMaterialBaseCfg | materials.RigidBodyMaterialFragment | list[materials.RigidBodyMaterialFragment] - ) = materials.RigidBodyMaterialBaseCfg() + ) = materials.RigidBodyMaterialCfg() """The physics material of the terrain. Defaults to a default physics material. The material is created at the path: ``{prim_path}/physicsMaterial``. @@ -100,7 +100,8 @@ class TerrainImporterCfg: .. note:: This parameter is used only when the ``terrain_type`` is "generator" or "plane". - Accepts a legacy rigid material cfg or a list of rigid-material fragments. + Accepts a legacy rigid material cfg, a single rigid-material fragment, or a list of + rigid-material fragments. """ max_init_terrain_level: int | None = None diff --git a/source/isaaclab/isaaclab/terrains/utils.py b/source/isaaclab/isaaclab/terrains/utils.py index 1d708dfe2dcc..893dee8b89b7 100644 --- a/source/isaaclab/isaaclab/terrains/utils.py +++ b/source/isaaclab/isaaclab/terrains/utils.py @@ -82,7 +82,7 @@ def create_prim_from_mesh(prim_path: str, mesh: trimesh.Trimesh, **kwargs): orientation: The orientation of the terrain. Defaults to None. visual_material: The visual material to apply. Defaults to None. physics_material: The physics material to apply. Defaults to None. Accepts a legacy rigid - material cfg or a list of rigid-material fragments. + material cfg, a single rigid-material fragment, or a list of fragments. """ # create parent prim sim_utils.create_prim(prim_path, "Xform") @@ -126,7 +126,7 @@ def create_prim_from_mesh(prim_path: str, mesh: trimesh.Trimesh, **kwargs): # create physics material physics_material = kwargs.get("physics_material") if physics_material is not None: - spawn_physics_material(f"{prim_path}/physicsMaterial", physics_material) + spawn_physics_material(f"{prim_path}/physicsMaterial", physics_material, require_rigid=True) sim_utils.bind_physics_material(prim.GetPrimPath(), f"{prim_path}/physicsMaterial") diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index 947452a1a57a..e4007737e758 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -100,8 +100,8 @@ def test_spawn_rigid_body_material_from_fragments_accepts_single_fragment(): def test_spawn_physics_material_dispatches_fragments_and_legacy(): - """The shared slot dispatcher handles both forms a spawner ``physics_material`` slot accepts: a - rigid-body fragment list, and a legacy material cfg carrying its own ``func``.""" + """The shared dispatcher handles both a rigid-body fragment collection and a legacy material + cfg carrying its own ``func``.""" from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg from isaaclab.sim.spawners.materials.physics_materials import spawn_physics_material @@ -110,8 +110,8 @@ def test_spawn_physics_material_dispatches_fragments_and_legacy(): sim_utils.create_new_stage() SimulationContext(SimulationCfg(dt=0.01)) - # fragment-list form - frag_prim = spawn_physics_material("/World/MaterialA", [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4)]) + # tuple form is accepted by the low-level dispatcher alongside the list form used by cfg slots + frag_prim = spawn_physics_material("/World/MaterialA", (UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4),)) assert bool(UsdPhysics.MaterialAPI(frag_prim)) assert frag_prim.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.4) @@ -143,24 +143,40 @@ def test_spawn_physics_material_rejects_non_current_stage_for_legacy(): assert prim.IsValid() -def test_spawn_physics_material_rejects_empty_and_mixed_lists(): - """A malformed fragment list surfaces a clear error rather than an opaque AttributeError.""" - from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg +def test_fragment_writer_validates_inputs_before_authoring(): + """Direct and dispatched fragment calls share one validation contract and do not leave prims.""" + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import ( + PhysxDeformableBodyMaterialCfg, + PhysxRigidBodyMaterialCfg, + ) - from isaaclab.sim.spawners.materials.physics_materials import spawn_physics_material + from isaaclab.sim.spawners.materials.physics_materials import ( + spawn_physics_material, + spawn_rigid_body_material_from_fragments, + ) from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg sim_utils.create_new_stage() SimulationContext(SimulationCfg(dt=0.01)) + stage = sim_utils.get_current_stage() with pytest.raises(ValueError): - spawn_physics_material("/World/MatEmpty", []) + spawn_rigid_body_material_from_fragments("/World/MatEmpty", [], stage) # a list mixing a fragment with a legacy cfg is not a valid fragment list with pytest.raises(TypeError): spawn_physics_material( "/World/MatMixed", [UsdPhysicsRigidBodyMaterialCfg(static_friction=0.4), PhysxRigidBodyMaterialCfg(static_friction=0.9)], ) + with pytest.raises(TypeError): + spawn_rigid_body_material_from_fragments("/World/MatLegacy", PhysxRigidBodyMaterialCfg(), stage) + with pytest.raises(TypeError): + spawn_physics_material("/World/MatInvalid", object()) + with pytest.raises(ValueError, match="rigid-only"): + spawn_physics_material("/World/MatDeformable", PhysxDeformableBodyMaterialCfg(), require_rigid=True) + + for path in ("MatEmpty", "MatMixed", "MatLegacy", "MatInvalid", "MatDeformable"): + assert not stage.GetPrimAtPath(f"/World/{path}").IsValid() def test_spawn_rigid_body_material_from_fragments_leaves_none_fields_unwritten(): @@ -419,8 +435,8 @@ def test_create_prim_from_mesh_accepts_fragment_list(): def test_legacy_base_cfg_authors_density(): """The legacy rigid material base authors ``physics:density``, matching the USD fragment. - ``UsdPhysics.MaterialAPI`` defines four properties; the legacy base must author all four so - fragment and legacy paths stay interchangeable (Newton's importer reads material density). + ``UsdPhysics.MaterialAPI`` defines four properties; explicitly set values must be available + through both interfaces, including material density read by Newton's importer. """ from isaaclab.sim.spawners.materials import spawn_rigid_body_material from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialBaseCfg @@ -434,116 +450,49 @@ def test_legacy_base_cfg_authors_density(): assert not prim2.GetAttribute("physics:density").HasAuthoredValue() -# ------------------------------------------------------------------------------------- -# Sim-wide default material: SimulationCfg.physics_material routed through the dispatcher -# ------------------------------------------------------------------------------------- - - -def test_simulation_default_material_accepts_fragment_list(): - """The sim-wide default material honors the fragment-list form of SimulationCfg.physics_material.""" - from isaaclab.sim.spawners.materials.physics_materials_cfg import UsdPhysicsRigidBodyMaterialCfg - - sim_utils.create_new_stage() - # SimulationContext is a process-wide singleton; other tests in this module construct one - # without tearing it down, so force a real re-init here to exercise physics-manager configuration - # (including default-material spawning) against this test's own cfg and stage. - SimulationContext.clear_instance() - SimulationContext(SimulationCfg(dt=0.01, physics_material=[UsdPhysicsRigidBodyMaterialCfg(static_friction=0.8)])) - stage = sim_utils.get_current_stage() - mat = stage.GetPrimAtPath("/physicsScene/defaultMaterial") - assert mat.IsValid() - assert mat.GetAttribute("physics:staticFriction").Get() == pytest.approx(0.8) - - -def test_default_material_base_cfg_matches_deprecated_leaf(): - """RigidBodyMaterialBaseCfg() authors byte-identical USD to the deprecated RigidBodyMaterialCfg() - default it replaces (the leaf's solver-specific fields default to None and author nothing).""" +def test_public_default_material_types_remain_backward_compatible(): + """Fragment support must not silently replace the released default config objects.""" from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialCfg - from isaaclab.sim.spawners.materials import spawn_rigid_body_material - from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialBaseCfg - - sim_utils.create_new_stage() - SimulationContext(SimulationCfg(dt=0.01)) - old = spawn_rigid_body_material("/World/DefaultOld", RigidBodyMaterialCfg()) - new = spawn_rigid_body_material("/World/DefaultNew", RigidBodyMaterialBaseCfg()) - - def authored(prim): - return ( - {a.GetName(): a.Get() for a in prim.GetAttributes() if a.HasAuthoredValue()}, - set(prim.GetAppliedSchemas()), - ) - - assert authored(old) == authored(new) - - -# ------------------------------------------------------------------------------------- -# Compliant-contact USD spawner: material spawn must route through the shared dispatcher -# ------------------------------------------------------------------------------------- - - -def test_compliant_contact_spawner_authors_material(tmp_path): - """The compliant-contact USD spawner authors its PhysX material via the shared dispatcher.""" - import os - - from pxr import Usd, UsdGeom, UsdPhysics - - from isaaclab.sim.spawners.from_files.from_files import spawn_from_usd_with_compliant_contact_material - from isaaclab.sim.spawners.from_files.from_files_cfg import UsdFileWithCompliantContactCfg - - usd_path = os.path.join(tmp_path, "asset.usda") - asset_stage = Usd.Stage.CreateNew(usd_path) - robot = UsdGeom.Xform.Define(asset_stage, "/Robot") - base = UsdGeom.Xform.Define(asset_stage, "/Robot/base").GetPrim() - UsdPhysics.RigidBodyAPI.Apply(base) - asset_stage.SetDefaultPrim(robot.GetPrim()) - asset_stage.Save() + from isaaclab.sim.spawners.from_files.from_files_cfg import GroundPlaneCfg + from isaaclab.terrains.terrain_importer_cfg import TerrainImporterCfg - sim_utils.create_new_stage() - SimulationContext(SimulationCfg(dt=0.01)) - cfg = UsdFileWithCompliantContactCfg( - usd_path=usd_path, - physics_material_prim_path="base", - compliant_contact_stiffness=1.0e5, - compliant_contact_damping=200.0, + defaults = ( + SimulationCfg().physics_material, + GroundPlaneCfg().physics_material, + TerrainImporterCfg(prim_path="/World/terrain").physics_material, ) - spawn_from_usd_with_compliant_contact_material("/World/Compliant", cfg) - stage = sim_utils.get_current_stage() - mat = stage.GetPrimAtPath("/World/Compliant/base/compliant_material") - assert mat.IsValid() - assert mat.GetAttribute("physxMaterial:compliantContactStiffness").Get() == pytest.approx(1.0e5) - + assert all(type(material) is RigidBodyMaterialCfg for material in defaults) -# ------------------------------------------------------------------------------------- -# Structural enforcement: fragment/legacy field parity + slot-typing contract -# ------------------------------------------------------------------------------------- - -def test_fragment_legacy_field_parity(): - """Structural parity: each backend's fragment authors exactly the fields its legacy cfg - authors (minus the inherited base for backend subclasses). Field drift fails here instead of - surfacing in review.""" +def test_physx_fragment_and_legacy_cfg_match_material_api_schema(): + """Both PhysX interfaces cover the properties declared by ``PhysxMaterialAPI``.""" import dataclasses - from isaaclab_newton.sim.schemas import NewtonMaterialPropertiesCfg - from isaaclab_newton.sim.spawners.materials.physics_materials_cfg import NewtonMaterialCfg from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import ( PhysxMaterialCfg, PhysxRigidBodyMaterialCfg, ) - from isaaclab.sim.spawners.materials.physics_materials_cfg import ( - RigidBodyMaterialBaseCfg, - UsdPhysicsRigidBodyMaterialCfg, - ) + from pxr import PhysxSchema + + from isaaclab.sim.spawners.materials.physics_materials_cfg import RigidBodyMaterialBaseCfg + from isaaclab.utils.string import to_camel_case def fields(cls): return {f.name for f in dataclasses.fields(cls) if f.name != "func"} base = fields(RigidBodyMaterialBaseCfg) - assert fields(UsdPhysicsRigidBodyMaterialCfg) == base - assert fields(PhysxMaterialCfg) == fields(PhysxRigidBodyMaterialCfg) - base - assert fields(NewtonMaterialCfg) == fields(NewtonMaterialPropertiesCfg) - base + schema_attrs = {name.split(":", 1)[1] for name in PhysxSchema.PhysxMaterialAPI.GetSchemaAttributeNames()} + fragment_attrs = {to_camel_case(name, "cC") for name in fields(PhysxMaterialCfg)} + legacy_attrs = {to_camel_case(name, "cC") for name in fields(PhysxRigidBodyMaterialCfg) - base} + assert fragment_attrs == schema_attrs + assert legacy_attrs == schema_attrs + + +# ------------------------------------------------------------------------------------- +# Slot-typing contract +# ------------------------------------------------------------------------------------- def test_material_slot_unions_match_spawner_kind(): @@ -553,7 +502,6 @@ def test_material_slot_unions_match_spawner_kind(): import sys import typing - from isaaclab.sim.simulation_cfg import SimulationCfg as _SimCfg from isaaclab.sim.spawners.from_files.from_files_cfg import FileCfg, GroundPlaneCfg from isaaclab.sim.spawners.materials import physics_materials_cfg as mats from isaaclab.sim.spawners.meshes.meshes_cfg import MeshCfg @@ -570,7 +518,7 @@ def union_args(cls): resolved = eval(annotation, vars(sys.modules[cls.__module__])) return set(typing.get_args(resolved)) - for cls in (ShapeCfg, GroundPlaneCfg, TerrainImporterCfg, _SimCfg): + for cls in (ShapeCfg, GroundPlaneCfg, TerrainImporterCfg): args = union_args(cls) assert mats.RigidBodyMaterialBaseCfg in args, f"{cls.__name__} must admit the rigid base" assert mats.RigidBodyMaterialFragment in args, f"{cls.__name__} must admit fragments" diff --git a/source/isaaclab_newton/test/sim/test_newton_schemas.py b/source/isaaclab_newton/test/sim/test_newton_schemas.py index 237d40795e55..0f78c8e39507 100644 --- a/source/isaaclab_newton/test/sim/test_newton_schemas.py +++ b/source/isaaclab_newton/test/sim/test_newton_schemas.py @@ -198,6 +198,8 @@ def test_newton_material_fragment_authors_all_six_newton_attrs(setup_sim): through :class:`~isaaclab_newton.sim.spawners.materials.NewtonMaterialCfg`, even though the generated ``NewtonMaterialAPI`` schema currently only declares the two friction attributes.""" from isaaclab_newton.sim.spawners.materials import NewtonMaterialCfg + from newton._src.usd.schema_resolver import PrimType + from newton._src.usd.schemas import SchemaResolverNewton from isaaclab.sim.spawners.materials import spawn_rigid_body_material_from_fragments @@ -212,13 +214,20 @@ def test_newton_material_fragment_authors_all_six_newton_attrs(setup_sim): contact_adhesion=0.01, ), ) + expected = { + "mu_torsional": 0.3, + "mu_rolling": 0.001, + "ke": 2500.0, + "kd": 100.0, + "kf": 1000.0, + "ka": 0.01, + } + assert "NewtonMaterialAPI" in prim.GetAppliedSchemas() - assert prim.GetAttribute("newton:torsionalFriction").Get() == pytest.approx(0.3) - assert prim.GetAttribute("newton:rollingFriction").Get() == pytest.approx(0.001) - assert prim.GetAttribute("newton:contactStiffness").Get() == pytest.approx(2500.0) - assert prim.GetAttribute("newton:contactDamping").Get() == pytest.approx(100.0) - assert prim.GetAttribute("newton:contactFrictionGain").Get() == pytest.approx(1000.0) - assert prim.GetAttribute("newton:contactAdhesion").Get() == pytest.approx(0.01) + resolver = SchemaResolverNewton() + assert set(resolver.mapping[PrimType.MATERIAL]) == set(expected) + for key, value in expected.items(): + assert resolver.get_value(prim, PrimType.MATERIAL, key) == pytest.approx(value) # --------------------------------------------------------------------------- diff --git a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst index e18911adeb3e..b580d3ad6316 100644 --- a/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab_physx/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -10,12 +10,3 @@ Added (writes ``physxMaterial:compliantContactAccelerationSpring``), completing the fragment's coverage of ``PhysxMaterialAPI``. Also added the same two fields to the legacy :class:`~isaaclab_physx.sim.spawners.materials.PhysxRigidBodyMaterialCfg`. - -Changed -^^^^^^^ - -* Changed the default physics-material spawn in the PhysX backend to go through - :func:`~isaaclab.sim.spawners.materials.spawn_physics_material`, so a list of - :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances assigned to - :attr:`~isaaclab.sim.SimulationCfg.physics_material` now works when PhysX is the active backend - (previously only a legacy single cfg was accepted there). diff --git a/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py b/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py index 1524a8566707..d399d95546be 100644 --- a/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py +++ b/source/isaaclab_physx/isaaclab_physx/physics/physx_manager.py @@ -655,13 +655,11 @@ def _configure_physics(cls) -> None: # default physics material (from SimulationCfg, or create default if None) physics_material = sim_cfg.physics_material if physics_material is None: - from isaaclab.sim.spawners.materials import RigidBodyMaterialBaseCfg + from isaaclab.sim.spawners.materials import RigidBodyMaterialCfg - physics_material = RigidBodyMaterialBaseCfg() + physics_material = RigidBodyMaterialCfg() mat_path = f"{sim_cfg.physics_prim_path}/defaultMaterial" - from isaaclab.sim.spawners.materials import spawn_physics_material - - spawn_physics_material(mat_path, physics_material) + physics_material.func(mat_path, physics_material) sim_utils.bind_physics_material(sim_cfg.physics_prim_path, mat_path) # warnings diff --git a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py index 9914563e7a17..3560bc12bb3b 100644 --- a/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py +++ b/source/isaaclab_physx/isaaclab_physx/sim/spawners/materials/physics_materials_cfg.py @@ -155,8 +155,9 @@ class PhysxRigidBodyMaterialCfg(RigidBodyMaterialBaseCfg): Extends :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg` with the `PhysxMaterialAPI`_ schema fields: compliant-contact spring (stiffness/damping) and the - friction/restitution combine-mode tokens. None of these fields have a Newton consumer - today; they are PhysX-engine-only knobs. + friction/restitution combine-mode tokens. Newton's USD importer also recognizes stiffness and + damping as fallback contact parameters; the acceleration-spring flag and combine modes are + PhysX-only. See :meth:`~isaaclab.sim.spawners.materials.spawn_rigid_body_material` for more information. @@ -173,14 +174,16 @@ class PhysxRigidBodyMaterialCfg(RigidBodyMaterialBaseCfg): """Spring stiffness for a compliant contact model using implicit springs. A higher stiffness results in behavior closer to a rigid contact. The compliant contact model - is only enabled if the stiffness is larger than 0. PhysX-only; not consumed by Newton. + is only enabled if the stiffness is larger than 0. Newton's USD importer also recognizes this + attribute as a fallback contact-stiffness value. """ compliant_contact_damping: float | None = None """Damping coefficient for a compliant contact model using implicit springs. Irrelevant if compliant contacts are disabled when :attr:`compliant_contact_stiffness` is set - to zero and rigid contacts are active. PhysX-only; not consumed by Newton. + to zero and rigid contacts are active. Newton's USD importer also recognizes this attribute as + a fallback contact-damping value. """ compliant_contact_acceleration_spring: bool | None = None @@ -226,10 +229,11 @@ class PhysxMaterialCfg(RigidBodyMaterialFragment): """``physxMaterial:*`` rigid-body material attributes from `PhysxMaterialAPI`_. Single-namespace fragment (see :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment`) - for the PhysX-only material knobs: compliant-contact spring (stiffness/damping) and the - friction/restitution combine-mode tokens. The ``PhysxMaterialAPI`` schema is applied (and the - ``physxMaterial:*`` attributes authored) by the generic - :func:`~isaaclab.sim.schemas.apply_namespaced` writer. ``None`` fields are left unchanged. + for the PhysX material namespace: compliant-contact spring (stiffness/damping), which Newton's + USD importer can read as fallback contact parameters, plus PhysX-only acceleration-spring and + combine-mode knobs. The ``PhysxMaterialAPI`` schema is applied (and the ``physxMaterial:*`` + attributes authored) by the generic :func:`~isaaclab.sim.schemas.apply_namespaced` writer. + ``None`` fields are left unchanged. .. _PhysxMaterialAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/latest/class_physx_schema_physx_material_a_p_i.html """ From 419d1c02eb01165794207bd160453ef78f89c017 Mon Sep 17 00:00:00 2001 From: Octi Zhang Date: Fri, 3 Jul 2026 18:47:20 -0700 Subject: [PATCH 19/19] Remove rigid policy from material dispatcher --- .../changelog.d/vidurv-schema-frag-materials.minor.rst | 3 --- .../isaaclab/sim/spawners/from_files/from_files.py | 2 +- .../sim/spawners/materials/physics_materials.py | 8 -------- source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py | 2 +- source/isaaclab/isaaclab/terrains/utils.py | 2 +- source/isaaclab/test/sim/test_material_fragments.py | 10 ++-------- 6 files changed, 5 insertions(+), 22 deletions(-) diff --git a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst index e92dd8ba79ca..1cfe675cb0b3 100644 --- a/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst +++ b/source/isaaclab/changelog.d/vidurv-schema-frag-materials.minor.rst @@ -41,8 +41,5 @@ Fixed :class:`~isaaclab_newton.sim.schemas.NewtonMaterialPropertiesCfg` instances raised ``ValueError`` on rigid meshes. The check now accepts any :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialBaseCfg`. -* Fixed rigid-only shape, ground-plane, and generated-terrain material slots accepting legacy - deformable-material configs at runtime. The dispatcher now rejects those configs before creating - a material prim. * Fixed malformed fragment inputs reaching an opaque legacy ``func`` call. Direct and dispatched fragment calls now reject empty, mixed, and non-fragment inputs before creating a material prim. diff --git a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py index 9d8ed0bf6470..80b9f940e417 100644 --- a/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py +++ b/source/isaaclab/isaaclab/sim/spawners/from_files/from_files.py @@ -212,7 +212,7 @@ def spawn_ground_plane( # Create physics material if cfg.physics_material is not None: - spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material, stage=stage, require_rigid=True) + spawn_physics_material(f"{prim_path}/physicsMaterial", cfg.physics_material, stage=stage) # Apply physics material to ground plane collision_prim = get_first_matching_child_prim( prim_path, diff --git a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py index be0381d26671..51f19226bb1e 100644 --- a/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py +++ b/source/isaaclab/isaaclab/sim/spawners/materials/physics_materials.py @@ -96,8 +96,6 @@ def spawn_physics_material( | list[physics_materials_cfg.RigidBodyMaterialFragment] | tuple[physics_materials_cfg.RigidBodyMaterialFragment, ...], stage: Usd.Stage | None = None, - *, - require_rigid: bool = False, ) -> Usd.Prim: """Spawn a physics material from a spawner ``physics_material`` slot value. @@ -113,9 +111,6 @@ def spawn_physics_material( stage: The stage to spawn on. Defaults to None, in which case the current stage is used. A legacy material cfg only supports the current stage (or None); passing a different stage raises. - require_rigid: Whether to reject legacy deformable-material configs. Fragment inputs are - always rigid-body materials. Defaults to False for mixed rigid/deformable slots. - Returns: The spawned material prim. @@ -123,7 +118,6 @@ def spawn_physics_material( ValueError: When ``material`` is an empty fragment collection. ValueError: When ``material`` is a legacy material cfg and ``stage`` is neither ``None`` nor the current stage. - ValueError: When ``require_rigid`` is True and ``material`` is a deformable-material cfg. TypeError: When ``material`` is a fragment collection containing anything other than :class:`~isaaclab.sim.spawners.materials.RigidBodyMaterialFragment` instances. TypeError: When ``material`` is neither a physics-material cfg nor a rigid-body fragment. @@ -136,8 +130,6 @@ def spawn_physics_material( "A physics material must be a PhysicsMaterialCfg or rigid-body material fragment; got" f" '{type(material).__name__}'." ) - if require_rigid and not isinstance(material, physics_materials_cfg.RigidBodyMaterialBaseCfg): - raise ValueError(f"A rigid-only material slot cannot use '{type(material).__name__}'.") # legacy single-cfg path (rigid or deformable material cfg with its own spawner ``func``). # Legacy material funcs take only ``(prim_path, cfg)`` and resolve the stage internally via # ``get_current_stage()`` (their path matching is also current-stage-bound), so an explicit diff --git a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py index da1f6560e3d5..2b8177423a88 100644 --- a/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py +++ b/source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py @@ -318,7 +318,7 @@ def _spawn_geom_from_prim_type( else: material_path = cfg.physics_material_path # create material (accepts a legacy material cfg or rigid-body fragment(s)) - spawn_physics_material(material_path, cfg.physics_material, stage=stage, require_rigid=True) + spawn_physics_material(material_path, cfg.physics_material, stage=stage) # apply material bind_physics_material(mesh_prim_path, material_path, stage=stage) diff --git a/source/isaaclab/isaaclab/terrains/utils.py b/source/isaaclab/isaaclab/terrains/utils.py index 893dee8b89b7..68498cfde402 100644 --- a/source/isaaclab/isaaclab/terrains/utils.py +++ b/source/isaaclab/isaaclab/terrains/utils.py @@ -126,7 +126,7 @@ def create_prim_from_mesh(prim_path: str, mesh: trimesh.Trimesh, **kwargs): # create physics material physics_material = kwargs.get("physics_material") if physics_material is not None: - spawn_physics_material(f"{prim_path}/physicsMaterial", physics_material, require_rigid=True) + spawn_physics_material(f"{prim_path}/physicsMaterial", physics_material) sim_utils.bind_physics_material(prim.GetPrimPath(), f"{prim_path}/physicsMaterial") diff --git a/source/isaaclab/test/sim/test_material_fragments.py b/source/isaaclab/test/sim/test_material_fragments.py index e4007737e758..8caf9a99fd92 100644 --- a/source/isaaclab/test/sim/test_material_fragments.py +++ b/source/isaaclab/test/sim/test_material_fragments.py @@ -145,10 +145,7 @@ def test_spawn_physics_material_rejects_non_current_stage_for_legacy(): def test_fragment_writer_validates_inputs_before_authoring(): """Direct and dispatched fragment calls share one validation contract and do not leave prims.""" - from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import ( - PhysxDeformableBodyMaterialCfg, - PhysxRigidBodyMaterialCfg, - ) + from isaaclab_physx.sim.spawners.materials.physics_materials_cfg import PhysxRigidBodyMaterialCfg from isaaclab.sim.spawners.materials.physics_materials import ( spawn_physics_material, @@ -172,10 +169,7 @@ def test_fragment_writer_validates_inputs_before_authoring(): spawn_rigid_body_material_from_fragments("/World/MatLegacy", PhysxRigidBodyMaterialCfg(), stage) with pytest.raises(TypeError): spawn_physics_material("/World/MatInvalid", object()) - with pytest.raises(ValueError, match="rigid-only"): - spawn_physics_material("/World/MatDeformable", PhysxDeformableBodyMaterialCfg(), require_rigid=True) - - for path in ("MatEmpty", "MatMixed", "MatLegacy", "MatInvalid", "MatDeformable"): + for path in ("MatEmpty", "MatMixed", "MatLegacy", "MatInvalid"): assert not stage.GetPrimAtPath(f"/World/{path}").IsValid()