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/scene/orientation.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
|
-
import { AxesHelper } from "./axes.js";
|
|
3
|
-
import { sceneTraverse } from "../utils/utils.js";
|
|
4
|
-
import { Font } from "three/examples/jsm/loaders/FontLoader.js";
|
|
5
|
-
import { helvetiker } from "../utils/font.js";
|
|
6
|
-
import type { Theme, AxisColors, ColoredMaterial } from "../core/types";
|
|
7
|
-
|
|
8
|
-
/** Length of orientation marker axes in pixels */
|
|
9
|
-
const length = 54;
|
|
10
|
-
/** Distance from origin to axis labels */
|
|
11
|
-
const distance = length + 18;
|
|
12
|
-
|
|
13
|
-
/** Typed mesh with colored material for cones and labels */
|
|
14
|
-
type ColoredMesh = THREE.Mesh<THREE.BufferGeometry, ColoredMaterial>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Displays an orientation gizmo in the corner showing XYZ axes.
|
|
18
|
-
* Syncs rotation with the main camera.
|
|
19
|
-
*/
|
|
20
|
-
class OrientationMarker {
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
cad_camera: THREE.Camera | null;
|
|
24
|
-
theme: Theme;
|
|
25
|
-
camera: THREE.OrthographicCamera | null;
|
|
26
|
-
scene: THREE.Scene | null;
|
|
27
|
-
renderer: THREE.WebGLRenderer | null;
|
|
28
|
-
labels: ColoredMesh[];
|
|
29
|
-
ready: boolean;
|
|
30
|
-
colors: AxisColors;
|
|
31
|
-
cones: ColoredMesh[];
|
|
32
|
-
axes: AxesHelper | null;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Create an OrientationMarker.
|
|
36
|
-
* @param width - Viewport width for the marker.
|
|
37
|
-
* @param height - Viewport height for the marker.
|
|
38
|
-
* @param camera - The main CAD camera to sync orientation with.
|
|
39
|
-
* @param theme - Color theme ("dark" or "light").
|
|
40
|
-
*/
|
|
41
|
-
constructor(width: number, height: number, camera: THREE.Camera, theme: Theme) {
|
|
42
|
-
this.width = width;
|
|
43
|
-
this.height = height;
|
|
44
|
-
this.cad_camera = camera;
|
|
45
|
-
this.theme = theme;
|
|
46
|
-
this.camera = null;
|
|
47
|
-
this.scene = null;
|
|
48
|
-
this.renderer = null;
|
|
49
|
-
this.labels = [];
|
|
50
|
-
this.ready = false;
|
|
51
|
-
this.colors = {
|
|
52
|
-
dark: [
|
|
53
|
-
[1, 69 / 255, 0],
|
|
54
|
-
[50 / 255, 205 / 255, 50 / 255],
|
|
55
|
-
[59 / 255, 158 / 255, 1],
|
|
56
|
-
],
|
|
57
|
-
light: [
|
|
58
|
-
[1, 0, 0],
|
|
59
|
-
[0, 0.5, 0],
|
|
60
|
-
[0, 0, 1],
|
|
61
|
-
],
|
|
62
|
-
};
|
|
63
|
-
this.cones = [];
|
|
64
|
-
this.axes = null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Create the orientation marker scene with axes, cones, and labels.
|
|
69
|
-
*/
|
|
70
|
-
create(): void {
|
|
71
|
-
const font = new Font(helvetiker);
|
|
72
|
-
const size = 2.5;
|
|
73
|
-
|
|
74
|
-
// scene
|
|
75
|
-
this.scene = new THREE.Scene();
|
|
76
|
-
|
|
77
|
-
// camera
|
|
78
|
-
this.camera = new THREE.OrthographicCamera(
|
|
79
|
-
-this.width,
|
|
80
|
-
this.width,
|
|
81
|
-
this.height,
|
|
82
|
-
-this.height,
|
|
83
|
-
1,
|
|
84
|
-
1000,
|
|
85
|
-
);
|
|
86
|
-
this.camera.up = this.cad_camera!.up; // important!
|
|
87
|
-
this.camera.lookAt(new THREE.Vector3(0, 0, 0));
|
|
88
|
-
|
|
89
|
-
// axes
|
|
90
|
-
this.axes = new AxesHelper(
|
|
91
|
-
[0, 0, 0],
|
|
92
|
-
length,
|
|
93
|
-
size,
|
|
94
|
-
this.width,
|
|
95
|
-
this.height,
|
|
96
|
-
true,
|
|
97
|
-
true,
|
|
98
|
-
this.theme,
|
|
99
|
-
);
|
|
100
|
-
this.scene.add(this.axes);
|
|
101
|
-
|
|
102
|
-
this.cones = [];
|
|
103
|
-
for (let i = 0; i < 3; i++) {
|
|
104
|
-
const coneGeometry = new THREE.CylinderGeometry(
|
|
105
|
-
0,
|
|
106
|
-
2.5 * size,
|
|
107
|
-
5 * size,
|
|
108
|
-
20,
|
|
109
|
-
1,
|
|
110
|
-
);
|
|
111
|
-
const coneMaterial = new THREE.MeshBasicMaterial({
|
|
112
|
-
color: new THREE.Color(...this.colors[this.theme][i]),
|
|
113
|
-
toneMapped: false,
|
|
114
|
-
});
|
|
115
|
-
const cone = new THREE.Mesh(coneGeometry, coneMaterial);
|
|
116
|
-
cone.matrixAutoUpdate = false;
|
|
117
|
-
this.cones.push(cone);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.cones[0].geometry.rotateZ(-Math.PI / 2);
|
|
121
|
-
this.cones[0].geometry.translate(length, 0, 0);
|
|
122
|
-
this.cones[1].geometry.translate(0, length, 0);
|
|
123
|
-
this.cones[2].geometry.rotateX(Math.PI / 2);
|
|
124
|
-
this.cones[2].geometry.translate(0, 0, length);
|
|
125
|
-
|
|
126
|
-
this.scene.add(...this.cones);
|
|
127
|
-
const axesNames = ["X", "Y", "Z"];
|
|
128
|
-
|
|
129
|
-
for (let i = 0; i < 3; i++) {
|
|
130
|
-
const mat = new THREE.LineBasicMaterial({
|
|
131
|
-
color:
|
|
132
|
-
this.theme === "dark"
|
|
133
|
-
? new THREE.Color(0.9, 0.9, 0.9)
|
|
134
|
-
: new THREE.Color(0, 0, 0),
|
|
135
|
-
side: THREE.DoubleSide,
|
|
136
|
-
});
|
|
137
|
-
const shape = font.generateShapes(axesNames[i], 16);
|
|
138
|
-
const geom = new THREE.ShapeGeometry(shape);
|
|
139
|
-
geom.computeBoundingBox();
|
|
140
|
-
const xMid = -0.5 * (geom.boundingBox!.max.x - geom.boundingBox!.min.x);
|
|
141
|
-
const yMid = -0.5 * (geom.boundingBox!.max.y - geom.boundingBox!.min.y);
|
|
142
|
-
geom.translate(xMid, yMid, 0);
|
|
143
|
-
const label = new THREE.Mesh(geom, mat);
|
|
144
|
-
|
|
145
|
-
this.scene.add(label);
|
|
146
|
-
this.labels.push(label);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const geometry = new THREE.SphereGeometry(3 * size, 20, 20);
|
|
150
|
-
const material = new THREE.MeshBasicMaterial({ color: 0xa0a0a0 });
|
|
151
|
-
const sphere = new THREE.Mesh(geometry, material);
|
|
152
|
-
this.scene.add(sphere);
|
|
153
|
-
|
|
154
|
-
this.scene.background = null;
|
|
155
|
-
this.ready = true;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Set visibility of all orientation marker elements.
|
|
160
|
-
* @param flag - Whether the marker should be visible.
|
|
161
|
-
*/
|
|
162
|
-
setVisible(flag: boolean): void {
|
|
163
|
-
if (!this.scene) return;
|
|
164
|
-
for (const child of this.scene.children) {
|
|
165
|
-
child.visible = flag;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Dispose of all resources and clean up memory.
|
|
171
|
-
*/
|
|
172
|
-
dispose(): void {
|
|
173
|
-
sceneTraverse(this.scene, (o) => {
|
|
174
|
-
if (o instanceof THREE.Mesh) {
|
|
175
|
-
o.geometry?.dispose();
|
|
176
|
-
if (o.material instanceof THREE.Material) {
|
|
177
|
-
o.material.dispose();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
this.scene = null;
|
|
182
|
-
this.camera = null;
|
|
183
|
-
this.cad_camera = null;
|
|
184
|
-
this.cones = [];
|
|
185
|
-
this.labels = [];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Render the orientation marker to the given renderer.
|
|
190
|
-
* @param renderer - The renderer to draw to.
|
|
191
|
-
*/
|
|
192
|
-
render(renderer: THREE.WebGLRenderer): void {
|
|
193
|
-
if (this.ready && this.scene && this.camera) {
|
|
194
|
-
// Rendering the corner marker mutates renderer state (viewport/scissor/scissor test).
|
|
195
|
-
// Preserve and restore those values so downstream renders are not clipped or offset.
|
|
196
|
-
const prevViewport = renderer.getViewport(new THREE.Vector4());
|
|
197
|
-
const prevScissor = renderer.getScissor(new THREE.Vector4());
|
|
198
|
-
const prevScissorTest = renderer.getScissorTest();
|
|
199
|
-
|
|
200
|
-
// Draw marker in its small corner viewport.
|
|
201
|
-
renderer.setViewport(0, 0, this.width, this.height);
|
|
202
|
-
renderer.render(this.scene, this.camera);
|
|
203
|
-
|
|
204
|
-
// Restore previous state for the main scene / shared render pipeline.
|
|
205
|
-
renderer.setViewport(prevViewport);
|
|
206
|
-
renderer.setScissor(prevScissor);
|
|
207
|
-
renderer.setScissorTest(prevScissorTest);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Update the marker to match the main camera's orientation.
|
|
213
|
-
* @param position - Camera position (will be normalized).
|
|
214
|
-
* @param quaternion - Camera rotation quaternion.
|
|
215
|
-
*/
|
|
216
|
-
update(position: THREE.Vector3, quaternion: THREE.Quaternion): void {
|
|
217
|
-
if (this.ready && this.camera) {
|
|
218
|
-
const q = new THREE.Quaternion().setFromUnitVectors(
|
|
219
|
-
new THREE.Vector3(0, 0, 1),
|
|
220
|
-
position.normalize(),
|
|
221
|
-
);
|
|
222
|
-
this.camera.position.set(0, 0, 1).applyQuaternion(q).multiplyScalar(300);
|
|
223
|
-
|
|
224
|
-
this.camera.quaternion.copy(quaternion);
|
|
225
|
-
|
|
226
|
-
for (let i = 0; i < 3; i++) {
|
|
227
|
-
this.labels[i].position.set(
|
|
228
|
-
i == 0 ? distance : 0,
|
|
229
|
-
i == 1 ? distance : 0,
|
|
230
|
-
i == 2 ? distance : 0,
|
|
231
|
-
);
|
|
232
|
-
this.labels[i].quaternion.copy(quaternion);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Change the color theme of the orientation marker.
|
|
239
|
-
* @param theme - The theme name ("dark" or "light").
|
|
240
|
-
*/
|
|
241
|
-
changeTheme(theme: Theme): void {
|
|
242
|
-
for (const i in this.cones) {
|
|
243
|
-
const cone = this.cones[i];
|
|
244
|
-
cone.material.color = new THREE.Color(...this.colors[theme][i]);
|
|
245
|
-
}
|
|
246
|
-
if (this.axes) {
|
|
247
|
-
this.axes.changeTheme(theme);
|
|
248
|
-
}
|
|
249
|
-
for (const i in this.labels) {
|
|
250
|
-
const label = this.labels[i];
|
|
251
|
-
label.material.color =
|
|
252
|
-
theme === "dark"
|
|
253
|
-
? new THREE.Color(0.9, 0.9, 0.9)
|
|
254
|
-
: new THREE.Color(0, 0, 0);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export { OrientationMarker };
|