Skip to content

[Fix] Build OVPhysX ContactSensor binding patterns per body so nested-hierarchy assets initialize - #6384

Merged
hujc7 merged 1 commit into
isaac-sim:developfrom
hujc7:jichuanh/ovphysx-contact-nested-view
Jul 16, 2026
Merged

hujc7 merged 1 commit into
isaac-sim:developfrom
hujc7:jichuanh/ovphysx-contact-nested-view

Conversation

@hujc7

@hujc7 hujc7 commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The OVPhysX ContactSensor fails to initialize on assets whose rigid bodies are nested (child link prims authored under their parent link prim, as produced by the URDF importer in Isaac Sim 6.0 and later). The contact-binding sensor patterns were built from the first matched body's parent plus leaf names:

bodies found (USD side):   .../Robot/pelvis
                           .../Robot/pelvis/left_hip
                           .../Robot/pelvis/left_hip/left_knee
patterns built:            .../Robot/pelvis        ← exists
                           .../Robot/left_hip      ← names a prim that does not exist
                           .../Robot/left_knee     ← names a prim that does not exist

Nested bodies do not share a parent, so the binding bound only the first-level links and initialization raised Failed to initialize contact binding for specified bodies (sensor_count not a multiple of the resolved body count). This is the OVPhysX counterpart of #6378 (PhysX, fixes #5126); verified by reproducing the pattern construction against a nested stage: 1/3 patterns name an existing prim before the fix, 3/3 after.

Changes

  • Build each sensor pattern from that body's own resolved path expression (the per-body destination expressions resolve_matching_prims_from_source already returns) instead of a shared parent plus leaf names.
  • Unlike the PhysX fix, no data-ordering changes are needed: the binding already received one pattern per body (pattern-major ordering documented and tested in test_multi_body_per_sensor_indexing), and body_names is stored from resolution rather than derived from view paths. The single-body pose pattern reuses sensor_patterns[0].
  • Include the constructed patterns in the initialization error message.
  • Regression test: kinematic chains with URDF-importer-style nested link prims authored directly under each environment prim, standalone sensor, asserting initialization succeeds (pre-fix: deterministic RuntimeError), exact body resolution and order, and data shape — at 1 and 3 environments on CPU and GPU.

Verification status

  • Root cause reproduced locally before fixing (construction level): on a nested stage, the shipped pattern construction yields 1/3 patterns naming existing prims; the fixed construction yields 3/3.
  • Both failure modes derived from the binding validation arithmetic: a loud init RuntimeError when the body count does not divide the bound sensor count, and a silent env-count misinference (corrupted data shapes) when it does. The regression test is parametrized to catch both (1 and 3 envs).
  • The isaaclab_ovphysx test suite does not execute on fork PRs (USE_OVPHYSX_WHEELHOUSE is gated to same-repo branches), so the regression test in this PR runs on the first develop CI after merge and in the nightly compatibility workflow. A maintainer can run it pre-merge by pushing the branch to the upstream repo.

Related to #5126 and #6378.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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 added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump extension.toml — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

The contact-binding sensor patterns were built from the first matched
body's parent plus leaf names. Bodies nested under other bodies (URDF
importer output in Isaac Sim 6.0+) do not share a parent, so the
constructed patterns named prims that do not exist, the binding bound
only the first-level links, and initialization failed.

Build each pattern from that body's own resolved path expression. The
binding already receives one pattern per body, so the pattern-major
data ordering is unchanged; body_names is stored from resolution and
needs no change either. Also include the constructed patterns in the
initialization error message.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jul 7, 2026
@hujc7
hujc7 marked this pull request as ready for review July 7, 2026 10:47
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes ContactSensor initialization failure on assets with nested rigid-body hierarchies (e.g. USD from the URDF importer in Isaac Sim 6.0+) by building per-body OVPhysX fnmatch glob patterns from each body's own resolved path expression instead of a shared first-body-parent plus leaf names. It is the OVPhysX counterpart of #6378.

  • Core fix (contact_sensor.py line 221): replaces the single base_glob derived from the first body's parent with a per-body list comprehension over the expr values returned by resolve_matching_prims_from_source, applying the same two regex substitutions ({ENV_REGEX_NS}→* and .*→*) to each expression. The single_pose_pattern for track_pose=True is updated to sensor_patterns[0] for consistency.
  • Diagnostics improvement: the RuntimeError on binding count mismatch now includes the constructed sensor_patterns list to aid debugging.
  • Regression test (test_nested_rigid_body_hierarchy): manually authors a 3-link kinematic chain with URDF-importer-style nested link prims and asserts initialization succeeds, exact body name order, and correct net_forces_w tensor shape at 1 and 3 environments on both CPU and GPU (test is gated to same-repo CI branches as documented).

