From 8ffb67689f1bad786a0c187a88787855a2f024af Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 24 May 2026 20:26:00 +0000 Subject: [PATCH] Changes Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com> --- src/components/three/viewCubeBus.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/three/viewCubeBus.ts b/src/components/three/viewCubeBus.ts index 643247f..cf9e3b8 100644 --- a/src/components/three/viewCubeBus.ts +++ b/src/components/three/viewCubeBus.ts @@ -128,9 +128,31 @@ export function pushCubeFace(dirWorld: THREE.Vector3) { } else { return; } + // Auto-rotate the main camera to look straight at the picked cube face + // so the user sees the corresponding model face head-on (especially helpful + // in orthographic mode where this guarantees a perpendicular click). + try { requestView(dirWorld.clone()); } catch {} notify(); } +/** Snap a unit vector to the nearest principal axis (±X/±Y/±Z) when within + * `maxDeg` degrees of it. Returns the snapped vector or the input unchanged. */ +function snapToPrincipalAxis(v: THREE.Vector3, maxDeg = 12): THREE.Vector3 { + const cosT = Math.cos(THREE.MathUtils.degToRad(maxDeg)); + const axes = [ + new THREE.Vector3(1, 0, 0), new THREE.Vector3(-1, 0, 0), + new THREE.Vector3(0, 1, 0), new THREE.Vector3(0, -1, 0), + new THREE.Vector3(0, 0, 1), new THREE.Vector3(0, 0,-1), + ]; + let best = v; + let bestDot = cosT; + for (const a of axes) { + const d = v.dot(a); + if (d > bestDot) { bestDot = d; best = a.clone(); } + } + return best; +} + /** * Called when user clicks a model face during calibration. * @param normalWorld world-space face normal of the clicked face