@floless/app 0.130.0 → 0.130.1
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 +1353 -647
- package/dist/schemas/steel.model.v2.schema.json +28 -8
- package/dist/web/steel-3d-view.js +328 -32
- package/dist/web/steel-editor.html +142 -8
- package/package.json +1 -1
|
@@ -67,14 +67,24 @@
|
|
|
67
67
|
"override": { "type": ["string", "null"], "description": "Set only when the user overrode a file that LIES about its units." }
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
"filter": {
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"description": "The
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
70
|
+
"filter": { "$ref": "#/$defs/referenceFilter" },
|
|
71
|
+
"versions": {
|
|
72
|
+
"type": "array",
|
|
73
|
+
"minItems": 1,
|
|
74
|
+
"description": "The chain of files this reference has been, OLDEST FIRST. The LAST entry is what is loaded now, and the top-level `file`/`name`/`filter` MIRROR it — a mirror rather than a lookup so every existing reader keeps working unchanged, and the invariant is asserted at the route rather than assumed. ABSENT on every reference imported before versioning existed, which is the ordinary state and not a defect: it is adopted as a chain of one the first time a new version is uploaded. Rollback REORDERS rather than truncates (a copy of the target is appended as the new last), so history survives and \"compare v3 against v1\" is still answerable while standing on v1.",
|
|
75
|
+
"items": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"additionalProperties": false,
|
|
78
|
+
"required": ["id", "file", "name", "sha256", "importedAt"],
|
|
79
|
+
"properties": {
|
|
80
|
+
"id": { "type": "string", "minLength": 1, "description": "Server-minted, opaque, unique within this chain. Versions are addressed by THIS, never by sha256: the same bytes can legitimately be uploaded twice under two names, so a sha is not unique within a chain and a lookup by it is ambiguous at exactly the moment (a rollback) when being wrong is least recoverable. JSON Schema cannot express uniqueness-by-key, so the routes check it too." },
|
|
81
|
+
"file": { "type": "string", "minLength": 1, "description": "Project-RELATIVE path to this version's retained original. Every version keeps its own file, which is what lets a removed object's ghost geometry be re-read from the version it vanished from." },
|
|
82
|
+
"name": { "type": "string", "description": "The display name this version was uploaded under." },
|
|
83
|
+
"sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$", "description": "The file's content hash, lowercase hex. DURABLE — unlike `sourceHash` on the reference cache, which lives in a reserved-internal file excluded from export, so it cannot answer \"which bytes was this version built from?\" after a round trip." },
|
|
84
|
+
"importedAt": { "type": "string", "description": "ISO-8601. For an `adopted` row this is when versioning RECORDED it, not when the file was imported — nothing durable records the latter." },
|
|
85
|
+
"adopted": { "const": true, "description": "Present and true ONLY on a v1 synthesised from a pre-versioning reference. Never false, so its absence cannot be read as a claim that the row was genuinely imported. It exists because such a row has no true import date: there is no durable record of when an existing reference was first inserted, so stamping `importedAt: now` would fabricate history in the one field a user reads to answer \"which of these did I load first?\". The UI renders it as \"recorded 14 Aug — first seen before versioning\", never \"imported 14 Aug\"." },
|
|
86
|
+
"filter": { "$ref": "#/$defs/referenceFilter" }
|
|
87
|
+
}
|
|
78
88
|
}
|
|
79
89
|
},
|
|
80
90
|
"display": {
|
|
@@ -631,6 +641,16 @@
|
|
|
631
641
|
}
|
|
632
642
|
]
|
|
633
643
|
},
|
|
644
|
+
"referenceFilter": {
|
|
645
|
+
"type": "object",
|
|
646
|
+
"additionalProperties": false,
|
|
647
|
+
"minProperties": 1,
|
|
648
|
+
"description": "The SUBSET of the file this reference was read from — ABSENT means the whole file. Stored so a re-read reproduces the same reference: without it, \"Reload its geometry\" would silently replace one storey with the whole building, from the one action a user takes when something already looks wrong. An empty list is never stored, and neither is an empty object: the reader treats an empty list as selecting NOTHING, so \"no filter\" is this key being absent. The two filters INTERSECT — storeys L1 plus type IFCBEAM means the beams on L1, not both sets.",
|
|
649
|
+
"properties": {
|
|
650
|
+
"storeys": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 }, "description": "Storey names as `probe` reported them. Matched case-insensitively by the reader." },
|
|
651
|
+
"ifcTypes": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 }, "description": "IFC entity names, e.g. IFCBEAM. Subtypes are included, so a supertype does not select nothing." }
|
|
652
|
+
}
|
|
653
|
+
},
|
|
634
654
|
"propLabels": {
|
|
635
655
|
"type": "object",
|
|
636
656
|
"additionalProperties": false,
|
|
@@ -381,6 +381,7 @@ function loop() {
|
|
|
381
381
|
sizeEndpoints();
|
|
382
382
|
sizeClipHandles();
|
|
383
383
|
sizeFrameHandle();
|
|
384
|
+
sizeGridLabels();
|
|
384
385
|
positionDimLabels();
|
|
385
386
|
positionOverlayLabels();
|
|
386
387
|
positionMemberLabels();
|
|
@@ -1374,6 +1375,11 @@ function setReferences(list) {
|
|
|
1374
1375
|
// a second lookup. `objectId` is the file's GlobalId and may be `''` (see `xrefSubSelected`), so
|
|
1375
1376
|
// it is normalised to null here rather than being allowed to masquerade as a real, empty id.
|
|
1376
1377
|
mesh.userData.objectId = (o && typeof o.id === 'string' && o.id) ? o.id : null;
|
|
1378
|
+
// THE FILE'S OWN GlobalId, and it is NOT `objectId` above. `objectId` is the reader's `id`, which
|
|
1379
|
+
// falls back to the expressID when a file records no GlobalId — a file-local sequence number that
|
|
1380
|
+
// two reads of two files share freely. Anything asking "is this the SAME object as before" must
|
|
1381
|
+
// use this one; anything merely addressing an object in THIS read may keep using `objectId`.
|
|
1382
|
+
mesh.userData.globalId = (o && typeof o.globalId === 'string' && o.globalId) ? o.globalId : null;
|
|
1377
1383
|
mesh.userData.objectIndex = i;
|
|
1378
1384
|
mesh.userData.colorRuns = runs;
|
|
1379
1385
|
group.add(mesh);
|
|
@@ -1403,12 +1409,36 @@ function setReferences(list) {
|
|
|
1403
1409
|
dupIds: (() => {
|
|
1404
1410
|
const seen = new Set(), dup = new Set();
|
|
1405
1411
|
for (const o of objects) {
|
|
1406
|
-
|
|
1412
|
+
// KEYED ON `globalId`, not `id`. Keyed on `id` this set was near-empty against a current
|
|
1413
|
+
// reader — the reader substitutes a unique expressID wherever a GlobalId is missing, so
|
|
1414
|
+
// duplicates could not appear and neither could blanks. It was guarding a case that cannot
|
|
1415
|
+
// occur while the real one passed straight through.
|
|
1416
|
+
const oid = (o && typeof o.globalId === 'string' && o.globalId) ? o.globalId : null;
|
|
1407
1417
|
if (oid === null) continue;
|
|
1408
1418
|
if (seen.has(oid)) dup.add(oid); else seen.add(oid);
|
|
1409
1419
|
}
|
|
1410
1420
|
return dup;
|
|
1411
1421
|
})(),
|
|
1422
|
+
/**
|
|
1423
|
+
* `globalId` -> the index its object now sits at, for ids that appear exactly ONCE.
|
|
1424
|
+
*
|
|
1425
|
+
* This is what makes `revalidateSubSelection` a REMAP rather than a re-check. Checking the same
|
|
1426
|
+
* array slot means an IFC that merely REORDERS its objects drops a perfectly valid drill even
|
|
1427
|
+
* though the object is still there under the same GlobalId — which does not lie to the user, but
|
|
1428
|
+
* throws away the identity this whole feature exists to supply. Duplicated ids are excluded for
|
|
1429
|
+
* the same reason `dupIds` refuses them: an id shared by two objects cannot say which one you
|
|
1430
|
+
* were on. Built here, in the loop that already walks every object, rather than per rebuild.
|
|
1431
|
+
*/
|
|
1432
|
+
byGlobalId: (() => {
|
|
1433
|
+
const at = new Map();
|
|
1434
|
+
for (let i = 0; i < objects.length; i++) {
|
|
1435
|
+
const o = objects[i];
|
|
1436
|
+
const oid = (o && typeof o.globalId === 'string' && o.globalId) ? o.globalId : null;
|
|
1437
|
+
if (oid === null) continue;
|
|
1438
|
+
at.set(oid, i);
|
|
1439
|
+
}
|
|
1440
|
+
return at;
|
|
1441
|
+
})(),
|
|
1412
1442
|
// `painted` is what `applyReferenceDisplay` compares against to decide whether re-materialling
|
|
1413
1443
|
// every mesh is necessary at all. Opacity is dragged live and must stay a per-material write.
|
|
1414
1444
|
mats, painted: null,
|
|
@@ -1448,17 +1478,28 @@ function setReferences(list) {
|
|
|
1448
1478
|
* the selection and ask nothing further. Only a genuine re-read hands over a new array. (Codex review
|
|
1449
1479
|
* caught this: the first cut dropped a perfectly valid drill every time an unrelated reference loaded.)
|
|
1450
1480
|
*
|
|
1451
|
-
* When the array HAS changed,
|
|
1452
|
-
*
|
|
1481
|
+
* When the array HAS changed, this REMAPS rather than re-checks, and the difference matters. The old
|
|
1482
|
+
* version asked whether `group.children[index]` still held the same id — so an IFC that merely REORDERED
|
|
1483
|
+
* its objects dropped a perfectly valid drill even though the object was still there, unchanged, under
|
|
1484
|
+
* the same GlobalId. That never lied to the user, but it threw away the identity this feature exists to
|
|
1485
|
+
* supply. Now the remembered `globalId` is looked up in the rebuilt entry and the selection MOVES to
|
|
1486
|
+
* wherever that object now sits.
|
|
1487
|
+
*
|
|
1488
|
+
* IT KEYS ON `globalId`, NOT `objectId`, and that is a fix rather than a rename. `objectId` is the
|
|
1489
|
+
* reader's `id`, which falls back to the expressID when a file records no GlobalId — so against a
|
|
1490
|
+
* current reader the blank case below was UNREACHABLE (the reader always substitutes something
|
|
1491
|
+
* non-empty and unique) while the real failure, an expressID landing on a different object across two
|
|
1492
|
+
* reads, passed straight through. The branch was guarding a case that could not occur. `globalId` is
|
|
1493
|
+
* the file's own value or null, so blank is reachable and means what it says.
|
|
1453
1494
|
*
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
1456
|
-
*
|
|
1457
|
-
* the
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
* not the file, not the reader, not us — so the
|
|
1461
|
-
* collected at build time and refused here.
|
|
1495
|
+
* TWO IDS THAT CANNOT DISTINGUISH ANYTHING STILL CANNOT PASS:
|
|
1496
|
+
*
|
|
1497
|
+
* null — a file whose objects carry no GlobalId gives every slot the same answer, so any check
|
|
1498
|
+
* against it would wave through whatever landed at index N. That is the failure this
|
|
1499
|
+
* function exists to prevent, arriving through the front door.
|
|
1500
|
+
* duplicate — the same, one step subtler: two objects sharing an id cannot say which one you were on.
|
|
1501
|
+
* Nothing validates GlobalId uniqueness — not the file, not the reader, not us — so the
|
|
1502
|
+
* ids that repeat inside one reference are collected at build time and refused here.
|
|
1462
1503
|
*
|
|
1463
1504
|
* The cost is stated rather than hidden: after a genuine re-read, a drill into an object with no id (or a
|
|
1464
1505
|
* duplicated one) does not survive. It is not much of a cost — such a file gives us nothing to tell two
|
|
@@ -1468,14 +1509,27 @@ function setReferences(list) {
|
|
|
1468
1509
|
function revalidateSubSelection(prevObjects) {
|
|
1469
1510
|
if (!xrefSubSelected) return;
|
|
1470
1511
|
const entry = xrefById.get(xrefSubSelected.refId);
|
|
1471
|
-
|
|
1472
|
-
if (!mesh || !mesh.isMesh) { xrefSubSelected = null; return; }
|
|
1512
|
+
if (!entry) { xrefSubSelected = null; return; }
|
|
1473
1513
|
// The cheap, total answer first: nothing was re-read, so nothing can have moved.
|
|
1474
1514
|
const prev = prevObjects && prevObjects.get(xrefSubSelected.refId);
|
|
1475
|
-
if (prev && prev === entry.objects)
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1515
|
+
if (prev && prev === entry.objects) {
|
|
1516
|
+
const held = entry.group.children[xrefSubSelected.index];
|
|
1517
|
+
if (!held || !held.isMesh) xrefSubSelected = null;
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
// A GENUINE RE-READ. Find the object by IDENTITY and move the selection to wherever it now sits —
|
|
1521
|
+
// rather than asking whether the same array slot still holds it, which fails an IFC that merely
|
|
1522
|
+
// reordered its objects while the object itself is still present and unchanged.
|
|
1523
|
+
const gid = xrefSubSelected.globalId;
|
|
1524
|
+
if (gid === null || gid === undefined || entry.dupIds.has(gid)) { xrefSubSelected = null; return; }
|
|
1525
|
+
const index = entry.byGlobalId.get(gid);
|
|
1526
|
+
if (index === undefined) { xrefSubSelected = null; return; }
|
|
1527
|
+
const mesh = entry.group.children[index];
|
|
1528
|
+
if (!mesh || !mesh.isMesh) { xrefSubSelected = null; return; }
|
|
1529
|
+
// REMAPPED, and `objectId` is refreshed with it: `id` may legitimately differ between two reads of
|
|
1530
|
+
// the same object (it falls back to the expressID), so carrying the old one forward would leave the
|
|
1531
|
+
// panel addressing a slot by a number this read never used.
|
|
1532
|
+
xrefSubSelected = { refId: xrefSubSelected.refId, index, objectId: mesh.userData.objectId ?? null, globalId: gid };
|
|
1479
1533
|
}
|
|
1480
1534
|
|
|
1481
1535
|
/**
|
|
@@ -1822,7 +1876,7 @@ function selectReferenceObject(refId, index) {
|
|
|
1822
1876
|
const mesh = entry && Number.isInteger(index) && index >= 0 ? entry.group.children[index] : null;
|
|
1823
1877
|
if (!mesh || !mesh.isMesh) return false;
|
|
1824
1878
|
xrefSelected = refId;
|
|
1825
|
-
xrefSubSelected = { refId, index, objectId: mesh.userData.objectId ?? null };
|
|
1879
|
+
xrefSubSelected = { refId, index, objectId: mesh.userData.objectId ?? null, globalId: mesh.userData.globalId ?? null };
|
|
1826
1880
|
paintReferenceSelection();
|
|
1827
1881
|
paintReferenceSubSelection();
|
|
1828
1882
|
emitReferenceSelect();
|
|
@@ -2231,6 +2285,12 @@ const structGridLines = new Map();
|
|
|
2231
2285
|
let selectedGridIds = new Set();
|
|
2232
2286
|
let structGridSignature = null;
|
|
2233
2287
|
const gridTexCache = new Map(); // 'b:LABEL' bubble / 't:LABEL' tag -> CanvasTexture (kept until dispose)
|
|
2288
|
+
// How big a grid bubble is ON SCREEN, in px — the user's setting (⋯ ▸ Display ▸ Grid label size), shared
|
|
2289
|
+
// with the 2D plan so one grid reads the same in both views. It is a VIEW preference, not model data, so
|
|
2290
|
+
// it lives in localStorage next to the other per-browser display prefs and never touches the contract.
|
|
2291
|
+
const GRID_LABEL_PX_DEFAULT = 26, GRID_LABEL_PX_MIN = 14, GRID_LABEL_PX_MAX = 48;
|
|
2292
|
+
function clampGridLabelPx(v) { const n = Math.round(+v); return Number.isFinite(n) && n > 0 ? Math.min(GRID_LABEL_PX_MAX, Math.max(GRID_LABEL_PX_MIN, n)) : GRID_LABEL_PX_DEFAULT; }
|
|
2293
|
+
let gridLabelPx = (() => { try { const raw = localStorage.getItem('steel:gridLabelPx:v1'); return raw === null ? GRID_LABEL_PX_DEFAULT : clampGridLabelPx(raw); } catch { return GRID_LABEL_PX_DEFAULT; } })();
|
|
2234
2294
|
|
|
2235
2295
|
// Snap targets for the 3D tools. Members come from the WHOLE model — every sheet, not just the active
|
|
2236
2296
|
// one — so "3D snapping on" can grab any member at any elevation (the 3D scene shows all sheets; snapping
|
|
@@ -2266,14 +2326,25 @@ function allCandidates(excludeId) {
|
|
|
2266
2326
|
function gridBubbleTexture(label) {
|
|
2267
2327
|
const key = 'b:' + label;
|
|
2268
2328
|
if (gridTexCache.has(key)) return gridTexCache.get(key);
|
|
2269
|
-
|
|
2329
|
+
// 256, not 128: the bubble is drawn at up to GRID_LABEL_PX_MAX on a 2× display, and the old texture
|
|
2330
|
+
// went visibly soft at the top of the size range.
|
|
2331
|
+
const S = 256, cv = document.createElement('canvas'); cv.width = cv.height = S;
|
|
2270
2332
|
const g = cv.getContext('2d');
|
|
2271
|
-
|
|
2333
|
+
const R = S / 2 - 10;
|
|
2334
|
+
g.beginPath(); g.arc(S / 2, S / 2, R, 0, Math.PI * 2);
|
|
2272
2335
|
g.fillStyle = '#0f172a'; g.fill();
|
|
2273
|
-
g.lineWidth =
|
|
2274
|
-
|
|
2336
|
+
g.lineWidth = 10; g.strokeStyle = '#64748b'; g.stroke();
|
|
2337
|
+
// Shrink to fit the CIRCLE, not to a fraction of the diameter — the same closed form the 2D plan uses
|
|
2338
|
+
// (see gridLabelFontPx there for the derivation), so the two views agree about what "fits" means. The
|
|
2339
|
+
// old `width > R * 1.5` rule is blind to where the text sits: a centred line is widest at its own
|
|
2340
|
+
// half-height, where the circle has already narrowed, and R*1.5 let the ink reach the rim stroke.
|
|
2341
|
+
g.fillStyle = '#e2e8f0';
|
|
2342
|
+
g.font = 'bold 100px system-ui';
|
|
2343
|
+
const wEm = g.measureText(label).width / 100, Ri = R - 10; // inner radius: the rim is a 10 px stroke centred on R
|
|
2344
|
+
const fs = Math.min(120, 0.95 * Ri / Math.sqrt(wEm * wEm / 4 + 0.1296));
|
|
2345
|
+
g.font = 'bold ' + fs + 'px system-ui';
|
|
2275
2346
|
g.textAlign = 'center'; g.textBaseline = 'middle';
|
|
2276
|
-
g.fillText(label, S / 2, S / 2 +
|
|
2347
|
+
g.fillText(label, S / 2, S / 2 + 4);
|
|
2277
2348
|
const tex = new THREE.CanvasTexture(cv);
|
|
2278
2349
|
gridTexCache.set(key, tex);
|
|
2279
2350
|
return tex;
|
|
@@ -2331,25 +2402,244 @@ function buildStructGrid() {
|
|
|
2331
2402
|
(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])]]));
|
|
2332
2403
|
scene.add(structGridGroup);
|
|
2333
2404
|
gridLabelGroup = new THREE.Group();
|
|
2334
|
-
const span = Math.max((geo.x1 - geo.x0) * k, (geo.y1 - geo.y0) * k, 1);
|
|
2335
|
-
const dia = Math.min(Math.max(span * 0.035, 400), 3000); // bubble ⌀ scales with the grid, clamped sane
|
|
2336
2405
|
const z0 = levels[0].mm;
|
|
2337
|
-
|
|
2406
|
+
// Every label records its ANCHOR (the point it belongs to) and, for a bubble, the OUTWARD direction
|
|
2407
|
+
// along its own line. Neither the position nor the scale is final here — sizeGridLabels() sets both
|
|
2408
|
+
// every frame, because both are camera-dependent (see there for why that is the CAD behaviour).
|
|
2409
|
+
const sprite = (tex, label, gridId) => {
|
|
2338
2410
|
// depthTest ON so steel in FRONT occludes the bubble/level tag (B7). The overlay pass runs with the
|
|
2339
2411
|
// depth buffer from pass 1 (members) intact — autoClear is off — so this occludes against the steel
|
|
2340
2412
|
// WITHOUT moving the labels out of overlayScene: they stay unclipped, so a section plane still can't
|
|
2341
2413
|
// cut them (the clip-regression guard above holds).
|
|
2342
2414
|
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, depthTest: true, depthWrite: false, transparent: true }));
|
|
2343
2415
|
s.userData.label=String(label||'');s.userData.gridId=gridId||null;
|
|
2344
|
-
s.
|
|
2416
|
+
s.renderOrder = 994;
|
|
2345
2417
|
gridLabelGroup.add(s);
|
|
2418
|
+
return s;
|
|
2346
2419
|
};
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2420
|
+
// A bubble at (ax,ay), on the line whose OTHER end is (ox,oy) — so it can hang off the end away from
|
|
2421
|
+
// the model, the way a grid bubble does on a drawing.
|
|
2422
|
+
const bubble = (label, gridId, ax, ay, ox, oy) => {
|
|
2423
|
+
const s = sprite(gridBubbleTexture(label), label, gridId);
|
|
2424
|
+
// AWAY from the other end: (anchor - other), normalised. Getting this sign wrong hangs every bubble
|
|
2425
|
+
// INTO the model, onto the perimeter columns — the exact thing the placement exists to prevent.
|
|
2426
|
+
const dx = ax - ox, dy = ay - oy, len = Math.hypot(dx, dy);
|
|
2427
|
+
s.userData.anchor = V(ax, ay, z0);
|
|
2428
|
+
// A zero-length line has no outward direction to compute. `|| 1` used to guard the division and hand
|
|
2429
|
+
// back a ZERO vector, which reads as handled and silently parks the bubble on the model. +X is
|
|
2430
|
+
// arbitrary but it is a real direction, so the bubble still clears the end it belongs to.
|
|
2431
|
+
s.userData.outward = len > 1e-9 ? V(dx / len, dy / len, 0) : V(1, 0, 0);
|
|
2432
|
+
s.position.copy(s.userData.anchor);
|
|
2433
|
+
};
|
|
2434
|
+
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);});
|
|
2435
|
+
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);});
|
|
2436
|
+
(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);});
|
|
2437
|
+
if (geo.zs.length) for (const lv of levels) { // one elevation tag per level, parked off the grid's top-left corner
|
|
2438
|
+
const s = sprite(gridTagTexture(lv.label), lv.label, null);
|
|
2439
|
+
s.userData.anchor = V(mmX(geo.x0), mmY(geo.y1), lv.mm);
|
|
2440
|
+
// The sprite's aspect is width/HEIGHT, and the height below is 0.75·d — so this is 4.8, not the
|
|
2441
|
+
// texture's 6.4. Reading the 6.4 out of the old comment and using it as the width multiplier gives
|
|
2442
|
+
// 6.4/0.75 = 8.53:1 against a 6.4:1 bitmap, i.e. every elevation tag 33% too wide.
|
|
2443
|
+
s.userData.tagAspect = 4.8; // 4.8 / 0.75 == the tag texture's 512×80, so a long elevation label stays undistorted
|
|
2444
|
+
s.position.copy(s.userData.anchor);
|
|
2445
|
+
}
|
|
2351
2446
|
overlayScene.add(gridLabelGroup);
|
|
2352
2447
|
finish();
|
|
2448
|
+
sizeGridLabels(); // place + size them NOW, so a pick or a probe between this build and the next frame sees where they really are
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
// Grid labels are CAD ANNOTATION, not model geometry, and three things follow from that — all three
|
|
2452
|
+
// camera-dependent, hence per frame:
|
|
2453
|
+
//
|
|
2454
|
+
// SIZE. They hold ONE size on screen (gridLabelPx) however far you zoom, exactly like Tekla's and
|
|
2455
|
+
// Revit's grid heads. They used to be world-space sprites of ⌀ span*0.035 (400–3000 mm), which is a
|
|
2456
|
+
// 3 m disc on a big job: unreadably small framed out, and swallowing whole bays zoomed in.
|
|
2457
|
+
//
|
|
2458
|
+
// PLACE. A bubble sits TANGENT to the end of its line, on the far side from the model — the line
|
|
2459
|
+
// stops at the circle rather than running to its centre. That is the convention gridFromDrawing
|
|
2460
|
+
// already measures on real sheets ("the line stops at the bubble's edge, end-gap ≈ r"), and it is
|
|
2461
|
+
// what keeps a bubble off the perimeter columns that stand at the grid ends.
|
|
2462
|
+
//
|
|
2463
|
+
// Tangency has to be solved ON SCREEN, which is the whole subtlety here. The standoff runs ALONG the
|
|
2464
|
+
// grid line in world space, so it foreshortens with that line's angle to the camera — but the bubble
|
|
2465
|
+
// is a camera-facing sprite whose radius does NOT foreshorten. Offsetting by half a bubble in world
|
|
2466
|
+
// units therefore lands the centre closer than one radius on screen, and the line visibly runs INSIDE
|
|
2467
|
+
// the circle: measured at 8.8 px against a 13.0 px radius on an ordinary iso view. So the offset is
|
|
2468
|
+
// the world distance whose PROJECTION is one radius, found by projecting the line direction and
|
|
2469
|
+
// dividing (see screenPxPerWorld). A line pointing nearly at the camera projects to almost nothing
|
|
2470
|
+
// and would demand a runaway offset, so it is capped — at that angle the line is a dot and there is
|
|
2471
|
+
// no visible tangency left to get right.
|
|
2472
|
+
//
|
|
2473
|
+
// DECLUTTER. A drawing never prints two bubbles on top of each other. Screen-constant labels on a
|
|
2474
|
+
// tight grid do collide once you frame out, so a bubble whose disc would TOUCH one already kept drops
|
|
2475
|
+
// out — centres nearer than 0.9 × the diameter, which is nearly two radii, not one. (Said as "centre
|
|
2476
|
+
// inside one already kept" here at first, which describes a rule ~1.8× looser than the code's.)
|
|
2477
|
+
// SELECTED lines are placed first and so always survive: losing the label AND the pick target of the
|
|
2478
|
+
// grid you are working on, to an unrelated line that merely sorted earlier, is not decluttering. Past
|
|
2479
|
+
// that, build order decides, so the survivors don't flicker as the camera moves. Elevation tags are
|
|
2480
|
+
// exempt entirely: there is one per level and they are the last wayfinding left when bubbles thin out.
|
|
2481
|
+
// Between two bubble CENTRES on screen, × gridLabelPx — so it must be ≥ 1, because gridLabelPx IS the
|
|
2482
|
+
// diameter and two discs whose centres are a diameter apart are exactly touching. At 0.9 they overlapped
|
|
2483
|
+
// by ~1 px for one zoom step before the pass fired (QA measured 24.4 px centres against 25.5 px discs);
|
|
2484
|
+
// 1.05 leaves a hair of clearance so the rims never kiss either.
|
|
2485
|
+
const GRID_LABEL_MIN_GAP = 1.05;
|
|
2486
|
+
// × the bubble radius — how far along its own line a bubble may be pushed to reach tangency. Generous:
|
|
2487
|
+
// it is bounded only so a line pointing straight at the camera cannot demand an unbounded world offset
|
|
2488
|
+
// (which would fly the sprite through the near/far planes and reorder it against the steel). Past this
|
|
2489
|
+
// the bubble is hidden instead — see the refusal in sizeGridLabels.
|
|
2490
|
+
const GRID_LABEL_MAX_STANDOFF = 60;
|
|
2491
|
+
let anchorlessLabelWarned = false, badLabelScaleWarned = false; // warn once each; a per-frame loop must never flood the console
|
|
2492
|
+
// Screen px per world unit ALONG `dir` at `from` — the foreshortening of that direction under the
|
|
2493
|
+
// current camera. Measured over a real span (`len`) rather than differentiated, so it is right for a
|
|
2494
|
+
// perspective camera too. Returns 0 when the span does not project (behind the camera), which the
|
|
2495
|
+
// caller reads as "unknown" and falls back from.
|
|
2496
|
+
// Answers null, not 0, when it cannot measure: 0 would read as a real "zero px per world unit" to the
|
|
2497
|
+
// next person, and it is numerically adjacent to the legitimate near-on-axis case the cap exists for.
|
|
2498
|
+
// The world size that reads as `px` on screen at `pos` — DEPTH-correct under perspective.
|
|
2499
|
+
//
|
|
2500
|
+
// A camera-facing sprite's projected size is set by the point's depth along the view axis, because that
|
|
2501
|
+
// is what the projection divides by. pxToWorldAt uses `camera.position.distanceTo(pos)`, which is the
|
|
2502
|
+
// RADIAL distance — the same number only on the axis, and larger everywhere else by 1/cos(angle). So a
|
|
2503
|
+
// bubble out at the corner of a wide viewport drew about 15% over its setting, and the re-measure at the
|
|
2504
|
+
// placed position repeated the error rather than cancelling it. Ortho has no distance term at all, and
|
|
2505
|
+
// it is this view's default, which is why every measurement so far read exactly 26.0 px.
|
|
2506
|
+
//
|
|
2507
|
+
// Deliberately NOT a fix inside pxToWorldAt: that helper is shared by sizeEndpoints, sizeClipHandles and
|
|
2508
|
+
// sizeFrameHandle, whose sizes are separately verified, so the same correction there is its own change
|
|
2509
|
+
// with its own evidence. Falls back to the shared helper whenever depth is unusable.
|
|
2510
|
+
const _depthV = new THREE.Vector3();
|
|
2511
|
+
function pxToWorldDepth(px, pos) {
|
|
2512
|
+
if (camera === orthoCam) return pxToWorldAt(px, pos);
|
|
2513
|
+
const depth = -_depthV.copy(pos).applyMatrix4(camera.matrixWorldInverse).z;
|
|
2514
|
+
if (!(depth > 0) || !Number.isFinite(depth)) return pxToWorldAt(px, pos); // at or behind the camera plane — no meaningful depth
|
|
2515
|
+
const h = (canvasEl && canvasEl.clientHeight) || 1;
|
|
2516
|
+
return px * (2 * Math.tan(THREE.MathUtils.degToRad(perspCam.fov) / 2) * depth) / h;
|
|
2517
|
+
}
|
|
2518
|
+
const _spA = new THREE.Vector3(), _spB = new THREE.Vector3();
|
|
2519
|
+
function screenPxPerWorld(from, dir, len, w, h) {
|
|
2520
|
+
if (!(len > 0)) return null;
|
|
2521
|
+
_spA.copy(from).project(camera);
|
|
2522
|
+
_spB.copy(from).addScaledVector(dir, len).project(camera);
|
|
2523
|
+
// BOTH components, not just .x — a NaN landing only in .y used to pass this and reach the caller as a
|
|
2524
|
+
// NaN ratio, which fell back only because `NaN > 1e-9` happens to be false. Right answer by accident.
|
|
2525
|
+
if (![_spA.x, _spA.y, _spB.x, _spB.y].every(Number.isFinite)) return null;
|
|
2526
|
+
const dx = (_spB.x - _spA.x) * 0.5 * w, dy = (_spB.y - _spA.y) * 0.5 * h;
|
|
2527
|
+
return Math.hypot(dx, dy) / len;
|
|
2528
|
+
}
|
|
2529
|
+
function sizeGridLabels() {
|
|
2530
|
+
if (!gridLabelGroup || !gridLabelGroup.children.length || !camera) return;
|
|
2531
|
+
const w = (canvasEl && canvasEl.clientWidth) || 1, h = (canvasEl && canvasEl.clientHeight) || 1;
|
|
2532
|
+
camera.updateMatrixWorld();
|
|
2533
|
+
const placed = [];
|
|
2534
|
+
for (const s of gridLabelGroup.children) {
|
|
2535
|
+
const ud = s.userData;
|
|
2536
|
+
// Every child is built by sprite() with an anchor, so this is unreachable today — but sprite() no
|
|
2537
|
+
// longer sets position or scale, so a future anchorless one would be a 1 mm disc at the world origin
|
|
2538
|
+
// that also escapes the visibility filter below. A per-frame loop must be total, so it still skips;
|
|
2539
|
+
// it just does not do so in silence.
|
|
2540
|
+
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; }
|
|
2541
|
+
s.visible = ud.allowed !== false; // applyGridVisibility owns WHETHER it may show; this owns where and how big
|
|
2542
|
+
if (!s.visible) continue;
|
|
2543
|
+
const d = pxToWorldDepth(gridLabelPx, ud.anchor); // the world size that reads as gridLabelPx on screen, measured AT the anchor
|
|
2544
|
+
// A degenerate ortho frustum, or a camera sitting exactly on the anchor, makes this 0 or NaN, and
|
|
2545
|
+
// `scale.set(0,0,1)` / `scale.set(NaN,NaN,1)` both render NOTHING while three.js throws on neither.
|
|
2546
|
+
// That is the undiagnosable disappearance: identical on screen to declutter, to an isolate filter,
|
|
2547
|
+
// and to "the grid failed to build". Keep the last good size instead of writing the bad one.
|
|
2548
|
+
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; }
|
|
2549
|
+
if (ud.tagAspect) {
|
|
2550
|
+
const tw = d * ud.tagAspect, th = d * 0.75, gap = d * 0.4;
|
|
2551
|
+
s.scale.set(tw, th, 1);
|
|
2552
|
+
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
|
|
2553
|
+
continue;
|
|
2554
|
+
}
|
|
2555
|
+
// Tangent ON SCREEN: push out far enough along the line that its projection is exactly one radius,
|
|
2556
|
+
// so the line stops at the rim instead of running into the circle. d/2 is the un-foreshortened
|
|
2557
|
+
// case (a line lying in the screen plane) and so is also the right fallback and the floor.
|
|
2558
|
+
const k = screenPxPerWorld(ud.anchor, ud.outward, d, w, h);
|
|
2559
|
+
const want = (k !== null && k > 1e-9) ? Math.max((gridLabelPx / 2) / k, d / 2) : d / 2;
|
|
2560
|
+
const standoff = Math.min(want, (d / 2) * GRID_LABEL_MAX_STANDOFF);
|
|
2561
|
+
s.position.copy(ud.anchor).addScaledVector(ud.outward, standoff);
|
|
2562
|
+
// The cap has to be able to REFUSE. Look almost straight down a grid line and k collapses, so the
|
|
2563
|
+
// distance needed for tangency runs away; capping it silently draws the line clean through the disc
|
|
2564
|
+
// and across the label — QA measured exactly that at a near-elevation angle, the line reaching 0.8 px
|
|
2565
|
+
// of the centre against a 13 px rim. (The first cap was 6 radii, with a comment claiming such a line
|
|
2566
|
+
// is "a dot with no visible tangency left to get right". It is not: QA's was 9 px long and its label
|
|
2567
|
+
// perfectly readable.) So the cap is generous enough to place any line you can still read along, and
|
|
2568
|
+
// when even that cannot clear the disc the bubble is HIDDEN rather than drawn crossed — you cannot
|
|
2569
|
+
// label a line you are looking down, and a missing mark beats a struck-through one.
|
|
2570
|
+
if (standoff < want * 0.999) { s.visible = false; continue; }
|
|
2571
|
+
// Re-measure at where it ENDED UP. Under perspective the standoff moves the sprite toward or away
|
|
2572
|
+
// from the camera, so a size taken at the anchor is off by that much — up to ~8% when the cap
|
|
2573
|
+
// engages. Ortho is unaffected (no distance term), but "constant size on screen" should be literally
|
|
2574
|
+
// true in both. Cheap, and the standoff is already fixed by the time it runs.
|
|
2575
|
+
const dAt = pxToWorldDepth(gridLabelPx, s.position);
|
|
2576
|
+
s.scale.setScalar(Number.isFinite(dAt) && dAt > 0 ? dAt : d);
|
|
2577
|
+
s.scale.z = 1;
|
|
2578
|
+
placed.push(s);
|
|
2579
|
+
}
|
|
2580
|
+
// THE OTHER LEVELS. A grid line is drawn once PER LEVEL (addLogical stacks a segment at every visible
|
|
2581
|
+
// Z), but a bubble exists only at the base level and can only be tangent to the segment it is anchored
|
|
2582
|
+
// to. Come at the grid from near-elevation and the upper segments project nearly collinear with the
|
|
2583
|
+
// lower one — and, having no bubble of their own to stop at, run straight through the disc. QA measured
|
|
2584
|
+
// an untrimmed upper segment reaching 2.7 px from the centre of a 13 px bubble, in 5 of 230
|
|
2585
|
+
// observations, and it was invisible to every earlier check because those all measured the bubble
|
|
2586
|
+
// against its OWN endpoint, which was tangent to 0.00 px throughout.
|
|
2587
|
+
//
|
|
2588
|
+
// Tangency cannot solve this — one disc, several lines. So the same rule as the cap: a bubble that
|
|
2589
|
+
// cannot be shown uncrossed is not shown. Distance is measured to the SEGMENT, not to its endpoints,
|
|
2590
|
+
// because the offending part is the middle of the segment passing over the disc.
|
|
2591
|
+
const lineSegs = new Map(); // gridId -> [[x1,y1,x2,y2], …] on screen, this frame
|
|
2592
|
+
for (const [id, line] of structGridLines) {
|
|
2593
|
+
if (!line.visible) continue;
|
|
2594
|
+
const pts = line.userData.segments || [], segs = [];
|
|
2595
|
+
for (let i = 0; i + 1 < pts.length; i += 2) {
|
|
2596
|
+
const a = _spA.set(pts[i][0], pts[i][1], pts[i][2]).project(camera);
|
|
2597
|
+
if (!Number.isFinite(a.x) || a.z > 1 || a.z < -1) continue;
|
|
2598
|
+
const ax = (a.x * 0.5 + 0.5) * w, ay = (-a.y * 0.5 + 0.5) * h;
|
|
2599
|
+
const b = _spB.set(pts[i + 1][0], pts[i + 1][1], pts[i + 1][2]).project(camera);
|
|
2600
|
+
if (!Number.isFinite(b.x) || b.z > 1 || b.z < -1) continue;
|
|
2601
|
+
segs.push([ax, ay, (b.x * 0.5 + 0.5) * w, (-b.y * 0.5 + 0.5) * h]);
|
|
2602
|
+
}
|
|
2603
|
+
if (segs.length) lineSegs.set(id, segs);
|
|
2604
|
+
}
|
|
2605
|
+
const distToSeg = (px, py, x1, y1, x2, y2) => {
|
|
2606
|
+
const vx = x2 - x1, vy = y2 - y1, len2 = vx * vx + vy * vy;
|
|
2607
|
+
const t = len2 > 0 ? Math.max(0, Math.min(1, ((px - x1) * vx + (py - y1) * vy) / len2)) : 0;
|
|
2608
|
+
return Math.hypot(px - (x1 + t * vx), py - (y1 + t * vy));
|
|
2609
|
+
};
|
|
2610
|
+
const survivors = [];
|
|
2611
|
+
for (const s of placed) {
|
|
2612
|
+
const p = _spA.copy(s.position).project(camera);
|
|
2613
|
+
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
|
|
2614
|
+
const cx = (p.x * 0.5 + 0.5) * w, cy = (-p.y * 0.5 + 0.5) * h;
|
|
2615
|
+
const segs = lineSegs.get(s.userData.gridId) || [];
|
|
2616
|
+
// The tangent segment sits at exactly one radius, so only something meaningfully INSIDE the rim
|
|
2617
|
+
// counts — 1.5 px of slack keeps float noise on the tangent one from hiding a perfectly good bubble.
|
|
2618
|
+
const crossed = segs.some((g) => distToSeg(cx, cy, g[0], g[1], g[2], g[3]) < gridLabelPx / 2 - 1.5);
|
|
2619
|
+
if (crossed) { s.visible = false; continue; }
|
|
2620
|
+
survivors.push(s);
|
|
2621
|
+
}
|
|
2622
|
+
placed.length = 0; placed.push(...survivors);
|
|
2623
|
+
// Selected lines first, so the grid the user is working on can never be the one whose label and pick
|
|
2624
|
+
// target get dropped in favour of an unrelated line that merely sorted earlier.
|
|
2625
|
+
if (selectedGridIds.size) placed.sort((a, b) => (selectedGridIds.has(b.userData.gridId) ? 1 : 0) - (selectedGridIds.has(a.userData.gridId) ? 1 : 0));
|
|
2626
|
+
const kept = [];
|
|
2627
|
+
const min = gridLabelPx * GRID_LABEL_MIN_GAP;
|
|
2628
|
+
for (const s of placed) {
|
|
2629
|
+
const p = _spA.copy(s.position).project(camera); // scratch, not a per-frame clone() — same reason screenPxPerWorld uses one
|
|
2630
|
+
// `z < -1` matters as much as `z > 1`, and ORTHO is this view's default. Under perspective a
|
|
2631
|
+
// behind-camera point flips w and lands z > 1; under ortho w is 1, so it lands z < -1 and used to
|
|
2632
|
+
// sail through — while its x/y stay the geometrically correct in-plane coordinates. It would then
|
|
2633
|
+
// enter `kept` and suppress a bubble that really is on screen.
|
|
2634
|
+
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
|
|
2635
|
+
const x = (p.x * 0.5 + 0.5) * w, y = (-p.y * 0.5 + 0.5) * h;
|
|
2636
|
+
if (kept.some((c) => Math.hypot(c.x - x, c.y - y) < min)) { s.visible = false; continue; }
|
|
2637
|
+
kept.push({ x, y });
|
|
2638
|
+
}
|
|
2639
|
+
// pickGridAt raycasts and gridBubblesScreen projects, and both read matrixWorld — which is refreshed
|
|
2640
|
+
// by the render pass, not by writing .position. Without this the build-time call above leaves a probe
|
|
2641
|
+
// in that sub-frame window reporting every bubble at the world origin.
|
|
2642
|
+
gridLabelGroup.updateMatrixWorld(true);
|
|
2353
2643
|
}
|
|
2354
2644
|
|
|
2355
2645
|
// The ortho frustum half-height in world units (set by a fit to the box, or by a projection toggle
|
|
@@ -4155,7 +4445,11 @@ function pickGridAt(cx,cy){
|
|
|
4155
4445
|
function applyGridVisibility(){
|
|
4156
4446
|
let anyLine=false;
|
|
4157
4447
|
for(const [id,line] of structGridLines){const on=(isolatedGridIds===null||isolatedGridIds.has(id))&&!gridSelectionHidden.has(id);line.visible=on;if(on)anyLine=true;}
|
|
4158
|
-
|
|
4448
|
+
// `allowed` is the visibility DECISION; sizeGridLabels() re-applies it every frame and may additionally
|
|
4449
|
+
// drop a bubble that collides with another on screen. Split in two so the declutter pass can never be
|
|
4450
|
+
// mistaken for an isolate/hide filter, and so this one stays the single authority on which grid shows.
|
|
4451
|
+
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;}
|
|
4452
|
+
sizeGridLabels();
|
|
4159
4453
|
}
|
|
4160
4454
|
function reconcileGridVisibilityState(scopeChanged=false){
|
|
4161
4455
|
const next=reconcileGridTransientState({
|
|
@@ -6318,6 +6612,8 @@ window.Steel3DView = {
|
|
|
6318
6612
|
selLenLabelTexts: () => selLenLabelPool.filter((el) => el.style.display !== 'none' && el.style.visibility !== 'hidden').map((el) => el.textContent), // visible on-select length chips — for tests
|
|
6319
6613
|
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
|
|
6320
6614
|
refreshGrid: buildStructGrid, // grid edited in the panel → re-render without a full rebuild
|
|
6615
|
+
setGridLabelPx: (px) => { gridLabelPx = clampGridLabelPx(px); sizeGridLabels(); }, // ⋯ ▸ Display ▸ Grid label size — no rebuild needed, the labels are re-placed every frame anyway
|
|
6616
|
+
gridLabelPx: () => gridLabelPx,
|
|
6321
6617
|
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)
|
|
6322
6618
|
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()],visible:visibleGridIds(),hidden:[...gridSelectionHidden],isolated:isolatedGridIds===null?null:[...isolatedGridIds] }), // test helper
|
|
6323
6619
|
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.
|