Environment.from_spec(): MjSpec + objects composition#62
Merged
Conversation
Accepts an MjSpec with the robot already assembled, attaches prl_assets
objects via MjSpec.attach_body (native mesh path resolution), compiles,
and sets up the full object registry.
This enables robots that need runtime MjSpec assembly (attaching a
gripper, adding an EE site) to use Environment's object management
without saving to temp files.
Usage:
spec = mujoco.MjSpec.from_file("franka_scene.xml")
add_franka_ee_site(spec)
env = Environment.from_spec(spec, objects_dir, {"can": 3})
Closes #61
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New classmethod `Environment.from_spec(spec, objects_dir, scene_config)` that accepts an MjSpec with the robot assembled, attaches prl_assets objects via MjSpec (native mesh path resolution), compiles, and sets up the full object registry.
Problem
`Environment.init` only accepts file paths. Robots that need MjSpec assembly (attaching grippers, adding EE sites) before adding objects must save temp files, which breaks because `from_xml_string` can't resolve relative mesh paths.
Solution
`from_spec` keeps everything in MjSpec where path resolution works natively. Also accepts shorthand `{"can": 3}` in addition to the full `{"can": {"count": 3}}` format.
Test plan
Closes #61
🤖 Generated with Claude Code