three-cad-viewer 4.3.5 → 4.3.7

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.
Files changed (58) hide show
  1. package/dist/three-cad-viewer.esm.js +8 -5
  2. package/dist/three-cad-viewer.esm.js.map +1 -1
  3. package/dist/three-cad-viewer.esm.min.js +1 -1
  4. package/dist/three-cad-viewer.js +8 -5
  5. package/dist/three-cad-viewer.min.js +1 -1
  6. package/package.json +2 -3
  7. package/src/_version.ts +0 -1
  8. package/src/camera/camera.ts +0 -445
  9. package/src/camera/controls/CADOrbitControls.ts +0 -241
  10. package/src/camera/controls/CADTrackballControls.ts +0 -598
  11. package/src/camera/controls.ts +0 -380
  12. package/src/core/patches.ts +0 -16
  13. package/src/core/studio-manager.ts +0 -652
  14. package/src/core/types.ts +0 -892
  15. package/src/core/viewer-state.ts +0 -784
  16. package/src/core/viewer.ts +0 -4821
  17. package/src/index.ts +0 -151
  18. package/src/rendering/environment.ts +0 -840
  19. package/src/rendering/light-detection.ts +0 -327
  20. package/src/rendering/material-factory.ts +0 -735
  21. package/src/rendering/material-presets.ts +0 -289
  22. package/src/rendering/raycast.ts +0 -291
  23. package/src/rendering/room-environment.ts +0 -192
  24. package/src/rendering/studio-composer.ts +0 -577
  25. package/src/rendering/studio-floor.ts +0 -108
  26. package/src/rendering/texture-cache.ts +0 -324
  27. package/src/rendering/tree-model.ts +0 -542
  28. package/src/rendering/triplanar.ts +0 -329
  29. package/src/scene/animation.ts +0 -343
  30. package/src/scene/axes.ts +0 -108
  31. package/src/scene/bbox.ts +0 -223
  32. package/src/scene/clipping.ts +0 -650
  33. package/src/scene/grid.ts +0 -864
  34. package/src/scene/nestedgroup.ts +0 -1448
  35. package/src/scene/objectgroup.ts +0 -866
  36. package/src/scene/orientation.ts +0 -259
  37. package/src/scene/render-shape.ts +0 -634
  38. package/src/tools/cad_tools/measure.ts +0 -811
  39. package/src/tools/cad_tools/select.ts +0 -100
  40. package/src/tools/cad_tools/tools.ts +0 -231
  41. package/src/tools/cad_tools/ui.ts +0 -454
  42. package/src/tools/cad_tools/zebra.ts +0 -369
  43. package/src/types/html.d.ts +0 -5
  44. package/src/types/n8ao.d.ts +0 -28
  45. package/src/types/three-augmentation.d.ts +0 -60
  46. package/src/ui/display.ts +0 -3295
  47. package/src/ui/index.html +0 -505
  48. package/src/ui/info.ts +0 -177
  49. package/src/ui/slider.ts +0 -206
  50. package/src/ui/toolbar.ts +0 -347
  51. package/src/ui/treeview.ts +0 -945
  52. package/src/utils/decode-instances.ts +0 -233
  53. package/src/utils/font.ts +0 -60
  54. package/src/utils/gpu-tracker.ts +0 -265
  55. package/src/utils/logger.ts +0 -92
  56. package/src/utils/sizeof.ts +0 -116
  57. package/src/utils/timer.ts +0 -69
  58. package/src/utils/utils.ts +0 -446
