Request: Allow raycast function to prevent traversal of children
See original GitHub issueRequest
Allow raycast function to prevent traversal of children so the parent object can handle custom raycasting for the child objects.
Use Case
I’m currently writing a 3D Tiles renderer library for three.js and I would like to take advantage of the bounding volume hierarchy for raycasting. For context the 3D Tiles format specifies a hierarchy of geometry that is swapped out as the camera gets closer. Each level of the tree has a bounding box that encapsulates all the child tiles. The bounding hierarchy should be able to be used to improve raycast performance by culling parts of the potentially deep tree more quickly. In the library all visible tiles viewable by the camera are added as children of a parent group called TilingGroup.
I would like to perform the hierarchy check in TilingGroup.raycast
and only call intersectObjects
on the geometry within the appropriate bounds. However the way Raycaster works right now all children are always traversed, which means there’s no opportunity to check the the bounding tree before performing raycasts.
One approach would be to allow raycast
to return a boolean which would prevent the Raycaster from traversing the Groups children, but that might not play nice with the new Layers functionality. Another option would be to move some of the raycast traversal logic into Object3D.raycast
so it can be overridden.
Maybe there are some other suggestions? I’ve looked a few different options but so far I’ve come up empty.
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top GitHub Comments
Sorry, but I don’t think it’s appropriate to add a more advanced API for this use case. Layers are already a quite generic approach and there are workarounds like the one of @makc if you need more flexibility.
In all other cases, it’s better if you implement a custom solution on top of
three.js
.@gkjohnson just
(or traverse, if children are nested)