newton.CollisionPipeline#
- class newton.CollisionPipeline(model, *, reduce_contacts=True, rigid_contact_max=None, max_triangle_pairs=1000000, shape_pairs_filtered=None, soft_contact_max=None, soft_contact_margin=0.01, requires_grad=None, broad_phase=None, narrow_phase=None, sdf_hydroelastic_config=None)[source]#
Bases:
objectFull-featured collision pipeline with GJK/MPR narrow phase and pluggable broad phase.
- Key features:
GJK/MPR algorithms for convex-convex collision detection
Multiple broad phase options: NXN (all-pairs), SAP (sweep-and-prune), EXPLICIT (precomputed pairs)
Mesh-mesh collision via SDF with contact reduction
Optional hydroelastic contact model for compliant surfaces
For most users, construct with
CollisionPipeline(model, ...).Note
Differentiable rigid contacts (the
rigid_contact_diff_*arrays whenrequires_gradis enabled) are experimental. The narrow phase stays frozen and gradients are a tangent approximation; validate accuracy and usefulness on your workflow before relying on them in optimization loops.- __init__(model, *, reduce_contacts=True, rigid_contact_max=None, max_triangle_pairs=1000000, shape_pairs_filtered=None, soft_contact_max=None, soft_contact_margin=0.01, requires_grad=None, broad_phase=None, narrow_phase=None, sdf_hydroelastic_config=None)#
Initialize the CollisionPipeline (expert API).
- Parameters:
model (Model) – The simulation model.
reduce_contacts (bool) – Whether to reduce contacts for mesh-mesh collisions. Defaults to True.
rigid_contact_max (int | None) – Maximum number of rigid contacts to allocate. Resolution order: - If provided, use this value. - Else if
model.rigid_contact_max > 0, use the model value. - Else estimate automatically from model shape and pair metadata.max_triangle_pairs (int) – Maximum number of triangle pairs allocated by narrow phase for mesh and heightfield collisions. Increase this when scenes with large/complex meshes or heightfields report triangle-pair overflow warnings.
soft_contact_max (int | None) – Maximum number of soft contacts to allocate. If None, computed as shape_count * particle_count.
soft_contact_margin (float) – Margin for soft contact generation. Defaults to 0.01.
requires_grad (bool | None) – Whether to enable gradient computation. If None, uses model.requires_grad.
broad_phase (Literal['nxn', 'sap', 'explicit'] | BroadPhaseAllPairs | BroadPhaseSAP | BroadPhaseExplicit | None) – Either a broad phase mode string (“explicit”, “nxn”, “sap”) or a prebuilt broad phase instance for expert usage.
narrow_phase (NarrowPhase | None) – Optional prebuilt narrow phase instance. Must be provided together with a broad phase instance for expert usage.
shape_pairs_filtered (wp.array(dtype=wp.vec2i) | None) – Precomputed shape pairs for EXPLICIT mode. When broad_phase is “explicit”, uses model.shape_contact_pairs if not provided. For “nxn”/”sap” modes, ignored.
sdf_hydroelastic_config (HydroelasticSDF.Config | None) – Configuration for hydroelastic collision handling. Defaults to None.
Note
When
requires_gradis true (explicitly or viamodel.requires_grad), rigid-contact autodiff viarigid_contact_diff_*is experimental; seecollide().
- collide(state, contacts, *, soft_contact_margin=None)#
Run the collision pipeline using NarrowPhase.
Safe to call inside a
wp.Tapecontext. The non-differentiable broad-phase and narrow-phase kernels are launched with tape recording hardcodedrecord_tape=Falseinternally. The differentiable kernels (soft-contact generation and rigid-contact augmentation) are recorded on the tape so that gradients flow throughstate.body_qandstate.particle_q.When
requires_grad=True, the differentiable rigid-contact arrays (contacts.rigid_contact_diff_*) are populated by a lightweight augmentation kernel that reconstructs world-space contact points from the frozen narrow-phase output through the body transforms.Note
This rigid-contact gradient path is experimental: usefulness and numerical behaviour are still being assessed across real-world scenarios.
- contacts()#
Allocate and return a new
newton.Contactsobject for this pipeline.The returned buffer uses this pipeline’s
requires_gradflag (resolved at construction from the argument ormodel.requires_grad).- Returns:
A newly allocated contacts buffer sized for this pipeline.
- Return type:
Note
If
requires_gradis true,rigid_contact_diff_*arrays may be allocated; rigid-contact differentiability is experimental (seecollide()).