There is one old problem for me, but still I can’t find same issue in task tracker.
Have a look at this line:
three.js/src/core/Raycaster.js
Line 46
in
a1daef3
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;
};
Um, this behavior is somewhat inconsistent. From my point of view, it would be actually better if
intersectObject()
does not check the visibility at all and delegates this to the app level code.If we keep
if ( object.visible === false ) return;
, we might consider to check the hierarchy, too. However, this will impact performance.I suggest to remove the test on
Object3D.visible
and add a test based onLayers
instead. This idea was already suggested here #7551 (comment) 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…