ThreeJS: how to determine if an object is rendered / visible

How can I detect as quickly as possible if a three-dimensional object is visible to the cameraโ€™s eyes? The obj.visible attribute is a setter, so it is not useful. Also frustumCullum is not enough, because it indicates only if the object is outside the camera viewing window. I need to know if an object is hidden behind another much larger object.

Anyone have an idea?

Greetings

Marcus

+2
source share
2 answers

Perhaps you could use THREE.Raycaster ()?

var intersects = raycaster.intersectObjects( objects ); if ( intersects.length > 0 ) { // find the object by name? intersects[0]. // Hidden if index > 0 } 
+4
source share

You can use RayCaster to take rays in the object of interest to you, and then check the raycaster.intersectObjects ([]) array. A quick diagram might look like this:

 var raycaster = projector.pickingRay( objectScreenPositionVector, camera ); var intersects = raycaster.intersectObjects( ObjectsArray ); //the objects you're interested in. 

will intersect in the distance closest to the first.

There are many online tutorials to choose from Three, and AFAIK, this is a relatively effective operation. I quickly looked through http://soledadpenades.com/articles/three-js-tutorials/object-picking/ to update my memory of command names.

+1
source share

All Articles