@floless/app 0.138.1 → 0.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autostart.mjs +6 -2
- package/desktop-access-production-manifest.mjs +7 -0
- package/dist/floless-server.cjs +157133 -70500
- package/dist/schemas/model.continuation.v1.schema.json +19 -0
- package/dist/schemas/model.continuation.v2.schema.json +19 -0
- package/dist/schemas/model.query-response.v1.schema.json +95 -0
- package/dist/schemas/model.query-response.v2.schema.json +80 -0
- package/dist/schemas/model.query.v1.schema.json +87 -0
- package/dist/schemas/model.query.v2.schema.json +87 -0
- package/dist/schemas/model.snap-candidate.v1.schema.json +48 -0
- package/dist/schemas/model.snap-constraint.v1.schema.json +18 -0
- package/dist/schemas/model.snap-query.v1.schema.json +24 -0
- package/dist/schemas/model.snap-result.v1.schema.json +33 -0
- package/dist/schemas/model.snapshot.v1.schema.json +136 -0
- package/dist/schemas/revit.model.v1.schema.json +24 -0
- package/dist/schemas/steel.model.v2.schema.json +45 -6
- package/dist/skills/floless-app-approval/SKILL.md +19 -5
- package/dist/skills/floless-app-bridge/SKILL.md +19 -6
- package/dist/skills/floless-app-knowledge/SKILL.md +22 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +31 -27
- package/dist/skills/floless-app-new-workflow/references/build-and-verify.md +13 -12
- package/dist/skills/floless-app-onboarding/SKILL.md +3 -3
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +16 -9
- package/dist/skills/floless-app-steel-model/SKILL.md +11 -2
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +95 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +146 -21
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +19 -0
- package/dist/skills/floless-app-tweak-contract/SKILL.md +42 -8
- package/dist/skills/floless-app-vectorize/SKILL.md +19 -6
- package/dist/skills/floless-app-workflows/SKILL.md +30 -3
- package/dist/skills/floless-app-workflows/references/workspace-data.md +77 -4
- package/dist/templates/floless-workspace-model-report.flo +77 -0
- package/dist/templates/revit-model.flo +111 -0
- package/dist/web/app.css +415 -177
- package/dist/web/app.js +302 -51
- package/dist/web/aware.js +1430 -1040
- package/dist/web/chat.css +692 -0
- package/dist/web/chat.js +2651 -0
- package/dist/web/commands-revit.js +42 -0
- package/dist/web/commands-shell.js +536 -70
- package/dist/web/commands-steel.js +344 -146
- package/dist/web/commands.js +1 -1
- package/dist/web/index.html +283 -77
- package/dist/web/instructor.js +217 -36
- package/dist/web/left-pane.js +636 -0
- package/dist/web/model-artifact-loader.js +75 -0
- package/dist/web/model-authoring-gestures.js +141 -0
- package/dist/web/model-cad-tools.js +20 -0
- package/dist/web/model-clip-gesture.js +148 -0
- package/dist/web/model-clip-list.js +156 -0
- package/dist/web/model-clip-session.js +274 -0
- package/dist/web/model-clip-three-overlay.js +295 -0
- package/dist/web/model-clip-three-preview.js +59 -0
- package/dist/web/model-editor-contract.js +519 -0
- package/dist/web/model-editor-revit-adapter.js +139 -0
- package/dist/web/model-editor-shell.js +271 -0
- package/dist/web/model-editor-state-recovery.js +44 -0
- package/dist/web/model-editor-steel-adapter.js +410 -0
- package/dist/web/model-editor.css +268 -0
- package/dist/web/model-frame.js +192 -0
- package/dist/web/model-inspector.js +128 -0
- package/dist/web/model-measure.js +390 -0
- package/dist/web/model-navigation-controls.js +246 -0
- package/dist/web/model-orientation-overlay.js +217 -0
- package/dist/web/model-panel-bridge.js +230 -0
- package/dist/web/model-pointer-dock.js +164 -0
- package/dist/web/model-revit-module.js +83 -0
- package/dist/web/model-selection-coordinator.js +151 -0
- package/dist/web/model-selection-tools.js +290 -0
- package/dist/web/model-snap-contract.js +267 -0
- package/dist/web/model-snapping.js +497 -0
- package/dist/web/model-spatial-panel.js +294 -0
- package/dist/web/model-spatial-tools.js +249 -0
- package/dist/web/model-tree.js +47 -0
- package/dist/web/model-viewport-lighting.js +166 -0
- package/dist/web/model-viewport-revit-adapter.js +1224 -0
- package/dist/web/model-viewport-state.js +505 -0
- package/dist/web/model-viewport-steel-adapter.js +150 -0
- package/dist/web/model-viewport-toolbar.js +516 -0
- package/dist/web/model-viewport.js +717 -0
- package/dist/web/panels.js +8 -15
- package/dist/web/renderers.js +3 -0
- package/dist/web/revit-editor.css +35 -0
- package/dist/web/revit-editor.html +74 -0
- package/dist/web/revit-editor.js +845 -0
- package/dist/web/steel-3d-core.js +16 -44
- package/dist/web/steel-3d-view.js +1384 -633
- package/dist/web/steel-canvas-guidance.js +3 -1
- package/dist/web/steel-editor.html +2121 -1253
- package/dist/web/steel-filter.html +5 -1
- package/dist/web/steel-model-v2-commands.js +72 -1
- package/dist/web/steel-split-view.js +5 -39
- package/dist/web/steel-view-generation.js +107 -17
- package/dist/web/vector-3d.html +12 -0
- package/dist/web/workspaces.js +2190 -277
- package/distribution-profile-active.mjs +2 -0
- package/distribution-profile-production.mjs +47 -0
- package/distribution-profile-shared.mjs +8 -0
- package/distribution-profile.mjs +18 -0
- package/distribution-resource-inventory.mjs +81 -0
- package/launch.mjs +18 -10
- package/log.mjs +2 -1
- package/managed-runtime-policy.mjs +104 -0
- package/model-reader-policy-active.mjs +7 -0
- package/network-policy-active.mjs +6 -0
- package/package.json +17 -2
- package/post-update-marker.mjs +3 -1
- package/rvt-production-uat-authority.mjs +60 -0
- package/teardown.mjs +4 -3
|
@@ -21,13 +21,42 @@ import { surfaceTextures, applyTriplanar, TILE_MM, DIRECTIONAL } from './steel-m
|
|
|
21
21
|
import { canvasToolGuidanceState } from './steel-canvas-guidance.js';
|
|
22
22
|
import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
|
|
23
23
|
import { FT_TO_MM as FT_MM } from './steel-units.js';
|
|
24
|
-
import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, projectPointOnSegment2d, projectPointOnSegment3d, selectedFrontmostHit, worldEndpointCommit, SEG_DEGENERACY, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, sectionKindOf, sectionTopology, memberMeshAxes, positionSwingDelta, snapToStep, rollCommitNorm, unwrapAngleStep, translateEndpoints, livePositionState, swingBasis, swingEndpoint, swingBarriers, clampSwingTheta, POSITION_SWING_MARGIN_RAD, POSITION_OFFSET_SNAP_MM, POSITION_ROT_SNAP_DEG, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
|
|
24
|
+
import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, projectToPlane, snapGridPoint, clipSegmentToPlanes, projectPointOnSegment2d, projectPointOnSegment3d, selectedFrontmostHit, worldEndpointCommit, SEG_DEGENERACY, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, sectionKindOf, sectionTopology, memberMeshAxes, positionSwingDelta, snapToStep, rollCommitNorm, unwrapAngleStep, translateEndpoints, livePositionState, swingBasis, swingEndpoint, swingBarriers, clampSwingTheta, POSITION_SWING_MARGIN_RAD, POSITION_OFFSET_SNAP_MM, POSITION_ROT_SNAP_DEG, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
|
|
25
25
|
// `gridGeometry`, `gridCandidates3d` and `sheetScaleMm` live behind the host's model read boundary
|
|
26
26
|
// because their display-scale argument is meaningless on a world-mm model grid.
|
|
27
27
|
import { visibleGridLevels, gridTransientScopeSignature, reconcileGridTransientState, objectSelectionStatus } from './grid-core.js';
|
|
28
|
+
import { createEntityKeyRegistry, encodeCameraState } from './model-viewport-state.js';
|
|
29
|
+
import { createModelViewportController } from './model-viewport.js';
|
|
30
|
+
import { createSteelViewportAdapter } from './model-viewport-steel-adapter.js';
|
|
31
|
+
import { MODEL_NAMED_VIEWS, createCadOrbitEventProxy, mountCadInputArbiter } from './model-navigation-controls.js';
|
|
32
|
+
import { createModelCadToolController } from './model-cad-tools.js';
|
|
33
|
+
import { createModelMeasureSession } from './model-measure.js';
|
|
34
|
+
import { createModelSpatialTools } from './model-spatial-tools.js';
|
|
35
|
+
import { solveModelSnapConstraint, solveModelSnapIntersection } from './model-snapping.js';
|
|
36
|
+
import { mountModelOrientationOverlay, modelOrientationPose } from './model-orientation-overlay.js';
|
|
37
|
+
import { createModelSelectionTools } from './model-selection-tools.js';
|
|
38
|
+
import { createModelClipGesture, orientClipNormalAwayFromCamera } from './model-clip-gesture.js';
|
|
39
|
+
import { createModelClipSession } from './model-clip-session.js';
|
|
40
|
+
import { createModelClipThreeOverlay } from './model-clip-three-overlay.js';
|
|
41
|
+
import { createModelClipThreePreview } from './model-clip-three-preview.js';
|
|
42
|
+
import { MODEL_LIGHTING_PROFILES, modelMeshCastsShadow, modelShadowsEnabled, modelSunDirection, normalizeModelLighting } from './model-viewport-lighting.js';
|
|
43
|
+
import { mountModelClipList } from './model-clip-list.js';
|
|
28
44
|
|
|
29
45
|
let renderer, scene, perspCam, orthoCam, camera, controls, root, api, canvasEl, ro, rafId, grid, raycaster, downXY, lastPick = '(none)';
|
|
46
|
+
let viewportController = null;
|
|
47
|
+
let cadInputArbiter = null;
|
|
48
|
+
let selectionTools = null;
|
|
49
|
+
let cadToolController = null, cadToolDispatch = false;
|
|
50
|
+
let measureSession = null, measurePendingMeta = null;
|
|
51
|
+
const measureProviderData = new Map();
|
|
52
|
+
let spatialTools = null;
|
|
53
|
+
let spatialFrameSignature = '';
|
|
54
|
+
let clipSession = null, clipOverlay = null, clipCreationPreview = null, releaseClipGestureInput = null, releaseClipOverlayInput = null, releaseClipSpatial = null, releaseClipSession = null, sharedClipList = null, sharedClipEdit = null;
|
|
55
|
+
let viewportReports = null;
|
|
56
|
+
let viewportIdentity = createEntityKeyRegistry();
|
|
30
57
|
let lightAmb, lightKey, lightFill; // dimmed in Realistic, where the environment lights the scene
|
|
58
|
+
const STEEL_MODEL_LIGHTING_DEFAULTS = MODEL_LIGHTING_PROFILES.steel;
|
|
59
|
+
let modelLighting = STEEL_MODEL_LIGHTING_DEFAULTS;
|
|
31
60
|
let shadowGround = null, shadowsEnabled = false; // the `shadowed` mode's ground catcher + its compiled state
|
|
32
61
|
let pending = null, dragging = null, marker = null, readout = null; // pending = member gesture; readout = drag dimension overlay
|
|
33
62
|
let boxSel = null, rubber = null; // LEFT-drag-on-empty rubber-band multi-select
|
|
@@ -39,6 +68,8 @@ let epRing = null, epPreview = null, epMovedLine = null; // white ring on
|
|
|
39
68
|
let hoverEp = null, dragEp = null; // {id,end} of the hovered / dragged end node
|
|
40
69
|
let refGroup = null; let refLineOn = false; // optional reference (work) lines between each member's end points
|
|
41
70
|
let insertMode = false; // armed "place a vectored detail" pick (mirrors clipMode)
|
|
71
|
+
let detailPlanePick = null; // after click 1: the locked member face plane; click 2 chooses its exact point
|
|
72
|
+
let detailPlaneCandidates = null; // snap candidates captured with that plane, then filtered to points genuinely on it
|
|
42
73
|
let connPick = null; // armed "name the members this connection joins" pick — {jointId, chosen:Set<id>}
|
|
43
74
|
let insertPending = null; // {name,url} — the detail the editor queued for the next placement click
|
|
44
75
|
let basePickCol = null; // Mode B: armed "trim column to base" pick — the target column id, or null
|
|
@@ -81,8 +112,8 @@ let connHidden = new Set(); // explicit per-PART hide (legend co
|
|
|
81
112
|
let selectionHidden = new Set(); // session-only per-mesh hide from the toolbar's Hide selected action; raw renderer ids never enter the tagged saved-view contract
|
|
82
113
|
let isolatedGridIds = null; // isolate-selected's logical grid-line half; null = no isolation, an empty Set intentionally hides every grid
|
|
83
114
|
let gridSelectionHidden = new Set(); // session-only logical grid lines hidden by Hide selected (never mutates the authored grid)
|
|
84
|
-
let
|
|
85
|
-
|
|
115
|
+
let orientationOverlay = null; // canonical shared ViewCube + world-axis triad mount
|
|
116
|
+
const orientationListeners = new Set(); // model.orientation.v1 subscribers (the shared mount is one)
|
|
86
117
|
const DRAG_TOL_PX = 4; // movement past this = a drag (not a click)
|
|
87
118
|
import { endpointDragPoint } from './steel-3d-core.js';
|
|
88
119
|
const SNAP_TOL_PX = 10; // snap an endpoint to a target within this screen distance
|
|
@@ -143,6 +174,9 @@ function candAllowed3d(type) {
|
|
|
143
174
|
// stays free there. Dimensions stay free 3D (they measure across elevations). Read live from the editor
|
|
144
175
|
// per hover so the toggle is instant — no candidate-cache rebuild. `dragged` is the cursor on the plane.
|
|
145
176
|
const WP_SNAP_TOL_MM = 1;
|
|
177
|
+
// An almost edge-on plane turns a few pointer pixels into an enormous jump across the model.
|
|
178
|
+
// Keep the marker under the real pointer when the pick is honest; require a small orbit when it is not.
|
|
179
|
+
const DETAIL_PLANE_MIN_RAY_DOT = 0.18;
|
|
146
180
|
function candOnActiveWP(c, dragged, wp) {
|
|
147
181
|
if (!api || !api.snap3dFree || api.snap3dFree()) return true; // free 3D (default) → no plane constraint
|
|
148
182
|
if (!wp || !wp.normal || !wp.origin) return true; // no valid plane → fail open (free); never throw out of the .filter() and break the pointer interaction
|
|
@@ -162,6 +196,7 @@ let inputActive = true; // does this view own the keyboard? The editor
|
|
|
162
196
|
// is the active one in a split — see setInputActive.
|
|
163
197
|
let dims3dGroup = null; // THREE.Group of placed-dim lines (+ the live preview line)
|
|
164
198
|
let dimPreviewLine = null; // reused preview line (point 1 → cursor)
|
|
199
|
+
let sharedSnapGuideGroup = null; // provider paint for guides emitted by the common contextual snap solvers
|
|
165
200
|
let dimLabelHost = null; // fixed-position container for label overlays
|
|
166
201
|
const dimLabelPool = []; // reused <div> labels, one per placed dim, positioned in the loop
|
|
167
202
|
let dimCandidates3d = null; // snap candidates cached for the active placement gesture
|
|
@@ -171,9 +206,405 @@ const overlayLabelPool = []; // reused <div> label chips for the overlay di
|
|
|
171
206
|
let dimParts = []; // the dim-relevant scene elements retained from the last build (plates + copes) to derive overlays from
|
|
172
207
|
const DIM_TICK = 8; // mm: length of the 45° CAD terminator tick — shared by placed dims (refreshDims) + derived overlays (cadDim)
|
|
173
208
|
|
|
174
|
-
function
|
|
209
|
+
function viewportBoxReceipt(box) {
|
|
210
|
+
return box && !box.isEmpty() ? { min: box.min.toArray(), max: box.max.toArray() } : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function viewportBounds(purpose) {
|
|
214
|
+
if (purpose === 'native-model') return viewportBoxReceipt(sceneBox);
|
|
215
|
+
if (purpose === 'camera-selection') {
|
|
216
|
+
if (!selIds.size) return viewportBoxReceipt(visibleWorldBox());
|
|
217
|
+
const selected = new THREE.Box3();
|
|
218
|
+
for (const id of selIds) {
|
|
219
|
+
const mesh = meshById.get(id), detail = String(id).startsWith('det:');
|
|
220
|
+
if (detail && mesh && (mesh.userData._detailOpacity == null ? mesh.material.opacity : mesh.userData._detailOpacity) <= 0) continue;
|
|
221
|
+
if (meshContributesPixels(mesh, displayMode === 'wire' && !detail)) selected.expandByObject(mesh);
|
|
222
|
+
}
|
|
223
|
+
return viewportBoxReceipt(selected);
|
|
224
|
+
}
|
|
225
|
+
return viewportBoxReceipt(visibleWorldBox());
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function viewportReferenceObjectSource(refId, index) {
|
|
229
|
+
return api?.referenceObjectSelectionSource?.(refId, index) ?? null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function viewportRenderRecords() {
|
|
233
|
+
const records = [
|
|
234
|
+
...[...meshById].map(([id, object]) => ({ key: viewportIdentity.registerSync('native', id).key, object, layer: 'model', selectable: true, providerToken: id })),
|
|
235
|
+
...[...structGridLines].map(([id, object]) => ({ key: viewportIdentity.registerSync('grid', id).key, object, layer: 'datum', selectable: true, providerToken: id })),
|
|
236
|
+
];
|
|
237
|
+
for (const [refId, entry] of xrefById) {
|
|
238
|
+
records.push({ key: viewportIdentity.registerSync('reference', refId).key, object: entry.group, layer: 'reference', selectable: true, providerToken: refId });
|
|
239
|
+
for (let index = 0; index < (entry.objects?.length ?? 0); index++) {
|
|
240
|
+
const sourceId = viewportReferenceObjectSource(refId, index); if (!sourceId) continue;
|
|
241
|
+
records.push({ key: viewportIdentity.registerSync('reference-object', sourceId).key,
|
|
242
|
+
object: entry.combined ?? entry.opaque ?? entry.translucent ?? entry.group,
|
|
243
|
+
layer: 'reference', selectable: true, providerToken: refId, instanceIndex: index });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return records;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function viewportRaycastRecords(event) {
|
|
250
|
+
if (!event || !Number.isFinite(event.clientX) || !Number.isFinite(event.clientY)) return [];
|
|
251
|
+
const native = meshHitsAt(event.clientX, event.clientY).map((hit) => {
|
|
252
|
+
const id = hit.object?.userData?.id;
|
|
253
|
+
return id ? { providerToken: id, key: viewportIdentity.registerSync('native', id).key,
|
|
254
|
+
point: hit.point?.toArray?.() ?? null, normal: hit.face?.normal?.toArray?.() ?? null, distance: hit.distance } : null;
|
|
255
|
+
}).filter(Boolean);
|
|
256
|
+
if (native.length) return native;
|
|
257
|
+
const reference = pickReferenceAt(event.clientX, event.clientY);
|
|
258
|
+
if (!reference) return [];
|
|
259
|
+
if (reference.objectIndex >= 0) {
|
|
260
|
+
const sourceId = viewportReferenceObjectSource(reference.referenceId, reference.objectIndex);
|
|
261
|
+
if (sourceId) return [{ providerToken: reference.referenceId, key: viewportIdentity.registerSync('reference-object', sourceId).key,
|
|
262
|
+
batchId: reference.batchId, point: reference.point, normal: reference.normal, distance: reference.distance }];
|
|
263
|
+
}
|
|
264
|
+
return [{ providerToken: reference.referenceId, key: viewportIdentity.registerSync('reference', reference.referenceId).key,
|
|
265
|
+
point: reference.point, normal: reference.normal, distance: reference.distance }];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function createSharedViewport(canvas, initialSelectionCommit = null) {
|
|
269
|
+
const hooks = {
|
|
270
|
+
mount: (context) => { viewportReports = context; },
|
|
271
|
+
unmount: () => { viewportReports = null; },
|
|
272
|
+
rebuild: async (fit, context) => { await rebuildSteel(fit); return { empty: !built, cameraFitted: camFitted, epoch: context.epoch }; },
|
|
273
|
+
bounds: viewportBounds,
|
|
274
|
+
fit: ({ purpose }) => purpose === 'camera-selection' ? frameSelectionSteel() : frameAllSteel(),
|
|
275
|
+
setPaintAllowed: (on) => { camFramed = on === true; if (!camFramed) hideLabelHosts(); },
|
|
276
|
+
setSelectionState, selectReference, selectReferenceObject,
|
|
277
|
+
selectReferenceObjectReceipt: (refId, stable) => { const index = api?.referenceObjectSelectionIndex?.(refId, stable); return Number.isInteger(index) && index >= 0 ? selectReferenceObject(refId, index) : selectReference(null); },
|
|
278
|
+
setHover,
|
|
279
|
+
setProjection: setProjectionSteel, setDisplayMode: setDisplayModeSteel, displayMode: () => displayMode, applyView: applyViewSteel, cameraState, setCameraState: setCameraStateSteel,
|
|
280
|
+
sectionState: () => ({ clipping: clipState().clips, selectedClipIds: clipState().selected, workPlane: workPlaneInfo(), workArea: clipState().workArea,
|
|
281
|
+
activeClipGesture: clipMode ? { kind: 'clip', mode: clipMode } : (wpMode ? { kind: 'work-plane', mode: wpMode } : null) }),
|
|
282
|
+
setSectionState: (value) => setClipStateSteel({ clips: value.clipping || [], workArea: value.workArea || null, selected: value.selectedClipIds || [], seq: clipSeq }),
|
|
283
|
+
objectsState: objectsPaneState, applyObjectsState: applyObjectsPaneState,
|
|
284
|
+
hideSelection: hideSelectedSteel, isolateSelection: isolateSelectedSteel, isIsolated, clearIsolation,
|
|
285
|
+
clearVisibility: showAllGroupsSteel, hasVisibilityFilter,
|
|
286
|
+
show: showSteel, hide: hideSteel, dispose: disposeSteel,
|
|
287
|
+
resize,
|
|
288
|
+
render: renderSteelFrame,
|
|
289
|
+
renderRecords: viewportRenderRecords,
|
|
290
|
+
raycastRecords: viewportRaycastRecords,
|
|
291
|
+
pick: (payload) => viewportRaycastRecords(payload)[0] ?? null,
|
|
292
|
+
blockOrbit: () => { const was = controls ? controls.enabled : false; if (controls) controls.enabled = false; return () => { if (controls) controls.enabled = was; }; },
|
|
293
|
+
};
|
|
294
|
+
const adapter = createSteelViewportAdapter({ hooks, identityRegistry: viewportIdentity });
|
|
295
|
+
const platform = {
|
|
296
|
+
requestFrame: (callback) => requestAnimationFrame(callback),
|
|
297
|
+
cancelFrame: (id) => cancelAnimationFrame(id),
|
|
298
|
+
// #1419: the controller races a timer against every animation frame so a viewport in a window that
|
|
299
|
+
// is not being composited keeps redrawing. A tab the browser reports as hidden is not that case —
|
|
300
|
+
// nobody is looking — so it opts out of the fallback and idles as it always has.
|
|
301
|
+
pageHidden: () => document.visibilityState === 'hidden',
|
|
302
|
+
observeResize: (surface, callback) => { ro = new ResizeObserver(callback); ro.observe(surface.parentElement || surface); return () => { if (ro) ro.disconnect(); ro = null; }; },
|
|
303
|
+
measureSurface: (surface) => { const el = surface.parentElement || surface; return { width: el.clientWidth || 1, height: el.clientHeight || 1, pixelRatio: Math.min(window.devicePixelRatio || 1, 2) }; },
|
|
304
|
+
win: null,
|
|
305
|
+
};
|
|
306
|
+
const controller = createModelViewportController({ adapter, platform, identityRegistry: viewportIdentity, initialSelectionCommit });
|
|
307
|
+
controller.init(canvas);
|
|
308
|
+
return controller;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// The shared spatial store is the provider-neutral state authority. Steel still owns Three.js objects,
|
|
312
|
+
// rich clip handles and its contract persistence; each provider mutation publishes one canonical mm
|
|
313
|
+
// snapshot here so saved views, frames, sectioning and visibility have the same semantics as Revit.
|
|
314
|
+
function syncSpatialVisibility() {
|
|
315
|
+
if (!spatialTools) return;
|
|
316
|
+
const hidden = [
|
|
317
|
+
...[...groupHidden].map((id) => `group:${id}`),
|
|
318
|
+
...[...connHidden].map((id) => `object:${id}`),
|
|
319
|
+
...[...selectionHidden].map((id) => `object:${id}`),
|
|
320
|
+
...[...gridSelectionHidden].map((id) => `grid:${id}`),
|
|
321
|
+
];
|
|
322
|
+
const isolated = [
|
|
323
|
+
...[...soloGroups].map((id) => `group:${id}`),
|
|
324
|
+
...(isolatedIds ? [...isolatedIds].map((id) => `object:${id}`) : []),
|
|
325
|
+
...(isolatedGridIds ? [...isolatedGridIds].map((id) => `grid:${id}`) : []),
|
|
326
|
+
];
|
|
327
|
+
spatialTools.setVisibility({ hidden, isolated });
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function syncSpatialSections() {
|
|
331
|
+
if (!spatialTools) return;
|
|
332
|
+
spatialTools.replaceSections({
|
|
333
|
+
clips: clips.map((clip) => clip.kind === 'box'
|
|
334
|
+
? { id: clip.id, kind: 'box', min: clip.box.min.toArray(), max: clip.box.max.toArray(), enabled: clip.enabled, label: clip.label }
|
|
335
|
+
: { id: clip.id, kind: 'plane', origin: clip.point.toArray(), normal: clip.n.toArray(), enabled: clip.enabled, label: clip.label }),
|
|
336
|
+
workArea: workArea ? { min: workArea.box.min.toArray(), max: workArea.box.max.toArray(), wholeParts: !!workArea.whole, visible: !!workArea.enabled } : null,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function adoptSharedClips(state) {
|
|
341
|
+
const incoming = state?.clips ?? [];
|
|
342
|
+
const signature = JSON.stringify(incoming);
|
|
343
|
+
if (signature === adoptSharedClips.signature) return;
|
|
344
|
+
adoptSharedClips.signature = signature;
|
|
345
|
+
clips = incoming.map((value) => {
|
|
346
|
+
const clip = value.kind === 'box'
|
|
347
|
+
? { id: value.id, kind: 'box', enabled: value.enabled !== false, label: value.label, box: new THREE.Box3(new THREE.Vector3(...value.min), new THREE.Vector3(...value.max)), planes: [] }
|
|
348
|
+
: { id: value.id, kind: 'plane', enabled: value.enabled !== false, label: value.label, n: new THREE.Vector3(...value.normal), point: new THREE.Vector3(...value.origin), planes: [] };
|
|
349
|
+
rebuildClipPlanes(clip); return clip;
|
|
350
|
+
});
|
|
351
|
+
applyClips(); clipOverlay?.render();
|
|
352
|
+
}
|
|
353
|
+
adoptSharedClips.signature = '';
|
|
354
|
+
|
|
355
|
+
function syncSpatialFrames() {
|
|
356
|
+
if (!spatialTools) return;
|
|
357
|
+
const signature = JSON.stringify({ frame3d, workPlane, wpVisible });
|
|
358
|
+
if (signature === spatialFrameSignature) return;
|
|
359
|
+
spatialFrameSignature = signature;
|
|
360
|
+
const hasLocal = spatialTools.state().frames.some((frame) => frame.id === 'local');
|
|
361
|
+
if (frame3d) spatialTools.setLocalTransform({ origin: frame3d.origin, xAxis: frame3d.xAxis, yAxis: frame3d.yAxis });
|
|
362
|
+
else if (hasLocal) spatialTools.removeFrame('local');
|
|
363
|
+
if (workPlane) {
|
|
364
|
+
spatialTools.setWorkPlaneFromFace({ origin: workPlane.origin, normal: workPlane.normal, xHint: workPlane.xAxis, providerRef: 'steel:working-plane' });
|
|
365
|
+
if (!wpVisible) spatialTools.setWorkPlaneVisible(false);
|
|
366
|
+
} else {
|
|
367
|
+
spatialTools.clearWorkPlane();
|
|
368
|
+
if (frame3d) spatialTools.activateFrame('local'); else spatialTools.resetGlobal();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function replaceSpatialViews(views) {
|
|
373
|
+
if (!spatialTools) return null;
|
|
374
|
+
for (const view of spatialTools.state().savedViews) spatialTools.deleteView(view.id);
|
|
375
|
+
for (const view of Array.isArray(views) ? views : []) spatialTools.saveView(view);
|
|
376
|
+
return spatialTools.state().savedViews;
|
|
377
|
+
}
|
|
378
|
+
function saveSpatialView(view) {
|
|
379
|
+
if (!spatialTools || !view?.id) return null;
|
|
380
|
+
const exists = spatialTools.state().savedViews.some((item) => item.id === view.id);
|
|
381
|
+
return exists ? spatialTools.updateView(view.id, view) : spatialTools.saveView(view);
|
|
382
|
+
}
|
|
383
|
+
function deleteSpatialView(id) { return spatialTools?.deleteView(id) ?? null; }
|
|
384
|
+
function spatialState() { return spatialTools?.state() ?? null; }
|
|
385
|
+
|
|
386
|
+
// The common session owns the complete dimension lifecycle and serializable point/presentation state.
|
|
387
|
+
// Steel owns only its provider rendering metadata (`axisDir`) and maps the neutral records back to the
|
|
388
|
+
// existing contract shape so old projects and the current Three presentation remain byte-compatible.
|
|
389
|
+
function steelMeasureDimensions() {
|
|
390
|
+
const records = measureSession?.dimensions?.() ?? api?.getDims3d?.() ?? [];
|
|
391
|
+
return records.map((dimension) => {
|
|
392
|
+
const provider = measureProviderData.get(dimension.id) ?? {};
|
|
393
|
+
return { id: dimension.id, a: [...dimension.a], b: [...dimension.b], axis: provider.axis ?? 'free',
|
|
394
|
+
...(provider.axisDir ? { axisDir: [...provider.axisDir] } : {}) };
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
function publishMeasureSession(value, reason) {
|
|
398
|
+
if (!api?.onMeasureSessionChange) return;
|
|
399
|
+
const dimensions = (value?.dimensions ?? []).map((dimension) => {
|
|
400
|
+
const provider = measureProviderData.get(dimension.id) ?? measurePendingMeta ?? {};
|
|
401
|
+
return { id: dimension.id, a: [...dimension.a], b: [...dimension.b], axis: provider.axis ?? 'free',
|
|
402
|
+
...(provider.axisDir ? { axisDir: [...provider.axisDir] } : {}) };
|
|
403
|
+
});
|
|
404
|
+
api.onMeasureSessionChange(dimensions, reason);
|
|
405
|
+
}
|
|
406
|
+
function reflectMeasureSession(state) {
|
|
407
|
+
dimMode3d = !!state.armed; dims3dVisibleFlag = state.visible !== false;
|
|
408
|
+
dimLock.clear(); for (const key of state.locks ?? []) dimLock.add(key);
|
|
409
|
+
dimDraft3d = state.first ? { a: [...state.first.point], ...(state.second ? { b: [...state.second.point] } : {}) } : null;
|
|
410
|
+
if (renderer) { reflectDimBar(); updateStatusChip(); refreshDims(); }
|
|
411
|
+
}
|
|
412
|
+
function initMeasureSession() {
|
|
413
|
+
measureSession?.dispose?.(); measureProviderData.clear();
|
|
414
|
+
const initial = (api?.getDims3d?.() ?? []).map((dimension) => {
|
|
415
|
+
measureProviderData.set(dimension.id, { axis: dimension.axis ?? 'free', axisDir: dimension.axisDir ? [...dimension.axisDir] : null });
|
|
416
|
+
return { id: dimension.id, a: dimension.a, b: dimension.b, offsetPx: 0,
|
|
417
|
+
locks: dimension.axis && dimension.axis !== 'free' ? [dimension.axis] : [] };
|
|
418
|
+
});
|
|
419
|
+
measureSession = createModelMeasureSession({ initialDimensions: initial,
|
|
420
|
+
onState: (state) => reflectMeasureSession(state),
|
|
421
|
+
onChange: (value, reason) => publishMeasureSession(value, reason) });
|
|
422
|
+
}
|
|
423
|
+
function measureAcquisition(result) {
|
|
424
|
+
return { status: 'acquired', candidateId: `${result.type || 'free'}:${result.p.map((value) => Number(value).toPrecision(12)).join(':')}`,
|
|
425
|
+
kind: result.type === 'intersection' ? 'semantic-intersection' : result.type || 'free-point',
|
|
426
|
+
pointMm: [...result.p], generation: sharedSnapGeneration(), providerRef: null };
|
|
427
|
+
}
|
|
428
|
+
function removeMeasureById(id) {
|
|
429
|
+
const index = measureSession?.dimensions?.().findIndex((dimension) => dimension.id === id) ?? -1;
|
|
430
|
+
if (index < 0) return false; measureProviderData.delete(id); return measureSession.remove(index);
|
|
431
|
+
}
|
|
432
|
+
function selectMeasureById(id) {
|
|
433
|
+
const index = measureSession?.dimensions?.().findIndex((dimension) => dimension.id === id) ?? -1;
|
|
434
|
+
return measureSession?.select(index >= 0 ? index : null);
|
|
435
|
+
}
|
|
436
|
+
function updateMeasureById(id, patch) {
|
|
437
|
+
const index = measureSession?.dimensions?.().findIndex((dimension) => dimension.id === id) ?? -1;
|
|
438
|
+
return index >= 0 ? measureSession.update(index, patch) : false;
|
|
439
|
+
}
|
|
440
|
+
function setMeasurePresentation(presentation) { return measureSession?.setPresentation?.(presentation) ?? null; }
|
|
441
|
+
|
|
442
|
+
// Steel keeps provider-specific connection drill-down and reference identity, but the gesture policy
|
|
443
|
+
// (single/toggle, overlap cycle, LTR window vs RTL crossing, Escape and Ctrl+A) is the same policy every
|
|
444
|
+
// model surface uses. This narrow coordinator is the mutation port: the shared tool hands it neutral
|
|
445
|
+
// entities and it delegates the resulting transaction to Steel's existing selection boundary.
|
|
446
|
+
function steelSelectionEntries() {
|
|
447
|
+
const entries = [
|
|
448
|
+
...[...selIds].map((sourceId) => ({ kind: 'native', sourceId })),
|
|
449
|
+
...[...selectedGridIds].map((sourceId) => ({ kind: 'grid', sourceId })),
|
|
450
|
+
];
|
|
451
|
+
if (xrefSubSelected) entries.push({ kind: 'reference-object', sourceId: JSON.stringify([xrefSubSelected.refId, xrefSubSelected.index]) });
|
|
452
|
+
else if (xrefSelected) entries.push({ kind: 'reference', sourceId: xrefSelected });
|
|
453
|
+
return entries;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function commitSteelSelectionEntities(entities, additive) {
|
|
457
|
+
const native = entities.filter((entry) => entry.kind === 'native').map((entry) => entry.sourceId);
|
|
458
|
+
const grids = entities.filter((entry) => entry.kind === 'grid').map((entry) => entry.sourceId);
|
|
459
|
+
const refObject = entities.find((entry) => entry.kind === 'reference-object');
|
|
460
|
+
const ref = entities.find((entry) => entry.kind === 'reference');
|
|
461
|
+
if (refObject && !native.length && !grids.length) {
|
|
462
|
+
try { const [refId, index] = JSON.parse(refObject.sourceId); if (selectReferenceObject(refId, Number(index))) return; } catch (_) {}
|
|
463
|
+
}
|
|
464
|
+
if (ref && !native.length && !grids.length) { selectReference(ref.sourceId); return; }
|
|
465
|
+
if (!native.length && !grids.length) {
|
|
466
|
+
selectReference(null); resetConnState();
|
|
467
|
+
if (api?.onSelectBatch) api.onSelectBatch({ memberIds: [], gridIds: [] }, additive);
|
|
468
|
+
else if (api?.onSelectMany) api.onSelectMany([], additive);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
selectReference(null);
|
|
472
|
+
const conns = new Set(native.map(connOf).filter(Boolean));
|
|
473
|
+
if (!additive && native.length === 1 && conns.size === 1) {
|
|
474
|
+
const picked = native[0]; const conn = connOf(picked);
|
|
475
|
+
if (ctxConn === conn) {
|
|
476
|
+
const group = boltGroupOf(picked);
|
|
477
|
+
if (api?.onSelectMany) api.onSelectMany(group, false); else if (api?.onSelect) api.onSelect(picked, false);
|
|
478
|
+
} else selectWholeConn(conn);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const allOneConnection = conns.size === 1 && native.length > 0 && native.every((id) => connOf(id) === [...conns][0]);
|
|
482
|
+
if (!additive && allOneConnection) {
|
|
483
|
+
const conn = [...conns][0]; const children = connChildIds(conn);
|
|
484
|
+
if (children.length === native.length && children.every((id) => native.includes(id))) {
|
|
485
|
+
if (grids.length) selectWholeConnWithGrids(conn, grids); else selectWholeConn(conn);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
resetConnState();
|
|
490
|
+
if (api?.onSelectBatch) api.onSelectBatch({ memberIds: native, gridIds: grids }, additive);
|
|
491
|
+
else if (grids.length && api?.onSelectGrid) for (const id of grids) api.onSelectGrid(id, additive);
|
|
492
|
+
else if (api?.onSelectMany) api.onSelectMany(native, additive);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/*
|
|
496
|
+
* Every commit the selection tools make passes through this port, and each one is the user's own pick: a click, a
|
|
497
|
+
* double-click, a box, Ctrl+A, Esc. A reference emitted while one runs is tagged `{ origin: 'pick' }`, because the
|
|
498
|
+
* same reference is also re-emitted by every presentation change (a display mode, Ghost, a rebuild re-applies the
|
|
499
|
+
* selection) and the editor must tell the two apart: re-picking the selected reference hands the Properties panel
|
|
500
|
+
* back from a saved view, while switching to Wire with that view shown must not (#1437).
|
|
501
|
+
*/
|
|
502
|
+
let referencePickDepth = 0;
|
|
503
|
+
function commitSteelPick(entities, additive) {
|
|
504
|
+
referencePickDepth++;
|
|
505
|
+
try { commitSteelSelectionEntities(entities, additive); } finally { referencePickDepth--; }
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function steelSelectionCoordinatorPort() {
|
|
509
|
+
return Object.freeze({
|
|
510
|
+
entries: steelSelectionEntries,
|
|
511
|
+
replaceAll(entities) { commitSteelPick(entities || [], false); },
|
|
512
|
+
toggle(entities) { commitSteelPick(entities || [], true); },
|
|
513
|
+
clear() { commitSteelPick([], false); },
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function steelSelectionHitsAt(pointer, event) {
|
|
518
|
+
let gridHit = null; let meshHits = [];
|
|
519
|
+
try { gridHit = pickGridAt(pointer.x, pointer.y); } catch (err) { console.error('steel-3d: shared grid hit-test failed', err); }
|
|
520
|
+
try { meshHits = meshHitsAt(pointer.x, pointer.y); } catch (err) { console.error('steel-3d: shared mesh hit-test failed', err); }
|
|
521
|
+
const occluders = OPAQUE_MODES.has(displayMode) ? meshHits.filter(occludesGrid) : [];
|
|
522
|
+
const meshDepth = occluders.length ? occluders[0].point.clone().project(camera).z : Infinity;
|
|
523
|
+
if (gridHit && gridDepthWins(gridHit.depth, meshDepth)) {
|
|
524
|
+
return [{ entity: { kind: 'grid', sourceId: gridHit.id }, selectable: !api?.canSelectGrid || api.canSelectGrid(), rawVisible: true }];
|
|
525
|
+
}
|
|
526
|
+
const native = []; const seen = new Set();
|
|
527
|
+
for (const hit of meshHits) {
|
|
528
|
+
const id = hit.object?.userData?.id; if (!id || seen.has(id)) continue; seen.add(id);
|
|
529
|
+
native.push({ entity: { kind: 'native', sourceId: id }, selectable: !api?.canSelectId || api.canSelectId(id), rawVisible: true });
|
|
530
|
+
}
|
|
531
|
+
if (native.length) return native;
|
|
532
|
+
let reference = null; try { reference = pickReferenceAt(pointer.x, pointer.y); } catch (_) {}
|
|
533
|
+
if (!reference) return [];
|
|
534
|
+
const selectable = !api?.canSelectReference || api.canSelectReference();
|
|
535
|
+
if ((event?.ctrlKey || event?.metaKey) && Number.isInteger(reference.objectIndex) && reference.objectIndex >= 0) {
|
|
536
|
+
return [{ entity: { kind: 'reference-object', sourceId: JSON.stringify([reference.referenceId, reference.objectIndex]) }, selectable, rawVisible: true }];
|
|
537
|
+
}
|
|
538
|
+
return [{ entity: { kind: 'reference', sourceId: reference.referenceId }, selectable, rawVisible: true }];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function steelMarqueeHits(rect) {
|
|
542
|
+
const x0 = rect.mode === 'enclosed' ? rect.left : rect.right;
|
|
543
|
+
const x1 = rect.mode === 'enclosed' ? rect.right : rect.left;
|
|
544
|
+
const native = [...membersInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed'), ...detailsInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed')];
|
|
545
|
+
for (const conn of connsInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed')) native.push(...connChildIds(conn));
|
|
546
|
+
return [
|
|
547
|
+
...[...new Set(native)].map((sourceId) => ({ entity: { kind: 'native', sourceId }, selectable: !api?.canSelectId || api.canSelectId(sourceId), rawVisible: true })),
|
|
548
|
+
...gridsInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed').map((sourceId) => ({ entity: { kind: 'grid', sourceId }, selectable: !api?.canSelectGrid || api.canSelectGrid(), rawVisible: true })),
|
|
549
|
+
];
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function paintSteelMarquee(rect) {
|
|
553
|
+
if (!rubber) return;
|
|
554
|
+
if (!rect) { rubber.style.display = 'none'; return; }
|
|
555
|
+
rubber.style.left = rect.left + 'px'; rubber.style.top = rect.top + 'px';
|
|
556
|
+
rubber.style.width = (rect.right - rect.left) + 'px'; rubber.style.height = (rect.bottom - rect.top) + 'px';
|
|
557
|
+
rubber.style.borderStyle = rect.mode === 'enclosed' ? 'solid' : 'dashed'; rubber.style.display = 'block';
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function onOrbitStarted() { xrefPreviewCamTouched = true; selectionTools?.interceptor.orbitStart(); }
|
|
561
|
+
function onOrbitChanged() { refMeasureCands = null; selectionTools?.cameraChanged(); viewportReports?.reportCameraState(); }
|
|
562
|
+
function onCanvasEnter() { pointerOverCanvas = true; }
|
|
563
|
+
function onCanvasLeave() {
|
|
564
|
+
pointerOverCanvas = false; hoverEp = null;
|
|
565
|
+
if (hoverRAF) { cancelAnimationFrame(hoverRAF); hoverRAF = 0; }
|
|
566
|
+
setHover(null);
|
|
567
|
+
if (posInteraction !== 'dragging') {
|
|
568
|
+
setPositionHover(null);
|
|
569
|
+
if (posHovered) { posHovered = false; if (api && api.hideHandleTip) api.hideHandleTip(); }
|
|
570
|
+
}
|
|
571
|
+
clipCreationPreview?.show({ kind: 'clear' }); if (clipMode && marker) marker.visible = false; updateStatusChip();
|
|
572
|
+
}
|
|
573
|
+
function onCanvasCancel(event) {
|
|
574
|
+
selectionTools?.interceptor.pointerCancel(event);
|
|
575
|
+
if (pending && pending.posGizmo) restorePositionGizmoMesh(pending.posGizmo);
|
|
576
|
+
const hadPos = !!(pending && pending.posGizmo) || posInteraction === 'dragging';
|
|
577
|
+
const hadDirectMember = !!(pending && (pending.epDrag || pending.geo === 'split'));
|
|
578
|
+
if (hadPos) { endPositionGesture(); hidePositionLeader(); if (readout) readout.style.display = 'none'; renderPositionGizmo(); }
|
|
579
|
+
if (teklaDrag) endTeklaDrag();
|
|
580
|
+
else if (!hadPos && !hadDirectMember) return;
|
|
581
|
+
pending = dragging = null; downXY = null; if (controls) controls.enabled = true;
|
|
582
|
+
if (hadDirectMember) { dragEp = null; if (epPreview) epPreview.visible = false; if (epMovedLine) epMovedLine.visible = false; rebuildEndpoints(); }
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function init(canvas, theApi, options = {}) {
|
|
175
586
|
if (renderer) return; // once
|
|
587
|
+
viewportIdentity = options.identityRegistry ?? createEntityKeyRegistry();
|
|
176
588
|
canvasEl = canvas; api = theApi;
|
|
589
|
+
spatialTools?.dispose(); spatialFrameSignature = '';
|
|
590
|
+
spatialTools = createModelSpatialTools();
|
|
591
|
+
replaceSpatialViews(api?.getSavedViews?.() ?? []);
|
|
592
|
+
syncSpatialFrames(); syncSpatialSections(); syncSpatialVisibility();
|
|
593
|
+
cadToolController = createModelCadToolController({ provider: {
|
|
594
|
+
measureState: () => measureSession?.state?.() ?? ({ armed: dimMode3d, count: api?.getDims3d?.().length ?? 0, visible: dims3dVisibleFlag, locks: [...dimLock] }),
|
|
595
|
+
setMeasureArmed: (on) => {
|
|
596
|
+
if (dimMode3d === on) return;
|
|
597
|
+
cadToolDispatch = true; try { toggleDimTool(); } finally { cadToolDispatch = false; }
|
|
598
|
+
},
|
|
599
|
+
setSnapMode: (kind, on) => {
|
|
600
|
+
const mapped = { endpoint: 'vertex', midpoint: 'midpoint', centerline: 'centerline', intersection: 'intersection',
|
|
601
|
+
perpendicular: 'perpendicular', parallel: 'parallel', extension: 'extension' }[kind];
|
|
602
|
+
if (!mapped) return; if (on) setSnapOnly3d(mapped); else if (snapOnly3d === mapped) setSnapOnly3d(null);
|
|
603
|
+
},
|
|
604
|
+
setMeasureAxisLock: setDimAxis,
|
|
605
|
+
clearMeasures: () => measureSession?.clear?.() ?? api?.onClearDims3d?.(),
|
|
606
|
+
snapState: () => ({ override: snapOnly3d, enabled: api?.snapState?.() ?? null }),
|
|
607
|
+
} });
|
|
177
608
|
renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
|
|
178
609
|
// Off by default and switched on only by the `shadowed` mode: leaving shadow mapping enabled
|
|
179
610
|
// compiles shadow code into every material even when nothing casts, so the cheap modes would still
|
|
@@ -188,36 +619,33 @@ function init(canvas, theApi) {
|
|
|
188
619
|
perspCam.up.set(0, 0, 1); // Z-up to match the scene
|
|
189
620
|
orthoCam = new THREE.OrthographicCamera(-1, 1, 1, -1, 1, 50_000_000);
|
|
190
621
|
orthoCam.up.set(0, 0, 1);
|
|
622
|
+
// A valid model.orientation.v1 pose exists before the first geometry fit so shared chrome can mount
|
|
623
|
+
// transactionally during boot. The ordinary first fit replaces this harmless seed before painting.
|
|
624
|
+
perspCam.position.set(1, -1, 1); orthoCam.position.copy(perspCam.position);
|
|
625
|
+
perspCam.lookAt(0, 0, 0); orthoCam.lookAt(0, 0, 0);
|
|
191
626
|
camera = orthoCam; // default to ORTHO (CAD/Tekla-style parallel projection); the first fitCamera on 3D-entry sizes it (orthoBaseH+reframeOrtho). A saved View or the Persp toggle still switches to perspective.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// a left-drag could mean either "orbit" or "move a member" — the source of "how do I drag in 3D?".
|
|
198
|
-
controls.mouseButtons = { LEFT: null, MIDDLE: THREE.MOUSE.PAN, RIGHT: THREE.MOUSE.ROTATE };
|
|
199
|
-
controls.zoomToCursor = true; // Tekla-style: the mouse position is the centre of zooming
|
|
627
|
+
// Shared FloLess CAD policy: left belongs to model tools, right orbits, middle pans, and wheel
|
|
628
|
+
// zooms to the cursor without post-release easing. Revit and every future provider use this exact
|
|
629
|
+
// policy rather than maintaining a look-alike copy.
|
|
630
|
+
const orbitInput = createCadOrbitEventProxy(canvas);
|
|
631
|
+
controls = new OrbitControls(camera, orbitInput.element);
|
|
200
632
|
// CAD re-pivot: on every orbit/zoom/pan START (OrbitControls fires 'start' for all three — incl. the wheel,
|
|
201
633
|
// BEFORE applying the gesture), move the orbit target to the DEPTH of whatever is under the cursor. Kept ON
|
|
202
634
|
// the view axis so the view never jumps — only the pivot depth changes, which is what makes the wheel converge
|
|
203
635
|
// on a connection detail in a few ticks and orbit/pan scale to it, instead of pivoting around a stale framed
|
|
204
636
|
// centre far away. ponytail: on-axis depth re-pivot, not a true off-axis orbit-about-cursor (OrbitControls
|
|
205
637
|
// always keeps the pivot screen-centred — that would need a custom control); add that only if this isn't enough.
|
|
206
|
-
controls.addEventListener('start', repivotToCursor);
|
|
207
638
|
// The progressive preview auto-frames ONCE, and must not do it to someone who has taken the camera.
|
|
208
639
|
// `start` is the honest signal for "the user did this": it fires on orbit, zoom and pan alike and
|
|
209
640
|
// never on our own `fitCamera`. It matters because the import modal offers "Continue in background"
|
|
210
641
|
// the moment the read starts, so a user can be navigating while the first batch is still arriving.
|
|
211
|
-
controls.addEventListener('start', () => { xrefPreviewCamTouched = true; });
|
|
212
642
|
// The measure's snap set is FRUSTUM-FILTERED, so unlike every other cached candidate list it goes stale
|
|
213
643
|
// the moment the camera moves — orbit past a corner and a cached set would keep offering it (projected
|
|
214
644
|
// to nonsense) while the corners now on screen were absent. Cheap: the rebuild only happens on the next
|
|
215
645
|
// pointer move that actually needs it.
|
|
216
|
-
controls.addEventListener('change', () => { refMeasureCands = null; });
|
|
217
646
|
// …and the two camera changes that do NOT go through OrbitControls: a resize alters the aspect (and
|
|
218
647
|
// so the frustum the set was filtered by), and switching ortho/persp copies the same position onto a
|
|
219
648
|
// camera with a different frustum, which controls.update() sees as no movement at all.
|
|
220
|
-
canvas.addEventListener('wheel', onWheelHover, { capture: true, passive: true }); // keep the cursor pos fresh for the wheel-triggered re-pivot (capture → runs before OrbitControls' wheel handler)
|
|
221
649
|
// Kept on module scope so Realistic can dim them: an environment map is itself a light source, and
|
|
222
650
|
// leaving this rig at full strength on top of it lights the scene roughly twice over.
|
|
223
651
|
lightAmb = new THREE.AmbientLight(0xffffff, 0.65); scene.add(lightAmb);
|
|
@@ -225,6 +653,7 @@ function init(canvas, theApi) {
|
|
|
225
653
|
lightFill = new THREE.DirectionalLight(0xffffff, 0.25); lightFill.position.set(-1, 0.6, 0.4); scene.add(lightFill);
|
|
226
654
|
root = new THREE.Group(); scene.add(root);
|
|
227
655
|
overlayScene = new THREE.Scene(); // clip/work-area gizmos render here in a 2nd unclipped pass (see loop)
|
|
656
|
+
initSharedClipLayer();
|
|
228
657
|
epGroup = new THREE.Group(); scene.add(epGroup);
|
|
229
658
|
// ONE geometry + two materials shared by every endpoint dot (rebuilt often on hover/selection —
|
|
230
659
|
// sharing avoids allocating/leaking a geometry+material per dot each rebuild).
|
|
@@ -270,6 +699,7 @@ function init(canvas, theApi) {
|
|
|
270
699
|
overlayDimsGroup = new THREE.Group(); scene.add(overlayDimsGroup); // derived dim overlays (bolt pitch / edge clearance / cope), toggled from the legend
|
|
271
700
|
dimPreviewLine = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]), new THREE.LineBasicMaterial({ color: 0x22d3ee }));
|
|
272
701
|
dimPreviewLine.material.depthTest = false; dimPreviewLine.renderOrder = 997; dimPreviewLine.visible = false; scene.add(dimPreviewLine);
|
|
702
|
+
sharedSnapGuideGroup = new THREE.Group(); scene.add(sharedSnapGuideGroup);
|
|
273
703
|
// Stage D's kept measured segment. DASHED, and that is the whole point of the treatment: the Dimension
|
|
274
704
|
// tool draws a SOLID line with 45° terminator ticks and PERSISTS it, so a solid line here would read as a
|
|
275
705
|
// dimension the user had just placed rather than as a question they are still asking. Cyan is already
|
|
@@ -349,44 +779,51 @@ function init(canvas, theApi) {
|
|
|
349
779
|
rubber.id = 'm3dRubber';
|
|
350
780
|
rubber.style.cssText = 'position:fixed;display:none;pointer-events:none;z-index:58;border:1px solid var(--brand,#3b82f6);background:rgba(59,130,246,.12)';
|
|
351
781
|
document.body.appendChild(rubber);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// active handle, the grabbing cursor — and a cancelled pointer sends no pointerup, so onUp never runs.
|
|
368
|
-
// Returning early here (as this handler used to for anything but a drag-out) left the gizmo stuck
|
|
369
|
-
// amber over a half-moved preview with orbit disabled, and nothing but another gesture could repair it.
|
|
370
|
-
if (pending && pending.posGizmo) restorePositionGizmoMesh(pending.posGizmo);
|
|
371
|
-
const hadPos = !!(pending && pending.posGizmo) || posInteraction === 'dragging';
|
|
372
|
-
const hadDirectMember = !!(pending && (pending.epDrag || pending.geo === 'split'));
|
|
373
|
-
if (hadPos) { endPositionGesture(); hidePositionLeader(); if (readout) readout.style.display = 'none'; renderPositionGizmo(); }
|
|
374
|
-
if (teklaDrag) endTeklaDrag();
|
|
375
|
-
else if (!hadPos && !hadDirectMember) return;
|
|
376
|
-
pending = dragging = null; downXY = null; if (controls) controls.enabled = true;
|
|
377
|
-
if (hadDirectMember) { dragEp = null; if (epPreview) epPreview.visible = false; if (epMovedLine) epMovedLine.visible = false; rebuildEndpoints(); }
|
|
782
|
+
initMeasureSession();
|
|
783
|
+
selectionTools = createModelSelectionTools({
|
|
784
|
+
coordinator: steelSelectionCoordinatorPort(),
|
|
785
|
+
hitsAt: steelSelectionHitsAt,
|
|
786
|
+
allHits: () => [
|
|
787
|
+
...[...meshById].filter(([, mesh]) => mesh.visible).map(([sourceId]) => ({ entity: { kind: 'native', sourceId }, selectable: !api?.canSelectId || api.canSelectId(sourceId), rawVisible: true })),
|
|
788
|
+
...[...structGridLines].filter(([, line]) => line.visible).map(([sourceId]) => ({ entity: { kind: 'grid', sourceId }, selectable: !api?.canSelectGrid || api.canSelectGrid(), rawVisible: true })),
|
|
789
|
+
],
|
|
790
|
+
marqueeHits: steelMarqueeHits,
|
|
791
|
+
onMarquee: paintSteelMarquee,
|
|
792
|
+
fitSelection: frameSelectionSteel,
|
|
793
|
+
onHover: () => {}, // Steel's richer connection/endpoint hover renderer remains the provider paint port.
|
|
794
|
+
filterHit: (hit) => hit.selectable !== false,
|
|
795
|
+
dragThreshold: DRAG_TOL_PX,
|
|
796
|
+
cycleRadius: CYCLE_TOL_PX,
|
|
378
797
|
});
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
798
|
+
// The shared arbiter owns the complete listener order and CAD navigation. Steel contributes only
|
|
799
|
+
// domain gestures and conflict predicates; it cannot mount a parallel camera/input implementation.
|
|
800
|
+
cadInputArbiter = mountCadInputArbiter({
|
|
801
|
+
surface: canvas, controls, orbitInput, mouse: THREE.MOUSE, getCamera: () => camera, pickPoint: navigationPickPoint,
|
|
802
|
+
applyView: applyViewSteel, fitSelection: frameSelectionSteel,
|
|
803
|
+
isActive: () => !!renderer && !!canvasEl && canvasEl.style.display !== 'none' && inputActive,
|
|
804
|
+
canFitSelection: (event) => !((event.key === 'z' || event.key === 'Z') && event.altKey && tfDraft),
|
|
805
|
+
canApplyView: (name) => !cmActive() && (name !== 'front' || !addActive()) && !wpMode,
|
|
806
|
+
plugin: {
|
|
807
|
+
pointerDown: onDown, windowPointerMove: onMove, windowPointerUp: onUp,
|
|
808
|
+
pointerMove: onHoverMove, pointerEnter: onCanvasEnter, pointerLeave: onCanvasLeave,
|
|
809
|
+
pointerCancel: onCanvasCancel, doubleClick: onDblClick,
|
|
810
|
+
keyDown(event) { const alreadyPrevented = event.defaultPrevented; onKey(event); if (event.defaultPrevented === alreadyPrevented) selectionTools?.interceptor.keyDown(event); onModifierChange(event); }, keyUp: onModifierChange,
|
|
811
|
+
orbitStart: onOrbitStarted, orbitChange: onOrbitChanged,
|
|
812
|
+
},
|
|
813
|
+
});
|
|
814
|
+
releaseClipGestureInput = cadInputArbiter.registerTool(ensureClipGesture().inputPlugin(), { id: 'model-clip', priority: 100, exclusiveGroup: 'model-command' });
|
|
815
|
+
const overlayInput = clipOverlay.inputPlugin();
|
|
816
|
+
releaseClipOverlayInput = cadInputArbiter.registerTool({ ...overlayInput,
|
|
817
|
+
keyDown(event) { return overlayInput.keyDown?.(event) === true || clipSession?.handleKeydown?.(event) === true; },
|
|
818
|
+
}, { id: 'model-clip-overlay', priority: 200 });
|
|
819
|
+
orientationOverlay = mountModelOrientationOverlay({
|
|
820
|
+
cubeHost: document.getElementById('m3dCube'),
|
|
821
|
+
triadHost: document.getElementById('m3dAxes'),
|
|
822
|
+
orientation: steelOrientationPort,
|
|
823
|
+
escapeTarget: canvas,
|
|
824
|
+
});
|
|
825
|
+
viewportController = createSharedViewport(canvas, options.initialSelectionCommit ?? null);
|
|
826
|
+
// The shared controller performs immediate + next-frame sizing and starts its loop only on show().
|
|
390
827
|
}
|
|
391
828
|
|
|
392
829
|
function resize() {
|
|
@@ -434,8 +871,7 @@ let unframedFrames = 0, unframedWarned = false; // a gate that never opens loo
|
|
|
434
871
|
function hideLabelHosts() {
|
|
435
872
|
for (const host of [dimLabelHost, memberLabelHost, propLabelHost, selLenLabelHost]) if (host) host.style.display = 'none';
|
|
436
873
|
}
|
|
437
|
-
function
|
|
438
|
-
rafId = requestAnimationFrame(loop); // MUST stay above the gate: schedule the next frame first, or a shut gate stops the loop dead and the pane never recovers without a re-entry
|
|
874
|
+
function renderSteelFrame() {
|
|
439
875
|
if (!camFramed) {
|
|
440
876
|
// Say so once rather than clear in silence for ever. A permanently shut gate — a /scene POST that
|
|
441
877
|
// never settles, a rebuild that never ran — is pixel-identical to a correctly-rendered empty model,
|
|
@@ -447,6 +883,7 @@ function loop() {
|
|
|
447
883
|
controls.update();
|
|
448
884
|
sizeEndpoints();
|
|
449
885
|
sizeClipHandles();
|
|
886
|
+
clipCreationPreview?.resize();
|
|
450
887
|
sizeFrameHandle();
|
|
451
888
|
// A gesture in flight rebuilds the position gizmo from its live state — here, ONCE per frame, so a 200 Hz
|
|
452
889
|
// pointer cannot rebuild faster than the display draws. It must run BEFORE the sizing pass, so a group
|
|
@@ -466,8 +903,7 @@ function loop() {
|
|
|
466
903
|
renderer.render(overlayScene, camera);
|
|
467
904
|
renderer.autoClear = true; renderer.clippingPlanes = saved;
|
|
468
905
|
}
|
|
469
|
-
|
|
470
|
-
if (triad) { syncTriad(); triad.renderer.render(triad.scene, triad.cam); }
|
|
906
|
+
emitSteelOrientation();
|
|
471
907
|
}
|
|
472
908
|
|
|
473
909
|
const V = (x, y, z) => new THREE.Vector3(x, y, z);
|
|
@@ -697,19 +1133,29 @@ function placeImage(mesh, el) {
|
|
|
697
1133
|
if (ghostUnselectedEnabled && mesh.userData.id && meshById.get(mesh.userData.id) === mesh) applyDisplayMode();
|
|
698
1134
|
});
|
|
699
1135
|
tex.colorSpace = THREE.SRGBColorSpace;
|
|
700
|
-
|
|
1136
|
+
// Keep the actual detail geometry exactly on its picked plane. Polygon offset is a render-only depth
|
|
1137
|
+
// bias that prevents z-fighting without corrupting the model point or making the image float in space.
|
|
1138
|
+
mesh.material = new THREE.MeshBasicMaterial({ map: tex, transparent: true, opacity: el.opacity == null ? 1 : el.opacity, side: THREE.DoubleSide, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 });
|
|
701
1139
|
const u = el.u ? new THREE.Vector3(el.u[0], el.u[1], el.u[2]).normalize() : new THREE.Vector3(1, 0, 0);
|
|
702
1140
|
const n = el.n ? new THREE.Vector3(el.n[0], el.n[1], el.n[2]).normalize() : new THREE.Vector3(0, -1, 0);
|
|
703
1141
|
const vAxis = new THREE.Vector3().crossVectors(n, u).normalize();
|
|
704
1142
|
mesh.quaternion.setFromRotationMatrix(new THREE.Matrix4().makeBasis(u, vAxis, n));
|
|
705
1143
|
if (el.rotZ) mesh.rotateZ((el.rotZ * Math.PI) / 180); // in-plane spin about the plane normal, degrees
|
|
706
|
-
|
|
707
|
-
// z-fighting the member it was dropped on, and so a click selects the detail (frontmost), not the member.
|
|
708
|
-
const OFF = 25;
|
|
709
|
-
mesh.position.set(((el.pos && el.pos[0]) || 0) + n.x * OFF, ((el.pos && el.pos[1]) || 0) + n.y * OFF, ((el.pos && el.pos[2]) || 0) + n.z * OFF);
|
|
1144
|
+
mesh.position.set((el.pos && el.pos[0]) || 0, (el.pos && el.pos[1]) || 0, (el.pos && el.pos[2]) || 0);
|
|
710
1145
|
mesh.renderOrder = 995;
|
|
711
1146
|
}
|
|
712
1147
|
|
|
1148
|
+
// Inspector sliders need a live preview without rebuilding the entire scene on every pointer tick.
|
|
1149
|
+
// The committed contract edit still happens on change; this only paints the already-rendered detail.
|
|
1150
|
+
function setDetailOpacity(id, opacity) {
|
|
1151
|
+
const key = String(id || '').startsWith('det:') ? String(id) : 'det:' + String(id || '');
|
|
1152
|
+
const mesh = meshById.get(key), value = Math.max(0, Math.min(1, Number(opacity)));
|
|
1153
|
+
if (!mesh || !mesh.material || !Number.isFinite(value)) return false;
|
|
1154
|
+
mesh.userData._detailOpacity = value;
|
|
1155
|
+
mesh.material.opacity = value; mesh.material.transparent = true; mesh.material.depthWrite = false; mesh.material.needsUpdate = true;
|
|
1156
|
+
return true;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
713
1159
|
// A cylinder between two points (anchor rod / bolt shank).
|
|
714
1160
|
function placeBar(mesh, a, b, r, radial) {
|
|
715
1161
|
const A = V(a[0], a[1], a[2]), B = V(b[0], b[1], b[2]);
|
|
@@ -958,6 +1404,8 @@ function applyCopes(mesh, cuts) {
|
|
|
958
1404
|
}
|
|
959
1405
|
|
|
960
1406
|
function buildFromScene(sc) {
|
|
1407
|
+
detailPlanePick = null; detailPlaneCandidates = null; // rebuilt meshes invalidate a locked face and its snap set
|
|
1408
|
+
setFacePickPreview(null); // a rebuilt mesh invalidates the hovered triangle region immediately
|
|
961
1409
|
clearRoot();
|
|
962
1410
|
clipCandidates = null; clipLevels = null; invalidateClipFloor(); invalidateModelCache(); // the model changed (edit/undo/redo) — drop the clip-draw snap cache AND the measured floor so a draw in progress re-snaps against the CURRENT members/grid/levels, never stale ones
|
|
963
1411
|
resetConnState(); // a fresh scene rebuilds selection from scratch — drop any stale connection envelope/context
|
|
@@ -1027,6 +1475,7 @@ function buildFromScene(sc) {
|
|
|
1027
1475
|
shadowGround.receiveShadow = true; shadowGround.visible = false;
|
|
1028
1476
|
scene.add(shadowGround);
|
|
1029
1477
|
}
|
|
1478
|
+
applyModelLighting(modelLighting);
|
|
1030
1479
|
renderWorkPlane(); // re-draw the gizmo + reference plane sized to the (possibly new) model bounds
|
|
1031
1480
|
// Retain the dim-relevant parts (plates + copes) so the legend's DIMENSIONS overlays can be derived
|
|
1032
1481
|
// from the resolved geometry — fin-plate holes give bolt pitch/edge clearance, cuts give cope size.
|
|
@@ -1810,6 +2259,7 @@ function setReferences(list) {
|
|
|
1810
2259
|
const selectedObjectWasHere = xrefSubSelected?.refId === ref.id;
|
|
1811
2260
|
revalidateSubSelection(new Map(old ? [[ref.id, old.objects]] : []));
|
|
1812
2261
|
paintReferenceSelection(); paintReferenceSubSelection();
|
|
2262
|
+
viewportController?.refreshRenderRecords();
|
|
1813
2263
|
if (selectedObjectWasHere) emitReferenceSelect();
|
|
1814
2264
|
if (api?.onReferenceGeometryCommit) api.onReferenceGeometryCommit(ref.id, staged.objects);
|
|
1815
2265
|
if (pendingFrameReference === ref.id) { pendingFrameReference = null; frameReference(ref.id); }
|
|
@@ -1828,6 +2278,7 @@ function setReferences(list) {
|
|
|
1828
2278
|
if (xrefSelected && !xrefById.has(xrefSelected)) xrefSelected = null;
|
|
1829
2279
|
revalidateSubSelection(prevObjects);
|
|
1830
2280
|
paintReferenceSelection(); paintReferenceSubSelection();
|
|
2281
|
+
viewportController?.refreshRenderRecords();
|
|
1831
2282
|
}
|
|
1832
2283
|
|
|
1833
2284
|
function _legacySetReferences(list) {
|
|
@@ -2549,15 +3000,20 @@ function pickReferenceAt(cx, cy) {
|
|
|
2549
3000
|
referenceId: u.referenceId,
|
|
2550
3001
|
objectId: batchedObject?.id ?? u.objectId ?? null,
|
|
2551
3002
|
objectIndex: Number.isInteger(batchedIndex) ? batchedIndex : (Number.isInteger(u.objectIndex) ? u.objectIndex : -1),
|
|
3003
|
+
batchId: Number.isInteger(hit.batchId) ? hit.batchId : null,
|
|
3004
|
+
point: hit.point ? hit.point.toArray() : null,
|
|
3005
|
+
normal: hit.face?.normal ? hit.face.normal.toArray() : null,
|
|
3006
|
+
distance: hit.distance,
|
|
2552
3007
|
};
|
|
2553
3008
|
}
|
|
2554
3009
|
|
|
2555
|
-
/** Tell the editor what is selected — the reference, and the one object inside it if there is one
|
|
3010
|
+
/** Tell the editor what is selected — the reference, and the one object inside it if there is one — and whether the
|
|
3011
|
+
* user's own pick is what emitted it (see `commitSteelPick`). */
|
|
2556
3012
|
function emitReferenceSelect() {
|
|
2557
3013
|
if (api && api.onReferenceSelect) {
|
|
2558
3014
|
api.onReferenceSelect(xrefSelected, xrefSubSelected && xrefSelected === xrefSubSelected.refId
|
|
2559
3015
|
? { index: xrefSubSelected.index, id: xrefSubSelected.objectId }
|
|
2560
|
-
: null);
|
|
3016
|
+
: null, referencePickDepth > 0 ? { origin: 'pick' } : null);
|
|
2561
3017
|
}
|
|
2562
3018
|
}
|
|
2563
3019
|
|
|
@@ -2819,14 +3275,16 @@ function referenceInfo() {
|
|
|
2819
3275
|
}
|
|
2820
3276
|
|
|
2821
3277
|
// ---- Insert a vectored detail (Slice 4): arm a placement pick; the editor owns the entry ----
|
|
2822
|
-
// Mirrors setClipMode's arm/disarm.
|
|
2823
|
-
//
|
|
2824
|
-
//
|
|
3278
|
+
// Mirrors setClipMode's arm/disarm. A drawing detail uses the SAME visible face-pick language as Clip:
|
|
3279
|
+
// hover previews the face patch and only a member face can commit. Other insert kinds (connections and
|
|
3280
|
+
// favourites) retain their broader member/ground-plane placement rules.
|
|
2825
3281
|
function setInsertMode(on, pending) {
|
|
2826
3282
|
if (on) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
2827
3283
|
insertMode = !!on;
|
|
2828
3284
|
insertPending = insertMode ? (pending || insertPending) : null;
|
|
3285
|
+
detailPlanePick = null; detailPlaneCandidates = null;
|
|
2829
3286
|
if (insertMode) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); setClipMode(null); disarmFrame3d(); }
|
|
3287
|
+
setFacePickPreview(null);
|
|
2830
3288
|
if (canvasEl) canvasEl.style.cursor = insertMode ? 'crosshair' : 'default';
|
|
2831
3289
|
if (api && api.onInsertModeChange) api.onInsertModeChange(insertMode);
|
|
2832
3290
|
updateStatusChip();
|
|
@@ -2945,8 +3403,68 @@ function basePickPoint(cx, cy) {
|
|
|
2945
3403
|
const s = snapElevation(g.z, basePickLevels, pxToWorldAt(ELEV_SNAP_PX, g)); // screen-scaled tol so the snap window is ~constant on-screen
|
|
2946
3404
|
return { z: s.z, snapped: s.snapped, label: s.label, x: ax, y: ay };
|
|
2947
3405
|
}
|
|
2948
|
-
//
|
|
2949
|
-
//
|
|
3406
|
+
// A drawing detail is design information attached to a REAL member face. It must never fall through to
|
|
3407
|
+
// the invisible ground/working plane: that made empty canvas clicks look successful and left people
|
|
3408
|
+
// unable to see what they had actually picked. `meshHitsAt(..., true)` keeps this on primary members;
|
|
3409
|
+
// the id check is the second line of defence against a detail/reference slipping into that set later.
|
|
3410
|
+
function detailFaceHitAt(cx, cy) {
|
|
3411
|
+
const hit = meshHitsAt(cx, cy, false, true).find((h) => !!h.face) || null;
|
|
3412
|
+
if (!hit) return null;
|
|
3413
|
+
const data = hit.object.userData || {}, id = String(data.id || '');
|
|
3414
|
+
return id && !id.includes(':') && !data.derived ? hit : null;
|
|
3415
|
+
}
|
|
3416
|
+
function detailFacePickFromHit(hit) {
|
|
3417
|
+
if (!hit) return null;
|
|
3418
|
+
const n = hit.face.normal.clone().transformDirection(hit.object.matrixWorld).normalize();
|
|
3419
|
+
const b = planeBasis([n.x, n.y, n.z]);
|
|
3420
|
+
return { point: [hit.point.x, hit.point.y, hit.point.z], u: b.u, n: [n.x, n.y, n.z], anchorId: hit.object.userData.id || null };
|
|
3421
|
+
}
|
|
3422
|
+
// Detail and Clip use ONE exact-face preview and ONE compact plane rectangle. Detail then locks the
|
|
3423
|
+
// chosen plane so its second click can place anywhere on that infinite plane, including past the member.
|
|
3424
|
+
function detailFacePreviewAt(cx, cy) {
|
|
3425
|
+
const hit = detailFaceHitAt(cx, cy); setFacePickPreview(hit); setPlaneHoverPreview(hit);
|
|
3426
|
+
return detailFacePickFromHit(hit);
|
|
3427
|
+
}
|
|
3428
|
+
function lockDetailPlaneAt(cx, cy) {
|
|
3429
|
+
const hit = detailFaceHitAt(cx, cy), pick = detailFacePickFromHit(hit); if (!pick) return null;
|
|
3430
|
+
detailPlanePick = { ...pick, origin: [...pick.point], hit };
|
|
3431
|
+
try { detailPlaneCandidates = allCandidates(); } catch { detailPlaneCandidates = []; }
|
|
3432
|
+
if (canvasEl) canvasEl.style.cursor = 'crosshair'; // an idle snap may have hidden it before this click; step 2 always keeps the real pointer visible
|
|
3433
|
+
setFacePickPreview(hit); setPlaneHoverPreview(hit); updateStatusChip(); notifyInstructor();
|
|
3434
|
+
return detailPlanePick;
|
|
3435
|
+
}
|
|
3436
|
+
function detailPlanePointAt(cx, cy) {
|
|
3437
|
+
if (!detailPlanePick) return null;
|
|
3438
|
+
camera.updateMatrixWorld(); root.updateMatrixWorld(true);
|
|
3439
|
+
const rect = canvasEl.getBoundingClientRect(); if (!rect.width || !rect.height) return null;
|
|
3440
|
+
const ndc = new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1);
|
|
3441
|
+
raycaster.setFromCamera(ndc, camera);
|
|
3442
|
+
const origin = new THREE.Vector3(...detailPlanePick.origin), normal = new THREE.Vector3(...detailPlanePick.n), planePoint = new THREE.Vector3();
|
|
3443
|
+
// Raycast straight from the pointer to the locked face plane so the marker stays under the pointer.
|
|
3444
|
+
// Near edge-on views are blocked because their shallow intersection amplifies tiny pointer moves.
|
|
3445
|
+
if (Math.abs(raycaster.ray.direction.dot(normal)) < DETAIL_PLANE_MIN_RAY_DOT) return null;
|
|
3446
|
+
if (!raycaster.ray.intersectPlane(new THREE.Plane().setFromNormalAndCoplanarPoint(normal, origin), planePoint)) return null;
|
|
3447
|
+
const raw = [planePoint.x, planePoint.y, planePoint.z];
|
|
3448
|
+
const originCandidate = { type: 'vertex', p: [...detailPlanePick.origin], fromId: detailPlanePick.anchorId };
|
|
3449
|
+
const onPlane = [originCandidate, ...(detailPlaneCandidates || []).filter((c) => candAllowed3d(c.type) && candidateOnPlane(c, raw, detailPlanePick.origin, detailPlanePick.n, WP_SNAP_TOL_MM))];
|
|
3450
|
+
const snapped = snapPoint(raw, onPlane, toScreen, SNAP_TOL_PX);
|
|
3451
|
+
// Plane tolerance decides whether a normal object snap is eligible; it must never become placement
|
|
3452
|
+
// depth. Flatten an accepted candidate back to the locked face so the final point is always U/V only.
|
|
3453
|
+
const finalPoint = snapped.candidate ? projectToPlane(snapped.snapped, detailPlanePick.origin, detailPlanePick.n) : snapped.snapped;
|
|
3454
|
+
return { ...detailPlanePick, point: finalPoint, snap: snapped.candidate && snapped.candidate.type };
|
|
3455
|
+
}
|
|
3456
|
+
function detailPlanePreviewAt(cx, cy) {
|
|
3457
|
+
if (!detailPlanePick) return detailFacePreviewAt(cx, cy);
|
|
3458
|
+
const pick = detailPlanePointAt(cx, cy);
|
|
3459
|
+
setFacePickPreview(detailPlanePick.hit);
|
|
3460
|
+
if (!pick) { setPlaneHoverPreview(null); if (marker) marker.visible = false; return null; }
|
|
3461
|
+
setPlaneHoverPreview({ point: new THREE.Vector3(...pick.point), normal: new THREE.Vector3(...pick.n) });
|
|
3462
|
+
if (pick.snap) showMarker(pick.point, pick.snap); else if (marker) marker.visible = false;
|
|
3463
|
+
return pick;
|
|
3464
|
+
}
|
|
3465
|
+
|
|
3466
|
+
// The broader placement raycast used by imported connections/favourites: a member face under the cursor
|
|
3467
|
+
// gives the point + its basis + the member id; empty space drops them on the ground plane.
|
|
2950
3468
|
function insertPick(cx, cy) {
|
|
2951
3469
|
camera.updateMatrixWorld(); root.updateMatrixWorld(true);
|
|
2952
3470
|
const rect = canvasEl.getBoundingClientRect(); if (!rect.width || !rect.height) return null;
|
|
@@ -3531,23 +4049,16 @@ function fitCamera(box, dir) {
|
|
|
3531
4049
|
camFitted = camFramed = true; // the camera now frames something real → durable fact + the loop may paint (see camFitted/camFramed)
|
|
3532
4050
|
}
|
|
3533
4051
|
|
|
3534
|
-
//
|
|
3535
|
-
//
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
// scale to it. Empty space → keep the current pivot (Fit / Home re-centre the model).
|
|
3539
|
-
function onWheelHover(e) { lastHoverXY = [e.clientX, e.clientY]; } // capture-phase wheel → fresh cursor pos for the re-pivot (named so dispose can remove it)
|
|
3540
|
-
function repivotToCursor() {
|
|
3541
|
-
if (!controls || !camera || !canvasEl || !lastHoverXY || !raycaster) return;
|
|
4052
|
+
// Provider boundary for the shared re-pivot rule: Steel supplies the nearest authenticated visible
|
|
4053
|
+
// world point; the generic arbiter owns cursor tracking, view-axis depth and OrbitControls timing.
|
|
4054
|
+
function navigationPickPoint(clientX, clientY) {
|
|
4055
|
+
if (!controls || !camera || !canvasEl || !raycaster) return null;
|
|
3542
4056
|
camera.updateMatrixWorld(); root.updateMatrixWorld(true);
|
|
3543
4057
|
const rect = canvasEl.getBoundingClientRect(); if (!rect.width || !rect.height) return;
|
|
3544
|
-
const ndc = new THREE.Vector2(((
|
|
4058
|
+
const ndc = new THREE.Vector2(((clientX - rect.left) / rect.width) * 2 - 1, -((clientY - rect.top) / rect.height) * 2 + 1);
|
|
3545
4059
|
raycaster.setFromCamera(ndc, camera);
|
|
3546
4060
|
const hits = raycaster.intersectObjects([...meshById.values()].filter((m) => m.visible), false);
|
|
3547
|
-
|
|
3548
|
-
const fwd = camera.getWorldDirection(new THREE.Vector3());
|
|
3549
|
-
const depth = hits[0].point.clone().sub(camera.position).dot(fwd); // hit distance along the view axis
|
|
3550
|
-
if (depth > 1e-3) controls.target.copy(camera.position).addScaledVector(fwd, depth);
|
|
4061
|
+
return hits[0]?.point?.toArray() ?? null;
|
|
3551
4062
|
}
|
|
3552
4063
|
|
|
3553
4064
|
let rebuildSeq = 0;
|
|
@@ -3561,7 +4072,7 @@ function cancelDirectMemberGestureForRebuild() {
|
|
|
3561
4072
|
if (epMovedLine) epMovedLine.visible = false;
|
|
3562
4073
|
rebuildEndpoints(); // restore the canonical dot immediately; a failed async scene refresh must not strand the drag preview
|
|
3563
4074
|
}
|
|
3564
|
-
async function
|
|
4075
|
+
async function rebuildSteel(fit = false) {
|
|
3565
4076
|
if (!api) return;
|
|
3566
4077
|
cancelDirectMemberGestureForRebuild(); // synchronous: no frozen host snapshot may survive into the awaited replacement scene
|
|
3567
4078
|
invalidatePointEntry('rebuild'); // synchronous, BEFORE the first await — the scene is changing; drop any open typed entry + stale base (never on stale async completion)
|
|
@@ -3596,7 +4107,7 @@ async function rebuild(fit = false) {
|
|
|
3596
4107
|
}
|
|
3597
4108
|
|
|
3598
4109
|
// ---- Persp/Ortho + Solid/Wire/X-ray + group visibility (parity with the AWARE viewer) ----
|
|
3599
|
-
function
|
|
4110
|
+
function setProjectionSteel(mode) {
|
|
3600
4111
|
refMeasureCands = null; // the measure's frustum-filtered snap set is derived from this — see setReferencePlacement
|
|
3601
4112
|
const want = mode === 'ortho' ? orthoCam : perspCam;
|
|
3602
4113
|
if (want === camera) return;
|
|
@@ -3611,7 +4122,7 @@ function setProjection(mode) {
|
|
|
3611
4122
|
controls.update();
|
|
3612
4123
|
}
|
|
3613
4124
|
function projection() { return camera === orthoCam ? 'ortho' : 'persp'; }
|
|
3614
|
-
function
|
|
4125
|
+
function setDisplayModeSteel(m) {
|
|
3615
4126
|
displayMode = m;
|
|
3616
4127
|
// Display modes repaint shared family materials (Realistic in particular replaces their colour).
|
|
3617
4128
|
// Reconcile the live selection first so returning to Solid gives every focused/context mesh its
|
|
@@ -3652,6 +4163,53 @@ function syncShadows(want) {
|
|
|
3652
4163
|
renderer.shadowMap.enabled = want;
|
|
3653
4164
|
for (const m of meshById.values()) if (m.material) m.material.needsUpdate = true;
|
|
3654
4165
|
}
|
|
4166
|
+
function syncMeshShadowBits() {
|
|
4167
|
+
for (const [id, mesh] of meshById) {
|
|
4168
|
+
const excluded = !mesh.visible || !mesh.material || String(id).startsWith('det:')
|
|
4169
|
+
|| (mesh.userData._ghostSource && mesh.material === mesh.userData._ghostMat);
|
|
4170
|
+
mesh.castShadow = modelMeshCastsShadow({
|
|
4171
|
+
shadowsEnabled,
|
|
4172
|
+
opacity: mesh.material?.opacity,
|
|
4173
|
+
excluded,
|
|
4174
|
+
});
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
function applyModelLighting(value = modelLighting) {
|
|
4178
|
+
modelLighting = normalizeModelLighting(value, STEEL_MODEL_LIGHTING_DEFAULTS);
|
|
4179
|
+
const realistic = !!scene?.environment;
|
|
4180
|
+
if (lightAmb) lightAmb.intensity = (realistic ? 0.06 : 0.65) * modelLighting.ambientBrightness;
|
|
4181
|
+
if (lightFill) lightFill.intensity = (realistic ? 0.10 : 0.25) * modelLighting.ambientBrightness;
|
|
4182
|
+
if (lightKey) {
|
|
4183
|
+
lightKey.intensity = modelLighting.sunlight ? (realistic ? 0.40 : 0.85) * modelLighting.sunBrightness : 0;
|
|
4184
|
+
const box = sceneBox && !sceneBox.isEmpty() ? sceneBox : null;
|
|
4185
|
+
const centre = box ? box.getCenter(new THREE.Vector3()) : new THREE.Vector3();
|
|
4186
|
+
const size = box ? box.getSize(new THREE.Vector3()) : new THREE.Vector3(10, 10, 10);
|
|
4187
|
+
const span = Math.max(size.x, size.y, size.z, 10);
|
|
4188
|
+
lightKey.position.copy(centre).addScaledVector(new THREE.Vector3().fromArray(modelSunDirection(modelLighting)), span * 2);
|
|
4189
|
+
lightKey.target.position.copy(centre);
|
|
4190
|
+
if (lightKey.target.parent !== scene) scene.add(lightKey.target);
|
|
4191
|
+
lightKey.target.updateMatrixWorld();
|
|
4192
|
+
if (lightKey.shadow?.camera) {
|
|
4193
|
+
const camera = lightKey.shadow.camera, radius = span * 1.2;
|
|
4194
|
+
camera.left = -radius; camera.right = radius; camera.top = radius; camera.bottom = -radius;
|
|
4195
|
+
camera.near = span * 0.02; camera.far = span * 10; camera.updateProjectionMatrix();
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
syncShadows(modelShadowsEnabled({
|
|
4199
|
+
displayMode,
|
|
4200
|
+
hasEnvironment: !!scene?.environment,
|
|
4201
|
+
sunlight: modelLighting.sunlight,
|
|
4202
|
+
}));
|
|
4203
|
+
return modelLighting;
|
|
4204
|
+
}
|
|
4205
|
+
function setModelLighting(value) {
|
|
4206
|
+
const previousSunlight = modelLighting.sunlight;
|
|
4207
|
+
applyModelLighting(value);
|
|
4208
|
+
// Numeric slider movement updates only the light rig. A sunlight transition also refreshes the
|
|
4209
|
+
// cheap per-mesh shadow bit, without re-running the full material/display pass on every input event.
|
|
4210
|
+
if (previousSunlight !== modelLighting.sunlight) syncMeshShadowBits();
|
|
4211
|
+
return { ...modelLighting };
|
|
4212
|
+
}
|
|
3655
4213
|
function setEnvironment(on) {
|
|
3656
4214
|
if (on && !envRT && !envFailed) {
|
|
3657
4215
|
try {
|
|
@@ -3667,14 +4225,6 @@ function setEnvironment(on) {
|
|
|
3667
4225
|
}
|
|
3668
4226
|
const live = on && !!envRT;
|
|
3669
4227
|
scene.environment = live ? envRT.texture : null;
|
|
3670
|
-
// An environment map IS a light source. The analytic rig above was tuned for a scene with NO
|
|
3671
|
-
// environment, so leaving it at full strength while the env is on lights everything about twice
|
|
3672
|
-
// over — which is why mid-grey paint was clipping to white and concrete looked washed out. The
|
|
3673
|
-
// ambient goes nearly to zero (the env supplies omnidirectional light, and far better, since it
|
|
3674
|
-
// has direction and therefore shows form) and the directionals drop to a shaping role.
|
|
3675
|
-
if (lightAmb) lightAmb.intensity = live ? 0.06 : 0.65;
|
|
3676
|
-
if (lightKey) lightKey.intensity = live ? 0.40 : 0.85;
|
|
3677
|
-
if (lightFill) lightFill.intensity = live ? 0.10 : 0.25;
|
|
3678
4228
|
// Brightness of the reflection is lifted PER MATERIAL via envMapIntensity (see applyDisplayMode),
|
|
3679
4229
|
// not via scene.environmentIntensity: that property only exists in three r163+, and AWARE's viewer
|
|
3680
4230
|
// pins r160, so scene-level lifting could not be ported to the shared read-only viewer.
|
|
@@ -3823,17 +4373,23 @@ function applyGridGhost(pass) {
|
|
|
3823
4373
|
// solid → opaque; wire → EdgesGeometry outline (fill hidden); xray → translucent, no depth write. Applied to
|
|
3824
4374
|
// whatever material each mesh currently carries (shared profile material OR its selection clone).
|
|
3825
4375
|
function applyDisplayMode() {
|
|
4376
|
+
// A scene-wide material pass, so before init() there is nothing to apply it to. It is reachable that
|
|
4377
|
+
// early: the editor restores clip + work-area state on every undo/redo, and setClipState ends in this
|
|
4378
|
+
// pass, so a session that never opened 3D could not undo (#1430). init's first rebuild() runs it.
|
|
4379
|
+
if (!scene) return;
|
|
3826
4380
|
const wire = displayMode === 'wire', live = new Set();
|
|
3827
4381
|
// Gate the PBR pass on the environment being LIVE, not merely on the mode being selected.
|
|
3828
4382
|
// Both realistic modes get the environment and the material table; only `shadowed` also casts.
|
|
3829
4383
|
const realistic = setEnvironment(displayMode === 'realistic' || displayMode === 'shadowed');
|
|
3830
|
-
|
|
4384
|
+
// Apply after the environment and mode are both final. This explicit ownership makes Realistic ↔
|
|
4385
|
+
// Shadowed transitions update shadow state even though both modes keep the same environment alive.
|
|
4386
|
+
applyModelLighting(modelLighting);
|
|
3831
4387
|
for (const [id, mesh] of meshById) {
|
|
3832
4388
|
// Restore only while the mesh still wears OUR faded clone. Selection, hover, or a review update
|
|
3833
4389
|
// may have installed a newer semantic material since the last pass; that newer owner must win.
|
|
3834
4390
|
if (mesh.userData._ghostSource && mesh.material === mesh.userData._ghostMat) mesh.material = mesh.userData._ghostSource;
|
|
3835
4391
|
const mat = mesh.material; if (!mat) continue;
|
|
3836
|
-
if (String(id).startsWith('det:')) { if (mesh.userData._detailOpacity == null) mesh.userData._detailOpacity = mat.opacity == null ? 1 : mat.opacity; mat.opacity = mesh.userData._detailOpacity; mat.transparent = true; mat.depthWrite = false; mat.color.setHex(selIds.has(id) && !ghostUnselectedEnabled ? 0x93c5fd : 0xffffff); mesh.castShadow = false; continue; }
|
|
4392
|
+
if (String(id).startsWith('det:')) { if (mesh.userData._detailOpacity == null) mesh.userData._detailOpacity = mat.opacity == null ? 1 : mat.opacity; mat.opacity = mesh.userData._detailOpacity; mat.transparent = true; mat.depthWrite = false; mat.color.setHex(selIds.has(id) && !ghostUnselectedEnabled ? 0x93c5fd : (hoverGlowIds.includes(id) ? HOVER_EMISSIVE : 0xffffff)); mesh.castShadow = false; continue; }
|
|
3837
4393
|
live.add(id);
|
|
3838
4394
|
// Reset the surface on EVERY pass so a mode switch is symmetric — leaving Realistic must restore
|
|
3839
4395
|
// the flat shading exactly, not strand the last family's metalness on a shared material.
|
|
@@ -3867,10 +4423,6 @@ function applyDisplayMode() {
|
|
|
3867
4423
|
mat.wireframe = false; mat.opacity = op; mat.transparent = op < 1; mat.depthWrite = op >= 1;
|
|
3868
4424
|
}
|
|
3869
4425
|
}
|
|
3870
|
-
// Decided HERE rather than at build time: it depends on the opacity this pass just set, and
|
|
3871
|
-
// three's shadow depth material has no notion of ordinary transparency, so a translucent element
|
|
3872
|
-
// would otherwise cast as solidly as steel.
|
|
3873
|
-
mesh.castShadow = shadowsEnabled && mat.opacity >= 0.95;
|
|
3874
4426
|
mat.needsUpdate = true;
|
|
3875
4427
|
}
|
|
3876
4428
|
const ghost = ghostPassState(wire);
|
|
@@ -3879,8 +4431,10 @@ function applyDisplayMode() {
|
|
|
3879
4431
|
if (String(id).startsWith('det:')) { mesh.material.opacity = Math.min(mesh.userData._detailOpacity == null ? 1 : mesh.userData._detailOpacity, ghost.opacity); mesh.material.depthWrite = false; }
|
|
3880
4432
|
else if (wire) { const ls = wireEdges.get(id); if (ls) ls.material = wireEdgeMatFor(wireEdgeColorOf(id, mesh), ghost.opacity); }
|
|
3881
4433
|
else { const source = mesh.material; mesh.material = ghostMaterial(mesh, source, Math.min(source.opacity == null ? 1 : source.opacity, ghost.opacity)); }
|
|
3882
|
-
mesh.castShadow = false;
|
|
3883
4434
|
}
|
|
4435
|
+
// Decided after mode and Ghost materials are final. Three's shadow depth material has no notion of
|
|
4436
|
+
// ordinary transparency, so translucent or contextual geometry must never cast as solid steel.
|
|
4437
|
+
syncMeshShadowBits();
|
|
3884
4438
|
applyGridGhost(ghost);
|
|
3885
4439
|
syncClipMirror(); // shadows just turned on or off — the mirror follows
|
|
3886
4440
|
for (const [id, ls] of wireEdges) if (!live.has(id) || ls.parent !== meshById.get(id)) { if (ls.parent) ls.parent.remove(ls); if (ls.geometry) ls.geometry.dispose(); wireEdges.delete(id); } // prune outlines whose mesh is gone OR was rebuilt under the same id (wireEdgesFor rebuilds on next Wire entry)
|
|
@@ -3916,7 +4470,7 @@ function visibleObjectIds() {
|
|
|
3916
4470
|
return out;
|
|
3917
4471
|
}
|
|
3918
4472
|
function visibleGridIds() { return [...structGridLines].filter(([, line]) => line.visible).map(([id]) => id); }
|
|
3919
|
-
function notifyVisibilityChange() { if (api && api.onIsolateChange) api.onIsolateChange(isolatedIds !== null || isolatedGridIds !== null); }
|
|
4473
|
+
function notifyVisibilityChange() { syncSpatialVisibility(); viewportReports?.reportVisibility(); if (api && api.onIsolateChange) api.onIsolateChange(isolatedIds !== null || isolatedGridIds !== null); }
|
|
3920
4474
|
function toggleGroup(k) { if (groupHidden.has(k)) groupHidden.delete(k); else groupHidden.add(k); soloGroups.clear(); applyGroupVisibility(); applyDisplayMode(); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); notifyVisibilityChange(); }
|
|
3921
4475
|
// Hide/show a SET of groups in one pass (a legend type-category master toggle) — deterministic (not a flip),
|
|
3922
4476
|
// so "hide all" / "show all" for the category is exact. Clears solo, like toggleGroup.
|
|
@@ -3927,7 +4481,7 @@ function setIdsHidden(ids, hidden) { for (const id of (ids || [])) { if (hidden)
|
|
|
3927
4481
|
// Isolate an explicit SET of profile groups (the editor's legend builds it from Ctrl/Shift dbl-clicks, Explorer-style).
|
|
3928
4482
|
function setSoloGroups(keys) { soloGroups = new Set((keys || []).filter((k) => k != null)); if (soloGroups.size) groupHidden.clear(); applyGroupVisibility(); applyDisplayMode(); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); notifyVisibilityChange(); }
|
|
3929
4483
|
function soloToggle(k) { setSoloGroups(soloGroups.size === 1 && soloGroups.has(k) ? [] : [k]); } // plain dbl-click: isolate just this group (or clear if it's already the only one)
|
|
3930
|
-
function
|
|
4484
|
+
function showAllGroupsSteel() { groupHidden.clear(); soloGroups.clear(); isolatedIds = null; isolatedGridIds = null; connHidden.clear(); selectionHidden.clear(); gridSelectionHidden.clear(); ghostUnselectedEnabled = false; applyGroupVisibility(); applyGridVisibility(); setSelection(selIds); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); updateStatusChip(); notifyVisibilityChange(); }
|
|
3931
4485
|
function groupState() { return { hidden: [...groupHidden], solo: [...soloGroups] }; }
|
|
3932
4486
|
// One serialisable snapshot of the objects-list pane's PERSISTENT visibility state — group hide/solo +
|
|
3933
4487
|
// isolate-selected + per-part legend hides. This is what a saved view (Views Organizer) captures; it
|
|
@@ -3951,10 +4505,10 @@ function applyObjectsPaneState(s) {
|
|
|
3951
4505
|
}
|
|
3952
4506
|
// Tekla "isolate selected": show ONLY the currently-selected parts (a snapshot taken now — distinct from
|
|
3953
4507
|
// soloToggle, which isolates a whole PROFILE group from the legend). clearIsolation / showAllGroups restore all.
|
|
3954
|
-
function
|
|
4508
|
+
function isolateSelectedSteel() { if (!selIds.size && !selectedGridIds.size) return false; isolatedIds = new Set(selIds); isolatedGridIds = new Set(selectedGridIds); applyGroupVisibility(); applyGridVisibility(); applyDisplayMode(); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); updateStatusChip(); notifyVisibilityChange(); return true; }
|
|
3955
4509
|
// Hide the current selection by explicit mesh id. This remains session-only because saved views require tagged
|
|
3956
4510
|
// SceneRefs while the renderer owns raw ids; broadening that contract is separate from toolbar state.
|
|
3957
|
-
function
|
|
4511
|
+
function hideSelectedSteel() { const ids = [...selIds].filter((id) => meshById.has(id)), gridIds = [...selectedGridIds].filter((id) => structGridLines.has(id)); if (!ids.length && !gridIds.length) return 0; for (const id of ids) selectionHidden.add(id); for (const id of gridIds) gridSelectionHidden.add(id); applyGroupVisibility(); applyGridVisibility(); applyDisplayMode(); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); updateStatusChip(); notifyVisibilityChange(); return ids.length + gridIds.length; }
|
|
3958
4512
|
function clearIsolation() { if (isolatedIds === null && isolatedGridIds === null) return; isolatedIds = null; isolatedGridIds = null; applyGroupVisibility(); applyGridVisibility(); applyDisplayMode(); rebuildEndpoints(); refreshOverlayDims(); refreshDims(); updateStatusChip(); notifyVisibilityChange(); }
|
|
3959
4513
|
function isIsolated() { return isolatedIds !== null || isolatedGridIds !== null; }
|
|
3960
4514
|
function hasVisibilityFilter() { return isolatedIds !== null || isolatedGridIds !== null || groupHidden.size > 0 || soloGroups.size > 0 || connHidden.size > 0 || selectionHidden.size > 0 || gridSelectionHidden.size > 0; }
|
|
@@ -3972,20 +4526,60 @@ let overlayScene = null; // clip/work-area gizmos live here, render
|
|
|
3972
4526
|
let clips = []; // each clip stores its SOURCE geom (plane: n+point; box: Box3) + derived .planes
|
|
3973
4527
|
let workArea = null; // the single work area (a clip box with a visible boundary) — set by the work-area controls
|
|
3974
4528
|
let clipSeq = 0, clipMode = null; // clipMode: 'plane' (click a face) | 'box' (2-corner draw) | null
|
|
4529
|
+
let clipGesture = null; // shared plane + corner/corner/height lifecycle; renderer callbacks stay here
|
|
3975
4530
|
let selectedClipIds = new Set(); // the clips whose outline + drag handles show in 3D (multi-select like parts/dims)
|
|
3976
4531
|
let clipBoxDraft = null; // { a:[x,y] } during a 2-point clip-box draw
|
|
3977
|
-
let clipGizmo = null; // THREE.Group: the selected clip's outline + drag handles
|
|
3978
|
-
let clipPreview = null; // THREE.Box3Helper while drawing a clip box
|
|
3979
4532
|
const EMPTY_CLIPS = Object.freeze([]);
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4533
|
+
function initSharedClipLayer() {
|
|
4534
|
+
releaseClipSpatial?.(); releaseClipSession?.(); clipSession?.dispose(); clipOverlay?.dispose(); clipCreationPreview?.dispose();
|
|
4535
|
+
adoptSharedClips.signature = '';
|
|
4536
|
+
clipSession = createModelClipSession({
|
|
4537
|
+
tools: spatialTools,
|
|
4538
|
+
onBeginEdit: () => api?.beginClipEdit?.(),
|
|
4539
|
+
placementOwnsKeyboard: () => !!clipMode,
|
|
4540
|
+
dragOwnsKeyboard: () => sharedClipEdit !== null,
|
|
4541
|
+
anotherCommandOwnsKeyboard: () => api?.anotherCommandOwnsKeyboard?.() === true,
|
|
4542
|
+
onArmPlane: () => { setClipMode('plane'); },
|
|
4543
|
+
onArmBox: () => { setClipMode('box'); },
|
|
4544
|
+
});
|
|
4545
|
+
releaseClipSpatial = spatialTools.subscribe(adoptSharedClips);
|
|
4546
|
+
clipOverlay = createModelClipThreeOverlay({
|
|
4547
|
+
THREE, overlayScene, canvas: canvasEl, getCamera: () => camera,
|
|
4548
|
+
rayAt: (clientX, clientY) => { const value = rayAt(clientX, clientY); return { origin: value.origin, direction: value.direction }; },
|
|
4549
|
+
getClips: () => clipSession.clips(), getSelectedClipIds: () => clipSession.selected(),
|
|
4550
|
+
isPlacementArmed: () => !!clipMode,
|
|
4551
|
+
formatDistance: (valueMm) => api?.fmtLen ? api.fmtLen(valueMm) : `${(valueMm / FT_MM).toFixed(2)} ft`,
|
|
4552
|
+
update({ clipId, clip }) {
|
|
4553
|
+
sharedClipEdit ||= clipSession.beginLogicalEdit('clip-handle-drag');
|
|
4554
|
+
const patch = clip.kind === 'plane'
|
|
4555
|
+
? { origin: [...(clip.origin ?? clip.point)], normal: [...(clip.normal ?? clip.n)] }
|
|
4556
|
+
: { min: [...(clip.box?.min ?? clip.min)], max: [...(clip.box?.max ?? clip.max)] };
|
|
4557
|
+
sharedClipEdit.update(clipId, patch);
|
|
4558
|
+
},
|
|
4559
|
+
commit() { sharedClipEdit?.finish(); sharedClipEdit = null; if (readout) readout.style.display = 'none'; },
|
|
4560
|
+
cancel() { sharedClipEdit?.finish(); sharedClipEdit = null; if (readout) readout.style.display = 'none'; },
|
|
4561
|
+
readout(value) {
|
|
4562
|
+
if (!readout || value?.hidden || !value?.readout?.text) { if (readout) readout.style.display = 'none'; return; }
|
|
4563
|
+
readout._dist.textContent = value.readout.text; readout._type.textContent = value.readout.type ? ` · ${value.readout.type}` : '';
|
|
4564
|
+
readout.style.left = `${value.event.clientX + 14}px`; readout.style.top = `${value.event.clientY + 14}px`; readout.style.display = 'block';
|
|
4565
|
+
},
|
|
4566
|
+
});
|
|
4567
|
+
clipCreationPreview = createModelClipThreePreview({ THREE, overlayScene, canvas: canvasEl, getCamera: () => camera });
|
|
4568
|
+
releaseClipSession = clipSession.subscribe((state) => {
|
|
4569
|
+
selectedClipIds = new Set(state.selectedIds); clipOverlay.render(); api?.onClipsChange?.();
|
|
4570
|
+
});
|
|
4571
|
+
}
|
|
4572
|
+
function publishClipState() { syncSpatialSections(); if (api?.onClipsChange) api.onClipsChange(); }
|
|
4573
|
+
function publishWorkAreaState() { syncSpatialSections(); if (api?.onWorkAreaChange) api.onWorkAreaChange(workAreaState()); }
|
|
4574
|
+
const CLIP_BOX_COLOR = 0x93c5fd; // lighter blue — the plane hover marker that Clip and Detail SHARE (setPlaneHoverPreview), its only use here; committed CLIP planes and boxes take their colours from model-clip-three-overlay.js, and the work-area box is coloured inline below
|
|
4575
|
+
const CLIP_PLANE_PREVIEW_R = FT_MM * 0.75; // 18″×18″ hover marker: smaller than the committed outline so the exact picked face stays dominant
|
|
3983
4576
|
function applyClips() {
|
|
3984
4577
|
if (!renderer) return;
|
|
3985
4578
|
const active = clips.filter((c) => c.enabled).flatMap((c) => c.planes);
|
|
3986
4579
|
if (workArea && workArea.enabled && !workArea.whole) active.push(...workArea.planes); // the work area sections the view too — unless it's in "show whole parts" mode (parts are hidden/shown whole via applyGroupVisibility, never sliced)
|
|
3987
4580
|
renderer.clippingPlanes = active.length ? active : EMPTY_CLIPS;
|
|
3988
4581
|
syncClipMirror(); // materials hold their own reference for the shadow pass — re-point it
|
|
4582
|
+
viewportReports?.reportSectionState();
|
|
3989
4583
|
if (ghostUnselectedEnabled) applyDisplayMode(); // clipping can remove the last focused rendered fragment
|
|
3990
4584
|
}
|
|
3991
4585
|
// 6 inward planes (keep INSIDE) for an axis-aligned Box3 → a section/clip box.
|
|
@@ -4002,13 +4596,13 @@ function rebuildClipPlanes(c) { // recompute a clip's .planes from its ed
|
|
|
4002
4596
|
function setClipMode(m) { // arm/disarm a clip pick: 'plane' (click a face) | 'box' (draw 2 corners) | null
|
|
4003
4597
|
abandonConnPick('other-tool'); // every other mode disarms its rivals; without this the pick keeps swallowing clicks while another tool reports armed
|
|
4004
4598
|
if (m) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
4005
|
-
if (m && dimMode3d)
|
|
4599
|
+
if (m && dimMode3d) disarmMeasureTool();
|
|
4006
4600
|
if (m) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } // clip shares the left-click — disarm Move/Copy + Add + the local frame so their picks don't steal it (onDown routes them first)
|
|
4007
|
-
|
|
4008
|
-
clipBoxDraft = null; clipCandidates = null; clipLevels = null; invalidateClipFloor();
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
if (
|
|
4601
|
+
const nextMode = (m === 'plane' || m === 'box') ? m : null;
|
|
4602
|
+
clipBoxDraft = null; clipCandidates = null; clipLevels = null; invalidateClipFloor(); clipCreationPreview?.show({ kind: 'clear' }); setFacePickPreview(null); setPlaneHoverPreview(null); if (marker) marker.visible = false; // drop the per-draw snap cache + measured floor + any live snap marker when arming/disarming
|
|
4603
|
+
const gesture = ensureClipGesture();
|
|
4604
|
+
if (nextMode) { releaseClipGestureInput?.activate?.(); gesture.arm(nextMode); }
|
|
4605
|
+
else if (!gesture.cancel('command')) { clipMode = null; if (canvasEl) canvasEl.style.cursor = 'default'; updateStatusChip(); if (api?.onClipModeChange) api.onClipModeChange(null); viewportReports?.reportSectionState(); }
|
|
4012
4606
|
return clipMode;
|
|
4013
4607
|
}
|
|
4014
4608
|
function clipModeOn() { return clipMode; }
|
|
@@ -4024,15 +4618,10 @@ function clipModeOn() { return clipMode; }
|
|
|
4024
4618
|
* for. What is left to each caller is the resulting normal: away from the camera for a clip (keep the
|
|
4025
4619
|
* far side, reveal the section), toward it for a working plane (you are about to draw on it).
|
|
4026
4620
|
*
|
|
4027
|
-
*
|
|
4028
|
-
*
|
|
4029
|
-
*
|
|
4030
|
-
*
|
|
4031
|
-
* direction you are looking from, so the clip tool can keep the wrong side of a face out at the edge of
|
|
4032
|
-
* a wide model. That is a pre-existing bug on the clip side, left alone here because this branch is not
|
|
4033
|
-
* where it should be fixed — but it is written down rather than smoothed over, because an earlier
|
|
4034
|
-
* version of this paragraph claimed the two callers differ in "exactly one thing" and that sentence is
|
|
4035
|
-
* an invitation to unify them on the wrong one. (Raised by Codex review of the merge.)
|
|
4621
|
+
* BOTH CALLERS USE THE RAY THAT ACTUALLY STRUCK THE FACE. That matters in orthographic views, where
|
|
4622
|
+
* `camera.position - hit.point` is not the viewing direction for an off-centre hit and can keep the
|
|
4623
|
+
* wrong side of a wide model. Clip orientation is resolved by the shared model clipping helper; the
|
|
4624
|
+
* working-plane caller uses the same hit ray with the opposite facing convention.
|
|
4036
4625
|
*
|
|
4037
4626
|
* REFERENCE GEOMETRY IS PICKABLE HERE AT ALL, and it was not before. This raycast saw `meshById` alone,
|
|
4038
4627
|
* so arming Clip plane and clicking an IFC wall produced no hover ghost and placed no plane — the tool
|
|
@@ -4073,7 +4662,7 @@ function faceHitAt(cx, cy) {
|
|
|
4073
4662
|
// BEFORE `meshHitsAt`, which has no such guard: a zero-sized canvas divides through to NaN, and a
|
|
4074
4663
|
// raycast down a NaN ray answers nothing while looking like an ordinary miss.
|
|
4075
4664
|
const rect = canvasEl.getBoundingClientRect(); if (!rect.width || !rect.height) return null;
|
|
4076
|
-
const own = meshHitsAt(cx, cy).find((h) => !!h.face);
|
|
4665
|
+
const own = meshHitsAt(cx, cy, false, true).find((h) => !!h.face);
|
|
4077
4666
|
if (own) return own;
|
|
4078
4667
|
if (!xrefGroup || !xrefGroup.children.length) return null;
|
|
4079
4668
|
// RE-AIMED RATHER THAN INHERITED. `meshHitsAt` has just pointed the shared `raycaster` at this very
|
|
@@ -4090,67 +4679,148 @@ function clipPlaneAtScreen(cx, cy) {
|
|
|
4090
4679
|
const hit = faceHitAt(cx, cy);
|
|
4091
4680
|
if (!hit) return null; // missed a face → no plane
|
|
4092
4681
|
const n = hit.face.normal.clone().transformDirection(hit.object.matrixWorld).normalize(); // face normal → world
|
|
4093
|
-
|
|
4682
|
+
n.fromArray(orientClipNormalAwayFromCamera(n.toArray(), rayAt(cx, cy).direction.toArray())); // actual camera ray works for perspective AND orthographic views
|
|
4094
4683
|
return { n, point: hit.point.clone() };
|
|
4095
4684
|
}
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
const c = { id, kind: 'plane', enabled: true, n: pp.n.clone(), point: pp.point.clone(), planes: [], label: 'Plane ' + clipSeq };
|
|
4103
|
-
rebuildClipPlanes(c); clips.push(c);
|
|
4104
|
-
applyClips(); selectClip(id); if (api && api.onClipsChange) api.onClipsChange();
|
|
4105
|
-
return id;
|
|
4106
|
-
}
|
|
4107
|
-
// The in-plane square (4 corners) for a plane patch of half-size r around hp — shared by the gizmo outline + the
|
|
4108
|
-
// hover preview so both read as the same 2'×2' marker.
|
|
4685
|
+
function addClipPlaneResolved(pp) {
|
|
4686
|
+
if (!pp) return null;
|
|
4687
|
+
return clipSession?.addPlane({ origin: pp.point.toArray(), normal: pp.n.toArray() }) ?? null;
|
|
4688
|
+
}
|
|
4689
|
+
// The in-plane square (4 corners) for a plane patch of half-size r around hp — used by the committed
|
|
4690
|
+
// clip-plane gizmo. The pre-click hover uses the exact picked face below instead.
|
|
4109
4691
|
function planePatchCorners(hp, n, r) {
|
|
4110
4692
|
const u = (Math.abs(n.z) < 0.9 ? new THREE.Vector3(0, 0, 1) : new THREE.Vector3(1, 0, 0)).cross(n).normalize(), v = n.clone().cross(u).normalize();
|
|
4111
4693
|
return [hp.clone().addScaledVector(u, r).addScaledVector(v, r), hp.clone().addScaledVector(u, -r).addScaledVector(v, r), hp.clone().addScaledVector(u, -r).addScaledVector(v, -r), hp.clone().addScaledVector(u, r).addScaledVector(v, -r)];
|
|
4112
4694
|
}
|
|
4113
|
-
let
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4695
|
+
let facePickPreview = null, facePickPreviewKey = '', planeHoverPreview = null;
|
|
4696
|
+
const coplanarFaceRegions = new WeakMap();
|
|
4697
|
+
/*
|
|
4698
|
+
* Return the edge-connected, coplanar triangle region containing `startFace`. Welding by POSITION rather
|
|
4699
|
+
* than by vertex index is load-bearing: ExtrudeGeometry and CSG commonly duplicate the two vertices on a
|
|
4700
|
+
* shared edge. Connectivity keeps the opposite flange out; the plane check keeps the web separate.
|
|
4701
|
+
*/
|
|
4702
|
+
function coplanarFaceRegion(geometry, startFace) {
|
|
4703
|
+
const pos = geometry && geometry.attributes && geometry.attributes.position, idx = geometry && geometry.index;
|
|
4704
|
+
if (!pos || !Number.isInteger(startFace) || startFace < 0) return null;
|
|
4705
|
+
const count = idx ? idx.count : pos.count, faceCount = Math.floor(count / 3);
|
|
4706
|
+
if (startFace >= faceCount) return null;
|
|
4707
|
+
let cached = coplanarFaceRegions.get(geometry);
|
|
4708
|
+
if (cached && cached.has(startFace)) return cached.get(startFace);
|
|
4709
|
+
if (!cached) { cached = new Map(); coplanarFaceRegions.set(geometry, cached); }
|
|
4710
|
+
const coord = (i) => pos.getX ? [pos.getX(i), pos.getY(i), pos.getZ(i)] : [pos.array[i * 3], pos.array[i * 3 + 1], pos.array[i * 3 + 2]];
|
|
4711
|
+
const vertex = (face, corner) => coord(idx ? idx.getX(face * 3 + corner) : face * 3 + corner);
|
|
4712
|
+
let lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity];
|
|
4713
|
+
for (let i = 0; i < pos.count; i++) { const p = coord(i); for (let j = 0; j < 3; j++) { lo[j] = Math.min(lo[j], p[j]); hi[j] = Math.max(hi[j], p[j]); } }
|
|
4714
|
+
const span = Math.max(hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2], 1), weld = Math.max(span * 1e-6, 1e-4), planeTol = weld * 2;
|
|
4715
|
+
const keyOf = (p) => p.map((v) => Math.round(v / weld)).join(',');
|
|
4716
|
+
const edgeOf = (a, b) => { const ka = keyOf(a), kb = keyOf(b); return ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`; };
|
|
4717
|
+
const triangles = [], byEdge = new Map();
|
|
4718
|
+
for (let face = 0; face < faceCount; face++) {
|
|
4719
|
+
const points = [vertex(face, 0), vertex(face, 1), vertex(face, 2)], a = points[0], b = points[1], c = points[2];
|
|
4720
|
+
const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]], ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
4721
|
+
const raw = [ab[1] * ac[2] - ab[2] * ac[1], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[0]], len = Math.hypot(raw[0], raw[1], raw[2]);
|
|
4722
|
+
const normal = len > 1e-12 ? raw.map((v) => v / len) : [0, 0, 0], edges = [edgeOf(a, b), edgeOf(b, c), edgeOf(c, a)];
|
|
4723
|
+
triangles.push({ face, points, normal, edges });
|
|
4724
|
+
for (const edge of edges) { if (!byEdge.has(edge)) byEdge.set(edge, []); byEdge.get(edge).push(face); }
|
|
4725
|
+
}
|
|
4726
|
+
const seed = triangles[startFace]; if (!seed || !seed.normal.some(Boolean)) return null;
|
|
4727
|
+
const planeD = seed.normal[0] * seed.points[0][0] + seed.normal[1] * seed.points[0][1] + seed.normal[2] * seed.points[0][2];
|
|
4728
|
+
const eligible = (tri) => {
|
|
4729
|
+
const dot = tri.normal[0] * seed.normal[0] + tri.normal[1] * seed.normal[1] + tri.normal[2] * seed.normal[2];
|
|
4730
|
+
return dot > 0.9998 && tri.points.every((p) => Math.abs(seed.normal[0] * p[0] + seed.normal[1] * p[1] + seed.normal[2] * p[2] - planeD) <= planeTol);
|
|
4731
|
+
};
|
|
4732
|
+
const chosen = new Set([startFace]), queue = [startFace];
|
|
4733
|
+
while (queue.length) {
|
|
4734
|
+
const face = queue.shift();
|
|
4735
|
+
for (const edge of triangles[face].edges) for (const next of (byEdge.get(edge) || [])) {
|
|
4736
|
+
if (!chosen.has(next) && eligible(triangles[next])) { chosen.add(next); queue.push(next); }
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
const faces = [...chosen].sort((a, b) => a - b);
|
|
4740
|
+
const region = { triangles: faces.map((face) => triangles[face]), normal: seed.normal, key: faces.join(',') };
|
|
4741
|
+
for (const face of faces) cached.set(face, region);
|
|
4742
|
+
return region;
|
|
4743
|
+
}
|
|
4744
|
+
function setFacePickPreview(hit) {
|
|
4745
|
+
if (!hit) {
|
|
4746
|
+
if (facePickPreview) { scene.remove(facePickPreview); facePickPreview.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); }
|
|
4747
|
+
facePickPreview = null; facePickPreviewKey = ''; setPlaneHoverPreview(null); return;
|
|
4748
|
+
}
|
|
4749
|
+
const region = coplanarFaceRegion(hit.object.geometry, hit.faceIndex);
|
|
4750
|
+
if (!region) { setFacePickPreview(null); return; }
|
|
4751
|
+
const key = `${hit.object.uuid}:${region.key}`; if (key === facePickPreviewKey) return;
|
|
4752
|
+
setFacePickPreview(null); hit.object.updateMatrixWorld(true);
|
|
4753
|
+
const worldNormal = new THREE.Vector3(...region.normal).transformDirection(hit.object.matrixWorld).normalize();
|
|
4754
|
+
const towardCamera = camera.position.clone().sub(hit.point); if (worldNormal.dot(towardCamera) < 0) worldNormal.negate();
|
|
4755
|
+
const offset = Math.max((sceneBox && !sceneBox.isEmpty() ? sceneBox.getSize(new THREE.Vector3()).length() : 1000) * 1e-5, 0.25);
|
|
4756
|
+
const toWorld = (p) => new THREE.Vector3(...p).applyMatrix4(hit.object.matrixWorld).addScaledVector(worldNormal, offset);
|
|
4757
|
+
const fillPoints = [], edgeCounts = new Map(), edgePoints = new Map();
|
|
4758
|
+
for (const tri of region.triangles) {
|
|
4759
|
+
const wp = tri.points.map(toWorld); fillPoints.push(...wp);
|
|
4760
|
+
for (let i = 0; i < 3; i++) { const edge = tri.edges[i]; edgeCounts.set(edge, (edgeCounts.get(edge) || 0) + 1); edgePoints.set(edge, [wp[i], wp[(i + 1) % 3]]); }
|
|
4761
|
+
}
|
|
4762
|
+
facePickPreview = new THREE.Group();
|
|
4763
|
+
const fillGeometry = new THREE.BufferGeometry().setFromPoints(fillPoints);
|
|
4764
|
+
const fill = new THREE.Mesh(fillGeometry, new THREE.MeshBasicMaterial({ color: HOVER_EMISSIVE, transparent: true, opacity: 0.28, side: THREE.DoubleSide, depthTest: true, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2 }));
|
|
4765
|
+
fill.renderOrder = 995; facePickPreview.add(fill);
|
|
4766
|
+
const boundary = []; for (const [edge, uses] of edgeCounts) if (uses === 1) boundary.push(...edgePoints.get(edge));
|
|
4767
|
+
const outline = new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(boundary), new THREE.LineBasicMaterial({ color: HOVER_EMISSIVE, transparent: true, opacity: 0.95, depthTest: true }));
|
|
4768
|
+
outline.renderOrder = 996; facePickPreview.add(outline);
|
|
4769
|
+
scene.add(facePickPreview); facePickPreviewKey = key;
|
|
4770
|
+
}
|
|
4771
|
+
// Detail and Clip share this world-space plane marker. Its centre dot is the exact projected/snapped point;
|
|
4772
|
+
// the normal crosshair remains visible so the user can see both their pointer and the constrained result.
|
|
4773
|
+
function setPlaneHoverPreview(hit) {
|
|
4774
|
+
if (planeHoverPreview) { if (overlayScene) overlayScene.remove(planeHoverPreview); planeHoverPreview.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); planeHoverPreview = null; }
|
|
4775
|
+
if (!hit || !overlayScene) return;
|
|
4776
|
+
const n = hit.normal
|
|
4777
|
+
? hit.normal.clone().normalize()
|
|
4778
|
+
: hit.face.normal.clone().transformDirection(hit.object.matrixWorld).normalize();
|
|
4779
|
+
planeHoverPreview = new THREE.Group();
|
|
4780
|
+
const fill = new THREE.Mesh(
|
|
4781
|
+
new THREE.PlaneGeometry(CLIP_PLANE_PREVIEW_R * 2, CLIP_PLANE_PREVIEW_R * 2),
|
|
4782
|
+
new THREE.MeshBasicMaterial({ color: CLIP_BOX_COLOR, transparent: true, opacity: 0.16, side: THREE.DoubleSide, depthTest: false, depthWrite: false })
|
|
4783
|
+
);
|
|
4784
|
+
fill.position.copy(hit.point); fill.quaternion.setFromUnitVectors(_ZA, n); fill.renderOrder = 997; planeHoverPreview.add(fill);
|
|
4785
|
+
const outline = new THREE.LineLoop(
|
|
4786
|
+
new THREE.BufferGeometry().setFromPoints(planePatchCorners(hit.point, n, CLIP_PLANE_PREVIEW_R)),
|
|
4787
|
+
new THREE.LineBasicMaterial({ color: CLIP_BOX_COLOR, transparent: true, opacity: 0.95, depthTest: false, depthWrite: false })
|
|
4788
|
+
);
|
|
4789
|
+
outline.renderOrder = 998; planeHoverPreview.add(outline);
|
|
4790
|
+
const centre = new THREE.Mesh(
|
|
4791
|
+
new THREE.CircleGeometry(CLIP_PLANE_PREVIEW_R * 0.035, 20),
|
|
4792
|
+
new THREE.MeshBasicMaterial({ color: CLIP_BOX_COLOR, transparent: true, opacity: 1, side: THREE.DoubleSide, depthTest: false, depthWrite: false })
|
|
4793
|
+
);
|
|
4794
|
+
centre.position.copy(hit.point); centre.quaternion.setFromUnitVectors(_ZA, n); centre.renderOrder = 999; planeHoverPreview.add(centre);
|
|
4795
|
+
overlayScene.add(planeHoverPreview);
|
|
4796
|
+
}
|
|
4797
|
+
// Clip and Detail share the exact face highlight and the smaller plane cursor.
|
|
4798
|
+
function clipPlanePreviewAt(cx, cy) { const hit = faceHitAt(cx, cy); setFacePickPreview(hit); setPlaneHoverPreview(hit); return hit; }
|
|
4127
4799
|
function addClipBoxFromBox(box) { // commit a clip box from an explicit Box3 (the 2-corner draw) — selects it
|
|
4128
4800
|
if (!box || box.isEmpty()) return null;
|
|
4129
|
-
|
|
4130
|
-
const id = 'clip' + (++clipSeq);
|
|
4131
|
-
const c = { id, kind: 'box', enabled: true, box: box.clone(), planes: [], label: 'Box ' + clipSeq };
|
|
4132
|
-
rebuildClipPlanes(c); clips.push(c);
|
|
4133
|
-
applyClips(); selectClip(id); if (api && api.onClipsChange) api.onClipsChange();
|
|
4134
|
-
return id;
|
|
4801
|
+
return clipSession?.addBox({ min: box.min.toArray(), max: box.max.toArray() }) ?? null;
|
|
4135
4802
|
}
|
|
4136
|
-
function toggleClip(id, on) {
|
|
4803
|
+
function toggleClip(id, on) { return clipSession ? (on === undefined ? clipSession.toggle(id) : clipSession.setEnabled(id, !!on)) : false; }
|
|
4137
4804
|
// Rename a clip. Returns false if the name is empty or already used by ANOTHER clip (case-insensitive) — the
|
|
4138
4805
|
// caller (legend inline edit) keeps the old name + warns. Undoable.
|
|
4139
4806
|
function renameClip(id, name) {
|
|
4140
|
-
|
|
4141
|
-
const nm = String(name || '').trim(); if (!nm) return false;
|
|
4142
|
-
if (clips.some((x) => x.id !== id && x.label.toLowerCase() === nm.toLowerCase())) return false; // name taken
|
|
4143
|
-
if (api && api.beginClipEdit) api.beginClipEdit();
|
|
4144
|
-
c.label = nm; if (api && api.onClipsChange) api.onClipsChange();
|
|
4145
|
-
return true;
|
|
4807
|
+
return clipSession?.rename(id, name) ?? false;
|
|
4146
4808
|
}
|
|
4147
|
-
function removeClip(id) {
|
|
4148
|
-
function clearClips() {
|
|
4809
|
+
function removeClip(id) { return clipSession?.remove(id) ?? false; }
|
|
4810
|
+
function clearClips() { return clipSession?.clear() ?? false; }
|
|
4149
4811
|
function getClips() { return clips.map((c) => ({ id: c.id, kind: c.kind, enabled: c.enabled, label: c.label, selected: selectedClipIds.has(c.id), size: c.box ? [c.box.max.x - c.box.min.x, c.box.max.y - c.box.min.y, c.box.max.z - c.box.min.z].map((v) => Math.round(v)) : null, planeConst: c.kind === 'plane' && c.planes[0] ? Math.round(c.planes[0].constant) : null })); }
|
|
4150
|
-
function setSelectedClips(ids) {
|
|
4151
|
-
function selectClip(id
|
|
4152
|
-
|
|
4153
|
-
|
|
4812
|
+
function setSelectedClips(ids) { return clipSession?.setSelected(ids) ?? null; }
|
|
4813
|
+
function selectClip(id, event = {}) {
|
|
4814
|
+
return clipSession ? (id ? clipSession.select(id, event) : clipSession.clearSelection()) : null;
|
|
4815
|
+
}
|
|
4816
|
+
function selectedClips() { return clipSession?.selected?.() ?? [...selectedClipIds]; }
|
|
4817
|
+
function deleteSelectedClips() { return clipSession?.deleteSelected() ?? 0; }
|
|
4818
|
+
function mountClipList(host) {
|
|
4819
|
+
sharedClipList?.destroy?.(); sharedClipList = null;
|
|
4820
|
+
if (!clipSession || !host) return null;
|
|
4821
|
+
sharedClipList = mountModelClipList({ session: clipSession, host, onError: (message) => api?.toast?.(message) });
|
|
4822
|
+
return sharedClipList;
|
|
4823
|
+
}
|
|
4154
4824
|
// ---- undo/redo: clips + work area are view-state (not in the contract), so the editor's snapshot grabs this
|
|
4155
4825
|
// serialized form and restores it via setClipState. Each manipulation calls api.beginClipEdit() FIRST (pushes a
|
|
4156
4826
|
// pre-edit snapshot); the editor's Ctrl+Z/Y then restores clips alongside the contract.
|
|
@@ -4163,12 +4833,13 @@ function clipState() {
|
|
|
4163
4833
|
selected: [...selectedClipIds], seq: clipSeq,
|
|
4164
4834
|
};
|
|
4165
4835
|
}
|
|
4166
|
-
function
|
|
4836
|
+
function setClipStateSteel(s) {
|
|
4167
4837
|
s = s || { clips: [], workArea: null, selected: [], seq: clipSeq };
|
|
4168
4838
|
clips = (s.clips || []).map((d) => {
|
|
4839
|
+
const box = d.box || d; const point = d.point || d.origin; const normal = d.n || d.normal;
|
|
4169
4840
|
const c = d.kind === 'box'
|
|
4170
|
-
? { id: d.id, kind: 'box', enabled: d.enabled, label: d.label, box: new THREE.Box3(new THREE.Vector3(...
|
|
4171
|
-
: { id: d.id, kind: 'plane', enabled: d.enabled, label: d.label, n: new THREE.Vector3(...
|
|
4841
|
+
? { id: d.id, kind: 'box', enabled: d.enabled, label: d.label, box: new THREE.Box3(new THREE.Vector3(...box.min), new THREE.Vector3(...box.max)), planes: [] }
|
|
4842
|
+
: { id: d.id, kind: 'plane', enabled: d.enabled, label: d.label, n: new THREE.Vector3(...normal), point: new THREE.Vector3(...point), planes: [] };
|
|
4172
4843
|
rebuildClipPlanes(c); return c;
|
|
4173
4844
|
});
|
|
4174
4845
|
if (s.workArea) { const b = new THREE.Box3(new THREE.Vector3(...s.workArea.box.min), new THREE.Vector3(...s.workArea.box.max)); workArea = { enabled: s.workArea.enabled, whole: s.workArea.whole !== false, box: b, planes: boxToPlanes(b) }; } // whole !== false → older snapshots (no field) restore as show-whole
|
|
@@ -4176,89 +4847,16 @@ function setClipState(s) {
|
|
|
4176
4847
|
selectedClipIds = new Set(s.selected || []);
|
|
4177
4848
|
if (typeof s.seq === 'number') clipSeq = Math.max(clipSeq, s.seq);
|
|
4178
4849
|
applyClips(); renderClipGizmo(); renderWorkArea(); refreshWorkAreaVis(); renderWorkPlane();
|
|
4850
|
+
syncSpatialSections();
|
|
4851
|
+
if (clipSession) clipSession.setSelected(s.selected || []);
|
|
4179
4852
|
if (api && api.onClipsChange) api.onClipsChange();
|
|
4180
4853
|
if (api && api.onWorkAreaChange) api.onWorkAreaChange(workAreaState()); // undo/redo of a work-area edit must resync the Work-area button + its sliders, not just the model
|
|
4181
4854
|
}
|
|
4182
4855
|
|
|
4183
|
-
|
|
4184
|
-
function
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
if (overlayScene) overlayScene.remove(clipGizmo); clipGizmo = null;
|
|
4188
|
-
}
|
|
4189
|
-
const FACE_AXES = [{ axis: 'x', sign: 1 }, { axis: 'x', sign: -1 }, { axis: 'y', sign: 1 }, { axis: 'y', sign: -1 }, { axis: 'z', sign: 1 }, { axis: 'z', sign: -1 }];
|
|
4190
|
-
function renderClipGizmo() {
|
|
4191
|
-
clearClipGizmo();
|
|
4192
|
-
if (!selectedClipIds.size || !overlayScene) return;
|
|
4193
|
-
clipGizmo = new THREE.Group(); overlayScene.add(clipGizmo);
|
|
4194
|
-
// The SAME manipulator for a clip plane AND each clip-box face: a translucent disc lying in the plane/face +
|
|
4195
|
-
// a normal arrow (stem + cone) showing the drag direction. Grab the disc or the arrow to slide it along `normal`.
|
|
4196
|
-
const addHandle = (anchor, normal, ud, color) => {
|
|
4197
|
-
const disc = new THREE.Mesh(new THREE.CircleGeometry(1, 32), new THREE.MeshBasicMaterial({ color, transparent: true, opacity: 0.32, side: THREE.DoubleSide }));
|
|
4198
|
-
disc.material.depthTest = false; disc.renderOrder = 998; disc.position.copy(anchor); disc.quaternion.setFromUnitVectors(_ZA, normal); disc.userData = { clipHandle: true, disc: true, ...ud }; clipGizmo.add(disc);
|
|
4199
|
-
const stem = new THREE.Line(new THREE.BufferGeometry().setFromPoints([anchor.clone(), anchor.clone()]), new THREE.LineBasicMaterial({ color })); stem.material.depthTest = false; stem.renderOrder = 998; stem.userData = { clipStem: true, baseHp: anchor.clone(), normal: normal.clone() }; clipGizmo.add(stem);
|
|
4200
|
-
const cone = new THREE.Mesh(new THREE.ConeGeometry(0.5, 1.5, 18), new THREE.MeshBasicMaterial({ color })); cone.material.depthTest = false; cone.renderOrder = 999; cone.quaternion.setFromUnitVectors(_YA, normal); cone.userData = { clipHandle: true, arrow: true, baseHp: anchor.clone(), normal: normal.clone(), ...ud }; clipGizmo.add(cone);
|
|
4201
|
-
};
|
|
4202
|
-
for (const c of clips) { // a gizmo for EACH selected clip (the handles carry clipId so a drag knows which one)
|
|
4203
|
-
if (!selectedClipIds.has(c.id)) continue;
|
|
4204
|
-
if (c.kind === 'box') {
|
|
4205
|
-
const hb = new THREE.Box3Helper(c.box, new THREE.Color(CLIP_BOX_COLOR)); hb.material.depthTest = false; hb.renderOrder = 996; clipGizmo.add(hb);
|
|
4206
|
-
const ctr = c.box.getCenter(new THREE.Vector3());
|
|
4207
|
-
for (const f of FACE_AXES) {
|
|
4208
|
-
const p = ctr.clone(); p[f.axis] = f.sign > 0 ? c.box.max[f.axis] : c.box.min[f.axis]; // face centre
|
|
4209
|
-
const nf = new THREE.Vector3(f.axis === 'x' ? f.sign : 0, f.axis === 'y' ? f.sign : 0, f.axis === 'z' ? f.sign : 0); // OUTWARD face normal = drag axis
|
|
4210
|
-
addHandle(p, nf, { face: f, clipId: c.id }, CLIP_BOX_COLOR);
|
|
4211
|
-
}
|
|
4212
|
-
} else {
|
|
4213
|
-
const hp = c.point.clone(); // the patch sits at the click point (c.point moves along the normal as you drag, so it stays put laterally)
|
|
4214
|
-
const r = CLIP_PLANE_PATCH_R; // small fixed 2'×2' patch — a marker at the cut, not a view-spanning sheet
|
|
4215
|
-
const outline = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(planePatchCorners(hp, c.n, r)), new THREE.LineBasicMaterial({ color: CLIP_PLANE_COLOR })); outline.material.depthTest = false; outline.renderOrder = 996; clipGizmo.add(outline);
|
|
4216
|
-
addHandle(hp, c.n, { plane: true, clipId: c.id }, CLIP_PLANE_COLOR); // disc-in-plane + normal arrow (same manipulator as the box faces)
|
|
4217
|
-
}
|
|
4218
|
-
}
|
|
4219
|
-
sizeClipHandles();
|
|
4220
|
-
}
|
|
4221
|
-
function sizeClipHandles() { // screen-constant handles (like the endpoint dots): box pads ~10px; plane disc ~14px + an arrow offset ~34px off the plane
|
|
4222
|
-
if (!clipGizmo) return;
|
|
4223
|
-
for (const h of clipGizmo.children) {
|
|
4224
|
-
const ud = h.userData; if (!ud) continue;
|
|
4225
|
-
if (ud.arrow) { const off = pxToWorldAt(34, ud.baseHp); h.position.copy(ud.baseHp).addScaledVector(ud.normal, off); h.scale.setScalar(pxToWorldAt(11, h.position)); }
|
|
4226
|
-
else if (ud.disc) h.scale.setScalar(pxToWorldAt(14, h.position));
|
|
4227
|
-
else if (ud.clipHandle) h.scale.setScalar(pxToWorldAt(10, h.position)); // box face pads
|
|
4228
|
-
else if (ud.clipStem) h.geometry.setFromPoints([ud.baseHp, ud.baseHp.clone().addScaledVector(ud.normal, pxToWorldAt(34, ud.baseHp))]); // stem from the plane to the cone
|
|
4229
|
-
}
|
|
4230
|
-
}
|
|
4231
|
-
function setClipPreview(box) { // ghost wireframe while drawing a clip box (null clears it)
|
|
4232
|
-
if (clipPreview) { if (overlayScene) overlayScene.remove(clipPreview); clipPreview.geometry.dispose(); clipPreview.material.dispose(); clipPreview = null; }
|
|
4233
|
-
if (!box || box.isEmpty() || !overlayScene) return;
|
|
4234
|
-
clipPreview = new THREE.Box3Helper(box.clone(), new THREE.Color(CLIP_BOX_COLOR)); clipPreview.material.depthTest = false; clipPreview.renderOrder = 997; overlayScene.add(clipPreview);
|
|
4235
|
-
}
|
|
4236
|
-
// Screen-space nearest clip handle (mesh) within a px tolerance, or null — like pickEndpoint.
|
|
4237
|
-
function pickClipHandle(cx, cy) {
|
|
4238
|
-
if (!clipGizmo) return null;
|
|
4239
|
-
camera.updateMatrixWorld();
|
|
4240
|
-
const rect = canvasEl.getBoundingClientRect(), px = cx - rect.left, py = cy - rect.top;
|
|
4241
|
-
let best = null, bestD = 16;
|
|
4242
|
-
for (const h of clipGizmo.children) {
|
|
4243
|
-
if (!h.userData || !h.userData.clipHandle) continue;
|
|
4244
|
-
const v = h.position.clone().project(camera); if (v.z > 1) continue;
|
|
4245
|
-
const sx = (v.x * 0.5 + 0.5) * rect.width, sy = (-v.y * 0.5 + 0.5) * rect.height, dd = Math.hypot(sx - px, sy - py);
|
|
4246
|
-
if (dd < bestD) { bestD = dd; best = h; }
|
|
4247
|
-
}
|
|
4248
|
-
return best;
|
|
4249
|
-
}
|
|
4250
|
-
// test helper: the selected clip's handles projected to client px (so an E2E can drag a specific one)
|
|
4251
|
-
function clipHandlesScreen() {
|
|
4252
|
-
if (!clipGizmo || !canvasEl) return [];
|
|
4253
|
-
camera.updateMatrixWorld();
|
|
4254
|
-
const rect = canvasEl.getBoundingClientRect(), out = [];
|
|
4255
|
-
for (const h of clipGizmo.children) {
|
|
4256
|
-
if (!h.userData || !h.userData.clipHandle) continue;
|
|
4257
|
-
const v = h.position.clone().project(camera);
|
|
4258
|
-
out.push({ plane: !!h.userData.plane, axis: h.userData.face ? h.userData.face.axis : null, sign: h.userData.face ? h.userData.face.sign : 0, x: rect.left + (v.x * 0.5 + 0.5) * rect.width, y: rect.top + (-v.y * 0.5 + 0.5) * rect.height, behind: v.z > 1 });
|
|
4259
|
-
}
|
|
4260
|
-
return out;
|
|
4261
|
-
}
|
|
4856
|
+
function clearClipGizmo() { /* the shared overlay owns and disposes every clip visual */ }
|
|
4857
|
+
function renderClipGizmo() { clipOverlay?.render(); }
|
|
4858
|
+
function sizeClipHandles() { clipOverlay?.resize(); }
|
|
4859
|
+
function clipHandlesScreen() { return clipOverlay?.handlesScreen() ?? []; }
|
|
4262
4860
|
// t along the line P + t*u (u unit) at the point closest to the cursor ray — drives handle dragging.
|
|
4263
4861
|
function lineClosestT(P, u, ray) {
|
|
4264
4862
|
const w0 = P.clone().sub(ray.origin), b = u.dot(ray.direction), e = ray.direction.dot(w0), d = u.dot(w0), cc = ray.direction.dot(ray.direction);
|
|
@@ -4270,33 +4868,6 @@ function rayAt(cx, cy) {
|
|
|
4270
4868
|
raycaster.setFromCamera(new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1), camera);
|
|
4271
4869
|
return raycaster.ray;
|
|
4272
4870
|
}
|
|
4273
|
-
function startClipDrag(h, e) { // h = the picked handle mesh; set up a drag along its axis
|
|
4274
|
-
const c = clips.find((x) => x.id === h.userData.clipId); if (!c) { controls.enabled = true; return; }
|
|
4275
|
-
const u = h.userData.plane ? c.n.clone() : new THREE.Vector3(h.userData.face.axis === 'x' ? 1 : 0, h.userData.face.axis === 'y' ? 1 : 0, h.userData.face.axis === 'z' ? 1 : 0);
|
|
4276
|
-
const lineP = h.position.clone(), t0 = lineClosestT(lineP, u, rayAt(e.clientX, e.clientY));
|
|
4277
|
-
pending = h.userData.plane
|
|
4278
|
-
? { clipDrag: true, clip: c, plane: true, u, lineP, t0, basePoint: c.point.clone(), prePoint: c.point.clone() }
|
|
4279
|
-
: { clipDrag: true, clip: c, face: h.userData.face, u, lineP, t0, startCoord: h.userData.face.sign > 0 ? c.box.max[h.userData.face.axis] : c.box.min[h.userData.face.axis], preBox: c.box.clone() };
|
|
4280
|
-
dragging = null;
|
|
4281
|
-
}
|
|
4282
|
-
function onMoveClip(e) {
|
|
4283
|
-
if (!dragging && Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) <= DRAG_TOL_PX) return;
|
|
4284
|
-
if (!dragging && api && api.beginClipEdit) api.beginClipEdit(); // first real move → snapshot the pre-drag state for undo
|
|
4285
|
-
dragging = pending;
|
|
4286
|
-
const c = pending.clip, t = lineClosestT(pending.lineP, pending.u, rayAt(e.clientX, e.clientY)), delta = t - pending.t0;
|
|
4287
|
-
if (pending.plane) { c.point = pending.basePoint.clone().addScaledVector(pending.u, delta); }
|
|
4288
|
-
else {
|
|
4289
|
-
const f = pending.face; let val = pending.startCoord + delta;
|
|
4290
|
-
if (f.sign > 0) c.box.max[f.axis] = Math.max(val, c.box.min[f.axis] + 1); // keep min < max
|
|
4291
|
-
else c.box.min[f.axis] = Math.min(val, c.box.max[f.axis] - 1);
|
|
4292
|
-
}
|
|
4293
|
-
rebuildClipPlanes(c); applyClips(); renderClipGizmo();
|
|
4294
|
-
if (readout) { // live readout near the cursor: the box dimension along the drag axis, or the plane's offset moved
|
|
4295
|
-
readout._dist.textContent = (pending.plane ? (delta / FT_MM) : ((c.box.max[pending.face.axis] - c.box.min[pending.face.axis]) / FT_MM)).toFixed(2) + ' ft';
|
|
4296
|
-
readout._type.textContent = pending.plane ? ' ⟂' : ' ' + pending.face.axis.toUpperCase();
|
|
4297
|
-
readout.style.left = (e.clientX + 14) + 'px'; readout.style.top = (e.clientY + 14) + 'px'; readout.style.display = 'block';
|
|
4298
|
-
}
|
|
4299
|
-
}
|
|
4300
4871
|
// 3-step clip-box draw: click the two FOOTPRINT corners on the floor, then move up/down to PULL the height and
|
|
4301
4872
|
// click to commit (CAD "rectangle then extrude"). clipBoxDraft: {a} → {a,b} → committed.
|
|
4302
4873
|
/**
|
|
@@ -4306,7 +4877,7 @@ function onMoveClip(e) {
|
|
|
4306
4877
|
* project holding only a borrowed IFC used to be z=0 while the building sat hundreds of feet away. The
|
|
4307
4878
|
* rectangle was then drawn in empty space below the model and the box committed around nothing.
|
|
4308
4879
|
*
|
|
4309
|
-
* HELD FOR THE SPAN OF ONE DRAW, in `clipFloorZ`, because
|
|
4880
|
+
* HELD FOR THE SPAN OF ONE DRAW, in `clipFloorZ`, because the shared gesture asks on every mousemove and
|
|
4310
4881
|
* the answer walks every mesh of every visible reference. Same per-draw cache the snap candidates use
|
|
4311
4882
|
* two lines down, dropped by the same `setClipMode` on every arm and disarm — so it cannot outlive the
|
|
4312
4883
|
* draw it was measured for, and a reference that arrives, moves, or is hidden between draws is picked
|
|
@@ -4316,9 +4887,6 @@ function clipBoxFloorZ() {
|
|
|
4316
4887
|
if (clipFloorZ === null) { const b = visibleWorldBox(); clipFloorZ = b.isEmpty() ? 0 : b.min.z; }
|
|
4317
4888
|
return clipFloorZ;
|
|
4318
4889
|
}
|
|
4319
|
-
function clipBoxFrom(a, b, zlo, ztop) {
|
|
4320
|
-
return new THREE.Box3(new THREE.Vector3(Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.min(zlo, ztop)), new THREE.Vector3(Math.max(a[0], b[0]), Math.max(a[1], b[1]), Math.max(zlo, ztop)));
|
|
4321
|
-
}
|
|
4322
4890
|
// The clip-box draw's snap targets, built ONCE per draw (allCandidates does O(n²) beam-intersection work — the
|
|
4323
4891
|
// dim/Move tools cache it too, tfCandidates/dimCandidates3d). Members can't change mid-draw, so setClipMode drops
|
|
4324
4892
|
// the cache on every arm/disarm. A malformed member/grid degrades to no snap (raw floor), never a broken tool.
|
|
@@ -4356,35 +4924,44 @@ function clipBoxHeightAt(cx, cy) {
|
|
|
4356
4924
|
const r = snapPoint([mx, my, zRaw], levels, toScreen, SNAP_TOL_PX);
|
|
4357
4925
|
return r.candidate ? { z: r.snapped[2], snap: [mx, my, r.snapped[2]] } : { z: zRaw, snap: null };
|
|
4358
4926
|
}
|
|
4359
|
-
function
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4927
|
+
function ensureClipGesture() {
|
|
4928
|
+
if (clipGesture) return clipGesture;
|
|
4929
|
+
clipGesture = createModelClipGesture({
|
|
4930
|
+
visibleBounds() {
|
|
4931
|
+
const box = visibleWorldBox(); return box.isEmpty() ? null : { min: box.min.toArray(), max: box.max.toArray() };
|
|
4932
|
+
},
|
|
4933
|
+
resolvePlane({ clientX, clientY }) {
|
|
4934
|
+
const value = clipPlaneAtScreen(clientX, clientY); return value ? { point: value.point.toArray(), normal: value.n.toArray() } : null;
|
|
4935
|
+
},
|
|
4936
|
+
resolveFloor({ clientX, clientY }) {
|
|
4937
|
+
const value = clipBoxFloorPoint(clientX, clientY); return value ? { point: value.world, snap: value.snap } : null;
|
|
4938
|
+
},
|
|
4939
|
+
resolveHeight({ clientX, clientY }) {
|
|
4940
|
+
const value = clipBoxHeightAt(clientX, clientY); return value ? { z: value.z, point: value.snap, snap: value.snap ? 'level' : null } : null;
|
|
4941
|
+
},
|
|
4942
|
+
preview(value) {
|
|
4943
|
+
clipCreationPreview?.show(value);
|
|
4944
|
+
if (!value || value.kind === 'clear') { if (marker) marker.visible = false; return; }
|
|
4945
|
+
if (value.kind === 'plane') return;
|
|
4946
|
+
if (value.point && value.snap) showMarker(value.point, value.snap); else if (marker) marker.visible = false;
|
|
4947
|
+
},
|
|
4948
|
+
commitPlane(value) { addClipPlaneResolved({ point: new THREE.Vector3(...value.point), n: new THREE.Vector3(...value.normal) }); },
|
|
4949
|
+
commitBox(value) { addClipBoxFromBox(new THREE.Box3(new THREE.Vector3(...value.min), new THREE.Vector3(...value.max))); },
|
|
4950
|
+
onState(value) {
|
|
4951
|
+
const active = value.active;
|
|
4952
|
+
clipMode = active?.mode ?? null;
|
|
4953
|
+
clipBoxDraft = active?.mode === 'box' && active.draft
|
|
4954
|
+
? { a: active.draft.a.slice(0, 2), b: active.draft.b ? active.draft.b.slice(0, 2) : null }
|
|
4955
|
+
: null;
|
|
4956
|
+
if (active?.mode === 'box' && Number.isFinite(active.floorZ)) clipFloorZ = active.floorZ;
|
|
4957
|
+
if (!active) { clipCandidates = null; clipLevels = null; invalidateClipFloor(); }
|
|
4958
|
+
if (!active) releaseClipGestureInput?.deactivate?.();
|
|
4959
|
+
if (canvasEl) canvasEl.style.cursor = clipMode ? 'crosshair' : 'default';
|
|
4960
|
+
updateStatusChip(); if (api?.onClipModeChange) api.onClipModeChange(clipMode); viewportReports?.reportSectionState();
|
|
4961
|
+
},
|
|
4962
|
+
onCursor(value) { if (canvasEl) canvasEl.style.cursor = value; },
|
|
4963
|
+
});
|
|
4964
|
+
return clipGesture;
|
|
4388
4965
|
}
|
|
4389
4966
|
|
|
4390
4967
|
// ---- working area (Tekla-style) ----
|
|
@@ -4407,7 +4984,7 @@ function setWorkAreaBox(box) {
|
|
|
4407
4984
|
const whole = workArea ? workArea.whole : true; // keep the current cut/whole mode across a re-define; a brand-new work area defaults to "show whole parts" (no surprise slicing)
|
|
4408
4985
|
workArea = { enabled: true, whole, planes: boxToPlanes(box), box: box.clone() };
|
|
4409
4986
|
applyClips(); renderWorkArea(); refreshWorkAreaVis(); renderWorkPlane();
|
|
4410
|
-
|
|
4987
|
+
publishWorkAreaState();
|
|
4411
4988
|
return true;
|
|
4412
4989
|
}
|
|
4413
4990
|
function workAreaSetAll() { return setWorkAreaBox(visibleWorldBox()); } // "set work area to all objects" — ALL objects, so a visible reference model counts; steel-only made this return false (a dead control) on a project holding only a borrowed IFC
|
|
@@ -4420,7 +4997,7 @@ function workAreaToggle(on) {
|
|
|
4420
4997
|
if (api && api.beginClipEdit) api.beginClipEdit(); // undoable
|
|
4421
4998
|
workArea.enabled = on === undefined ? !workArea.enabled : !!on;
|
|
4422
4999
|
applyClips(); renderWorkArea(); refreshWorkAreaVis(); renderWorkPlane();
|
|
4423
|
-
|
|
5000
|
+
publishWorkAreaState();
|
|
4424
5001
|
return workArea.enabled;
|
|
4425
5002
|
}
|
|
4426
5003
|
// "Show whole parts" toggle: whole → a part touching the box shows in full (nothing sliced); cut → hard planar
|
|
@@ -4430,18 +5007,18 @@ function workAreaSetWhole(on) {
|
|
|
4430
5007
|
if (api && api.beginClipEdit) api.beginClipEdit(); // undoable
|
|
4431
5008
|
workArea.whole = on === undefined ? !workArea.whole : !!on;
|
|
4432
5009
|
applyClips(); refreshWorkAreaVis();
|
|
4433
|
-
|
|
5010
|
+
publishWorkAreaState();
|
|
4434
5011
|
return workArea.whole;
|
|
4435
5012
|
}
|
|
4436
|
-
function clearWorkArea() { if (api && api.beginClipEdit && workArea) api.beginClipEdit(); workArea = null; applyClips(); renderWorkArea(); refreshWorkAreaVis(); renderWorkPlane();
|
|
5013
|
+
function clearWorkArea() { if (api && api.beginClipEdit && workArea) api.beginClipEdit(); workArea = null; applyClips(); renderWorkArea(); refreshWorkAreaVis(); renderWorkPlane(); publishWorkAreaState(); }
|
|
4437
5014
|
function workAreaState() { return workArea ? { on: workArea.enabled, whole: !!workArea.whole } : null; }
|
|
4438
5015
|
// The camera viewpoint as plain data — position + orbit target + projection + the ortho frustum half-height
|
|
4439
5016
|
// and zoom. A saved view restores it via setCameraState. (perspCam/orthoCam share position; orthoBaseH+zoom
|
|
4440
5017
|
// size the ortho frustum.)
|
|
4441
|
-
function cameraState() { return { v: 1, pos: camera.position.toArray(), target: controls.target.toArray(), proj: projection(), orthoH: orthoBaseH, zoom: orthoCam.zoom }; }
|
|
4442
|
-
function
|
|
5018
|
+
function cameraState() { return { v: 1, pos: camera.position.toArray(), target: controls.target.toArray(), proj: projection(), orthoH: orthoBaseH, zoom: orthoCam.zoom, up: camera.up.toArray(), near: camera.near, far: camera.far }; }
|
|
5019
|
+
function setCameraStateSteel(s) {
|
|
4443
5020
|
if (!s || !Array.isArray(s.pos) || !Array.isArray(s.target)) return;
|
|
4444
|
-
|
|
5021
|
+
setProjectionSteel(s.proj === 'ortho' ? 'ortho' : 'persp'); // provider primitive: the controller already owns this transaction
|
|
4445
5022
|
controls.target.fromArray(s.target);
|
|
4446
5023
|
camera.position.fromArray(s.pos);
|
|
4447
5024
|
if (camera === orthoCam) { if (s.orthoH > 0) orthoBaseH = s.orthoH; orthoCam.zoom = s.zoom > 0 ? s.zoom : 1; reframeOrtho(); }
|
|
@@ -4543,41 +5120,18 @@ function visibleWorldBox() {
|
|
|
4543
5120
|
return box;
|
|
4544
5121
|
}
|
|
4545
5122
|
|
|
4546
|
-
function
|
|
4547
|
-
|
|
4548
|
-
|
|
5123
|
+
function frameAllSteel() { fitCamera(visibleWorldBox()); }
|
|
5124
|
+
// Mutation-test seam retained for the Steel reference-bounds guard; the values themselves live only
|
|
5125
|
+
// in the shared navigation module, so every provider and the guard exercise the same presets.
|
|
5126
|
+
const VIEWS = MODEL_NAMED_VIEWS;
|
|
5127
|
+
function applyViewSteel(name) { const d = VIEWS[name]; if (d) fitCamera(visibleWorldBox(), new THREE.Vector3(d[0], d[1], d[2])); }
|
|
4549
5128
|
// Fit just the selection (Tekla "Zoom selected" / Shift+Space); falls back to fit-all when nothing's picked.
|
|
4550
|
-
function
|
|
4551
|
-
if (!selIds.size) { fitCamera(visibleWorldBox()); return; }
|
|
5129
|
+
function frameSelectionSteel() {
|
|
5130
|
+
if (!selIds.size) { fitCamera(visibleWorldBox()); return true; }
|
|
4552
5131
|
const box = new THREE.Box3();
|
|
4553
|
-
for (const id of selIds) { const m = meshById.get(id);
|
|
4554
|
-
if (
|
|
4555
|
-
}
|
|
4556
|
-
// ---- Tekla-style keyboard nav: arrows pan, Ctrl+arrows rotate 15°, Shift+arrows rotate 5° ----
|
|
4557
|
-
const _UP = new THREE.Vector3(0, 0, 1);
|
|
4558
|
-
function rotateView(dAz, dPolar) { // dAz = around world up (Z); dPolar = tilt around the camera-right axis
|
|
4559
|
-
camera.updateMatrix();
|
|
4560
|
-
const off = camera.position.clone().sub(controls.target);
|
|
4561
|
-
off.applyAxisAngle(_UP, dAz);
|
|
4562
|
-
const right = new THREE.Vector3().crossVectors(off, _UP);
|
|
4563
|
-
if (right.lengthSq() < 1e-9) right.setFromMatrixColumn(camera.matrix, 0); // looking straight down/up → use the camera's screen-right so tilt still works
|
|
4564
|
-
right.normalize();
|
|
4565
|
-
const tilted = off.clone().applyAxisAngle(right, dPolar);
|
|
4566
|
-
if (Math.abs(tilted.clone().normalize().dot(_UP)) < 0.999) off.copy(tilted); // don't flip over the pole
|
|
4567
|
-
camera.position.copy(controls.target).add(off); camera.lookAt(controls.target); controls.update();
|
|
4568
|
-
}
|
|
4569
|
-
function panView(dx, dy) { // dx/dy in "steps" along the camera's screen right/up
|
|
4570
|
-
// step ∝ the on-screen world height: distance for perspective, frustum-height/zoom for ortho.
|
|
4571
|
-
const step = camera.isOrthographicCamera
|
|
4572
|
-
? ((orthoCam.top - orthoCam.bottom) / (orthoCam.zoom || 1)) * 0.06
|
|
4573
|
-
: camera.position.distanceTo(controls.target) * 0.06;
|
|
4574
|
-
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
|
|
4575
|
-
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
|
|
4576
|
-
const move = right.multiplyScalar(dx * step).add(up.multiplyScalar(dy * step));
|
|
4577
|
-
camera.position.add(move); controls.target.add(move); controls.update();
|
|
4578
|
-
}
|
|
4579
|
-
const ARROWS = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, 1], ArrowDown: [0, -1] };
|
|
4580
|
-
const VIEW_KEYS = { t: 'top', f: 'front', r: 'right', b: 'back', l: 'left' }; // single-key ortho views, mirrors the ViewCube + AWARE viewer-3d
|
|
5132
|
+
for (const id of selIds) { const m = meshById.get(id),detail=String(id).startsWith('det:');if(detail&&m&&(m.userData._detailOpacity==null?m.material.opacity:m.userData._detailOpacity)<=0)continue;if(meshContributesPixels(m,displayMode==='wire'&&!detail))box.expandByObject(m); }
|
|
5133
|
+
if (box.isEmpty()) return false;fitCamera(box);return true;
|
|
5134
|
+
}
|
|
4581
5135
|
function onKey(e) {
|
|
4582
5136
|
// NOT "is the canvas visible" — that predicate was written when 2D and 3D were mutually exclusive,
|
|
4583
5137
|
// where visible and active were the same fact. In a split both canvases are on screen at once, and a
|
|
@@ -4592,7 +5146,6 @@ function onKey(e) {
|
|
|
4592
5146
|
// loaded, and cancelling only the active case left it armed to fire on the next few pixels of a
|
|
4593
5147
|
// press the user had already abandoned.
|
|
4594
5148
|
if (teklaDrag && e.key === 'Escape') { e.preventDefault(); endTeklaDrag(); pending = dragging = null; if (controls) controls.enabled = true; return; }
|
|
4595
|
-
if (pending && pending.clipDrag && e.key === 'Escape') { e.preventDefault(); const p = pending; if (p.plane) p.clip.point = p.prePoint; else p.clip.box.copy(p.preBox); rebuildClipPlanes(p.clip); applyClips(); renderClipGizmo(); pending = dragging = null; if (controls) controls.enabled = true; if (readout) readout.style.display = 'none'; return; } // Esc mid-drag → undo the handle move
|
|
4596
5149
|
if (framePicking() && e.key === 'Escape') { e.preventDefault(); if (frame3d) { cancelFramePick(); fireFrameChange(); } else armFrame3d(false); return; } // Esc cancels the whole 3-click pick (discards partial clicks); no prior frame → also exit the tool
|
|
4597
5150
|
if (pending && pending.frameDrag && e.key === 'Escape') { e.preventDefault(); if (frame3d && pending.preFrame) frame3d = cloneFrame(pending.preFrame); pending = dragging = null; if (controls) controls.enabled = true; if (readout) readout.style.display = 'none'; fireFrameChange(); return; } // Esc mid-drag → revert the frame to its pre-drag basis
|
|
4598
5151
|
if (frameMode && e.key === 'Escape' && !pending) { e.preventDefault(); disarmFrame3d(); return; } // armed but idle (frame set, gizmo grabbable for refine) → Esc exits the "Set local axes" tool (the frame stays; it just stops being editable). `!pending` so a mid-gesture Esc (member move / endpoint stretch, reachable while the tool is armed) still falls through to the cancel-and-revert below instead of silently committing (code-review) (frame set, gizmo grabbable for refine) → Esc exits the "Set local axes" tool (the frame stays; it just stops being editable). `!pending` so a mid-gesture Esc (member move / endpoint stretch, reachable while the tool is armed) still falls through to the cancel-and-revert below instead of silently committing (code-review)
|
|
@@ -4633,9 +5186,17 @@ function onKey(e) {
|
|
|
4633
5186
|
if (api && api.onConnMemberPickCommit) api.onConnMemberPickCommit(jointId, chosen, skipped);
|
|
4634
5187
|
return;
|
|
4635
5188
|
}
|
|
4636
|
-
if (insertMode && e.key === 'Escape') {
|
|
5189
|
+
if (insertMode && e.key === 'Escape') {
|
|
5190
|
+
e.preventDefault();
|
|
5191
|
+
if (detailPlanePick) {
|
|
5192
|
+
detailPlanePick = null; detailPlaneCandidates = null; setFacePickPreview(null);
|
|
5193
|
+
if (marker) marker.visible = false; if (readout) readout.style.display = 'none';
|
|
5194
|
+
if (canvasEl) canvasEl.style.cursor = 'crosshair';
|
|
5195
|
+
updateStatusChip(); notifyInstructor(); if (api && api.toast) api.toast('Face released — choose another member face');
|
|
5196
|
+
} else { setInsertMode(false); if (api && api.toast) api.toast('Insert cancelled'); }
|
|
5197
|
+
return;
|
|
5198
|
+
} // Detail placement steps back from point → face before a second Esc disarms it
|
|
4637
5199
|
if (basePickCol && e.key === 'Escape') { e.preventDefault(); setBasePickMode(null); if (api && api.toast) api.toast('Trim cancelled'); return; } // Esc disarms the Mode B column-base pick
|
|
4638
|
-
if (clipMode && e.key === 'Escape') { e.preventDefault(); if (clipMode === 'box' && clipBoxDraft) { if (clipBoxDraft.b) clipBoxDraft.b = null; else clipBoxDraft = null; setClipPreview(null); if (marker) marker.visible = false; updateStatusChip(); } else setClipMode(null); return; } // Esc steps back: height→footprint→cancel, else disarms the pick
|
|
4639
5200
|
if (isIsolated() && e.key === 'Escape' && !dimMode3d) { e.preventDefault(); clearIsolation(); return; } // Esc exits isolate-selected (the dim tool's own Esc wins while it's armed)
|
|
4640
5201
|
// Esc ascends the REFERENCE drill: one object → the whole reference. ONE RUNG ONLY — unlike the
|
|
4641
5202
|
// connection ladder below, which is part → whole → nothing. A reference is borrowed geometry you keep
|
|
@@ -4645,26 +5206,19 @@ function onKey(e) {
|
|
|
4645
5206
|
// line contradicts.)
|
|
4646
5207
|
if (e.key === 'Escape' && !dimMode3d && !cmActive() && xrefSubSelected) { e.preventDefault(); selectReference(xrefSubSelected.refId); return; }
|
|
4647
5208
|
if (e.key === 'Escape' && !dimMode3d && !cmActive() && ascendConn()) { e.preventDefault(); return; } // Esc ascends the connection drill: part → whole → nothing
|
|
4648
|
-
if ((e.key === ' ' && e.shiftKey) || ((e.key === 'z' || e.key === 'Z') && e.altKey && !tfDraft)) { e.preventDefault(); frameSelection(); return; } // zoom-selected (Tekla Shift+Space / viewer Alt+Z) — Alt+Z is suppressed while a Move/Copy base is active: there Alt is the normal-lock modifier, so a reflexive Alt+Z must not jerk the camera mid-move (UCS Stage 4)
|
|
4649
5209
|
const k = e.key.toLowerCase();
|
|
4650
5210
|
// Don't touch the dim tool while a member gesture (drag / box-select) owns the shared marker/readout —
|
|
4651
5211
|
// toggling would clear them mid-gesture. The gesture finishes on pointerup; the key is a no-op until then.
|
|
4652
5212
|
const midGesture = pending || dragging || boxSel;
|
|
4653
|
-
if (k === 'd' && !e.ctrlKey && !e.metaKey && !e.altKey && !midGesture) { e.preventDefault();
|
|
5213
|
+
if (k === 'd' && !e.ctrlKey && !e.metaKey && !e.altKey && !midGesture) { e.preventDefault(); toggleMeasureTool(); return; } // D routes through the shared CAD lifecycle
|
|
4654
5214
|
if (dimMode3d && !midGesture) {
|
|
4655
|
-
if (k === 'escape') { e.preventDefault(); if (snapOnly3d) setSnapOnly3d(null); else if (dimDraft3d) { dimDraft3d = null; dimPreviewLine.visible = false; readout.style.display = 'none'; } else
|
|
4656
|
-
if (k === 'f' || k === 'x' || k === 'y' || k === 'z') { e.preventDefault();
|
|
5215
|
+
if (k === 'escape') { e.preventDefault(); if (snapOnly3d) setSnapOnly3d(null); else if (measureSession) { measureSession.cancelStep(); dimPreviewLine.visible = false; readout.style.display = 'none'; clearSharedSnapGuides(); } else if (dimDraft3d) { dimDraft3d = null; dimPreviewLine.visible = false; readout.style.display = 'none'; } else disarmMeasureTool(); return; } // Esc steps back through the common restriction → point 2 → point 1 → tool lifecycle
|
|
5216
|
+
if (k === 'f' || k === 'x' || k === 'y' || k === 'z') { e.preventDefault(); setMeasureAxisLock(k); return; } // shared controller owns axis-lock commands; Steel paints the richer bar
|
|
4657
5217
|
}
|
|
4658
|
-
// Named-view shortcuts mirror the ViewCube faces (parity with AWARE viewer-3d): T/F/R/B/L snap to an ortho view.
|
|
4659
|
-
if (VIEW_KEYS[k] && !cmActive() && (k !== 'f' || !addActive()) && !wpMode && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey) { e.preventDefault(); applyView(VIEW_KEYS[k]); return; } // while Move/Copy or a set-plane pick is armed, no view key fires (unchanged); while Add is armed only F is claimed (axis-lock clear) — T/R/B/L still switch views (review finding)
|
|
4660
|
-
const a = ARROWS[e.key]; if (!a) return;
|
|
4661
|
-
const [hx, hy] = a;
|
|
4662
|
-
if (e.ctrlKey || e.metaKey) { e.preventDefault(); rotateView(-hx * Math.PI / 12, hy * Math.PI / 12); } // 15°
|
|
4663
|
-
else if (e.shiftKey) { e.preventDefault(); rotateView(-hx * Math.PI / 36, hy * Math.PI / 36); } // 5°
|
|
4664
|
-
else { e.preventDefault(); panView(hx, hy); } // pan
|
|
4665
5218
|
}
|
|
4666
5219
|
// ---- 3D dimension tool controls (driven from the toolbar + the keyboard) ----
|
|
4667
5220
|
function toggleDimTool() {
|
|
5221
|
+
if (cadToolController && !cadToolDispatch) return cadToolController.toggleMeasure().armed;
|
|
4668
5222
|
abandonConnPick('other-tool'); // every other mode disarms its rivals; without this the pick keeps swallowing clicks while another tool reports armed
|
|
4669
5223
|
// ARMING is refused when the host says the model is read-only (unit 5, P7d). Disabling the #m3dDim
|
|
4670
5224
|
// BUTTON is not enough and that was measured, not assumed: the tool also arms from a bare `d` keydown
|
|
@@ -4676,13 +5230,18 @@ function toggleDimTool() {
|
|
|
4676
5230
|
return dimMode3d;
|
|
4677
5231
|
}
|
|
4678
5232
|
if (!dimMode3d) { dropGridLinePick3d(); dropRefMeasure3d(); } // arming the dim tool takes the left-click — cancel an armed grid-line pick AND an armed reference measure through the editor first
|
|
4679
|
-
|
|
4680
|
-
if (
|
|
5233
|
+
const nextMeasureArmed = !dimMode3d;
|
|
5234
|
+
if (measureSession) measureSession.setArmed(nextMeasureArmed); else dimMode3d = nextMeasureArmed;
|
|
5235
|
+
if (!nextMeasureArmed) { dimDraft3d = null; dimCandidates3d = null; dimPreviewLine.visible = false; marker.visible = false; readout.style.display = 'none'; canvasEl.style.cursor = 'default'; setSnapOnly3d(null); clearSharedSnapGuides(); } // disarming ends the operation → the snap override reverts to all snaps
|
|
4681
5236
|
else { if (clipMode) setClipMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); controls.enabled = true; canvasEl.style.cursor = 'crosshair'; } // arming the dim tool disarms the clip pick, a set-plane pick, Move/Copy, Add-member AND the local frame (all share the left-click + Esc)
|
|
4682
5237
|
reflectDimBar();
|
|
4683
5238
|
updateStatusChip();
|
|
4684
5239
|
return dimMode3d;
|
|
4685
5240
|
}
|
|
5241
|
+
function toggleMeasureTool() { return cadToolController && !cadToolDispatch ? cadToolController.toggleMeasure() : toggleDimTool(); }
|
|
5242
|
+
function disarmMeasureTool() { return cadToolController && !cadToolDispatch ? cadToolController.setMeasureArmed(false) : (dimMode3d ? toggleDimTool() : null); }
|
|
5243
|
+
function setMeasureAxisLock(kind) { return cadToolController && !cadToolDispatch ? cadToolController.setMeasureAxisLock(kind) : setDimAxis(kind); }
|
|
5244
|
+
function clearMeasures() { return cadToolController ? cadToolController.clearMeasures() : (api?.onClearDims3d?.(), null); }
|
|
4686
5245
|
// Arm/disarm the grid panel's "Add single line" pick for the 3D view. The early-out keeps re-arming a no-op:
|
|
4687
5246
|
// every path that arms this pick starts from a fresh {a:null}, so a redundant arm can never wipe a half-finished one.
|
|
4688
5247
|
function armGridLinePick3d(on) {
|
|
@@ -4693,7 +5252,7 @@ function armGridLinePick3d(on) {
|
|
|
4693
5252
|
// basePickCol and insertMode matter as much as the rest: onDown routes both AHEAD of this pick, so leaving either
|
|
4694
5253
|
// armed would make every click place a detail / do the base pick while the hint still reads "Pick the first point"
|
|
4695
5254
|
// — the exact dead-control failure this change exists to fix.
|
|
4696
|
-
if (on) { dropRefMeasure3d(); if (dimMode3d)
|
|
5255
|
+
if (on) { dropRefMeasure3d(); if (dimMode3d) disarmMeasureTool(); if (clipMode) setClipMode(null); setInsertMode(false); setBasePickMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); }
|
|
4697
5256
|
gridLinePick3d = on ? { a: null } : null;
|
|
4698
5257
|
if (!gridLinePick3d) { if (dimPreviewLine) dimPreviewLine.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; if (canvasEl) canvasEl.style.cursor = 'default'; }
|
|
4699
5258
|
else { if (controls) controls.enabled = true; if (canvasEl) canvasEl.style.cursor = 'crosshair'; }
|
|
@@ -4724,7 +5283,7 @@ function armRefMeasure3d(refId) {
|
|
|
4724
5283
|
if (next && !was) {
|
|
4725
5284
|
// The DISARM direction on every one of these, exactly as armGridLinePick3d takes them: toggleDimTool
|
|
4726
5285
|
// and armWorkPlanePick are toggles, so they are called only when the thing is on, which turns it off.
|
|
4727
|
-
if (dimMode3d)
|
|
5286
|
+
if (dimMode3d) disarmMeasureTool();
|
|
4728
5287
|
// dropGridLinePick3d(), NOT armGridLinePick3d(false): the local setter clears only OUR flag and
|
|
4729
5288
|
// leaves the EDITOR's `gridLinePick` armed, so its panel hint goes on claiming a pick it no longer
|
|
4730
5289
|
// owns AND its Escape rung — which sits above the measure's — eats the first Esc. Every sibling
|
|
@@ -4850,6 +5409,7 @@ function setSnapOnly3d(k) { snapOnly3d = k || null; if (api && api.onSnapOnlyCha
|
|
|
4850
5409
|
// whichever locked axis the span runs most along); F/free clears → aligned. Refreshes the bar + chip so a key press
|
|
4851
5410
|
// then a click without moving measures what's shown.
|
|
4852
5411
|
function setDimAxis(a) {
|
|
5412
|
+
if (measureSession) { measureSession.setAxisLock(a === 'free' ? 'f' : a); return; }
|
|
4853
5413
|
if (a === 'free' || a === 'f') dimLock.clear();
|
|
4854
5414
|
else if (a === 'x' || a === 'y' || a === 'z') { if (dimLock.has(a)) dimLock.delete(a); else dimLock.add(a); }
|
|
4855
5415
|
reflectDimAxisBar(); updateStatusChip();
|
|
@@ -4868,7 +5428,7 @@ function dimAxisLabel(a) {
|
|
|
4868
5428
|
// "measuring" (NOT "locked") — a dimension only changes the MEASURED direction; the 2nd point still free-snaps
|
|
4869
5429
|
// (unlike Move/Copy, whose pick is truly axis-constrained). Frame-aware via dimAxisLabel.
|
|
4870
5430
|
function dimLockChipTxt() { const _l = ['x', 'y', 'z'].filter((a) => dimLock.has(a)); return _l.length ? ' · measuring ' + _l.map(dimAxisLabel).join(', ') : ''; }
|
|
4871
|
-
function setDims3dVisible(on) { dims3dVisibleFlag = !!on; refreshDims(); }
|
|
5431
|
+
function setDims3dVisible(on) { if (measureSession) measureSession.setVisible(!!on); else { dims3dVisibleFlag = !!on; refreshDims(); } }
|
|
4872
5432
|
function dims3dVisible() { return dims3dVisibleFlag; }
|
|
4873
5433
|
function reflectDimBar() {
|
|
4874
5434
|
const b = document.getElementById('m3dDim'); if (b) b.classList.toggle('on', dimMode3d);
|
|
@@ -5060,7 +5620,7 @@ function hoverMaterial(mesh) {
|
|
|
5060
5620
|
function setHoverGlow(id, on, sync = true) {
|
|
5061
5621
|
if (id == null) return;
|
|
5062
5622
|
const mesh = meshById.get(id);
|
|
5063
|
-
if (!mesh || String(id).startsWith('det:')) return; // placed details
|
|
5623
|
+
if (!mesh || String(id).startsWith('det:')) return; // placed details keep their texture; applyDisplayMode tints it from hoverGlowIds instead
|
|
5064
5624
|
if (selIds.has(id)) return; // selected beats hovered — don't disturb its blue glow
|
|
5065
5625
|
// Leaving hover returns to the RESTING material — amber if this connection is asking for review, so a
|
|
5066
5626
|
// pointer sweeping across the model does not wipe the lift off everything it touches.
|
|
@@ -5167,7 +5727,7 @@ function refreshDims() {
|
|
|
5167
5727
|
if (!dims3dGroup || !api || !api.getDims3d) return;
|
|
5168
5728
|
dimCandidates3d = null; // a rebuild may follow a member edit → don't keep stale snap targets for the next click
|
|
5169
5729
|
for (const c of [...dims3dGroup.children]) { dims3dGroup.remove(c); c.geometry.dispose(); c.material.dispose(); }
|
|
5170
|
-
const dims =
|
|
5730
|
+
const dims = steelMeasureDimensions();
|
|
5171
5731
|
const sel = new Set(api.selDim3d ? api.selDim3d() : []); // selDim3d now returns the selected-id ARRAY (multi-select)
|
|
5172
5732
|
if (dims3dVisibleFlag) {
|
|
5173
5733
|
for (const d of dims) {
|
|
@@ -5187,7 +5747,7 @@ function syncDimLabels(dims) {
|
|
|
5187
5747
|
while (dimLabelPool.length < dims.length) {
|
|
5188
5748
|
const el = document.createElement('div');
|
|
5189
5749
|
el.style.cssText = 'position:absolute;transform:translate(-50%,-50%);pointer-events:auto;cursor:pointer;background:var(--panel,#0f172a);color:var(--text,#f8fafc);border:1px solid var(--line,#1e293b);border-left:2px solid #67e8f9;border-radius:4px;padding:2px 6px;font:12px system-ui;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,.5)'; // cyan left accent (amber when selected) ties the chip to its dim line — matches the derived overlays
|
|
5190
|
-
el.addEventListener('pointerdown', (e) => { e.stopPropagation(); const id = el._dimId; if (api && api.onSelectDim3d) { api.onSelectDim3d(id, { ctrl: e.ctrlKey || e.metaKey, shift: e.shiftKey }); refreshDims(); } }); // Ctrl/Shift
|
|
5750
|
+
el.addEventListener('pointerdown', (e) => { e.stopPropagation(); const id = el._dimId; selectMeasureById(id); if (api && api.onSelectDim3d) { api.onSelectDim3d(id, { ctrl: e.ctrlKey || e.metaKey, shift: e.shiftKey }); refreshDims(); } }); // shared session owns the selected dimension; Steel preserves Ctrl/Shift multi-selection as provider chrome
|
|
5191
5751
|
dimLabelHost.appendChild(el); dimLabelPool.push(el);
|
|
5192
5752
|
}
|
|
5193
5753
|
const selSet = new Set(api.selDim3d ? api.selDim3d() : []);
|
|
@@ -5422,108 +5982,39 @@ function positionOverlayLabels() {
|
|
|
5422
5982
|
}
|
|
5423
5983
|
}
|
|
5424
5984
|
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
const
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
const hit = ray.intersectObject(mesh, false)[0]; if (!hit || !hit.face) return;
|
|
5455
|
-
const p = mesh.worldToLocal(hit.point.clone()), snap = (x) => Math.abs(x) > 0.6 ? Math.sign(x) : 0;
|
|
5456
|
-
const dv = new THREE.Vector3(snap(p.x), snap(p.y), snap(p.z));
|
|
5457
|
-
if (Math.abs(dv.x) + Math.abs(dv.y) + Math.abs(dv.z) <= 1) { const f = CUBE_FACES[hit.face.materialIndex]; if (f) applyView(f.view); } // a face → ortho view
|
|
5458
|
-
else fitCamera(visibleWorldBox(), dv); // an edge/corner → iso-style view from that world direction (the same bounds the face path frames through applyView — steel-only here would frame a cube FACE onto a reference model but a cube EDGE onto nothing)
|
|
5459
|
-
});
|
|
5460
|
-
cube = { renderer: cr, scene: cs, cam: cc, mesh };
|
|
5461
|
-
}
|
|
5462
|
-
|
|
5463
|
-
// ---- World-axis triad (Tekla-style) — a passive bottom-right gizmo showing where world X/Y/Z point.
|
|
5464
|
-
// Same sync-to-camera pattern as the ViewCube, but pointer-events:none: orientation CHANGES stay the
|
|
5465
|
-
// cube's job; this only reads out. Colors are the CAD convention (X red, Y green, Z blue = --brand).
|
|
5466
|
-
const TRIAD_AXES = [['X', '#ef4444', [1, 0, 0]], ['Y', '#22c55e', [0, 1, 0]], ['Z', '#3b82f6', [0, 0, 1]]];
|
|
5467
|
-
function triadTip(label, color, pos) { // free-standing colored letter with a dark halo — legible over any geometry, no disc
|
|
5468
|
-
const c = document.createElement('canvas'); c.width = c.height = 64; const g = c.getContext('2d');
|
|
5469
|
-
g.font = 'bold 46px ui-sans-serif,system-ui,sans-serif'; g.textAlign = 'center'; g.textBaseline = 'middle';
|
|
5470
|
-
g.lineWidth = 8; g.lineJoin = 'round'; g.strokeStyle = 'rgba(2,8,23,.9)'; g.strokeText(label, 32, 34);
|
|
5471
|
-
g.fillStyle = color; g.fillText(label, 32, 34);
|
|
5472
|
-
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: new THREE.CanvasTexture(c) }));
|
|
5473
|
-
s.position.copy(pos); s.scale.setScalar(0.85);
|
|
5474
|
-
return s;
|
|
5475
|
-
}
|
|
5476
|
-
function initTriad() {
|
|
5477
|
-
const host = document.getElementById('m3dAxes'); if (!host) return;
|
|
5478
|
-
const PX = 78;
|
|
5479
|
-
const tr = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
|
5480
|
-
tr.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2)); tr.setSize(PX, PX);
|
|
5481
|
-
host.appendChild(tr.domElement);
|
|
5482
|
-
const ts = new THREE.Scene();
|
|
5483
|
-
const tc = new THREE.OrthographicCamera(-2.1, 2.1, 2.1, -2.1, 0.1, 20); tc.position.set(0, 0, 5);
|
|
5484
|
-
const g = new THREE.Group();
|
|
5485
|
-
const Y = new THREE.Vector3(0, 1, 0); // Cylinder/ConeGeometry's own axis
|
|
5486
|
-
for (const [label, color, dir] of TRIAD_AXES) {
|
|
5487
|
-
const d = new THREE.Vector3(dir[0], dir[1], dir[2]);
|
|
5488
|
-
const mat = new THREE.MeshBasicMaterial({ color });
|
|
5489
|
-
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.06, 0.06, 1.05, 8), mat);
|
|
5490
|
-
shaft.quaternion.setFromUnitVectors(Y, d);
|
|
5491
|
-
shaft.position.copy(d).multiplyScalar(0.525);
|
|
5492
|
-
const head = new THREE.Mesh(new THREE.ConeGeometry(0.16, 0.34, 12), mat); // arrowhead at the shaft end
|
|
5493
|
-
head.quaternion.copy(shaft.quaternion);
|
|
5494
|
-
head.position.copy(d).multiplyScalar(1.22);
|
|
5495
|
-
g.add(shaft, head, triadTip(label, color, d.clone().multiplyScalar(1.62)));
|
|
5496
|
-
}
|
|
5497
|
-
g.add(new THREE.Mesh(new THREE.SphereGeometry(0.1, 12, 8), new THREE.MeshBasicMaterial({ color: 0xe2e8f0 }))); // origin dot
|
|
5498
|
-
ts.add(g);
|
|
5499
|
-
// The glyph is three arms out of ONE corner, so its origin dot sits dead centre while its visible mass
|
|
5500
|
-
// hangs up-and-right of it — against a chip centred under the box, the triad read as shifted. Centre the
|
|
5501
|
-
// ARTWORK instead of the origin: measure the group's bounds once, here, before any rotation is applied.
|
|
5502
|
-
// Measured rather than typed, so a change to the arm length keeps it centred. The label SPRITES are
|
|
5503
|
-
// left out of that measurement: each is a 0.85-unit quad carrying a single letter with a lot of
|
|
5504
|
-
// transparent padding, so a bounds that counts the quad counts ink that is not there and drags the
|
|
5505
|
-
// centre toward the labels — which is what left the arms sitting up and right of the box. Bounding
|
|
5506
|
-
// the shafts, heads and origin dot centres what a reader actually sees as the glyph.
|
|
5507
|
-
const armsOnly = new THREE.Box3();
|
|
5508
|
-
g.traverse((o) => { if (o.isMesh) armsOnly.expandByObject(o); });
|
|
5509
|
-
const centre = armsOnly.isEmpty()
|
|
5510
|
-
? new THREE.Box3().setFromObject(g).getCenter(new THREE.Vector3())
|
|
5511
|
-
: armsOnly.getCenter(new THREE.Vector3());
|
|
5512
|
-
triad = { renderer: tr, scene: ts, cam: tc, group: g, centre };
|
|
5513
|
-
}
|
|
5514
|
-
// The offset is re-rotated every frame rather than baked in: the group spins with the camera, so a fixed
|
|
5515
|
-
// translation would centre the glyph in one view and throw it off in every other.
|
|
5516
|
-
function syncTriad() {
|
|
5517
|
-
triad.group.quaternion.copy(camera.quaternion).invert();
|
|
5518
|
-
triad.group.position.copy(triad.centre).applyQuaternion(triad.group.quaternion).negate();
|
|
5519
|
-
}
|
|
5520
|
-
// Mirror the scene from the main camera's direction (the FRONT face turns toward the viewer in a
|
|
5521
|
-
// front view, etc.) by orienting the cube by the inverse of the camera's world rotation.
|
|
5522
|
-
function syncCube() { cube.mesh.quaternion.copy(camera.quaternion).invert(); }
|
|
5985
|
+
|
|
5986
|
+
// ---- Shared model.orientation.v1 port -----------------------------------------------------------
|
|
5987
|
+
// The provider owns fitting/bounds and camera state. The canonical shared chrome only consumes this
|
|
5988
|
+
// finite world-space pose and sends named or arbitrary target-to-camera directions back through it.
|
|
5989
|
+
function steelOrientationPose() {
|
|
5990
|
+
return modelOrientationPose({ v: 1, camera: {
|
|
5991
|
+
position: camera.position.toArray(), target: controls.target.toArray(), up: camera.up.toArray(),
|
|
5992
|
+
} });
|
|
5993
|
+
}
|
|
5994
|
+
function emitSteelOrientation() {
|
|
5995
|
+
if (!camera || !controls || !orientationListeners.size) return;
|
|
5996
|
+
const pose = steelOrientationPose(); for (const listener of orientationListeners) listener(pose);
|
|
5997
|
+
}
|
|
5998
|
+
function applySteelOrientationDirection(direction) {
|
|
5999
|
+
if (!Array.isArray(direction) || direction.length !== 3 || !direction.every(Number.isFinite)) throw new TypeError('View direction must be a finite vector.');
|
|
6000
|
+
const value = new THREE.Vector3().fromArray(direction); if (value.lengthSq() <= Number.EPSILON) throw new TypeError('View direction must be non-zero.');
|
|
6001
|
+
fitCamera(visibleWorldBox(), value.normalize());
|
|
6002
|
+
}
|
|
6003
|
+
const steelOrientationPort = Object.freeze({
|
|
6004
|
+
getPose: steelOrientationPose,
|
|
6005
|
+
subscribe(listener) {
|
|
6006
|
+
if (typeof listener !== 'function') throw new TypeError('Orientation subscriber must be a function.');
|
|
6007
|
+
orientationListeners.add(listener); listener(steelOrientationPose());
|
|
6008
|
+
let active = true; return () => { if (active) { active = false; orientationListeners.delete(listener); } };
|
|
6009
|
+
},
|
|
6010
|
+
applyView,
|
|
6011
|
+
applyDirection: applySteelOrientationDirection,
|
|
6012
|
+
});
|
|
6013
|
+
|
|
5523
6014
|
|
|
5524
6015
|
// Raycast the member meshes at a client (px) point → visible, clip-filtered hits nearest-first.
|
|
5525
6016
|
// Only VISIBLE meshes are included (a legend-hidden group must not swallow what's behind it).
|
|
5526
|
-
function meshHitsAt(cx,cy,primaryOnly=false) {
|
|
6017
|
+
function meshHitsAt(cx,cy,primaryOnly=false,visualOrder=false) {
|
|
5527
6018
|
camera.updateMatrixWorld(); root.updateMatrixWorld(true); // ensure current after any camera/mesh move
|
|
5528
6019
|
const rect = canvasEl.getBoundingClientRect();
|
|
5529
6020
|
const ndc = new THREE.Vector2(((cx - rect.left) / rect.width) * 2 - 1, -((cy - rect.top) / rect.height) * 2 + 1);
|
|
@@ -5531,7 +6022,7 @@ function meshHitsAt(cx,cy,primaryOnly=false) {
|
|
|
5531
6022
|
const hits = 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]));
|
|
5532
6023
|
// Ghost context must remain selectable, but it must not phantom-occlude a focused opaque object at
|
|
5533
6024
|
// the same cursor position. Preserve ray distance inside each tier so click-to-cycle stays stable.
|
|
5534
|
-
if (ghostUnselectedEnabled && selIds.size) hits.sort((a,b)=>(Number(selIds.has(b.object.userData.id))-Number(selIds.has(a.object.userData.id)))||(a.distance-b.distance));
|
|
6025
|
+
if (!visualOrder && ghostUnselectedEnabled && selIds.size) hits.sort((a,b)=>(Number(selIds.has(b.object.userData.id))-Number(selIds.has(a.object.userData.id)))||(a.distance-b.distance));
|
|
5535
6026
|
return hits;
|
|
5536
6027
|
}
|
|
5537
6028
|
function pickAt(cx, cy) {
|
|
@@ -5575,65 +6066,30 @@ function reconcileGridVisibilityState(scopeChanged=false){
|
|
|
5575
6066
|
if(next.changed){updateStatusChip();notifyVisibilityChange();}
|
|
5576
6067
|
}
|
|
5577
6068
|
function setGridSelection(ids){selectedGridIds=ids instanceof Set?new Set(ids):new Set(ids||[]);applyDisplayMode();updateStatusChip();}
|
|
5578
|
-
|
|
6069
|
+
// A Ghost change arriving here is an object-visibility change like any other, so it notifies as
|
|
6070
|
+
// setGhostUnselected() does: without that the host's Show all never learned Ghost had been turned on.
|
|
6071
|
+
// Only a CHANGE notifies — this runs on every selection repaint, and those must stay quiet.
|
|
6072
|
+
function setSelectionState(ids, gridIds, ghostEnabled=ghostUnselectedEnabled){const ghostChanged=(ghostEnabled===true)!==ghostUnselectedEnabled;ghostUnselectedEnabled=ghostEnabled===true;selectedGridIds=gridIds instanceof Set?new Set(gridIds):new Set(gridIds||[]);setSelection(ids);if(ghostChanged)notifyVisibilityChange();}
|
|
5579
6073
|
// Raycast ALL visible meshes — members AND derived connection parts — at a client point → ids
|
|
5580
6074
|
// front-to-back (nearest first), deduped. Backs click-to-cycle so a small plate/bolt/weld stacked on a
|
|
5581
6075
|
// beam at a joint is reachable without a modifier (D). pickAt stays members-only — the down-gesture
|
|
5582
6076
|
// (drag / box-select / geo-edit) and the dim-tool plane pick; hover uses pickAllAt so derived parts get the select cursor.
|
|
5583
6077
|
function pickAllAt(cx, cy) {
|
|
5584
6078
|
const hits = meshHitsAt(cx,cy);
|
|
6079
|
+
// A placed detail is intentionally coplanar with its anchor face. Polygon offset makes it visible but
|
|
6080
|
+
// does not affect ray distance, so break an effectively-equal hit in favour of the visible detail.
|
|
6081
|
+
hits.sort((a,b)=>{
|
|
6082
|
+
// Ghost mode deliberately lifts selected objects above faded context. Keep that tier intact, then
|
|
6083
|
+
// resolve the otherwise-indistinguishable anchor-face/detail hit inside the tier.
|
|
6084
|
+
if(ghostUnselectedEnabled&&selIds.size){const tier=Number(selIds.has(b.object.userData.id))-Number(selIds.has(a.object.userData.id));if(tier)return tier;}
|
|
6085
|
+
const d=a.distance-b.distance;if(Math.abs(d)>1e-3)return d;
|
|
6086
|
+
const ad=String(a.object.userData.id||'').startsWith('det:'),bd=String(b.object.userData.id||'').startsWith('det:');return Number(bd)-Number(ad);
|
|
6087
|
+
});
|
|
5585
6088
|
const ids = [];
|
|
5586
6089
|
for (const h of hits) { const id = h.object.userData.id; if (id && !ids.includes(id)) ids.push(id); }
|
|
5587
6090
|
return ids;
|
|
5588
6091
|
}
|
|
5589
|
-
// Click selection with cycle-through-overlaps: a plain click selects the nearest thing under the cursor
|
|
5590
|
-
// (incl. a derived part); clicking the SAME spot again steps to the next overlapping mesh (plate → beam …)
|
|
5591
|
-
// so a joint's stacked parts are all reachable. Ctrl+click toggles the nearest (no cycle). Drag (move/box/
|
|
5592
|
-
// endpoint) never routes here, so member drag/edit is unchanged.
|
|
5593
|
-
let cycleAnchor = null, cycleIds = [], cycleIdx = 0;
|
|
5594
6092
|
const CYCLE_TOL_PX = 8;
|
|
5595
|
-
function resetCycle() { cycleAnchor = null; cycleIds = []; cycleIdx = 0; }
|
|
5596
|
-
function clickSelect(cx, cy, ctrl) {
|
|
5597
|
-
let hits = []; try { hits = pickAllAt(cx, cy); } catch { hits = []; }
|
|
5598
|
-
selectionTrace={phase:'up-pick',x:cx,y:cy,ownHits:hits.slice(0,4)};
|
|
5599
|
-
if (hits.length) selectReference(null); // anything of OURS under the cursor drops a reference selection
|
|
5600
|
-
if (!hits.length) {
|
|
5601
|
-
// Nothing of ours here — only NOW may a reference answer. Consulted second, never first, so a
|
|
5602
|
-
// reference standing in front of a beam can never steal the beam's click; that is how "native
|
|
5603
|
-
// selection behaviour is unchanged" is earned structurally rather than tested for and hoped.
|
|
5604
|
-
// A plain click selects the WHOLE reference — it is one borrowed thing. Ctrl DRILLS INTO the one
|
|
5605
|
-
// object under the pointer, which is the same gesture this editor already uses to reach a part
|
|
5606
|
-
// stacked inside a connection, and it is free here: the modifier's other meaning (additive select)
|
|
5607
|
-
// belongs to the branch above, which this arm is only ever reached instead of.
|
|
5608
|
-
let ref = null; try { ref = pickReferenceAt(cx, cy); } catch { ref = null; }
|
|
5609
|
-
selectionTrace={...selectionTrace,reference:ref,referenceAllowed:!api||!api.canSelectReference||api.canSelectReference()};
|
|
5610
|
-
if (ref) {
|
|
5611
|
-
// A filtered class is inert: hitting it must not be reinterpreted as empty canvas, because that
|
|
5612
|
-
// would clear the selection the user already has. Selection filtering and visibility remain
|
|
5613
|
-
// independent, just as they are for native members.
|
|
5614
|
-
if (api && api.canSelectReference && !api.canSelectReference()) return;
|
|
5615
|
-
resetCycle();
|
|
5616
|
-
// The drill FALLS BACK to selecting the whole reference when the object cannot be addressed
|
|
5617
|
-
// (`objectIndex` -1 from a mesh built before this existed). Refusing outright would make Ctrl+click
|
|
5618
|
-
// do nothing at all on such a reference, which reads as a broken control rather than an older one.
|
|
5619
|
-
if (!(ctrl && selectReferenceObject(ref.referenceId, ref.objectIndex))) selectReference(ref.referenceId);
|
|
5620
|
-
return;
|
|
5621
|
-
}
|
|
5622
|
-
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)
|
|
5623
|
-
}
|
|
5624
|
-
if (ctrl) { resetCycle(); resetConnState(); if (api && api.onSelect) api.onSelect(hits[0], true); return; } // additive toggles the nearest RAW part (leaves connection mode)
|
|
5625
|
-
const same = cycleAnchor && Math.hypot(cx - cycleAnchor[0], cy - cycleAnchor[1]) <= CYCLE_TOL_PX
|
|
5626
|
-
&& cycleIds.length === hits.length && cycleIds.every((v, i) => v === hits[i]);
|
|
5627
|
-
if (same) cycleIdx = (cycleIdx + 1) % hits.length; else { cycleIds = hits; cycleIdx = 0; cycleAnchor = [cx, cy]; }
|
|
5628
|
-
const pick = hits[cycleIdx], conn = connOf(pick);
|
|
5629
|
-
if (!conn) { resetConnState(); if (api && api.onSelect) api.onSelect(pick, false); return; } // a bare member → normal single select
|
|
5630
|
-
if (ctxConn === conn) { // drilled INTO this connection → clicks land on its parts (bolt array or a single part)
|
|
5631
|
-
const grp = boltGroupOf(pick);
|
|
5632
|
-
if (grp.length > 1) { if (api && api.onSelectMany) api.onSelectMany(grp); } else if (api && api.onSelect) api.onSelect(pick, false);
|
|
5633
|
-
return;
|
|
5634
|
-
}
|
|
5635
|
-
selectWholeConn(conn); // at root (or over a different connection) → select the WHOLE connection
|
|
5636
|
-
}
|
|
5637
6093
|
// A bolt/head/nut id → all bolt-group part ids of the same joint (the connection's bolt array); else just [id].
|
|
5638
6094
|
function boltGroupOf(id) {
|
|
5639
6095
|
const ci = id.indexOf(':'); if (ci < 0) return [id];
|
|
@@ -5927,7 +6383,7 @@ function frameInfo() {
|
|
|
5927
6383
|
}
|
|
5928
6384
|
return { mode: 'global' };
|
|
5929
6385
|
}
|
|
5930
|
-
function fireFrameChange() { invalidatePointEntry('drift'); if (!(pending && pending.frameDrag)) { tfCandidates = null; dimCandidates3d = null; } renderWorkPlane(); reflectDimAxisBar(); updateStatusChip(); } // re-draws the gizmo + reference plane + fires the Axes chip; relabels the dim-axis bar (X′/Y′/Elev follows the frame); invalidates the typed HUD (drift) + the snap caches so the UCS-origin snap follows the frame — but NOT during a live origin drag (the drag's own snap cache, which excludes the origin, stays efficient). renderWorkPlane now re-syncs BOTH gizmos (arming/disarming the frame flips the position gizmo's visibility; the position gizmo hides the frame gizmo), so both react in one tick.
|
|
6386
|
+
function fireFrameChange() { syncSpatialFrames(); invalidatePointEntry('drift'); if (!(pending && pending.frameDrag)) { tfCandidates = null; dimCandidates3d = null; } renderWorkPlane(); reflectDimAxisBar(); updateStatusChip(); } // re-draws the gizmo + reference plane + fires the Axes chip; relabels the dim-axis bar (X′/Y′/Elev follows the frame); invalidates the typed HUD (drift) + the snap caches so the UCS-origin snap follows the frame — but NOT during a live origin drag (the drag's own snap cache, which excludes the origin, stays efficient). renderWorkPlane now re-syncs BOTH gizmos (arming/disarming the frame flips the position gizmo's visibility; the position gizmo hides the frame gizmo), so both react in one tick.
|
|
5931
6387
|
// Set a HORIZONTAL frame at origin (numeric entry + gizmo materialize). origin defaults its Z to the active level.
|
|
5932
6388
|
function setFrame3d(originMm, angleDeg) {
|
|
5933
6389
|
const z = (originMm && originMm.length > 2) ? originMm[2] : frameZ();
|
|
@@ -5948,7 +6404,7 @@ function armFrame3d(on) {
|
|
|
5948
6404
|
frameMode = on == null ? !frameMode : !!on;
|
|
5949
6405
|
if (frameMode) { dropGridLinePick3d(); dropRefMeasure3d(); }
|
|
5950
6406
|
if (frameMode) {
|
|
5951
|
-
if (dimMode3d)
|
|
6407
|
+
if (dimMode3d) disarmMeasureTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); if (wpMode) { wpMode = null; wpDraft = null; reflectWpBar(); } setClipMode(null); setInsertMode(false); // arming the frame disarms EVERY other left-click 3D tool (incl. clip + insert)
|
|
5952
6408
|
framePickPts = frame3d ? null : []; // no frame yet → start the 3-click pick; an existing frame → straight to drag-refine (re-pick from the panel)
|
|
5953
6409
|
disposeFramePreview();
|
|
5954
6410
|
} else cancelFramePick();
|
|
@@ -6212,7 +6668,6 @@ function buildPositionGizmo(st, opts) {
|
|
|
6212
6668
|
const g = new THREE.Group();
|
|
6213
6669
|
const V = (a) => new THREE.Vector3(a[0], a[1], a[2]);
|
|
6214
6670
|
const P = posProfileAxes(st);
|
|
6215
|
-
const yv = V(P.y), zv = V(P.z);
|
|
6216
6671
|
const mat = (tag, col, extra) => {
|
|
6217
6672
|
const s = posHandleStyle(tag, col);
|
|
6218
6673
|
return new THREE.LineBasicMaterial({ color: s.color, transparent: true, opacity: s.opacity, depthTest: false, ...(extra || {}) });
|
|
@@ -6627,7 +7082,7 @@ function startPositionGizmoDrag(kind, e) {
|
|
|
6627
7082
|
// degeneracy cone exactly, so it can neither enter nor leave it and needs no barrier at all.
|
|
6628
7083
|
const barriers = kind === 'swingElev' ? swingBarriers(st.anchor, st.end, st.yAxis, st.up, POS_SWING_MARGIN_RAD) : null;
|
|
6629
7084
|
if (swinging && (!basis || (kind === 'swingElev' && !barriers))) {
|
|
6630
|
-
const why = 'This member can’t be swung from its current direction — set its geometry in the
|
|
7085
|
+
const why = 'This member can’t be swung from its current direction — set its geometry in the Properties panel.';
|
|
6631
7086
|
console.warn('steel-3d: reference-line swing refused — no usable', basis ? 'plumb barrier' : 'swing plane');
|
|
6632
7087
|
positionGizmoReadout(e, why, '');
|
|
6633
7088
|
pending = null; if (controls) controls.enabled = true; return;
|
|
@@ -6670,7 +7125,7 @@ function onMovePositionGizmo(e) {
|
|
|
6670
7125
|
const pg = pending.posGizmo, st = pg.state, mesh = meshById.get(pg.id);
|
|
6671
7126
|
if (pg.refline) { onMoveRefLineGizmo(e, pg, st, mesh); return; }
|
|
6672
7127
|
const ang = posGizmoArcAngle(e, st);
|
|
6673
|
-
if (ang == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in
|
|
7128
|
+
if (ang == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in the Properties panel', ''); return; }
|
|
6674
7129
|
if (pg.startScalar == null) { pg.startScalar = ang; pg.prevAng = ang; return; } // grab was edge-on → set the reference on the first valid hit
|
|
6675
7130
|
if (pg.prevAng == null) pg.prevAng = ang;
|
|
6676
7131
|
// Accumulate the arc CONTINUOUSLY (shortest-arc step per move) so dragging across the ±180° seam adds a
|
|
@@ -6716,11 +7171,11 @@ function onMoveRefLineGizmo(e, pg, st, mesh) {
|
|
|
6716
7171
|
if (trans && pg.axis !== 'slide') {
|
|
6717
7172
|
const tip = pg.axis === 'depth' ? scr && scr.depthTip : scr && scr.widthTip;
|
|
6718
7173
|
if (scr && tip && !tip.behind && Math.hypot(tip.x - scr.anchor.x, tip.y - scr.anchor.y) < posEdgeOnPx(_posAnchorV.set(st.anchor[0], st.anchor[1], st.anchor[2]), st)) {
|
|
6719
|
-
positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in
|
|
7174
|
+
positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in the Properties panel', ''); return;
|
|
6720
7175
|
}
|
|
6721
7176
|
} else if (scr && scr.anchor && scr.slideTip && !scr.slideTip.behind
|
|
6722
7177
|
&& Math.hypot(scr.slideTip.x - scr.anchor.x, scr.slideTip.y - scr.anchor.y) < posEdgeOnPx(_posAnchorV.set(st.anchor[0], st.anchor[1], st.anchor[2]), st)) {
|
|
6723
|
-
positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in
|
|
7178
|
+
positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in the Properties panel', ''); return;
|
|
6724
7179
|
}
|
|
6725
7180
|
if (trans) {
|
|
6726
7181
|
// `ax` is used raw here while the commit normalises inside translateEndpoints. Safe because every
|
|
@@ -6728,7 +7183,7 @@ function onMoveRefLineGizmo(e, pg, st, mesh) {
|
|
|
6728
7183
|
// which steel-3d-core's own test pins — so preview and commit cannot diverge.
|
|
6729
7184
|
const ax = pg.transAxis || posTranslateAxis(st, pg.axis);
|
|
6730
7185
|
const s = posGizmoAxisScalar(e, st, ax);
|
|
6731
|
-
if (s == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in
|
|
7186
|
+
if (s == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in the Properties panel', ''); return; }
|
|
6732
7187
|
if (pg.startScalar == null) { pg.startScalar = s; return; } // grab was edge-on → set the reference on the first valid hit
|
|
6733
7188
|
const raw = s - pg.startScalar;
|
|
6734
7189
|
const delta = e.shiftKey ? raw : snapToStep(raw, POS_SNAP_MM);
|
|
@@ -6746,7 +7201,7 @@ function onMoveRefLineGizmo(e, pg, st, mesh) {
|
|
|
6746
7201
|
}
|
|
6747
7202
|
// --- swing: rotate the member DIRECTION about the frozen axis, moving only the far work point.
|
|
6748
7203
|
const ang = posSwingAngle(e, st, pg.swingAxis, pg.basis);
|
|
6749
|
-
if (ang == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in
|
|
7204
|
+
if (ang == null) { positionGizmoReadout(e, 'View is edge-on — orbit, or set the value in the Properties panel', ''); return; }
|
|
6750
7205
|
if (pg.startScalar == null) { pg.startScalar = ang; pg.prevAng = ang; return; }
|
|
6751
7206
|
if (pg.prevAng == null) pg.prevAng = ang;
|
|
6752
7207
|
// Accumulate CONTINUOUSLY, as the shipped roll arc does, so crossing the ±180° seam adds an increment
|
|
@@ -6961,20 +7416,84 @@ function renderWorkPlane() {
|
|
|
6961
7416
|
g.position.set(O[0], O[1], O[2]);
|
|
6962
7417
|
wpGroup = g; scene.add(g); // on `scene` (like epGroup) so rebuild() never wipes it; not in meshById → picking ignores it
|
|
6963
7418
|
}
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
7419
|
+
/**
|
|
7420
|
+
* A stored `workPlane.kind` → the attribute value the menu button carrying that choice is tagged with.
|
|
7421
|
+
*
|
|
7422
|
+
* THE TWO ARE NOT THE SAME STRING, which is the whole reason this map exists rather than a direct
|
|
7423
|
+
* comparison: "Pick 3 points…" is `data-wp=3pt` while the kind it stores is `p3`. Stated over the map's
|
|
7424
|
+
* VALUES, so that the one divergent entry is not hidden in a list of look-alikes: `face`/`3pt` live on
|
|
7425
|
+
* `data-wp` and `xy`/`xz`/`yz` on `data-wpp`, and no value appears in both attributes, so one lookup
|
|
7426
|
+
* can drive both rows. `reset` is deliberately absent — "Reset to level" records no kind (it sets
|
|
7427
|
+
* `workPlane` back to null), so it can never match and must never read as the active choice.
|
|
7428
|
+
*/
|
|
7429
|
+
const WP_KIND_ATTR = { face: 'face', p3: '3pt', xy: 'xy', xz: 'xz', yz: 'yz' };
|
|
7430
|
+
/**
|
|
7431
|
+
* Mark which Plane-menu option produced the plane that is currently set, the way the Camera and Display
|
|
7432
|
+
* menus mark theirs — without it the menu looks identical whichever plane is active (#1396).
|
|
7433
|
+
*
|
|
7434
|
+
* NOTHING is marked while a pick is ARMED: `wpMode` means the user is mid-face/3-point pick and the
|
|
7435
|
+
* plane it will produce does not exist yet, so marking the option it came from would claim a plane that
|
|
7436
|
+
* is not set. Nothing is marked with no plane either, which is the initial state the markup ships.
|
|
7437
|
+
*
|
|
7438
|
+
* A MISSING MENU IS A DELIBERATE NO-OP, not an oversight worth a warning: `vector-3d.html` loads this
|
|
7439
|
+
* same module and has no `#m3dWpMenu` at all, so anything logged here would fire on that page on every
|
|
7440
|
+
* call. The empty node list is the whole guard.
|
|
7441
|
+
*/
|
|
7442
|
+
function reflectWpMenu() {
|
|
7443
|
+
// `Object.hasOwn`, not a bare lookup: `WP_KIND_ATTR['constructor']` inherits a truthy FUNCTION from
|
|
7444
|
+
// Object.prototype. No prototype value is a string so nothing could ever match, but "truthy `want`
|
|
7445
|
+
// that marks nothing" is a worse failure to debug than "no such kind", and own-key is the real question.
|
|
7446
|
+
const want = (!wpMode && workPlane && Object.hasOwn(WP_KIND_ATTR, workPlane.kind)) ? WP_KIND_ATTR[workPlane.kind] : '';
|
|
7447
|
+
// SELECTED BY ROLE, not by `[data-wp], [data-wpp]`. "Reset to level" carries a `data-wp` of its own, so
|
|
7448
|
+
// the attribute selector swept it up and wrote `aria-checked=false` onto it — an attribute no role a
|
|
7449
|
+
// plain `<button>` has supports, and a direct contradiction of the markup's own comment. The role names
|
|
7450
|
+
// the five mutually-exclusive plane-kind options and nothing else in this menu; what holds that set to
|
|
7451
|
+
// five (rather than silently growing if a sixth button ever takes the role) is the `seen` assertion in
|
|
7452
|
+
// `server/wp-menu-active-mark.test.ts`, not this selector. (Design review.)
|
|
7453
|
+
document.querySelectorAll('#m3dWpMenu button[role=menuitemradio]').forEach((b) => {
|
|
7454
|
+
const on = !!want && (b.getAttribute('data-wp') === want || b.getAttribute('data-wpp') === want);
|
|
7455
|
+
b.classList.toggle('on', on);
|
|
7456
|
+
b.setAttribute('aria-checked', String(on)); // role=menuitemradio → aria-checked is the state a screen reader reads, and the class alone would leave it saying nothing
|
|
7457
|
+
});
|
|
7458
|
+
}
|
|
7459
|
+
// Armed set-plane hover. All three points of a 3-point pick snap (origin, X point, Y side), so the reticle
|
|
7460
|
+
// follows the cursor on every step. It used to move only before the first point, which left points 2 and 3
|
|
7461
|
+
// with no snap feedback at all: the click still counted, but it read as "the second point cannot be picked".
|
|
7462
|
+
function wpPickHover() {
|
|
7463
|
+
canvasEl.style.cursor = 'crosshair';
|
|
7464
|
+
if (wpMode === '3pt') { const r = dimPointAt({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt });
|
|
7465
|
+
if (r) showMarker(r.p, r.type); else marker.visible = false; } // no point here → no reticle (a click here does nothing)
|
|
7466
|
+
}
|
|
7467
|
+
// kind → [corner code, name]. The code is at most 2 characters because it is drawn as the corner badge of a
|
|
7468
|
+
// 30px icon button (#1395); the name goes to the hidden label and the tooltip.
|
|
7469
|
+
const WP_KIND_LABEL = { face: ['FE', 'Face'], p3: ['3P', '3 points'], xy: ['XY', 'XY'], xz: ['XZ', 'XZ'], yz: ['YZ', 'YZ'] };
|
|
7470
|
+
// The icon stays. State goes into the badge, the hidden label and the tooltip, never `b.textContent`, which
|
|
7471
|
+
// wiped the icon and wrapped "◇ Plane: XY ▾" inside the 30px square (#1395). Same idiom as Clip: brand wash
|
|
7472
|
+
// only while armed (a click cancels), cyan code while the button holds a plane.
|
|
7473
|
+
function reflectWpBar() { const b = document.getElementById('m3dWp'); if (b) {
|
|
7474
|
+
const lbl = !wpMode && workPlane && Object.hasOwn(WP_KIND_LABEL, workPlane.kind) ? WP_KIND_LABEL[workPlane.kind] : null; // armed: the new plane does not exist yet, so no code (the menu mark's rule too)
|
|
7475
|
+
b.classList.toggle('on', !!wpMode);
|
|
7476
|
+
b.toggleAttribute('data-cancels-pick', !!wpMode); // armed: a click cancels the pick, so the Instructor must not click it to open the menu (#1199)
|
|
7477
|
+
if (lbl) b.setAttribute('data-state-code', lbl[0]); else b.removeAttribute('data-state-code');
|
|
7478
|
+
b.toggleAttribute('data-state-on', !wpMode && !lbl && wpVisible); // "Show plane" on at level: no code to show, so the dot says something is on (#1403)
|
|
7479
|
+
if (b.dataset.tipIdle === undefined) b.dataset.tipIdle = b.dataset.tip; // the markup's own tip, restored when the plane is cleared
|
|
7480
|
+
const rl = b.querySelector('.rlbl'); if (rl) rl.textContent = wpMode ? 'Cancel plane pick' : (lbl ? 'Plane: ' + lbl[1] : 'Plane');
|
|
7481
|
+
b.dataset.tip = wpMode ? 'Setting the working plane — click to cancel' : (lbl ? 'Working plane: ' + lbl[1] + ' — every 3D pick lands on it. Click to change or reset it.' : b.dataset.tipIdle);
|
|
7482
|
+
} reflectDimAxisBar(); reflectWpMenu(); } // relabel the dim-axis bar (a set/cleared plane flips X/Y between World and local); mark the active option INSIDE the menu too (#1396) — LAST and OUTSIDE the `if (b)`, so it runs with no toolbar button present and so a throw in the menu marking cannot stop the dim-axis reflector before it
|
|
7483
|
+
function armWorkPlanePick(mode) { abandonConnPick('other-tool'); if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; dropGridLinePick3d(); dropRefMeasure3d(); if (dimMode3d) disarmMeasureTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } marker.visible = false; canvasEl.style.cursor = wpMode ? 'crosshair' : 'default'; reflectWpBar(); updateStatusChip(); viewportReports?.reportSectionState(); } // a set-plane pick shares the left-click — disarm Move/Copy + Add + the local frame (their onDown routes run first)
|
|
6968
7484
|
function setWorkPlanePrincipal(kind, offsetMm) {
|
|
6969
7485
|
const off = offsetMm || 0;
|
|
6970
7486
|
const def = { xy: { normal: [0, 0, 1], xAxis: [1, 0, 0] }, xz: { normal: [0, 1, 0], xAxis: [1, 0, 0] }, yz: { normal: [1, 0, 0], xAxis: [0, 1, 0] } }[kind];
|
|
6971
7487
|
if (!def) return;
|
|
6972
7488
|
workPlane = { origin: def.normal.map((c) => c * off), normal: def.normal, xAxis: def.xAxis, kind };
|
|
6973
|
-
wpMode = null; wpDraft = null; invalidatePointEntry('drift'); renderWorkPlane(); reflectWpBar(); updateStatusChip();
|
|
6974
|
-
}
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
-
function
|
|
7489
|
+
wpMode = null; wpDraft = null; syncSpatialFrames(); invalidatePointEntry('drift'); renderWorkPlane(); reflectWpBar(); updateStatusChip(); viewportReports?.reportSectionState();
|
|
7490
|
+
}
|
|
7491
|
+
// The principal plane Enter in the offset box applies: the XZ/YZ plane already set, so a new offset moves
|
|
7492
|
+
// THAT plane. XY when no plane is set, or when it came from a face or 3 points (no principal offset).
|
|
7493
|
+
function wpOffsetKind() { return workPlane && (workPlane.kind === 'xz' || workPlane.kind === 'yz') ? workPlane.kind : 'xy'; }
|
|
7494
|
+
function clearWorkPlane() { workPlane = null; wpMode = null; wpDraft = null; syncSpatialFrames(); invalidatePointEntry('drift'); renderWorkPlane(); reflectWpBar(); updateStatusChip(); viewportReports?.reportSectionState(); }
|
|
7495
|
+
function toggleWorkPlaneVisible(on) { wpVisible = on === undefined ? !wpVisible : !!on; try { localStorage.setItem('steel:wpVisible:v2', wpVisible ? '1' : '0'); } catch { /* storage can be unavailable; keep the session preference */ } syncSpatialFrames(); renderWorkPlane(); viewportReports?.reportSectionState(); reflectWpBar(); }
|
|
7496
|
+
function workPlaneInfo() { return { set: !!workPlane, mode: wpMode, visible: wpVisible, plane: workPlane ? { origin: [...workPlane.origin], normal: [...workPlane.normal], xAxis: [...workPlane.xAxis], kind: workPlane.kind } : null }; }
|
|
6978
7497
|
/**
|
|
6979
7498
|
* face pick: the same face → plane conversion the clip tool does, over the same `faceHitAt`, with the
|
|
6980
7499
|
* opposite normal convention — the plane lands ON the face, facing you.
|
|
@@ -7071,15 +7590,129 @@ function gridSnapCand(p) {
|
|
|
7071
7590
|
return node ? [{ type: 'origin-grid', p: node, fromId: 'ucs-grid' }] : [];
|
|
7072
7591
|
}
|
|
7073
7592
|
|
|
7593
|
+
const CONTEXTUAL_SNAP_PREF = Object.freeze({ perpendicular: 'perp', parallel: 'par', extension: 'ext' });
|
|
7594
|
+
const SHARED_SNAP_KINDS = Object.freeze(['semantic-intersection', 'free-point']);
|
|
7595
|
+
function contextualSnapEnabled(kind, anchor) {
|
|
7596
|
+
if ((kind === 'perpendicular' || kind === 'parallel') && !anchor) return false;
|
|
7597
|
+
if (snapOnly3d === 'none') return false;
|
|
7598
|
+
if (snapOnly3d) return snapOnly3d === kind;
|
|
7599
|
+
return api?.snapEnabled?.()?.[CONTEXTUAL_SNAP_PREF[kind]] === true;
|
|
7600
|
+
}
|
|
7601
|
+
function sharedSnapFrame() {
|
|
7602
|
+
const f = spatialTools?.activeFrame?.();
|
|
7603
|
+
return f ? { schemaVersion: 'floless.model-frame/v1', frameId: f.id, originMm: [...f.origin],
|
|
7604
|
+
xAxis: [...f.xAxis], yAxis: [...f.yAxis], zAxis: [...f.zAxis] }
|
|
7605
|
+
: { schemaVersion: 'floless.model-frame/v1', frameId: 'global', originMm: [0, 0, 0],
|
|
7606
|
+
xAxis: [1, 0, 0], yAxis: [0, 1, 0], zAxis: [0, 0, 1] };
|
|
7607
|
+
}
|
|
7608
|
+
function sharedSnapGeneration() {
|
|
7609
|
+
return { projectUuid: 'steel-session', authority: 'steel', revisionId: 'live',
|
|
7610
|
+
sourceDigest: '0'.repeat(64), epoch: spatialTools?.state?.().revision ?? 0 };
|
|
7611
|
+
}
|
|
7612
|
+
function sharedSnapCameraPort() {
|
|
7613
|
+
return {
|
|
7614
|
+
rayForCss(pointer) {
|
|
7615
|
+
if (!canvasEl || !camera || !Array.isArray(pointer)) return null;
|
|
7616
|
+
const rect = canvasEl.getBoundingClientRect(); if (!rect.width || !rect.height) return null;
|
|
7617
|
+
camera.updateMatrixWorld();
|
|
7618
|
+
const ndc = new THREE.Vector2((pointer[0] / rect.width) * 2 - 1, -(pointer[1] / rect.height) * 2 + 1);
|
|
7619
|
+
const probe = new THREE.Raycaster(); probe.setFromCamera(ndc, camera);
|
|
7620
|
+
return { originMm: probe.ray.origin.toArray(), direction: probe.ray.direction.toArray() };
|
|
7621
|
+
},
|
|
7622
|
+
projectPoint(point) {
|
|
7623
|
+
if (!canvasEl || !camera || !Array.isArray(point)) return null;
|
|
7624
|
+
const rect = canvasEl.getBoundingClientRect();
|
|
7625
|
+
const p = new THREE.Vector3(...point).project(camera);
|
|
7626
|
+
return { x: (p.x * 0.5 + 0.5) * rect.width, y: (-p.y * 0.5 + 0.5) * rect.height,
|
|
7627
|
+
visible: p.z >= -1 && p.z <= 1 && p.x >= -1 && p.x <= 1 && p.y >= -1 && p.y <= 1 };
|
|
7628
|
+
},
|
|
7629
|
+
isOccluded: (point) => isPointClipped(point),
|
|
7630
|
+
};
|
|
7631
|
+
}
|
|
7632
|
+
function sharedSnapQuery(e, mode, anchor) {
|
|
7633
|
+
const rect = canvasEl.getBoundingClientRect(); const cameraPort = sharedSnapCameraPort();
|
|
7634
|
+
const pointerCssPx = [e.clientX - rect.left, e.clientY - rect.top];
|
|
7635
|
+
return { cameraPort, query: { schemaVersion: 'floless.model-snap-query/v1', generation: sharedSnapGeneration(),
|
|
7636
|
+
pointerCssPx, viewportCssPx: [Math.max(1, rect.width), Math.max(1, rect.height)], raySource: 'camera-port',
|
|
7637
|
+
ray: cameraPort.rayForCss(pointerCssPx), enabledKinds: [...SHARED_SNAP_KINDS], mode,
|
|
7638
|
+
...(anchor ? { firstAnchor: { pointMm: [...anchor] } } : {}), activeFrame: sharedSnapFrame() } };
|
|
7639
|
+
}
|
|
7640
|
+
function contextualSegment(candidate, dragged) {
|
|
7641
|
+
if (!candidate?.a || !candidate?.b) return null;
|
|
7642
|
+
const z = dragged?.[2] ?? 0;
|
|
7643
|
+
const a = candidate.type === 'grid-line' ? [candidate.a[0], candidate.a[1], z] : [...candidate.a];
|
|
7644
|
+
const b = candidate.type === 'grid-line' ? [candidate.b[0], candidate.b[1], z] : [...candidate.b];
|
|
7645
|
+
return Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]) > 1e-9
|
|
7646
|
+
? { type: 'segment', startMm: a, endMm: b } : null;
|
|
7647
|
+
}
|
|
7648
|
+
function contextualTargets(candidates, dragged, e) {
|
|
7649
|
+
const pt = [e.clientX - canvasEl.getBoundingClientRect().left, e.clientY - canvasEl.getBoundingClientRect().top];
|
|
7650
|
+
const distance = (segment) => {
|
|
7651
|
+
const a = toScreen(segment.startMm), b = toScreen(segment.endMm);
|
|
7652
|
+
return projectPointOnSegment2d(pt, [a.x, a.y], [b.x, b.y], SEG_DEGENERACY.atMost(1e-9)).distance;
|
|
7653
|
+
};
|
|
7654
|
+
return (candidates || []).filter((c) => c.type === 'centerline' || c.type === 'grid-line')
|
|
7655
|
+
.map((source) => ({ source, target: contextualSegment(source, dragged) })).filter((item) => item.target)
|
|
7656
|
+
.sort((left, right) => distance(left.target) - distance(right.target) || String(left.source.fromId).localeCompare(String(right.source.fromId)))
|
|
7657
|
+
.slice(0, 256);
|
|
7658
|
+
}
|
|
7659
|
+
function solveSharedContextualSnap(e, anchor, candidates, dragged, mode = '3d') {
|
|
7660
|
+
const enabled = ['perpendicular', 'parallel', 'extension'].filter((kind) => contextualSnapEnabled(kind, anchor));
|
|
7661
|
+
if (!enabled.length) return null;
|
|
7662
|
+
const { query, cameraPort } = sharedSnapQuery(e, mode, anchor);
|
|
7663
|
+
const wp = mode === 'work-plane' ? effectiveWP() : null;
|
|
7664
|
+
const workPlaneReceipt = wp ? { type: 'plane', originMm: [...wp.origin], normal: _unit3(wp.normal) } : null;
|
|
7665
|
+
let best = null;
|
|
7666
|
+
for (const { target } of contextualTargets(candidates, dragged, e)) for (const solverKind of enabled) {
|
|
7667
|
+
const result = solveModelSnapConstraint({ schemaVersion: 'floless.model-snap-constraint/v1', query,
|
|
7668
|
+
solverKind, firstAnchorMm: [...(anchor || dragged)], target, activeFrame: query.activeFrame,
|
|
7669
|
+
workPlane: workPlaneReceipt, extentPolicy: solverKind === 'perpendicular' && !contextualSnapEnabled('extension', anchor) ? 'finite' : 'infinite' }, cameraPort);
|
|
7670
|
+
if (result.status === 'acquired' && (!best || result.distanceCssPx < best.distanceCssPx)) best = { ...result, type: solverKind };
|
|
7671
|
+
}
|
|
7672
|
+
return best;
|
|
7673
|
+
}
|
|
7674
|
+
function sharedIntersectionPair(candidate, candidates, dragged) {
|
|
7675
|
+
const ids = Array.isArray(candidate?.fromIds) ? candidate.fromIds
|
|
7676
|
+
: String(candidate?.fromId || '').startsWith('grid-') ? String(candidate.fromId).slice(5).split('/').map((id) => `grid-${id}`) : [];
|
|
7677
|
+
if (ids.length !== 2) return null;
|
|
7678
|
+
const lines = ids.map((id) => candidates.find((item) => (item.type === 'centerline' || item.type === 'grid-line') && item.fromId === id));
|
|
7679
|
+
const targets = lines.map((line) => contextualSegment(line, dragged));
|
|
7680
|
+
return targets.every(Boolean) ? targets : null;
|
|
7681
|
+
}
|
|
7682
|
+
function solveSharedIntersectionSnap(e, candidate, candidates, dragged, mode = '3d') {
|
|
7683
|
+
const pair = sharedIntersectionPair(candidate, candidates, dragged); if (!pair) return null;
|
|
7684
|
+
const { query, cameraPort } = sharedSnapQuery(e, mode, null);
|
|
7685
|
+
const wp = mode === 'work-plane' ? effectiveWP() : null;
|
|
7686
|
+
const result = solveModelSnapIntersection({ query, left: pair[0], right: pair[1],
|
|
7687
|
+
workPlane: wp ? { type: 'plane', originMm: [...wp.origin], normal: _unit3(wp.normal) } : null,
|
|
7688
|
+
extentPolicy: 'finite' }, cameraPort);
|
|
7689
|
+
return result.status === 'acquired' ? { ...result, type: 'intersection' } : null;
|
|
7690
|
+
}
|
|
7691
|
+
|
|
7692
|
+
function resolveSteelSnap(e, anchor, candidates, dragged, mode = '3d', targetCandidates = candidates) {
|
|
7693
|
+
const ordinary = snapPoint(dragged, candidates, toScreen, SNAP_TOL_PX);
|
|
7694
|
+
let ordinaryResult = ordinary.candidate ? { p: ordinary.snapped, snap: true, type: ordinary.candidate.type, candidate: ordinary.candidate } : null;
|
|
7695
|
+
if (ordinaryResult && (ordinaryResult.type === 'intersection' || ordinaryResult.type === 'grid-int')) {
|
|
7696
|
+
const shared = solveSharedIntersectionSnap(e, ordinaryResult.candidate, targetCandidates, ordinaryResult.p, mode);
|
|
7697
|
+
ordinaryResult = shared ? { p: [...shared.pointMm], snap: true, type: 'intersection', guides: shared.guides } : null;
|
|
7698
|
+
}
|
|
7699
|
+
const contextual = solveSharedContextualSnap(e, anchor, targetCandidates, dragged, mode);
|
|
7700
|
+
const hardPoint = ordinaryResult && ['vertex', 'intersection', 'grid-int', 'midpoint', 'origin', 'origin-grid'].includes(ordinaryResult.type);
|
|
7701
|
+
if (contextual && !hardPoint) return { p: [...contextual.pointMm], snap: true, type: contextual.type, guides: contextual.guides };
|
|
7702
|
+
return ordinaryResult || { p: dragged, snap: false, type: null };
|
|
7703
|
+
}
|
|
7704
|
+
|
|
7074
7705
|
// snapped pick projected onto the working plane (Tekla: snaps win, then land on the plane)
|
|
7075
|
-
function wpPointAt(e) {
|
|
7706
|
+
function wpPointAt(e, anchor = null) {
|
|
7076
7707
|
const wp = effectiveWP();
|
|
7077
7708
|
const hit = rayToWP(e.clientX, e.clientY, wp); if (!hit) return null;
|
|
7709
|
+
clearSharedSnapGuides();
|
|
7078
7710
|
if (!e.altKey) {
|
|
7079
7711
|
if (!tfCandidates) tfCandidates = allCandidates(null); // members + grid, so Move/Copy + draw-on-plane snap to the grid too
|
|
7080
|
-
const
|
|
7081
|
-
const
|
|
7082
|
-
|
|
7712
|
+
const geometric = tfCandidates.filter((c) => candOnActiveWP(c, hit, wp));
|
|
7713
|
+
const cands = geometric.filter((c) => candAllowed3d(c.type)).concat(gridSnapCand(hit)); // running-snaps / override, then (3D toggle off) the working-plane constraint; opt-in origin grid rides on top (its own precedence)
|
|
7714
|
+
const r = resolveSteelSnap(e, anchor, cands, hit, 'work-plane', geometric);
|
|
7715
|
+
if (r.snap) { renderSharedSnapGuides(r.guides, r.p); return r; } // land on the TRUE 3D snap (member end / grid) when the SNAP-bar 3D toggle is ON — free to the whole model, same as global (Pawel D5); OFF constrains to the working plane above; a free (non-snapped) click still rides the plane below
|
|
7083
7716
|
}
|
|
7084
7717
|
return { p: hit, snap: false, type: null };
|
|
7085
7718
|
}
|
|
@@ -7149,7 +7782,7 @@ function cmEffAxis(e, base, opts) {
|
|
|
7149
7782
|
function cmDestPointFrom(e, base) {
|
|
7150
7783
|
const ax = cmEffAxis(e, base);
|
|
7151
7784
|
if (ax) return cmAxisLock(e, frameBasis()[ax], base);
|
|
7152
|
-
const r = wpPointAt(e); if (!r) return null;
|
|
7785
|
+
const r = wpPointAt(e, base); if (!r) return null;
|
|
7153
7786
|
return { p: r.p, snap: r.snap, type: r.type };
|
|
7154
7787
|
}
|
|
7155
7788
|
function cmDestPoint(e) { return cmDestPointFrom(e, tfDraft && tfDraft.base); } // Move/Copy destination; base may be null before the base pick (cmEffAxis then returns null → free) — do NOT deref tfDraft eagerly
|
|
@@ -7355,6 +7988,9 @@ function makeReticleTexture(kind) {
|
|
|
7355
7988
|
else if (kind === 'square') dual(() => { g.beginPath(); g.rect(cx - r, cy - r, 2 * r, 2 * r); g.stroke(); }, 7, 13); // vertex/endpoint = square (CAD convention; matches the 2D endpoint marker)
|
|
7356
7989
|
else if (kind === 'hourglass') dual(() => { g.beginPath(); g.moveTo(cx - r, cy - r); g.lineTo(cx + r, cy - r); g.lineTo(cx - r, cy + r); g.lineTo(cx + r, cy + r); g.closePath(); g.stroke(); }, 6, 12); // on-line ("nearest") = hourglass/clepsydra, matches the 2D marker
|
|
7357
7990
|
else if (kind === 'plus') dual(() => { g.beginPath(); g.moveTo(cx - r, cy); g.lineTo(cx + r, cy); g.moveTo(cx, cy - r); g.lineTo(cx, cy + r); g.stroke(); }, 7, 13); // origin-grid node = upright plus (distinct from the × intersection glyph)
|
|
7991
|
+
else if (kind === 'perp') dual(() => { g.beginPath(); g.moveTo(cx - r, cy + r); g.lineTo(cx - r, cy - r); g.lineTo(cx + r, cy - r); g.stroke(); }, 7, 13);
|
|
7992
|
+
else if (kind === 'parallel') dual(() => { g.beginPath(); g.moveTo(cx - r, cy - r); g.lineTo(cx + r, cy - r); g.moveTo(cx - r, cy + r); g.lineTo(cx + r, cy + r); g.stroke(); }, 7, 13);
|
|
7993
|
+
else if (kind === 'extension') dual(() => { g.save(); g.setLineDash([9, 7]); g.beginPath(); g.rect(cx - r, cy - r, 2 * r, 2 * r); g.stroke(); g.restore(); }, 7, 13);
|
|
7358
7994
|
else { g.fillStyle = HALO; g.beginPath(); g.arc(cx, cy, 11, 0, Math.PI * 2); g.fill(); g.fillStyle = CY; g.beginPath(); g.arc(cx, cy, 8, 0, Math.PI * 2); g.fill(); } // dot (fallback)
|
|
7359
7995
|
const tex = new THREE.CanvasTexture(c); if (THREE.SRGBColorSpace) tex.colorSpace = THREE.SRGBColorSpace; tex.needsUpdate = true;
|
|
7360
7996
|
return tex;
|
|
@@ -7365,6 +8001,7 @@ function reticleFor(type) {
|
|
|
7365
8001
|
: (type === 'centerline' || type === 'grid-line') ? 'hourglass' // snap ONTO a line = "nearest"
|
|
7366
8002
|
: type === 'level' ? 'bar' // elevation level = horizontal bar
|
|
7367
8003
|
: type === 'origin-grid' ? 'plus' // origin-relative grid node (UCS Stage 6)
|
|
8004
|
+
: type === 'perpendicular' ? 'perp' : type === 'parallel' ? 'parallel' : type === 'extension' ? 'extension'
|
|
7368
8005
|
: type === 'vertical-axis' ? 'vbar' : type === 'vertex' ? 'square' : 'dot';
|
|
7369
8006
|
return reticleTex[k] || (reticleTex[k] = makeReticleTexture(k));
|
|
7370
8007
|
}
|
|
@@ -7377,10 +8014,34 @@ function showMarker(p, type) {
|
|
|
7377
8014
|
marker.visible = true; lastSnapType3d = type || 'dot';
|
|
7378
8015
|
}
|
|
7379
8016
|
|
|
8017
|
+
function clearSharedSnapGuides() {
|
|
8018
|
+
if (!sharedSnapGuideGroup) return;
|
|
8019
|
+
for (const child of [...sharedSnapGuideGroup.children]) {
|
|
8020
|
+
sharedSnapGuideGroup.remove(child); child.geometry?.dispose?.(); child.material?.dispose?.();
|
|
8021
|
+
}
|
|
8022
|
+
}
|
|
8023
|
+
function renderSharedSnapGuides(guides, focusPoint) {
|
|
8024
|
+
clearSharedSnapGuides(); if (!sharedSnapGuideGroup || !Array.isArray(guides)) return;
|
|
8025
|
+
const span = Math.max(1, pxToWorldAt(460, focusPoint || controls?.target || [0, 0, 0]));
|
|
8026
|
+
for (const guide of guides) {
|
|
8027
|
+
let endpoints = null;
|
|
8028
|
+
if (guide.type === 'segment') endpoints = [guide.startMm, guide.endMm];
|
|
8029
|
+
else if (guide.type === 'line') endpoints = [
|
|
8030
|
+
guide.originMm.map((value, axis) => value - guide.direction[axis] * span),
|
|
8031
|
+
guide.originMm.map((value, axis) => value + guide.direction[axis] * span),
|
|
8032
|
+
];
|
|
8033
|
+
if (!endpoints?.every((point) => Array.isArray(point) && point.every(Number.isFinite))) continue;
|
|
8034
|
+
const line = new THREE.Line(new THREE.BufferGeometry().setFromPoints(endpoints.map((point) => new THREE.Vector3(...point))),
|
|
8035
|
+
new THREE.LineDashedMaterial({ color: 0x22d3ee, transparent: true, opacity: 0.72, dashSize: Math.max(4, span / 32), gapSize: Math.max(3, span / 48) }));
|
|
8036
|
+
line.material.depthTest = false; line.renderOrder = 995; line.computeLineDistances(); sharedSnapGuideGroup.add(line);
|
|
8037
|
+
}
|
|
8038
|
+
}
|
|
8039
|
+
|
|
7380
8040
|
// The snapped 3D point under the cursor for the dim tool. `anchor` (point 1) is set during the 2nd
|
|
7381
8041
|
// pick: with Alt held the result is locked to the anchor's plan X/Y (a pure vertical / Z measurement,
|
|
7382
8042
|
// the elevation-drag feel). Returns { p:[x,y,z], type } (type = the snap label, or null).
|
|
7383
8043
|
function dimPointAt(e, anchor) {
|
|
8044
|
+
clearSharedSnapGuides();
|
|
7384
8045
|
if (anchor && e.altKey) {
|
|
7385
8046
|
const hit = rayToVerticalPlane(e.clientX, e.clientY, anchor); if (!hit) return null;
|
|
7386
8047
|
return { p: [anchor[0], anchor[1], hit[2]], type: 'vertical' };
|
|
@@ -7398,26 +8059,45 @@ function dimPointAt(e, anchor) {
|
|
|
7398
8059
|
// floor, not the ground copy. Member candidates keep the member/scene plane; closest-on-screen wins overall.
|
|
7399
8060
|
const isGrid = (c) => c.type === 'grid-int' || c.type === 'grid-line';
|
|
7400
8061
|
const gridCands = gridLevelsMm.length ? cands.filter(isGrid) : [];
|
|
8062
|
+
const rawGridCands = gridLevelsMm.length ? dimCandidates3d.filter(isGrid) : [];
|
|
7401
8063
|
// Grid candidates belong to the level loop below and NOWHERE else. Never let them fall through to the
|
|
7402
8064
|
// member set: gridCandidates3d gates on g.on alone and ignores hidden_z, so with every Z datum hidden
|
|
7403
8065
|
// the grid draws nothing yet still emits candidates — which would snap, invisibly, on the member plane.
|
|
7404
8066
|
// What isn't drawn must not snap. (No grid at all → gridCandidates3d returns [] and this filters nothing.)
|
|
7405
8067
|
const memCands = cands.filter((c) => !isGrid(c));
|
|
7406
|
-
const best = (cset, dragged) => {
|
|
7407
|
-
if (!
|
|
7408
|
-
|
|
8068
|
+
const best = (cset, targets, dragged) => {
|
|
8069
|
+
if (!cset.length || !dragged) return null;
|
|
8070
|
+
const r = snapPoint(dragged, cset, toScreen, SNAP_TOL_PX); if (!r.candidate) return null;
|
|
8071
|
+
let p = r.snapped, type = r.candidate.type, guides = null;
|
|
8072
|
+
if (type === 'intersection' || type === 'grid-int') {
|
|
8073
|
+
const shared = solveSharedIntersectionSnap(e, r.candidate, targets, p, '3d'); if (!shared) return null;
|
|
8074
|
+
p = [...shared.pointMm]; guides = shared.guides;
|
|
8075
|
+
}
|
|
8076
|
+
const a = toScreen(dragged), b = toScreen(p); return { p, type, guides, d: Math.hypot(a.x - b.x, a.y - b.y) };
|
|
8077
|
+
};
|
|
8078
|
+
const rawMemCands = dimCandidates3d.filter((c) => !isGrid(c));
|
|
8079
|
+
const rMem = best(memCands, rawMemCands, [hit[0], hit[1], hit[2]]);
|
|
7409
8080
|
// Evaluate the grid on EVERY drawn level (each on its own plane, so the level picked is the elevation the
|
|
7410
8081
|
// point gets) and let the pure pickGridLevel rule choose — bounded intersection head start, planeZ breaking
|
|
7411
8082
|
// the Top-view tie where the levels stack on one pixel. See its doc comment in steel-3d-core for the why.
|
|
7412
8083
|
const gridHits = [];
|
|
7413
8084
|
if (gridCands.length) for (const gz of gridLevelsMm) {
|
|
7414
|
-
const r = best(gridCands, rayToPlane(e.clientX, e.clientY, gz)); // null when the view is edge-on to that level → skip it, never a NaN point
|
|
7415
|
-
if (r) gridHits.push({ z: gz, d: r.d, type: r.
|
|
8085
|
+
const r = best(gridCands, rawGridCands, rayToPlane(e.clientX, e.clientY, gz)); // null when the view is edge-on to that level → skip it, never a NaN point
|
|
8086
|
+
if (r) gridHits.push({ z: gz, d: r.d, type: r.type, r });
|
|
7416
8087
|
}
|
|
7417
8088
|
const gridWin = pickGridLevel(gridHits, planeZ);
|
|
7418
8089
|
const rGrid = gridWin ? { r: gridWin.r, d: gridWin.d } : null;
|
|
7419
8090
|
const win = rGrid && (!rMem || rGrid.d <= rMem.d) ? rGrid : rMem;
|
|
7420
|
-
|
|
8091
|
+
let ordinary = win ? { p: win.r.p, type: win.r.type, guides: win.r.guides } : null;
|
|
8092
|
+
let contextual = null;
|
|
8093
|
+
for (const dragged of [hit, ...gridLevelsMm.map((z) => rayToPlane(e.clientX, e.clientY, z)).filter(Boolean)]) {
|
|
8094
|
+
const candidate = solveSharedContextualSnap(e, anchor, dimCandidates3d, dragged, '3d');
|
|
8095
|
+
if (candidate && (!contextual || candidate.distanceCssPx < contextual.distanceCssPx)) contextual = candidate;
|
|
8096
|
+
}
|
|
8097
|
+
const hardPoint = ordinary && ['vertex', 'intersection', 'midpoint', 'origin', 'origin-grid'].includes(ordinary.type);
|
|
8098
|
+
const result = contextual && !hardPoint ? { p: [...contextual.pointMm], type: contextual.type, guides: contextual.guides }
|
|
8099
|
+
: ordinary || { p: hit, type: null, guides: null };
|
|
8100
|
+
renderSharedSnapGuides(result.guides, result.p); return result;
|
|
7421
8101
|
}
|
|
7422
8102
|
// The point under the cursor for the grid-line pick. Reuses the dimension tool's snapped pick (member + grid
|
|
7423
8103
|
// candidates, running-snaps applied) with NO anchor, so Alt never forces the dim tool's vertical branch — a grid
|
|
@@ -7467,38 +8147,46 @@ function onDown(e) {
|
|
|
7467
8147
|
if (posInteraction === 'typing') return; // the docked numeric HUD is open (camera frozen) → consume the click (start no gesture); the input blurs naturally, and its blur handler closes the HUD + toasts if anything was typed (Fable 5: explicit state, not focus)
|
|
7468
8148
|
if (e.button === 2) { rightDownXY = [e.clientX, e.clientY]; rightMoved = false; } // arm the click-vs-drag test for the snap menu
|
|
7469
8149
|
if (e.button !== 0) return; // RIGHT/MIDDLE → OrbitControls (orbit/pan)
|
|
7470
|
-
if (wpMode === 'face') { e.stopPropagation(); const r = wpFacePick(e.clientX, e.clientY); if (r) { workPlane = r; wpMode = null; invalidatePointEntry('drift'); canvasEl.style.cursor = 'default'; renderWorkPlane(); reflectWpBar(); updateStatusChip(); if (api && api.toast) api.toast('Working plane set on the face'); } return; } // armed: one face click sets the plane
|
|
8150
|
+
if (wpMode === 'face') { e.stopPropagation(); const r = wpFacePick(e.clientX, e.clientY); if (r) { workPlane = r; wpMode = null; syncSpatialFrames(); invalidatePointEntry('drift'); canvasEl.style.cursor = 'default'; renderWorkPlane(); reflectWpBar(); updateStatusChip(); viewportReports?.reportSectionState(); if (api && api.toast) api.toast('Working plane set on the face'); } return; } // armed: one face click sets the plane
|
|
7471
8151
|
if (wpMode === '3pt') { e.stopPropagation();
|
|
7472
8152
|
const r = dimPointAt(e); if (!r) return;
|
|
7473
8153
|
wpDraft = wpDraft || []; wpDraft.push(r.p);
|
|
7474
8154
|
showMarker(r.p, r.type);
|
|
7475
8155
|
if (wpDraft.length === 3) { const wp = planeFrom3Points(wpDraft[0], wpDraft[1], wpDraft[2]);
|
|
7476
8156
|
wpDraft = null; wpMode = null; marker.visible = false; canvasEl.style.cursor = 'default';
|
|
7477
|
-
if (wp) { wp.kind = 'p3'; workPlane = wp; invalidatePointEntry('drift'); renderWorkPlane(); if (api && api.toast) api.toast('Working plane set from 3 points'); }
|
|
8157
|
+
if (wp) { wp.kind = 'p3'; workPlane = wp; syncSpatialFrames(); invalidatePointEntry('drift'); renderWorkPlane(); viewportReports?.reportSectionState(); if (api && api.toast) api.toast('Working plane set from 3 points'); }
|
|
7478
8158
|
else if (api && api.toast) api.toast('Points are collinear — plane not set');
|
|
7479
|
-
reflectWpBar(); }
|
|
8159
|
+
reflectWpBar(); viewportReports?.reportSectionState(); }
|
|
7480
8160
|
updateStatusChip(); return; }
|
|
7481
8161
|
if (addActive()) { e.stopPropagation(); controls.enabled = true; drClick(e); return; } // Add-member armed (editor state) → two plane picks draw a member
|
|
7482
8162
|
if (cmActive()) { if (tfClick(e)) { e.stopPropagation(); controls.enabled = true; return; } } // Move/Copy armed (editor state) → picks land on the working plane; an empty-selection click falls through to select
|
|
7483
8163
|
if (basePickCol) { e.stopPropagation(); const r = basePickPoint(e.clientX, e.clientY); if (r) { if (api && api.onBasePick) api.onBasePick(r); setBasePickMode(null); } return; } // Mode B: commit + disarm only on a valid on-column pick; an off-column click is ignored (stays armed) — Esc cancels
|
|
7484
8164
|
if (connPick) { e.stopPropagation(); const r = insertPick(e.clientX, e.clientY); connPickToggle(r && r.anchorId); return; } // armed: clicking a member toggles it into the set this connection is recorded against
|
|
7485
|
-
if (insertMode) { e.stopPropagation(); const
|
|
7486
|
-
|
|
7487
|
-
|
|
8165
|
+
if (insertMode) { e.stopPropagation(); const detail=insertPending&&insertPending.kind==='detail'; const sticky = insertPending && insertPending.sticky;
|
|
8166
|
+
if (detail && !detailPlanePick) {
|
|
8167
|
+
const locked = lockDetailPlaneAt(e.clientX, e.clientY);
|
|
8168
|
+
if (!locked) { if(api&&api.toast)api.toast('Choose a member face — empty space cannot place a drawing detail'); return; }
|
|
8169
|
+
if (api && api.toast) api.toast('Face chosen — move on this plane, then click the exact detail location');
|
|
8170
|
+
return;
|
|
8171
|
+
}
|
|
8172
|
+
// Detail preview and commit deliberately share this one calculation. Calling the preview path here
|
|
8173
|
+
// paints the exact final projected/snapped point and hands that same object to the editor to save.
|
|
8174
|
+
const r=detail?detailPlanePreviewAt(e.clientX,e.clientY):insertPick(e.clientX,e.clientY);
|
|
8175
|
+
if(!r&&detail){if(api&&api.toast)api.toast('Plane is too edge-on — orbit slightly to place');return;}
|
|
8176
|
+
if (r && api && api.onInsertPlace) api.onInsertPlace(r, insertPending); if (!sticky) setInsertMode(false); return; } // details choose face then point; favourites may stay armed for repeat placement
|
|
7488
8177
|
if (framePicking()) { e.stopPropagation(); controls.enabled = true; framePickClick(e); return; } // 3-click UCS set: this click collects the origin / X point / Y point
|
|
7489
8178
|
if (frameMode) { let fh = null; try { fh = pickFrameHandle(e.clientX, e.clientY); } catch { fh = null; } if (fh) { e.stopPropagation(); controls.enabled = false; startFrameDrag(fh, e); return; } } // grab the local-frame origin/ring (armed) → drag it; an empty click falls through (orbit)
|
|
7490
8179
|
if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !gridLinePick3d && !refMeasure3d && !selectedClipIds.size) { // passive gizmo, no tool armed → clicking its origin/ring re-selects the local frame for editing (NOT reached by box-select or select-all, which only touch members). gridLinePick3d belongs in this list like every other armed tool: the handle captures within ~16 px, so without it the frame ORIGIN — a snap target the grid pick advertises — could never be used as a grid endpoint; the click would re-arm the frame and cancel the pick instead. refMeasure3d is here for the same reason and it BITES HARDER: the UCS origin sits at world [0,0,0] or the local frame origin, which is routinely inside the very reference being measured, so without it a measure click near it would arm a frame drag and silently cancel the measure.
|
|
7491
8180
|
let fh = null; try { fh = pickFrameHandle(e.clientX, e.clientY, true); } catch { fh = null; }
|
|
7492
8181
|
if (fh) { e.stopPropagation(); controls.enabled = false; armFrame3d(true); startFrameDrag(fh, e); return; } // re-arm the tool + grab the clicked handle so a click-drag manipulates immediately
|
|
7493
8182
|
}
|
|
7494
|
-
if (selectedClipIds.size && !gridLinePick3d && !refMeasure3d) { let ch = null; try { ch = pickClipHandle(e.clientX, e.clientY); } catch { ch = null; } if (ch) { e.stopPropagation(); controls.enabled = false; downXY = [e.clientX, e.clientY]; startClipDrag(ch, e); return; } } // grab a clip handle (plane dot / box face) → drag it. Not while the grid pick is armed: a handle drag would start under an armed two-click tool, leaving the button + hint claiming a pick and the shared preview line stranded (onUp clears the marker/readout but not dimPreviewLine).
|
|
7495
8183
|
if (refMeasure3d) { // S2 Stage D: pick A, then B → the EDITOR owns the result; nothing is stored here
|
|
7496
8184
|
e.stopPropagation(); controls.enabled = true;
|
|
7497
8185
|
const r = refMeasurePointAt(e); if (!r) return; // no snap, no point — a miss is a no-op, not a mid-air pick
|
|
7498
8186
|
if (!refMeasure3d.a) { refMeasure3d.a = r.p; updateStatusChip(); if (api && api.onRefMeasureStep) api.onRefMeasureStep(); return; }
|
|
7499
8187
|
const a = refMeasure3d.a, b = r.p;
|
|
7500
8188
|
const mm = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
|
|
7501
|
-
// A COINCIDENT SECOND PICK IS SILENTLY IGNORED, anchor kept.
|
|
8189
|
+
// A COINCIDENT SECOND PICK IS SILENTLY IGNORED, anchor kept. The shared clip-box gesture treats a
|
|
7502
8190
|
// same-point second corner exactly this way; a louder pattern for a near-identical mis-click would be
|
|
7503
8191
|
// the invention, and re-picking a first point that was already right is a tax.
|
|
7504
8192
|
//
|
|
@@ -7543,13 +8231,18 @@ function onDown(e) {
|
|
|
7543
8231
|
if (dimMode3d) { // 2-click dimension placement (not a drag): pick A, then B → place
|
|
7544
8232
|
e.stopPropagation(); controls.enabled = true;
|
|
7545
8233
|
const r = dimPointAt(e, dimDraft3d && dimDraft3d.a); if (!r) return;
|
|
7546
|
-
if (!dimDraft3d) { dimDraft3d = { a: r.p }; dimCandidates3d = null; }
|
|
8234
|
+
if (!dimDraft3d) { if (measureSession) measureSession.pickPoint(measureAcquisition(r)); else dimDraft3d = { a: r.p }; dimCandidates3d = null; }
|
|
7547
8235
|
else {
|
|
7548
8236
|
const a = dimDraft3d.a, b = r.p, axis = dimEffAxis(e.altKey, a, b), axisDir = dimAxisDir(axis);
|
|
7549
8237
|
const g = dim3dGeom(a, b, axis, axisDir);
|
|
7550
|
-
|
|
7551
|
-
|
|
8238
|
+
if (g.valueMm > 1 && measureSession) {
|
|
8239
|
+
measureSession.pickPoint(measureAcquisition(r));
|
|
8240
|
+
measurePendingMeta = { axis, axisDir: axisDir ? [...axisDir] : null };
|
|
8241
|
+
measureSession.setPlacementOffset(0); const placed = measureSession.commitPlacement();
|
|
8242
|
+
measureProviderData.set(placed.id, measurePendingMeta); measurePendingMeta = null;
|
|
8243
|
+
} else if (g.valueMm > 1 && api && api.onAddDim3d) api.onAddDim3d({ id: api.newDim3dId(), a, b, axis, ...(axisDir ? { axisDir } : {}) });
|
|
7552
8244
|
else if (g.valueMm <= 1 && axis !== 'free') { dimDraft3d = { a }; if (api && api.toast) api.toast('No length along the locked axis — move the second point or switch axis'); } // any AXIS-LOCKED projection (world X/Y/Z/Elev or local X′/Y′) collapsed to ~0 despite a real 2nd pick — e.g. two points at the same level with Z / Alt-vertical → keep the first anchor + explain, don't silently drop the pick. A coincident 'free' double-click stays a silent no-op.
|
|
8245
|
+
if (g.valueMm > 1 || axis === 'free') { dimDraft3d = null; dimPreviewLine.visible = false; marker.visible = false; readout.style.display = 'none'; dimCandidates3d = null; clearSharedSnapGuides(); }
|
|
7553
8246
|
}
|
|
7554
8247
|
updateStatusChip(); return;
|
|
7555
8248
|
}
|
|
@@ -7605,7 +8298,7 @@ function onDown(e) {
|
|
|
7605
8298
|
// up-side picker repeats this guard defensively, but a real pointer lifecycle may otherwise clear the
|
|
7606
8299
|
// current native selection before that late raycast gets a vote.
|
|
7607
8300
|
if(!id&&api&&api.canSelectReference&&!api.canSelectReference()){let filteredRef=null;try{filteredRef=pickReferenceAt(e.clientX,e.clientY);}catch{}selectionTrace={phase:'down-filter',x:e.clientX,y:e.clientY,own:id,reference:filteredRef,referenceAllowed:false};if(filteredRef){e.stopPropagation();controls.enabled=false;pending={filteredReference:true};return;}}
|
|
7608
|
-
if (!id) { pending = null; boxSel = { x: e.clientX, y: e.clientY }; return; } // empty space →
|
|
8301
|
+
if (!id) { pending = null; boxSel = { x: e.clientX, y: e.clientY, sharedStart: true }; selectionTools?.interceptor.pointerDown(e); return; } // empty space → shared click/marquee policy
|
|
7609
8302
|
e.stopPropagation(); controls.enabled = false; // grabbed a member → suppress orbit (enabled=false is the reliable guard)
|
|
7610
8303
|
try {
|
|
7611
8304
|
const m = memberById(id);
|
|
@@ -7878,7 +8571,6 @@ function onMove(e) {
|
|
|
7878
8571
|
return;
|
|
7879
8572
|
}
|
|
7880
8573
|
if (boxSel) { onBoxMove(e); return; }
|
|
7881
|
-
if (pending && pending.clipDrag) { onMoveClip(e); return; } // dragging a clip handle (plane offset / box face)
|
|
7882
8574
|
if (pending && pending.frameDrag) { onMoveFrame(e); return; } // dragging the local-frame origin / rotation ring
|
|
7883
8575
|
if (pending && pending.posGizmo) { onMovePositionGizmo(e); return; } // dragging a Profile Position handle (depth/width offset or roll)
|
|
7884
8576
|
if (!pending || pending.geo) return;
|
|
@@ -7930,13 +8622,13 @@ function positionCopyGhost(dx, dy) {
|
|
|
7930
8622
|
}
|
|
7931
8623
|
function clearCopyGhost() { if (copyGhost) { scene.remove(copyGhost); copyGhost = null; } }
|
|
7932
8624
|
function onBoxMove(e) {
|
|
7933
|
-
if (
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
rubber.style.display = '
|
|
8625
|
+
if (!boxSel.sharedStart) {
|
|
8626
|
+
selectionTools?.interceptor.pointerDown({ button: 0, pointerId: e.pointerId, clientX: boxSel.x, clientY: boxSel.y });
|
|
8627
|
+
boxSel.sharedStart = true;
|
|
8628
|
+
}
|
|
8629
|
+
const handled = selectionTools?.interceptor.pointerMove(e);
|
|
8630
|
+
boxSel.moved = handled === true;
|
|
8631
|
+
if (!boxSel.moved && rubber) rubber.style.display = 'none';
|
|
7940
8632
|
}
|
|
7941
8633
|
// --- Tekla-style area select: point/segment vs screen rect [x0,y0,x1,y1]. window = both ends enclosed
|
|
7942
8634
|
// (L→R drag); crossing = the member's screen footprint touches the rect (R→L drag). Same math the 2D marquee uses. ---
|
|
@@ -7986,6 +8678,17 @@ function membersInRect(x0, y0, x1, y1, windowMode) {
|
|
|
7986
8678
|
}
|
|
7987
8679
|
return out;
|
|
7988
8680
|
}
|
|
8681
|
+
// Placed detail image planes obey the same CAD marquee direction as rendered model solids:
|
|
8682
|
+
// left-to-right fully encloses their footprint; right-to-left only needs to touch it.
|
|
8683
|
+
function detailsInRect(x0, y0, x1, y1, windowMode) {
|
|
8684
|
+
const rect = canvasEl.getBoundingClientRect();
|
|
8685
|
+
const r = [Math.min(x0, x1), Math.min(y0, y1), Math.max(x0, x1), Math.max(y0, y1)];
|
|
8686
|
+
const out = [];
|
|
8687
|
+
for (const [id, mesh] of meshById) {
|
|
8688
|
+
if (String(id).startsWith('det:') && mesh.visible && memberFootprintHit(mesh, r, windowMode, rect)) out.push(id);
|
|
8689
|
+
}
|
|
8690
|
+
return out;
|
|
8691
|
+
}
|
|
7989
8692
|
const gridPlaneSpecs=planes=>(planes||[]).map(p=>({normal:[p.normal.x,p.normal.y,p.normal.z],constant:p.constant}));
|
|
7990
8693
|
function visibleGridSegment(a,b){return clipSegmentToPlanes(a,b,gridPlaneSpecs(renderer&&renderer.clippingPlanes));}
|
|
7991
8694
|
function gridCameraFrustum(){camera.updateMatrixWorld();return new THREE.Frustum().setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse));}
|
|
@@ -8048,18 +8751,8 @@ function onUp(e) {
|
|
|
8048
8751
|
if (!renderer || !canvasEl || canvasEl.style.display === 'none') { downXY = null; boxSel = pending = dragging = null; if (controls) controls.enabled = true; return; } // 3D hidden mid-gesture → drop stale gesture state (no resume on re-show)
|
|
8049
8752
|
const bs = boxSel; boxSel = null;
|
|
8050
8753
|
if (bs) { // empty-space gesture: drag = box-select, click = clear selection
|
|
8051
|
-
if (bs.moved)
|
|
8052
|
-
|
|
8053
|
-
const additive = e.ctrlKey || e.metaKey || e.shiftKey; // Ctrl/Shift → toggle the framed set into the current selection (add/remove), else replace
|
|
8054
|
-
const memberIds = membersInRect(bs.x, bs.y, e.clientX, e.clientY, windowMode);
|
|
8055
|
-
const connIds = connsInRect(bs.x, bs.y, e.clientX, e.clientY, windowMode);
|
|
8056
|
-
const gridIds=gridsInRect(bs.x,bs.y,e.clientX,e.clientY,windowMode);
|
|
8057
|
-
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
|
|
8058
|
-
else if(gridIds.length&&api&&api.onSelectBatch){if(!additive)resetConnState();api.onSelectBatch({memberIds:[...memberIds,...connIds.flatMap(c=>connChildIds(c))],gridIds},additive);}
|
|
8059
|
-
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
|
|
8060
|
-
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
|
|
8061
|
-
}
|
|
8062
|
-
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
|
|
8754
|
+
if (bs.moved) selectionTools?.finishMarquee(e);
|
|
8755
|
+
else selectionTools?.selectAt(e);
|
|
8063
8756
|
downXY = null; return;
|
|
8064
8757
|
}
|
|
8065
8758
|
const p = pending, wasDragging = dragging; pending = dragging = null;
|
|
@@ -8067,8 +8760,8 @@ function onUp(e) {
|
|
|
8067
8760
|
const moved = downXY ? Math.hypot(e.clientX - downXY[0], e.clientY - downXY[1]) : Infinity; downXY = null;
|
|
8068
8761
|
if (!p) return;
|
|
8069
8762
|
if(p.filteredGrid||p.filteredReference||p.posAnchor)return; // an anchor-dot press is inert BY DESIGN: no drag, and no selection change either
|
|
8070
|
-
if(p.gridId){if(moved>DRAG_TOL_PX)return;
|
|
8071
|
-
if (p.clipDrag) return; //
|
|
8763
|
+
if(p.gridId){if(moved>DRAG_TOL_PX)return;selectionTools?.selectAt(e);return;}
|
|
8764
|
+
if (p.clipDrag) { publishClipState(); return; } // geometry applied live; publish the final canonical section state once on pointer-up
|
|
8072
8765
|
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)
|
|
8073
8766
|
if (p.posGizmo) { // Profile Position handle → commit the ABSOLUTE new offset/roll through the editor (one undo entry)
|
|
8074
8767
|
if (readout) readout.style.display = 'none';
|
|
@@ -8161,7 +8854,7 @@ function onUp(e) {
|
|
|
8161
8854
|
}
|
|
8162
8855
|
if (!wasDragging) {
|
|
8163
8856
|
if (p.id && !p.geo && !p.epDrag && moved > DRAG_TOL_PX && api && api.onSelect) { api.onSelect(p.id, p.add); return; } // a blocked drag (drag-move/copy OFF) acts on the GRABBED member, not whatever's under the release point (Ctrl/Shift toggles it)
|
|
8164
|
-
|
|
8857
|
+
selectionTools?.selectAt(e); return; // shared click/overlap-cycle policy; provider mutation port preserves Steel connection semantics
|
|
8165
8858
|
}
|
|
8166
8859
|
if (p.copy) { // Ctrl+drag → commit a copy at the plan delta (the editor clones + selects); the ghost was the preview
|
|
8167
8860
|
if (p.delta && !(p.delta[0] === 0 && p.delta[1] === 0) && api && api.onCopyDrag3d) api.onCopyDrag3d(p.copyIds, p.delta[0], p.delta[1]);
|
|
@@ -8286,11 +8979,7 @@ function onHoverMove(e) {
|
|
|
8286
8979
|
} else { marker.visible = false; readout.style.display = 'none'; canvasEl.style.cursor = 'crosshair'; }
|
|
8287
8980
|
return;
|
|
8288
8981
|
}
|
|
8289
|
-
if (wpMode) {
|
|
8290
|
-
canvasEl.style.cursor = 'crosshair';
|
|
8291
|
-
if (wpMode === '3pt') { const r = dimPointAt({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt });
|
|
8292
|
-
if (r && !(wpDraft && wpDraft.length)) showMarker(r.p, r.type); }
|
|
8293
|
-
updateStatusChip(); return; }
|
|
8982
|
+
if (wpMode) { wpPickHover(); updateStatusChip(); return; } // armed set-plane pick: crosshair (+ snap marker for the 3pt flow)
|
|
8294
8983
|
if (addActive()) { // Add-member armed: snap marker + rubber preview on the working plane
|
|
8295
8984
|
canvasEl.style.cursor = 'crosshair';
|
|
8296
8985
|
drPreview({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt, shiftKey: tfLastShift });
|
|
@@ -8302,7 +8991,8 @@ function onHoverMove(e) {
|
|
|
8302
8991
|
if (r && r.snap) showMarker(r.p, r.type); else marker.visible = false;
|
|
8303
8992
|
if (r) roShowCoordOnly(r.p, lastHoverXY[0], lastHoverXY[1]); else if (readout) readout.style.display = 'none'; } // local coords of the base point before it's picked
|
|
8304
8993
|
updateStatusChip(); return; }
|
|
8305
|
-
if (
|
|
8994
|
+
if (insertMode && insertPending && insertPending.kind === 'detail') { const p=detailPlanePreviewAt(lastHoverXY[0],lastHoverXY[1]);canvasEl.style.cursor=p?'crosshair':'not-allowed';return; } // the crosshair stays visible; the separate rectangle + centre dot show the projected, plane-only point and its ordinary on-plane snap
|
|
8995
|
+
if (clipMode) { canvasEl.style.cursor = 'crosshair'; return; } // the registered shared clip gesture already painted this hover; provider hover stands down
|
|
8306
8996
|
if (dimMode3d) { dimHoverPreview(dimLastAlt); return; } // dim tool: snap marker + live preview line + readout (extracted so setDimAxis can refresh it synchronously)
|
|
8307
8997
|
if (framePicking()) { // 3-click UCS set in progress: live rubber-band X/Y + Z-flip arrow, snap marker at the cursor
|
|
8308
8998
|
canvasEl.style.cursor = 'crosshair';
|
|
@@ -8319,7 +9009,6 @@ function onHoverMove(e) {
|
|
|
8319
9009
|
let fh = null; try { fh = pickFrameHandle(lastHoverXY[0], lastHoverXY[1], true); } catch { fh = null; }
|
|
8320
9010
|
if (fh) { canvasEl.style.cursor = 'pointer'; return; }
|
|
8321
9011
|
}
|
|
8322
|
-
if (selectedClipIds.size) { let ch = null; try { ch = pickClipHandle(lastHoverXY[0], lastHoverXY[1]); } catch { ch = null; } if (ch) { canvasEl.style.cursor = 'move'; return; } } // over a clip handle → move cursor
|
|
8323
9012
|
let ep = null;
|
|
8324
9013
|
if (!geoMode() && (MODEL().endpointEditing === true || MODEL().memberEditing !== false)) {
|
|
8325
9014
|
try { ep = pickEndpoint(lastHoverXY[0], lastHoverXY[1]); } catch { ep = null; }
|
|
@@ -8388,7 +9077,9 @@ function instructorCommand() {
|
|
|
8388
9077
|
covers the CROSSHAIR stage only; once the point is accepted the pick above takes over and
|
|
8389
9078
|
`steel.connection-members` narrates naming the members. (Found by review.) */
|
|
8390
9079
|
if (insertMode && insertPending && insertPending.kind === 'connection-replace') return { armed: 'steel.connection-replace', step: 0 };
|
|
8391
|
-
if (insertMode) return { armed: 'steel.insert-detail', step: 0 };
|
|
9080
|
+
if (insertMode && insertPending && insertPending.kind === 'detail') return { armed: 'steel.insert-detail', step: detailPlanePick ? 1 : 0 };
|
|
9081
|
+
if (insertMode && insertPending && insertPending.kind === 'favourite') return { armed: 'steel.favourite-place', step: 0 };
|
|
9082
|
+
if (insertMode && insertPending && insertPending.kind === 'connection') return { armed: 'steel.connection-place', step: 0 };
|
|
8392
9083
|
if (basePickCol) return { armed: 'steel.base-pick', step: 0 };
|
|
8393
9084
|
if (gridLinePick3d) return { armed: 'steel.grid-line', step: gridLinePick3d.a ? 1 : 0 };
|
|
8394
9085
|
if (dimMode3d) return { armed: 'steel.dimension', step: dimDraft3d ? 1 : 0 };
|
|
@@ -8449,7 +9140,7 @@ function updateStatusChip() {
|
|
|
8449
9140
|
teklaDragActive: !!(teklaDrag && teklaDrag.active), workPlaneMode: wpMode,
|
|
8450
9141
|
addActive: !!addActive(), transformActive: !!cmActive(), referenceMeasureActive: !!refMeasure3d,
|
|
8451
9142
|
gridLinePickActive: !!gridLinePick3d, clipMode, dimensionMode: dimMode3d,
|
|
8452
|
-
dimensionHasStart: !!dimDraft3d, insertMode, insertName: insertPending && insertPending.name,
|
|
9143
|
+
dimensionHasStart: !!dimDraft3d, insertMode, insertKind: insertPending && insertPending.kind, insertName: insertPending && insertPending.name,
|
|
8453
9144
|
basePickColumn: basePickCol, frameMode, framePickStep: framePickStep(), geometryMode: geoMode(),
|
|
8454
9145
|
connectionMemberPick: !!connPick, connectionMemberPickCount: connPick ? connPick.chosen.size : 0,
|
|
8455
9146
|
});
|
|
@@ -8533,11 +9224,11 @@ function updateStatusChip() {
|
|
|
8533
9224
|
// opened the gate so the pane would not sit blank, but never fitted anything), so this re-closes it
|
|
8534
9225
|
// and the retry is as clean as a first open. unframedFrames/unframedWarned reset with it, or two
|
|
8535
9226
|
// short stalls would add up into one bogus warning.
|
|
8536
|
-
function
|
|
8537
|
-
function
|
|
9227
|
+
function showSteel() { camFramed = camFitted; unframedFrames = 0; unframedWarned = false; if (controls) controls.enabled = true; if (canvasEl) { canvasEl.style.display = 'block'; resize(); } updateStatusChip(); refreshDims(); refreshOverlayDims(); renderFrameGizmo(); reflectWpBar(); } // reset orbit in case a gesture was stranded by a mid-drag hide; reflectWpBar so a Show plane restored from storage marks the button on arrival (#1403)
|
|
9228
|
+
function hideSteel() {
|
|
8538
9229
|
abandonConnPick('left-3d'); // Enter/Esc cannot reach an armed pick once this canvas is hidden
|
|
8539
9230
|
invalidatePointEntry('hide'); // leaving 3D → drop any open typed entry + stale base/start
|
|
8540
|
-
if (dimMode3d)
|
|
9231
|
+
if (dimMode3d) disarmMeasureTool(); // shared lifecycle disarms and syncs its toolbar
|
|
8541
9232
|
// …and the reference measure, through the editor so its panel card goes with it. Routed via
|
|
8542
9233
|
// dropRefMeasure3d rather than disarmed locally for exactly the reason that function exists: a local
|
|
8543
9234
|
// disarm would leave the Inspect panel showing a Measured block for a tool that owns nothing.
|
|
@@ -8552,12 +9243,48 @@ function hide() {
|
|
|
8552
9243
|
endTeklaDrag(); // and a live drag-out to Tekla — a stranded one would leave its badge on screen and swallow every later pointer move
|
|
8553
9244
|
if (canvasEl) canvasEl.style.display = 'none'; if (hoverChipShell) hoverChipShell.style.display = 'none'; else if (hoverChip) hoverChip.style.display = 'none'; if (rafId) { cancelAnimationFrame(rafId); rafId = null; }
|
|
8554
9245
|
}
|
|
9246
|
+
function show() { return viewportController ? viewportController.show() : showSteel(); }
|
|
9247
|
+
function hide() { return viewportController ? viewportController.hide() : hideSteel(); }
|
|
9248
|
+
function setProjection(mode) { return viewportController ? viewportController.setProjection(mode) : setProjectionSteel(mode); }
|
|
9249
|
+
function setCameraState(value) {
|
|
9250
|
+
if (!viewportController) return setCameraStateSteel(value);
|
|
9251
|
+
const current = viewportController.cameraState();
|
|
9252
|
+
return viewportController.applyCamera({ ...current, projection: value?.proj ?? current.projection,
|
|
9253
|
+
position: value?.pos ?? current.position, target: value?.target ?? current.target,
|
|
9254
|
+
orthoHeight: value?.orthoH ?? current.orthoHeight, zoom: value?.zoom ?? current.zoom });
|
|
9255
|
+
}
|
|
9256
|
+
function setDisplayMode(m) { return viewportController ? viewportController.setDisplayMode(m) : setDisplayModeSteel(m); }
|
|
9257
|
+
function applyView(name) { return viewportController ? viewportController.applyOrientation(name) : applyViewSteel(name); }
|
|
9258
|
+
function frameAll() { return viewportController ? viewportController.fitAll() : frameAllSteel(); }
|
|
9259
|
+
function frameSelection() { return viewportController ? viewportController.fitSelection() : frameSelectionSteel(); }
|
|
9260
|
+
function hideSelected() { const count = viewportController ? viewportController.hideSelection() : hideSelectedSteel(); if (count) api?.onVisibilitySelectionHidden?.(); return count; }
|
|
9261
|
+
function isolateSelected() { return viewportController ? viewportController.isolateSelection() : isolateSelectedSteel(); }
|
|
9262
|
+
function showAllGroups() { return viewportController ? viewportController.showAll() : showAllGroupsSteel(); }
|
|
9263
|
+
function setClipState(value) { return viewportController ? viewportController.setSectionState(value) : setClipStateSteel(value); }
|
|
9264
|
+
async function rebuild(fit = false) {
|
|
9265
|
+
if (!viewportController) return rebuildSteel(fit);
|
|
9266
|
+
const outcome = await viewportController.rebuild({ fit });
|
|
9267
|
+
return outcome.result;
|
|
9268
|
+
}
|
|
9269
|
+
function commitSelection(commit) {
|
|
9270
|
+
if (!viewportController) throw new Error('viewport controller is not initialized');
|
|
9271
|
+
return viewportController.commitSelection(commit);
|
|
9272
|
+
}
|
|
9273
|
+
function viewportState() { return viewportController ? viewportController.state() : null; }
|
|
8555
9274
|
// The editor's active-pane state, pushed in. Defaults true so every existing caller — and vector-3d.html,
|
|
8556
9275
|
// which has no split and never calls this — keeps today's behaviour with no change.
|
|
8557
|
-
function setInputActive(on) { inputActive = on !== false; if (!inputActive) abandonConnPick('pane-inactive'); }
|
|
9276
|
+
function setInputActive(on) { inputActive = on !== false; viewportController?.setInputActive(inputActive); if (!inputActive) abandonConnPick('pane-inactive'); }
|
|
8558
9277
|
function isReady() { return built; }
|
|
8559
9278
|
|
|
8560
|
-
function
|
|
9279
|
+
function disposeSteel() {
|
|
9280
|
+
clipGesture?.dispose(); clipGesture = null;
|
|
9281
|
+
sharedClipList?.destroy?.(); sharedClipList = null; releaseClipGestureInput?.(); releaseClipGestureInput = null; releaseClipOverlayInput?.(); releaseClipOverlayInput = null;
|
|
9282
|
+
releaseClipSession?.(); releaseClipSession = null; releaseClipSpatial?.(); releaseClipSpatial = null;
|
|
9283
|
+
clipOverlay?.dispose(); clipOverlay = null; clipSession?.dispose(); clipSession = null; sharedClipEdit = null;
|
|
9284
|
+
cadToolController?.dispose(); cadToolController = null; cadToolDispatch = false;
|
|
9285
|
+
measureSession?.dispose(); measureSession = null; measurePendingMeta = null; measureProviderData.clear();
|
|
9286
|
+
spatialTools?.dispose(); spatialTools = null; spatialFrameSignature = '';
|
|
9287
|
+
selectionTools?.destroy(); selectionTools = null;
|
|
8561
9288
|
positionBasisListeners.clear();
|
|
8562
9289
|
/* THROUGH abandonConnPick, not `connPick = null`. A re-placement transaction in the editor AWAITS this
|
|
8563
9290
|
pick's settlement and holds the write gate until it comes; clearing the state without firing the
|
|
@@ -8591,33 +9318,26 @@ function dispose() {
|
|
|
8591
9318
|
if (rafId) { cancelAnimationFrame(rafId); rafId = null; }
|
|
8592
9319
|
if (hoverRAF) { cancelAnimationFrame(hoverRAF); hoverRAF = 0; }
|
|
8593
9320
|
if (ro) ro.disconnect();
|
|
8594
|
-
|
|
8595
|
-
if (controls) controls.
|
|
8596
|
-
window.removeEventListener('pointermove', onMove);
|
|
8597
|
-
window.removeEventListener('pointerup', onUp);
|
|
8598
|
-
window.removeEventListener('keydown', onKey);
|
|
8599
|
-
window.removeEventListener('keydown', onModifierChange);
|
|
8600
|
-
window.removeEventListener('keyup', onModifierChange);
|
|
9321
|
+
cadInputArbiter?.destroy(); cadInputArbiter = null;
|
|
9322
|
+
if (controls) controls.dispose();
|
|
8601
9323
|
for (const ovl of [readout, hoverChipShell || hoverChip, rubber, dimLabelHost]) if (ovl && ovl.parentNode) ovl.parentNode.removeChild(ovl);
|
|
8602
9324
|
hoverChip = hoverChipShell = hoverChipToggle = null;
|
|
8603
9325
|
dimLabelHost = null; dimLabelPool.length = 0;
|
|
8604
9326
|
if (memberLabelHost && memberLabelHost.parentNode) memberLabelHost.parentNode.removeChild(memberLabelHost);
|
|
8605
|
-
memberLabelHost = null; memberLabelPool.length = 0; labelsOnFlag = false; insertMode = false; insertPending = null;
|
|
9327
|
+
memberLabelHost = null; memberLabelPool.length = 0; labelsOnFlag = false; insertMode = false; insertPending = null; detailPlanePick = null; detailPlaneCandidates = null;
|
|
8606
9328
|
if (propLabelHost && propLabelHost.parentNode) propLabelHost.parentNode.removeChild(propLabelHost);
|
|
8607
9329
|
propLabelHost = null; propLabelPool.length = 0; propLabelSpec = null;
|
|
8608
9330
|
if (selLenLabelHost && selLenLabelHost.parentNode) selLenLabelHost.parentNode.removeChild(selLenLabelHost);
|
|
8609
9331
|
selLenLabelHost = null; selLenLabelPool.length = 0; selLenLabelSpec = null;
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
w.renderer.dispose(); if (w.renderer.domElement.parentNode) w.renderer.domElement.parentNode.removeChild(w.renderer.domElement);
|
|
8614
|
-
}
|
|
8615
|
-
cube = triad = null;
|
|
9332
|
+
// One shared mount owns both mini-WebGL contexts. Its teardown is idempotent, unsubscribes first,
|
|
9333
|
+
// disposes every scene resource, and force-loses both contexts before a later init can remount.
|
|
9334
|
+
orientationOverlay?.destroy(); orientationOverlay = null; orientationListeners.clear();
|
|
8616
9335
|
if (epGeom) epGeom.dispose(); if (epMatStart) epMatStart.dispose(); if (epMatEnd) epMatEnd.dispose();
|
|
8617
9336
|
if (dims3dGroup) { if (scene) scene.remove(dims3dGroup); for (const c of dims3dGroup.children) { c.geometry.dispose(); c.material.dispose(); } } // placed-dim lines
|
|
8618
9337
|
if (overlayDimsGroup) { if (scene) scene.remove(overlayDimsGroup); for (const c of overlayDimsGroup.children) { c.geometry.dispose(); c.material.dispose(); } } // derived dim-overlay lines
|
|
8619
9338
|
overlayLabelPool.length = 0; dimParts = [];
|
|
8620
9339
|
if (dimPreviewLine && scene) scene.remove(dimPreviewLine);
|
|
9340
|
+
clearSharedSnapGuides(); if (sharedSnapGuideGroup && scene) scene.remove(sharedSnapGuideGroup); sharedSnapGuideGroup = null;
|
|
8621
9341
|
for (const o of [epRing, epPreview, epMovedLine, refGroup, dimPreviewLine]) if (o) { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }
|
|
8622
9342
|
epGeom = epMatStart = epMatEnd = epRing = epPreview = epMovedLine = refGroup = null;
|
|
8623
9343
|
dims3dGroup = dimPreviewLine = overlayDimsGroup = null;
|
|
@@ -8638,12 +9358,14 @@ function dispose() {
|
|
|
8638
9358
|
xrefSubSelected = null; xrefSubMesh = null; xrefSubMats = null;
|
|
8639
9359
|
clearStructGrid();
|
|
8640
9360
|
clearWireEdges();
|
|
9361
|
+
if (scene) scene.environment = null;
|
|
9362
|
+
if (envRT) envRT.dispose(); envRT = null; envFailed = false;
|
|
8641
9363
|
for (const tex of gridTexCache.values()) tex.dispose();
|
|
8642
9364
|
gridTexCache.clear();
|
|
8643
9365
|
clearRoot();
|
|
8644
9366
|
if (workAreaHelper) { if (overlayScene) overlayScene.remove(workAreaHelper); workAreaHelper.geometry.dispose(); workAreaHelper.material.dispose(); workAreaHelper = null; }
|
|
8645
9367
|
if (wpGroup) { if (scene) scene.remove(wpGroup); wpGroup.traverse((o) => { if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); }); wpGroup = null; } // the reference plane can exist by default now → dispose it too (code-review)
|
|
8646
|
-
clearConnEnvelope(); clearClipGizmo();
|
|
9368
|
+
clearConnEnvelope(); clearClipGizmo(); clipCreationPreview?.dispose(); clipCreationPreview = null; setFacePickPreview(null); setPlaneHoverPreview(null); disposeFramePreview(); disposeFrameGizmo();
|
|
8647
9369
|
/* MODULE state, not scene state: disposing the objects leaves posInteraction/posActiveHandle/posLiveState
|
|
8648
9370
|
exactly as the gesture left them, and init() mints a fresh view around them — which would come up with
|
|
8649
9371
|
orbit disabled and a handle already amber. End the gesture before dropping the scene it belonged to.
|
|
@@ -8654,18 +9376,23 @@ function dispose() {
|
|
|
8654
9376
|
pending = dragging = null; downXY = null;
|
|
8655
9377
|
disposePositionGizmo(); disposePositionLeader(); overlayScene = null; // dispose the clip/frame/position gizmo + leader + preview THREE resources before dropping the scene (Codex)
|
|
8656
9378
|
clips = []; workArea = null; clipMode = null; selectedClipIds.clear(); clipBoxDraft = null; // clips live on the renderer; drop them with the renderer
|
|
8657
|
-
if (renderer) renderer.dispose();
|
|
9379
|
+
if (renderer) { renderer.dispose(); renderer.forceContextLoss?.(); }
|
|
8658
9380
|
renderer = scene = camera = perspCam = orthoCam = controls = root = api = canvasEl = ro = null; built = false;
|
|
8659
9381
|
// …and re-arm the first-frame gate, because camFramed is module state and would otherwise outlive
|
|
8660
9382
|
// the cameras it describes: init() mints fresh, never-framed ones, so a gate left open paints them
|
|
8661
|
-
// straight away and the flat top view is back.
|
|
8662
|
-
//
|
|
8663
|
-
//
|
|
8664
|
-
// editor tears down by reloading, which resets module state anyway), so this guards the exported
|
|
8665
|
-
// teardown surface, not a path the app drives.
|
|
9383
|
+
// straight away and the flat top view is back. Workspaces requests this teardown before replacing a
|
|
9384
|
+
// same-origin editor frame, with non-persisted pagehide as the fallback, so the reset protects the
|
|
9385
|
+
// live project-switch path as well as direct callers.
|
|
8666
9386
|
camFitted = camFramed = false; unframedFrames = 0; unframedWarned = false; // the LATCH resets too, or a working re-init after dispose could never warn again
|
|
8667
9387
|
}
|
|
8668
9388
|
|
|
9389
|
+
function dispose() {
|
|
9390
|
+
if (!viewportController) return disposeSteel();
|
|
9391
|
+
const current = viewportController;
|
|
9392
|
+
viewportController = null;
|
|
9393
|
+
return current.dispose();
|
|
9394
|
+
}
|
|
9395
|
+
|
|
8669
9396
|
function debug() {
|
|
8670
9397
|
const box = new THREE.Box3(); for (const m of meshById.values()) box.expandByObject(m);
|
|
8671
9398
|
const s = box.getSize(new THREE.Vector3()), c = box.getCenter(new THREE.Vector3());
|
|
@@ -8673,6 +9400,10 @@ function debug() {
|
|
|
8673
9400
|
meshes: meshById.size,
|
|
8674
9401
|
camFramed, // the first-frame gate — exposed so a browser pass can ASSERT the unframed window instead of photographing it
|
|
8675
9402
|
triangles: renderer ? renderer.info.render.triangles : -1,
|
|
9403
|
+
rendererInfo: renderer ? {
|
|
9404
|
+
render: { calls: renderer.info.render.calls, triangles: renderer.info.render.triangles, points: renderer.info.render.points, lines: renderer.info.render.lines },
|
|
9405
|
+
memory: { geometries: renderer.info.memory.geometries, textures: renderer.info.memory.textures },
|
|
9406
|
+
} : null,
|
|
8676
9407
|
bboxEmpty: box.isEmpty(), bboxSize: [s.x, s.y, s.z], bboxCenter: [c.x, c.y, c.z],
|
|
8677
9408
|
firstId: meshById.keys().next().value ?? null,
|
|
8678
9409
|
ids: [...meshById.keys()].slice(0, 12),
|
|
@@ -8775,7 +9506,7 @@ function snapCandidatesScreen(type) {
|
|
|
8775
9506
|
* object it named — a green run for a feature that does not work. So each candidate point is fed back
|
|
8776
9507
|
* through `pickReferenceAt` and kept only if it answers with that same object.
|
|
8777
9508
|
*
|
|
8778
|
-
* AND NOTHING OF OURS MAY STAND THERE.
|
|
9509
|
+
* AND NOTHING OF OURS MAY STAND THERE. The shared selection hit provider consults the reference layer only when its own
|
|
8779
9510
|
* members answered nothing, so a point with one of our beams in front is not a point at which this
|
|
8780
9511
|
* object can be drilled into at all — however cleanly the reference raycast resolves it. The first pass
|
|
8781
9512
|
* of this helper omitted that check and handed back a coordinate covered by a column; the click selected
|
|
@@ -8816,8 +9547,15 @@ function gridSegmentsScreen() {
|
|
|
8816
9547
|
}
|
|
8817
9548
|
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};});}
|
|
8818
9549
|
window.Steel3DView = {
|
|
8819
|
-
init, show, hide, setInputActive, rebuild, setSelection, setGridSelection, setSelectionState, isReady, dispose,
|
|
9550
|
+
init, show, hide, setInputActive, rebuild, setSelection, setGridSelection, setSelectionState, commitSelection, viewportState, isReady, dispose,
|
|
8820
9551
|
setProjection, projection, setDisplayMode, mode: () => displayMode, frameAll, frameSelection, applyView,
|
|
9552
|
+
setLighting: setModelLighting, lightingState: () => ({ ...modelLighting }),
|
|
9553
|
+
lightingProbe: () => ({
|
|
9554
|
+
state: { ...modelLighting }, shadowsEnabled,
|
|
9555
|
+
keyCastsShadow: !!lightKey?.castShadow,
|
|
9556
|
+
groundVisible: !!shadowGround?.visible,
|
|
9557
|
+
meshShadowCount: [...meshById.values()].filter((mesh) => mesh.castShadow).length,
|
|
9558
|
+
}),
|
|
8821
9559
|
setRefLine, refLine: () => refLineOn,
|
|
8822
9560
|
setInsertMode, insertMode: insertModeOn, // arm/query the detail-placement pick (Slice 4)
|
|
8823
9561
|
setConnMemberPick, connMemberPick: connMemberPickOn, connMemberPickJoint, // arm/query "name the members this connection joins"
|
|
@@ -8875,6 +9613,7 @@ window.Steel3DView = {
|
|
|
8875
9613
|
refMeasureCandidateSources: () => (refMeasure3d
|
|
8876
9614
|
? [...new Set(referenceCandidates(refMeasure3d.refId).map((c) => c.fromId))].sort() : []),
|
|
8877
9615
|
setLabelsOn, labelsOn: () => labelsOnFlag, // member mark/id label overlay toggle
|
|
9616
|
+
setDetailOpacity, // selected placed-detail inspector: live slider preview, no scene rebuild
|
|
8878
9617
|
syncMemberLabels, // editor calls after a mark/id edit to refresh labels
|
|
8879
9618
|
setPropLabels, // right-click property labels: editor pushes { labels:[{id,lines}], placement }
|
|
8880
9619
|
setSelLenLabels, // on-select member-length labels: editor pushes [{id,text}] (⋯ Display "Show member length")
|
|
@@ -8891,28 +9630,40 @@ window.Steel3DView = {
|
|
|
8891
9630
|
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 })) };
|
|
8892
9631
|
},
|
|
8893
9632
|
toggleGroup, setGroupsHidden, setIdsHidden, connHiddenIds: () => [...connHidden], selectionHiddenIds: () => [...selectionHidden], soloToggle, setSoloGroups, showAllGroups, groupState, getGroups, visibleMemberIds, visibleObjectIds, visibleGridIds,
|
|
8894
|
-
setClipMode, clipMode: clipModeOn, toggleClip, removeClip, clearClips, getClips, renameClip, selectClip, setSelectedClips, selectedClips, deleteSelectedClips, clipState, setClipState,
|
|
9633
|
+
setClipMode, clipMode: clipModeOn, toggleClip, removeClip, clearClips, getClips, renameClip, selectClip, setSelectedClips, selectedClips, deleteSelectedClips, clipState, setClipState, mountClipList,
|
|
8895
9634
|
// Instructor seam: what this module has armed, and the one slot that paints what the shell produced.
|
|
8896
9635
|
instructorCommand, renderGuidance,
|
|
8897
9636
|
isolateSelected, hideSelected, clearIsolation, isIsolated, hasVisibilityFilter, hasVisibilityTreatment,
|
|
8898
|
-
setGhostUnselected
|
|
8899
|
-
|
|
9637
|
+
setGhostUnselected: (on) => viewportController ? viewportController.setGhostUnselected(on) : setGhostUnselected(on),
|
|
9638
|
+
toggleGhostUnselected: () => viewportController ? viewportController.toggleGhostUnselected() : setGhostUnselected(!ghostUnselectedEnabled),
|
|
9639
|
+
ghostUnselected: () => viewportController ? viewportController.ghostUnselected() : ghostUnselectedEnabled,
|
|
9640
|
+
getState: () => viewportController.getState(),
|
|
9641
|
+
subscribe: (listener) => viewportController.subscribe(listener),
|
|
9642
|
+
// Saved cameras obey the existing closed v1 contract; the controller's internal hook retains
|
|
9643
|
+
// up/near/far for transactional restore. Invalid coordinates fail closed in the shared codec.
|
|
9644
|
+
cameraState: () => encodeCameraState(cameraState()), setCameraState, sectionViewState, sceneBounds, objectsPaneState,
|
|
9645
|
+
applyObjectsPaneState: (value) => {
|
|
9646
|
+
if (!value || typeof value !== 'object') return;
|
|
9647
|
+
// Restore the controller's authoritative Ghost state too; its provider hook remains raw.
|
|
9648
|
+
return viewportController ? viewportController.applyVisibilitySnapshot({ ...value, ghostUnselected: value.ghostUnselected === true }) : applyObjectsPaneState(value);
|
|
9649
|
+
},
|
|
9650
|
+
spatialState, replaceSpatialViews, saveSpatialView, deleteSpatialView,
|
|
8900
9651
|
workAreaSetAll, workAreaFromSelection, workAreaToggle, workAreaSetWhole, clearWorkArea, workAreaState,
|
|
8901
|
-
armWorkPlanePick, setWorkPlanePrincipal, clearWorkPlane, toggleWorkPlaneVisible, workPlaneInfo,
|
|
9652
|
+
armWorkPlanePick, setWorkPlanePrincipal, clearWorkPlane, toggleWorkPlaneVisible, workPlaneInfo, wpOffsetKind, reflectWpBar,
|
|
8902
9653
|
armFrame3d, disarmFrame3d, repickFrame3d, setFrame3d, setFrameBasis, setFrameAngle, setFrameOrigin, clearFrame3d, frameInfo, positionAuthoringBasis: positionAuthoringBasisSnapshot, onPositionAuthoringBasisChange, frameArmed: () => frameMode, framePicking, framePickStep, frameHandlesScreen, // 3D local drawing frame (UCS stage 1)
|
|
8903
9654
|
setPositionGizmoVisible, positionGizmoHandlesScreen, memberWorldTransform, setPositionTyping, positionLeaderVisible, frameGizmoVisible, positionGizmoStyleProbe, // Profile Position gizmo (slice 3a/3b): ⋯ Display toggle + E2E grab-point + world-transform/leader/frame-gizmo probes + typed-HUD camera freeze
|
|
8904
9655
|
coordReadout: () => { if (!readout || !readout._coord || readout.style.display === 'none' || readout._coord.style.display === 'none') return null; return { local: readout._coord.classList.contains('ro-local'), values: readout._coordV.map((v) => v.textContent), labels: readout._coordL.map((l) => l.textContent.trim()), text: readout._coord.textContent }; }, // UCS stage 2 test probe: the live local-coordinate row (null when hidden)
|
|
8905
9656
|
cmEscape, cmHasBase, cmClear3d, setCmAxis, cmLastClient, cmHudApply,
|
|
8906
9657
|
drHudApply, pointEntryBegin, pointEntryEnd, drHasStart: () => !!drDraft, // UCS stage 3: shared typed point-entry HUD (Move/Copy + Add)
|
|
8907
9658
|
drClear3d, drEscape: () => { if (drDraft) { drDraft = null; drBasisTok = null; if (drRubber) drRubber.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; return true; } return false; }, // Esc drops the START only — KEEP the axis lock (tfLock) so the next member reuses it (matches the chip + Move/Copy step-back); full disarm (drClear3d) clears the lock
|
|
8908
|
-
toggleDimTool, setDimAxis, dimAxis, setDims3dVisible, dims3dVisible, refreshDims,
|
|
9659
|
+
toggleDimTool: toggleMeasureTool, setDimAxis: setMeasureAxisLock, clearMeasures, removeMeasureById, selectMeasureById, updateMeasureById, setMeasurePresentation, measureState: () => measureSession?.state?.() ?? null, cadToolState: () => cadToolController?.measureState() ?? null, dimAxis, setDims3dVisible, dims3dVisible, refreshDims,
|
|
8909
9660
|
setSnapOnly: setSnapOnly3d, snapOnly: () => snapOnly3d, dimToolOn: () => dimMode3d, rightDragged: () => rightMoved, // Tekla-style snap override (right-click menu lives in steel-editor.html)
|
|
8910
9661
|
teklaDragging: () => !!(teklaDrag && teklaDrag.active), // a drag-out to Tekla is in flight — the editor's global Escape must leave it (and the selection) alone
|
|
8911
9662
|
refreshOverlayDims,
|
|
8912
9663
|
overlayDimsInfo: () => computeOverlayDims().map((s) => ({ label: s.label, cat: s.cat })), // the dims currently emitted (toggle + visibility applied) — for tests
|
|
8913
9664
|
overlayLabelTexts: () => overlayLabelPool.filter((el) => el.style.display !== 'none' && el.style.visibility !== 'hidden').map((el) => el.textContent),
|
|
8914
|
-
dims3dCount: () => (
|
|
8915
|
-
dims3dRecords: () => (
|
|
9665
|
+
dims3dCount: () => steelMeasureDimensions().length,
|
|
9666
|
+
dims3dRecords: () => steelMeasureDimensions().map((d) => ({ id: d.id, axis: d.axis, axisDir: d.axisDir || null, valueMm: dim3dGeom(d.a, d.b, d.axis, d.axisDir).valueMm })), // test probe: lightweight per-dim {axis, axisDir, rendered length} for E2E assertions (frame-aware capture + read==write)
|
|
8916
9667
|
dimAxisBarLabels: () => Array.from(document.querySelectorAll('#m3dDimAxis button')).map((b) => b.textContent), // test probe: the visible axis-control labels (3-state disclosure)
|
|
8917
9668
|
dimLockSet: () => [...dimLock], // test probe: the dimension's locked measure axes (x|y|z)
|
|
8918
9669
|
axisLockSet: () => [...tfLock], // test probe: the shared Move/Copy + Add line-lock set (u|v|n)
|
|
@@ -8922,7 +9673,7 @@ window.Steel3DView = {
|
|
|
8922
9673
|
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 }; },
|
|
8923
9674
|
wireEdgeColor: (id) => { const ls = wireEdges.get(id); return ls && ls.visible && ls.parent && ls.parent.visible && ls.material ? '#' + ls.material.color.getHexString() : null; }, // test probe: the Wire-mode OUTLINE colour of a member. probe() reads the hidden FILL's emissive, which is set in every mode — so it stays green even when the outline never adopts the cue (exactly the regression this fixes); this is the only read of the line that Wire actually draws. Gated like its sibling probes: ls.visible (leaving Wire only HIDES the outline — wireEdgesFor runs on the wire branch alone — so an ungated read reports a stale Wire colour) and ls.parent.visible (group/legend/isolate/work-area hide the parent MESH, and three skips a hidden parent's children). It still cannot see clip planes, frustum culling or a display:none canvas — a false "on" is possible there, never a false "off"
|
|
8924
9675
|
debug, probe, screenOf, centerOf, worldOf, memberBasis, snapCandidatesScreen, referenceObjectsScreen, gridSegmentsScreen, gridBubblesScreen, clipHandlesScreen,
|
|
8925
|
-
clipPlanePreviewShown: () =>
|
|
9676
|
+
clipPlanePreviewShown: () => clipCreationPreview?.state().kind === 'plane', // test helper: is the shared armed-plane hover ghost currently showing?
|
|
8926
9677
|
clipBoxFloorAt: (x, y) => clipBoxFloorPoint(x, y), // test helper: the snapped footprint point at a cursor ({ xy, snap, world } or null)
|
|
8927
9678
|
pointClipped: (p) => isPointClipped(p), // test helper: is a world point on the cut-away side of any active clip?
|
|
8928
9679
|
};
|