@floless/app 0.101.0 → 0.101.2

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.
@@ -17,7 +17,7 @@
17
17
  import * as THREE from 'three';
18
18
  import { OrbitControls } from 'three/addons/OrbitControls.js';
19
19
  import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
20
- import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint } from './steel-3d-core.js';
20
+ import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d } from './steel-3d-core.js';
21
21
  import { gridGeometry, gridCandidates3d, mmPerPx } from './grid-core.js';
22
22
 
23
23
  let renderer, scene, perspCam, orthoCam, camera, controls, root, api, canvasEl, ro, rafId, grid, raycaster, downXY, lastPick = '(none)';
@@ -890,6 +890,8 @@ function positionSelLenLabels() {
890
890
  // the contract via api.getGrid() (grid-core owns parsing/geometry); allCandidates() feeds the same
891
891
  // grid into snapping, plan-locked.
892
892
  let structGridGroup = null, gridLabelGroup = null;
893
+ const structGridLines = new Map();
894
+ let selectedGridIds = new Set();
893
895
  const gridTexCache = new Map(); // 'b:LABEL' bubble / 't:LABEL' tag -> CanvasTexture (kept until dispose)
894
896
 
895
897
  // Snap targets for the 3D tools. Members come from the WHOLE model — every sheet, not just the active
@@ -924,14 +926,14 @@ function gridBubbleTexture(label) {
924
926
  function gridTagTexture(label) {
925
927
  const key = 't:' + label;
926
928
  if (gridTexCache.has(key)) return gridTexCache.get(key);
927
- const W = 256, H = 80, cv = document.createElement('canvas'); cv.width = W; cv.height = H;
929
+ const W = 512, H = 80, cv = document.createElement('canvas'); cv.width = W; cv.height = H;
928
930
  const g = cv.getContext('2d');
929
931
  g.beginPath(); g.roundRect(4, 4, W - 8, H - 8, 14);
930
932
  g.fillStyle = '#0f172a'; g.fill();
931
933
  g.lineWidth = 4; g.strokeStyle = '#64748b'; g.stroke();
932
- g.fillStyle = '#94a3b8'; g.font = 'bold 40px system-ui';
934
+ 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';}
933
935
  g.textAlign = 'center'; g.textBaseline = 'middle';
934
- g.fillText(label, W / 2, H / 2 + 2);
936
+ 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
935
937
  const tex = new THREE.CanvasTexture(cv);
936
938
  gridTexCache.set(key, tex);
937
939
  return tex;
@@ -942,7 +944,7 @@ function clearStructGrid() {
942
944
  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
943
945
  if (parent) parent.remove(grp);
944
946
  }
945
- structGridGroup = gridLabelGroup = null;
947
+ structGridGroup = gridLabelGroup = null;structGridLines.clear();
946
948
  }
947
949
  function buildStructGrid() {
948
950
  clearStructGrid();
@@ -954,38 +956,30 @@ function buildStructGrid() {
954
956
  const k = mmPerPx(api.ptPerFt());
955
957
  const mmX = (px) => px * k, mmY = (px) => -px * k; // display → scene (Y flips)
956
958
  const levels = geo.zs.length ? geo.zs : [{ mm: 0, label: '0' }];
957
- const pts = [];
958
- for (const lv of levels) {
959
- const z = lv.mm - 25; // sit just under the steel at the level (no z-fight/burial)
960
- for (const l of geo.v) pts.push(V(mmX(l.x), mmY(l.lo), z), V(mmX(l.x), mmY(l.hi), z));
961
- for (const l of geo.h) pts.push(V(mmX(l.lo), mmY(l.y), z), V(mmX(l.hi), mmY(l.y), z));
962
- for (const l of geo.lines || []) pts.push(V(mmX(l.a[0]), mmY(l.a[1]), z), V(mmX(l.b[0]), mmY(l.b[1]), z));
963
- }
964
959
  structGridGroup = new THREE.Group();
965
- const seg = new THREE.LineSegments(
966
- new THREE.BufferGeometry().setFromPoints(pts),
967
- new THREE.LineDashedMaterial({ color: 0x64748b, dashSize: 450, gapSize: 220, transparent: true, opacity: 0.85 }),
968
- );
969
- seg.computeLineDistances();
970
- structGridGroup.add(seg);
960
+ const addLogical=(id,ends)=>{const pts=[];for(const lv of levels){const z=lv.mm-25;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);};
961
+ geo.v.forEach((l,i)=>addLogical('gv:'+i,[[mmX(l.x),mmY(l.lo)],[mmX(l.x),mmY(l.hi)]]));
962
+ geo.h.forEach((l,i)=>addLogical('gh:'+i,[[mmX(l.lo),mmY(l.y)],[mmX(l.hi),mmY(l.y)]]));
963
+ (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])]]));
971
964
  scene.add(structGridGroup);
