three-cad-viewer 4.3.4 → 4.3.6

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 (59) hide show
  1. package/dist/scene/clipping.d.ts +6 -0
  2. package/dist/three-cad-viewer.esm.js +20 -5
  3. package/dist/three-cad-viewer.esm.js.map +1 -1
  4. package/dist/three-cad-viewer.esm.min.js +1 -1
  5. package/dist/three-cad-viewer.js +20 -5
  6. package/dist/three-cad-viewer.min.js +1 -1
  7. package/package.json +2 -3
  8. package/src/_version.ts +0 -1
  9. package/src/camera/camera.ts +0 -445
  10. package/src/camera/controls/CADOrbitControls.ts +0 -241
  11. package/src/camera/controls/CADTrackballControls.ts +0 -598
  12. package/src/camera/controls.ts +0 -380
  13. package/src/core/patches.ts +0 -16
  14. package/src/core/studio-manager.ts +0 -652
  15. package/src/core/types.ts +0 -892
  16. package/src/core/viewer-state.ts +0 -784
  17. package/src/core/viewer.ts +0 -4821
  18. package/src/index.ts +0 -151
  19. package/src/rendering/environment.ts +0 -840
  20. package/src/rendering/light-detection.ts +0 -327
  21. package/src/rendering/material-factory.ts +0 -735
  22. package/src/rendering/material-presets.ts +0 -289
  23. package/src/rendering/raycast.ts +0 -291
  24. package/src/rendering/room-environment.ts +0 -192
  25. package/src/rendering/studio-composer.ts +0 -577
  26. package/src/rendering/studio-floor.ts +0 -108
  27. package/src/rendering/texture-cache.ts +0 -324
  28. package/src/rendering/tree-model.ts +0 -542
  29. package/src/rendering/triplanar.ts +0 -329
  30. package/src/scene/animation.ts +0 -343
  31. package/src/scene/axes.ts +0 -108
  32. package/src/scene/bbox.ts +0 -223
  33. package/src/scene/clipping.ts +0 -640
  34. package/src/scene/grid.ts +0 -864
  35. package/src/scene/nestedgroup.ts +0 -1444
  36. package/src/scene/objectgroup.ts +0 -866
  37. package/src/scene/orientation.ts +0 -259
  38. package/src/scene/render-shape.ts +0 -634
  39. package/src/tools/cad_tools/measure.ts +0 -811
  40. package/src/tools/cad_tools/select.ts +0 -100
  41. package/src/tools/cad_tools/tools.ts +0 -231
  42. package/src/tools/cad_tools/ui.ts +0 -454
  43. package/src/tools/cad_tools/zebra.ts +0 -369
  44. package/src/types/html.d.ts +0 -5
  45. package/src/types/n8ao.d.ts +0 -28
  46. package/src/types/three-augmentation.d.ts +0 -60
  47. package/src/ui/display.ts +0 -3295
  48. package/src/ui/index.html +0 -505
  49. package/src/ui/info.ts +0 -177
  50. package/src/ui/slider.ts +0 -206
  51. package/src/ui/toolbar.ts +0 -347
  52. package/src/ui/treeview.ts +0 -945
  53. package/src/utils/decode-instances.ts +0 -233
  54. package/src/utils/font.ts +0 -60
  55. package/src/utils/gpu-tracker.ts +0 -265
  56. package/src/utils/logger.ts +0 -92
  57. package/src/utils/sizeof.ts +0 -116
  58. package/src/utils/timer.ts +0 -69
  59. package/src/utils/utils.ts +0 -446
package/src/scene/axes.ts DELETED
@@ -1,108 +0,0 @@
1
- import { LineSegments2 } from "three/examples/jsm/lines/LineSegments2.js";
2
- import { LineSegmentsGeometry } from "../core/patches.js";
3
- import { LineMaterial } from "three/examples/jsm/lines/LineMaterial.js";
4
- import type { Theme, AxisColorsFlatArray } from "../core/types";
5
-
6
- /**
7
- * Renders XYZ axes as colored line segments.
8
- * Extends LineSegments2 for thick line rendering.
9
- */
10
- class AxesHelper extends LineSegments2 {
11
- declare type: string;
12
- declare geometry: LineSegmentsGeometry;
13
- colors: AxisColorsFlatArray;
14
- center: number[];
15
-
16
- /**
17
- * Create an AxesHelper.
18
- * @param center - Origin point [x, y, z] for the axes.
19
- * @param size - Length of each axis in world units.
20
- * @param lineWidth - Line width in pixels.
21
- * @param width - Viewport width for material resolution.
22
- * @param height - Viewport height for material resolution.
23
- * @param axes0 - If true, position at origin; if false, at center.
24
- * @param visible - Initial visibility state.
25
- * @param theme - Color theme ("dark" or "light").
26
- */
27
- constructor(
28
- center: number[],
29
- size: number,
30
- lineWidth: number,
31
- width: number,
32
- height: number,
33
- axes0: boolean,
34
- visible: boolean,
35
- theme: Theme,
36
- ) {
37
- // prettier-ignore
38
- const vertices = new Float32Array([
39
- 0, 0, 0, size, 0, 0,
40
- 0, 0, 0, 0, size, 0,
41
- 0, 0, 0, 0, 0, size
42
- ]);
43
-
44
- const geometry = new LineSegmentsGeometry();
45
- geometry.setPositions(vertices);
46
-
47
- const material = new LineMaterial({
48
- vertexColors: true,
49
- toneMapped: false,
50
- linewidth: lineWidth,
51
- transparent: true,
52
- });
53
- material.resolution.set(width, height);
54
-
55
- super(geometry, material);
56
- // prettier-ignore
57
- this.colors = {
58
- dark:[
59
- 1, 69 / 255, 0, 1, 69 / 255, 0, // x
60
- 50 / 255, 205 / 255, 50 / 255, 50 / 255, 205 / 255, 50 / 255, // y
61
- 59 / 255, 158 / 255, 1, 59 / 255, 158 / 255, 1 // z
62
- ],
63
- light:[
64
- 1, 0, 0, 1, 0, 0, // x
65
- 0, 0.5, 0, 0, 0.5, 0, // y
66
- 0, 0, 1, 0, 0, 1 // z
67
- ]};
68
- geometry.setColors(new Float32Array(this.colors[theme]));
69
- this.geometry = geometry;
70
-
71
- this.center = center;
72
-
73
- this.type = "AxesHelper";
74
- this.name = "AxesHelper";
75
- this.visible = visible;
76
- this.setCenter(axes0);
77
- }
78
-
79
- /**
80
- * Set the axes position based on the axes0 flag.
81
- * @param axes0 - If true, position at origin; if false, at center.
82
- */
83
- setCenter(axes0: boolean): void {
84
- if (axes0) {
85
- this.position.set(0, 0, 0);
86
- } else {
87
- this.position.set(this.center[0], this.center[1], this.center[2]);
88
- }
89
- }
90
-
91
- /**
92
- * Set the visibility of the axes helper.
93
- * @param visible - Whether the axes should be visible.
94
- */
95
- setVisible(visible: boolean): void {
96
- this.visible = visible;
97
- }
98
-
99
- /**
100
- * Change the color theme of the axes.
101
- * @param theme - The theme name ("dark" or "light").
102
- */
103
- changeTheme(theme: Theme): void {
104
- this.geometry.setColors(new Float32Array(this.colors[theme]));
105
- }
106
- }
107
-
108
- export { AxesHelper };
package/src/scene/bbox.ts DELETED
@@ -1,223 +0,0 @@
1
- import * as THREE from "three";
2
- import type { Vector3Tuple } from "three";
3
- import { disposeGeometry, toVector3Tuple } from "../utils/utils.js";
4
- import { isObjectGroup } from "./objectgroup.js";
5
-
6
- /**
7
- * Get the geometry from an Object3D if it has one (Mesh, Line, Points).
8
- * @returns The BufferGeometry if present, null otherwise.
9
- */
10
- function getGeometry(object: THREE.Object3D): THREE.BufferGeometry | null {
11
- if ("geometry" in object && object.geometry instanceof THREE.BufferGeometry) {
12
- return object.geometry;
13
- }
14
- return null;
15
- }
16
-
17
- /**
18
- * Extended THREE.Box3 for CAD-specific bounding box calculations.
19
- * Handles ObjectGroup instances and excludes clipping plane meshes.
20
- */
21
- class BoundingBox extends THREE.Box3 {
22
- /**
23
- * Expand the bounding box to include an object.
24
- * For ObjectGroup instances, only the first mesh (faces) is considered.
25
- * Clipping plane meshes (PlaneMeshes/StencilPlane) are excluded.
26
- */
27
- expandByObject(object: THREE.Object3D, precise: boolean = false): this {
28
- object.updateWorldMatrix(false, false);
29
-
30
- if (isObjectGroup(object)) {
31
- // for ObjectGroups calculate bounding box of first Mesh only
32
- this.expandByObject(object.children[0], precise);
33
- return this;
34
- }
35
-
36
- const geometry = getGeometry(object);
37
- if (geometry !== null) {
38
- if (
39
- precise &&
40
- geometry.attributes !== undefined &&
41
- geometry.attributes.position !== undefined
42
- ) {
43
- if (object.type.startsWith("LineSegment")) {
44
- const g = geometry.clone();
45
- g.applyMatrix4(object.matrixWorld);
46
- g.boundingBox = null;
47
- g.computeBoundingBox();
48
- this.union(g.boundingBox!);
49
- g.dispose(); // Dispose cloned geometry to prevent memory leak
50
- } else {
51
- const position = geometry.attributes.position;
52
- for (let i = 0, l = position.count; i < l; i++) {
53
- _vector3
54
- .fromBufferAttribute(position, i)
55
- .applyMatrix4(object.matrixWorld);
56
- this.expandByPoint(_vector3);
57
- }
58
- }
59
- } else {
60
- if (geometry.boundingBox === null) {
61
- geometry.computeBoundingBox();
62
- }
63
- _bbox.copy(geometry.boundingBox!);
64
- _bbox.applyMatrix4(object.matrixWorld);
65
-
66
- this.union(_bbox);
67
- }
68
- }
69
-
70
- const children = object.children;
71
-
72
- for (let i = 0, l = children.length; i < l; i++) {
73
- const child = children[i];
74
- if (
75
- !(
76
- child.name === "PlaneMeshes" &&
77
- child.children &&
78
- child.children.length > 0 &&
79
- child.children[0].type.startsWith("StencilPlane")
80
- )
81
- ) {
82
- this.expandByObject(child, precise);
83
- }
84
- }
85
-
86
- return this;
87
- }
88
-
89
- /**
90
- * Calculate the maximum distance from the origin to any corner of the box.
91
- */
92
- max_dist_from_center(): number {
93
- return Math.max(
94
- ...this.min
95
- .toArray()
96
- .concat(this.max.toArray())
97
- .map((x) => Math.abs(x)),
98
- );
99
- }
100
-
101
- /**
102
- * Get the bounding sphere of this box.
103
- */
104
- boundingSphere(): THREE.Sphere {
105
- this.getBoundingSphere(_sphere);
106
- return _sphere;
107
- }
108
-
109
- /**
110
- * Get the center point of this box as an array.
111
- */
112
- center(): Vector3Tuple {
113
- this.getCenter(_vector3);
114
- return toVector3Tuple(_vector3.toArray());
115
- }
116
- }
117
-
118
- /**
119
- * Visual helper for displaying a bounding box as wireframe lines.
120
- * Extends THREE.LineSegments to render the 12 edges of a box.
121
- */
122
- class BoxHelper extends THREE.LineSegments {
123
- declare type: "BoxHelper";
124
- declare geometry: THREE.BufferGeometry & {
125
- attributes: { position: THREE.BufferAttribute };
126
- };
127
- object: THREE.Object3D | undefined;
128
-
129
- /**
130
- * Create a BoxHelper for visualizing an object's bounding box.
131
- */
132
- constructor(object: THREE.Object3D, color: number = 0xffff00) {
133
- const indices = new Uint16Array([
134
- 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7,
135
- ]);
136
- const positions = new Float32Array(8 * 3);
137
-
138
- const geometry = new THREE.BufferGeometry();
139
- geometry.setIndex(new THREE.BufferAttribute(indices, 1));
140
- geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
141
-
142
- super(
143
- geometry,
144
- new THREE.LineBasicMaterial({ color: color, toneMapped: false }),
145
- );
146
-
147
- this.object = object;
148
- this.type = "BoxHelper";
149
- this.matrixAutoUpdate = false;
150
-
151
- this.update();
152
- }
153
-
154
- /**
155
- * Update the helper geometry to match the current bounding box.
156
- * Should be called when the target object changes.
157
- */
158
- update(): void {
159
- if (this.object !== undefined) {
160
- _hbox.setFromObject(this.object, true);
161
- }
162
-
163
- if (_hbox.isEmpty()) return;
164
-
165
- const min = _hbox.min;
166
- const max = _hbox.max;
167
-
168
- const position = this.geometry.attributes.position;
169
- const array = position.array;
170
-
171
- array[0] = max.x;
172
- array[1] = max.y;
173
- array[2] = max.z;
174
- array[3] = min.x;
175
- array[4] = max.y;
176
- array[5] = max.z;
177
- array[6] = min.x;
178
- array[7] = min.y;
179
- array[8] = max.z;
180
- array[9] = max.x;
181
- array[10] = min.y;
182
- array[11] = max.z;
183
- array[12] = max.x;
184
- array[13] = max.y;
185
- array[14] = min.z;
186
- array[15] = min.x;
187
- array[16] = max.y;
188
- array[17] = min.z;
189
- array[18] = min.x;
190
- array[19] = min.y;
191
- array[20] = min.z;
192
- array[21] = max.x;
193
- array[22] = min.y;
194
- array[23] = min.z;
195
-
196
- position.needsUpdate = true;
197
- this.geometry.computeBoundingSphere();
198
- }
199
-
200
- /**
201
- * Set the target object and update the helper.
202
- */
203
- setFromObject(object: THREE.Object3D): this {
204
- this.object = object;
205
- this.update();
206
-
207
- return this;
208
- }
209
-
210
- /**
211
- * Dispose of geometry and material resources.
212
- */
213
- dispose(): void {
214
- disposeGeometry(this.geometry);
215
- }
216
- }
217
-
218
- const _vector3 = new THREE.Vector3();
219
- const _bbox = new BoundingBox();
220
- const _hbox = new BoundingBox();
221
- const _sphere = new THREE.Sphere();
222
-
223
- export { BoundingBox, BoxHelper };