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