Confidence Score: 4/5

Targeted, backward-compatible fix with a direct regression test; flat-hierarchy sensors are unaffected and nested-hierarchy sensors that previously raised unconditionally now initialize correctly.

The fix is a clean, minimal change that replaces a flawed parent-deriving heuristic with the already-available per-body expressions. The regex substitutions applied are identical to the pre-existing filter-glob path, so there is no new substitution logic to audit. The regression test is thorough but is gated behind same-repo CI and cannot be verified on this fork PR prior to merge.

The test file deserves attention on the body_names ordering assertion, which relies on USD DFS traversal order being stable across environments. The implementation file is straightforward.

Important Files Changed

Filename Overview
source/isaaclab_ovphysx/isaaclab_ovphysx/sensors/contact_sensor/contact_sensor.py Core bug fix: sensor patterns now built from each body's own resolved path expression instead of first-body-parent + leaf names; single_pose_pattern for track_pose updated to use sensor_patterns[0]; error message enriched with pattern list for diagnostics.
source/isaaclab_ovphysx/test/sensors/test_contact_sensor.py Adds _author_nested_chain helper and test_nested_rigid_body_hierarchy parametrized over 1/3 envs and CPU/GPU; validates initialization succeeds, body resolution order, and net_forces tensor shape. Test cannot run on fork PRs (CI gate noted in PR description).
source/isaaclab_ovphysx/changelog.d/ovphysx-contact-nested-view.rst New changelog fragment accurately describing the nested-hierarchy ContactSensor fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["ContactSensor._initialize_impl()"] --> B["resolve_matching_prims_from_source(parent_expr, has_contact_report)"]
    B --> C["body_matches: list of (prim, expr) per body type"]
    C --> D["body_names = [prim leaf name for prim, _ in body_matches]"]

    subgraph OLD ["❌ Old: broken for nested hierarchies"]
        OA["Take first body expr, strip last component"] --> OB["sensor_patterns = [parent_glob/name for name in body_names]\n.../Robot/pelvis ✓ | .../Robot/left_hip ✗ | .../Robot/left_knee ✗"]
    end

    subgraph NEW ["✅ New: handles nested hierarchies"]
        NA["For each (_, expr) in body_matches, apply env wildcard subs"] --> NB["sensor_patterns = per-body glob\n.../Robot/pelvis ✓ | .../Robot/pelvis/left_hip ✓ | .../Robot/pelvis/left_hip/left_knee ✓"]
    end

    D --> OLD
    D --> NEW
    NEW --> E["create_contact_binding(sensor_patterns=...)"]
    OLD --> E
    E --> F{"sensor_count % num_sensors == 0?"}
    F -- "No" --> G["RuntimeError (now includes patterns)"]
    F -- "Yes" --> H["Override _num_envs, create buffers"]
    H --> I{"track_pose?"}
    I -- "Yes" --> J["single_pose_pattern = sensor_patterns[0]"]
    I -- "No" --> K["Done"]
    J --> K
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["ContactSensor._initialize_impl()"] --> B["resolve_matching_prims_from_source(parent_expr, has_contact_report)"]
    B --> C["body_matches: list of (prim, expr) per body type"]
    C --> D["body_names = [prim leaf name for prim, _ in body_matches]"]

    subgraph OLD ["❌ Old: broken for nested hierarchies"]
        OA["Take first body expr, strip last component"] --> OB["sensor_patterns = [parent_glob/name for name in body_names]\n.../Robot/pelvis ✓ | .../Robot/left_hip ✗ | .../Robot/left_knee ✗"]
    end

    subgraph NEW ["✅ New: handles nested hierarchies"]
        NA["For each (_, expr) in body_matches, apply env wildcard subs"] --> NB["sensor_patterns = per-body glob\n.../Robot/pelvis ✓ | .../Robot/pelvis/left_hip ✓ | .../Robot/pelvis/left_hip/left_knee ✓"]
    end

    D --> OLD
    D --> NEW
    NEW --> E["create_contact_binding(sensor_patterns=...)"]
    OLD --> E
    E --> F{"sensor_count % num_sensors == 0?"}
    F -- "No" --> G["RuntimeError (now includes patterns)"]
    F -- "Yes" --> H["Override _num_envs, create buffers"]
    H --> I{"track_pose?"}
    I -- "Yes" --> J["single_pose_pattern = sensor_patterns[0]"]
    I -- "No" --> K["Done"]
    J --> K
