首页 > 解决方案 > Three.js 剪裁平面

问题描述

我从https://github.com/mrdoob/three.js/pull/20290实现了一项技术

几乎一切正常,但我需要使用 spotLight.shadow.camera frustum 剪辑模型:

shadowCameraHelper = new THREE.CameraHelper( three.spotLight.shadow.camera );

在此处输入图像描述

我了解如何获得飞机进行剪裁:

frustum = new THREE.Frustum();
frustum.setFromMatrix( new THREE.Matrix4().multiply( spotLight.shadow.camera.projectionMatrix, spotLight.shadow.camera.matrixWorldInverse ) );

当我向我的相机添加助手时,我发现它们几乎适合 SpotLightHelper - 由于 spotLight.shadow.camera.near 参数(如果我理解正确的话)略有差异:

helpers = new THREE.Group();
helpers.add( new THREE.PlaneHelper( frustum.planes[ 0 ], 75, 0xff0000 ) );
helpers.add( new THREE.PlaneHelper( frustum.planes[ 1 ], 75, 0x00ff00) );
helpers.add( new THREE.PlaneHelper( frustum.planes[ 2 ], 75, 0x00ff00 ) );
helpers.add( new THREE.PlaneHelper( frustum.planes[ 3 ], 75, 0xff0000 ) );
helpers.add( new THREE.PlaneHelper( frustum.planes[ 4 ], 75, 0x0000ff ) );
helpers.add( new THREE.PlaneHelper( frustum.planes[ 5 ], 75, 0x0000ff ) );

spotLight.shadow.camera.add(helpers)

在此处输入图像描述

在此处输入图像描述

我不明白如何为飞机设置正确的定位来剪辑模型。完美,它必须是局部裁剪(但全局也可以)。

所有 Threejs 对象都放置在 Cesium 空间中,因此坐标类似于:

(x: 2847473.624183968, y: 2197845.085011498, z: 5249482.064107984)

所以我有两个问题:

如何将 frustum.planes 完全适合 CameraHelper

如何用 frustum.planes 剪辑模型?

还是我做错了什么,还有其他方法可以解决问题?

标签: three.jscesiumclipping

解决方案


推荐阅读