ducjs 4.2.0 → 4.4.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.
@@ -7,6 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { configureModelMotion } from "../../utils/modelMotion";
11
+ import { installCompactComponentRegistry } from "../../utils/compactComponentRegistry";
10
12
  import { mapViewerStateToOptions } from "./mapViewerStateToOptions";
11
13
  import { applyParametricViewerState } from "./parametricViewerState";
12
14
  import { sanitizeParametricShapes } from "./parametricShapes";
@@ -100,9 +102,11 @@ export const renderOffscreenModelThumbnail = (_a) => __awaiter(void 0, [_a], voi
100
102
  });
101
103
  const viewerOptions = Object.assign(Object.assign({}, mappedOptions.viewerOptions), { cadWidth: renderWidth, height: renderHeight, tools: false, measureTools: false, selectTool: false, explodeTool: true, zscaleTool: false, zebraTool: true });
102
104
  viewer = new Viewer(display, viewerOptions, () => undefined, null, false);
105
+ installCompactComponentRegistry(viewer);
103
106
  // Thumbnail dimensions are output pixels, independent of the screen's DPI.
104
107
  viewer.renderer.setPixelRatio(1);
105
108
  viewer.render(sanitizeParametricShapes(shapes), mappedOptions.renderOptions, viewerOptions);
109
+ configureModelMotion(viewer, shapes);
106
110
  viewer.update(true);
107
111
  if (signal === null || signal === void 0 ? void 0 : signal.aborted)
108
112
  return null;
@@ -1,4 +1,5 @@
1
1
  import * as THREE from "three";
2
+ import { withBatchedViewerUpdates } from "../../utils/viewerUpdateBatch";
2
3
  import { CLIPPING_AXES, shouldMirrorSingleAxisIntersection, } from "./clippingUtils";
