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

标签 javascript camera three.js fieldofview

在使用 2d Canvas 时,如果您想检查某些内容是否不再“显示在屏幕上”,您只需执行以下操作:

if( pos.x > window.innerWidth || pos.x < 0 ||
    pos.y > window.innerHeight || pos.y < 0 ) {
    // has left the screen
}

我如何检查在 three.js 场景中是否仍有东西“在屏幕上”(在相机的视野中)?

最佳答案

您可以检查 3d 点是否在截锥体中,而不是检查 2d Canvas 。

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...
}

关于javascript - three.js - 检查对象是否仍在相机视野内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29758233/

相关文章:

javascript - 从小部件获取表单父级

javascript - 在谷歌地图 API javascript 中从 map (使用绘图管理器)获取所有折线

javascript - 如何检测 Safari 上的页面是否是从跳板打开的?

android - Android 位图出现奇怪的 OutOfMemoryError : Why does showing and then hiding the containing View avoid it?

javascript - Three.js 拖动控件固定与相机的距离

javascript - 图像 slider - 幻灯片动画 - jQuery

java - 在 Android 中使用外部 USB 摄像头

Android 调整相机预览

javascript - 抗锯齿 :true in Threejs 的 FPS 性能不佳

animation - 如何将 ms3d 模型转换为three.js?