Skip to content

Commit 545d25c

Browse files
committed
Remove collision filter deprecation scaffolding
Replace finalized model collision filters with a compact read-only set view and remove the expired mutation compatibility path. Remove the deprecated contact-pair rebuilding API and update docs, serialization handling, and regression coverage.
1 parent e5b731c commit 545d25c

6 files changed

Lines changed: 91 additions & 358 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove `ModelBuilder.find_shape_contact_pairs()` and support for mutating `Model.shape_collision_filter_pairs`; update `ModelBuilder.shape_collision_filter_pairs` before calling `finalize()` and rebuild the model instead.

docs/concepts/collisions.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,10 @@ Filter pairs are automatically populated in several cases:
708708
- **USD filtered pairs**: Pairs defined by ``physics:filteredPairs`` relationships in USD files
709709
- **USD collision disabled**: Shapes with ``physics:collisionEnabled=false`` (filtered against all other shapes)
710710

711-
The resulting filter pairs are stored in :attr:`~Model.shape_collision_filter_pairs` as a set of
712-
``(shape_index_a, shape_index_b)`` tuples (canonical order: ``a < b``).
713-
714-
.. deprecated:: 1.4
715-
Mutating this finalized-model set is deprecated; update
716-
:attr:`~ModelBuilder.shape_collision_filter_pairs` before calling ``finalize()`` and rebuild the
717-
model instead, because the precomputed :attr:`~Model.shape_contact_pairs` array is not rebuilt by
718-
post-finalize filter edits.
711+
The resulting filter pairs are stored in :attr:`~Model.shape_collision_filter_pairs` as a read-only
712+
set of ``(shape_index_a, shape_index_b)`` tuples (canonical order: ``a < b``). Update
713+
:attr:`~ModelBuilder.shape_collision_filter_pairs` before calling ``finalize()`` and rebuild the
714+
model to change collision filters.
719715

720716
**USD Import Example**
721717

newton/_src/sim/builder.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13197,9 +13197,7 @@ def _to_wp_array(data, dtype, requires_grad):
1319713197
m.mujoco.equality_constraint_world_start = wp.array(self._equality_constraint_world_start, dtype=wp.int32)
1319813198
m.constraint_mimic_count = len(self.constraint_mimic_joint0)
1319913199

13200-
# The packed array was just installed on the model, so builder and
13201-
# model filters are known to match without rebuilding it.
13202-
self._find_shape_contact_pairs(m, allow_filter_blocks=True)
13200+
self._find_shape_contact_pairs(m)
1320313201

1320413202
# enable ground plane
1320513203
m.up_axis = self.up_axis
@@ -13511,43 +13509,7 @@ def _validate_compact_shape_collision_filter_blocks(self, compact_filter_blocks)
1351113509
)
1351213510
validated_templates.add(template_key)
1351313511

13514-
def find_shape_contact_pairs(self, model: Model):
13515-
"""Deprecated method for rebuilding explicit shape contact pairs.
13516-
13517-
.. deprecated:: 1.4
13518-
Shape contact pairs are generated automatically by :meth:`finalize`.
13519-
Configure collision filters before finalization instead of rebuilding
13520-
contact pairs manually.
13521-
13522-
Identifies and stores all potential shape contact pairs for collision detection.
13523-
13524-
This method examines the collision groups and collision masks of all shapes in the model
13525-
to determine which pairs of shapes should be considered for contact generation. It respects
13526-
any user-specified collision filter pairs to avoid redundant or undesired contacts.
13527-
13528-
The resulting contact pairs are stored in the model as a 2D array of shape indices.
13529-
13530-
Uses the exact same filtering logic as the broad phase kernels (test_world_and_group_pair)
13531-
to ensure consistency between EXPLICIT mode (precomputed pairs) and NXN/SAP modes.
13532-
13533-
Args:
13534-
model: The simulation model to which the contact pairs will be assigned.
13535-
13536-
Side Effects:
13537-
- Sets `model.shape_contact_pairs` to a wp.array of shape pairs (wp.vec2i).
13538-
- Sets `model.shape_contact_pair_count` to the number of contact pairs found.
13539-
"""
13540-
warnings.warn(
13541-
"ModelBuilder.find_shape_contact_pairs() is deprecated; shape contact pairs are generated "
13542-
+ "automatically by ModelBuilder.finalize(). Configure collision filters before finalization instead.",
13543-
DeprecationWarning,
13544-
stacklevel=2,
13545-
)
13546-
# Deprecated calls may supply an unrelated model or a builder that has
13547-
# changed since finalization, so always query filters from the model.
13548-
self._find_shape_contact_pairs(model, allow_filter_blocks=False)
13549-
13550-
def _find_shape_contact_pairs(self, model: Model, *, allow_filter_blocks: bool) -> None:
13512+
def _find_shape_contact_pairs(self, model: Model) -> None:
1355113513
filter_pairs = self._shape_collision_filter_pairs
1355213514
world_filter_blocks: tuple[_ShapeCollisionFilterBlock, ...] = ()
1355313515
explicit_filter_pairs: tuple[tuple[int, int], ...] = ()
@@ -13570,11 +13532,7 @@ def _find_shape_contact_pairs(self, model: Model, *, allow_filter_blocks: bool)
1357013532
self._iter_validated_shape_collision_filter_pairs((*filter_pairs.explicit_pairs, *floating_block_pairs))
1357113533
)
1357213534

13573-
# Builder-side storage is valid only while it describes the model's
13574-
# filters exactly; otherwise the general path queries the model.
13575-
use_world_templates = (
13576-
allow_filter_blocks and self.world_count > 0 and isinstance(filter_pairs, _BuilderShapeCollisionFilterPairs)
13577-
)
13535+
use_world_templates = self.world_count > 0 and isinstance(filter_pairs, _BuilderShapeCollisionFilterPairs)
1357813536
if use_world_templates:
1357913537
shape_world_np = np.asarray(self.shape_world, dtype=np.int32)
1358013538
starts = self.shape_world_start

0 commit comments

Comments
 (0)