Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-24 20:06:43 +00:00
parent ce642ff505
commit 5e7ff33a3e
+36 -3
View File
@@ -246,6 +246,18 @@ function GLBModel({ sceneModel, isActive }: { sceneModel: SceneModel; isActive:
? 'y'
: 'z';
// Calibration quaternion (applied innermost, around center). We render with identity
// while calibration is in progress for this model so face normals reflect the
// un-calibrated frame; the result is committed at the end.
const calQuatArr = sceneModel.calibrationQuat;
const isCalibratingThis = calibration.modelId === sceneModel.id && calibration.step !== 'idle' && calibration.step !== 'done';
const calQuat = useMemo(() => {
if (isCalibratingThis) return new THREE.Quaternion();
if (!calQuatArr) return new THREE.Quaternion();
return new THREE.Quaternion(calQuatArr[0], calQuatArr[1], calQuatArr[2], calQuatArr[3]);
}, [calQuatArr, isCalibratingThis]);
const calGroupRef = useRef<THREE.Group>(null);
return (
<group
scale={[renderFactor, renderFactor, renderFactor]}
@@ -253,6 +265,27 @@ function GLBModel({ sceneModel, isActive }: { sceneModel: SceneModel; isActive:
e.stopPropagation();
if ((e.delta ?? 0) > 4) return;
// Calibration: capture model face normal in world space.
if (
calibration.modelId === sceneModel.id &&
(calibration.step === 'await-model-1' || calibration.step === 'await-model-2' || calibration.step === 'await-model-3') &&
e.face && e.object
) {
const n = e.face.normal.clone();
const nm = new THREE.Matrix3().getNormalMatrix(e.object.matrixWorld);
n.applyMatrix3(nm).normalize();
const wq = new THREE.Quaternion();
(calGroupRef.current ?? e.object).getWorldQuaternion(wq);
pushModelFaceNormal(n, wq);
if (calibration.step === 'done') {
const q = computeCalibrationQuaternion(calibration.pairs);
if (q) {
useModelStore.getState().setCalibration(sceneModel.id, [q.x, q.y, q.z, q.w]);
}
}
return;
}
if (selectionMode) {
const element = findElementRoot(e.object);
if (element) {
@@ -273,9 +306,8 @@ function GLBModel({ sceneModel, isActive }: { sceneModel: SceneModel; isActive:
rotation={[rotXRad, rotYRad, rotZRad]}
scale={[s, s, s]}
>
{/* Shift geometry so its center sits at the parent's origin (pivot = center).
This is the local frame where measurement points are stored, so measurements
follow the model when posX/Y/Z or rotX/Y/Z change in "Posicionar" mode. */}
{/* Calibration rotation (innermost, around center). */}
<group ref={calGroupRef} quaternion={calQuat}>
<ModelLocalFrame modelId={sceneModel.id} center={modelInfo.center}>
<primitive object={scene} />
<ModelMeasurements modelId={sceneModel.id} />
@@ -283,6 +315,7 @@ function GLBModel({ sceneModel, isActive }: { sceneModel: SceneModel; isActive:
</group>
</group>
</group>
</group>
);
}