@floless/app 0.133.2 → 0.134.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 +116 -32
- package/dist/web/app.css +65 -0
- package/dist/web/app.js +32 -0
- package/dist/web/aware.js +243 -7
- package/dist/web/commands-shell.js +32 -0
- package/dist/web/commands-steel.js +22 -0
- package/dist/web/index.html +13 -0
- package/dist/web/instructor.js +1 -1
- package/dist/web/steel-3d-core.js +87 -0
- package/dist/web/steel-3d-view.js +363 -6
- package/dist/web/steel-editor.html +179 -19
- package/dist/web/workspaces.js +186 -13
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ import { RoomEnvironment } from 'three/addons/RoomEnvironment.js';
|
|
|
20
20
|
import { surfaceTextures, applyTriplanar, TILE_MM, DIRECTIONAL } from './steel-materials.js';
|
|
21
21
|
import { canvasToolGuidanceState } from './steel-canvas-guidance.js';
|
|
22
22
|
import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
|
|
23
|
-
import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, sectionKindOf, sectionTopology, memberMeshAxes, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
|
|
23
|
+
import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, sectionKindOf, sectionTopology, memberMeshAxes, positionSwingDelta, snapToStep, rollCommitNorm, unwrapAngleStep, POSITION_OFFSET_SNAP_MM, POSITION_ROT_SNAP_DEG, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
|
|
24
24
|
// `gridGeometry`, `gridCandidates3d` and `mmPerPx` live behind the host's model read boundary because
|
|
25
25
|
// their display-scale argument is meaningless on a world-mm model grid.
|
|
26
26
|
import { visibleGridLevels, gridTransientScopeSignature, reconcileGridTransientState, objectSelectionStatus } from './grid-core.js';
|
|
@@ -427,6 +427,7 @@ function loop() {
|
|
|
427
427
|
sizeEndpoints();
|
|
428
428
|
sizeClipHandles();
|
|
429
429
|
sizeFrameHandle();
|
|
430
|
+
sizePositionGizmo();
|
|
430
431
|
sizeGridLabels();
|
|
431
432
|
positionDimLabels();
|
|
432
433
|
positionOverlayLabels();
|
|
@@ -998,6 +999,7 @@ function buildFromScene(sc) {
|
|
|
998
999
|
// (computeOverlayDims scopes the plate path to group 'shear-plate' — base/washer plates are skipped there.)
|
|
999
1000
|
dimParts = (sc.elements || []).filter((el) => el && (el.kind === 'plate' || el.kind === 'cut'));
|
|
1000
1001
|
renderClipGizmo(); // re-anchor the selected clip's gizmo to the (possibly new) sceneBox after a rebuild
|
|
1002
|
+
syncGizmoVisibility(); // re-anchor the Profile Position gizmo (the rebuild replaced its member's mesh); (un)hide the frame gizmo if availability changed
|
|
1001
1003
|
buildGrid(box);
|
|
1002
1004
|
// Reconcile mesh visibility BEFORE the structural grid: mixed member+grid isolation needs the
|
|
1003
1005
|
// grid reconciler to see the surviving mesh count, otherwise deleting the last isolated member
|
|
@@ -4366,6 +4368,16 @@ function onKey(e) {
|
|
|
4366
4368
|
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
|
|
4367
4369
|
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
|
|
4368
4370
|
if (frameMode && e.key === 'Escape' && !pending) { e.preventDefault(); disarmFrame3d(); return; } // armed but idle (frame set, gizmo grabbable for refine) → Esc exits the "Set local axes" tool (the frame stays; it just stops being editable). `!pending` so a mid-gesture Esc (member move / endpoint stretch, reachable while the tool is armed) still falls through to the cancel-and-revert below instead of silently committing (code-review) (frame set, gizmo grabbable for refine) → Esc exits the "Set local axes" tool (the frame stays; it just stops being editable). `!pending` so a mid-gesture Esc (member move / endpoint stretch, reachable while the tool is armed) still falls through to the cancel-and-revert below instead of silently committing (code-review)
|
|
4371
|
+
if (pending && pending.posGizmo && e.key === 'Escape') { // Esc mid-drag → cancel a Profile Position edit; put the live-previewed steel back, no commit
|
|
4372
|
+
e.preventDefault();
|
|
4373
|
+
restorePositionGizmoMesh(pending.posGizmo);
|
|
4374
|
+
pending = dragging = null;
|
|
4375
|
+
posInteraction = 'idle'; hidePositionLeader();
|
|
4376
|
+
if (controls) controls.enabled = true;
|
|
4377
|
+
if (readout) readout.style.display = 'none';
|
|
4378
|
+
renderPositionGizmo();
|
|
4379
|
+
return;
|
|
4380
|
+
}
|
|
4369
4381
|
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)
|
|
4370
4382
|
e.preventDefault();
|
|
4371
4383
|
if (pending.mesh && pending.meshPos0) pending.mesh.position.copy(pending.meshPos0); // put a live-moved (or Alt-vertical) member mesh back
|
|
@@ -4648,6 +4660,23 @@ function reflectDimAxisBar() {
|
|
|
4648
4660
|
// teleport the camera). Replaces the old set-orbit-pivot — zoom-to sets the pivot anyway, and
|
|
4649
4661
|
// zoomToCursor already lets the wheel zoom toward the cursor.
|
|
4650
4662
|
function onDblClick(e) {
|
|
4663
|
+
// Double-click a position handle → open the docked numeric HUD to type an exact value (spec §3.1); the two
|
|
4664
|
+
// mousedowns each start a zero-movement grab that onUp restores as a no-op (no undo entry), and cancelling any
|
|
4665
|
+
// lingering `pending` here upholds the one-editable-gizmo invariant before the HUD opens. This wins over the
|
|
4666
|
+
// zoom-to-part below, which only runs past this guard.
|
|
4667
|
+
if (positionGizmoVisible && posGizmoState && !frameMode) {
|
|
4668
|
+
let ph = null; try { ph = pickPositionGizmoHandle(e.clientX, e.clientY); } catch (err) { console.error('steel-3d: position-gizmo dblclick hit-test failed', err); ph = null; } // mirror onDown's logging — a swallowed exception here would silently fall through to zoom-to-part
|
|
4669
|
+
if (ph && ph !== 'anchor') {
|
|
4670
|
+
e.preventDefault(); e.stopPropagation();
|
|
4671
|
+
if (pending && pending.posGizmo) restorePositionGizmoMesh(pending.posGizmo);
|
|
4672
|
+
pending = dragging = null; posInteraction = 'idle'; hidePositionLeader();
|
|
4673
|
+
if (controls) controls.enabled = true; // defensive: normal dblclick sequencing already re-enabled controls via onUp, but if this branch is reached abnormally and the HUD does NOT open below, never strand the camera disabled (openPositionHud → setPositionTyping(true) re-freezes it when it does open)
|
|
4674
|
+
const scr = positionGizmoHandlesScreen();
|
|
4675
|
+
const p = scr && (ph === 'depth' ? scr.depthTip : ph === 'width' ? scr.widthTip : scr.rotHandle);
|
|
4676
|
+
if (p && api && api.openPositionHud) api.openPositionHud([...selIds][0], ph, [p.x, p.y]);
|
|
4677
|
+
return;
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4651
4680
|
camera.updateMatrixWorld(); root.updateMatrixWorld(true);
|
|
4652
4681
|
const rect = canvasEl.getBoundingClientRect();
|
|
4653
4682
|
const ndc = new THREE.Vector2(((e.clientX - rect.left) / rect.width) * 2 - 1, -((e.clientY - rect.top) / rect.height) * 2 + 1);
|
|
@@ -4694,6 +4723,7 @@ function setSelection(ids) {
|
|
|
4694
4723
|
let reglow = false; for (const g of hoverGlowIds) if (!set.has(g)) { setHoverGlow(g, true, false); reglow = true; } // still-hovered, now-unselected parts keep their glow (the material swap above cleared it)
|
|
4695
4724
|
if (reglow) applyDisplayMode(); // one re-sync after re-lighting the whole set, not one per part
|
|
4696
4725
|
updateStatusChip();
|
|
4726
|
+
syncGizmoVisibility(); // the Profile Position gizmo follows the selection (single member only); (un)hides the frame gizmo to match
|
|
4697
4727
|
}
|
|
4698
4728
|
let selIds = new Set();
|
|
4699
4729
|
// Material.clone() copies parameters but NOT instance-assigned callbacks, so a cloned highlight
|
|
@@ -5535,13 +5565,14 @@ function pointEntryCommit() { pointEntryTok = null; bumpPointEntryGen(); }
|
|
|
5535
5565
|
// base/start so a stale anchor can't revalidate; soft (frame/workplane drift) keeps the world base.
|
|
5536
5566
|
function invalidatePointEntry(reason) {
|
|
5537
5567
|
const hadLive = !!pointEntryTok, hadStaged = !!(tfDraft && tfDraft.vA);
|
|
5568
|
+
const hadPosHud = posInteraction === 'typing'; // the position typed-HUD carries NO pointEntryTok, so it needs its own close/toast trigger (Codex): a rebuild/frame-change/hide must not leave it open committing against changed state with the camera frozen
|
|
5538
5569
|
bumpPointEntryGen(); pointEntryTok = null;
|
|
5539
5570
|
tfLast = null; tfLastClient = null; // drop the captured aim so a reopened {dist} demands a fresh hover under the new frame (Codex R5 #1)
|
|
5540
5571
|
const hard = reason === 'rebuild' || reason === 'undo' || reason === 'view' || reason === 'hide';
|
|
5541
5572
|
if (hard) { cmClear3d(); drClear3d(); }
|
|
5542
5573
|
else if (tfDraft && tfDraft.vA) { tfDraft.vA = null; tfPreviewClear(); } // soft drift: drop staged direction A, keep the base (geometry didn't move)
|
|
5543
|
-
if (hadLive && api && api.closeCmHud) api.closeCmHud();
|
|
5544
|
-
if (reason === 'drift' && (hadLive || hadStaged) && api && api.toast) api.toast('Frame changed — re-enter the value');
|
|
5574
|
+
if ((hadLive || hadPosHud) && api && api.closeCmHud) api.closeCmHud(); // close an open typed-entry HUD (movecopy/add token OR the tokenless position HUD → its close unfreezes the camera)
|
|
5575
|
+
if (reason === 'drift' && (hadLive || hadStaged || hadPosHud) && api && api.toast) api.toast('Frame changed — re-enter the value');
|
|
5545
5576
|
}
|
|
5546
5577
|
// A pointer base/start pick invalidates any open typed-entry token (silent — no toast): the anchor changed,
|
|
5547
5578
|
// so a stale HUD from a prior phase/operation must not commit against the new draft.
|
|
@@ -5559,7 +5590,7 @@ function frameInfo() {
|
|
|
5559
5590
|
}
|
|
5560
5591
|
return { mode: 'global' };
|
|
5561
5592
|
}
|
|
5562
|
-
function fireFrameChange() { invalidatePointEntry('drift'); if (!(pending && pending.frameDrag)) { tfCandidates = null; dimCandidates3d = null; } renderWorkPlane(); reflectDimAxisBar(); updateStatusChip(); } // re-draws the gizmo + reference plane + fires the Axes chip; relabels the dim-axis bar (X′/Y′/Elev follows the frame); invalidates the typed HUD (drift) + the snap caches so the UCS-origin snap follows the frame — but NOT during a live origin drag (the drag's own snap cache, which excludes the origin, stays efficient)
|
|
5593
|
+
function fireFrameChange() { invalidatePointEntry('drift'); if (!(pending && pending.frameDrag)) { tfCandidates = null; dimCandidates3d = null; } renderWorkPlane(); reflectDimAxisBar(); updateStatusChip(); } // re-draws the gizmo + reference plane + fires the Axes chip; relabels the dim-axis bar (X′/Y′/Elev follows the frame); invalidates the typed HUD (drift) + the snap caches so the UCS-origin snap follows the frame — but NOT during a live origin drag (the drag's own snap cache, which excludes the origin, stays efficient). renderWorkPlane now re-syncs BOTH gizmos (arming/disarming the frame flips the position gizmo's visibility; the position gizmo hides the frame gizmo), so both react in one tick.
|
|
5563
5594
|
// Set a HORIZONTAL frame at origin (numeric entry + gizmo materialize). origin defaults its Z to the active level.
|
|
5564
5595
|
function setFrame3d(originMm, angleDeg) {
|
|
5565
5596
|
const z = (originMm && originMm.length > 2) ? originMm[2] : frameZ();
|
|
@@ -5596,9 +5627,19 @@ function disarmFrame3d() { if (frameMode || framePicking()) { cancelFramePick();
|
|
|
5596
5627
|
// overlayScene (2nd unclipped pass) so a section plane never cuts it. A set ◇ Plane shadows it (its own patch shows).
|
|
5597
5628
|
let frameGizmo = null;
|
|
5598
5629
|
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; }
|
|
5630
|
+
// The two overlay gizmos never coexist as editables: the position handle sits ON the member and its blue depth /
|
|
5631
|
+
// green width read as the frame's blue/green axes, and a passive frame handle that still picks would steal a
|
|
5632
|
+
// position drag (a failure this codebase has shipped before). So each HIDES the other — draws nothing AND is not
|
|
5633
|
+
// hit-tested (structural, never opacity-0-but-still-picking). `currentPositionGizmoState()` already folds in the
|
|
5634
|
+
// toggle, single-selection, workPlane, availability and frameMode gates, so this is the single source of truth.
|
|
5635
|
+
function positionGizmoShowing() { return !!currentPositionGizmoState(); }
|
|
5636
|
+
// Re-render BOTH so a change to one (arm the frame, toggle the handle, change the selection) flips the other's
|
|
5637
|
+
// visibility in the same tick. Position first: it refreshes the `posGizmoState` cache the frame paths read.
|
|
5638
|
+
function syncGizmoVisibility() { renderPositionGizmo(); renderFrameGizmo(); }
|
|
5599
5639
|
function renderFrameGizmo() {
|
|
5600
5640
|
disposeFrameGizmo();
|
|
5601
5641
|
if (!overlayScene) return; // ALWAYS draw the gizmo (matches the reference plane); a ◇ Plane no longer removes it
|
|
5642
|
+
if (positionGizmoShowing()) return; // position gizmo is the active editable → hide the frame gizmo entirely (no draw, nothing to pick)
|
|
5602
5643
|
const on = frameMode && !workPlane; // grabbable/armed only when the LOCAL frame is the active basis (a ◇ Plane is picked, not gizmo-dragged)
|
|
5603
5644
|
const { O, u: ux, v: uy, n: uz } = refPlaneBasis(); // effective basis the tools follow: ◇ Plane > local frame > global
|
|
5604
5645
|
const u = new THREE.Vector3(...ux), v = new THREE.Vector3(...uy), n = new THREE.Vector3(...uz);
|
|
@@ -5626,11 +5667,287 @@ function sizeFrameHandle() {
|
|
|
5626
5667
|
const O = frameGizmoOrigin(), wp = new THREE.Vector3(O[0], O[1], O[2]), r = pxToWorldAt(frameMode ? 7 : 5.5, wp);
|
|
5627
5668
|
for (const h of frameGizmo.children) if (h.userData && h.userData.frameHandle === 'origin') h.scale.setScalar(r);
|
|
5628
5669
|
}
|
|
5670
|
+
|
|
5671
|
+
// ---- Profile Position gizmo (slice 3a) -----------------------------------------------------------
|
|
5672
|
+
// A Tekla-shaped handle anchored to the SELECTED member's start work point: a blue depth arrow and a
|
|
5673
|
+
// green width arrow drive the numeric offsets, a red arc about the member axis drives the roll. The
|
|
5674
|
+
// editor owns the semantics (`api.positionGizmoState` / `api.commitMemberPosition`); the view only
|
|
5675
|
+
// draws the arrows and, on a drag, reports an ABSOLUTE new value back. Lives in `overlayScene` (2nd
|
|
5676
|
+
// unclipped pass, `depthTest:false`) so a section plane never cuts it, and the whole group is scaled
|
|
5677
|
+
// screen-constant like the frame/clip handles — grabbable on a 6" stub and a 40' girder alike.
|
|
5678
|
+
let positionGizmo = null; // THREE.Group, built in LOCAL space around the anchor, positioned + scaled per frame
|
|
5679
|
+
let positionGizmoVisible = false; // the ⋯ Display-menu toggle, pushed in from the editor
|
|
5680
|
+
let posGizmoState = null; // last api.positionGizmoState() snapshot for the single selection (anchor, axes, offsets)
|
|
5681
|
+
// Explicit interaction state consulted by every position-gizmo handler (drag/dblclick/keydown), instead of
|
|
5682
|
+
// trusting focus + stopPropagation (Fable 5 review): 'idle' | 'dragging' | 'typing'. 'typing' = the docked
|
|
5683
|
+
// numeric HUD is open (camera frozen); handlers that must not fire while typing check this and bail.
|
|
5684
|
+
let posInteraction = 'idle';
|
|
5685
|
+
let posHovered = false; // a position handle is under the cursor (drives the shared-#tooltip hide on leave)
|
|
5686
|
+
let positionLeader = null; // cyan #22d3ee rubber-band line: amber anchor → live drag point, shown for a whole drag
|
|
5687
|
+
const POS_GIZMO_REACH_PX = 132; // screen-constant arrow reach (spec §3)
|
|
5688
|
+
// Per-handle hover copy — leads with the consequence (spec §3) + the double-click-to-type hint (3b.3). Shown
|
|
5689
|
+
// through the shared themed #tooltip (api.showHandleTip), never a native title=.
|
|
5690
|
+
const POS_HANDLE_TIP = {
|
|
5691
|
+
depth: 'Slides the section along its depth axis. Drag, or double-click to type an exact value — ¼" snap; hold Shift for no snap.',
|
|
5692
|
+
width: 'Slides the section along its width axis. Drag, or double-click to type an exact value — ¼" snap; hold Shift for no snap.',
|
|
5693
|
+
rot: 'Rolls the section about the reference line. Drag, or double-click to type an exact angle — 5° snap; hold Shift for no snap.',
|
|
5694
|
+
anchor: 'Reference-line start — the profile pivots here. This point never moves.',
|
|
5695
|
+
};
|
|
5696
|
+
function disposePositionGizmo() {
|
|
5697
|
+
hidePositionLeader(); // the transient drag leader never outlives a gizmo rebuild
|
|
5698
|
+
if (!positionGizmo) return;
|
|
5699
|
+
if (overlayScene) overlayScene.remove(positionGizmo);
|
|
5700
|
+
positionGizmo.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); });
|
|
5701
|
+
positionGizmo = null;
|
|
5702
|
+
}
|
|
5703
|
+
// The gizmo shows only when the toggle is on, exactly one member is selected, we are not in a work-plane
|
|
5704
|
+
// pick, and the editor reports the member as available (resolvable frame + offsets). Otherwise → null.
|
|
5705
|
+
function currentPositionGizmoState() {
|
|
5706
|
+
// frameMode hides the position gizmo: while the user is editing the coordinate system, the position handles
|
|
5707
|
+
// (and their per-frame-mutating roll digits) are noise and another hit-steal target — one editable gizmo at a
|
|
5708
|
+
// time (Fable 5). The reverse (position gizmo hides the frame gizmo) is enforced in renderFrameGizmo.
|
|
5709
|
+
if (!positionGizmoVisible || !api || !api.positionGizmoState || !overlayScene || workPlane || frameMode) return null;
|
|
5710
|
+
if (selIds.size !== 1) return null;
|
|
5711
|
+
const st = api.positionGizmoState([...selIds][0]);
|
|
5712
|
+
if (st && st.available) return st;
|
|
5713
|
+
// The editor computed a specific reason (incomplete work points, unresolvable basis, no frame). The
|
|
5714
|
+
// handle is deliberately not drawn, but log the reason so a "handle won't show" report is diagnosable
|
|
5715
|
+
// rather than an inert toggle with no tell. code-review: silent-failure #2.
|
|
5716
|
+
if (st && st.reason) console.debug('steel-3d: Profile Position handle hidden —', st.reason);
|
|
5717
|
+
return null;
|
|
5718
|
+
}
|
|
5719
|
+
function renderPositionGizmo() {
|
|
5720
|
+
disposePositionGizmo();
|
|
5721
|
+
const st = currentPositionGizmoState(); posGizmoState = st;
|
|
5722
|
+
if (!st) return;
|
|
5723
|
+
const g = new THREE.Group();
|
|
5724
|
+
const V = (a) => new THREE.Vector3(a[0], a[1], a[2]);
|
|
5725
|
+
const yv = V(st.yAxis), zv = V(st.zAxis);
|
|
5726
|
+
// Built in LOCAL space with the anchor at (0,0,0): the group carries no rotation, so local coords ARE
|
|
5727
|
+
// world offsets from the anchor, and scaling the whole group keeps every part screen-constant.
|
|
5728
|
+
const arrow = (dirArr, col, tag) => {
|
|
5729
|
+
const d = V(dirArr).normalize();
|
|
5730
|
+
const line = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(0, 0, 0), d.clone().multiplyScalar(1)]),
|
|
5731
|
+
new THREE.LineBasicMaterial({ color: col }));
|
|
5732
|
+
line.material.depthTest = false; line.renderOrder = 997; line.userData = { posHandle: tag, stem: true }; g.add(line);
|
|
5733
|
+
const cone = new THREE.Mesh(new THREE.ConeGeometry(0.13, 0.36, 16), new THREE.MeshBasicMaterial({ color: col }));
|
|
5734
|
+
cone.material.depthTest = false; cone.renderOrder = 998; cone.quaternion.setFromUnitVectors(_YA, d);
|
|
5735
|
+
cone.position.copy(d.clone().multiplyScalar(1)); cone.userData = { posHandle: tag, arrow: true }; g.add(cone);
|
|
5736
|
+
};
|
|
5737
|
+
// BY DESIGN the arrows point along the UNROTATED part axes (st.zAxis/st.yAxis), because a Profile
|
|
5738
|
+
// Position offset is defined on the unrotated profile (§1.3). For a rolled member (rot ≠ 0) the steel
|
|
5739
|
+
// therefore travels along the roll-swung direction, not along the arrow — the gizmo stays internally
|
|
5740
|
+
// consistent (grab arrow → offset changes by the amount dragged along it) and preview↔commit agree, but
|
|
5741
|
+
// arrow and motion diverge. Re-expressing the roll so they coincide is slice 3b; do not "fix" one half.
|
|
5742
|
+
arrow(st.zAxis, 0x3b82f6, 'depth'); // blue = depth (positionOffset)
|
|
5743
|
+
arrow(st.yAxis, 0x22c55e, 'width'); // green = width (positionHOffset)
|
|
5744
|
+
// Rotation arc (red) about the member axis, drawn in the width–depth plane over a 270° sweep so both
|
|
5745
|
+
// ends stay clear of the two arrows.
|
|
5746
|
+
const R = 0.72, pts = [];
|
|
5747
|
+
for (let i = 0; i <= 36; i++) { const p = (-0.75 + (i / 36) * 1.5) * Math.PI;
|
|
5748
|
+
pts.push(yv.clone().multiplyScalar(Math.cos(p) * R).add(zv.clone().multiplyScalar(Math.sin(p) * R))); }
|
|
5749
|
+
const arc = new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts), new THREE.LineBasicMaterial({ color: 0xef4444 }));
|
|
5750
|
+
arc.material.depthTest = false; arc.renderOrder = 997; arc.userData = { posHandle: 'rot', arc: true }; g.add(arc);
|
|
5751
|
+
// Anchor dot (amber) — the reference-line start the whole gizmo pivots on.
|
|
5752
|
+
const dot = new THREE.Mesh(new THREE.SphereGeometry(0.08, 12, 8), new THREE.MeshBasicMaterial({ color: 0xf59e0b }));
|
|
5753
|
+
dot.material.depthTest = false; dot.renderOrder = 999; dot.userData = { posHandle: 'anchor' }; g.add(dot);
|
|
5754
|
+
g.position.set(st.anchor[0], st.anchor[1], st.anchor[2]);
|
|
5755
|
+
positionGizmo = g; overlayScene.add(g); sizePositionGizmo();
|
|
5756
|
+
}
|
|
5757
|
+
// Cyan #22d3ee rubber-band leader from the amber anchor to the live drag point — the "offsetting from a fixed
|
|
5758
|
+
// point" signal. #22d3ee already ships as the frame-gizmo rotation ring + the cmHud selected-segment accent, so
|
|
5759
|
+
// it is in-palette (blessed by the ui-ux pass). Lives in the overlay scene, depthTest:false, above the arrows.
|
|
5760
|
+
function updatePositionLeader(tipWorld) {
|
|
5761
|
+
if (!overlayScene || !posGizmoState) return;
|
|
5762
|
+
const O = posGizmoState.anchor, pts = [new THREE.Vector3(O[0], O[1], O[2]), new THREE.Vector3(tipWorld[0], tipWorld[1], tipWorld[2])];
|
|
5763
|
+
if (!positionLeader) {
|
|
5764
|
+
positionLeader = new THREE.Line(new THREE.BufferGeometry().setFromPoints(pts), new THREE.LineBasicMaterial({ color: 0x22d3ee, transparent: true, opacity: 0.9 }));
|
|
5765
|
+
positionLeader.material.depthTest = false; positionLeader.renderOrder = 996; overlayScene.add(positionLeader);
|
|
5766
|
+
} else { positionLeader.geometry.setFromPoints(pts); positionLeader.geometry.computeBoundingSphere && positionLeader.geometry.computeBoundingSphere(); }
|
|
5767
|
+
positionLeader.visible = true;
|
|
5768
|
+
}
|
|
5769
|
+
function hidePositionLeader() { if (positionLeader) positionLeader.visible = false; }
|
|
5770
|
+
function disposePositionLeader() {
|
|
5771
|
+
if (!positionLeader) return;
|
|
5772
|
+
if (overlayScene) overlayScene.remove(positionLeader);
|
|
5773
|
+
if (positionLeader.geometry) positionLeader.geometry.dispose(); if (positionLeader.material) positionLeader.material.dispose();
|
|
5774
|
+
positionLeader = null;
|
|
5775
|
+
}
|
|
5776
|
+
// Screen-constant: scale the whole group so a unit-length arrow spans POS_GIZMO_REACH_PX at the anchor.
|
|
5777
|
+
function sizePositionGizmo() {
|
|
5778
|
+
if (!positionGizmo || !posGizmoState) return;
|
|
5779
|
+
const O = posGizmoState.anchor;
|
|
5780
|
+
positionGizmo.scale.setScalar(pxToWorldAt(POS_GIZMO_REACH_PX, new THREE.Vector3(O[0], O[1], O[2])));
|
|
5781
|
+
}
|
|
5782
|
+
// The gizmo's grab points in client px, for an E2E to drive precise drags (mirrors frameHandlesScreen).
|
|
5783
|
+
function positionGizmoHandlesScreen() {
|
|
5784
|
+
if (!canvasEl || !posGizmoState) return null;
|
|
5785
|
+
camera.updateMatrixWorld();
|
|
5786
|
+
const rect = canvasEl.getBoundingClientRect(), O = posGizmoState.anchor;
|
|
5787
|
+
const sc = pxToWorldAt(POS_GIZMO_REACH_PX, new THREE.Vector3(O[0], O[1], O[2]));
|
|
5788
|
+
const toS = (p) => { const w = new THREE.Vector3(p[0], p[1], p[2]).project(camera);
|
|
5789
|
+
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 }; };
|
|
5790
|
+
const at = (ax, k) => toS([O[0] + ax[0] * sc * k, O[1] + ax[1] * sc * k, O[2] + ax[2] * sc * k]);
|
|
5791
|
+
const rotArr = [posGizmoState.yAxis[0] * 0.51 + posGizmoState.zAxis[0] * 0.51,
|
|
5792
|
+
posGizmoState.yAxis[1] * 0.51 + posGizmoState.zAxis[1] * 0.51,
|
|
5793
|
+
posGizmoState.yAxis[2] * 0.51 + posGizmoState.zAxis[2] * 0.51];
|
|
5794
|
+
return { anchor: toS(O), depthTip: at(posGizmoState.zAxis, 1), widthTip: at(posGizmoState.yAxis, 1), rotHandle: at(rotArr, 1), available: true };
|
|
5795
|
+
}
|
|
5796
|
+
function setPositionGizmoVisible(on) { positionGizmoVisible = !!on; syncGizmoVisibility(); } // ⋯ Display toggle → editor pushes the flag (also (un)hides the frame gizmo)
|
|
5797
|
+
// The editor's docked numeric HUD is open on a handle → freeze the camera so orbit/zoom can't drift the anchor
|
|
5798
|
+
// the HUD is pinned to (Fable 5 trap #4), and mark the explicit interaction state so canvas handlers bail.
|
|
5799
|
+
function setPositionTyping(on) {
|
|
5800
|
+
posInteraction = on ? 'typing' : 'idle';
|
|
5801
|
+
if (controls) controls.enabled = !on; // idle default = orbit enabled; typing = frozen
|
|
5802
|
+
if (on) { hidePositionLeader(); posHovered = false; if (api && api.hideHandleTip) api.hideHandleTip(); }
|
|
5803
|
+
if (canvasEl) canvasEl.style.cursor = on ? 'text' : 'default';
|
|
5804
|
+
}
|
|
5805
|
+
// E2E read-only probe: a member mesh's WORLD transform, so a test can assert a gizmo drag's live preview
|
|
5806
|
+
// equals the committed rebuild (no jump on release) and that "From member" leaves the steel exactly put.
|
|
5807
|
+
function memberWorldTransform(id) {
|
|
5808
|
+
const mesh = meshById.get(id); if (!mesh) return null;
|
|
5809
|
+
mesh.updateWorldMatrix(true, false);
|
|
5810
|
+
const p = new THREE.Vector3(), q = new THREE.Quaternion(), sc = new THREE.Vector3();
|
|
5811
|
+
mesh.matrixWorld.decompose(p, q, sc);
|
|
5812
|
+
return { pos: [p.x, p.y, p.z], quat: [q.x, q.y, q.z, q.w] };
|
|
5813
|
+
}
|
|
5814
|
+
// E2E read-only probes (3b.3): is the cyan drag leader currently shown, and is the UCS frame gizmo currently
|
|
5815
|
+
// drawn? The latter proves the mutual hide (position gizmo showing → frame gizmo null → not pickable).
|
|
5816
|
+
function positionLeaderVisible() { return !!(positionLeader && positionLeader.visible); }
|
|
5817
|
+
function frameGizmoVisible() { return !!frameGizmo; }
|
|
5818
|
+
|
|
5819
|
+
// --- Profile Position gizmo: pick + drag. depth/width arrows drive the numeric offsets; the arc drives
|
|
5820
|
+
// the roll. Every gesture reports an ABSOLUTE new value to the editor on release (one undo entry).
|
|
5821
|
+
const POS_SNAP_MM = POSITION_OFFSET_SNAP_MM; // ¼" offset snap (shared with the bake helpers, in steel-3d-core)
|
|
5822
|
+
const POS_SNAP_DEG = POSITION_ROT_SNAP_DEG; // 5° rotation snap
|
|
5823
|
+
const POS_EDGE_ON_PX = 26; // below this projected axis length a drag is refused (spec §3.1)
|
|
5824
|
+
function posGizmoRay(e) {
|
|
5825
|
+
const rect = canvasEl.getBoundingClientRect();
|
|
5826
|
+
const ndc = new THREE.Vector2(((e.clientX - rect.left) / rect.width) * 2 - 1, -((e.clientY - rect.top) / rect.height) * 2 + 1);
|
|
5827
|
+
const rc = new THREE.Raycaster(); rc.setFromCamera(ndc, camera); return rc.ray;
|
|
5828
|
+
}
|
|
5829
|
+
// Signed distance (mm) along a unit axis through the anchor to the pointer ray's closest approach.
|
|
5830
|
+
function posGizmoAxisScalar(e, st, axisArr) {
|
|
5831
|
+
const ray = posGizmoRay(e);
|
|
5832
|
+
const O = new THREE.Vector3(st.anchor[0], st.anchor[1], st.anchor[2]);
|
|
5833
|
+
const u = new THREE.Vector3(axisArr[0], axisArr[1], axisArr[2]).normalize(), v = ray.direction;
|
|
5834
|
+
const w0 = new THREE.Vector3().subVectors(O, ray.origin);
|
|
5835
|
+
const b = u.dot(v), denom = 1 - b * b; // a = u·u = 1 (u is unit), c = v·v = 1 (ray dir is unit)
|
|
5836
|
+
if (Math.abs(denom) < 1e-9) return null; // ray parallel to the axis (edge-on)
|
|
5837
|
+
return (b * v.dot(w0) - u.dot(w0)) / denom; // t on the axis line, in mm
|
|
5838
|
+
}
|
|
5839
|
+
// Angle (rad) of the pointer in the member's transverse plane, measured +y → +z.
|
|
5840
|
+
function posGizmoArcAngle(e, st) {
|
|
5841
|
+
const ray = posGizmoRay(e);
|
|
5842
|
+
const O = new THREE.Vector3(st.anchor[0], st.anchor[1], st.anchor[2]);
|
|
5843
|
+
const plane = new THREE.Plane().setFromNormalAndCoplanarPoint(new THREE.Vector3(st.xAxis[0], st.xAxis[1], st.xAxis[2]).normalize(), O);
|
|
5844
|
+
const hit = new THREE.Vector3(); if (!ray.intersectPlane(plane, hit)) return null;
|
|
5845
|
+
const d = new THREE.Vector3().subVectors(hit, O);
|
|
5846
|
+
return Math.atan2(d.dot(new THREE.Vector3(st.zAxis[0], st.zAxis[1], st.zAxis[2])), d.dot(new THREE.Vector3(st.yAxis[0], st.yAxis[1], st.yAxis[2])));
|
|
5847
|
+
}
|
|
5848
|
+
function pickPositionGizmoHandle(cx, cy) {
|
|
5849
|
+
if (!positionGizmoVisible || !posGizmoState || !canvasEl) return null;
|
|
5850
|
+
const h = positionGizmoHandlesScreen(); if (!h) return null;
|
|
5851
|
+
const hit = (pt) => pt && !pt.behind && Math.hypot(pt.x - cx, pt.y - cy) <= 14;
|
|
5852
|
+
if (hit(h.depthTip)) return 'depth';
|
|
5853
|
+
if (hit(h.widthTip)) return 'width';
|
|
5854
|
+
// Arc: sample it in screen space and grab the nearest point within tolerance.
|
|
5855
|
+
const O = posGizmoState.anchor, sc = pxToWorldAt(POS_GIZMO_REACH_PX, new THREE.Vector3(O[0], O[1], O[2]));
|
|
5856
|
+
const rect = canvasEl.getBoundingClientRect(), yv = posGizmoState.yAxis, zv = posGizmoState.zAxis; let best = 12;
|
|
5857
|
+
for (let i = 0; i <= 36; i++) { const p = (-0.75 + (i / 36) * 1.5) * Math.PI, c = Math.cos(p) * 0.72, s = Math.sin(p) * 0.72;
|
|
5858
|
+
const w = new THREE.Vector3(O[0] + (yv[0] * c + zv[0] * s) * sc, O[1] + (yv[1] * c + zv[1] * s) * sc, O[2] + (yv[2] * c + zv[2] * s) * sc).project(camera);
|
|
5859
|
+
if (w.z > 1) continue; const sx = rect.left + (w.x * 0.5 + 0.5) * rect.width, sy = rect.top + (-w.y * 0.5 + 0.5) * rect.height;
|
|
5860
|
+
const dd = Math.hypot(sx - cx, sy - cy); if (dd < best) best = dd; }
|
|
5861
|
+
return best < 12 ? 'rot' : null;
|
|
5862
|
+
}
|
|
5863
|
+
function startPositionGizmoDrag(kind, e) {
|
|
5864
|
+
const id = [...selIds][0], st = api.positionGizmoState(id);
|
|
5865
|
+
// The handle was picked from the CACHED snapshot, but the base value comes from a FRESH read — if the
|
|
5866
|
+
// frame drifted in between, bail AND re-enable orbit (onDown disabled it before calling us; without this
|
|
5867
|
+
// a fall-through click on empty space would strand the camera). code-review: silent-failure #1.
|
|
5868
|
+
if (!st || !st.available) { pending = null; if (controls) controls.enabled = true; return; }
|
|
5869
|
+
const mesh = meshById.get(id);
|
|
5870
|
+
const base = kind === 'depth' ? st.positionOffset : kind === 'width' ? st.positionHOffset : st.rot;
|
|
5871
|
+
const startScalar = kind === 'rot' ? posGizmoArcAngle(e, st) : posGizmoAxisScalar(e, st, kind === 'depth' ? st.zAxis : st.yAxis);
|
|
5872
|
+
pending = { posGizmo: { id, axis: kind, state: st, base, startScalar, newVal: base,
|
|
5873
|
+
accumRad: 0, prevAng: kind === 'rot' ? startScalar : null, // rot: accumulate the arc CONTINUOUSLY (unwrapAngleStep) so a ±180° seam crossing never jumps ~2π
|
|
5874
|
+
meshPos0: mesh ? mesh.position.clone() : null, meshQuat0: mesh ? mesh.quaternion.clone() : null } };
|
|
5875
|
+
posInteraction = 'dragging';
|
|
5876
|
+
posHovered = false; if (api && api.hideHandleTip) api.hideHandleTip(); // the hover handler is inert during a drag — clear any lingering handle tip so it doesn't sit where the readout will land
|
|
5877
|
+
downXY = [e.clientX, e.clientY];
|
|
5878
|
+
}
|
|
5879
|
+
function positionGizmoReadout(e, txt, type) {
|
|
5880
|
+
if (!readout) return;
|
|
5881
|
+
readout._dist.textContent = txt; readout._type.textContent = type;
|
|
5882
|
+
readout.style.left = (e.clientX + 14) + 'px'; readout.style.top = (e.clientY + 14) + 'px'; readout.style.display = 'block';
|
|
5883
|
+
}
|
|
5884
|
+
function restorePositionGizmoMesh(pg) {
|
|
5885
|
+
const mesh = meshById.get(pg.id); if (!mesh) return;
|
|
5886
|
+
if (pg.meshPos0) mesh.position.copy(pg.meshPos0);
|
|
5887
|
+
if (pg.meshQuat0) mesh.quaternion.copy(pg.meshQuat0);
|
|
5888
|
+
}
|
|
5889
|
+
function onMovePositionGizmo(e) {
|
|
5890
|
+
if (!dragging && Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) <= DRAG_TOL_PX) return;
|
|
5891
|
+
dragging = pending;
|
|
5892
|
+
const pg = pending.posGizmo, st = pg.state, mesh = meshById.get(pg.id);
|
|
5893
|
+
if (pg.axis === 'rot') {
|
|
5894
|
+
const ang = posGizmoArcAngle(e, st);
|
|
5895
|
+
if (ang == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in Inspect', ''); return; }
|
|
5896
|
+
if (pg.startScalar == null) { pg.startScalar = ang; pg.prevAng = ang; return; } // grab was edge-on → set the reference on the first valid hit
|
|
5897
|
+
if (pg.prevAng == null) pg.prevAng = ang;
|
|
5898
|
+
// Accumulate the arc CONTINUOUSLY (shortest-arc step per move) so dragging across the ±180° seam adds a
|
|
5899
|
+
// small increment instead of the ~2π jump a bare (ang − start) makes near the seam. The running total is
|
|
5900
|
+
// the true swept angle, so the value tracks the hand monotonically and renormalizes only on commit.
|
|
5901
|
+
pg.accumRad += unwrapAngleStep(pg.prevAng, ang); pg.prevAng = ang;
|
|
5902
|
+
// Snap the DELTA, not the absolute value: since 3b.2 the resting roll is re-expressed into the current
|
|
5903
|
+
// frame and is generically off-grid (e.g. 33.71°), so snapping the absolute would yank the steel to the
|
|
5904
|
+
// 5° grid on the very first drag tick (a jump at drag-START). Stepping the delta keeps the value at the
|
|
5905
|
+
// member's own roll when Δ=0 and moves in 5° increments from there.
|
|
5906
|
+
const rawDeltaDeg = pg.accumRad * 180 / Math.PI;
|
|
5907
|
+
const deg = pg.base + (e.shiftKey ? rawDeltaDeg : snapToStep(rawDeltaDeg, POS_SNAP_DEG));
|
|
5908
|
+
pg.newVal = deg;
|
|
5909
|
+
if (mesh && pg.meshPos0 && pg.meshQuat0) { // exact live preview: roll about the reference-line anchor
|
|
5910
|
+
const axis = new THREE.Vector3(st.xAxis[0], st.xAxis[1], st.xAxis[2]).normalize();
|
|
5911
|
+
const roll = new THREE.Quaternion().setFromAxisAngle(axis, (deg - pg.base) * Math.PI / 180);
|
|
5912
|
+
const O = new THREE.Vector3(st.anchor[0], st.anchor[1], st.anchor[2]);
|
|
5913
|
+
mesh.position.copy(pg.meshPos0.clone().sub(O).applyQuaternion(roll).add(O));
|
|
5914
|
+
mesh.quaternion.copy(roll.clone().multiply(pg.meshQuat0));
|
|
5915
|
+
}
|
|
5916
|
+
{ const O = st.anchor, R = 0.72 * pxToWorldAt(POS_GIZMO_REACH_PX, new THREE.Vector3(O[0], O[1], O[2])), c = Math.cos(ang), s2 = Math.sin(ang);
|
|
5917
|
+
updatePositionLeader([O[0] + (st.yAxis[0] * c + st.zAxis[0] * s2) * R, O[1] + (st.yAxis[1] * c + st.zAxis[1] * s2) * R, O[2] + (st.yAxis[2] * c + st.zAxis[2] * s2) * R]); }
|
|
5918
|
+
positionGizmoReadout(e, 'Rotation ' + Math.round(deg) + '°', ''); // label-first, to match the Inspect panel's "Rotation" row
|
|
5919
|
+
return;
|
|
5920
|
+
}
|
|
5921
|
+
// depth / width: refuse an edge-on axis (a foreshortened axis inflates mm-per-pixel without bound).
|
|
5922
|
+
const scr = positionGizmoHandlesScreen();
|
|
5923
|
+
const tip = scr && (pg.axis === 'depth' ? scr.depthTip : scr.widthTip);
|
|
5924
|
+
if (scr && tip && !tip.behind && Math.hypot(tip.x - scr.anchor.x, tip.y - scr.anchor.y) < POS_EDGE_ON_PX) {
|
|
5925
|
+
positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in Inspect', ''); return;
|
|
5926
|
+
}
|
|
5927
|
+
const s = posGizmoAxisScalar(e, st, pg.axis === 'depth' ? st.zAxis : st.yAxis);
|
|
5928
|
+
if (s == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in Inspect', ''); return; }
|
|
5929
|
+
if (pg.startScalar == null) { pg.startScalar = s; return; } // grab was edge-on → set the reference on the first valid hit (mirrors the rot arm)
|
|
5930
|
+
// Snap the DELTA, not the absolute (see the rot arm): a base offset need not be grid-aligned — since 3b.2
|
|
5931
|
+
// it commonly is not — so snapping the absolute would jump to the ¼" grid on the first tick. Stepping the
|
|
5932
|
+
// delta holds the value at the member's own offset when Δ=0.
|
|
5933
|
+
const rawDeltaMm = s - pg.startScalar;
|
|
5934
|
+
const val = pg.base + (e.shiftKey ? rawDeltaMm : snapToStep(rawDeltaMm, POS_SNAP_MM));
|
|
5935
|
+
pg.newVal = val;
|
|
5936
|
+
{ const O = st.anchor, ax = pg.axis === 'depth' ? st.zAxis : st.yAxis; // leader to the drag point on this axis
|
|
5937
|
+
updatePositionLeader([O[0] + ax[0] * s, O[1] + ax[1] * s, O[2] + ax[2] * s]); }
|
|
5938
|
+
if (mesh && pg.meshPos0) { // exact live preview: the SAME swing the bake uses (positionSwingDelta), so the steel never jumps on release
|
|
5939
|
+
const w = positionSwingDelta({ y: st.yAxis, z: st.zAxis }, pg.axis, val - pg.base, st.rot || 0);
|
|
5940
|
+
mesh.position.set(pg.meshPos0.x + w[0], pg.meshPos0.y + w[1], pg.meshPos0.z + w[2]);
|
|
5941
|
+
}
|
|
5942
|
+
const shownVal = api && api.fmtLen ? api.fmtLen(val) : Math.round(val) + ' mm';
|
|
5943
|
+
positionGizmoReadout(e, (pg.axis === 'depth' ? 'Depth ' : 'Width ') + shownVal, ''); // label-first + panel's own unit (fmtLen), to match the Inspect panel exactly
|
|
5944
|
+
}
|
|
5629
5945
|
// --- frame manipulator: grab + drag the gizmo's origin (translate) or ring (rotate about Z). Armed only. ---
|
|
5630
5946
|
const FRAME_RING_R = (1524 * 2 / 2) * 0.8; // ring radius (matches renderFrameGizmo's half*0.8, N=2)
|
|
5631
5947
|
function frameGizmoOrigin() { return frame3d ? frame3d.origin : [0, 0, 0]; } // Global → true global 0,0,0
|
|
5632
5948
|
function pickFrameHandle(cx, cy, allowPassive) { // → 'origin' | 'ring' | null (screen-space, like pickClipHandle). allowPassive: hit-test the un-armed (passive) gizmo too, for click-to-re-select.
|
|
5633
5949
|
if ((!frameMode && !allowPassive) || !overlayScene || workPlane || !canvasEl) return null;
|
|
5950
|
+
if (positionGizmoVisible && !frameMode && !workPlane && posGizmoState) return null; // position gizmo is showing (cheap cached check) → the frame gizmo is not drawn and must not pick (belt-and-braces vs hit-steal)
|
|
5634
5951
|
camera.updateMatrixWorld();
|
|
5635
5952
|
const rect = canvasEl.getBoundingClientRect(), px = cx - rect.left, py = cy - rect.top;
|
|
5636
5953
|
const O = frameGizmoOrigin();
|
|
@@ -5772,7 +6089,9 @@ function refPlaneBasis() {
|
|
|
5772
6089
|
return { O: frameGizmoOrigin(), u: [1, 0, 0], v: [0, 1, 0], n: [0, 0, 1] }; // Global → horizontal at 0,0,0
|
|
5773
6090
|
}
|
|
5774
6091
|
function renderWorkPlane() {
|
|
5775
|
-
|
|
6092
|
+
renderPositionGizmo(); // a ◇ Plane hides the position gizmo (currentPositionGizmoState guards workPlane): refresh it FIRST here so setting/clearing a work plane disposes the stale handle + clears posGizmoState (else it stays drawn AND pickable — Codex). Every work-plane setter and fireFrameChange routes through here, so this is the one place both gizmos re-sync.
|
|
6093
|
+
renderFrameGizmo(); // the axes+origin gizmo always draws (matches the plane; never shadowed) — reads the fresh posGizmoState above for the mutual hide
|
|
6094
|
+
|
|
5776
6095
|
if (api && api.onFrame3dChange) api.onFrame3dChange(frameInfo()); // refresh the Axes chip: "Plane" when a plane is set, back to Local/Global when cleared
|
|
5777
6096
|
if (wpGroup) { scene.remove(wpGroup); wpGroup.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); wpGroup = null; }
|
|
5778
6097
|
if (!wpVisible || !scene) return; // "Show plane" off → no reference plane (works at Global too now, not only for a ◇ Plane)
|
|
@@ -6308,6 +6627,7 @@ function dimAxisDir(axis) {
|
|
|
6308
6627
|
|
|
6309
6628
|
function onDown(e) {
|
|
6310
6629
|
if (readout) { readout.style.display = 'none'; if (readout._coord) readout._coord.style.display = 'none'; } // UCS Stage 2: hide the whole readout chip so a drag never shows a lingering coordinate (or an empty coord-only shell); the drag/next hover re-shows it
|
|
6630
|
+
if (posInteraction === 'typing') return; // the docked numeric HUD is open (camera frozen) → consume the click (start no gesture); the input blurs naturally, and its blur handler closes the HUD + toasts if anything was typed (Fable 5: explicit state, not focus)
|
|
6311
6631
|
if (e.button === 2) { rightDownXY = [e.clientX, e.clientY]; rightMoved = false; } // arm the click-vs-drag test for the snap menu
|
|
6312
6632
|
if (e.button !== 0) return; // RIGHT/MIDDLE → OrbitControls (orbit/pan)
|
|
6313
6633
|
if (wpMode === 'face') { e.stopPropagation(); const r = wpFacePick(e.clientX, e.clientY); if (r) { workPlane = r; wpMode = null; invalidatePointEntry('drift'); canvasEl.style.cursor = 'default'; renderWorkPlane(); reflectWpBar(); updateStatusChip(); if (api && api.toast) api.toast('Working plane set on the face'); } return; } // armed: one face click sets the plane
|
|
@@ -6396,6 +6716,12 @@ function onDown(e) {
|
|
|
6396
6716
|
updateStatusChip(); return;
|
|
6397
6717
|
}
|
|
6398
6718
|
downXY = [e.clientX, e.clientY];
|
|
6719
|
+
// Profile Position gizmo (slice 3a): a handle sits ON the selected member, so grab it before the
|
|
6720
|
+
// ordinary member pick/endpoint grab. Only a live handle (visible + single selection) can be hit.
|
|
6721
|
+
if (positionGizmoVisible && posGizmoState) {
|
|
6722
|
+
let pgh = null; try { pgh = pickPositionGizmoHandle(e.clientX, e.clientY); } catch (err) { console.error('steel-3d: position-gizmo hit-test failed', err); pgh = null; } // match the grid/mesh hit-test logging (no silent swallow)
|
|
6723
|
+
if (pgh) { e.stopPropagation(); controls.enabled = false; startPositionGizmoDrag(pgh, e); if (pending) return; }
|
|
6724
|
+
}
|
|
6399
6725
|
let id = null; try { id = pickAt(e.clientX, e.clientY); } catch { id = null; }
|
|
6400
6726
|
// Geometry-edit mode (Trim/Extend or Split armed in the inspector): a click does the edit, no drag.
|
|
6401
6727
|
if (geoMode() && (geoMode() === 'el' ? selIds.size >= 1 : selIds.size === 1)) { e.stopPropagation(); pending = { geo: geoMode(), selId: [...selIds][0], targetId: id }; return; } // Split: single; Extend/Trim: any selection
|
|
@@ -6662,6 +6988,7 @@ function onMove(e) {
|
|
|
6662
6988
|
if (boxSel) { onBoxMove(e); return; }
|
|
6663
6989
|
if (pending && pending.clipDrag) { onMoveClip(e); return; } // dragging a clip handle (plane offset / box face)
|
|
6664
6990
|
if (pending && pending.frameDrag) { onMoveFrame(e); return; } // dragging the local-frame origin / rotation ring
|
|
6991
|
+
if (pending && pending.posGizmo) { onMovePositionGizmo(e); return; } // dragging a Profile Position handle (depth/width offset or roll)
|
|
6665
6992
|
if (!pending || pending.geo) return;
|
|
6666
6993
|
if (pending.gridId||pending.filteredGrid||pending.filteredReference) { const d=Math.hypot(e.clientX-downXY[0],e.clientY-downXY[1]);if(d<=DRAG_TOL_PX)return;pending=null;controls.enabled=true;boxSel={x:downXY[0],y:downXY[1]};onBoxMove(e);return; } // a filtered-reference/grid click stays inert, but once it moves the same press becomes a normal marquee so an overlay cannot blanket-disable box selection
|
|
6667
6994
|
if (pending.epDrag) { onMoveEndpoint(e); return; }
|
|
@@ -6798,6 +7125,7 @@ function connsInRect(x0, y0, x1, y1, windowMode) {
|
|
|
6798
7125
|
|
|
6799
7126
|
function onUp(e) {
|
|
6800
7127
|
if (e.button === 2) rightDownXY = null; // end the click-vs-drag test (rightMoved keeps the verdict for the contextmenu that follows)
|
|
7128
|
+
if (posInteraction === 'typing') return; // the docked numeric HUD is open (camera frozen). onUp unconditionally re-enables OrbitControls below; a pointerup while typing (e.g. clicking into the input) must NOT thaw the freeze — else a wheel would drift the anchor the HUD is pinned to. There is no gesture to finish here (pending is null). Mirrors onDown's typing guard.
|
|
6801
7129
|
// A live drag-out ends here: released outside our window → send; anywhere inside → silently
|
|
6802
7130
|
// nothing, which is the escape hatch. A press that never travelled was a click, so it falls
|
|
6803
7131
|
// through and still toggles the member in the selection, exactly as it always has.
|
|
@@ -6850,6 +7178,25 @@ function onUp(e) {
|
|
|
6850
7178
|
if(p.gridId){if(moved>DRAG_TOL_PX)return;if(!p.add)resetConnState();if(api&&api.onSelectBatch)api.onSelectBatch({memberIds:[],gridIds:[p.gridId]},p.add);else if(api&&api.onSelectGrid)api.onSelectGrid(p.gridId,p.add);return;}
|
|
6851
7179
|
if (p.clipDrag) return; // a clip handle drag is applied live during onMoveClip; nothing to commit on up (controls re-enabled above)
|
|
6852
7180
|
if (p.frameDrag) { if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; tfCandidates = null; dimCandidates3d = null; return; } // local-frame origin/rotation is applied live during onMoveFrame; session-only, nothing to commit — clear the snap marker/readout AND re-null the snap caches (they were rebuilt sans the UCS origin during the drag) so the next Move/Dimension snaps TO the moved origin again (code-review)
|
|
7181
|
+
if (p.posGizmo) { // Profile Position handle → commit the ABSOLUTE new offset/roll through the editor (one undo entry)
|
|
7182
|
+
if (readout) readout.style.display = 'none';
|
|
7183
|
+
hidePositionLeader();
|
|
7184
|
+
posInteraction = 'idle';
|
|
7185
|
+
const pg = p.posGizmo;
|
|
7186
|
+
// rot is compared by ANGULAR equality (mod 360): a drag that loops the arc back to the member's own roll
|
|
7187
|
+
// (Δ = 360°) reads as no move and must commit nothing / push no undo entry (Fable 5 test 1). depth/width
|
|
7188
|
+
// stay a linear compare.
|
|
7189
|
+
const moved = pg.axis === 'rot'
|
|
7190
|
+
? Math.abs((((pg.newVal - pg.base) % 360) + 540) % 360 - 180) > 1e-6 // shortest angular distance (deg) from base
|
|
7191
|
+
: Math.abs(pg.newVal - pg.base) > 1e-9;
|
|
7192
|
+
if (wasDragging && pg.newVal != null && moved && api && api.commitMemberPosition) {
|
|
7193
|
+
const key = pg.axis === 'depth' ? 'positionOffset' : pg.axis === 'width' ? 'positionHOffset' : 'rot';
|
|
7194
|
+
const val = pg.axis === 'rot' ? rollCommitNorm(pg.newVal) : pg.newVal; // fold the accumulated/off-grid roll to the panel's stored convention
|
|
7195
|
+
const ok = api.commitMemberPosition(pg.id, { [key]: val }, null); // editor's edit() rebuilds → renderPositionGizmo re-anchors
|
|
7196
|
+
if (!ok) { restorePositionGizmoMesh(pg); renderPositionGizmo(); } // refused (e.g. frame drifted) → snap the live preview back
|
|
7197
|
+
} else { restorePositionGizmoMesh(pg); renderPositionGizmo(); } // no net move or a plain click → restore the preview
|
|
7198
|
+
return;
|
|
7199
|
+
}
|
|
6853
7200
|
if (p.epDrag) { // end-node drag → write just that endpoint's wp; a click (no drag) just selects the member
|
|
6854
7201
|
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)); }
|
|
6855
7202
|
else if (api && api.onSelect) api.onSelect(p.id, false);
|
|
@@ -7018,6 +7365,15 @@ function onHoverMove(e) {
|
|
|
7018
7365
|
canvasEl.style.cursor = fh ? 'grab' : 'crosshair';
|
|
7019
7366
|
return;
|
|
7020
7367
|
}
|
|
7368
|
+
// Profile Position handle hover (toggle on, single selection, frame not armed): grab cursor + a themed
|
|
7369
|
+
// tooltip. Mirrors onDown precedence (the handle sits ON the member and wins over the passive frame origin).
|
|
7370
|
+
if (positionGizmoVisible && posGizmoState && !frameMode && posInteraction !== 'typing') {
|
|
7371
|
+
let ph = null; try { ph = pickPositionGizmoHandle(lastHoverXY[0], lastHoverXY[1]); } catch { ph = null; }
|
|
7372
|
+
if (ph) { canvasEl.style.cursor = 'grab';
|
|
7373
|
+
if (api && api.showHandleTip) api.showHandleTip(POS_HANDLE_TIP[ph], lastHoverXY[0], lastHoverXY[1]);
|
|
7374
|
+
posHovered = true; return; }
|
|
7375
|
+
if (posHovered) { posHovered = false; if (api && api.hideHandleTip) api.hideHandleTip(); }
|
|
7376
|
+
} else if (posHovered) { posHovered = false; if (api && api.hideHandleTip) api.hideHandleTip(); } // gizmo disappeared while a tip was up
|
|
7021
7377
|
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"
|
|
7022
7378
|
let fh = null; try { fh = pickFrameHandle(lastHoverXY[0], lastHoverXY[1], true); } catch { fh = null; }
|
|
7023
7379
|
if (fh) { canvasEl.style.cursor = 'pointer'; return; }
|
|
@@ -7289,7 +7645,7 @@ function dispose() {
|
|
|
7289
7645
|
clearRoot();
|
|
7290
7646
|
if (workAreaHelper) { if (overlayScene) overlayScene.remove(workAreaHelper); workAreaHelper.geometry.dispose(); workAreaHelper.material.dispose(); workAreaHelper = null; }
|
|
7291
7647
|
if (wpGroup) { if (scene) scene.remove(wpGroup); wpGroup.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); wpGroup = null; } // the reference plane can exist by default now → dispose it too (code-review)
|
|
7292
|
-
clearConnEnvelope(); clearClipGizmo(); setClipPreview(null); setClipPlanePreview(null); disposeFramePreview(); disposeFrameGizmo(); overlayScene = null; // dispose the clip/frame gizmo
|
|
7648
|
+
clearConnEnvelope(); clearClipGizmo(); setClipPreview(null); setClipPlanePreview(null); disposeFramePreview(); disposeFrameGizmo(); disposePositionGizmo(); disposePositionLeader(); overlayScene = null; // dispose the clip/frame/position gizmo + leader + preview THREE resources before dropping the scene (Codex)
|
|
7293
7649
|
clips = []; workArea = null; clipMode = null; selectedClipIds.clear(); clipBoxDraft = null; // clips live on the renderer; drop them with the renderer
|
|
7294
7650
|
if (renderer) renderer.dispose();
|
|
7295
7651
|
renderer = scene = camera = perspCam = orthoCam = controls = root = api = canvasEl = ro = null; built = false;
|
|
@@ -7528,6 +7884,7 @@ window.Steel3DView = {
|
|
|
7528
7884
|
workAreaSetAll, workAreaFromSelection, workAreaToggle, workAreaSetWhole, clearWorkArea, workAreaState,
|
|
7529
7885
|
armWorkPlanePick, setWorkPlanePrincipal, clearWorkPlane, toggleWorkPlaneVisible, workPlaneInfo,
|
|
7530
7886
|
armFrame3d, disarmFrame3d, repickFrame3d, setFrame3d, setFrameBasis, setFrameAngle, setFrameOrigin, clearFrame3d, frameInfo, positionAuthoringBasis: positionAuthoringBasisSnapshot, onPositionAuthoringBasisChange, frameArmed: () => frameMode, framePicking, framePickStep, frameHandlesScreen, // 3D local drawing frame (UCS stage 1)
|
|
7887
|
+
setPositionGizmoVisible, positionGizmoHandlesScreen, memberWorldTransform, setPositionTyping, positionLeaderVisible, frameGizmoVisible, // Profile Position gizmo (slice 3a/3b): ⋯ Display toggle + E2E grab-point + world-transform/leader/frame-gizmo probes + typed-HUD camera freeze
|
|
7531
7888
|
coordReadout: () => { if (!readout || !readout._coord || readout.style.display === 'none' || readout._coord.style.display === 'none') return null; return { local: readout._coord.classList.contains('ro-local'), values: readout._coordV.map((v) => v.textContent), labels: readout._coordL.map((l) => l.textContent.trim()), text: readout._coord.textContent }; }, // UCS stage 2 test probe: the live local-coordinate row (null when hidden)
|
|
7532
7889
|
cmEscape, cmHasBase, cmClear3d, setCmAxis, cmLastClient, cmHudApply,
|
|
7533
7890
|
drHudApply, pointEntryBegin, pointEntryEnd, drHasStart: () => !!drDraft, // UCS stage 3: shared typed point-entry HUD (Move/Copy + Add)
|