@floless/app 0.90.2 → 0.91.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.
@@ -53106,7 +53106,7 @@ function appVersion() {
53106
53106
  return resolveVersion({
53107
53107
  isSea: isSea2(),
53108
53108
  sqVersionXml: readSqVersionXml(),
53109
- define: true ? "0.90.2" : void 0,
53109
+ define: true ? "0.91.0" : void 0,
53110
53110
  pkgVersion: readPkgVersion()
53111
53111
  });
53112
53112
  }
@@ -53116,7 +53116,7 @@ function resolveChannel(s) {
53116
53116
  return "dev";
53117
53117
  }
53118
53118
  function appChannel() {
53119
- return resolveChannel({ isSea: isSea2(), define: true ? "0.90.2" : void 0 });
53119
+ return resolveChannel({ isSea: isSea2(), define: true ? "0.91.0" : void 0 });
53120
53120
  }
53121
53121
 
53122
53122
  // workflow-update.ts
@@ -195,6 +195,54 @@ export function vecToPlane(vec, u, v, n) {
195
195
  return { du: _dot(vec, u), dv: _dot(vec, v), dn: _dot(vec, n) };
196
196
  }
197
197
 
198
+ // --- Local coordinate frame (3D UCS): a FULL 3D basis { origin:[x,y,z]mm, xAxis, yAxis, normal }
199
+ // (orthonormal, right-handed: xAxis × yAxis = normal). The single seam every UCS power routes through.
200
+ // The global identity is { origin:[0,0,0], xAxis:[1,0,0], yAxis:[0,1,0], normal:[0,0,1] } → a no-op.
201
+ // A horizontal "rotate about Z by a" frame is xAxis:[cos,sin,0], yAxis:[−sin,cos,0], normal:[0,0,1];
202
+ // a tilted frame (from a 3-point pick) can point its normal anywhere (see frameFrom3Points).
203
+ /** world point → local: components of (p − origin) along each frame axis = Rᵀ·(p − origin). */
204
+ export function worldToLocal(p, frame) {
205
+ const o = frame.origin, X = frame.xAxis, Y = frame.yAxis, Z = frame.normal;
206
+ const d = [p[0] - o[0], p[1] - o[1], p[2] - o[2]];
207
+ return [nz(_dot(d, X)), nz(_dot(d, Y)), nz(_dot(d, Z))];
208
+ }
209
+ /** local point → world: origin + lx·X + ly·Y + lz·Z. Inverse of worldToLocal. */
210
+ export function localToWorld(l, frame) {
211
+ const o = frame.origin, X = frame.xAxis, Y = frame.yAxis, Z = frame.normal;
212
+ return [nz(o[0] + l[0] * X[0] + l[1] * Y[0] + l[2] * Z[0]),
213
+ nz(o[1] + l[0] * X[1] + l[1] * Y[1] + l[2] * Z[1]),
214
+ nz(o[2] + l[0] * X[2] + l[1] * Y[2] + l[2] * Z[2])];
215
+ }
216
+ /** local VECTOR → world (rotation only, NO origin translation — for relative typed entry / offsets). */
217
+ export function localVectorToWorld(v, frame) {
218
+ const X = frame.xAxis, Y = frame.yAxis, Z = frame.normal;
219
+ return [nz(v[0] * X[0] + v[1] * Y[0] + v[2] * Z[0]),
220
+ nz(v[0] * X[1] + v[1] * Y[1] + v[2] * Z[1]),
221
+ nz(v[0] * X[2] + v[1] * Y[2] + v[2] * Z[2])];
222
+ }
223
+ /**
224
+ * Full 3D UCS from 3 picked points (CAD 3-point flow): origin=a, +X toward b, +Y toward the c-side
225
+ * (the component of c−a ⊥ X), normal = X × Y. Which side c is picked flips the normal (± Z). Returns
226
+ * an orthonormal right-handed { origin, xAxis, yAxis, normal }, or null when degenerate (a≈b, or c
227
+ * on the X line). Reuses planeFrom3Points (origin/xAxis/normal) and derives yAxis = normal × xAxis.
228
+ */
229
+ export function frameFrom3Points(a, b, c) {
230
+ const p = planeFrom3Points(a, b, c);
231
+ if (!p) return null;
232
+ const yAxis = _norm(_cross(p.normal, p.xAxis)); // Y = Z × X → ⊥ X, on c's side, right-handed
233
+ if (!yAxis) return null;
234
+ return { origin: p.origin, xAxis: p.xAxis, yAxis, normal: p.normal };
235
+ }
236
+ /** The global identity frame (a no-op UCS). */
237
+ export function identityFrame(origin = [0, 0, 0]) {
238
+ return { origin: [origin[0], origin[1], origin[2]], xAxis: [1, 0, 0], yAxis: [0, 1, 0], normal: [0, 0, 1] };
239
+ }
240
+ /** A horizontal "rotate about Z by angleRad" frame at origin — the common non-tilted case. */
241
+ export function frameFromAngle(origin, angleRad) {
242
+ const c = Math.cos(angleRad), s = Math.sin(angleRad);
243
+ return { origin: [origin[0], origin[1], origin[2]], xAxis: [c, s, 0], yAxis: [-s, c, 0], normal: [0, 0, 1] };
244
+ }
245
+
198
246
  /**
199
247
  * 3D dimension geometry (pure). a,b are scene mm [x,y,z]. axis ∈ free|x|y|z.
200
248
  * free → the straight segment a→b (valueMm = full 3D distance); x|y|z →
@@ -17,7 +17,7 @@
17
17
  import * as THREE from 'three';
18
18
  import { OrbitControls } from 'three/addons/OrbitControls.js';
19
19
  import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
20
- import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, planeBasis, projectToPlane, planeFrom3Points, vecToPlane } from './steel-3d-core.js';
20
+ import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle } from './steel-3d-core.js';
21
21
  import { gridGeometry, gridCandidates3d, mmPerPx } from './grid-core.js';
22
22
 
23
23
  let renderer, scene, perspCam, orthoCam, camera, controls, root, api, canvasEl, ro, rafId, grid, raycaster, downXY, lastPick = '(none)';
@@ -216,6 +216,7 @@ function loop() {
216
216
  controls.update();
217
217
  sizeEndpoints();
218
218
  sizeClipHandles();
219
+ sizeFrameHandle();
219
220
  positionDimLabels();
220
221
  positionOverlayLabels();
221
222
  positionMemberLabels();
@@ -656,7 +657,7 @@ function setRefLine(on) { refLineOn = !!on; buildRefLines(); }
656
657
  function setInsertMode(on, pending) {
657
658
  insertMode = !!on;
658
659
  insertPending = insertMode ? (pending || insertPending) : null;
659
- if (insertMode) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); setClipMode(null); }
660
+ if (insertMode) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); setClipMode(null); disarmFrame3d(); }
660
661
  if (canvasEl) canvasEl.style.cursor = insertMode ? 'crosshair' : 'default';
661
662
  if (api && api.onInsertModeChange) api.onInsertModeChange(insertMode);
662
663
  }
@@ -1192,7 +1193,7 @@ function rebuildClipPlanes(c) { // recompute a clip's .planes from its ed
1192
1193
  }
1193
1194
  function setClipMode(m) { // arm/disarm a clip pick: 'plane' (click a face) | 'box' (draw 2 corners) | null
1194
1195
  if (m && dimMode3d) toggleDimTool();
1195
- if (m) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); } // clip shares the left-click — disarm Move/Copy + Add so their picks don't steal it (onDown routes them first)
1196
+ 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)
1196
1197
  clipMode = (m === 'plane' || m === 'box') ? m : null;
1197
1198
  clipBoxDraft = null; setClipPreview(null);
1198
1199
  if (canvasEl) canvasEl.style.cursor = clipMode ? 'crosshair' : 'default';
@@ -1548,6 +1549,8 @@ function onKey(e) {
1548
1549
  if (!renderer || !canvasEl || canvasEl.style.display === 'none') return; // only when 3D is active
1549
1550
  const ae = document.activeElement; if (ae && /^(INPUT|SELECT|TEXTAREA)$/.test(ae.tagName)) return;
1550
1551
  if (pending && pending.clipDrag && e.key === 'Escape') { e.preventDefault(); const p = pending; if (p.plane) p.clip.point = p.prePoint; else p.clip.box.copy(p.preBox); rebuildClipPlanes(p.clip); applyClips(); renderClipGizmo(); pending = dragging = null; if (controls) controls.enabled = true; if (readout) readout.style.display = 'none'; return; } // Esc mid-drag → undo the handle move
1552
+ if (framePicking() && e.key === 'Escape') { e.preventDefault(); if (frame3d) { cancelFramePick(); fireFrameChange(); } else armFrame3d(false); return; } // Esc cancels the whole 3-click pick (discards partial clicks); no prior frame → also exit the tool
1553
+ if (pending && pending.frameDrag && e.key === 'Escape') { e.preventDefault(); if (frame3d && pending.preFrame) frame3d = cloneFrame(pending.preFrame); pending = dragging = null; if (controls) controls.enabled = true; if (readout) readout.style.display = 'none'; fireFrameChange(); return; } // Esc mid-drag → revert the frame to its pre-drag basis
1551
1554
  if (pending && e.key === 'Escape' && (pending.epDrag || pending.origMm)) { // Esc mid-drag → cancel a member move / endpoint stretch and revert to the pre-drag state (no commit)
1552
1555
  e.preventDefault();
1553
1556
  if (pending.mesh && pending.meshPos0) pending.mesh.position.copy(pending.meshPos0); // put a live-moved (or Alt-vertical) member mesh back
@@ -1586,7 +1589,7 @@ function onKey(e) {
1586
1589
  function toggleDimTool() {
1587
1590
  dimMode3d = !dimMode3d;
1588
1591
  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
1589
- else { if (clipMode) setClipMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); controls.enabled = true; canvasEl.style.cursor = 'crosshair'; } // arming the dim tool disarms the clip pick, a set-plane pick, Move/Copy AND Add-member (all share the left-click + Esc)
1592
+ 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)
1590
1593
  reflectDimBar();
1591
1594
  return dimMode3d;
1592
1595
  }
@@ -2242,8 +2245,243 @@ let wpMode = null; // 'face' | '3pt' — armed set-plane pick mode
2242
2245
  let wpDraft = null; // 3pt picks collected so far
2243
2246
  let wpVisible = true; // "Show plane" toggle (applies to an explicit plane)
2244
2247
  let wpGroup = null;
2245
- function effectiveWP() { return workPlane || { origin: [0, 0, api ? api.defaultTosMm() : 0], normal: [0, 0, 1], xAxis: [1, 0, 0] }; }
2248
+ // ---- 3D local drawing frame (UCS, stage 1): a SEPARATE rotate-about-Z frame for skewed framing.
2249
+ // NOT the workPlane — an explicit ◇ Plane wins over it. null = global (world identity). Session-only,
2250
+ // model-wide, never saved to the contract (the frame is a temporary aid; dims it authors persist, not it).
2251
+ // The 3D local frame is a FULL 3D UCS — an orthonormal right-handed basis { origin, xAxis, yAxis, normal }
2252
+ // (a tilted frame is allowed; set by a 3-click pick). A horizontal frame has normal ≈ ±Z. The single seam
2253
+ // (worldToLocal/localToWorld) + every re-aiming tool routes through this via effectiveWP()→planeBasis.
2254
+ let frame3d = null; // { origin:[x,y,z]mm, xAxis, yAxis, normal } | null
2255
+ let frameMode = false; // armed: the gizmo handles are grabbable (else the gizmo is a passive indicator)
2256
+ let framePickPts = null; // null = not picking; [] / [origin] / [origin,xPt] = collecting the 3-click set (frame3d untouched until the 3rd click commits)
2257
+ let framePreview = null; // THREE.Group: the live X/Y rubber-band + Z-flip arrow during a pick
2258
+ const cloneFrame = (f) => ({ origin: [...f.origin], xAxis: [...f.xAxis], yAxis: [...f.yAxis], normal: [...f.normal] });
2259
+ const _dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2260
+ function frameZ() { return frame3d ? frame3d.origin[2] : (api ? api.defaultTosMm() : 0); }
2261
+ function effectiveWP() {
2262
+ if (workPlane) return workPlane; // explicit ◇ Plane wins (unchanged)
2263
+ if (frame3d) return { origin: [...frame3d.origin], normal: [...frame3d.normal], xAxis: [...frame3d.xAxis], kind: 'frame' };
2264
+ return { origin: [0, 0, api ? api.defaultTosMm() : 0], normal: [0, 0, 1], xAxis: [1, 0, 0] };
2265
+ }
2266
+ // What the tools ACTUALLY follow — a set ◇ Plane shadows the local frame, so the chip never claims Local
2267
+ // while a plane overrides it. Editor's Axes chip reads this in 3D. A horizontal frame reports its in-plane
2268
+ // angle; a tilted frame reports its tilt (normal off-vertical) — a single angle can't describe a 3D orientation.
2269
+ function frameInfo() {
2270
+ if (workPlane) return { mode: 'plane', kind: workPlane.kind || null };
2271
+ if (frame3d) {
2272
+ const n = frame3d.normal, horizontal = Math.abs(n[2]) > 0.9999;
2273
+ const angleDeg = horizontal ? Math.atan2(frame3d.xAxis[1], frame3d.xAxis[0]) * 180 / Math.PI : null;
2274
+ const tiltDeg = Math.acos(Math.max(-1, Math.min(1, Math.abs(n[2])))) * 180 / Math.PI; // 0 = horizontal
2275
+ return { mode: 'local', origin: [...frame3d.origin], xAxis: [...frame3d.xAxis], yAxis: [...frame3d.yAxis], normal: [...n], horizontal, angleDeg, tiltDeg, zUp: n[2] >= 0 };
2276
+ }
2277
+ return { mode: 'global' };
2278
+ }
2279
+ function fireFrameChange() { renderFrameGizmo(); if (api && api.onFrame3dChange) api.onFrame3dChange(frameInfo()); }
2280
+ // Set a HORIZONTAL frame at origin (numeric entry + gizmo materialize). origin defaults its Z to the active level.
2281
+ function setFrame3d(originMm, angleDeg) {
2282
+ const z = (originMm && originMm.length > 2) ? originMm[2] : frameZ();
2283
+ frame3d = frameFromAngle(originMm ? [originMm[0], originMm[1], z] : [0, 0, z], (angleDeg || 0) * Math.PI / 180);
2284
+ fireFrameChange();
2285
+ }
2286
+ // Set a full (possibly tilted) UCS from a computed basis — the 3-click pick's output.
2287
+ function setFrameBasis(basis) { frame3d = cloneFrame(basis); fireFrameChange(); }
2288
+ // Numeric "Angle°" sets a HORIZONTAL frame at that in-plane angle (keeps origin) — the horizontal refine case.
2289
+ function setFrameAngle(angleDeg) { setFrame3d(frame3d ? frame3d.origin : [0, 0, api ? api.defaultTosMm() : 0], angleDeg); }
2290
+ function setFrameOrigin(originMm) { // translate origin, keep the basis orientation
2291
+ if (!frame3d) { setFrame3d(originMm, 0); return; }
2292
+ frame3d.origin = [originMm[0], originMm[1], originMm.length > 2 ? originMm[2] : frame3d.origin[2]];
2293
+ fireFrameChange();
2294
+ }
2295
+ function clearFrame3d() { const had = !!frame3d || frameMode; cancelFramePick(); frame3d = null; frameMode = false; if (had) fireFrameChange(); }
2296
+ function armFrame3d(on) { // arm/disarm the tool; arming disarms conflicting tools
2297
+ frameMode = on == null ? !frameMode : !!on;
2298
+ if (frameMode) {
2299
+ 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)
2300
+ framePickPts = frame3d ? null : []; // no frame yet → start the 3-click pick; an existing frame → straight to drag-refine (re-pick from the panel)
2301
+ disposeFramePreview();
2302
+ } else cancelFramePick();
2303
+ if (canvasEl) canvasEl.style.cursor = frameMode ? 'crosshair' : 'default';
2304
+ fireFrameChange();
2305
+ }
2306
+ // re-run the 3-click pick on an already-armed frame (the panel "Re-pick" action) — keeps the old frame visible until commit
2307
+ function repickFrame3d() { if (frameMode) { framePickPts = []; disposeFramePreview(); fireFrameChange(); } }
2308
+ // disarm the frame tool — called by every OTHER left-click 3D tool when it arms, so the frame can't stay armed behind it and silently swallow clicks (Codex/silent-failure MED-2)
2309
+ function disarmFrame3d() { if (frameMode || framePicking()) { cancelFramePick(); frameMode = false; if (canvasEl) canvasEl.style.cursor = 'default'; fireFrameChange(); } }
2310
+ // The frame gizmo: an X–Y plane patch + red-X / green-Y / blue-Z axes at the (draggable) origin, ALWAYS
2311
+ // visible (at global 0,0 identity when no frame is set), armed → grabbable handles + rotation ring. In
2312
+ // overlayScene (2nd unclipped pass) so a section plane never cuts it. A set ◇ Plane shadows it (its own patch shows).
2313
+ let frameGizmo = null;
2314
+ function disposeFrameGizmo() { if (!frameGizmo) return; if (overlayScene) overlayScene.remove(frameGizmo); frameGizmo.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); frameGizmo = null; }
2315
+ function renderFrameGizmo() {
2316
+ disposeFrameGizmo();
2317
+ if (!overlayScene || workPlane) return; // ◇ Plane shadows the frame → renderWorkPlane draws instead
2318
+ const act = !!frame3d, on = frameMode;
2319
+ const O = frame3d ? frame3d.origin : [0, 0, api ? api.defaultTosMm() : 0];
2320
+ const u = new THREE.Vector3(...(frame3d ? frame3d.xAxis : [1, 0, 0])), v = new THREE.Vector3(...(frame3d ? frame3d.yAxis : [0, 1, 0])), n = new THREE.Vector3(...(frame3d ? frame3d.normal : [0, 0, 1])); // the real basis (tilted-aware)
2321
+ const g = new THREE.Group();
2322
+ const CELL = 1524, N = 4, half = (CELL * N) / 2; // a small 4×4 @ 5ft patch (drawn in local coords, group oriented below)
2323
+ const verts = []; for (let i = 0; i <= N; i++) { const o = -half + i * CELL; verts.push(o, -half, 0, o, half, 0, -half, o, 0, half, o, 0); }
2324
+ const grid = new THREE.BufferGeometry(); grid.setAttribute('position', new THREE.Float32BufferAttribute(verts, 3));
2325
+ g.add(new THREE.LineSegments(grid, new THREE.LineBasicMaterial({ color: 0x3b82f6, transparent: true, opacity: act ? 0.3 : 0.14 })));
2326
+ g.add(new THREE.Mesh(new THREE.PlaneGeometry(CELL * N, CELL * N), new THREE.MeshBasicMaterial({ color: 0x3b82f6, transparent: true, opacity: act ? 0.1 : 0.05, side: THREE.DoubleSide, depthWrite: false })));
2327
+ const axis = (len, col, vx, vy, vz) => { const l = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), new THREE.Vector3(vx * len, vy * len, vz * len)]), new THREE.LineBasicMaterial({ color: col, transparent: true, opacity: 0.95 })); l.renderOrder = 997; return l; };
2328
+ g.add(axis(half, 0xef4444, 1, 0, 0)); // local X = red
2329
+ g.add(axis(half, 0x22c55e, 0, 1, 0)); // local Y = green
2330
+ g.add(axis(half * 0.9, 0x3b82f6, 0, 0, 1)); // local Z = blue (up)
2331
+ const od = new THREE.Mesh(new THREE.SphereGeometry(1, 12, 8), new THREE.MeshBasicMaterial({ color: on ? 0xf59e0b : 0x3b82f6 })); // unit sphere → sizeFrameHandle() keeps it screen-constant (like the endpoint/clip dots); armed = amber #f59e0b (distinct from the warm-yellow endpoint dots), passive = brand blue
2332
+ od.userData.frameHandle = 'origin'; g.add(od);
2333
+ if (on) { // armed → the cyan rotation ring (grabbable)
2334
+ const pts = []; for (let i = 0; i <= 48; i++) { const p = i / 48 * Math.PI * 2; pts.push(new THREE.Vector3(Math.cos(p) * half * 0.8, Math.sin(p) * half * 0.8, 0)); }
2335
+ const ring = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(pts), new THREE.LineBasicMaterial({ color: 0x22d3ee, transparent: true, opacity: 0.85 }));
2336
+ ring.renderOrder = 997; ring.userData.frameHandle = 'ring'; g.add(ring);
2337
+ }
2338
+ g.applyMatrix4(new THREE.Matrix4().makeBasis(u, v, n));
2339
+ g.position.set(O[0], O[1], O[2]);
2340
+ frameGizmo = g; overlayScene.add(g); sizeFrameHandle();
2341
+ }
2342
+ // Screen-constant origin dot — mirrors sizeClipHandles(); called each frame from loop() so the grab dot
2343
+ // stays ~14px armed / ~11px passive at any zoom (the cyan ring + patch stay world-sized as large affordances).
2344
+ function sizeFrameHandle() {
2345
+ if (!frameGizmo) return;
2346
+ const O = frameGizmoOrigin(), wp = new THREE.Vector3(O[0], O[1], O[2]), r = pxToWorldAt(frameMode ? 7 : 5.5, wp);
2347
+ for (const h of frameGizmo.children) if (h.userData && h.userData.frameHandle === 'origin') h.scale.setScalar(r);
2348
+ }
2349
+ // --- frame manipulator: grab + drag the gizmo's origin (translate) or ring (rotate about Z). Armed only. ---
2350
+ const FRAME_RING_R = (1524 * 4 / 2) * 0.8; // ring radius (matches renderFrameGizmo)
2351
+ function frameGizmoOrigin() { return frame3d ? frame3d.origin : [0, 0, api ? api.defaultTosMm() : 0]; }
2352
+ function pickFrameHandle(cx, cy) { // → 'origin' | 'ring' | null (screen-space, like pickClipHandle)
2353
+ if (!frameMode || !overlayScene || workPlane || !canvasEl) return null;
2354
+ camera.updateMatrixWorld();
2355
+ const rect = canvasEl.getBoundingClientRect(), px = cx - rect.left, py = cy - rect.top;
2356
+ const O = frameGizmoOrigin();
2357
+ const toS = (p) => { const w = new THREE.Vector3(p[0], p[1], p[2]).project(camera); return w.z > 1 ? null : [(w.x * 0.5 + 0.5) * rect.width, (-w.y * 0.5 + 0.5) * rect.height]; };
2358
+ const os = toS(O); if (os && Math.hypot(os[0] - px, os[1] - py) <= 16) return 'origin';
2359
+ const u = frame3d ? frame3d.xAxis : [1, 0, 0], v = frame3d ? frame3d.yAxis : [0, 1, 0]; let bestD = 12; // ring lies in the frame's X-Y plane — sample all THREE coords so a tilted ring's grab matches the drawn ring
2360
+ for (let i = 0; i < 48; i++) { const ph = i / 48 * Math.PI * 2, c = Math.cos(ph), s = Math.sin(ph);
2361
+ const ss = toS([O[0] + FRAME_RING_R * (c * u[0] + s * v[0]), O[1] + FRAME_RING_R * (c * u[1] + s * v[1]), O[2] + FRAME_RING_R * (c * u[2] + s * v[2])]);
2362
+ if (ss) { const dd = Math.hypot(ss[0] - px, ss[1] - py); if (dd < bestD) bestD = dd; } }
2363
+ return bestD < 12 ? 'ring' : null;
2364
+ }
2365
+ function startFrameDrag(kind, e) {
2366
+ const O = frameGizmoOrigin();
2367
+ if (!frame3d) setFrame3d([O[0], O[1], O[2]], 0); // materialize a horizontal frame on first grab from global
2368
+ pending = { frameDrag: kind, preFrame: cloneFrame(frame3d) };
2369
+ if (kind === 'ring') { // capture the in-plane angle at the grab point so the rotation is RELATIVE (grabbing at 90° doesn't jump the frame 90°)
2370
+ const hit = rayToFramePlane(e.clientX, e.clientY, frame3d.origin, frame3d.normal);
2371
+ const d = hit ? [hit[0] - frame3d.origin[0], hit[1] - frame3d.origin[1], hit[2] - frame3d.origin[2]] : null;
2372
+ pending.startAngle = d ? Math.atan2(_dot3(d, frame3d.yAxis), _dot3(d, frame3d.xAxis)) : null; // edge-on grab → null; onMoveFrame sets the reference on the first valid hit (no jump)
2373
+ }
2374
+ dragging = null; downXY = [e.clientX, e.clientY];
2375
+ }
2376
+ // camera ray → intersection with the arbitrary plane (origin, normal); null when the ray is ∥ the plane (edge-on)
2377
+ function rayToFramePlane(cx, cy, origin, normal) {
2378
+ if (!canvasEl) return null;
2379
+ const rect = canvasEl.getBoundingClientRect();
2380
+ const ndc = new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1);
2381
+ const rc = new THREE.Raycaster(); rc.setFromCamera(ndc, camera);
2382
+ const nrm = new THREE.Vector3(normal[0], normal[1], normal[2]);
2383
+ if (Math.abs(rc.ray.direction.dot(nrm)) < 1e-3) return null; // ray ∥ the plane (edge-on) → no reliable intersection (would be astronomically far → a false rotation delta)
2384
+ const plane = new THREE.Plane(nrm, -(normal[0] * origin[0] + normal[1] * origin[1] + normal[2] * origin[2]));
2385
+ const pt = new THREE.Vector3();
2386
+ return rc.ray.intersectPlane(plane, pt) ? [pt.x, pt.y, pt.z] : null;
2387
+ }
2388
+ function onMoveFrame(e) {
2389
+ if (!dragging && Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) <= DRAG_TOL_PX) return;
2390
+ dragging = pending;
2391
+ const pre = pending.preFrame;
2392
+ const showRO = (dist, type) => { if (readout) { readout._dist.textContent = dist; readout._type.textContent = type; readout.style.left = (e.clientX + 14) + 'px'; readout.style.top = (e.clientY + 14) + 'px'; readout.style.display = 'block'; } };
2393
+ if (pending.frameDrag === 'origin') { // translate the origin — snaps to geometry like any point pick; Shift = ortho lock; Alt = no snap (basis orientation kept)
2394
+ let target = null;
2395
+ if (!e.shiftKey && !e.altKey) { const sn = dimPointAt(e); if (sn && sn.type) { target = sn.p; showMarker(sn.p, sn.type); } } // snapped to a real member end / grid / intersection → land on the true 3D point
2396
+ if (!target) {
2397
+ const hit = rayToPlane(e.clientX, e.clientY, pre.origin[2]); // free move on the plane at the origin's Z; edge-on view → null → skip (no NaN)
2398
+ if (!hit) { showRO('rotate to an angled or top view', ''); return; }
2399
+ let x = hit[0], y = hit[1];
2400
+ if (e.shiftKey) { const dx = x - pre.origin[0], dy = y - pre.origin[1]; if (Math.abs(dx) >= Math.abs(dy)) y = pre.origin[1]; else x = pre.origin[0]; } // Shift = ortho lock (H/V) from the pre-drag origin, like dragging a member
2401
+ target = [x, y, pre.origin[2]]; if (marker) marker.visible = false;
2402
+ }
2403
+ frame3d.origin = target;
2404
+ showRO((Math.hypot(target[0] - pre.origin[0], target[1] - pre.origin[1], target[2] - pre.origin[2]) / FT_MM).toFixed(2) + ' ft', ' moved');
2405
+ } else { // ring → rotate the basis about its OWN normal (tilt preserved)
2406
+ const hit = rayToFramePlane(e.clientX, e.clientY, pre.origin, pre.normal);
2407
+ if (!hit) { showRO('rotate to an angled or top view', ''); return; }
2408
+ const d = [hit[0] - pre.origin[0], hit[1] - pre.origin[1], hit[2] - pre.origin[2]];
2409
+ const cur = Math.atan2(_dot3(d, pre.yAxis), _dot3(d, pre.xAxis));
2410
+ if (pending.startAngle == null) { pending.startAngle = cur; return; } // grab was edge-on → set the reference on the FIRST valid hit, don't rotate this frame (Codex)
2411
+ const ang = cur - pending.startAngle, c = Math.cos(ang), s = Math.sin(ang); // RELATIVE to the grab point: rotate by the delta, not the absolute cursor angle
2412
+ frame3d = { origin: [...pre.origin], normal: [...pre.normal],
2413
+ xAxis: [c * pre.xAxis[0] + s * pre.yAxis[0], c * pre.xAxis[1] + s * pre.yAxis[1], c * pre.xAxis[2] + s * pre.yAxis[2]],
2414
+ yAxis: [-s * pre.xAxis[0] + c * pre.yAxis[0], -s * pre.xAxis[1] + c * pre.yAxis[1], -s * pre.xAxis[2] + c * pre.yAxis[2]] };
2415
+ showRO(Math.round(ang * 180 / Math.PI) + '°', ' rot');
2416
+ }
2417
+ fireFrameChange();
2418
+ }
2419
+ // test helper: the frame gizmo's grab points projected to client px (origin + two ring samples), so an E2E can drive precise drags
2420
+ function frameHandlesScreen() {
2421
+ if (!canvasEl) return null;
2422
+ camera.updateMatrixWorld();
2423
+ const rect = canvasEl.getBoundingClientRect(), O = frameGizmoOrigin();
2424
+ const toS = (p) => { const w = new THREE.Vector3(p[0], p[1], p[2]).project(camera); return { x: rect.left + (w.x * 0.5 + 0.5) * rect.width, y: rect.top + (-w.y * 0.5 + 0.5) * rect.height, behind: w.z > 1 }; };
2425
+ const u = frame3d ? frame3d.xAxis : [1, 0, 0], v = frame3d ? frame3d.yAxis : [0, 1, 0];
2426
+ const ringAt = (deg) => { const ph = deg * Math.PI / 180, c = Math.cos(ph), s = Math.sin(ph); return toS([O[0] + FRAME_RING_R * (c * u[0] + s * v[0]), O[1] + FRAME_RING_R * (c * u[1] + s * v[1]), O[2] + FRAME_RING_R * (c * u[2] + s * v[2])]); }; // all 3 coords → matches the drawn tilted ring
2427
+ return { origin: toS(O), ring0: ringAt(0), ring90: ringAt(90), armed: frameMode };
2428
+ }
2429
+ // --- 3-click UCS set (D6): pick origin → X-axis point → Y-side point → frameFrom3Points → a full (possibly
2430
+ // tilted) basis. Each click snaps freely to member ends / grid / geometry (dimPointAt = D5, works from any
2431
+ // camera angle). frame3d is untouched until the 3rd click commits, so the chip + prior gizmo don't flicker. ---
2432
+ function framePicking() { return framePickPts !== null; }
2433
+ function framePickStep() { return framePickPts ? framePickPts.length : null; } // 0=origin · 1=X · 2=Y | null when not picking
2434
+ function cancelFramePick() { framePickPts = null; disposeFramePreview(); if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; }
2435
+ function disposeFramePreview() { if (!framePreview) return; if (overlayScene) overlayScene.remove(framePreview); framePreview.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); framePreview = null; }
2436
+ function fireFramePickChange() { if (api && api.onFrame3dChange) api.onFrame3dChange(frameInfo()); } // the panel hint follows the pick step; frame3d is unchanged so the chip/gizmo stay put
2437
+ function framePickClick(e) {
2438
+ const r = dimPointAt(e); if (!r) return; // a valid snapped/plane point
2439
+ if (framePickPts.length === 1 && Math.hypot(r.p[0] - framePickPts[0][0], r.p[1] - framePickPts[0][1], r.p[2] - framePickPts[0][2]) < 5) { // X point == origin → there's no X axis; reject HERE with an accurate message (else every later Y pick fails on a≈b)
2440
+ if (api && api.toast) api.toast('That’s the origin — pick a different point to set the X direction'); return; }
2441
+ if (framePickPts.length < 2) { framePickPts.push(r.p); showMarker(r.p, r.type); fireFramePickChange(); return; }
2442
+ const basis = frameFrom3Points(framePickPts[0], framePickPts[1], r.p); // 3rd click → build the UCS
2443
+ if (!basis) { if (api && api.toast) api.toast('That point is in line with the X axis — pick a point off to the side'); return; } // degenerate: keep collecting
2444
+ framePickPts = null; disposeFramePreview(); if (marker) marker.visible = false; if (readout) readout.style.display = 'none';
2445
+ setFrameBasis(basis); // commit → frame3d set, chip/panel update, gizmo redraws; frameMode stays armed for drag-refine
2446
+ }
2447
+ // Live preview: after the origin → the X arm to the cursor; after X → the Y arm + a Z arrow that visibly
2448
+ // flips as the cursor crosses to the other side of X (the D6 "which side sets Z up/down" risk, made visible).
2449
+ function renderFramePickPreview(e) {
2450
+ disposeFramePreview();
2451
+ if (!overlayScene || !framePickPts) return;
2452
+ const r = dimPointAt(e), cur = r ? r.p : null;
2453
+ if (r) showMarker(r.p, r.type); else if (marker) marker.visible = false; // snap reticle on EVERY step, including the origin pick
2454
+ if (!cur || !framePickPts.length) return; // origin step: just the reticle, no rubber-band yet
2455
+ const g = new THREE.Group();
2456
+ const line = (a, b, col, op) => { const l = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(...a), new THREE.Vector3(...b)]), new THREE.LineBasicMaterial({ color: col, transparent: true, opacity: op == null ? 0.95 : op })); l.material.depthTest = false; l.renderOrder = 998; return l; };
2457
+ const O = framePickPts[0];
2458
+ if (framePickPts.length === 1) { // origin set → preview local X toward the cursor
2459
+ g.add(line(O, cur, 0xef4444));
2460
+ } else { // origin + X set → preview Y + the flipping Z
2461
+ const X = framePickPts[1], basis = frameFrom3Points(O, X, cur);
2462
+ g.add(line(O, X, 0xef4444)); // committed X (red)
2463
+ if (basis) {
2464
+ const half = Math.max(1524, Math.hypot(X[0] - O[0], X[1] - O[1], X[2] - O[2]));
2465
+ g.add(line(O, [O[0] + basis.yAxis[0] * half, O[1] + basis.yAxis[1] * half, O[2] + basis.yAxis[2] * half], 0x22c55e)); // Y (green)
2466
+ g.add(line(O, [O[0] + basis.normal[0] * half * 0.9, O[1] + basis.normal[1] * half * 0.9, O[2] + basis.normal[2] * half * 0.9], 0x3b82f6)); // Z (blue) — flips with the cursor side
2467
+ if (readout) { readout._dist.textContent = basis.normal[2] >= 0 ? 'Z up' : 'Z down'; readout._type.textContent = ''; readout.style.left = (e.clientX + 14) + 'px'; readout.style.top = (e.clientY + 14) + 'px'; readout.style.display = 'block'; }
2468
+ }
2469
+ }
2470
+ framePreview = g; overlayScene.add(g);
2471
+ }
2472
+ // F3: lock a plan-space [dx,dy] drag delta to the dominant working-plane axis (Shift = ortho on a direct member drag — move or Ctrl+drag copy).
2473
+ // Reuses effectiveWP() above so a rotated-about-Z local UCS is honoured; a genuinely tilted frame (>~0.8°) falls back to
2474
+ // plan X/Y (whose u/v aren't horizontal) — the horizontal plan drag never gains a Z component.
2475
+ function orthoLockDelta(dx, dy) {
2476
+ const wp = effectiveWP();
2477
+ if (Math.abs(wp.normal[2]) < 0.9999) return Math.abs(dx) >= Math.abs(dy) ? [dx, 0] : [0, dy]; // only a horizontal frame (incl. rotated-about-Z) uses u/v; a tilted frame falls back to plan X/Y
2478
+ const { u, v } = planeBasis(wp.normal, wp.xAxis);
2479
+ const du = dx * u[0] + dy * u[1], dv = dx * v[0] + dy * v[1];
2480
+ return Math.abs(du) >= Math.abs(dv) ? [du * u[0], du * u[1]] : [dv * v[0], dv * v[1]];
2481
+ }
2246
2482
  function renderWorkPlane() {
2483
+ renderFrameGizmo(); // keep the frame gizmo in sync with the ◇ Plane (it self-guards on workPlane: hidden while a plane is set, restored when cleared) — Codex/code-review
2484
+ if (api && api.onFrame3dChange) api.onFrame3dChange(frameInfo()); // and refresh the Axes chip: "Plane" when a plane is set, back to Local/Global when cleared
2247
2485
  if (wpGroup) { scene.remove(wpGroup); wpGroup.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); wpGroup = null; }
2248
2486
  if (!workPlane || !wpVisible) return; // the implicit level plane is not drawn — the 2D plan already communicates it
2249
2487
  const wp = effectiveWP(), { u, v } = planeBasis(wp.normal, wp.xAxis);
@@ -2268,7 +2506,7 @@ function renderWorkPlane() {
2268
2506
  function reflectWpBar() { const b = document.getElementById('m3dWp'); if (b) { b.classList.toggle('on', !!wpMode || !!workPlane);
2269
2507
  const kind = workPlane && workPlane.kind ? { face: 'Face', p3: '3pt', xy: 'XY', xz: 'XZ', yz: 'YZ' }[workPlane.kind] || '' : '';
2270
2508
  b.textContent = wpMode ? '◇ Plane ✕' : (kind ? '◇ Plane: ' + kind + ' ▾' : '◇ Plane ▾'); } } // the label reads the active plane without opening the menu (ux review)
2271
- function armWorkPlanePick(mode) { if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); } marker.visible = false; canvasEl.style.cursor = wpMode ? 'crosshair' : 'default'; reflectWpBar(); } // a set-plane pick shares the left-click — disarm Move/Copy + Add (their onDown routes run first)
2509
+ function armWorkPlanePick(mode) { if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; 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)
2272
2510
  function setWorkPlanePrincipal(kind, offsetMm) {
2273
2511
  const off = offsetMm || 0;
2274
2512
  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];
@@ -2326,7 +2564,7 @@ function wpPointAt(e) {
2326
2564
  if (!e.altKey) {
2327
2565
  if (!tfCandidates) tfCandidates = allCandidates(null); // members + grid, so Move/Copy + draw-on-plane snap to the grid too
2328
2566
  const r = snapPoint(hit, tfCandidates.filter((c) => candAllowed3d(c.type)), toScreen, SNAP_TOL_PX); // honour the running-snaps / override
2329
- if (r.candidate) return { p: projectToPlane(r.snapped, wp.origin, wp.normal), snap: true, type: r.candidate.type };
2567
+ if (r.candidate) return { p: r.snapped, snap: true, type: r.candidate.type }; // land on the TRUE 3D snap (member end / grid), NOT projected onto the plane — snapping stays free to the whole model, same as global (Pawel D5); a free (non-snapped) click still rides the plane below
2330
2568
  }
2331
2569
  return { p: hit, snap: false, type: null };
2332
2570
  }
@@ -2573,6 +2811,8 @@ function onDown(e) {
2573
2811
  if (insertMode) { e.stopPropagation(); const r = insertPick(e.clientX, e.clientY); const sticky = insertPending && insertPending.sticky; if (r && api && api.onInsertPlace) api.onInsertPlace(r, insertPending); if (!sticky) setInsertMode(false); return; } // armed: place at the pick. One-shot for a detail / IFC import; a sticky pending (a favourite) STAYS armed for repeat placement — Esc/onInsertPlace's own cancel disarms.
2574
2812
  if (clipMode === 'plane') { e.stopPropagation(); addClipPlaneAtScreen(e.clientX, e.clientY); return; } // armed: left-click a face → place a clip plane (stays armed)
2575
2813
  if (clipMode === 'box') { e.stopPropagation(); onClipBoxClick(e); return; } // armed: 2-corner clip-box draw on the floor plane
2814
+ if (framePicking()) { e.stopPropagation(); controls.enabled = true; framePickClick(e); return; } // 3-click UCS set: this click collects the origin / X point / Y point
2815
+ 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)
2576
2816
  if (selectedClipIds.size) { 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
2577
2817
  if (dimMode3d) { // 2-click dimension placement (not a drag): pick A, then B → place
2578
2818
  e.stopPropagation(); controls.enabled = true;
@@ -2674,6 +2914,7 @@ function onMove(e) {
2674
2914
  if (!renderer || !canvasEl || canvasEl.style.display === 'none') return; // 3D inactive — ignore window pointer events
2675
2915
  if (boxSel) { onBoxMove(e); return; }
2676
2916
  if (pending && pending.clipDrag) { onMoveClip(e); return; } // dragging a clip handle (plane offset / box face)
2917
+ if (pending && pending.frameDrag) { onMoveFrame(e); return; } // dragging the local-frame origin / rotation ring
2677
2918
  if (!pending || pending.geo) return;
2678
2919
  if (pending.epDrag) { onMoveEndpoint(e); return; }
2679
2920
  if (!pending.grab || !pending.origMm) return;
@@ -2685,16 +2926,21 @@ function onMove(e) {
2685
2926
  if (pending.mode === 'vertical') { onMoveVertical(e); return; }
2686
2927
  const cur = rayToPlane(e.clientX, e.clientY, pending.planeZ); if (!cur) return;
2687
2928
  let dx = cur[0] - pending.grab[0], dy = cur[1] - pending.grab[1];
2688
- // snap the translated endpoints; take the closest winning correction
2689
- let best = Infinity, corr = null, at = null, atType = null;
2690
- for (const ep of pending.origMm) {
2691
- const tp = [ep[0] + dx, ep[1] + dy, ep[2]];
2692
- const r = snapPoint(tp, pending.candidates, toScreen, SNAP_TOL_PX);
2693
- if (!r.candidate) continue;
2694
- const a = toScreen(tp), b = toScreen(r.snapped), d = Math.hypot(b.x - a.x, b.y - a.y);
2695
- if (d < best) { best = d; corr = [r.snapped[0] - tp[0], r.snapped[1] - tp[1]]; at = r.snapped; atType = r.candidate.type; }
2696
- }
2697
- if (corr) { dx += corr[0]; dy += corr[1]; }
2929
+ let at = null, atType = null;
2930
+ if (e.shiftKey) { // F3: Shift = ortho lock along the dominant in-plane axis; snap suppressed (marker stays hidden) — mirrors the Move/Copy tool
2931
+ [dx, dy] = orthoLockDelta(dx, dy);
2932
+ } else {
2933
+ // snap the translated endpoints; take the closest winning correction
2934
+ let best = Infinity, corr = null;
2935
+ for (const ep of pending.origMm) {
2936
+ const tp = [ep[0] + dx, ep[1] + dy, ep[2]];
2937
+ const r = snapPoint(tp, pending.candidates, toScreen, SNAP_TOL_PX);
2938
+ if (!r.candidate) continue;
2939
+ const a = toScreen(tp), b = toScreen(r.snapped), d = Math.hypot(b.x - a.x, b.y - a.y);
2940
+ if (d < best) { best = d; corr = [r.snapped[0] - tp[0], r.snapped[1] - tp[1]]; at = r.snapped; atType = r.candidate.type; }
2941
+ }
2942
+ if (corr) { dx += corr[0]; dy += corr[1]; }
2943
+ }
2698
2944
  pending.delta = [dx, dy];
2699
2945
  if (pending.copy) positionCopyGhost(dx, dy); // Ctrl+drag: move a translucent ghost, never the original
2700
2946
  else if (pending.mesh && pending.meshPos0) pending.mesh.position.set(pending.meshPos0.x + dx, pending.meshPos0.y + dy, pending.meshPos0.z);
@@ -2829,6 +3075,7 @@ function onUp(e) {
2829
3075
  const moved = downXY ? Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) : Infinity; downXY = null;
2830
3076
  if (!p) return;
2831
3077
  if (p.clipDrag) return; // a clip handle drag is applied live during onMoveClip; nothing to commit on up (controls re-enabled above)
3078
+ if (p.frameDrag) { if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; return; } // local-frame origin/rotation is applied live during onMoveFrame; session-only, nothing to commit — clear the snap marker/readout on release
2832
3079
  if (p.epDrag) { // end-node drag → write just that endpoint's wp; a click (no drag) just selects the member
2833
3080
  if (wasDragging && p.newPt && api && api.onMoveEndpoint) { if (api.onSelect) api.onSelect(p.id, false); api.onMoveEndpoint(p.id, p.end, planPointToWp(p.newPt, p.ppf)); }
2834
3081
  else if (api && api.onSelect) api.onSelect(p.id, false);
@@ -2929,6 +3176,17 @@ function onHoverMove(e) {
2929
3176
  } else { dimPreviewLine.visible = false; if (!dimDraft3d) readout.style.display = 'none'; }
2930
3177
  return;
2931
3178
  }
3179
+ if (framePicking()) { // 3-click UCS set in progress: live rubber-band X/Y + Z-flip arrow, snap marker at the cursor
3180
+ canvasEl.style.cursor = 'crosshair';
3181
+ renderFramePickPreview({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt });
3182
+ return;
3183
+ }
3184
+ if (frameMode) { // armed local-frame: over the origin/ring → grab cursor + brighten the ring; else crosshair (no member hover while armed)
3185
+ let fh = null; try { fh = pickFrameHandle(lastHoverXY[0], lastHoverXY[1]); } catch { fh = null; }
3186
+ if (frameGizmo) for (const h of frameGizmo.children) if (h.userData && h.userData.frameHandle === 'ring' && h.material) h.material.opacity = (fh === 'ring') ? 1 : 0.85; // stateless: set both ways every hover, no restore needed
3187
+ canvasEl.style.cursor = fh ? 'grab' : 'crosshair';
3188
+ return;
3189
+ }
2932
3190
  if (selectedClipIds.size) { let ch = null; try { ch = pickClipHandle(lastHoverXY[0], lastHoverXY[1]); } catch { ch = null; } if (ch) { canvasEl.style.cursor = 'move'; return; } } // over a clip handle → move cursor
2933
3191
  let ep = null; try { ep = pickEndpoint(lastHoverXY[0], lastHoverXY[1]); } catch { ep = null; }
2934
3192
  if (ep) { // over an end node → ring + move cursor; keep its member's dots shown
@@ -2972,12 +3230,13 @@ function updateStatusChip() {
2972
3230
  hoverChip.style.display = canvasEl.style.display === 'none' ? 'none' : 'block';
2973
3231
  }
2974
3232
 
2975
- function show() { if (controls) controls.enabled = true; if (canvasEl) { canvasEl.style.display = 'block'; resize(); } if (!rafId) loop(); updateStatusChip(); refreshDims(); refreshOverlayDims(); } // resume the render loop (reset orbit in case a gesture was stranded by a mid-drag hide)
3233
+ function show() { if (controls) controls.enabled = true; if (canvasEl) { canvasEl.style.display = 'block'; resize(); } if (!rafId) loop(); updateStatusChip(); refreshDims(); refreshOverlayDims(); renderFrameGizmo(); } // resume the render loop (reset orbit in case a gesture was stranded by a mid-drag hide)
2976
3234
  function hide() {
2977
3235
  if (dimMode3d) toggleDimTool(); // disarm the dim tool + sync its toolbar (no stale draft/armed state on return)
2978
3236
  if (clipMode) setClipMode(null); // disarm the clip-plane pick too (no stale armed state on return)
2979
3237
  if (insertMode) setInsertMode(false); // disarm a pending detail placement — else the first click on return would place it
2980
3238
  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
3239
+ if (frameMode || (pending && pending.frameDrag) || framePicking()) { if (pending && pending.frameDrag && frame3d && pending.preFrame) frame3d = cloneFrame(pending.preFrame); cancelFramePick(); frameMode = false; if (pending && pending.frameDrag) pending = dragging = null; if (readout) readout.style.display = 'none'; fireFrameChange(); } // leaving 3D disarms the local-frame manipulator + cancels an in-progress pick/drag
2981
3240
  cmClear3d(); drClear3d(); // and any 3D Move/Copy or draw draft/ghosts
2982
3241
  if (dimLabelHost) dimLabelHost.style.display = 'none'; // the loop that hides labels is about to stop — hide synchronously so none are stranded
2983
3242
  if (memberLabelHost) memberLabelHost.style.display = 'none'; // member labels ride the same about-to-stop loop — hide them too, or they strand over the 2D UI
@@ -3024,7 +3283,7 @@ function dispose() {
3024
3283
  gridTexCache.clear();
3025
3284
  clearRoot();
3026
3285
  if (workAreaHelper) { if (overlayScene) overlayScene.remove(workAreaHelper); workAreaHelper.geometry.dispose(); workAreaHelper.material.dispose(); workAreaHelper = null; }
3027
- clearConnEnvelope(); clearClipGizmo(); setClipPreview(null); overlayScene = null;
3286
+ clearConnEnvelope(); clearClipGizmo(); setClipPreview(null); disposeFramePreview(); disposeFrameGizmo(); overlayScene = null; // dispose the frame gizmo/preview THREE resources before dropping the scene (Codex)
3028
3287
  clips = []; workArea = null; clipMode = null; selectedClipIds.clear(); clipBoxDraft = null; // clips live on the renderer; drop them with the renderer
3029
3288
  if (renderer) renderer.dispose();
3030
3289
  renderer = scene = camera = perspCam = orthoCam = controls = root = api = canvasEl = ro = null; built = false;
@@ -3103,6 +3362,7 @@ window.Steel3DView = {
3103
3362
  cameraState, setCameraState, objectsPaneState, applyObjectsPaneState, // saved-view snapshot surface (Views Organizer)
3104
3363
  workAreaSetAll, workAreaFromSelection, workAreaToggle, workAreaSetWhole, clearWorkArea, workAreaState,
3105
3364
  armWorkPlanePick, setWorkPlanePrincipal, clearWorkPlane, toggleWorkPlaneVisible, workPlaneInfo,
3365
+ armFrame3d, disarmFrame3d, repickFrame3d, setFrame3d, setFrameBasis, setFrameAngle, setFrameOrigin, clearFrame3d, frameInfo, frameArmed: () => frameMode, framePicking, framePickStep, frameHandlesScreen, // 3D local drawing frame (UCS stage 1)
3106
3366
  cmEscape, cmHasBase, cmClear3d, setCmAxis, cmLastClient, cmHudApply,
3107
3367
  drClear3d, drEscape: () => { if (drDraft) { drDraft = null; drClear3d(); return true; } return false; },
3108
3368
  toggleDimTool, setDimAxis, dimAxis, setDims3dVisible, dims3dVisible, refreshDims,
@@ -145,7 +145,7 @@
145
145
  .aithumb{position:relative;display:inline-flex} .aithumb img{height:60px;border-radius:4px;border:1px solid var(--line);background:#fff;display:block}
146
146
  .aithumb button{position:absolute;top:-5px;right:-5px;width:16px;height:16px;padding:0;border-radius:8px;font-size:10px;line-height:16px;text-align:center;background:#7f1d1d;border-color:#991b1b;color:#fecaca}
147
147
  #saveStat.dirty{color:#fbbf24} #saveStat.ok{color:#86efac} #saveStat.err{color:#fca5a5}
148
- #csStat.local{border:1px solid #22d3ee;background:rgba(34,211,238,.10);border-radius:4px;padding:1px 6px} /* lift the chip out of the muted row when a local frame is active (reuses the dim/accent cyan — no new colour) */
148
+ #csStat.local{border:1px solid #22d3ee;background:rgba(34,211,238,.10);border-radius:4px;padding:1px 6px;cursor:pointer} /* lift the chip out of the muted row when a local frame/plane is active (reuses the dim/accent cyan — no new colour); clickable → reset to global */
149
149
  #snapStat{cursor:pointer;border:1px solid #22d3ee;background:rgba(34,211,238,.10);border-radius:4px;padding:1px 6px} /* snap-override chip — same cyan treatment as #csStat.local; the cyan IS the snap-marker colour it restricts */
