Skip to content

Add lock_inertia flag to ModelBuilder.add_link, add_body#1422

Merged
eric-heiden merged 1 commit into
newton-physics:mainfrom
eric-heiden:body-inertia-locking
Jan 21, 2026
Merged

Add lock_inertia flag to ModelBuilder.add_link, add_body#1422
eric-heiden merged 1 commit into
newton-physics:mainfrom
eric-heiden:body-inertia-locking

Conversation

@eric-heiden

@eric-heiden eric-heiden commented Jan 20, 2026

Copy link
Copy Markdown
Member

This flag (defaults to False) will prevent shapes to contribute mass, COM, inertia to a body.
Fixes #1330.

Summary by CodeRabbit

  • New Features

    • Added lock_inertia parameter to body and link creation methods, enabling users to prevent automatic mass and inertia updates when shapes are subsequently added to locked bodies.
  • Tests

    • Added tests verifying inertia locking behavior for shape addition and fixed joint collapse operations.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
@eric-heiden eric-heiden requested a review from vastsoun January 20, 2026 20:24
@coderabbitai

coderabbitai Bot commented Jan 20, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR introduces a per-body lock_inertia flag in ModelBuilder that prevents subsequent shape additions from modifying a body's mass, center of mass, or inertia. The flag is added as a parameter to add_body() and add_link(), propagated through joint collapses and builder merges, and respected during finalization operations.

Changes

Cohort / File(s) Summary
Core Builder Implementation
newton/_src/sim/builder.py
Added body_lock_inertia: list field to track per-body locking state. Extended add_body() and add_link() with new lock_inertia parameter. Updated inertia computation paths (finalize, _update_body_mass, shape inertia) to skip updates for locked bodies. Propagated lock flag through collapse_fixed_joints() and dfs() merge operations.
Unit Tests
newton/tests/test_model.py
Added test_lock_inertia_on_shape_addition() to verify locked bodies preserve mass/com/inertia when shapes are added. Added test_collapse_fixed_joints_with_locked_inertia() to verify lock state is preserved when collapsing fixed joints.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Add inertia verification, correction #440 #455: Modifies ModelBuilder's inertia handling paths (finalize, mass/inertia updates) alongside the main PR's per-body lock flag implementation; both affect overlapping code paths for inertia verification and updates during builder finalization.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a lock_inertia flag parameter to two public methods.
Linked Issues check ✅ Passed The PR fully addresses issue #1330 by implementing the proposed lock_inertia flag on add_body and add_link that prevents shape additions from modifying mass/inertia/COM.
Out of Scope Changes check ✅ Passed All changes are within scope: lock_inertia parameter addition, internal propagation through merge/collapse logic, and comprehensive test coverage for the feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@codecov

codecov Bot commented Jan 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@eric-heiden eric-heiden marked this pull request as ready for review January 20, 2026 23:47
@eric-heiden eric-heiden self-assigned this Jan 21, 2026

@vastsoun vastsoun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, seems to do the trick.

I think, however, that this solution is not ideal. We could consider in a future refactoring/reworking of the ModelBuilder, to handle this in a more systematic manner. For example, we could define some logic similar to that of USD, where automatic re-calculations happen only based on the data provided to the builder etc, and re-calculate if something is missing from the body specs, as well as to add a helper function that users can call to perform the recalculations.

@eric-heiden eric-heiden added this pull request to the merge queue Jan 21, 2026
Merged via the queue into newton-physics:main with commit 622a8c3 Jan 21, 2026
22 checks passed
jnskkmhr pushed a commit to jnskkmhr/newton that referenced this pull request Jan 22, 2026
…ysics#1422)

Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
eric-heiden added a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
…ysics#1422)

Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
@coderabbitai coderabbitai Bot mentioned this pull request Feb 6, 2026
4 tasks
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
…ysics#1422)

Signed-off-by: Eric Heiden <eric-heiden@outlook.com>
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.

Prevent overwriting body mass from shapes in ModelBuilder

2 participants