Add whole-scene USD export and preview - #589
Conversation
|
| runtime_assets[uid] = _externalize_glb_textures( | ||
| source_glb=source_glb, | ||
| destination_root=runtime_assets_root / uid, | ||
| ) |
There was a problem hiding this comment.
UID paths escape package roots
When editing or rebuilding a scene export whose accepted uid is absolute or contains parent-directory components, this code appends that value directly to the runtime-assets root and later the packaged-assets root, causing generated GLTF or USDC payloads to be written outside scene_usd and potentially overwrite another writable location. Validate or safely encode UIDs before using them as path components. How this was verified: The importer accepts any nonempty string as a UID, and the package builder uses that string directly as the destination path without a containment check.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: embodichain/gen_sim/scene_engine/pipeline/utils/scene_usd.py
Line: 515-518
Comment:
**UID paths escape package roots**
When editing or rebuilding a scene export whose accepted `uid` is absolute or contains parent-directory components, this code appends that value directly to the runtime-assets root and later the packaged-assets root, causing generated GLTF or USDC payloads to be written outside `scene_usd` and potentially overwrite another writable location. Validate or safely encode UIDs before using them as path components. **How this was verified:** The importer accepts any nonempty string as a UID, and the package builder uses that string directly as the destination path without a containment check.
**Knowledge Base Used:**
- [Generative simulation pipelines](https://app.greptile.com/dexforce/-/custom-context/knowledge-base/dexforce/embodichain/-/docs/generative-simulation.md)
- [Scene generation engine](https://app.greptile.com/dexforce/-/custom-context/knowledge-base/dexforce/embodichain/-/docs/scene-generation-engine.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for managed_file in (scene_usd_path, manifest_path): | ||
| if managed_file.is_symlink(): | ||
| managed_file.unlink() | ||
| _remove_path(scene_usd_root / "textures") |
There was a problem hiding this comment.
Rebuild can break existing package
When rebuilding an existing package, this removes its textures before the simulator is constructed. If construction fails, the old scene.usda and manifest remain, but their referenced textures are gone, so a previously usable package can no longer be previewed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: embodichain/gen_sim/scene_engine/pipeline/utils/scene_usd.py
Line: 175
Comment:
**Rebuild can break existing package**
When rebuilding an existing package, this removes its textures before the simulator is constructed. If construction fails, the old `scene.usda` and manifest remain, but their referenced textures are gone, so a previously usable package can no longer be previewed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Want your agent to iterate on Greptile's feedback? Start a greploop in Codex and it will work through the open comments and keep going until this PR reviews clean. |
| if usd_index.schema_version == USD_SCENE_SCHEMA: | ||
| return _load_embodichain_usd_stage( | ||
| sim=sim, | ||
| scene_usd_path=scene_usd_path, | ||
| index=usd_index, | ||
| ) |
There was a problem hiding this comment.
Direct USD preview misplaces meshes
For newly generated schema-v2 scenes, --usd and --usd-file now import the USD stage directly instead of loading the packaged GLTF/USDC assets. The existing compatibility path avoids direct import because DexSim cannot faithfully restore GLB internal node transforms from the flattened stage. Scenes with those transforms can therefore show misplaced meshes even though the package contains native assets that preserve their layout.
Knowledge Base Used: Scene generation engine
Prompt To Fix With AI
This is a comment left during a code review.
Path: embodichain/gen_sim/scene_engine/pipeline/utils/scene_usd.py
Line: 355-360
Comment:
**Direct USD preview misplaces meshes**
For newly generated schema-v2 scenes, `--usd` and `--usd-file` now import the USD stage directly instead of loading the packaged GLTF/USDC assets. The existing compatibility path avoids direct import because DexSim cannot faithfully restore GLB internal node transforms from the flattened stage. Scenes with those transforms can therefore show misplaced meshes even though the package contains native assets that preserve their layout.
**Knowledge Base Used:** [Scene generation engine](https://app.greptile.com/dexforce/-/custom-context/knowledge-base/dexforce/embodichain/-/docs/scene-generation-engine.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| scene_usd_path = scene_usd_root / "scene.usda" | ||
| temporary_scene_usd_path = scene_usd_root / "scene.in_progress.usda" | ||
| manifest_path = scene_usd_root / "scene_usd_manifest.json" | ||
| runtime_assets_root = scene_usd_root / ".export_runtime_assets" | ||
| packaged_assets_root = scene_usd_root / "assets" | ||
| temporary_scene_usd_path.unlink(missing_ok=True) | ||
| for managed_file in (scene_usd_path, manifest_path): | ||
| if managed_file.is_symlink(): | ||
| managed_file.unlink() | ||
| _remove_path(scene_usd_root / "textures") |
There was a problem hiding this comment.
Failed rebuild leaves stale USDZ
When an edit rewrites scene_export/, the rebuild does not remove the previous scene.usdz. If building the USD stage or packaging the new USDZ fails, the pipeline can warn that the optional export was skipped while leaving the old standalone file in place. Delivering or previewing that file then shows the scene from before the edit.
Knowledge Base Used: Scene generation engine
Prompt To Fix With AI
This is a comment left during a code review.
Path: embodichain/gen_sim/scene_engine/pipeline/utils/scene_usd.py
Line: 171-180
Comment:
**Failed rebuild leaves stale USDZ**
When an edit rewrites `scene_export/`, the rebuild does not remove the previous `scene.usdz`. If building the USD stage or packaging the new USDZ fails, the pipeline can warn that the optional export was skipped while leaving the old standalone file in place. Delivering or previewing that file then shows the scene from before the edit.
**Knowledge Base Used:** [Scene generation engine](https://app.greptile.com/dexforce/-/custom-context/knowledge-base/dexforce/embodichain/-/docs/scene-generation-engine.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| def scene_entity_cfg(self, uid: str) -> object: | ||
| """Create the Gym ``SceneEntityCfg`` corresponding to ``uid``.""" | ||
| self.get(uid) | ||
| from embodichain.lab.gym.envs.managers.cfg import SceneEntityCfg | ||
|
|
||
| return SceneEntityCfg(uid=uid) |
There was a problem hiding this comment.
scene_entity_cfg(uid) returns the authored scene UID, but add_usd() registers imported objects under DexSim descriptor names without registering that UID as an alias. When an object's runtime name differs from its scene UID, the returned SceneEntityCfg cannot resolve the object through the simulation manager, breaking the promised stable-UID binding.
Knowledge Base Used: Simulation lab
Prompt To Fix With AI
This is a comment left during a code review.
Path: embodichain/gen_sim/scene_engine/pipeline/utils/usd_scene.py
Line: 266-271
Comment:
**Logical UIDs do not resolve**
`scene_entity_cfg(uid)` returns the authored scene UID, but `add_usd()` registers imported objects under DexSim descriptor names without registering that UID as an alias. When an object's runtime name differs from its scene UID, the returned `SceneEntityCfg` cannot resolve the object through the simulation manager, breaking the promised stable-UID binding.
**Knowledge Base Used:** [Simulation lab](https://app.greptile.com/dexforce/-/custom-context/knowledge-base/dexforce/embodichain/-/docs/simulation-lab.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Description
This PR adds a portable whole-scene USD package alongside the existing editable
Scene Export output.
scene_usd/scene.usda, a manifest, externally textured GLTFpayloads, and articulated USDC payloads after both scene generation and scene
editing.
articulated-object behavior through the package manifest.
embodichain preview-scene --output_root <path> --usdto preview thepackaged scene; this also works with
--viserand supported articulationjoint controls.
scene_export/as the editable GLB/USDC source form, whilescene_usd/is the portable preview/delivery package.The native DexSim adapter deliberately loads packaged GLTF/USDC payloads
through the manifest because flattened USD mesh import does not currently
preserve GLB internal node transforms faithfully.
scene_usd.pyis an internal Scene Engine adapter, not a public API module.Dependencies: no new runtime dependencies.
No linked issue.
Type of change
Screenshots
N/A — CLI and simulation-preview change.
Validation
black --check --diff --color ./python docs/scripts/check_api_docs.py—
1680/1680public exports documented.python -m pytest tests/gen_sim/scene_engine/test_scene_core_and_export.py—
18 passed.Checklist