且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

three.js - 检查对象是否仍然在相机视野中

更新时间:2023-01-23 23:26:52

而不是检查2d画布,你可以检查3d点是否为平截头体。

Instead of check 2d canvas, you can check a 3d point is in frustum or not.

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

// Your 3d point to check
var pos = new THREE.Vector3(x, y, z);
if (frustum.containsPoint(pos)) {
    // Do something with the position...
}