How can I get my mesh has gone off screen?

可紊 提交于 2019-12-08 11:48:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!