150
150
  #snapStat:hover b{color:#fff}
151
151
  #snapMenu{position:fixed;left:0;top:0;z-index:45;min-width:186px} /* right-click snap menu — reuses the .m3dmenu skin, opened at the cursor */
@@ -172,6 +172,15 @@
172
172
  #moreMenu #m3dInsertMenu{left:auto;right:calc(100% + 4px);top:0}
173
173
  body:not(.v3d) #moreMenu #insWrap{display:none} /* Insert detail places into the 3D scene — hide it in 2D (needs 2 ids to beat the .m3dwrap.ins-in-menu display:block) */
174
174
  body.v3d #moreMenu #dimStyleB{display:none} /* …and the mirror: Dimension style edits the 2D dim overlay, so it has nothing to show in 3D (Grid lines… stays — a grid IS drawn in 3D) */
175
+ body.v3d #moreMenu #csSetB{display:none} /* the 2D set-local-axes (P.frame) is 2D-only… */
176
+ body:not(.v3d) #moreMenu #csArm3dB,body:not(.v3d) #moreMenu #csF3dFields{display:none} /* …and the 3D local frame is 3D-only */
177
+ #moreMenu #csArm3dB.on{border-color:var(--brand);color:var(--brand)}
178
+ #csF3dFields{display:none;grid-template-columns:auto 1fr;gap:4px 7px;align-items:center;margin:6px 2px 2px} /* base hide as a RULE (not inline) so #csF3dFields.on can override it — an inline display:none can't be beaten by a class (Codex) */
179
+ #csF3dFields.on{display:grid}
180
+ #csF3dFields .csf3lab{font:12px system-ui;color:var(--mut)}
181
+ #csF3dFields .csf3val{font:12px system-ui;color:var(--text);padding:0 2px;min-height:26px;display:flex;align-items:center} /* read-only orientation readout — a label/value row, never a disabled input (orientation is set by the pick + ring, not typed) */
182
+ #csF3dFields input{width:100%;height:26px;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:5px;padding:0 7px;font:12px system-ui}
183
+ #csF3dFields input:focus{outline:none;border-color:var(--brand)}
175
184
  #moreMenu button.msnap,#moreMenu button.dtog{display:flex;align-items:center;gap:0} /* .dtog = the Display show/hide toggles, same slider switch as Snapping (.msnap) */
