newton.CollisionPipelineUnified#

class newton.CollisionPipelineUnified(shape_count, particle_count, shape_pairs_filtered=None, rigid_contact_max=None, rigid_contact_max_per_pair=10, rigid_contact_margin=0.01, soft_contact_max=None, soft_contact_margin=0.01, edge_sdf_iter=10, iterate_mesh_vertices=True, requires_grad=False, device=None, broad_phase_mode=BroadPhaseMode.NXN, shape_collision_group=None, shape_world=None, shape_flags=None, sap_sort_type=None, enable_contact_matching=False)[source]#

Bases: object

Collision pipeline using NarrowPhase class for narrow phase collision detection.

This is similar to CollisionPipelineUnified but uses the NarrowPhase API, mainly for testing purposes.

classmethod from_model(model, rigid_contact_max_per_pair=None, rigid_contact_margin=0.01, soft_contact_max=None, soft_contact_margin=0.01, edge_sdf_iter=10, iterate_mesh_vertices=True, requires_grad=None, broad_phase_mode=BroadPhaseMode.NXN, shape_pairs_filtered=None, sap_sort_type=None, enable_contact_matching=False)#

Create a CollisionPipelineUnified instance from a Model.

Parameters:
  • model (Model) – The simulation model.

  • rigid_contact_max_per_pair (int | None, optional) – Maximum number of contact points per shape pair. If None, uses model.rigid_contact_max and sets per-pair to 0.

  • rigid_contact_margin (float, optional) – Margin for rigid contact generation. Defaults to 0.01.

  • soft_contact_max (int | None, optional) – Maximum number of soft contacts to allocate.

  • soft_contact_margin (float, optional) – Margin for soft contact generation. Defaults to 0.01.

  • edge_sdf_iter (int, optional) – Number of iterations for edge SDF collision. Defaults to 10.

  • iterate_mesh_vertices (bool, optional) – Whether to iterate mesh vertices for collision. Defaults to True.

  • requires_grad (bool | None, optional) – Whether to enable gradient computation. If None, uses model.requires_grad.

  • broad_phase_mode (BroadPhaseMode, optional) – Broad phase collision detection mode. Defaults to BroadPhaseMode.NXN.

  • shape_pairs_filtered (wp.array | None, optional) – Precomputed shape pairs for EXPLICIT mode. Required when broad_phase_mode is BroadPhaseMode.EXPLICIT. For NXN/SAP modes, can use model.shape_contact_pairs if available.

  • sap_sort_type (SAPSortType | None, optional) – Sorting algorithm for SAP broad phase. Only used when broad_phase_mode is BroadPhaseMode.SAP. If None, uses default (SEGMENTED).

  • enable_contact_matching (bool, optional) – Whether to enable contact matching data generation. If True, allocates and populates contact_pair_key and contact_key arrays. Defaults to False.

Returns:

The constructed collision pipeline.

Return type:

CollisionPipeline

__init__(shape_count, particle_count, shape_pairs_filtered=None, rigid_contact_max=None, rigid_contact_max_per_pair=10, rigid_contact_margin=0.01, soft_contact_max=None, soft_contact_margin=0.01, edge_sdf_iter=10, iterate_mesh_vertices=True, requires_grad=False, device=None, broad_phase_mode=BroadPhaseMode.NXN, shape_collision_group=None, shape_world=None, shape_flags=None, sap_sort_type=None, enable_contact_matching=False)#

Initialize the CollisionPipelineUnified.

Parameters:
  • shape_count (int) – Number of shapes in the simulation.

  • particle_count (int) – Number of particles in the simulation.

  • shape_pairs_filtered (wp.array | None, optional) – Precomputed shape pairs for EXPLICIT broad phase mode. Required when broad_phase_mode is BroadPhaseMode.EXPLICIT, ignored otherwise.

  • rigid_contact_max (int | None, optional) – Maximum number of rigid contacts to allocate. If None, computed as shape_pairs_max * rigid_contact_max_per_pair.

  • rigid_contact_max_per_pair (int, optional) – Maximum number of contact points per shape pair. Defaults to 10.

  • rigid_contact_margin (float, optional) – Margin for rigid contact generation. Defaults to 0.01.

  • soft_contact_max (int | None, optional) – Maximum number of soft contacts to allocate. If None, computed as shape_count * particle_count.

  • soft_contact_margin (float, optional) – Margin for soft contact generation. Defaults to 0.01.

  • edge_sdf_iter (int, optional) – Number of iterations for edge SDF collision. Defaults to 10.

  • iterate_mesh_vertices (bool, optional) – Whether to iterate mesh vertices for collision. Defaults to True.

  • requires_grad (bool, optional) – Whether to enable gradient computation. Defaults to False.

  • device (Devicelike, optional) – The device on which to allocate arrays and perform computation.

  • broad_phase_mode (BroadPhaseMode, optional) – Broad phase mode for collision detection. - BroadPhaseMode.NXN: Use all-pairs AABB broad phase (O(N²), good for small scenes) - BroadPhaseMode.SAP: Use sweep-and-prune AABB broad phase (O(N log N), better for larger scenes) - BroadPhaseMode.EXPLICIT: Use precomputed shape pairs (most efficient when pairs known) Defaults to BroadPhaseMode.NXN.

  • shape_collision_group (wp.array | None, optional) – Array of collision group IDs for each shape. Used during broad phase kernel execution to filter pairs based on collision group rules.

  • shape_world (wp.array | None, optional) – Array of world indices for each shape. Required by NXN and SAP broad phases to organize geometries by world. If None, will be set during collide().

  • shape_flags (wp.array | None, optional) – Array of shape flags (ShapeFlags) for each shape. Used by NXN and SAP broad phases to filter out non-colliding shapes (e.g., visual-only). If provided, only shapes with COLLIDE_SHAPES flag will participate in broad phase.

  • sap_sort_type (SAPSortType | None, optional) – Sorting algorithm for SAP broad phase. Only used when broad_phase_mode is BroadPhaseMode.SAP. Options: SEGMENTED or TILE. If None, uses default (SEGMENTED).

  • enable_contact_matching (bool, optional) – Whether to enable contact matching data generation. If True, allocates buffers for contact_pair_key and contact_key arrays that can be used with ContactMatcher for warm-starting physics solvers. Defaults to False.

collide(model, state)#

Run the collision pipeline using NarrowPhase.

Parameters:
  • model (Model) – The simulation model

  • state (State) – The current simulation state

Returns:

The generated contacts

Return type:

Contacts