Fix clipping box clipping planes error

This commit is contained in:
Fuhrmann 2025-04-11 11:17:42 +02:00
parent ce20daeee2
commit 6bf44194b3

View file

@ -194,17 +194,23 @@ export function buildClippingplanes(
edgeMeshMap[p.orientation] = edges;
}
for (const o in Orientation) {
const capMeshGroupName = `cap-mesh-group-${o}`;
for (const p of planesData) {
// Create ClippingGroup for each cap mesh face
const capMeshGroupName = `cap-mesh-group-${p.orientation}`;
let capMeshGroup = scene.getObjectByName(capMeshGroupName) as ClippingGroup;
if (capMeshGroup) {
capMeshGroup.clear();
} else {
capMeshGroup = new ClippingGroup();
capMeshGroup.name = capMeshGroupName;
capMeshGroup.clippingPlanes = planes;
scene.add(capMeshGroup);
}
// Set clipping planes for the cap meshes
const capMeshGroupPlanes = planes.filter(
(plane) => plane.normal.dot(p.normal) !== 1
);
capMeshGroup.clippingPlanes = capMeshGroupPlanes;
}
// Add meshes to the scene
@ -668,18 +674,6 @@ function generateCapMeshes(
capMesh.visible = mesh.visible;
capMesh.name = mesh.name;
// Offset mesh to avoid flickering
const normal = plane.normal.clone().multiplyScalar(10);
const positionAttr = capMesh.geometry.attributes.position;
for (let i = 0; i < positionAttr.count; i++) {
const x = positionAttr.getX(i) + normal.x;
const y = positionAttr.getY(i) + normal.y;
const z = positionAttr.getZ(i) + normal.z;
positionAttr.setXYZ(i, x, y, z);
}
positionAttr.needsUpdate = true;
if (capMesh && geometry.index && geometry.index.count > 0) {
capMeshGroup.add(capMesh);
}