Skip to content

Preserve explicit mass for small MJCF geoms - #4160

Open
elrnv wants to merge 1 commit into
newton-physics:mainfrom
elrnv:fix/small-body-mass-properties
Open

Preserve explicit mass for small MJCF geoms#4160
elrnv wants to merge 1 commit into
newton-physics:mainfrom
elrnv:fix/small-body-mass-properties

Conversation

@elrnv

@elrnv elrnv commented Sep 4, 2026

Copy link
Copy Markdown

Context

Using a sphere collider the size of a human finger tip fails in the MJCF pipeline. This PR tries to resolve this.

[This PR is AI generated, but human reviewed]

Description

Preserve authored mass and inertia for small MJCF sphere, cylinder, capsule, and ellipsoid geoms.

The previous one-cubic-centimeter unit-density cutoff incorrectly discarded explicit mass for realistic small primitives. Lower the cutoff to the volume of a cube measuring 0.1 mm on each side while retaining protection against effectively degenerate geometry.

Add regression coverage for small primitives and values immediately above and below the new cutoff.

Checklist

  • New or existing tests cover these changes
  • The documentation is up to date with these changes
  • For user-facing changes, a fragment has been added by following the changelog fragment instructions

Test plan

  • uv run --extra dev -m newton.tests -k test_explicit_geom_mass_for_small_primitives

Bug fix

Steps to reproduce:

  1. Import an MJCF body containing a 5 mm-radius sphere with an explicit mass.
  2. Finalize the model.
  3. Observe that the explicit mass and inertia are discarded.

Minimal reproduction:

import newton

mjcf = """
<mujoco>
    <worldbody>
        <body>
            <freejoint/>
            <geom type="sphere" size="0.005" mass="0.1"/>
        </body>
    </worldbody>
</mujoco>
"""

builder = newton.ModelBuilder()
builder.add_mjcf(mjcf)
model = builder.finalize()

print(model.body_mass.numpy()[0])
print(model.body_inertia.numpy()[0])

Before this change, the mass and inertia are zero. Afterward, the authored mass is 0.1 and the inertia is nonzero.

Summary by CodeRabbit

  • Bug Fixes

    • Explicit mass and inertia values are now preserved for very small MJCF sphere, cylinder, capsule, and ellipsoid geoms when their reference mass is above the supported cutoff.
    • Extremely small geoms below the cutoff continue to receive zero mass and inertia.
  • Tests

    • Added coverage for explicit mass handling across small primitive geometries and cutoff boundary cases.

Replace the one-cubic-centimeter unit-density cutoff with the volume
of a cube measuring 0.1 mm on each side.

This preserves authored mass and inertia for realistic small primitives
while retaining a guard for effectively degenerate geometry.

Add regression coverage above and below the new cutoff.
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 4, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: elrnv / name: Egor Larionov (5bbac60)

@elrnv
elrnv requested a deployment to external-pr-approval September 4, 2026 18:59 — with GitHub Actions Waiting
@elrnv
elrnv requested a deployment to external-pr-approval September 4, 2026 18:59 — with GitHub Actions Waiting
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Team

Run ID: bf48b092-6cdd-40e1-a61e-4496fafa0408

📥 Commits

Reviewing files that changed from the base of the PR and between d37f4d3 and 5bbac60.

📒 Files selected for processing (3)
  • changelog/+mjcf-explicit-small-mass-9c3a2f.fixed.md
  • newton/_src/utils/import_mjcf.py
  • newton/tests/test_import_mjcf.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The MJCF importer now applies explicit mass scaling to small sphere, cylinder, capsule, and ellipsoid geoms when their reference mass meets the new cutoff. Tests cover masses and inertia above and below the cutoff.

Changes

MJCF small primitive mass handling

Layer / File(s) Summary
Lower explicit-mass inertia threshold
newton/_src/utils/import_mjcf.py
Defines a 1.0e-12 reference-mass cutoff and uses it for explicit-mass inertia scaling across sphere, cylinder, capsule, and ellipsoid geoms.
Validate small primitive imports
newton/tests/test_import_mjcf.py, changelog/+mjcf-explicit-small-mass-9c3a2f.fixed.md
Adds coverage for authored masses and non-zero inertia above the cutoff, zero mass and inertia below it, and documents the change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5bbac

MJCF imports now preserve explicitly authored mass and inertia for small supported primitive geoms while retaining degenerate-geometry protection. Boundary and primitive regression coverage support merge readiness with no remaining actionable risk.

Suggested reviewers: eric-heiden, vreutskyy

🚥 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 main change: preserving explicitly authored mass for small MJCF geoms.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 u…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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.

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.

1 participant