3
4
  const CLIP_AXIS_INDEX = {
4
5
  x: 0,
@@ -80,11 +81,11 @@ const getActiveParametricClipIndices = (clipping) => {
80
81
  return activeIndices;
81
82
  };
82
83
  const applyParametricClipPlaneSubset = (rendered, clipping, hasAnyClip) => {
83
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
84
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
84
85
  const activeIndices = getActiveParametricClipIndices(clipping);
85
86
  const activeIndexSet = new Set(activeIndices);
86
87
  const shouldMirrorSingleAxisClip = shouldMirrorSingleAxisIntersection(clipping);
87
- const suppressCapMeshes = isIfcRenderedModel(rendered) && !clipping.objectColorCaps;
88
+ const suppressCapMeshes = !clipping.showPlanes || (isIfcRenderedModel(rendered) && !clipping.objectColorCaps);
88
89
  const activeClipPlanes = hasAnyClip
89
90
  ? activeIndices
90
91
  .map((index) => {
@@ -108,11 +109,24 @@ const applyParametricClipPlaneSubset = (rendered, clipping, hasAnyClip) => {
108
109
  .filter((entry) => Boolean(entry[1])));
109
110
  const capAndHelperPlanes = Array.from(capAndHelperPlaneByIndex.values());
110
111
  (_b = (_a = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _a === void 0 ? void 0 : _a.setClipPlanes) === null || _b === void 0 ? void 0 : _b.call(_a, activeClipPlanes);
111
- (_d = (_c = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _c === void 0 ? void 0 : _c.setVisible) === null || _d === void 0 ? void 0 : _d.call(_c, hasAnyClip);
112
- const planeHelpers = (_e = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _e === void 0 ? void 0 : _e.planeHelpers;
112
+ (_d = (_c = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _c === void 0 ? void 0 : _c.setVisible) === null || _d === void 0 ? void 0 : _d.call(_c, hasAnyClip && !suppressCapMeshes);
113
+ // Keep stencil writes paired with their cap even when the viewer reculls meshes.
114
+ for (const group of Object.values((_f = (_e = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _e === void 0 ? void 0 : _e.groups) !== null && _f !== void 0 ? _f : {})) {
115
+ if (!group || typeof group !== "object" || !("clipping" in group) || !(group.clipping instanceof Map))
116
+ continue;
117
+ for (const [index, stencils] of group.clipping) {
118
+ const enabled = hasAnyClip && !suppressCapMeshes && activeIndexSet.has(index);
119
+ for (const child of stencils.children) {
120
+ const material = child.material;
121
+ if (material)
122
+ material.stencilWrite = enabled;
123
+ }
124
+ }
125
+ }
126
+ const planeHelpers = (_g = rendered === null || rendered === void 0 ? void 0 : rendered.clipping) === null || _g === void 0 ? void 0 : _g.planeHelpers;
113
127
  if (planeHelpers) {
114
128
  planeHelpers.visible = hasAnyClip && clipping.showPlanes;
115
- for (const helper of (_f = planeHelpers.children) !== null && _f !== void 0 ? _f : []) {
129
+ for (const helper of (_h = planeHelpers.children) !== null && _h !== void 0 ? _h : []) {
116
130
  const helperMesh = helper;
117
131
  const helperIndex = helperMesh.index;
118
132
  const isActive = helperIndex != null && activeIndexSet.has(helperIndex);
@@ -125,11 +139,11 @@ const applyParametricClipPlaneSubset = (rendered, clipping, hasAnyClip) => {
125
139
  }
126
140
  }
127
141
  }
128
- for (const child of (_j = (_h = (_g = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _g === void 0 ? void 0 : _g.rootGroup) === null || _h === void 0 ? void 0 : _h.children) !== null && _j !== void 0 ? _j : []) {
142
+ for (const child of (_l = (_k = (_j = rendered === null || rendered === void 0 ? void 0 : rendered.nestedGroup) === null || _j === void 0 ? void 0 : _j.rootGroup) === null || _k === void 0 ? void 0 : _k.children) !== null && _l !== void 0 ? _l : []) {
129
143
  if ((child === null || child === void 0 ? void 0 : child.name) !== PLANE_MESH_GROUP_NAME)
130
144
  continue;
131
145
  child.visible = !suppressCapMeshes;
132
- for (const capPlane of (_k = child.children) !== null && _k !== void 0 ? _k : []) {
146
+ for (const capPlane of (_m = child.children) !== null && _m !== void 0 ? _m : []) {
133
147
  const capPlaneMesh = capPlane;
134
148
  const capPlaneIndex = capPlaneMesh.index;
135
149
  const isActive = hasAnyClip && capPlaneIndex != null && activeIndexSet.has(capPlaneIndex);
@@ -151,27 +165,29 @@ const applyParametricClipPlaneSubset = (rendered, clipping, hasAnyClip) => {
151
165
  }
152
166
  };
153
167
  export const applyParametricClipping = (viewer, clipping) => {
154
- var _a, _b, _c, _d, _e, _f, _g;
155
168
  let rendered;
156
169
  try {
157
170
  rendered = viewer === null || viewer === void 0 ? void 0 : viewer.rendered;
158
171
  }
159
- catch (_h) {
172
+ catch (_a) {
160
173
  return;
161
174
  }
162
175
  if (!(rendered === null || rendered === void 0 ? void 0 : rendered.clipping))
163
176
  return;
164
177
  const hasAnyClip = CLIPPING_AXES.some((axis) => clipping[axis].enabled);
165
- for (const axis of CLIPPING_AXES) {
166
- const index = CLIP_AXIS_INDEX[axis];
167
- const plane = clipping[axis];
168
- const actualValue = getParametricClipActualValue(viewer, axis, plane);
169
- (_a = viewer === null || viewer === void 0 ? void 0 : viewer.setClipSlider) === null || _a === void 0 ? void 0 : _a.call(viewer, index, actualValue, false);
170
- }
171
- (_b = viewer === null || viewer === void 0 ? void 0 : viewer.setClipIntersection) === null || _b === void 0 ? void 0 : _b.call(viewer, clipping.intersection, false);
172
- (_c = viewer === null || viewer === void 0 ? void 0 : viewer.setClipPlaneHelpers) === null || _c === void 0 ? void 0 : _c.call(viewer, clipping.showPlanes, false);
173
- (_d = viewer === null || viewer === void 0 ? void 0 : viewer.setLocalClipping) === null || _d === void 0 ? void 0 : _d.call(viewer, hasAnyClip);
174
- (_f = (_e = rendered.nestedGroup) === null || _e === void 0 ? void 0 : _e.setBackVisible) === null || _f === void 0 ? void 0 : _f.call(_e, hasAnyClip);
175
- applyParametricClipPlaneSubset(rendered, clipping, hasAnyClip);
176
- (_g = viewer === null || viewer === void 0 ? void 0 : viewer.update) === null || _g === void 0 ? void 0 : _g.call(viewer, true);
178
+ withBatchedViewerUpdates(viewer, () => {
179
+ var _a, _b, _c, _d, _e, _f, _g;
180
+ for (const axis of CLIPPING_AXES) {
181
+ const index = CLIP_AXIS_INDEX[axis];
182
+ const plane = clipping[axis];
183
+ const actualValue = getParametricClipActualValue(viewer, axis, plane);
184
+ (_a = viewer === null || viewer === void 0 ? void 0 : viewer.setClipSlider) === null || _a === void 0 ? void 0 : _a.call(viewer, index, actualValue, false);
185
+ }
186
+ (_b = viewer === null || viewer === void 0 ? void 0 : viewer.setClipIntersection) === null || _b === void 0 ? void 0 : _b.call(viewer, clipping.intersection, false);
187
+ (_c = viewer === null || viewer === void 0 ? void 0 : viewer.setClipPlaneHelpers) === null || _c === void 0 ? void 0 : _c.call(viewer, clipping.showPlanes, false);
188
+ (_d = viewer === null || viewer === void 0 ? void 0 : viewer.setLocalClipping) === null || _d === void 0 ? void 0 : _d.call(viewer, hasAnyClip);
189
+ (_f = (_e = rendered.nestedGroup) === null || _e === void 0 ? void 0 : _e.setBackVisible) === null || _f === void 0 ? void 0 : _f.call(_e, hasAnyClip);
190
+ applyParametricClipPlaneSubset(rendered, clipping, hasAnyClip);
191
+ (_g = viewer === null || viewer === void 0 ? void 0 : viewer.update) === null || _g === void 0 ? void 0 : _g.call(viewer, true);
192
+ });
177
193
  };
@@ -1,3 +1,5 @@
1
+ import { applyModelExplode } from "../../utils/modelMotion";
2
+ import { withBatchedViewerUpdates } from "../../utils/viewerUpdateBatch";
1
3
  import { applyParametricClipping, getParametricClipPercentValue, PARAMETRIC_CLIP_AXIS_NORMALS, } from "./parametricClip";
2
4
  import { getViewerGridPlanes, viewerGridPlanesToTuple } from "./viewerGrid";
3
5
  const PARAMETRIC_CLIP_AXES = ["x", "y", "z"];
@@ -119,10 +121,13 @@ export const getParametricViewerStateApplyPlan = (state, previousState) => ({
119
121
  zebra: !previousState || !deepEqual(previousState.zebra, state.zebra),
120
122
  });
121
123
  export const applyParametricViewerState = (viewer, state, options = {}) => {
122
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
123
124
  const rendered = getRenderedViewer(viewer);
124
125
  if (!viewer || !rendered)
125
126
  return false;
127
+ return withBatchedViewerUpdates(viewer, () => applyUnbatchedViewerState(viewer, rendered, state, options));
128
+ };
129
+ const applyUnbatchedViewerState = (viewer, rendered, state, options) => {
130
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
126
131
  try {
127
132
  const applyCamera = (_a = options.applyCamera) !== null && _a !== void 0 ? _a : true;
128
133
  const { display, material, clipping, explode, zebra } = state;
@@ -169,17 +174,16 @@ export const applyParametricViewerState = (viewer, state, options = {}) => {
169
174
  }
170
175
  if (applyPlan.explode) {
171
176
  setParametricExplodeState(viewer, explode.active, explode.value);
172
- (_3 = (_2 = viewer).setExplode) === null || _3 === void 0 ? void 0 : _3.call(_2, explode.active);
173
- (_5 = (_4 = viewer).setRelativeTime) === null || _5 === void 0 ? void 0 : _5.call(_4, explode.active ? explode.value : 0);
177
+ applyModelExplode(viewer, explode.active, explode.value);
174
178
  }
175
179
  if (applyPlan.zebra) {
176
180
  setParametricZebraActive(viewer, zebra.active);
177
- (_7 = (_6 = viewer).enableZebraTool) === null || _7 === void 0 ? void 0 : _7.call(_6, zebra.active);
178
- (_9 = (_8 = viewer).setZebraCount) === null || _9 === void 0 ? void 0 : _9.call(_8, zebra.stripeCount);
179
- (_11 = (_10 = viewer).setZebraOpacity) === null || _11 === void 0 ? void 0 : _11.call(_10, zebra.opacity);
180
- (_13 = (_12 = viewer).setZebraDirection) === null || _13 === void 0 ? void 0 : _13.call(_12, zebra.stripeDirection);
181
- (_15 = (_14 = viewer).setZebraColorScheme) === null || _15 === void 0 ? void 0 : _15.call(_14, zebra.colorScheme);
182
- (_17 = (_16 = viewer).setZebraMappingMode) === null || _17 === void 0 ? void 0 : _17.call(_16, zebra.mappingMode);
181
+ (_3 = (_2 = viewer).enableZebraTool) === null || _3 === void 0 ? void 0 : _3.call(_2, zebra.active);
182
+ (_5 = (_4 = viewer).setZebraCount) === null || _5 === void 0 ? void 0 : _5.call(_4, zebra.stripeCount);
183
+ (_7 = (_6 = viewer).setZebraOpacity) === null || _7 === void 0 ? void 0 : _7.call(_6, zebra.opacity);
184
+ (_9 = (_8 = viewer).setZebraDirection) === null || _9 === void 0 ? void 0 : _9.call(_8, zebra.stripeDirection);
185
+ (_11 = (_10 = viewer).setZebraColorScheme) === null || _11 === void 0 ? void 0 : _11.call(_10, zebra.colorScheme);
186
+ (_13 = (_12 = viewer).setZebraMappingMode) === null || _13 === void 0 ? void 0 : _13.call(_12, zebra.mappingMode);
183
187
  }
184
188
  const didApplyState = ((applyCamera && applyPlan.camera)
185
189
  || applyPlan.display
@@ -188,11 +192,11 @@ export const applyParametricViewerState = (viewer, state, options = {}) => {
188
192
  || applyPlan.explode
189
193
  || applyPlan.zebra);
190
194
  if (didApplyState) {
191
- (_19 = (_18 = viewer).update) === null || _19 === void 0 ? void 0 : _19.call(_18, true);
195
+ (_15 = (_14 = viewer).update) === null || _15 === void 0 ? void 0 : _15.call(_14, true);
192
196
  }
193
197
  return true;
194
198
  }
195
- catch (_20) {
199
+ catch (_16) {
196
200
  return false;
197
201
  }
198
202
  };
@@ -79,7 +79,15 @@ export interface DucCharterDecision {
79
79
  * A Charter holds what an engineer or agent needs to understand what the project
80
80
  * is trying to achieve and why the current artifact state exists.
81
81
  */
82
+ export interface DucCharterPhaseChange {
83
+ id: string;
84
+ previousPhase: DucCharterPhase;
85
+ phase: DucCharterPhase;
86
+ changedAt: number;
87
+ closedReason?: string;
88
+ }
82
89
  export interface DucCharter {
90
+ phaseHistory?: DucCharterPhaseChange[];
83
91
  title: string;
84
92
  /** Orientation: what kind of project this is and the context needed to read the charter */
85
93
  description?: string;
@@ -126,6 +126,8 @@ export type DucGlobalState = {
126
126
  * The background color of the drawing
127
127
  */
128
128
  viewBackgroundColor: string;
129
+ /** Use this drawing’s background color across themes. */
130
+ lockBackgroundColor: boolean;
129
131
  };
130
132
  export type DucLocalState = {
131
133
  scrollX: number;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Memory-compact replacement for three-cad-viewer's id-picking ComponentRegistry.
3
+ *
4
+ * The stock registry stores a record per face, edge and vertex whose `path` is a
5
+ * freshly concatenated `${nodePath}/faces/faces_${i}` string, and indexes every
6
+ * record by that string. Node paths are the full assembly path, so a dense model
7
+ * retains hundreds of thousands of ~200-byte strings (80+ MB for a 360k-component
8
+ * tokamak assembly). This registry keeps the shared node path plus the component
9
+ * index and derives `path` / `name` on demand, exposing the same interface.
10
+ */
11
+ type ComponentTopo = "face" | "edge" | "vertex";
12
+ interface ComponentInfo {
13
+ path: string;
14
+ name: string;
15
+ topo: string;
16
+ subtype?: string | null;
17
+ solidPath?: string | null;
18
+ }
19
+ type ComponentRecord = ComponentInfo & {
20
+ id: number;
21
+ };
22
+ declare class CompactComponent {
23
+ readonly id: number;
24
+ readonly topo: ComponentTopo;
25
+ readonly index: number;
26
+ readonly nodePath: string;
27
+ readonly subtype: string | null;
28
+ readonly solidPath: string | null;
29
+ constructor(id: number, topo: ComponentTopo, index: number, nodePath: string, subtype: string | null, solidPath: string | null);
30
+ get path(): string;
31
+ get name(): string;
32
+ }
33
+ export declare class CompactComponentRegistry {
34
+ private records;
35
+ private ordered;
36
+ private byNode;
37
+ private byPath;
38
+ private nextId;
39
+ register(info: ComponentInfo): number;
40
+ get(id: number): ComponentRecord | CompactComponent | undefined;
41
+ getByPath(path: string): ComponentRecord | CompactComponent | undefined;
42
+ entries(): IterableIterator<ComponentRecord | CompactComponent>;
43
+ get maxId(): number;
44
+ get size(): number;
45
+ removeByPathPrefix(prefix: string): void;
46
+ clear(): void;
47
+ /**
48
+ * Solid components are registered with `solidPath` set to their node path, so the
49
+ * shared node string can be reused without flattening the concatenated `path`.
50
+ * The length check confirms `path === ${solidPath}/${segment}/${name}` in O(1).
51
+ */
52
+ private toCompact;
53
+ }
54
+ /**
55
+ * Makes every id-picking scene built by this three-cad-viewer module use
56
+ * {@link CompactComponentRegistry}. The registry class is internal, so the
57
+ * nested group class is discovered through an empty, GPU-free tessellation and
58
+ * its `render` swaps in the compact registry before any component registers.
59
+ * Call after constructing a Viewer and before `viewer.render`. Returns false and
60
+ * leaves the viewer untouched when the internals do not match.
61
+ */
62
+ export declare function installCompactComponentRegistry(viewer: unknown): boolean;
63
+ export {};
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Memory-compact replacement for three-cad-viewer's id-picking ComponentRegistry.
3
+ *
4
+ * The stock registry stores a record per face, edge and vertex whose `path` is a
5
+ * freshly concatenated `${nodePath}/faces/faces_${i}` string, and indexes every
6
+ * record by that string. Node paths are the full assembly path, so a dense model
7
+ * retains hundreds of thousands of ~200-byte strings (80+ MB for a 360k-component
8
+ * tokamak assembly). This registry keeps the shared node path plus the component
9
+ * index and derives `path` / `name` on demand, exposing the same interface.
10
+ */
11
+ const TOPO_SEGMENTS = {
12
+ face: "faces",
13
+ edge: "edges",
14
+ vertex: "vertices",
15
+ };
16
+ const SEGMENT_TOPOS = {
17
+ faces: "face",
18
+ edges: "edge",
19
+ vertices: "vertex",
20
+ };
21
+ const COMPONENT_PATH = /^(.*)\/(faces|edges|vertices)\/\2_(\d+)$/;
22
+ class CompactComponent {
23
+ constructor(id, topo, index, nodePath, subtype, solidPath) {
24
+ this.id = id;
25
+ this.topo = topo;
26
+ this.index = index;
27
+ this.nodePath = nodePath;
28
+ this.subtype = subtype;
29
+ this.solidPath = solidPath;
30
+ }
31
+ get path() {
32
+ const segment = TOPO_SEGMENTS[this.topo];
33
+ return `${this.nodePath}/${segment}/${segment}_${this.index}`;
34
+ }
35
+ get name() {
36
+ return `${TOPO_SEGMENTS[this.topo]}_${this.index}`;
37
+ }
38
+ }
39
+ export class CompactComponentRegistry {
40
+ constructor() {
41
+ this.records = [];
42
+ // Dense id-ordered list: hover and selection walk every component per pointer move.
43
+ this.ordered = [];
44
+ this.byNode = new Map();
45
+ this.byPath = new Map();
46
+ this.nextId = 1;
47
+ }
48
+ register(info) {
49
+ var _a, _b;
50
+ var _c;
51
+ const id = this.nextId;
52
+ this.nextId += 1;
53
+ const compact = this.toCompact(id, info);
54
+ if (compact) {
55
+ this.records[id] = compact;
56
+ this.ordered.push(compact);
57
+ const node = (_a = this.byNode.get(compact.nodePath)) !== null && _a !== void 0 ? _a : {};
58
+ ((_b = node[_c = compact.topo]) !== null && _b !== void 0 ? _b : (node[_c] = []))[compact.index] = id;
59
+ this.byNode.set(compact.nodePath, node);
60
+ }
61
+ else {
62
+ const record = Object.assign(Object.assign({}, info), { id });
63
+ this.records[id] = record;
64
+ this.ordered.push(record);
65
+ this.byPath.set(record.path, record);
66
+ }
67
+ return id;
68
+ }
69
+ get(id) {
70
+ return this.records[id];
71
+ }
72
+ getByPath(path) {
73
+ var _a, _b;
74
+ const match = COMPONENT_PATH.exec(path);
75
+ if (match) {
76
+ const id = (_b = (_a = this.byNode.get(match[1])) === null || _a === void 0 ? void 0 : _a[SEGMENT_TOPOS[match[2]]]) === null || _b === void 0 ? void 0 : _b[Number(match[3])];
77
+ const record = id === undefined ? undefined : this.records[id];
78
+ if (record)
79
+ return record;
80
+ }
81
+ return this.byPath.get(path);
82
+ }
83
+ entries() {
84
+ return this.ordered.values();
85
+ }
86
+ get maxId() {
87
+ return this.nextId - 1;
88
+ }
89
+ get size() {
90
+ return this.ordered.length;
91
+ }
92
+ removeByPathPrefix(prefix) {
93
+ const sub = `${prefix}/`;
94
+ this.ordered = this.ordered.filter((record) => {
95
+ var _a;
96
+ const path = record.path;
97
+ if (path !== prefix && !path.startsWith(sub))
98
+ return true;
99
+ this.records[record.id] = undefined;
100
+ if (record instanceof CompactComponent) {
101
+ const ids = (_a = this.byNode.get(record.nodePath)) === null || _a === void 0 ? void 0 : _a[record.topo];
102
+ if ((ids === null || ids === void 0 ? void 0 : ids[record.index]) === record.id)
103
+ delete ids[record.index];
104
+ }
105
+ else if (this.byPath.get(path) === record) {
106
+ this.byPath.delete(path);
107
+ }
108
+ return false;
109
+ });
110
+ }
111
+ clear() {
112
+ this.records = [];
113
+ this.ordered = [];
114
+ this.byNode.clear();
115
+ this.byPath.clear();
116
+ this.nextId = 1;
117
+ }
118
+ /**
119
+ * Solid components are registered with `solidPath` set to their node path, so the
120
+ * shared node string can be reused without flattening the concatenated `path`.
121
+ * The length check confirms `path === ${solidPath}/${segment}/${name}` in O(1).
122
+ */
123
+ toCompact(id, info) {
124
+ var _a;
125
+ const topo = info.topo;
126
+ const segment = TOPO_SEGMENTS[topo];
127
+ const nodePath = info.solidPath;
128
+ if (!segment || !nodePath || !info.name.startsWith(`${segment}_`))
129
+ return null;
130
+ const index = Number(info.name.slice(segment.length + 1));
131
+ if (!Number.isSafeInteger(index) || index < 0)
132
+ return null;
133
+ if (info.path.length !== nodePath.length + segment.length + info.name.length + 2)
134
+ return null;
135
+ return new CompactComponent(id, topo, index, nodePath, (_a = info.subtype) !== null && _a !== void 0 ? _a : null, nodePath);
136
+ }
137
+ }
138
+ const installedPrototypes = new WeakSet();
139
+ const REGISTRY_PROBE_SHAPES = {
140
+ version: 3,
141
+ id: "/__registry_probe",
142
+ name: "__registry_probe",
143
+ loc: [[0, 0, 0], [0, 0, 0, 1]],
144
+ parts: [],
145
+ };
146
+ /**
147
+ * Makes every id-picking scene built by this three-cad-viewer module use
148
+ * {@link CompactComponentRegistry}. The registry class is internal, so the
149
+ * nested group class is discovered through an empty, GPU-free tessellation and
150
+ * its `render` swaps in the compact registry before any component registers.
151
+ * Call after constructing a Viewer and before `viewer.render`. Returns false and
152
+ * leaves the viewer untouched when the internals do not match.
153
+ */
154
+ export function installCompactComponentRegistry(viewer) {
155
+ var _a, _b, _c, _d, _e;
156
+ try {
157
+ const renderer = (_b = (_a = viewer).getShapeRenderer) === null || _b === void 0 ? void 0 : _b.call(_a);
158
+ const probe = (_c = renderer === null || renderer === void 0 ? void 0 : renderer._renderTessellatedShapes) === null || _c === void 0 ? void 0 : _c.call(renderer, structuredClone(REGISTRY_PROBE_SHAPES), false);
159
+ const proto = probe ? Object.getPrototypeOf(probe) : null;
160
+ (_d = probe === null || probe === void 0 ? void 0 : probe.dispose) === null || _d === void 0 ? void 0 : _d.call(probe);
161
+ if (!proto || typeof proto.render !== "function" || typeof ((_e = probe === null || probe === void 0 ? void 0 : probe.registry) === null || _e === void 0 ? void 0 : _e.register) !== "function") {
162
+ return false;
163
+ }
164
+ if (installedPrototypes.has(proto))
165
+ return true;
166
+ const render = proto.render;
167
+ proto.render = function renderWithCompactRegistry(...args) {
168
+ var _a;
169
+ if (this.assignIds && !(this.registry instanceof CompactComponentRegistry) && ((_a = this.registry) === null || _a === void 0 ? void 0 : _a.size) === 0) {
170
+ this.registry = new CompactComponentRegistry();
171
+ }
172
+ return render.apply(this, args);
173
+ };
174
+ installedPrototypes.add(proto);
175
+ return true;
176
+ }
177
+ catch (_f) {
178
+ return false;
179
+ }
180
+ }
@@ -0,0 +1,38 @@
1
+ type Track = {
2
+ path: string;
3
+ action: string;
4
+ times: number[];
5
+ values: (number | number[])[];
6
+ };
7
+ type Motion = {
8
+ animation: Track[];
9
+ explode: Track[];
10
+ ifc: boolean;
11
+ };
12
+ type Viewer = {
13
+ state?: {
14
+ get(key: any): unknown;
15
+ };
16
+ rendered?: {
17
+ nestedGroup?: {
18
+ groups?: Record<string, unknown>;
19
+ };
20
+ };
21
+ hasAnimation?(): boolean;
22
+ backupAnimation?(): void;
23
+ restoreAnimation?(): void;
24
+ clearAnimation?(): void;
25
+ explode?(duration: number, speed: number, multiplier: number): void;
26
+ setExplode?(active: boolean): void;
27
+ initAnimation?(duration: number, speed: number, label: string, repeat: boolean): void;
28
+ addPositionTrack?(path: string, times: number[], values: number[][]): void;
29
+ addQuaternionTrack?(path: string, times: number[], values: number[][]): void;
30
+ addTranslationTrack?(path: string, axis: any, times: number[], values: number[]): void;
31
+ addRotationTrack?(path: string, axis: any, times: number[], values: number[]): void;
32
+ setRelativeTime?(fraction: number): void;
33
+ update?(marker: boolean): void;
34
+ };
35
+ export declare function readModelMotion(payload: any): Motion;
36
+ export declare function configureModelMotion(viewer: Viewer, payload: unknown): void;
37
+ export declare function applyModelExplode(viewer: Viewer, active: boolean, value: number): void;
38
+ export {};
@@ -0,0 +1,160 @@
1
+ const motions = new WeakMap();
2
+ const activeExplosions = new WeakSet();
3
+ function tracks(input) {
4
+ if (!Array.isArray(input))
5
+ return [];
6
+ return input.flatMap((raw) => {
7
+ var _a;
8
+ if (!raw || typeof raw !== "object")
9
+ return [];
10
+ const [path, action, times, values] = Array.isArray(raw)
11
+ ? raw
12
+ : [(_a = raw.path) !== null && _a !== void 0 ? _a : raw.selector, raw.action, raw.times, raw.values];
13
+ if (typeof path !== "string" ||
14
+ !["t", "q", "tx", "ty", "tz", "rx", "ry", "rz"].includes(action) ||
15
+ !Array.isArray(times) ||
16
+ times.length < 2 ||
17
+ !times.every((n, i) => Number.isFinite(n) && n >= 0 && (!i || n > times[i - 1])) ||
18
+ !Array.isArray(values) ||
19
+ values.length !== times.length)
20
+ return [];
21
+ const width = action === "t" ? 3 : action === "q" ? 4 : 0;
22
+ if (!values.every((v) => width
23
+ ? Array.isArray(v) && v.length === width && v.every(Number.isFinite)
24
+ : Number.isFinite(v)))
25
+ return [];
26
+ return [{ path, action, times, values }];
27
+ });
28
+ }
29
+ function explodeDirections(input) {
30
+ if (!input || typeof input !== "object")
31
+ return [];
32
+ const entries = Array.isArray(input)
33
+ ? input
34
+ : Object.entries(input).map(([path, direction]) => ({ path, direction }));
35
+ return entries.flatMap((entry) => {
36
+ var _a;
37
+ const vector = entry === null || entry === void 0 ? void 0 : entry.direction;
38
+ const distance = (_a = entry === null || entry === void 0 ? void 0 : entry.distance) !== null && _a !== void 0 ? _a : 1;
39
+ if (typeof (entry === null || entry === void 0 ? void 0 : entry.path) !== "string" ||
40
+ !Array.isArray(vector) ||
41
+ vector.length !== 3 ||
42
+ !vector.every(Number.isFinite) ||
43
+ !Number.isFinite(distance))
44
+ return [];
45
+ return [
46
+ {
47
+ path: entry.path,
48
+ action: "t",
49
+ times: [0, 1],
50
+ values: [[0, 0, 0], vector.map((n) => n * distance)],
51
+ },
52
+ ];
53
+ });
54
+ }
55
+ export function readModelMotion(payload) {
56
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
57
+ const root = (_a = payload === null || payload === void 0 ? void 0 : payload.shapes) !== null && _a !== void 0 ? _a : payload;
58
+ const metadata = (_b = payload === null || payload === void 0 ? void 0 : payload.metadata) !== null && _b !== void 0 ? _b : root === null || root === void 0 ? void 0 : root.metadata;
59
+ const animation = (_d = (_c = payload === null || payload === void 0 ? void 0 : payload.animation) !== null && _c !== void 0 ? _c : metadata === null || metadata === void 0 ? void 0 : metadata.animation) !== null && _d !== void 0 ? _d : root === null || root === void 0 ? void 0 : root.animation;
60
+ const explode = (_f = (_e = payload === null || payload === void 0 ? void 0 : payload.explode) !== null && _e !== void 0 ? _e : metadata === null || metadata === void 0 ? void 0 : metadata.explode) !== null && _f !== void 0 ? _f : root === null || root === void 0 ? void 0 : root.explode;
61
+ const ifc = (metadata === null || metadata === void 0 ? void 0 : metadata.source) === "ifcopenshell" || (root === null || root === void 0 ? void 0 : root.id) === "ifc-model";
62
+ const animationTracks = tracks((_k = (_j = (_h = (_g = animation === null || animation === void 0 ? void 0 : animation.tracks) !== null && _g !== void 0 ? _g : animation === null || animation === void 0 ? void 0 : animation.data) !== null && _h !== void 0 ? _h : animation) !== null && _j !== void 0 ? _j : payload === null || payload === void 0 ? void 0 : payload.tracks) !== null && _k !== void 0 ? _k : root === null || root === void 0 ? void 0 : root.tracks);
63
+ const speed = (_l = animation === null || animation === void 0 ? void 0 : animation.speed) !== null && _l !== void 0 ? _l : (_m = animation === null || animation === void 0 ? void 0 : animation.config) === null || _m === void 0 ? void 0 : _m.speed;
64
+ if (Number.isFinite(speed) && speed > 0 && speed !== 1) {
65
+ for (const track of animationTracks)
66
+ track.times = track.times.map((time) => time / speed);
67
+ }
68
+ const explodeTracks = [
69
+ ...tracks((_o = explode === null || explode === void 0 ? void 0 : explode.tracks) !== null && _o !== void 0 ? _o : explode),
70
+ ...explodeDirections(explode === null || explode === void 0 ? void 0 : explode.directions),
71
+ ];
72
+ if (!ifc || (!animationTracks.length && !explodeTracks.length)) {
73
+ return { animation: animationTracks, explode: explodeTracks, ifc };
74
+ }
75
+ // A single IFC product can tessellate into separate groups for each material.
76
+ const products = new Map();
77
+ const visit = (part) => {
78
+ var _a;
79
+ if ((part === null || part === void 0 ? void 0 : part.ifc) && typeof part.id === "string") {
80
+ for (const key of new Set([
81
+ part.ifc.globalId,
82
+ String(part.ifc.expressID),
83
+ ])) {
84
+ if (!key)
85
+ continue;
86
+ const paths = (_a = products.get(key)) !== null && _a !== void 0 ? _a : [];
87
+ paths.push(part.id);
88
+ products.set(key, paths);
89
+ }
90
+ }
91
+ if (Array.isArray(part === null || part === void 0 ? void 0 : part.parts))
92
+ part.parts.forEach(visit);
93
+ };
94
+ visit(root);
95
+ const resolve = (list) => list.flatMap((track) => {
96
+ var _a;
97
+ return ((_a = products.get(track.path)) !== null && _a !== void 0 ? _a : [track.path]).map((path) => (Object.assign(Object.assign({}, track), { path })));
98
+ });
99
+ return {
100
+ animation: resolve(animationTracks),
101
+ explode: resolve(explodeTracks),
102
+ ifc,
103
+ };
104
+ }
105
+ function applyTracks(viewer, list, explosion) {
106
+ var _a, _b, _c, _d, _e, _f, _g;
107
+ let duration = 0;
108
+ const groups = (_b = (_a = viewer.rendered) === null || _a === void 0 ? void 0 : _a.nestedGroup) === null || _b === void 0 ? void 0 : _b.groups;
109
+ for (const { path, action, times, values } of list) {
110
+ if (groups && !Object.prototype.hasOwnProperty.call(groups, path))
111
+ continue;
112
+ if (action === "q")
113
+ (_c = viewer.addQuaternionTrack) === null || _c === void 0 ? void 0 : _c.call(viewer, path, times, values);
114
+ else if (action === "t")
115
+ (_d = viewer.addPositionTrack) === null || _d === void 0 ? void 0 : _d.call(viewer, path, times, values.map((v) => v.map((n) => n * (explosion ? 3 : 1))));
116
+ else if (action[0] === "t")
117
+ (_e = viewer.addTranslationTrack) === null || _e === void 0 ? void 0 : _e.call(viewer, path, action[1], times, values.map((n) => n * (explosion ? 3 : 1)));
118
+ else
119
+ (_f = viewer.addRotationTrack) === null || _f === void 0 ? void 0 : _f.call(viewer, path, action[1], times, values);
120
+ duration = Math.max(duration, times[times.length - 1]);
121
+ }
122
+ if (duration)
123
+ (_g = viewer.initAnimation) === null || _g === void 0 ? void 0 : _g.call(viewer, duration, 1, explosion ? "E" : "A", false);
124
+ return duration;
125
+ }
126
+ export function configureModelMotion(viewer, payload) {
127
+ var _a;
128
+ activeExplosions.delete(viewer);
129
+ const motion = readModelMotion(payload);
130
+ if (motions.has(viewer) || motion.animation.length)
131
+ (_a = viewer.clearAnimation) === null || _a === void 0 ? void 0 : _a.call(viewer);
132
+ motions.set(viewer, motion);
133
+ if (motion.animation.length)
134
+ applyTracks(viewer, motion.animation, false);
135
+ }
136
+ export function applyModelExplode(viewer, active, value) {
137
+ var _a, _b, _c, _d, _e, _f, _g;
138
+ const config = motions.get(viewer);
139
+ if (!active || ((config === null || config === void 0 ? void 0 : config.ifc) && !config.explode.length)) {
140
+ if (activeExplosions.delete(viewer) ||
141
+ ((_a = viewer.state) === null || _a === void 0 ? void 0 : _a.get("animationMode")) === "explode")
142
+ (_b = viewer.setExplode) === null || _b === void 0 ? void 0 : _b.call(viewer, false);
143
+ return;
144
+ }
145
+ if (!activeExplosions.has(viewer)) {
146
+ if ((_c = viewer.hasAnimation) === null || _c === void 0 ? void 0 : _c.call(viewer))
147
+ (_d = viewer.backupAnimation) === null || _d === void 0 ? void 0 : _d.call(viewer);
148
+ if (config === null || config === void 0 ? void 0 : config.explode.length) {
149
+ (_e = viewer.clearAnimation) === null || _e === void 0 ? void 0 : _e.call(viewer);
150
+ applyTracks(viewer, config.explode, true);
151
+ }
152
+ // Upstream displaces by (multiplier - 1). Its default 2.5 gives 1.5 at 100%.
153
+ else if (viewer.explode)
154
+ viewer.explode(2, 1, 5.5);
155
+ else
156
+ (_f = viewer.setExplode) === null || _f === void 0 ? void 0 : _f.call(viewer, true);
157
+ activeExplosions.add(viewer);
158
+ }
159
+ (_g = viewer.setRelativeTime) === null || _g === void 0 ? void 0 : _g.call(viewer, Math.min(3, Math.max(0, value)) / 3);
160
+ }