Skip to content

Adds rigid object collections for Newton - #4853

Merged
kellyguo11 merged 23 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/newton_rigid_object_collection
Mar 6, 2026
Merged

kellyguo11 merged 23 commits into
isaac-sim:developfrom
AntoineRichard:antoiner/feat/newton_rigid_object_collection

Conversation

@AntoineRichard

@AntoineRichard AntoineRichard commented Mar 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds rigid object collections for Newton. Builds ontop of #4818

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@AntoineRichard
AntoineRichard requested a review from ooctipus March 6, 2026 14:34
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Mar 6, 2026
@greptile-apps

greptile-apps Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a Newton physics backend implementation of RigidObjectCollection — mirroring the existing PhysX implementation — along with a comprehensive test suite, Newton backend integration in shared interface tests, and several bug fixes to the existing Articulation and RigidObject Newton assets.

Key additions and changes:

  • New RigidObjectCollection and RigidObjectCollectionData classes for Newton, using a single ArticulationView with a combined fnmatch pattern to represent all body types in a 2D (num_envs, num_bodies) layout.
  • _build_combined_pattern static helper that merges per-body USD path expressions into one glob by wildcarding differing segments.
  • Articulation fixes: switched wp.copy() → .assign() for joint target writes, applied _resolve_mask() consistently, and registered a PHYSICS_READY rebind callback to prevent stale bindings after sim.reset().
  • RigidObjectData fixes: lazy buffer init, is_contiguous property usage, CoM kernel naming, and inertia binding rework.
  • Mask type standardization: test helpers changed from int32 masks to wp.bool masks across all interface test files.
  • Two critical issues found in the new RigidObjectCollectionData:
    • _body_inertia is created with wp.clone() (a disconnected copy from Newton's model), meaning set_inertias_index / set_inertias_mask writes are silently dropped and never reach the physics engine.
    • No PHYSICS_READY rebind callback is registered in RigidObjectCollection._initialize_impl, leaving all simulation pointers stale after sim.reset() — unlike Articulation which correctly registers this callback in the same PR.

Confidence Score: 2/5

  • Not safe to merge — two correctness bugs in the new RigidObjectCollection must be resolved first.
  • The new RigidObjectCollection has two logic bugs: (1) inertia writes go to a cloned/disconnected array rather than Newton's model, silently breaking set_inertias_index/mask; (2) no PHYSICS_READY rebind callback means all sim bindings become stale after sim.reset(). These are in the core new feature being added by this PR.
  • Pay close attention to rigid_object_collection_data.py (inertia clone issue) and rigid_object_collection.py (missing PHYSICS_READY callback, unused object_ids in reset, and overly broad _build_combined_pattern).

Important Files Changed

Filename Overview
source/isaaclab_newton/isaaclab_newton/assets/rigid_object_collection/rigid_object_collection.py New Newton RigidObjectCollection implementation — missing PHYSICS_READY rebind callback (causes stale bindings after sim.reset()), object_ids parameter in reset() is resolved but unused, and _build_combined_pattern may match unintended USD prims.
source/isaaclab_newton/isaaclab_newton/assets/rigid_object_collection/rigid_object_collection_data.py New data container for Newton RigidObjectCollection — _body_inertia is created via wp.clone() (disconnected from Newton's model), making set_inertias_index/set_inertias_mask writes ineffective. Inconsistent with RigidObjectData where _sim_bind_body_inertia is a direct view.
source/isaaclab_newton/isaaclab_newton/assets/articulation/articulation.py Adds PHYSICS_READY rebind callback and fixes .assign() vs wp.copy() for joint targets and _resolve_mask usage for env_mask — changes look correct and consistent.
source/isaaclab_newton/isaaclab_newton/assets/rigid_object/rigid_object_data.py Bug fixes for lazy buffer initialization, is_contiguous usage, and body_com_pos_b kernel input naming — changes look sound. Inertia uses a direct view (_sim_bind_body_inertia) without clone, correctly enabling sim writes.
source/isaaclab_newton/isaaclab_newton/test/mock_interfaces/views/mock_articulation_view.py Adds MockNewtonCollectionView with correct (N, B) shaped bindings for rigid object collection testing, and refactors MockNewtonArticulationView — well-structured mock implementations.
source/isaaclab/test/assets/test_rigid_object_collection_iface.py Extends interface tests with Newton backend for RigidObjectCollection — correctly uses bool masks, adds xfail markers for CoM orientation differences, and wires in the new Newton factory function.
source/isaaclab_newton/test/assets/test_rigid_object_collection.py Comprehensive Newton-specific RigidObjectCollection integration tests with multi-env parametrization — good coverage of state writes, resets, external forces, and property consistency checks.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class BaseRigidObjectCollection {
        <<abstract>>
        +reset()
        +write_data_to_sim()
        +update()
    }

    class RigidObjectCollection {
        +cfg: RigidObjectCollectionCfg
        +__backend_name__: str = "newton"
        +data: RigidObjectCollectionData
        +num_instances: int
        +num_bodies: int
        +body_names: list[str]
        +root_view: ArticulationView
        +instantaneous_wrench_composer: WrenchComposer
        +permanent_wrench_composer: WrenchComposer
        +reset(env_ids, object_ids, env_mask, object_mask)
        +write_data_to_sim()
        +update(dt)
        +find_bodies(name_keys)
        +write_body_pose_to_sim_index()
        +write_body_pose_to_sim_mask()
        +write_body_link_pose_to_sim_index()
        +write_body_com_pose_to_sim_index()
        +write_body_com_velocity_to_sim_index()
        +write_body_link_velocity_to_sim_index()
        +set_masses_index() / set_masses_mask()
        +set_coms_index() / set_coms_mask()
        +set_inertias_index() / set_inertias_mask()
        -_initialize_impl()
        -_create_buffers()
        -_process_cfg()
        -_build_combined_pattern(exprs) $
        -_resolve_env_ids() / _resolve_body_ids()
        -_resolve_env_mask() / _resolve_body_mask()
    }

    class RigidObjectCollectionData {
        +__backend_name__: str = "newton"
        +num_instances: int
        +num_bodies: int
        +body_names: list[str]
        +body_link_pose_w: wp.array
        +body_com_pose_w: wp.array
        +body_com_vel_w: wp.array
        +body_com_acc_w: wp.array
        +body_com_pos_b: wp.array
        +body_mass: wp.array
        +body_inertia: wp.array
        +projected_gravity_b: wp.array
        +heading_w: wp.array
        +default_body_pose: wp.array
        +default_body_vel: wp.array
        +update(dt)
        -_create_simulation_bindings()
        -_sim_bind_body_link_pose_w
        -_sim_bind_body_com_vel_w
        -_sim_bind_body_com_pos_b
        -_sim_bind_body_mass
        -_body_inertia [clone - not sim binding!]
    }

    class ArticulationView {
        <<newton>>
        +count: int
        +get_root_transforms(state)
        +get_root_velocities(state)
        +get_attribute(name, model)
    }

    class NewtonManager {
        <<singleton>>
        +get_model()$
        +get_state_0()$
        +get_dt()$
        +add_model_change(flags)$
        +register_callback(fn, event, name)$
    }

    class WrenchComposer {
        +active: bool
        +composed_force: wp.array
        +composed_torque: wp.array
        +reset(env_ids)
    }

    BaseRigidObjectCollection <|-- RigidObjectCollection
    RigidObjectCollection *-- RigidObjectCollectionData
    RigidObjectCollection *-- WrenchComposer : instantaneous + permanent
    RigidObjectCollection --> NewtonManager : uses
    RigidObjectCollectionData --> ArticulationView : weakref proxy
    RigidObjectCollectionData --> NewtonManager : reads model/state
Loading

Last reviewed commit: 955bd4e

Comment on lines +599 to +601
# -- Body inertia: (num_envs, num_bodies, 1) mat33f → squeeze, clone to contiguous, convert to float32
inertia_mat33 = self._root_view.get_attribute("body_inertia", model)[:, :, 0]
self._body_inertia = wp.clone(inertia_mat33).view(wp.float32).reshape((self.num_instances, self.num_bodies, 9))

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.

Inertia binding is a disconnected clone, not a sim binding

_body_inertia is created via wp.clone(), which allocates a new array copied from Newton's model memory — it is not a direct binding. This is inconsistent with how RigidObjectData handles the same attribute:

# rigid_object_data.py (_create_simulation_bindings)
_inertia_mat33 = self._root_view.get_attribute("body_inertia", SimulationManager.get_model())[:, 0]
self._sim_bind_body_inertia = _inertia_mat33.view(wp.float32).reshape(...)  # direct binding, no clone

Because _body_inertia is a clone, calling set_inertias_index or set_inertias_mask (which write to self.data._body_inertia) does not update Newton's simulation model. The comment on line ~1009 that says "writes go directly to Newton's state via the 2D binding" is therefore incorrect for the inertia case.

If wp.clone() is required here because the 2D slice [:, :, 0] yields non-contiguous memory (preventing .view()), the write methods must copy data back to the original binding (e.g., via wp.copy(inertia_mat33, self._body_inertia.view(wp.mat33f))), or Newton's model will never receive the updated inertia values.

Comment on lines +1128 to +1138
# container for data access
self._data = RigidObjectCollectionData(self._root_view, self.num_bodies, self.device)

# create buffers
self._create_buffers()
# process configuration
self._process_cfg()
# update the rigid body data
self.update(0.0)
# Let the rigid object collection data know that it is fully instantiated and ready to use.
self.data.is_primed = True

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.

Missing PHYSICS_READY rebind callback after sim reset

Articulation._initialize_impl registers a PHYSICS_READY callback to re-run _data._create_simulation_bindings() when Newton recreates the model/state after sim.reset():

# From articulation.py
self._physics_ready_handle = SimulationManager.register_callback(
    lambda _: self._data._create_simulation_bindings(),
    PhysicsEvent.PHYSICS_READY,
    name=f"articulation_rebind_{self.cfg.prim_path}",
)

RigidObjectCollection._initialize_impl has no equivalent, so _sim_bind_body_link_pose_w, _sim_bind_body_com_vel_w, _sim_bind_body_com_pos_b, _sim_bind_body_external_wrench, _sim_bind_body_mass, and _body_inertia will all point to stale warp arrays after the first full sim reset — causing silent data corruption or crashes.

The CHANGELOG lists this rebind fix as already applied to both ArticulationData and RigidObjectData, so the new collection class should receive the same treatment at initialization.

Comment on lines +160 to +182
def reset(
self,
env_ids: Sequence[int] | torch.Tensor | wp.array | None = None,
object_ids: slice | torch.Tensor | None = None,
env_mask: wp.array | None = None,
object_mask: wp.array | None = None,
) -> None:
"""Resets all internal buffers of selected environments and objects.

Args:
env_ids: Environment indices. If None, then all indices are used.
object_ids: Object indices. If None, then all indices are used.
env_mask: Environment mask. If None, then all the instances are updated. Shape is (num_instances,).
object_mask: Object mask. Not used currently.
"""
# resolve all indices
if env_ids is None:
env_ids = self._ALL_ENV_INDICES
if object_ids is None:
object_ids = self._ALL_BODY_INDICES
# reset external wrench
self._instantaneous_wrench_composer.reset(env_ids)
self._permanent_wrench_composer.reset(env_ids)

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.

object_ids parameter resolved but never consumed

object_ids is resolved to self._ALL_BODY_INDICES when None, but is never passed to either _instantaneous_wrench_composer.reset() or _permanent_wrench_composer.reset(). The docstring says "Object indices. If None, then all indices are used" — suggesting per-object reset should be supported, but the parameter has no effect.

Either the parameter should be removed/marked as reserved, or the wrench composers should be updated to accept a body/object subset. If intentionally unused, the docstring should say "Not used currently" (as done for object_mask).

Comment on lines +1227 to +1264
@staticmethod
def _build_combined_pattern(prim_path_exprs: list[str]) -> str:
"""Build a single fnmatch pattern that matches all body types.

Compares path segments across all expressions and wildcards the segments that differ.
For example, given::

["/World/Env_*/DexCube/Cube", "/World/Env_*/DexSphere/Sphere"]

produces ``"/World/Env_*/*/*"``.

Args:
prim_path_exprs: List of prim path expressions, one per body type.

Returns:
A single fnmatch pattern string.

Raises:
ValueError: If the expressions have different numbers of path segments.
"""
if len(prim_path_exprs) == 1:
return prim_path_exprs[0]

split_paths = [p.split("/") for p in prim_path_exprs]
lengths = {len(s) for s in split_paths}
if len(lengths) != 1:
raise ValueError(
f"Cannot build combined pattern: path expressions have different segment counts: {prim_path_exprs}"
)

combined_segments = []
for segments in zip(*split_paths):
unique = set(segments)
if len(unique) == 1:
combined_segments.append(segments[0])
else:
combined_segments.append("*")
return "/".join(combined_segments)

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.

_build_combined_pattern could produce overly broad glob patterns

The method wildcards every path segment where the inputs differ, which can easily create patterns that match unintended USD prims. For example:

  • /World/Env_*/ObjectA/Body and /World/Env_*/ObjectB/Lid
    → combined: /World/Env_*/*/*

This would match any prim two levels below /World/Env_*/, not just the two intended rigid bodies. If the USD stage contains other prims at that depth (e.g., geometry, lights, sensors), ArticulationView would pick them up, silently breaking the num_bodies count and index mapping.

Consider adding a post-construction check that self._root_view.count == expected_total_count (i.e., num_envs * num_bodies) to detect over-matching early, or log a warning when the combined pattern contains segments that were wildcarded.

@kellyguo11
kellyguo11 merged commit 4a99ae5 into isaac-sim:develop Mar 6, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants