Skip to content

Commit e48fbf6

Browse files
vidurv-nvidiamyurasov-nv
authored andcommitted
Apply SDF mesh conversion before the enviorment is replicated
1 parent 9aaeff8 commit e48fbf6

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

source/isaaclab_newton/isaaclab_newton/cloner/newton_replicate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _build_newton_builder_from_mapping(
6969
# SDF collision requires original triangle meshes for mesh.build_sdf().
7070
# Convex hull approximation destroys the source geometry, so shapes
7171
# matching SDF patterns must be excluded from approximation here.
72-
# _apply_sdf_config() will build the SDF on these meshes later.
72+
# _apply_sdf_config() builds the SDF on each prototype after approximation.
7373
cfg = PhysicsManager._cfg
7474
sdf_cfg = getattr(cfg, "sdf_cfg", None) if cfg is not None else None
7575
body_pats = [re.compile(x) for x in sdf_cfg.body_patterns] if sdf_cfg and sdf_cfg.body_patterns else None
@@ -111,6 +111,10 @@ def _build_newton_builder_from_mapping(
111111
p.approximate_meshes("convex_hull", shape_indices=approx_indices, keep_visual_shapes=True)
112112
else:
113113
p.approximate_meshes("convex_hull", keep_visual_shapes=True)
114+
# Build SDF on prototype before add_builder copies it N times.
115+
# Mesh objects are shared by reference, so SDF is built once and
116+
# all environments inherit it.
117+
NewtonManager._apply_sdf_config(p)
114118
protos[src_path] = p
115119

116120
# create a separate world for each environment (heterogeneous spawning)

source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,11 @@ def start_simulation(cls) -> None:
608608
"""
609609
logger.debug(f"Builder: {cls._builder}")
610610

611-
# Create builder from USD stage if not provided
611+
# Create builder from USD stage if not provided.
612+
# When the builder was set externally (e.g. by newton_replicate),
613+
# SDF was already applied on the prototype before replication.
612614
if cls._builder is None:
613615
cls.instantiate_builder_from_stage()
614-
else:
615-
# Builder was set externally (e.g. by newton_replicate) — still apply SDF
616-
cls._apply_sdf_config(cls._builder)
617616

618617
logger.info("Dispatching MODEL_INIT callbacks")
619618
cls.dispatch_event(PhysicsEvent.MODEL_INIT)

0 commit comments

Comments
 (0)