@ridp/threejs 1.4.2 → 1.4.4

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