176
185
  #moreMenu button.msnap.on,#moreMenu button.dtog.on{color:var(--text)} /* the switch carries the state — don't also brand the text (reads as an armed tool elsewhere in this menu) */
177
186
  #moreMenu .mck,.cmmenu .mck,.m3dmenu .mck{position:relative;width:26px;height:14px;margin-right:9px;border-radius:7px;border:1px solid var(--line);background:#0b1220;flex:none;transition:background-color .15s,border-color .15s} /* delicate CSS-only slider switch — shared by the ⋯ Snapping rows, the Move/Copy → Drag-to-move/copy toggle, and the Work-area toggles */
@@ -761,6 +770,13 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
761
770
  <button class=msec-hdr data-sec=coords aria-expanded=false data-tip="Local vs global drawing axes (for skewed framing)">Coordinate system<span class=chev aria-hidden=true>▸</span></button>
762
771
  <div class=msec-body>
763
772
  <button id=csSetB data-tip="Define a local X axis by clicking two points (origin, then X-direction). Y follows at 90°. Orthogonal drawing and X/Y dimensions then snap to this frame — for skewed framing.">↺ Set local axes…</button>
773
+ <button id=csArm3dB data-tip="Set the local drawing frame (3D): click 3 points — origin, X-direction, then a point on the Y side (which also sets which way Z points). Then drag the amber origin or the cyan ring to refine.">↺ Set local axes (3D)…</button>
774
+ <div id=csF3dFields>
775
+ <label class=csf3lab>Orientation</label><span id=csF3dOri class=csf3val data-tip="Set by the 3-click pick; spin it with the cyan ring. Re-pick to change the tilt.">—</span>
776
+ <label class=csf3lab>Origin X (ft)</label><input id=csF3dX type=number step=0.1 inputmode=decimal autocomplete=off>
777
+ <label class=csf3lab>Origin Y (ft)</label><input id=csF3dY type=number step=0.1 inputmode=decimal autocomplete=off>
778
+ <label class=csf3lab>Origin Z (ft)</label><input id=csF3dZ type=number step=0.1 inputmode=decimal autocomplete=off>
779
+ </div>
764
780
  <button id=csResetB data-tip="Return to the global X/Y axes (default)" disabled>Reset to global axes</button>
