@ridp/threejs 1.4.3 → 1.4.5
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.
- package/dist/ImageLoader-6mmE7g5P.cjs +24 -0
- package/dist/ImageLoader-CnBqJLru.js +1444 -0
- package/dist/PredictiveLoader-DTN7SDRI.js +3842 -0
- package/dist/PredictiveLoader-KOCZXzGy.cjs +2 -0
- package/dist/assets/{gltfParser.worker-Bqz8BBJx.js → gltfParser.worker-D2lwod50.js} +2 -2
- package/dist/assets/{gltfParserOptimized.worker-DfipxPjm.js → gltfParserOptimized.worker-yo8WMPFM.js} +2 -2
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +9 -12
- package/dist/{packages/threejs/src/utils/modelOptimizer.js → modelOptimizer-D6fRg-DF.js} +1 -1
- package/dist/threejs.cjs +3 -1
- package/dist/threejs.js +428 -58
- package/dist/useBatchGLTFLoader-19GZ1dxv.cjs +5 -0
- package/dist/useBatchGLTFLoader-DPT0_95u.js +493 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +32 -40
- package/package.json +1 -1
- package/dist/packages/threejs/package.json.cjs +0 -1
- package/dist/packages/threejs/package.json.js +0 -4
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useBatchGLTFLoader.js +0 -83
- package/dist/packages/threejs/src/hooks/useGLTFLoader.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useGLTFLoader.js +0 -292
- package/dist/packages/threejs/src/hooks/useObb.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useObb.js +0 -41
- package/dist/packages/threejs/src/hooks/useRaycaster.cjs +0 -1
- package/dist/packages/threejs/src/hooks/useRaycaster.js +0 -35
- package/dist/packages/threejs/src/hooks/useThreeJs.cjs +0 -5
- package/dist/packages/threejs/src/hooks/useThreeJs.js +0 -153
- package/dist/packages/threejs/src/instance/IDBCache.cjs +0 -1
- package/dist/packages/threejs/src/instance/IDBCache.js +0 -142
- package/dist/packages/threejs/src/instance/threeIns.cjs +0 -3
- package/dist/packages/threejs/src/instance/threeIns.js +0 -393
- package/dist/packages/threejs/src/utils/CacheMonitor.cjs +0 -1
- package/dist/packages/threejs/src/utils/CacheMonitor.js +0 -125
- package/dist/packages/threejs/src/utils/ImageLoader.cjs +0 -1
- package/dist/packages/threejs/src/utils/ImageLoader.js +0 -33
- package/dist/packages/threejs/src/utils/PredictiveLoader.cjs +0 -1
- package/dist/packages/threejs/src/utils/PredictiveLoader.js +0 -155
- package/dist/packages/threejs/src/utils/RetryHelper.cjs +0 -1
- package/dist/packages/threejs/src/utils/RetryHelper.js +0 -108
- package/dist/packages/threejs/src/utils/common.cjs +0 -1
- package/dist/packages/threejs/src/utils/common.js +0 -15
- package/dist/packages/threejs/src/utils/css3dHelper.cjs +0 -15
- package/dist/packages/threejs/src/utils/css3dHelper.js +0 -42
- package/dist/packages/threejs/src/utils/disposeObject.cjs +0 -1
- package/dist/packages/threejs/src/utils/disposeObject.js +0 -13
- package/dist/packages/threejs/src/utils/helper.cjs +0 -1
- package/dist/packages/threejs/src/utils/helper.js +0 -47
- package/dist/packages/threejs/src/utils/modelSerialize.cjs +0 -1
- package/dist/packages/threejs/src/utils/modelSerialize.js +0 -225
- package/dist/packages/threejs/src/utils/sceneRebuilder.cjs +0 -1
- package/dist/packages/threejs/src/utils/sceneRebuilder.js +0 -138
- package/dist/packages/threejs/src/workers/gltfParser.worker.cjs +0 -1
- package/dist/packages/threejs/src/workers/gltfParser.worker.js +0 -11
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.cjs +0 -1
- package/dist/packages/threejs/src/workers/gltfParserOptimized.worker.js +0 -11
- /package/dist/{packages/threejs/src/utils/modelOptimizer.cjs → modelOptimizer-A0Cs6f9e.cjs} +0 -0
|
@@ -0,0 +1,3842 @@
|
|
|
1
|
+
import * as A from "three";
|
|
2
|
+
import { Controls as gt, Vector3 as S, MOUSE as B, TOUCH as V, Quaternion as le, Spherical as Ue, Vector2 as k, Ray as yt, Plane as _t, MathUtils as nt, TrianglesDrawMode as Tt, TriangleFanDrawMode as De, TriangleStripDrawMode as it, Loader as ot, FileLoader as de, SRGBColorSpace as Y, LinearSRGBColorSpace as U, BufferGeometry as rt, BufferAttribute as oe, Color as q, ColorManagement as Pe, LoaderUtils as re, MeshPhysicalMaterial as j, SpotLight as wt, PointLight as bt, DirectionalLight as Et, Matrix4 as se, InstancedMesh as xt, InstancedBufferAttribute as At, Object3D as ve, TextureLoader as Mt, ImageBitmapLoader as Rt, InterleavedBuffer as St, InterleavedBufferAttribute as Lt, LinearMipmapLinearFilter as at, NearestMipmapLinearFilter as Dt, LinearMipmapNearestFilter as Pt, NearestMipmapNearestFilter as Ct, LinearFilter as Ce, NearestFilter as ct, RepeatWrapping as Oe, MirroredRepeatWrapping as Ot, ClampToEdgeWrapping as kt, PointsMaterial as It, Material as Te, LineBasicMaterial as Nt, MeshStandardMaterial as lt, DoubleSide as vt, MeshBasicMaterial as ie, PropertyBinding as Ht, SkinnedMesh as Ft, Mesh as Ut, LineSegments as jt, Line as Gt, LineLoop as Bt, Points as zt, Group as we, PerspectiveCamera as Kt, OrthographicCamera as Wt, Skeleton as Xt, AnimationClip as Vt, Bone as Yt, InterpolateDiscrete as qt, InterpolateLinear as ht, Texture as je, VectorKeyframeTrack as Ge, NumberKeyframeTrack as Be, QuaternionKeyframeTrack as ze, FrontSide as $t, Interpolant as Zt, Box3 as Qt, Sphere as Jt, CameraHelper as es, GridHelper as ts, BoxHelper as ss, Raycaster as ns, AxesHelper as is, ArrowHelper as os } from "three";
|
|
3
|
+
import rs from "dexie";
|
|
4
|
+
const Ke = { type: "change" }, He = { type: "start" }, ut = { type: "end" }, ue = new yt(), We = new _t(), as = Math.cos(70 * nt.DEG2RAD), L = new S(), O = 2 * Math.PI, M = {
|
|
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 dt extends gt {
|
|
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 = M.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 Ue(), this._sphericalDelta = new Ue(), 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 = ls.bind(this), this._onPointerDown = cs.bind(this), this._onPointerUp = hs.bind(this), this._onContextMenu = ys.bind(this), this._onMouseWheel = fs.bind(this), this._onKeyDown = ps.bind(this), this._onTouchStart = ms.bind(this), this._onTouchMove = gs.bind(this), this._onMouseDown = us.bind(this), this._onMouseMove = ds.bind(this), this._interceptControlDown = _s.bind(this), this._interceptControlUp = Ts.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(Ke), this.update(), this.state = M.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 === M.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)) < as ? this.object.lookAt(this.target) : (We.setFromNormalAndCoplanarPoint(this.object.up, this.target), ue.intersectPlane(We, 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(Ke), 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 cs(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 ls(r) {
|
|
314
|
+
this.enabled !== !1 && (r.pointerType === "touch" ? this._onTouchMove(r) : this._onMouseMove(r));
|
|
315
|
+
}
|
|
316
|
+
function hs(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(ut), this.state = M.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 us(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 = M.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 = M.PAN;
|
|
351
|
+
} else {
|
|
352
|
+
if (this.enableRotate === !1) return;
|
|
353
|
+
this._handleMouseDownRotate(r), this.state = M.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 = M.ROTATE;
|
|
360
|
+
} else {
|
|
361
|
+
if (this.enablePan === !1) return;
|
|
362
|
+
this._handleMouseDownPan(r), this.state = M.PAN;
|
|
363
|
+
}
|
|
364
|
+
break;
|
|
365
|
+
default:
|
|
366
|
+
this.state = M.NONE;
|
|
367
|
+
}
|
|
368
|
+
this.state !== M.NONE && this.dispatchEvent(He);
|
|
369
|
+
}
|
|
370
|
+
function ds(r) {
|
|
371
|
+
switch (this.state) {
|
|
372
|
+
case M.ROTATE:
|
|
373
|
+
if (this.enableRotate === !1) return;
|
|
374
|
+
this._handleMouseMoveRotate(r);
|
|
375
|
+
break;
|
|
376
|
+
case M.DOLLY:
|
|
377
|
+
if (this.enableZoom === !1) return;
|
|
378
|
+
this._handleMouseMoveDolly(r);
|
|
379
|
+
break;
|
|
380
|
+
case M.PAN:
|
|
381
|
+
if (this.enablePan === !1) return;
|
|
382
|
+
this._handleMouseMovePan(r);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function fs(r) {
|
|
387
|
+
this.enabled === !1 || this.enableZoom === !1 || this.state !== M.NONE || (r.preventDefault(), this.dispatchEvent(He), this._handleMouseWheel(this._customWheelEvent(r)), this.dispatchEvent(ut));
|
|
388
|
+
}
|
|
389
|
+
function ps(r) {
|
|
390
|
+
this.enabled !== !1 && this._handleKeyDown(r);
|
|
391
|
+
}
|
|
392
|
+
function ms(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 = M.TOUCH_ROTATE;
|
|
399
|
+
break;
|
|
400
|
+
case V.PAN:
|
|
401
|
+
if (this.enablePan === !1) return;
|
|
402
|
+
this._handleTouchStartPan(r), this.state = M.TOUCH_PAN;
|
|
403
|
+
break;
|
|
404
|
+
default:
|
|
405
|
+
this.state = M.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 = M.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 = M.TOUCH_DOLLY_ROTATE;
|
|
417
|
+
break;
|
|
418
|
+
default:
|
|
419
|
+
this.state = M.NONE;
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
default:
|
|
423
|
+
this.state = M.NONE;
|
|
424
|
+
}
|
|
425
|
+
this.state !== M.NONE && this.dispatchEvent(He);
|
|
426
|
+
}
|
|
427
|
+
function gs(r) {
|
|
428
|
+
switch (this._trackPointer(r), this.state) {
|
|
429
|
+
case M.TOUCH_ROTATE:
|
|
430
|
+
if (this.enableRotate === !1) return;
|
|
431
|
+
this._handleTouchMoveRotate(r), this.update();
|
|
432
|
+
break;
|
|
433
|
+
case M.TOUCH_PAN:
|
|
434
|
+
if (this.enablePan === !1) return;
|
|
435
|
+
this._handleTouchMovePan(r), this.update();
|
|
436
|
+
break;
|
|
437
|
+
case M.TOUCH_DOLLY_PAN:
|
|
438
|
+
if (this.enableZoom === !1 && this.enablePan === !1) return;
|
|
439
|
+
this._handleTouchMoveDollyPan(r), this.update();
|
|
440
|
+
break;
|
|
441
|
+
case M.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 = M.NONE;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function ys(r) {
|
|
450
|
+
this.enabled !== !1 && r.preventDefault();
|
|
451
|
+
}
|
|
452
|
+
function _s(r) {
|
|
453
|
+
r.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
|
|
454
|
+
}
|
|
455
|
+
function Ts(r) {
|
|
456
|
+
r.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
|
|
457
|
+
}
|
|
458
|
+
class ws extends dt {
|
|
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 Xe(r, e) {
|
|
464
|
+
if (e === Tt)
|
|
465
|
+
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), r;
|
|
466
|
+
if (e === De || e === it) {
|
|
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 === De)
|
|
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 bs extends ot {
|
|
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 rt();
|
|
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), Pe.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 = Es.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 Es() {
|
|
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 xs extends ot {
|
|
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 Ls(t);
|
|
774
|
+
}), this.register(function(t) {
|
|
775
|
+
return new Ds(t);
|
|
776
|
+
}), this.register(function(t) {
|
|
777
|
+
return new Fs(t);
|
|
778
|
+
}), this.register(function(t) {
|
|
779
|
+
return new Us(t);
|
|
780
|
+
}), this.register(function(t) {
|
|
781
|
+
return new js(t);
|
|
782
|
+
}), this.register(function(t) {
|
|
783
|
+
return new Cs(t);
|
|
784
|
+
}), this.register(function(t) {
|
|
785
|
+
return new Os(t);
|
|
786
|
+
}), this.register(function(t) {
|
|
787
|
+
return new ks(t);
|
|
788
|
+
}), this.register(function(t) {
|
|
789
|
+
return new Is(t);
|
|
790
|
+
}), this.register(function(t) {
|
|
791
|
+
return new Ss(t);
|
|
792
|
+
}), this.register(function(t) {
|
|
793
|
+
return new Ns(t);
|
|
794
|
+
}), this.register(function(t) {
|
|
795
|
+
return new Ps(t);
|
|
796
|
+
}), this.register(function(t) {
|
|
797
|
+
return new Hs(t);
|
|
798
|
+
}), this.register(function(t) {
|
|
799
|
+
return new vs(t);
|
|
800
|
+
}), this.register(function(t) {
|
|
801
|
+
return new Ms(t);
|
|
802
|
+
}), this.register(function(t) {
|
|
803
|
+
return new Gs(t);
|
|
804
|
+
}), this.register(function(t) {
|
|
805
|
+
return new Bs(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)) === ft) {
|
|
906
|
+
try {
|
|
907
|
+
o[b.KHR_BINARY_GLTF] = new zs(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 sn(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 Ks(i, this.dracoLoader);
|
|
943
|
+
break;
|
|
944
|
+
case b.KHR_TEXTURE_TRANSFORM:
|
|
945
|
+
o[h] = new Ws();
|
|
946
|
+
break;
|
|
947
|
+
case b.KHR_MESH_QUANTIZATION:
|
|
948
|
+
o[h] = new Xs();
|
|
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 As() {
|
|
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 Ms {
|
|
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 Et(u), l.target.position.set(0, 0, -1), l.add(l.target);
|
|
1035
|
+
break;
|
|
1036
|
+
case "point":
|
|
1037
|
+
l = new bt(u), l.distance = h;
|
|
1038
|
+
break;
|
|
1039
|
+
case "spot":
|
|
1040
|
+
l = new wt(u), l.distance = h, a.spot = a.spot || {}, a.spot.innerConeAngle = a.spot.innerConeAngle !== void 0 ? a.spot.innerConeAngle : 0, a.spot.outerConeAngle = a.spot.outerConeAngle !== void 0 ? a.spot.outerConeAngle : Math.PI / 4, l.angle = a.spot.outerConeAngle, l.penumbra = 1 - a.spot.innerConeAngle / a.spot.outerConeAngle, l.target.position.set(0, 0, -1), l.add(l.target);
|
|
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 Ss {
|
|
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 Ls {
|
|
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 Ds {
|
|
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 Cs {
|
|
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 Os {
|
|
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 ks {
|
|
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 Is {
|
|
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 Ns {
|
|
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 vs {
|
|
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 Hs {
|
|
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 Fs {
|
|
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 Us {
|
|
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 js {
|
|
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 Gs {
|
|
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 Bs {
|
|
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 xt(_.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 At(E.array, E.itemSize, E.normalized);
|
|
1367
|
+
} else y !== "TRANSLATION" && y !== "ROTATION" && y !== "SCALE" && _.geometry.setAttribute(y, a[y]);
|
|
1368
|
+
ve.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 ft = "glTF", ne = 12, Ve = { JSON: 1313821514, BIN: 5130562 };
|
|
1375
|
+
class zs {
|
|
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 !== ft)
|
|
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 === Ve.JSON) {
|
|
1394
|
+
const l = new Uint8Array(e, ne + o, c);
|
|
1395
|
+
this.content = n.decode(l);
|
|
1396
|
+
} else if (a === Ve.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 Ks {
|
|
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 Ws {
|
|
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 Xs {
|
|
1447
|
+
constructor() {
|
|
1448
|
+
this.name = b.KHR_MESH_QUANTIZATION;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
class pt extends Zt {
|
|
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, R = o[_ + y + c], P = o[_ + y] * u;
|
|
1465
|
+
i[y] = g * E + T * x + d * R + f * P;
|
|
1466
|
+
}
|
|
1467
|
+
return i;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
const Vs = new le();
|
|
1471
|
+
class Ys extends pt {
|
|
1472
|
+
interpolate_(e, t, n, s) {
|
|
1473
|
+
const i = super.interpolate_(e, t, n, s);
|
|
1474
|
+
return Vs.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
|
+
}, Ye = {
|
|
1493
|
+
9728: ct,
|
|
1494
|
+
9729: Ce,
|
|
1495
|
+
9984: Ct,
|
|
1496
|
+
9985: Pt,
|
|
1497
|
+
9986: Dt,
|
|
1498
|
+
9987: at
|
|
1499
|
+
}, qe = {
|
|
1500
|
+
33071: kt,
|
|
1501
|
+
33648: Ot,
|
|
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
|
+
}, qs = {
|
|
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: ht,
|
|
1532
|
+
STEP: qt
|
|
1533
|
+
}, Ae = {
|
|
1534
|
+
OPAQUE: "OPAQUE",
|
|
1535
|
+
MASK: "MASK",
|
|
1536
|
+
BLEND: "BLEND"
|
|
1537
|
+
};
|
|
1538
|
+
function $s(r) {
|
|
1539
|
+
return r.DefaultMaterial === void 0 && (r.DefaultMaterial = new lt({
|
|
1540
|
+
color: 16777215,
|
|
1541
|
+
emissive: 0,
|
|
1542
|
+
metalness: 1,
|
|
1543
|
+
roughness: 1,
|
|
1544
|
+
transparent: !1,
|
|
1545
|
+
depthTest: !0,
|
|
1546
|
+
side: $t
|
|
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 Zs(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 Qs(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 Js(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 + ":" + Me(t.attributes) : e = r.indices + ":" + Me(r.attributes) + ":" + r.mode, r.targets !== void 0)
|
|
1606
|
+
for (let n = 0, s = r.targets.length; n < s; n++)
|
|
1607
|
+
e += ":" + Me(r.targets[n]);
|
|
1608
|
+
return e;
|
|
1609
|
+
}
|
|
1610
|
+
function Me(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 en(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 tn = new se();
|
|
1635
|
+
class sn {
|
|
1636
|
+
constructor(e = {}, t = {}) {
|
|
1637
|
+
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new As(), 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 Mt(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 St(w, m / u), t.cache.add(g, T)), d = new Lt(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 R = 0, P = E.length; R < P; R++) {
|
|
1902
|
+
const C = E[R];
|
|
1903
|
+
if (d.setX(C, x[R * a]), a >= 2 && d.setY(C, x[R * a + 1]), a >= 3 && d.setZ(C, x[R * a + 2]), a >= 4 && d.setW(C, x[R * 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 = Ye[p.magFilter] || Ce, u.minFilter = Ye[p.minFilter] || at, u.wrapS = qe[p.wrapS] || Oe, u.wrapT = qe[p.wrapT] || Oe, u.generateMipmaps = !u.isCompressedTexture && u.minFilter !== ct && 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 je(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 || en(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 It(), 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 Nt(), 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 lt;
|
|
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 = vt);
|
|
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 = Ht.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 $e(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 = Js(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 = $e(new rt(), 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 ? $s(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 Ft(w, g) : new Ut(w, g), f.isSkinnedMesh === !0 && f.normalizeSkinWeights(), d.mode === I.TRIANGLE_STRIP ? f.geometry = Xe(f.geometry, it) : d.mode === I.TRIANGLE_FAN && (f.geometry = Xe(f.geometry, De));
|
|
2127
|
+
else if (d.mode === I.LINES)
|
|
2128
|
+
f = new jt(w, g);
|
|
2129
|
+
else if (d.mode === I.LINE_STRIP)
|
|
2130
|
+
f = new Gt(w, g);
|
|
2131
|
+
else if (d.mode === I.LINE_LOOP)
|
|
2132
|
+
f = new Bt(w, g);
|
|
2133
|
+
else if (d.mode === I.POINTS)
|
|
2134
|
+
f = new zt(w, g);
|
|
2135
|
+
else
|
|
2136
|
+
throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + d.mode);
|
|
2137
|
+
Object.keys(f.geometry.morphAttributes).length > 0 && Qs(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 Kt(nt.radToDeg(s.yfov), s.aspectRatio || 1, s.znear || 1, s.zfar || 2e6) : n.type === "orthographic" && (t = new Wt(-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 Xt(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], R = w[g], P = d[g];
|
|
2217
|
+
if (y === void 0) continue;
|
|
2218
|
+
y.updateMatrix && y.updateMatrix();
|
|
2219
|
+
const C = n._createAnimationTracks(y, E, x, R, P);
|
|
2220
|
+
if (C)
|
|
2221
|
+
for (let z = 0; z < C.length; z++)
|
|
2222
|
+
f.push(C[z]);
|
|
2223
|
+
}
|
|
2224
|
+
return new Vt(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, tn);
|
|
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 Yt() : l.length > 1 ? u = new we() : l.length === 1 ? u = l[0] : u = new ve(), 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 je) && 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 = Be;
|
|
2335
|
+
break;
|
|
2336
|
+
case K.rotation:
|
|
2337
|
+
l = ze;
|
|
2338
|
+
break;
|
|
2339
|
+
case K.translation:
|
|
2340
|
+
case K.scale:
|
|
2341
|
+
l = Ge;
|
|
2342
|
+
break;
|
|
2343
|
+
default:
|
|
2344
|
+
switch (n.itemSize) {
|
|
2345
|
+
case 1:
|
|
2346
|
+
l = Be;
|
|
2347
|
+
break;
|
|
2348
|
+
case 2:
|
|
2349
|
+
case 3:
|
|
2350
|
+
default:
|
|
2351
|
+
l = Ge;
|
|
2352
|
+
break;
|
|
2353
|
+
}
|
|
2354
|
+
break;
|
|
2355
|
+
}
|
|
2356
|
+
const u = s.interpolation !== void 0 ? qs[s.interpolation] : ht, 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 ze ? Ys : pt;
|
|
2381
|
+
return new s(this.times, this.values, this.getValueSize() / 3, n);
|
|
2382
|
+
}, e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
function nn(r, e, t) {
|
|
2386
|
+
const n = e.attributes, s = new Qt();
|
|
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 Jt();
|
|
2424
|
+
s.getCenter(o.center), o.radius = s.min.distanceTo(s.max) / 2, r.boundingSphere = o;
|
|
2425
|
+
}
|
|
2426
|
+
function $e(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 Pe.workingColorSpace !== U && "COLOR_0" in n && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Pe.workingColorSpace}" not supported.`), G(r, e), nn(r, e, t), Promise.all(s).then(function() {
|
|
2444
|
+
return e.targets !== void 0 ? Zs(r, e.targets, t) : r;
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
const Ze = new S(), on = new le(), Qe = new S();
|
|
2448
|
+
class rn extends ve {
|
|
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 Tn extends rn {
|
|
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(), an = new se();
|
|
2479
|
+
class wn {
|
|
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), P = (f.isPerspectiveCamera ? "perspective(" + g + "px) " : "") + x + "translate(" + i + "px," + o + "px)";
|
|
2507
|
+
c.camera.style !== P && (u.style.transform = P, c.camera.style = P), 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(an.makeRotationZ(d.rotation2D)), d.matrixWorld.decompose(Ze, on, Qe), F.setPosition(Ze), F.scale(Qe), 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 R = c.objects.get(d);
|
|
2539
|
+
if (R === void 0 || R.style !== x) {
|
|
2540
|
+
E.style.transform = x;
|
|
2541
|
+
const P = { style: x };
|
|
2542
|
+
c.objects.set(d, P);
|
|
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 bn(r) {
|
|
2605
|
+
return new es(r);
|
|
2606
|
+
}
|
|
2607
|
+
function En(r = 150, ...e) {
|
|
2608
|
+
return new ts(r, r / 10, ...e);
|
|
2609
|
+
}
|
|
2610
|
+
function xn(r) {
|
|
2611
|
+
return new ss(r, 16776960);
|
|
2612
|
+
}
|
|
2613
|
+
function An(r, e) {
|
|
2614
|
+
return new dt(r, e);
|
|
2615
|
+
}
|
|
2616
|
+
function Mn(r, e) {
|
|
2617
|
+
return new ws(r, e);
|
|
2618
|
+
}
|
|
2619
|
+
function Rn() {
|
|
2620
|
+
const r = new ns(), e = new k(0, 0);
|
|
2621
|
+
return {
|
|
2622
|
+
raycaster: r,
|
|
2623
|
+
pointer: e
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
function Sn(r = 10) {
|
|
2627
|
+
return new is(r);
|
|
2628
|
+
}
|
|
2629
|
+
function Ln(r = new S(1, 1, 1), e = new S(10, 10, 10), t = 5, n = 16776960) {
|
|
2630
|
+
return r.normalize(), new os(r, e, t, n);
|
|
2631
|
+
}
|
|
2632
|
+
function Dn() {
|
|
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 cn = (r) => {
|
|
2637
|
+
r.geometry && r.geometry.dispose(), r.material && (Array.isArray(r.material) ? r.material.forEach((e) => {
|
|
2638
|
+
Je(e);
|
|
2639
|
+
}) : Je(r.material)), r.children && r.children.forEach((e) => cn(e));
|
|
2640
|
+
};
|
|
2641
|
+
function Je(r) {
|
|
2642
|
+
for (const e in r)
|
|
2643
|
+
r[e] && r[e].isTexture && r[e].dispose();
|
|
2644
|
+
r.dispose();
|
|
2645
|
+
}
|
|
2646
|
+
const Re = {};
|
|
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 Cn(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 ln(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 On(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 (Re[r.name]) return Re[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, Re[r.name] = s, s;
|
|
2863
|
+
}
|
|
2864
|
+
class hn {
|
|
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 hn();
|
|
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 et = 4;
|
|
3089
|
+
class tt {
|
|
3090
|
+
/**
|
|
3091
|
+
* 构造函数
|
|
3092
|
+
* @param {string} dbName - 数据库名称
|
|
3093
|
+
* @param {CacheOptions} options - 缓存配置选项
|
|
3094
|
+
*/
|
|
3095
|
+
constructor(e = "threeJsIDBCache", t = {}) {
|
|
3096
|
+
this.version = et, 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 rs(this.dbName), this.db.version(this.version).stores({
|
|
3107
|
+
models: "&path, version, timestamp, accessCount, size"
|
|
3108
|
+
}).upgrade(async (e) => {
|
|
3109
|
+
console.log("[ IDBCache 版本更新 ] ====> version", et);
|
|
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 mt(r) {
|
|
3226
|
+
const { geometries: e, materials: t, hierarchy: n } = r, s = /* @__PURE__ */ new Map();
|
|
3227
|
+
e.forEach((a, l) => {
|
|
3228
|
+
const u = un(a);
|
|
3229
|
+
s.set(l, u);
|
|
3230
|
+
});
|
|
3231
|
+
const i = /* @__PURE__ */ new Map();
|
|
3232
|
+
t.forEach((a, l) => {
|
|
3233
|
+
const u = dn(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, l.userData = a.userData || {}, 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 un(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 dn(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 kn {
|
|
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 mt(e);
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3352
|
+
* 完成构建
|
|
3353
|
+
*/
|
|
3354
|
+
finalize() {
|
|
3355
|
+
return this.buildCurrent();
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
function fn(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 pn(r) {
|
|
3367
|
+
return new Worker(
|
|
3368
|
+
"" + new URL("assets/gltfParserOptimized.worker-yo8WMPFM.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, st = 0;
|
|
3377
|
+
const X = /* @__PURE__ */ new Map(), H = /* @__PURE__ */ new Map();
|
|
3378
|
+
function Ne(r) {
|
|
3379
|
+
const e = r.clone(!1);
|
|
3380
|
+
r.userData && typeof r.userData == "object" ? e.userData = JSON.parse(JSON.stringify(r.userData)) : e.userData = r.userData;
|
|
3381
|
+
for (const t of r.children) {
|
|
3382
|
+
const n = Ne(t);
|
|
3383
|
+
e.add(n);
|
|
3384
|
+
}
|
|
3385
|
+
return e;
|
|
3386
|
+
}
|
|
3387
|
+
const mn = (r = {}) => {
|
|
3388
|
+
const { debug: e = !1 } = r, t = new xs(), n = new bs();
|
|
3389
|
+
n.setDecoderPath(Le), t.setDRACOLoader(n);
|
|
3390
|
+
const s = {
|
|
3391
|
+
info: (...d) => e && console.log(...d),
|
|
3392
|
+
warn: (...d) => e && console.warn(...d),
|
|
3393
|
+
error: (...d) => console.error(...d),
|
|
3394
|
+
// 错误总是输出
|
|
3395
|
+
time: (d) => e && console.time(d),
|
|
3396
|
+
timeEnd: (d) => e && console.timeEnd(d)
|
|
3397
|
+
};
|
|
3398
|
+
function i(d, f, g, T) {
|
|
3399
|
+
return t.load(d, f, g, T);
|
|
3400
|
+
}
|
|
3401
|
+
function o(d, f) {
|
|
3402
|
+
return new Promise((g, T) => {
|
|
3403
|
+
t.load(d, g, f, T);
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
async function c(d, f, g, T = {}) {
|
|
3407
|
+
const y = performance.now();
|
|
3408
|
+
let E = !1;
|
|
3409
|
+
const {
|
|
3410
|
+
maxRetries: x = 3,
|
|
3411
|
+
optimizeMaterials: R = !1,
|
|
3412
|
+
simplifyGeometry: P = !1,
|
|
3413
|
+
simplifyRatio: C = 0.5,
|
|
3414
|
+
simplifyOptions: z = {},
|
|
3415
|
+
useMemoryCache: he = !0
|
|
3416
|
+
// 是否使用内存缓存(默认 true)
|
|
3417
|
+
} = T;
|
|
3418
|
+
if (he) {
|
|
3419
|
+
const D = H.get(d);
|
|
3420
|
+
if (D && D.has(f)) {
|
|
3421
|
+
const N = D.get(f);
|
|
3422
|
+
s.info(`[ 内存缓存命中 ] ${d} (version: ${f})`), s.time("[ 内存缓存克隆耗时 ]");
|
|
3423
|
+
const $ = Ne(N);
|
|
3424
|
+
return s.timeEnd("[ 内存缓存克隆耗时 ]"), W.recordHit(performance.now() - y), $;
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
try {
|
|
3428
|
+
let D = await l(d, f);
|
|
3429
|
+
if (D)
|
|
3430
|
+
s.info(`[ asyncFetch ] ====> IndexedDB 缓存命中: ${d}`), E = !0;
|
|
3431
|
+
else {
|
|
3432
|
+
s.info(`[ asyncFetch ] ====> 缓存未命中: ${d}`), s.time("[ fetchArrayBuffer ] 加载模型耗时"), D = await ye.retry(
|
|
3433
|
+
() => a(d, g),
|
|
3434
|
+
{
|
|
3435
|
+
maxRetries: x,
|
|
3436
|
+
shouldRetry: (Fe) => !!(Fe.name === "TypeError" || Fe.message.includes("HTTP error! status: 5"))
|
|
3437
|
+
}
|
|
3438
|
+
), s.timeEnd("[ fetchArrayBuffer ] 加载模型耗时");
|
|
3439
|
+
const v = performance.now();
|
|
3440
|
+
await ee.saveModel(d, f, D);
|
|
3441
|
+
const _e = performance.now() - v;
|
|
3442
|
+
W.recordCacheSave(_e), E = !1;
|
|
3443
|
+
}
|
|
3444
|
+
s.time("[ 解析模型耗时 ]");
|
|
3445
|
+
let N = await u(D);
|
|
3446
|
+
if (s.timeEnd("[ 解析模型耗时 ]"), s.time("[ 模型优化耗时 ]"), R) {
|
|
3447
|
+
s.info("🔧 [ 材质优化 ] 开始合并相同材质...");
|
|
3448
|
+
const { modelOptimizer: v } = await import("./modelOptimizer-D6fRg-DF.js");
|
|
3449
|
+
N = v.optimizeMaterials(N);
|
|
3450
|
+
}
|
|
3451
|
+
if (P) {
|
|
3452
|
+
s.info(`🔧 [ 几何体简化 ] 开始简化模型 (比例: ${C})...`);
|
|
3453
|
+
const { modelOptimizer: v } = await import("./modelOptimizer-D6fRg-DF.js"), _e = {
|
|
3454
|
+
minFaceCount: 100,
|
|
3455
|
+
preserveUVs: !0,
|
|
3456
|
+
...z
|
|
3457
|
+
};
|
|
3458
|
+
N = v.simplifyModel(N, C, _e);
|
|
3459
|
+
}
|
|
3460
|
+
if (s.timeEnd("[ 模型优化耗时 ]"), he) {
|
|
3461
|
+
H.has(d) || H.set(d, /* @__PURE__ */ new Map());
|
|
3462
|
+
const v = H.get(d);
|
|
3463
|
+
v.has(f) || (s.info(`[ 内存缓存 ] 存储模型 ${d} (version: ${f})`), v.set(f, Ne(N)));
|
|
3464
|
+
}
|
|
3465
|
+
const $ = performance.now() - y;
|
|
3466
|
+
return E ? W.recordHit($) : W.recordMiss($), N;
|
|
3467
|
+
} catch (D) {
|
|
3468
|
+
throw s.error(`加载模型 ${d} 失败:`, D), W.recordError(d, D), D.name === "TypeError" && D.message.includes("fetch") ? ce.networkError(d, D) : D;
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
async function a(d, f) {
|
|
3472
|
+
return new Promise((g, T) => {
|
|
3473
|
+
fetch(d).then((y) => {
|
|
3474
|
+
if (!y.ok)
|
|
3475
|
+
throw new Error(`HTTP error! status: ${y.status}`);
|
|
3476
|
+
return y;
|
|
3477
|
+
}).then((y) => {
|
|
3478
|
+
const E = y.headers.get("content-length"), x = E ? parseInt(E, 10) : 0;
|
|
3479
|
+
if (f && x > 0) {
|
|
3480
|
+
const R = y.body.getReader();
|
|
3481
|
+
let P = 0;
|
|
3482
|
+
const C = [], z = () => {
|
|
3483
|
+
R.read().then(({ done: he, value: D }) => {
|
|
3484
|
+
if (he) {
|
|
3485
|
+
const N = new Uint8Array(P);
|
|
3486
|
+
let $ = 0;
|
|
3487
|
+
for (const v of C)
|
|
3488
|
+
N.set(v, $), $ += v.length;
|
|
3489
|
+
g(N.buffer);
|
|
3490
|
+
return;
|
|
3491
|
+
}
|
|
3492
|
+
C.push(D), P += D.length, f(Math.round(P / x * 100)), z();
|
|
3493
|
+
}).catch(T);
|
|
3494
|
+
};
|
|
3495
|
+
z();
|
|
3496
|
+
} else
|
|
3497
|
+
return y.arrayBuffer();
|
|
3498
|
+
}).then((y) => g(y)).catch((y) => {
|
|
3499
|
+
T(y);
|
|
3500
|
+
});
|
|
3501
|
+
});
|
|
3502
|
+
}
|
|
3503
|
+
async function l(d, f) {
|
|
3504
|
+
return ee || (ee = new tt()), ee.getModel(d, f);
|
|
3505
|
+
}
|
|
3506
|
+
async function u(d, f = {}) {
|
|
3507
|
+
if (!d) return null;
|
|
3508
|
+
const { useOptimizedParser: g = !0, useProgressive: T = !1 } = f;
|
|
3509
|
+
if (g) {
|
|
3510
|
+
const x = p();
|
|
3511
|
+
if (x)
|
|
3512
|
+
try {
|
|
3513
|
+
s.time("[ 优化解析 ] 使用 Transferable Objects 解析");
|
|
3514
|
+
const R = await m(x, d, T);
|
|
3515
|
+
return s.timeEnd("[ 优化解析 ] 使用 Transferable Objects 解析"), mt(R);
|
|
3516
|
+
} catch (R) {
|
|
3517
|
+
s.warn("[ 优化解析 ] 失败,回退到标准解析", R);
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
const y = h();
|
|
3521
|
+
if (y)
|
|
3522
|
+
try {
|
|
3523
|
+
const x = await _(y, d);
|
|
3524
|
+
return ln(x);
|
|
3525
|
+
} catch (x) {
|
|
3526
|
+
s.warn("[ GLTF Worker ] ====> 解析失败,回退到主线程解析", x);
|
|
3527
|
+
}
|
|
3528
|
+
return (await w(d)).scene;
|
|
3529
|
+
}
|
|
3530
|
+
const h = () => {
|
|
3531
|
+
if (typeof window > "u" || typeof Worker > "u")
|
|
3532
|
+
return null;
|
|
3533
|
+
if (!Q)
|
|
3534
|
+
try {
|
|
3535
|
+
s.info("[GLTF Worker] 使用 ?worker 工厂函数创建 Worker..."), Q = fn(), s.info("[GLTF Worker] Worker 创建成功:", Q), Q.onmessage = (d) => {
|
|
3536
|
+
const { id: f, data: g, error: T } = d.data || {};
|
|
3537
|
+
if (!f || !X.has(f)) return;
|
|
3538
|
+
const { resolve: y, reject: E } = X.get(f);
|
|
3539
|
+
X.delete(f), T ? E(new Error(T)) : y(g);
|
|
3540
|
+
}, Q.onmessageerror = (d) => {
|
|
3541
|
+
console.error("[ GLTF Worker ] ====> 消息解析失败", d);
|
|
3542
|
+
}, Q.onerror = (d) => {
|
|
3543
|
+
console.error("[ GLTF Worker ] ====> 运行错误", d);
|
|
3544
|
+
};
|
|
3545
|
+
} catch (d) {
|
|
3546
|
+
console.error("[GLTF Worker] 创建 Worker 失败:", d), console.error("[GLTF Worker] 错误堆栈:", d.stack);
|
|
3547
|
+
}
|
|
3548
|
+
return Q;
|
|
3549
|
+
}, p = () => {
|
|
3550
|
+
if (typeof window > "u" || typeof Worker > "u")
|
|
3551
|
+
return null;
|
|
3552
|
+
if (!J)
|
|
3553
|
+
try {
|
|
3554
|
+
s.info("[Optimized Worker] 使用 ?worker 工厂函数创建 Worker..."), J = pn(), s.info("[Optimized Worker] Worker 创建成功:", J), J.onmessage = (d) => {
|
|
3555
|
+
const { id: f, data: g, error: T, type: y } = d.data || {};
|
|
3556
|
+
if (!f || !X.has(f) || y === "progress")
|
|
3557
|
+
return;
|
|
3558
|
+
const { resolve: E, reject: x } = X.get(f);
|
|
3559
|
+
X.delete(f), T ? x(new Error(T)) : E(g);
|
|
3560
|
+
}, J.onmessageerror = (d) => {
|
|
3561
|
+
console.error("[ 优化 Worker ] ====> 消息解析失败", d);
|
|
3562
|
+
}, J.onerror = (d) => {
|
|
3563
|
+
console.error("[ 优化 Worker ] ====> 运行错误", d);
|
|
3564
|
+
};
|
|
3565
|
+
} catch (d) {
|
|
3566
|
+
return s.warn("[ 优化 Worker ] ====> 创建失败,可能不支持模块化 Worker", d), null;
|
|
3567
|
+
}
|
|
3568
|
+
return J;
|
|
3569
|
+
}, m = (d, f, g = !1) => new Promise((T, y) => {
|
|
3570
|
+
const E = ++st;
|
|
3571
|
+
X.set(E, { resolve: T, reject: y });
|
|
3572
|
+
const x = {
|
|
3573
|
+
id: E,
|
|
3574
|
+
arrayBuffer: f,
|
|
3575
|
+
dracoPath: Le,
|
|
3576
|
+
mode: g ? "progressive" : "standard"
|
|
3577
|
+
};
|
|
3578
|
+
d.postMessage(x, [f]);
|
|
3579
|
+
}), _ = (d, f) => new Promise((g, T) => {
|
|
3580
|
+
const y = ++st;
|
|
3581
|
+
X.set(y, { resolve: g, reject: T }), d.postMessage({ id: y, arrayBuffer: f, dracoPath: Le });
|
|
3582
|
+
}), w = (d) => new Promise((f, g) => {
|
|
3583
|
+
t.parse(d, "", f, g);
|
|
3584
|
+
});
|
|
3585
|
+
return {
|
|
3586
|
+
load: i,
|
|
3587
|
+
asyncLoad: o,
|
|
3588
|
+
asyncCacheLoad: c,
|
|
3589
|
+
asyncFetch: c,
|
|
3590
|
+
/**
|
|
3591
|
+
* 获取缓存统计信息
|
|
3592
|
+
* @returns {Object} 统计数据
|
|
3593
|
+
*/
|
|
3594
|
+
getCacheStats: () => W.getStats(),
|
|
3595
|
+
/**
|
|
3596
|
+
* 获取缓存实例
|
|
3597
|
+
* @returns {IDBCache} 缓存实例
|
|
3598
|
+
*/
|
|
3599
|
+
getCache: () => ee || (ee = new tt()),
|
|
3600
|
+
/**
|
|
3601
|
+
* 打印缓存性能报告
|
|
3602
|
+
*/
|
|
3603
|
+
logCacheReport: () => W.logReport(),
|
|
3604
|
+
/**
|
|
3605
|
+
* 重置缓存统计
|
|
3606
|
+
*/
|
|
3607
|
+
resetCacheStats: () => W.reset(),
|
|
3608
|
+
/**
|
|
3609
|
+
* 清空内存缓存
|
|
3610
|
+
* 释放已缓存的 3D 模型对象内存
|
|
3611
|
+
* @returns {number} 释放的模型数量
|
|
3612
|
+
*/
|
|
3613
|
+
clearMemoryCache: () => {
|
|
3614
|
+
let d = 0;
|
|
3615
|
+
for (const [f, g] of H.entries())
|
|
3616
|
+
d += g.size, g.clear();
|
|
3617
|
+
return H.clear(), s.info(`[ 内存缓存 ] 已清空,释放了 ${d} 个模型`), d;
|
|
3618
|
+
},
|
|
3619
|
+
/**
|
|
3620
|
+
* 获取内存缓存信息
|
|
3621
|
+
* @returns {Object} 内存缓存统计
|
|
3622
|
+
* @returns {number} returns.totalPaths - 缓存的不同模型路径数量
|
|
3623
|
+
* @returns {number} returns.totalModels - 缓存的总模型数量
|
|
3624
|
+
* @returns {Array} returns.details - 每个路径的详细信息
|
|
3625
|
+
*/
|
|
3626
|
+
getMemoryCacheInfo: () => {
|
|
3627
|
+
const d = [];
|
|
3628
|
+
let f = 0;
|
|
3629
|
+
for (const [g, T] of H.entries()) {
|
|
3630
|
+
const y = Array.from(T.keys());
|
|
3631
|
+
f += y.length, d.push({
|
|
3632
|
+
path: g,
|
|
3633
|
+
versions: y,
|
|
3634
|
+
count: y.length
|
|
3635
|
+
});
|
|
3636
|
+
}
|
|
3637
|
+
return {
|
|
3638
|
+
totalPaths: H.size,
|
|
3639
|
+
totalModels: f,
|
|
3640
|
+
details: d
|
|
3641
|
+
};
|
|
3642
|
+
},
|
|
3643
|
+
/**
|
|
3644
|
+
* 删除指定模型的内存缓存
|
|
3645
|
+
* @param {string} path - 模型路径
|
|
3646
|
+
* @param {string} [version] - 可选的版本号,如果不指定则删除该路径的所有版本
|
|
3647
|
+
* @returns {boolean} 是否删除成功
|
|
3648
|
+
*/
|
|
3649
|
+
deleteMemoryCache: (d, f) => {
|
|
3650
|
+
const g = H.get(d);
|
|
3651
|
+
if (!g)
|
|
3652
|
+
return !1;
|
|
3653
|
+
if (f) {
|
|
3654
|
+
const T = g.delete(f);
|
|
3655
|
+
return g.size === 0 && H.delete(d), s.info(`[ 内存缓存 ] 删除模型 ${d} (version: ${f})`), T;
|
|
3656
|
+
} else {
|
|
3657
|
+
const T = g.size;
|
|
3658
|
+
return H.delete(d), s.info(`[ 内存缓存 ] 删除模型 ${d} 及其所有版本 (共 ${T} 个)`), T > 0;
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
};
|
|
3662
|
+
};
|
|
3663
|
+
class gn {
|
|
3664
|
+
constructor(e = {}) {
|
|
3665
|
+
this.options = {
|
|
3666
|
+
maxPreloadCount: e.maxPreloadCount || 5,
|
|
3667
|
+
preloadDelay: e.preloadDelay || 1e3,
|
|
3668
|
+
enableLearning: e.enableLearning !== !1
|
|
3669
|
+
}, 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 = mn()), this.loader);
|
|
3670
|
+
}
|
|
3671
|
+
/**
|
|
3672
|
+
* 记录模型加载
|
|
3673
|
+
* @param {string} path - 模型路径
|
|
3674
|
+
* @param {string} version - 模型版本
|
|
3675
|
+
*/
|
|
3676
|
+
recordLoad(e, t) {
|
|
3677
|
+
const n = Date.now(), s = this.loadHistory.get(e) || {
|
|
3678
|
+
count: 0,
|
|
3679
|
+
lastLoadTime: 0,
|
|
3680
|
+
versions: /* @__PURE__ */ new Set()
|
|
3681
|
+
};
|
|
3682
|
+
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);
|
|
3683
|
+
}
|
|
3684
|
+
/**
|
|
3685
|
+
* 学习模型关联规则
|
|
3686
|
+
* @private
|
|
3687
|
+
* @param {string} currentPath - 当前加载的模型
|
|
3688
|
+
*/
|
|
3689
|
+
_learnAssociations(e) {
|
|
3690
|
+
const n = this.loadSequence.length - 1;
|
|
3691
|
+
for (let s = Math.max(0, n - 10); s < n; s++) {
|
|
3692
|
+
const { path: i } = this.loadSequence[s];
|
|
3693
|
+
if (this.loadSequence[n].timestamp - this.loadSequence[s].timestamp < 5 * 60 * 1e3 && i !== e) {
|
|
3694
|
+
this.associations.has(i) || this.associations.set(i, /* @__PURE__ */ new Map());
|
|
3695
|
+
const c = this.associations.get(i), a = c.get(e) || 0;
|
|
3696
|
+
c.set(e, a + 1);
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
/**
|
|
3701
|
+
* 触发预测性预加载
|
|
3702
|
+
* @private
|
|
3703
|
+
* @param {string} currentPath - 当前加载的模型
|
|
3704
|
+
* @param {string} version - 模型版本
|
|
3705
|
+
*/
|
|
3706
|
+
_triggerPredictivePreload(e, t) {
|
|
3707
|
+
setTimeout(() => {
|
|
3708
|
+
const n = this.predictNext(e);
|
|
3709
|
+
this.preload(n, t);
|
|
3710
|
+
}, this.options.preloadDelay);
|
|
3711
|
+
}
|
|
3712
|
+
/**
|
|
3713
|
+
* 预测下一个可能加载的模型
|
|
3714
|
+
* @param {string} currentPath - 当前模型路径
|
|
3715
|
+
* @returns {Array<string>} 预测的模型路径列表
|
|
3716
|
+
*/
|
|
3717
|
+
predictNext(e) {
|
|
3718
|
+
const t = /* @__PURE__ */ new Map(), n = this.associations.get(e);
|
|
3719
|
+
n && n.forEach((c, a) => {
|
|
3720
|
+
t.set(a, (t.get(a) || 0) + c * 2);
|
|
3721
|
+
});
|
|
3722
|
+
const s = Array.from(this.loadHistory.values()).reduce((c, a) => c + a.count, 0) / (this.loadHistory.size || 1);
|
|
3723
|
+
this.loadHistory.forEach((c, a) => {
|
|
3724
|
+
if (a !== e) {
|
|
3725
|
+
const l = c.count / s;
|
|
3726
|
+
t.set(a, (t.get(a) || 0) + l);
|
|
3727
|
+
}
|
|
3728
|
+
});
|
|
3729
|
+
const i = this.loadSequence.slice(-10);
|
|
3730
|
+
return new Set(i.map((c) => c.path)).forEach((c) => {
|
|
3731
|
+
c !== e && t.set(c, (t.get(c) || 0) + 0.5);
|
|
3732
|
+
}), Array.from(t.entries()).sort((c, a) => a[1] - c[1]).slice(0, this.options.maxPreloadCount).map(([c]) => c);
|
|
3733
|
+
}
|
|
3734
|
+
/**
|
|
3735
|
+
* 预加载模型列表
|
|
3736
|
+
* @param {Array<string>} paths - 模型路径列表
|
|
3737
|
+
* @param {string} version - 模型版本
|
|
3738
|
+
*/
|
|
3739
|
+
async preload(e, t = "latest") {
|
|
3740
|
+
if (this.isPreloading)
|
|
3741
|
+
return;
|
|
3742
|
+
this.isPreloading = !0;
|
|
3743
|
+
const { asyncFetch: n } = this.getLoader(), s = e.filter((i) => !this.preloadQueue.has(i)).slice(0, this.options.maxPreloadCount).map(async (i) => {
|
|
3744
|
+
this.preloadQueue.add(i);
|
|
3745
|
+
try {
|
|
3746
|
+
console.log(`[ 智能预加载 ] 开始预加载: ${i}`), await n(i, t), console.log(`[ 智能预加载 ] 完成: ${i}`);
|
|
3747
|
+
} catch (o) {
|
|
3748
|
+
console.warn(`[ 智能预加载 ] 失败: ${i}`, o);
|
|
3749
|
+
} finally {
|
|
3750
|
+
this.preloadQueue.delete(i);
|
|
3751
|
+
}
|
|
3752
|
+
});
|
|
3753
|
+
await Promise.all(s), this.isPreloading = !1;
|
|
3754
|
+
}
|
|
3755
|
+
/**
|
|
3756
|
+
* 手动添加关联规则
|
|
3757
|
+
* @param {string} fromPath - 源模型路径
|
|
3758
|
+
* @param {Array<string>} toPaths - 关联的模型路径列表
|
|
3759
|
+
*/
|
|
3760
|
+
addAssociation(e, t) {
|
|
3761
|
+
this.associations.has(e) || this.associations.set(e, /* @__PURE__ */ new Map());
|
|
3762
|
+
const n = this.associations.get(e);
|
|
3763
|
+
t.forEach((s) => {
|
|
3764
|
+
const i = n.get(s) || 0;
|
|
3765
|
+
n.set(s, i + 10);
|
|
3766
|
+
});
|
|
3767
|
+
}
|
|
3768
|
+
/**
|
|
3769
|
+
* 获取加载统计信息
|
|
3770
|
+
* @returns {Object} 统计数据
|
|
3771
|
+
*/
|
|
3772
|
+
getStats() {
|
|
3773
|
+
const e = Array.from(this.loadHistory.entries()).sort((t, n) => n[1].count - t[1].count).slice(0, 10).map(([t, n]) => ({
|
|
3774
|
+
path: t,
|
|
3775
|
+
loadCount: n.count,
|
|
3776
|
+
lastLoadTime: new Date(n.lastLoadTime).toLocaleString()
|
|
3777
|
+
}));
|
|
3778
|
+
return {
|
|
3779
|
+
totalModelsLoaded: this.loadHistory.size,
|
|
3780
|
+
totalAssociations: this.associations.size,
|
|
3781
|
+
topModels: e,
|
|
3782
|
+
preloadQueueSize: this.preloadQueue.size
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
/**
|
|
3786
|
+
* 清空历史记录
|
|
3787
|
+
*/
|
|
3788
|
+
clearHistory() {
|
|
3789
|
+
this.loadHistory.clear(), this.loadSequence = [], this.associations.clear();
|
|
3790
|
+
}
|
|
3791
|
+
/**
|
|
3792
|
+
* 导出关联规则(可持久化)
|
|
3793
|
+
* @returns {Object} 关联规则数据
|
|
3794
|
+
*/
|
|
3795
|
+
exportAssociations() {
|
|
3796
|
+
const e = {};
|
|
3797
|
+
return this.associations.forEach((t, n) => {
|
|
3798
|
+
e[n] = Array.from(t.entries());
|
|
3799
|
+
}), e;
|
|
3800
|
+
}
|
|
3801
|
+
/**
|
|
3802
|
+
* 导入关联规则
|
|
3803
|
+
* @param {Object} data - 关联规则数据
|
|
3804
|
+
*/
|
|
3805
|
+
importAssociations(e) {
|
|
3806
|
+
Object.entries(e).forEach(([t, n]) => {
|
|
3807
|
+
const s = new Map(n);
|
|
3808
|
+
this.associations.set(t, s);
|
|
3809
|
+
});
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
const In = new gn();
|
|
3813
|
+
export {
|
|
3814
|
+
hn as C,
|
|
3815
|
+
Se as E,
|
|
3816
|
+
tt as I,
|
|
3817
|
+
ce as M,
|
|
3818
|
+
gn as P,
|
|
3819
|
+
ye as R,
|
|
3820
|
+
ae as S,
|
|
3821
|
+
En as a,
|
|
3822
|
+
xn as b,
|
|
3823
|
+
bn as c,
|
|
3824
|
+
An as d,
|
|
3825
|
+
Mn as e,
|
|
3826
|
+
Rn as f,
|
|
3827
|
+
Sn as g,
|
|
3828
|
+
Ln as h,
|
|
3829
|
+
Dn as i,
|
|
3830
|
+
cn as j,
|
|
3831
|
+
Cn as k,
|
|
3832
|
+
ln as l,
|
|
3833
|
+
On as m,
|
|
3834
|
+
W as n,
|
|
3835
|
+
Pn as o,
|
|
3836
|
+
In as p,
|
|
3837
|
+
kn as q,
|
|
3838
|
+
mt as r,
|
|
3839
|
+
wn as s,
|
|
3840
|
+
Tn as t,
|
|
3841
|
+
mn as u
|
|
3842
|
+
};
|