Fix visual material randomization lifecycle - #459
Conversation
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.
There was a problem hiding this comment.
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_defaultoption 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 onlyrandomize_*visual functors (keeping deterministicset_*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.
| update_default: bool = False, | ||
| ) -> None: | ||
| """Set visual material for the rigid object. |
Greptile SummaryThis follow-up preserves explicitly assigned materials as reset baselines and bounds texture allocation during legacy visual randomization.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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]
Reviews (2): Last reviewed commit: "wip" | Re-trigger Greptile
There was a problem hiding this comment.
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_materialsays “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.
Description
This PR fixes visual material state and texture lifecycle issues in visual randomization:
filter_visual_randis enabled;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
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 unchangedpytest -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 passedgit diff --check origin/main— passedChecklist
black .command to format the code base.