How to determine if a plane is in Three.js Frustum chamber

I find it difficult to execute a function that returns true if the plane is inside the camera frame. I found this post on github , but the recipe always returns false whether the object is in truncation.

Has anyone already implemented this wisely? Thank you so much.

+8
source share
2 answers

Maybe the matrices are not updated?

camera.updateMatrix(); // make sure camera local matrix is updated camera.updateMatrixWorld(); // make sure camera world matrix is updated camera.matrixWorldInverse.getInverse( camera.matrixWorld ); plane.updateMatrix(); // make sure plane local matrix is updated plane.updateMatrixWorld(); // make sure plane world matrix is updated var frustum = new THREE.Frustum(); frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ) ); alert( frustum.contains( plane ) ); 
+15
source share

Correct me if I am wrong, but why calculate the truncation a second time?

I am working on a complex project, and the accepted answer is not the best solution for me. I see no reason to count what the Aleids counted. For my purpose, I changed my copy of three.js by raising the flag if something was detected in truncation or not. Later just check your object if object.inFrustum === true

Below the next line

 if ( webglObjects && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) { 

add

 object.inFrustum = true; 

also, where the end of the if ends, adds the oposite flag

 else { object.inFrustum = false; } 

My final result is in r70, which works fine:

 if ( webglObjects && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) { object.inFrustum = true; // The line to add for ( var i = 0, l = webglObjects.length; i < l; i ++ ) { var webglObject = webglObjects[i]; unrollBufferMaterial( webglObject ); webglObject.render = true; if ( _this.sortObjects === true ) { _vector3.setFromMatrixPosition( object.matrixWorld ); _vector3.applyProjection( _projScreenMatrix ); webglObject.z = _vector3.z; } } } else { // Create second condition like that object.inFrustum = false; } 
+3
source share

All Articles