@ridp/threejs 1.3.2 → 1.3.3

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.
@@ -1,1083 +0,0 @@
1
- import * as M from "three";
2
- import { Matrix4 as ft, Vector3 as x, Quaternion as nt, Object3D as wt, Controls as Dt, MOUSE as z, TOUCH as F, Spherical as ht, Vector2 as L, Ray as St, Plane as Pt, MathUtils as Tt, CameraHelper as Mt, GridHelper as At, BoxHelper as Rt, Raycaster as xt, AxesHelper as Ot, ArrowHelper as vt, DataTextureLoader as Lt, HalfFloatType as X, FloatType as et, DataUtils as V, LinearSRGBColorSpace as kt, LinearFilter as ct, EquirectangularReflectionMapping as Ct } from "three";
3
- var K = function() {
4
- var e = 0, t = document.createElement("div");
5
- t.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", t.addEventListener("click", function(m) {
6
- m.preventDefault(), s(++e % t.children.length);
7
- }, !1);
8
- function i(m) {
9
- return t.appendChild(m.dom), m;
10
- }
11
- function s(m) {
12
- for (var h = 0; h < t.children.length; h++)
13
- t.children[h].style.display = h === m ? "block" : "none";
14
- e = m;
15
- }
16
- var r = (performance || Date).now(), a = r, n = 0, c = i(new K.Panel("FPS", "#0ff", "#002")), d = i(new K.Panel("MS", "#0f0", "#020"));
17
- if (self.performance && self.performance.memory)
18
- var g = i(new K.Panel("MB", "#f08", "#201"));
19
- return s(0), {
20
- REVISION: 16,
21
- dom: t,
22
- addPanel: i,
23
- showPanel: s,
24
- begin: function() {
25
- r = (performance || Date).now();
26
- },
27
- end: function() {
28
- n++;
29
- var m = (performance || Date).now();
30
- if (d.update(m - r, 200), m >= a + 1e3 && (c.update(n * 1e3 / (m - a), 100), a = m, n = 0, g)) {
31
- var h = performance.memory;
32
- g.update(h.usedJSHeapSize / 1048576, h.jsHeapSizeLimit / 1048576);
33
- }
34
- return m;
35
- },
36
- update: function() {
37
- r = this.end();
38
- },
39
- // Backwards Compatibility
40
- domElement: t,
41
- setMode: s
42
- };
43
- };
44
- K.Panel = function(e, t, i) {
45
- var s = 1 / 0, r = 0, a = Math.round, n = a(window.devicePixelRatio || 1), c = 80 * n, d = 48 * n, g = 3 * n, m = 2 * n, h = 3 * n, v = 15 * n, k = 74 * n, C = 30 * n, I = document.createElement("canvas");
46
- I.width = c, I.height = d, I.style.cssText = "width:80px;height:48px";
47
- var l = I.getContext("2d");
48
- return l.font = "bold " + 9 * n + "px Helvetica,Arial,sans-serif", l.textBaseline = "top", l.fillStyle = i, l.fillRect(0, 0, c, d), l.fillStyle = t, l.fillText(e, g, m), l.fillRect(h, v, k, C), l.fillStyle = i, l.globalAlpha = 0.9, l.fillRect(h, v, k, C), {
49
- dom: I,
50
- update: function(o, T) {
51
- s = Math.min(s, o), r = Math.max(r, o), l.fillStyle = i, l.globalAlpha = 1, l.fillRect(0, 0, c, v), l.fillStyle = t, l.fillText(a(o) + " " + e + " (" + a(s) + "-" + a(r) + ")", g, m), l.drawImage(I, h + n, v, k - n, C, h, v, k - n, C), l.fillRect(h + k - n, v, n, C), l.fillStyle = i, l.globalAlpha = 0.9, l.fillRect(h + k - n, v, n, a((1 - o / T) * C));
52
- }
53
- };
54
- };
55
- const pt = new x(), It = new nt(), dt = new x();
56
- class jt extends wt {
57
- /**
58
- * Constructs a new CSS3D object.
59
- *
60
- * @param {DOMElement} [element] - The DOM element.
61
- */
62
- constructor(t = document.createElement("div")) {
63
- super(), this.isCSS3DObject = !0, this.element = t, this.element.style.position = "absolute", this.element.style.pointerEvents = "auto", this.element.style.userSelect = "none", this.element.setAttribute("draggable", !1), this.addEventListener("removed", function() {
64
- this.traverse(function(i) {
65
- i.element instanceof i.element.ownerDocument.defaultView.Element && i.element.parentNode !== null && i.element.remove();
66
- });
67
- });
68
- }
69
- copy(t, i) {
70
- return super.copy(t, i), this.element = t.element.cloneNode(!0), this;
71
- }
72
- }
73
- class ee extends jt {
74
- /**
75
- * Constructs a new CSS3D sprite object.
76
- *
77
- * @param {DOMElement} [element] - The DOM element.
78
- */
79
- constructor(t) {
80
- super(t), this.isCSS3DSprite = !0, this.rotation2D = 0;
81
- }
82
- copy(t, i) {
83
- return super.copy(t, i), this.rotation2D = t.rotation2D, this;
84
- }
85
- }
86
- const H = new ft(), Nt = new ft();
87
- class ie {
88
- /**
89
- * Constructs a new CSS3D renderer.
90
- *
91
- * @param {CSS3DRenderer~Parameters} [parameters] - The parameters.
92
- */
93
- constructor(t = {}) {
94
- const i = this;
95
- let s, r, a, n;
96
- const c = {
97
- camera: { style: "" },
98
- objects: /* @__PURE__ */ new WeakMap()
99
- }, d = t.element !== void 0 ? t.element : document.createElement("div");
100
- d.style.overflow = "hidden", this.domElement = d;
101
- const g = document.createElement("div");
102
- g.style.transformOrigin = "0 0", g.style.pointerEvents = "none", d.appendChild(g);
103
- const m = document.createElement("div");
104
- m.style.transformStyle = "preserve-3d", g.appendChild(m), this.getSize = function() {
105
- return {
106
- width: s,
107
- height: r
108
- };
109
- }, this.render = function(l, o) {
110
- const T = o.projectionMatrix.elements[5] * n;
111
- o.view && o.view.enabled ? (g.style.transform = `translate( ${-o.view.offsetX * (s / o.view.width)}px, ${-o.view.offsetY * (r / o.view.height)}px )`, g.style.transform += `scale( ${o.view.fullWidth / o.view.width}, ${o.view.fullHeight / o.view.height} )`) : g.style.transform = "", l.matrixWorldAutoUpdate === !0 && l.updateMatrixWorld(), o.parent === null && o.matrixWorldAutoUpdate === !0 && o.updateMatrixWorld();
112
- let B, A;
113
- o.isOrthographicCamera && (B = -(o.right + o.left) / 2, A = (o.top + o.bottom) / 2);
114
- const O = o.view && o.view.enabled ? o.view.height / o.view.fullHeight : 1, j = o.isOrthographicCamera ? `scale( ${O} )scale(` + T + ")translate(" + h(B) + "px," + h(A) + "px)" + v(o.matrixWorldInverse) : `scale( ${O} )translateZ(` + T + "px)" + v(o.matrixWorldInverse), p = (o.isPerspectiveCamera ? "perspective(" + T + "px) " : "") + j + "translate(" + a + "px," + n + "px)";
115
- c.camera.style !== p && (m.style.transform = p, c.camera.style = p), I(l, l, o);
116
- }, this.setSize = function(l, o) {
117
- s = l, r = o, a = s / 2, n = r / 2, d.style.width = l + "px", d.style.height = o + "px", g.style.width = l + "px", g.style.height = o + "px", m.style.width = l + "px", m.style.height = o + "px";
118
- };
119
- function h(l) {
120
- return Math.abs(l) < 1e-10 ? 0 : l;
121
- }
122
- function v(l) {
123
- const o = l.elements;
124
- return "matrix3d(" + h(o[0]) + "," + h(-o[1]) + "," + h(o[2]) + "," + h(o[3]) + "," + h(o[4]) + "," + h(-o[5]) + "," + h(o[6]) + "," + h(o[7]) + "," + h(o[8]) + "," + h(-o[9]) + "," + h(o[10]) + "," + h(o[11]) + "," + h(o[12]) + "," + h(-o[13]) + "," + h(o[14]) + "," + h(o[15]) + ")";
125
- }
126
- function k(l) {
127
- const o = l.elements;
128
- return "translate(-50%,-50%)" + ("matrix3d(" + h(o[0]) + "," + h(o[1]) + "," + h(o[2]) + "," + h(o[3]) + "," + h(-o[4]) + "," + h(-o[5]) + "," + h(-o[6]) + "," + h(-o[7]) + "," + h(o[8]) + "," + h(o[9]) + "," + h(o[10]) + "," + h(o[11]) + "," + h(o[12]) + "," + h(o[13]) + "," + h(o[14]) + "," + h(o[15]) + ")");
129
- }
130
- function C(l) {
131
- l.isCSS3DObject && (l.element.style.display = "none");
132
- for (let o = 0, T = l.children.length; o < T; o++)
133
- C(l.children[o]);
134
- }
135
- function I(l, o, T, B) {
136
- if (l.visible === !1) {
137
- C(l);
138
- return;
139
- }
140
- if (l.isCSS3DObject) {
141
- const A = l.layers.test(T.layers) === !0, O = l.element;
142
- if (O.style.display = A === !0 ? "" : "none", A === !0) {
143
- l.onBeforeRender(i, o, T);
144
- let j;
145
- l.isCSS3DSprite ? (H.copy(T.matrixWorldInverse), H.transpose(), l.rotation2D !== 0 && H.multiply(Nt.makeRotationZ(l.rotation2D)), l.matrixWorld.decompose(pt, It, dt), H.setPosition(pt), H.scale(dt), H.elements[3] = 0, H.elements[7] = 0, H.elements[11] = 0, H.elements[15] = 1, j = k(H)) : j = k(l.matrixWorld);
146
- const N = c.objects.get(l);
147
- if (N === void 0 || N.style !== j) {
148
- O.style.transform = j;
149
- const p = { style: j };
150
- c.objects.set(l, p);
151
- }
152
- O.parentNode !== m && m.appendChild(O), l.onAfterRender(i, o, T);
153
- }
154
- }
155
- for (let A = 0, O = l.children.length; A < O; A++)
156
- I(l.children[A], o, T);
157
- }
158
- }
159
- }
160
- const ut = { type: "change" }, at = { type: "start" }, yt = { type: "end" }, q = new St(), mt = new Pt(), Ht = Math.cos(70 * Tt.DEG2RAD), P = new x(), R = 2 * Math.PI, _ = {
161
- NONE: -1,
162
- ROTATE: 0,
163
- DOLLY: 1,
164
- PAN: 2,
165
- TOUCH_ROTATE: 3,
166
- TOUCH_PAN: 4,
167
- TOUCH_DOLLY_PAN: 5,
168
- TOUCH_DOLLY_ROTATE: 6
169
- }, it = 1e-6;
170
- class gt extends Dt {
171
- /**
172
- * Constructs a new controls instance.
173
- *
174
- * @param {Object3D} object - The object that is managed by the controls.
175
- * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
176
- */
177
- constructor(t, i = null) {
178
- super(t, i), this.state = _.NONE, this.target = new x(), this.cursor = new x(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: z.ROTATE, MIDDLE: z.DOLLY, RIGHT: z.PAN }, this.touches = { ONE: F.ROTATE, TWO: F.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new x(), this._lastQuaternion = new nt(), this._lastTargetPosition = new x(), this._quat = new nt().setFromUnitVectors(t.up, new x(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new ht(), this._sphericalDelta = new ht(), this._scale = 1, this._panOffset = new x(), this._rotateStart = new L(), this._rotateEnd = new L(), this._rotateDelta = new L(), this._panStart = new L(), this._panEnd = new L(), this._panDelta = new L(), this._dollyStart = new L(), this._dollyEnd = new L(), this._dollyDelta = new L(), this._dollyDirection = new x(), this._mouse = new L(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = Ut.bind(this), this._onPointerDown = Gt.bind(this), this._onPointerUp = Yt.bind(this), this._onContextMenu = Xt.bind(this), this._onMouseWheel = Bt.bind(this), this._onKeyDown = Zt.bind(this), this._onTouchStart = Wt.bind(this), this._onTouchMove = Kt.bind(this), this._onMouseDown = zt.bind(this), this._onMouseMove = Ft.bind(this), this._interceptControlDown = Vt.bind(this), this._interceptControlUp = qt.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
179
- }
180
- connect(t) {
181
- super.connect(t), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointercancel", this._onPointerUp), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: !1 }), this.domElement.getRootNode().addEventListener("keydown", this._interceptControlDown, { passive: !0, capture: !0 }), this.domElement.style.touchAction = "none";
182
- }
183
- disconnect() {
184
- this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointercancel", this._onPointerUp), this.domElement.removeEventListener("wheel", this._onMouseWheel), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.stopListenToKeyEvents(), this.domElement.getRootNode().removeEventListener("keydown", this._interceptControlDown, { capture: !0 }), this.domElement.style.touchAction = "auto";
185
- }
186
- dispose() {
187
- this.disconnect();
188
- }
189
- /**
190
- * Get the current vertical rotation, in radians.
191
- *
192
- * @return {number} The current vertical rotation, in radians.
193
- */
194
- getPolarAngle() {
195
- return this._spherical.phi;
196
- }
197
- /**
198
- * Get the current horizontal rotation, in radians.
199
- *
200
- * @return {number} The current horizontal rotation, in radians.
201
- */
202
- getAzimuthalAngle() {
203
- return this._spherical.theta;
204
- }
205
- /**
206
- * Returns the distance from the camera to the target.
207
- *
208
- * @return {number} The distance from the camera to the target.
209
- */
210
- getDistance() {
211
- return this.object.position.distanceTo(this.target);
212
- }
213
- /**
214
- * Adds key event listeners to the given DOM element.
215
- * `window` is a recommended argument for using this method.
216
- *
217
- * @param {HTMLDOMElement} domElement - The DOM element
218
- */
219
- listenToKeyEvents(t) {
220
- t.addEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = t;
221
- }
222
- /**
223
- * Removes the key event listener previously defined with `listenToKeyEvents()`.
224
- */
225
- stopListenToKeyEvents() {
226
- this._domElementKeyEvents !== null && (this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = null);
227
- }
228
- /**
229
- * Save the current state of the controls. This can later be recovered with `reset()`.
230
- */
231
- saveState() {
232
- this.target0.copy(this.target), this.position0.copy(this.object.position), this.zoom0 = this.object.zoom;
233
- }
234
- /**
235
- * Reset the controls to their state from either the last time the `saveState()`
236
- * was called, or the initial state.
237
- */
238
- reset() {
239
- this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(ut), this.update(), this.state = _.NONE;
240
- }
241
- update(t = null) {
242
- const i = this.object.position;
243
- P.copy(i).sub(this.target), P.applyQuaternion(this._quat), this._spherical.setFromVector3(P), this.autoRotate && this.state === _.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
244
- let s = this.minAzimuthAngle, r = this.maxAzimuthAngle;
245
- isFinite(s) && isFinite(r) && (s < -Math.PI ? s += R : s > Math.PI && (s -= R), r < -Math.PI ? r += R : r > Math.PI && (r -= R), s <= r ? this._spherical.theta = Math.max(s, Math.min(r, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (s + r) / 2 ? Math.max(s, this._spherical.theta) : Math.min(r, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
246
- let a = !1;
247
- if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
248
- this._spherical.radius = this._clampDistance(this._spherical.radius);
249
- else {
250
- const n = this._spherical.radius;
251
- this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), a = n != this._spherical.radius;
252
- }
253
- if (P.setFromSpherical(this._spherical), P.applyQuaternion(this._quatInverse), i.copy(this.target).add(P), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
254
- let n = null;
255
- if (this.object.isPerspectiveCamera) {
256
- const c = P.length();
257
- n = this._clampDistance(c * this._scale);
258
- const d = c - n;
259
- this.object.position.addScaledVector(this._dollyDirection, d), this.object.updateMatrixWorld(), a = !!d;
260
- } else if (this.object.isOrthographicCamera) {
261
- const c = new x(this._mouse.x, this._mouse.y, 0);
262
- c.unproject(this.object);
263
- const d = this.object.zoom;
264
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), a = d !== this.object.zoom;
265
- const g = new x(this._mouse.x, this._mouse.y, 0);
266
- g.unproject(this.object), this.object.position.sub(g).add(c), this.object.updateMatrixWorld(), n = P.length();
267
- } else
268
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
269
- n !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(n).add(this.object.position) : (q.origin.copy(this.object.position), q.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(q.direction)) < Ht ? this.object.lookAt(this.target) : (mt.setFromNormalAndCoplanarPoint(this.object.up, this.target), q.intersectPlane(mt, this.target))));
270
- } else if (this.object.isOrthographicCamera) {
271
- const n = this.object.zoom;
272
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), n !== this.object.zoom && (this.object.updateProjectionMatrix(), a = !0);
273
- }
274
- return this._scale = 1, this._performCursorZoom = !1, a || this._lastPosition.distanceToSquared(this.object.position) > it || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > it || this._lastTargetPosition.distanceToSquared(this.target) > it ? (this.dispatchEvent(ut), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
275
- }
276
- _getAutoRotationAngle(t) {
277
- return t !== null ? R / 60 * this.autoRotateSpeed * t : R / 60 / 60 * this.autoRotateSpeed;
278
- }
279
- _getZoomScale(t) {
280
- const i = Math.abs(t * 0.01);
281
- return Math.pow(0.95, this.zoomSpeed * i);
282
- }
283
- _rotateLeft(t) {
284
- this._sphericalDelta.theta -= t;
285
- }
286
- _rotateUp(t) {
287
- this._sphericalDelta.phi -= t;
288
- }
289
- _panLeft(t, i) {
290
- P.setFromMatrixColumn(i, 0), P.multiplyScalar(-t), this._panOffset.add(P);
291
- }
292
- _panUp(t, i) {
293
- this.screenSpacePanning === !0 ? P.setFromMatrixColumn(i, 1) : (P.setFromMatrixColumn(i, 0), P.crossVectors(this.object.up, P)), P.multiplyScalar(t), this._panOffset.add(P);
294
- }
295
- // deltaX and deltaY are in pixels; right and down are positive
296
- _pan(t, i) {
297
- const s = this.domElement;
298
- if (this.object.isPerspectiveCamera) {
299
- const r = this.object.position;
300
- P.copy(r).sub(this.target);
301
- let a = P.length();
302
- a *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * a / s.clientHeight, this.object.matrix), this._panUp(2 * i * a / s.clientHeight, this.object.matrix);
303
- } else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / s.clientWidth, this.object.matrix), this._panUp(i * (this.object.top - this.object.bottom) / this.object.zoom / s.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
304
- }
305
- _dollyOut(t) {
306
- this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
307
- }
308
- _dollyIn(t) {
309
- this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
310
- }
311
- _updateZoomParameters(t, i) {
312
- if (!this.zoomToCursor)
313
- return;
314
- this._performCursorZoom = !0;
315
- const s = this.domElement.getBoundingClientRect(), r = t - s.left, a = i - s.top, n = s.width, c = s.height;
316
- this._mouse.x = r / n * 2 - 1, this._mouse.y = -(a / c) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
317
- }
318
- _clampDistance(t) {
319
- return Math.max(this.minDistance, Math.min(this.maxDistance, t));
320
- }
321
- //
322
- // event callbacks - update the object state
323
- //
324
- _handleMouseDownRotate(t) {
325
- this._rotateStart.set(t.clientX, t.clientY);
326
- }
327
- _handleMouseDownDolly(t) {
328
- this._updateZoomParameters(t.clientX, t.clientX), this._dollyStart.set(t.clientX, t.clientY);
329
- }
330
- _handleMouseDownPan(t) {
331
- this._panStart.set(t.clientX, t.clientY);
332
- }
333
- _handleMouseMoveRotate(t) {
334
- this._rotateEnd.set(t.clientX, t.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
335
- const i = this.domElement;
336
- this._rotateLeft(R * this._rotateDelta.x / i.clientHeight), this._rotateUp(R * this._rotateDelta.y / i.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
337
- }
338
- _handleMouseMoveDolly(t) {
339
- this._dollyEnd.set(t.clientX, t.clientY), this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart), this._dollyDelta.y > 0 ? this._dollyOut(this._getZoomScale(this._dollyDelta.y)) : this._dollyDelta.y < 0 && this._dollyIn(this._getZoomScale(this._dollyDelta.y)), this._dollyStart.copy(this._dollyEnd), this.update();
340
- }
341
- _handleMouseMovePan(t) {
342
- this._panEnd.set(t.clientX, t.clientY), this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd), this.update();
343
- }
344
- _handleMouseWheel(t) {
345
- this._updateZoomParameters(t.clientX, t.clientY), t.deltaY < 0 ? this._dollyIn(this._getZoomScale(t.deltaY)) : t.deltaY > 0 && this._dollyOut(this._getZoomScale(t.deltaY)), this.update();
346
- }
347
- _handleKeyDown(t) {
348
- let i = !1;
349
- switch (t.code) {
350
- case this.keys.UP:
351
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(R * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), i = !0;
352
- break;
353
- case this.keys.BOTTOM:
354
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-R * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), i = !0;
355
- break;
356
- case this.keys.LEFT:
357
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(R * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), i = !0;
358
- break;
359
- case this.keys.RIGHT:
360
- t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-R * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), i = !0;
361
- break;
362
- }
363
- i && (t.preventDefault(), this.update());
364
- }
365
- _handleTouchStartRotate(t) {
366
- if (this._pointers.length === 1)
367
- this._rotateStart.set(t.pageX, t.pageY);
368
- else {
369
- const i = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + i.x), r = 0.5 * (t.pageY + i.y);
370
- this._rotateStart.set(s, r);
371
- }
372
- }
373
- _handleTouchStartPan(t) {
374
- if (this._pointers.length === 1)
375
- this._panStart.set(t.pageX, t.pageY);
376
- else {
377
- const i = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + i.x), r = 0.5 * (t.pageY + i.y);
378
- this._panStart.set(s, r);
379
- }
380
- }
381
- _handleTouchStartDolly(t) {
382
- const i = this._getSecondPointerPosition(t), s = t.pageX - i.x, r = t.pageY - i.y, a = Math.sqrt(s * s + r * r);
383
- this._dollyStart.set(0, a);
384
- }
385
- _handleTouchStartDollyPan(t) {
386
- this.enableZoom && this._handleTouchStartDolly(t), this.enablePan && this._handleTouchStartPan(t);
387
- }
388
- _handleTouchStartDollyRotate(t) {
389
- this.enableZoom && this._handleTouchStartDolly(t), this.enableRotate && this._handleTouchStartRotate(t);
390
- }
391
- _handleTouchMoveRotate(t) {
392
- if (this._pointers.length == 1)
393
- this._rotateEnd.set(t.pageX, t.pageY);
394
- else {
395
- const s = this._getSecondPointerPosition(t), r = 0.5 * (t.pageX + s.x), a = 0.5 * (t.pageY + s.y);
396
- this._rotateEnd.set(r, a);
397
- }
398
- this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
399
- const i = this.domElement;
400
- this._rotateLeft(R * this._rotateDelta.x / i.clientHeight), this._rotateUp(R * this._rotateDelta.y / i.clientHeight), this._rotateStart.copy(this._rotateEnd);
401
- }
402
- _handleTouchMovePan(t) {
403
- if (this._pointers.length === 1)
404
- this._panEnd.set(t.pageX, t.pageY);
405
- else {
406
- const i = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + i.x), r = 0.5 * (t.pageY + i.y);
407
- this._panEnd.set(s, r);
408
- }
409
- this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
410
- }
411
- _handleTouchMoveDolly(t) {
412
- const i = this._getSecondPointerPosition(t), s = t.pageX - i.x, r = t.pageY - i.y, a = Math.sqrt(s * s + r * r);
413
- this._dollyEnd.set(0, a), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
414
- const n = (t.pageX + i.x) * 0.5, c = (t.pageY + i.y) * 0.5;
415
- this._updateZoomParameters(n, c);
416
- }
417
- _handleTouchMoveDollyPan(t) {
418
- this.enableZoom && this._handleTouchMoveDolly(t), this.enablePan && this._handleTouchMovePan(t);
419
- }
420
- _handleTouchMoveDollyRotate(t) {
421
- this.enableZoom && this._handleTouchMoveDolly(t), this.enableRotate && this._handleTouchMoveRotate(t);
422
- }
423
- // pointers
424
- _addPointer(t) {
425
- this._pointers.push(t.pointerId);
426
- }
427
- _removePointer(t) {
428
- delete this._pointerPositions[t.pointerId];
429
- for (let i = 0; i < this._pointers.length; i++)
430
- if (this._pointers[i] == t.pointerId) {
431
- this._pointers.splice(i, 1);
432
- return;
433
- }
434
- }
435
- _isTrackingPointer(t) {
436
- for (let i = 0; i < this._pointers.length; i++)
437
- if (this._pointers[i] == t.pointerId) return !0;
438
- return !1;
439
- }
440
- _trackPointer(t) {
441
- let i = this._pointerPositions[t.pointerId];
442
- i === void 0 && (i = new L(), this._pointerPositions[t.pointerId] = i), i.set(t.pageX, t.pageY);
443
- }
444
- _getSecondPointerPosition(t) {
445
- const i = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
446
- return this._pointerPositions[i];
447
- }
448
- //
449
- _customWheelEvent(t) {
450
- const i = t.deltaMode, s = {
451
- clientX: t.clientX,
452
- clientY: t.clientY,
453
- deltaY: t.deltaY
454
- };
455
- switch (i) {
456
- case 1:
457
- s.deltaY *= 16;
458
- break;
459
- case 2:
460
- s.deltaY *= 100;
461
- break;
462
- }
463
- return t.ctrlKey && !this._controlActive && (s.deltaY *= 10), s;
464
- }
465
- }
466
- function Gt(e) {
467
- this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(e.pointerId), this.domElement.addEventListener("pointermove", this._onPointerMove), this.domElement.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(e) && (this._addPointer(e), e.pointerType === "touch" ? this._onTouchStart(e) : this._onMouseDown(e)));
468
- }
469
- function Ut(e) {
470
- this.enabled !== !1 && (e.pointerType === "touch" ? this._onTouchMove(e) : this._onMouseMove(e));
471
- }
472
- function Yt(e) {
473
- switch (this._removePointer(e), this._pointers.length) {
474
- case 0:
475
- this.domElement.releasePointerCapture(e.pointerId), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(yt), this.state = _.NONE;
476
- break;
477
- case 1:
478
- const t = this._pointers[0], i = this._pointerPositions[t];
479
- this._onTouchStart({ pointerId: t, pageX: i.x, pageY: i.y });
480
- break;
481
- }
482
- }
483
- function zt(e) {
484
- let t;
485
- switch (e.button) {
486
- case 0:
487
- t = this.mouseButtons.LEFT;
488
- break;
489
- case 1:
490
- t = this.mouseButtons.MIDDLE;
491
- break;
492
- case 2:
493
- t = this.mouseButtons.RIGHT;
494
- break;
495
- default:
496
- t = -1;
497
- }
498
- switch (t) {
499
- case z.DOLLY:
500
- if (this.enableZoom === !1) return;
501
- this._handleMouseDownDolly(e), this.state = _.DOLLY;
502
- break;
503
- case z.ROTATE:
504
- if (e.ctrlKey || e.metaKey || e.shiftKey) {
505
- if (this.enablePan === !1) return;
506
- this._handleMouseDownPan(e), this.state = _.PAN;
507
- } else {
508
- if (this.enableRotate === !1) return;
509
- this._handleMouseDownRotate(e), this.state = _.ROTATE;
510
- }
511
- break;
512
- case z.PAN:
513
- if (e.ctrlKey || e.metaKey || e.shiftKey) {
514
- if (this.enableRotate === !1) return;
515
- this._handleMouseDownRotate(e), this.state = _.ROTATE;
516
- } else {
517
- if (this.enablePan === !1) return;
518
- this._handleMouseDownPan(e), this.state = _.PAN;
519
- }
520
- break;
521
- default:
522
- this.state = _.NONE;
523
- }
524
- this.state !== _.NONE && this.dispatchEvent(at);
525
- }
526
- function Ft(e) {
527
- switch (this.state) {
528
- case _.ROTATE:
529
- if (this.enableRotate === !1) return;
530
- this._handleMouseMoveRotate(e);
531
- break;
532
- case _.DOLLY:
533
- if (this.enableZoom === !1) return;
534
- this._handleMouseMoveDolly(e);
535
- break;
536
- case _.PAN:
537
- if (this.enablePan === !1) return;
538
- this._handleMouseMovePan(e);
539
- break;
540
- }
541
- }
542
- function Bt(e) {
543
- this.enabled === !1 || this.enableZoom === !1 || this.state !== _.NONE || (e.preventDefault(), this.dispatchEvent(at), this._handleMouseWheel(this._customWheelEvent(e)), this.dispatchEvent(yt));
544
- }
545
- function Zt(e) {
546
- this.enabled !== !1 && this._handleKeyDown(e);
547
- }
548
- function Wt(e) {
549
- switch (this._trackPointer(e), this._pointers.length) {
550
- case 1:
551
- switch (this.touches.ONE) {
552
- case F.ROTATE:
553
- if (this.enableRotate === !1) return;
554
- this._handleTouchStartRotate(e), this.state = _.TOUCH_ROTATE;
555
- break;
556
- case F.PAN:
557
- if (this.enablePan === !1) return;
558
- this._handleTouchStartPan(e), this.state = _.TOUCH_PAN;
559
- break;
560
- default:
561
- this.state = _.NONE;
562
- }
563
- break;
564
- case 2:
565
- switch (this.touches.TWO) {
566
- case F.DOLLY_PAN:
567
- if (this.enableZoom === !1 && this.enablePan === !1) return;
568
- this._handleTouchStartDollyPan(e), this.state = _.TOUCH_DOLLY_PAN;
569
- break;
570
- case F.DOLLY_ROTATE:
571
- if (this.enableZoom === !1 && this.enableRotate === !1) return;
572
- this._handleTouchStartDollyRotate(e), this.state = _.TOUCH_DOLLY_ROTATE;
573
- break;
574
- default:
575
- this.state = _.NONE;
576
- }
577
- break;
578
- default:
579
- this.state = _.NONE;
580
- }
581
- this.state !== _.NONE && this.dispatchEvent(at);
582
- }
583
- function Kt(e) {
584
- switch (this._trackPointer(e), this.state) {
585
- case _.TOUCH_ROTATE:
586
- if (this.enableRotate === !1) return;
587
- this._handleTouchMoveRotate(e), this.update();
588
- break;
589
- case _.TOUCH_PAN:
590
- if (this.enablePan === !1) return;
591
- this._handleTouchMovePan(e), this.update();
592
- break;
593
- case _.TOUCH_DOLLY_PAN:
594
- if (this.enableZoom === !1 && this.enablePan === !1) return;
595
- this._handleTouchMoveDollyPan(e), this.update();
596
- break;
597
- case _.TOUCH_DOLLY_ROTATE:
598
- if (this.enableZoom === !1 && this.enableRotate === !1) return;
599
- this._handleTouchMoveDollyRotate(e), this.update();
600
- break;
601
- default:
602
- this.state = _.NONE;
603
- }
604
- }
605
- function Xt(e) {
606
- this.enabled !== !1 && e.preventDefault();
607
- }
608
- function Vt(e) {
609
- e.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
610
- }
611
- function qt(e) {
612
- e.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
613
- }
614
- class $t extends gt {
615
- constructor(t, i) {
616
- super(t, i), this.screenSpacePanning = !1, this.mouseButtons = { LEFT: z.PAN, MIDDLE: z.DOLLY, RIGHT: z.ROTATE }, this.touches = { ONE: F.PAN, TWO: F.DOLLY_ROTATE };
617
- }
618
- }
619
- function se(e) {
620
- return new Mt(e);
621
- }
622
- function oe(e = 150, ...t) {
623
- return new At(e, e / 10, ...t);
624
- }
625
- function ne(e) {
626
- return new Rt(e, 16776960);
627
- }
628
- function ae(e, t) {
629
- return new gt(e, t);
630
- }
631
- function re(e, t) {
632
- return new $t(e, t);
633
- }
634
- function le() {
635
- const e = new xt(), t = new L(0, 0);
636
- return {
637
- raycaster: e,
638
- pointer: t
639
- };
640
- }
641
- function he(e = 10) {
642
- return new Ot(e);
643
- }
644
- function ce(e = new x(1, 1, 1), t = new x(10, 10, 10), i = 5, s = 16776960) {
645
- return e.normalize(), new vt(e, t, i, s);
646
- }
647
- function pe() {
648
- const e = new K();
649
- return e.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", e;
650
- }
651
- class Qt extends Lt {
652
- /**
653
- * Constructs a new RGBE loader.
654
- *
655
- * @param {LoadingManager} [manager] - The loading manager.
656
- */
657
- constructor(t) {
658
- super(t), this.type = X;
659
- }
660
- /**
661
- * Parses the given RGBE texture data.
662
- *
663
- * @param {ArrayBuffer} buffer - The raw texture data.
664
- * @return {DataTextureLoader~TexData} An object representing the parsed texture data.
665
- */
666
- parse(t) {
667
- const n = function(p, f) {
668
- switch (p) {
669
- case 1:
670
- throw new Error("THREE.RGBELoader: Read Error: " + (f || ""));
671
- case 2:
672
- throw new Error("THREE.RGBELoader: Write Error: " + (f || ""));
673
- case 3:
674
- throw new Error("THREE.RGBELoader: Bad File Format: " + (f || ""));
675
- default:
676
- case 4:
677
- throw new Error("THREE.RGBELoader: Memory Error: " + (f || ""));
678
- }
679
- }, m = `
680
- `, h = function(p, f, b) {
681
- f = f || 1024;
682
- let D = p.pos, w = -1, u = 0, S = "", y = String.fromCharCode.apply(null, new Uint16Array(p.subarray(D, D + 128)));
683
- for (; 0 > (w = y.indexOf(m)) && u < f && D < p.byteLength; )
684
- S += y, u += y.length, D += 128, y += String.fromCharCode.apply(null, new Uint16Array(p.subarray(D, D + 128)));
685
- return -1 < w ? (p.pos += u + w + 1, S + y.slice(0, w)) : !1;
686
- }, v = function(p) {
687
- const f = /^#\?(\S+)/, b = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/, E = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/, D = /^\s*FORMAT=(\S+)\s*$/, w = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/, u = {
688
- valid: 0,
689
- /* indicate which fields are valid */
690
- string: "",
691
- /* the actual header string */
692
- comments: "",
693
- /* comments found in header */
694
- programtype: "RGBE",
695
- /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
696
- format: "",
697
- /* RGBE format, default 32-bit_rle_rgbe */
698
- gamma: 1,
699
- /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
700
- exposure: 1,
701
- /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
702
- width: 0,
703
- height: 0
704
- /* image dimensions, width/height */
705
- };
706
- let S, y;
707
- for ((p.pos >= p.byteLength || !(S = h(p))) && n(1, "no header found"), (y = S.match(f)) || n(3, "bad initial token"), u.valid |= 1, u.programtype = y[1], u.string += S + `
708
- `; S = h(p), S !== !1; ) {
709
- if (u.string += S + `
710
- `, S.charAt(0) === "#") {
711
- u.comments += S + `
712
- `;
713
- continue;
714
- }
715
- if ((y = S.match(b)) && (u.gamma = parseFloat(y[1])), (y = S.match(E)) && (u.exposure = parseFloat(y[1])), (y = S.match(D)) && (u.valid |= 2, u.format = y[1]), (y = S.match(w)) && (u.valid |= 4, u.height = parseInt(y[1], 10), u.width = parseInt(y[2], 10)), u.valid & 2 && u.valid & 4) break;
716
- }
717
- return u.valid & 2 || n(3, "missing format specifier"), u.valid & 4 || n(3, "missing image size specifier"), u;
718
- }, k = function(p, f, b) {
719
- const E = f;
720
- if (
721
- // run length encoding is not allowed so read flat
722
- E < 8 || E > 32767 || // this file is not run length encoded
723
- p[0] !== 2 || p[1] !== 2 || p[2] & 128
724
- )
725
- return new Uint8Array(p);
726
- E !== (p[2] << 8 | p[3]) && n(3, "wrong scanline width");
727
- const D = new Uint8Array(4 * f * b);
728
- D.length || n(4, "unable to allocate buffer space");
729
- let w = 0, u = 0;
730
- const S = 4 * E, y = new Uint8Array(4), Z = new Uint8Array(S);
731
- let rt = b;
732
- for (; rt > 0 && u < p.byteLength; ) {
733
- u + 4 > p.byteLength && n(1), y[0] = p[u++], y[1] = p[u++], y[2] = p[u++], y[3] = p[u++], (y[0] != 2 || y[1] != 2 || (y[2] << 8 | y[3]) != E) && n(3, "bad rgbe scanline format");
734
- let W = 0, G;
735
- for (; W < S && u < p.byteLength; ) {
736
- G = p[u++];
737
- const U = G > 128;
738
- if (U && (G -= 128), (G === 0 || W + G > S) && n(3, "bad scanline data"), U) {
739
- const Y = p[u++];
740
- for (let lt = 0; lt < G; lt++)
741
- Z[W++] = Y;
742
- } else
743
- Z.set(p.subarray(u, u + G), W), W += G, u += G;
744
- }
745
- const Et = E;
746
- for (let U = 0; U < Et; U++) {
747
- let Y = 0;
748
- D[w] = Z[U + Y], Y += E, D[w + 1] = Z[U + Y], Y += E, D[w + 2] = Z[U + Y], Y += E, D[w + 3] = Z[U + Y], w += 4;
749
- }
750
- rt--;
751
- }
752
- return D;
753
- }, C = function(p, f, b, E) {
754
- const D = p[f + 3], w = Math.pow(2, D - 128) / 255;
755
- b[E + 0] = p[f + 0] * w, b[E + 1] = p[f + 1] * w, b[E + 2] = p[f + 2] * w, b[E + 3] = 1;
756
- }, I = function(p, f, b, E) {
757
- const D = p[f + 3], w = Math.pow(2, D - 128) / 255;
758
- b[E + 0] = V.toHalfFloat(Math.min(p[f + 0] * w, 65504)), b[E + 1] = V.toHalfFloat(Math.min(p[f + 1] * w, 65504)), b[E + 2] = V.toHalfFloat(Math.min(p[f + 2] * w, 65504)), b[E + 3] = V.toHalfFloat(1);
759
- }, l = new Uint8Array(t);
760
- l.pos = 0;
761
- const o = v(l), T = o.width, B = o.height, A = k(l.subarray(l.pos), T, B);
762
- let O, j, N;
763
- switch (this.type) {
764
- case et:
765
- N = A.length / 4;
766
- const p = new Float32Array(N * 4);
767
- for (let b = 0; b < N; b++)
768
- C(A, b * 4, p, b * 4);
769
- O = p, j = et;
770
- break;
771
- case X:
772
- N = A.length / 4;
773
- const f = new Uint16Array(N * 4);
774
- for (let b = 0; b < N; b++)
775
- I(A, b * 4, f, b * 4);
776
- O = f, j = X;
777
- break;
778
- default:
779
- throw new Error("THREE.RGBELoader: Unsupported type: " + this.type);
780
- }
781
- return {
782
- width: T,
783
- height: B,
784
- data: O,
785
- header: o.string,
786
- gamma: o.gamma,
787
- exposure: o.exposure,
788
- type: j
789
- };
790
- }
791
- /**
792
- * Sets the texture type.
793
- *
794
- * @param {(HalfFloatType|FloatType)} value - The texture type to set.
795
- * @return {RGBELoader} A reference to this loader.
796
- */
797
- setDataType(t) {
798
- return this.type = t, this;
799
- }
800
- load(t, i, s, r) {
801
- function a(n, c) {
802
- switch (n.type) {
803
- case et:
804
- case X:
805
- n.colorSpace = kt, n.minFilter = ct, n.magFilter = ct, n.generateMipmaps = !1, n.flipY = !0;
806
- break;
807
- }
808
- i && i(n, c);
809
- }
810
- return super.load(t, a, s, r);
811
- }
812
- }
813
- const Jt = (e) => {
814
- e.geometry && e.geometry.dispose(), e.material && (Array.isArray(e.material) ? e.material.forEach((t) => {
815
- _t(t);
816
- }) : _t(e.material)), e.children && e.children.forEach((t) => Jt(t));
817
- };
818
- function _t(e) {
819
- for (const t in e)
820
- e[t] && e[t].isTexture && e[t].dispose();
821
- e.dispose();
822
- }
823
- const st = {}, bt = new Qt();
824
- async function de(e, t) {
825
- if (t) {
826
- if (st[t]) {
827
- const i = st[t];
828
- e.environment = i;
829
- return;
830
- }
831
- return new Promise((i, s) => {
832
- bt.load(t, i, void 0, s);
833
- }).then((i) => {
834
- i.mapping = Ct, e.environment = i, st[t] = i;
835
- }).catch((i) => {
836
- console.log(" =====> e:", i);
837
- });
838
- }
839
- }
840
- async function ue(e) {
841
- return new Promise((t, i) => {
842
- bt.load(e, t, void 0, i);
843
- });
844
- }
845
- const ot = {};
846
- async function me(e, t = 50) {
847
- const i = {
848
- type: e.type,
849
- name: e.name,
850
- position: e.position.toArray(),
851
- rotation: e.rotation.toArray(),
852
- scale: e.scale.toArray(),
853
- visible: e.visible,
854
- children: [],
855
- geometry: null,
856
- material: null,
857
- userData: e.userData
858
- };
859
- e.isMesh && (i.geometry = $(e.geometry), i.material = J(e.material));
860
- const s = [{ object: e, parentData: i }];
861
- let r = 0;
862
- for (; s.length > 0; ) {
863
- const { object: a, parentData: n } = s.pop();
864
- for (const c of a.children) {
865
- const d = {
866
- type: c.type,
867
- name: c.name,
868
- position: c.position.toArray(),
869
- rotation: c.rotation.toArray(),
870
- scale: c.scale.toArray(),
871
- visible: c.visible,
872
- children: [],
873
- geometry: null,
874
- material: null,
875
- userData: c.userData
876
- };
877
- c.isMesh && (d.geometry = $(c.geometry), d.material = J(c.material)), n.children.push(d), s.push({ object: c, parentData: d }), r++, r % t === 0 && await new Promise((g) => requestAnimationFrame(g));
878
- }
879
- }
880
- return i;
881
- }
882
- function _e(e) {
883
- const t = {
884
- type: e.type,
885
- name: e.name,
886
- position: e.position.toArray(),
887
- rotation: e.rotation.toArray(),
888
- scale: e.scale.toArray(),
889
- visible: e.visible,
890
- children: [],
891
- geometry: null,
892
- material: null,
893
- userData: e.userData
894
- };
895
- e.isMesh && (t.geometry = $(e.geometry), t.material = J(e.material));
896
- const i = [{ object: e, parentData: t }];
897
- for (; i.length > 0; ) {
898
- const { object: s, parentData: r } = i.pop();
899
- for (const a of s.children) {
900
- const n = {
901
- type: a.type,
902
- name: a.name,
903
- position: a.position.toArray(),
904
- rotation: a.rotation.toArray(),
905
- scale: a.scale.toArray(),
906
- visible: a.visible,
907
- children: [],
908
- geometry: null,
909
- material: null,
910
- userData: a.userData
911
- };
912
- a.isMesh && (n.geometry = $(a.geometry), n.material = J(a.material)), r.children.push(n), i.push({ object: a, parentData: n });
913
- }
914
- }
915
- return t;
916
- }
917
- async function fe(e, t = 50) {
918
- const i = [];
919
- let s;
920
- switch (e.type) {
921
- case "Mesh":
922
- const a = Q(e.geometry), n = tt(e.material);
923
- s = new M.Mesh(a, n);
924
- break;
925
- case "Group":
926
- s = new M.Group();
927
- break;
928
- case "Object3D":
929
- s = new M.Object3D();
930
- break;
931
- default:
932
- return console.warn(`Unsupported object type: ${e.type}`), null;
933
- }
934
- s.name = e.name, s.position.fromArray(e.position), s.rotation.fromArray(e.rotation), s.scale.fromArray(e.scale), s.visible = e.visible, s.userData = e.userData, i.push({ data: e, object: s });
935
- let r = 0;
936
- for (; i.length > 0; ) {
937
- const { data: a, object: n } = i.pop();
938
- for (const c of [...a.children].reverse()) {
939
- let d;
940
- switch (c.type) {
941
- case "Mesh":
942
- const g = Q(c.geometry), m = tt(c.material);
943
- d = new M.Mesh(g, m);
944
- break;
945
- case "Group":
946
- d = new M.Group();
947
- break;
948
- case "Object3D":
949
- d = new M.Object3D();
950
- break;
951
- default:
952
- console.warn(`Unsupported object type: ${c.type}`);
953
- continue;
954
- }
955
- d && (d.name = c.name, d.position.fromArray(c.position), d.rotation.fromArray(c.rotation), d.scale.fromArray(c.scale), d.visible = c.visible, d.userData = c.userData, n.add(d), i.push({ data: c, object: d }), r++, r % t === 0 && await new Promise((g) => requestAnimationFrame(g)));
956
- }
957
- }
958
- return s;
959
- }
960
- function ye(e) {
961
- const t = [];
962
- let i;
963
- switch (e.type) {
964
- case "Mesh":
965
- const s = Q(e.geometry), r = tt(e.material);
966
- i = new M.Mesh(s, r);
967
- break;
968
- case "Group":
969
- i = new M.Group();
970
- break;
971
- case "Object3D":
972
- i = new M.Object3D();
973
- break;
974
- default:
975
- return console.warn(`Unsupported object type: ${e.type}`), null;
976
- }
977
- for (i.name = e.name, i.position.fromArray(e.position), i.rotation.fromArray(e.rotation), i.scale.fromArray(e.scale), i.visible = e.visible, i.userData = e.userData, t.push({ data: e, object: i }); t.length > 0; ) {
978
- const { data: s, object: r } = t.pop();
979
- for (const a of [...s.children].reverse()) {
980
- let n;
981
- switch (a.type) {
982
- case "Mesh":
983
- const c = Q(a.geometry), d = tt(a.material);
984
- n = new M.Mesh(c, d);
985
- break;
986
- case "Group":
987
- n = new M.Group();
988
- break;
989
- case "Object3D":
990
- n = new M.Object3D();
991
- break;
992
- default:
993
- console.warn(`Unsupported object type: ${a.type}`);
994
- continue;
995
- }
996
- n && (n.name = a.name, n.position.fromArray(a.position), n.rotation.fromArray(a.rotation), n.scale.fromArray(a.scale), n.visible = a.visible, n.userData = a.userData, r.add(n), t.push({ data: a, object: n }));
997
- }
998
- }
999
- return i;
1000
- }
1001
- function $(e) {
1002
- const t = {}, { attributes: i, index: s, type: r } = e;
1003
- i.position && (t.position = {
1004
- type: "Float32Array",
1005
- array: Array.from(i.position.array),
1006
- itemSize: 3
1007
- }), i.normal && (t.normal = {
1008
- type: "Float32Array",
1009
- array: Array.from(i.normal.array),
1010
- itemSize: 3
1011
- }), i.uv && (t.uv = {
1012
- type: "Float32Array",
1013
- array: Array.from(i.uv.array),
1014
- itemSize: 2
1015
- });
1016
- const a = {
1017
- type: r,
1018
- attributes: t
1019
- };
1020
- return s && s.array && (a.index = {
1021
- type: "Uint32Array",
1022
- array: Array.from(s.array),
1023
- itemSize: 1
1024
- }), a;
1025
- }
1026
- function Q(e) {
1027
- const { type: t, attributes: i, index: s } = e, r = new M.BufferGeometry();
1028
- for (const a in i)
1029
- if (i.hasOwnProperty(a)) {
1030
- const { type: n, array: c, itemSize: d } = i[a];
1031
- r.setAttribute(
1032
- a,
1033
- new M.BufferAttribute(new Float32Array(c), d)
1034
- );
1035
- }
1036
- return s && r.setIndex(s.array), r;
1037
- }
1038
- function J(e) {
1039
- return {
1040
- type: e.type,
1041
- color: e.color.getHex(),
1042
- map: e.map ? e.map.image.src : null,
1043
- opacity: e.opacity,
1044
- name: e.name,
1045
- depthTest: e.depthTest,
1046
- depthWrite: e.depthWrite,
1047
- transparent: e.transparent,
1048
- side: e.side,
1049
- roughness: e.roughness,
1050
- metalness: e.metalness,
1051
- emissive: e.emissive.getHex()
1052
- };
1053
- }
1054
- function tt(e) {
1055
- if (ot[e.name]) return ot[e.name];
1056
- const { type: t, ...i } = e, s = t || "MeshStandardMaterial", r = new M[s]({ ...i });
1057
- if (e.map) {
1058
- const a = new M.TextureLoader().load(e.map);
1059
- r.map = a;
1060
- }
1061
- return r.needsUpdate = !0, ot[e.name] = r, r;
1062
- }
1063
- export {
1064
- ie as C,
1065
- ue as I,
1066
- K as S,
1067
- oe as a,
1068
- ne as b,
1069
- se as c,
1070
- ae as d,
1071
- re as e,
1072
- le as f,
1073
- he as g,
1074
- ce as h,
1075
- pe as i,
1076
- Jt as j,
1077
- de as k,
1078
- _e as l,
1079
- fe as m,
1080
- ye as n,
1081
- me as o,
1082
- ee as p
1083
- };