@floless/app 0.119.0 → 0.120.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 +1503 -733
- package/dist/schemas/steel.model.v2.schema.json +43 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +87 -10
- package/dist/web/app.css +38 -4
- package/dist/web/aware.js +5 -0
- package/dist/web/steel-3d-core.js +21 -0
- package/dist/web/steel-3d-view.js +359 -1
- package/dist/web/steel-editor.html +782 -5
- package/package.json +2 -1
|
@@ -861,6 +861,328 @@ function buildRefLines() {
|
|
|
861
861
|
}
|
|
862
862
|
function setRefLine(on) { refLineOn = !!on; buildRefLines(); }
|
|
863
863
|
|
|
864
|
+
// ---- Reference models (#278): borrowed geometry, on an EDITOR-ONLY layer --------------------
|
|
865
|
+
//
|
|
866
|
+
// An IFC somebody else authored, overlaid so you can see it, snap to it and build against it. It is
|
|
867
|
+
// never ours: it reaches no BOM, no export of our steel, no connection and no lock.
|
|
868
|
+
//
|
|
869
|
+
// THAT PROPERTY IS STRUCTURAL HERE, NOT FILTERED. This geometry never passes through
|
|
870
|
+
// `contractToScene` — the projector that feeds BOTH this editor and every exporter — so an exporter
|
|
871
|
+
// cannot reach it even by mistake. It arrives from its own route (`/api/steel/:appId/reference/:id/
|
|
872
|
+
// geometry`) straight into `xrefGroup`, a sibling of `root` that nothing but this section touches.
|
|
873
|
+
// The alternative (load it into the shared scene, tag it, filter it out downstream) puts the one rule
|
|
874
|
+
// that defines the feature one forgotten filter away from breaking.
|
|
875
|
+
//
|
|
876
|
+
// It is also why native behaviour is untouched by construction rather than by care: `meshHitsAt`
|
|
877
|
+
// raycasts `meshById` only, and reference meshes are never in that map, so member picking, drag,
|
|
878
|
+
// box-select and Ctrl+A cannot see them however this layer changes.
|
|
879
|
+
|
|
880
|
+
let xrefGroup = null; // one child Group per reference, each holding its meshes
|
|
881
|
+
const xrefById = new Map(); // id -> { group, display, points, capped, total, bounds }
|
|
882
|
+
let xrefSelected = null; // the whole-selected reference, or null
|
|
883
|
+
let xrefCandWarned = false; // one warning per session if snap candidates ever fail
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Slate-400 — the muted grey this app already spends on "not your content".
|
|
887
|
+
*
|
|
888
|
+
* DELIBERATELY NOWHERE NEAR THE BRAND BLUE at any opacity. `rgba(59,130,246,…)` is this app's
|
|
889
|
+
* dedicated "this is selected / this is mine" wash (`.lrow.solo`, `.ci-row.sel`, `.vwrow.active`), and
|
|
890
|
+
* a translucent overlay tinted towards it would read as "part of my selection" — exactly backwards
|
|
891
|
+
* from the one thing this feature must never let a user believe.
|
|
892
|
+
*/
|
|
893
|
+
const XREF_COLOR = 0x94a3b8;
|
|
894
|
+
/** Vertices closer than this collapse into one snap point — a tessellated corner is many coincident ones. */
|
|
895
|
+
const XREF_SNAP_QUANT_MM = 0.5;
|
|
896
|
+
/**
|
|
897
|
+
* A ceiling on how many reference points may enter a drag's snap candidate list.
|
|
898
|
+
*
|
|
899
|
+
* `snapPoint` PROJECTS EVERY CANDIDATE, on every mouse move. Member and grid candidates are naturally
|
|
900
|
+
* bounded; a tessellated building is not — a federated coordination model can carry a million vertices,
|
|
901
|
+
* and handing those to a per-move loop would turn a drag into a slideshow. So the list is bounded, and
|
|
902
|
+
* `capped` is reported through the debug probe and the panel rather than being silently applied: a
|
|
903
|
+
* limit nobody can see reads as "snapping is broken here", which is worse than a limit that is stated.
|
|
904
|
+
*/
|
|
905
|
+
const XREF_SNAP_BUDGET = 6000;
|
|
906
|
+
/**
|
|
907
|
+
* How many unique vertices are KEPT AT ALL, per reference.
|
|
908
|
+
*
|
|
909
|
+
* The budget above bounded the wrong thing, and review was right that the comment claimed otherwise:
|
|
910
|
+
* it capped the OUTPUT while `xrefSnapPoints` had already materialised every unique vertex as a string
|
|
911
|
+
* key and an array, and `referenceCandidates` had already transformed and accumulated every in-frustum
|
|
912
|
+
* point before sorting. At the 8M-vertex ceiling the reader itself permits, that is millions of
|
|
913
|
+
* allocations at load and a full scan-and-sort on every pointer move — a frozen tab, from a cap whose
|
|
914
|
+
* stated purpose was to prevent one.
|
|
915
|
+
*
|
|
916
|
+
* So the work is bounded where the work happens: dedup stops accepting new points here. What is kept is
|
|
917
|
+
* the first N in file order, which is arbitrary but honest, and `capped` says so.
|
|
918
|
+
*/
|
|
919
|
+
const XREF_SNAP_KEEP = 40_000;
|
|
920
|
+
|
|
921
|
+
// NO FRAME CORRECTION HERE — deliberately, and this is where one used to live.
|
|
922
|
+
//
|
|
923
|
+
// Reference vertices arrive already in the file's own Z-up world frame, the same frame our scene uses
|
|
924
|
+
// (`contractToScene` emits `meta.up='z'`). `toReferenceObjects` (server/reference-import.ts) settles
|
|
925
|
+
// that on the way in: it turns web-ifc's Y-up tessellation UNLESS the reader states `frame: 'z-up'`.
|
|
926
|
+
// An absent `frame` means the pre-1.0.0 reader, and IS turned — that omission is the whole upgrade
|
|
927
|
+
// path, so "only when it says y-up" would describe the opposite of the default that carries this.
|
|
928
|
+
//
|
|
929
|
+
// Until AWARE's `ifc-reference-reader` 1.0.0 this renderer composed a `makeRotationX(PI/2)` of its own,
|
|
930
|
+
// because `read-model` shipped web-ifc's Y-up mesh while `probe` reported the file's Z-up box
|
|
931
|
+
// (aware-aeco/aware#343, fixed upstream in CLI v0.114.0). Against a current bridge that rotation is now
|
|
932
|
+
// WRONG — it would take correct geometry and lay it on its side, the very defect it was written to
|
|
933
|
+
// cure. It moved to the adapter rather than being deleted outright because a stale bridge still returns
|
|
934
|
+
// Y-up, and only the response itself can say which one arrived.
|
|
935
|
+
//
|
|
936
|
+
// So: do not reintroduce a rotation here — in any spelling. If a reference renders on its side, the
|
|
937
|
+
// question is which `frame` the reader sent, and the answer belongs in `toReferenceObjects`.
|
|
938
|
+
|
|
939
|
+
/** Scale about the insertion point, then rotate about Z, then move — the order the schema documents. */
|
|
940
|
+
function xrefMatrix(placement) {
|
|
941
|
+
const p = placement || {};
|
|
942
|
+
const s = Number.isFinite(p.scale) && p.scale > 0 ? p.scale : 1;
|
|
943
|
+
const rot = (Number.isFinite(p.rotation) ? p.rotation : 0) * Math.PI / 180;
|
|
944
|
+
const o = Array.isArray(p.origin) && p.origin.length === 3 ? p.origin : [0, 0, 0];
|
|
945
|
+
return new THREE.Matrix4()
|
|
946
|
+
.makeTranslation(o[0] || 0, o[1] || 0, o[2] || 0)
|
|
947
|
+
.multiply(new THREE.Matrix4().makeRotationZ(rot))
|
|
948
|
+
.multiply(new THREE.Matrix4().makeScale(s, s, s));
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/** Unique world points for snapping, quantised so a tessellated corner is one target and not thirty. */
|
|
952
|
+
function xrefSnapPoints(objects) {
|
|
953
|
+
const seen = new Set(); const out = [];
|
|
954
|
+
for (const o of objects || []) {
|
|
955
|
+
const pos = o.positions || [];
|
|
956
|
+
for (let i = 0; i + 2 < pos.length; i += 3) {
|
|
957
|
+
if (out.length >= XREF_SNAP_KEEP) return { points: out, capped: true }; // bail BEFORE allocating more
|
|
958
|
+
const k = `${Math.round(pos[i] / XREF_SNAP_QUANT_MM)},${Math.round(pos[i + 1] / XREF_SNAP_QUANT_MM)},${Math.round(pos[i + 2] / XREF_SNAP_QUANT_MM)}`;
|
|
959
|
+
if (seen.has(k)) continue;
|
|
960
|
+
seen.add(k); out.push([pos[i], pos[i + 1], pos[i + 2]]);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return { points: out, capped: false };
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* (Re)build the whole reference layer from what the editor holds.
|
|
968
|
+
*
|
|
969
|
+
* `list` is `[{ id, name, objects, placement, display }]` — `objects` straight from the geometry route,
|
|
970
|
+
* `placement`/`display` from the contract. A reference whose geometry has not arrived yet (the cold
|
|
971
|
+
* cache streaming in behind the native steel) simply carries no `objects` and renders nothing, which is
|
|
972
|
+
* the honest encoding of "not here yet" and keeps project open from ever blocking on someone else's model.
|
|
973
|
+
*/
|
|
974
|
+
function setReferences(list) {
|
|
975
|
+
if (!scene) return;
|
|
976
|
+
if (!xrefGroup) { xrefGroup = new THREE.Group(); scene.add(xrefGroup); }
|
|
977
|
+
for (const child of [...xrefGroup.children]) {
|
|
978
|
+
child.traverse?.((o) => { o.geometry?.dispose?.(); o.material?.dispose?.(); });
|
|
979
|
+
xrefGroup.remove(child);
|
|
980
|
+
}
|
|
981
|
+
xrefById.clear();
|
|
982
|
+
|
|
983
|
+
for (const ref of list || []) {
|
|
984
|
+
if (!ref || !ref.id) continue;
|
|
985
|
+
const group = new THREE.Group();
|
|
986
|
+
group.userData.referenceId = ref.id;
|
|
987
|
+
// BEHIND everything of ours. `renderOrder` -1 plus `depthWrite:false` means our steel always wins
|
|
988
|
+
// the pixel where they overlap — a reference that occludes the model it exists to be compared
|
|
989
|
+
// against is worse than no reference.
|
|
990
|
+
group.renderOrder = -1;
|
|
991
|
+
const objects = Array.isArray(ref.objects) ? ref.objects : [];
|
|
992
|
+
for (const o of objects) {
|
|
993
|
+
const g = new THREE.BufferGeometry();
|
|
994
|
+
g.setAttribute('position', new THREE.Float32BufferAttribute(o.positions || [], 3));
|
|
995
|
+
if (Array.isArray(o.indices) && o.indices.length) g.setIndex(o.indices);
|
|
996
|
+
g.computeVertexNormals();
|
|
997
|
+
const mesh = new THREE.Mesh(g, new THREE.MeshStandardMaterial({
|
|
998
|
+
color: XREF_COLOR, metalness: 0, roughness: 0.95,
|
|
999
|
+
transparent: true, opacity: 1, depthWrite: false, side: THREE.DoubleSide,
|
|
1000
|
+
}));
|
|
1001
|
+
mesh.userData.referenceId = ref.id;
|
|
1002
|
+
group.add(mesh);
|
|
1003
|
+
}
|
|
1004
|
+
group.applyMatrix4(xrefMatrix(ref.placement));
|
|
1005
|
+
xrefGroup.add(group);
|
|
1006
|
+
|
|
1007
|
+
const { points, capped: keptCapped } = xrefSnapPoints(objects);
|
|
1008
|
+
// NO CACHED `bounds` HERE. It was stored and never read — `referenceBounds` recomputes — and the
|
|
1009
|
+
// stored copy was measured without un-hiding, so it was null for a hidden reference while
|
|
1010
|
+
// `frameReference` correctly un-hides first. Two answers to one question, one of them wrong.
|
|
1011
|
+
xrefById.set(ref.id, {
|
|
1012
|
+
group, display: ref.display || {}, name: ref.name || ref.id,
|
|
1013
|
+
points, total: points.length, capped: keptCapped, keptCapped,
|
|
1014
|
+
});
|
|
1015
|
+
applyReferenceDisplay(ref.id, ref.display || {});
|
|
1016
|
+
}
|
|
1017
|
+
if (xrefSelected && !xrefById.has(xrefSelected)) xrefSelected = null;
|
|
1018
|
+
paintReferenceSelection();
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Apply one reference's display state.
|
|
1023
|
+
*
|
|
1024
|
+
* `visible` and `snap` are INDEPENDENT and the independence is a product decision, not an oversight:
|
|
1025
|
+
* you hide a reference to get it out of your way while you keep building TO it. Hiding therefore
|
|
1026
|
+
* touches only what is drawn — `snap` is read separately, by `allCandidates`, and does not consult
|
|
1027
|
+
* this at all.
|
|
1028
|
+
*
|
|
1029
|
+
* `locked` is not read here either. It freezes EDITS (move/rotate/scale/delete/reload), which are
|
|
1030
|
+
* refused where they are performed; a locked reference stays exactly as visible and as snappable as an
|
|
1031
|
+
* unlocked one.
|
|
1032
|
+
*/
|
|
1033
|
+
function applyReferenceDisplay(id, display) {
|
|
1034
|
+
const entry = xrefById.get(id); if (!entry) return;
|
|
1035
|
+
entry.display = display || {};
|
|
1036
|
+
const visible = entry.display.visible !== false;
|
|
1037
|
+
const opacity = Number.isFinite(entry.display.opacity) ? Math.max(0, Math.min(1, entry.display.opacity)) : 0.5;
|
|
1038
|
+
entry.group.visible = visible;
|
|
1039
|
+
entry.group.traverse((o) => { if (o.material) { o.material.opacity = opacity; o.material.needsUpdate = true; } });
|
|
1040
|
+
paintReferenceSelection();
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* Re-place one reference without touching a single vertex.
|
|
1045
|
+
*
|
|
1046
|
+
* The separate cheap path matters: `setReferences` re-uploads every buffer, and a whole tessellated
|
|
1047
|
+
* building is tens of megabytes of GPU traffic. Dragging the scale field or nudging the origin must
|
|
1048
|
+
* not pay that on every keystroke — a transform is a 4×4 matrix, so it is applied as one.
|
|
1049
|
+
*/
|
|
1050
|
+
function setReferencePlacement(id, placement) {
|
|
1051
|
+
const entry = xrefById.get(id); if (!entry) return;
|
|
1052
|
+
entry.group.matrix.identity();
|
|
1053
|
+
entry.group.position.set(0, 0, 0); entry.group.quaternion.identity(); entry.group.scale.set(1, 1, 1);
|
|
1054
|
+
entry.group.applyMatrix4(xrefMatrix(placement));
|
|
1055
|
+
entry.group.updateMatrixWorld(true);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** The whole-model selection highlight: an emissive lift, never the brand wash (see XREF_COLOR). */
|
|
1059
|
+
function paintReferenceSelection() {
|
|
1060
|
+
for (const [id, entry] of xrefById) {
|
|
1061
|
+
const on = id === xrefSelected;
|
|
1062
|
+
entry.group.traverse((o) => {
|
|
1063
|
+
if (!o.material || !o.material.emissive) return;
|
|
1064
|
+
o.material.emissive.setHex(on ? 0xe2e8f0 : 0x000000);
|
|
1065
|
+
o.material.emissiveIntensity = on ? 0.35 : 0;
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* The reference under the pointer, or null.
|
|
1072
|
+
*
|
|
1073
|
+
* Raycast SEPARATELY from `meshHitsAt`, and consulted only when that found nothing — so a reference
|
|
1074
|
+
* standing in front of a beam never steals the beam's click. The plan's acceptance list asks for the
|
|
1075
|
+
* negative ("native selection unchanged") and this is where it is earned rather than hoped for.
|
|
1076
|
+
*
|
|
1077
|
+
* A HIDDEN reference is not pickable: `visible` is false on its group, and unlike snapping, picking
|
|
1078
|
+
* something you cannot see has no case to make for itself.
|
|
1079
|
+
*/
|
|
1080
|
+
function pickReferenceAt(cx, cy) {
|
|
1081
|
+
if (!xrefGroup || !xrefGroup.children.length || !canvasEl) return null;
|
|
1082
|
+
camera.updateMatrixWorld(); xrefGroup.updateMatrixWorld(true);
|
|
1083
|
+
const rect = canvasEl.getBoundingClientRect();
|
|
1084
|
+
raycaster.setFromCamera(new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1), camera);
|
|
1085
|
+
const hit = raycaster.intersectObjects(xrefGroup.children, true)
|
|
1086
|
+
.filter((h) => !isPointClipped([h.point.x, h.point.y, h.point.z]))[0];
|
|
1087
|
+
return hit ? (hit.object.userData.referenceId || null) : null;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
function selectReference(id) {
|
|
1091
|
+
xrefSelected = xrefById.has(id) ? id : null;
|
|
1092
|
+
paintReferenceSelection();
|
|
1093
|
+
if (api && api.onReferenceSelect) api.onReferenceSelect(xrefSelected);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/** World bounds of one reference — what zoom-to frames, and what the off-screen check measures. */
|
|
1097
|
+
function referenceBounds(id) {
|
|
1098
|
+
const entry = xrefById.get(id);
|
|
1099
|
+
if (!entry || !entry.group.children.length) return null;
|
|
1100
|
+
// UN-HIDE FIRST. `Box3.setFromObject` skips invisible children, so a hidden reference measured null —
|
|
1101
|
+
// and "where is it and how big is it" is exactly the question you ask about something you cannot see.
|
|
1102
|
+
// `frameReference` already did this; this did not, so the panel's size line and the off-screen check
|
|
1103
|
+
// both went blank the moment you hid a row.
|
|
1104
|
+
const wasVisible = entry.group.visible;
|
|
1105
|
+
entry.group.visible = true;
|
|
1106
|
+
const box = new THREE.Box3().setFromObject(entry.group);
|
|
1107
|
+
entry.group.visible = wasVisible;
|
|
1108
|
+
return box.isEmpty() ? null : { min: box.min.toArray(), max: box.max.toArray() };
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Frame one reference.
|
|
1113
|
+
*
|
|
1114
|
+
* THE MOST IMPORTANT CONTROL IN THE FEATURE, which is not obvious until you measure a real file: the
|
|
1115
|
+
* Motebello sample is correctly sized and sits 74 m up and 40 m out, entirely off-screen. Without this
|
|
1116
|
+
* the import looks like it silently failed, and the user's next move is to load it again.
|
|
1117
|
+
*
|
|
1118
|
+
* It frames a HIDDEN reference too, deliberately — "show me where it is" is exactly the question you
|
|
1119
|
+
* ask about something you cannot currently see.
|
|
1120
|
+
*/
|
|
1121
|
+
function frameReference(id) {
|
|
1122
|
+
const b = referenceBounds(id); // un-hides to measure, so this frames a hidden reference too
|
|
1123
|
+
if (!b) return false;
|
|
1124
|
+
fitCamera(new THREE.Box3(new THREE.Vector3(...b.min), new THREE.Vector3(...b.max)));
|
|
1125
|
+
return true;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* The reference snap candidates for a drag, in the shape `snapPoint` consumes.
|
|
1130
|
+
*
|
|
1131
|
+
* IGNORES `visible` BY DESIGN and honours `snap` alone — a hidden reference still snaps unless its own
|
|
1132
|
+
* snap toggle is off (§10.3). Frustum-filtered first, so the list is what is actually in view rather
|
|
1133
|
+
* than the whole building, then capped nearest-first with the cap recorded on the entry so the panel
|
|
1134
|
+
* can say it out loud.
|
|
1135
|
+
*/
|
|
1136
|
+
function referenceCandidates() {
|
|
1137
|
+
if (!xrefById.size || !camera) return [];
|
|
1138
|
+
camera.updateMatrixWorld();
|
|
1139
|
+
const frustum = new THREE.Frustum().setFromProjectionMatrix(
|
|
1140
|
+
new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse),
|
|
1141
|
+
);
|
|
1142
|
+
const out = [];
|
|
1143
|
+
for (const [id, entry] of xrefById) {
|
|
1144
|
+
entry.capped = false;
|
|
1145
|
+
if (entry.display.snap === false) continue;
|
|
1146
|
+
const m = entry.group.matrixWorld;
|
|
1147
|
+
const v = new THREE.Vector3();
|
|
1148
|
+
let taken = 0;
|
|
1149
|
+
// STOPS AT THE BUDGET rather than collecting everything and sorting. The nearest-first sort was a
|
|
1150
|
+
// nicety that cost an O(n log n) over every in-frustum point on EVERY pointer move; taking the
|
|
1151
|
+
// first N in view is the same order of usefulness at a bounded cost, and `capped` reports it.
|
|
1152
|
+
for (const p of entry.points) {
|
|
1153
|
+
if (taken >= XREF_SNAP_BUDGET) { entry.capped = true; break; }
|
|
1154
|
+
v.set(p[0], p[1], p[2]).applyMatrix4(m);
|
|
1155
|
+
if (!frustum.containsPoint(v)) continue;
|
|
1156
|
+
// 'vertex', WHICH IS THE CANDIDATE TYPE — 'end' is the snap PREFERENCE key it maps to
|
|
1157
|
+
// (SNAP3D_PREF), and emitting that instead was a real bug the independent QA pass caught: nothing
|
|
1158
|
+
// understands 'end' as a type, so `candidatePoint` fell through to its segment arm and dereferenced
|
|
1159
|
+
// the `a`/`b` a point candidate does not have, throwing on every pointer move with a drawing tool
|
|
1160
|
+
// armed. It also meant reference points ignored the user's Endpoint-snap toggle entirely. Our own
|
|
1161
|
+
// member ends are 'vertex' (steel-3d-core `memberCandidates`), and a reference's corners are the
|
|
1162
|
+
// same kind of thing.
|
|
1163
|
+
out.push({ type: 'vertex', p: [v.x, v.y, v.z], fromId: `ref:${id}` });
|
|
1164
|
+
taken++;
|
|
1165
|
+
}
|
|
1166
|
+
if (entry.keptCapped) entry.capped = true; // it was already truncated at load
|
|
1167
|
+
}
|
|
1168
|
+
return out;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/** Test/panel probe: what the layer is actually holding, per reference. */
|
|
1172
|
+
function referenceInfo() {
|
|
1173
|
+
return [...xrefById.entries()].map(([id, e]) => ({
|
|
1174
|
+
id, name: e.name,
|
|
1175
|
+
meshes: e.group.children.length,
|
|
1176
|
+
visible: e.group.visible,
|
|
1177
|
+
opacity: e.group.children[0]?.material?.opacity ?? null,
|
|
1178
|
+
snap: e.display.snap !== false,
|
|
1179
|
+
locked: !!e.display.locked,
|
|
1180
|
+
selected: id === xrefSelected,
|
|
1181
|
+
snapPoints: e.total, snapCapped: e.capped || !!e.keptCapped,
|
|
1182
|
+
bounds: referenceBounds(id),
|
|
1183
|
+
}));
|
|
1184
|
+
}
|
|
1185
|
+
|
|
864
1186
|
// ---- Insert a vectored detail (Slice 4): arm a placement pick; the editor owns the entry ----
|
|
865
1187
|
// Mirrors setClipMode's arm/disarm. `pending` = {name,url} the editor's Insert menu queued; the
|
|
866
1188
|
// placement click raycasts a member face (anchor) or the ground plane and hands the point + basis +
|
|
@@ -1092,6 +1414,23 @@ function allCandidates(excludeId) {
|
|
|
1092
1414
|
// model data, and it keeps its position between them so the candidate ORDER is unchanged.
|
|
1093
1415
|
const base = MODEL().memberCandidates(excludeId);
|
|
1094
1416
|
if (frame3d && !(pending && pending.frameDrag)) base.push({ type: 'origin', p: [...frame3d.origin], fromId: 'ucs-origin' }); // the local UCS origin is a snap target for every tool (Move/Copy, Add, Dimension); excluded while dragging the origin itself → no self-snap
|
|
1417
|
+
// Reference models, appended AFTER ours — and this comment used to claim more than the code delivers,
|
|
1418
|
+
// so it is worth being exact. A reference's points are `vertex`, the same rank as our own member ends
|
|
1419
|
+
// (PRECEDENCE 0), so between the two it is NEAREST-ON-SCREEN that wins, exactly as it would between
|
|
1420
|
+
// two of our own candidates. What the ordering buys is the TIE: `snapPoint` improves on the incumbent
|
|
1421
|
+
// only when the distance is strictly smaller, so at equal distance the first candidate stands, and
|
|
1422
|
+
// ours are first. That is the right split. Ranking references permanently below ours would mean a
|
|
1423
|
+
// member end 8 px away silently stealing the corner the user was aiming at, in a feature whose whole
|
|
1424
|
+
// point is building against that corner — while the tie going to our own geometry keeps the default
|
|
1425
|
+
// honest when the two coincide. (Before the snap-type fix this read as though ours always won; that
|
|
1426
|
+
// was never true in practice, because the mistyped candidate threw before any of it was reached.)
|
|
1427
|
+
try { base.push(...referenceCandidates()); }
|
|
1428
|
+
catch (e) {
|
|
1429
|
+
// A reference must never break member dragging — but a SILENT stop means snapping to the reference
|
|
1430
|
+
// quietly dies for the rest of the session and the user has no way to know why. Warned once, so a
|
|
1431
|
+
// per-move failure cannot flood the console.
|
|
1432
|
+
if (!xrefCandWarned) { xrefCandWarned = true; console.warn('[reference] snap candidates unavailable', e); }
|
|
1433
|
+
}
|
|
1095
1434
|
try { return base.concat(MODEL().gridCandidates()); }
|
|
1096
1435
|
catch { return base; } // a malformed hand-edited grid must never break member dragging
|
|
1097
1436
|
}
|
|
@@ -2673,7 +3012,16 @@ const CYCLE_TOL_PX = 8;
|
|
|
2673
3012
|
function resetCycle() { cycleAnchor = null; cycleIds = []; cycleIdx = 0; }
|
|
2674
3013
|
function clickSelect(cx, cy, ctrl) {
|
|
2675
3014
|
let hits = []; try { hits = pickAllAt(cx, cy); } catch { hits = []; }
|
|
2676
|
-
if (
|
|
3015
|
+
if (hits.length) selectReference(null); // anything of OURS under the cursor drops a reference selection
|
|
3016
|
+
if (!hits.length) {
|
|
3017
|
+
// Nothing of ours here — only NOW may a reference answer. Consulted second, never first, so a
|
|
3018
|
+
// reference standing in front of a beam can never steal the beam's click; that is how "native
|
|
3019
|
+
// selection behaviour is unchanged" is earned structurally rather than tested for and hoped.
|
|
3020
|
+
// A whole reference is the only selectable unit: it is one borrowed thing, not a set of parts.
|
|
3021
|
+
let ref = null; try { ref = pickReferenceAt(cx, cy); } catch { ref = null; }
|
|
3022
|
+
if (ref) { resetCycle(); selectReference(ref); return; }
|
|
3023
|
+
resetCycle(); selectReference(null); if (!ctrl) clearConnSel(); return; // empty → deselect (clears any connection too); Ctrl/Shift+empty-click preserves the selection (parity with 2D + the additive intent — a near-miss shouldn't wipe it)
|
|
3024
|
+
}
|
|
2677
3025
|
if (ctrl) { resetCycle(); resetConnState(); if (api && api.onSelect) api.onSelect(hits[0], true); return; } // additive toggles the nearest RAW part (leaves connection mode)
|
|
2678
3026
|
const same = cycleAnchor && Math.hypot(cx - cycleAnchor[0], cy - cycleAnchor[1]) <= CYCLE_TOL_PX
|
|
2679
3027
|
&& cycleIds.length === hits.length && cycleIds.every((v, i) => v === hits[i]);
|
|
@@ -4448,6 +4796,10 @@ function dispose() {
|
|
|
4448
4796
|
for (const o of [epRing, epPreview, epMovedLine, refGroup, dimPreviewLine]) if (o) { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }
|
|
4449
4797
|
epGeom = epMatStart = epMatEnd = epRing = epPreview = epMovedLine = refGroup = null;
|
|
4450
4798
|
dims3dGroup = dimPreviewLine = overlayDimsGroup = null;
|
|
4799
|
+
// The reference layer owns real GPU buffers — a whole tessellated building's worth. Leaving them
|
|
4800
|
+
// attached to a torn-down scene is the kind of leak that only shows up after the fifth 2D↔3D switch.
|
|
4801
|
+
if (xrefGroup) { xrefGroup.traverse((o) => { o.geometry?.dispose?.(); o.material?.dispose?.(); }); if (scene) scene.remove(xrefGroup); }
|
|
4802
|
+
xrefGroup = null; xrefById.clear(); xrefSelected = null;
|
|
4451
4803
|
clearStructGrid();
|
|
4452
4804
|
clearWireEdges();
|
|
4453
4805
|
for (const tex of gridTexCache.values()) tex.dispose();
|
|
@@ -4550,6 +4902,12 @@ window.Steel3DView = {
|
|
|
4550
4902
|
setInsertMode, insertMode: insertModeOn, // arm/query the detail-placement pick (Slice 4)
|
|
4551
4903
|
setBasePickMode, basePickMode: basePickModeOn, // arm/query the Mode B column-base pick (level-snapped elevation)
|
|
4552
4904
|
selectWholeConn, clearConnSel, ascendConn, connContext, connEnvelopeOn: () => !!connEnvelope, // Connection Components (Slice A): whole-select / drill / ascend + test probes
|
|
4905
|
+
// Reference models (#278) — an editor-only layer. `setReferences` takes the geometry the editor
|
|
4906
|
+
// fetched from the reference route; nothing here ever passes through contractToScene, which is what
|
|
4907
|
+
// keeps borrowed geometry out of every export by construction rather than by filtering.
|
|
4908
|
+
setReferences, setReferenceDisplay: applyReferenceDisplay, setReferencePlacement, selectReference,
|
|
4909
|
+
selectedReference: () => xrefSelected, frameReference, referenceBounds, referenceInfo,
|
|
4910
|
+
pickReferenceAt,
|
|
4553
4911
|
setLabelsOn, labelsOn: () => labelsOnFlag, // member mark/id label overlay toggle
|
|
4554
4912
|
syncMemberLabels, // editor calls after a mark/id edit to refresh labels
|
|
4555
4913
|
setPropLabels, // right-click property labels: editor pushes { labels:[{id,lines}], placement }
|