I am using Material.clippingPlanes to try and clip Meshes along a cubic shape. This works fine for one cube, but I have an issue if I try to apply my current solution to two or more intersecting cubes.
My Meshes are usually loaded through THREE loaders such as OBJLoader for example. They also almost all use MeshLambertMaterial.
My current solution is as follows :
// box3 is the clipping cube.
// backwards/forwards/left/right/upward/downward are the normal vectors for each face.
// mesh is the mesh that should get clipped by the cube.
const min = box3.min;
const max = box3.max;
// Box faces as planes
const frontPlane = new THREE.Plane();
frontPlane.setFromNormalAndCoplanarPoint(forward, min);
const leftPlane = new THREE.Plane();
leftPlane.setFromNormalAndCoplanarPoint(right, min);
const rightPlane = new THREE.Plane();
rightPlane.setFromNormalAndCoplanarPoint(left, max);
const backPlane = new THREE.Plane();
backPlane.setFromNormalAndCoplanarPoint(backward , max);
const topPlane = new THREE.Plane();
topPlane.setFromNormalAndCoplanarPoint(downward, max);
const bottomPlane = new THREE.Plane();
bottomPlane.setFromNormalAndCoplanarPoint(upward, min);
const clippingPlanes = [frontPlane, leftPlane, rightPlane, backPlane, topPlane, bottomPlane];
mesh.material.clippingPlanes = clippingPlanes;
mesh.material.clipIntersection = false;
As stated, this works fine for one cube.
What happens if I try this approach for two or more cubes by concatenating all clippingPlanes, is “all that is contained in the intersection of all cubes is rendered, anything else is not”.
I would like to have “all that is contained in the union of all cubes is rendered, anything else is not”.
How can I achieve such a result with this method ?