@tonybfox/threejs-tools 1.0.5 → 1.0.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 (41) hide show
  1. package/dist/asset-loader/index.cjs +3 -417
  2. package/dist/asset-loader/index.mjs +1 -6
  3. package/dist/camera/index.cjs +1 -393
  4. package/dist/camera/index.mjs +1 -6
  5. package/dist/chunk-4O4ENFL7.mjs +83 -0
  6. package/dist/chunk-55YVGK52.mjs +1 -0
  7. package/dist/chunk-B75TYEOO.mjs +44 -0
  8. package/dist/chunk-CLSRN5D2.mjs +1 -0
  9. package/dist/chunk-EQRUOKFV.mjs +1 -0
  10. package/dist/chunk-JRJBW66X.mjs +1 -0
  11. package/dist/chunk-OJFYE56U.mjs +1 -0
  12. package/dist/chunk-WZ4X7GQ2.mjs +1 -0
  13. package/dist/chunk-Z5VL3O6M.mjs +43 -0
  14. package/dist/compass/index.cjs +3 -304
  15. package/dist/compass/index.mjs +1 -6
  16. package/dist/grid/index.cjs +3 -159
  17. package/dist/grid/index.mjs +1 -6
  18. package/dist/index.cjs +7 -5406
  19. package/dist/index.mjs +1 -384
  20. package/dist/measurements/index.cjs +1 -1197
  21. package/dist/measurements/index.mjs +1 -8
  22. package/dist/sunlight/index.cjs +1 -440
  23. package/dist/sunlight/index.d.mts +19 -0
  24. package/dist/sunlight/index.d.ts +19 -0
  25. package/dist/sunlight/index.mjs +1 -6
  26. package/dist/terrain/index.cjs +1 -422
  27. package/dist/terrain/index.mjs +1 -6
  28. package/dist/transform-controls/index.cjs +1 -1586
  29. package/dist/transform-controls/index.mjs +1 -12
  30. package/dist/view-helper/index.cjs +1 -435
  31. package/dist/view-helper/index.mjs +1 -6
  32. package/package.json +1 -1
  33. package/dist/chunk-2CDI7ORN.mjs +0 -163
  34. package/dist/chunk-FBTT6MU6.mjs +0 -386
  35. package/dist/chunk-IAZH4OHC.mjs +0 -399
  36. package/dist/chunk-LUE7VHLK.mjs +0 -422
  37. package/dist/chunk-OZKJ3GAD.mjs +0 -1160
  38. package/dist/chunk-W4DAAAW6.mjs +0 -404
  39. package/dist/chunk-XA7OKYSM.mjs +0 -357
  40. package/dist/chunk-YMMLYGHV.mjs +0 -1578
  41. package/dist/chunk-ZNGFST7K.mjs +0 -348
@@ -1,357 +0,0 @@
1
- // packages/camera/src/DualCameraControls.ts
2
- import * as THREE from "three";
3
- import CameraControls from "camera-controls";
4
- var controlsInstalled = false;
5
- var tempVec3A = new THREE.Vector3();
6
- var tempVec3B = new THREE.Vector3();
7
- var tempVec2 = new THREE.Vector2();
8
- function ensureCameraControlsInstalled() {
9
- if (!controlsInstalled) {
10
- CameraControls.install({ THREE });
11
- controlsInstalled = true;
12
- }
13
- }
14
- function toVector3(value, fallback, target) {
15
- if (!value) {
16
- target.set(fallback[0], fallback[1], fallback[2]);
17
- return target;
18
- }
19
- if (Array.isArray(value)) {
20
- target.set(value[0], value[1], value[2]);
21
- return target;
22
- }
23
- target.copy(value);
24
- return target;
25
- }
26
- var DualCameraControls = class extends CameraControls {
27
- constructor(renderer, options = {}) {
28
- ensureCameraControlsInstalled();
29
- const { domElement = renderer.domElement } = options;
30
- const aspect = resolveAspect(renderer, domElement);
31
- const perspectiveConfig = options.perspective ?? {};
32
- const orthographicConfig = options.orthographic ?? {};
33
- const perspectiveCamera = new THREE.PerspectiveCamera(
34
- perspectiveConfig.fov ?? 60,
35
- aspect,
36
- perspectiveConfig.near ?? 0.1,
37
- perspectiveConfig.far ?? 2e3
38
- );
39
- perspectiveCamera.position.copy(
40
- toVector3(perspectiveConfig.position, [12, 12, 12], new THREE.Vector3())
41
- );
42
- if (perspectiveConfig.zoom !== void 0) {
43
- perspectiveCamera.zoom = perspectiveConfig.zoom;
44
- perspectiveCamera.updateProjectionMatrix();
45
- }
46
- const orthoHalfHeight = Math.max(orthographicConfig.size ?? 20, 1e-3) * 0.5;
47
- const orthoHalfWidth = orthoHalfHeight * aspect;
48
- const orthographicCamera = new THREE.OrthographicCamera(
49
- -orthoHalfWidth,
50
- orthoHalfWidth,
51
- orthoHalfHeight,
52
- -orthoHalfHeight,
53
- orthographicConfig.near ?? 0.1,
54
- orthographicConfig.far ?? 2e3
55
- );
56
- orthographicCamera.position.copy(
57
- toVector3(orthographicConfig.position, [12, 12, 12], new THREE.Vector3())
58
- );
59
- if (orthographicConfig.zoom !== void 0) {
60
- orthographicCamera.zoom = orthographicConfig.zoom;
61
- orthographicCamera.updateProjectionMatrix();
62
- }
63
- const initialMode = options.initialMode ?? "perspective";
64
- const initialCamera = initialMode === "orthographic" ? orthographicCamera : perspectiveCamera;
65
- super(initialCamera, domElement);
66
- this.updateClock = new THREE.Clock();
67
- this.externalCamera = null;
68
- const initialTarget = toVector3(
69
- options.initialTarget,
70
- [0, 0, 0],
71
- new THREE.Vector3()
72
- );
73
- void this.setLookAt(
74
- initialCamera.position.x,
75
- initialCamera.position.y,
76
- initialCamera.position.z,
77
- initialTarget.x,
78
- initialTarget.y,
79
- initialTarget.z,
80
- false
81
- );
82
- this.renderer = renderer;
83
- this.domElementRef = domElement;
84
- this.perspectiveCamera = perspectiveCamera;
85
- this.orthographicCamera = orthographicCamera;
86
- this.activeMode = initialMode;
87
- this.minOrthoHalfHeight = orthoHalfHeight;
88
- this.updateInputBindingsForMode(initialMode);
89
- }
90
- get mode() {
91
- return this.activeMode;
92
- }
93
- /**
94
- * Returns the currently active camera instance.
95
- */
96
- get activeCamera() {
97
- return this.camera;
98
- }
99
- /**
100
- * Switch to the perspective camera while keeping the current framing.
101
- */
102
- switchToPerspective(enableTransition = false) {
103
- if (this.activeMode === "perspective" && !this.externalCamera) {
104
- return;
105
- }
106
- this.externalCamera = null;
107
- const target = this.getTarget(tempVec3A);
108
- const position = this.getPosition(tempVec3B);
109
- const aspect = resolveAspect(this.renderer, this.domElementRef);
110
- this.perspectiveCamera.aspect = aspect;
111
- this.perspectiveCamera.position.copy(position);
112
- this.perspectiveCamera.quaternion.copy(this.camera.quaternion);
113
- this.perspectiveCamera.up.copy(this.camera.up);
114
- this.perspectiveCamera.updateProjectionMatrix();
115
- this.camera = this.perspectiveCamera;
116
- this.activeMode = "perspective";
117
- this.updateInputBindingsForMode("perspective");
118
- void this.setLookAt(
119
- position.x,
120
- position.y,
121
- position.z,
122
- target.x,
123
- target.y,
124
- target.z,
125
- enableTransition
126
- );
127
- this.dispatchEvent({
128
- type: "modechange",
129
- mode: this.activeMode,
130
- previousMode: "orthographic",
131
- camera: this.perspectiveCamera
132
- });
133
- }
134
- /**
135
- * Switch to the orthographic camera while keeping the current framing.
136
- */
137
- switchToOrthographic(enableTransition = false) {
138
- if (this.activeMode === "orthographic" && !this.externalCamera) {
139
- return;
140
- }
141
- this.externalCamera = null;
142
- const target = this.getTarget(tempVec3A);
143
- const position = this.getPosition(tempVec3B);
144
- const aspect = resolveAspect(this.renderer, this.domElementRef);
145
- this.updateOrthographicFrustum(position, target, aspect);
146
- this.orthographicCamera.position.copy(position);
147
- this.orthographicCamera.quaternion.copy(this.camera.quaternion);
148
- this.orthographicCamera.up.copy(this.camera.up);
149
- this.orthographicCamera.updateProjectionMatrix();
150
- this.camera = this.orthographicCamera;
151
- this.activeMode = "orthographic";
152
- this.updateInputBindingsForMode("orthographic");
153
- void this.setLookAt(
154
- position.x,
155
- position.y,
156
- position.z,
157
- target.x,
158
- target.y,
159
- target.z,
160
- enableTransition
161
- );
162
- this.dispatchEvent({
163
- type: "modechange",
164
- mode: this.activeMode,
165
- previousMode: "perspective",
166
- camera: this.orthographicCamera
167
- });
168
- }
169
- /**
170
- * Toggles between perspective and orthographic camera modes.
171
- */
172
- toggleCameraMode(enableTransition = false) {
173
- if (this.activeMode === "perspective") {
174
- this.switchToOrthographic(enableTransition);
175
- } else {
176
- this.switchToPerspective(enableTransition);
177
- }
178
- }
179
- /**
180
- * Returns true if currently using an external camera.
181
- */
182
- get isUsingExternalCamera() {
183
- return this.externalCamera !== null;
184
- }
185
- /**
186
- * Sets an external camera to use with the controls.
187
- * This allows using a camera created outside of DualCameraControls.
188
- * Call `clearExternalCamera()` to return to the internal cameras.
189
- */
190
- setCamera(camera, target, enableTransition = false) {
191
- const previousCamera = this.camera;
192
- this.externalCamera = camera;
193
- const aspect = resolveAspect(this.renderer, this.domElementRef);
194
- if (camera.type === "PerspectiveCamera") {
195
- ;
196
- camera.aspect = aspect;
197
- camera.updateProjectionMatrix();
198
- } else if (camera.type === "OrthographicCamera") {
199
- const ortho = camera;
200
- const currentHeight = (ortho.top - ortho.bottom) * 0.5;
201
- const newHalfWidth = currentHeight * aspect;
202
- ortho.left = -newHalfWidth;
203
- ortho.right = newHalfWidth;
204
- ortho.updateProjectionMatrix();
205
- }
206
- this.camera = camera;
207
- const mode = camera.type === "PerspectiveCamera" ? "perspective" : "orthographic";
208
- this.activeMode = mode;
209
- this.updateInputBindingsForMode(mode);
210
- const targetVec = toVector3(target, [0, 0, 0], tempVec3A);
211
- void this.setLookAt(
212
- camera.position.x,
213
- camera.position.y,
214
- camera.position.z,
215
- targetVec.x,
216
- targetVec.y,
217
- targetVec.z,
218
- enableTransition
219
- );
220
- this.dispatchEvent({
221
- type: "externalcamerachange",
222
- camera,
223
- previousCamera
224
- });
225
- }
226
- /**
227
- * Clears the external camera and returns to using the internal cameras.
228
- * Will switch to the camera matching the current mode.
229
- */
230
- clearExternalCamera(enableTransition = false) {
231
- if (!this.externalCamera) {
232
- return;
233
- }
234
- const target = this.getTarget(tempVec3A);
235
- const position = this.getPosition(tempVec3B);
236
- this.externalCamera = null;
237
- const internalCamera = this.activeMode === "orthographic" ? this.orthographicCamera : this.perspectiveCamera;
238
- internalCamera.position.copy(position);
239
- internalCamera.quaternion.copy(this.camera.quaternion);
240
- internalCamera.up.copy(this.camera.up);
241
- const aspect = resolveAspect(this.renderer, this.domElementRef);
242
- if (this.activeMode === "orthographic") {
243
- this.updateOrthographicFrustum(position, target, aspect);
244
- } else {
245
- this.perspectiveCamera.aspect = aspect;
246
- this.perspectiveCamera.updateProjectionMatrix();
247
- }
248
- this.camera = internalCamera;
249
- void this.setLookAt(
250
- position.x,
251
- position.y,
252
- position.z,
253
- target.x,
254
- target.y,
255
- target.z,
256
- enableTransition
257
- );
258
- this.dispatchEvent({
259
- type: "modechange",
260
- mode: this.activeMode,
261
- previousMode: this.activeMode,
262
- camera: internalCamera
263
- });
264
- }
265
- /**
266
- * Update camera projection parameters when the viewport size changes.
267
- */
268
- handleResize(width, height) {
269
- const aspect = height === 0 ? 1 : width / height;
270
- this.perspectiveCamera.aspect = aspect;
271
- this.perspectiveCamera.updateProjectionMatrix();
272
- const target = this.getTarget(tempVec3A);
273
- const position = this.getPosition(tempVec3B);
274
- this.updateOrthographicFrustum(position, target, aspect);
275
- if (this.activeMode === "orthographic") {
276
- this.camera = this.orthographicCamera;
277
- void this.setLookAt(
278
- position.x,
279
- position.y,
280
- position.z,
281
- target.x,
282
- target.y,
283
- target.z,
284
- false
285
- );
286
- }
287
- }
288
- /**
289
- * Moves the camera to a new position and target.
290
- */
291
- moveCamera(position, target, enableTransition = true) {
292
- toVector3(position, [0, 0, 0], tempVec3A);
293
- toVector3(target, [0, 0, 0], tempVec3B);
294
- return this.setLookAt(
295
- tempVec3A.x,
296
- tempVec3A.y,
297
- tempVec3A.z,
298
- tempVec3B.x,
299
- tempVec3B.y,
300
- tempVec3B.z,
301
- enableTransition
302
- );
303
- }
304
- /**
305
- * Updates the controls using an internally managed clock.
306
- * Useful when you don't want to pass delta time each frame.
307
- */
308
- updateDelta() {
309
- const delta = this.updateClock.getDelta();
310
- return super.update(delta);
311
- }
312
- updateInputBindingsForMode(mode) {
313
- const { ACTION } = CameraControls;
314
- if (mode === "orthographic") {
315
- this.mouseButtons.left = ACTION.TRUCK;
316
- this.mouseButtons.right = ACTION.ROTATE;
317
- this.mouseButtons.wheel = ACTION.ZOOM;
318
- this.touches.one = ACTION.TOUCH_TRUCK;
319
- this.touches.two = ACTION.TOUCH_ZOOM_TRUCK;
320
- } else {
321
- this.mouseButtons.left = ACTION.ROTATE;
322
- this.mouseButtons.right = ACTION.TRUCK;
323
- this.mouseButtons.wheel = ACTION.DOLLY;
324
- this.touches.one = ACTION.TOUCH_ROTATE;
325
- this.touches.two = ACTION.TOUCH_DOLLY_TRUCK;
326
- }
327
- }
328
- updateOrthographicFrustum(position, target, aspect) {
329
- const distance = Math.max(position.distanceTo(target), 1e-3);
330
- const fov = this.perspectiveCamera.fov;
331
- const halfHeight = Math.max(
332
- distance * Math.tan(THREE.MathUtils.degToRad(fov * 0.5)),
333
- this.minOrthoHalfHeight
334
- );
335
- const halfWidth = halfHeight * aspect;
336
- this.orthographicCamera.left = -halfWidth;
337
- this.orthographicCamera.right = halfWidth;
338
- this.orthographicCamera.top = halfHeight;
339
- this.orthographicCamera.bottom = -halfHeight;
340
- this.orthographicCamera.updateProjectionMatrix();
341
- }
342
- };
343
- function resolveAspect(renderer, domElement) {
344
- const size = renderer.getSize(tempVec2);
345
- if (size.y > 0) {
346
- return size.x / size.y;
347
- }
348
- const { clientWidth, clientHeight } = domElement;
349
- if (clientHeight > 0) {
350
- return clientWidth / clientHeight;
351
- }
352
- return 1;
353
- }
354
-
355
- export {
356
- DualCameraControls
357
- };