972
965
  gridLabelGroup = new THREE.Group();
973
966
  const span = Math.max((geo.x1 - geo.x0) * k, (geo.y1 - geo.y0) * k, 1);
974
967
  const dia = Math.min(Math.max(span * 0.035, 400), 3000); // bubble ⌀ scales with the grid, clamped sane
975
968
  const z0 = levels[0].mm;
976
- const sprite = (tex, x, y, z, w, h) => {
969
+ const sprite = (tex, x, y, z, w, h, label, gridId) => {
977
970
  // depthTest ON so steel in FRONT occludes the bubble/level tag (B7). The overlay pass runs with the
978
971
  // depth buffer from pass 1 (members) intact — autoClear is off — so this occludes against the steel
979
972
  // WITHOUT moving the labels out of overlayScene: they stay unclipped, so a section plane still can't
980
973
  // cut them (the clip-regression guard above holds).
981
974
  const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, depthTest: true, depthWrite: false, transparent: true }));
975
+ s.userData.label=String(label||'');s.userData.gridId=gridId||null;
982
976
  s.position.set(x, y, z); s.scale.set(w, h, 1); s.renderOrder = 994;
983
977
  gridLabelGroup.add(s);
984
978
  };
985
- for (const l of geo.v) { sprite(gridBubbleTexture(l.label), mmX(l.x), mmY(l.lo), z0, dia, dia); sprite(gridBubbleTexture(l.label), mmX(l.x), mmY(l.hi), z0, dia, dia); }
986
- for (const l of geo.h) { sprite(gridBubbleTexture(l.label), mmX(l.lo), mmY(l.y), z0, dia, dia); sprite(gridBubbleTexture(l.label), mmX(l.hi), mmY(l.y), z0, dia, dia); }
987
- for (const l of geo.lines || []) { sprite(gridBubbleTexture(l.label), mmX(l.a[0]), mmY(l.a[1]), z0, dia, dia); sprite(gridBubbleTexture(l.label), mmX(l.b[0]), mmY(l.b[1]), z0, dia, dia); }
988
- if (geo.zs.length > 1) for (const lv of geo.zs) sprite(gridTagTexture(lv.label), mmX(geo.x0), mmY(geo.y1), lv.mm, dia * 2.4, dia * 0.75); // level tags up the near corner
979
+ geo.v.forEach((l,i)=>{const id='gv:'+i;sprite(gridBubbleTexture(l.label), mmX(l.x), mmY(l.lo), z0, dia, dia,l.label,id); sprite(gridBubbleTexture(l.label), mmX(l.x), mmY(l.hi), z0, dia, dia,l.label,id);});
980
+ geo.h.forEach((l,i)=>{const id='gh:'+i;sprite(gridBubbleTexture(l.label), mmX(l.lo), mmY(l.y), z0, dia, dia,l.label,id); sprite(gridBubbleTexture(l.label), mmX(l.hi), mmY(l.y), z0, dia, dia,l.label,id);});
981
+ (geo.lines || []).forEach((l,i)=>{const id='gl:'+(l.id!=null?l.id:i);sprite(gridBubbleTexture(l.label), mmX(l.a[0]), mmY(l.a[1]), z0, dia, dia,l.label,id); sprite(gridBubbleTexture(l.label), mmX(l.b[0]), mmY(l.b[1]), z0, dia, dia,l.label,id);});
982
+ if (geo.zs.length) for (const lv of geo.zs) sprite(gridTagTexture(lv.label), mmX(geo.x0), mmY(geo.y1), lv.mm, dia * 4.8, dia * 0.75,lv.label); // 6.4:1 sprite matches the tag texture, so long elevation labels stay undistorted
989
983
  overlayScene.add(gridLabelGroup);
990
984
  }
991
985
 
@@ -1163,6 +1157,11 @@ function visibleIgnoringWorkArea(m) {
1163
1157
  function applyGroupVisibility() {
1164
1158
  for (const m of meshById.values()) m.visible = visibleIgnoringWorkArea(m) && meshInWorkArea(m); // meshInWorkArea: work-area whole-parts spatial filter
1165
1159
  }
1160
+ function visibleMemberIds() {
1161
+ const out = [];
1162
+ for (const [id, m] of meshById) if (m.visible && !m.userData.derived) out.push(id);
1163
+ return out;
1164
+ }
1166
1165
  function toggleGroup(k) { if (groupHidden.has(k)) groupHidden.delete(k); else groupHidden.add(k); soloGroups.clear(); applyGroupVisibility(); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); }
1167
1166
  // Hide/show a SET of groups in one pass (a legend type-category master toggle) — deterministic (not a flip),
1168
1167
  // so "hide all" / "show all" for the category is exact. Clears solo, like toggleGroup.
@@ -2205,27 +2204,43 @@ function syncTriad() { triad.group.quaternion.copy(camera.quaternion).invert();
2205
2204
  // front view, etc.) by orienting the cube by the inverse of the camera's world rotation.
2206
2205
  function syncCube() { cube.mesh.quaternion.copy(camera.quaternion).invert(); }
2207
2206
 
2208
- // Raycast the member meshes at a client (px) point → the hit member id, or null for empty space.
2209
- // Only VISIBLE meshes (a legend-hidden group must not swallow the pick for what's behind it).
2210
- function pickAt(cx, cy) {
2207
+ // Raycast the member meshes at a client (px) point → visible, clip-filtered hits nearest-first.
2208
+ // Only VISIBLE meshes are included (a legend-hidden group must not swallow what's behind it).
2209
+ function meshHitsAt(cx,cy,primaryOnly=false) {
2211
2210
  camera.updateMatrixWorld(); root.updateMatrixWorld(true); // ensure current after any camera/mesh move
2212
2211
  const rect = canvasEl.getBoundingClientRect();
2213
2212
  const ndc = new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1);
2214
2213
  raycaster.setFromCamera(ndc, camera);
2215
- const hits = raycaster.intersectObjects([...meshById.values()].filter((m) => m.visible && !m.userData.derived), false);
2214
+ return raycaster.intersectObjects([...meshById.values()].filter((m) => m.visible && (!primaryOnly || !m.userData.derived)), false).filter(h=>!isPointClipped([h.point.x,h.point.y,h.point.z]));
2215
+ }
2216
+ function pickAt(cx, cy) {
2217
+ // Primary member id under the pointer, or null for empty space.
2218
+ const hits = meshHitsAt(cx,cy,true);
2216
2219
  lastPick = hits.length ? hits[0].object.userData.id : null;
2217
2220
  return lastPick;
2218
2221
  }
2222
+ function pickGridAt(cx,cy){
2223
+ if(!structGridLines.size)return null;
2224
+ 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);
2225
+ 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};
2226
+ // Match WebGL's visible line exactly before measuring in screen pixels. In a close perspective
2227
+ // view a long grid can cross the near plane: projecting its original behind-camera endpoint
2228
+ // either drops a visible segment or creates an invisible pick extension. Clip all six camera-
2229
+ // frustum planes first (after section clipping), then project only the rendered portion.
2230
+ const frustum=gridCameraFrustum();
2231
+ 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;};
2232
+ let best=null;
2233
+ 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=pointSegmentDistance2d([cx,cy],a,b),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};}}
2234
+ return best;
2235
+ }
2236
+
2237
+ function setGridSelection(ids){selectedGridIds=ids instanceof Set?new Set(ids):new Set(ids||[]);for(const [id,line] of structGridLines){line.material.color.setHex(selectedGridIds.has(id)?0x3b82f6:0x64748b);line.material.opacity=selectedGridIds.has(id)?1:0.85;}}
2219
2238
  // Raycast ALL visible meshes — members AND derived connection parts — at a client point → ids
2220
2239
  // front-to-back (nearest first), deduped. Backs click-to-cycle so a small plate/bolt/weld stacked on a
2221
2240
  // beam at a joint is reachable without a modifier (D). pickAt stays members-only — the down-gesture
2222
2241
  // (drag / box-select / geo-edit) and the dim-tool plane pick; hover uses pickAllAt so derived parts get the select cursor.
2223
2242
  function pickAllAt(cx, cy) {
2224
- camera.updateMatrixWorld(); root.updateMatrixWorld(true);
2225
- const rect = canvasEl.getBoundingClientRect();
2226
- const ndc = new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1);
2227
- raycaster.setFromCamera(ndc, camera);
2228
- const hits = raycaster.intersectObjects([...meshById.values()].filter((m) => m.visible), false);
2243
+ const hits = meshHitsAt(cx,cy);
2229
2244
  const ids = [];
2230
2245
  for (const h of hits) { const id = h.object.userData.id; if (id && !ids.includes(id)) ids.push(id); }
2231
2246
  return ids;
@@ -2297,6 +2312,17 @@ function selectWholeConn(conn) {
2297
2312
  renderConnEnvelope(conn);
2298
2313
  if (api && api.onSelectMany) api.onSelectMany(kids);
2299
2314
  }
2315
+ function selectWholeConnWithGrids(conn, gridIds) {
2316
+ const kids = conn ? connChildIds(conn) : [];
2317
+ if (!conn || !kids.length) return clearConnSel();
2318
+ const selectableKids = api && api.canSelectId ? kids.filter(api.canSelectId) : kids;
2319
+ const selectableGrid = (gridIds || []).length && (!api || !api.canSelectGrid || api.canSelectGrid());
2320
+ if (!selectableKids.length && !selectableGrid) return; // a wholly filtered batch is inert, including its existing whole/drilled connection context
2321
+ if (selectableKids.length) { selConn = conn; ctxConn = null; renderConnEnvelope(conn); }
2322
+ else resetConnState(); // a filtered connection may share the box with an allowed grid; never show a phantom envelope
2323
+ if (api && api.onSelectBatch) api.onSelectBatch({ memberIds: kids, gridIds: gridIds || [] }, false);
2324
+ else selectWholeConn(conn);
2325
+ }
2300
2326
  // Clear any connection selection/drill (back to bare Model root — deselects).
2301
2327
  function clearConnSel() { resetConnState(); if (api && api.onSelect) api.onSelect(null, false); }
2302
2328
  // Enter a connection (double-click) and select the part under the cursor — the drill-in step.
