diff --git a/src/stores/useModelStore.ts b/src/stores/useModelStore.ts index b598904..3a15175 100644 --- a/src/stores/useModelStore.ts +++ b/src/stores/useModelStore.ts @@ -564,14 +564,15 @@ export const useModelStore = create((set, get) => ({ const distanceMM = distanceWorldMM / factor; // Convert world points to active model's local frame so they follow the model. const modelId = state.activeModelId ?? undefined; - const aLocal = (modelId && worldToModelLocal(modelId, a)) || a; - const bLocal = (modelId && worldToModelLocal(modelId, b)) || b; + const aConv = modelId ? worldToModelLocal(modelId, a) : null; + const bConv = modelId ? worldToModelLocal(modelId, b) : null; + const attached = !!(aConv && bConv); const measurement: Measurement = { id: `m_${Date.now()}`, - pointA: aLocal, - pointB: bLocal, + pointA: attached ? aConv! : a, + pointB: attached ? bConv! : b, distanceMM, - modelId: worldToModelLocal(modelId, a) ? modelId : undefined, + modelId: attached ? modelId : undefined, }; return { measurePoints: [], measurements: [...state.measurements, measurement] }; }