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 factor = state.scaleRatio?.factor ?? 1;
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 = {
id: `m_${Date.now()}`,
pointA: a,
pointB: b,
pointA: aLocal,
pointB: bLocal,
distanceMM,
modelId: worldToModelLocal(modelId, a) ? modelId : undefined,
};
return { measurePoints: [], measurements: [...state.measurements, measurement] };
}
@@ -587,27 +592,40 @@ export const useModelStore = create<ModelStore>((set, get) => ({
return { measurements: state.measurements.slice(0, -1) };
}),
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 attached = false;
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 = {
id: `m_${Date.now()}`,
pointA: c,
pointB: c,
pointA: c.point,
pointB: c.point,
distanceMM: info.value,
kind: 'hole',
label: `Ø ${info.value.toFixed(1)}`,
modelId: attached ? modelId : undefined,
};
} else {
const a = info.endpoints?.a ?? { x: info.position[0], y: info.position[1], z: info.position[2] };
const b = info.endpoints?.b ?? a;
const aw = info.endpoints?.a ?? { x: info.position[0], y: info.position[1], z: info.position[2] };
const bw = info.endpoints?.b ?? aw;
const a = toLocal(aw);
const b = toLocal(bw);
attached = a.attached && b.attached;
measurement = {
id: `m_${Date.now()}`,
pointA: a,
pointB: b,
pointA: attached ? a.point : aw,
pointB: attached ? b.point : bw,
distanceMM: info.value,
kind: 'edge',
label: `${info.value.toFixed(1)} mm`,
modelId: attached ? modelId : undefined,
};
}
return { measurements: [...state.measurements, measurement], hoverInfo: null };