From 233216c2844c3e787e3ce56367d1fdae896407f6 Mon Sep 17 00:00:00 2001 From: Thomas Fuhrmann Date: Mon, 31 Mar 2025 09:40:19 +0200 Subject: [PATCH] Simplify z-scaling calculations in generateCapMeshes --- app/three/SceneView.ts | 7 ------- app/three/utils/build-clipping-planes.ts | 16 ++++++++-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/app/three/SceneView.ts b/app/three/SceneView.ts index 9fb2dc8..5d262c4 100644 --- a/app/three/SceneView.ts +++ b/app/three/SceneView.ts @@ -424,13 +424,6 @@ export class SceneView extends EventTarget { // Set z scaling factor setZScale(scale: number) { - // Update extent - //this._extent = { - // ...this._extent, - // zmin: (scale * this._extent.zmin) / this._scene.scale.z, - // zmax: (scale * this._extent.zmax) / this._scene.scale.z, - //}; - // Set scale factor this._scene.scale.set(1, 1, scale); diff --git a/app/three/utils/build-clipping-planes.ts b/app/three/utils/build-clipping-planes.ts index a7d3ead..cc823e2 100644 --- a/app/three/utils/build-clipping-planes.ts +++ b/app/three/utils/build-clipping-planes.ts @@ -397,7 +397,7 @@ export function buildClippingplanes( // Generate new cap meshes const capMeshes = generateCapMeshes( meshes, - plane, + plane.clone(), planes, orientation, scene @@ -580,7 +580,10 @@ function generateCapMeshes( scene: Scene ) { const capMeshes: Mesh[] = []; - const scaleFactor = scene.scale.z; + + // Rescale to local coordinates + if (orientation === Orientation.Z || orientation === Orientation.NZ) + plane.constant /= scene.scale.z; // Iterate over the list of geologic meshes for (const mesh of meshes) { @@ -601,17 +604,17 @@ function generateCapMeshes( const v1 = new Vector3( position[i1], position[i1 + 1], - scaleFactor * (position[i1 + 2] + mesh.position.z) + position[i1 + 2] + mesh.position.z ); const v2 = new Vector3( position[i2], position[i2 + 1], - scaleFactor * (position[i2 + 2] + mesh.position.z) + position[i2 + 2] + mesh.position.z ); const v3 = new Vector3( position[i3], position[i3 + 1], - scaleFactor * (position[i3 + 2] + mesh.position.z) + position[i3 + 2] + mesh.position.z ); // Check if the triangle is cut by the plane @@ -627,11 +630,8 @@ function generateCapMeshes( if (d3 * d1 < 0) intersections.push(intersectEdge(v3, v1, d3, d1)); if (intersections.length === 2) { - // Rescale local coordinates and push to edges const start = intersections[0]; const end = intersections[1]; - start.z = start.z / scaleFactor; - end.z = end.z / scaleFactor; edges.push([start, end]); } }