Clipping planes

Hello.

I implemented a technique from https://github.com/mrdoob/three.js/pull/20290

Almost everything works fine, but i need to clip a model with spotLight.shadow.camera frustum:

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

I understood how to get planes for clipping:

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

When i add helpers to my camera i see that they almost fits SpotLightHelper - slight discrepancy due to spotLight.shadow.camera.near parameter (if i understood right):

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)


I don’t understand how to set right positioning for planes to clip the model. Perfectly it must be local clipping (but global is fine too).

All Threejs objects are placed in Cesium space, so the coordinates are something like:

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

So i have two questions:

  1. How to fully fit frustum.planes to CameraHelper

  2. How to clip model with frustum.planes?

Or am I doing something wrong and there is other way to resolve the issues?