fix: support multiple worldbody elements in MJCF parser#1496
Conversation
MuJoCo allows multiple <worldbody> elements in a single model (e.g.,
when using <include> to bring in separate MJCF files). Previously,
Newton's parser only processed the first worldbody element.
Changed root.find('worldbody') to iterate over root.findall('worldbody')
so all worldbody elements are processed into the world body, matching
MuJoCo's behavior.
Added tests for:
- Multiple inline worldbody elements with geoms and bodies
- Multiple worldbody elements with sites
- Includes that create multiple worldbody elements
📝 WalkthroughWalkthroughModified MJCF parsing to support multiple worldbody elements instead of a single worldbody. Restructured parsing logic to loop through each worldbody and process its child elements (bodies, geoms, sites, frames) within per-world context. Added comprehensive test coverage for multiple worldbody scenarios. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@newton/tests/test_import_mjcf.py`:
- Around line 4183-4187: The xml_resolver function currently has an unused
parameter base_dir causing ARG001; rename that parameter to _base_dir (or prefix
with an underscore) in the xml_resolver definition so the signature reads
xml_resolver(_base_dir, file_path) (or explicitly ignore it) and update any
references accordingly to silence Ruff while keeping behavior intact for the
xml_resolver function used in the tests.
MuJoCo allows multiple elements in a single model (e.g., when using to bring in separate MJCF files). Previously, Newton's parser only processed the first worldbody element.
Changed root.find('worldbody') to iterate over root.findall('worldbody') so all worldbody elements are processed into the world body, matching MuJoCo's behavior.
Added tests for:
Before your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
Release Notes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.