Skip to content

Fix MJCF primitive shell inertia - #3738

Open
han-xudong wants to merge 1 commit into
newton-physics:mainfrom
han-xudong:fix/mjcf-primitive-shellinertia
Open

Fix MJCF primitive shell inertia#3738
han-xudong wants to merge 1 commit into
newton-physics:mainfrom
han-xudong:fix/mjcf-primitive-shellinertia

Conversation

@han-xudong

@han-xudong han-xudong commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Import shellinertia="true" for sphere, capsule, cylinder, ellipsoid, and box geoms. The importer now treats density as mass per surface area and accumulates primitive shell mass properties using MuJoCo-compatible formulas, while preserving the original collision geometry.

Closes #3737

Checklist

  • New or existing tests cover these changes
  • The documentation is up to date with these changes
  • CHANGELOG.md has been updated (if user-facing change)

Test plan

uv run --extra dev -m newton.tests -k test_primitive_shellinertia_matches_native_mujoco
uvx pre-commit run -a

Bug fix

Steps to reproduce:

  1. Import a primitive geom with shellinertia="true".
  2. Inspect the inferred body mass and inertia.
  3. Observe solid-volume mass properties instead of MuJoCo's surface properties.

Minimal reproduction:

See #3737.

Summary by CodeRabbit

  • New Features

    • Added support for importing MJCF primitive geometries with shellinertia="true".
    • Supports shell mass and inertia calculations for spheres, capsules, cylinders, ellipsoids, and boxes.
    • Explicit mass values are supported for shell geometries.
  • Bug Fixes

    • Improved consistency between imported geometry mass properties and native MuJoCo behavior.
  • Tests

    • Added regression coverage for shell inertia across supported primitive geometries.

Interpret shell geom density as mass per area and compute primitive\nsurface mass properties with MuJoCo-compatible formulas. Handle both\ndensity-authored and explicit-mass geoms without changing collision geometry.
@han-xudong
han-xudong requested a deployment to external-pr-approval July 31, 2026 06:40 — with GitHub Actions Waiting
@han-xudong
han-xudong requested a deployment to external-pr-approval July 31, 2026 06:40 — with GitHub Actions Waiting
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

MJCF shell inertia support

Layer / File(s) Summary
Primitive shell property calculations
newton/_src/utils/import_mjcf.py
Added surface-area and diagonal shell-inertia calculations for spheres, capsules, cylinders, ellipsoids, and boxes.
Shell geometry mass integration
newton/_src/utils/import_mjcf.py
Shell geoms now use non-solid configuration and receive explicit or density-derived mass and inertia updates.
Native MuJoCo parity validation
newton/tests/test_import_mjcf.py, CHANGELOG.md
Added regression coverage for primitive shell inertia and documented the importer support.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MJCF
  participant Importer
  participant NewtonBody
  participant MuJoCoTest
  MJCF->>Importer: Parse primitive geom with shellinertia
  Importer->>Importer: Compute surface area and shell inertia
  Importer->>NewtonBody: Apply shell mass and inertia
  MuJoCoTest->>NewtonBody: Compare mass and diagonal inertia
  MuJoCoTest->>MuJoCo: Compare native mass properties
Loading

Possibly related PRs

Suggested reviewers: adenzler-nvidia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the fix for MJCF primitive shell inertia.
Linked Issues check ✅ Passed The changes support shellinertia for all required primitive geoms, mass paths, MuJoCo formulas, default resolution, and collision preservation [#3737].
Out of Scope Changes check ✅ Passed The implementation, regression test, and changelog entry directly support the linked issue and stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
CHANGELOG.md (1)

98-98: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add the issue reference.

Neighboring Fixed entries cite the linked issue, for example lines 122, 136, and 139. This fix resolves issue #3737.

♻️ Proposed entry
-- Import MJCF primitive geom `shellinertia` mass properties.
+- Import MJCF primitive geom `shellinertia` mass properties. (`#3737`)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.md` at line 98, Update the MJCF primitive geom “shellinertia”
changelog entry to include the issue reference `#3737`, matching the format used
by neighboring Fixed entries.

Source: Path instructions

newton/_src/utils/import_mjcf.py (1)

1308-1318: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Warn when shellinertia="true" is ignored.

Line 878 restricts shell handling to five primitive types. A mesh geom with shellinertia="true" is common in MJCF assets. For such geoms the importer keeps the solid volumetric result and reports nothing, so the mass and inertia silently differ from native MuJoCo.

Add a verbose warning for the ignored case so users can detect the gap.

♻️ Proposed warning for unsupported shell types
             primitive_shell_inertia = geom_attrib.get("shellinertia", "false").lower() == "true" and geom_type in {
                 "sphere",
                 "capsule",
                 "cylinder",
                 "ellipsoid",
                 "box",
             }
+            if not primitive_shell_inertia and geom_attrib.get("shellinertia", "false").lower() == "true" and verbose:
+                print(
+                    f"Warning: shellinertia is not supported for geom type '{geom_type}' "
+                    f"({geom_name}); using solid mass properties"
+                )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@newton/_src/utils/import_mjcf.py` around lines 1308 - 1318, In the MJCF geom
import logic near the primitive shell handling, add a verbose warning when
shellinertia is requested for an unsupported geom type such as mesh, while
preserving the existing solid volumetric mass and inertia behavior. Reuse the
importer’s existing verbose warning mechanism and ensure supported types
continue through the current _compute_mjcf_primitive_shell_inertia path
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@CHANGELOG.md`:
- Line 98: Update the MJCF primitive geom “shellinertia” changelog entry to
include the issue reference `#3737`, matching the format used by neighboring Fixed
entries.

In `@newton/_src/utils/import_mjcf.py`:
- Around line 1308-1318: In the MJCF geom import logic near the primitive shell
handling, add a verbose warning when shellinertia is requested for an
unsupported geom type such as mesh, while preserving the existing solid
volumetric mass and inertia behavior. Reuse the importer’s existing verbose
warning mechanism and ensure supported types continue through the current
_compute_mjcf_primitive_shell_inertia path unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6246d9ca-6e6f-44c3-82ef-c657f98caba4

📥 Commits

Reviewing files that changed from the base of the PR and between 0f97d2a and 59dd8c2.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • newton/_src/utils/import_mjcf.py
  • newton/tests/test_import_mjcf.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MJCF importer ignores primitive geom shellinertia

1 participant