Skip to content

Add builder.add_joint_free in parse_body in import_usd#426

Merged
eric-heiden merged 11 commits into
newton-physics:mainfrom
apradhana:apradhana/fix_import_usd_add_free_body
Aug 1, 2025
Merged

Add builder.add_joint_free in parse_body in import_usd#426
eric-heiden merged 11 commits into
newton-physics:mainfrom
apradhana:apradhana/fix_import_usd_add_free_body

Conversation

@apradhana

@apradhana apradhana commented Jul 16, 2025

Copy link
Copy Markdown
Member

Purpose: In import_usd, free_floating_bodies should have free_joint. This should only be applied to bodies that are added by import_usd.

We want the result of parsing a USD as a model to also work with MJWarp. As MJWarp requires at least one joint, we add a free joint in the body that has none when we add a body to the builder. Here's an example of a simulation that we get after running the result of import_usd through MJWarp:
simple_drop_mjwarp

Here's the result of simulating cube_cylinder.usda that is in tests/assets through MJWarp and XPBD:
cube_cylinder_mjwarp_annotated
cube_cylinder_xpbd_annotated

Summary by CodeRabbit

  • New Features
    • Automatically adds free joints to bodies not connected by existing joints, enhancing simulation accuracy and flexibility.
    • Introduced a detailed 3D scene asset featuring physics-enabled objects with realistic materials and lighting.
  • Tests
    • Added a test verifying joint count correctness and material properties when importing the new 3D scene file.

Signed-off-by: apradhana <andre.pradhana@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The update adds a new method add_free_joints_to_floating_bodies to the ModelBuilder class in newton/sim/builder.py, which adds free joints to bodies that are not children in any joint and have positive mass. The import_usd.py script is modified to call this new method after setting inverse inertia matrices for bodies with the PhysicsMassAPI schema, before collapsing fixed joints. A new USD test asset cube_cylinder.usda is added, along with a unit test verifying the joint count and material properties after import. No other logic or function signatures are changed.

Changes

Cohort / File(s) Change Summary
ModelBuilder core logic
newton/sim/builder.py
Added ModelBuilder.add_free_joints_to_floating_bodies() method to add free joints to floating bodies.
USD import integration
newton/utils/import_usd.py
Inserted call to builder.add_free_joints_to_floating_bodies() after setting inverse inertia matrices.
Test assets
newton/tests/assets/cube_cylinder.usda
Added new USD scene file defining physics-enabled objects with materials, joints, and environment.
Unit tests
newton/tests/test_import_usd.py
Added test test_import_cube_cylinder_joint_count to verify joint count and material properties after importing cube_cylinder.usda.

Sequence Diagram(s)

sequenceDiagram
    participant import_usd
    participant builder

    import_usd->>builder: set_inverse_inertia_matrices()
    import_usd->>builder: add_free_joints_to_floating_bodies()
    import_usd->>builder: collapse_fixed_joints()
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • Milad-Rakhsha-NV

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bde49e4 and 9a3d056.

📒 Files selected for processing (2)
  • newton/sim/builder.py (1 hunks)
  • newton/tests/test_import_usd.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • newton/tests/test_import_usd.py
  • newton/sim/builder.py
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)
  • GitHub Check: Run GPU Benchmarks (Pull Request)
  • GitHub Check: run-newton-tests / newton-unittests (windows-latest)
  • GitHub Check: run-newton-tests / newton-unittests (ubuntu-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@apradhana apradhana temporarily deployed to external-pr-approval July 16, 2025 17:14 — with GitHub Actions Inactive
Comment thread newton/utils/import_usd.py Outdated

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e649ced and 0bc3284.

📒 Files selected for processing (1)
  • newton/utils/import_usd.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
newton/utils/import_usd.py (1)
newton/sim/builder.py (1)
  • add_joint_free (1106-1157)

Comment thread newton/utils/import_usd.py Outdated
Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: apradhana <andre.pradhana@gmail.com>

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
newton/tests/test_import_usd.py (1)

158-167: LGTM! Test correctly validates the new free joint functionality.

The test properly validates that the new add_free_joints_to_floating_bodies functionality works as expected, ensuring MJWarp compatibility by adding at least one joint to USD imports.

Consider enhancing the test with additional assertions to make it more comprehensive:

 @unittest.skipUnless(USD_AVAILABLE, "Requires usd-core")
 def test_import_cube_cylinder_joint_count(self):
+    """Test that floating bodies get free joints added for MJWarp compatibility."""
     builder = newton.ModelBuilder()
     parse_usd(
         os.path.join(os.path.dirname(__file__), "assets", "cube_cylinder.usda"),
         builder,
         collapse_fixed_joints=True,
         invert_rotations=True,
     )
     self.assertEqual(builder.joint_count, 1)
+    # Verify the added joint is a free joint
+    self.assertEqual(builder.joint_type[0], newton.JOINT_FREE)

This would provide better validation that the correct type of joint is being added and include documentation explaining the test's purpose.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 117d09f and 7af8c10.

📒 Files selected for processing (2)
  • newton/tests/assets/cube_cylinder.usda (1 hunks)
  • newton/tests/test_import_usd.py (1 hunks)
🧠 Learnings (1)
newton/tests/test_import_usd.py (1)

Learnt from: dylanturpin
PR: #394
File: newton/tests/test_ik.py:119-119
Timestamp: 2025-07-15T21:00:03.709Z
Learning: In the Newton physics engine codebase, it's acceptable to test private API functions (those prefixed with underscore) in unit and component tests, as the maintainers consider this appropriate for testing internal functionality.

✅ Files skipped from review due to trivial changes (1)
  • newton/tests/assets/cube_cylinder.usda
🧰 Additional context used
🧠 Learnings (1)
newton/tests/test_import_usd.py (1)

Learnt from: dylanturpin
PR: #394
File: newton/tests/test_ik.py:119-119
Timestamp: 2025-07-15T21:00:03.709Z
Learning: In the Newton physics engine codebase, it's acceptable to test private API functions (those prefixed with underscore) in unit and component tests, as the maintainers consider this appropriate for testing internal functionality.

⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)

Comment thread newton/sim/builder.py Outdated
Comment thread newton/tests/test_import_usd.py
Comment thread newton/utils/import_usd.py Outdated
Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: apradhana <andre.pradhana@gmail.com>
@codecov

codecov Bot commented Jul 30, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Eric Heiden <eheiden@nvidia.com>
@eric-heiden eric-heiden enabled auto-merge (squash) July 31, 2025 04:31
@apradhana

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@eric-heiden eric-heiden merged commit a406a95 into newton-physics:main Aug 1, 2025
11 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 30, 2025
4 tasks
eric-heiden added a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
…s#426)

Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: Eric Heiden <eheiden@nvidia.com>
Co-authored-by: Eric Heiden <eheiden@nvidia.com>
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
…s#426)

Signed-off-by: apradhana <andre.pradhana@gmail.com>
Signed-off-by: Eric Heiden <eheiden@nvidia.com>
Co-authored-by: Eric Heiden <eheiden@nvidia.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.

2 participants