@@ -3202,6 +3228,8 @@ function onDown(e) {
3202
3228
  // An end node (the yellow/magenta dot) under the cursor → grab just that endpoint to stretch the member.
3203
3229
  let ep = null; try { ep = pickEndpoint(e.clientX, e.clientY); } catch { ep = null; }
3204
3230
  if (ep) { e.stopPropagation(); controls.enabled = false; startEndpointGrab(ep, e); return; }
3231
+ let gridHit=null,allMeshHits=[];try{gridHit=pickGridAt(e.clientX,e.clientY);}catch(err){console.error('steel-3d: grid hit-test failed',err);}try{allMeshHits=meshHitsAt(e.clientX,e.clientY);}catch(err){console.error('steel-3d: mesh hit-test failed',err);}const gridAllowed=!api||!api.canSelectGrid||api.canSelectGrid(),gridOccluders=displayMode==='solid'?allMeshHits:[],meshDepth=gridOccluders.length?gridOccluders[0].point.clone().project(camera).z:Infinity,gridInFront=gridHit&&gridDepthWins(gridHit.depth,meshDepth);if(gridHit&&!gridAllowed&&gridInFront){e.stopPropagation();controls.enabled=false;pending={filteredGrid:true};return;} // Deliberately consume the LEFT select gesture like 2D when the visible grid is frontmost: a filtered grid stays inert and preserves selection. RIGHT-drag orbit is a separate handler.
3232
+ const gridWins=gridAllowed&&gridHit&&gridInFront;if(gridWins){e.stopPropagation();controls.enabled=false;pending={gridId:gridHit.id,add:e.ctrlKey||e.metaKey||e.shiftKey};return;} // Compare projected depth in Solid; Wire/X-ray fills do not write depth and therefore cannot phantom-occlude a visible grid.
3205
3233
  if (!id) { pending = null; boxSel = { x: e.clientX, y: e.clientY }; return; } // empty space → box-select on drag
3206
3234
  e.stopPropagation(); controls.enabled = false; // grabbed a member → suppress orbit (enabled=false is the reliable guard)
3207
3235
  try {
@@ -3285,6 +3313,7 @@ function onMove(e) {
3285
3313
  if (pending && pending.clipDrag) { onMoveClip(e); return; } // dragging a clip handle (plane offset / box face)
3286
3314
  if (pending && pending.frameDrag) { onMoveFrame(e); return; } // dragging the local-frame origin / rotation ring
3287
3315
  if (!pending || pending.geo) return;
3316
+ if (pending.gridId||pending.filteredGrid) { 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; } // any grid press becomes a normal marquee once it moves, even when grid selection is filtered off; only a true click stays grid-specific/inert
3288
3317
  if (pending.epDrag) { onMoveEndpoint(e); return; }
3289
3318
  if (!pending.grab || !pending.origMm) return;
3290
3319
  if (!dragging && Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) <= DRAG_TOL_PX) return;
@@ -3343,11 +3372,7 @@ function onBoxMove(e) {
3343
3372
  // --- Tekla-style area select: point/segment vs screen rect [x0,y0,x1,y1]. window = both ends enclosed
3344
3373
  // (L→R drag); crossing = the member's screen footprint touches the rect (R→L drag). Same math the 2D marquee uses. ---
3345
3374
  function _inRect(p, r) { return p[0] >= r[0] && p[0] <= r[2] && p[1] >= r[1] && p[1] <= r[3]; }
3346
- function _ccw(a, b, c) { return (c[1] - a[1]) * (b[0] - a[0]) - (b[1] - a[1]) * (c[0] - a[0]); }
3347
- function _segSeg(a, b, c, d) { return (_ccw(a, c, d) > 0) !== (_ccw(b, c, d) > 0) && (_ccw(a, b, c) > 0) !== (_ccw(a, b, d) > 0); }
3348
- function _rectHit(p0, p1, r) { if (_inRect(p0, r) || _inRect(p1, r)) return true; const c = [[r[0], r[1]], [r[2], r[1]], [r[2], r[3]], [r[0], r[3]]]; for (let i = 0; i < 4; i++) if (_segSeg(p0, p1, c[i], c[(i + 1) % 4])) return true; return false; }
3349
- const _boxEdges = [[0, 1], [0, 2], [0, 4], [3, 1], [3, 2], [3, 7], [5, 1], [5, 4], [5, 7], [6, 2], [6, 4], [6, 7]];
3350
- function _rectOverlap(a, r) { return a && a[0] <= r[2] && a[2] >= r[0] && a[1] <= r[3] && a[3] >= r[1]; }
3375
+ function _rectHit(p0, p1, r) { return segmentHitsRect2d(p0, p1, r, false); }
3351
3376
  function memberFootprintHit(mesh, r, windowMode, rect) {
3352
3377
  if (!mesh || !mesh.geometry) return false;
3353
3378
  if (!mesh.geometry.boundingBox) mesh.geometry.computeBoundingBox();
@@ -3355,21 +3380,16 @@ function memberFootprintHit(mesh, r, windowMode, rect) {
3355
3380
  if (!b || b.isEmpty()) return false;
3356
3381
  mesh.updateMatrixWorld(true);
3357
3382
  const pts = [];
3358
- let sx0 = Infinity, sy0 = Infinity, sx1 = -Infinity, sy1 = -Infinity, behind = false;
3383
+ let behind = false;
3359
3384
  for (let i = 0; i < 8; i++) {
3360
3385
  const p = new THREE.Vector3(i & 1 ? b.max.x : b.min.x, i & 2 ? b.max.y : b.min.y, i & 4 ? b.max.z : b.min.z).applyMatrix4(mesh.matrixWorld);
3361
3386
  const v = p.project(camera);
3362
3387
  if (v.z > 1) { behind = true; break; }
3363
3388
  const s = [rect.left + (v.x * 0.5 + 0.5) * rect.width, rect.top + (-v.y * 0.5 + 0.5) * rect.height];
3364
- pts.push(s); sx0 = Math.min(sx0, s[0]); sy0 = Math.min(sy0, s[1]); sx1 = Math.max(sx1, s[0]); sy1 = Math.max(sy1, s[1]);
3389
+ pts.push(s);
3365
3390
  }
3366
3391
  if (behind || !pts.length) return false;
3367
- if (windowMode) return pts.every((p) => _inRect(p, r));
3368
- if (!_rectOverlap([sx0, sy0, sx1, sy1], r)) return false;
3369
- if (pts.some((p) => _inRect(p, r))) return true;
3370
- const rc = [[r[0], r[1]], [r[2], r[1]], [r[2], r[3]], [r[0], r[3]]];
3371
- for (const [a, b] of _boxEdges) for (let i = 0; i < 4; i++) if (_segSeg(pts[a], pts[b], rc[i], rc[(i + 1) % 4])) return true;
3372
- return true; // overlapping projected solid AABBs still count for crossing; avoids missing thick/vertical members.
3392
+ return projectedFootprintHitsRect2d(pts, r, windowMode); // crossing uses the projected solid hull, avoiding both centreline misses and rotated-AABB false positives.
3373
3393
  }
3374
3394
  // every VISIBLE member whose projected centreline meets the drag rect — window: both ends inside · crossing: touches
3375
3395
  function membersInRect(x0, y0, x1, y1, windowMode) {
@@ -3398,6 +3418,11 @@ function membersInRect(x0, y0, x1, y1, windowMode) {
3398
3418
  }
3399
3419
  return out;
3400
3420
  }
3421
+ const gridPlaneSpecs=planes=>(planes||[]).map(p=>({normal:[p.normal.x,p.normal.y,p.normal.z],constant:p.constant}));
3422
+ function visibleGridSegment(a,b){return clipSegmentToPlanes(a,b,gridPlaneSpecs(renderer&&renderer.clippingPlanes));}
3423
+ function gridCameraFrustum(){camera.updateMatrixWorld();return new THREE.Frustum().setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse));}
3424
+ function cameraVisibleGridSegment(p,frustum){return clipSegmentToPlanes(p[0],p[1],gridPlaneSpecs(frustum&&frustum.planes));}
3425
+ 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){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 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.
3401
3426
  // Connection Components whose screen footprint (projected bbox) meets a marquee rect — so area-select picks
3402
3427
  // up connections, not just members. window: the whole footprint enclosed · crossing: it overlaps the rect.
3403
3428
  function connsInRect(x0, y0, x1, y1, windowMode) {
@@ -3433,7 +3458,10 @@ function onUp(e) {
3433
3458
  const additive = e.ctrlKey || e.metaKey || e.shiftKey; // Ctrl/Shift → toggle the framed set into the current selection (add/remove), else replace
3434
3459
  const memberIds = membersInRect(bs.x, bs.y, e.clientX, e.clientY, windowMode);
3435
3460
  const connIds = connsInRect(bs.x, bs.y, e.clientX, e.clientY, windowMode);
3436
- if (!additive && !memberIds.length && connIds.length === 1) selectWholeConn(connIds[0]); // a lone connection framed (no modifier) → full component select (envelope + inspector), same as a click
3461
+ const gridIds=gridsInRect(bs.x,bs.y,e.clientX,e.clientY,windowMode);
3462
+ if(gridIds.length&&!additive&&!memberIds.length&&connIds.length===1)selectWholeConnWithGrids(connIds[0],gridIds); // preserve the whole-connection envelope/crumb when the same replacement marquee also catches a grid
3463
+ else if(gridIds.length&&api&&api.onSelectBatch){if(!additive)resetConnState();api.onSelectBatch({memberIds:[...memberIds,...connIds.flatMap(c=>connChildIds(c))],gridIds},additive);}
3464
+ else if (!additive && !memberIds.length && connIds.length === 1) selectWholeConn(connIds[0]); // a lone connection framed (no modifier) → full component select (envelope + inspector), same as a click
3437
3465
  else { resetConnState(); const ids = [...memberIds, ...connIds.flatMap((c) => connChildIds(c))]; if (api && api.onSelectMany) api.onSelectMany(ids, additive); } // members and/or several connections → multi-select (replace, or Ctrl/Shift-toggle) INCLUDING the connections' parts
3438
3466
  }
3439
3467
  else clickSelect(e.clientX, e.clientY, e.ctrlKey || e.metaKey || e.shiftKey); // click in empty space → cycle-pick (may land on a derived part) or clear
@@ -3443,6 +3471,8 @@ function onUp(e) {
3443
3471
  controls.enabled = true;
3444
3472
  const moved = downXY ? Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) : Infinity; downXY = null;
3445
3473
  if (!p) return;
3474
+ if(p.filteredGrid)return;
3475
+ 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;}
3446
3476
  if (p.clipDrag) return; // a clip handle drag is applied live during onMoveClip; nothing to commit on up (controls re-enabled above)
3447
3477
  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)
3448
3478
  if (p.epDrag) { // end-node drag → write just that endpoint's wp; a click (no drag) just selects the member
@@ -3752,8 +3782,16 @@ function snapCandidatesScreen(type) {
3752
3782
  return allCandidates(null).filter((c) => c.type === type && c.p)
3753
3783
  .map((c) => { const s = toScreen(c.p); return { world: c.p, x: rect.left + s.x, y: rect.top + s.y }; });
3754
3784
  }
3785
+ // test helper: projected, clip-trimmed structural-grid segments. E2E uses these coordinates to drive a
3786
+ // real line click / marquee without guessing where an oblique 3D line landed after camera fitting.
3787
+ function gridSegmentsScreen() {
3788
+ const rect=canvasEl.getBoundingClientRect(),out=[],frustum=gridCameraFrustum();
3789
+ 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}});}}
3790
+ return out;
3791
+ }
3792
+ function gridBubblesScreen(){if(!gridLabelGroup)return [];const rect=canvasEl.getBoundingClientRect();return gridLabelGroup.children.filter(s=>s.visible&&s.userData.gridId).map(s=>{const p=s.getWorldPosition(new THREE.Vector3()).project(camera);return {id:s.userData.gridId,x:rect.left+(p.x*.5+.5)*rect.width,y:rect.top+(-p.y*.5+.5)*rect.height};});}
3755
3793
  window.Steel3DView = {
3756
- init, show, hide, rebuild, setSelection, isReady, dispose,
3794
+ init, show, hide, rebuild, setSelection, setGridSelection, isReady, dispose,
3757
3795
  setProjection, projection, setDisplayMode, mode: () => displayMode, frameAll, frameSelection, applyView,
3758
3796
  setRefLine, refLine: () => refLineOn,
3759
3797
  setInsertMode, insertMode: insertModeOn, // arm/query the detail-placement pick (Slice 4)
@@ -3767,12 +3805,12 @@ window.Steel3DView = {
3767
3805
  selLenLabelTexts: () => selLenLabelPool.filter((el) => el.style.display !== 'none' && el.style.visibility !== 'hidden').map((el) => el.textContent), // visible on-select length chips — for tests
3768
3806
  epScreen: (id) => { const m = memberById(id); if (!m || !canvasEl) return null; const g = memberGeometry(m, api.ptPerFt(), api.defaultTosMm()); 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
3769
3807
  refreshGrid: buildStructGrid, // grid edited in the panel → re-render without a full rebuild
3770
- gridInfo: () => ({ lines: structGridGroup ? 1 : 0, labels: gridLabelGroup ? gridLabelGroup.children.length : 0 }), // test helper
3808
+ gridInfo: () => ({ lines: structGridLines.size, labels: gridLabelGroup ? gridLabelGroup.children.length : 0,labelTexts:gridLabelGroup?[...new Set(gridLabelGroup.children.map(s=>s.userData.label).filter(Boolean))]:[],selected:[...selectedGridIds],ids:[...structGridLines.keys()] }), // test helper
3771
3809
  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.
3772
3810
  if (!wpGroup) return { group: false, extent: wpExtent };
3773
3811
  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 })) };
