@floless/app 0.143.0 → 0.144.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 +177152 -160760
- package/dist/schemas/steel.model.v2.schema.json +50 -2
- package/dist/schemas/tekla.model.v1.schema.json +66 -0
- package/dist/schemas/tekla.model.v2.schema.json +69 -0
- package/dist/schemas/tekla.source-package.v1.schema.json +37 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +24 -1
- package/dist/skills/floless-app-workflows/SKILL.md +8 -2
- package/dist/skills/floless-app-workflows/references/workspace-data.md +25 -4
- package/dist/templates/floless-workspace-model-report.flo +27 -23
- package/dist/templates/revit-model.flo +6 -2
- package/dist/templates/tekla-model-report.flo +60 -0
- package/dist/templates/tekla-parser.flo +61 -0
- package/dist/web/app.css +89 -2
- package/dist/web/aware.js +423 -46
- package/dist/web/commands-revit.js +4 -0
- package/dist/web/commands-shell.js +136 -3
- package/dist/web/commands-steel.js +6 -0
- package/dist/web/commands-tekla-parser.js +48 -0
- package/dist/web/commands.js +1 -1
- package/dist/web/grid-core.js +15 -0
- package/dist/web/index.html +40 -2
- package/dist/web/instructor.js +13 -3
- package/dist/web/left-pane.js +160 -10
- package/dist/web/model-artifact-loader.js +15 -0
- package/dist/web/model-display-units.js +89 -0
- package/dist/web/model-editor-revit-adapter.js +21 -4
- package/dist/web/model-editor.css +4 -2
- package/dist/web/model-measure.js +10 -6
- package/dist/web/model-panel-bridge.js +46 -3
- package/dist/web/model-pointer-dock.js +21 -1
- package/dist/web/model-property-display.js +91 -0
- package/dist/web/model-revit-module.js +9 -0
- package/dist/web/model-selection-tools.js +11 -0
- package/dist/web/model-spatial-panel.js +52 -21
- package/dist/web/model-structural-grid-view.js +334 -0
- package/dist/web/model-tekla-selection.js +32 -0
- package/dist/web/model-viewport-revit-adapter.js +119 -32
- package/dist/web/revit-editor.css +11 -1
- package/dist/web/revit-editor.html +4 -3
- package/dist/web/revit-editor.js +589 -111
- package/dist/web/steel-3d-view.js +58 -372
- package/dist/web/steel-editor.html +231 -8
- package/dist/web/tekla-editor.html +71 -0
- package/dist/web/tekla-structural-grid-adapter.js +56 -0
- package/dist/web/workspaces.js +872 -97
- package/distribution-profile-production.mjs +4 -0
- package/distribution-resource-inventory.mjs +4 -2
- package/package.json +5 -2
|
@@ -21,7 +21,7 @@ import { surfaceTextures, applyTriplanar, TILE_MM, DIRECTIONAL } from './steel-m
|
|
|
21
21
|
import { canvasToolGuidanceState } from './steel-canvas-guidance.js';
|
|
22
22
|
import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
|
|
23
23
|
import { FT_TO_MM as FT_MM } from './steel-units.js';
|
|
24
|
-
import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, projectToPlane, snapGridPoint,
|
|
24
|
+
import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, projectToPlane, snapGridPoint, projectPointOnSegment2d, projectPointOnSegment3d, selectedFrontmostHit, worldEndpointCommit, SEG_DEGENERACY, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, sectionKindOf, sectionTopology, memberMeshAxes, positionSwingDelta, snapToStep, rollCommitNorm, unwrapAngleStep, translateEndpoints, livePositionState, swingBasis, swingEndpoint, swingBarriers, clampSwingTheta, POSITION_SWING_MARGIN_RAD, POSITION_OFFSET_SNAP_MM, POSITION_ROT_SNAP_DEG, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
|
|
25
25
|
// `gridGeometry`, `gridCandidates3d` and `sheetScaleMm` live behind the host's model read boundary
|
|
26
26
|
// because their display-scale argument is meaningless on a world-mm model grid.
|
|
27
27
|
import { visibleGridLevels, gridTransientScopeSignature, reconcileGridTransientState, objectSelectionStatus } from './grid-core.js';
|
|
@@ -35,12 +35,14 @@ import { createModelSpatialTools } from './model-spatial-tools.js';
|
|
|
35
35
|
import { solveModelSnapConstraint, solveModelSnapIntersection } from './model-snapping.js';
|
|
36
36
|
import { mountModelOrientationOverlay, modelOrientationPose } from './model-orientation-overlay.js';
|
|
37
37
|
import { createModelSelectionTools } from './model-selection-tools.js';
|
|
38
|
+
import { orderModelSelectionHits } from './model-selection-tools.js';
|
|
38
39
|
import { createModelClipGesture, orientClipNormalAwayFromCamera } from './model-clip-gesture.js';
|
|
39
40
|
import { createModelClipSession } from './model-clip-session.js';
|
|
40
41
|
import { createModelClipThreeOverlay } from './model-clip-three-overlay.js';
|
|
41
42
|
import { createModelClipThreePreview } from './model-clip-three-preview.js';
|
|
42
43
|
import { MODEL_LIGHTING_PROFILES, modelMeshCastsShadow, modelShadowsEnabled, modelSunDirection, normalizeModelLighting } from './model-viewport-lighting.js';
|
|
43
44
|
import { mountModelClipList } from './model-clip-list.js';
|
|
45
|
+
import { createModelStructuralGridView } from './model-structural-grid-view.js';
|
|
44
46
|
|
|
45
47
|
let renderer, scene, perspCam, orthoCam, camera, controls, root, api, canvasEl, ro, rafId, grid, raycaster, downXY, lastPick = '(none)';
|
|
46
48
|
let viewportController = null;
|
|
@@ -213,14 +215,15 @@ function viewportBoxReceipt(box) {
|
|
|
213
215
|
function viewportBounds(purpose) {
|
|
214
216
|
if (purpose === 'native-model') return viewportBoxReceipt(sceneBox);
|
|
215
217
|
if (purpose === 'camera-selection') {
|
|
216
|
-
if (!selIds.size) return viewportBoxReceipt(visibleWorldBox());
|
|
218
|
+
if (!selIds.size && !selectedGridIds.size) return viewportBoxReceipt(visibleWorldBox());
|
|
217
219
|
const selected = new THREE.Box3();
|
|
218
220
|
for (const id of selIds) {
|
|
219
221
|
const mesh = meshById.get(id), detail = String(id).startsWith('det:');
|
|
220
222
|
if (detail && mesh && (mesh.userData._detailOpacity == null ? mesh.material.opacity : mesh.userData._detailOpacity) <= 0) continue;
|
|
221
223
|
if (meshContributesPixels(mesh, displayMode === 'wire' && !detail)) selected.expandByObject(mesh);
|
|
222
224
|
}
|
|
223
|
-
return viewportBoxReceipt(selected)
|
|
225
|
+
return viewportBoxReceipt(structuralGridView?.composeBounds({ meshBounds: selected.isEmpty() ? null : selected,
|
|
226
|
+
purpose: 'camera-selection', gridOwnerSelected: selectedGridIds.size > 0 }));
|
|
224
227
|
}
|
|
225
228
|
return viewportBoxReceipt(visibleWorldBox());
|
|
226
229
|
}
|
|
@@ -515,20 +518,21 @@ function steelSelectionCoordinatorPort() {
|
|
|
515
518
|
}
|
|
516
519
|
|
|
517
520
|
function steelSelectionHitsAt(pointer, event) {
|
|
518
|
-
let
|
|
519
|
-
try {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
return
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
521
|
+
let meshHits = []; try { meshHits = meshHitsAt(pointer.x, pointer.y); } catch (err) { console.error('steel-3d: shared mesh hit-test failed', err); }
|
|
522
|
+
let winner = null; try { winner = structuralGridView?.pick({ clientX: pointer.x, clientY: pointer.y, meshHits,
|
|
523
|
+
isOpaqueOccluder: (hit) => OPAQUE_MODES.has(displayMode) && occludesGrid(hit), raycaster }); }
|
|
524
|
+
catch (err) { console.error('steel-3d: shared grid/mesh hit-test failed', err); }
|
|
525
|
+
const meshCandidates = meshHits.map((hit) => {
|
|
526
|
+
const id = hit.object?.userData?.id;
|
|
527
|
+
return id ? { entity: { kind: 'native', sourceId: id }, selectable: !api?.canSelectId || api.canSelectId(id), rawVisible: true,
|
|
528
|
+
distance: hit.distance } : null;
|
|
529
|
+
}).filter(Boolean);
|
|
530
|
+
const primary = winner?.kind === 'grid'
|
|
531
|
+
? { entity: { kind: 'grid', sourceId: winner.id }, selectable: !api?.canSelectGrid || api.canSelectGrid(), rawVisible: true,
|
|
532
|
+
distance: winner.distance }
|
|
533
|
+
: winner?.kind === 'mesh' ? meshCandidates.find((candidate) => candidate.entity.sourceId === winner.hit.object?.userData?.id) ?? null : null;
|
|
534
|
+
const candidates = orderModelSelectionHits(primary, meshCandidates);
|
|
535
|
+
if (candidates.length) return candidates;
|
|
532
536
|
let reference = null; try { reference = pickReferenceAt(pointer.x, pointer.y); } catch (_) {}
|
|
533
537
|
if (!reference) return [];
|
|
534
538
|
const selectable = !api?.canSelectReference || api.canSelectReference();
|
|
@@ -655,6 +659,16 @@ function init(canvas, theApi, options = {}) {
|
|
|
655
659
|
lightFill = new THREE.DirectionalLight(0xffffff, 0.25); lightFill.position.set(-1, 0.6, 0.4); scene.add(lightFill);
|
|
656
660
|
root = new THREE.Group(); scene.add(root);
|
|
657
661
|
overlayScene = new THREE.Scene(); // clip/work-area gizmos render here in a 2nd unclipped pass (see loop)
|
|
662
|
+
structuralGridView?.dispose?.();
|
|
663
|
+
structuralGridView = createModelStructuralGridView({
|
|
664
|
+
scene,
|
|
665
|
+
labelScene: overlayScene,
|
|
666
|
+
getCamera: () => camera,
|
|
667
|
+
getCanvas: () => canvasEl,
|
|
668
|
+
getClipPlanes: () => renderer?.clippingPlanes ?? [],
|
|
669
|
+
labelPx: gridLabelPx,
|
|
670
|
+
});
|
|
671
|
+
structGridLines = structuralGridView.lines;
|
|
658
672
|
initSharedClipLayer();
|
|
659
673
|
epGroup = new THREE.Group(); scene.add(epGroup);
|
|
660
674
|
// ONE geometry + two materials shared by every endpoint dot (rebuilt often on hover/selection —
|
|
@@ -3628,12 +3642,11 @@ function positionSelLenLabels() {
|
|
|
3628
3642
|
// wayfinding survives sectioning/work-area (the UX review's clip-regression guard). Data comes from
|
|
3629
3643
|
// the contract via api.getGrid() (grid-core owns parsing/geometry); allCandidates() feeds the same
|
|
3630
3644
|
// grid into snapping, plan-locked.
|
|
3631
|
-
let structGridGroup = null, gridLabelGroup = null;
|
|
3645
|
+
let structuralGridView = null, structGridGroup = null, gridLabelGroup = null;
|
|
3632
3646
|
let gridLevelsMm = []; // world Zs the grid is DRAWN at (one per visible level) — set by buildStructGrid so grid snapping can never drift from what the user sees
|
|
3633
|
-
|
|
3647
|
+
let structGridLines = new Map();
|
|
3634
3648
|
let selectedGridIds = new Set();
|
|
3635
3649
|
let structGridSignature = null;
|
|
3636
|
-
const gridTexCache = new Map(); // 'b:LABEL' bubble / 't:LABEL' tag -> CanvasTexture (kept until dispose)
|
|
3637
3650
|
// How big a grid bubble is ON SCREEN, in px — the user's setting (⋯ ▸ Display ▸ Grid label size), shared
|
|
3638
3651
|
// with the 2D plan so one grid reads the same in both views. It is a VIEW preference, not model data, so
|
|
3639
3652
|
// it lives in localStorage next to the other per-browser display prefs and never touches the contract.
|
|
@@ -3672,55 +3685,10 @@ function allCandidates(excludeId) {
|
|
|
3672
3685
|
catch { return base; } // a malformed hand-edited grid must never break member dragging
|
|
3673
3686
|
}
|
|
3674
3687
|
|
|
3675
|
-
function gridBubbleTexture(label) {
|
|
3676
|
-
const key = 'b:' + label;
|
|
3677
|
-
if (gridTexCache.has(key)) return gridTexCache.get(key);
|
|
3678
|
-
// 256, not 128: the bubble is drawn at up to GRID_LABEL_PX_MAX on a 2× display, and the old texture
|
|
3679
|
-
// went visibly soft at the top of the size range.
|
|
3680
|
-
const S = 256, cv = document.createElement('canvas'); cv.width = cv.height = S;
|
|
3681
|
-
const g = cv.getContext('2d');
|
|
3682
|
-
const R = S / 2 - 10;
|
|
3683
|
-
g.beginPath(); g.arc(S / 2, S / 2, R, 0, Math.PI * 2);
|
|
3684
|
-
g.fillStyle = '#0f172a'; g.fill();
|
|
3685
|
-
g.lineWidth = 10; g.strokeStyle = '#64748b'; g.stroke();
|
|
3686
|
-
// Shrink to fit the CIRCLE, not to a fraction of the diameter — the same closed form the 2D plan uses
|
|
3687
|
-
// (see gridLabelFontPx there for the derivation), so the two views agree about what "fits" means. The
|
|
3688
|
-
// old `width > R * 1.5` rule is blind to where the text sits: a centred line is widest at its own
|
|
3689
|
-
// half-height, where the circle has already narrowed, and R*1.5 let the ink reach the rim stroke.
|
|
3690
|
-
g.fillStyle = '#e2e8f0';
|
|
3691
|
-
g.font = 'bold 100px system-ui';
|
|
3692
|
-
const wEm = g.measureText(label).width / 100, Ri = R - 10; // inner radius: the rim is a 10 px stroke centred on R
|
|
3693
|
-
const fs = Math.min(120, 0.95 * Ri / Math.sqrt(wEm * wEm / 4 + 0.1296));
|
|
3694
|
-
g.font = 'bold ' + fs + 'px system-ui';
|
|
3695
|
-
g.textAlign = 'center'; g.textBaseline = 'middle';
|
|
3696
|
-
g.fillText(label, S / 2, S / 2 + 4);
|
|
3697
|
-
const tex = new THREE.CanvasTexture(cv);
|
|
3698
|
-
gridTexCache.set(key, tex);
|
|
3699
|
-
return tex;
|
|
3700
|
-
}
|
|
3701
|
-
function gridTagTexture(label) {
|
|
3702
|
-
const key = 't:' + label;
|
|
3703
|
-
if (gridTexCache.has(key)) return gridTexCache.get(key);
|
|
3704
|
-
const W = 512, H = 80, cv = document.createElement('canvas'); cv.width = W; cv.height = H;
|
|
3705
|
-
const g = cv.getContext('2d');
|
|
3706
|
-
g.beginPath(); g.roundRect(4, 4, W - 8, H - 8, 14);
|
|
3707
|
-
g.fillStyle = '#0f172a'; g.fill();
|
|
3708
|
-
g.lineWidth = 4; g.strokeStyle = '#64748b'; g.stroke();
|
|
3709
|
-
g.fillStyle = '#94a3b8'; let fs = 40;g.font = 'bold '+fs+'px system-ui';while(fs>12&&g.measureText(label).width>W-28){fs-=2;g.font='bold '+fs+'px system-ui';}
|
|
3710
|
-
g.textAlign = 'center'; g.textBaseline = 'middle';
|
|
3711
|
-
g.fillText(label, W / 2, H / 2 + 2, W - 28); // the schema accepts 40 chars; the safety width prevents even an all-wide-glyph label from clipping
|
|
3712
|
-
const tex = new THREE.CanvasTexture(cv);
|
|
3713
|
-
gridTexCache.set(key, tex);
|
|
3714
|
-
return tex;
|
|
3715
|
-
}
|
|
3716
3688
|
function clearStructGrid() {
|
|
3717
3689
|
invalidateCameraClipBounds();
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
for (const o of [...grp.children]) { grp.remove(o); if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); } // sprite materials are per-sprite; textures stay cached
|
|
3721
|
-
if (parent) parent.remove(grp);
|
|
3722
|
-
}
|
|
3723
|
-
structGridGroup = gridLabelGroup = null;structGridLines.clear();gridLevelsMm = [];
|
|
3690
|
+
structuralGridView?.clear(); structGridGroup = structuralGridView?.lineGroup ?? null;
|
|
3691
|
+
gridLabelGroup = structuralGridView?.labelGroup ?? null; structGridLines = structuralGridView?.lines ?? new Map(); gridLevelsMm = [];
|
|
3724
3692
|
}
|
|
3725
3693
|
function buildStructGrid() {
|
|
3726
3694
|
dimCandidates3d = null; tfCandidates = null; clipCandidates = null; clipLevels = null; invalidateModelCache(); // the grid just changed → EVERY cached snap set built from the OLD one is stale (dim, Move/Copy + Add, clip-box draw). rebuild() already nulls these, but refresh3DGrid() (grid panel edits, and the plan switch setPlan now fires) reaches us without it, which would pair one sheet's grid X/Y with another's elevations.
|
|
@@ -3739,255 +3707,13 @@ function buildStructGrid() {
|
|
|
3739
3707
|
const mmX = (u) => u * k, mmY = (u) => (flipY ? -u : u) * k; // stored space → scene
|
|
3740
3708
|
const levels = geo.zs.length ? visibleGridLevels(geo.zs, g.hidden_z) : [{ mm: 0, label: '0' }];
|
|
3741
3709
|
if (!levels.length) {finish();return;} // every authored Z datum is hidden
|
|
3742
|
-
|
|
3743
|
-
structGridGroup =
|
|
3744
|
-
|
|
3745
|
-
// targets (gridCandidates3d) are at the true Z — so the reticle floated a fixed 25 mm above the line
|
|
3746
|
-
// the user aimed at, which reads as several px of snap error once you zoom in (Pawel 2026-07-18).
|
|
3747
|
-
const addLogical=(id,ends)=>{const pts=[];for(const lv of levels){const z=lv.mm;pts.push(V(ends[0][0],ends[0][1],z),V(ends[1][0],ends[1][1],z));}const on=selectedGridIds.has(id);const seg=new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(pts),new THREE.LineDashedMaterial({color:on?0x3b82f6:0x64748b,dashSize:450,gapSize:220,transparent:true,opacity:on?1:0.85}));seg.computeLineDistances();seg.userData.gridId=id;seg.userData.segments=pts.map(p=>[p.x,p.y,p.z]);structGridLines.set(id,seg);structGridGroup.add(seg);};
|
|
3748
|
-
geo.v.forEach((l,i)=>addLogical('gv:'+i,[[mmX(l.x),mmY(l.lo)],[mmX(l.x),mmY(l.hi)]]));
|
|
3749
|
-
geo.h.forEach((l,i)=>addLogical('gh:'+i,[[mmX(l.lo),mmY(l.y)],[mmX(l.hi),mmY(l.y)]]));
|
|
3750
|
-
(geo.lines||[]).forEach((l,i)=>addLogical('gl:'+(l.id!=null?l.id:i),[[mmX(l.a[0]),mmY(l.a[1])],[mmX(l.b[0]),mmY(l.b[1])]]));
|
|
3751
|
-
scene.add(structGridGroup);
|
|
3752
|
-
gridLabelGroup = new THREE.Group();
|
|
3753
|
-
const z0 = levels[0].mm;
|
|
3754
|
-
// Every label records its ANCHOR (the point it belongs to) and, for a bubble, the OUTWARD direction
|
|
3755
|
-
// along its own line. Neither the position nor the scale is final here — sizeGridLabels() sets both
|
|
3756
|
-
// every frame, because both are camera-dependent (see there for why that is the CAD behaviour).
|
|
3757
|
-
const sprite = (tex, label, gridId) => {
|
|
3758
|
-
// depthTest ON so steel in FRONT occludes the bubble/level tag (B7). The overlay pass runs with the
|
|
3759
|
-
// depth buffer from pass 1 (members) intact — autoClear is off — so this occludes against the steel
|
|
3760
|
-
// WITHOUT moving the labels out of overlayScene: they stay unclipped, so a section plane still can't
|
|
3761
|
-
// cut them (the clip-regression guard above holds).
|
|
3762
|
-
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, depthTest: true, depthWrite: false, transparent: true }));
|
|
3763
|
-
s.userData.label=String(label||'');s.userData.gridId=gridId||null;
|
|
3764
|
-
s.renderOrder = 994;
|
|
3765
|
-
gridLabelGroup.add(s);
|
|
3766
|
-
return s;
|
|
3767
|
-
};
|
|
3768
|
-
// A bubble at (ax,ay), on the line whose OTHER end is (ox,oy) — so it can hang off the end away from
|
|
3769
|
-
// the model, the way a grid bubble does on a drawing.
|
|
3770
|
-
const bubble = (label, gridId, ax, ay, ox, oy) => {
|
|
3771
|
-
const s = sprite(gridBubbleTexture(label), label, gridId);
|
|
3772
|
-
// AWAY from the other end: (anchor - other), normalised. Getting this sign wrong hangs every bubble
|
|
3773
|
-
// INTO the model, onto the perimeter columns — the exact thing the placement exists to prevent.
|
|
3774
|
-
const dx = ax - ox, dy = ay - oy, len = Math.hypot(dx, dy);
|
|
3775
|
-
s.userData.anchor = V(ax, ay, z0);
|
|
3776
|
-
// A zero-length line has no outward direction to compute. `|| 1` used to guard the division and hand
|
|
3777
|
-
// back a ZERO vector, which reads as handled and silently parks the bubble on the model. +X is
|
|
3778
|
-
// arbitrary but it is a real direction, so the bubble still clears the end it belongs to.
|
|
3779
|
-
s.userData.outward = len > 1e-9 ? V(dx / len, dy / len, 0) : V(1, 0, 0);
|
|
3780
|
-
s.position.copy(s.userData.anchor);
|
|
3781
|
-
};
|
|
3782
|
-
geo.v.forEach((l,i)=>{const id='gv:'+i,x=mmX(l.x),lo=mmY(l.lo),hi=mmY(l.hi);bubble(l.label,id,x,lo,x,hi);bubble(l.label,id,x,hi,x,lo);});
|
|
3783
|
-
geo.h.forEach((l,i)=>{const id='gh:'+i,y=mmY(l.y),lo=mmX(l.lo),hi=mmX(l.hi);bubble(l.label,id,lo,y,hi,y);bubble(l.label,id,hi,y,lo,y);});
|
|
3784
|
-
(geo.lines || []).forEach((l,i)=>{const id='gl:'+(l.id!=null?l.id:i),ax=mmX(l.a[0]),ay=mmY(l.a[1]),bx=mmX(l.b[0]),by=mmY(l.b[1]);bubble(l.label,id,ax,ay,bx,by);bubble(l.label,id,bx,by,ax,ay);});
|
|
3785
|
-
if (geo.zs.length) for (const lv of levels) { // one elevation tag per level, parked off the grid's top-left corner
|
|
3786
|
-
const s = sprite(gridTagTexture(lv.label), lv.label, null);
|
|
3787
|
-
s.userData.anchor = V(mmX(geo.x0), mmY(geo.y1), lv.mm);
|
|
3788
|
-
// The sprite's aspect is width/HEIGHT, and the height below is 0.75·d — so this is 4.8, not the
|
|
3789
|
-
// texture's 6.4. Reading the 6.4 out of the old comment and using it as the width multiplier gives
|
|
3790
|
-
// 6.4/0.75 = 8.53:1 against a 6.4:1 bitmap, i.e. every elevation tag 33% too wide.
|
|
3791
|
-
s.userData.tagAspect = 4.8; // 4.8 / 0.75 == the tag texture's 512×80, so a long elevation label stays undistorted
|
|
3792
|
-
s.position.copy(s.userData.anchor);
|
|
3793
|
-
}
|
|
3794
|
-
overlayScene.add(gridLabelGroup);
|
|
3710
|
+
structuralGridView.build({ grid: g, geometry: geo, scale: k, flipY, selectedIds: selectedGridIds });
|
|
3711
|
+
structGridGroup = structuralGridView.lineGroup; gridLabelGroup = structuralGridView.labelGroup;
|
|
3712
|
+
structGridLines = structuralGridView.lines; gridLevelsMm = structuralGridView.levels;
|
|
3795
3713
|
finish();
|
|
3796
3714
|
sizeGridLabels(); // place + size them NOW, so a pick or a probe between this build and the next frame sees where they really are
|
|
3797
3715
|
}
|
|
3798
|
-
|
|
3799
|
-
// Grid labels are CAD ANNOTATION, not model geometry, and three things follow from that — all three
|
|
3800
|
-
// camera-dependent, hence per frame:
|
|
3801
|
-
//
|
|
3802
|
-
// SIZE. They hold ONE size on screen (gridLabelPx) however far you zoom, exactly like Tekla's and
|
|
3803
|
-
// Revit's grid heads. They used to be world-space sprites of ⌀ span*0.035 (400–3000 mm), which is a
|
|
3804
|
-
// 3 m disc on a big job: unreadably small framed out, and swallowing whole bays zoomed in.
|
|
3805
|
-
//
|
|
3806
|
-
// PLACE. A bubble sits TANGENT to the end of its line, on the far side from the model — the line
|
|
3807
|
-
// stops at the circle rather than running to its centre. That is the convention gridFromDrawing
|
|
3808
|
-
// already measures on real sheets ("the line stops at the bubble's edge, end-gap ≈ r"), and it is
|
|
3809
|
-
// what keeps a bubble off the perimeter columns that stand at the grid ends.
|
|
3810
|
-
//
|
|
3811
|
-
// Tangency has to be solved ON SCREEN, which is the whole subtlety here. The standoff runs ALONG the
|
|
3812
|
-
// grid line in world space, so it foreshortens with that line's angle to the camera — but the bubble
|
|
3813
|
-
// is a camera-facing sprite whose radius does NOT foreshorten. Offsetting by half a bubble in world
|
|
3814
|
-
// units therefore lands the centre closer than one radius on screen, and the line visibly runs INSIDE
|
|
3815
|
-
// the circle: measured at 8.8 px against a 13.0 px radius on an ordinary iso view. So the offset is
|
|
3816
|
-
// the world distance whose PROJECTION is one radius, found by projecting the line direction and
|
|
3817
|
-
// dividing (see screenPxPerWorld). A line pointing nearly at the camera projects to almost nothing
|
|
3818
|
-
// and would demand a runaway offset, so it is capped — at that angle the line is a dot and there is
|
|
3819
|
-
// no visible tangency left to get right.
|
|
3820
|
-
//
|
|
3821
|
-
// DECLUTTER. A drawing never prints two bubbles on top of each other. Screen-constant labels on a
|
|
3822
|
-
// tight grid do collide once you frame out, so a bubble whose disc would TOUCH one already kept drops
|
|
3823
|
-
// out — centres nearer than 0.9 × the diameter, which is nearly two radii, not one. (Said as "centre
|
|
3824
|
-
// inside one already kept" here at first, which describes a rule ~1.8× looser than the code's.)
|
|
3825
|
-
// SELECTED lines are placed first and so always survive: losing the label AND the pick target of the
|
|
3826
|
-
// grid you are working on, to an unrelated line that merely sorted earlier, is not decluttering. Past
|
|
3827
|
-
// that, build order decides, so the survivors don't flicker as the camera moves. Elevation tags are
|
|
3828
|
-
// exempt entirely: there is one per level and they are the last wayfinding left when bubbles thin out.
|
|
3829
|
-
// Between two bubble CENTRES on screen, × gridLabelPx — so it must be ≥ 1, because gridLabelPx IS the
|
|
3830
|
-
// diameter and two discs whose centres are a diameter apart are exactly touching. At 0.9 they overlapped
|
|
3831
|
-
// by ~1 px for one zoom step before the pass fired (QA measured 24.4 px centres against 25.5 px discs);
|
|
3832
|
-
// 1.05 leaves a hair of clearance so the rims never kiss either.
|
|
3833
|
-
const GRID_LABEL_MIN_GAP = 1.05;
|
|
3834
|
-
// × the bubble radius — how far along its own line a bubble may be pushed to reach tangency. Generous:
|
|
3835
|
-
// it is bounded only so a line pointing straight at the camera cannot demand an unbounded world offset
|
|
3836
|
-
// (which would fly the sprite through the near/far planes and reorder it against the steel). Past this
|
|
3837
|
-
// the bubble is hidden instead — see the refusal in sizeGridLabels.
|
|
3838
|
-
const GRID_LABEL_MAX_STANDOFF = 60;
|
|
3839
|
-
let anchorlessLabelWarned = false, badLabelScaleWarned = false; // warn once each; a per-frame loop must never flood the console
|
|
3840
|
-
// Screen px per world unit ALONG `dir` at `from` — the foreshortening of that direction under the
|
|
3841
|
-
// current camera. Measured over a real span (`len`) rather than differentiated, so it is right for a
|
|
3842
|
-
// perspective camera too. Returns 0 when the span does not project (behind the camera), which the
|
|
3843
|
-
// caller reads as "unknown" and falls back from.
|
|
3844
|
-
// Answers null, not 0, when it cannot measure: 0 would read as a real "zero px per world unit" to the
|
|
3845
|
-
// next person, and it is numerically adjacent to the legitimate near-on-axis case the cap exists for.
|
|
3846
|
-
// The world size that reads as `px` on screen at `pos` — DEPTH-correct under perspective.
|
|
3847
|
-
//
|
|
3848
|
-
// A camera-facing sprite's projected size is set by the point's depth along the view axis, because that
|
|
3849
|
-
// is what the projection divides by. pxToWorldAt uses `camera.position.distanceTo(pos)`, which is the
|
|
3850
|
-
// RADIAL distance — the same number only on the axis, and larger everywhere else by 1/cos(angle). So a
|
|
3851
|
-
// bubble out at the corner of a wide viewport drew about 15% over its setting, and the re-measure at the
|
|
3852
|
-
// placed position repeated the error rather than cancelling it. Ortho has no distance term at all, and
|
|
3853
|
-
// it is this view's default, which is why every measurement so far read exactly 26.0 px.
|
|
3854
|
-
//
|
|
3855
|
-
// Deliberately NOT a fix inside pxToWorldAt: that helper is shared by sizeEndpoints, sizeClipHandles and
|
|
3856
|
-
// sizeFrameHandle, whose sizes are separately verified, so the same correction there is its own change
|
|
3857
|
-
// with its own evidence. Falls back to the shared helper whenever depth is unusable.
|
|
3858
|
-
const _depthV = new THREE.Vector3();
|
|
3859
|
-
function pxToWorldDepth(px, pos) {
|
|
3860
|
-
if (camera === orthoCam) return pxToWorldAt(px, pos);
|
|
3861
|
-
const depth = -_depthV.copy(pos).applyMatrix4(camera.matrixWorldInverse).z;
|
|
3862
|
-
if (!(depth > 0) || !Number.isFinite(depth)) return pxToWorldAt(px, pos); // at or behind the camera plane — no meaningful depth
|
|
3863
|
-
const h = (canvasEl && canvasEl.clientHeight) || 1;
|
|
3864
|
-
return px * (2 * Math.tan(THREE.MathUtils.degToRad(perspCam.fov) / 2) * depth) / h;
|
|
3865
|
-
}
|
|
3866
|
-
const _spA = new THREE.Vector3(), _spB = new THREE.Vector3();
|
|
3867
|
-
function screenPxPerWorld(from, dir, len, w, h) {
|
|
3868
|
-
if (!(len > 0)) return null;
|
|
3869
|
-
_spA.copy(from).project(camera);
|
|
3870
|
-
_spB.copy(from).addScaledVector(dir, len).project(camera);
|
|
3871
|
-
// BOTH components, not just .x — a NaN landing only in .y used to pass this and reach the caller as a
|
|
3872
|
-
// NaN ratio, which fell back only because `NaN > 1e-9` happens to be false. Right answer by accident.
|
|
3873
|
-
if (![_spA.x, _spA.y, _spB.x, _spB.y].every(Number.isFinite)) return null;
|
|
3874
|
-
const dx = (_spB.x - _spA.x) * 0.5 * w, dy = (_spB.y - _spA.y) * 0.5 * h;
|
|
3875
|
-
return Math.hypot(dx, dy) / len;
|
|
3876
|
-
}
|
|
3877
|
-
function sizeGridLabels() {
|
|
3878
|
-
if (!gridLabelGroup || !gridLabelGroup.children.length || !camera) return;
|
|
3879
|
-
const w = (canvasEl && canvasEl.clientWidth) || 1, h = (canvasEl && canvasEl.clientHeight) || 1;
|
|
3880
|
-
camera.updateMatrixWorld();
|
|
3881
|
-
const placed = [];
|
|
3882
|
-
for (const s of gridLabelGroup.children) {
|
|
3883
|
-
const ud = s.userData;
|
|
3884
|
-
// Every child is built by sprite() with an anchor, so this is unreachable today — but sprite() no
|
|
3885
|
-
// longer sets position or scale, so a future anchorless one would be a 1 mm disc at the world origin
|
|
3886
|
-
// that also escapes the visibility filter below. A per-frame loop must be total, so it still skips;
|
|
3887
|
-
// it just does not do so in silence.
|
|
3888
|
-
if (!ud || !ud.anchor) { if (!anchorlessLabelWarned) { anchorlessLabelWarned = true; console.warn('[steel-3d] a grid label has no anchor — it will not be placed, sized, or hidden with its line'); } continue; }
|
|
3889
|
-
s.visible = ud.allowed !== false; // applyGridVisibility owns WHETHER it may show; this owns where and how big
|
|
3890
|
-
if (!s.visible) continue;
|
|
3891
|
-
const d = pxToWorldDepth(gridLabelPx, ud.anchor); // the world size that reads as gridLabelPx on screen, measured AT the anchor
|
|
3892
|
-
// A degenerate ortho frustum, or a camera sitting exactly on the anchor, makes this 0 or NaN, and
|
|
3893
|
-
// `scale.set(0,0,1)` / `scale.set(NaN,NaN,1)` both render NOTHING while three.js throws on neither.
|
|
3894
|
-
// That is the undiagnosable disappearance: identical on screen to declutter, to an isolate filter,
|
|
3895
|
-
// and to "the grid failed to build". Keep the last good size instead of writing the bad one.
|
|
3896
|
-
if (!(d > 0) || !Number.isFinite(d)) { if (!badLabelScaleWarned) { badLabelScaleWarned = true; console.warn('[steel-3d] grid label size came out as ' + d + ' — keeping the last good size (check the camera frustum)'); } continue; }
|
|
3897
|
-
if (ud.tagAspect) {
|
|
3898
|
-
const tw = d * ud.tagAspect, th = d * 0.75, gap = d * 0.4;
|
|
3899
|
-
s.scale.set(tw, th, 1);
|
|
3900
|
-
s.position.set(ud.anchor.x - tw / 2 - gap, ud.anchor.y + th / 2 + gap, ud.anchor.z); // clear of the corner, not centred on it
|
|
3901
|
-
continue;
|
|
3902
|
-
}
|
|
3903
|
-
// Tangent ON SCREEN: push out far enough along the line that its projection is exactly one radius,
|
|
3904
|
-
// so the line stops at the rim instead of running into the circle. d/2 is the un-foreshortened
|
|
3905
|
-
// case (a line lying in the screen plane) and so is also the right fallback and the floor.
|
|
3906
|
-
const k = screenPxPerWorld(ud.anchor, ud.outward, d, w, h);
|
|
3907
|
-
const want = (k !== null && k > 1e-9) ? Math.max((gridLabelPx / 2) / k, d / 2) : d / 2;
|
|
3908
|
-
const standoff = Math.min(want, (d / 2) * GRID_LABEL_MAX_STANDOFF);
|
|
3909
|
-
s.position.copy(ud.anchor).addScaledVector(ud.outward, standoff);
|
|
3910
|
-
// The cap has to be able to REFUSE. Look almost straight down a grid line and k collapses, so the
|
|
3911
|
-
// distance needed for tangency runs away; capping it silently draws the line clean through the disc
|
|
3912
|
-
// and across the label — QA measured exactly that at a near-elevation angle, the line reaching 0.8 px
|
|
3913
|
-
// of the centre against a 13 px rim. (The first cap was 6 radii, with a comment claiming such a line
|
|
3914
|
-
// is "a dot with no visible tangency left to get right". It is not: QA's was 9 px long and its label
|
|
3915
|
-
// perfectly readable.) So the cap is generous enough to place any line you can still read along, and
|
|
3916
|
-
// when even that cannot clear the disc the bubble is HIDDEN rather than drawn crossed — you cannot
|
|
3917
|
-
// label a line you are looking down, and a missing mark beats a struck-through one.
|
|
3918
|
-
if (standoff < want * 0.999) { s.visible = false; continue; }
|
|
3919
|
-
// Re-measure at where it ENDED UP. Under perspective the standoff moves the sprite toward or away
|
|
3920
|
-
// from the camera, so a size taken at the anchor is off by that much — up to ~8% when the cap
|
|
3921
|
-
// engages. Ortho is unaffected (no distance term), but "constant size on screen" should be literally
|
|
3922
|
-
// true in both. Cheap, and the standoff is already fixed by the time it runs.
|
|
3923
|
-
const dAt = pxToWorldDepth(gridLabelPx, s.position);
|
|
3924
|
-
s.scale.setScalar(Number.isFinite(dAt) && dAt > 0 ? dAt : d);
|
|
3925
|
-
s.scale.z = 1;
|
|
3926
|
-
placed.push(s);
|
|
3927
|
-
}
|
|
3928
|
-
// THE OTHER LEVELS. A grid line is drawn once PER LEVEL (addLogical stacks a segment at every visible
|
|
3929
|
-
// Z), but a bubble exists only at the base level and can only be tangent to the segment it is anchored
|
|
3930
|
-
// to. Come at the grid from near-elevation and the upper segments project nearly collinear with the
|
|
3931
|
-
// lower one — and, having no bubble of their own to stop at, run straight through the disc. QA measured
|
|
3932
|
-
// an untrimmed upper segment reaching 2.7 px from the centre of a 13 px bubble, in 5 of 230
|
|
3933
|
-
// observations, and it was invisible to every earlier check because those all measured the bubble
|
|
3934
|
-
// against its OWN endpoint, which was tangent to 0.00 px throughout.
|
|
3935
|
-
//
|
|
3936
|
-
// Tangency cannot solve this — one disc, several lines. So the same rule as the cap: a bubble that
|
|
3937
|
-
// cannot be shown uncrossed is not shown. Distance is measured to the SEGMENT, not to its endpoints,
|
|
3938
|
-
// because the offending part is the middle of the segment passing over the disc.
|
|
3939
|
-
const lineSegs = new Map(); // gridId -> [[x1,y1,x2,y2], …] on screen, this frame
|
|
3940
|
-
for (const [id, line] of structGridLines) {
|
|
3941
|
-
if (!line.visible) continue;
|
|
3942
|
-
const pts = line.userData.segments || [], segs = [];
|
|
3943
|
-
for (let i = 0; i + 1 < pts.length; i += 2) {
|
|
3944
|
-
const a = _spA.set(pts[i][0], pts[i][1], pts[i][2]).project(camera);
|
|
3945
|
-
if (!Number.isFinite(a.x) || a.z > 1 || a.z < -1) continue;
|
|
3946
|
-
const ax = (a.x * 0.5 + 0.5) * w, ay = (-a.y * 0.5 + 0.5) * h;
|
|
3947
|
-
const b = _spB.set(pts[i + 1][0], pts[i + 1][1], pts[i + 1][2]).project(camera);
|
|
3948
|
-
if (!Number.isFinite(b.x) || b.z > 1 || b.z < -1) continue;
|
|
3949
|
-
segs.push([ax, ay, (b.x * 0.5 + 0.5) * w, (-b.y * 0.5 + 0.5) * h]);
|
|
3950
|
-
}
|
|
3951
|
-
if (segs.length) lineSegs.set(id, segs);
|
|
3952
|
-
}
|
|
3953
|
-
// Screen pixels, and this caller's historic rule is `len2 > 0` (#951 — the shared primitive lives in
|
|
3954
|
-
// steel-3d-core; the rule stays this caller's own).
|
|
3955
|
-
const distToSeg = (px, py, x1, y1, x2, y2) =>
|
|
3956
|
-
projectPointOnSegment2d([px, py], [x1, y1], [x2, y2], SEG_DEGENERACY.atMost(0)).distance;
|
|
3957
|
-
const survivors = [];
|
|
3958
|
-
for (const s of placed) {
|
|
3959
|
-
const p = _spA.copy(s.position).project(camera);
|
|
3960
|
-
if (!Number.isFinite(p.x) || !Number.isFinite(p.y) || p.z > 1 || p.z < -1) { survivors.push(s); continue; } // off screen — nothing to cross it there
|
|
3961
|
-
const cx = (p.x * 0.5 + 0.5) * w, cy = (-p.y * 0.5 + 0.5) * h;
|
|
3962
|
-
const segs = lineSegs.get(s.userData.gridId) || [];
|
|
3963
|
-
// The tangent segment sits at exactly one radius, so only something meaningfully INSIDE the rim
|
|
3964
|
-
// counts — 1.5 px of slack keeps float noise on the tangent one from hiding a perfectly good bubble.
|
|
3965
|
-
const crossed = segs.some((g) => distToSeg(cx, cy, g[0], g[1], g[2], g[3]) < gridLabelPx / 2 - 1.5);
|
|
3966
|
-
if (crossed) { s.visible = false; continue; }
|
|
3967
|
-
survivors.push(s);
|
|
3968
|
-
}
|
|
3969
|
-
placed.length = 0; placed.push(...survivors);
|
|
3970
|
-
// Selected lines first, so the grid the user is working on can never be the one whose label and pick
|
|
3971
|
-
// target get dropped in favour of an unrelated line that merely sorted earlier.
|
|
3972
|
-
if (selectedGridIds.size) placed.sort((a, b) => (selectedGridIds.has(b.userData.gridId) ? 1 : 0) - (selectedGridIds.has(a.userData.gridId) ? 1 : 0));
|
|
3973
|
-
const kept = [];
|
|
3974
|
-
const min = gridLabelPx * GRID_LABEL_MIN_GAP;
|
|
3975
|
-
for (const s of placed) {
|
|
3976
|
-
const p = _spA.copy(s.position).project(camera); // scratch, not a per-frame clone() — same reason screenPxPerWorld uses one
|
|
3977
|
-
// `z < -1` matters as much as `z > 1`, and ORTHO is this view's default. Under perspective a
|
|
3978
|
-
// behind-camera point flips w and lands z > 1; under ortho w is 1, so it lands z < -1 and used to
|
|
3979
|
-
// sail through — while its x/y stay the geometrically correct in-plane coordinates. It would then
|
|
3980
|
-
// enter `kept` and suppress a bubble that really is on screen.
|
|
3981
|
-
if (!Number.isFinite(p.x) || !Number.isFinite(p.y) || p.z > 1 || p.z < -1) continue; // not on screen, so it can't crowd anything
|
|
3982
|
-
const x = (p.x * 0.5 + 0.5) * w, y = (-p.y * 0.5 + 0.5) * h;
|
|
3983
|
-
if (kept.some((c) => Math.hypot(c.x - x, c.y - y) < min)) { s.visible = false; continue; }
|
|
3984
|
-
kept.push({ x, y });
|
|
3985
|
-
}
|
|
3986
|
-
// pickGridAt raycasts and gridBubblesScreen projects, and both read matrixWorld — which is refreshed
|
|
3987
|
-
// by the render pass, not by writing .position. Without this the build-time call above leaves a probe
|
|
3988
|
-
// in that sub-frame window reporting every bubble at the world origin.
|
|
3989
|
-
gridLabelGroup.updateMatrixWorld(true);
|
|
3990
|
-
}
|
|
3716
|
+
function sizeGridLabels() { structuralGridView?.resizeLabels(); }
|
|
3991
3717
|
|
|
3992
3718
|
// The ortho frustum half-height in world units (set by a fit to the box, or by a projection toggle
|
|
3993
3719
|
// to match the current perspective view). reframeOrtho applies it aspect-preserving on resize, so the
|
|
@@ -4376,7 +4102,7 @@ function ghostPassState(wire) {
|
|
|
4376
4102
|
// Testing a detail as lines would conservatively count a fully clipped plane as visible focus.
|
|
4377
4103
|
return meshContributesPixels(m, wire && !isDetail);
|
|
4378
4104
|
}));
|
|
4379
|
-
const gridFocus = new Set([...selectedGridIds].filter((id) =>
|
|
4105
|
+
const gridFocus = new Set([...selectedGridIds].filter((id) => structuralGridView?.hasVisibleFragment(id)));
|
|
4380
4106
|
if (!meshFocus.size && !gridFocus.size) return { active: false, opacity: 1, meshFocus, gridFocus };
|
|
4381
4107
|
let weakest = gridFocus.size ? 1 : Infinity;
|
|
4382
4108
|
for (const id of meshFocus) { const m = meshById.get(id); const authored = String(id).startsWith('det:') ? (m.userData._detailOpacity == null ? 1 : m.userData._detailOpacity) : (m.material && m.material.opacity == null ? 1 : m.material.opacity); weakest = Math.min(weakest, authored); }
|
|
@@ -4394,23 +4120,10 @@ function ghostMaterial(mesh, source, opacity) {
|
|
|
4394
4120
|
return u._ghostMat;
|
|
4395
4121
|
}
|
|
4396
4122
|
function applyGridGhost(pass) {
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
line.material.color.setHex(focused ? 0x3b82f6 : 0x64748b);
|
|
4402
|
-
line.material.transparent = faded || !focused;
|
|
4403
|
-
line.material.opacity = faded ? pass.opacity : (focused ? 1 : 0.85);
|
|
4404
|
-
line.material.depthWrite = !faded;
|
|
4405
|
-
}
|
|
4406
|
-
if (gridLabelGroup) for (const label of gridLabelGroup.children) {
|
|
4407
|
-
if (!label.material) continue;
|
|
4408
|
-
const id = label.userData && label.userData.gridId;
|
|
4409
|
-
// Elevation tags are shared by the logical grid and intentionally have no line id. Keep them with
|
|
4410
|
-
// grid focus when any selected line survives; with mesh-only focus they belong to Ghost context.
|
|
4411
|
-
const faded = pass.active && (id ? !pass.gridFocus.has(id) : !pass.gridFocus.size);
|
|
4412
|
-
label.material.transparent = true; label.material.opacity = faded ? pass.opacity : 1; label.material.depthWrite = false;
|
|
4413
|
-
}
|
|
4123
|
+
structuralGridView?.applyPaint({
|
|
4124
|
+
selectedIds: selectedGridIds,
|
|
4125
|
+
ghost: { active: pass.active, focusIds: pass.gridFocus, opacity: pass.opacity },
|
|
4126
|
+
});
|
|
4414
4127
|
}
|
|
4415
4128
|
// solid → opaque; wire → EdgesGeometry outline (fill hidden); xray → translucent, no depth write. Applied to
|
|
4416
4129
|
// whatever material each mesh currently carries (shared profile material OR its selection clone).
|
|
@@ -5149,7 +4862,7 @@ function visibleWorldBox() {
|
|
|
5149
4862
|
xrefGroup.updateWorldMatrix(true, false);
|
|
5150
4863
|
for (const g of xrefGroup.children) if (g.visible) box.union(new THREE.Box3().setFromObject(g));
|
|
5151
4864
|
}
|
|
5152
|
-
return box;
|
|
4865
|
+
return structuralGridView?.composeBounds({ meshBounds: box.isEmpty() ? null : box, purpose: 'camera-all' }) ?? box;
|
|
5153
4866
|
}
|
|
5154
4867
|
|
|
5155
4868
|
function frameAllSteel() { fitCamera(visibleWorldBox()); }
|
|
@@ -5159,10 +4872,11 @@ const VIEWS = MODEL_NAMED_VIEWS;
|
|
|
5159
4872
|
function applyViewSteel(name) { const d = VIEWS[name]; if (d) fitCamera(visibleWorldBox(), new THREE.Vector3(d[0], d[1], d[2])); }
|
|
5160
4873
|
// Fit just the selection (Tekla "Zoom selected" / Shift+Space); falls back to fit-all when nothing's picked.
|
|
5161
4874
|
function frameSelectionSteel() {
|
|
5162
|
-
if (!selIds.size) { fitCamera(visibleWorldBox()); return true; }
|
|
4875
|
+
if (!selIds.size && !selectedGridIds.size) { fitCamera(visibleWorldBox()); return true; }
|
|
5163
4876
|
const box = new THREE.Box3();
|
|
5164
4877
|
for (const id of selIds) { const m = meshById.get(id),detail=String(id).startsWith('det:');if(detail&&m&&(m.userData._detailOpacity==null?m.material.opacity:m.userData._detailOpacity)<=0)continue;if(meshContributesPixels(m,displayMode==='wire'&&!detail))box.expandByObject(m); }
|
|
5165
|
-
|
|
4878
|
+
const composed = structuralGridView?.composeBounds({ meshBounds: box.isEmpty() ? null : box, purpose: 'camera-selection', gridOwnerSelected: selectedGridIds.size > 0 }) ?? box;
|
|
4879
|
+
if (!composed || composed.isEmpty()) return false;fitCamera(composed);return true;
|
|
5166
4880
|
}
|
|
5167
4881
|
function onKey(e) {
|
|
5168
4882
|
// NOT "is the canvas visible" — that predicate was written when 2D and 3D were mutually exclusive,
|
|
@@ -6063,30 +5777,9 @@ function pickAt(cx, cy) {
|
|
|
6063
5777
|
lastPick = hits.length ? hits[0].object.userData.id : null;
|
|
6064
5778
|
return lastPick;
|
|
6065
5779
|
}
|
|
6066
|
-
function pickGridAt(cx,cy){
|
|
6067
|
-
if(!structGridLines.size)return null;
|
|
6068
|
-
camera.updateMatrixWorld();const rect=canvasEl.getBoundingClientRect(),ndc=new THREE.Vector2(((cx-rect.left)/rect.width)*2-1,-((cy-rect.top)/rect.height)*2+1);raycaster.setFromCamera(ndc,camera);
|
|
6069
|
-
const bubbles=gridLabelGroup?gridLabelGroup.children.filter(o=>o.visible&&o.userData.gridId):[],bubble=raycaster.intersectObjects(bubbles,false)[0];if(bubble)return {id:bubble.object.userData.gridId,bubble:true,distance:bubble.distance,depth:bubble.point.clone().project(camera).z};
|
|
6070
|
-
// Match WebGL's visible line exactly before measuring in screen pixels. In a close perspective
|
|
6071
|
-
// view a long grid can cross the near plane: projecting its original behind-camera endpoint
|
|
6072
|
-
// either drops a visible segment or creates an invisible pick extension. Clip all six camera-
|
|
6073
|
-
// frustum planes first (after section clipping), then project only the rendered portion.
|
|
6074
|
-
const frustum=gridCameraFrustum();
|
|
6075
|
-
const screen=p=>{const v=new THREE.Vector3(...p).project(camera);return Number.isFinite(v.x)&&Number.isFinite(v.y)?[rect.left+(v.x*.5+.5)*rect.width,rect.top+(-v.y*.5+.5)*rect.height]:null;};
|
|
6076
|
-
let best=null;
|
|
6077
|
-
for(const [id,line] of structGridLines){if(!line.visible)continue;const pts=line.userData.segments||[];for(let i=0;i+1<pts.length;i+=2){const sectionVisible=visibleGridSegment(pts[i],pts[i+1]),vis=sectionVisible&&cameraVisibleGridSegment(sectionVisible,frustum);if(!vis)continue;const a=screen(vis[0]),b=screen(vis[1]);if(!a||!b)continue;const hit=projectPointOnSegment2d([cx,cy],a,b,SEG_DEGENERACY.atMost(0)),pixelDistance=hit.distance;if(pixelDistance>8)continue;const clip0=new THREE.Vector4(...vis[0],1).applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix),clip1=new THREE.Vector4(...vis[1],1).applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix),t=perspectiveSegmentParameter(hit.t,clip0.w,clip1.w),world=[vis[0][0]+(vis[1][0]-vis[0][0])*t,vis[0][1]+(vis[1][1]-vis[0][1])*t,vis[0][2]+(vis[1][2]-vis[0][2])*t],worldPoint=new THREE.Vector3(...world),distance=camera.position.distanceTo(worldPoint),depth=worldPoint.clone().project(camera).z;if(!best||pixelDistance<best.pixelDistance-0.01||(Math.abs(pixelDistance-best.pixelDistance)<=0.01&&distance<best.distance))best={id,bubble:false,distance,depth,pixelDistance};}}
|
|
6078
|
-
return best;
|
|
6079
|
-
}
|
|
6080
|
-
|
|
6081
5780
|
function applyGridVisibility(){
|
|
6082
5781
|
invalidateCameraClipBounds();
|
|
6083
|
-
|
|
6084
|
-
for(const [id,line] of structGridLines){const on=(isolatedGridIds===null||isolatedGridIds.has(id))&&!gridSelectionHidden.has(id);line.visible=on;if(on)anyLine=true;}
|
|
6085
|
-
// `allowed` is the visibility DECISION; sizeGridLabels() re-applies it every frame and may additionally
|
|
6086
|
-
// drop a bubble that collides with another on screen. Split in two so the declutter pass can never be
|
|
6087
|
-
// mistaken for an isolate/hide filter, and so this one stays the single authority on which grid shows.
|
|
6088
|
-
if(gridLabelGroup)for(const label of gridLabelGroup.children){const id=label.userData&&label.userData.gridId;const allowed=id?((isolatedGridIds===null||isolatedGridIds.has(id))&&!gridSelectionHidden.has(id)):anyLine;label.userData.allowed=allowed;label.visible=allowed;}
|
|
6089
|
-
sizeGridLabels();
|
|
5782
|
+
structuralGridView?.setVisibility({ hiddenIds: gridSelectionHidden, isolatedIds: isolatedGridIds });
|
|
6090
5783
|
}
|
|
6091
5784
|
function reconcileGridVisibilityState(scopeChanged=false){
|
|
6092
5785
|
const next=reconcileGridTransientState({
|
|
@@ -8326,8 +8019,8 @@ function onDown(e) {
|
|
|
8326
8019
|
const ep = endpointHit;
|
|
8327
8020
|
if (ep) { e.stopPropagation(); controls.enabled = false; startEndpointGrab(ep, e); return; }
|
|
8328
8021
|
}
|
|
8329
|
-
let
|
|
8330
|
-
|
|
8022
|
+
let allMeshHits=[],selectionWinner=null;try{allMeshHits=meshHitsAt(e.clientX,e.clientY);selectionWinner=structuralGridView?.pick({clientX:e.clientX,clientY:e.clientY,meshHits:allMeshHits,isOpaqueOccluder:(hit)=>OPAQUE_MODES.has(displayMode)&&occludesGrid(hit),raycaster});}catch(err){console.error('steel-3d: shared grid/mesh hit-test failed',err);}const gridAllowed=!api||!api.canSelectGrid||api.canSelectGrid(),gridInFront=selectionWinner?.kind==='grid',gridHit=gridInFront?selectionWinner:null;const selectableMeshBehind=allMeshHits.some((hit)=>{const candidateId=hit.object?.userData?.id;return candidateId&&(!api?.canSelectId||api.canSelectId(candidateId));});if(gridHit&&!gridAllowed&&!selectableMeshBehind){e.stopPropagation();controls.enabled=false;pending={filteredGrid:true};return;} // A filtered-only grid is inert. When selectable geometry overlaps it, the shared hit stack filters the grid and keeps the geometry reachable. RIGHT-drag orbit is separate.
|
|
8023
|
+
if(gridAllowed&&gridHit){e.stopPropagation();controls.enabled=false;pending={gridId:gridHit.id,add:e.ctrlKey||e.metaKey||e.shiftKey};return;} // The shared grid object owns projected depth arbitration; Wire/X-ray fills do not phantom-occlude a visible grid.
|
|
8331
8024
|
// Consume a filtered reference on DOWN, before it can become an empty-space box/click gesture. The
|
|
8332
8025
|
// up-side picker repeats this guard defensively, but a real pointer lifecycle may otherwise clear the
|
|
8333
8026
|
// current native selection before that late raycast gets a vote.
|
|
@@ -8723,11 +8416,7 @@ function detailsInRect(x0, y0, x1, y1, windowMode) {
|
|
|
8723
8416
|
}
|
|
8724
8417
|
return out;
|
|
8725
8418
|
}
|
|
8726
|
-
|
|
8727
|
-
function visibleGridSegment(a,b){return clipSegmentToPlanes(a,b,gridPlaneSpecs(renderer&&renderer.clippingPlanes));}
|
|
8728
|
-
function gridCameraFrustum(){camera.updateMatrixWorld();return new THREE.Frustum().setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse));}
|
|
8729
|
-
function cameraVisibleGridSegment(p,frustum){return clipSegmentToPlanes(p[0],p[1],gridPlaneSpecs(frustum&&frustum.planes));}
|
|
8730
|
-
function gridsInRect(x0,y0,x1,y1,windowMode){const rect=canvasEl.getBoundingClientRect(),r=[Math.min(x0,x1),Math.min(y0,y1),Math.max(x0,x1),Math.max(y0,y1)],out=[],frustum=gridCameraFrustum();const screen=p=>{const v=new THREE.Vector3(...p).project(camera);return Number.isFinite(v.x)&&Number.isFinite(v.y)?[rect.left+(v.x*.5+.5)*rect.width,rect.top+(-v.y*.5+.5)*rect.height]:null;};for(const [id,line] of structGridLines){if(!line.visible)continue;const pts=line.userData.segments||[];let hit=false;for(let i=0;i+1<pts.length;i+=2){const sectionVisible=visibleGridSegment(pts[i],pts[i+1]),vis=sectionVisible&&cameraVisibleGridSegment(sectionVisible,frustum);if(!vis)continue;const a=screen(vis[0]),b=screen(vis[1]);if(!a||!b)continue;if(segmentHitsRect2d(a,b,r,windowMode)){hit=true;break;}}if(hit)out.push(id);}return out;} // Keep visible raw hits even when grid selection is filtered off; the host batch filter uses them to make filtered-only marquees inert instead of clearing the current selection. Visibility-hidden grids never become phantom box hits.
|
|
8419
|
+
function gridsInRect(x0,y0,x1,y1,windowMode){return structuralGridView?.rectangleHits(x0,y0,x1,y1,windowMode) ?? [];} // Keep visible raw hits even when grid selection is filtered off; the host batch filter uses them to make filtered-only marquees inert instead of clearing the current selection. Visibility-hidden grids never become phantom box hits.
|
|
8731
8420
|
// Connection Components whose screen footprint (projected bbox) meets a marquee rect — so area-select picks
|
|
8732
8421
|
// up connections, not just members. window: the whole footprint enclosed · crossing: it overlaps the rect.
|
|
8733
8422
|
function connsInRect(x0, y0, x1, y1, windowMode) {
|
|
@@ -9390,12 +9079,11 @@ function disposeSteel() {
|
|
|
9390
9079
|
clearReferenceGhosts();
|
|
9391
9080
|
xrefGroup = null; xrefById.clear(); xrefSelected = null; invalidateCameraClipBounds();
|
|
9392
9081
|
xrefSubSelected = null; xrefSubMesh = null; xrefSubMats = null;
|
|
9393
|
-
|
|
9082
|
+
structuralGridView?.dispose(); structuralGridView = null;
|
|
9083
|
+
structGridGroup = gridLabelGroup = null; structGridLines = new Map(); gridLevelsMm = [];
|
|
9394
9084
|
clearWireEdges();
|
|
9395
9085
|
if (scene) scene.environment = null;
|
|
9396
9086
|
if (envRT) envRT.dispose(); envRT = null; envFailed = false;
|
|
9397
|
-
for (const tex of gridTexCache.values()) tex.dispose();
|
|
9398
|
-
gridTexCache.clear();
|
|
9399
9087
|
clearRoot();
|
|
9400
9088
|
if (workAreaHelper) { if (overlayScene) overlayScene.remove(workAreaHelper); workAreaHelper.geometry.dispose(); workAreaHelper.material.dispose(); workAreaHelper = null; }
|
|
9401
9089
|
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)
|
|
@@ -9575,11 +9263,9 @@ function selectionHitAtScreen(x,y){let own=null,ref=null;try{own=pickAt(x,y);}ca
|
|
|
9575
9263
|
// test helper: projected, clip-trimmed structural-grid segments. E2E uses these coordinates to drive a
|
|
9576
9264
|
// real line click / marquee without guessing where an oblique 3D line landed after camera fitting.
|
|
9577
9265
|
function gridSegmentsScreen() {
|
|
9578
|
-
|
|
9579
|
-
for(const [id,line] of structGridLines){const pts=line.userData.segments||[];for(let i=0;i+1<pts.length;i+=2){const sectionVisible=visibleGridSegment(pts[i],pts[i+1]),vis=sectionVisible&&cameraVisibleGridSegment(sectionVisible,frustum);if(!vis)continue;const a=toScreen(vis[0]),b=toScreen(vis[1]);out.push({id,a:{x:rect.left+a.x,y:rect.top+a.y},b:{x:rect.left+b.x,y:rect.top+b.y}});}}
|
|
9580
|
-
return out;
|
|
9266
|
+
return structuralGridView?.segmentsScreen() ?? [];
|
|
9581
9267
|
}
|
|
9582
|
-
function gridBubblesScreen(){
|
|
9268
|
+
function gridBubblesScreen(){return structuralGridView?.bubblesScreen() ?? [];}
|
|
9583
9269
|
window.Steel3DView = {
|
|
9584
9270
|
init, show, hide, setInputActive, rebuild, setSelection, setGridSelection, setSelectionState, commitSelection, viewportState, isReady, dispose,
|
|
9585
9271
|
setProjection, projection, setDisplayMode, mode: () => displayMode, frameAll, frameSelection, applyView,
|
|
@@ -9655,10 +9341,10 @@ window.Steel3DView = {
|
|
|
9655
9341
|
selLenLabelTexts: () => selLenLabelPool.filter((el) => el.style.display !== 'none' && el.style.visibility !== 'hidden').map((el) => el.textContent), // visible on-select length chips — for tests
|
|
9656
9342
|
epScreen: (id) => { const m = memberById(id); if (!m || !canvasEl) return null; const g = geoOf(m); const rect = canvasEl.getBoundingClientRect(); const proj = (p) => { const v = new THREE.Vector3(p[0], p[1], p[2]).project(camera); return { x: rect.left + (v.x * 0.5 + 0.5) * rect.width, y: rect.top + (-v.y * 0.5 + 0.5) * rect.height }; }; return { a: proj(g.line[0]), b: proj(g.line[1]) }; }, // project a member's endpoints to viewport px — test probe for endpoint-drag tests
|
|
9657
9343
|
refreshGrid: () => { buildStructGrid(); applyDisplayMode(); }, // grid edited in the panel → rebuild, then re-derive Ghost against the fresh line/label materials
|
|
9658
|
-
setGridLabelPx: (px) => { gridLabelPx = clampGridLabelPx(px);
|
|
9344
|
+
setGridLabelPx: (px) => { gridLabelPx = clampGridLabelPx(px); structuralGridView?.setLabelPx(gridLabelPx); }, // ⋯ ▸ Display ▸ Grid label size — no rebuild needed, the labels are re-placed every frame anyway
|
|
9659
9345
|
gridLabelPx: () => gridLabelPx,
|
|
9660
9346
|
armGridLinePick3d, gridLinePick3dState: () => (gridLinePick3d ? { armed: true, hasFirst: !!gridLinePick3d.a, a: gridLinePick3d.a || null } : { armed: false, hasFirst: false, a: null }), // grid panel "Add single line" in 3D (+ test probe)
|
|
9661
|
-
gridInfo: () => ({ lines:
|
|
9347
|
+
gridInfo: () => structuralGridView?.info() ?? ({ lines: 0, labels: 0, labelTexts: [], lineOpacities: [], labelOpacities: [], selected: [], ids: [], visible: [], hidden: [], isolated: null }), // test helper
|
|
9662
9348
|
wpProbe: () => { // test helper: the "Show plane" reference surface — asserts no grid, bbox-sized surface, light-blue colour. `extent` is the projected u/v footprint the surface was actually sized to (work-area/tilted-plane aware), null for the fallback square. Surface w == extent.uSpan + 2*extent.margin.
|
|
9663
9349
|
if (!wpGroup) return { group: false, extent: wpExtent };
|
|
9664
9350
|
return { group: true, extent: wpExtent, children: wpGroup.children.map((c) => ({ type: c.type, color: c.material && '#' + c.material.color.getHexString(), opacity: c.material && c.material.opacity, w: c.geometry && c.geometry.parameters ? c.geometry.parameters.width : null, h: c.geometry && c.geometry.parameters ? c.geometry.parameters.height : null })) };
|