765
781
  </div>
766
782
  <button class=msec-hdr data-sec=session aria-expanded=false data-tip="Reload from the server, or export the data">Session<span class=chev aria-hidden=true>▸</span></button>
@@ -2314,6 +2330,22 @@ function panel(){
2314
2330
  if(gridMode){renderGridPanel(p);return;}
2315
2331
  if(dimStyleMode&&(selIds.size||selDimIds.size))dimStyleMode=false; // anything that selects (Ctrl+A, Duplicates, Reversed beams, a legend/RFI locate…) takes the panel back from the style pane — one guard instead of a disarm call at every such command
2316
2332
  if(dimStyleMode){renderDimStylePanel(p);return;}
2333
+ if(view3d&&window.Steel3DView&&window.Steel3DView.frameArmed&&window.Steel3DView.frameArmed()){ // 3D local-frame armed → the panel-takeover idiom (badge + hint), like the 2D Set-local-axes / Dimension tools
2334
+ const _d3=window.Steel3DView,_step=(_d3.framePicking&&_d3.framePicking())?(_d3.framePickStep?_d3.framePickStep():0):null;
2335
+ if(_step!==null){ // collecting the 3-click set → step prompt
2336
+ const _pr=['Click the <b>origin</b> — snaps freely to member ends, grid points, or any geometry. <b>Esc</b> cancels.',
2337
+ 'Click a second point to set local <b>X</b> — the axis runs from the origin toward it. <b>Esc</b> cancels.',
2338
+ 'Click a third point on the <b>Y side</b>. This also sets which way <b>Z</b> points — click the other side of X to flip it. <b>Esc</b> cancels.'];
2339
+ p.innerHTML=`<span class=badge>Set local axes (3D)</span>
2340
+ <div class=hint style="margin-top:8px">${_pr[_step]||_pr[0]}</div>
2341
+ <div class=hint style="margin-top:8px">Three points define a full 3D frame — it re-aims the drawing tools; nothing in the model moves.</div>`;
2342
+ return;}
2343
+ p.innerHTML=`<span class=badge>Local axes (3D)</span>
2344
+ <div class=hint style="margin-top:8px">Local axes set. Drag the <b>amber origin</b> to move it, or the <b>cyan ring</b> to spin it. <b>Esc</b> exits.</div>
2345
+ <div class=hint style="margin-top:8px">Only re-aims the drawing tools (ortho, Move/Copy, Add) — nothing in the model moves.</div>
2346
+ <button id=csRepickB class=ghostw style="margin-top:10px" data-tip="Re-run the 3-click pick to change the origin, axes or tilt">↺ Re-pick…</button>`;
2347
+ const _rb=document.getElementById('csRepickB');if(_rb)_rb.onclick=()=>{if(_d3.repickFrame3d)_d3.repickFrame3d();};
2348
+ return;}
2317
2349
  if(csaxisMode){p.innerHTML=`<span class=badge>Set local axes</span>
2318
2350
  <div class=hint id=csHint style="margin-top:8px">${csDraft?'Click the <b>second</b> point — the local-X direction. Y follows at 90°.':'Click the <b>origin</b> point to start.'}</div>
2319
2351
  <div class=hint style="margin-top:8px">Two clicks define the frame; snaps to member ends &amp; grid (<b>Alt</b> off). <b>Esc</b> cancels.</div>`;return;}
@@ -3430,7 +3462,7 @@ function disarmCm(){cmTool=null;cmArrayMode=false;cmDraft=null;cmHudClose();cmPr
3430
3462
  if(window.Steel3DView&&window.Steel3DView.cmClear3d)window.Steel3DView.cmClear3d();} // drop the 3D-side pick/preview too
3431
3463
  function armCm(tool,array){ // re-arming the same config toggles the tool off — works in 2D and (on the working plane) in 3D
3432
3464
  if(cmTool===tool&&cmArrayMode===!!array){disarmCm();render();return;}
3433
- if(view3d&&window.Steel3DView){const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))window.Steel3DView.toggleDimTool();} // the 3D dim tool shares the left-click — disarm it
3465
+ if(view3d&&window.Steel3DView){const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))window.Steel3DView.toggleDimTool();if(window.Steel3DView.disarmFrame3d)window.Steel3DView.disarmFrame3d();} // the 3D dim tool + the local frame share the left-click — disarm both
3434
3466
  if(!selIds.size){toast('Select members first, then '+(tool==='move'?'Move':'Copy'));return;}
