-
Notifications
You must be signed in to change notification settings - Fork 637
Open
Description
Bug: Duplicate intersections due to too-small ray offset (self._scale)
I encountered an issue where trimesh.ray.intersects_id returns massive duplicate intersection points when multiple_hits=True.
Symptoms
- A single ray produces a very large number of duplicate hit locations.
- Increasing
max_hitsresults in proportionally more identical points. - All returned intersection points are effectively the same (within floating-point precision).
Root cause (suspected)
The problem appears to be caused by an extremely small self._scale value, which makes the computed ray offset:
distance = np.clip(_ray_offset_factor * self._scale, _ray_offset_floor, np.inf)too small relative to the scene scale.
As a result:
- The updated ray origin (
new_origins + ray_offsets) does not move far enough. - The next Embree query hits the same triangle again.
- This repeats until
max_hitsis reached, producing duplicate intersections.
In short: ray origins are not effectively advancing between iterations.
Expected behavior
Ray origins should advance enough to avoid immediately re-hitting the same triangle (or duplicates should be filtered).
Environment
trimeshversion:4.11.2- Backend: Embree
- OS: (fill in)
Reproduction
I will provide:
- Minimal test script
import trimesh
mesh = trimesh.load_mesh("combined.stl")
x = -164.70464393956098
y = 275.5539451575655
z = 10000
origin = [[x, y, z]]
direction = [[0, 0, -1]]
# mesh.ray._scale_to_box = False
index_tri, index_ray, locations = mesh.ray.intersects_id(
origin, direction, multiple_hits=True, return_locations=True
)
print(f"{index_tri=}")
print(f"{index_ray=}")
print(f"{locations=}")combined.stlmesh that reproduces the issue
Notes
This seems related to scale-dependent robustness in the multi-hit ray loop.
Potential fixes might include:
- A configurable option for minimum offset
- Triangle ID re-hit prevention
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels