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.
- package/dist/three-cad-viewer.esm.js +8 -5
- package/dist/three-cad-viewer.esm.js.map +1 -1
- package/dist/three-cad-viewer.esm.min.js +1 -1
- package/dist/three-cad-viewer.js +8 -5
- package/dist/three-cad-viewer.min.js +1 -1
- package/package.json +2 -3
- package/src/_version.ts +0 -1
- package/src/camera/camera.ts +0 -445
- package/src/camera/controls/CADOrbitControls.ts +0 -241
- package/src/camera/controls/CADTrackballControls.ts +0 -598
- package/src/camera/controls.ts +0 -380
- package/src/core/patches.ts +0 -16
- package/src/core/studio-manager.ts +0 -652
- package/src/core/types.ts +0 -892
- package/src/core/viewer-state.ts +0 -784
- package/src/core/viewer.ts +0 -4821
- package/src/index.ts +0 -151
- package/src/rendering/environment.ts +0 -840
- package/src/rendering/light-detection.ts +0 -327
- package/src/rendering/material-factory.ts +0 -735
- package/src/rendering/material-presets.ts +0 -289
- package/src/rendering/raycast.ts +0 -291
- package/src/rendering/room-environment.ts +0 -192
- package/src/rendering/studio-composer.ts +0 -577
- package/src/rendering/studio-floor.ts +0 -108
- package/src/rendering/texture-cache.ts +0 -324
- package/src/rendering/tree-model.ts +0 -542
- package/src/rendering/triplanar.ts +0 -329
- package/src/scene/animation.ts +0 -343
- package/src/scene/axes.ts +0 -108
- package/src/scene/bbox.ts +0 -223
- package/src/scene/clipping.ts +0 -650
- package/src/scene/grid.ts +0 -864
- package/src/scene/nestedgroup.ts +0 -1448
- package/src/scene/objectgroup.ts +0 -866
- package/src/scene/orientation.ts +0 -259
- package/src/scene/render-shape.ts +0 -634
- package/src/tools/cad_tools/measure.ts +0 -811
- package/src/tools/cad_tools/select.ts +0 -100
- package/src/tools/cad_tools/tools.ts +0 -231
- package/src/tools/cad_tools/ui.ts +0 -454
- package/src/tools/cad_tools/zebra.ts +0 -369
- package/src/types/html.d.ts +0 -5
- package/src/types/n8ao.d.ts +0 -28
- package/src/types/three-augmentation.d.ts +0 -60
- package/src/ui/display.ts +0 -3295
- package/src/ui/index.html +0 -505
- package/src/ui/info.ts +0 -177
- package/src/ui/slider.ts +0 -206
- package/src/ui/toolbar.ts +0 -347
- package/src/ui/treeview.ts +0 -945
- package/src/utils/decode-instances.ts +0 -233
- package/src/utils/font.ts +0 -60
- package/src/utils/gpu-tracker.ts +0 -265
- package/src/utils/logger.ts +0 -92
- package/src/utils/sizeof.ts +0 -116
- package/src/utils/timer.ts +0 -69
- package/src/utils/utils.ts +0 -446
package/src/camera/controls.ts
DELETED
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
|
-
|
|
3
|
-
import { CADOrbitControls } from "./controls/CADOrbitControls.js";
|
|
4
|
-
import { CADTrackballControls } from "./controls/CADTrackballControls.js";
|
|
5
|
-
import type { ControlType } from "../core/types";
|
|
6
|
-
|
|
7
|
-
// Internal normalization factors for user-facing speed settings (1.0 = default experience)
|
|
8
|
-
// TrackballControls and OrbitControls have different internal scaling, so we normalize separately
|
|
9
|
-
const SPEED_FACTORS: Record<
|
|
10
|
-
ControlType,
|
|
11
|
-
{ pan: number; rotate: number; zoom: number }
|
|
12
|
-
> = {
|
|
13
|
-
trackball: {
|
|
14
|
-
pan: 0.22,
|
|
15
|
-
rotate: 1.0,
|
|
16
|
-
zoom: 2.0,
|
|
17
|
-
},
|
|
18
|
-
orbit: {
|
|
19
|
-
pan: 1.0,
|
|
20
|
-
rotate: 1.0,
|
|
21
|
-
zoom: 1.0,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ControlsInstance = CADOrbitControls | CADTrackballControls;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Unified camera controls supporting both orbit and trackball modes.
|
|
29
|
-
*
|
|
30
|
-
* Controls wraps CADOrbitControls and CADTrackballControls, providing:
|
|
31
|
-
* - Consistent API regardless of control type
|
|
32
|
-
* - Normalized speed settings (1.0 = default experience)
|
|
33
|
-
* - State saving/restoring for reset functionality
|
|
34
|
-
* - Camera switching support
|
|
35
|
-
*
|
|
36
|
-
* ## Control Types
|
|
37
|
-
* - `"orbit"`: OrbitControls - familiar Google Maps style rotation
|
|
38
|
-
* - `"trackball"`: TrackballControls - unrestricted rotation with optional Holroyd mode
|
|
39
|
-
*
|
|
40
|
-
* ## Holroyd Mode
|
|
41
|
-
* When enabled for trackball controls, prevents tumbling by keeping
|
|
42
|
-
* the up vector stable. This provides a more intuitive CAD experience.
|
|
43
|
-
*
|
|
44
|
-
* @internal - This is an internal class used by Viewer
|
|
45
|
-
*/
|
|
46
|
-
class Controls {
|
|
47
|
-
type: ControlType;
|
|
48
|
-
camera: THREE.Camera;
|
|
49
|
-
target: THREE.Vector3;
|
|
50
|
-
target0: THREE.Vector3;
|
|
51
|
-
domElement: HTMLElement;
|
|
52
|
-
rotateSpeed: number;
|
|
53
|
-
zoomSpeed: number;
|
|
54
|
-
panSpeed: number;
|
|
55
|
-
holroyd: boolean;
|
|
56
|
-
controls!: ControlsInstance; // Initialized in constructor via initOrbitControls/initTrackballControls
|
|
57
|
-
currentUpdateCallback: (() => void) | null;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Create Camera Controls.
|
|
61
|
-
* @param type - Type of controls: "orbit", "trackball".
|
|
62
|
-
* @param camera - The camera object.
|
|
63
|
-
* @param target - The lookAt target for the camera.
|
|
64
|
-
* @param domElement - The dom element of the rendering canvas.
|
|
65
|
-
* @param rotateSpeed - Speed for rotating.
|
|
66
|
-
* @param zoomSpeed - Speed for zooming.
|
|
67
|
-
* @param panSpeed - Speed for panning.
|
|
68
|
-
* @param holroyd - Enable holroyd (non-tumbling) mode for trackball.
|
|
69
|
-
*/
|
|
70
|
-
constructor(
|
|
71
|
-
type: ControlType,
|
|
72
|
-
camera: THREE.Camera,
|
|
73
|
-
target: THREE.Vector3,
|
|
74
|
-
domElement: HTMLElement,
|
|
75
|
-
rotateSpeed: number = 1.0,
|
|
76
|
-
zoomSpeed: number = 1.0,
|
|
77
|
-
panSpeed: number = 1.0,
|
|
78
|
-
holroyd: boolean = true,
|
|
79
|
-
) {
|
|
80
|
-
this.type = type;
|
|
81
|
-
this.camera = camera;
|
|
82
|
-
this.target = target;
|
|
83
|
-
this.target0 = target.clone();
|
|
84
|
-
this.domElement = domElement;
|
|
85
|
-
this.rotateSpeed = rotateSpeed;
|
|
86
|
-
this.zoomSpeed = zoomSpeed;
|
|
87
|
-
this.panSpeed = panSpeed;
|
|
88
|
-
this.holroyd = holroyd;
|
|
89
|
-
|
|
90
|
-
switch (type) {
|
|
91
|
-
case "orbit":
|
|
92
|
-
this.initOrbitControls();
|
|
93
|
-
break;
|
|
94
|
-
case "trackball":
|
|
95
|
-
this.initTrackballControls(holroyd);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this.controls.target.copy(this.target);
|
|
100
|
-
this._applySpeedFactors();
|
|
101
|
-
|
|
102
|
-
this.currentUpdateCallback = null;
|
|
103
|
-
|
|
104
|
-
// save default view for reset
|
|
105
|
-
this.saveState();
|
|
106
|
-
this.update();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Get the speed factors for the current control type.
|
|
111
|
-
*/
|
|
112
|
-
private _getSpeedFactors(): { pan: number; rotate: number; zoom: number } {
|
|
113
|
-
return SPEED_FACTORS[this.type];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Apply speed factors to controls.
|
|
118
|
-
*/
|
|
119
|
-
private _applySpeedFactors(): void {
|
|
120
|
-
const factors = this._getSpeedFactors();
|
|
121
|
-
this.controls.rotateSpeed = this.rotateSpeed * factors.rotate;
|
|
122
|
-
this.controls.zoomSpeed = this.zoomSpeed * factors.zoom;
|
|
123
|
-
this.controls.panSpeed = this.panSpeed * factors.pan;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Remove assets and event handlers.
|
|
128
|
-
*/
|
|
129
|
-
dispose(): void {
|
|
130
|
-
this.controls.dispose();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Save state for reset.
|
|
135
|
-
*/
|
|
136
|
-
saveState(): void {
|
|
137
|
-
this.controls.saveState();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Initialize Trackball Controls.
|
|
142
|
-
* @param holroyd - enable holroyd (non tumbling) mode.
|
|
143
|
-
*/
|
|
144
|
-
initTrackballControls(holroyd: boolean = true): void {
|
|
145
|
-
this.controls = new CADTrackballControls(this.camera, this.domElement);
|
|
146
|
-
this.setHolroydTrackball(holroyd);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Initialize Orbit Controls.
|
|
151
|
-
*/
|
|
152
|
-
initOrbitControls(): void {
|
|
153
|
-
this.controls = new CADOrbitControls(this.camera, this.domElement);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Add an event listener callback for the "change" event.
|
|
158
|
-
* @param callback - the callback function.
|
|
159
|
-
*/
|
|
160
|
-
addChangeListener(callback: () => void): void {
|
|
161
|
-
if (this.currentUpdateCallback == null) {
|
|
162
|
-
this.currentUpdateCallback = callback;
|
|
163
|
-
this.controls.addEventListener("change", callback);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Remove the event listener callback for the "change" event.
|
|
169
|
-
*/
|
|
170
|
-
removeChangeListener(): void {
|
|
171
|
-
if (this.currentUpdateCallback != null) {
|
|
172
|
-
this.controls.removeEventListener("change", this.currentUpdateCallback);
|
|
173
|
-
this.currentUpdateCallback = null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Update controls after camera position, zoom or quaternion changes.
|
|
179
|
-
*/
|
|
180
|
-
update(): void {
|
|
181
|
-
this.controls.update();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Update screen dimensions after canvas resize.
|
|
186
|
-
* Only applies to TrackballControls which caches screen dimensions.
|
|
187
|
-
*/
|
|
188
|
-
handleResize(): void {
|
|
189
|
-
if (this.controls instanceof CADTrackballControls) {
|
|
190
|
-
this.controls.handleResize();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Reset camera to initial (automatically saved) state of position, up, quaternion and zoom.
|
|
196
|
-
*/
|
|
197
|
-
reset(): void {
|
|
198
|
-
this.controls.reset();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Set the camera to be controlled.
|
|
203
|
-
* @param camera - a threejs Camera object.
|
|
204
|
-
*/
|
|
205
|
-
setCamera(camera: THREE.Camera): void {
|
|
206
|
-
this.controls.object = camera;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Change the trackball holroyd (non tumbling) flag.
|
|
211
|
-
* @param flag - holroyd mode enabled.
|
|
212
|
-
*/
|
|
213
|
-
setHolroydTrackball(flag: boolean): void {
|
|
214
|
-
this.getTrackballControls().holroyd = flag;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Get the lookAt target of the camera.
|
|
219
|
-
* @returns The lookAt target
|
|
220
|
-
*/
|
|
221
|
-
getTarget(): THREE.Vector3 {
|
|
222
|
-
return this.controls.target;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Check if the user is currently interacting with the controls (rotating, panning, zooming).
|
|
227
|
-
* @returns true if user is dragging/interacting, false otherwise.
|
|
228
|
-
*/
|
|
229
|
-
isInteracting(): boolean {
|
|
230
|
-
// Both OrbitControls and TrackballControls use state = -1 for NONE (not interacting)
|
|
231
|
-
// Any other state value means the user is actively dragging
|
|
232
|
-
return this.controls.state !== -1;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Get the initial zoom value of the camera.
|
|
237
|
-
*/
|
|
238
|
-
getZoom0(): number {
|
|
239
|
-
return this.controls.zoom0;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Set the lookAt target of the camera.
|
|
244
|
-
* @param target - camera target as THREE.Vector3.
|
|
245
|
-
*/
|
|
246
|
-
setTarget(target: THREE.Vector3): void {
|
|
247
|
-
this.controls.target.copy(target);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Set the zoom speed.
|
|
252
|
-
* @param val - the speed value (1.0 = default).
|
|
253
|
-
*/
|
|
254
|
-
setZoomSpeed(val: number): void {
|
|
255
|
-
this.zoomSpeed = val;
|
|
256
|
-
this.controls.zoomSpeed = val * this._getSpeedFactors().zoom;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Set the pan speed.
|
|
261
|
-
* @param val - the speed value (1.0 = default).
|
|
262
|
-
*/
|
|
263
|
-
setPanSpeed(val: number): void {
|
|
264
|
-
this.panSpeed = val;
|
|
265
|
-
this.controls.panSpeed = val * this._getSpeedFactors().pan;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Set the rotate speed.
|
|
270
|
-
* @param val - the speed value (1.0 = default).
|
|
271
|
-
*/
|
|
272
|
-
setRotateSpeed(val: number): void {
|
|
273
|
-
this.rotateSpeed = val;
|
|
274
|
-
this.controls.rotateSpeed = val * this._getSpeedFactors().rotate;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Get reset location value.
|
|
279
|
-
* @returns target, position, quaternion, zoom as object.
|
|
280
|
-
*/
|
|
281
|
-
getResetLocation = (): {
|
|
282
|
-
target0: THREE.Vector3;
|
|
283
|
-
position0: THREE.Vector3;
|
|
284
|
-
quaternion0: THREE.Quaternion;
|
|
285
|
-
zoom0: number;
|
|
286
|
-
} => {
|
|
287
|
-
return {
|
|
288
|
-
target0: this.controls.target0.clone(),
|
|
289
|
-
position0: this.controls.position0.clone(),
|
|
290
|
-
quaternion0: this.controls.quaternion0.clone(),
|
|
291
|
-
zoom0: this.controls.zoom0,
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Set reset location value.
|
|
297
|
-
* @param target - camera target as THREE.Vector3.
|
|
298
|
-
* @param position - camera position as THREE.Vector3.
|
|
299
|
-
* @param quaternion - camera rotation as THREE.Quaternion.
|
|
300
|
-
* @param zoom - camera zoom value.
|
|
301
|
-
*/
|
|
302
|
-
setResetLocation = (
|
|
303
|
-
target: THREE.Vector3,
|
|
304
|
-
position: THREE.Vector3,
|
|
305
|
-
quaternion: THREE.Quaternion,
|
|
306
|
-
zoom: number,
|
|
307
|
-
): void => {
|
|
308
|
-
this.controls.target0.copy(target);
|
|
309
|
-
this.controls.position0.copy(position);
|
|
310
|
-
this.controls.quaternion0.copy(quaternion);
|
|
311
|
-
this.controls.zoom0 = zoom;
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
// Type-safe accessors for control-specific methods
|
|
315
|
-
|
|
316
|
-
private getOrbitControls(): CADOrbitControls {
|
|
317
|
-
if (!(this.controls instanceof CADOrbitControls)) {
|
|
318
|
-
throw new Error("Operation requires OrbitControls");
|
|
319
|
-
}
|
|
320
|
-
return this.controls;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
private getTrackballControls(): CADTrackballControls {
|
|
324
|
-
if (!(this.controls instanceof CADTrackballControls)) {
|
|
325
|
-
throw new Error("Operation requires TrackballControls");
|
|
326
|
-
}
|
|
327
|
-
return this.controls;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Rotations for OrbitControls
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Rotate camera up (OrbitControls only)
|
|
334
|
-
* @param angle - the angle to rotate.
|
|
335
|
-
*/
|
|
336
|
-
rotateUp(angle: number): void {
|
|
337
|
-
this.getOrbitControls().rotateUp((-angle / 180) * Math.PI);
|
|
338
|
-
this.update();
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Rotate camera left (OrbitControls only)
|
|
343
|
-
* @param angle - the angle to rotate.
|
|
344
|
-
*/
|
|
345
|
-
rotateLeft(angle: number): void {
|
|
346
|
-
this.getOrbitControls().rotateLeft((angle / 180) * Math.PI);
|
|
347
|
-
this.update();
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// Rotations for TrackballControls
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Rotate camera around x-axis (TrackballControls only)
|
|
354
|
-
* @param angle - the angle to rotate.
|
|
355
|
-
*/
|
|
356
|
-
rotateX(angle: number): void {
|
|
357
|
-
this.getTrackballControls().rotateX((angle / 180) * Math.PI);
|
|
358
|
-
this.update();
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Rotate camera around y-axis (TrackballControls only)
|
|
363
|
-
* @param angle - the angle to rotate.
|
|
364
|
-
*/
|
|
365
|
-
rotateY(angle: number): void {
|
|
366
|
-
this.getTrackballControls().rotateY((angle / 180) * Math.PI);
|
|
367
|
-
this.update();
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Rotate camera around z-axis (TrackballControls only)
|
|
372
|
-
* @param angle - the angle to rotate.
|
|
373
|
-
*/
|
|
374
|
-
rotateZ(angle: number): void {
|
|
375
|
-
this.getTrackballControls().rotateZ((angle / 180) * Math.PI);
|
|
376
|
-
this.update();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export { Controls };
|
package/src/core/patches.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { InstancedBufferGeometry } from "three";
|
|
2
|
-
import { LineSegmentsGeometry as _LineSegmentsGeometry } from "three/examples/jsm/lines/LineSegmentsGeometry.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Extended LineSegmentsGeometry with fixed toJSON method.
|
|
6
|
-
* The original LineSegmentsGeometry has a broken toJSON implementation.
|
|
7
|
-
*/
|
|
8
|
-
class LineSegmentsGeometry extends _LineSegmentsGeometry {
|
|
9
|
-
toJSON(): ReturnType<typeof InstancedBufferGeometry.prototype.toJSON> {
|
|
10
|
-
// skip the broken toJSON method of _LineSegmentsGeometry
|
|
11
|
-
const data = InstancedBufferGeometry.prototype.toJSON.call(this);
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { LineSegmentsGeometry };
|