THREE.js检查对象是否在平截头体中

Kev*_*uyl 3 frustum three.js

我一直在修补three.js,我有一个画布,我想用作一种GUI.因为我必须检查一个物体是否在相机平截头体中.

我目前的代码:

camera.updateMatrix(); 
camera.updateMatrixWorld(); 

var frustum = new THREE.Frustum();
var projScreenMatrix = new THREE.Matrix4();
projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );

frustum.setFromMatrix( camera.projectionMatrix );

if(frustum.containsPoint( mesh.position )){
    //stuff happens...
};
Run Code Online (Sandbox Code Playgroud)

frustum.containsPoint()不断返回虚假.我在这做错了什么?

Lee*_*eft 6

您的代码正在使用

frustum.setFromMatrix( camera.projectionMatrix );
Run Code Online (Sandbox Code Playgroud)

但那不是你想要的矩阵.而是使用:

frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ) );
Run Code Online (Sandbox Code Playgroud)

如何确定飞机是否在Three.js相机Frustum中回答