Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-05-21 20:49:33 +00:00
parent 07f4b76598
commit 2455cefa75
+27 -9
View File
@@ -562,11 +562,16 @@ export const useModelStore = create<ModelStore>((set, get) => ({
const distanceWorldMM = Math.sqrt(dx * dx + dy * dy + dz * dz); const distanceWorldMM = Math.sqrt(dx * dx + dy * dy + dz * dz);
const factor = state.scaleRatio?.factor ?? 1; const factor = state.scaleRatio?.factor ?? 1;
const distanceMM = distanceWorldMM / factor; 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 measurement: Measurement = { const measurement: Measurement = {
id: `m_${Date.now()}`, id: `m_${Date.now()}`,
pointA: a, pointA: aLocal,
pointB: b, pointB: bLocal,
distanceMM, distanceMM,
modelId: worldToModelLocal(modelId, a) ? modelId : undefined,
}; };
return { measurePoints: [], measurements: [...state.measurements, measurement] }; return { measurePoints: [], measurements: [...state.measurements, measurement] };
} }
@@ -587,27 +592,40 @@ export const useModelStore = create<ModelStore>((set, get) => ({
return { measurements: state.measurements.slice(0, -1) }; return { measurements: state.measurements.slice(0, -1) };
}), }),
registerHoverMeasurement: (info) => set((state) => { registerHoverMeasurement: (info) => set((state) => {
const modelId = state.activeModelId ?? undefined;
const toLocal = (p: MeasurePoint): { point: MeasurePoint; attached: boolean } => {
const conv = modelId ? worldToModelLocal(modelId, p) : null;
return conv ? { point: conv, attached: true } : { point: p, attached: false };
};
let measurement: Measurement; let measurement: Measurement;
let attached = false;
if (info.type === 'hole') { if (info.type === 'hole') {
const c: MeasurePoint = { x: info.position[0], y: info.position[1], z: info.position[2] }; const cw: MeasurePoint = { x: info.position[0], y: info.position[1], z: info.position[2] };
const c = toLocal(cw);
attached = c.attached;
measurement = { measurement = {
id: `m_${Date.now()}`, id: `m_${Date.now()}`,
pointA: c, pointA: c.point,
pointB: c, pointB: c.point,
distanceMM: info.value, distanceMM: info.value,
kind: 'hole', kind: 'hole',
label: `Ø ${info.value.toFixed(1)}`, label: `Ø ${info.value.toFixed(1)}`,
modelId: attached ? modelId : undefined,
}; };
} else { } else {
const a = info.endpoints?.a ?? { x: info.position[0], y: info.position[1], z: info.position[2] }; const aw = info.endpoints?.a ?? { x: info.position[0], y: info.position[1], z: info.position[2] };
const b = info.endpoints?.b ?? a; const bw = info.endpoints?.b ?? aw;
const a = toLocal(aw);
const b = toLocal(bw);
attached = a.attached && b.attached;
measurement = { measurement = {
id: `m_${Date.now()}`, id: `m_${Date.now()}`,
pointA: a, pointA: attached ? a.point : aw,
pointB: b, pointB: attached ? b.point : bw,
distanceMM: info.value, distanceMM: info.value,
kind: 'edge', kind: 'edge',
label: `${info.value.toFixed(1)} mm`, label: `${info.value.toFixed(1)} mm`,
modelId: attached ? modelId : undefined,
}; };
} }
return { measurements: [...state.measurements, measurement], hoverInfo: null }; return { measurements: [...state.measurements, measurement], hoverInfo: null };