Skip to content

fix: multi-world particle BVH indexing#1641

Open
Idate96 wants to merge 3 commits intonewton-physics:mainfrom
Idate96:fix/tiled-camera-multiworld-particles
Open

fix: multi-world particle BVH indexing#1641
Idate96 wants to merge 3 commits intonewton-physics:mainfrom
Idate96:fix/tiled-camera-multiworld-particles

Conversation

@Idate96
Copy link

@Idate96 Idate96 commented Feb 14, 2026

Problem

SensorTiledCamera builds the particle BVH over the global particle arrays (particles_position/particles_radius) and uses BVH groups to restrict queries to a given world.

In newton/_src/sensors/warp_raytrace/ray_cast.py, particle hits were indexed as if wp.bvh_query_next() returned a world-local index (subtracting world_index * bvh_particles_size).

For multi-world particle scenes this produces invalid indices (and can trigger CUDA illegal memory access) and/or incorrect depth images for world_index > 0.

Fix

Treat the BVH hit index returned by wp.bvh_query_next() as a global index into the particle arrays, and remove the per-world offset in:

  • closest_hit_particles()
  • first_hit_particles()

Test

Add a minimal regression test that renders a tiny particle grid in multiple worlds and asserts the per-world depth images match (within a small fp32 tolerance):

  • newton/tests/test_sensor_tiled_camera_particles_multiworld.py

The test uses the existing device parametrization helpers, so it runs on CPU and CUDA.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed particle ray-casting index handling to correct depth results in sensor rendering across multiple worlds.
  • Tests

    • Added a regression test validating multi-world particle sensor depth consistency across transforms and devices.

SensorTiledCamera particle BVH queries already return global particle indices; don't apply a per-world offset.
Catches incorrect BVH particle index mapping across worlds (can cause CUDA illegal memory access).
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 14, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

Refactored particle index handling in ray casting to use BVH query indices directly as global indices into particle arrays, removing local remapping. Added a regression test that builds a 4-world particle scene and verifies SensorTiledCamera depth images are identical across translated worlds.

Changes

Cohort / File(s) Summary
Ray casting index handling
newton/_src/sensors/warp_raytrace/ray_cast.py
Simplified particle traversal in closestHit and firstHit to treat indices returned by wp.bvh_query_next() as global indices into particles_position/particles_radius. Removed prior global->local remapping and added comments documenting the global-index assumption and BVH construction over global particle arrays.
Multi-world camera consistency test
newton/tests/test_sensor_tiled_camera_particles_multiworld.py
New regression test module that constructs a multi-world particle model with per-world translations and verifies SensorTiledCamera depth-image consistency across 4 worlds. Adds helper _build_multiworld_particle_model, device-parametrized test test_sensor_tiled_camera_multiworld_particles_consistent, and a unittest harness class.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • eric-heiden
🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: multi-world particle BVH indexing' directly and concisely describes the main change: correcting BVH index handling for multi-world particle scenes.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
newton/tests/test_sensor_tiled_camera_particles_multiworld.py (1)

27-72: Well-structured helper — clean and deterministic.

The builder logic is clear and the docstring explains intent well. Two tiny nits, both entirely optional:

  1. Line 66: int(worlds) is redundant since worlds is already typed as int.
  2. Lines 38/40: Ruff TRY003 suggests moving long exception messages into custom exception classes, but for a test helper this is fine.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@newton/tests/test_sensor_tiled_camera_particles_multiworld.py`:
- Around line 1-2: Update the SPDX header in the new file by changing the
copyright year from 2025 to 2026: modify the two header lines starting with
"SPDX-FileCopyrightText" and "SPDX-License-Identifier" so the copyright year
reads 2026 (i.e., replace "Copyright (c) 2025" with "Copyright (c) 2026") to
match the current-year requirement.
🧹 Nitpick comments (1)
newton/tests/test_sensor_tiled_camera_particles_multiworld.py (1)

98-111: Inconsistent quaternion construction — prefer wp.quat_identity() for clarity.

Line 69 uses wp.quat_identity() but line 98 constructs the identity quaternion manually as wp.quatf(0.0, 0.0, 0.0, 1.0). Using the same helper would be clearer and less error-prone.

Proposed fix
-    cam_quat = wp.quatf(0.0, 0.0, 0.0, 1.0)
+    cam_quat = wp.quat_identity()

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d1059f8cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- update SPDX year to 2026

- use wp.quat_identity() consistently

- add docstrings to satisfy docstring coverage
@Idate96
Copy link
Author

Idate96 commented Feb 14, 2026

Addressed CodeRabbit review nits in 71f669f: updated SPDX year to 2026, switched to wp.quat_identity() consistently, and added docstrings for the new regression test.

@codecov
Copy link

codecov bot commented Feb 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@daniela-hase
Copy link
Member

Thank you for catching and fixing this! :D

Looks all good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments