@tonybfox/threejs-tools 1.0.3 → 1.0.5
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/asset-loader/index.cjs +64 -3
- package/dist/asset-loader/index.d.mts +6 -1
- package/dist/asset-loader/index.d.ts +6 -1
- package/dist/asset-loader/index.mjs +1 -2
- package/dist/camera/index.cjs +0 -1
- package/dist/camera/index.mjs +1 -2
- package/dist/{chunk-EQDOX34V.mjs → chunk-2CDI7ORN.mjs} +0 -1
- package/dist/{chunk-EIROAPF7.mjs → chunk-FBTT6MU6.mjs} +0 -1
- package/dist/{chunk-VETFQ3IQ.mjs → chunk-IAZH4OHC.mjs} +0 -1
- package/dist/{chunk-WZ6IGBSE.mjs → chunk-LUE7VHLK.mjs} +64 -3
- package/dist/{chunk-5DP6WDB3.mjs → chunk-OZKJ3GAD.mjs} +0 -1
- package/dist/{chunk-IIAZ2WJJ.mjs → chunk-W4DAAAW6.mjs} +0 -1
- package/dist/{chunk-IEE7DQOU.mjs → chunk-XA7OKYSM.mjs} +0 -1
- package/dist/{chunk-BJKSICFA.mjs → chunk-YMMLYGHV.mjs} +0 -1
- package/dist/{chunk-P35QJCOG.mjs → chunk-ZNGFST7K.mjs} +15 -6
- package/dist/compass/index.cjs +15 -6
- package/dist/compass/index.d.mts +4 -2
- package/dist/compass/index.d.ts +4 -2
- package/dist/compass/index.mjs +1 -2
- package/dist/grid/index.cjs +0 -1
- package/dist/grid/index.mjs +1 -2
- package/dist/index.cjs +485 -75
- package/dist/index.d.mts +169 -1
- package/dist/index.d.ts +169 -1
- package/dist/index.mjs +347 -10
- package/dist/measurements/index.cjs +0 -1
- package/dist/measurements/index.mjs +1 -2
- package/dist/sunlight/index.cjs +0 -1
- package/dist/sunlight/index.mjs +1 -2
- package/dist/terrain/index.cjs +0 -1
- package/dist/terrain/index.mjs +1 -2
- package/dist/transform-controls/index.cjs +0 -1
- package/dist/transform-controls/index.mjs +1 -2
- package/dist/view-helper/index.cjs +0 -1
- package/dist/view-helper/index.mjs +1 -2
- package/package.json +1 -1
- package/dist/asset-loader/index.cjs.map +0 -1
- package/dist/asset-loader/index.mjs.map +0 -1
- package/dist/camera/index.cjs.map +0 -1
- package/dist/camera/index.mjs.map +0 -1
- package/dist/chunk-5DP6WDB3.mjs.map +0 -1
- package/dist/chunk-BJKSICFA.mjs.map +0 -1
- package/dist/chunk-EIROAPF7.mjs.map +0 -1
- package/dist/chunk-EQDOX34V.mjs.map +0 -1
- package/dist/chunk-IEE7DQOU.mjs.map +0 -1
- package/dist/chunk-IIAZ2WJJ.mjs.map +0 -1
- package/dist/chunk-P35QJCOG.mjs.map +0 -1
- package/dist/chunk-VETFQ3IQ.mjs.map +0 -1
- package/dist/chunk-WZ6IGBSE.mjs.map +0 -1
- package/dist/compass/index.cjs.map +0 -1
- package/dist/compass/index.mjs.map +0 -1
- package/dist/grid/index.cjs.map +0 -1
- package/dist/grid/index.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/measurements/index.cjs.map +0 -1
- package/dist/measurements/index.mjs.map +0 -1
- package/dist/sunlight/index.cjs.map +0 -1
- package/dist/sunlight/index.mjs.map +0 -1
- package/dist/terrain/index.cjs.map +0 -1
- package/dist/terrain/index.mjs.map +0 -1
- package/dist/transform-controls/index.cjs.map +0 -1
- package/dist/transform-controls/index.mjs.map +0 -1
- package/dist/view-helper/index.cjs.map +0 -1
- package/dist/view-helper/index.mjs.map +0 -1
|
@@ -40,6 +40,10 @@ var import_GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader.js");
|
|
|
40
40
|
var import_FBXLoader = require("three/examples/jsm/loaders/FBXLoader.js");
|
|
41
41
|
var import_OBJLoader = require("three/examples/jsm/loaders/OBJLoader.js");
|
|
42
42
|
var import_USDLoader = require("three/examples/jsm/loaders/USDLoader.js");
|
|
43
|
+
var import_ColladaLoader = require("three/examples/jsm/loaders/ColladaLoader.js");
|
|
44
|
+
var import_STLLoader = require("three/examples/jsm/loaders/STLLoader.js");
|
|
45
|
+
var import_PLYLoader = require("three/examples/jsm/loaders/PLYLoader.js");
|
|
46
|
+
var import_MFLoader = require("three/examples/jsm/loaders/3MFLoader.js");
|
|
43
47
|
var AssetLoader = class extends THREE.EventDispatcher {
|
|
44
48
|
constructor() {
|
|
45
49
|
super();
|
|
@@ -53,6 +57,10 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
53
57
|
this.fbxLoader = new import_FBXLoader.FBXLoader();
|
|
54
58
|
this.objLoader = new import_OBJLoader.OBJLoader();
|
|
55
59
|
this.usdLoader = new import_USDLoader.USDLoader();
|
|
60
|
+
this.colladaLoader = new import_ColladaLoader.ColladaLoader();
|
|
61
|
+
this.stlLoader = new import_STLLoader.STLLoader();
|
|
62
|
+
this.plyLoader = new import_PLYLoader.PLYLoader();
|
|
63
|
+
this.threeMFLoader = new import_MFLoader.ThreeMFLoader();
|
|
56
64
|
}
|
|
57
65
|
/**
|
|
58
66
|
* Create a placeholder cube with shader effect
|
|
@@ -180,7 +188,7 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
180
188
|
const center = boundingBox.getCenter(new THREE.Vector3());
|
|
181
189
|
const bottomCenter = new THREE.Vector3(
|
|
182
190
|
center.x,
|
|
183
|
-
boundingBox.min.y
|
|
191
|
+
boundingBox.min.y - 0.01,
|
|
184
192
|
center.z
|
|
185
193
|
);
|
|
186
194
|
if (!Number.isFinite(bottomCenter.x) || !Number.isFinite(bottomCenter.y) || !Number.isFinite(bottomCenter.z)) {
|
|
@@ -222,6 +230,7 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
222
230
|
size,
|
|
223
231
|
lowResUrl,
|
|
224
232
|
enableCaching = true,
|
|
233
|
+
disablePlaceholder = false,
|
|
225
234
|
placeholderColor = 5227511,
|
|
226
235
|
placeholderOpacity = 0.4,
|
|
227
236
|
errorColor = 16729156,
|
|
@@ -241,7 +250,7 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
241
250
|
}
|
|
242
251
|
this.errorColor = errorColor;
|
|
243
252
|
this.errorOpacity = errorOpacity;
|
|
244
|
-
if (size) {
|
|
253
|
+
if (size && !disablePlaceholder) {
|
|
245
254
|
this.placeholder = this.createPlaceholder(
|
|
246
255
|
size,
|
|
247
256
|
placeholderColor,
|
|
@@ -348,6 +357,59 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
348
357
|
onError
|
|
349
358
|
);
|
|
350
359
|
break;
|
|
360
|
+
case "dae":
|
|
361
|
+
this.colladaLoader.load(
|
|
362
|
+
url,
|
|
363
|
+
(collada) => {
|
|
364
|
+
const scene = collada.scene;
|
|
365
|
+
this.positionAssetAtBottomCenter(scene);
|
|
366
|
+
resolve(scene);
|
|
367
|
+
},
|
|
368
|
+
onProgress,
|
|
369
|
+
onError
|
|
370
|
+
);
|
|
371
|
+
break;
|
|
372
|
+
case "stl":
|
|
373
|
+
this.stlLoader.load(
|
|
374
|
+
url,
|
|
375
|
+
(geometry) => {
|
|
376
|
+
const material = new THREE.MeshStandardMaterial({
|
|
377
|
+
color: 8947848
|
|
378
|
+
});
|
|
379
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
380
|
+
this.positionAssetAtBottomCenter(mesh);
|
|
381
|
+
resolve(mesh);
|
|
382
|
+
},
|
|
383
|
+
onProgress,
|
|
384
|
+
onError
|
|
385
|
+
);
|
|
386
|
+
break;
|
|
387
|
+
case "ply":
|
|
388
|
+
this.plyLoader.load(
|
|
389
|
+
url,
|
|
390
|
+
(geometry) => {
|
|
391
|
+
const material = new THREE.MeshStandardMaterial({
|
|
392
|
+
vertexColors: true
|
|
393
|
+
});
|
|
394
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
395
|
+
this.positionAssetAtBottomCenter(mesh);
|
|
396
|
+
resolve(mesh);
|
|
397
|
+
},
|
|
398
|
+
onProgress,
|
|
399
|
+
onError
|
|
400
|
+
);
|
|
401
|
+
break;
|
|
402
|
+
case "3mf":
|
|
403
|
+
this.threeMFLoader.load(
|
|
404
|
+
url,
|
|
405
|
+
(object) => {
|
|
406
|
+
this.positionAssetAtBottomCenter(object);
|
|
407
|
+
resolve(object);
|
|
408
|
+
},
|
|
409
|
+
onProgress,
|
|
410
|
+
onError
|
|
411
|
+
);
|
|
412
|
+
break;
|
|
351
413
|
default:
|
|
352
414
|
reject(new Error(`Unsupported asset type: ${type}`));
|
|
353
415
|
}
|
|
@@ -394,4 +456,3 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
394
456
|
0 && (module.exports = {
|
|
395
457
|
AssetLoader
|
|
396
458
|
});
|
|
397
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -19,13 +19,14 @@ interface AssetLoaderEventMap {
|
|
|
19
19
|
lowRes: THREE.Object3D;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz';
|
|
22
|
+
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz' | 'dae' | 'stl' | 'ply' | '3mf';
|
|
23
23
|
interface AssetLoaderOptions {
|
|
24
24
|
type: AssetType;
|
|
25
25
|
url: string;
|
|
26
26
|
size?: [number, number, number];
|
|
27
27
|
lowResUrl?: string;
|
|
28
28
|
enableCaching?: boolean;
|
|
29
|
+
disablePlaceholder?: boolean;
|
|
29
30
|
placeholderColor?: number;
|
|
30
31
|
placeholderOpacity?: number;
|
|
31
32
|
errorColor?: number;
|
|
@@ -37,6 +38,10 @@ declare class AssetLoader extends THREE.EventDispatcher<AssetLoaderEventMap> {
|
|
|
37
38
|
private fbxLoader;
|
|
38
39
|
private objLoader;
|
|
39
40
|
private usdLoader;
|
|
41
|
+
private colladaLoader;
|
|
42
|
+
private stlLoader;
|
|
43
|
+
private plyLoader;
|
|
44
|
+
private threeMFLoader;
|
|
40
45
|
private placeholder;
|
|
41
46
|
private loadedAsset;
|
|
42
47
|
private lowResAsset;
|
|
@@ -19,13 +19,14 @@ interface AssetLoaderEventMap {
|
|
|
19
19
|
lowRes: THREE.Object3D;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz';
|
|
22
|
+
type AssetType = 'gltf' | 'fbx' | 'obj' | 'usd' | 'usdz' | 'dae' | 'stl' | 'ply' | '3mf';
|
|
23
23
|
interface AssetLoaderOptions {
|
|
24
24
|
type: AssetType;
|
|
25
25
|
url: string;
|
|
26
26
|
size?: [number, number, number];
|
|
27
27
|
lowResUrl?: string;
|
|
28
28
|
enableCaching?: boolean;
|
|
29
|
+
disablePlaceholder?: boolean;
|
|
29
30
|
placeholderColor?: number;
|
|
30
31
|
placeholderOpacity?: number;
|
|
31
32
|
errorColor?: number;
|
|
@@ -37,6 +38,10 @@ declare class AssetLoader extends THREE.EventDispatcher<AssetLoaderEventMap> {
|
|
|
37
38
|
private fbxLoader;
|
|
38
39
|
private objLoader;
|
|
39
40
|
private usdLoader;
|
|
41
|
+
private colladaLoader;
|
|
42
|
+
private stlLoader;
|
|
43
|
+
private plyLoader;
|
|
44
|
+
private threeMFLoader;
|
|
40
45
|
private placeholder;
|
|
41
46
|
private loadedAsset;
|
|
42
47
|
private lowResAsset;
|
package/dist/camera/index.cjs
CHANGED
package/dist/camera/index.mjs
CHANGED
|
@@ -4,6 +4,10 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
|
4
4
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader.js";
|
|
5
5
|
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader.js";
|
|
6
6
|
import { USDLoader } from "three/examples/jsm/loaders/USDLoader.js";
|
|
7
|
+
import { ColladaLoader } from "three/examples/jsm/loaders/ColladaLoader.js";
|
|
8
|
+
import { STLLoader } from "three/examples/jsm/loaders/STLLoader.js";
|
|
9
|
+
import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
|
|
10
|
+
import { ThreeMFLoader } from "three/examples/jsm/loaders/3MFLoader.js";
|
|
7
11
|
var AssetLoader = class extends THREE.EventDispatcher {
|
|
8
12
|
constructor() {
|
|
9
13
|
super();
|
|
@@ -17,6 +21,10 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
17
21
|
this.fbxLoader = new FBXLoader();
|
|
18
22
|
this.objLoader = new OBJLoader();
|
|
19
23
|
this.usdLoader = new USDLoader();
|
|
24
|
+
this.colladaLoader = new ColladaLoader();
|
|
25
|
+
this.stlLoader = new STLLoader();
|
|
26
|
+
this.plyLoader = new PLYLoader();
|
|
27
|
+
this.threeMFLoader = new ThreeMFLoader();
|
|
20
28
|
}
|
|
21
29
|
/**
|
|
22
30
|
* Create a placeholder cube with shader effect
|
|
@@ -144,7 +152,7 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
144
152
|
const center = boundingBox.getCenter(new THREE.Vector3());
|
|
145
153
|
const bottomCenter = new THREE.Vector3(
|
|
146
154
|
center.x,
|
|
147
|
-
boundingBox.min.y
|
|
155
|
+
boundingBox.min.y - 0.01,
|
|
148
156
|
center.z
|
|
149
157
|
);
|
|
150
158
|
if (!Number.isFinite(bottomCenter.x) || !Number.isFinite(bottomCenter.y) || !Number.isFinite(bottomCenter.z)) {
|
|
@@ -186,6 +194,7 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
186
194
|
size,
|
|
187
195
|
lowResUrl,
|
|
188
196
|
enableCaching = true,
|
|
197
|
+
disablePlaceholder = false,
|
|
189
198
|
placeholderColor = 5227511,
|
|
190
199
|
placeholderOpacity = 0.4,
|
|
191
200
|
errorColor = 16729156,
|
|
@@ -205,7 +214,7 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
205
214
|
}
|
|
206
215
|
this.errorColor = errorColor;
|
|
207
216
|
this.errorOpacity = errorOpacity;
|
|
208
|
-
if (size) {
|
|
217
|
+
if (size && !disablePlaceholder) {
|
|
209
218
|
this.placeholder = this.createPlaceholder(
|
|
210
219
|
size,
|
|
211
220
|
placeholderColor,
|
|
@@ -312,6 +321,59 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
312
321
|
onError
|
|
313
322
|
);
|
|
314
323
|
break;
|
|
324
|
+
case "dae":
|
|
325
|
+
this.colladaLoader.load(
|
|
326
|
+
url,
|
|
327
|
+
(collada) => {
|
|
328
|
+
const scene = collada.scene;
|
|
329
|
+
this.positionAssetAtBottomCenter(scene);
|
|
330
|
+
resolve(scene);
|
|
331
|
+
},
|
|
332
|
+
onProgress,
|
|
333
|
+
onError
|
|
334
|
+
);
|
|
335
|
+
break;
|
|
336
|
+
case "stl":
|
|
337
|
+
this.stlLoader.load(
|
|
338
|
+
url,
|
|
339
|
+
(geometry) => {
|
|
340
|
+
const material = new THREE.MeshStandardMaterial({
|
|
341
|
+
color: 8947848
|
|
342
|
+
});
|
|
343
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
344
|
+
this.positionAssetAtBottomCenter(mesh);
|
|
345
|
+
resolve(mesh);
|
|
346
|
+
},
|
|
347
|
+
onProgress,
|
|
348
|
+
onError
|
|
349
|
+
);
|
|
350
|
+
break;
|
|
351
|
+
case "ply":
|
|
352
|
+
this.plyLoader.load(
|
|
353
|
+
url,
|
|
354
|
+
(geometry) => {
|
|
355
|
+
const material = new THREE.MeshStandardMaterial({
|
|
356
|
+
vertexColors: true
|
|
357
|
+
});
|
|
358
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
359
|
+
this.positionAssetAtBottomCenter(mesh);
|
|
360
|
+
resolve(mesh);
|
|
361
|
+
},
|
|
362
|
+
onProgress,
|
|
363
|
+
onError
|
|
364
|
+
);
|
|
365
|
+
break;
|
|
366
|
+
case "3mf":
|
|
367
|
+
this.threeMFLoader.load(
|
|
368
|
+
url,
|
|
369
|
+
(object) => {
|
|
370
|
+
this.positionAssetAtBottomCenter(object);
|
|
371
|
+
resolve(object);
|
|
372
|
+
},
|
|
373
|
+
onProgress,
|
|
374
|
+
onError
|
|
375
|
+
);
|
|
376
|
+
break;
|
|
315
377
|
default:
|
|
316
378
|
reject(new Error(`Unsupported asset type: ${type}`));
|
|
317
379
|
}
|
|
@@ -358,4 +420,3 @@ var AssetLoader = class extends THREE.EventDispatcher {
|
|
|
358
420
|
export {
|
|
359
421
|
AssetLoader
|
|
360
422
|
};
|
|
361
|
-
//# sourceMappingURL=chunk-WZ6IGBSE.mjs.map
|
|
@@ -11,6 +11,7 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
11
11
|
size: options.size || 100,
|
|
12
12
|
position: options.position || "bottom-right",
|
|
13
13
|
offset: options.offset || { x: 20, y: 20 },
|
|
14
|
+
northDirection: options.northDirection?.clone().normalize() || new THREE.Vector3(0, 0, -1),
|
|
14
15
|
colors: {
|
|
15
16
|
background: options.colors?.background || "#1a1a1a",
|
|
16
17
|
border: options.colors?.border || "#333333",
|
|
@@ -23,6 +24,7 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
23
24
|
this.container = this.options.container;
|
|
24
25
|
this.createCompassElement();
|
|
25
26
|
this.setupStyles();
|
|
27
|
+
this.start();
|
|
26
28
|
}
|
|
27
29
|
createCompassElement() {
|
|
28
30
|
this.compassElement = document.createElement("div");
|
|
@@ -229,8 +231,13 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
229
231
|
forward.transformDirection(cameraMatrix);
|
|
230
232
|
forward.y = 0;
|
|
231
233
|
forward.normalize();
|
|
234
|
+
const north = this.options.northDirection.clone();
|
|
235
|
+
north.y = 0;
|
|
236
|
+
north.normalize();
|
|
232
237
|
const targetAngle = Math.atan2(-forward.x, -forward.z) * (180 / Math.PI);
|
|
233
|
-
|
|
238
|
+
const northAngle = Math.atan2(-north.x, -north.z) * (180 / Math.PI);
|
|
239
|
+
const adjustedAngle = targetAngle - northAngle;
|
|
240
|
+
let angleDiff = adjustedAngle - this.currentRotation;
|
|
234
241
|
while (angleDiff > 180) angleDiff -= 360;
|
|
235
242
|
while (angleDiff < -180) angleDiff += 360;
|
|
236
243
|
this.currentRotation += angleDiff;
|
|
@@ -242,6 +249,9 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
242
249
|
setCamera(camera) {
|
|
243
250
|
this.camera = camera;
|
|
244
251
|
}
|
|
252
|
+
getNorthDirection() {
|
|
253
|
+
return this.options.northDirection.clone();
|
|
254
|
+
}
|
|
245
255
|
setSize(size) {
|
|
246
256
|
this.options.size = size;
|
|
247
257
|
this.compassElement.style.width = `${size}px`;
|
|
@@ -275,17 +285,17 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
275
285
|
this.updateStyles();
|
|
276
286
|
}
|
|
277
287
|
/**
|
|
278
|
-
* Helper method to reset camera to look north
|
|
288
|
+
* Helper method to reset camera to look north
|
|
279
289
|
* This is a convenience method that can be called when handling the 'resetToNorth' event
|
|
280
290
|
*/
|
|
281
|
-
static resetCameraToNorth(camera, smooth = true) {
|
|
291
|
+
static resetCameraToNorth(camera, smooth = true, northDirection = new THREE.Vector3(0, 0, -1)) {
|
|
282
292
|
if (smooth) {
|
|
283
293
|
const startQuaternion = camera.quaternion.clone();
|
|
284
294
|
const targetQuaternion = new THREE.Quaternion();
|
|
285
295
|
const targetMatrix = new THREE.Matrix4();
|
|
286
296
|
targetMatrix.lookAt(
|
|
287
297
|
camera.position,
|
|
288
|
-
camera.position.clone().add(
|
|
298
|
+
camera.position.clone().add(northDirection),
|
|
289
299
|
new THREE.Vector3(0, 1, 0)
|
|
290
300
|
);
|
|
291
301
|
targetQuaternion.setFromRotationMatrix(targetMatrix);
|
|
@@ -306,7 +316,7 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
306
316
|
};
|
|
307
317
|
animate();
|
|
308
318
|
} else {
|
|
309
|
-
camera.lookAt(camera.position.clone().add(
|
|
319
|
+
camera.lookAt(camera.position.clone().add(northDirection));
|
|
310
320
|
}
|
|
311
321
|
}
|
|
312
322
|
updateStyles() {
|
|
@@ -336,4 +346,3 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
336
346
|
export {
|
|
337
347
|
CompassOverlay
|
|
338
348
|
};
|
|
339
|
-
//# sourceMappingURL=chunk-P35QJCOG.mjs.map
|
package/dist/compass/index.cjs
CHANGED
|
@@ -47,6 +47,7 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
47
47
|
size: options.size || 100,
|
|
48
48
|
position: options.position || "bottom-right",
|
|
49
49
|
offset: options.offset || { x: 20, y: 20 },
|
|
50
|
+
northDirection: options.northDirection?.clone().normalize() || new THREE.Vector3(0, 0, -1),
|
|
50
51
|
colors: {
|
|
51
52
|
background: options.colors?.background || "#1a1a1a",
|
|
52
53
|
border: options.colors?.border || "#333333",
|
|
@@ -59,6 +60,7 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
59
60
|
this.container = this.options.container;
|
|
60
61
|
this.createCompassElement();
|
|
61
62
|
this.setupStyles();
|
|
63
|
+
this.start();
|
|
62
64
|
}
|
|
63
65
|
createCompassElement() {
|
|
64
66
|
this.compassElement = document.createElement("div");
|
|
@@ -265,8 +267,13 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
265
267
|
forward.transformDirection(cameraMatrix);
|
|
266
268
|
forward.y = 0;
|
|
267
269
|
forward.normalize();
|
|
270
|
+
const north = this.options.northDirection.clone();
|
|
271
|
+
north.y = 0;
|
|
272
|
+
north.normalize();
|
|
268
273
|
const targetAngle = Math.atan2(-forward.x, -forward.z) * (180 / Math.PI);
|
|
269
|
-
|
|
274
|
+
const northAngle = Math.atan2(-north.x, -north.z) * (180 / Math.PI);
|
|
275
|
+
const adjustedAngle = targetAngle - northAngle;
|
|
276
|
+
let angleDiff = adjustedAngle - this.currentRotation;
|
|
270
277
|
while (angleDiff > 180) angleDiff -= 360;
|
|
271
278
|
while (angleDiff < -180) angleDiff += 360;
|
|
272
279
|
this.currentRotation += angleDiff;
|
|
@@ -278,6 +285,9 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
278
285
|
setCamera(camera) {
|
|
279
286
|
this.camera = camera;
|
|
280
287
|
}
|
|
288
|
+
getNorthDirection() {
|
|
289
|
+
return this.options.northDirection.clone();
|
|
290
|
+
}
|
|
281
291
|
setSize(size) {
|
|
282
292
|
this.options.size = size;
|
|
283
293
|
this.compassElement.style.width = `${size}px`;
|
|
@@ -311,17 +321,17 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
311
321
|
this.updateStyles();
|
|
312
322
|
}
|
|
313
323
|
/**
|
|
314
|
-
* Helper method to reset camera to look north
|
|
324
|
+
* Helper method to reset camera to look north
|
|
315
325
|
* This is a convenience method that can be called when handling the 'resetToNorth' event
|
|
316
326
|
*/
|
|
317
|
-
static resetCameraToNorth(camera, smooth = true) {
|
|
327
|
+
static resetCameraToNorth(camera, smooth = true, northDirection = new THREE.Vector3(0, 0, -1)) {
|
|
318
328
|
if (smooth) {
|
|
319
329
|
const startQuaternion = camera.quaternion.clone();
|
|
320
330
|
const targetQuaternion = new THREE.Quaternion();
|
|
321
331
|
const targetMatrix = new THREE.Matrix4();
|
|
322
332
|
targetMatrix.lookAt(
|
|
323
333
|
camera.position,
|
|
324
|
-
camera.position.clone().add(
|
|
334
|
+
camera.position.clone().add(northDirection),
|
|
325
335
|
new THREE.Vector3(0, 1, 0)
|
|
326
336
|
);
|
|
327
337
|
targetQuaternion.setFromRotationMatrix(targetMatrix);
|
|
@@ -342,7 +352,7 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
342
352
|
};
|
|
343
353
|
animate();
|
|
344
354
|
} else {
|
|
345
|
-
camera.lookAt(camera.position.clone().add(
|
|
355
|
+
camera.lookAt(camera.position.clone().add(northDirection));
|
|
346
356
|
}
|
|
347
357
|
}
|
|
348
358
|
updateStyles() {
|
|
@@ -372,4 +382,3 @@ var CompassOverlay = class extends THREE.EventDispatcher {
|
|
|
372
382
|
0 && (module.exports = {
|
|
373
383
|
CompassOverlay
|
|
374
384
|
});
|
|
375
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/compass/index.d.mts
CHANGED
|
@@ -8,6 +8,7 @@ interface CompassOverlayOptions {
|
|
|
8
8
|
x: number;
|
|
9
9
|
y: number;
|
|
10
10
|
};
|
|
11
|
+
northDirection?: THREE.Vector3;
|
|
11
12
|
colors?: {
|
|
12
13
|
background: string;
|
|
13
14
|
border: string;
|
|
@@ -40,6 +41,7 @@ declare class CompassOverlay extends THREE.EventDispatcher<CompassOverlayEventMa
|
|
|
40
41
|
stop(): void;
|
|
41
42
|
update(): void;
|
|
42
43
|
setCamera(camera: THREE.Camera): void;
|
|
44
|
+
getNorthDirection(): THREE.Vector3;
|
|
43
45
|
setSize(size: number): void;
|
|
44
46
|
setPosition(position: CompassOverlayOptions['position'], offset?: {
|
|
45
47
|
x: number;
|
|
@@ -47,10 +49,10 @@ declare class CompassOverlay extends THREE.EventDispatcher<CompassOverlayEventMa
|
|
|
47
49
|
}): void;
|
|
48
50
|
setColors(colors: Partial<CompassOverlayOptions['colors']>): void;
|
|
49
51
|
/**
|
|
50
|
-
* Helper method to reset camera to look north
|
|
52
|
+
* Helper method to reset camera to look north
|
|
51
53
|
* This is a convenience method that can be called when handling the 'resetToNorth' event
|
|
52
54
|
*/
|
|
53
|
-
static resetCameraToNorth(camera: THREE.Camera, smooth?: boolean): void;
|
|
55
|
+
static resetCameraToNorth(camera: THREE.Camera, smooth?: boolean, northDirection?: THREE.Vector3): void;
|
|
54
56
|
private updateStyles;
|
|
55
57
|
dispose(): void;
|
|
56
58
|
}
|
package/dist/compass/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface CompassOverlayOptions {
|
|
|
8
8
|
x: number;
|
|
9
9
|
y: number;
|
|
10
10
|
};
|
|
11
|
+
northDirection?: THREE.Vector3;
|
|
11
12
|
colors?: {
|
|
12
13
|
background: string;
|
|
13
14
|
border: string;
|
|
@@ -40,6 +41,7 @@ declare class CompassOverlay extends THREE.EventDispatcher<CompassOverlayEventMa
|
|
|
40
41
|
stop(): void;
|
|
41
42
|
update(): void;
|
|
42
43
|
setCamera(camera: THREE.Camera): void;
|
|
44
|
+
getNorthDirection(): THREE.Vector3;
|
|
43
45
|
setSize(size: number): void;
|
|
44
46
|
setPosition(position: CompassOverlayOptions['position'], offset?: {
|
|
45
47
|
x: number;
|
|
@@ -47,10 +49,10 @@ declare class CompassOverlay extends THREE.EventDispatcher<CompassOverlayEventMa
|
|
|
47
49
|
}): void;
|
|
48
50
|
setColors(colors: Partial<CompassOverlayOptions['colors']>): void;
|
|
49
51
|
/**
|
|
50
|
-
* Helper method to reset camera to look north
|
|
52
|
+
* Helper method to reset camera to look north
|
|
51
53
|
* This is a convenience method that can be called when handling the 'resetToNorth' event
|
|
52
54
|
*/
|
|
53
|
-
static resetCameraToNorth(camera: THREE.Camera, smooth?: boolean): void;
|
|
55
|
+
static resetCameraToNorth(camera: THREE.Camera, smooth?: boolean, northDirection?: THREE.Vector3): void;
|
|
54
56
|
private updateStyles;
|
|
55
57
|
dispose(): void;
|
|
56
58
|
}
|
package/dist/compass/index.mjs
CHANGED
package/dist/grid/index.cjs
CHANGED