Raycaster intersects with invisible objects
See original GitHub issueThere is one old problem for me, but still I can’t find same issue in task tracker.
Have a look at this line:
https://github.com/mrdoob/three.js/blob/a1daef37e5a6b80d0173af54edd000202b95fca5/src/core/Raycaster.js#L46
Why Raycaster checks visible
property only on intersectable’s object? I mean, if I set visible = false
in parent, children become invisible for renderer, but still intersectable. Should Raycaster check nearest parents until find invisible? I have to check result of intersection for invisible parents in every single project. Is it any reason for not checking parents here?
My code:
var bool;
THREE.Object3D.prototype.isVisible = function() {
bool = true;
this.traverseAncestors((parent) => {
if (!parent.visible) bool = false;
});
return bool;
};
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:26 (4 by maintainers)
Top Results From Across the Web
Raycaster hits invisible object? - Questions - three.js forum
This is where I just gave up - the raycaster seems to be detecting some invisible object above the actual object. - Imagine...
Read more >How to raycasting hidden object or not add to scene in Threejs
One way to achieve what you require would be to not add your Box objects to your scene which would ensure that they...
Read more >Raycaster - Three.js Tutorials - sbcode.net
Raycasting allows you to create a vector from a 3D point in the scene, and detect which object(s) the vector intersects. The raycasting...
Read more >Interacting with objects – Visualising Data on the Web
We do this by setting up a 'raycaster' object. Think of our 2D cursor as being on the glass ... setFromCamera( mouse, camera...
Read more >Picking by Raycaster - CGwith3JS - Google Sites
Picking in Three.js is done via the Raycaster. It is a complete CPU manipulation (unlike the ... if (intersects[0].object.name === "cube1") alert("cube1");
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suggest to remove the test on
Object3D.visible
and add a test based onLayers
instead. This idea was already suggested here https://github.com/mrdoob/three.js/issues/7551#issuecomment-154400499 and it would be similar to how raycasting works in Unity. In this way, we decouple the raycast from the visibility of the object but still allow to filter out unwanted objects. Something like this inintersectObject()
might work:Notice that children would still be tested even if the layer test evaluates to
false
for the current object. In this way, layers inRaycaster
are treated similar like inWebGLRenderer
. Unfortunately, this change might break user code so it’s problematic to get it into the library…Alternative strategy! (for anyone having similar issues)
It’s worth remembering that you send an array of objects to Raycaster in the first place, and in this array you can easily weed out the objects you don’t want in the Raycast operation. That’s always been my strategy, and never had any problems.