Loading

Reviews (1): Last reviewed commit: "Fix OVPhysX contact binding patterns for..." | Re-trigger Greptile

@hujc7
hujc7 merged commit 6b4d15f into isaac-sim:develop Jul 16, 2026
60 of 63 checks passed
matthewtrepte pushed a commit to matthewtrepte/IsaacLab that referenced this pull request Aug 4, 2026
…-hierarchy assets initialize (isaac-sim#6384)

# Description

The OVPhysX `ContactSensor` fails to initialize on assets whose rigid
bodies are nested (child link prims authored under their parent link
prim, as produced by the URDF importer in Isaac Sim 6.0 and later). The
contact-binding sensor patterns were built from the first matched body's
parent plus leaf names:

```
bodies found (USD side):   .../Robot/pelvis
                           .../Robot/pelvis/left_hip
                           .../Robot/pelvis/left_hip/left_knee
patterns built:            .../Robot/pelvis        ← exists
                           .../Robot/left_hip      ← names a prim that does not exist
                           .../Robot/left_knee     ← names a prim that does not exist
```

Nested bodies do not share a parent, so the binding bound only the
first-level links and initialization raised `Failed to initialize
contact binding for specified bodies` (`sensor_count` not a multiple of
the resolved body count). This is the OVPhysX counterpart of isaac-sim#6378
(PhysX, fixes isaac-sim#5126); verified by reproducing the pattern construction
against a nested stage: 1/3 patterns name an existing prim before the
fix, 3/3 after.

## Changes

- Build each sensor pattern from that body's own resolved path
expression (the per-body destination expressions
`resolve_matching_prims_from_source` already returns) instead of a
shared parent plus leaf names.
- Unlike the PhysX fix, **no data-ordering changes are needed**: the
binding already received one pattern per body (pattern-major ordering
documented and tested in `test_multi_body_per_sensor_indexing`), and
`body_names` is stored from resolution rather than derived from view
paths. The single-body pose pattern reuses `sensor_patterns[0]`.
- Include the constructed patterns in the initialization error message.
- Regression test: kinematic chains with URDF-importer-style nested link
prims authored directly under each environment prim, standalone sensor,
asserting initialization succeeds (pre-fix: deterministic
`RuntimeError`), exact body resolution and order, and data shape — at 1
and 3 environments on CPU and GPU.

## Verification status

- **Root cause reproduced locally before fixing** (construction level):
on a nested stage, the shipped pattern construction yields 1/3 patterns
naming existing prims; the fixed construction yields 3/3.
- **Both failure modes derived from the binding validation arithmetic**:
a loud init `RuntimeError` when the body count does not divide the bound
sensor count, and a silent env-count misinference (corrupted data
shapes) when it does. The regression test is parametrized to catch both
(1 and 3 envs).
- **The `isaaclab_ovphysx` test suite does not execute on fork PRs**
(`USE_OVPHYSX_WHEELHOUSE` is gated to same-repo branches), so the
regression test in this PR runs on the first `develop` CI after merge
and in the nightly compatibility workflow. A maintainer can run it
pre-merge by pushing the branch to the upstream repo.

Related to isaac-sim#5126 and isaac-sim#6378.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package (do **not** edit
`CHANGELOG.rst` or bump `extension.toml` — CI handles that)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
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