我无法弄清楚如何检测到屏幕外的信号,有人可以帮忙吗?我正在使用WebGL和Three.js。

最佳答案

您可以使用Frustum测试,如下所示:

// 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!
}


这是从WebGLRenderer sources复制的。

10-07 23:19