3435
3467
  if(mode==='add'){mode='sel';setMode();if(window.Steel3DView&&window.Steel3DView.drClear3d)window.Steel3DView.drClear3d();}
3436
3468
  if(dimMode){dimMode=false;setDimMode();}
@@ -3658,9 +3690,17 @@ function axisGlyphSvg(o,dir,preview){
3658
3690
  +`<circle cx="${ox}" cy="${oy}" r="${4/zoom}" fill="#3b82f6" stroke="#e2e8f0" stroke-width="${1.5/zoom}"/>`
3659
3691
  +tag(lx,'#ef4444','X')+tag(ly,'#22c55e','Y')+`</g>`;}
3660
3692
  // header chip + the More-menu "Reset to global" enabled state — reflect the current frame.
3661
- function updCS(){const s=document.getElementById('csStat');
3662
- if(s){const f=P&&P.frame;s.innerHTML='Axes <b>'+(f?(Math.round(Math.atan2(f.u[1],f.u[0])*180/Math.PI)+'° local'):'Global')+'</b>';s.classList.toggle('local',!!f);s.dataset.tip=f?'Local coordinate frame active — ortho draw & X/Y dimensions follow it. Reset via the ⋯ menu.':'Global axes (default). Set a local frame from the ⋯ menu for skewed framing.';}
3663
- const r=document.getElementById('csResetB');if(r)r.disabled=!(P&&P.frame);}
3693
+ function updCS(){const s=document.getElementById('csStat');const r=document.getElementById('csResetB');
3694
+ if(view3d&&window.Steel3DView&&window.Steel3DView.frameInfo){ // 3D → the local drawing frame (◇ Plane shadows it)
3695
+ const fi=window.Steel3DView.frameInfo(),local=fi.mode==='local',plane=fi.mode==='plane';
3696
+ const desc=plane?'Plane':(local?((fi.horizontal?Math.round(fi.angleDeg)+'°':'tilted')+' local (3D)'):'Global'); // a tilt can't be one number → the word "tilted" (numeric tilt lives in the panel/tooltip)
3697
+ if(s){s.innerHTML='Axes <b>'+desc+'</b>';s.classList.toggle('local',local||plane);
3698
+ s.dataset.tip=local?(fi.horizontal?'Local axes active (3D) — drag the amber origin / cyan ring, or re-pick from the ⋯ menu to change them. Click to reset to global.':'Local axes active (3D), tilted out of horizontal — drag the amber origin / cyan ring to spin them in place, or re-pick from the ⋯ menu to change the tilt. Click to reset to global.'):(plane?'A working plane (◇ Plane) is set — it drives the axes. Click to clear it.':'Global axes (default). Set local axes (3D) from the ⋯ menu for skewed framing.');}
3699
+ if(r)r.disabled=!local;return;
3700
+ }
3701
+ const f=P&&P.frame;
3702
+ if(s){s.innerHTML='Axes <b>'+(f?(Math.round(Math.atan2(f.u[1],f.u[0])*180/Math.PI)+'° local'):'Global')+'</b>';s.classList.toggle('local',!!f);s.dataset.tip=f?'Local axes active — ortho draw & X/Y dimensions follow them. Click to reset to global.':'Global axes (default). Set local axes from the ⋯ menu for skewed framing.';}
3703
+ if(r)r.disabled=!(P&&P.frame);}
3664
3704
  // themed transient toast (baseline tokens — never a native alert)
