question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: Allow raycast function to prevent traversal of children

See original GitHub issue

Request

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Mar 23, 2021

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.

1reaction
makccommented, Mar 16, 2020

@gkjohnson just

yourObject.children.forEach(function (child) { child.raycast = function () {} });

(or traverse, if children are nested)

Read more comments on GitHub >

github_iconTop Results From Across the Web

THREE.Object3D : How to disable Raycast for Object, not ...
Solution 1: Manually filtering raycast candidates and results. It doesn't look like there is any built in field to achieve what you want...
Read more >
Raycast no longer hitting, if parent has a Rigidbody component
If you want to have a collider child of a rigidbody where the child is treated as an independent collider instead of as...
Read more >
CanvasGroup - Scripting API - Unity - Manual
A Canvas placable element that can be used to modify children Alpha, Raycasting, Enabled state. A canvas group can be used to modify...
Read more >
Canvas Group Block Raycasts - Documentation - Game Creator
Canvas Group, The Canvas Group component that changes its value. Block Raycasts, If true, the canvas group and its children block raycasts ......
Read more >
three-mesh-bvh - npm
A BVH implementation to speed up raycasting and enable spatial ... Setting "firstHitOnly" to true means the Mesh.raycast function will use ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found