Skip to content

Propagate Newton shape colors before cloning - #6194

Merged
rilei-nvidia merged 4 commits into
isaac-sim:developfrom
rilei-nvidia:new-replace-newton-builder-colors
Jun 16, 2026
Merged

rilei-nvidia merged 4 commits into
isaac-sim:developfrom
rilei-nvidia:new-replace-newton-builder-colors

Conversation

@rilei-nvidia

@rilei-nvidia rilei-nvidia commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR integrates @ooctipus's proposed fix for newton shape color replacement to occur pre-clone. Original PR: rilei-nvidia#1

Replace the post-finalize replace_newton_shape_colors pass on the Newton model with replace_newton_builder_shape_colors, applied to each ModelBuilder before clone replication. This ensures all cloned environments automatically inherit the correct USD material and displayColor values. This not only improves performance but also addresses the regression that @huidongc discovered last week where only env_0 (the clone source) had the right color for the robot arm, and the other cloned envs got the fallback colors

  • Add replace_newton_builder_shape_colors to newton_model_utils.
  • Removed replace_newton_shape_colors and any un-used functionality
  • Call it in NewtonManager (flat, env, and proto-source builders),
    newton_clone_utils, and replicate
  • Update tests to exercise the new replace_newton_builder_shape_colors
  • Update dexsuite_kuka_hetero golden images for correctness

Validation

Validated for correctness in the Newton visualizer with (all robot arms should have the same color):

./isaaclab.sh train --rl_library rsl_rl \
    --task Isaac-Lift-KukaAllegro-Camera \
    presets=newton_mjwarp,newton_renderer,rgb64,single_camera \
    --seed 42 \
    --num_envs 4 \
    --max_iterations 2 \
    --visualizer newton
image

Rendering test golden images for the dexsuite_kuka_hetero kitless suite have also been updated to reflect fix to the regression

./isaaclab.sh -p -m pytest -v -rA source/isaaclab_tasks/test/core/test_rendering_dexsuite_kuka_hetero_kitless.py::test_rendering_dexsuite_kuka_hetero_kitless[newton-newton_warp-rgb]
image

Performance

Testing on a AMD Ryzen Threadripper PRO 7965WX 24-Cores (48) @ 5.36 GHz

For testing the performance impact I used the benchmark script:

./isaaclab.sh -p scripts/benchmarks/benchmark_non_rl.py \
    --task Isaac-Lift-KukaAllegro-Camera \
    presets=newton_mjwarp,ovrtx_renderer,rgb64,single_camera \
    --seed 42 \
    --num_envs "8000" \
    --benchmark_backend json \
    --output_path "hdc/benchmarks/20260611/heterogeneous_8000"

The time of replace_newton_shape_colors has been moved to calls to the new replace_newton_builder_shape_colors pre-clone:

# Env replace_newton_shape_colors (Before) replace_newton_builder_shape_colors (After)
4000 2 s 0.0045~ s
8000 4 s 0.0045~ s

With @ooctipus's change the time for shape color propagation is not only "free" now, but constant to increasing # of environments.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jun 15, 2026
@rilei-nvidia
rilei-nvidia force-pushed the new-replace-newton-builder-colors branch 2 times, most recently from d88b615 to 8a55d29 Compare June 15, 2026 23:36
@rilei-nvidia
rilei-nvidia marked this pull request as ready for review June 15, 2026 23:56
@rilei-nvidia rilei-nvidia changed the title Draft: Propagate Newton shape colors before cloning Propagate Newton shape colors before cloning Jun 15, 2026
@greptile-apps

greptile-apps Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a regression where only env_0 received correct USD material colors in multi-env Newton simulations by moving color resolution from a post-finalization GPU scatter pass to a pre-clone host-side pass applied to each ModelBuilder. The approach is architecturally sound: colorizing source builders once before add_builder replication means all cloned environments automatically inherit the correct colors, and the constant-time cost replaces a pass that scaled linearly with environment count.

  • replace_newton_builder_shape_colors replaces the removed replace_newton_shape_colors; it iterates over builder.shape_color (a CPU list pre-finalization) and applies the sRGB OETF inline, removing the Warp scatter kernel entirely.
  • The new function is wired into all three build paths in NewtonManager (flat, env-split global builder, and proto-source builder) and into replicate.py/newton_clone_utils.py for the replicate path.
  • Tests are updated to match the new list-based API and two new tests validate the pre-clone source-builder and missing-prim skip scenarios.

Confidence Score: 4/5

Safe to merge; the bug fix is well-targeted and all three builder paths are covered.

The core logic change is correct and well-tested. The only issues are non-blocking: the _resolve_shape_color docstring still references the deleted scatter kernel and its removed return-type annotation, the public function's docstring dropped all behavioral detail, and per-shape deduplication for unbound USD-instanced geometry is no longer performed (correctness is preserved but the helper _canonical_prim_lookup_key now goes unused for its original purpose).

source/isaaclab/isaaclab/sim/utils/newton_model_utils.py — stale internal docstrings and missing deduplication note.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sim/utils/newton_model_utils.py Replaces post-finalize GPU scatter kernel approach with a host-side pre-finalization loop; _resolve_shape_color docstring still references the removed scatter kernel and function, and the new public function has a sparse one-liner docstring.
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Removes two post-finalize replace_newton_shape_colors calls and adds three pre-finalize replace_newton_builder_shape_colors calls covering flat, env-split, and proto-source builder paths correctly.
source/isaaclab_newton/isaaclab_newton/cloner/replicate.py Adds one pre-replication call on the global (non-env) builder inside _build_newton_builder_from_mapping; source builders are handled separately in newton_clone_utils.py.
source/isaaclab_newton/isaaclab_newton/cloner/newton_clone_utils.py Adds replace_newton_builder_shape_colors call after mesh approximation for each source builder; placement is correct (before colors are replicated N times via add_builder).
source/isaaclab/test/sim/test_newton_model_utils.py Tests migrated from wp.array/torch-based assertions to plain Python list assertions; removes GPU-device parametrization (appropriate since builder colors are now CPU-side lists); adds two new tests covering the source-builder pre-clone scenario and missing-prim skip behavior.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant NM as NewtonManager
    participant RU as replicate.py
    participant NCU as newton_clone_utils.py
    participant UTIL as newton_model_utils.py

    Note over NM: Env-split load path
    NM->>NM: builder.add_usd(stage, ignore_env_paths)
    NM->>UTIL: replace_newton_builder_shape_colors(builder, stage)
    NM->>NM: "proto_builder.add_usd(stage, root_path=proto_path)"
    NM->>UTIL: replace_newton_builder_shape_colors(proto_builder, stage)
    NM->>NM: builder.finalize() → model ✅ colors already set

    Note over RU: Replicate path (heterogeneous envs)
    RU->>RU: global_builder.add_usd(ignore_env_paths)
    RU->>UTIL: replace_newton_builder_shape_colors(global_builder, stage)
    RU->>NCU: build_source_builders(stage, sources, ...)
    loop per source
        NCU->>NCU: "src_builder.add_usd(root_path=source)"
        NCU->>NCU: src_builder.approximate_meshes(...)
        NCU->>UTIL: replace_newton_builder_shape_colors(src_builder, stage)
    end
    RU->>RU: replicate_builder_mapping → add_builder(src_builder) × N envs
    Note right of RU: Each env inherits correct colors from the single colorized source
    RU->>RU: global_builder.finalize() → model ✅
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant NM as NewtonManager
    participant RU as replicate.py
    participant NCU as newton_clone_utils.py
    participant UTIL as newton_model_utils.py

    Note over NM: Env-split load path
    NM->>NM: builder.add_usd(stage, ignore_env_paths)
    NM->>UTIL: replace_newton_builder_shape_colors(builder, stage)
    NM->>NM: "proto_builder.add_usd(stage, root_path=proto_path)"
    NM->>UTIL: replace_newton_builder_shape_colors(proto_builder, stage)
    NM->>NM: builder.finalize() → model ✅ colors already set

    Note over RU: Replicate path (heterogeneous envs)
    RU->>RU: global_builder.add_usd(ignore_env_paths)
    RU->>UTIL: replace_newton_builder_shape_colors(global_builder, stage)
    RU->>NCU: build_source_builders(stage, sources, ...)
    loop per source
        NCU->>NCU: "src_builder.add_usd(root_path=source)"
        NCU->>NCU: src_builder.approximate_meshes(...)
        NCU->>UTIL: replace_newton_builder_shape_colors(src_builder, stage)
    end
    RU->>RU: replicate_builder_mapping → add_builder(src_builder) × N envs
    Note right of RU: Each env inherits correct colors from the single colorized source
    RU->>RU: global_builder.finalize() → model ✅
Loading

Comments Outside Diff (1)

  1. source/isaaclab/isaaclab/sim/utils/newton_model_utils.py, line 172-178 (link)

    P2 Stale docstring references removed scatter kernel

    _resolve_shape_color's docstring still says "sRGB encoding is applied in the scatter kernel" and the Returns block points to :func:_scatter_shape_color_rows_kernel" — both of which were deleted in this PR. The caller (replace_newton_builder_shape_colors`) now applies sRGB encoding inline, so any reader of this docstring will be confused about where the conversion happens.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "Propagate Newton shape colors before clo..." | Re-trigger Greptile

Comment on lines 224 to 233
material_color_cache: dict[str, tuple[float, float, float] | None] = {}

unique_keys = dict.fromkeys(shape_keys)
for key in unique_keys:
color = _resolve_shape_color(stage, key, material_color_cache)
resolved_color_cache[key] = color

# Prepare the indices and colors for the scatter kernel:
# - Indices point to the slots in the shape_colors array that should be updated
# - Colors are the new values to write into the slots
indices_np = np.empty(num_shapes, dtype=np.int32)
colors_np = np.empty((num_shapes, 3), dtype=np.float32)

for i, shape_key in enumerate(shape_keys):
if rgb := resolved_color_cache.get(shape_key):
indices_np[num_color_updates] = i
colors_np[num_color_updates] = rgb
for i, label in enumerate(shape_labels):
rgb = _resolve_shape_color(stage, label, material_color_cache)
if rgb is not None:
shape_colors[i] = wp.vec3(
_linear_channel_to_srgb(rgb[0]),
_linear_channel_to_srgb(rgb[1]),
_linear_channel_to_srgb(rgb[2]),
)
num_color_updates += 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 No per-shape deduplication for unbound USD-instanced geometry

The old implementation built a resolved_color_cache keyed by _canonical_prim_lookup_key(shape_prim), which mapped instance-proxy paths to their shared prototype path. Shapes from the same USD prototype were resolved once. The new loop calls _resolve_shape_color(stage, label, material_color_cache) for every label; the material_color_cache only deduplicates at the material level. For builders with many USD-native-instanced meshes that have no material binding (displayColor only), each proxy prim is looked up separately. Correctness is preserved (instance proxies delegate to the prototype's displayColor transparently), but scenes heavy with unbound USD instancing pay for extra per-label USD traversals. Worth a comment at minimum, and the _canonical_prim_lookup_key helper is now dead code for its original deduplication purpose.

Replace the post-finalize replace_newton_shape_colors pass on the
Newton model with replace_newton_builder_shape_colors, applied to
each ModelBuilder before clone replication. This ensures all cloned
environments automatically inherit the correct USD material and
displayColor values.

- Add replace_newton_builder_shape_colors to newton_model_utils
- Call it in NewtonManager (flat, env, and proto-source builders),
  newton_clone_utils, and replicate
- Update tests to exercise the new replace_newton_builder_shape_colors
- Update dexsuite_kuka_hetero golden images for corrected colors
…aclab/test/sim/test_newton_manager_visualization_state.py
@rilei-nvidia
rilei-nvidia force-pushed the new-replace-newton-builder-colors branch from a530bcd to 88d0148 Compare June 16, 2026 04:38
@rilei-nvidia
rilei-nvidia merged commit f547744 into isaac-sim:develop Jun 16, 2026
60 of 61 checks passed
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
# Description

This PR integrates @ooctipus's proposed fix for newton shape color
replacement to occur pre-clone. Original PR:
rilei-nvidia#1

Replace the post-finalize `replace_newton_shape_colors` pass on the
Newton model with `replace_newton_builder_shape_colors`, applied to each
ModelBuilder before clone replication. This ensures all cloned
environments automatically inherit the correct USD material and
displayColor values. This not only improves performance but also
addresses the regression that @huidongc discovered last week where only
env_0 (the clone source) had the right color for the robot arm, and the
other cloned envs got the fallback colors

- Add replace_newton_builder_shape_colors to newton_model_utils.  
- Removed replace_newton_shape_colors and any un-used functionality
- Call it in NewtonManager (flat, env, and proto-source builders),
  newton_clone_utils, and replicate
- Update tests to exercise the new replace_newton_builder_shape_colors
- Update dexsuite_kuka_hetero golden images for correctness 

# Validation

Validated for correctness in the Newton visualizer with (all robot arms
should have the same color):
```bash
./isaaclab.sh train --rl_library rsl_rl \
    --task Isaac-Lift-KukaAllegro-Camera \
    presets=newton_mjwarp,newton_renderer,rgb64,single_camera \
    --seed 42 \
    --num_envs 4 \
    --max_iterations 2 \
    --visualizer newton
```
<img width="1917" height="1159" alt="image"
src="https://github.com/user-attachments/assets/fabf9ef4-60f6-4e29-a11a-e266e77d7f61"
/>


Rendering test golden images for the dexsuite_kuka_hetero kitless suite
have also been updated to reflect fix to the regression
```bash
./isaaclab.sh -p -m pytest -v -rA source/isaaclab_tasks/test/core/test_rendering_dexsuite_kuka_hetero_kitless.py::test_rendering_dexsuite_kuka_hetero_kitless[newton-newton_warp-rgb]
```
<img width="742" height="1046" alt="image"
src="https://github.com/user-attachments/assets/6e357b06-5cf2-458f-886b-4b283952c94f"
/>


# Performance

Testing on a AMD Ryzen Threadripper PRO 7965WX 24-Cores (48) @ 5.36 GHz

For testing the performance impact I used the benchmark script:
```bash
./isaaclab.sh -p scripts/benchmarks/benchmark_non_rl.py \
    --task Isaac-Lift-KukaAllegro-Camera \
    presets=newton_mjwarp,ovrtx_renderer,rgb64,single_camera \
    --seed 42 \
    --num_envs "8000" \
    --benchmark_backend json \
    --output_path "hdc/benchmarks/20260611/heterogeneous_8000"
```

The time of replace_newton_shape_colors has been moved to calls to the
new replace_newton_builder_shape_colors pre-clone:
| # Env | replace_newton_shape_colors (Before) |
replace_newton_builder_shape_colors (After) |
| ------ | ----- | ----- |
| 4000 | 2 s | 0.0045~ s|  
| 8000 | 4 s | 0.0045~ s|  

With @ooctipus's change the time for shape color propagation is not only
"free" now, but constant to increasing # of environments.

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants