@tonybfox/threejs-tools 1.0.4 → 1.0.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 (45) hide show
  1. package/dist/asset-loader/index.cjs +3 -355
  2. package/dist/asset-loader/index.d.mts +6 -1
  3. package/dist/asset-loader/index.d.ts +6 -1
  4. package/dist/asset-loader/index.mjs +1 -6
  5. package/dist/camera/index.cjs +1 -393
  6. package/dist/camera/index.mjs +1 -6
  7. package/dist/chunk-4O4ENFL7.mjs +83 -0
  8. package/dist/chunk-55YVGK52.mjs +1 -0
  9. package/dist/chunk-B75TYEOO.mjs +44 -0
  10. package/dist/chunk-EQRUOKFV.mjs +1 -0
  11. package/dist/chunk-JRJBW66X.mjs +1 -0
  12. package/dist/chunk-OJFYE56U.mjs +1 -0
  13. package/dist/chunk-UJF4S4J3.mjs +1 -0
  14. package/dist/chunk-WZ4X7GQ2.mjs +1 -0
  15. package/dist/chunk-Z5VL3O6M.mjs +43 -0
  16. package/dist/compass/index.cjs +3 -304
  17. package/dist/compass/index.mjs +1 -6
  18. package/dist/grid/index.cjs +3 -159
  19. package/dist/grid/index.mjs +1 -6
  20. package/dist/index.cjs +7 -5005
  21. package/dist/index.d.mts +169 -1
  22. package/dist/index.d.ts +169 -1
  23. package/dist/index.mjs +1 -46
  24. package/dist/measurements/index.cjs +1 -1197
  25. package/dist/measurements/index.mjs +1 -8
  26. package/dist/sunlight/index.cjs +1 -440
  27. package/dist/sunlight/index.d.mts +19 -0
  28. package/dist/sunlight/index.d.ts +19 -0
  29. package/dist/sunlight/index.mjs +1 -6
  30. package/dist/terrain/index.cjs +1 -422
  31. package/dist/terrain/index.mjs +1 -6
  32. package/dist/transform-controls/index.cjs +1 -1586
  33. package/dist/transform-controls/index.mjs +1 -12
  34. package/dist/view-helper/index.cjs +1 -435
  35. package/dist/view-helper/index.mjs +1 -6
  36. package/package.json +1 -1
  37. package/dist/chunk-27WUVRGX.mjs +0 -360
  38. package/dist/chunk-2CDI7ORN.mjs +0 -163
  39. package/dist/chunk-FBTT6MU6.mjs +0 -386
  40. package/dist/chunk-IAZH4OHC.mjs +0 -399
  41. package/dist/chunk-OZKJ3GAD.mjs +0 -1160
  42. package/dist/chunk-W4DAAAW6.mjs +0 -404
  43. package/dist/chunk-XA7OKYSM.mjs +0 -357
  44. package/dist/chunk-YMMLYGHV.mjs +0 -1578
  45. package/dist/chunk-ZNGFST7K.mjs +0 -348
@@ -1,12 +1 @@
1
- import {
2
- TransformControls,
3
- TransformControlsGizmo,
4
- TransformControlsPlane,
5
- calculateBoundingBoxCenter
6
- } from "../chunk-YMMLYGHV.mjs";
7
- export {
8
- TransformControls,
9
- TransformControlsGizmo,
10
- TransformControlsPlane,
11
- calculateBoundingBoxCenter
12
- };
1
+ import{a,b,c,d}from"../chunk-WZ4X7GQ2.mjs";export{a as TransformControls,c as TransformControlsGizmo,d as TransformControlsPlane,b as calculateBoundingBoxCenter};
@@ -1,435 +1 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // packages/view-helper/src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- ViewHelper: () => ViewHelper
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
-
37
- // packages/view-helper/src/ViewHelper.ts
38
- var THREE = __toESM(require("three"));
39
- var AXIS_COLORS = {
40
- x: "#ed4358",
41
- y: "#82cc19",
42
- z: "#3185eb"
43
- };
44
- var ViewHelper = class extends THREE.EventDispatcher {
45
- constructor(camera, domElement, options = {}) {
46
- super();
47
- this.viewport = new THREE.Vector4();
48
- // Animation properties
49
- this.animating = false;
50
- this.targetPosition = new THREE.Vector3();
51
- this.targetQuaternion = new THREE.Quaternion();
52
- this.q1 = new THREE.Quaternion();
53
- this.q2 = new THREE.Quaternion();
54
- this.dummy = new THREE.Object3D();
55
- this.radius = 0;
56
- this.turnRate = 2 * Math.PI;
57
- // turn rate in angles per second
58
- this.tempVecA = new THREE.Vector3();
59
- // Interactive elements
60
- this.interactiveObjects = [];
61
- this.raycaster = new THREE.Raycaster();
62
- this.mouse = new THREE.Vector2();
63
- this.controls = options.controls;
64
- this.camera = this.controls?.camera ?? camera;
65
- this.domElement = domElement || document.body;
66
- const defaultCenter = options.center ?? (this.controls ? this.controls.getTarget(new THREE.Vector3()) : new THREE.Vector3());
67
- this.options = {
68
- container: options.container || document.body,
69
- size: options.size || 128,
70
- position: options.position || "bottom-right",
71
- offset: options.offset || { x: 20, y: 20 },
72
- center: defaultCenter.clone(),
73
- labels: {
74
- x: options.labels?.x || "x",
75
- y: options.labels?.y || "y",
76
- z: options.labels?.z || "z",
77
- ...options.labels
78
- }
79
- };
80
- this.center = this.options.center.clone();
81
- this.scene = new THREE.Scene();
82
- this.scene.background = null;
83
- this.orthoCamera = new THREE.OrthographicCamera(-2, 2, 2, -2, 0, 4);
84
- this.orthoCamera.position.set(0, 0, 2);
85
- this.createAxes();
86
- this.createSprites();
87
- this.setupEventListeners();
88
- }
89
- syncActiveCamera() {
90
- if (this.controls) {
91
- this.camera = this.controls.camera;
92
- }
93
- return this.camera;
94
- }
95
- getCameraPosition(target) {
96
- if (this.controls) {
97
- return this.controls.getPosition(target);
98
- }
99
- return target.copy(this.camera.position);
100
- }
101
- createAxes() {
102
- const geometry = new THREE.CylinderGeometry(0.04, 0.04, 0.8, 5).rotateZ(-Math.PI / 2).translate(0.4, 0, 0);
103
- const xAxisMaterial = new THREE.MeshBasicMaterial({
104
- color: AXIS_COLORS.x,
105
- toneMapped: false
106
- });
107
- const yAxisMaterial = new THREE.MeshBasicMaterial({
108
- color: AXIS_COLORS.y,
109
- toneMapped: false
110
- });
111
- const zAxisMaterial = new THREE.MeshBasicMaterial({
112
- color: AXIS_COLORS.z,
113
- toneMapped: false
114
- });
115
- this.axes = {
116
- x: new THREE.Mesh(geometry.clone(), xAxisMaterial),
117
- y: new THREE.Mesh(geometry.clone(), yAxisMaterial),
118
- z: new THREE.Mesh(geometry.clone(), zAxisMaterial)
119
- };
120
- this.axes.y.rotation.z = Math.PI / 2;
121
- this.axes.z.rotation.y = -Math.PI / 2;
122
- this.scene.add(this.axes.x);
123
- this.scene.add(this.axes.y);
124
- this.scene.add(this.axes.z);
125
- }
126
- createSprites() {
127
- const posXSprite = this.createSprite(AXIS_COLORS.x, this.options.labels.x);
128
- const posYSprite = this.createSprite(AXIS_COLORS.y, this.options.labels.y);
129
- const posZSprite = this.createSprite(AXIS_COLORS.z, this.options.labels.z);
130
- const negXSprite = this.createSprite(AXIS_COLORS.x);
131
- const negYSprite = this.createSprite(AXIS_COLORS.y);
132
- const negZSprite = this.createSprite(AXIS_COLORS.z);
133
- this.sprites = {
134
- posX: posXSprite,
135
- posY: posYSprite,
136
- posZ: posZSprite,
137
- negX: negXSprite,
138
- negY: negYSprite,
139
- negZ: negZSprite
140
- };
141
- this.sprites.posX.position.set(1, 0, 0);
142
- this.sprites.posY.position.set(0, 1, 0);
143
- this.sprites.posZ.position.set(0, 0, 1);
144
- this.sprites.negX.position.set(-1, 0, 0);
145
- this.sprites.negY.position.set(0, -1, 0);
146
- this.sprites.negZ.position.set(0, 0, -1);
147
- this.sprites.negX.material.opacity = 0.2;
148
- this.sprites.negY.material.opacity = 0.2;
149
- this.sprites.negZ.material.opacity = 0.2;
150
- this.sprites.posX.userData.type = "posX";
151
- this.sprites.posY.userData.type = "posY";
152
- this.sprites.posZ.userData.type = "posZ";
153
- this.sprites.negX.userData.type = "negX";
154
- this.sprites.negY.userData.type = "negY";
155
- this.sprites.negZ.userData.type = "negZ";
156
- Object.values(this.sprites).forEach((sprite) => {
157
- this.scene.add(sprite);
158
- this.interactiveObjects.push(sprite);
159
- });
160
- }
161
- createSprite(color, text) {
162
- const pixelRatio = window.devicePixelRatio || 1;
163
- const size = 128 * pixelRatio;
164
- const radius = 28 * pixelRatio;
165
- const canvas = document.createElement("canvas");
166
- canvas.width = size;
167
- canvas.height = size;
168
- const context = canvas.getContext("2d");
169
- context.imageSmoothingEnabled = true;
170
- context.imageSmoothingQuality = "high";
171
- context.scale(pixelRatio, pixelRatio);
172
- const center = size / (2 * pixelRatio);
173
- const actualRadius = radius / pixelRatio;
174
- context.beginPath();
175
- context.arc(center, center, actualRadius, 0, 2 * Math.PI);
176
- context.closePath();
177
- context.fillStyle = color;
178
- context.fill();
179
- if (text) {
180
- context.font = "bold 48px Arial, sans-serif";
181
- context.textAlign = "center";
182
- context.textBaseline = "middle";
183
- context.fillStyle = "#ffffff";
184
- context.strokeStyle = "#000000";
185
- context.lineWidth = 2;
186
- context.strokeText(text, center, center);
187
- context.fillText(text, center, center);
188
- }
189
- const texture = new THREE.CanvasTexture(canvas);
190
- texture.colorSpace = THREE.SRGBColorSpace;
191
- texture.generateMipmaps = false;
192
- texture.minFilter = THREE.LinearFilter;
193
- texture.magFilter = THREE.LinearFilter;
194
- return new THREE.Sprite(
195
- new THREE.SpriteMaterial({
196
- map: texture,
197
- toneMapped: false,
198
- alphaTest: 0.1
199
- })
200
- );
201
- }
202
- setupEventListeners() {
203
- this.pointerDownHandler = (event) => {
204
- this.handleClick(event);
205
- };
206
- this.domElement.addEventListener("pointerdown", this.pointerDownHandler);
207
- }
208
- render(renderer) {
209
- this.renderer = renderer;
210
- const activeCamera = this.syncActiveCamera();
211
- this.scene.quaternion.copy(activeCamera.quaternion).invert();
212
- this.scene.updateMatrixWorld();
213
- const size = this.options.size;
214
- const canvasWidth = renderer.domElement.width / renderer.getPixelRatio();
215
- const canvasHeight = renderer.domElement.height / renderer.getPixelRatio();
216
- let x, y;
217
- switch (this.options.position) {
218
- case "top-left":
219
- x = this.options.offset.x;
220
- y = canvasHeight - size - this.options.offset.y;
221
- break;
222
- case "top-right":
223
- x = canvasWidth - size - this.options.offset.x;
224
- y = canvasHeight - size - this.options.offset.y;
225
- break;
226
- case "bottom-left":
227
- x = this.options.offset.x;
228
- y = this.options.offset.y;
229
- break;
230
- case "bottom-right":
231
- default:
232
- x = canvasWidth - size - this.options.offset.x;
233
- y = this.options.offset.y;
234
- break;
235
- }
236
- renderer.getViewport(this.viewport);
237
- const autoClear = renderer.autoClear;
238
- renderer.setViewport(x, y, size, size);
239
- renderer.autoClear = false;
240
- renderer.setScissorTest(true);
241
- renderer.setScissor(x, y, size, size);
242
- renderer.clearDepth();
243
- renderer.render(this.scene, this.orthoCamera);
244
- renderer.setScissorTest(false);
245
- renderer.autoClear = autoClear;
246
- renderer.setViewport(
247
- this.viewport.x,
248
- this.viewport.y,
249
- this.viewport.z,
250
- this.viewport.w
251
- );
252
- }
253
- handleClick(event) {
254
- if (this.animating || !this.renderer) return false;
255
- this.syncActiveCamera();
256
- const rect = this.domElement.getBoundingClientRect();
257
- const size = this.options.size;
258
- let offsetX, offsetY;
259
- switch (this.options.position) {
260
- case "top-left":
261
- offsetX = rect.left + this.options.offset.x;
262
- offsetY = rect.top + this.options.offset.y;
263
- break;
264
- case "top-right":
265
- offsetX = rect.left + rect.width - size - this.options.offset.x;
266
- offsetY = rect.top + this.options.offset.y;
267
- break;
268
- case "bottom-left":
269
- offsetX = rect.left + this.options.offset.x;
270
- offsetY = rect.top + rect.height - size - this.options.offset.y;
271
- break;
272
- case "bottom-right":
273
- default:
274
- offsetX = rect.left + rect.width - size - this.options.offset.x;
275
- offsetY = rect.top + rect.height - size - this.options.offset.y;
276
- break;
277
- }
278
- this.mouse.x = (event.clientX - offsetX) / size * 2 - 1;
279
- this.mouse.y = -((event.clientY - offsetY) / size) * 2 + 1;
280
- if (this.mouse.x < -1 || this.mouse.x > 1 || this.mouse.y < -1 || this.mouse.y > 1) {
281
- return false;
282
- }
283
- this.raycaster.setFromCamera(this.mouse, this.orthoCamera);
284
- const intersects = this.raycaster.intersectObjects(this.interactiveObjects);
285
- if (intersects.length > 0) {
286
- const intersection = intersects[0];
287
- const object = intersection.object;
288
- this.prepareAnimationData(object, this.center);
289
- if (this.controls) {
290
- this.startControlsAnimation(this.center);
291
- } else {
292
- this.animating = true;
293
- this.dispatchEvent({ type: "animationStart" });
294
- }
295
- return true;
296
- }
297
- return false;
298
- }
299
- prepareAnimationData(object, focusPoint) {
300
- switch (object.userData.type) {
301
- case "posX":
302
- this.targetPosition.set(1, 0, 0);
303
- this.targetQuaternion.setFromEuler(new THREE.Euler(0, Math.PI * 0.5, 0));
304
- break;
305
- case "posY":
306
- this.targetPosition.set(0, 1, 0);
307
- this.targetQuaternion.setFromEuler(
308
- new THREE.Euler(-Math.PI * 0.5, 0, 0)
309
- );
310
- break;
311
- case "posZ":
312
- this.targetPosition.set(0, 0, 1);
313
- this.targetQuaternion.setFromEuler(new THREE.Euler());
314
- break;
315
- case "negX":
316
- this.targetPosition.set(-1, 0, 0);
317
- this.targetQuaternion.setFromEuler(
318
- new THREE.Euler(0, -Math.PI * 0.5, 0)
319
- );
320
- break;
321
- case "negY":
322
- this.targetPosition.set(0, -1, 0);
323
- this.targetQuaternion.setFromEuler(new THREE.Euler(Math.PI * 0.5, 0, 0));
324
- break;
325
- case "negZ":
326
- this.targetPosition.set(0, 0, -1);
327
- this.targetQuaternion.setFromEuler(new THREE.Euler(0, Math.PI, 0));
328
- break;
329
- default:
330
- console.error("ViewHelper: Invalid axis.");
331
- return;
332
- }
333
- const cameraPosition = this.getCameraPosition(this.tempVecA);
334
- this.radius = cameraPosition.distanceTo(focusPoint);
335
- this.targetPosition.multiplyScalar(this.radius).add(focusPoint);
336
- this.dummy.position.copy(focusPoint);
337
- this.dummy.lookAt(cameraPosition);
338
- this.q1.copy(this.dummy.quaternion);
339
- this.dummy.lookAt(this.targetPosition);
340
- this.q2.copy(this.dummy.quaternion);
341
- }
342
- startControlsAnimation(focusPoint) {
343
- const controls = this.controls;
344
- if (!controls) {
345
- return;
346
- }
347
- controls.enabled = false;
348
- controls.stop?.();
349
- this.animating = true;
350
- this.dispatchEvent({ type: "animationStart" });
351
- const applyLookAt = () => {
352
- controls.setLookAt(
353
- this.targetPosition.x,
354
- this.targetPosition.y,
355
- this.targetPosition.z,
356
- focusPoint.x,
357
- focusPoint.y,
358
- focusPoint.z,
359
- true
360
- );
361
- setTimeout(() => {
362
- controls.enabled = true;
363
- }, 100);
364
- };
365
- try {
366
- void Promise.resolve(applyLookAt()).catch((error) => {
367
- console.warn("ViewHelper: Unable to set camera look-at.", error);
368
- }).finally(() => {
369
- this.animating = false;
370
- this.dispatchEvent({ type: "animationEnd" });
371
- });
372
- } catch (error) {
373
- console.warn("ViewHelper: Unable to set camera look-at.", error);
374
- this.animating = false;
375
- this.dispatchEvent({ type: "animationEnd" });
376
- }
377
- }
378
- update(delta) {
379
- this.syncActiveCamera();
380
- if (this.controls) {
381
- return;
382
- }
383
- if (!this.animating) return;
384
- const step = delta * this.turnRate;
385
- this.q1.rotateTowards(this.q2, step);
386
- this.camera.position.set(0, 0, 1).applyQuaternion(this.q1).multiplyScalar(this.radius).add(this.center);
387
- this.camera.quaternion.rotateTowards(this.targetQuaternion, step);
388
- if (this.q1.angleTo(this.q2) === 0) {
389
- this.animating = false;
390
- this.dispatchEvent({ type: "animationEnd" });
391
- }
392
- }
393
- setLabels(labelX, labelY, labelZ) {
394
- if (labelX !== void 0) this.options.labels.x = labelX;
395
- if (labelY !== void 0) this.options.labels.y = labelY;
396
- if (labelZ !== void 0) this.options.labels.z = labelZ;
397
- this.updateLabels();
398
- }
399
- updateLabels() {
400
- this.sprites.posX.material.map?.dispose();
401
- this.sprites.posY.material.map?.dispose();
402
- this.sprites.posZ.material.map?.dispose();
403
- this.sprites.posX.material.dispose();
404
- this.sprites.posY.material.dispose();
405
- this.sprites.posZ.material.dispose();
406
- const newPosX = this.createSprite(AXIS_COLORS.x, this.options.labels.x);
407
- const newPosY = this.createSprite(AXIS_COLORS.y, this.options.labels.y);
408
- const newPosZ = this.createSprite(AXIS_COLORS.z, this.options.labels.z);
409
- this.sprites.posX.material = newPosX.material;
410
- this.sprites.posY.material = newPosY.material;
411
- this.sprites.posZ.material = newPosZ.material;
412
- }
413
- dispose() {
414
- this.axes.x.geometry.dispose();
415
- this.axes.y.geometry.dispose();
416
- this.axes.z.geometry.dispose();
417
- this.axes.x.material.dispose();
418
- this.axes.y.material.dispose();
419
- this.axes.z.material.dispose();
420
- Object.values(this.sprites).forEach((sprite) => {
421
- sprite.material.map?.dispose();
422
- sprite.material.dispose();
423
- });
424
- if (this.pointerDownHandler) {
425
- this.domElement.removeEventListener(
426
- "pointerdown",
427
- this.pointerDownHandler
428
- );
429
- }
430
- }
431
- };
432
- // Annotate the CommonJS export names for ESM import in node:
433
- 0 && (module.exports = {
434
- ViewHelper
435
- });
1
+ "use strict";var f=Object.create;var m=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var b=(n,p)=>{for(var t in p)m(n,t,{get:p[t],enumerable:!0})},d=(n,p,t,s)=>{if(p&&typeof p=="object"||typeof p=="function")for(let e of T(p))!R.call(n,e)&&e!==t&&m(n,e,{get:()=>p[e],enumerable:!(s=H(p,e))||s.enumerable});return n};var v=(n,p,t)=>(t=n!=null?f(y(n)):{},d(p||!n||!n.__esModule?m(t,"default",{value:n,enumerable:!0}):t,n)),w=n=>d(m({},"__esModule",{value:!0}),n);var x={};b(x,{ViewHelper:()=>u});module.exports=w(x);var i=v(require("three")),c={x:"#ed4358",y:"#82cc19",z:"#3185eb"},u=class extends i.EventDispatcher{constructor(t,s,e={}){super();this.viewport=new i.Vector4;this.animating=!1;this.targetPosition=new i.Vector3;this.targetQuaternion=new i.Quaternion;this.q1=new i.Quaternion;this.q2=new i.Quaternion;this.dummy=new i.Object3D;this.radius=0;this.turnRate=2*Math.PI;this.tempVecA=new i.Vector3;this.interactiveObjects=[];this.raycaster=new i.Raycaster;this.mouse=new i.Vector2;this.controls=e.controls,this.camera=this.controls?.camera??t,this.domElement=s||document.body;let a=e.center??(this.controls?this.controls.getTarget(new i.Vector3):new i.Vector3);this.options={container:e.container||document.body,size:e.size||128,position:e.position||"bottom-right",offset:e.offset||{x:20,y:20},center:a.clone(),labels:{x:e.labels?.x||"x",y:e.labels?.y||"y",z:e.labels?.z||"z",...e.labels}},this.center=this.options.center.clone(),this.scene=new i.Scene,this.scene.background=null,this.orthoCamera=new i.OrthographicCamera(-2,2,2,-2,0,4),this.orthoCamera.position.set(0,0,2),this.createAxes(),this.createSprites(),this.setupEventListeners()}syncActiveCamera(){return this.controls&&(this.camera=this.controls.camera),this.camera}getCameraPosition(t){return this.controls?this.controls.getPosition(t):t.copy(this.camera.position)}createAxes(){let t=new i.CylinderGeometry(.04,.04,.8,5).rotateZ(-Math.PI/2).translate(.4,0,0),s=new i.MeshBasicMaterial({color:c.x,toneMapped:!1}),e=new i.MeshBasicMaterial({color:c.y,toneMapped:!1}),a=new i.MeshBasicMaterial({color:c.z,toneMapped:!1});this.axes={x:new i.Mesh(t.clone(),s),y:new i.Mesh(t.clone(),e),z:new i.Mesh(t.clone(),a)},this.axes.y.rotation.z=Math.PI/2,this.axes.z.rotation.y=-Math.PI/2,this.scene.add(this.axes.x),this.scene.add(this.axes.y),this.scene.add(this.axes.z)}createSprites(){let t=this.createSprite(c.x,this.options.labels.x),s=this.createSprite(c.y,this.options.labels.y),e=this.createSprite(c.z,this.options.labels.z),a=this.createSprite(c.x),h=this.createSprite(c.y),r=this.createSprite(c.z);this.sprites={posX:t,posY:s,posZ:e,negX:a,negY:h,negZ:r},this.sprites.posX.position.set(1,0,0),this.sprites.posY.position.set(0,1,0),this.sprites.posZ.position.set(0,0,1),this.sprites.negX.position.set(-1,0,0),this.sprites.negY.position.set(0,-1,0),this.sprites.negZ.position.set(0,0,-1),this.sprites.negX.material.opacity=.2,this.sprites.negY.material.opacity=.2,this.sprites.negZ.material.opacity=.2,this.sprites.posX.userData.type="posX",this.sprites.posY.userData.type="posY",this.sprites.posZ.userData.type="posZ",this.sprites.negX.userData.type="negX",this.sprites.negY.userData.type="negY",this.sprites.negZ.userData.type="negZ",Object.values(this.sprites).forEach(o=>{this.scene.add(o),this.interactiveObjects.push(o)})}createSprite(t,s){let e=window.devicePixelRatio||1,a=128*e,h=28*e,r=document.createElement("canvas");r.width=a,r.height=a;let o=r.getContext("2d");o.imageSmoothingEnabled=!0,o.imageSmoothingQuality="high",o.scale(e,e);let l=a/(2*e),g=h/e;o.beginPath(),o.arc(l,l,g,0,2*Math.PI),o.closePath(),o.fillStyle=t,o.fill(),s&&(o.font="bold 48px Arial, sans-serif",o.textAlign="center",o.textBaseline="middle",o.fillStyle="#ffffff",o.strokeStyle="#000000",o.lineWidth=2,o.strokeText(s,l,l),o.fillText(s,l,l));let E=new i.CanvasTexture(r);return E.colorSpace=i.SRGBColorSpace,E.generateMipmaps=!1,E.minFilter=i.LinearFilter,E.magFilter=i.LinearFilter,new i.Sprite(new i.SpriteMaterial({map:E,toneMapped:!1,alphaTest:.1}))}setupEventListeners(){this.pointerDownHandler=t=>{this.handleClick(t)},this.domElement.addEventListener("pointerdown",this.pointerDownHandler)}render(t){this.renderer=t;let s=this.syncActiveCamera();this.scene.quaternion.copy(s.quaternion).invert(),this.scene.updateMatrixWorld();let e=this.options.size,a=t.domElement.width/t.getPixelRatio(),h=t.domElement.height/t.getPixelRatio(),r,o;switch(this.options.position){case"top-left":r=this.options.offset.x,o=h-e-this.options.offset.y;break;case"top-right":r=a-e-this.options.offset.x,o=h-e-this.options.offset.y;break;case"bottom-left":r=this.options.offset.x,o=this.options.offset.y;break;case"bottom-right":default:r=a-e-this.options.offset.x,o=this.options.offset.y;break}t.getViewport(this.viewport);let l=t.autoClear;t.setViewport(r,o,e,e),t.autoClear=!1,t.setScissorTest(!0),t.setScissor(r,o,e,e),t.clearDepth(),t.render(this.scene,this.orthoCamera),t.setScissorTest(!1),t.autoClear=l,t.setViewport(this.viewport.x,this.viewport.y,this.viewport.z,this.viewport.w)}handleClick(t){if(this.animating||!this.renderer)return!1;this.syncActiveCamera();let s=this.domElement.getBoundingClientRect(),e=this.options.size,a,h;switch(this.options.position){case"top-left":a=s.left+this.options.offset.x,h=s.top+this.options.offset.y;break;case"top-right":a=s.left+s.width-e-this.options.offset.x,h=s.top+this.options.offset.y;break;case"bottom-left":a=s.left+this.options.offset.x,h=s.top+s.height-e-this.options.offset.y;break;case"bottom-right":default:a=s.left+s.width-e-this.options.offset.x,h=s.top+s.height-e-this.options.offset.y;break}if(this.mouse.x=(t.clientX-a)/e*2-1,this.mouse.y=-((t.clientY-h)/e)*2+1,this.mouse.x<-1||this.mouse.x>1||this.mouse.y<-1||this.mouse.y>1)return!1;this.raycaster.setFromCamera(this.mouse,this.orthoCamera);let r=this.raycaster.intersectObjects(this.interactiveObjects);if(r.length>0){let l=r[0].object;return this.prepareAnimationData(l,this.center),this.controls?this.startControlsAnimation(this.center):(this.animating=!0,this.dispatchEvent({type:"animationStart"})),!0}return!1}prepareAnimationData(t,s){switch(t.userData.type){case"posX":this.targetPosition.set(1,0,0),this.targetQuaternion.setFromEuler(new i.Euler(0,Math.PI*.5,0));break;case"posY":this.targetPosition.set(0,1,0),this.targetQuaternion.setFromEuler(new i.Euler(-Math.PI*.5,0,0));break;case"posZ":this.targetPosition.set(0,0,1),this.targetQuaternion.setFromEuler(new i.Euler);break;case"negX":this.targetPosition.set(-1,0,0),this.targetQuaternion.setFromEuler(new i.Euler(0,-Math.PI*.5,0));break;case"negY":this.targetPosition.set(0,-1,0),this.targetQuaternion.setFromEuler(new i.Euler(Math.PI*.5,0,0));break;case"negZ":this.targetPosition.set(0,0,-1),this.targetQuaternion.setFromEuler(new i.Euler(0,Math.PI,0));break;default:console.error("ViewHelper: Invalid axis.");return}let e=this.getCameraPosition(this.tempVecA);this.radius=e.distanceTo(s),this.targetPosition.multiplyScalar(this.radius).add(s),this.dummy.position.copy(s),this.dummy.lookAt(e),this.q1.copy(this.dummy.quaternion),this.dummy.lookAt(this.targetPosition),this.q2.copy(this.dummy.quaternion)}startControlsAnimation(t){let s=this.controls;if(!s)return;s.enabled=!1,s.stop?.(),this.animating=!0,this.dispatchEvent({type:"animationStart"});let e=()=>{s.setLookAt(this.targetPosition.x,this.targetPosition.y,this.targetPosition.z,t.x,t.y,t.z,!0),setTimeout(()=>{s.enabled=!0},100)};try{Promise.resolve(e()).catch(a=>{console.warn("ViewHelper: Unable to set camera look-at.",a)}).finally(()=>{this.animating=!1,this.dispatchEvent({type:"animationEnd"})})}catch(a){console.warn("ViewHelper: Unable to set camera look-at.",a),this.animating=!1,this.dispatchEvent({type:"animationEnd"})}}update(t){if(this.syncActiveCamera(),this.controls||!this.animating)return;let s=t*this.turnRate;this.q1.rotateTowards(this.q2,s),this.camera.position.set(0,0,1).applyQuaternion(this.q1).multiplyScalar(this.radius).add(this.center),this.camera.quaternion.rotateTowards(this.targetQuaternion,s),this.q1.angleTo(this.q2)===0&&(this.animating=!1,this.dispatchEvent({type:"animationEnd"}))}setLabels(t,s,e){t!==void 0&&(this.options.labels.x=t),s!==void 0&&(this.options.labels.y=s),e!==void 0&&(this.options.labels.z=e),this.updateLabels()}updateLabels(){this.sprites.posX.material.map?.dispose(),this.sprites.posY.material.map?.dispose(),this.sprites.posZ.material.map?.dispose(),this.sprites.posX.material.dispose(),this.sprites.posY.material.dispose(),this.sprites.posZ.material.dispose();let t=this.createSprite(c.x,this.options.labels.x),s=this.createSprite(c.y,this.options.labels.y),e=this.createSprite(c.z,this.options.labels.z);this.sprites.posX.material=t.material,this.sprites.posY.material=s.material,this.sprites.posZ.material=e.material}dispose(){this.axes.x.geometry.dispose(),this.axes.y.geometry.dispose(),this.axes.z.geometry.dispose(),this.axes.x.material.dispose(),this.axes.y.material.dispose(),this.axes.z.material.dispose(),Object.values(this.sprites).forEach(t=>{t.material.map?.dispose(),t.material.dispose()}),this.pointerDownHandler&&this.domElement.removeEventListener("pointerdown",this.pointerDownHandler)}};0&&(module.exports={ViewHelper});
@@ -1,6 +1 @@
1
- import {
2
- ViewHelper
3
- } from "../chunk-IAZH4OHC.mjs";
4
- export {
5
- ViewHelper
6
- };
1
+ import{a}from"../chunk-UJF4S4J3.mjs";export{a as ViewHelper};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonybfox/threejs-tools",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A single entry point that bundles all Three.js tools (camera, terrain, measurements, helpers, and more).",
5
5
  "private": false,
6
6
  "main": "./dist/index.cjs",