@floless/app 0.123.2 → 0.124.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/floless-server.cjs +600 -317
- package/dist/schemas/steel.model.v2.schema.json +10 -0
- package/dist/skills/floless-app-approval/SKILL.md +7 -1
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +21 -3
- package/dist/web/app.js +3 -3
- package/dist/web/aware.js +37 -5
- package/dist/web/index.html +2 -2
- package/dist/web/steel-3d-view.js +345 -14
- package/dist/web/steel-editor.html +745 -21
- package/dist/web/steel-filter.html +64 -8
- package/dist/web/vector-editor.html +15 -1
- package/dist/web/workspaces.js +324 -4
- package/package.json +1 -1
|
@@ -93,6 +93,17 @@ let dimMode3d = false; // tool armed
|
|
|
93
93
|
// dimension tool (and as the 2D pick it mirrors): null = disarmed, {a:null} = waiting for the first point,
|
|
94
94
|
// {a:[x,y,z]} = waiting for the second. The editor owns the arming — it drives BOTH views off one flag.
|
|
95
95
|
let gridLinePick3d = null;
|
|
96
|
+
// The Stage D reference measure. EPHEMERAL — none of this ever becomes model data; the editor holds the
|
|
97
|
+
// result in a module variable of its own and only an accepted one reaches `placement.scale`.
|
|
98
|
+
// refMeasure3d null = disarmed, { refId, a:null } = waiting for the first point, { refId, a:[…] } = the second
|
|
99
|
+
// refMeasureKept the finished segment, kept DRAWN so the user can see what they measured while they
|
|
100
|
+
// type its true size into the panel. Independent of `refMeasure3d`: the tool stays armed
|
|
101
|
+
// after a result so re-measuring is one gesture (design review).
|
|
102
|
+
let refMeasure3d = null;
|
|
103
|
+
let refMeasureKept = null;
|
|
104
|
+
let refMeasureLine = null; // the dashed THREE.Line for `kept` (the live rubber band reuses dimPreviewLine)
|
|
105
|
+
let refMeasureLabel = null; // one <div> in dimLabelHost carrying the measured value
|
|
106
|
+
let refMeasureCands = null; // the restricted snap set, cached per camera (see refMeasurePointAt)
|
|
96
107
|
let snapOnly3d = null; // Tekla-style snap override for the dim tool: a snapCandidates type ('vertex'|'intersection'|'midpoint'|'centerline'|'vertical-axis'), 'none' = free, null = all (set from the right-click menu in steel-editor.html)
|
|
97
108
|
// map a 3D candidate type → the 2D running-snap key (⋯ menu → Snapping). Types with no key (level, vertical-axis) are 3D-only aids, always allowed.
|
|
98
109
|
const SNAP3D_PREF = { vertex: 'end', intersection: 'int', midpoint: 'mid', centerline: 'line', 'grid-line': 'line', 'grid-int': 'int' };
|
|
@@ -174,6 +185,14 @@ function init(canvas, theApi) {
|
|
|
174
185
|
// centre far away. ponytail: on-axis depth re-pivot, not a true off-axis orbit-about-cursor (OrbitControls
|
|
175
186
|
// always keeps the pivot screen-centred — that would need a custom control); add that only if this isn't enough.
|
|
176
187
|
controls.addEventListener('start', repivotToCursor);
|
|
188
|
+
// The measure's snap set is FRUSTUM-FILTERED, so unlike every other cached candidate list it goes stale
|
|
189
|
+
// the moment the camera moves — orbit past a corner and a cached set would keep offering it (projected
|
|
190
|
+
// to nonsense) while the corners now on screen were absent. Cheap: the rebuild only happens on the next
|
|
191
|
+
// pointer move that actually needs it.
|
|
192
|
+
controls.addEventListener('change', () => { refMeasureCands = null; });
|
|
193
|
+
// …and the two camera changes that do NOT go through OrbitControls: a resize alters the aspect (and
|
|
194
|
+
// so the frustum the set was filtered by), and switching ortho/persp copies the same position onto a
|
|
195
|
+
// camera with a different frustum, which controls.update() sees as no movement at all.
|
|
177
196
|
canvas.addEventListener('wheel', onWheelHover, { capture: true, passive: true }); // keep the cursor pos fresh for the wheel-triggered re-pivot (capture → runs before OrbitControls' wheel handler)
|
|
178
197
|
// Kept on module scope so Realistic can dim them: an environment map is itself a light source, and
|
|
179
198
|
// leaving this rig at full strength on top of it lights the scene roughly twice over.
|
|
@@ -222,9 +241,22 @@ function init(canvas, theApi) {
|
|
|
222
241
|
overlayDimsGroup = new THREE.Group(); scene.add(overlayDimsGroup); // derived dim overlays (bolt pitch / edge clearance / cope), toggled from the legend
|
|
223
242
|
dimPreviewLine = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]), new THREE.LineBasicMaterial({ color: 0x22d3ee }));
|
|
224
243
|
dimPreviewLine.material.depthTest = false; dimPreviewLine.renderOrder = 997; dimPreviewLine.visible = false; scene.add(dimPreviewLine);
|
|
244
|
+
// Stage D's kept measured segment. DASHED, and that is the whole point of the treatment: the Dimension
|
|
245
|
+
// tool draws a SOLID line with 45° terminator ticks and PERSISTS it, so a solid line here would read as a
|
|
246
|
+
// dimension the user had just placed rather than as a question they are still asking. Cyan is already
|
|
247
|
+
// this feature's own colour (the refsnap dot, the snap reticles), so the dashes carry the distinction on
|
|
248
|
+
// their own and no new token enters the baseline.
|
|
249
|
+
refMeasureLine = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]),
|
|
250
|
+
new THREE.LineDashedMaterial({ color: 0x22d3ee, dashSize: 60, gapSize: 40 }));
|
|
251
|
+
refMeasureLine.material.depthTest = false; refMeasureLine.renderOrder = 997; refMeasureLine.visible = false; scene.add(refMeasureLine);
|
|
225
252
|
dimLabelHost = document.createElement('div');
|
|
226
253
|
dimLabelHost.style.cssText = 'position:fixed;left:0;top:0;pointer-events:none;z-index:57';
|
|
227
254
|
document.body.appendChild(dimLabelHost);
|
|
255
|
+
// …and its label, in the dim host so it is positioned by the same per-frame projection. The cssText is
|
|
256
|
+
// the member-label chip's verbatim (cyan border = a dimension read); only `display` is ours to drive.
|
|
257
|
+
refMeasureLabel = document.createElement('div');
|
|
258
|
+
refMeasureLabel.style.cssText = 'position:absolute;transform:translate(-50%,-50%);pointer-events:none;background:var(--panel,#0f172a);color:#e2e8f0;border:1px solid #22d3ee;border-radius:4px;padding:1px 6px;font:11px system-ui;white-space:nowrap;box-shadow:0 1px 4px rgba(0,0,0,.4);display:none';
|
|
259
|
+
dimLabelHost.appendChild(refMeasureLabel);
|
|
228
260
|
memberLabelHost = document.createElement('div'); // member mark/id labels (Slice 4) — below the dim labels
|
|
229
261
|
memberLabelHost.style.cssText = 'position:fixed;left:0;top:0;pointer-events:none;z-index:56;display:none';
|
|
230
262
|
document.body.appendChild(memberLabelHost);
|
|
@@ -273,6 +305,7 @@ function init(canvas, theApi) {
|
|
|
273
305
|
}
|
|
274
306
|
|
|
275
307
|
function resize() {
|
|
308
|
+
refMeasureCands = null; // the measure's frustum-filtered snap set is derived from this — see setReferencePlacement
|
|
276
309
|
if (!renderer) return;
|
|
277
310
|
const el = canvasEl.parentElement || canvasEl;
|
|
278
311
|
const w = el.clientWidth || 1, h = el.clientHeight || 1;
|
|
@@ -1070,6 +1103,7 @@ function disposeReferenceMaterials() {
|
|
|
1070
1103
|
* the honest encoding of "not here yet" and keeps project open from ever blocking on someone else's model.
|
|
1071
1104
|
*/
|
|
1072
1105
|
function setReferences(list) {
|
|
1106
|
+
refMeasureCands = null; // the measure's frustum-filtered snap set is derived from this — see setReferencePlacement
|
|
1073
1107
|
if (!scene) return;
|
|
1074
1108
|
if (!xrefGroup) { xrefGroup = new THREE.Group(); scene.add(xrefGroup); }
|
|
1075
1109
|
disposeReferenceMaterials();
|
|
@@ -1377,10 +1411,54 @@ function xrefBaseMaterial(entry, mesh, shape) {
|
|
|
1377
1411
|
*/
|
|
1378
1412
|
function setReferencePlacement(id, placement) {
|
|
1379
1413
|
const entry = xrefById.get(id); if (!entry) return;
|
|
1414
|
+
// THE OLD MATRIX, kept because three pieces of Stage D state are expressed in the world space it
|
|
1415
|
+
// defines. This function is the ONLY writer of that matrix, which is why the invalidation belongs
|
|
1416
|
+
// here rather than in any one caller: the Scale box, the heuristic's fix button, the measure's own
|
|
1417
|
+
// accept and 'move it next to your model' all arrive through it.
|
|
1418
|
+
const before = refMeasure3d || refMeasureKept ? entry.group.matrixWorld.clone() : null;
|
|
1380
1419
|
entry.group.matrix.identity();
|
|
1381
1420
|
entry.group.position.set(0, 0, 0); entry.group.quaternion.identity(); entry.group.scale.set(1, 1, 1);
|
|
1382
1421
|
entry.group.applyMatrix4(xrefMatrix(placement));
|
|
1383
1422
|
entry.group.updateMatrixWorld(true);
|
|
1423
|
+
if (refMeasure3d && refMeasure3d.refId === id) {
|
|
1424
|
+
// The cache holds points BAKED through the old matrix, so every one of them now points at where
|
|
1425
|
+
// the geometry used to be. Camera 'change' is the only other invalidation and no camera moved.
|
|
1426
|
+
refMeasureCands = null;
|
|
1427
|
+
// …and so does a first point already picked. Mixing it with a second point taken after the change
|
|
1428
|
+
// produced a distance at neither scale, which the card then labelled 'at this reference's scale
|
|
1429
|
+
// right now' and the accept multiplied by the NEW scale — wrong by exactly the ratio, silently,
|
|
1430
|
+
// under a success toast. Dropping it costs one click and says so.
|
|
1431
|
+
if (refMeasure3d.a) {
|
|
1432
|
+
refMeasure3d.a = null;
|
|
1433
|
+
if (dimPreviewLine) dimPreviewLine.visible = false;
|
|
1434
|
+
if (marker) marker.visible = false;
|
|
1435
|
+
if (readout) readout.style.display = 'none';
|
|
1436
|
+
if (api && api.toast) api.toast('That reference just moved — pick the first point again');
|
|
1437
|
+
}
|
|
1438
|
+
updateStatusChip();
|
|
1439
|
+
}
|
|
1440
|
+
// The KEPT segment is drawn at absolute world points too. Carried through the same change the
|
|
1441
|
+
// geometry made (M_new . M_old^-1) so it keeps describing the corners it was taken on — which is
|
|
1442
|
+
// what makes the editor's scale-only invalidation honest: a translation really does leave the
|
|
1443
|
+
// measurement valid, and now it leaves the PICTURE valid too instead of stranding it.
|
|
1444
|
+
if (refMeasureKept && refMeasureKept.refId === id && before) {
|
|
1445
|
+
const delta = entry.group.matrixWorld.clone().multiply(before.clone().invert());
|
|
1446
|
+
const move = (p) => { const v = new THREE.Vector3(p[0], p[1], p[2]).applyMatrix4(delta); return [v.x, v.y, v.z]; };
|
|
1447
|
+
refMeasureKept.a = move(refMeasureKept.a); refMeasureKept.b = move(refMeasureKept.b);
|
|
1448
|
+
const a = refMeasureKept.a, b = refMeasureKept.b;
|
|
1449
|
+
refMeasureKept.mm = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
|
|
1450
|
+
if (refMeasureLine) {
|
|
1451
|
+
refMeasureLine.geometry.setFromPoints([new THREE.Vector3(...a), new THREE.Vector3(...b)]);
|
|
1452
|
+
refMeasureLine.geometry.computeBoundingSphere();
|
|
1453
|
+
refMeasureLine.material.dashSize = refMeasureKept.mm / 24; refMeasureLine.material.gapSize = refMeasureKept.mm / 36;
|
|
1454
|
+
refMeasureLine.material.needsUpdate = true;
|
|
1455
|
+
refMeasureLine.computeLineDistances();
|
|
1456
|
+
}
|
|
1457
|
+
if (refMeasureLabel) {
|
|
1458
|
+
refMeasureLabel.textContent = api && api.fmtLen ? api.fmtLen(refMeasureKept.mm) : Math.round(refMeasureKept.mm) + ' mm';
|
|
1459
|
+
refMeasureLabel._mid = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1384
1462
|
}
|
|
1385
1463
|
|
|
1386
1464
|
/** The whole-model selection highlight: an emissive lift, never the brand wash (see XREF_COLOR). */
|
|
@@ -1633,8 +1711,14 @@ function frameReference(id) {
|
|
|
1633
1711
|
* snap toggle is off (§10.3). Frustum-filtered first, so the list is what is actually in view rather
|
|
1634
1712
|
* than the whole building, then capped nearest-first with the cap recorded on the entry so the panel
|
|
1635
1713
|
* can say it out loud.
|
|
1714
|
+
*
|
|
1715
|
+
* `onlyId` (S2 Stage D) narrows it to ONE reference and, there, deliberately ignores that reference's own
|
|
1716
|
+
* `snap` toggle. The two halves go together. `display.snap` governs AMBIENT snapping — what your steel
|
|
1717
|
+
* grabs while you draw it — whereas `onlyId` is set only by a tool the user armed AGAINST this reference
|
|
1718
|
+
* by name, where refusing every click because ambient snapping is off would be a dead control. It is the
|
|
1719
|
+
* same split §10.3 already makes for `visible`: an explicit act is not the ambient default.
|
|
1636
1720
|
*/
|
|
1637
|
-
function referenceCandidates() {
|
|
1721
|
+
function referenceCandidates(onlyId) {
|
|
1638
1722
|
if (!xrefById.size || !camera) return [];
|
|
1639
1723
|
camera.updateMatrixWorld();
|
|
1640
1724
|
const frustum = new THREE.Frustum().setFromProjectionMatrix(
|
|
@@ -1642,16 +1726,30 @@ function referenceCandidates() {
|
|
|
1642
1726
|
);
|
|
1643
1727
|
const out = [];
|
|
1644
1728
|
for (const [id, entry] of xrefById) {
|
|
1645
|
-
|
|
1646
|
-
|
|
1729
|
+
// SKIPPED BEFORE `capped` IS TOUCHED, so a single-reference pass leaves every OTHER entry's cap flag
|
|
1730
|
+
// exactly as the last whole-scene pass computed it. Clearing them here would make the panel's
|
|
1731
|
+
// "some points were left out" note flicker off on a reference this pass never even looked at.
|
|
1732
|
+
if (onlyId != null && id !== onlyId) continue;
|
|
1733
|
+
// The flag is the WHOLE-SCENE pass's readout (the panel's "some points were left out" note). The
|
|
1734
|
+
// restricted pass has a different budget entirely, so letting it write here would flip that note on
|
|
1735
|
+
// and off purely because a measure happened to be armed.
|
|
1736
|
+
if (onlyId == null) entry.capped = false;
|
|
1737
|
+
if (onlyId == null && entry.display.snap === false) continue;
|
|
1647
1738
|
const m = entry.group.matrixWorld;
|
|
1648
1739
|
const v = new THREE.Vector3();
|
|
1649
1740
|
let taken = 0;
|
|
1650
1741
|
// STOPS AT THE BUDGET rather than collecting everything and sorting. The nearest-first sort was a
|
|
1651
1742
|
// nicety that cost an O(n log n) over every in-frustum point on EVERY pointer move; taking the
|
|
1652
1743
|
// first N in view is the same order of usefulness at a bounded cost, and `capped` reports it.
|
|
1744
|
+
// THE BUDGET IS THE AMBIENT PATH'S ECONOMY, and it must not silently amputate the single-reference
|
|
1745
|
+
// pass. It takes the first N in FILE ORDER (the nearest-first sort was dropped as too expensive to
|
|
1746
|
+
// pay on every pointer move over every reference), so on a real building the corner the user is
|
|
1747
|
+
// aiming at may simply not be in the set — no reticle, click does nothing, nothing said. That cost
|
|
1748
|
+
// argument does not apply here: `onlyId` walks ONE reference and its result is cached per camera,
|
|
1749
|
+
// not rebuilt per move. XREF_SNAP_KEEP still bounds it at load.
|
|
1750
|
+
const budget = onlyId != null ? Infinity : XREF_SNAP_BUDGET;
|
|
1653
1751
|
for (const p of entry.points) {
|
|
1654
|
-
if (taken >=
|
|
1752
|
+
if (taken >= budget) { entry.capped = true; break; }
|
|
1655
1753
|
v.set(p[0], p[1], p[2]).applyMatrix4(m);
|
|
1656
1754
|
if (!frustum.containsPoint(v)) continue;
|
|
1657
1755
|
// 'vertex', WHICH IS THE CANDIDATE TYPE — 'end' is the snap PREFERENCE key it maps to
|
|
@@ -1689,7 +1787,7 @@ function referenceInfo() {
|
|
|
1689
1787
|
// placement click raycasts a member face (anchor) or the ground plane and hands the point + basis +
|
|
1690
1788
|
// anchor id back to the editor, which creates + selects the detail and records the create request.
|
|
1691
1789
|
function setInsertMode(on, pending) {
|
|
1692
|
-
if (on) dropGridLinePick3d();
|
|
1790
|
+
if (on) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
1693
1791
|
insertMode = !!on;
|
|
1694
1792
|
insertPending = insertMode ? (pending || insertPending) : null;
|
|
1695
1793
|
if (insertMode) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); setClipMode(null); disarmFrame3d(); }
|
|
@@ -1703,7 +1801,7 @@ function insertModeOn() { return insertMode; }
|
|
|
1703
1801
|
// snaps the base to a real framing level. A one-shot left-click hands the picked base elevation to the editor
|
|
1704
1802
|
// via api.onBasePick. Mirrors setInsertMode.
|
|
1705
1803
|
function setBasePickMode(colId) {
|
|
1706
|
-
if (colId) dropGridLinePick3d();
|
|
1804
|
+
if (colId) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
1707
1805
|
basePickCol = colId || null;
|
|
1708
1806
|
basePickLevels = null;
|
|
1709
1807
|
if (basePickCol) {
|
|
@@ -2120,6 +2218,7 @@ async function rebuild(fit = false) {
|
|
|
2120
2218
|
|
|
2121
2219
|
// ---- Persp/Ortho + Solid/Wire/X-ray + group visibility (parity with the AWARE viewer) ----
|
|
2122
2220
|
function setProjection(mode) {
|
|
2221
|
+
refMeasureCands = null; // the measure's frustum-filtered snap set is derived from this — see setReferencePlacement
|
|
2123
2222
|
const want = mode === 'ortho' ? orthoCam : perspCam;
|
|
2124
2223
|
if (want === camera) return;
|
|
2125
2224
|
const tgt = controls.target.clone(), pos = camera.position.clone();
|
|
@@ -2386,7 +2485,7 @@ function rebuildClipPlanes(c) { // recompute a clip's .planes from its ed
|
|
|
2386
2485
|
c.planes = c.kind === 'box' ? boxToPlanes(c.box) : [new THREE.Plane().setFromNormalAndCoplanarPoint(c.n, c.point)];
|
|
2387
2486
|
}
|
|
2388
2487
|
function setClipMode(m) { // arm/disarm a clip pick: 'plane' (click a face) | 'box' (draw 2 corners) | null
|
|
2389
|
-
if (m) dropGridLinePick3d();
|
|
2488
|
+
if (m) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
2390
2489
|
if (m && dimMode3d) toggleDimTool();
|
|
2391
2490
|
if (m) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } // clip shares the left-click — disarm Move/Copy + Add + the local frame so their picks don't steal it (onDown routes them first)
|
|
2392
2491
|
clipMode = (m === 'plane' || m === 'box') ? m : null;
|
|
@@ -2898,7 +2997,7 @@ function toggleDimTool() {
|
|
|
2898
2997
|
if (api.toast) api.toast('This model is read-only here — dimensions are coming. Ask your terminal AI to change it.');
|
|
2899
2998
|
return dimMode3d;
|
|
2900
2999
|
}
|
|
2901
|
-
if (!dimMode3d) dropGridLinePick3d(); // arming the dim tool takes the left-click — cancel an armed grid-line pick through the editor first
|
|
3000
|
+
if (!dimMode3d) { dropGridLinePick3d(); dropRefMeasure3d(); } // arming the dim tool takes the left-click — cancel an armed grid-line pick AND an armed reference measure through the editor first
|
|
2902
3001
|
dimMode3d = !dimMode3d;
|
|
2903
3002
|
if (!dimMode3d) { dimDraft3d = null; dimCandidates3d = null; dimPreviewLine.visible = false; marker.visible = false; readout.style.display = 'none'; canvasEl.style.cursor = 'default'; setSnapOnly3d(null); } // disarming ends the operation → the snap override reverts to all snaps
|
|
2904
3003
|
else { if (clipMode) setClipMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); controls.enabled = true; canvasEl.style.cursor = 'crosshair'; } // arming the dim tool disarms the clip pick, a set-plane pick, Move/Copy, Add-member AND the local frame (all share the left-click + Esc)
|
|
@@ -2915,7 +3014,7 @@ function armGridLinePick3d(on) {
|
|
|
2915
3014
|
// basePickCol and insertMode matter as much as the rest: onDown routes both AHEAD of this pick, so leaving either
|
|
2916
3015
|
// armed would make every click place a detail / do the base pick while the hint still reads "Pick the first point"
|
|
2917
3016
|
// — the exact dead-control failure this change exists to fix.
|
|
2918
|
-
if (on) { if (dimMode3d) toggleDimTool(); if (clipMode) setClipMode(null); setInsertMode(false); setBasePickMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); }
|
|
3017
|
+
if (on) { dropRefMeasure3d(); if (dimMode3d) toggleDimTool(); if (clipMode) setClipMode(null); setInsertMode(false); setBasePickMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); }
|
|
2919
3018
|
gridLinePick3d = on ? { a: null } : null;
|
|
2920
3019
|
if (!gridLinePick3d) { if (dimPreviewLine) dimPreviewLine.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; if (canvasEl) canvasEl.style.cursor = 'default'; }
|
|
2921
3020
|
else { if (controls) controls.enabled = true; if (canvasEl) canvasEl.style.cursor = 'crosshair'; }
|
|
@@ -2926,6 +3025,146 @@ function armGridLinePick3d(on) {
|
|
|
2926
3025
|
// THROUGH the editor, so the panel hint and the button's armed state can't be left claiming a pick that no longer owns
|
|
2927
3026
|
// the canvas. Falls back to a local disarm if the host wired no callback, so the pick can never survive the handover.
|
|
2928
3027
|
function dropGridLinePick3d() { if (!gridLinePick3d) return; if (api && api.onGridLinePickCancel) api.onGridLinePickCancel(); else armGridLinePick3d(false); }
|
|
3028
|
+
/**
|
|
3029
|
+
* Arm the Stage D reference measure against ONE reference; `null` disarms. Returns the armed id, or null.
|
|
3030
|
+
*
|
|
3031
|
+
* THE DISARM BLOCK RUNS ONLY ON THE not-armed → armed TRANSITION, and that is what makes the mutual
|
|
3032
|
+
* exclusion terminate rather than merely usually terminate. Every OTHER tool's arm branch calls
|
|
3033
|
+
* `dropRefMeasure3d()`, which routes back through the editor to `armRefMeasure3d(null)` — a call that, by
|
|
3034
|
+
* this rule, never re-enters the block and so can never bounce back at the tool that is arming. (The
|
|
3035
|
+
* sibling `armGridLinePick3d` gets the same property from `if (on === !!gridLinePick3d) return`, but its
|
|
3036
|
+
* flag is a boolean and ours is an id, so the same one-line spelling would not have said the same thing.)
|
|
3037
|
+
*
|
|
3038
|
+
* Re-arming the reference already armed is a deliberate no-op, so clicking the ⋯ item twice — or the panel
|
|
3039
|
+
* button after the menu — cannot wipe a first point that is already down.
|
|
3040
|
+
*/
|
|
3041
|
+
function armRefMeasure3d(refId) {
|
|
3042
|
+
const next = refId == null ? null : String(refId);
|
|
3043
|
+
const was = refMeasure3d ? refMeasure3d.refId : null;
|
|
3044
|
+
if (was === next) return next;
|
|
3045
|
+
if (next && !was) {
|
|
3046
|
+
// The DISARM direction on every one of these, exactly as armGridLinePick3d takes them: toggleDimTool
|
|
3047
|
+
// and armWorkPlanePick are toggles, so they are called only when the thing is on, which turns it off.
|
|
3048
|
+
if (dimMode3d) toggleDimTool();
|
|
3049
|
+
// dropGridLinePick3d(), NOT armGridLinePick3d(false): the local setter clears only OUR flag and
|
|
3050
|
+
// leaves the EDITOR's `gridLinePick` armed, so its panel hint goes on claiming a pick it no longer
|
|
3051
|
+
// owns AND its Escape rung — which sits above the measure's — eats the first Esc. Every sibling
|
|
3052
|
+
// tool routes through the editor here for exactly that reason.
|
|
3053
|
+
dropGridLinePick3d();
|
|
3054
|
+
if (clipMode) setClipMode(null);
|
|
3055
|
+
setInsertMode(false); setBasePickMode(null);
|
|
3056
|
+
if (wpMode) armWorkPlanePick(wpMode);
|
|
3057
|
+
if (api && api.disarmTransform) api.disarmTransform();
|
|
3058
|
+
if (api && api.disarmAdd) api.disarmAdd();
|
|
3059
|
+
drClear3d(); disarmFrame3d();
|
|
3060
|
+
}
|
|
3061
|
+
refMeasureCands = null; // a different reference (or none) means a different snap set
|
|
3062
|
+
// A RESULT BELONGS TO THE REFERENCE IT WAS TAKEN ON. Arming against a different one must not leave the
|
|
3063
|
+
// previous reference's dashed segment on screen offering to scale a reference the tool is no longer on.
|
|
3064
|
+
if (refMeasureKept && refMeasureKept.refId !== next) clearRefMeasure3d();
|
|
3065
|
+
refMeasure3d = next ? { refId: next, a: null } : null;
|
|
3066
|
+
if (!refMeasure3d) { if (dimPreviewLine) dimPreviewLine.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; if (canvasEl) canvasEl.style.cursor = 'default'; }
|
|
3067
|
+
else { if (controls) controls.enabled = true; if (canvasEl) canvasEl.style.cursor = 'crosshair'; }
|
|
3068
|
+
updateStatusChip();
|
|
3069
|
+
return next;
|
|
3070
|
+
}
|
|
3071
|
+
/**
|
|
3072
|
+
* The reverse of the exclusivity above: another tool taking the left-click cancels an armed measure
|
|
3073
|
+
* THROUGH the editor, so the panel's card and button can never be left claiming a pick that no longer owns
|
|
3074
|
+
* the canvas. Falls back to a local disarm if the host wired no callback, so it can never survive the
|
|
3075
|
+
* handover. (Same shape and same reasoning as dropGridLinePick3d.)
|
|
3076
|
+
*/
|
|
3077
|
+
function dropRefMeasure3d() { if (!refMeasure3d && !refMeasureKept) return; if (api && api.onRefMeasureCancel) api.onRefMeasureCancel(); else { armRefMeasure3d(null); clearRefMeasure3d(); } }
|
|
3078
|
+
/**
|
|
3079
|
+
* One Esc press against the measure, returning whether it consumed it. THE EDITOR CALLS THIS — this layer
|
|
3080
|
+
* deliberately has no Escape branch for the measure, exactly as it has none for `gridLinePick3d` and for
|
|
3081
|
+
* the reason stated there: the editor binds its window keydown at parse time and ours inside init(), so
|
|
3082
|
+
* the editor's runs FIRST, and its catch-all Escape clears the member selection. Handling it here as well
|
|
3083
|
+
* would make one press do two things — clear the user's selection AND step the measure back.
|
|
3084
|
+
*
|
|
3085
|
+
* Three stages, one more than the Dimension tool's two, because this tool has a state it does not: an
|
|
3086
|
+
* unaccepted RESULT. Drop the in-progress second pick → drop the result → leave the tool.
|
|
3087
|
+
*/
|
|
3088
|
+
function refMeasureEscape() {
|
|
3089
|
+
if (!refMeasure3d && !refMeasureKept) return false;
|
|
3090
|
+
// A member gesture owns the shared marker and readout; clearing them under it would strand the drag.
|
|
3091
|
+
// Same guard the dim tool's key handling takes, spelled out here because that one is local to onKey.
|
|
3092
|
+
if (pending || dragging || boxSel) return false;
|
|
3093
|
+
if (refMeasure3d && refMeasure3d.a) { refMeasure3d.a = null; if (dimPreviewLine) dimPreviewLine.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; updateStatusChip(); return true; }
|
|
3094
|
+
if (refMeasureKept) { clearRefMeasure3d(); return true; } // the EDITOR clears its own card — it is the caller
|
|
3095
|
+
armRefMeasure3d(null); return true;
|
|
3096
|
+
}
|
|
3097
|
+
/** Erase the kept segment and its label. The editor calls this when the result is taken or dismissed. */
|
|
3098
|
+
function clearRefMeasure3d() {
|
|
3099
|
+
refMeasureKept = null;
|
|
3100
|
+
if (refMeasureLine) refMeasureLine.visible = false;
|
|
3101
|
+
if (refMeasureLabel) { refMeasureLabel.style.display = 'none'; refMeasureLabel._mid = null; }
|
|
3102
|
+
updateStatusChip();
|
|
3103
|
+
}
|
|
3104
|
+
/**
|
|
3105
|
+
* The snapped point under the cursor for the measure — that reference's own points, and NOTHING else.
|
|
3106
|
+
*
|
|
3107
|
+
* PURE SCREEN-SPACE NEAREST, not `dimPointAt`'s ray-onto-a-plane-then-snap, because there is no honest
|
|
3108
|
+
* plane to raycast here. `dimPointAt` picks its plane from the member under the cursor (or the scene
|
|
3109
|
+
* floor); a reference is a whole building, so any plane choice would bias which of two equally-close
|
|
3110
|
+
* corners wins by how far each happens to sit from an arbitrary datum. What the user is aiming at is what
|
|
3111
|
+
* is nearest on screen, and that is a quantity we can answer exactly.
|
|
3112
|
+
*
|
|
3113
|
+
* Returns null when nothing is within tolerance, DELIBERATELY. A point in mid-air is not a feature of the
|
|
3114
|
+
* file and cannot size it, so a miss is a no-op rather than a point the arithmetic would then trust.
|
|
3115
|
+
*/
|
|
3116
|
+
function refMeasurePointAt(e) {
|
|
3117
|
+
if (!refMeasure3d || !canvasEl) return null;
|
|
3118
|
+
// CACHED PER CAMERA, not rebuilt per pointer move. `referenceCandidates` walks up to XREF_SNAP_KEEP
|
|
3119
|
+
// (40,000) stored points doing a matrix multiply and a frustum test on each; every sibling tool caches
|
|
3120
|
+
// its candidate set for exactly this reason (dimCandidates3d, tfCandidates), and this one's own comment
|
|
3121
|
+
// records that even a sort over the in-frustum subset was too expensive to pay per move. The set is
|
|
3122
|
+
// frustum-filtered, so unlike theirs it must fall when the camera does — hence the invalidation on the
|
|
3123
|
+
// controls' change event rather than only on arm.
|
|
3124
|
+
if (!refMeasureCands) refMeasureCands = referenceCandidates(refMeasure3d.refId);
|
|
3125
|
+
const cands = refMeasureCands;
|
|
3126
|
+
if (!cands.length) return null;
|
|
3127
|
+
const rect = canvasEl.getBoundingClientRect();
|
|
3128
|
+
// `toScreen` returns CANVAS-RELATIVE px (it does not add rect.left/top), so the cursor is converted to
|
|
3129
|
+
// the same space rather than the other way round.
|
|
3130
|
+
const cx = e.clientX - rect.left, cy = e.clientY - rect.top;
|
|
3131
|
+
// NEAREST ON SCREEN, then NEAREST TO THE CAMERA. The second half matters more than it looks: on a
|
|
3132
|
+
// building the near and far corners of one bay project within a pixel or two of each other, so a
|
|
3133
|
+
// pure 2D winner is decided by sub-pixel noise and the reticle looks identical either way — the user
|
|
3134
|
+
// cannot tell which was taken until they orbit, by which time the measurement (and the scale derived
|
|
3135
|
+
// from it) is silently wrong. Ties are judged inside SCREEN_TIE_PX because exact equality never
|
|
3136
|
+
// happens in floating point.
|
|
3137
|
+
const SCREEN_TIE_PX = 1.5;
|
|
3138
|
+
let best = null, bestD = SNAP_TOL_PX, bestZ = Infinity;
|
|
3139
|
+
for (const c of cands) {
|
|
3140
|
+
const s = toScreen(c.p);
|
|
3141
|
+
const d = Math.hypot(s.x - cx, s.y - cy);
|
|
3142
|
+
if (d >= bestD + SCREEN_TIE_PX) continue;
|
|
3143
|
+
const z = camera.position.distanceToSquared(new THREE.Vector3(c.p[0], c.p[1], c.p[2]));
|
|
3144
|
+
if (!best || d < bestD - SCREEN_TIE_PX || z < bestZ) { best = c; bestZ = z; if (d < bestD) bestD = d; }
|
|
3145
|
+
}
|
|
3146
|
+
return best ? { p: [...best.p], type: 'vertex' } : null;
|
|
3147
|
+
}
|
|
3148
|
+
// Reticle on a snappable corner, the rubber band once the first point is down, and the running distance in
|
|
3149
|
+
// the same cursor-following chip every other 3D tool uses. JUST THE NUMBER in it: the tools that put words
|
|
3150
|
+
// there are naming a MODE (angle, snap type, locked axis), and this tool has one mode.
|
|
3151
|
+
function refMeasureHoverPreview() {
|
|
3152
|
+
if (!lastHoverXY || !canvasEl || !dimPreviewLine) return;
|
|
3153
|
+
const r = refMeasurePointAt({ clientX: lastHoverXY[0], clientY: lastHoverXY[1] });
|
|
3154
|
+
if (r) showMarker(r.p, r.type); else marker.visible = false;
|
|
3155
|
+
canvasEl.style.cursor = r ? 'none' : 'crosshair';
|
|
3156
|
+
if (refMeasure3d.a && r) {
|
|
3157
|
+
const a = refMeasure3d.a;
|
|
3158
|
+
dimPreviewLine.geometry.setFromPoints([new THREE.Vector3(...a), new THREE.Vector3(...r.p)]);
|
|
3159
|
+
dimPreviewLine.geometry.computeBoundingSphere();
|
|
3160
|
+
dimPreviewLine.visible = true;
|
|
3161
|
+
const mm = Math.hypot(r.p[0] - a[0], r.p[1] - a[1], r.p[2] - a[2]);
|
|
3162
|
+
readout._dist.textContent = api && api.fmtLen ? api.fmtLen(mm) : (mm / FT_MM).toFixed(2) + ' ft';
|
|
3163
|
+
readout._type.textContent = '';
|
|
3164
|
+
readout.style.left = (lastHoverXY[0] + 14) + 'px'; readout.style.top = (lastHoverXY[1] + 14) + 'px';
|
|
3165
|
+
readout.style.display = 'block';
|
|
3166
|
+
} else { dimPreviewLine.visible = false; readout.style.display = 'none'; }
|
|
3167
|
+
}
|
|
2929
3168
|
// snap override setter — notifies the host page so its header chip stays in sync with every clear path
|
|
2930
3169
|
function setSnapOnly3d(k) { snapOnly3d = k || null; if (api && api.onSnapOnlyChanged) api.onSnapOnlyChanged(); }
|
|
2931
3170
|
// X/Y/Z each TOGGLE the measure axis in the lock set (press again to release; combine 2–3 → the dim measures along
|
|
@@ -3224,6 +3463,21 @@ function positionDimLabels() {
|
|
|
3224
3463
|
el.style.top = (rect.top + (-v.y * 0.5 + 0.5) * rect.height) + 'px';
|
|
3225
3464
|
el.style.visibility = 'visible';
|
|
3226
3465
|
}
|
|
3466
|
+
// Stage D's kept measurement rides the same per-frame projection as the pool above — it is one label, not
|
|
3467
|
+
// a pooled one, because there is only ever one measurement on screen.
|
|
3468
|
+
if (refMeasureLabel && refMeasureLabel.style.display !== 'none' && refMeasureLabel._mid) {
|
|
3469
|
+
// Clipped away with its segment, the same rule the pool above takes: a measurement whose midpoint is
|
|
3470
|
+
// on the cut side of a section plane must not keep a label floating over the cut.
|
|
3471
|
+
if (isPointClipped(refMeasureLabel._mid)) { refMeasureLabel.style.visibility = 'hidden'; return; }
|
|
3472
|
+
const v = new THREE.Vector3(...refMeasureLabel._mid).project(camera);
|
|
3473
|
+
if (v.z > 1 || v.x < -1 || v.x > 1 || v.y < -1 || v.y > 1) refMeasureLabel.style.visibility = 'hidden';
|
|
3474
|
+
else {
|
|
3475
|
+
const rect = canvasEl.getBoundingClientRect();
|
|
3476
|
+
refMeasureLabel.style.left = (rect.left + (v.x * 0.5 + 0.5) * rect.width) + 'px';
|
|
3477
|
+
refMeasureLabel.style.top = (rect.top + (-v.y * 0.5 + 0.5) * rect.height) + 'px';
|
|
3478
|
+
refMeasureLabel.style.visibility = 'visible';
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3227
3481
|
}
|
|
3228
3482
|
|
|
3229
3483
|
// ---- derived dimension overlays (the legend's DIMENSIONS toggles) ----
|
|
@@ -3863,7 +4117,7 @@ function setFrameOrigin(originMm) {
|
|
|
3863
4117
|
function clearFrame3d() { const had = !!frame3d || frameMode; cancelFramePick(); frame3d = null; frameMode = false; if (had) fireFrameChange(); }
|
|
3864
4118
|
function armFrame3d(on) { // arm/disarm the tool; arming disarms conflicting tools
|
|
3865
4119
|
frameMode = on == null ? !frameMode : !!on;
|
|
3866
|
-
if (frameMode) dropGridLinePick3d();
|
|
4120
|
+
if (frameMode) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
3867
4121
|
if (frameMode) {
|
|
3868
4122
|
if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); if (wpMode) { wpMode = null; wpDraft = null; reflectWpBar(); } setClipMode(null); setInsertMode(false); // arming the frame disarms EVERY other left-click 3D tool (incl. clip + insert)
|
|
3869
4123
|
framePickPts = frame3d ? null : []; // no frame yet → start the 3-click pick; an existing frame → straight to drag-refine (re-pick from the panel)
|
|
@@ -4096,7 +4350,7 @@ function renderWorkPlane() {
|
|
|
4096
4350
|
function reflectWpBar() { const b = document.getElementById('m3dWp'); if (b) { b.classList.toggle('on', !!wpMode || !!workPlane);
|
|
4097
4351
|
const kind = workPlane && workPlane.kind ? { face: 'Face', p3: '3pt', xy: 'XY', xz: 'XZ', yz: 'YZ' }[workPlane.kind] || '' : '';
|
|
4098
4352
|
b.textContent = wpMode ? '◇ Plane ✕' : (kind ? '◇ Plane: ' + kind + ' ▾' : '◇ Plane ▾'); } reflectDimAxisBar(); } // the label reads the active plane without opening the menu (ux review); relabel the dim-axis bar (a set/cleared plane flips X/Y between World and local)
|
|
4099
|
-
function armWorkPlanePick(mode) { if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; dropGridLinePick3d(); if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } marker.visible = false; canvasEl.style.cursor = wpMode ? 'crosshair' : 'default'; reflectWpBar(); } // a set-plane pick shares the left-click — disarm Move/Copy + Add + the local frame (their onDown routes run first)
|
|
4353
|
+
function armWorkPlanePick(mode) { if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; dropGridLinePick3d(); dropRefMeasure3d(); if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } marker.visible = false; canvasEl.style.cursor = wpMode ? 'crosshair' : 'default'; reflectWpBar(); } // a set-plane pick shares the left-click — disarm Move/Copy + Add + the local frame (their onDown routes run first)
|
|
4100
4354
|
function setWorkPlanePrincipal(kind, offsetMm) {
|
|
4101
4355
|
const off = offsetMm || 0;
|
|
4102
4356
|
const def = { xy: { normal: [0, 0, 1], xAxis: [1, 0, 0] }, xz: { normal: [0, 1, 0], xAxis: [1, 0, 0] }, yz: { normal: [1, 0, 0], xAxis: [0, 1, 0] } }[kind];
|
|
@@ -4579,11 +4833,50 @@ function onDown(e) {
|
|
|
4579
4833
|
if (clipMode === 'box') { e.stopPropagation(); onClipBoxClick(e); return; } // armed: 2-corner clip-box draw on the floor plane
|
|
4580
4834
|
if (framePicking()) { e.stopPropagation(); controls.enabled = true; framePickClick(e); return; } // 3-click UCS set: this click collects the origin / X point / Y point
|
|
4581
4835
|
if (frameMode) { let fh = null; try { fh = pickFrameHandle(e.clientX, e.clientY); } catch { fh = null; } if (fh) { e.stopPropagation(); controls.enabled = false; startFrameDrag(fh, e); return; } } // grab the local-frame origin/ring (armed) → drag it; an empty click falls through (orbit)
|
|
4582
|
-
if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !gridLinePick3d && !selectedClipIds.size) { // passive gizmo, no tool armed → clicking its origin/ring re-selects the local frame for editing (NOT reached by box-select or select-all, which only touch members). gridLinePick3d belongs in this list like every other armed tool: the handle captures within ~16 px, so without it the frame ORIGIN — a snap target the grid pick advertises — could never be used as a grid endpoint; the click would re-arm the frame and cancel the pick instead.
|
|
4836
|
+
if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !gridLinePick3d && !refMeasure3d && !selectedClipIds.size) { // passive gizmo, no tool armed → clicking its origin/ring re-selects the local frame for editing (NOT reached by box-select or select-all, which only touch members). gridLinePick3d belongs in this list like every other armed tool: the handle captures within ~16 px, so without it the frame ORIGIN — a snap target the grid pick advertises — could never be used as a grid endpoint; the click would re-arm the frame and cancel the pick instead. refMeasure3d is here for the same reason and it BITES HARDER: the UCS origin sits at world [0,0,0] or the local frame origin, which is routinely inside the very reference being measured, so without it a measure click near it would arm a frame drag and silently cancel the measure.
|
|
4583
4837
|
let fh = null; try { fh = pickFrameHandle(e.clientX, e.clientY, true); } catch { fh = null; }
|
|
4584
4838
|
if (fh) { e.stopPropagation(); controls.enabled = false; armFrame3d(true); startFrameDrag(fh, e); return; } // re-arm the tool + grab the clicked handle so a click-drag manipulates immediately
|
|
4585
4839
|
}
|
|
4586
|
-
if (selectedClipIds.size && !gridLinePick3d) { let ch = null; try { ch = pickClipHandle(e.clientX, e.clientY); } catch { ch = null; } if (ch) { e.stopPropagation(); controls.enabled = false; downXY = [e.clientX, e.clientY]; startClipDrag(ch, e); return; } } // grab a clip handle (plane dot / box face) → drag it. Not while the grid pick is armed: a handle drag would start under an armed two-click tool, leaving the button + hint claiming a pick and the shared preview line stranded (onUp clears the marker/readout but not dimPreviewLine).
|
|
4840
|
+
if (selectedClipIds.size && !gridLinePick3d && !refMeasure3d) { let ch = null; try { ch = pickClipHandle(e.clientX, e.clientY); } catch { ch = null; } if (ch) { e.stopPropagation(); controls.enabled = false; downXY = [e.clientX, e.clientY]; startClipDrag(ch, e); return; } } // grab a clip handle (plane dot / box face) → drag it. Not while the grid pick is armed: a handle drag would start under an armed two-click tool, leaving the button + hint claiming a pick and the shared preview line stranded (onUp clears the marker/readout but not dimPreviewLine).
|
|
4841
|
+
if (refMeasure3d) { // S2 Stage D: pick A, then B → the EDITOR owns the result; nothing is stored here
|
|
4842
|
+
e.stopPropagation(); controls.enabled = true;
|
|
4843
|
+
const r = refMeasurePointAt(e); if (!r) return; // no snap, no point — a miss is a no-op, not a mid-air pick
|
|
4844
|
+
if (!refMeasure3d.a) { refMeasure3d.a = r.p; updateStatusChip(); if (api && api.onRefMeasureStep) api.onRefMeasureStep(); return; }
|
|
4845
|
+
const a = refMeasure3d.a, b = r.p;
|
|
4846
|
+
const mm = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
|
|
4847
|
+
// A COINCIDENT SECOND PICK IS SILENTLY IGNORED, anchor kept. onClipBoxClick already ignores a
|
|
4848
|
+
// same-point second corner exactly this way; a louder pattern for a near-identical mis-click would be
|
|
4849
|
+
// the invention, and re-picking a first point that was already right is a tax.
|
|
4850
|
+
//
|
|
4851
|
+
// THE TEST IS `> 0`, NOT `> 1 mm`, and the difference is the whole feature. A 1 mm world floor reads
|
|
4852
|
+
// as harmless until you remember which references this tool exists for: one drawn 1000x too small
|
|
4853
|
+
// renders a real 900 mm span as 0.9 mm, so the floor silently refused the exact pick the user came
|
|
4854
|
+
// here to make — reticle on both corners, rubber band between them, click, nothing, forever. Snap
|
|
4855
|
+
// points are deduped, so clicking one candidate twice gives exactly 0 and `> 0` catches it exactly.
|
|
4856
|
+
if (!(mm > 0)) return;
|
|
4857
|
+
const refId = refMeasure3d.refId;
|
|
4858
|
+
// STAYS ARMED with the anchor cleared, so "measure something else on this reference" is one gesture
|
|
4859
|
+
// rather than a trip back to the ⋯ menu. Nothing was written, so a replacement result costs nothing.
|
|
4860
|
+
refMeasure3d = { refId, a: null };
|
|
4861
|
+
dimPreviewLine.visible = false; marker.visible = false; readout.style.display = 'none';
|
|
4862
|
+
refMeasureKept = { refId, a, b, mm };
|
|
4863
|
+
refMeasureLine.geometry.setFromPoints([new THREE.Vector3(...a), new THREE.Vector3(...b)]);
|
|
4864
|
+
refMeasureLine.geometry.computeBoundingSphere();
|
|
4865
|
+
// DASH LENGTH FROM THE SPAN, not a fixed 60 mm. dashSize is in world units, and this tool's own
|
|
4866
|
+
// population is references drawn at 0.001 scale — where a whole measured span is under 100 mm and a
|
|
4867
|
+
// fixed dash renders as one solid line, silently losing the very distinction from a placed Dimension
|
|
4868
|
+
// that the dashes exist to carry. ~12 dashes at any scale.
|
|
4869
|
+
refMeasureLine.material.dashSize = mm / 24; refMeasureLine.material.gapSize = mm / 36;
|
|
4870
|
+
refMeasureLine.material.needsUpdate = true;
|
|
4871
|
+
refMeasureLine.computeLineDistances(); // LineDashedMaterial draws SOLID without this
|
|
4872
|
+
refMeasureLine.visible = true;
|
|
4873
|
+
refMeasureLabel.textContent = api && api.fmtLen ? api.fmtLen(mm) : Math.round(mm) + ' mm';
|
|
4874
|
+
refMeasureLabel._mid = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
|
|
4875
|
+
refMeasureLabel.style.display = 'block';
|
|
4876
|
+
updateStatusChip();
|
|
4877
|
+
if (api && api.onRefMeasure) api.onRefMeasure(refId, a, b, mm);
|
|
4878
|
+
return;
|
|
4879
|
+
}
|
|
4587
4880
|
if (gridLinePick3d) { // grid panel "Add single line": pick A, then B → the editor commits it (mirrors the 2D pick)
|
|
4588
4881
|
e.stopPropagation(); controls.enabled = true;
|
|
4589
4882
|
const r = gridLinePickPoint3d(e); if (!r) return;
|
|
@@ -5181,6 +5474,7 @@ function onHoverMove(e) {
|
|
|
5181
5474
|
hoverRAF = requestAnimationFrame(() => {
|
|
5182
5475
|
hoverRAF = 0;
|
|
5183
5476
|
if (!lastHoverXY || pending || dragging || boxSel) return;
|
|
5477
|
+
if (refMeasure3d) { refMeasureHoverPreview(); return; } // armed reference measure owns the hover: reticle on THAT reference's own corners + rubber band + running distance
|
|
5184
5478
|
if (gridLinePick3d) { gridLineHoverPreview3d(); return; } // armed grid-line pick owns the hover (rubber-band + snap reticle)
|
|
5185
5479
|
if (basePickCol) { // Mode B armed: reticle on the column axis + a live elevation readout
|
|
5186
5480
|
const p = basePickPoint(lastHoverXY[0], lastHoverXY[1]);
|
|
@@ -5223,7 +5517,7 @@ function onHoverMove(e) {
|
|
|
5223
5517
|
canvasEl.style.cursor = fh ? 'grab' : 'crosshair';
|
|
5224
5518
|
return;
|
|
5225
5519
|
}
|
|
5226
|
-
if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !selectedClipIds.size) { // hovering the PASSIVE gizmo (nothing armed) → pointer cursor hints "click to edit the local axes again"
|
|
5520
|
+
if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !refMeasure3d && !selectedClipIds.size) { // hovering the PASSIVE gizmo (nothing armed) → pointer cursor hints "click to edit the local axes again"
|
|
5227
5521
|
let fh = null; try { fh = pickFrameHandle(lastHoverXY[0], lastHoverXY[1], true); } catch { fh = null; }
|
|
5228
5522
|
if (fh) { canvasEl.style.cursor = 'pointer'; return; }
|
|
5229
5523
|
}
|
|
@@ -5271,6 +5565,14 @@ function updateStatusChip() {
|
|
|
5271
5565
|
else if (cmActive()) { const st = cmActive(), lock = lockChipTxt();
|
|
5272
5566
|
txt = (!tfDraft ? ((st.tool === 'move' ? 'Move' : (st.array ? 'Copy array' : 'Copy')) + ' — click the base point on the working plane · type after the pick for an exact value')
|
|
5273
5567
|
: (st.array && !tfDraft.vA ? 'Click the direction-A point — or type its spacing' : st.array ? 'Click the direction-B point — the grid previews live' : 'Click the destination — X/Y lock to the plane axes · Esc cancels')) + lock; }
|
|
5568
|
+
// Above the showId/default branches for the reason the grid-line branch below states. Three states, not
|
|
5569
|
+
// two: unlike every sibling two-click tool this one has a RESULT the user can still act on, and while
|
|
5570
|
+
// that is up the chip has to say where it went (the panel) and that a fresh pick just replaces it.
|
|
5571
|
+
else if (refMeasure3d) txt = refMeasure3d.a
|
|
5572
|
+
? 'Click the second point on this reference · Esc to step back'
|
|
5573
|
+
: refMeasureKept
|
|
5574
|
+
? 'Measured — see the panel · click two new points to try again · Esc to finish'
|
|
5575
|
+
: 'Click the first point on this reference · Esc to cancel';
|
|
5274
5576
|
else if (gridLinePick3d) txt = gridLinePick3d.a ? 'Click the second point of the grid line · Esc to cancel' : 'Click the first point of the grid line · Esc to cancel'; // must sit above the showId/default branches, else an armed two-click tool shows the hovered member or the drag-move hint the user can't act on
|
|
5275
5577
|
else if (clipMode === 'plane') txt = 'Click a face to set a clip plane · Esc to cancel';
|
|
5276
5578
|
else if (clipMode === 'box') txt = !clipBoxDraft ? 'Click the first floor corner of the clip box · Esc to cancel' : !clipBoxDraft.b ? 'Click the opposite floor corner · Esc to cancel' : 'Move up/down to set the height, then click · Esc to step back';
|
|
@@ -5293,6 +5595,10 @@ function show() { if (controls) controls.enabled = true; if (canvasEl) { canvasE
|
|
|
5293
5595
|
function hide() {
|
|
5294
5596
|
invalidatePointEntry('hide'); // leaving 3D → drop any open typed entry + stale base/start
|
|
5295
5597
|
if (dimMode3d) toggleDimTool(); // disarm the dim tool + sync its toolbar (no stale draft/armed state on return)
|
|
5598
|
+
// …and the reference measure, through the editor so its panel card goes with it. Routed via
|
|
5599
|
+
// dropRefMeasure3d rather than disarmed locally for exactly the reason that function exists: a local
|
|
5600
|
+
// disarm would leave the Inspect panel showing a Measured block for a tool that owns nothing.
|
|
5601
|
+
if (refMeasure3d || refMeasureKept) dropRefMeasure3d();
|
|
5296
5602
|
if (clipMode) setClipMode(null); // disarm the clip-plane pick too (no stale armed state on return)
|
|
5297
5603
|
if (insertMode) setInsertMode(false); // disarm a pending detail placement — else the first click on return would place it
|
|
5298
5604
|
if (wpMode) { wpMode = null; wpDraft = null; if (marker) marker.visible = false; reflectWpBar(); } // drop an in-progress set-plane pick — else a stale face/3pt pick steals the first click on return
|
|
@@ -5308,6 +5614,12 @@ function hide() {
|
|
|
5308
5614
|
function isReady() { return built; }
|
|
5309
5615
|
|
|
5310
5616
|
function dispose() {
|
|
5617
|
+
// Stage D, torn down like every sibling overlay above. Without it a re-init() mints a fresh line and
|
|
5618
|
+
// label while refMeasure3d still reports armed:true against a reference id from the previous
|
|
5619
|
+
// session — a chip asking for a first point over a scene where every click is a no-op.
|
|
5620
|
+
if (refMeasureLine) { scene.remove(refMeasureLine); refMeasureLine.geometry.dispose(); refMeasureLine.material.dispose(); refMeasureLine = null; }
|
|
5621
|
+
if (refMeasureLabel && refMeasureLabel.remove) refMeasureLabel.remove();
|
|
5622
|
+
refMeasureLabel = null; refMeasure3d = null; refMeasureKept = null; refMeasureCands = null;
|
|
5311
5623
|
modelReads = null; // the resolved read half belongs to the host that was torn down; a re-init must ask the new one (unit 5, P7d)
|
|
5312
5624
|
endTeklaDrag(); // release the pointer capture and take the badge with us
|
|
5313
5625
|
if (rafId) cancelAnimationFrame(rafId);
|
|
@@ -5498,6 +5810,25 @@ window.Steel3DView = {
|
|
|
5498
5810
|
// Stage A: drilling into ONE object inside a reference. `selectReferenceObject` is what Ctrl+click and
|
|
5499
5811
|
// (later) an object-tree row both call, so the two routes cannot drift into different selections.
|
|
5500
5812
|
selectReferenceObject, selectedReferenceObject,
|
|
5813
|
+
// Stage D: the two-point measure. `armRefMeasure3d(id)` arms it, `armRefMeasure3d(null)` disarms;
|
|
5814
|
+
// `clearRefMeasure3d()` drops the kept segment. The three probes below are what the E2E asserts against,
|
|
5815
|
+
// because "a function was called" is not evidence that anything was drawn.
|
|
5816
|
+
armRefMeasure3d, clearRefMeasure3d, refMeasureEscape,
|
|
5817
|
+
refMeasureState: () => (refMeasure3d
|
|
5818
|
+
? { armed: true, refId: refMeasure3d.refId, hasFirst: !!refMeasure3d.a, a: refMeasure3d.a ? [...refMeasure3d.a] : null }
|
|
5819
|
+
: { armed: false, refId: null, hasFirst: false, a: null }),
|
|
5820
|
+
refMeasureKept: () => (refMeasureKept ? { refId: refMeasureKept.refId, a: [...refMeasureKept.a], b: [...refMeasureKept.b], mm: refMeasureKept.mm } : null),
|
|
5821
|
+
refMeasureLabelText: () => (refMeasureLabel && refMeasureLabel.style.display !== 'none' ? refMeasureLabel.textContent : null),
|
|
5822
|
+
refMeasureLineOn: () => !!(refMeasureLine && refMeasureLine.visible),
|
|
5823
|
+
refMeasurePointAtScreen: (x, y) => refMeasurePointAt({ clientX: x, clientY: y }), // test probe: what WOULD snap at a cursor — read-only, no pick
|
|
5824
|
+
refCandidateCount: (id) => referenceCandidates(id).length, // test probe: how many points the restricted set offers
|
|
5825
|
+
// TEST PROBE FOR THE RESTRICTION ITSELF, and it exists because nothing else can see it: swap
|
|
5826
|
+
// referenceCandidates(refId) for allCandidates(null) and every other assertion in this feature still
|
|
5827
|
+
// passes. This reports the DISTINCT sources the armed measure would snap to, so the E2E can assert the
|
|
5828
|
+
// NEGATIVE — that our steel, the grid and a second reference are absent — rather than only that the
|
|
5829
|
+
// armed reference is present.
|
|
5830
|
+
refMeasureCandidateSources: () => (refMeasure3d
|
|
5831
|
+
? [...new Set(referenceCandidates(refMeasure3d.refId).map((c) => c.fromId))].sort() : []),
|
|
5501
5832
|
setLabelsOn, labelsOn: () => labelsOnFlag, // member mark/id label overlay toggle
|
|
5502
5833
|
syncMemberLabels, // editor calls after a mark/id edit to refresh labels
|
|
5503
5834
|
setPropLabels, // right-click property labels: editor pushes { labels:[{id,lines}], placement }
|