Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-24 20:26:00 +00:00
parent cbeb186a60
commit 8ffb67689f
+22
View File
@@ -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