3665
3705
  function toast(msg){let t=document.getElementById('toast');
3666
3706
  if(!t){t=document.createElement('div');t.id='toast';t.style.cssText='position:fixed;left:50%;bottom:18px;transform:translateX(-50%);background:var(--panel);color:var(--text);border:1px solid var(--line);border-radius:8px;padding:8px 14px;box-shadow:0 6px 20px rgba(0,0,0,.5);z-index:60;font:13px system-ui;opacity:0;transition:opacity .2s;pointer-events:none';document.body.appendChild(t);}
@@ -3894,11 +3934,38 @@ function setMode(){document.body.classList.toggle('add',mode==='add');document.g
3894
3934
  picking=false;pickKind='profile';pickEnd=null; // a pick armed in one mode must never bleed into the other (an inspector ⌖ pick would otherwise show the Add panel's button pre-armed)
3895
3935
  if(mode!=='add'){drawDraft=null;drawPrevClear();}} // leaving Add-member drops any in-progress start point + its preview
3896
3936
  document.getElementById('mAdd').onclick=()=>{if(dimMode){dimMode=false;setDimMode();}if(csaxisMode){csaxisMode=false;setCsMode();}if(cmTool)disarmCm();
3897
- if(view3d&&window.Steel3DView){const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))window.Steel3DView.toggleDimTool();} // the 3D dim tool shares the left-click — disarm it when entering add mode
3937
+ if(view3d&&window.Steel3DView){const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))window.Steel3DView.toggleDimTool();if(window.Steel3DView.disarmFrame3d)window.Steel3DView.disarmFrame3d();} // the 3D dim tool + the local frame share the left-click — disarm both when entering add mode
3898
3938
  selDimIds.clear();dimStyleMode=false;mode=(mode==='add'?'sel':'add');if(mode==='add')selIds.clear();else if(window.Steel3DView&&window.Steel3DView.drClear3d)window.Steel3DView.drClear3d();snapOnlyClear2d();setMode();render();setLastCmd('Add member',()=>{if(mode!=='add'){if(dimMode){dimMode=false;setDimMode();}mode='add';selIds.clear();setMode();render();}});}; // entering add/sel disarms the Dimension + set-axes tools + the Dimension style pane + drops any dim selection + reverts a snap override; leaving add clears the 3D draw draft
