Part of #121. See IDEA.md stage 3 for the full context.
Goal
Replace part of scene_ops.inject_robot_into_scene with spec.attach(robot_spec, prefix=..., frame=...) when STRANDS_SIM_USE_MJSPEC=1.
Current code (after mj_spec flag lands):
inject_robot_into_scene loads robot XML, parses, prefixes names, merges with scene XML, reloads. ~100 lines of ElementTree + name-mangling.
Target:
robot_spec = mujoco.MjSpec.from_file(robot.urdf_path)
frame = scene_spec.worldbody.add_frame(pos=robot.position, quat=robot.orientation)
scene_spec.attach(robot_spec, prefix=f'{robot.name}_', frame=frame)
world._model, world._data = scene_spec.recompile(world._model, world._data)
attach() handles name prefixing across bodies, joints, geoms, actuators, sensors, sites; default-class namespacing; asset deduplication; keyframe merging.
Acceptance
- When
STRANDS_SIM_USE_MJSPEC=1, single-robot add_robot uses spec.attach().
- Joint/actuator ID discovery (
_discover_* helpers) still works - they read from the compiled MjModel.
- Legacy path untouched. Feature flag still default-off.
- New tests in
test_spec_builder.py for attach semantics (prefix applied, assets dedup'd).
Non-goals
- Don't delete
_save_and_patch_xml yet - multi-robot still needs it until Stage 4.
- Don't change public API.
Part of #121. See IDEA.md stage 3 for the full context.
Goal
Replace part of
scene_ops.inject_robot_into_scenewithspec.attach(robot_spec, prefix=..., frame=...)whenSTRANDS_SIM_USE_MJSPEC=1.Current code (after mj_spec flag lands):
inject_robot_into_sceneloads robot XML, parses, prefixes names, merges with scene XML, reloads. ~100 lines of ElementTree + name-mangling.Target:
attach()handles name prefixing across bodies, joints, geoms, actuators, sensors, sites; default-class namespacing; asset deduplication; keyframe merging.Acceptance
STRANDS_SIM_USE_MJSPEC=1, single-robotadd_robotusesspec.attach()._discover_*helpers) still works - they read from the compiled MjModel.test_spec_builder.pyfor attach semantics (prefix applied, assets dedup'd).Non-goals
_save_and_patch_xmlyet - multi-robot still needs it until Stage 4.