问题
I cannot figure out how to detect it going off screen, can anybody help? I am using WebGL and Three.js.
回答1:
You can use Frustum testing, a little like this:
// Create a new Frustum object (for efficiency, do this only once)
var frustum = new THREE.Frustum();
// Helper matrix (for efficiency, do this only once)
var projScreenMatrix = new THREE.Matrix4();
// Set the matrix from camera matrices (which are updated on each renderer.render() call)
projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
// Update the frustum
frustum.setFromMatrix( projScreenMatrix );
// Test for visibility
if ( !frustum.contains( object ) ) {
// It's off-screen!
}
This is copied from WebGLRenderer sources.
来源:https://stackoverflow.com/questions/13125415/how-can-i-get-my-mesh-has-gone-off-screen