3899
3939
  document.getElementById('dimB').onclick=()=>{if(csaxisMode){csaxisMode=false;setCsMode();}dimMode=!dimMode;setDimMode();render();setLastCmd('Dimension',()=>{if(!dimMode){dimMode=true;setDimMode();render();}});};
3900
3940
  document.getElementById('csSetB').onclick=()=>{csaxisMode=!csaxisMode;setCsMode();render();};
3901
- document.getElementById('csResetB').onclick=()=>{resetFrame();render();};
3941
+ document.getElementById('csResetB').onclick=()=>{ if(view3d&&window.Steel3DView&&window.Steel3DView.clearFrame3d){window.Steel3DView.clearFrame3d();csSyncF3d();updCS();} else {resetFrame();render();} };
3942
+ document.getElementById('csStat').onclick=()=>{ // click the Axes chip → reset to global (easy exit; mirrors ⋯ "Reset to global axes", and clears a set ◇ Plane)
3943
+ if(view3d&&window.Steel3DView){const d3=window.Steel3DView,fi=d3.frameInfo&&d3.frameInfo();
3944
+ if(fi&&fi.mode==='plane'){if(d3.clearWorkPlane)d3.clearWorkPlane();}
3945
+ else if(fi&&fi.mode==='local'){if(d3.clearFrame3d)d3.clearFrame3d();}
3946
+ else return; // already global → nothing to reset
3947
+ if(typeof csSyncF3d==='function')csSyncF3d();updCS();}
3948
+ else if(P&&P.frame){resetFrame();render();}};
3949
+ // 3D local drawing frame (UCS): arm the 3-click pick / drag-refine + read-only orientation + editable origin
3950
+ let csPrevPick=null; // prior pick step (0/1/2|null) — so #panel re-renders on each pick step + on commit, but NOT on every drag tick
3951
+ function csSyncF3d(){const d3=window.Steel3DView;if(!d3||!d3.frameInfo)return;
3952
+ const fi=d3.frameInfo(),armed=!!(d3.frameArmed&&d3.frameArmed()),armB=document.getElementById('csArm3dB'),fields=document.getElementById('csF3dFields');
3953
+ const pick=(d3.framePicking&&d3.framePicking())?(d3.framePickStep?d3.framePickStep():0):null, pickChanged=pick!==csPrevPick; csPrevPick=pick;
3954
+ const wasArmed=armB?armB.classList.contains('on'):false; // arm/disarm edge — take over / release #panel only on the transition (+ pick-step changes), not on every drag tick
3955
+ if(armB)armB.classList.toggle('on',armed);if(fields)fields.classList.toggle('on',armed);
3956
+ if(armed){const FT=304.8,set=(id,v)=>{const el=document.getElementById(id);if(el&&document.activeElement!==el)el.value=v;};
3957
+ const ori=document.getElementById('csF3dOri');
3958
+ if(fi.mode==='local'){
3959
+ if(ori)ori.textContent=fi.horizontal?(Math.round(fi.angleDeg)+'°'+(fi.zUp?'':' · Z down')):('Tilted '+Math.round(fi.tiltDeg)+'° · Z '+(fi.zUp?'up':'down')); // read-only: set by the pick, spun by the ring; note a flipped-Z horizontal frame (Codex)
3960
+ set('csF3dX',(fi.origin[0]/FT).toFixed(2));set('csF3dY',(fi.origin[1]/FT).toFixed(2));set('csF3dZ',(fi.origin[2]/FT).toFixed(2));}
3961
+ else if(ori)ori.textContent='—';}
3962
+ if((wasArmed!==armed||pickChanged)&&typeof panel==='function')panel();} // arm/disarm edge OR a pick-step change → repaint #panel (drag ticks don't, so no per-move rebuild)
3963
+ document.getElementById('csArm3dB').onclick=()=>{const d3=window.Steel3DView;if(!d3||!d3.armFrame3d)return;const armed=!!(d3.frameArmed&&d3.frameArmed());d3.armFrame3d(!armed);csSyncF3d();updCS();};
3964
+ ['csF3dX','csF3dY','csF3dZ'].forEach(id=>{const el=document.getElementById(id);if(!el)return; // Origin X/Y/Z stay editable (translate-only); orientation is read-only (pick + ring)
3965
+ el.addEventListener('input',()=>{const d3=window.Steel3DView;if(!d3)return;const FT=304.8;
3966
+ const fi=d3.frameInfo(),o=fi.origin?[...fi.origin]:[0,0,0],x=parseFloat(document.getElementById('csF3dX').value)*FT,y=parseFloat(document.getElementById('csF3dY').value)*FT,z=parseFloat(document.getElementById('csF3dZ').value)*FT;
3967
+ d3.setFrameOrigin([isNaN(x)?o[0]:x,isNaN(y)?o[1]:y,isNaN(z)?o[2]:z]);
3968
+ updCS();});});
3902
3969
  function updDimToggle(){const b=document.getElementById('dimToggleB');if(b){b.classList.toggle('on',dimsVisible);b.setAttribute('aria-checked',String(dimsVisible));}}