@@ -1,454 +0,0 @@
1
- import { TopoFilter, Raycaster } from "../../rendering/raycast.js";
2
- import type { DisplayLike } from "./tools.js";
3
-
4
- /**
5
- * Type guard to check if a value is a number array of specific length.
6
- */
7
- function isNumberArray(value: unknown, length: number): value is number[] {
8
- return Array.isArray(value) && value.length === length && value.every((v) => typeof v === "number");
9
- }
10
-
11
- /**
12
- * Type guard to check if a value is a Record<string, number[]> (bounding box data).
13
- */
14
- function isBoundingBoxData(value: unknown): value is Record<string, number[]> {
15
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
16
- return false;
17
- }
18
- return Object.values(value).every((v) => isNumberArray(v, 3));
19
- }
20
-
21
- interface CallbackEntry {
22
- callback: EventListener;
23
- type: string;
24
- }
25
-
26
- /**
27
- * Format a key for display: lowercase and insert space before trailing digits.
28
- * e.g. "normal1" → "normal 1", "Point 1" → "point 1", "Distance" → "distance"
29
- */
30
- function formatKey(key: string): string {
31
- return key.toLowerCase().replace(/(\D)(\d+)$/, "$1 $2");
32
- }
33
-
34
- function createVectorRow(key: string, value: number[]): HTMLTableRowElement {
35
- const xyzColors = [
36
- "tcv_x_measure_val",
37
- "tcv_y_measure_val",
38
- "tcv_z_measure_val",
39
- ];
40
- const tr = document.createElement("tr");
41
- const th = document.createElement("th");
42
-
43
- th.textContent = formatKey(key);
44
- th.classList.add("tcv_measure_key");
45
- th.classList.add("tcv_measure_cell");
46
- tr.appendChild(th);
47
-
48
- const br1 = document.createElement("td");
49
- br1.textContent = "(";
50
- br1.classList.add("tcv_measure_cell_bracket");
51
- tr.appendChild(br1);
52
-
53
- for (let i = 0; i < 3; ++i) {
54
- const td = document.createElement("td");
55
- td.textContent = value[i].toFixed(3);
56
- td.classList.add("tcv_measure_val");
57
- td.classList.add("tcv_measure_cell");
58
- td.classList.add(xyzColors[i]);
59
- tr.appendChild(td);
60
- }
61
-
62
- const br2 = document.createElement("td");
63
- br2.textContent = ")";
64
- br2.classList.add("tcv_measure_cell_bracket");
65
- tr.appendChild(br2);
66
-
67
- return tr;
68
- }
69
-
70
- function createStringRow(key: string, value: string): HTMLTableRowElement {
71
- const tr = document.createElement("tr");
72
- const th = document.createElement("th");
73
- const td = document.createElement("td");
74
- th.textContent = formatKey(key);
75
- th.classList.add("tcv_measure_key");
76
- th.classList.add("tcv_measure_cell");
77
- tr.appendChild(th);
78
-
79
- td.textContent = value;
80
- td.classList.add("tcv_measure_val_center");
81
- td.classList.add("tcv_measure_cell");
82
- td.colSpan = 5;
83
- tr.appendChild(td);
84
-
85
- return tr;
86
- }
87
-
88
- function createValueRow(key: string, value: number, qualifier: string | null = null): HTMLTableRowElement {
89
- const tr = document.createElement("tr");
90
- const th = document.createElement("th");
91
- const td = document.createElement("td");
92
-
93
- th.textContent = formatKey(key);
94
- th.classList.add("tcv_measure_key");
95
- th.classList.add("tcv_measure_cell");
96
- tr.appendChild(th);
97
-
98
- for (let i = 0; i < 2; i++) {
99
- const empty = document.createElement("td");
100
- tr.appendChild(empty);
101
- }
102
-
103
- td.textContent = value.toFixed(3);
104
- td.classList.add("tcv_measure_val");
105
- td.classList.add("tcv_measure_cell");
106
- tr.appendChild(td);
107
-
108
- if (qualifier == null) {
109
- for (let i = 0; i < 2; i++) {
110
- const empty = document.createElement("td");
111
- tr.appendChild(empty);
112
- }
113
- } else {
114
- const qualText = document.createElement("td");
115
- qualText.textContent = `(${qualifier})`;
116
- qualText.classList.add("tcv_measure_cell");
117
- tr.appendChild(qualText);
118
- const empty = document.createElement("td");
119
- tr.appendChild(empty);
120
- }
121
- return tr;
122
- }
123
-
124
- abstract class Panel {
125
- display: DisplayLike;
126
- html: HTMLElement;
127
- finished: boolean;
128
- callbacks: CallbackEntry[];
129
-
130
- constructor(display: DisplayLike) {
131
- this.display = display;
132
- this.html = this.getHtmlElement();
133
- this.finished = false;
134
- this.callbacks = [];
135
- this.html.addEventListener("contextmenu", (ev) => {
136
- ev.preventDefault();
137
- });
138
- }
139
-
140
- private removeTable(): void {
141
- const table = this.html.getElementsByTagName("table");
142
- if (table.length > 0) {
143
- table[0].remove();
144
- }
145
- this.finished = false;
146
- }
147
-
148
- protected resetTable(): void {
149
- this.removeTable();
150
- }
151
-
152
- protected abstract getHtmlElement(): HTMLElement;
153
-
154
- /**
155
- * Show or hide the panel
156
- */
157
- show = (flag: boolean): void => {
158
- this.html.style.display = flag ? "inline-block" : "none";
159
- };
160
-
161
- /**
162
- * Get status of the panel
163
- */
164
- isVisible = (): boolean => {
165
- return this.html.style.display == "inline-block";
166
- };
167
-
168
- /**
169
- * Sets the position of the panel (with the top left corner at the specified coordinates)
170
- */
171
- relocate = (x: number | null, y: number | null): void => {
172
- this.html.style.left = `${x}px`;
173
- this.html.style.top = `${y}px`;
174
- };
175
-
176
- /**
177
- * Register a callback for a specific event type
178
- */
179
- registerCallback(eventType: string, callback: EventListener): void {
180
- this.callbacks.push({ callback: callback, type: eventType });
181
- this.html.addEventListener(eventType, callback);
182
- }
183
-
184
- dispose(): void {
185
- for (const callback of this.callbacks) {
186
- this.html.removeEventListener(callback.type, callback.callback);
187
- }
188
- }
189
- }
190
-
191
- /**
192
- * Skip list for technical fields that should not be rendered in panels.
193
- */
194
- const SKIP_KEYS = [
195
- "type", "tool_type", "subtype", "info",
196
- "refpoint", "refpoint1", "refpoint2",
197
- "shape_type", "geom_type", "groups", "result",
198
- ];
199
-
200
- /**
201
- * Render entries from a group object into a tbody.
202
- * If addSeparator is true, the first rendered row gets a top border.
203
- */
204
- function renderGroup(
205
- group: Record<string, unknown>,
206
- tbody: HTMLTableSectionElement,
207
- addSeparator: boolean,
208
- ): void {
209
- let firstRow = true;
210
- for (const key in group) {
211
- if (!Object.prototype.hasOwnProperty.call(group, key)) continue;
212
- if (SKIP_KEYS.includes(key.toLowerCase())) continue;
213
-
214
- const value = group[key];
215
-
216
- let tr: HTMLTableRowElement | undefined;
217
- if (key.toLowerCase() === "bb" && isBoundingBoxData(value)) {
218
- for (const bbKey in value) {
219
- const bbTr = createVectorRow(`bb ${bbKey}`, value[bbKey]);
220
- if (addSeparator && firstRow) {
221
- bbTr.classList.add("tcv_measure_cell_top_border");
222
- firstRow = false;
223
- }
224
- tbody.appendChild(bbTr);
225
- }
226
- } else if (isNumberArray(value, 3)) {
227
- tr = createVectorRow(key, value);
228
- } else if (typeof value === "number") {
229
- if (key.toLowerCase() === "distance") {
230
- const info = typeof group["info"] === "string" ? group["info"] : undefined;
231
- tr = createValueRow(key, value, info ?? null);
232
- } else {
233
- tr = createValueRow(key, value);
234
- }
235
- } else if (typeof value === "string") {
236
- tr = createStringRow(key, value);
237
- }
238
- if (tr) {
239
- if (addSeparator && firstRow) {
240
- tr.classList.add("tcv_measure_cell_top_border");
241
- }
242
- tbody.appendChild(tr);
243
- firstRow = false;
244
- }
245
- }
246
- }
247
-
248
- /**
249
- * Render groups into a tbody, or fall back to treating properties as a single group.
250
- */
251
- function renderGroups(
252
- properties: Record<string, unknown>,
253
- tbody: HTMLTableSectionElement,
254
- ): void {
255
- const groups = properties.result ?? properties.groups;
256
- if (Array.isArray(groups)) {
257
- for (let i = 0; i < groups.length; i++) {
258
- renderGroup(groups[i] as Record<string, unknown>, tbody, i > 0);
259
- }
260
- } else {
261
- renderGroup(properties, tbody, false);
262
- }
263
- }
264
-
265
- interface DistanceResponseData {
266
- result?: Record<string, unknown>[];
267
- groups?: Record<string, unknown>[];
268
- refpoint1?: number[];
269
- refpoint2?: number[];
270
- [key: string]: unknown;
271
- }
272
-
273
- class DistancePanel extends Panel {
274
- constructor(display: DisplayLike) {
275
- super(display);
276
- }
277
-
278
- protected getHtmlElement(): HTMLElement {
279
- return this.display.measurementPanels.distancePanel;
280
- }
281
-
282
- createTable(properties: DistanceResponseData): void {
283
- if (this.finished) return;
284
-
285
- this.resetTable();
286
-
287
- const table = document.createElement("table");
288
- table.classList.add("tcv_properties_table");
289
- const tbody = document.createElement("tbody");
290
- renderGroups(properties as Record<string, unknown>, tbody);
291
- table.appendChild(tbody);
292
- this.html.append(table);
293
- this.finished = true;
294
- }
295
- }
296
-
297
- interface PropertiesResponseData {
298
- result?: Record<string, unknown>[];
299
- groups?: Record<string, unknown>[];
300
- shape_type?: string;
301
- geom_type?: string;
302
- refpoint?: number[];
303
- [key: string]: unknown;
304
- }
305
-
306
- class PropertiesPanel extends Panel {
307
- constructor(display: DisplayLike) {
308
- super(display);
309
- }
310
-
311
- protected getHtmlElement(): HTMLElement {
312
- return this.display.measurementPanels.propertiesPanel;
313
- }
314
-
315
- private setSubHeader(text: string): void {
316
- this.html.getElementsByClassName("tcv_measure_subheader")[0].textContent =
317
- text;
318
- }
319
-
320
- createTable(properties: PropertiesResponseData): void {
321
- if (this.finished) return;
322
-
323
- this.resetTable();
324
-
325
- this.setSubHeader(
326
- `${properties["shape_type"] ?? ""} / ${properties["geom_type"] ?? ""}`,
327
- );
328
- const table = document.createElement("table");
329
- table.classList.add("tcv_properties_table");
330
- const tbody = document.createElement("tbody");
331
- renderGroups(properties as Record<string, unknown>, tbody);
332
- table.appendChild(tbody);
333
- this.html.append(table);
334
- this.finished = true;
335
- }
336
- }
337
-
338
- class FilterByDropDownMenu {
339
- private display: DisplayLike;
340
- private elements: DisplayLike["filterDropdown"];
341
- private raycaster: Raycaster | null;
342
-
343
- /**
344
- * Initialize a new filter drop down menu, it needs the raycast to update interactively the filter mode
345
- */
346
- constructor(display: DisplayLike) {
347
- this.display = display;
348
- this.elements = display.filterDropdown;
349
- this.elements.container.style.display = "none";
350
- this.raycaster = null;
351
- }
352
-
353
- /**
354
- * Set the raycaster to update the filter mode
355
- */
356
- setRaycaster(raycaster: Raycaster): void {
357
- this.raycaster = raycaster;
358
- }
359
-
360
- private setValue = (topoType: string): void => {
361
- if (this.raycaster != null) {
362
- this.elements.value.innerText = topoType;
363
- const key = topoType.toLowerCase();
364
- if (key === "none") {
365
- this.raycaster.filters.topoFilter = [TopoFilter.none];
366
- } else if (key in TopoFilter) {
367
- this.raycaster.filters.topoFilter = [
368
- TopoFilter[key as keyof typeof TopoFilter],
369
- ];
370
- }
371
- }
372
- };
373
-
374
- private toggleDropdown = (ev: Event | null): void => {
375
- if (ev != null) {
376
- ev.stopPropagation();
377
- }
378
- if (this.elements.dropdown.classList.contains("tcv_filter_dropdown_active")) {
379
- this.elements.dropdown.classList.remove("tcv_filter_dropdown_active");
380
- this.elements.icon.innerText = "⏶";
381
- } else {
382
- this.elements.dropdown.classList.add("tcv_filter_dropdown_active");
383
- this.elements.icon.innerText = "⏷";
384
- }
385
- };
386
-
387
- private closeDropdown = (ev: Event): void => {
388
- if (this.elements.dropdown.classList.contains("tcv_filter_dropdown_active")) {
389
- this.toggleDropdown(ev);
390
- }
391
- };
392
-
393
- private handleSelection = (ev: Event): void => {
394
- const target = ev.target;
395
- if (target instanceof HTMLElement) {
396
- this.setValue(target.innerText);
397
- this.toggleDropdown(ev);
398
- }
399
- };
400
-
401
- reset = (): void => {
402
- this.setValue("None");
403
- };
404
-
405
- private keybindSelect = (e: KeyboardEvent): void => {
406
- const validKeys = ["n", "v", "e", "f", "s", "Escape"];
407
- if (validKeys.indexOf(e.key) === -1) return;
408
- if (e.key == "n") this.setValue("None");
409
- else if (e.key == "v") this.setValue("Vertex");
410
- else if (e.key == "e") this.setValue("Edge");
411
- else if (e.key == "f") this.setValue("Face");
412
- else if (e.key == "s") this.setValue("Solid");
413
- else if (e.key == "Escape") this.closeDropdown(e);
414
- };
415
-
416
- private getOptionElements(): HTMLElement[] {
417
- const opts = this.elements.options;
418
- return [opts.none, opts.vertex, opts.edge, opts.face, opts.solid];
419
- }
420
-
421
- /**
422
- * Show or hide the drop down menu
423
- */
424
- show(flag: boolean): void {
425
- if (flag) {
426
- // Use document-level listener for keyboard shortcuts (container div can't receive focus)
427
- document.addEventListener("keydown", this.keybindSelect as EventListener);
428
- this.display.container.addEventListener("click", this.closeDropdown);
429
-
430
- this.elements.content.addEventListener("click", this.toggleDropdown as EventListener);
431
-
432
- for (const el of this.getOptionElements()) {
433
- el.addEventListener("click", this.handleSelection);
434
- }
435
- } else {
436
- document.removeEventListener(
437
- "keydown",
438
- this.keybindSelect as EventListener,
439
- );
440
- this.display.container.removeEventListener("click", this.closeDropdown);
441
-
442
- this.elements.content.removeEventListener("click", this.toggleDropdown as EventListener);
443
-
444
- for (const el of this.getOptionElements()) {
445
- el.removeEventListener("click", this.handleSelection);
446
- }
447
- }
448
-
449
- this.elements.container.style.display = flag ? "block" : "none";
450
- }
451
- }
452
-
453
- export { FilterByDropDownMenu, DistancePanel, PropertiesPanel };
454
- export type { DistanceResponseData, PropertiesResponseData };