@ridp/threejs 1.4.1 → 1.4.2

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 (55) hide show
  1. package/dist/hooks.cjs +1 -1
  2. package/dist/hooks.js +12 -9
  3. package/dist/packages/threejs/package.json.cjs +1 -0
  4. package/dist/packages/threejs/package.json.js +4 -0
  5. package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +1 -0
  6. package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +83 -0
  7. package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +1 -0
  8. package/dist/packages/threejs/src/hooks/useGLTFLoader.js +292 -0
  9. package/dist/packages/threejs/src/hooks/useObb.cjs +1 -0
  10. package/dist/packages/threejs/src/hooks/useObb.js +41 -0
  11. package/dist/packages/threejs/src/hooks/useRaycaster.cjs +1 -0
  12. package/dist/packages/threejs/src/hooks/useRaycaster.js +35 -0
  13. package/dist/packages/threejs/src/hooks/useThreeJs.cjs +5 -0
  14. package/dist/packages/threejs/src/hooks/useThreeJs.js +153 -0
  15. package/dist/packages/threejs/src/instance/IDBCache.cjs +1 -0
  16. package/dist/packages/threejs/src/instance/IDBCache.js +142 -0
  17. package/dist/packages/threejs/src/instance/threeIns.cjs +3 -0
  18. package/dist/packages/threejs/src/instance/threeIns.js +369 -0
  19. package/dist/packages/threejs/src/utils/CacheMonitor.cjs +1 -0
  20. package/dist/packages/threejs/src/utils/CacheMonitor.js +125 -0
  21. package/dist/packages/threejs/src/utils/ImageLoader.cjs +1 -0
  22. package/dist/packages/threejs/src/utils/ImageLoader.js +33 -0
  23. package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +1 -0
  24. package/dist/packages/threejs/src/utils/PredictiveLoader.js +155 -0
  25. package/dist/packages/threejs/src/utils/RetryHelper.cjs +1 -0
  26. package/dist/packages/threejs/src/utils/RetryHelper.js +108 -0
  27. package/dist/packages/threejs/src/utils/common.cjs +1 -0
  28. package/dist/packages/threejs/src/utils/common.js +15 -0
  29. package/dist/packages/threejs/src/utils/css3dHelper.cjs +15 -0
  30. package/dist/packages/threejs/src/utils/css3dHelper.js +42 -0
  31. package/dist/packages/threejs/src/utils/disposeObject.cjs +1 -0
  32. package/dist/packages/threejs/src/utils/disposeObject.js +13 -0
  33. package/dist/packages/threejs/src/utils/helper.cjs +1 -0
  34. package/dist/packages/threejs/src/utils/helper.js +47 -0
  35. package/dist/packages/threejs/src/utils/modelSerialize.cjs +1 -0
  36. package/dist/packages/threejs/src/utils/modelSerialize.js +225 -0
  37. package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +1 -0
  38. package/dist/packages/threejs/src/utils/sceneRebuilder.js +138 -0
  39. package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +1 -0
  40. package/dist/packages/threejs/src/workers/gltfParser.worker.js +11 -0
  41. package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +1 -0
  42. package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +11 -0
  43. package/dist/threejs.cjs +1 -3
  44. package/dist/threejs.js +58 -404
  45. package/dist/utils.cjs +1 -1
  46. package/dist/utils.js +40 -32
  47. package/package.json +1 -1
  48. package/dist/ImageLoader-Br_nvMOg.js +0 -1444
  49. package/dist/ImageLoader-DL32KyTh.cjs +0 -24
  50. package/dist/PredictiveLoader-CZfMSjv-.js +0 -3731
  51. package/dist/PredictiveLoader-DDxh7dDg.cjs +0 -2
  52. package/dist/useBatchGLTFLoader-B5EUagWI.js +0 -493
  53. package/dist/useBatchGLTFLoader-BjAvIpyB.cjs +0 -5
  54. /package/dist/{modelOptimizer-A0Cs6f9e.cjs → packages/threejs/src/utils/modelOptimizer.cjs} +0 -0
  55. /package/dist/{modelOptimizer-BRPnM2RH.js → packages/threejs/src/utils/modelOptimizer.js} +0 -0
@@ -1,3731 +0,0 @@
1
- import * as E from "three";
2
- import { Matrix4 as J, Vector3 as L, Quaternion as re, Object3D as De, Controls as ht, MOUSE as U, TOUCH as z, Spherical as Ie, Vector2 as C, Ray as ut, Plane as dt, MathUtils as $e, CameraHelper as ft, GridHelper as pt, BoxHelper as mt, Raycaster as gt, AxesHelper as yt, ArrowHelper as _t, TrianglesDrawMode as Tt, TriangleFanDrawMode as Ae, TriangleStripDrawMode as Qe, Loader as Je, FileLoader as ce, SRGBColorSpace as K, LinearSRGBColorSpace as N, BufferGeometry as et, BufferAttribute as se, Color as W, ColorManagement as Re, LoaderUtils as ne, MeshPhysicalMaterial as v, SpotLight as wt, PointLight as bt, DirectionalLight as Et, InstancedMesh as xt, InstancedBufferAttribute as At, TextureLoader as Rt, ImageBitmapLoader as St, InterleavedBuffer as Mt, InterleavedBufferAttribute as Lt, LinearMipmapLinearFilter as tt, NearestMipmapLinearFilter as Pt, LinearMipmapNearestFilter as Dt, NearestMipmapNearestFilter as Ot, LinearFilter as Se, NearestFilter as st, RepeatWrapping as Me, MirroredRepeatWrapping as Ct, ClampToEdgeWrapping as It, PointsMaterial as kt, Material as pe, LineBasicMaterial as Nt, MeshStandardMaterial as nt, DoubleSide as vt, MeshBasicMaterial as te, PropertyBinding as Ht, SkinnedMesh as Ft, Mesh as Ut, LineSegments as jt, Line as Gt, LineLoop as Bt, Points as zt, Group as me, PerspectiveCamera as Kt, OrthographicCamera as Wt, Skeleton as Xt, AnimationClip as Vt, Bone as Yt, InterpolateDiscrete as qt, InterpolateLinear as it, Texture as ke, VectorKeyframeTrack as Ne, NumberKeyframeTrack as ve, QuaternionKeyframeTrack as He, FrontSide as Zt, Interpolant as $t, Box3 as Qt, Sphere as Jt } from "three";
3
- import es from "dexie";
4
- var ie = function() {
5
- var r = 0, e = document.createElement("div");
6
- e.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", e.addEventListener("click", function(u) {
7
- u.preventDefault(), s(++r % e.children.length);
8
- }, !1);
9
- function t(u) {
10
- return e.appendChild(u.dom), u;
11
- }
12
- function s(u) {
13
- for (var h = 0; h < e.children.length; h++)
14
- e.children[h].style.display = h === u ? "block" : "none";
15
- r = u;
16
- }
17
- var n = (performance || Date).now(), i = n, o = 0, c = t(new ie.Panel("FPS", "#0ff", "#002")), a = t(new ie.Panel("MS", "#0f0", "#020"));
18
- if (self.performance && self.performance.memory)
19
- var l = t(new ie.Panel("MB", "#f08", "#201"));
20
- return s(0), {
21
- REVISION: 16,
22
- dom: e,
23
- addPanel: t,
24
- showPanel: s,
25
- begin: function() {
26
- n = (performance || Date).now();
27
- },
28
- end: function() {
29
- o++;
30
- var u = (performance || Date).now();
31
- if (a.update(u - n, 200), u >= i + 1e3 && (c.update(o * 1e3 / (u - i), 100), i = u, o = 0, l)) {
32
- var h = performance.memory;
33
- l.update(h.usedJSHeapSize / 1048576, h.jsHeapSizeLimit / 1048576);
34
- }
35
- return u;
36
- },
37
- update: function() {
38
- n = this.end();
39
- },
40
- // Backwards Compatibility
41
- domElement: e,
42
- setMode: s
43
- };
44
- };
45
- ie.Panel = function(r, e, t) {
46
- var s = 1 / 0, n = 0, i = Math.round, o = i(window.devicePixelRatio || 1), c = 80 * o, a = 48 * o, l = 3 * o, u = 2 * o, h = 3 * o, m = 15 * o, f = 74 * o, g = 30 * o, y = document.createElement("canvas");
47
- y.width = c, y.height = a, y.style.cssText = "width:80px;height:48px";
48
- var p = y.getContext("2d");
49
- return p.font = "bold " + 9 * o + "px Helvetica,Arial,sans-serif", p.textBaseline = "top", p.fillStyle = t, p.fillRect(0, 0, c, a), p.fillStyle = e, p.fillText(r, l, u), p.fillRect(h, m, f, g), p.fillStyle = t, p.globalAlpha = 0.9, p.fillRect(h, m, f, g), {
50
- dom: y,
51
- update: function(d, _) {
52
- s = Math.min(s, d), n = Math.max(n, d), p.fillStyle = t, p.globalAlpha = 1, p.fillRect(0, 0, c, m), p.fillStyle = e, p.fillText(i(d) + " " + r + " (" + i(s) + "-" + i(n) + ")", l, u), p.drawImage(y, h + o, m, f - o, g, h, m, f - o, g), p.fillRect(h + f - o, m, o, g), p.fillStyle = t, p.globalAlpha = 0.9, p.fillRect(h + f - o, m, o, i((1 - d / _) * g));
53
- }
54
- };
55
- };
56
- const Fe = new L(), ts = new re(), Ue = new L();
57
- class ss extends De {
58
- /**
59
- * Constructs a new CSS3D object.
60
- *
61
- * @param {DOMElement} [element] - The DOM element.
62
- */
63
- constructor(e = document.createElement("div")) {
64
- super(), this.isCSS3DObject = !0, this.element = e, this.element.style.position = "absolute", this.element.style.pointerEvents = "auto", this.element.style.userSelect = "none", this.element.setAttribute("draggable", !1), this.addEventListener("removed", function() {
65
- this.traverse(function(t) {
66
- t.element instanceof t.element.ownerDocument.defaultView.Element && t.element.parentNode !== null && t.element.remove();
67
- });
68
- });
69
- }
70
- copy(e, t) {
71
- return super.copy(e, t), this.element = e.element.cloneNode(!0), this;
72
- }
73
- }
74
- class fn extends ss {
75
- /**
76
- * Constructs a new CSS3D sprite object.
77
- *
78
- * @param {DOMElement} [element] - The DOM element.
79
- */
80
- constructor(e) {
81
- super(e), this.isCSS3DSprite = !0, this.rotation2D = 0;
82
- }
83
- copy(e, t) {
84
- return super.copy(e, t), this.rotation2D = e.rotation2D, this;
85
- }
86
- }
87
- const k = new J(), ns = new J();
88
- class pn {
89
- /**
90
- * Constructs a new CSS3D renderer.
91
- *
92
- * @param {CSS3DRenderer~Parameters} [parameters] - The parameters.
93
- */
94
- constructor(e = {}) {
95
- const t = this;
96
- let s, n, i, o;
97
- const c = {
98
- camera: { style: "" },
99
- objects: /* @__PURE__ */ new WeakMap()
100
- }, a = e.element !== void 0 ? e.element : document.createElement("div");
101
- a.style.overflow = "hidden", this.domElement = a;
102
- const l = document.createElement("div");
103
- l.style.transformOrigin = "0 0", l.style.pointerEvents = "none", a.appendChild(l);
104
- const u = document.createElement("div");
105
- u.style.transformStyle = "preserve-3d", l.appendChild(u), this.getSize = function() {
106
- return {
107
- width: s,
108
- height: n
109
- };
110
- }, this.render = function(p, d) {
111
- const _ = d.projectionMatrix.elements[5] * o;
112
- d.view && d.view.enabled ? (l.style.transform = `translate( ${-d.view.offsetX * (s / d.view.width)}px, ${-d.view.offsetY * (n / d.view.height)}px )`, l.style.transform += `scale( ${d.view.fullWidth / d.view.width}, ${d.view.fullHeight / d.view.height} )`) : l.style.transform = "", p.matrixWorldAutoUpdate === !0 && p.updateMatrixWorld(), d.parent === null && d.matrixWorldAutoUpdate === !0 && d.updateMatrixWorld();
113
- let w, T;
114
- d.isOrthographicCamera && (w = -(d.right + d.left) / 2, T = (d.top + d.bottom) / 2);
115
- const A = d.view && d.view.enabled ? d.view.height / d.view.fullHeight : 1, S = d.isOrthographicCamera ? `scale( ${A} )scale(` + _ + ")translate(" + h(w) + "px," + h(T) + "px)" + m(d.matrixWorldInverse) : `scale( ${A} )translateZ(` + _ + "px)" + m(d.matrixWorldInverse), R = (d.isPerspectiveCamera ? "perspective(" + _ + "px) " : "") + S + "translate(" + i + "px," + o + "px)";
116
- c.camera.style !== R && (u.style.transform = R, c.camera.style = R), y(p, p, d);
117
- }, this.setSize = function(p, d) {
118
- s = p, n = d, i = s / 2, o = n / 2, a.style.width = p + "px", a.style.height = d + "px", l.style.width = p + "px", l.style.height = d + "px", u.style.width = p + "px", u.style.height = d + "px";
119
- };
120
- function h(p) {
121
- return Math.abs(p) < 1e-10 ? 0 : p;
122
- }
123
- function m(p) {
124
- const d = p.elements;
125
- return "matrix3d(" + h(d[0]) + "," + h(-d[1]) + "," + h(d[2]) + "," + h(d[3]) + "," + h(d[4]) + "," + h(-d[5]) + "," + h(d[6]) + "," + h(d[7]) + "," + h(d[8]) + "," + h(-d[9]) + "," + h(d[10]) + "," + h(d[11]) + "," + h(d[12]) + "," + h(-d[13]) + "," + h(d[14]) + "," + h(d[15]) + ")";
126
- }
127
- function f(p) {
128
- const d = p.elements;
129
- return "translate(-50%,-50%)" + ("matrix3d(" + h(d[0]) + "," + h(d[1]) + "," + h(d[2]) + "," + h(d[3]) + "," + h(-d[4]) + "," + h(-d[5]) + "," + h(-d[6]) + "," + h(-d[7]) + "," + h(d[8]) + "," + h(d[9]) + "," + h(d[10]) + "," + h(d[11]) + "," + h(d[12]) + "," + h(d[13]) + "," + h(d[14]) + "," + h(d[15]) + ")");
130
- }
131
- function g(p) {
132
- p.isCSS3DObject && (p.element.style.display = "none");
133
- for (let d = 0, _ = p.children.length; d < _; d++)
134
- g(p.children[d]);
135
- }
136
- function y(p, d, _, w) {
137
- if (p.visible === !1) {
138
- g(p);
139
- return;
140
- }
141
- if (p.isCSS3DObject) {
142
- const T = p.layers.test(_.layers) === !0, A = p.element;
143
- if (A.style.display = T === !0 ? "" : "none", T === !0) {
144
- p.onBeforeRender(t, d, _);
145
- let S;
146
- p.isCSS3DSprite ? (k.copy(_.matrixWorldInverse), k.transpose(), p.rotation2D !== 0 && k.multiply(ns.makeRotationZ(p.rotation2D)), p.matrixWorld.decompose(Fe, ts, Ue), k.setPosition(Fe), k.scale(Ue), k.elements[3] = 0, k.elements[7] = 0, k.elements[11] = 0, k.elements[15] = 1, S = f(k)) : S = f(p.matrixWorld);
147
- const M = c.objects.get(p);
148
- if (M === void 0 || M.style !== S) {
149
- A.style.transform = S;
150
- const R = { style: S };
151
- c.objects.set(p, R);
152
- }
153
- A.parentNode !== u && u.appendChild(A), p.onAfterRender(t, d, _);
154
- }
155
- }
156
- for (let T = 0, A = p.children.length; T < A; T++)
157
- y(p.children[T], d, _);
158
- }
159
- }
160
- }
161
- const je = { type: "change" }, Oe = { type: "start" }, ot = { type: "end" }, ae = new ut(), Ge = new dt(), is = Math.cos(70 * $e.DEG2RAD), P = new L(), O = 2 * Math.PI, x = {
162
- NONE: -1,
163
- ROTATE: 0,
164
- DOLLY: 1,
165
- PAN: 2,
166
- TOUCH_ROTATE: 3,
167
- TOUCH_PAN: 4,
168
- TOUCH_DOLLY_PAN: 5,
169
- TOUCH_DOLLY_ROTATE: 6
170
- }, ge = 1e-6;
171
- class rt extends ht {
172
- /**
173
- * Constructs a new controls instance.
174
- *
175
- * @param {Object3D} object - The object that is managed by the controls.
176
- * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
177
- */
178
- constructor(e, t = null) {
179
- super(e, t), this.state = x.NONE, this.target = new L(), this.cursor = new L(), 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: U.ROTATE, MIDDLE: U.DOLLY, RIGHT: U.PAN }, this.touches = { ONE: z.ROTATE, TWO: z.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new L(), this._lastQuaternion = new re(), this._lastTargetPosition = new L(), this._quat = new re().setFromUnitVectors(e.up, new L(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new Ie(), this._sphericalDelta = new Ie(), this._scale = 1, this._panOffset = new L(), this._rotateStart = new C(), this._rotateEnd = new C(), this._rotateDelta = new C(), this._panStart = new C(), this._panEnd = new C(), this._panDelta = new C(), this._dollyStart = new C(), this._dollyEnd = new C(), this._dollyDelta = new C(), this._dollyDirection = new L(), this._mouse = new C(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = rs.bind(this), this._onPointerDown = os.bind(this), this._onPointerUp = as.bind(this), this._onContextMenu = ps.bind(this), this._onMouseWheel = hs.bind(this), this._onKeyDown = us.bind(this), this._onTouchStart = ds.bind(this), this._onTouchMove = fs.bind(this), this._onMouseDown = cs.bind(this), this._onMouseMove = ls.bind(this), this._interceptControlDown = ms.bind(this), this._interceptControlUp = gs.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
180
- }
181
- connect(e) {
182
- super.connect(e), 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";
183
- }
184
- disconnect() {
185
- 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";
186
- }
187
- dispose() {
188
- this.disconnect();
189
- }
190
- /**
191
- * Get the current vertical rotation, in radians.
192
- *
193
- * @return {number} The current vertical rotation, in radians.
194
- */
195
- getPolarAngle() {
196
- return this._spherical.phi;
197
- }
198
- /**
199
- * Get the current horizontal rotation, in radians.
200
- *
201
- * @return {number} The current horizontal rotation, in radians.
202
- */
203
- getAzimuthalAngle() {
204
- return this._spherical.theta;
205
- }
206
- /**
207
- * Returns the distance from the camera to the target.
208
- *
209
- * @return {number} The distance from the camera to the target.
210
- */
211
- getDistance() {
212
- return this.object.position.distanceTo(this.target);
213
- }
214
- /**
215
- * Adds key event listeners to the given DOM element.
216
- * `window` is a recommended argument for using this method.
217
- *
218
- * @param {HTMLDOMElement} domElement - The DOM element
219
- */
220
- listenToKeyEvents(e) {
221
- e.addEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = e;
222
- }
223
- /**
224
- * Removes the key event listener previously defined with `listenToKeyEvents()`.
225
- */
226
- stopListenToKeyEvents() {
227
- this._domElementKeyEvents !== null && (this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = null);
228
- }
229
- /**
230
- * Save the current state of the controls. This can later be recovered with `reset()`.
231
- */
232
- saveState() {
233
- this.target0.copy(this.target), this.position0.copy(this.object.position), this.zoom0 = this.object.zoom;
234
- }
235
- /**
236
- * Reset the controls to their state from either the last time the `saveState()`
237
- * was called, or the initial state.
238
- */
239
- reset() {
240
- this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(je), this.update(), this.state = x.NONE;
241
- }
242
- update(e = null) {
243
- const t = this.object.position;
244
- P.copy(t).sub(this.target), P.applyQuaternion(this._quat), this._spherical.setFromVector3(P), this.autoRotate && this.state === x.NONE && this._rotateLeft(this._getAutoRotationAngle(e)), 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);
245
- let s = this.minAzimuthAngle, n = this.maxAzimuthAngle;
246
- isFinite(s) && isFinite(n) && (s < -Math.PI ? s += O : s > Math.PI && (s -= O), n < -Math.PI ? n += O : n > Math.PI && (n -= O), s <= n ? this._spherical.theta = Math.max(s, Math.min(n, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (s + n) / 2 ? Math.max(s, this._spherical.theta) : Math.min(n, 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);
247
- let i = !1;
248
- if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
249
- this._spherical.radius = this._clampDistance(this._spherical.radius);
250
- else {
251
- const o = this._spherical.radius;
252
- this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), i = o != this._spherical.radius;
253
- }
254
- if (P.setFromSpherical(this._spherical), P.applyQuaternion(this._quatInverse), t.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) {
255
- let o = null;
256
- if (this.object.isPerspectiveCamera) {
257
- const c = P.length();
258
- o = this._clampDistance(c * this._scale);
259
- const a = c - o;
260
- this.object.position.addScaledVector(this._dollyDirection, a), this.object.updateMatrixWorld(), i = !!a;
261
- } else if (this.object.isOrthographicCamera) {
262
- const c = new L(this._mouse.x, this._mouse.y, 0);
263
- c.unproject(this.object);
264
- const a = this.object.zoom;
265
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), i = a !== this.object.zoom;
266
- const l = new L(this._mouse.x, this._mouse.y, 0);
267
- l.unproject(this.object), this.object.position.sub(l).add(c), this.object.updateMatrixWorld(), o = P.length();
268
- } else
269
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
270
- o !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position) : (ae.origin.copy(this.object.position), ae.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(ae.direction)) < is ? this.object.lookAt(this.target) : (Ge.setFromNormalAndCoplanarPoint(this.object.up, this.target), ae.intersectPlane(Ge, this.target))));
271
- } else if (this.object.isOrthographicCamera) {
272
- const o = this.object.zoom;
273
- this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), o !== this.object.zoom && (this.object.updateProjectionMatrix(), i = !0);
274
- }
275
- return this._scale = 1, this._performCursorZoom = !1, i || this._lastPosition.distanceToSquared(this.object.position) > ge || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > ge || this._lastTargetPosition.distanceToSquared(this.target) > ge ? (this.dispatchEvent(je), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
276
- }
277
- _getAutoRotationAngle(e) {
278
- return e !== null ? O / 60 * this.autoRotateSpeed * e : O / 60 / 60 * this.autoRotateSpeed;
279
- }
280
- _getZoomScale(e) {
281
- const t = Math.abs(e * 0.01);
282
- return Math.pow(0.95, this.zoomSpeed * t);
283
- }
284
- _rotateLeft(e) {
285
- this._sphericalDelta.theta -= e;
286
- }
287
- _rotateUp(e) {
288
- this._sphericalDelta.phi -= e;
289
- }
290
- _panLeft(e, t) {
291
- P.setFromMatrixColumn(t, 0), P.multiplyScalar(-e), this._panOffset.add(P);
292
- }
293
- _panUp(e, t) {
294
- this.screenSpacePanning === !0 ? P.setFromMatrixColumn(t, 1) : (P.setFromMatrixColumn(t, 0), P.crossVectors(this.object.up, P)), P.multiplyScalar(e), this._panOffset.add(P);
295
- }
296
- // deltaX and deltaY are in pixels; right and down are positive
297
- _pan(e, t) {
298
- const s = this.domElement;
299
- if (this.object.isPerspectiveCamera) {
300
- const n = this.object.position;
301
- P.copy(n).sub(this.target);
302
- let i = P.length();
303
- i *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * e * i / s.clientHeight, this.object.matrix), this._panUp(2 * t * i / s.clientHeight, this.object.matrix);
304
- } else this.object.isOrthographicCamera ? (this._panLeft(e * (this.object.right - this.object.left) / this.object.zoom / s.clientWidth, this.object.matrix), this._panUp(t * (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);
305
- }
306
- _dollyOut(e) {
307
- this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= e : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
308
- }
309
- _dollyIn(e) {
310
- this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= e : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
311
- }
312
- _updateZoomParameters(e, t) {
313
- if (!this.zoomToCursor)
314
- return;
315
- this._performCursorZoom = !0;
316
- const s = this.domElement.getBoundingClientRect(), n = e - s.left, i = t - s.top, o = s.width, c = s.height;
317
- this._mouse.x = n / o * 2 - 1, this._mouse.y = -(i / c) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
318
- }
319
- _clampDistance(e) {
320
- return Math.max(this.minDistance, Math.min(this.maxDistance, e));
321
- }
322
- //
323
- // event callbacks - update the object state
324
- //
325
- _handleMouseDownRotate(e) {
326
- this._rotateStart.set(e.clientX, e.clientY);
327
- }
328
- _handleMouseDownDolly(e) {
329
- this._updateZoomParameters(e.clientX, e.clientX), this._dollyStart.set(e.clientX, e.clientY);
330
- }
331
- _handleMouseDownPan(e) {
332
- this._panStart.set(e.clientX, e.clientY);
333
- }
334
- _handleMouseMoveRotate(e) {
335
- this._rotateEnd.set(e.clientX, e.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
336
- const t = this.domElement;
337
- this._rotateLeft(O * this._rotateDelta.x / t.clientHeight), this._rotateUp(O * this._rotateDelta.y / t.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
338
- }
339
- _handleMouseMoveDolly(e) {
340
- this._dollyEnd.set(e.clientX, e.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();
341
- }
342
- _handleMouseMovePan(e) {
343
- this._panEnd.set(e.clientX, e.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();
344
- }
345
- _handleMouseWheel(e) {
346
- this._updateZoomParameters(e.clientX, e.clientY), e.deltaY < 0 ? this._dollyIn(this._getZoomScale(e.deltaY)) : e.deltaY > 0 && this._dollyOut(this._getZoomScale(e.deltaY)), this.update();
347
- }
348
- _handleKeyDown(e) {
349
- let t = !1;
350
- switch (e.code) {
351
- case this.keys.UP:
352
- e.ctrlKey || e.metaKey || e.shiftKey ? this.enableRotate && this._rotateUp(O * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), t = !0;
353
- break;
354
- case this.keys.BOTTOM:
355
- e.ctrlKey || e.metaKey || e.shiftKey ? this.enableRotate && this._rotateUp(-O * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), t = !0;
356
- break;
357
- case this.keys.LEFT:
358
- e.ctrlKey || e.metaKey || e.shiftKey ? this.enableRotate && this._rotateLeft(O * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), t = !0;
359
- break;
360
- case this.keys.RIGHT:
361
- e.ctrlKey || e.metaKey || e.shiftKey ? this.enableRotate && this._rotateLeft(-O * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), t = !0;
362
- break;
363
- }
364
- t && (e.preventDefault(), this.update());
365
- }
366
- _handleTouchStartRotate(e) {
367
- if (this._pointers.length === 1)
368
- this._rotateStart.set(e.pageX, e.pageY);
369
- else {
370
- const t = this._getSecondPointerPosition(e), s = 0.5 * (e.pageX + t.x), n = 0.5 * (e.pageY + t.y);
371
- this._rotateStart.set(s, n);
372
- }
373
- }
374
- _handleTouchStartPan(e) {
375
- if (this._pointers.length === 1)
376
- this._panStart.set(e.pageX, e.pageY);
377
- else {
378
- const t = this._getSecondPointerPosition(e), s = 0.5 * (e.pageX + t.x), n = 0.5 * (e.pageY + t.y);
379
- this._panStart.set(s, n);
380
- }
381
- }
382
- _handleTouchStartDolly(e) {
383
- const t = this._getSecondPointerPosition(e), s = e.pageX - t.x, n = e.pageY - t.y, i = Math.sqrt(s * s + n * n);
384
- this._dollyStart.set(0, i);
385
- }
386
- _handleTouchStartDollyPan(e) {
387
- this.enableZoom && this._handleTouchStartDolly(e), this.enablePan && this._handleTouchStartPan(e);
388
- }
389
- _handleTouchStartDollyRotate(e) {
390
- this.enableZoom && this._handleTouchStartDolly(e), this.enableRotate && this._handleTouchStartRotate(e);
391
- }
392
- _handleTouchMoveRotate(e) {
393
- if (this._pointers.length == 1)
394
- this._rotateEnd.set(e.pageX, e.pageY);
395
- else {
396
- const s = this._getSecondPointerPosition(e), n = 0.5 * (e.pageX + s.x), i = 0.5 * (e.pageY + s.y);
397
- this._rotateEnd.set(n, i);
398
- }
399
- this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
400
- const t = this.domElement;
401
- this._rotateLeft(O * this._rotateDelta.x / t.clientHeight), this._rotateUp(O * this._rotateDelta.y / t.clientHeight), this._rotateStart.copy(this._rotateEnd);
402
- }
403
- _handleTouchMovePan(e) {
404
- if (this._pointers.length === 1)
405
- this._panEnd.set(e.pageX, e.pageY);
406
- else {
407
- const t = this._getSecondPointerPosition(e), s = 0.5 * (e.pageX + t.x), n = 0.5 * (e.pageY + t.y);
408
- this._panEnd.set(s, n);
409
- }
410
- this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
411
- }
412
- _handleTouchMoveDolly(e) {
413
- const t = this._getSecondPointerPosition(e), s = e.pageX - t.x, n = e.pageY - t.y, i = Math.sqrt(s * s + n * n);
414
- this._dollyEnd.set(0, i), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
415
- const o = (e.pageX + t.x) * 0.5, c = (e.pageY + t.y) * 0.5;
416
- this._updateZoomParameters(o, c);
417
- }
418
- _handleTouchMoveDollyPan(e) {
419
- this.enableZoom && this._handleTouchMoveDolly(e), this.enablePan && this._handleTouchMovePan(e);
420
- }
421
- _handleTouchMoveDollyRotate(e) {
422
- this.enableZoom && this._handleTouchMoveDolly(e), this.enableRotate && this._handleTouchMoveRotate(e);
423
- }
424
- // pointers
425
- _addPointer(e) {
426
- this._pointers.push(e.pointerId);
427
- }
428
- _removePointer(e) {
429
- delete this._pointerPositions[e.pointerId];
430
- for (let t = 0; t < this._pointers.length; t++)
431
- if (this._pointers[t] == e.pointerId) {
432
- this._pointers.splice(t, 1);
433
- return;
434
- }
435
- }
436
- _isTrackingPointer(e) {
437
- for (let t = 0; t < this._pointers.length; t++)
438
- if (this._pointers[t] == e.pointerId) return !0;
439
- return !1;
440
- }
441
- _trackPointer(e) {
442
- let t = this._pointerPositions[e.pointerId];
443
- t === void 0 && (t = new C(), this._pointerPositions[e.pointerId] = t), t.set(e.pageX, e.pageY);
444
- }
445
- _getSecondPointerPosition(e) {
446
- const t = e.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
447
- return this._pointerPositions[t];
448
- }
449
- //
450
- _customWheelEvent(e) {
451
- const t = e.deltaMode, s = {
452
- clientX: e.clientX,
453
- clientY: e.clientY,
454
- deltaY: e.deltaY
455
- };
456
- switch (t) {
457
- case 1:
458
- s.deltaY *= 16;
459
- break;
460
- case 2:
461
- s.deltaY *= 100;
462
- break;
463
- }
464
- return e.ctrlKey && !this._controlActive && (s.deltaY *= 10), s;
465
- }
466
- }
467
- function os(r) {
468
- this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(r.pointerId), this.domElement.addEventListener("pointermove", this._onPointerMove), this.domElement.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(r) && (this._addPointer(r), r.pointerType === "touch" ? this._onTouchStart(r) : this._onMouseDown(r)));
469
- }
470
- function rs(r) {
471
- this.enabled !== !1 && (r.pointerType === "touch" ? this._onTouchMove(r) : this._onMouseMove(r));
472
- }
473
- function as(r) {
474
- switch (this._removePointer(r), this._pointers.length) {
475
- case 0:
476
- this.domElement.releasePointerCapture(r.pointerId), this.domElement.removeEventListener("pointermove", this._onPointerMove), this.domElement.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(ot), this.state = x.NONE;
477
- break;
478
- case 1:
479
- const e = this._pointers[0], t = this._pointerPositions[e];
480
- this._onTouchStart({ pointerId: e, pageX: t.x, pageY: t.y });
481
- break;
482
- }
483
- }
484
- function cs(r) {
485
- let e;
486
- switch (r.button) {
487
- case 0:
488
- e = this.mouseButtons.LEFT;
489
- break;
490
- case 1:
491
- e = this.mouseButtons.MIDDLE;
492
- break;
493
- case 2:
494
- e = this.mouseButtons.RIGHT;
495
- break;
496
- default:
497
- e = -1;
498
- }
499
- switch (e) {
500
- case U.DOLLY:
501
- if (this.enableZoom === !1) return;
502
- this._handleMouseDownDolly(r), this.state = x.DOLLY;
503
- break;
504
- case U.ROTATE:
505
- if (r.ctrlKey || r.metaKey || r.shiftKey) {
506
- if (this.enablePan === !1) return;
507
- this._handleMouseDownPan(r), this.state = x.PAN;
508
- } else {
509
- if (this.enableRotate === !1) return;
510
- this._handleMouseDownRotate(r), this.state = x.ROTATE;
511
- }
512
- break;
513
- case U.PAN:
514
- if (r.ctrlKey || r.metaKey || r.shiftKey) {
515
- if (this.enableRotate === !1) return;
516
- this._handleMouseDownRotate(r), this.state = x.ROTATE;
517
- } else {
518
- if (this.enablePan === !1) return;
519
- this._handleMouseDownPan(r), this.state = x.PAN;
520
- }
521
- break;
522
- default:
523
- this.state = x.NONE;
524
- }
525
- this.state !== x.NONE && this.dispatchEvent(Oe);
526
- }
527
- function ls(r) {
528
- switch (this.state) {
529
- case x.ROTATE:
530
- if (this.enableRotate === !1) return;
531
- this._handleMouseMoveRotate(r);
532
- break;
533
- case x.DOLLY:
534
- if (this.enableZoom === !1) return;
535
- this._handleMouseMoveDolly(r);
536
- break;
537
- case x.PAN:
538
- if (this.enablePan === !1) return;
539
- this._handleMouseMovePan(r);
540
- break;
541
- }
542
- }
543
- function hs(r) {
544
- this.enabled === !1 || this.enableZoom === !1 || this.state !== x.NONE || (r.preventDefault(), this.dispatchEvent(Oe), this._handleMouseWheel(this._customWheelEvent(r)), this.dispatchEvent(ot));
545
- }
546
- function us(r) {
547
- this.enabled !== !1 && this._handleKeyDown(r);
548
- }
549
- function ds(r) {
550
- switch (this._trackPointer(r), this._pointers.length) {
551
- case 1:
552
- switch (this.touches.ONE) {
553
- case z.ROTATE:
554
- if (this.enableRotate === !1) return;
555
- this._handleTouchStartRotate(r), this.state = x.TOUCH_ROTATE;
556
- break;
557
- case z.PAN:
558
- if (this.enablePan === !1) return;
559
- this._handleTouchStartPan(r), this.state = x.TOUCH_PAN;
560
- break;
561
- default:
562
- this.state = x.NONE;
563
- }
564
- break;
565
- case 2:
566
- switch (this.touches.TWO) {
567
- case z.DOLLY_PAN:
568
- if (this.enableZoom === !1 && this.enablePan === !1) return;
569
- this._handleTouchStartDollyPan(r), this.state = x.TOUCH_DOLLY_PAN;
570
- break;
571
- case z.DOLLY_ROTATE:
572
- if (this.enableZoom === !1 && this.enableRotate === !1) return;
573
- this._handleTouchStartDollyRotate(r), this.state = x.TOUCH_DOLLY_ROTATE;
574
- break;
575
- default:
576
- this.state = x.NONE;
577
- }
578
- break;
579
- default:
580
- this.state = x.NONE;
581
- }
582
- this.state !== x.NONE && this.dispatchEvent(Oe);
583
- }
584
- function fs(r) {
585
- switch (this._trackPointer(r), this.state) {
586
- case x.TOUCH_ROTATE:
587
- if (this.enableRotate === !1) return;
588
- this._handleTouchMoveRotate(r), this.update();
589
- break;
590
- case x.TOUCH_PAN:
591
- if (this.enablePan === !1) return;
592
- this._handleTouchMovePan(r), this.update();
593
- break;
594
- case x.TOUCH_DOLLY_PAN:
595
- if (this.enableZoom === !1 && this.enablePan === !1) return;
596
- this._handleTouchMoveDollyPan(r), this.update();
597
- break;
598
- case x.TOUCH_DOLLY_ROTATE:
599
- if (this.enableZoom === !1 && this.enableRotate === !1) return;
600
- this._handleTouchMoveDollyRotate(r), this.update();
601
- break;
602
- default:
603
- this.state = x.NONE;
604
- }
605
- }
606
- function ps(r) {
607
- this.enabled !== !1 && r.preventDefault();
608
- }
609
- function ms(r) {
610
- r.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
611
- }
612
- function gs(r) {
613
- r.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
614
- }
615
- class ys extends rt {
616
- constructor(e, t) {
617
- super(e, t), this.screenSpacePanning = !1, this.mouseButtons = { LEFT: U.PAN, MIDDLE: U.DOLLY, RIGHT: U.ROTATE }, this.touches = { ONE: z.PAN, TWO: z.DOLLY_ROTATE };
618
- }
619
- }
620
- function mn(r) {
621
- return new ft(r);
622
- }
623
- function gn(r = 150, ...e) {
624
- return new pt(r, r / 10, ...e);
625
- }
626
- function yn(r) {
627
- return new mt(r, 16776960);
628
- }
629
- function _n(r, e) {
630
- return new rt(r, e);
631
- }
632
- function Tn(r, e) {
633
- return new ys(r, e);
634
- }
635
- function wn() {
636
- const r = new gt(), e = new C(0, 0);
637
- return {
638
- raycaster: r,
639
- pointer: e
640
- };
641
- }
642
- function bn(r = 10) {
643
- return new yt(r);
644
- }
645
- function En(r = new L(1, 1, 1), e = new L(10, 10, 10), t = 5, s = 16776960) {
646
- return r.normalize(), new _t(r, e, t, s);
647
- }
648
- function xn() {
649
- const r = new ie();
650
- return r.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", r;
651
- }
652
- function Be(r, e) {
653
- if (e === Tt)
654
- return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), r;
655
- if (e === Ae || e === Qe) {
656
- let t = r.getIndex();
657
- if (t === null) {
658
- const o = [], c = r.getAttribute("position");
659
- if (c !== void 0) {
660
- for (let a = 0; a < c.count; a++)
661
- o.push(a);
662
- r.setIndex(o), t = r.getIndex();
663
- } else
664
- return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), r;
665
- }
666
- const s = t.count - 2, n = [];
667
- if (e === Ae)
668
- for (let o = 1; o <= s; o++)
669
- n.push(t.getX(0)), n.push(t.getX(o)), n.push(t.getX(o + 1));
670
- else
671
- for (let o = 0; o < s; o++)
672
- o % 2 === 0 ? (n.push(t.getX(o)), n.push(t.getX(o + 1)), n.push(t.getX(o + 2))) : (n.push(t.getX(o + 2)), n.push(t.getX(o + 1)), n.push(t.getX(o)));
673
- n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
674
- const i = r.clone();
675
- return i.setIndex(n), i.clearGroups(), i;
676
- } else
677
- return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), r;
678
- }
679
- const ye = /* @__PURE__ */ new WeakMap();
680
- class _s extends Je {
681
- /**
682
- * Constructs a new Draco loader.
683
- *
684
- * @param {LoadingManager} [manager] - The loading manager.
685
- */
686
- constructor(e) {
687
- super(e), this.decoderPath = "", this.decoderConfig = {}, this.decoderBinary = null, this.decoderPending = null, this.workerLimit = 4, this.workerPool = [], this.workerNextTaskID = 1, this.workerSourceURL = "", this.defaultAttributeIDs = {
688
- position: "POSITION",
689
- normal: "NORMAL",
690
- color: "COLOR",
691
- uv: "TEX_COORD"
692
- }, this.defaultAttributeTypes = {
693
- position: "Float32Array",
694
- normal: "Float32Array",
695
- color: "Float32Array",
696
- uv: "Float32Array"
697
- };
698
- }
699
- /**
700
- * Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
701
- *
702
- * @param {string} path - The decoder path.
703
- * @return {DRACOLoader} A reference to this loader.
704
- */
705
- setDecoderPath(e) {
706
- return this.decoderPath = e, this;
707
- }
708
- /**
709
- * Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
710
- *
711
- * @param {{type:('js'|'wasm')}} config - The decoder config.
712
- * @return {DRACOLoader} A reference to this loader.
713
- */
714
- setDecoderConfig(e) {
715
- return this.decoderConfig = e, this;
716
- }
717
- /**
718
- * Sets the maximum number of Web Workers to be used during decoding.
719
- * A lower limit may be preferable if workers are also for other tasks in the application.
720
- *
721
- * @param {number} workerLimit - The worker limit.
722
- * @return {DRACOLoader} A reference to this loader.
723
- */
724
- setWorkerLimit(e) {
725
- return this.workerLimit = e, this;
726
- }
727
- /**
728
- * Starts loading from the given URL and passes the loaded Draco asset
729
- * to the `onLoad()` callback.
730
- *
731
- * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
732
- * @param {function(BufferGeometry)} onLoad - Executed when the loading process has been finished.
733
- * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
734
- * @param {onErrorCallback} onError - Executed when errors occur.
735
- */
736
- load(e, t, s, n) {
737
- const i = new ce(this.manager);
738
- i.setPath(this.path), i.setResponseType("arraybuffer"), i.setRequestHeader(this.requestHeader), i.setWithCredentials(this.withCredentials), i.load(e, (o) => {
739
- this.parse(o, t, n);
740
- }, s, n);
741
- }
742
- /**
743
- * Parses the given Draco data.
744
- *
745
- * @param {ArrayBuffer} buffer - The raw Draco data as an array buffer.
746
- * @param {function(BufferGeometry)} onLoad - Executed when the loading/parsing process has been finished.
747
- * @param {onErrorCallback} onError - Executed when errors occur.
748
- */
749
- parse(e, t, s = () => {
750
- }) {
751
- this.decodeDracoFile(e, t, null, null, K, s).catch(s);
752
- }
753
- //
754
- decodeDracoFile(e, t, s, n, i = N, o = () => {
755
- }) {
756
- const c = {
757
- attributeIDs: s || this.defaultAttributeIDs,
758
- attributeTypes: n || this.defaultAttributeTypes,
759
- useUniqueIDs: !!s,
760
- vertexColorSpace: i
761
- };
762
- return this.decodeGeometry(e, c).then(t).catch(o);
763
- }
764
- decodeGeometry(e, t) {
765
- const s = JSON.stringify(t);
766
- if (ye.has(e)) {
767
- const a = ye.get(e);
768
- if (a.key === s)
769
- return a.promise;
770
- if (e.byteLength === 0)
771
- throw new Error(
772
- "THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred."
773
- );
774
- }
775
- let n;
776
- const i = this.workerNextTaskID++, o = e.byteLength, c = this._getWorker(i, o).then((a) => (n = a, new Promise((l, u) => {
777
- n._callbacks[i] = { resolve: l, reject: u }, n.postMessage({ type: "decode", id: i, taskConfig: t, buffer: e }, [e]);
778
- }))).then((a) => this._createGeometry(a.geometry));
779
- return c.catch(() => !0).then(() => {
780
- n && i && this._releaseTask(n, i);
781
- }), ye.set(e, {
782
- key: s,
783
- promise: c
784
- }), c;
785
- }
786
- _createGeometry(e) {
787
- const t = new et();
788
- e.index && t.setIndex(new se(e.index.array, 1));
789
- for (let s = 0; s < e.attributes.length; s++) {
790
- const n = e.attributes[s], i = n.name, o = n.array, c = n.itemSize, a = new se(o, c);
791
- i === "color" && (this._assignVertexColorSpace(a, n.vertexColorSpace), a.normalized = !(o instanceof Float32Array)), t.setAttribute(i, a);
792
- }
793
- return t;
794
- }
795
- _assignVertexColorSpace(e, t) {
796
- if (t !== K) return;
797
- const s = new W();
798
- for (let n = 0, i = e.count; n < i; n++)
799
- s.fromBufferAttribute(e, n), Re.colorSpaceToWorking(s, K), e.setXYZ(n, s.r, s.g, s.b);
800
- }
801
- _loadLibrary(e, t) {
802
- const s = new ce(this.manager);
803
- return s.setPath(this.decoderPath), s.setResponseType(t), s.setWithCredentials(this.withCredentials), new Promise((n, i) => {
804
- s.load(e, n, void 0, i);
805
- });
806
- }
807
- preload() {
808
- return this._initDecoder(), this;
809
- }
810
- _initDecoder() {
811
- if (this.decoderPending) return this.decoderPending;
812
- const e = typeof WebAssembly != "object" || this.decoderConfig.type === "js", t = [];
813
- return e ? t.push(this._loadLibrary("draco_decoder.js", "text")) : (t.push(this._loadLibrary("draco_wasm_wrapper.js", "text")), t.push(this._loadLibrary("draco_decoder.wasm", "arraybuffer"))), this.decoderPending = Promise.all(t).then((s) => {
814
- const n = s[0];
815
- e || (this.decoderConfig.wasmBinary = s[1]);
816
- const i = Ts.toString(), o = [
817
- "/* draco decoder */",
818
- n,
819
- "",
820
- "/* worker */",
821
- i.substring(i.indexOf("{") + 1, i.lastIndexOf("}"))
822
- ].join(`
823
- `);
824
- this.workerSourceURL = URL.createObjectURL(new Blob([o]));
825
- }), this.decoderPending;
826
- }
827
- _getWorker(e, t) {
828
- return this._initDecoder().then(() => {
829
- if (this.workerPool.length < this.workerLimit) {
830
- const n = new Worker(this.workerSourceURL);
831
- n._callbacks = {}, n._taskCosts = {}, n._taskLoad = 0, n.postMessage({ type: "init", decoderConfig: this.decoderConfig }), n.onmessage = function(i) {
832
- const o = i.data;
833
- switch (o.type) {
834
- case "decode":
835
- n._callbacks[o.id].resolve(o);
836
- break;
837
- case "error":
838
- n._callbacks[o.id].reject(o);
839
- break;
840
- default:
841
- console.error('THREE.DRACOLoader: Unexpected message, "' + o.type + '"');
842
- }
843
- }, this.workerPool.push(n);
844
- } else
845
- this.workerPool.sort(function(n, i) {
846
- return n._taskLoad > i._taskLoad ? -1 : 1;
847
- });
848
- const s = this.workerPool[this.workerPool.length - 1];
849
- return s._taskCosts[e] = t, s._taskLoad += t, s;
850
- });
851
- }
852
- _releaseTask(e, t) {
853
- e._taskLoad -= e._taskCosts[t], delete e._callbacks[t], delete e._taskCosts[t];
854
- }
855
- debug() {
856
- console.log("Task load: ", this.workerPool.map((e) => e._taskLoad));
857
- }
858
- dispose() {
859
- for (let e = 0; e < this.workerPool.length; ++e)
860
- this.workerPool[e].terminate();
861
- return this.workerPool.length = 0, this.workerSourceURL !== "" && URL.revokeObjectURL(this.workerSourceURL), this;
862
- }
863
- }
864
- function Ts() {
865
- let r, e;
866
- onmessage = function(o) {
867
- const c = o.data;
868
- switch (c.type) {
869
- case "init":
870
- r = c.decoderConfig, e = new Promise(function(u) {
871
- r.onModuleLoaded = function(h) {
872
- u({ draco: h });
873
- }, DracoDecoderModule(r);
874
- });
875
- break;
876
- case "decode":
877
- const a = c.buffer, l = c.taskConfig;
878
- e.then((u) => {
879
- const h = u.draco, m = new h.Decoder();
880
- try {
881
- const f = t(h, m, new Int8Array(a), l), g = f.attributes.map((y) => y.array.buffer);
882
- f.index && g.push(f.index.array.buffer), self.postMessage({ type: "decode", id: c.id, geometry: f }, g);
883
- } catch (f) {
884
- console.error(f), self.postMessage({ type: "error", id: c.id, error: f.message });
885
- } finally {
886
- h.destroy(m);
887
- }
888
- });
889
- break;
890
- }
891
- };
892
- function t(o, c, a, l) {
893
- const u = l.attributeIDs, h = l.attributeTypes;
894
- let m, f;
895
- const g = c.GetEncodedGeometryType(a);
896
- if (g === o.TRIANGULAR_MESH)
897
- m = new o.Mesh(), f = c.DecodeArrayToMesh(a, a.byteLength, m);
898
- else if (g === o.POINT_CLOUD)
899
- m = new o.PointCloud(), f = c.DecodeArrayToPointCloud(a, a.byteLength, m);
900
- else
901
- throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
902
- if (!f.ok() || m.ptr === 0)
903
- throw new Error("THREE.DRACOLoader: Decoding failed: " + f.error_msg());
904
- const y = { index: null, attributes: [] };
905
- for (const p in u) {
906
- const d = self[h[p]];
907
- let _, w;
908
- if (l.useUniqueIDs)
909
- w = u[p], _ = c.GetAttributeByUniqueId(m, w);
910
- else {
911
- if (w = c.GetAttributeId(m, o[u[p]]), w === -1) continue;
912
- _ = c.GetAttribute(m, w);
913
- }
914
- const T = n(o, c, m, p, d, _);
915
- p === "color" && (T.vertexColorSpace = l.vertexColorSpace), y.attributes.push(T);
916
- }
917
- return g === o.TRIANGULAR_MESH && (y.index = s(o, c, m)), o.destroy(m), y;
918
- }
919
- function s(o, c, a) {
920
- const u = a.num_faces() * 3, h = u * 4, m = o._malloc(h);
921
- c.GetTrianglesUInt32Array(a, h, m);
922
- const f = new Uint32Array(o.HEAPF32.buffer, m, u).slice();
923
- return o._free(m), { array: f, itemSize: 1 };
924
- }
925
- function n(o, c, a, l, u, h) {
926
- const m = h.num_components(), g = a.num_points() * m, y = g * u.BYTES_PER_ELEMENT, p = i(o, u), d = o._malloc(y);
927
- c.GetAttributeDataArrayForAllPoints(a, h, p, y, d);
928
- const _ = new u(o.HEAPF32.buffer, d, g).slice();
929
- return o._free(d), {
930
- name: l,
931
- array: _,
932
- itemSize: m
933
- };
934
- }
935
- function i(o, c) {
936
- switch (c) {
937
- case Float32Array:
938
- return o.DT_FLOAT32;
939
- case Int8Array:
940
- return o.DT_INT8;
941
- case Int16Array:
942
- return o.DT_INT16;
943
- case Int32Array:
944
- return o.DT_INT32;
945
- case Uint8Array:
946
- return o.DT_UINT8;
947
- case Uint16Array:
948
- return o.DT_UINT16;
949
- case Uint32Array:
950
- return o.DT_UINT32;
951
- }
952
- }
953
- }
954
- class ws extends Je {
955
- /**
956
- * Constructs a new glTF loader.
957
- *
958
- * @param {LoadingManager} [manager] - The loading manager.
959
- */
960
- constructor(e) {
961
- super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) {
962
- return new Rs(t);
963
- }), this.register(function(t) {
964
- return new Ss(t);
965
- }), this.register(function(t) {
966
- return new Ns(t);
967
- }), this.register(function(t) {
968
- return new vs(t);
969
- }), this.register(function(t) {
970
- return new Hs(t);
971
- }), this.register(function(t) {
972
- return new Ls(t);
973
- }), this.register(function(t) {
974
- return new Ps(t);
975
- }), this.register(function(t) {
976
- return new Ds(t);
977
- }), this.register(function(t) {
978
- return new Os(t);
979
- }), this.register(function(t) {
980
- return new As(t);
981
- }), this.register(function(t) {
982
- return new Cs(t);
983
- }), this.register(function(t) {
984
- return new Ms(t);
985
- }), this.register(function(t) {
986
- return new ks(t);
987
- }), this.register(function(t) {
988
- return new Is(t);
989
- }), this.register(function(t) {
990
- return new Es(t);
991
- }), this.register(function(t) {
992
- return new Fs(t);
993
- }), this.register(function(t) {
994
- return new Us(t);
995
- });
996
- }
997
- /**
998
- * Starts loading from the given URL and passes the loaded glTF asset
999
- * to the `onLoad()` callback.
1000
- *
1001
- * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
1002
- * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
1003
- * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
1004
- * @param {onErrorCallback} onError - Executed when errors occur.
1005
- */
1006
- load(e, t, s, n) {
1007
- const i = this;
1008
- let o;
1009
- if (this.resourcePath !== "")
1010
- o = this.resourcePath;
1011
- else if (this.path !== "") {
1012
- const l = ne.extractUrlBase(e);
1013
- o = ne.resolveURL(l, this.path);
1014
- } else
1015
- o = ne.extractUrlBase(e);
1016
- this.manager.itemStart(e);
1017
- const c = function(l) {
1018
- n ? n(l) : console.error(l), i.manager.itemError(e), i.manager.itemEnd(e);
1019
- }, a = new ce(this.manager);
1020
- a.setPath(this.path), a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setWithCredentials(this.withCredentials), a.load(e, function(l) {
1021
- try {
1022
- i.parse(l, o, function(u) {
1023
- t(u), i.manager.itemEnd(e);
1024
- }, c);
1025
- } catch (u) {
1026
- c(u);
1027
- }
1028
- }, s, c);
1029
- }
1030
- /**
1031
- * Sets the given Draco loader to this loader. Required for decoding assets
1032
- * compressed with the `KHR_draco_mesh_compression` extension.
1033
- *
1034
- * @param {DRACOLoader} dracoLoader - The Draco loader to set.
1035
- * @return {GLTFLoader} A reference to this loader.
1036
- */
1037
- setDRACOLoader(e) {
1038
- return this.dracoLoader = e, this;
1039
- }
1040
- /**
1041
- * Sets the given KTX2 loader to this loader. Required for loading KTX2
1042
- * compressed textures.
1043
- *
1044
- * @param {KTX2Loader} ktx2Loader - The KTX2 loader to set.
1045
- * @return {GLTFLoader} A reference to this loader.
1046
- */
1047
- setKTX2Loader(e) {
1048
- return this.ktx2Loader = e, this;
1049
- }
1050
- /**
1051
- * Sets the given meshopt decoder. Required for decoding assets
1052
- * compressed with the `EXT_meshopt_compression` extension.
1053
- *
1054
- * @param {Object} meshoptDecoder - The meshopt decoder to set.
1055
- * @return {GLTFLoader} A reference to this loader.
1056
- */
1057
- setMeshoptDecoder(e) {
1058
- return this.meshoptDecoder = e, this;
1059
- }
1060
- /**
1061
- * Registers a plugin callback. This API is internally used to implement the various
1062
- * glTF extensions but can also used by third-party code to add additional logic
1063
- * to the loader.
1064
- *
1065
- * @param {function(parser:GLTFParser)} callback - The callback function to register.
1066
- * @return {GLTFLoader} A reference to this loader.
1067
- */
1068
- register(e) {
1069
- return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this;
1070
- }
1071
- /**
1072
- * Unregisters a plugin callback.
1073
- *
1074
- * @param {Function} callback - The callback function to unregister.
1075
- * @return {GLTFLoader} A reference to this loader.
1076
- */
1077
- unregister(e) {
1078
- return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this;
1079
- }
1080
- /**
1081
- * Parses the given FBX data and returns the resulting group.
1082
- *
1083
- * @param {string|ArrayBuffer} data - The raw glTF data.
1084
- * @param {string} path - The URL base path.
1085
- * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
1086
- * @param {onErrorCallback} onError - Executed when errors occur.
1087
- */
1088
- parse(e, t, s, n) {
1089
- let i;
1090
- const o = {}, c = {}, a = new TextDecoder();
1091
- if (typeof e == "string")
1092
- i = JSON.parse(e);
1093
- else if (e instanceof ArrayBuffer)
1094
- if (a.decode(new Uint8Array(e, 0, 4)) === at) {
1095
- try {
1096
- o[b.KHR_BINARY_GLTF] = new js(e);
1097
- } catch (h) {
1098
- n && n(h);
1099
- return;
1100
- }
1101
- i = JSON.parse(o[b.KHR_BINARY_GLTF].content);
1102
- } else
1103
- i = JSON.parse(a.decode(e));
1104
- else
1105
- i = e;
1106
- if (i.asset === void 0 || i.asset.version[0] < 2) {
1107
- n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
1108
- return;
1109
- }
1110
- const l = new Js(i, {
1111
- path: t || this.resourcePath || "",
1112
- crossOrigin: this.crossOrigin,
1113
- requestHeader: this.requestHeader,
1114
- manager: this.manager,
1115
- ktx2Loader: this.ktx2Loader,
1116
- meshoptDecoder: this.meshoptDecoder
1117
- });
1118
- l.fileLoader.setRequestHeader(this.requestHeader);
1119
- for (let u = 0; u < this.pluginCallbacks.length; u++) {
1120
- const h = this.pluginCallbacks[u](l);
1121
- h.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), c[h.name] = h, o[h.name] = !0;
1122
- }
1123
- if (i.extensionsUsed)
1124
- for (let u = 0; u < i.extensionsUsed.length; ++u) {
1125
- const h = i.extensionsUsed[u], m = i.extensionsRequired || [];
1126
- switch (h) {
1127
- case b.KHR_MATERIALS_UNLIT:
1128
- o[h] = new xs();
1129
- break;
1130
- case b.KHR_DRACO_MESH_COMPRESSION:
1131
- o[h] = new Gs(i, this.dracoLoader);
1132
- break;
1133
- case b.KHR_TEXTURE_TRANSFORM:
1134
- o[h] = new Bs();
1135
- break;
1136
- case b.KHR_MESH_QUANTIZATION:
1137
- o[h] = new zs();
1138
- break;
1139
- default:
1140
- m.indexOf(h) >= 0 && c[h] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + h + '".');
1141
- }
1142
- }
1143
- l.setExtensions(o), l.setPlugins(c), l.parse(s, n);
1144
- }
1145
- /**
1146
- * Async version of {@link GLTFLoader#parse}.
1147
- *
1148
- * @async
1149
- * @param {string|ArrayBuffer} data - The raw glTF data.
1150
- * @param {string} path - The URL base path.
1151
- * @return {Promise<GLTFLoader~LoadObject>} A Promise that resolves with the loaded glTF when the parsing has been finished.
1152
- */
1153
- parseAsync(e, t) {
1154
- const s = this;
1155
- return new Promise(function(n, i) {
1156
- s.parse(e, t, n, i);
1157
- });
1158
- }
1159
- }
1160
- function bs() {
1161
- let r = {};
1162
- return {
1163
- get: function(e) {
1164
- return r[e];
1165
- },
1166
- add: function(e, t) {
1167
- r[e] = t;
1168
- },
1169
- remove: function(e) {
1170
- delete r[e];
1171
- },
1172
- removeAll: function() {
1173
- r = {};
1174
- }
1175
- };
1176
- }
1177
- const b = {
1178
- KHR_BINARY_GLTF: "KHR_binary_glTF",
1179
- KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
1180
- KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
1181
- KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
1182
- KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion",
1183
- KHR_MATERIALS_IOR: "KHR_materials_ior",
1184
- KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
1185
- KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
1186
- KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
1187
- KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
1188
- KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
1189
- KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
1190
- KHR_MATERIALS_VOLUME: "KHR_materials_volume",
1191
- KHR_TEXTURE_BASISU: "KHR_texture_basisu",
1192
- KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
1193
- KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
1194
- KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
1195
- EXT_MATERIALS_BUMP: "EXT_materials_bump",
1196
- EXT_TEXTURE_WEBP: "EXT_texture_webp",
1197
- EXT_TEXTURE_AVIF: "EXT_texture_avif",
1198
- EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
1199
- EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
1200
- };
1201
- class Es {
1202
- constructor(e) {
1203
- this.parser = e, this.name = b.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
1204
- }
1205
- _markDefs() {
1206
- const e = this.parser, t = this.parser.json.nodes || [];
1207
- for (let s = 0, n = t.length; s < n; s++) {
1208
- const i = t[s];
1209
- i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && e._addNodeRef(this.cache, i.extensions[this.name].light);
1210
- }
1211
- }
1212
- _loadLight(e) {
1213
- const t = this.parser, s = "light:" + e;
1214
- let n = t.cache.get(s);
1215
- if (n) return n;
1216
- const i = t.json, a = ((i.extensions && i.extensions[this.name] || {}).lights || [])[e];
1217
- let l;
1218
- const u = new W(16777215);
1219
- a.color !== void 0 && u.setRGB(a.color[0], a.color[1], a.color[2], N);
1220
- const h = a.range !== void 0 ? a.range : 0;
1221
- switch (a.type) {
1222
- case "directional":
1223
- l = new Et(u), l.target.position.set(0, 0, -1), l.add(l.target);
1224
- break;
1225
- case "point":
1226
- l = new bt(u), l.distance = h;
1227
- break;
1228
- case "spot":
1229
- l = new wt(u), l.distance = h, a.spot = a.spot || {}, a.spot.innerConeAngle = a.spot.innerConeAngle !== void 0 ? a.spot.innerConeAngle : 0, a.spot.outerConeAngle = a.spot.outerConeAngle !== void 0 ? a.spot.outerConeAngle : Math.PI / 4, l.angle = a.spot.outerConeAngle, l.penumbra = 1 - a.spot.innerConeAngle / a.spot.outerConeAngle, l.target.position.set(0, 0, -1), l.add(l.target);
1230
- break;
1231
- default:
1232
- throw new Error("THREE.GLTFLoader: Unexpected light type: " + a.type);
1233
- }
1234
- return l.position.set(0, 0, 0), F(l, a), a.intensity !== void 0 && (l.intensity = a.intensity), l.name = t.createUniqueName(a.name || "light_" + e), n = Promise.resolve(l), t.cache.add(s, n), n;
1235
- }
1236
- getDependency(e, t) {
1237
- if (e === "light")
1238
- return this._loadLight(t);
1239
- }
1240
- createNodeAttachment(e) {
1241
- const t = this, s = this.parser, i = s.json.nodes[e], c = (i.extensions && i.extensions[this.name] || {}).light;
1242
- return c === void 0 ? null : this._loadLight(c).then(function(a) {
1243
- return s._getNodeRef(t.cache, c, a);
1244
- });
1245
- }
1246
- }
1247
- class xs {
1248
- constructor() {
1249
- this.name = b.KHR_MATERIALS_UNLIT;
1250
- }
1251
- getMaterialType() {
1252
- return te;
1253
- }
1254
- extendParams(e, t, s) {
1255
- const n = [];
1256
- e.color = new W(1, 1, 1), e.opacity = 1;
1257
- const i = t.pbrMetallicRoughness;
1258
- if (i) {
1259
- if (Array.isArray(i.baseColorFactor)) {
1260
- const o = i.baseColorFactor;
1261
- e.color.setRGB(o[0], o[1], o[2], N), e.opacity = o[3];
1262
- }
1263
- i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, K));
1264
- }
1265
- return Promise.all(n);
1266
- }
1267
- }
1268
- class As {
1269
- constructor(e) {
1270
- this.parser = e, this.name = b.KHR_MATERIALS_EMISSIVE_STRENGTH;
1271
- }
1272
- extendMaterialParams(e, t) {
1273
- const n = this.parser.json.materials[e];
1274
- if (!n.extensions || !n.extensions[this.name])
1275
- return Promise.resolve();
1276
- const i = n.extensions[this.name].emissiveStrength;
1277
- return i !== void 0 && (t.emissiveIntensity = i), Promise.resolve();
1278
- }
1279
- }
1280
- class Rs {
1281
- constructor(e) {
1282
- this.parser = e, this.name = b.KHR_MATERIALS_CLEARCOAT;
1283
- }
1284
- getMaterialType(e) {
1285
- const s = this.parser.json.materials[e];
1286
- return !s.extensions || !s.extensions[this.name] ? null : v;
1287
- }
1288
- extendMaterialParams(e, t) {
1289
- const s = this.parser, n = s.json.materials[e];
1290
- if (!n.extensions || !n.extensions[this.name])
1291
- return Promise.resolve();
1292
- const i = [], o = n.extensions[this.name];
1293
- if (o.clearcoatFactor !== void 0 && (t.clearcoat = o.clearcoatFactor), o.clearcoatTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatMap", o.clearcoatTexture)), o.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = o.clearcoatRoughnessFactor), o.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatRoughnessMap", o.clearcoatRoughnessTexture)), o.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(t, "clearcoatNormalMap", o.clearcoatNormalTexture)), o.clearcoatNormalTexture.scale !== void 0)) {
1294
- const c = o.clearcoatNormalTexture.scale;
1295
- t.clearcoatNormalScale = new C(c, c);
1296
- }
1297
- return Promise.all(i);
1298
- }
1299
- }
1300
- class Ss {
1301
- constructor(e) {
1302
- this.parser = e, this.name = b.KHR_MATERIALS_DISPERSION;
1303
- }
1304
- getMaterialType(e) {
1305
- const s = this.parser.json.materials[e];
1306
- return !s.extensions || !s.extensions[this.name] ? null : v;
1307
- }
1308
- extendMaterialParams(e, t) {
1309
- const n = this.parser.json.materials[e];
1310
- if (!n.extensions || !n.extensions[this.name])
1311
- return Promise.resolve();
1312
- const i = n.extensions[this.name];
1313
- return t.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve();
1314
- }
1315
- }
1316
- class Ms {
1317
- constructor(e) {
1318
- this.parser = e, this.name = b.KHR_MATERIALS_IRIDESCENCE;
1319
- }
1320
- getMaterialType(e) {
1321
- const s = this.parser.json.materials[e];
1322
- return !s.extensions || !s.extensions[this.name] ? null : v;
1323
- }
1324
- extendMaterialParams(e, t) {
1325
- const s = this.parser, n = s.json.materials[e];
1326
- if (!n.extensions || !n.extensions[this.name])
1327
- return Promise.resolve();
1328
- const i = [], o = n.extensions[this.name];
1329
- return o.iridescenceFactor !== void 0 && (t.iridescence = o.iridescenceFactor), o.iridescenceTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceMap", o.iridescenceTexture)), o.iridescenceIor !== void 0 && (t.iridescenceIOR = o.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), o.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = o.iridescenceThicknessMinimum), o.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = o.iridescenceThicknessMaximum), o.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceThicknessMap", o.iridescenceThicknessTexture)), Promise.all(i);
1330
- }
1331
- }
1332
- class Ls {
1333
- constructor(e) {
1334
- this.parser = e, this.name = b.KHR_MATERIALS_SHEEN;
1335
- }
1336
- getMaterialType(e) {
1337
- const s = this.parser.json.materials[e];
1338
- return !s.extensions || !s.extensions[this.name] ? null : v;
1339
- }
1340
- extendMaterialParams(e, t) {
1341
- const s = this.parser, n = s.json.materials[e];
1342
- if (!n.extensions || !n.extensions[this.name])
1343
- return Promise.resolve();
1344
- const i = [];
1345
- t.sheenColor = new W(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1;
1346
- const o = n.extensions[this.name];
1347
- if (o.sheenColorFactor !== void 0) {
1348
- const c = o.sheenColorFactor;
1349
- t.sheenColor.setRGB(c[0], c[1], c[2], N);
1350
- }
1351
- return o.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = o.sheenRoughnessFactor), o.sheenColorTexture !== void 0 && i.push(s.assignTexture(t, "sheenColorMap", o.sheenColorTexture, K)), o.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "sheenRoughnessMap", o.sheenRoughnessTexture)), Promise.all(i);
1352
- }
1353
- }
1354
- class Ps {
1355
- constructor(e) {
1356
- this.parser = e, this.name = b.KHR_MATERIALS_TRANSMISSION;
1357
- }
1358
- getMaterialType(e) {
1359
- const s = this.parser.json.materials[e];
1360
- return !s.extensions || !s.extensions[this.name] ? null : v;
1361
- }
1362
- extendMaterialParams(e, t) {
1363
- const s = this.parser, n = s.json.materials[e];
1364
- if (!n.extensions || !n.extensions[this.name])
1365
- return Promise.resolve();
1366
- const i = [], o = n.extensions[this.name];
1367
- return o.transmissionFactor !== void 0 && (t.transmission = o.transmissionFactor), o.transmissionTexture !== void 0 && i.push(s.assignTexture(t, "transmissionMap", o.transmissionTexture)), Promise.all(i);
1368
- }
1369
- }
1370
- class Ds {
1371
- constructor(e) {
1372
- this.parser = e, this.name = b.KHR_MATERIALS_VOLUME;
1373
- }
1374
- getMaterialType(e) {
1375
- const s = this.parser.json.materials[e];
1376
- return !s.extensions || !s.extensions[this.name] ? null : v;
1377
- }
1378
- extendMaterialParams(e, t) {
1379
- const s = this.parser, n = s.json.materials[e];
1380
- if (!n.extensions || !n.extensions[this.name])
1381
- return Promise.resolve();
1382
- const i = [], o = n.extensions[this.name];
1383
- t.thickness = o.thicknessFactor !== void 0 ? o.thicknessFactor : 0, o.thicknessTexture !== void 0 && i.push(s.assignTexture(t, "thicknessMap", o.thicknessTexture)), t.attenuationDistance = o.attenuationDistance || 1 / 0;
1384
- const c = o.attenuationColor || [1, 1, 1];
1385
- return t.attenuationColor = new W().setRGB(c[0], c[1], c[2], N), Promise.all(i);
1386
- }
1387
- }
1388
- class Os {
1389
- constructor(e) {
1390
- this.parser = e, this.name = b.KHR_MATERIALS_IOR;
1391
- }
1392
- getMaterialType(e) {
1393
- const s = this.parser.json.materials[e];
1394
- return !s.extensions || !s.extensions[this.name] ? null : v;
1395
- }
1396
- extendMaterialParams(e, t) {
1397
- const n = this.parser.json.materials[e];
1398
- if (!n.extensions || !n.extensions[this.name])
1399
- return Promise.resolve();
1400
- const i = n.extensions[this.name];
1401
- return t.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
1402
- }
1403
- }
1404
- class Cs {
1405
- constructor(e) {
1406
- this.parser = e, this.name = b.KHR_MATERIALS_SPECULAR;
1407
- }
1408
- getMaterialType(e) {
1409
- const s = this.parser.json.materials[e];
1410
- return !s.extensions || !s.extensions[this.name] ? null : v;
1411
- }
1412
- extendMaterialParams(e, t) {
1413
- const s = this.parser, n = s.json.materials[e];
1414
- if (!n.extensions || !n.extensions[this.name])
1415
- return Promise.resolve();
1416
- const i = [], o = n.extensions[this.name];
1417
- t.specularIntensity = o.specularFactor !== void 0 ? o.specularFactor : 1, o.specularTexture !== void 0 && i.push(s.assignTexture(t, "specularIntensityMap", o.specularTexture));
1418
- const c = o.specularColorFactor || [1, 1, 1];
1419
- return t.specularColor = new W().setRGB(c[0], c[1], c[2], N), o.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, K)), Promise.all(i);
1420
- }
1421
- }
1422
- class Is {
1423
- constructor(e) {
1424
- this.parser = e, this.name = b.EXT_MATERIALS_BUMP;
1425
- }
1426
- getMaterialType(e) {
1427
- const s = this.parser.json.materials[e];
1428
- return !s.extensions || !s.extensions[this.name] ? null : v;
1429
- }
1430
- extendMaterialParams(e, t) {
1431
- const s = this.parser, n = s.json.materials[e];
1432
- if (!n.extensions || !n.extensions[this.name])
1433
- return Promise.resolve();
1434
- const i = [], o = n.extensions[this.name];
1435
- return t.bumpScale = o.bumpFactor !== void 0 ? o.bumpFactor : 1, o.bumpTexture !== void 0 && i.push(s.assignTexture(t, "bumpMap", o.bumpTexture)), Promise.all(i);
1436
- }
1437
- }
1438
- class ks {
1439
- constructor(e) {
1440
- this.parser = e, this.name = b.KHR_MATERIALS_ANISOTROPY;
1441
- }
1442
- getMaterialType(e) {
1443
- const s = this.parser.json.materials[e];
1444
- return !s.extensions || !s.extensions[this.name] ? null : v;
1445
- }
1446
- extendMaterialParams(e, t) {
1447
- const s = this.parser, n = s.json.materials[e];
1448
- if (!n.extensions || !n.extensions[this.name])
1449
- return Promise.resolve();
1450
- const i = [], o = n.extensions[this.name];
1451
- return o.anisotropyStrength !== void 0 && (t.anisotropy = o.anisotropyStrength), o.anisotropyRotation !== void 0 && (t.anisotropyRotation = o.anisotropyRotation), o.anisotropyTexture !== void 0 && i.push(s.assignTexture(t, "anisotropyMap", o.anisotropyTexture)), Promise.all(i);
1452
- }
1453
- }
1454
- class Ns {
1455
- constructor(e) {
1456
- this.parser = e, this.name = b.KHR_TEXTURE_BASISU;
1457
- }
1458
- loadTexture(e) {
1459
- const t = this.parser, s = t.json, n = s.textures[e];
1460
- if (!n.extensions || !n.extensions[this.name])
1461
- return null;
1462
- const i = n.extensions[this.name], o = t.options.ktx2Loader;
1463
- if (!o) {
1464
- if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0)
1465
- throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
1466
- return null;
1467
- }
1468
- return t.loadTextureImage(e, i.source, o);
1469
- }
1470
- }
1471
- class vs {
1472
- constructor(e) {
1473
- this.parser = e, this.name = b.EXT_TEXTURE_WEBP;
1474
- }
1475
- loadTexture(e) {
1476
- const t = this.name, s = this.parser, n = s.json, i = n.textures[e];
1477
- if (!i.extensions || !i.extensions[t])
1478
- return null;
1479
- const o = i.extensions[t], c = n.images[o.source];
1480
- let a = s.textureLoader;
1481
- if (c.uri) {
1482
- const l = s.options.manager.getHandler(c.uri);
1483
- l !== null && (a = l);
1484
- }
1485
- return s.loadTextureImage(e, o.source, a);
1486
- }
1487
- }
1488
- class Hs {
1489
- constructor(e) {
1490
- this.parser = e, this.name = b.EXT_TEXTURE_AVIF;
1491
- }
1492
- loadTexture(e) {
1493
- const t = this.name, s = this.parser, n = s.json, i = n.textures[e];
1494
- if (!i.extensions || !i.extensions[t])
1495
- return null;
1496
- const o = i.extensions[t], c = n.images[o.source];
1497
- let a = s.textureLoader;
1498
- if (c.uri) {
1499
- const l = s.options.manager.getHandler(c.uri);
1500
- l !== null && (a = l);
1501
- }
1502
- return s.loadTextureImage(e, o.source, a);
1503
- }
1504
- }
1505
- class Fs {
1506
- constructor(e) {
1507
- this.name = b.EXT_MESHOPT_COMPRESSION, this.parser = e;
1508
- }
1509
- loadBufferView(e) {
1510
- const t = this.parser.json, s = t.bufferViews[e];
1511
- if (s.extensions && s.extensions[this.name]) {
1512
- const n = s.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), o = this.parser.options.meshoptDecoder;
1513
- if (!o || !o.supported) {
1514
- if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0)
1515
- throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
1516
- return null;
1517
- }
1518
- return i.then(function(c) {
1519
- const a = n.byteOffset || 0, l = n.byteLength || 0, u = n.count, h = n.byteStride, m = new Uint8Array(c, a, l);
1520
- return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(u, h, m, n.mode, n.filter).then(function(f) {
1521
- return f.buffer;
1522
- }) : o.ready.then(function() {
1523
- const f = new ArrayBuffer(u * h);
1524
- return o.decodeGltfBuffer(new Uint8Array(f), u, h, m, n.mode, n.filter), f;
1525
- });
1526
- });
1527
- } else
1528
- return null;
1529
- }
1530
- }
1531
- class Us {
1532
- constructor(e) {
1533
- this.name = b.EXT_MESH_GPU_INSTANCING, this.parser = e;
1534
- }
1535
- createNodeMesh(e) {
1536
- const t = this.parser.json, s = t.nodes[e];
1537
- if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0)
1538
- return null;
1539
- const n = t.meshes[s.mesh];
1540
- for (const l of n.primitives)
1541
- if (l.mode !== I.TRIANGLES && l.mode !== I.TRIANGLE_STRIP && l.mode !== I.TRIANGLE_FAN && l.mode !== void 0)
1542
- return null;
1543
- const o = s.extensions[this.name].attributes, c = [], a = {};
1544
- for (const l in o)
1545
- c.push(this.parser.getDependency("accessor", o[l]).then((u) => (a[l] = u, a[l])));
1546
- return c.length < 1 ? null : (c.push(this.parser.createNodeMesh(e)), Promise.all(c).then((l) => {
1547
- const u = l.pop(), h = u.isGroup ? u.children : [u], m = l[0].count, f = [];
1548
- for (const g of h) {
1549
- const y = new J(), p = new L(), d = new re(), _ = new L(1, 1, 1), w = new xt(g.geometry, g.material, m);
1550
- for (let T = 0; T < m; T++)
1551
- a.TRANSLATION && p.fromBufferAttribute(a.TRANSLATION, T), a.ROTATION && d.fromBufferAttribute(a.ROTATION, T), a.SCALE && _.fromBufferAttribute(a.SCALE, T), w.setMatrixAt(T, y.compose(p, d, _));
1552
- for (const T in a)
1553
- if (T === "_COLOR_0") {
1554
- const A = a[T];
1555
- w.instanceColor = new At(A.array, A.itemSize, A.normalized);
1556
- } else T !== "TRANSLATION" && T !== "ROTATION" && T !== "SCALE" && g.geometry.setAttribute(T, a[T]);
1557
- De.prototype.copy.call(w, g), this.parser.assignFinalMaterial(w), f.push(w);
1558
- }
1559
- return u.isGroup ? (u.clear(), u.add(...f), u) : f[0];
1560
- }));
1561
- }
1562
- }
1563
- const at = "glTF", ee = 12, ze = { JSON: 1313821514, BIN: 5130562 };
1564
- class js {
1565
- constructor(e) {
1566
- this.name = b.KHR_BINARY_GLTF, this.content = null, this.body = null;
1567
- const t = new DataView(e, 0, ee), s = new TextDecoder();
1568
- if (this.header = {
1569
- magic: s.decode(new Uint8Array(e.slice(0, 4))),
1570
- version: t.getUint32(4, !0),
1571
- length: t.getUint32(8, !0)
1572
- }, this.header.magic !== at)
1573
- throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
1574
- if (this.header.version < 2)
1575
- throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
1576
- const n = this.header.length - ee, i = new DataView(e, ee);
1577
- let o = 0;
1578
- for (; o < n; ) {
1579
- const c = i.getUint32(o, !0);
1580
- o += 4;
1581
- const a = i.getUint32(o, !0);
1582
- if (o += 4, a === ze.JSON) {
1583
- const l = new Uint8Array(e, ee + o, c);
1584
- this.content = s.decode(l);
1585
- } else if (a === ze.BIN) {
1586
- const l = ee + o;
1587
- this.body = e.slice(l, l + c);
1588
- }
1589
- o += c;
1590
- }
1591
- if (this.content === null)
1592
- throw new Error("THREE.GLTFLoader: JSON content not found.");
1593
- }
1594
- }
1595
- class Gs {
1596
- constructor(e, t) {
1597
- if (!t)
1598
- throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
1599
- this.name = b.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload();
1600
- }
1601
- decodePrimitive(e, t) {
1602
- const s = this.json, n = this.dracoLoader, i = e.extensions[this.name].bufferView, o = e.extensions[this.name].attributes, c = {}, a = {}, l = {};
1603
- for (const u in o) {
1604
- const h = Le[u] || u.toLowerCase();
1605
- c[h] = o[u];
1606
- }
1607
- for (const u in e.attributes) {
1608
- const h = Le[u] || u.toLowerCase();
1609
- if (o[u] !== void 0) {
1610
- const m = s.accessors[e.attributes[u]], f = Q[m.componentType];
1611
- l[h] = f.name, a[h] = m.normalized === !0;
1612
- }
1613
- }
1614
- return t.getDependency("bufferView", i).then(function(u) {
1615
- return new Promise(function(h, m) {
1616
- n.decodeDracoFile(u, function(f) {
1617
- for (const g in f.attributes) {
1618
- const y = f.attributes[g], p = a[g];
1619
- p !== void 0 && (y.normalized = p);
1620
- }
1621
- h(f);
1622
- }, c, l, N, m);
1623
- });
1624
- });
1625
- }
1626
- }
1627
- class Bs {
1628
- constructor() {
1629
- this.name = b.KHR_TEXTURE_TRANSFORM;
1630
- }
1631
- extendTexture(e, t) {
1632
- return (t.texCoord === void 0 || t.texCoord === e.channel) && t.offset === void 0 && t.rotation === void 0 && t.scale === void 0 || (e = e.clone(), t.texCoord !== void 0 && (e.channel = t.texCoord), t.offset !== void 0 && e.offset.fromArray(t.offset), t.rotation !== void 0 && (e.rotation = t.rotation), t.scale !== void 0 && e.repeat.fromArray(t.scale), e.needsUpdate = !0), e;
1633
- }
1634
- }
1635
- class zs {
1636
- constructor() {
1637
- this.name = b.KHR_MESH_QUANTIZATION;
1638
- }
1639
- }
1640
- class ct extends $t {
1641
- constructor(e, t, s, n) {
1642
- super(e, t, s, n);
1643
- }
1644
- copySampleValue_(e) {
1645
- const t = this.resultBuffer, s = this.sampleValues, n = this.valueSize, i = e * n * 3 + n;
1646
- for (let o = 0; o !== n; o++)
1647
- t[o] = s[i + o];
1648
- return t;
1649
- }
1650
- interpolate_(e, t, s, n) {
1651
- const i = this.resultBuffer, o = this.sampleValues, c = this.valueSize, a = c * 2, l = c * 3, u = n - t, h = (s - t) / u, m = h * h, f = m * h, g = e * l, y = g - l, p = -2 * f + 3 * m, d = f - m, _ = 1 - p, w = d - m + h;
1652
- for (let T = 0; T !== c; T++) {
1653
- const A = o[y + T + c], S = o[y + T + a] * u, M = o[g + T + c], R = o[g + T] * u;
1654
- i[T] = _ * A + w * S + p * M + d * R;
1655
- }
1656
- return i;
1657
- }
1658
- }
1659
- const Ks = new re();
1660
- class Ws extends ct {
1661
- interpolate_(e, t, s, n) {
1662
- const i = super.interpolate_(e, t, s, n);
1663
- return Ks.fromArray(i).normalize().toArray(i), i;
1664
- }
1665
- }
1666
- const I = {
1667
- POINTS: 0,
1668
- LINES: 1,
1669
- LINE_LOOP: 2,
1670
- LINE_STRIP: 3,
1671
- TRIANGLES: 4,
1672
- TRIANGLE_STRIP: 5,
1673
- TRIANGLE_FAN: 6
1674
- }, Q = {
1675
- 5120: Int8Array,
1676
- 5121: Uint8Array,
1677
- 5122: Int16Array,
1678
- 5123: Uint16Array,
1679
- 5125: Uint32Array,
1680
- 5126: Float32Array
1681
- }, Ke = {
1682
- 9728: st,
1683
- 9729: Se,
1684
- 9984: Ot,
1685
- 9985: Dt,
1686
- 9986: Pt,
1687
- 9987: tt
1688
- }, We = {
1689
- 33071: It,
1690
- 33648: Ct,
1691
- 10497: Me
1692
- }, _e = {
1693
- SCALAR: 1,
1694
- VEC2: 2,
1695
- VEC3: 3,
1696
- VEC4: 4,
1697
- MAT2: 4,
1698
- MAT3: 9,
1699
- MAT4: 16
1700
- }, Le = {
1701
- POSITION: "position",
1702
- NORMAL: "normal",
1703
- TANGENT: "tangent",
1704
- TEXCOORD_0: "uv",
1705
- TEXCOORD_1: "uv1",
1706
- TEXCOORD_2: "uv2",
1707
- TEXCOORD_3: "uv3",
1708
- COLOR_0: "color",
1709
- WEIGHTS_0: "skinWeight",
1710
- JOINTS_0: "skinIndex"
1711
- }, G = {
1712
- scale: "scale",
1713
- translation: "position",
1714
- rotation: "quaternion",
1715
- weights: "morphTargetInfluences"
1716
- }, Xs = {
1717
- CUBICSPLINE: void 0,
1718
- // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
1719
- // keyframe track will be initialized with a default interpolation type, then modified.
1720
- LINEAR: it,
1721
- STEP: qt
1722
- }, Te = {
1723
- OPAQUE: "OPAQUE",
1724
- MASK: "MASK",
1725
- BLEND: "BLEND"
1726
- };
1727
- function Vs(r) {
1728
- return r.DefaultMaterial === void 0 && (r.DefaultMaterial = new nt({
1729
- color: 16777215,
1730
- emissive: 0,
1731
- metalness: 1,
1732
- roughness: 1,
1733
- transparent: !1,
1734
- depthTest: !0,
1735
- side: Zt
1736
- })), r.DefaultMaterial;
1737
- }
1738
- function X(r, e, t) {
1739
- for (const s in t.extensions)
1740
- r[s] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[s] = t.extensions[s]);
1741
- }
1742
- function F(r, e) {
1743
- e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(r.userData, e.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + e.extras));
1744
- }
1745
- function Ys(r, e, t) {
1746
- let s = !1, n = !1, i = !1;
1747
- for (let l = 0, u = e.length; l < u; l++) {
1748
- const h = e[l];
1749
- if (h.POSITION !== void 0 && (s = !0), h.NORMAL !== void 0 && (n = !0), h.COLOR_0 !== void 0 && (i = !0), s && n && i) break;
1750
- }
1751
- if (!s && !n && !i) return Promise.resolve(r);
1752
- const o = [], c = [], a = [];
1753
- for (let l = 0, u = e.length; l < u; l++) {
1754
- const h = e[l];
1755
- if (s) {
1756
- const m = h.POSITION !== void 0 ? t.getDependency("accessor", h.POSITION) : r.attributes.position;
1757
- o.push(m);
1758
- }
1759
- if (n) {
1760
- const m = h.NORMAL !== void 0 ? t.getDependency("accessor", h.NORMAL) : r.attributes.normal;
1761
- c.push(m);
1762
- }
1763
- if (i) {
1764
- const m = h.COLOR_0 !== void 0 ? t.getDependency("accessor", h.COLOR_0) : r.attributes.color;
1765
- a.push(m);
1766
- }
1767
- }
1768
- return Promise.all([
1769
- Promise.all(o),
1770
- Promise.all(c),
1771
- Promise.all(a)
1772
- ]).then(function(l) {
1773
- const u = l[0], h = l[1], m = l[2];
1774
- return s && (r.morphAttributes.position = u), n && (r.morphAttributes.normal = h), i && (r.morphAttributes.color = m), r.morphTargetsRelative = !0, r;
1775
- });
1776
- }
1777
- function qs(r, e) {
1778
- if (r.updateMorphTargets(), e.weights !== void 0)
1779
- for (let t = 0, s = e.weights.length; t < s; t++)
1780
- r.morphTargetInfluences[t] = e.weights[t];
1781
- if (e.extras && Array.isArray(e.extras.targetNames)) {
1782
- const t = e.extras.targetNames;
1783
- if (r.morphTargetInfluences.length === t.length) {
1784
- r.morphTargetDictionary = {};
1785
- for (let s = 0, n = t.length; s < n; s++)
1786
- r.morphTargetDictionary[t[s]] = s;
1787
- } else
1788
- console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
1789
- }
1790
- }
1791
- function Zs(r) {
1792
- let e;
1793
- const t = r.extensions && r.extensions[b.KHR_DRACO_MESH_COMPRESSION];
1794
- if (t ? e = "draco:" + t.bufferView + ":" + t.indices + ":" + we(t.attributes) : e = r.indices + ":" + we(r.attributes) + ":" + r.mode, r.targets !== void 0)
1795
- for (let s = 0, n = r.targets.length; s < n; s++)
1796
- e += ":" + we(r.targets[s]);
1797
- return e;
1798
- }
1799
- function we(r) {
1800
- let e = "";
1801
- const t = Object.keys(r).sort();
1802
- for (let s = 0, n = t.length; s < n; s++)
1803
- e += t[s] + ":" + r[t[s]] + ";";
1804
- return e;
1805
- }
1806
- function Pe(r) {
1807
- switch (r) {
1808
- case Int8Array:
1809
- return 1 / 127;
1810
- case Uint8Array:
1811
- return 1 / 255;
1812
- case Int16Array:
1813
- return 1 / 32767;
1814
- case Uint16Array:
1815
- return 1 / 65535;
1816
- default:
1817
- throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
1818
- }
1819
- }
1820
- function $s(r) {
1821
- return r.search(/\.jpe?g($|\?)/i) > 0 || r.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : r.search(/\.webp($|\?)/i) > 0 || r.search(/^data\:image\/webp/) === 0 ? "image/webp" : r.search(/\.ktx2($|\?)/i) > 0 || r.search(/^data\:image\/ktx2/) === 0 ? "image/ktx2" : "image/png";
1822
- }
1823
- const Qs = new J();
1824
- class Js {
1825
- constructor(e = {}, t = {}) {
1826
- this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new bs(), this.associations = /* @__PURE__ */ new Map(), this.primitiveCache = {}, this.nodeCache = {}, this.meshCache = { refs: {}, uses: {} }, this.cameraCache = { refs: {}, uses: {} }, this.lightCache = { refs: {}, uses: {} }, this.sourceCache = {}, this.textureCache = {}, this.nodeNamesUsed = {};
1827
- let s = !1, n = -1, i = !1, o = -1;
1828
- if (typeof navigator < "u") {
1829
- const c = navigator.userAgent;
1830
- s = /^((?!chrome|android).)*safari/i.test(c) === !0;
1831
- const a = c.match(/Version\/(\d+)/);
1832
- n = s && a ? parseInt(a[1], 10) : -1, i = c.indexOf("Firefox") > -1, o = i ? c.match(/Firefox\/([0-9]+)\./)[1] : -1;
1833
- }
1834
- typeof createImageBitmap > "u" || s && n < 17 || i && o < 98 ? this.textureLoader = new Rt(this.options.manager) : this.textureLoader = new St(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new ce(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
1835
- }
1836
- setExtensions(e) {
1837
- this.extensions = e;
1838
- }
1839
- setPlugins(e) {
1840
- this.plugins = e;
1841
- }
1842
- parse(e, t) {
1843
- const s = this, n = this.json, i = this.extensions;
1844
- this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(o) {
1845
- return o._markDefs && o._markDefs();
1846
- }), Promise.all(this._invokeAll(function(o) {
1847
- return o.beforeRoot && o.beforeRoot();
1848
- })).then(function() {
1849
- return Promise.all([
1850
- s.getDependencies("scene"),
1851
- s.getDependencies("animation"),
1852
- s.getDependencies("camera")
1853
- ]);
1854
- }).then(function(o) {
1855
- const c = {
1856
- scene: o[0][n.scene || 0],
1857
- scenes: o[0],
1858
- animations: o[1],
1859
- cameras: o[2],
1860
- asset: n.asset,
1861
- parser: s,
1862
- userData: {}
1863
- };
1864
- return X(i, c, n), F(c, n), Promise.all(s._invokeAll(function(a) {
1865
- return a.afterRoot && a.afterRoot(c);
1866
- })).then(function() {
1867
- for (const a of c.scenes)
1868
- a.updateMatrixWorld();
1869
- e(c);
1870
- });
1871
- }).catch(t);
1872
- }
1873
- /**
1874
- * Marks the special nodes/meshes in json for efficient parse.
1875
- *
1876
- * @private
1877
- */
1878
- _markDefs() {
1879
- const e = this.json.nodes || [], t = this.json.skins || [], s = this.json.meshes || [];
1880
- for (let n = 0, i = t.length; n < i; n++) {
1881
- const o = t[n].joints;
1882
- for (let c = 0, a = o.length; c < a; c++)
1883
- e[o[c]].isBone = !0;
1884
- }
1885
- for (let n = 0, i = e.length; n < i; n++) {
1886
- const o = e[n];
1887
- o.mesh !== void 0 && (this._addNodeRef(this.meshCache, o.mesh), o.skin !== void 0 && (s[o.mesh].isSkinnedMesh = !0)), o.camera !== void 0 && this._addNodeRef(this.cameraCache, o.camera);
1888
- }
1889
- }
1890
- /**
1891
- * Counts references to shared node / Object3D resources. These resources
1892
- * can be reused, or "instantiated", at multiple nodes in the scene
1893
- * hierarchy. Mesh, Camera, and Light instances are instantiated and must
1894
- * be marked. Non-scenegraph resources (like Materials, Geometries, and
1895
- * Textures) can be reused directly and are not marked here.
1896
- *
1897
- * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
1898
- *
1899
- * @private
1900
- * @param {Object} cache
1901
- * @param {Object3D} index
1902
- */
1903
- _addNodeRef(e, t) {
1904
- t !== void 0 && (e.refs[t] === void 0 && (e.refs[t] = e.uses[t] = 0), e.refs[t]++);
1905
- }
1906
- /**
1907
- * Returns a reference to a shared resource, cloning it if necessary.
1908
- *
1909
- * @private
1910
- * @param {Object} cache
1911
- * @param {number} index
1912
- * @param {Object} object
1913
- * @return {Object}
1914
- */
1915
- _getNodeRef(e, t, s) {
1916
- if (e.refs[t] <= 1) return s;
1917
- const n = s.clone(), i = (o, c) => {
1918
- const a = this.associations.get(o);
1919
- a != null && this.associations.set(c, a);
1920
- for (const [l, u] of o.children.entries())
1921
- i(u, c.children[l]);
1922
- };
1923
- return i(s, n), n.name += "_instance_" + e.uses[t]++, n;
1924
- }
1925
- _invokeOne(e) {
1926
- const t = Object.values(this.plugins);
1927
- t.push(this);
1928
- for (let s = 0; s < t.length; s++) {
1929
- const n = e(t[s]);
1930
- if (n) return n;
1931
- }
1932
- return null;
1933
- }
1934
- _invokeAll(e) {
1935
- const t = Object.values(this.plugins);
1936
- t.unshift(this);
1937
- const s = [];
1938
- for (let n = 0; n < t.length; n++) {
1939
- const i = e(t[n]);
1940
- i && s.push(i);
1941
- }
1942
- return s;
1943
- }
1944
- /**
1945
- * Requests the specified dependency asynchronously, with caching.
1946
- *
1947
- * @private
1948
- * @param {string} type
1949
- * @param {number} index
1950
- * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
1951
- */
1952
- getDependency(e, t) {
1953
- const s = e + ":" + t;
1954
- let n = this.cache.get(s);
1955
- if (!n) {
1956
- switch (e) {
1957
- case "scene":
1958
- n = this.loadScene(t);
1959
- break;
1960
- case "node":
1961
- n = this._invokeOne(function(i) {
1962
- return i.loadNode && i.loadNode(t);
1963
- });
1964
- break;
1965
- case "mesh":
1966
- n = this._invokeOne(function(i) {
1967
- return i.loadMesh && i.loadMesh(t);
1968
- });
1969
- break;
1970
- case "accessor":
1971
- n = this.loadAccessor(t);
1972
- break;
1973
- case "bufferView":
1974
- n = this._invokeOne(function(i) {
1975
- return i.loadBufferView && i.loadBufferView(t);
1976
- });
1977
- break;
1978
- case "buffer":
1979
- n = this.loadBuffer(t);
1980
- break;
1981
- case "material":
1982
- n = this._invokeOne(function(i) {
1983
- return i.loadMaterial && i.loadMaterial(t);
1984
- });
1985
- break;
1986
- case "texture":
1987
- n = this._invokeOne(function(i) {
1988
- return i.loadTexture && i.loadTexture(t);
1989
- });
1990
- break;
1991
- case "skin":
1992
- n = this.loadSkin(t);
1993
- break;
1994
- case "animation":
1995
- n = this._invokeOne(function(i) {
1996
- return i.loadAnimation && i.loadAnimation(t);
1997
- });
1998
- break;
1999
- case "camera":
2000
- n = this.loadCamera(t);
2001
- break;
2002
- default:
2003
- if (n = this._invokeOne(function(i) {
2004
- return i != this && i.getDependency && i.getDependency(e, t);
2005
- }), !n)
2006
- throw new Error("Unknown type: " + e);
2007
- break;
2008
- }
2009
- this.cache.add(s, n);
2010
- }
2011
- return n;
2012
- }
2013
- /**
2014
- * Requests all dependencies of the specified type asynchronously, with caching.
2015
- *
2016
- * @private
2017
- * @param {string} type
2018
- * @return {Promise<Array<Object>>}
2019
- */
2020
- getDependencies(e) {
2021
- let t = this.cache.get(e);
2022
- if (!t) {
2023
- const s = this, n = this.json[e + (e === "mesh" ? "es" : "s")] || [];
2024
- t = Promise.all(n.map(function(i, o) {
2025
- return s.getDependency(e, o);
2026
- })), this.cache.add(e, t);
2027
- }
2028
- return t;
2029
- }
2030
- /**
2031
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2032
- *
2033
- * @private
2034
- * @param {number} bufferIndex
2035
- * @return {Promise<ArrayBuffer>}
2036
- */
2037
- loadBuffer(e) {
2038
- const t = this.json.buffers[e], s = this.fileLoader;
2039
- if (t.type && t.type !== "arraybuffer")
2040
- throw new Error("THREE.GLTFLoader: " + t.type + " buffer type is not supported.");
2041
- if (t.uri === void 0 && e === 0)
2042
- return Promise.resolve(this.extensions[b.KHR_BINARY_GLTF].body);
2043
- const n = this.options;
2044
- return new Promise(function(i, o) {
2045
- s.load(ne.resolveURL(t.uri, n.path), i, void 0, function() {
2046
- o(new Error('THREE.GLTFLoader: Failed to load buffer "' + t.uri + '".'));
2047
- });
2048
- });
2049
- }
2050
- /**
2051
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2052
- *
2053
- * @private
2054
- * @param {number} bufferViewIndex
2055
- * @return {Promise<ArrayBuffer>}
2056
- */
2057
- loadBufferView(e) {
2058
- const t = this.json.bufferViews[e];
2059
- return this.getDependency("buffer", t.buffer).then(function(s) {
2060
- const n = t.byteLength || 0, i = t.byteOffset || 0;
2061
- return s.slice(i, i + n);
2062
- });
2063
- }
2064
- /**
2065
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
2066
- *
2067
- * @private
2068
- * @param {number} accessorIndex
2069
- * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
2070
- */
2071
- loadAccessor(e) {
2072
- const t = this, s = this.json, n = this.json.accessors[e];
2073
- if (n.bufferView === void 0 && n.sparse === void 0) {
2074
- const o = _e[n.type], c = Q[n.componentType], a = n.normalized === !0, l = new c(n.count * o);
2075
- return Promise.resolve(new se(l, o, a));
2076
- }
2077
- const i = [];
2078
- return n.bufferView !== void 0 ? i.push(this.getDependency("bufferView", n.bufferView)) : i.push(null), n.sparse !== void 0 && (i.push(this.getDependency("bufferView", n.sparse.indices.bufferView)), i.push(this.getDependency("bufferView", n.sparse.values.bufferView))), Promise.all(i).then(function(o) {
2079
- const c = o[0], a = _e[n.type], l = Q[n.componentType], u = l.BYTES_PER_ELEMENT, h = u * a, m = n.byteOffset || 0, f = n.bufferView !== void 0 ? s.bufferViews[n.bufferView].byteStride : void 0, g = n.normalized === !0;
2080
- let y, p;
2081
- if (f && f !== h) {
2082
- const d = Math.floor(m / f), _ = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + d + ":" + n.count;
2083
- let w = t.cache.get(_);
2084
- w || (y = new l(c, d * f, n.count * f / u), w = new Mt(y, f / u), t.cache.add(_, w)), p = new Lt(w, a, m % f / u, g);
2085
- } else
2086
- c === null ? y = new l(n.count * a) : y = new l(c, m, n.count * a), p = new se(y, a, g);
2087
- if (n.sparse !== void 0) {
2088
- const d = _e.SCALAR, _ = Q[n.sparse.indices.componentType], w = n.sparse.indices.byteOffset || 0, T = n.sparse.values.byteOffset || 0, A = new _(o[1], w, n.sparse.count * d), S = new l(o[2], T, n.sparse.count * a);
2089
- c !== null && (p = new se(p.array.slice(), p.itemSize, p.normalized)), p.normalized = !1;
2090
- for (let M = 0, R = A.length; M < R; M++) {
2091
- const D = A[M];
2092
- if (p.setX(D, S[M * a]), a >= 2 && p.setY(D, S[M * a + 1]), a >= 3 && p.setZ(D, S[M * a + 2]), a >= 4 && p.setW(D, S[M * a + 3]), a >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
2093
- }
2094
- p.normalized = g;
2095
- }
2096
- return p;
2097
- });
2098
- }
2099
- /**
2100
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
2101
- *
2102
- * @private
2103
- * @param {number} textureIndex
2104
- * @return {Promise<THREE.Texture|null>}
2105
- */
2106
- loadTexture(e) {
2107
- const t = this.json, s = this.options, i = t.textures[e].source, o = t.images[i];
2108
- let c = this.textureLoader;
2109
- if (o.uri) {
2110
- const a = s.manager.getHandler(o.uri);
2111
- a !== null && (c = a);
2112
- }
2113
- return this.loadTextureImage(e, i, c);
2114
- }
2115
- loadTextureImage(e, t, s) {
2116
- const n = this, i = this.json, o = i.textures[e], c = i.images[t], a = (c.uri || c.bufferView) + ":" + o.sampler;
2117
- if (this.textureCache[a])
2118
- return this.textureCache[a];
2119
- const l = this.loadImageSource(t, s).then(function(u) {
2120
- u.flipY = !1, u.name = o.name || c.name || "", u.name === "" && typeof c.uri == "string" && c.uri.startsWith("data:image/") === !1 && (u.name = c.uri);
2121
- const m = (i.samplers || {})[o.sampler] || {};
2122
- return u.magFilter = Ke[m.magFilter] || Se, u.minFilter = Ke[m.minFilter] || tt, u.wrapS = We[m.wrapS] || Me, u.wrapT = We[m.wrapT] || Me, u.generateMipmaps = !u.isCompressedTexture && u.minFilter !== st && u.minFilter !== Se, n.associations.set(u, { textures: e }), u;
2123
- }).catch(function() {
2124
- return null;
2125
- });
2126
- return this.textureCache[a] = l, l;
2127
- }
2128
- loadImageSource(e, t) {
2129
- const s = this, n = this.json, i = this.options;
2130
- if (this.sourceCache[e] !== void 0)
2131
- return this.sourceCache[e].then((h) => h.clone());
2132
- const o = n.images[e], c = self.URL || self.webkitURL;
2133
- let a = o.uri || "", l = !1;
2134
- if (o.bufferView !== void 0)
2135
- a = s.getDependency("bufferView", o.bufferView).then(function(h) {
2136
- l = !0;
2137
- const m = new Blob([h], { type: o.mimeType });
2138
- return a = c.createObjectURL(m), a;
2139
- });
2140
- else if (o.uri === void 0)
2141
- throw new Error("THREE.GLTFLoader: Image " + e + " is missing URI and bufferView");
2142
- const u = Promise.resolve(a).then(function(h) {
2143
- return new Promise(function(m, f) {
2144
- let g = m;
2145
- t.isImageBitmapLoader === !0 && (g = function(y) {
2146
- const p = new ke(y);
2147
- p.needsUpdate = !0, m(p);
2148
- }), t.load(ne.resolveURL(h, i.path), g, void 0, f);
2149
- });
2150
- }).then(function(h) {
2151
- return l === !0 && c.revokeObjectURL(a), F(h, o), h.userData.mimeType = o.mimeType || $s(o.uri), h;
2152
- }).catch(function(h) {
2153
- throw console.error("THREE.GLTFLoader: Couldn't load texture", a), h;
2154
- });
2155
- return this.sourceCache[e] = u, u;
2156
- }
2157
- /**
2158
- * Asynchronously assigns a texture to the given material parameters.
2159
- *
2160
- * @private
2161
- * @param {Object} materialParams
2162
- * @param {string} mapName
2163
- * @param {Object} mapDef
2164
- * @param {string} [colorSpace]
2165
- * @return {Promise<Texture>}
2166
- */
2167
- assignTexture(e, t, s, n) {
2168
- const i = this;
2169
- return this.getDependency("texture", s.index).then(function(o) {
2170
- if (!o) return null;
2171
- if (s.texCoord !== void 0 && s.texCoord > 0 && (o = o.clone(), o.channel = s.texCoord), i.extensions[b.KHR_TEXTURE_TRANSFORM]) {
2172
- const c = s.extensions !== void 0 ? s.extensions[b.KHR_TEXTURE_TRANSFORM] : void 0;
2173
- if (c) {
2174
- const a = i.associations.get(o);
2175
- o = i.extensions[b.KHR_TEXTURE_TRANSFORM].extendTexture(o, c), i.associations.set(o, a);
2176
- }
2177
- }
2178
- return n !== void 0 && (o.colorSpace = n), e[t] = o, o;
2179
- });
2180
- }
2181
- /**
2182
- * Assigns final material to a Mesh, Line, or Points instance. The instance
2183
- * already has a material (generated from the glTF material options alone)
2184
- * but reuse of the same glTF material may require multiple threejs materials
2185
- * to accommodate different primitive types, defines, etc. New materials will
2186
- * be created if necessary, and reused from a cache.
2187
- *
2188
- * @private
2189
- * @param {Object3D} mesh Mesh, Line, or Points instance.
2190
- */
2191
- assignFinalMaterial(e) {
2192
- const t = e.geometry;
2193
- let s = e.material;
2194
- const n = t.attributes.tangent === void 0, i = t.attributes.color !== void 0, o = t.attributes.normal === void 0;
2195
- if (e.isPoints) {
2196
- const c = "PointsMaterial:" + s.uuid;
2197
- let a = this.cache.get(c);
2198
- a || (a = new kt(), pe.prototype.copy.call(a, s), a.color.copy(s.color), a.map = s.map, a.sizeAttenuation = !1, this.cache.add(c, a)), s = a;
2199
- } else if (e.isLine) {
2200
- const c = "LineBasicMaterial:" + s.uuid;
2201
- let a = this.cache.get(c);
2202
- a || (a = new Nt(), pe.prototype.copy.call(a, s), a.color.copy(s.color), a.map = s.map, this.cache.add(c, a)), s = a;
2203
- }
2204
- if (n || i || o) {
2205
- let c = "ClonedMaterial:" + s.uuid + ":";
2206
- n && (c += "derivative-tangents:"), i && (c += "vertex-colors:"), o && (c += "flat-shading:");
2207
- let a = this.cache.get(c);
2208
- a || (a = s.clone(), i && (a.vertexColors = !0), o && (a.flatShading = !0), n && (a.normalScale && (a.normalScale.y *= -1), a.clearcoatNormalScale && (a.clearcoatNormalScale.y *= -1)), this.cache.add(c, a), this.associations.set(a, this.associations.get(s))), s = a;
2209
- }
2210
- e.material = s;
2211
- }
2212
- getMaterialType() {
2213
- return nt;
2214
- }
2215
- /**
2216
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
2217
- *
2218
- * @private
2219
- * @param {number} materialIndex
2220
- * @return {Promise<Material>}
2221
- */
2222
- loadMaterial(e) {
2223
- const t = this, s = this.json, n = this.extensions, i = s.materials[e];
2224
- let o;
2225
- const c = {}, a = i.extensions || {}, l = [];
2226
- if (a[b.KHR_MATERIALS_UNLIT]) {
2227
- const h = n[b.KHR_MATERIALS_UNLIT];
2228
- o = h.getMaterialType(), l.push(h.extendParams(c, i, t));
2229
- } else {
2230
- const h = i.pbrMetallicRoughness || {};
2231
- if (c.color = new W(1, 1, 1), c.opacity = 1, Array.isArray(h.baseColorFactor)) {
2232
- const m = h.baseColorFactor;
2233
- c.color.setRGB(m[0], m[1], m[2], N), c.opacity = m[3];
2234
- }
2235
- h.baseColorTexture !== void 0 && l.push(t.assignTexture(c, "map", h.baseColorTexture, K)), c.metalness = h.metallicFactor !== void 0 ? h.metallicFactor : 1, c.roughness = h.roughnessFactor !== void 0 ? h.roughnessFactor : 1, h.metallicRoughnessTexture !== void 0 && (l.push(t.assignTexture(c, "metalnessMap", h.metallicRoughnessTexture)), l.push(t.assignTexture(c, "roughnessMap", h.metallicRoughnessTexture))), o = this._invokeOne(function(m) {
2236
- return m.getMaterialType && m.getMaterialType(e);
2237
- }), l.push(Promise.all(this._invokeAll(function(m) {
2238
- return m.extendMaterialParams && m.extendMaterialParams(e, c);
2239
- })));
2240
- }
2241
- i.doubleSided === !0 && (c.side = vt);
2242
- const u = i.alphaMode || Te.OPAQUE;
2243
- if (u === Te.BLEND ? (c.transparent = !0, c.depthWrite = !1) : (c.transparent = !1, u === Te.MASK && (c.alphaTest = i.alphaCutoff !== void 0 ? i.alphaCutoff : 0.5)), i.normalTexture !== void 0 && o !== te && (l.push(t.assignTexture(c, "normalMap", i.normalTexture)), c.normalScale = new C(1, 1), i.normalTexture.scale !== void 0)) {
2244
- const h = i.normalTexture.scale;
2245
- c.normalScale.set(h, h);
2246
- }
2247
- if (i.occlusionTexture !== void 0 && o !== te && (l.push(t.assignTexture(c, "aoMap", i.occlusionTexture)), i.occlusionTexture.strength !== void 0 && (c.aoMapIntensity = i.occlusionTexture.strength)), i.emissiveFactor !== void 0 && o !== te) {
2248
- const h = i.emissiveFactor;
2249
- c.emissive = new W().setRGB(h[0], h[1], h[2], N);
2250
- }
2251
- return i.emissiveTexture !== void 0 && o !== te && l.push(t.assignTexture(c, "emissiveMap", i.emissiveTexture, K)), Promise.all(l).then(function() {
2252
- const h = new o(c);
2253
- return i.name && (h.name = i.name), F(h, i), t.associations.set(h, { materials: e }), i.extensions && X(n, h, i), h;
2254
- });
2255
- }
2256
- /**
2257
- * When Object3D instances are targeted by animation, they need unique names.
2258
- *
2259
- * @private
2260
- * @param {string} originalName
2261
- * @return {string}
2262
- */
2263
- createUniqueName(e) {
2264
- const t = Ht.sanitizeNodeName(e || "");
2265
- return t in this.nodeNamesUsed ? t + "_" + ++this.nodeNamesUsed[t] : (this.nodeNamesUsed[t] = 0, t);
2266
- }
2267
- /**
2268
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
2269
- *
2270
- * Creates BufferGeometries from primitives.
2271
- *
2272
- * @private
2273
- * @param {Array<GLTF.Primitive>} primitives
2274
- * @return {Promise<Array<BufferGeometry>>}
2275
- */
2276
- loadGeometries(e) {
2277
- const t = this, s = this.extensions, n = this.primitiveCache;
2278
- function i(c) {
2279
- return s[b.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(c, t).then(function(a) {
2280
- return Xe(a, c, t);
2281
- });
2282
- }
2283
- const o = [];
2284
- for (let c = 0, a = e.length; c < a; c++) {
2285
- const l = e[c], u = Zs(l), h = n[u];
2286
- if (h)
2287
- o.push(h.promise);
2288
- else {
2289
- let m;
2290
- l.extensions && l.extensions[b.KHR_DRACO_MESH_COMPRESSION] ? m = i(l) : m = Xe(new et(), l, t), n[u] = { primitive: l, promise: m }, o.push(m);
2291
- }
2292
- }
2293
- return Promise.all(o);
2294
- }
2295
- /**
2296
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
2297
- *
2298
- * @private
2299
- * @param {number} meshIndex
2300
- * @return {Promise<Group|Mesh|SkinnedMesh|Line|Points>}
2301
- */
2302
- loadMesh(e) {
2303
- const t = this, s = this.json, n = this.extensions, i = s.meshes[e], o = i.primitives, c = [];
2304
- for (let a = 0, l = o.length; a < l; a++) {
2305
- const u = o[a].material === void 0 ? Vs(this.cache) : this.getDependency("material", o[a].material);
2306
- c.push(u);
2307
- }
2308
- return c.push(t.loadGeometries(o)), Promise.all(c).then(function(a) {
2309
- const l = a.slice(0, a.length - 1), u = a[a.length - 1], h = [];
2310
- for (let f = 0, g = u.length; f < g; f++) {
2311
- const y = u[f], p = o[f];
2312
- let d;
2313
- const _ = l[f];
2314
- if (p.mode === I.TRIANGLES || p.mode === I.TRIANGLE_STRIP || p.mode === I.TRIANGLE_FAN || p.mode === void 0)
2315
- d = i.isSkinnedMesh === !0 ? new Ft(y, _) : new Ut(y, _), d.isSkinnedMesh === !0 && d.normalizeSkinWeights(), p.mode === I.TRIANGLE_STRIP ? d.geometry = Be(d.geometry, Qe) : p.mode === I.TRIANGLE_FAN && (d.geometry = Be(d.geometry, Ae));
2316
- else if (p.mode === I.LINES)
2317
- d = new jt(y, _);
2318
- else if (p.mode === I.LINE_STRIP)
2319
- d = new Gt(y, _);
2320
- else if (p.mode === I.LINE_LOOP)
2321
- d = new Bt(y, _);
2322
- else if (p.mode === I.POINTS)
2323
- d = new zt(y, _);
2324
- else
2325
- throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + p.mode);
2326
- Object.keys(d.geometry.morphAttributes).length > 0 && qs(d, i), d.name = t.createUniqueName(i.name || "mesh_" + e), F(d, i), p.extensions && X(n, d, p), t.assignFinalMaterial(d), h.push(d);
2327
- }
2328
- for (let f = 0, g = h.length; f < g; f++)
2329
- t.associations.set(h[f], {
2330
- meshes: e,
2331
- primitives: f
2332
- });
2333
- if (h.length === 1)
2334
- return i.extensions && X(n, h[0], i), h[0];
2335
- const m = new me();
2336
- i.extensions && X(n, m, i), t.associations.set(m, { meshes: e });
2337
- for (let f = 0, g = h.length; f < g; f++)
2338
- m.add(h[f]);
2339
- return m;
2340
- });
2341
- }
2342
- /**
2343
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
2344
- *
2345
- * @private
2346
- * @param {number} cameraIndex
2347
- * @return {Promise<THREE.Camera>}
2348
- */
2349
- loadCamera(e) {
2350
- let t;
2351
- const s = this.json.cameras[e], n = s[s.type];
2352
- if (!n) {
2353
- console.warn("THREE.GLTFLoader: Missing camera parameters.");
2354
- return;
2355
- }
2356
- return s.type === "perspective" ? t = new Kt($e.radToDeg(n.yfov), n.aspectRatio || 1, n.znear || 1, n.zfar || 2e6) : s.type === "orthographic" && (t = new Wt(-n.xmag, n.xmag, n.ymag, -n.ymag, n.znear, n.zfar)), s.name && (t.name = this.createUniqueName(s.name)), F(t, s), Promise.resolve(t);
2357
- }
2358
- /**
2359
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
2360
- *
2361
- * @private
2362
- * @param {number} skinIndex
2363
- * @return {Promise<Skeleton>}
2364
- */
2365
- loadSkin(e) {
2366
- const t = this.json.skins[e], s = [];
2367
- for (let n = 0, i = t.joints.length; n < i; n++)
2368
- s.push(this._loadNodeShallow(t.joints[n]));
2369
- return t.inverseBindMatrices !== void 0 ? s.push(this.getDependency("accessor", t.inverseBindMatrices)) : s.push(null), Promise.all(s).then(function(n) {
2370
- const i = n.pop(), o = n, c = [], a = [];
2371
- for (let l = 0, u = o.length; l < u; l++) {
2372
- const h = o[l];
2373
- if (h) {
2374
- c.push(h);
2375
- const m = new J();
2376
- i !== null && m.fromArray(i.array, l * 16), a.push(m);
2377
- } else
2378
- console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', t.joints[l]);
2379
- }
2380
- return new Xt(c, a);
2381
- });
2382
- }
2383
- /**
2384
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
2385
- *
2386
- * @private
2387
- * @param {number} animationIndex
2388
- * @return {Promise<AnimationClip>}
2389
- */
2390
- loadAnimation(e) {
2391
- const t = this.json, s = this, n = t.animations[e], i = n.name ? n.name : "animation_" + e, o = [], c = [], a = [], l = [], u = [];
2392
- for (let h = 0, m = n.channels.length; h < m; h++) {
2393
- const f = n.channels[h], g = n.samplers[f.sampler], y = f.target, p = y.node, d = n.parameters !== void 0 ? n.parameters[g.input] : g.input, _ = n.parameters !== void 0 ? n.parameters[g.output] : g.output;
2394
- y.node !== void 0 && (o.push(this.getDependency("node", p)), c.push(this.getDependency("accessor", d)), a.push(this.getDependency("accessor", _)), l.push(g), u.push(y));
2395
- }
2396
- return Promise.all([
2397
- Promise.all(o),
2398
- Promise.all(c),
2399
- Promise.all(a),
2400
- Promise.all(l),
2401
- Promise.all(u)
2402
- ]).then(function(h) {
2403
- const m = h[0], f = h[1], g = h[2], y = h[3], p = h[4], d = [];
2404
- for (let _ = 0, w = m.length; _ < w; _++) {
2405
- const T = m[_], A = f[_], S = g[_], M = y[_], R = p[_];
2406
- if (T === void 0) continue;
2407
- T.updateMatrix && T.updateMatrix();
2408
- const D = s._createAnimationTracks(T, A, S, M, R);
2409
- if (D)
2410
- for (let H = 0; H < D.length; H++)
2411
- d.push(D[H]);
2412
- }
2413
- return new Vt(i, void 0, d);
2414
- });
2415
- }
2416
- createNodeMesh(e) {
2417
- const t = this.json, s = this, n = t.nodes[e];
2418
- return n.mesh === void 0 ? null : s.getDependency("mesh", n.mesh).then(function(i) {
2419
- const o = s._getNodeRef(s.meshCache, n.mesh, i);
2420
- return n.weights !== void 0 && o.traverse(function(c) {
2421
- if (c.isMesh)
2422
- for (let a = 0, l = n.weights.length; a < l; a++)
2423
- c.morphTargetInfluences[a] = n.weights[a];
2424
- }), o;
2425
- });
2426
- }
2427
- /**
2428
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
2429
- *
2430
- * @private
2431
- * @param {number} nodeIndex
2432
- * @return {Promise<Object3D>}
2433
- */
2434
- loadNode(e) {
2435
- const t = this.json, s = this, n = t.nodes[e], i = s._loadNodeShallow(e), o = [], c = n.children || [];
2436
- for (let l = 0, u = c.length; l < u; l++)
2437
- o.push(s.getDependency("node", c[l]));
2438
- const a = n.skin === void 0 ? Promise.resolve(null) : s.getDependency("skin", n.skin);
2439
- return Promise.all([
2440
- i,
2441
- Promise.all(o),
2442
- a
2443
- ]).then(function(l) {
2444
- const u = l[0], h = l[1], m = l[2];
2445
- m !== null && u.traverse(function(f) {
2446
- f.isSkinnedMesh && f.bind(m, Qs);
2447
- });
2448
- for (let f = 0, g = h.length; f < g; f++)
2449
- u.add(h[f]);
2450
- return u;
2451
- });
2452
- }
2453
- // ._loadNodeShallow() parses a single node.
2454
- // skin and child nodes are created and added in .loadNode() (no '_' prefix).
2455
- _loadNodeShallow(e) {
2456
- const t = this.json, s = this.extensions, n = this;
2457
- if (this.nodeCache[e] !== void 0)
2458
- return this.nodeCache[e];
2459
- const i = t.nodes[e], o = i.name ? n.createUniqueName(i.name) : "", c = [], a = n._invokeOne(function(l) {
2460
- return l.createNodeMesh && l.createNodeMesh(e);
2461
- });
2462
- return a && c.push(a), i.camera !== void 0 && c.push(n.getDependency("camera", i.camera).then(function(l) {
2463
- return n._getNodeRef(n.cameraCache, i.camera, l);
2464
- })), n._invokeAll(function(l) {
2465
- return l.createNodeAttachment && l.createNodeAttachment(e);
2466
- }).forEach(function(l) {
2467
- c.push(l);
2468
- }), this.nodeCache[e] = Promise.all(c).then(function(l) {
2469
- let u;
2470
- if (i.isBone === !0 ? u = new Yt() : l.length > 1 ? u = new me() : l.length === 1 ? u = l[0] : u = new De(), u !== l[0])
2471
- for (let h = 0, m = l.length; h < m; h++)
2472
- u.add(l[h]);
2473
- if (i.name && (u.userData.name = i.name, u.name = o), F(u, i), i.extensions && X(s, u, i), i.matrix !== void 0) {
2474
- const h = new J();
2475
- h.fromArray(i.matrix), u.applyMatrix4(h);
2476
- } else
2477
- i.translation !== void 0 && u.position.fromArray(i.translation), i.rotation !== void 0 && u.quaternion.fromArray(i.rotation), i.scale !== void 0 && u.scale.fromArray(i.scale);
2478
- if (!n.associations.has(u))
2479
- n.associations.set(u, {});
2480
- else if (i.mesh !== void 0 && n.meshCache.refs[i.mesh] > 1) {
2481
- const h = n.associations.get(u);
2482
- n.associations.set(u, { ...h });
2483
- }
2484
- return n.associations.get(u).nodes = e, u;
2485
- }), this.nodeCache[e];
2486
- }
2487
- /**
2488
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
2489
- *
2490
- * @private
2491
- * @param {number} sceneIndex
2492
- * @return {Promise<Group>}
2493
- */
2494
- loadScene(e) {
2495
- const t = this.extensions, s = this.json.scenes[e], n = this, i = new me();
2496
- s.name && (i.name = n.createUniqueName(s.name)), F(i, s), s.extensions && X(t, i, s);
2497
- const o = s.nodes || [], c = [];
2498
- for (let a = 0, l = o.length; a < l; a++)
2499
- c.push(n.getDependency("node", o[a]));
2500
- return Promise.all(c).then(function(a) {
2501
- for (let u = 0, h = a.length; u < h; u++)
2502
- i.add(a[u]);
2503
- const l = (u) => {
2504
- const h = /* @__PURE__ */ new Map();
2505
- for (const [m, f] of n.associations)
2506
- (m instanceof pe || m instanceof ke) && h.set(m, f);
2507
- return u.traverse((m) => {
2508
- const f = n.associations.get(m);
2509
- f != null && h.set(m, f);
2510
- }), h;
2511
- };
2512
- return n.associations = l(i), i;
2513
- });
2514
- }
2515
- _createAnimationTracks(e, t, s, n, i) {
2516
- const o = [], c = e.name ? e.name : e.uuid, a = [];
2517
- G[i.path] === G.weights ? e.traverse(function(m) {
2518
- m.morphTargetInfluences && a.push(m.name ? m.name : m.uuid);
2519
- }) : a.push(c);
2520
- let l;
2521
- switch (G[i.path]) {
2522
- case G.weights:
2523
- l = ve;
2524
- break;
2525
- case G.rotation:
2526
- l = He;
2527
- break;
2528
- case G.translation:
2529
- case G.scale:
2530
- l = Ne;
2531
- break;
2532
- default:
2533
- switch (s.itemSize) {
2534
- case 1:
2535
- l = ve;
2536
- break;
2537
- case 2:
2538
- case 3:
2539
- default:
2540
- l = Ne;
2541
- break;
2542
- }
2543
- break;
2544
- }
2545
- const u = n.interpolation !== void 0 ? Xs[n.interpolation] : it, h = this._getArrayFromAccessor(s);
2546
- for (let m = 0, f = a.length; m < f; m++) {
2547
- const g = new l(
2548
- a[m] + "." + G[i.path],
2549
- t.array,
2550
- h,
2551
- u
2552
- );
2553
- n.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(g), o.push(g);
2554
- }
2555
- return o;
2556
- }
2557
- _getArrayFromAccessor(e) {
2558
- let t = e.array;
2559
- if (e.normalized) {
2560
- const s = Pe(t.constructor), n = new Float32Array(t.length);
2561
- for (let i = 0, o = t.length; i < o; i++)
2562
- n[i] = t[i] * s;
2563
- t = n;
2564
- }
2565
- return t;
2566
- }
2567
- _createCubicSplineTrackInterpolant(e) {
2568
- e.createInterpolant = function(s) {
2569
- const n = this instanceof He ? Ws : ct;
2570
- return new n(this.times, this.values, this.getValueSize() / 3, s);
2571
- }, e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
2572
- }
2573
- }
2574
- function en(r, e, t) {
2575
- const s = e.attributes, n = new Qt();
2576
- if (s.POSITION !== void 0) {
2577
- const c = t.json.accessors[s.POSITION], a = c.min, l = c.max;
2578
- if (a !== void 0 && l !== void 0) {
2579
- if (n.set(
2580
- new L(a[0], a[1], a[2]),
2581
- new L(l[0], l[1], l[2])
2582
- ), c.normalized) {
2583
- const u = Pe(Q[c.componentType]);
2584
- n.min.multiplyScalar(u), n.max.multiplyScalar(u);
2585
- }
2586
- } else {
2587
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
2588
- return;
2589
- }
2590
- } else
2591
- return;
2592
- const i = e.targets;
2593
- if (i !== void 0) {
2594
- const c = new L(), a = new L();
2595
- for (let l = 0, u = i.length; l < u; l++) {
2596
- const h = i[l];
2597
- if (h.POSITION !== void 0) {
2598
- const m = t.json.accessors[h.POSITION], f = m.min, g = m.max;
2599
- if (f !== void 0 && g !== void 0) {
2600
- if (a.setX(Math.max(Math.abs(f[0]), Math.abs(g[0]))), a.setY(Math.max(Math.abs(f[1]), Math.abs(g[1]))), a.setZ(Math.max(Math.abs(f[2]), Math.abs(g[2]))), m.normalized) {
2601
- const y = Pe(Q[m.componentType]);
2602
- a.multiplyScalar(y);
2603
- }
2604
- c.max(a);
2605
- } else
2606
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
2607
- }
2608
- }
2609
- n.expandByVector(c);
2610
- }
2611
- r.boundingBox = n;
2612
- const o = new Jt();
2613
- n.getCenter(o.center), o.radius = n.min.distanceTo(n.max) / 2, r.boundingSphere = o;
2614
- }
2615
- function Xe(r, e, t) {
2616
- const s = e.attributes, n = [];
2617
- function i(o, c) {
2618
- return t.getDependency("accessor", o).then(function(a) {
2619
- r.setAttribute(c, a);
2620
- });
2621
- }
2622
- for (const o in s) {
2623
- const c = Le[o] || o.toLowerCase();
2624
- c in r.attributes || n.push(i(s[o], c));
2625
- }
2626
- if (e.indices !== void 0 && !r.index) {
2627
- const o = t.getDependency("accessor", e.indices).then(function(c) {
2628
- r.setIndex(c);
2629
- });
2630
- n.push(o);
2631
- }
2632
- return Re.workingColorSpace !== N && "COLOR_0" in s && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Re.workingColorSpace}" not supported.`), F(r, e), en(r, e, t), Promise.all(n).then(function() {
2633
- return e.targets !== void 0 ? Ys(r, e.targets, t) : r;
2634
- });
2635
- }
2636
- const tn = (r) => {
2637
- r.geometry && r.geometry.dispose(), r.material && (Array.isArray(r.material) ? r.material.forEach((e) => {
2638
- Ve(e);
2639
- }) : Ve(r.material)), r.children && r.children.forEach((e) => tn(e));
2640
- };
2641
- function Ve(r) {
2642
- for (const e in r)
2643
- r[e] && r[e].isTexture && r[e].dispose();
2644
- r.dispose();
2645
- }
2646
- const be = {};
2647
- async function An(r, e = 50) {
2648
- const t = {
2649
- type: r.type,
2650
- name: r.name,
2651
- position: r.position.toArray(),
2652
- rotation: r.rotation.toArray(),
2653
- scale: r.scale.toArray(),
2654
- visible: r.visible,
2655
- children: [],
2656
- geometry: null,
2657
- material: null,
2658
- userData: r.userData
2659
- };
2660
- r.isMesh && (t.geometry = le(r.geometry), t.material = ue(r.material));
2661
- const s = [{ object: r, parentData: t }];
2662
- let n = 0;
2663
- for (; s.length > 0; ) {
2664
- const { object: i, parentData: o } = s.pop();
2665
- for (const c of i.children) {
2666
- const a = {
2667
- type: c.type,
2668
- name: c.name,
2669
- position: c.position.toArray(),
2670
- rotation: c.rotation.toArray(),
2671
- scale: c.scale.toArray(),
2672
- visible: c.visible,
2673
- children: [],
2674
- geometry: null,
2675
- material: null,
2676
- userData: c.userData
2677
- };
2678
- c.isMesh && (a.geometry = le(c.geometry), a.material = ue(c.material)), o.children.push(a), s.push({ object: c, parentData: a }), n++, n % e === 0 && await new Promise((l) => requestAnimationFrame(l));
2679
- }
2680
- }
2681
- return t;
2682
- }
2683
- function Rn(r) {
2684
- const e = {
2685
- type: r.type,
2686
- name: r.name,
2687
- position: r.position.toArray(),
2688
- rotation: r.rotation.toArray(),
2689
- scale: r.scale.toArray(),
2690
- visible: r.visible,
2691
- children: [],
2692
- geometry: null,
2693
- material: null,
2694
- userData: r.userData
2695
- };
2696
- r.isMesh && (e.geometry = le(r.geometry), e.material = ue(r.material));
2697
- const t = [{ object: r, parentData: e }];
2698
- for (; t.length > 0; ) {
2699
- const { object: s, parentData: n } = t.pop();
2700
- for (const i of s.children) {
2701
- const o = {
2702
- type: i.type,
2703
- name: i.name,
2704
- position: i.position.toArray(),
2705
- rotation: i.rotation.toArray(),
2706
- scale: i.scale.toArray(),
2707
- visible: i.visible,
2708
- children: [],
2709
- geometry: null,
2710
- material: null,
2711
- userData: i.userData
2712
- };
2713
- i.isMesh && (o.geometry = le(i.geometry), o.material = ue(i.material)), n.children.push(o), t.push({ object: i, parentData: o });
2714
- }
2715
- }
2716
- return e;
2717
- }
2718
- async function sn(r, e = 50) {
2719
- const t = [];
2720
- let s;
2721
- switch (r.type) {
2722
- case "Mesh":
2723
- const i = he(r.geometry), o = de(r.material);
2724
- s = new E.Mesh(i, o);
2725
- break;
2726
- case "Group":
2727
- s = new E.Group();
2728
- break;
2729
- case "Object3D":
2730
- s = new E.Object3D();
2731
- break;
2732
- default:
2733
- return console.warn(`Unsupported object type: ${r.type}`), null;
2734
- }
2735
- s.name = r.name, s.position.fromArray(r.position), s.rotation.fromArray(r.rotation), s.scale.fromArray(r.scale), s.visible = r.visible, s.userData = r.userData, t.push({ data: r, object: s });
2736
- let n = 0;
2737
- for (; t.length > 0; ) {
2738
- const { data: i, object: o } = t.pop();
2739
- for (const c of [...i.children].reverse()) {
2740
- let a;
2741
- switch (c.type) {
2742
- case "Mesh":
2743
- const l = he(c.geometry), u = de(c.material);
2744
- a = new E.Mesh(l, u);
2745
- break;
2746
- case "Group":
2747
- a = new E.Group();
2748
- break;
2749
- case "Object3D":
2750
- a = new E.Object3D();
2751
- break;
2752
- default:
2753
- console.warn(`Unsupported object type: ${c.type}`);
2754
- continue;
2755
- }
2756
- a && (a.name = c.name, a.position.fromArray(c.position), a.rotation.fromArray(c.rotation), a.scale.fromArray(c.scale), a.visible = c.visible, a.userData = c.userData, o.add(a), t.push({ data: c, object: a }), n++, n % e === 0 && await new Promise((l) => requestAnimationFrame(l)));
2757
- }
2758
- }
2759
- return s;
2760
- }
2761
- function Sn(r) {
2762
- const e = [];
2763
- let t;
2764
- switch (r.type) {
2765
- case "Mesh":
2766
- const s = he(r.geometry), n = de(r.material);
2767
- t = new E.Mesh(s, n);
2768
- break;
2769
- case "Group":
2770
- t = new E.Group();
2771
- break;
2772
- case "Object3D":
2773
- t = new E.Object3D();
2774
- break;
2775
- default:
2776
- return console.warn(`Unsupported object type: ${r.type}`), null;
2777
- }
2778
- for (t.name = r.name, t.position.fromArray(r.position), t.rotation.fromArray(r.rotation), t.scale.fromArray(r.scale), t.visible = r.visible, t.userData = r.userData, e.push({ data: r, object: t }); e.length > 0; ) {
2779
- const { data: s, object: n } = e.pop();
2780
- for (const i of [...s.children].reverse()) {
2781
- let o;
2782
- switch (i.type) {
2783
- case "Mesh":
2784
- const c = he(i.geometry), a = de(i.material);
2785
- o = new E.Mesh(c, a);
2786
- break;
2787
- case "Group":
2788
- o = new E.Group();
2789
- break;
2790
- case "Object3D":
2791
- o = new E.Object3D();
2792
- break;
2793
- default:
2794
- console.warn(`Unsupported object type: ${i.type}`);
2795
- continue;
2796
- }
2797
- o && (o.name = i.name, o.position.fromArray(i.position), o.rotation.fromArray(i.rotation), o.scale.fromArray(i.scale), o.visible = i.visible, o.userData = i.userData, n.add(o), e.push({ data: i, object: o }));
2798
- }
2799
- }
2800
- return t;
2801
- }
2802
- function le(r) {
2803
- const e = {}, { attributes: t, index: s, type: n } = r;
2804
- t.position && (e.position = {
2805
- type: "Float32Array",
2806
- array: Array.from(t.position.array),
2807
- itemSize: 3
2808
- }), t.normal && (e.normal = {
2809
- type: "Float32Array",
2810
- array: Array.from(t.normal.array),
2811
- itemSize: 3
2812
- }), t.uv && (e.uv = {
2813
- type: "Float32Array",
2814
- array: Array.from(t.uv.array),
2815
- itemSize: 2
2816
- });
2817
- const i = {
2818
- type: n,
2819
- attributes: e
2820
- };
2821
- return s && s.array && (i.index = {
2822
- type: "Uint32Array",
2823
- array: Array.from(s.array),
2824
- itemSize: 1
2825
- }), i;
2826
- }
2827
- function he(r) {
2828
- const { type: e, attributes: t, index: s } = r, n = new E.BufferGeometry();
2829
- for (const i in t)
2830
- if (t.hasOwnProperty(i)) {
2831
- const { type: o, array: c, itemSize: a } = t[i];
2832
- n.setAttribute(
2833
- i,
2834
- new E.BufferAttribute(new Float32Array(c), a)
2835
- );
2836
- }
2837
- return s && n.setIndex(s.array), n;
2838
- }
2839
- function ue(r) {
2840
- return {
2841
- type: r.type,
2842
- color: r.color.getHex(),
2843
- map: r.map ? r.map.image.src : null,
2844
- opacity: r.opacity,
2845
- name: r.name,
2846
- depthTest: r.depthTest,
2847
- depthWrite: r.depthWrite,
2848
- transparent: r.transparent,
2849
- side: r.side,
2850
- roughness: r.roughness,
2851
- metalness: r.metalness,
2852
- emissive: r.emissive.getHex()
2853
- };
2854
- }
2855
- function de(r) {
2856
- if (be[r.name]) return be[r.name];
2857
- const { type: e, ...t } = r, s = e || "MeshStandardMaterial", n = new E[s]({ ...t });
2858
- if (r.map) {
2859
- const i = new E.TextureLoader().load(r.map);
2860
- n.map = i;
2861
- }
2862
- return n.needsUpdate = !0, be[r.name] = n, n;
2863
- }
2864
- class nn {
2865
- constructor() {
2866
- this.stats = {
2867
- hits: 0,
2868
- // 缓存命中次数
2869
- misses: 0,
2870
- // 缓存未命中次数
2871
- totalLoadTime: 0,
2872
- // 总加载时间(ms)
2873
- cacheSaveTime: 0,
2874
- // 缓存保存时间(ms)
2875
- errors: 0
2876
- // 错误次数
2877
- }, this.loadHistory = [];
2878
- }
2879
- /**
2880
- * 记录缓存命中
2881
- * @param {number} loadTime - 加载耗时(ms)
2882
- */
2883
- recordHit(e) {
2884
- this.stats.hits++, this.stats.totalLoadTime += e, this._recordHistory("hit", e);
2885
- }
2886
- /**
2887
- * 记录缓存未命中
2888
- * @param {number} loadTime - 加载耗时(ms)
2889
- */
2890
- recordMiss(e) {
2891
- this.stats.misses++, this.stats.totalLoadTime += e, this._recordHistory("miss", e);
2892
- }
2893
- /**
2894
- * 记录缓存保存时间
2895
- * @param {number} saveTime - 保存耗时(ms)
2896
- */
2897
- recordCacheSave(e) {
2898
- this.stats.cacheSaveTime += e;
2899
- }
2900
- /**
2901
- * 记录错误
2902
- * @param {string} path - 模型路径
2903
- * @param {Error} error - 错误对象
2904
- */
2905
- recordError(e, t) {
2906
- this.stats.errors++, this._recordHistory("error", 0, { path: e, error: t.message });
2907
- }
2908
- /**
2909
- * 计算缓存命中率
2910
- * @returns {string} 命中率百分比字符串
2911
- */
2912
- getHitRate() {
2913
- const e = this.stats.hits + this.stats.misses;
2914
- return e > 0 ? (this.stats.hits / e * 100).toFixed(2) + "%" : "0%";
2915
- }
2916
- /**
2917
- * 计算平均加载时间
2918
- * @returns {string} 平均加载时间(含单位)
2919
- */
2920
- getAvgLoadTime() {
2921
- const e = this.stats.hits + this.stats.misses;
2922
- return e > 0 ? (this.stats.totalLoadTime / e).toFixed(2) + "ms" : "0ms";
2923
- }
2924
- /**
2925
- * 获取完整的统计数据
2926
- * @returns {Object} 统计数据对象
2927
- */
2928
- getStats() {
2929
- const e = this.stats.hits + this.stats.misses;
2930
- return {
2931
- 命中率: this.getHitRate(),
2932
- 平均加载时间: this.getAvgLoadTime(),
2933
- 缓存命中数: this.stats.hits,
2934
- 缓存未命中数: this.stats.misses,
2935
- 总加载次数: e,
2936
- 总加载时间: this.stats.totalLoadTime.toFixed(2) + "ms",
2937
- 缓存保存时间: this.stats.cacheSaveTime.toFixed(2) + "ms",
2938
- 错误次数: this.stats.errors
2939
- };
2940
- }
2941
- /**
2942
- * 获取最近N条加载历史
2943
- * @param {number} count - 获取条数,默认 10
2944
- * @returns {Array} 历史记录数组
2945
- */
2946
- getHistory(e = 10) {
2947
- return this.loadHistory.slice(-e);
2948
- }
2949
- /**
2950
- * 清空统计数据
2951
- */
2952
- reset() {
2953
- this.stats = {
2954
- hits: 0,
2955
- misses: 0,
2956
- totalLoadTime: 0,
2957
- cacheSaveTime: 0,
2958
- errors: 0
2959
- }, this.loadHistory = [];
2960
- }
2961
- /**
2962
- * 内部方法: 记录历史
2963
- * @private
2964
- */
2965
- _recordHistory(e, t, s = {}) {
2966
- this.loadHistory.push({
2967
- type: e,
2968
- duration: t,
2969
- timestamp: Date.now(),
2970
- ...s
2971
- }), this.loadHistory.length > 100 && this.loadHistory.shift();
2972
- }
2973
- /**
2974
- * 打印统计报告到控制台
2975
- */
2976
- logReport() {
2977
- console.group("📊 缓存性能报告");
2978
- const e = this.getStats();
2979
- Object.entries(e).forEach(([t, s]) => {
2980
- console.log(`${t}: ${s}`);
2981
- }), console.groupEnd();
2982
- }
2983
- }
2984
- const V = new nn();
2985
- class fe {
2986
- /**
2987
- * 异步操作并支持重试
2988
- * @param {Function} operation - 要执行的异步操作
2989
- * @param {RetryOptions} options - 重试配置
2990
- * @returns {Promise} 操作结果
2991
- */
2992
- static async retry(e, t = {}) {
2993
- const {
2994
- maxRetries: s = 3,
2995
- initialDelay: n = 1e3,
2996
- maxDelay: i = 1e4,
2997
- backoffFactor: o = 2,
2998
- shouldRetry: c = fe.defaultShouldRetry
2999
- } = t;
3000
- let a, l = n;
3001
- for (let u = 0; u <= s; u++)
3002
- try {
3003
- return await e();
3004
- } catch (h) {
3005
- if (a = h, u === s || !c(h, u))
3006
- throw h;
3007
- console.warn(
3008
- `[ RetryHelper ] 操作失败,第 ${u + 1} 次尝试失败,${l}ms 后进行第 ${u + 2} 次尝试...`,
3009
- h
3010
- ), await fe.delay(l), l = Math.min(l * o, i);
3011
- }
3012
- throw a;
3013
- }
3014
- /**
3015
- * 默认的重试判断逻辑
3016
- * @param {Error} error - 错误对象
3017
- * @param {number} attempt - 当前尝试次数
3018
- * @returns {boolean} 是否应该重试
3019
- */
3020
- static defaultShouldRetry(e, t) {
3021
- if (e.name === "TypeError" && e.message.includes("fetch"))
3022
- return !0;
3023
- if (e.message.includes("HTTP error")) {
3024
- const s = e.message.match(/status:\s*(\d+)/);
3025
- if (s) {
3026
- const n = parseInt(s[1], 10);
3027
- return n >= 500 || n === 429 || n === 408;
3028
- }
3029
- }
3030
- return !1;
3031
- }
3032
- /**
3033
- * 延迟指定时间
3034
- * @param {number} ms - 延迟毫秒数
3035
- * @returns {Promise}
3036
- */
3037
- static delay(e) {
3038
- return new Promise((t) => setTimeout(t, e));
3039
- }
3040
- }
3041
- const Ee = {
3042
- NETWORK: "NETWORK",
3043
- // 网络错误
3044
- PARSE: "PARSE",
3045
- // 解析错误
3046
- VERSION_MISMATCH: "VERSION",
3047
- // 版本不匹配
3048
- UNKNOWN: "UNKNOWN"
3049
- // 未知错误
3050
- };
3051
- class oe extends Error {
3052
- constructor(e, t, s, n) {
3053
- super(e), this.name = "ModelLoadError", this.type = t, this.path = s, this.originalError = n, this.timestamp = Date.now();
3054
- }
3055
- /**
3056
- * 创建网络错误
3057
- */
3058
- static networkError(e, t) {
3059
- return new oe(
3060
- `网络加载失败: ${e}`,
3061
- Ee.NETWORK,
3062
- e,
3063
- t
3064
- );
3065
- }
3066
- /**
3067
- * 创建解析错误
3068
- */
3069
- static parseError(e, t) {
3070
- return new oe(
3071
- `模型解析失败: ${e}`,
3072
- Ee.PARSE,
3073
- e,
3074
- t
3075
- );
3076
- }
3077
- /**
3078
- * 创建版本不匹配错误
3079
- */
3080
- static versionMismatchError(e, t, s) {
3081
- return new oe(
3082
- `版本不匹配: ${e} (期望: ${t}, 实际: ${s})`,
3083
- Ee.VERSION_MISMATCH,
3084
- e
3085
- );
3086
- }
3087
- }
3088
- const Ye = 4;
3089
- class qe {
3090
- /**
3091
- * 构造函数
3092
- * @param {string} dbName - 数据库名称
3093
- * @param {CacheOptions} options - 缓存配置选项
3094
- */
3095
- constructor(e = "threeJsIDBCache", t = {}) {
3096
- this.version = Ye, this.dbName = e, this.options = {
3097
- maxSize: t.maxSize || 500 * 1024 * 1024,
3098
- // 默认 500MB
3099
- maxEntries: t.maxEntries || 50,
3100
- // 默认最多 50 个模型
3101
- evictRatio: t.evictRatio || 0.2
3102
- // 淘汰 20%
3103
- }, this.dbInit();
3104
- }
3105
- dbInit() {
3106
- this.db = new es(this.dbName), this.db.version(this.version).stores({
3107
- models: "&path, version, timestamp, accessCount, size"
3108
- }).upgrade(async (e) => {
3109
- console.log("[ IDBCache 版本更新 ] ====> version", Ye);
3110
- const t = e.table("models"), s = await t.toArray();
3111
- for (const n of s)
3112
- n.data instanceof ArrayBuffer || await t.delete(n.path);
3113
- });
3114
- }
3115
- /**
3116
- * 获取 Dexie 数据库实例
3117
- * @returns {Dexie} Dexie 实例
3118
- */
3119
- getDatabase() {
3120
- return this.db;
3121
- }
3122
- async saveModel(e, t, s) {
3123
- await this.ensureCapacity(s.byteLength), await this.db.table("models").put({
3124
- path: e,
3125
- version: t,
3126
- data: s,
3127
- size: s.byteLength,
3128
- timestamp: Date.now(),
3129
- accessCount: 0
3130
- });
3131
- }
3132
- /**
3133
- * 确保缓存容量足够,不足时执行 LRU 淘汰
3134
- * @param {number} requiredSize - 需要的额外空间(字节)
3135
- */
3136
- async ensureCapacity(e) {
3137
- const t = await this.db.table("models").toArray(), s = t.reduce((c, a) => c + (a.size || 0), 0), n = t.length, i = s + e > this.options.maxSize, o = n >= this.options.maxEntries;
3138
- (i || o) && (console.log(`[ IDBCache ] ====> 容量不足,开始 LRU 淘汰. 总大小: ${(s / 1024 / 1024).toFixed(2)}MB, 条目数: ${n}`), await this.evictLRU(t));
3139
- }
3140
- /**
3141
- * 执行 LRU 淘汰策略
3142
- * @param {Array} models - 所有缓存记录
3143
- */
3144
- async evictLRU(e) {
3145
- const t = e.sort((c, a) => (c.accessCount || 0) !== (a.accessCount || 0) ? (c.accessCount || 0) - (a.accessCount || 0) : (c.timestamp || 0) - (a.timestamp || 0)), s = Math.max(1, Math.floor(t.length * this.options.evictRatio)), n = t.slice(0, s), i = n.map((c) => c.path);
3146
- await this.db.table("models").bulkDelete(i);
3147
- const o = n.reduce((c, a) => c + (a.size || 0), 0);
3148
- console.log(`[ IDBCache ] ====> LRU 淘汰完成. 删除 ${s} 个条目,释放 ${(o / 1024 / 1024).toFixed(2)}MB`);
3149
- }
3150
- async getModel(e, t) {
3151
- const s = await this.db.table("models").get(e);
3152
- return s ? s.version !== t ? (console.log("模型版本不一致, 清除当前记录"), await this.db.table("models").delete(e), null) : (await this.db.table("models").update(e, {
3153
- accessCount: (s.accessCount || 0) + 1,
3154
- timestamp: Date.now()
3155
- }), s.data) : (console.warn(`Model "${e}" not found in table models`), null);
3156
- }
3157
- // ---------------------------- ---------------------------------
3158
- /**
3159
- * 缓存模型到 IndexedDB
3160
- * @param {string} path - 主键值
3161
- * @param {THREE.Object3D} model - 要缓存的模型
3162
- * @param {string} [version] - 缓存模型版本
3163
- */
3164
- async cacheModel(e, t, s) {
3165
- console.log("[ ] ====> path, modelData, version", e, t, s);
3166
- try {
3167
- this.db.table("models").put({ version: s, path: e, data: t }).then(() => {
3168
- console.log(`Model "${e}" cached successfully in table models`);
3169
- });
3170
- } catch {
3171
- console.log(" 缓存模型失败 =====> ");
3172
- }
3173
- return t;
3174
- }
3175
- /**
3176
- * 从 IndexedDB 加载缓存的模型
3177
- * @param {string} path - 主键值
3178
- * @returns {THREE.Object3D | null} 加载的模型
3179
- */
3180
- async loadCachedModel(e, t) {
3181
- let s = null;
3182
- try {
3183
- if (s = await this.db.table("models").get(e), !s)
3184
- return console.warn(`Model "${t}" not found in table models`), null;
3185
- if (s.version !== t)
3186
- return console.log(" =====> 模型版本不一致, 清除当前记录"), await this.db.table("models").delete(e), null;
3187
- } catch {
3188
- return console.log(" =====> 查询表中模型失败"), this.db.delete().then(() => {
3189
- this.init();
3190
- }), null;
3191
- }
3192
- return s.data;
3193
- }
3194
- /**
3195
- * 获取缓存统计信息
3196
- * @returns {Promise<Object>} 缓存统计数据
3197
- */
3198
- async getStats() {
3199
- const e = await this.db.table("models").toArray(), t = e.reduce((n, i) => n + (i.size || 0), 0), s = e.reduce((n, i) => n + (i.accessCount || 0), 0);
3200
- return {
3201
- count: e.length,
3202
- totalSize: t,
3203
- totalSizeMB: (t / 1024 / 1024).toFixed(2),
3204
- maxEntries: this.options.maxEntries,
3205
- maxSizeMB: (this.options.maxSize / 1024 / 1024).toFixed(2),
3206
- usagePercentage: (t / this.options.maxSize * 100).toFixed(2),
3207
- totalAccessCount: s,
3208
- avgAccessCount: e.length > 0 ? (s / e.length).toFixed(2) : 0
3209
- };
3210
- }
3211
- /**
3212
- * 清空所有缓存
3213
- */
3214
- async clear() {
3215
- await this.db.table("models").clear(), console.log("[ IDBCache ] ====> 缓存已清空");
3216
- }
3217
- /**
3218
- * 删除指定模型缓存
3219
- * @param {string} path - 模型路径
3220
- */
3221
- async deleteModel(e) {
3222
- await this.db.table("models").delete(e);
3223
- }
3224
- }
3225
- function lt(r) {
3226
- const { geometries: e, materials: t, hierarchy: s } = r, n = /* @__PURE__ */ new Map();
3227
- e.forEach((a, l) => {
3228
- const u = on(a);
3229
- n.set(l, u);
3230
- });
3231
- const i = /* @__PURE__ */ new Map();
3232
- t.forEach((a, l) => {
3233
- const u = rn(a);
3234
- i.set(l, u);
3235
- });
3236
- const o = new E.Group();
3237
- o.name = "Scene";
3238
- const c = /* @__PURE__ */ new Map();
3239
- return s.forEach((a) => {
3240
- let l;
3241
- if (a.type === "Mesh") {
3242
- const u = a.geometryIndex >= 0 ? n.get(a.geometryIndex) : null, h = a.materialIndex >= 0 ? i.get(a.materialIndex) : null;
3243
- l = new E.Mesh(u, h);
3244
- } else a.type === "Group" ? l = new E.Group() : a.type === "Object3D" ? l = new E.Object3D() : l = new E.Object3D();
3245
- l.name = a.name, l.position.fromArray(a.position), l.rotation.fromArray(a.rotation), l.scale.fromArray(a.scale), l.visible = a.visible, c.set(a.id, l);
3246
- }), s.forEach((a) => {
3247
- const l = c.get(a.id);
3248
- if (a.parentId !== null) {
3249
- const u = c.get(a.parentId);
3250
- u && u.add(l);
3251
- } else
3252
- o.add(l);
3253
- }), o;
3254
- }
3255
- function on(r) {
3256
- const e = new E.BufferGeometry();
3257
- for (const t in r.attributes) {
3258
- const s = r.attributes[t], n = s.array;
3259
- let i;
3260
- if (n.byteLength === 0) {
3261
- console.warn(`[ sceneRebuilder ] 属性 ${t} 的数组为空`);
3262
- continue;
3263
- }
3264
- if (n.buffer && n.buffer.byteLength === 0) {
3265
- console.warn(`[ sceneRebuilder ] 属性 ${t} 的 buffer 已被转移,尝试重建`);
3266
- continue;
3267
- }
3268
- i = n;
3269
- const o = new E.BufferAttribute(i, s.itemSize);
3270
- o.normalized = s.normalized, e.setAttribute(t, o);
3271
- }
3272
- if (r.index) {
3273
- const t = r.index, s = t.array;
3274
- if (s && s.byteLength > 0) {
3275
- const n = new E.BufferAttribute(s, t.itemSize);
3276
- e.setIndex(n);
3277
- }
3278
- }
3279
- return e;
3280
- }
3281
- function rn(r) {
3282
- let e;
3283
- const t = {
3284
- color: r.color !== void 0 ? r.color : 16777215,
3285
- opacity: r.opacity !== void 0 ? r.opacity : 1,
3286
- transparent: r.transparent !== void 0 ? r.transparent : !1,
3287
- alphaTest: r.alphaTest !== void 0 ? r.alphaTest : 0,
3288
- // 关键渲染属性 - 这些缺失会导致渲染抖动和显示错误
3289
- side: r.side !== void 0 ? r.side : E.FrontSide,
3290
- depthTest: r.depthTest !== void 0 ? r.depthTest : !0,
3291
- depthWrite: r.depthWrite !== void 0 ? r.depthWrite : !0,
3292
- wireframe: r.wireframe !== void 0 ? r.wireframe : !1,
3293
- vertexColors: r.vertexColors !== void 0 ? r.vertexColors : !1
3294
- };
3295
- switch (r.type) {
3296
- case "MeshStandardMaterial":
3297
- e = new E.MeshStandardMaterial({
3298
- ...t,
3299
- roughness: r.roughness !== void 0 ? r.roughness : 0.5,
3300
- metalness: r.metalness !== void 0 ? r.metalness : 0.5,
3301
- emissive: r.emissive !== void 0 ? r.emissive : 0,
3302
- emissiveIntensity: r.emissiveIntensity !== void 0 ? r.emissiveIntensity : 1
3303
- });
3304
- break;
3305
- case "MeshBasicMaterial":
3306
- e = new E.MeshBasicMaterial({
3307
- ...t
3308
- });
3309
- break;
3310
- case "MeshPhongMaterial":
3311
- e = new E.MeshPhongMaterial({
3312
- ...t,
3313
- shininess: r.shininess !== void 0 ? r.shininess : 30,
3314
- specular: r.specular !== void 0 ? r.specular : 1118481,
3315
- emissive: r.emissive !== void 0 ? r.emissive : 0,
3316
- emissiveIntensity: r.emissiveIntensity !== void 0 ? r.emissiveIntensity : 1
3317
- });
3318
- break;
3319
- default:
3320
- e = new E.MeshStandardMaterial(t);
3321
- }
3322
- return e.uuid = r.uuid, e;
3323
- }
3324
- class Mn {
3325
- constructor() {
3326
- this.geometries = [], this.materials = [], this.hierarchy = [], this.geometryMap = /* @__PURE__ */ new Map(), this.materialMap = /* @__PURE__ */ new Map();
3327
- }
3328
- /**
3329
- * 添加场景数据块
3330
- */
3331
- addChunk(e) {
3332
- e.geometries && e.geometries.forEach((t) => {
3333
- const s = this.geometries.length;
3334
- this.geometries.push(t), this.geometryMap.set(t.uuid, s);
3335
- }), e.materials && e.materials.forEach((t) => {
3336
- const s = this.materials.length;
3337
- this.materials.push(t), this.materialMap.set(t.uuid, s);
3338
- }), e.hierarchy && this.hierarchy.push(...e.hierarchy);
3339
- }
3340
- /**
3341
- * 构建当前可渲染的场景
3342
- */
3343
- buildCurrent() {
3344
- const e = {
3345
- geometries: this.geometries,
3346
- materials: this.materials,
3347
- hierarchy: this.hierarchy
3348
- };
3349
- return lt(e);
3350
- }
3351
- /**
3352
- * 完成构建
3353
- */
3354
- finalize() {
3355
- return this.buildCurrent();
3356
- }
3357
- }
3358
- const an = "/assets/gltfParser.worker-Bqz8BBJx.js", cn = "/assets/gltfParserOptimized.worker-DfipxPjm.js";
3359
- let q;
3360
- const xe = "/draco/";
3361
- let Z, $, Ze = 0;
3362
- const B = /* @__PURE__ */ new Map(), ln = () => {
3363
- const r = new ws(), e = new _s();
3364
- e.setDecoderPath(xe), r.setDRACOLoader(e);
3365
- function t(f, g, y, p) {
3366
- return r.load(f, g, y, p);
3367
- }
3368
- function s(f, g) {
3369
- return new Promise((y, p) => {
3370
- r.load(f, y, g, p);
3371
- });
3372
- }
3373
- async function n(f, g, y, p = {}) {
3374
- const d = performance.now();
3375
- let _ = !1;
3376
- const {
3377
- maxRetries: w = 3,
3378
- optimizeMaterials: T = !1,
3379
- simplifyGeometry: A = !1,
3380
- simplifyRatio: S = 0.5,
3381
- simplifyOptions: M = {}
3382
- } = p;
3383
- try {
3384
- let R = await o(f, g);
3385
- if (R)
3386
- console.log(`[ asyncFetch ] ====> 缓存命中: ${f}`), _ = !0;
3387
- else {
3388
- console.log(`[ asyncFetch ] ====> 缓存未命中: ${f}`), console.time("[ fetchArrayBuffer ] 加载模型耗时"), R = await fe.retry(
3389
- () => i(f, y),
3390
- {
3391
- maxRetries: w,
3392
- shouldRetry: (Ce) => !!(Ce.name === "TypeError" || Ce.message.includes("HTTP error! status: 5"))
3393
- }
3394
- ), console.timeEnd("[ fetchArrayBuffer ] 加载模型耗时");
3395
- const j = performance.now();
3396
- await q.saveModel(f, g, R);
3397
- const Y = performance.now() - j;
3398
- V.recordCacheSave(Y), _ = !1;
3399
- }
3400
- console.time("[ 解析模型耗时 ]");
3401
- let D = await c(R);
3402
- if (console.timeEnd("[ 解析模型耗时 ]"), console.time("[ 模型优化耗时 ]"), T) {
3403
- console.log("🔧 [ 材质优化 ] 开始合并相同材质...");
3404
- const { modelOptimizer: j } = await import("./modelOptimizer-BRPnM2RH.js");
3405
- D = j.optimizeMaterials(D);
3406
- }
3407
- if (A) {
3408
- console.log(`🔧 [ 几何体简化 ] 开始简化模型 (比例: ${S})...`);
3409
- const { modelOptimizer: j } = await import("./modelOptimizer-BRPnM2RH.js"), Y = {
3410
- minFaceCount: 100,
3411
- preserveUVs: !0,
3412
- ...M
3413
- };
3414
- D = j.simplifyModel(D, S, Y);
3415
- }
3416
- console.timeEnd("[ 模型优化耗时 ]");
3417
- const H = performance.now() - d;
3418
- return _ ? V.recordHit(H) : V.recordMiss(H), D;
3419
- } catch (R) {
3420
- throw console.error(`加载模型 ${f} 失败:`, R), V.recordError(f, R), R.name === "TypeError" && R.message.includes("fetch") ? oe.networkError(f, R) : R;
3421
- }
3422
- }
3423
- async function i(f, g) {
3424
- return new Promise((y, p) => {
3425
- fetch(f).then((d) => {
3426
- if (!d.ok)
3427
- throw new Error(`HTTP error! status: ${d.status}`);
3428
- return d;
3429
- }).then((d) => {
3430
- const _ = d.headers.get("content-length"), w = _ ? parseInt(_, 10) : 0;
3431
- if (g && w > 0) {
3432
- const T = d.body.getReader();
3433
- let A = 0;
3434
- const S = [], M = () => {
3435
- T.read().then(({ done: R, value: D }) => {
3436
- if (R) {
3437
- const H = new Uint8Array(A);
3438
- let j = 0;
3439
- for (const Y of S)
3440
- H.set(Y, j), j += Y.length;
3441
- y(H.buffer);
3442
- return;
3443
- }
3444
- S.push(D), A += D.length, g(Math.round(A / w * 100)), M();
3445
- }).catch(p);
3446
- };
3447
- M();
3448
- } else
3449
- return d.arrayBuffer();
3450
- }).then((d) => y(d)).catch((d) => {
3451
- p(d);
3452
- });
3453
- });
3454
- }
3455
- async function o(f, g) {
3456
- return q || (q = new qe()), q.getModel(f, g);
3457
- }
3458
- async function c(f, g = {}) {
3459
- if (!f) return null;
3460
- const { useOptimizedParser: y = !0, useProgressive: p = !1 } = g;
3461
- if (y) {
3462
- const w = l();
3463
- if (w)
3464
- try {
3465
- console.time("[ 优化解析 ] 使用 Transferable Objects 解析");
3466
- const T = await u(w, f, p);
3467
- return console.timeEnd("[ 优化解析 ] 使用 Transferable Objects 解析"), lt(T);
3468
- } catch (T) {
3469
- console.warn("[ 优化解析 ] 失败,回退到标准解析", T);
3470
- }
3471
- }
3472
- const d = a();
3473
- if (d)
3474
- try {
3475
- const w = await h(d, f);
3476
- return sn(w);
3477
- } catch (w) {
3478
- console.warn("[ GLTF Worker ] ====> 解析失败,回退到主线程解析", w);
3479
- }
3480
- return (await m(f)).scene;
3481
- }
3482
- const a = () => typeof window > "u" || typeof Worker > "u" ? null : (Z || (Z = new Worker(an, { type: "module" }), Z.onmessage = (f) => {
3483
- const { id: g, data: y, error: p } = f.data || {};
3484
- if (!g || !B.has(g)) return;
3485
- const { resolve: d, reject: _ } = B.get(g);
3486
- B.delete(g), p ? _(new Error(p)) : d(y);
3487
- }, Z.onmessageerror = (f) => {
3488
- console.error("[ GLTF Worker ] ====> 消息解析失败", f);
3489
- }, Z.onerror = (f) => {
3490
- console.error("[ GLTF Worker ] ====> 运行错误", f);
3491
- }), Z), l = () => {
3492
- if (typeof window > "u" || typeof Worker > "u")
3493
- return null;
3494
- if (!$)
3495
- try {
3496
- $ = new Worker(cn, { type: "module" }), $.onmessage = (f) => {
3497
- const { id: g, data: y, error: p, type: d } = f.data || {};
3498
- if (!g || !B.has(g) || d === "progress")
3499
- return;
3500
- const { resolve: _, reject: w } = B.get(g);
3501
- B.delete(g), p ? w(new Error(p)) : _(y);
3502
- }, $.onmessageerror = (f) => {
3503
- console.error("[ 优化 Worker ] ====> 消息解析失败", f);
3504
- }, $.onerror = (f) => {
3505
- console.error("[ 优化 Worker ] ====> 运行错误", f);
3506
- };
3507
- } catch (f) {
3508
- return console.warn("[ 优化 Worker ] ====> 创建失败,可能不支持模块化 Worker", f), null;
3509
- }
3510
- return $;
3511
- }, u = (f, g, y = !1) => new Promise((p, d) => {
3512
- const _ = ++Ze;
3513
- B.set(_, { resolve: p, reject: d });
3514
- const w = {
3515
- id: _,
3516
- arrayBuffer: g,
3517
- dracoPath: xe,
3518
- mode: y ? "progressive" : "standard"
3519
- };
3520
- f.postMessage(w, [g]);
3521
- }), h = (f, g) => new Promise((y, p) => {
3522
- const d = ++Ze;
3523
- B.set(d, { resolve: y, reject: p }), f.postMessage({ id: d, arrayBuffer: g, dracoPath: xe });
3524
- }), m = (f) => new Promise((g, y) => {
3525
- r.parse(f, "", g, y);
3526
- });
3527
- return {
3528
- load: t,
3529
- asyncLoad: s,
3530
- asyncCacheLoad: n,
3531
- asyncFetch: n,
3532
- /**
3533
- * 获取缓存统计信息
3534
- * @returns {Object} 统计数据
3535
- */
3536
- getCacheStats: () => V.getStats(),
3537
- /**
3538
- * 获取缓存实例
3539
- * @returns {IDBCache} 缓存实例
3540
- */
3541
- getCache: () => q || (q = new qe()),
3542
- /**
3543
- * 打印缓存性能报告
3544
- */
3545
- logCacheReport: () => V.logReport(),
3546
- /**
3547
- * 重置缓存统计
3548
- */
3549
- resetCacheStats: () => V.reset()
3550
- };
3551
- };
3552
- class hn {
3553
- constructor(e = {}) {
3554
- this.options = {
3555
- maxPreloadCount: e.maxPreloadCount || 5,
3556
- preloadDelay: e.preloadDelay || 1e3,
3557
- enableLearning: e.enableLearning !== !1
3558
- }, this.loadHistory = /* @__PURE__ */ new Map(), this.loadSequence = [], this.associations = /* @__PURE__ */ new Map(), this.preloadQueue = /* @__PURE__ */ new Set(), this.isPreloading = !1, this.loader = null, this.getLoader = () => (this.loader || (this.loader = ln()), this.loader);
3559
- }
3560
- /**
3561
- * 记录模型加载
3562
- * @param {string} path - 模型路径
3563
- * @param {string} version - 模型版本
3564
- */
3565
- recordLoad(e, t) {
3566
- const s = Date.now(), n = this.loadHistory.get(e) || {
3567
- count: 0,
3568
- lastLoadTime: 0,
3569
- versions: /* @__PURE__ */ new Set()
3570
- };
3571
- n.count++, n.lastLoadTime = s, n.versions.add(t), this.loadHistory.set(e, n), this.loadSequence.push({ path: e, timestamp: s }), this.loadSequence.length > 100 && this.loadSequence.shift(), this.options.enableLearning && this.loadSequence.length >= 2 && this._learnAssociations(e), this._triggerPredictivePreload(e, t);
3572
- }
3573
- /**
3574
- * 学习模型关联规则
3575
- * @private
3576
- * @param {string} currentPath - 当前加载的模型
3577
- */
3578
- _learnAssociations(e) {
3579
- const s = this.loadSequence.length - 1;
3580
- for (let n = Math.max(0, s - 10); n < s; n++) {
3581
- const { path: i } = this.loadSequence[n];
3582
- if (this.loadSequence[s].timestamp - this.loadSequence[n].timestamp < 5 * 60 * 1e3 && i !== e) {
3583
- this.associations.has(i) || this.associations.set(i, /* @__PURE__ */ new Map());
3584
- const c = this.associations.get(i), a = c.get(e) || 0;
3585
- c.set(e, a + 1);
3586
- }
3587
- }
3588
- }
3589
- /**
3590
- * 触发预测性预加载
3591
- * @private
3592
- * @param {string} currentPath - 当前加载的模型
3593
- * @param {string} version - 模型版本
3594
- */
3595
- _triggerPredictivePreload(e, t) {
3596
- setTimeout(() => {
3597
- const s = this.predictNext(e);
3598
- this.preload(s, t);
3599
- }, this.options.preloadDelay);
3600
- }
3601
- /**
3602
- * 预测下一个可能加载的模型
3603
- * @param {string} currentPath - 当前模型路径
3604
- * @returns {Array<string>} 预测的模型路径列表
3605
- */
3606
- predictNext(e) {
3607
- const t = /* @__PURE__ */ new Map(), s = this.associations.get(e);
3608
- s && s.forEach((c, a) => {
3609
- t.set(a, (t.get(a) || 0) + c * 2);
3610
- });
3611
- const n = Array.from(this.loadHistory.values()).reduce((c, a) => c + a.count, 0) / (this.loadHistory.size || 1);
3612
- this.loadHistory.forEach((c, a) => {
3613
- if (a !== e) {
3614
- const l = c.count / n;
3615
- t.set(a, (t.get(a) || 0) + l);
3616
- }
3617
- });
3618
- const i = this.loadSequence.slice(-10);
3619
- return new Set(i.map((c) => c.path)).forEach((c) => {
3620
- c !== e && t.set(c, (t.get(c) || 0) + 0.5);
3621
- }), Array.from(t.entries()).sort((c, a) => a[1] - c[1]).slice(0, this.options.maxPreloadCount).map(([c]) => c);
3622
- }
3623
- /**
3624
- * 预加载模型列表
3625
- * @param {Array<string>} paths - 模型路径列表
3626
- * @param {string} version - 模型版本
3627
- */
3628
- async preload(e, t = "latest") {
3629
- if (this.isPreloading)
3630
- return;
3631
- this.isPreloading = !0;
3632
- const { asyncFetch: s } = this.getLoader(), n = e.filter((i) => !this.preloadQueue.has(i)).slice(0, this.options.maxPreloadCount).map(async (i) => {
3633
- this.preloadQueue.add(i);
3634
- try {
3635
- console.log(`[ 智能预加载 ] 开始预加载: ${i}`), await s(i, t), console.log(`[ 智能预加载 ] 完成: ${i}`);
3636
- } catch (o) {
3637
- console.warn(`[ 智能预加载 ] 失败: ${i}`, o);
3638
- } finally {
3639
- this.preloadQueue.delete(i);
3640
- }
3641
- });
3642
- await Promise.all(n), this.isPreloading = !1;
3643
- }
3644
- /**
3645
- * 手动添加关联规则
3646
- * @param {string} fromPath - 源模型路径
3647
- * @param {Array<string>} toPaths - 关联的模型路径列表
3648
- */
3649
- addAssociation(e, t) {
3650
- this.associations.has(e) || this.associations.set(e, /* @__PURE__ */ new Map());
3651
- const s = this.associations.get(e);
3652
- t.forEach((n) => {
3653
- const i = s.get(n) || 0;
3654
- s.set(n, i + 10);
3655
- });
3656
- }
3657
- /**
3658
- * 获取加载统计信息
3659
- * @returns {Object} 统计数据
3660
- */
3661
- getStats() {
3662
- const e = Array.from(this.loadHistory.entries()).sort((t, s) => s[1].count - t[1].count).slice(0, 10).map(([t, s]) => ({
3663
- path: t,
3664
- loadCount: s.count,
3665
- lastLoadTime: new Date(s.lastLoadTime).toLocaleString()
3666
- }));
3667
- return {
3668
- totalModelsLoaded: this.loadHistory.size,
3669
- totalAssociations: this.associations.size,
3670
- topModels: e,
3671
- preloadQueueSize: this.preloadQueue.size
3672
- };
3673
- }
3674
- /**
3675
- * 清空历史记录
3676
- */
3677
- clearHistory() {
3678
- this.loadHistory.clear(), this.loadSequence = [], this.associations.clear();
3679
- }
3680
- /**
3681
- * 导出关联规则(可持久化)
3682
- * @returns {Object} 关联规则数据
3683
- */
3684
- exportAssociations() {
3685
- const e = {};
3686
- return this.associations.forEach((t, s) => {
3687
- e[s] = Array.from(t.entries());
3688
- }), e;
3689
- }
3690
- /**
3691
- * 导入关联规则
3692
- * @param {Object} data - 关联规则数据
3693
- */
3694
- importAssociations(e) {
3695
- Object.entries(e).forEach(([t, s]) => {
3696
- const n = new Map(s);
3697
- this.associations.set(t, n);
3698
- });
3699
- }
3700
- }
3701
- const Ln = new hn();
3702
- export {
3703
- nn as C,
3704
- Ee as E,
3705
- qe as I,
3706
- oe as M,
3707
- hn as P,
3708
- fe as R,
3709
- ie as S,
3710
- gn as a,
3711
- yn as b,
3712
- mn as c,
3713
- _n as d,
3714
- Tn as e,
3715
- wn as f,
3716
- bn as g,
3717
- En as h,
3718
- xn as i,
3719
- tn as j,
3720
- Rn as k,
3721
- sn as l,
3722
- Sn as m,
3723
- V as n,
3724
- An as o,
3725
- Ln as p,
3726
- Mn as q,
3727
- lt as r,
3728
- pn as s,
3729
- fn as t,
3730
- ln as u
3731
- };