-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Exposes Newton collision pipeline configuration through NewtonCfg #5219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AntoineRichard
merged 3 commits into
isaac-sim:develop
from
ooctipus:expose_newton_collision_pipeline
Apr 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
source/isaaclab_newton/isaaclab_newton/physics/newton_collision_cfg.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Configuration for Newton collision pipeline.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Literal | ||
|
|
||
| from isaaclab.utils import configclass | ||
|
|
||
|
|
||
| @configclass | ||
| class HydroelasticSDFCfg: | ||
| """Configuration for SDF-based hydroelastic collision handling. | ||
|
|
||
| Hydroelastic contacts generate distributed contact areas instead of point contacts, | ||
| providing more realistic force distribution for manipulation and compliant surfaces. | ||
|
|
||
| For more details, see the `Newton Collisions Guide`_. | ||
|
|
||
| .. _Newton Collisions Guide: https://newton-physics.github.io/newton/latest/concepts/collisions.html#hydroelastic-contacts | ||
| """ | ||
|
|
||
| reduce_contacts: bool = True | ||
| """Whether to reduce contacts to a smaller representative set per shape pair. | ||
|
|
||
| When False, all generated contacts are passed through without reduction. | ||
|
|
||
| Defaults to ``True`` (same as Newton's default). | ||
| """ | ||
|
|
||
| buffer_fraction: float = 1.0 | ||
| """Fraction of worst-case hydroelastic buffer allocations. Range: (0, 1]. | ||
|
|
||
| Lower values reduce memory usage but may cause overflows in dense scenes. | ||
| Overflows are bounds-safe and emit warnings; increase this value when warnings appear. | ||
|
|
||
| Defaults to ``1.0`` (same as Newton's default). | ||
| """ | ||
|
|
||
| normal_matching: bool = True | ||
| """Whether to rotate reduced contact normals to align with aggregate force direction. | ||
|
|
||
| Only active when ``reduce_contacts`` is True. | ||
|
|
||
| Defaults to ``True`` (same as Newton's default). | ||
| """ | ||
|
|
||
| anchor_contact: bool = False | ||
| """Whether to add an anchor contact at the center of pressure for each normal bin. | ||
|
|
||
| The anchor contact helps preserve moment balance. Only active when ``reduce_contacts`` is True. | ||
|
|
||
| Defaults to ``False`` (same as Newton's default). | ||
| """ | ||
|
|
||
| margin_contact_area: float = 0.01 | ||
| """Contact area [m^2] used for non-penetrating contacts at the margin. | ||
|
|
||
| Defaults to ``0.01`` (same as Newton's default). | ||
| """ | ||
|
|
||
| output_contact_surface: bool = False | ||
| """Whether to output hydroelastic contact surface vertices for visualization. | ||
|
|
||
| Defaults to ``False`` (same as Newton's default). | ||
| """ | ||
|
|
||
|
|
||
| @configclass | ||
| class NewtonCollisionPipelineCfg: | ||
| """Configuration for Newton collision pipeline. | ||
|
|
||
| Full-featured collision pipeline with GJK/MPR narrow phase and pluggable broad phase. | ||
| When this config is set on :attr:`NewtonCfg.collision_cfg`: | ||
|
|
||
| - **MJWarpSolverCfg**: Newton's collision pipeline replaces MuJoCo's internal contact solver. | ||
| - **Other solvers** (XPBD, Featherstone, etc.): Configures the collision pipeline parameters | ||
| (these solvers always use Newton's collision pipeline). | ||
|
|
||
| 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 more details, see the `Newton Collisions Guide`_ and `CollisionPipeline API`_. | ||
|
|
||
| .. _Newton Collisions Guide: https://newton-physics.github.io/newton/latest/concepts/collisions.html | ||
| .. _CollisionPipeline API: https://newton-physics.github.io/newton/api/_generated/newton.CollisionPipeline.html | ||
| """ | ||
|
|
||
| broad_phase: Literal["explicit", "nxn", "sap"] = "explicit" | ||
| """Broad phase algorithm for collision detection. | ||
|
|
||
| Options: | ||
|
|
||
| - ``"explicit"``: Use precomputed shape pairs from ``model.shape_contact_pairs``. | ||
| - ``"nxn"``: All-pairs brute force. Simple but O(n^2) complexity. | ||
| - ``"sap"``: Sweep-and-prune. Good for scenes with many dynamic objects. | ||
|
|
||
| Defaults to ``"explicit"`` (same as Newton's default when ``broad_phase=None``). | ||
| """ | ||
|
|
||
| reduce_contacts: bool = True | ||
| """Whether to reduce contacts for mesh-mesh collisions. | ||
|
|
||
| When True, uses shared memory contact reduction to select representative contacts. | ||
| Improves performance and stability for meshes with many vertices. | ||
|
|
||
| Defaults to ``True`` (same as Newton's default). | ||
| """ | ||
|
|
||
| rigid_contact_max: int | None = None | ||
| """Maximum number of rigid contacts to allocate. | ||
|
|
||
| Resolution order: | ||
|
|
||
| 1. If provided, use this value. | ||
| 2. Else if ``model.rigid_contact_max > 0``, use the model value. | ||
| 3. Else estimate automatically from model shape and pair metadata. | ||
|
|
||
| Defaults to ``None`` (auto-estimate, same as Newton's default). | ||
| """ | ||
|
|
||
| max_triangle_pairs: int = 1_000_000 | ||
| """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. | ||
|
|
||
| Defaults to ``1_000_000`` (same as Newton's default). | ||
| """ | ||
|
|
||
| soft_contact_max: int | None = None | ||
| """Maximum number of soft contacts to allocate. | ||
|
|
||
| If None, computed as ``shape_count * particle_count``. | ||
|
|
||
| Defaults to ``None`` (auto-compute, same as Newton's default). | ||
| """ | ||
|
|
||
| soft_contact_margin: float = 0.01 | ||
| """Margin [m] for soft contact generation. | ||
|
|
||
| Defaults to ``0.01`` (same as Newton's default). | ||
| """ | ||
|
|
||
| requires_grad: bool | None = None | ||
| """Whether to enable gradient computation for collision. | ||
|
|
||
| If ``None``, uses ``model.requires_grad``. | ||
|
|
||
| Defaults to ``None`` (same as Newton's default). | ||
| """ | ||
|
|
||
| sdf_hydroelastic_config: HydroelasticSDFCfg | None = None | ||
| """Configuration for SDF-based hydroelastic collision handling. | ||
|
|
||
| If ``None``, hydroelastic contacts are disabled. | ||
| If set, enables hydroelastic contacts with the specified parameters. | ||
|
|
||
| Defaults to ``None`` (hydroelastic disabled, same as Newton's default). | ||
| """ | ||
|
|
||
| def to_pipeline_args(self) -> dict[str, Any]: | ||
| """Build keyword arguments for :class:`newton.CollisionPipeline`. | ||
|
|
||
| Converts this configuration into the dict expected by | ||
| ``CollisionPipeline.__init__``, handling nested config conversion | ||
| (e.g. :class:`HydroelasticSDFCfg` → ``HydroelasticSDF.Config``). | ||
|
|
||
| Returns: | ||
| Keyword arguments suitable for ``CollisionPipeline(model, **args)``. | ||
| """ | ||
| from newton.geometry import HydroelasticSDF | ||
|
|
||
| cfg_dict = self.to_dict() | ||
| hydro_cfg = cfg_dict.pop("sdf_hydroelastic_config", None) | ||
| if hydro_cfg is not None: | ||
| cfg_dict["sdf_hydroelastic_config"] = HydroelasticSDF.Config(**hydro_cfg) | ||
| return cfg_dict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,10 @@ | |
| from isaaclab.physics import PhysicsCfg | ||
| from isaaclab.utils import configclass | ||
|
|
||
| from .newton_collision_cfg import NewtonCollisionPipelineCfg | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .newton_manager import NewtonManager | ||
| from isaaclab_newton.physics import NewtonManager | ||
|
|
||
|
|
||
| @configclass | ||
|
|
@@ -104,7 +106,27 @@ class MJWarpSolverCfg(NewtonSolverCfg): | |
| """Whether to use parallel line search.""" | ||
|
|
||
| use_mujoco_contacts: bool = True | ||
| """Whether to use MuJoCo's contact solver.""" | ||
| """Whether to use MuJoCo's internal contact solver. | ||
|
|
||
| If ``True`` (default), MuJoCo handles collision detection and contact resolution internally. | ||
| If ``False``, Newton's :class:`CollisionPipeline` is used instead. A default pipeline | ||
| (``broad_phase="explicit"``) is created automatically when :attr:`NewtonCfg.collision_cfg` | ||
| is ``None``. Set :attr:`NewtonCfg.collision_cfg` to a :class:`NewtonCollisionPipelineCfg` | ||
| to customize pipeline parameters (broad phase, contact limits, hydroelastic, etc.). | ||
|
|
||
| .. note:: | ||
| Setting ``collision_cfg`` while ``use_mujoco_contacts=True`` raises | ||
| :class:`ValueError` because the two collision modes are mutually exclusive. | ||
| """ | ||
|
|
||
| tolerance: float = 1e-6 | ||
| """Solver convergence tolerance for the constraint residual. | ||
|
|
||
| The solver iterates until the residual drops below this threshold or | ||
| ``iterations`` is reached. Lower values give more precise constraint | ||
| satisfaction at the cost of more iterations. MuJoCo default is ``1e-8``; | ||
| Newton default is ``1e-6``. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning: This new |
||
| """ | ||
|
|
||
|
|
||
| @configclass | ||
|
|
@@ -218,3 +240,20 @@ class NewtonCfg(PhysicsCfg): | |
|
|
||
| solver_cfg: NewtonSolverCfg = MJWarpSolverCfg() | ||
| """Solver configuration. Default is MJWarpSolverCfg().""" | ||
|
|
||
| collision_cfg: NewtonCollisionPipelineCfg | None = None | ||
| """Newton collision pipeline configuration. | ||
|
|
||
| Controls how Newton's :class:`CollisionPipeline` is configured when it is active. | ||
| The pipeline is active when: | ||
|
|
||
| - :class:`MJWarpSolverCfg` with ``use_mujoco_contacts=False``, or | ||
| - any non-MuJoCo solver (:class:`XPBDSolverCfg`, :class:`FeatherstoneSolverCfg`). | ||
|
|
||
| If ``None`` (default), a pipeline with ``broad_phase="explicit"`` is created | ||
| automatically. Set this to a :class:`NewtonCollisionPipelineCfg` to customize | ||
| parameters such as broad phase algorithm, contact limits, or hydroelastic mode. | ||
|
|
||
| .. note:: | ||
| Must not be set when ``use_mujoco_contacts=True`` (raises :class:`ValueError`). | ||
| """ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.