3903
3970
  document.getElementById('dimToggleB').onclick=e=>{e.stopPropagation();dimsVisible=!dimsVisible;updDimToggle();render();};
3904
3971
  function updLenToggle(){const b=document.getElementById('lenToggleB');if(b){b.classList.toggle('on',showSelLen);b.setAttribute('aria-checked',String(showSelLen));}}
@@ -4102,6 +4169,7 @@ document.getElementById('cpLevelB').onclick=()=>openLevelModal('copy');
4102
4169
  // member Inspector can show a read-only "Cope (auto)" note (a coped beam otherwise looks like an error).
4103
4170
  let copesByMember={}, partsById={};
4104
4171
  const view3dApi={
4172
+ onFrame3dChange:()=>{updCS();if(typeof csSyncF3d==='function')csSyncF3d();}, // the 3D local frame moved/armed/reset → resync the Axes chip + the numeric fields
4105
4173
  // POST the in-progress contract so the model reflects unsaved edits; throws on a bad contract.
4106
4174
  fetchScene:async()=>{const r=await fetch('/api/contract/'+encodeURIComponent(APP_ID)+'/scene',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({contract:C})});const j=await r.json();if(!j.ok)throw new Error(j.error||'scene render failed');
4107
4175
  // The bake reports everything it could NOT emit in `skipped[]`, and we used to discard it entirely — so a
@@ -5457,6 +5525,7 @@ async function setView(on){
5457
5525
  if(!view3dReady){window.Steel3DView.init(document.getElementById('stage3d'),view3dApi);view3dReady=true;}
5458
5526
  applyViewState(true);
5459
5527
  window.Steel3DView.show();
5528
+ updCS();if(typeof csSyncF3d==='function')csSyncF3d(); // reflect the (persisted) 3D local frame in the Axes chip IMMEDIATELY — before the awaited rebuild, else the chip shows a stale "Global" for the rebuild's duration (QA F14)
5460
5529
  await window.Steel3DView.rebuild(true); // fit the camera on entering 3D
5461
5530
  window.Steel3DView.setSelection(selIds);
5462
5531
  wire3DBar();wireLegendTabs();loadSteelFavourites();build3DLegend();showLegendPanel(); // build the Objects body + load the (global) favourites library, then open the panel on the last-used tab
@@ -5471,6 +5540,7 @@ async function setView(on){
5471
5540
  if(propPopOpen()){if(propPopPinned){dockPropPop();renderPropPop();}else closePropPop(true);} // the popup is anchored to one canvas — re-dock if pinned (renderPropPop re-syncs its "Show in this view" checkbox to the now-live view), else dismiss on the view switch
5472
5541
  panel(); // repaint the inspector for the NOW-current view (view3d is final here): a cross-view tool stays armed but its in-progress draft was dropped above — Add-member's drawHint (:2288) and Move/Copy's cmHint are view-specific, so without this the panel keeps the stale 2D "Click 2: end" (drawDraft already null) instead of the 3D working-plane hint (and vice-versa on return)
5473
5542
  refreshPropLabels3d();updatePropHint(); // push the label set to whichever view is now live (3D shows them; 2D hides the 3D host) + refresh the corner note
5543
+ updCS();if(typeof csSyncF3d==='function')csSyncF3d(); // the Axes chip is view-scoped (2D=P.frame, 3D=frame3d) — resync it + the 3D-frame fields on every switch (applyViewState alone doesn't; Codex MAJOR 6)
5474
5544
  }
5475
5545
  document.getElementById('vt2d').onclick=()=>{if(view3d)setView(false);};
5476
5546
  document.getElementById('vt3d').onclick=()=>{if(!view3d)setView(true);};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.90.2",
3
+ "version": "0.91.0",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {