Skip to content

Fix visual material randomization lifecycle - #459

Merged
yuecideng merged 2 commits into
mainfrom
yueci/fix-material-rand
Aug 5, 2026
Merged

Fix visual material randomization lifecycle#459
yuecideng merged 2 commits into
mainfrom
yueci/fix-material-rand

Conversation

@yuecideng

Copy link
Copy Markdown
Contributor

Description

This PR fixes visual material state and texture lifecycle issues in visual randomization:

  • preserves deterministic material assignments as the reset baseline for rigid objects and articulations;
  • keeps deterministic material setter events when filter_visual_rand is enabled;
  • reuses cached library textures and a bounded solid-color texture pool in the legacy/fallback path, preventing repeated randomization from exhausting DexSim texture IDs.

This is a follow-up to #395. It prevents resets from reverting explicitly configured materials and keeps long-running legacy randomization bounded.

Dependencies: None.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Not applicable; this is a behavioral and resource-lifecycle fix covered by regression tests.

Validation

  • black . --extend-exclude '/embodichain/gen_sim/gradio_ui/' — 600 tracked Python files left unchanged
  • pytest -q tests/gym/envs/managers/test_randomize_visual_material.py tests/sim/objects/test_asset_material_initialization.py tests/gym/envs/test_embodied_env.py::test_visual_randomization_filter_keeps_deterministic_material_events — 55 passed
  • git diff --check origin/main — passed
  • Full test suite not run; focused tests cover the affected randomization, material reset, and event-filter behavior.

Checklist

  • I have run the black . command to format the code base.
  • I have updated the affected public API docstrings.
  • I have added tests that prove my fix is effective.
  • Dependencies are unchanged.

Preserve deterministic material assignments as reset baselines, keep non-random setters when visual randomization is filtered, and reuse bounded texture pools in the legacy path.
Copilot AI lite review requested due to automatic review settings August 5, 2026 12:01
@yuecideng yuecideng added bug Something isn't working rendering Things related to rendering (eg, performace, efficiency, bug) dexsim Things related to dexsim object Simulation object assets gym robot learning env and its related features labels Aug 5, 2026

Copilot AI left a comment

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.

Pull request overview

This PR fixes the lifecycle of visual material randomization by ensuring deterministic material assignments become the reset baseline for assets, keeping deterministic “setter” events when visual-randomization filtering is enabled, and preventing unbounded DexSim texture allocation in legacy/fallback randomization paths.

Changes:

  • Add an update_default option to rigid-object and articulation material setters, and use it from deterministic/material-config entry points to preserve reset baselines.
  • Refine EmbodiedEnv._apply_functor_filter() to remove only randomize_* visual functors (keeping deterministic set_* events).
  • Rework legacy visual randomization to reuse cached library textures and a bounded solid-color texture palette; add/extend regression tests for baseline and pooling behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/sim/objects/test_asset_material_initialization.py Adds coverage that update_default=True updates the reset material baseline.
tests/gym/envs/test_embodied_env.py Adds regression test ensuring filter_visual_rand removes randomizers but keeps deterministic setters.
tests/gym/envs/managers/test_randomize_visual_material.py Adds tests for deterministic setter baseline updates and bounded texture pooling in fallback/legacy paths.
embodichain/lab/sim/sim_manager.py Ensures configured rigid-object materials become the reset baseline (update_default=True).
embodichain/lab/sim/objects/rigid_object.py Implements update_default behavior for rigid-object material assignment.
embodichain/lab/sim/objects/articulation.py Implements update_default behavior for articulation material assignment.
embodichain/lab/gym/envs/managers/randomization/visual.py Reuses cached Texture objects and a bounded solid-color palette in legacy/fallback randomization to avoid texture-ID exhaustion.
embodichain/lab/gym/envs/embodied_env.py Narrows visual functor filtering to randomize_* exports to preserve deterministic setters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2178 to 2180
update_default: bool = False,
) -> None:
"""Set visual material for the rigid object.
Copilot AI review requested due to automatic review settings August 5, 2026 12:05
@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown

Greptile Summary

This follow-up preserves explicitly assigned materials as reset baselines and bounds texture allocation during legacy visual randomization.

  • Adds optional reset-baseline updates for rigid-object and articulation material assignment.
  • Retains deterministic material setters while filtering randomization events.
  • Reuses cached library textures and a bounded solid-color texture pool in legacy and fallback paths.
  • Improves demonstration progress labels with episode and action-list indices.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
embodichain/lab/gym/envs/managers/randomization/visual.py Legacy and fallback randomization now bind pre-created library or solid-color textures rather than allocating a texture on each invocation.
embodichain/lab/sim/objects/rigid_object.py Material assignment can optionally replace the per-environment reset baseline.
embodichain/lab/sim/objects/articulation.py Material assignment can optionally replace reset baselines for selected environments and links.
embodichain/lab/gym/envs/embodied_env.py Visual filtering now removes only exported randomization functors, preserving deterministic material setters.
embodichain/lab/sim/sim_manager.py Rigid-object materials configured during creation are recorded as reset baselines.
embodichain/lab/scripts/run_env.py Demonstration progress output now distinguishes episode and local action-list indices.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Configure visual material] --> B[Assign material instance]
    B --> C{Update reset baseline?}
    C -- Yes --> D[Capture render materials as baseline]
    C -- No --> E[Keep existing baseline]
    D --> F[Visual randomization]
    E --> F
    F --> G{Library texture selected?}
    G -- Yes --> H[Bind cached library texture]
    G -- No --> I[Bind cached solid-color texture]
    H --> J[Reset]
    I --> J
    J --> K[Restore captured baseline]
Loading

Reviews (2): Last reviewed commit: "wip" | Re-trigger Greptile

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Suppressed comments (1)

embodichain/lab/sim/objects/articulation.py:2180

  • The docstring for Articulation.set_visual_material says “rigid object”, but this method is on the articulation class. This can confuse API users and makes the doc inconsistent with the surrounding class.
        """Set visual material for the rigid object.

@yuecideng
yuecideng merged commit 99999b7 into main Aug 5, 2026
6 checks passed
@yuecideng
yuecideng deleted the yueci/fix-material-rand branch August 5, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dexsim Things related to dexsim gym robot learning env and its related features object Simulation object assets rendering Things related to rendering (eg, performace, efficiency, bug)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants