@ridp/threejs 1.1.7 → 1.2.0

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 (77) hide show
  1. package/dist/common-C1rNPPkt.cjs +15 -0
  2. package/dist/common-D1_IztgM.js +54 -0
  3. package/dist/hooks.cjs +1 -1
  4. package/dist/hooks.js +4 -4
  5. package/dist/modelSerialize-5oJb1ka7.js +965 -0
  6. package/dist/modelSerialize-Ds_2KBaA.cjs +5 -0
  7. package/dist/threejs.cjs +1 -1
  8. package/dist/threejs.js +184 -24
  9. package/dist/useGLTFLoader-2awW2QaH.cjs +4 -0
  10. package/dist/useGLTFLoader-BBGTGOYm.js +5507 -0
  11. package/dist/utils.cjs +1 -1
  12. package/dist/utils.js +18 -16
  13. package/esdoc/ast/source/.external-ecmascript.js.json +2801 -2801
  14. package/esdoc/ast/source/hooks/index.js.json +738 -738
  15. package/esdoc/ast/source/hooks/useGLTFLoader.js.json +9110 -9110
  16. package/esdoc/ast/source/hooks/useObb.js.json +16462 -16462
  17. package/esdoc/ast/source/hooks/useRaycaster.js.json +15555 -15555
  18. package/esdoc/ast/source/hooks/useThreeJs.js.json +52886 -52886
  19. package/esdoc/ast/source/index.js.json +569 -569
  20. package/esdoc/ast/source/instance/IDBCache.js.json +40977 -40977
  21. package/esdoc/ast/source/instance/index.js.json +231 -231
  22. package/esdoc/ast/source/utils/ImageLoader.js.json +7036 -7036
  23. package/esdoc/ast/source/utils/common.js.json +5133 -5133
  24. package/esdoc/ast/source/utils/css3dHelper.js.json +9100 -9100
  25. package/esdoc/ast/source/utils/disposeObject.js.json +5977 -5977
  26. package/esdoc/ast/source/utils/helper.js.json +10521 -10521
  27. package/esdoc/ast/source/utils/index.js.json +907 -907
  28. package/esdoc/badge.svg +17 -17
  29. package/esdoc/class/src/instance/IDBCache.js~IDBCache.html +1299 -1299
  30. package/esdoc/coverage.json +85 -85
  31. package/esdoc/css/github.css +83 -83
  32. package/esdoc/css/identifiers.css +37 -37
  33. package/esdoc/css/manual.css +134 -134
  34. package/esdoc/css/prettify-tomorrow.css +132 -132
  35. package/esdoc/css/search.css +84 -84
  36. package/esdoc/css/source.css +55 -55
  37. package/esdoc/css/style.css +608 -608
  38. package/esdoc/css/test.css +58 -58
  39. package/esdoc/file/src/hooks/index.js.html +75 -75
  40. package/esdoc/file/src/hooks/useGLTFLoader.js.html +75 -75
  41. package/esdoc/file/src/hooks/useObb.js.html +75 -75
  42. package/esdoc/file/src/hooks/useRaycaster.js.html +75 -75
  43. package/esdoc/file/src/hooks/useThreeJs.js.html +75 -75
  44. package/esdoc/file/src/index.js.html +75 -75
  45. package/esdoc/file/src/instance/IDBCache.js.html +75 -75
  46. package/esdoc/file/src/instance/index.js.html +75 -75
  47. package/esdoc/file/src/utils/ImageLoader.js.html +75 -75
  48. package/esdoc/file/src/utils/common.js.html +75 -75
  49. package/esdoc/file/src/utils/css3dHelper.js.html +75 -75
  50. package/esdoc/file/src/utils/disposeObject.js.html +75 -75
  51. package/esdoc/file/src/utils/helper.js.html +75 -75
  52. package/esdoc/file/src/utils/index.js.html +75 -75
  53. package/esdoc/function/index.html +2019 -2019
  54. package/esdoc/identifiers.html +738 -738
  55. package/esdoc/image/badge.svg +17 -17
  56. package/esdoc/image/manual-badge.svg +17 -17
  57. package/esdoc/index.html +153 -153
  58. package/esdoc/index.json +2050 -2050
  59. package/esdoc/script/inherited-summary.js +28 -28
  60. package/esdoc/script/inner-link.js +32 -32
  61. package/esdoc/script/manual.js +12 -12
  62. package/esdoc/script/patch-for-local.js +8 -8
  63. package/esdoc/script/prettify/Apache-License-2.0.txt +202 -202
  64. package/esdoc/script/prettify/prettify.js +46 -46
  65. package/esdoc/script/pretty-print.js +25 -25
  66. package/esdoc/script/search.js +117 -117
  67. package/esdoc/script/search_index.js +571 -571
  68. package/esdoc/script/test-summary.js +54 -54
  69. package/esdoc/source.html +213 -213
  70. package/esdoc/variable/index.html +225 -225
  71. package/package.json +3 -5
  72. package/dist/ImageLoader-B_rHfhtt.cjs +0 -1
  73. package/dist/ImageLoader-D9uANgrl.js +0 -1475
  74. package/dist/common-DTEEkXFr.cjs +0 -1
  75. package/dist/common-DhuVL1VV.js +0 -73
  76. package/dist/useGLTFLoader-BDER-upw.cjs +0 -1
  77. package/dist/useGLTFLoader-UD3WYZET.js +0 -7016
@@ -1,1475 +0,0 @@
1
- import { Object3D, Matrix4, Vector3, Quaternion, Controls, MOUSE, TOUCH, Spherical, Vector2, Ray, Plane, MathUtils, CameraHelper, GridHelper, BoxHelper, Raycaster, AxesHelper, ArrowHelper, DataTextureLoader, HalfFloatType, FloatType, DataUtils, LinearSRGBColorSpace, LinearFilter, EquirectangularReflectionMapping } from "three";
2
- var Stats = function() {
3
- var mode = 0;
4
- var container = document.createElement("div");
5
- container.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";
6
- container.addEventListener("click", function(event) {
7
- event.preventDefault();
8
- showPanel(++mode % container.children.length);
9
- }, false);
10
- function addPanel(panel) {
11
- container.appendChild(panel.dom);
12
- return panel;
13
- }
14
- function showPanel(id) {
15
- for (var i = 0; i < container.children.length; i++) {
16
- container.children[i].style.display = i === id ? "block" : "none";
17
- }
18
- mode = id;
19
- }
20
- var beginTime = (performance || Date).now(), prevTime = beginTime, frames = 0;
21
- var fpsPanel = addPanel(new Stats.Panel("FPS", "#0ff", "#002"));
22
- var msPanel = addPanel(new Stats.Panel("MS", "#0f0", "#020"));
23
- if (self.performance && self.performance.memory) {
24
- var memPanel = addPanel(new Stats.Panel("MB", "#f08", "#201"));
25
- }
26
- showPanel(0);
27
- return {
28
- REVISION: 16,
29
- dom: container,
30
- addPanel,
31
- showPanel,
32
- begin: function() {
33
- beginTime = (performance || Date).now();
34
- },
35
- end: function() {
36
- frames++;
37
- var time = (performance || Date).now();
38
- msPanel.update(time - beginTime, 200);
39
- if (time >= prevTime + 1e3) {
40
- fpsPanel.update(frames * 1e3 / (time - prevTime), 100);
41
- prevTime = time;
42
- frames = 0;
43
- if (memPanel) {
44
- var memory = performance.memory;
45
- memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
46
- }
47
- }
48
- return time;
49
- },
50
- update: function() {
51
- beginTime = this.end();
52
- },
53
- // Backwards Compatibility
54
- domElement: container,
55
- setMode: showPanel
56
- };
57
- };
58
- Stats.Panel = function(name, fg, bg) {
59
- var min = Infinity, max = 0, round = Math.round;
60
- var PR = round(window.devicePixelRatio || 1);
61
- var WIDTH = 80 * PR, HEIGHT = 48 * PR, TEXT_X = 3 * PR, TEXT_Y = 2 * PR, GRAPH_X = 3 * PR, GRAPH_Y = 15 * PR, GRAPH_WIDTH = 74 * PR, GRAPH_HEIGHT = 30 * PR;
62
- var canvas = document.createElement("canvas");
63
- canvas.width = WIDTH;
64
- canvas.height = HEIGHT;
65
- canvas.style.cssText = "width:80px;height:48px";
66
- var context = canvas.getContext("2d");
67
- context.font = "bold " + 9 * PR + "px Helvetica,Arial,sans-serif";
68
- context.textBaseline = "top";
69
- context.fillStyle = bg;
70
- context.fillRect(0, 0, WIDTH, HEIGHT);
71
- context.fillStyle = fg;
72
- context.fillText(name, TEXT_X, TEXT_Y);
73
- context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
74
- context.fillStyle = bg;
75
- context.globalAlpha = 0.9;
76
- context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
77
- return {
78
- dom: canvas,
79
- update: function(value, maxValue) {
80
- min = Math.min(min, value);
81
- max = Math.max(max, value);
82
- context.fillStyle = bg;
83
- context.globalAlpha = 1;
84
- context.fillRect(0, 0, WIDTH, GRAPH_Y);
85
- context.fillStyle = fg;
86
- context.fillText(round(value) + " " + name + " (" + round(min) + "-" + round(max) + ")", TEXT_X, TEXT_Y);
87
- context.drawImage(canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT);
88
- context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT);
89
- context.fillStyle = bg;
90
- context.globalAlpha = 0.9;
91
- context.fillRect(GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round((1 - value / maxValue) * GRAPH_HEIGHT));
92
- }
93
- };
94
- };
95
- const _position = new Vector3();
96
- const _quaternion = new Quaternion();
97
- const _scale = new Vector3();
98
- class CSS3DObject extends Object3D {
99
- /**
100
- * Constructs a new CSS3D object.
101
- *
102
- * @param {DOMElement} [element] - The DOM element.
103
- */
104
- constructor(element = document.createElement("div")) {
105
- super();
106
- this.isCSS3DObject = true;
107
- this.element = element;
108
- this.element.style.position = "absolute";
109
- this.element.style.pointerEvents = "auto";
110
- this.element.style.userSelect = "none";
111
- this.element.setAttribute("draggable", false);
112
- this.addEventListener("removed", function() {
113
- this.traverse(function(object) {
114
- if (object.element instanceof object.element.ownerDocument.defaultView.Element && object.element.parentNode !== null) {
115
- object.element.remove();
116
- }
117
- });
118
- });
119
- }
120
- copy(source, recursive) {
121
- super.copy(source, recursive);
122
- this.element = source.element.cloneNode(true);
123
- return this;
124
- }
125
- }
126
- class CSS3DSprite extends CSS3DObject {
127
- /**
128
- * Constructs a new CSS3D sprite object.
129
- *
130
- * @param {DOMElement} [element] - The DOM element.
131
- */
132
- constructor(element) {
133
- super(element);
134
- this.isCSS3DSprite = true;
135
- this.rotation2D = 0;
136
- }
137
- copy(source, recursive) {
138
- super.copy(source, recursive);
139
- this.rotation2D = source.rotation2D;
140
- return this;
141
- }
142
- }
143
- const _matrix = new Matrix4();
144
- const _matrix2 = new Matrix4();
145
- class CSS3DRenderer {
146
- /**
147
- * Constructs a new CSS3D renderer.
148
- *
149
- * @param {CSS3DRenderer~Parameters} [parameters] - The parameters.
150
- */
151
- constructor(parameters = {}) {
152
- const _this = this;
153
- let _width, _height;
154
- let _widthHalf, _heightHalf;
155
- const cache = {
156
- camera: { style: "" },
157
- objects: /* @__PURE__ */ new WeakMap()
158
- };
159
- const domElement = parameters.element !== void 0 ? parameters.element : document.createElement("div");
160
- domElement.style.overflow = "hidden";
161
- this.domElement = domElement;
162
- const viewElement = document.createElement("div");
163
- viewElement.style.transformOrigin = "0 0";
164
- viewElement.style.pointerEvents = "none";
165
- domElement.appendChild(viewElement);
166
- const cameraElement = document.createElement("div");
167
- cameraElement.style.transformStyle = "preserve-3d";
168
- viewElement.appendChild(cameraElement);
169
- this.getSize = function() {
170
- return {
171
- width: _width,
172
- height: _height
173
- };
174
- };
175
- this.render = function(scene, camera) {
176
- const fov = camera.projectionMatrix.elements[5] * _heightHalf;
177
- if (camera.view && camera.view.enabled) {
178
- viewElement.style.transform = `translate( ${-camera.view.offsetX * (_width / camera.view.width)}px, ${-camera.view.offsetY * (_height / camera.view.height)}px )`;
179
- viewElement.style.transform += `scale( ${camera.view.fullWidth / camera.view.width}, ${camera.view.fullHeight / camera.view.height} )`;
180
- } else {
181
- viewElement.style.transform = "";
182
- }
183
- if (scene.matrixWorldAutoUpdate === true) scene.updateMatrixWorld();
184
- if (camera.parent === null && camera.matrixWorldAutoUpdate === true) camera.updateMatrixWorld();
185
- let tx, ty;
186
- if (camera.isOrthographicCamera) {
187
- tx = -(camera.right + camera.left) / 2;
188
- ty = (camera.top + camera.bottom) / 2;
189
- }
190
- const scaleByViewOffset = camera.view && camera.view.enabled ? camera.view.height / camera.view.fullHeight : 1;
191
- const cameraCSSMatrix = camera.isOrthographicCamera ? `scale( ${scaleByViewOffset} )scale(` + fov + ")translate(" + epsilon(tx) + "px," + epsilon(ty) + "px)" + getCameraCSSMatrix(camera.matrixWorldInverse) : `scale( ${scaleByViewOffset} )translateZ(` + fov + "px)" + getCameraCSSMatrix(camera.matrixWorldInverse);
192
- const perspective = camera.isPerspectiveCamera ? "perspective(" + fov + "px) " : "";
193
- const style = perspective + cameraCSSMatrix + "translate(" + _widthHalf + "px," + _heightHalf + "px)";
194
- if (cache.camera.style !== style) {
195
- cameraElement.style.transform = style;
196
- cache.camera.style = style;
197
- }
198
- renderObject(scene, scene, camera);
199
- };
200
- this.setSize = function(width, height) {
201
- _width = width;
202
- _height = height;
203
- _widthHalf = _width / 2;
204
- _heightHalf = _height / 2;
205
- domElement.style.width = width + "px";
206
- domElement.style.height = height + "px";
207
- viewElement.style.width = width + "px";
208
- viewElement.style.height = height + "px";
209
- cameraElement.style.width = width + "px";
210
- cameraElement.style.height = height + "px";
211
- };
212
- function epsilon(value) {
213
- return Math.abs(value) < 1e-10 ? 0 : value;
214
- }
215
- function getCameraCSSMatrix(matrix) {
216
- const elements = matrix.elements;
217
- return "matrix3d(" + epsilon(elements[0]) + "," + epsilon(-elements[1]) + "," + epsilon(elements[2]) + "," + epsilon(elements[3]) + "," + epsilon(elements[4]) + "," + epsilon(-elements[5]) + "," + epsilon(elements[6]) + "," + epsilon(elements[7]) + "," + epsilon(elements[8]) + "," + epsilon(-elements[9]) + "," + epsilon(elements[10]) + "," + epsilon(elements[11]) + "," + epsilon(elements[12]) + "," + epsilon(-elements[13]) + "," + epsilon(elements[14]) + "," + epsilon(elements[15]) + ")";
218
- }
219
- function getObjectCSSMatrix(matrix) {
220
- const elements = matrix.elements;
221
- const matrix3d = "matrix3d(" + epsilon(elements[0]) + "," + epsilon(elements[1]) + "," + epsilon(elements[2]) + "," + epsilon(elements[3]) + "," + epsilon(-elements[4]) + "," + epsilon(-elements[5]) + "," + epsilon(-elements[6]) + "," + epsilon(-elements[7]) + "," + epsilon(elements[8]) + "," + epsilon(elements[9]) + "," + epsilon(elements[10]) + "," + epsilon(elements[11]) + "," + epsilon(elements[12]) + "," + epsilon(elements[13]) + "," + epsilon(elements[14]) + "," + epsilon(elements[15]) + ")";
222
- return "translate(-50%,-50%)" + matrix3d;
223
- }
224
- function hideObject(object) {
225
- if (object.isCSS3DObject) object.element.style.display = "none";
226
- for (let i = 0, l = object.children.length; i < l; i++) {
227
- hideObject(object.children[i]);
228
- }
229
- }
230
- function renderObject(object, scene, camera, cameraCSSMatrix) {
231
- if (object.visible === false) {
232
- hideObject(object);
233
- return;
234
- }
235
- if (object.isCSS3DObject) {
236
- const visible = object.layers.test(camera.layers) === true;
237
- const element = object.element;
238
- element.style.display = visible === true ? "" : "none";
239
- if (visible === true) {
240
- object.onBeforeRender(_this, scene, camera);
241
- let style;
242
- if (object.isCSS3DSprite) {
243
- _matrix.copy(camera.matrixWorldInverse);
244
- _matrix.transpose();
245
- if (object.rotation2D !== 0) _matrix.multiply(_matrix2.makeRotationZ(object.rotation2D));
246
- object.matrixWorld.decompose(_position, _quaternion, _scale);
247
- _matrix.setPosition(_position);
248
- _matrix.scale(_scale);
249
- _matrix.elements[3] = 0;
250
- _matrix.elements[7] = 0;
251
- _matrix.elements[11] = 0;
252
- _matrix.elements[15] = 1;
253
- style = getObjectCSSMatrix(_matrix);
254
- } else {
255
- style = getObjectCSSMatrix(object.matrixWorld);
256
- }
257
- const cachedObject = cache.objects.get(object);
258
- if (cachedObject === void 0 || cachedObject.style !== style) {
259
- element.style.transform = style;
260
- const objectData = { style };
261
- cache.objects.set(object, objectData);
262
- }
263
- if (element.parentNode !== cameraElement) {
264
- cameraElement.appendChild(element);
265
- }
266
- object.onAfterRender(_this, scene, camera);
267
- }
268
- }
269
- for (let i = 0, l = object.children.length; i < l; i++) {
270
- renderObject(object.children[i], scene, camera);
271
- }
272
- }
273
- }
274
- }
275
- const _changeEvent = { type: "change" };
276
- const _startEvent = { type: "start" };
277
- const _endEvent = { type: "end" };
278
- const _ray = new Ray();
279
- const _plane = new Plane();
280
- const _TILT_LIMIT = Math.cos(70 * MathUtils.DEG2RAD);
281
- const _v = new Vector3();
282
- const _twoPI = 2 * Math.PI;
283
- const _STATE = {
284
- NONE: -1,
285
- ROTATE: 0,
286
- DOLLY: 1,
287
- PAN: 2,
288
- TOUCH_ROTATE: 3,
289
- TOUCH_PAN: 4,
290
- TOUCH_DOLLY_PAN: 5,
291
- TOUCH_DOLLY_ROTATE: 6
292
- };
293
- const _EPS = 1e-6;
294
- class OrbitControls extends Controls {
295
- /**
296
- * Constructs a new controls instance.
297
- *
298
- * @param {Object3D} object - The object that is managed by the controls.
299
- * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
300
- */
301
- constructor(object, domElement = null) {
302
- super(object, domElement);
303
- this.state = _STATE.NONE;
304
- this.target = new Vector3();
305
- this.cursor = new Vector3();
306
- this.minDistance = 0;
307
- this.maxDistance = Infinity;
308
- this.minZoom = 0;
309
- this.maxZoom = Infinity;
310
- this.minTargetRadius = 0;
311
- this.maxTargetRadius = Infinity;
312
- this.minPolarAngle = 0;
313
- this.maxPolarAngle = Math.PI;
314
- this.minAzimuthAngle = -Infinity;
315
- this.maxAzimuthAngle = Infinity;
316
- this.enableDamping = false;
317
- this.dampingFactor = 0.05;
318
- this.enableZoom = true;
319
- this.zoomSpeed = 1;
320
- this.enableRotate = true;
321
- this.rotateSpeed = 1;
322
- this.keyRotateSpeed = 1;
323
- this.enablePan = true;
324
- this.panSpeed = 1;
325
- this.screenSpacePanning = true;
326
- this.keyPanSpeed = 7;
327
- this.zoomToCursor = false;
328
- this.autoRotate = false;
329
- this.autoRotateSpeed = 2;
330
- this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
331
- this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
332
- this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
333
- this.target0 = this.target.clone();
334
- this.position0 = this.object.position.clone();
335
- this.zoom0 = this.object.zoom;
336
- this._domElementKeyEvents = null;
337
- this._lastPosition = new Vector3();
338
- this._lastQuaternion = new Quaternion();
339
- this._lastTargetPosition = new Vector3();
340
- this._quat = new Quaternion().setFromUnitVectors(object.up, new Vector3(0, 1, 0));
341
- this._quatInverse = this._quat.clone().invert();
342
- this._spherical = new Spherical();
343
- this._sphericalDelta = new Spherical();
344
- this._scale = 1;
345
- this._panOffset = new Vector3();
346
- this._rotateStart = new Vector2();
347
- this._rotateEnd = new Vector2();
348
- this._rotateDelta = new Vector2();
349
- this._panStart = new Vector2();
350
- this._panEnd = new Vector2();
351
- this._panDelta = new Vector2();
352
- this._dollyStart = new Vector2();
353
- this._dollyEnd = new Vector2();
354
- this._dollyDelta = new Vector2();
355
- this._dollyDirection = new Vector3();
356
- this._mouse = new Vector2();
357
- this._performCursorZoom = false;
358
- this._pointers = [];
359
- this._pointerPositions = {};
360
- this._controlActive = false;
361
- this._onPointerMove = onPointerMove.bind(this);
362
- this._onPointerDown = onPointerDown.bind(this);
363
- this._onPointerUp = onPointerUp.bind(this);
364
- this._onContextMenu = onContextMenu.bind(this);
365
- this._onMouseWheel = onMouseWheel.bind(this);
366
- this._onKeyDown = onKeyDown.bind(this);
367
- this._onTouchStart = onTouchStart.bind(this);
368
- this._onTouchMove = onTouchMove.bind(this);
369
- this._onMouseDown = onMouseDown.bind(this);
370
- this._onMouseMove = onMouseMove.bind(this);
371
- this._interceptControlDown = interceptControlDown.bind(this);
372
- this._interceptControlUp = interceptControlUp.bind(this);
373
- if (this.domElement !== null) {
374
- this.connect(this.domElement);
375
- }
376
- this.update();
377
- }
378
- connect(element) {
379
- super.connect(element);
380
- this.domElement.addEventListener("pointerdown", this._onPointerDown);
381
- this.domElement.addEventListener("pointercancel", this._onPointerUp);
382
- this.domElement.addEventListener("contextmenu", this._onContextMenu);
383
- this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: false });
384
- const document2 = this.domElement.getRootNode();
385
- document2.addEventListener("keydown", this._interceptControlDown, { passive: true, capture: true });
386
- this.domElement.style.touchAction = "none";
387
- }
388
- disconnect() {
389
- this.domElement.removeEventListener("pointerdown", this._onPointerDown);
390
- this.domElement.removeEventListener("pointermove", this._onPointerMove);
391
- this.domElement.removeEventListener("pointerup", this._onPointerUp);
392
- this.domElement.removeEventListener("pointercancel", this._onPointerUp);
393
- this.domElement.removeEventListener("wheel", this._onMouseWheel);
394
- this.domElement.removeEventListener("contextmenu", this._onContextMenu);
395
- this.stopListenToKeyEvents();
396
- const document2 = this.domElement.getRootNode();
397
- document2.removeEventListener("keydown", this._interceptControlDown, { capture: true });
398
- this.domElement.style.touchAction = "auto";
399
- }
400
- dispose() {
401
- this.disconnect();
402
- }
403
- /**
404
- * Get the current vertical rotation, in radians.
405
- *
406
- * @return {number} The current vertical rotation, in radians.
407
- */
408
- getPolarAngle() {
409
- return this._spherical.phi;
410
- }
411
- /**
412
- * Get the current horizontal rotation, in radians.
413
- *
414
- * @return {number} The current horizontal rotation, in radians.
415
- */
416
- getAzimuthalAngle() {
417
- return this._spherical.theta;
418
- }
419
- /**
420
- * Returns the distance from the camera to the target.
421
- *
422
- * @return {number} The distance from the camera to the target.
423
- */
424
- getDistance() {
425
- return this.object.position.distanceTo(this.target);
426
- }
427
- /**
428
- * Adds key event listeners to the given DOM element.
429
- * `window` is a recommended argument for using this method.
430
- *
431
- * @param {HTMLDOMElement} domElement - The DOM element
432
- */
433
- listenToKeyEvents(domElement) {
434
- domElement.addEventListener("keydown", this._onKeyDown);
435
- this._domElementKeyEvents = domElement;
436
- }
437
- /**
438
- * Removes the key event listener previously defined with `listenToKeyEvents()`.
439
- */
440
- stopListenToKeyEvents() {
441
- if (this._domElementKeyEvents !== null) {
442
- this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown);
443
- this._domElementKeyEvents = null;
444
- }
445
- }
446
- /**
447
- * Save the current state of the controls. This can later be recovered with `reset()`.
448
- */
449
- saveState() {
450
- this.target0.copy(this.target);
451
- this.position0.copy(this.object.position);
452
- this.zoom0 = this.object.zoom;
453
- }
454
- /**
455
- * Reset the controls to their state from either the last time the `saveState()`
456
- * was called, or the initial state.
457
- */
458
- reset() {
459
- this.target.copy(this.target0);
460
- this.object.position.copy(this.position0);
461
- this.object.zoom = this.zoom0;
462
- this.object.updateProjectionMatrix();
463
- this.dispatchEvent(_changeEvent);
464
- this.update();
465
- this.state = _STATE.NONE;
466
- }
467
- update(deltaTime = null) {
468
- const position = this.object.position;
469
- _v.copy(position).sub(this.target);
470
- _v.applyQuaternion(this._quat);
471
- this._spherical.setFromVector3(_v);
472
- if (this.autoRotate && this.state === _STATE.NONE) {
473
- this._rotateLeft(this._getAutoRotationAngle(deltaTime));
474
- }
475
- if (this.enableDamping) {
476
- this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor;
477
- this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor;
478
- } else {
479
- this._spherical.theta += this._sphericalDelta.theta;
480
- this._spherical.phi += this._sphericalDelta.phi;
481
- }
482
- let min = this.minAzimuthAngle;
483
- let max = this.maxAzimuthAngle;
484
- if (isFinite(min) && isFinite(max)) {
485
- if (min < -Math.PI) min += _twoPI;
486
- else if (min > Math.PI) min -= _twoPI;
487
- if (max < -Math.PI) max += _twoPI;
488
- else if (max > Math.PI) max -= _twoPI;
489
- if (min <= max) {
490
- this._spherical.theta = Math.max(min, Math.min(max, this._spherical.theta));
491
- } else {
492
- this._spherical.theta = this._spherical.theta > (min + max) / 2 ? Math.max(min, this._spherical.theta) : Math.min(max, this._spherical.theta);
493
- }
494
- }
495
- this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi));
496
- this._spherical.makeSafe();
497
- if (this.enableDamping === true) {
498
- this.target.addScaledVector(this._panOffset, this.dampingFactor);
499
- } else {
500
- this.target.add(this._panOffset);
501
- }
502
- this.target.sub(this.cursor);
503
- this.target.clampLength(this.minTargetRadius, this.maxTargetRadius);
504
- this.target.add(this.cursor);
505
- let zoomChanged = false;
506
- if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera) {
507
- this._spherical.radius = this._clampDistance(this._spherical.radius);
508
- } else {
509
- const prevRadius = this._spherical.radius;
510
- this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale);
511
- zoomChanged = prevRadius != this._spherical.radius;
512
- }
513
- _v.setFromSpherical(this._spherical);
514
- _v.applyQuaternion(this._quatInverse);
515
- position.copy(this.target).add(_v);
516
- this.object.lookAt(this.target);
517
- if (this.enableDamping === true) {
518
- this._sphericalDelta.theta *= 1 - this.dampingFactor;
519
- this._sphericalDelta.phi *= 1 - this.dampingFactor;
520
- this._panOffset.multiplyScalar(1 - this.dampingFactor);
521
- } else {
522
- this._sphericalDelta.set(0, 0, 0);
523
- this._panOffset.set(0, 0, 0);
524
- }
525
- if (this.zoomToCursor && this._performCursorZoom) {
526
- let newRadius = null;
527
- if (this.object.isPerspectiveCamera) {
528
- const prevRadius = _v.length();
529
- newRadius = this._clampDistance(prevRadius * this._scale);
530
- const radiusDelta = prevRadius - newRadius;
531
- this.object.position.addScaledVector(this._dollyDirection, radiusDelta);
532
- this.object.updateMatrixWorld();
533
- zoomChanged = !!radiusDelta;
534
- } else if (this.object.isOrthographicCamera) {
535
- const mouseBefore = new Vector3(this._mouse.x, this._mouse.y, 0);
536
- mouseBefore.unproject(this.object);
537
- const prevZoom = this.object.zoom;
538
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale));
539
- this.object.updateProjectionMatrix();
540
- zoomChanged = prevZoom !== this.object.zoom;
541
- const mouseAfter = new Vector3(this._mouse.x, this._mouse.y, 0);
542
- mouseAfter.unproject(this.object);
543
- this.object.position.sub(mouseAfter).add(mouseBefore);
544
- this.object.updateMatrixWorld();
545
- newRadius = _v.length();
546
- } else {
547
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.");
548
- this.zoomToCursor = false;
549
- }
550
- if (newRadius !== null) {
551
- if (this.screenSpacePanning) {
552
- this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(newRadius).add(this.object.position);
553
- } else {
554
- _ray.origin.copy(this.object.position);
555
- _ray.direction.set(0, 0, -1).transformDirection(this.object.matrix);
556
- if (Math.abs(this.object.up.dot(_ray.direction)) < _TILT_LIMIT) {
557
- this.object.lookAt(this.target);
558
- } else {
559
- _plane.setFromNormalAndCoplanarPoint(this.object.up, this.target);
560
- _ray.intersectPlane(_plane, this.target);
561
- }
562
- }
563
- }
564
- } else if (this.object.isOrthographicCamera) {
565
- const prevZoom = this.object.zoom;
566
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale));
567
- if (prevZoom !== this.object.zoom) {
568
- this.object.updateProjectionMatrix();
569
- zoomChanged = true;
570
- }
571
- }
572
- this._scale = 1;
573
- this._performCursorZoom = false;
574
- if (zoomChanged || this._lastPosition.distanceToSquared(this.object.position) > _EPS || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > _EPS || this._lastTargetPosition.distanceToSquared(this.target) > _EPS) {
575
- this.dispatchEvent(_changeEvent);
576
- this._lastPosition.copy(this.object.position);
577
- this._lastQuaternion.copy(this.object.quaternion);
578
- this._lastTargetPosition.copy(this.target);
579
- return true;
580
- }
581
- return false;
582
- }
583
- _getAutoRotationAngle(deltaTime) {
584
- if (deltaTime !== null) {
585
- return _twoPI / 60 * this.autoRotateSpeed * deltaTime;
586
- } else {
587
- return _twoPI / 60 / 60 * this.autoRotateSpeed;
588
- }
589
- }
590
- _getZoomScale(delta) {
591
- const normalizedDelta = Math.abs(delta * 0.01);
592
- return Math.pow(0.95, this.zoomSpeed * normalizedDelta);
593
- }
594
- _rotateLeft(angle) {
595
- this._sphericalDelta.theta -= angle;
596
- }
597
- _rotateUp(angle) {
598
- this._sphericalDelta.phi -= angle;
599
- }
600
- _panLeft(distance, objectMatrix) {
601
- _v.setFromMatrixColumn(objectMatrix, 0);
602
- _v.multiplyScalar(-distance);
603
- this._panOffset.add(_v);
604
- }
605
- _panUp(distance, objectMatrix) {
606
- if (this.screenSpacePanning === true) {
607
- _v.setFromMatrixColumn(objectMatrix, 1);
608
- } else {
609
- _v.setFromMatrixColumn(objectMatrix, 0);
610
- _v.crossVectors(this.object.up, _v);
611
- }
612
- _v.multiplyScalar(distance);
613
- this._panOffset.add(_v);
614
- }
615
- // deltaX and deltaY are in pixels; right and down are positive
616
- _pan(deltaX, deltaY) {
617
- const element = this.domElement;
618
- if (this.object.isPerspectiveCamera) {
619
- const position = this.object.position;
620
- _v.copy(position).sub(this.target);
621
- let targetDistance = _v.length();
622
- targetDistance *= Math.tan(this.object.fov / 2 * Math.PI / 180);
623
- this._panLeft(2 * deltaX * targetDistance / element.clientHeight, this.object.matrix);
624
- this._panUp(2 * deltaY * targetDistance / element.clientHeight, this.object.matrix);
625
- } else if (this.object.isOrthographicCamera) {
626
- this._panLeft(deltaX * (this.object.right - this.object.left) / this.object.zoom / element.clientWidth, this.object.matrix);
627
- this._panUp(deltaY * (this.object.top - this.object.bottom) / this.object.zoom / element.clientHeight, this.object.matrix);
628
- } else {
629
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
630
- this.enablePan = false;
631
- }
632
- }
633
- _dollyOut(dollyScale) {
634
- if (this.object.isPerspectiveCamera || this.object.isOrthographicCamera) {
635
- this._scale /= dollyScale;
636
- } else {
637
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
638
- this.enableZoom = false;
639
- }
640
- }
641
- _dollyIn(dollyScale) {
642
- if (this.object.isPerspectiveCamera || this.object.isOrthographicCamera) {
643
- this._scale *= dollyScale;
644
- } else {
645
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
646
- this.enableZoom = false;
647
- }
648
- }
649
- _updateZoomParameters(x, y) {
650
- if (!this.zoomToCursor) {
651
- return;
652
- }
653
- this._performCursorZoom = true;
654
- const rect = this.domElement.getBoundingClientRect();
655
- const dx = x - rect.left;
656
- const dy = y - rect.top;
657
- const w = rect.width;
658
- const h = rect.height;
659
- this._mouse.x = dx / w * 2 - 1;
660
- this._mouse.y = -(dy / h) * 2 + 1;
661
- this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
662
- }
663
- _clampDistance(dist) {
664
- return Math.max(this.minDistance, Math.min(this.maxDistance, dist));
665
- }
666
- //
667
- // event callbacks - update the object state
668
- //
669
- _handleMouseDownRotate(event) {
670
- this._rotateStart.set(event.clientX, event.clientY);
671
- }
672
- _handleMouseDownDolly(event) {
673
- this._updateZoomParameters(event.clientX, event.clientX);
674
- this._dollyStart.set(event.clientX, event.clientY);
675
- }
676
- _handleMouseDownPan(event) {
677
- this._panStart.set(event.clientX, event.clientY);
678
- }
679
- _handleMouseMoveRotate(event) {
680
- this._rotateEnd.set(event.clientX, event.clientY);
681
- this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
682
- const element = this.domElement;
683
- this._rotateLeft(_twoPI * this._rotateDelta.x / element.clientHeight);
684
- this._rotateUp(_twoPI * this._rotateDelta.y / element.clientHeight);
685
- this._rotateStart.copy(this._rotateEnd);
686
- this.update();
687
- }
688
- _handleMouseMoveDolly(event) {
689
- this._dollyEnd.set(event.clientX, event.clientY);
690
- this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart);
691
- if (this._dollyDelta.y > 0) {
692
- this._dollyOut(this._getZoomScale(this._dollyDelta.y));
693
- } else if (this._dollyDelta.y < 0) {
694
- this._dollyIn(this._getZoomScale(this._dollyDelta.y));
695
- }
696
- this._dollyStart.copy(this._dollyEnd);
697
- this.update();
698
- }
699
- _handleMouseMovePan(event) {
700
- this._panEnd.set(event.clientX, event.clientY);
701
- this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed);
702
- this._pan(this._panDelta.x, this._panDelta.y);
703
- this._panStart.copy(this._panEnd);
704
- this.update();
705
- }
706
- _handleMouseWheel(event) {
707
- this._updateZoomParameters(event.clientX, event.clientY);
708
- if (event.deltaY < 0) {
709
- this._dollyIn(this._getZoomScale(event.deltaY));
710
- } else if (event.deltaY > 0) {
711
- this._dollyOut(this._getZoomScale(event.deltaY));
712
- }
713
- this.update();
714
- }
715
- _handleKeyDown(event) {
716
- let needsUpdate = false;
717
- switch (event.code) {
718
- case this.keys.UP:
719
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
720
- if (this.enableRotate) {
721
- this._rotateUp(_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
722
- }
723
- } else {
724
- if (this.enablePan) {
725
- this._pan(0, this.keyPanSpeed);
726
- }
727
- }
728
- needsUpdate = true;
729
- break;
730
- case this.keys.BOTTOM:
731
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
732
- if (this.enableRotate) {
733
- this._rotateUp(-_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
734
- }
735
- } else {
736
- if (this.enablePan) {
737
- this._pan(0, -this.keyPanSpeed);
738
- }
739
- }
740
- needsUpdate = true;
741
- break;
742
- case this.keys.LEFT:
743
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
744
- if (this.enableRotate) {
745
- this._rotateLeft(_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
746
- }
747
- } else {
748
- if (this.enablePan) {
749
- this._pan(this.keyPanSpeed, 0);
750
- }
751
- }
752
- needsUpdate = true;
753
- break;
754
- case this.keys.RIGHT:
755
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
756
- if (this.enableRotate) {
757
- this._rotateLeft(-_twoPI * this.keyRotateSpeed / this.domElement.clientHeight);
758
- }
759
- } else {
760
- if (this.enablePan) {
761
- this._pan(-this.keyPanSpeed, 0);
762
- }
763
- }
764
- needsUpdate = true;
765
- break;
766
- }
767
- if (needsUpdate) {
768
- event.preventDefault();
769
- this.update();
770
- }
771
- }
772
- _handleTouchStartRotate(event) {
773
- if (this._pointers.length === 1) {
774
- this._rotateStart.set(event.pageX, event.pageY);
775
- } else {
776
- const position = this._getSecondPointerPosition(event);
777
- const x = 0.5 * (event.pageX + position.x);
778
- const y = 0.5 * (event.pageY + position.y);
779
- this._rotateStart.set(x, y);
780
- }
781
- }
782
- _handleTouchStartPan(event) {
783
- if (this._pointers.length === 1) {
784
- this._panStart.set(event.pageX, event.pageY);
785
- } else {
786
- const position = this._getSecondPointerPosition(event);
787
- const x = 0.5 * (event.pageX + position.x);
788
- const y = 0.5 * (event.pageY + position.y);
789
- this._panStart.set(x, y);
790
- }
791
- }
792
- _handleTouchStartDolly(event) {
793
- const position = this._getSecondPointerPosition(event);
794
- const dx = event.pageX - position.x;
795
- const dy = event.pageY - position.y;
796
- const distance = Math.sqrt(dx * dx + dy * dy);
797
- this._dollyStart.set(0, distance);
798
- }
799
- _handleTouchStartDollyPan(event) {
800
- if (this.enableZoom) this._handleTouchStartDolly(event);
801
- if (this.enablePan) this._handleTouchStartPan(event);
802
- }
803
- _handleTouchStartDollyRotate(event) {
804
- if (this.enableZoom) this._handleTouchStartDolly(event);
805
- if (this.enableRotate) this._handleTouchStartRotate(event);
806
- }
807
- _handleTouchMoveRotate(event) {
808
- if (this._pointers.length == 1) {
809
- this._rotateEnd.set(event.pageX, event.pageY);
810
- } else {
811
- const position = this._getSecondPointerPosition(event);
812
- const x = 0.5 * (event.pageX + position.x);
813
- const y = 0.5 * (event.pageY + position.y);
814
- this._rotateEnd.set(x, y);
815
- }
816
- this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
817
- const element = this.domElement;
818
- this._rotateLeft(_twoPI * this._rotateDelta.x / element.clientHeight);
819
- this._rotateUp(_twoPI * this._rotateDelta.y / element.clientHeight);
820
- this._rotateStart.copy(this._rotateEnd);
821
- }
822
- _handleTouchMovePan(event) {
823
- if (this._pointers.length === 1) {
824
- this._panEnd.set(event.pageX, event.pageY);
825
- } else {
826
- const position = this._getSecondPointerPosition(event);
827
- const x = 0.5 * (event.pageX + position.x);
828
- const y = 0.5 * (event.pageY + position.y);
829
- this._panEnd.set(x, y);
830
- }
831
- this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed);
832
- this._pan(this._panDelta.x, this._panDelta.y);
833
- this._panStart.copy(this._panEnd);
834
- }
835
- _handleTouchMoveDolly(event) {
836
- const position = this._getSecondPointerPosition(event);
837
- const dx = event.pageX - position.x;
838
- const dy = event.pageY - position.y;
839
- const distance = Math.sqrt(dx * dx + dy * dy);
840
- this._dollyEnd.set(0, distance);
841
- this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed));
842
- this._dollyOut(this._dollyDelta.y);
843
- this._dollyStart.copy(this._dollyEnd);
844
- const centerX = (event.pageX + position.x) * 0.5;
845
- const centerY = (event.pageY + position.y) * 0.5;
846
- this._updateZoomParameters(centerX, centerY);
847
- }
848
- _handleTouchMoveDollyPan(event) {
849
- if (this.enableZoom) this._handleTouchMoveDolly(event);
850
- if (this.enablePan) this._handleTouchMovePan(event);
851
- }
852
- _handleTouchMoveDollyRotate(event) {
853
- if (this.enableZoom) this._handleTouchMoveDolly(event);
854
- if (this.enableRotate) this._handleTouchMoveRotate(event);
855
- }
856
- // pointers
857
- _addPointer(event) {
858
- this._pointers.push(event.pointerId);
859
- }
860
- _removePointer(event) {
861
- delete this._pointerPositions[event.pointerId];
862
- for (let i = 0; i < this._pointers.length; i++) {
863
- if (this._pointers[i] == event.pointerId) {
864
- this._pointers.splice(i, 1);
865
- return;
866
- }
867
- }
868
- }
869
- _isTrackingPointer(event) {
870
- for (let i = 0; i < this._pointers.length; i++) {
871
- if (this._pointers[i] == event.pointerId) return true;
872
- }
873
- return false;
874
- }
875
- _trackPointer(event) {
876
- let position = this._pointerPositions[event.pointerId];
877
- if (position === void 0) {
878
- position = new Vector2();
879
- this._pointerPositions[event.pointerId] = position;
880
- }
881
- position.set(event.pageX, event.pageY);
882
- }
883
- _getSecondPointerPosition(event) {
884
- const pointerId = event.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
885
- return this._pointerPositions[pointerId];
886
- }
887
- //
888
- _customWheelEvent(event) {
889
- const mode = event.deltaMode;
890
- const newEvent = {
891
- clientX: event.clientX,
892
- clientY: event.clientY,
893
- deltaY: event.deltaY
894
- };
895
- switch (mode) {
896
- case 1:
897
- newEvent.deltaY *= 16;
898
- break;
899
- case 2:
900
- newEvent.deltaY *= 100;
901
- break;
902
- }
903
- if (event.ctrlKey && !this._controlActive) {
904
- newEvent.deltaY *= 10;
905
- }
906
- return newEvent;
907
- }
908
- }
909
- function onPointerDown(event) {
910
- if (this.enabled === false) return;
911
- if (this._pointers.length === 0) {
912
- this.domElement.setPointerCapture(event.pointerId);
913
- this.domElement.addEventListener("pointermove", this._onPointerMove);
914
- this.domElement.addEventListener("pointerup", this._onPointerUp);
915
- }
916
- if (this._isTrackingPointer(event)) return;
917
- this._addPointer(event);
918
- if (event.pointerType === "touch") {
919
- this._onTouchStart(event);
920
- } else {
921
- this._onMouseDown(event);
922
- }
923
- }
924
- function onPointerMove(event) {
925
- if (this.enabled === false) return;
926
- if (event.pointerType === "touch") {
927
- this._onTouchMove(event);
928
- } else {
929
- this._onMouseMove(event);
930
- }
931
- }
932
- function onPointerUp(event) {
933
- this._removePointer(event);
934
- switch (this._pointers.length) {
935
- case 0:
936
- this.domElement.releasePointerCapture(event.pointerId);
937
- this.domElement.removeEventListener("pointermove", this._onPointerMove);
938
- this.domElement.removeEventListener("pointerup", this._onPointerUp);
939
- this.dispatchEvent(_endEvent);
940
- this.state = _STATE.NONE;
941
- break;
942
- case 1:
943
- const pointerId = this._pointers[0];
944
- const position = this._pointerPositions[pointerId];
945
- this._onTouchStart({ pointerId, pageX: position.x, pageY: position.y });
946
- break;
947
- }
948
- }
949
- function onMouseDown(event) {
950
- let mouseAction;
951
- switch (event.button) {
952
- case 0:
953
- mouseAction = this.mouseButtons.LEFT;
954
- break;
955
- case 1:
956
- mouseAction = this.mouseButtons.MIDDLE;
957
- break;
958
- case 2:
959
- mouseAction = this.mouseButtons.RIGHT;
960
- break;
961
- default:
962
- mouseAction = -1;
963
- }
964
- switch (mouseAction) {
965
- case MOUSE.DOLLY:
966
- if (this.enableZoom === false) return;
967
- this._handleMouseDownDolly(event);
968
- this.state = _STATE.DOLLY;
969
- break;
970
- case MOUSE.ROTATE:
971
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
972
- if (this.enablePan === false) return;
973
- this._handleMouseDownPan(event);
974
- this.state = _STATE.PAN;
975
- } else {
976
- if (this.enableRotate === false) return;
977
- this._handleMouseDownRotate(event);
978
- this.state = _STATE.ROTATE;
979
- }
980
- break;
981
- case MOUSE.PAN:
982
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
983
- if (this.enableRotate === false) return;
984
- this._handleMouseDownRotate(event);
985
- this.state = _STATE.ROTATE;
986
- } else {
987
- if (this.enablePan === false) return;
988
- this._handleMouseDownPan(event);
989
- this.state = _STATE.PAN;
990
- }
991
- break;
992
- default:
993
- this.state = _STATE.NONE;
994
- }
995
- if (this.state !== _STATE.NONE) {
996
- this.dispatchEvent(_startEvent);
997
- }
998
- }
999
- function onMouseMove(event) {
1000
- switch (this.state) {
1001
- case _STATE.ROTATE:
1002
- if (this.enableRotate === false) return;
1003
- this._handleMouseMoveRotate(event);
1004
- break;
1005
- case _STATE.DOLLY:
1006
- if (this.enableZoom === false) return;
1007
- this._handleMouseMoveDolly(event);
1008
- break;
1009
- case _STATE.PAN:
1010
- if (this.enablePan === false) return;
1011
- this._handleMouseMovePan(event);
1012
- break;
1013
- }
1014
- }
1015
- function onMouseWheel(event) {
1016
- if (this.enabled === false || this.enableZoom === false || this.state !== _STATE.NONE) return;
1017
- event.preventDefault();
1018
- this.dispatchEvent(_startEvent);
1019
- this._handleMouseWheel(this._customWheelEvent(event));
1020
- this.dispatchEvent(_endEvent);
1021
- }
1022
- function onKeyDown(event) {
1023
- if (this.enabled === false) return;
1024
- this._handleKeyDown(event);
1025
- }
1026
- function onTouchStart(event) {
1027
- this._trackPointer(event);
1028
- switch (this._pointers.length) {
1029
- case 1:
1030
- switch (this.touches.ONE) {
1031
- case TOUCH.ROTATE:
1032
- if (this.enableRotate === false) return;
1033
- this._handleTouchStartRotate(event);
1034
- this.state = _STATE.TOUCH_ROTATE;
1035
- break;
1036
- case TOUCH.PAN:
1037
- if (this.enablePan === false) return;
1038
- this._handleTouchStartPan(event);
1039
- this.state = _STATE.TOUCH_PAN;
1040
- break;
1041
- default:
1042
- this.state = _STATE.NONE;
1043
- }
1044
- break;
1045
- case 2:
1046
- switch (this.touches.TWO) {
1047
- case TOUCH.DOLLY_PAN:
1048
- if (this.enableZoom === false && this.enablePan === false) return;
1049
- this._handleTouchStartDollyPan(event);
1050
- this.state = _STATE.TOUCH_DOLLY_PAN;
1051
- break;
1052
- case TOUCH.DOLLY_ROTATE:
1053
- if (this.enableZoom === false && this.enableRotate === false) return;
1054
- this._handleTouchStartDollyRotate(event);
1055
- this.state = _STATE.TOUCH_DOLLY_ROTATE;
1056
- break;
1057
- default:
1058
- this.state = _STATE.NONE;
1059
- }
1060
- break;
1061
- default:
1062
- this.state = _STATE.NONE;
1063
- }
1064
- if (this.state !== _STATE.NONE) {
1065
- this.dispatchEvent(_startEvent);
1066
- }
1067
- }
1068
- function onTouchMove(event) {
1069
- this._trackPointer(event);
1070
- switch (this.state) {
1071
- case _STATE.TOUCH_ROTATE:
1072
- if (this.enableRotate === false) return;
1073
- this._handleTouchMoveRotate(event);
1074
- this.update();
1075
- break;
1076
- case _STATE.TOUCH_PAN:
1077
- if (this.enablePan === false) return;
1078
- this._handleTouchMovePan(event);
1079
- this.update();
1080
- break;
1081
- case _STATE.TOUCH_DOLLY_PAN:
1082
- if (this.enableZoom === false && this.enablePan === false) return;
1083
- this._handleTouchMoveDollyPan(event);
1084
- this.update();
1085
- break;
1086
- case _STATE.TOUCH_DOLLY_ROTATE:
1087
- if (this.enableZoom === false && this.enableRotate === false) return;
1088
- this._handleTouchMoveDollyRotate(event);
1089
- this.update();
1090
- break;
1091
- default:
1092
- this.state = _STATE.NONE;
1093
- }
1094
- }
1095
- function onContextMenu(event) {
1096
- if (this.enabled === false) return;
1097
- event.preventDefault();
1098
- }
1099
- function interceptControlDown(event) {
1100
- if (event.key === "Control") {
1101
- this._controlActive = true;
1102
- const document2 = this.domElement.getRootNode();
1103
- document2.addEventListener("keyup", this._interceptControlUp, { passive: true, capture: true });
1104
- }
1105
- }
1106
- function interceptControlUp(event) {
1107
- if (event.key === "Control") {
1108
- this._controlActive = false;
1109
- const document2 = this.domElement.getRootNode();
1110
- document2.removeEventListener("keyup", this._interceptControlUp, { passive: true, capture: true });
1111
- }
1112
- }
1113
- class MapControls extends OrbitControls {
1114
- constructor(object, domElement) {
1115
- super(object, domElement);
1116
- this.screenSpacePanning = false;
1117
- this.mouseButtons = { LEFT: MOUSE.PAN, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.ROTATE };
1118
- this.touches = { ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_ROTATE };
1119
- }
1120
- }
1121
- function createCameraHelper(camera) {
1122
- return new CameraHelper(camera);
1123
- }
1124
- function createGridHelper(size = 150, ...args) {
1125
- return new GridHelper(size, size / 10, ...args);
1126
- }
1127
- function createBox3Helper(model) {
1128
- return new BoxHelper(model, 16776960);
1129
- }
1130
- function createOrbitControl(camera, dom) {
1131
- return new OrbitControls(camera, dom);
1132
- }
1133
- function createMapControls(camera, dom) {
1134
- return new MapControls(camera, dom);
1135
- }
1136
- function createRaycaster() {
1137
- const raycaster = new Raycaster();
1138
- const pointer = new Vector2(0, 0);
1139
- return {
1140
- raycaster,
1141
- pointer
1142
- };
1143
- }
1144
- function createAxesHelper(size = 10) {
1145
- return new AxesHelper(size);
1146
- }
1147
- function createArrowHelper(dir = new Vector3(1, 1, 1), ori = new Vector3(10, 10, 10), length = 5, hex = 16776960) {
1148
- dir.normalize();
1149
- return new ArrowHelper(dir, ori, length, hex);
1150
- }
1151
- function createStats() {
1152
- const stats = new Stats();
1153
- stats.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";
1154
- return stats;
1155
- }
1156
- class RGBELoader extends DataTextureLoader {
1157
- /**
1158
- * Constructs a new RGBE loader.
1159
- *
1160
- * @param {LoadingManager} [manager] - The loading manager.
1161
- */
1162
- constructor(manager) {
1163
- super(manager);
1164
- this.type = HalfFloatType;
1165
- }
1166
- /**
1167
- * Parses the given RGBE texture data.
1168
- *
1169
- * @param {ArrayBuffer} buffer - The raw texture data.
1170
- * @return {DataTextureLoader~TexData} An object representing the parsed texture data.
1171
- */
1172
- parse(buffer) {
1173
- const rgbe_read_error = 1, rgbe_write_error = 2, rgbe_format_error = 3, rgbe_memory_error = 4, rgbe_error = function(rgbe_error_code, msg) {
1174
- switch (rgbe_error_code) {
1175
- case rgbe_read_error:
1176
- throw new Error("THREE.RGBELoader: Read Error: " + (msg || ""));
1177
- case rgbe_write_error:
1178
- throw new Error("THREE.RGBELoader: Write Error: " + (msg || ""));
1179
- case rgbe_format_error:
1180
- throw new Error("THREE.RGBELoader: Bad File Format: " + (msg || ""));
1181
- default:
1182
- case rgbe_memory_error:
1183
- throw new Error("THREE.RGBELoader: Memory Error: " + (msg || ""));
1184
- }
1185
- }, RGBE_VALID_PROGRAMTYPE = 1, RGBE_VALID_FORMAT = 2, RGBE_VALID_DIMENSIONS = 4, NEWLINE = "\n", fgets = function(buffer2, lineLimit, consume) {
1186
- const chunkSize = 128;
1187
- lineLimit = !lineLimit ? 1024 : lineLimit;
1188
- let p = buffer2.pos, i = -1, len = 0, s = "", chunk = String.fromCharCode.apply(null, new Uint16Array(buffer2.subarray(p, p + chunkSize)));
1189
- while (0 > (i = chunk.indexOf(NEWLINE)) && len < lineLimit && p < buffer2.byteLength) {
1190
- s += chunk;
1191
- len += chunk.length;
1192
- p += chunkSize;
1193
- chunk += String.fromCharCode.apply(null, new Uint16Array(buffer2.subarray(p, p + chunkSize)));
1194
- }
1195
- if (-1 < i) {
1196
- buffer2.pos += len + i + 1;
1197
- return s + chunk.slice(0, i);
1198
- }
1199
- return false;
1200
- }, RGBE_ReadHeader = function(buffer2) {
1201
- const magic_token_re = /^#\?(\S+)/, gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/, exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/, format_re = /^\s*FORMAT=(\S+)\s*$/, dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/, header = {
1202
- valid: 0,
1203
- /* indicate which fields are valid */
1204
- string: "",
1205
- /* the actual header string */
1206
- comments: "",
1207
- /* comments found in header */
1208
- programtype: "RGBE",
1209
- /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
1210
- format: "",
1211
- /* RGBE format, default 32-bit_rle_rgbe */
1212
- gamma: 1,
1213
- /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
1214
- exposure: 1,
1215
- /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
1216
- width: 0,
1217
- height: 0
1218
- /* image dimensions, width/height */
1219
- };
1220
- let line, match;
1221
- if (buffer2.pos >= buffer2.byteLength || !(line = fgets(buffer2))) {
1222
- rgbe_error(rgbe_read_error, "no header found");
1223
- }
1224
- if (!(match = line.match(magic_token_re))) {
1225
- rgbe_error(rgbe_format_error, "bad initial token");
1226
- }
1227
- header.valid |= RGBE_VALID_PROGRAMTYPE;
1228
- header.programtype = match[1];
1229
- header.string += line + "\n";
1230
- while (true) {
1231
- line = fgets(buffer2);
1232
- if (false === line) break;
1233
- header.string += line + "\n";
1234
- if ("#" === line.charAt(0)) {
1235
- header.comments += line + "\n";
1236
- continue;
1237
- }
1238
- if (match = line.match(gamma_re)) {
1239
- header.gamma = parseFloat(match[1]);
1240
- }
1241
- if (match = line.match(exposure_re)) {
1242
- header.exposure = parseFloat(match[1]);
1243
- }
1244
- if (match = line.match(format_re)) {
1245
- header.valid |= RGBE_VALID_FORMAT;
1246
- header.format = match[1];
1247
- }
1248
- if (match = line.match(dimensions_re)) {
1249
- header.valid |= RGBE_VALID_DIMENSIONS;
1250
- header.height = parseInt(match[1], 10);
1251
- header.width = parseInt(match[2], 10);
1252
- }
1253
- if (header.valid & RGBE_VALID_FORMAT && header.valid & RGBE_VALID_DIMENSIONS) break;
1254
- }
1255
- if (!(header.valid & RGBE_VALID_FORMAT)) {
1256
- rgbe_error(rgbe_format_error, "missing format specifier");
1257
- }
1258
- if (!(header.valid & RGBE_VALID_DIMENSIONS)) {
1259
- rgbe_error(rgbe_format_error, "missing image size specifier");
1260
- }
1261
- return header;
1262
- }, RGBE_ReadPixels_RLE = function(buffer2, w2, h2) {
1263
- const scanline_width = w2;
1264
- if (
1265
- // run length encoding is not allowed so read flat
1266
- scanline_width < 8 || scanline_width > 32767 || // this file is not run length encoded
1267
- (2 !== buffer2[0] || 2 !== buffer2[1] || buffer2[2] & 128)
1268
- ) {
1269
- return new Uint8Array(buffer2);
1270
- }
1271
- if (scanline_width !== (buffer2[2] << 8 | buffer2[3])) {
1272
- rgbe_error(rgbe_format_error, "wrong scanline width");
1273
- }
1274
- const data_rgba = new Uint8Array(4 * w2 * h2);
1275
- if (!data_rgba.length) {
1276
- rgbe_error(rgbe_memory_error, "unable to allocate buffer space");
1277
- }
1278
- let offset = 0, pos = 0;
1279
- const ptr_end = 4 * scanline_width;
1280
- const rgbeStart = new Uint8Array(4);
1281
- const scanline_buffer = new Uint8Array(ptr_end);
1282
- let num_scanlines = h2;
1283
- while (num_scanlines > 0 && pos < buffer2.byteLength) {
1284
- if (pos + 4 > buffer2.byteLength) {
1285
- rgbe_error(rgbe_read_error);
1286
- }
1287
- rgbeStart[0] = buffer2[pos++];
1288
- rgbeStart[1] = buffer2[pos++];
1289
- rgbeStart[2] = buffer2[pos++];
1290
- rgbeStart[3] = buffer2[pos++];
1291
- if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanline_width) {
1292
- rgbe_error(rgbe_format_error, "bad rgbe scanline format");
1293
- }
1294
- let ptr = 0, count;
1295
- while (ptr < ptr_end && pos < buffer2.byteLength) {
1296
- count = buffer2[pos++];
1297
- const isEncodedRun = count > 128;
1298
- if (isEncodedRun) count -= 128;
1299
- if (0 === count || ptr + count > ptr_end) {
1300
- rgbe_error(rgbe_format_error, "bad scanline data");
1301
- }
1302
- if (isEncodedRun) {
1303
- const byteValue = buffer2[pos++];
1304
- for (let i = 0; i < count; i++) {
1305
- scanline_buffer[ptr++] = byteValue;
1306
- }
1307
- } else {
1308
- scanline_buffer.set(buffer2.subarray(pos, pos + count), ptr);
1309
- ptr += count;
1310
- pos += count;
1311
- }
1312
- }
1313
- const l = scanline_width;
1314
- for (let i = 0; i < l; i++) {
1315
- let off = 0;
1316
- data_rgba[offset] = scanline_buffer[i + off];
1317
- off += scanline_width;
1318
- data_rgba[offset + 1] = scanline_buffer[i + off];
1319
- off += scanline_width;
1320
- data_rgba[offset + 2] = scanline_buffer[i + off];
1321
- off += scanline_width;
1322
- data_rgba[offset + 3] = scanline_buffer[i + off];
1323
- offset += 4;
1324
- }
1325
- num_scanlines--;
1326
- }
1327
- return data_rgba;
1328
- };
1329
- const RGBEByteToRGBFloat = function(sourceArray, sourceOffset, destArray, destOffset) {
1330
- const e = sourceArray[sourceOffset + 3];
1331
- const scale = Math.pow(2, e - 128) / 255;
1332
- destArray[destOffset + 0] = sourceArray[sourceOffset + 0] * scale;
1333
- destArray[destOffset + 1] = sourceArray[sourceOffset + 1] * scale;
1334
- destArray[destOffset + 2] = sourceArray[sourceOffset + 2] * scale;
1335
- destArray[destOffset + 3] = 1;
1336
- };
1337
- const RGBEByteToRGBHalf = function(sourceArray, sourceOffset, destArray, destOffset) {
1338
- const e = sourceArray[sourceOffset + 3];
1339
- const scale = Math.pow(2, e - 128) / 255;
1340
- destArray[destOffset + 0] = DataUtils.toHalfFloat(Math.min(sourceArray[sourceOffset + 0] * scale, 65504));
1341
- destArray[destOffset + 1] = DataUtils.toHalfFloat(Math.min(sourceArray[sourceOffset + 1] * scale, 65504));
1342
- destArray[destOffset + 2] = DataUtils.toHalfFloat(Math.min(sourceArray[sourceOffset + 2] * scale, 65504));
1343
- destArray[destOffset + 3] = DataUtils.toHalfFloat(1);
1344
- };
1345
- const byteArray = new Uint8Array(buffer);
1346
- byteArray.pos = 0;
1347
- const rgbe_header_info = RGBE_ReadHeader(byteArray);
1348
- const w = rgbe_header_info.width, h = rgbe_header_info.height, image_rgba_data = RGBE_ReadPixels_RLE(byteArray.subarray(byteArray.pos), w, h);
1349
- let data, type;
1350
- let numElements;
1351
- switch (this.type) {
1352
- case FloatType:
1353
- numElements = image_rgba_data.length / 4;
1354
- const floatArray = new Float32Array(numElements * 4);
1355
- for (let j = 0; j < numElements; j++) {
1356
- RGBEByteToRGBFloat(image_rgba_data, j * 4, floatArray, j * 4);
1357
- }
1358
- data = floatArray;
1359
- type = FloatType;
1360
- break;
1361
- case HalfFloatType:
1362
- numElements = image_rgba_data.length / 4;
1363
- const halfArray = new Uint16Array(numElements * 4);
1364
- for (let j = 0; j < numElements; j++) {
1365
- RGBEByteToRGBHalf(image_rgba_data, j * 4, halfArray, j * 4);
1366
- }
1367
- data = halfArray;
1368
- type = HalfFloatType;
1369
- break;
1370
- default:
1371
- throw new Error("THREE.RGBELoader: Unsupported type: " + this.type);
1372
- }
1373
- return {
1374
- width: w,
1375
- height: h,
1376
- data,
1377
- header: rgbe_header_info.string,
1378
- gamma: rgbe_header_info.gamma,
1379
- exposure: rgbe_header_info.exposure,
1380
- type
1381
- };
1382
- }
1383
- /**
1384
- * Sets the texture type.
1385
- *
1386
- * @param {(HalfFloatType|FloatType)} value - The texture type to set.
1387
- * @return {RGBELoader} A reference to this loader.
1388
- */
1389
- setDataType(value) {
1390
- this.type = value;
1391
- return this;
1392
- }
1393
- load(url, onLoad, onProgress, onError) {
1394
- function onLoadCallback(texture, texData) {
1395
- switch (texture.type) {
1396
- case FloatType:
1397
- case HalfFloatType:
1398
- texture.colorSpace = LinearSRGBColorSpace;
1399
- texture.minFilter = LinearFilter;
1400
- texture.magFilter = LinearFilter;
1401
- texture.generateMipmaps = false;
1402
- texture.flipY = true;
1403
- break;
1404
- }
1405
- if (onLoad) onLoad(texture, texData);
1406
- }
1407
- return super.load(url, onLoadCallback, onProgress, onError);
1408
- }
1409
- }
1410
- const disposeThreeObject = (object) => {
1411
- if (object.geometry) {
1412
- object.geometry.dispose();
1413
- }
1414
- if (object.material) {
1415
- if (Array.isArray(object.material)) {
1416
- object.material.forEach((material) => {
1417
- disposeMaterial(material);
1418
- });
1419
- } else {
1420
- disposeMaterial(object.material);
1421
- }
1422
- }
1423
- if (object.children) {
1424
- object.children.forEach((child) => disposeThreeObject(child));
1425
- }
1426
- };
1427
- function disposeMaterial(material) {
1428
- for (const key in material) {
1429
- if (material[key] && material[key].isTexture) {
1430
- material[key].dispose();
1431
- }
1432
- }
1433
- material.dispose();
1434
- }
1435
- const cacheHdr = {};
1436
- const rgbeLoader = new RGBELoader();
1437
- async function initEnvImage(scene, path) {
1438
- if (!path) return;
1439
- if (cacheHdr[path]) {
1440
- const texture = cacheHdr[path];
1441
- scene.environment = texture;
1442
- return;
1443
- }
1444
- return new Promise((resolve, reject) => {
1445
- rgbeLoader.load(path, resolve, void 0, reject);
1446
- }).then((texture) => {
1447
- texture.mapping = EquirectangularReflectionMapping;
1448
- scene.environment = texture;
1449
- cacheHdr[path] = texture;
1450
- }).catch((e) => {
1451
- console.log(" =====> e:", e);
1452
- });
1453
- }
1454
- async function ImageLoader(path) {
1455
- return new Promise((resolve, reject) => {
1456
- rgbeLoader.load(path, resolve, void 0, reject);
1457
- });
1458
- }
1459
- export {
1460
- CSS3DSprite as C,
1461
- ImageLoader as I,
1462
- Stats as S,
1463
- createGridHelper as a,
1464
- createBox3Helper as b,
1465
- createCameraHelper as c,
1466
- createOrbitControl as d,
1467
- createMapControls as e,
1468
- createRaycaster as f,
1469
- createAxesHelper as g,
1470
- createArrowHelper as h,
1471
- createStats as i,
1472
- disposeThreeObject as j,
1473
- initEnvImage as k,
1474
- CSS3DRenderer as l
1475
- };