3774
3812
  },
3775
- toggleGroup, setGroupsHidden, setIdsHidden, connHiddenIds: () => [...connHidden], soloToggle, setSoloGroups, showAllGroups, groupState, getGroups,
3813
+ toggleGroup, setGroupsHidden, setIdsHidden, connHiddenIds: () => [...connHidden], soloToggle, setSoloGroups, showAllGroups, groupState, getGroups, visibleMemberIds,
3776
3814
  setClipMode, clipMode: clipModeOn, addClipBox, toggleClip, removeClip, clearClips, getClips, renameClip, selectClip, setSelectedClips, selectedClips, deleteSelectedClips, clipState, setClipState,
3777
3815
  isolateSelected, clearIsolation, isIsolated,
3778
3816
  cameraState, setCameraState, sectionViewState, sceneBounds, objectsPaneState, applyObjectsPaneState, // saved-view snapshot surface (Views Organizer + F11 generated cuts)
@@ -3797,6 +3835,6 @@ window.Steel3DView = {
3797
3835
  addDestAt: (x, y) => { if (!drDraft) return null; const r = drDestPoint({ clientX: x, clientY: y, shiftKey: false, altKey: false }); return r ? { p: r.p, snap: r.snap } : null; }, // test probe: the resolved 2nd draw point at a cursor (respects the axis lock) — read-only, no commit
3798
3836
  selDims3dCount: () => (api && api.selDim3d ? (api.selDim3d() || []).length : 0), // test helper: how many 3D dims are selected
3799
3837
  dim3dLabelOf: (i) => { const el = dimLabelPool[i]; if (!el || el.style.display === 'none') return null; const r = el.getBoundingClientRect(); return { x: r.left + r.width / 2, y: r.top + r.height / 2, text: el.textContent }; },
3800
- debug, probe, screenOf, centerOf, worldOf, snapCandidatesScreen, clipHandlesScreen,
3838
+ debug, probe, screenOf, centerOf, worldOf, snapCandidatesScreen, gridSegmentsScreen, gridBubblesScreen, clipHandlesScreen,
3801
3839
  pointClipped: (p) => isPointClipped(p), // test helper: is a world point on the cut-away side of any active clip?
3802
3840
  };