如何return THREE.Perspective 相机的截锥体并将其存储为变量?

How to return the frustum of the THREE.Perspective camera and store it as a variable?

我正在查看 Three.js API,我发现 Frustum is used for the camera visible area. I was wondering if I can access the view frustum of my PerspectiveCamera 并将视锥体声明为一个对象。基本上,我的目标是给相机的截锥体上色。

如果您想可视化相机的截锥体,可以使用 THREE.CameraHelper。它基本上可以完成您在问题中描述的内容:它可以让您为截锥体着色,以便将其可视化。

要实现它,您只需将相机作为参数启动它,然后将它添加到场景中:

var camera = new THREE.PerspectiveCamera( 75, camRatio, 0.1, 1000 );
var helper = new THREE.CameraHelper( camera );
scene.add( helper );

您可以阅读更多相关信息in the docs and you can see it in action on the right side of this example

更新:

如果您想读取用于构建助手的数据,可以从第 38 行到第 83 行访问它的 .pointmap property. It's got lots of points that determine the position of the near plane (n1, n2, n3...), far plane (f1, f2, f3...), target, etc. To get better acquainted with what each key means, you can look at its constructor。代码在其中有很好的记录。