@ridp/threejs 1.2.2 → 1.3.1
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/hooks.cjs +1 -1
- package/dist/hooks.js +1 -1
- package/dist/threejs.cjs +1 -1
- package/dist/threejs.js +54 -53
- package/dist/useGLTFLoader-B6Cm6xQg.cjs +2 -0
- package/dist/useGLTFLoader-kuE8ICl_.js +2477 -0
- package/package.json +9 -7
- package/readme.md +21 -1
- package/dist/useGLTFLoader-Cw4DG52q.js +0 -5507
- package/dist/useGLTFLoader-DEwFr0G4.cjs +0 -4
|
@@ -0,0 +1,2477 @@
|
|
|
1
|
+
import { TrianglesDrawMode as lt, TriangleFanDrawMode as ye, TriangleStripDrawMode as Ve, Loader as Xe, FileLoader as le, SRGBColorSpace as V, LinearSRGBColorSpace as F, BufferGeometry as qe, BufferAttribute as ie, Color as G, ColorManagement as Re, LoaderUtils as oe, MeshPhysicalMaterial as v, Vector2 as Se, SpotLight as ut, PointLight as dt, DirectionalLight as ht, Matrix4 as ee, Vector3 as _, Quaternion as We, InstancedMesh as ft, InstancedBufferAttribute as pt, Object3D as Ye, TextureLoader as mt, ImageBitmapLoader as gt, InterleavedBuffer as Tt, InterleavedBufferAttribute as xt, LinearMipmapLinearFilter as Je, NearestMipmapLinearFilter as yt, LinearMipmapNearestFilter as Rt, NearestMipmapNearestFilter as bt, LinearFilter as be, NearestFilter as Qe, RepeatWrapping as Ae, MirroredRepeatWrapping as At, ClampToEdgeWrapping as wt, PointsMaterial as _t, Material as he, LineBasicMaterial as Et, MeshStandardMaterial as Ze, DoubleSide as St, MeshBasicMaterial as re, PropertyBinding as Lt, SkinnedMesh as Mt, Mesh as It, LineSegments as Ct, Line as Nt, LineLoop as Ot, Points as Dt, Group as fe, PerspectiveCamera as $e, MathUtils as Z, OrthographicCamera as Pt, Skeleton as kt, AnimationClip as Ft, Bone as vt, InterpolateDiscrete as Ht, InterpolateLinear as et, Texture as Ce, VectorKeyframeTrack as Ne, NumberKeyframeTrack as Oe, QuaternionKeyframeTrack as De, FrontSide as Ut, Interpolant as Gt, Box3 as ue, Sphere as Bt, Matrix3 as tt, Ray as jt, WebGLRenderer as zt, Scene as Kt, Raycaster as Vt } from "three";
|
|
2
|
+
import { ref as pe, shallowRef as Xt, onMounted as qt, onUnmounted as Wt, nextTick as Pe } from "vue";
|
|
3
|
+
import { d as Yt, j as Jt, S as Qt, C as Zt, l as $t, o as en } from "./modelSerialize-5oJb1ka7.js";
|
|
4
|
+
import tn from "dexie";
|
|
5
|
+
function ke(h, e) {
|
|
6
|
+
if (e === lt)
|
|
7
|
+
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), h;
|
|
8
|
+
if (e === ye || e === Ve) {
|
|
9
|
+
let t = h.getIndex();
|
|
10
|
+
if (t === null) {
|
|
11
|
+
const i = [], a = h.getAttribute("position");
|
|
12
|
+
if (a !== void 0) {
|
|
13
|
+
for (let o = 0; o < a.count; o++)
|
|
14
|
+
i.push(o);
|
|
15
|
+
h.setIndex(i), t = h.getIndex();
|
|
16
|
+
} else
|
|
17
|
+
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), h;
|
|
18
|
+
}
|
|
19
|
+
const r = t.count - 2, n = [];
|
|
20
|
+
if (e === ye)
|
|
21
|
+
for (let i = 1; i <= r; i++)
|
|
22
|
+
n.push(t.getX(0)), n.push(t.getX(i)), n.push(t.getX(i + 1));
|
|
23
|
+
else
|
|
24
|
+
for (let i = 0; i < r; i++)
|
|
25
|
+
i % 2 === 0 ? (n.push(t.getX(i)), n.push(t.getX(i + 1)), n.push(t.getX(i + 2))) : (n.push(t.getX(i + 2)), n.push(t.getX(i + 1)), n.push(t.getX(i)));
|
|
26
|
+
n.length / 3 !== r && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
|
|
27
|
+
const s = h.clone();
|
|
28
|
+
return s.setIndex(n), s.clearGroups(), s;
|
|
29
|
+
} else
|
|
30
|
+
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), h;
|
|
31
|
+
}
|
|
32
|
+
const me = /* @__PURE__ */ new WeakMap();
|
|
33
|
+
class nn extends Xe {
|
|
34
|
+
/**
|
|
35
|
+
* Constructs a new Draco loader.
|
|
36
|
+
*
|
|
37
|
+
* @param {LoadingManager} [manager] - The loading manager.
|
|
38
|
+
*/
|
|
39
|
+
constructor(e) {
|
|
40
|
+
super(e), this.decoderPath = "", this.decoderConfig = {}, this.decoderBinary = null, this.decoderPending = null, this.workerLimit = 4, this.workerPool = [], this.workerNextTaskID = 1, this.workerSourceURL = "", this.defaultAttributeIDs = {
|
|
41
|
+
position: "POSITION",
|
|
42
|
+
normal: "NORMAL",
|
|
43
|
+
color: "COLOR",
|
|
44
|
+
uv: "TEX_COORD"
|
|
45
|
+
}, this.defaultAttributeTypes = {
|
|
46
|
+
position: "Float32Array",
|
|
47
|
+
normal: "Float32Array",
|
|
48
|
+
color: "Float32Array",
|
|
49
|
+
uv: "Float32Array"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} path - The decoder path.
|
|
56
|
+
* @return {DRACOLoader} A reference to this loader.
|
|
57
|
+
*/
|
|
58
|
+
setDecoderPath(e) {
|
|
59
|
+
return this.decoderPath = e, this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Provides configuration for the decoder libraries. Configuration cannot be changed after decoding begins.
|
|
63
|
+
*
|
|
64
|
+
* @param {{type:('js'|'wasm')}} config - The decoder config.
|
|
65
|
+
* @return {DRACOLoader} A reference to this loader.
|
|
66
|
+
*/
|
|
67
|
+
setDecoderConfig(e) {
|
|
68
|
+
return this.decoderConfig = e, this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sets the maximum number of Web Workers to be used during decoding.
|
|
72
|
+
* A lower limit may be preferable if workers are also for other tasks in the application.
|
|
73
|
+
*
|
|
74
|
+
* @param {number} workerLimit - The worker limit.
|
|
75
|
+
* @return {DRACOLoader} A reference to this loader.
|
|
76
|
+
*/
|
|
77
|
+
setWorkerLimit(e) {
|
|
78
|
+
return this.workerLimit = e, this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Starts loading from the given URL and passes the loaded Draco asset
|
|
82
|
+
* to the `onLoad()` callback.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
|
|
85
|
+
* @param {function(BufferGeometry)} onLoad - Executed when the loading process has been finished.
|
|
86
|
+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
|
|
87
|
+
* @param {onErrorCallback} onError - Executed when errors occur.
|
|
88
|
+
*/
|
|
89
|
+
load(e, t, r, n) {
|
|
90
|
+
const s = new le(this.manager);
|
|
91
|
+
s.setPath(this.path), s.setResponseType("arraybuffer"), s.setRequestHeader(this.requestHeader), s.setWithCredentials(this.withCredentials), s.load(e, (i) => {
|
|
92
|
+
this.parse(i, t, n);
|
|
93
|
+
}, r, n);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parses the given Draco data.
|
|
97
|
+
*
|
|
98
|
+
* @param {ArrayBuffer} buffer - The raw Draco data as an array buffer.
|
|
99
|
+
* @param {function(BufferGeometry)} onLoad - Executed when the loading/parsing process has been finished.
|
|
100
|
+
* @param {onErrorCallback} onError - Executed when errors occur.
|
|
101
|
+
*/
|
|
102
|
+
parse(e, t, r = () => {
|
|
103
|
+
}) {
|
|
104
|
+
this.decodeDracoFile(e, t, null, null, V, r).catch(r);
|
|
105
|
+
}
|
|
106
|
+
//
|
|
107
|
+
decodeDracoFile(e, t, r, n, s = F, i = () => {
|
|
108
|
+
}) {
|
|
109
|
+
const a = {
|
|
110
|
+
attributeIDs: r || this.defaultAttributeIDs,
|
|
111
|
+
attributeTypes: n || this.defaultAttributeTypes,
|
|
112
|
+
useUniqueIDs: !!r,
|
|
113
|
+
vertexColorSpace: s
|
|
114
|
+
};
|
|
115
|
+
return this.decodeGeometry(e, a).then(t).catch(i);
|
|
116
|
+
}
|
|
117
|
+
decodeGeometry(e, t) {
|
|
118
|
+
const r = JSON.stringify(t);
|
|
119
|
+
if (me.has(e)) {
|
|
120
|
+
const o = me.get(e);
|
|
121
|
+
if (o.key === r)
|
|
122
|
+
return o.promise;
|
|
123
|
+
if (e.byteLength === 0)
|
|
124
|
+
throw new Error(
|
|
125
|
+
"THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred."
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
let n;
|
|
129
|
+
const s = this.workerNextTaskID++, i = e.byteLength, a = this._getWorker(s, i).then((o) => (n = o, new Promise((c, u) => {
|
|
130
|
+
n._callbacks[s] = { resolve: c, reject: u }, n.postMessage({ type: "decode", id: s, taskConfig: t, buffer: e }, [e]);
|
|
131
|
+
}))).then((o) => this._createGeometry(o.geometry));
|
|
132
|
+
return a.catch(() => !0).then(() => {
|
|
133
|
+
n && s && this._releaseTask(n, s);
|
|
134
|
+
}), me.set(e, {
|
|
135
|
+
key: r,
|
|
136
|
+
promise: a
|
|
137
|
+
}), a;
|
|
138
|
+
}
|
|
139
|
+
_createGeometry(e) {
|
|
140
|
+
const t = new qe();
|
|
141
|
+
e.index && t.setIndex(new ie(e.index.array, 1));
|
|
142
|
+
for (let r = 0; r < e.attributes.length; r++) {
|
|
143
|
+
const n = e.attributes[r], s = n.name, i = n.array, a = n.itemSize, o = new ie(i, a);
|
|
144
|
+
s === "color" && (this._assignVertexColorSpace(o, n.vertexColorSpace), o.normalized = !(i instanceof Float32Array)), t.setAttribute(s, o);
|
|
145
|
+
}
|
|
146
|
+
return t;
|
|
147
|
+
}
|
|
148
|
+
_assignVertexColorSpace(e, t) {
|
|
149
|
+
if (t !== V) return;
|
|
150
|
+
const r = new G();
|
|
151
|
+
for (let n = 0, s = e.count; n < s; n++)
|
|
152
|
+
r.fromBufferAttribute(e, n), Re.colorSpaceToWorking(r, V), e.setXYZ(n, r.r, r.g, r.b);
|
|
153
|
+
}
|
|
154
|
+
_loadLibrary(e, t) {
|
|
155
|
+
const r = new le(this.manager);
|
|
156
|
+
return r.setPath(this.decoderPath), r.setResponseType(t), r.setWithCredentials(this.withCredentials), new Promise((n, s) => {
|
|
157
|
+
r.load(e, n, void 0, s);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
preload() {
|
|
161
|
+
return this._initDecoder(), this;
|
|
162
|
+
}
|
|
163
|
+
_initDecoder() {
|
|
164
|
+
if (this.decoderPending) return this.decoderPending;
|
|
165
|
+
const e = typeof WebAssembly != "object" || this.decoderConfig.type === "js", t = [];
|
|
166
|
+
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((r) => {
|
|
167
|
+
const n = r[0];
|
|
168
|
+
e || (this.decoderConfig.wasmBinary = r[1]);
|
|
169
|
+
const s = sn.toString(), i = [
|
|
170
|
+
"/* draco decoder */",
|
|
171
|
+
n,
|
|
172
|
+
"",
|
|
173
|
+
"/* worker */",
|
|
174
|
+
s.substring(s.indexOf("{") + 1, s.lastIndexOf("}"))
|
|
175
|
+
].join(`
|
|
176
|
+
`);
|
|
177
|
+
this.workerSourceURL = URL.createObjectURL(new Blob([i]));
|
|
178
|
+
}), this.decoderPending;
|
|
179
|
+
}
|
|
180
|
+
_getWorker(e, t) {
|
|
181
|
+
return this._initDecoder().then(() => {
|
|
182
|
+
if (this.workerPool.length < this.workerLimit) {
|
|
183
|
+
const n = new Worker(this.workerSourceURL);
|
|
184
|
+
n._callbacks = {}, n._taskCosts = {}, n._taskLoad = 0, n.postMessage({ type: "init", decoderConfig: this.decoderConfig }), n.onmessage = function(s) {
|
|
185
|
+
const i = s.data;
|
|
186
|
+
switch (i.type) {
|
|
187
|
+
case "decode":
|
|
188
|
+
n._callbacks[i.id].resolve(i);
|
|
189
|
+
break;
|
|
190
|
+
case "error":
|
|
191
|
+
n._callbacks[i.id].reject(i);
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
console.error('THREE.DRACOLoader: Unexpected message, "' + i.type + '"');
|
|
195
|
+
}
|
|
196
|
+
}, this.workerPool.push(n);
|
|
197
|
+
} else
|
|
198
|
+
this.workerPool.sort(function(n, s) {
|
|
199
|
+
return n._taskLoad > s._taskLoad ? -1 : 1;
|
|
200
|
+
});
|
|
201
|
+
const r = this.workerPool[this.workerPool.length - 1];
|
|
202
|
+
return r._taskCosts[e] = t, r._taskLoad += t, r;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
_releaseTask(e, t) {
|
|
206
|
+
e._taskLoad -= e._taskCosts[t], delete e._callbacks[t], delete e._taskCosts[t];
|
|
207
|
+
}
|
|
208
|
+
debug() {
|
|
209
|
+
console.log("Task load: ", this.workerPool.map((e) => e._taskLoad));
|
|
210
|
+
}
|
|
211
|
+
dispose() {
|
|
212
|
+
for (let e = 0; e < this.workerPool.length; ++e)
|
|
213
|
+
this.workerPool[e].terminate();
|
|
214
|
+
return this.workerPool.length = 0, this.workerSourceURL !== "" && URL.revokeObjectURL(this.workerSourceURL), this;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function sn() {
|
|
218
|
+
let h, e;
|
|
219
|
+
onmessage = function(i) {
|
|
220
|
+
const a = i.data;
|
|
221
|
+
switch (a.type) {
|
|
222
|
+
case "init":
|
|
223
|
+
h = a.decoderConfig, e = new Promise(function(u) {
|
|
224
|
+
h.onModuleLoaded = function(l) {
|
|
225
|
+
u({ draco: l });
|
|
226
|
+
}, DracoDecoderModule(h);
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
case "decode":
|
|
230
|
+
const o = a.buffer, c = a.taskConfig;
|
|
231
|
+
e.then((u) => {
|
|
232
|
+
const l = u.draco, d = new l.Decoder();
|
|
233
|
+
try {
|
|
234
|
+
const f = t(l, d, new Int8Array(o), c), p = f.attributes.map((T) => T.array.buffer);
|
|
235
|
+
f.index && p.push(f.index.array.buffer), self.postMessage({ type: "decode", id: a.id, geometry: f }, p);
|
|
236
|
+
} catch (f) {
|
|
237
|
+
console.error(f), self.postMessage({ type: "error", id: a.id, error: f.message });
|
|
238
|
+
} finally {
|
|
239
|
+
l.destroy(d);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
function t(i, a, o, c) {
|
|
246
|
+
const u = c.attributeIDs, l = c.attributeTypes;
|
|
247
|
+
let d, f;
|
|
248
|
+
const p = a.GetEncodedGeometryType(o);
|
|
249
|
+
if (p === i.TRIANGULAR_MESH)
|
|
250
|
+
d = new i.Mesh(), f = a.DecodeArrayToMesh(o, o.byteLength, d);
|
|
251
|
+
else if (p === i.POINT_CLOUD)
|
|
252
|
+
d = new i.PointCloud(), f = a.DecodeArrayToPointCloud(o, o.byteLength, d);
|
|
253
|
+
else
|
|
254
|
+
throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
|
|
255
|
+
if (!f.ok() || d.ptr === 0)
|
|
256
|
+
throw new Error("THREE.DRACOLoader: Decoding failed: " + f.error_msg());
|
|
257
|
+
const T = { index: null, attributes: [] };
|
|
258
|
+
for (const m in u) {
|
|
259
|
+
const g = self[l[m]];
|
|
260
|
+
let b, S;
|
|
261
|
+
if (c.useUniqueIDs)
|
|
262
|
+
S = u[m], b = a.GetAttributeByUniqueId(d, S);
|
|
263
|
+
else {
|
|
264
|
+
if (S = a.GetAttributeId(d, i[u[m]]), S === -1) continue;
|
|
265
|
+
b = a.GetAttribute(d, S);
|
|
266
|
+
}
|
|
267
|
+
const y = n(i, a, d, m, g, b);
|
|
268
|
+
m === "color" && (y.vertexColorSpace = c.vertexColorSpace), T.attributes.push(y);
|
|
269
|
+
}
|
|
270
|
+
return p === i.TRIANGULAR_MESH && (T.index = r(i, a, d)), i.destroy(d), T;
|
|
271
|
+
}
|
|
272
|
+
function r(i, a, o) {
|
|
273
|
+
const u = o.num_faces() * 3, l = u * 4, d = i._malloc(l);
|
|
274
|
+
a.GetTrianglesUInt32Array(o, l, d);
|
|
275
|
+
const f = new Uint32Array(i.HEAPF32.buffer, d, u).slice();
|
|
276
|
+
return i._free(d), { array: f, itemSize: 1 };
|
|
277
|
+
}
|
|
278
|
+
function n(i, a, o, c, u, l) {
|
|
279
|
+
const d = l.num_components(), p = o.num_points() * d, T = p * u.BYTES_PER_ELEMENT, m = s(i, u), g = i._malloc(T);
|
|
280
|
+
a.GetAttributeDataArrayForAllPoints(o, l, m, T, g);
|
|
281
|
+
const b = new u(i.HEAPF32.buffer, g, p).slice();
|
|
282
|
+
return i._free(g), {
|
|
283
|
+
name: c,
|
|
284
|
+
array: b,
|
|
285
|
+
itemSize: d
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function s(i, a) {
|
|
289
|
+
switch (a) {
|
|
290
|
+
case Float32Array:
|
|
291
|
+
return i.DT_FLOAT32;
|
|
292
|
+
case Int8Array:
|
|
293
|
+
return i.DT_INT8;
|
|
294
|
+
case Int16Array:
|
|
295
|
+
return i.DT_INT16;
|
|
296
|
+
case Int32Array:
|
|
297
|
+
return i.DT_INT32;
|
|
298
|
+
case Uint8Array:
|
|
299
|
+
return i.DT_UINT8;
|
|
300
|
+
case Uint16Array:
|
|
301
|
+
return i.DT_UINT16;
|
|
302
|
+
case Uint32Array:
|
|
303
|
+
return i.DT_UINT32;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
class rn extends Xe {
|
|
308
|
+
/**
|
|
309
|
+
* Constructs a new glTF loader.
|
|
310
|
+
*
|
|
311
|
+
* @param {LoadingManager} [manager] - The loading manager.
|
|
312
|
+
*/
|
|
313
|
+
constructor(e) {
|
|
314
|
+
super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) {
|
|
315
|
+
return new un(t);
|
|
316
|
+
}), this.register(function(t) {
|
|
317
|
+
return new dn(t);
|
|
318
|
+
}), this.register(function(t) {
|
|
319
|
+
return new Rn(t);
|
|
320
|
+
}), this.register(function(t) {
|
|
321
|
+
return new bn(t);
|
|
322
|
+
}), this.register(function(t) {
|
|
323
|
+
return new An(t);
|
|
324
|
+
}), this.register(function(t) {
|
|
325
|
+
return new fn(t);
|
|
326
|
+
}), this.register(function(t) {
|
|
327
|
+
return new pn(t);
|
|
328
|
+
}), this.register(function(t) {
|
|
329
|
+
return new mn(t);
|
|
330
|
+
}), this.register(function(t) {
|
|
331
|
+
return new gn(t);
|
|
332
|
+
}), this.register(function(t) {
|
|
333
|
+
return new ln(t);
|
|
334
|
+
}), this.register(function(t) {
|
|
335
|
+
return new Tn(t);
|
|
336
|
+
}), this.register(function(t) {
|
|
337
|
+
return new hn(t);
|
|
338
|
+
}), this.register(function(t) {
|
|
339
|
+
return new yn(t);
|
|
340
|
+
}), this.register(function(t) {
|
|
341
|
+
return new xn(t);
|
|
342
|
+
}), this.register(function(t) {
|
|
343
|
+
return new an(t);
|
|
344
|
+
}), this.register(function(t) {
|
|
345
|
+
return new wn(t);
|
|
346
|
+
}), this.register(function(t) {
|
|
347
|
+
return new _n(t);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Starts loading from the given URL and passes the loaded glTF asset
|
|
352
|
+
* to the `onLoad()` callback.
|
|
353
|
+
*
|
|
354
|
+
* @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
|
|
355
|
+
* @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
|
|
356
|
+
* @param {onProgressCallback} onProgress - Executed while the loading is in progress.
|
|
357
|
+
* @param {onErrorCallback} onError - Executed when errors occur.
|
|
358
|
+
*/
|
|
359
|
+
load(e, t, r, n) {
|
|
360
|
+
const s = this;
|
|
361
|
+
let i;
|
|
362
|
+
if (this.resourcePath !== "")
|
|
363
|
+
i = this.resourcePath;
|
|
364
|
+
else if (this.path !== "") {
|
|
365
|
+
const c = oe.extractUrlBase(e);
|
|
366
|
+
i = oe.resolveURL(c, this.path);
|
|
367
|
+
} else
|
|
368
|
+
i = oe.extractUrlBase(e);
|
|
369
|
+
this.manager.itemStart(e);
|
|
370
|
+
const a = function(c) {
|
|
371
|
+
n ? n(c) : console.error(c), s.manager.itemError(e), s.manager.itemEnd(e);
|
|
372
|
+
}, o = new le(this.manager);
|
|
373
|
+
o.setPath(this.path), o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(e, function(c) {
|
|
374
|
+
try {
|
|
375
|
+
s.parse(c, i, function(u) {
|
|
376
|
+
t(u), s.manager.itemEnd(e);
|
|
377
|
+
}, a);
|
|
378
|
+
} catch (u) {
|
|
379
|
+
a(u);
|
|
380
|
+
}
|
|
381
|
+
}, r, a);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Sets the given Draco loader to this loader. Required for decoding assets
|
|
385
|
+
* compressed with the `KHR_draco_mesh_compression` extension.
|
|
386
|
+
*
|
|
387
|
+
* @param {DRACOLoader} dracoLoader - The Draco loader to set.
|
|
388
|
+
* @return {GLTFLoader} A reference to this loader.
|
|
389
|
+
*/
|
|
390
|
+
setDRACOLoader(e) {
|
|
391
|
+
return this.dracoLoader = e, this;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Sets the given KTX2 loader to this loader. Required for loading KTX2
|
|
395
|
+
* compressed textures.
|
|
396
|
+
*
|
|
397
|
+
* @param {KTX2Loader} ktx2Loader - The KTX2 loader to set.
|
|
398
|
+
* @return {GLTFLoader} A reference to this loader.
|
|
399
|
+
*/
|
|
400
|
+
setKTX2Loader(e) {
|
|
401
|
+
return this.ktx2Loader = e, this;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Sets the given meshopt decoder. Required for decoding assets
|
|
405
|
+
* compressed with the `EXT_meshopt_compression` extension.
|
|
406
|
+
*
|
|
407
|
+
* @param {Object} meshoptDecoder - The meshopt decoder to set.
|
|
408
|
+
* @return {GLTFLoader} A reference to this loader.
|
|
409
|
+
*/
|
|
410
|
+
setMeshoptDecoder(e) {
|
|
411
|
+
return this.meshoptDecoder = e, this;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Registers a plugin callback. This API is internally used to implement the various
|
|
415
|
+
* glTF extensions but can also used by third-party code to add additional logic
|
|
416
|
+
* to the loader.
|
|
417
|
+
*
|
|
418
|
+
* @param {function(parser:GLTFParser)} callback - The callback function to register.
|
|
419
|
+
* @return {GLTFLoader} A reference to this loader.
|
|
420
|
+
*/
|
|
421
|
+
register(e) {
|
|
422
|
+
return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Unregisters a plugin callback.
|
|
426
|
+
*
|
|
427
|
+
* @param {Function} callback - The callback function to unregister.
|
|
428
|
+
* @return {GLTFLoader} A reference to this loader.
|
|
429
|
+
*/
|
|
430
|
+
unregister(e) {
|
|
431
|
+
return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Parses the given FBX data and returns the resulting group.
|
|
435
|
+
*
|
|
436
|
+
* @param {string|ArrayBuffer} data - The raw glTF data.
|
|
437
|
+
* @param {string} path - The URL base path.
|
|
438
|
+
* @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
|
|
439
|
+
* @param {onErrorCallback} onError - Executed when errors occur.
|
|
440
|
+
*/
|
|
441
|
+
parse(e, t, r, n) {
|
|
442
|
+
let s;
|
|
443
|
+
const i = {}, a = {}, o = new TextDecoder();
|
|
444
|
+
if (typeof e == "string")
|
|
445
|
+
s = JSON.parse(e);
|
|
446
|
+
else if (e instanceof ArrayBuffer)
|
|
447
|
+
if (o.decode(new Uint8Array(e, 0, 4)) === nt) {
|
|
448
|
+
try {
|
|
449
|
+
i[R.KHR_BINARY_GLTF] = new En(e);
|
|
450
|
+
} catch (l) {
|
|
451
|
+
n && n(l);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
s = JSON.parse(i[R.KHR_BINARY_GLTF].content);
|
|
455
|
+
} else
|
|
456
|
+
s = JSON.parse(o.decode(e));
|
|
457
|
+
else
|
|
458
|
+
s = e;
|
|
459
|
+
if (s.asset === void 0 || s.asset.version[0] < 2) {
|
|
460
|
+
n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const c = new Hn(s, {
|
|
464
|
+
path: t || this.resourcePath || "",
|
|
465
|
+
crossOrigin: this.crossOrigin,
|
|
466
|
+
requestHeader: this.requestHeader,
|
|
467
|
+
manager: this.manager,
|
|
468
|
+
ktx2Loader: this.ktx2Loader,
|
|
469
|
+
meshoptDecoder: this.meshoptDecoder
|
|
470
|
+
});
|
|
471
|
+
c.fileLoader.setRequestHeader(this.requestHeader);
|
|
472
|
+
for (let u = 0; u < this.pluginCallbacks.length; u++) {
|
|
473
|
+
const l = this.pluginCallbacks[u](c);
|
|
474
|
+
l.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[l.name] = l, i[l.name] = !0;
|
|
475
|
+
}
|
|
476
|
+
if (s.extensionsUsed)
|
|
477
|
+
for (let u = 0; u < s.extensionsUsed.length; ++u) {
|
|
478
|
+
const l = s.extensionsUsed[u], d = s.extensionsRequired || [];
|
|
479
|
+
switch (l) {
|
|
480
|
+
case R.KHR_MATERIALS_UNLIT:
|
|
481
|
+
i[l] = new cn();
|
|
482
|
+
break;
|
|
483
|
+
case R.KHR_DRACO_MESH_COMPRESSION:
|
|
484
|
+
i[l] = new Sn(s, this.dracoLoader);
|
|
485
|
+
break;
|
|
486
|
+
case R.KHR_TEXTURE_TRANSFORM:
|
|
487
|
+
i[l] = new Ln();
|
|
488
|
+
break;
|
|
489
|
+
case R.KHR_MESH_QUANTIZATION:
|
|
490
|
+
i[l] = new Mn();
|
|
491
|
+
break;
|
|
492
|
+
default:
|
|
493
|
+
d.indexOf(l) >= 0 && a[l] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + l + '".');
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
c.setExtensions(i), c.setPlugins(a), c.parse(r, n);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Async version of {@link GLTFLoader#parse}.
|
|
500
|
+
*
|
|
501
|
+
* @async
|
|
502
|
+
* @param {string|ArrayBuffer} data - The raw glTF data.
|
|
503
|
+
* @param {string} path - The URL base path.
|
|
504
|
+
* @return {Promise<GLTFLoader~LoadObject>} A Promise that resolves with the loaded glTF when the parsing has been finished.
|
|
505
|
+
*/
|
|
506
|
+
parseAsync(e, t) {
|
|
507
|
+
const r = this;
|
|
508
|
+
return new Promise(function(n, s) {
|
|
509
|
+
r.parse(e, t, n, s);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function on() {
|
|
514
|
+
let h = {};
|
|
515
|
+
return {
|
|
516
|
+
get: function(e) {
|
|
517
|
+
return h[e];
|
|
518
|
+
},
|
|
519
|
+
add: function(e, t) {
|
|
520
|
+
h[e] = t;
|
|
521
|
+
},
|
|
522
|
+
remove: function(e) {
|
|
523
|
+
delete h[e];
|
|
524
|
+
},
|
|
525
|
+
removeAll: function() {
|
|
526
|
+
h = {};
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
const R = {
|
|
531
|
+
KHR_BINARY_GLTF: "KHR_binary_glTF",
|
|
532
|
+
KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
|
|
533
|
+
KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
|
|
534
|
+
KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
|
|
535
|
+
KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion",
|
|
536
|
+
KHR_MATERIALS_IOR: "KHR_materials_ior",
|
|
537
|
+
KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
|
|
538
|
+
KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
|
|
539
|
+
KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
|
|
540
|
+
KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
|
|
541
|
+
KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
|
|
542
|
+
KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
|
|
543
|
+
KHR_MATERIALS_VOLUME: "KHR_materials_volume",
|
|
544
|
+
KHR_TEXTURE_BASISU: "KHR_texture_basisu",
|
|
545
|
+
KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
|
|
546
|
+
KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
|
|
547
|
+
KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
|
|
548
|
+
EXT_MATERIALS_BUMP: "EXT_materials_bump",
|
|
549
|
+
EXT_TEXTURE_WEBP: "EXT_texture_webp",
|
|
550
|
+
EXT_TEXTURE_AVIF: "EXT_texture_avif",
|
|
551
|
+
EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
|
|
552
|
+
EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
|
|
553
|
+
};
|
|
554
|
+
class an {
|
|
555
|
+
constructor(e) {
|
|
556
|
+
this.parser = e, this.name = R.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
|
|
557
|
+
}
|
|
558
|
+
_markDefs() {
|
|
559
|
+
const e = this.parser, t = this.parser.json.nodes || [];
|
|
560
|
+
for (let r = 0, n = t.length; r < n; r++) {
|
|
561
|
+
const s = t[r];
|
|
562
|
+
s.extensions && s.extensions[this.name] && s.extensions[this.name].light !== void 0 && e._addNodeRef(this.cache, s.extensions[this.name].light);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
_loadLight(e) {
|
|
566
|
+
const t = this.parser, r = "light:" + e;
|
|
567
|
+
let n = t.cache.get(r);
|
|
568
|
+
if (n) return n;
|
|
569
|
+
const s = t.json, o = ((s.extensions && s.extensions[this.name] || {}).lights || [])[e];
|
|
570
|
+
let c;
|
|
571
|
+
const u = new G(16777215);
|
|
572
|
+
o.color !== void 0 && u.setRGB(o.color[0], o.color[1], o.color[2], F);
|
|
573
|
+
const l = o.range !== void 0 ? o.range : 0;
|
|
574
|
+
switch (o.type) {
|
|
575
|
+
case "directional":
|
|
576
|
+
c = new ht(u), c.target.position.set(0, 0, -1), c.add(c.target);
|
|
577
|
+
break;
|
|
578
|
+
case "point":
|
|
579
|
+
c = new dt(u), c.distance = l;
|
|
580
|
+
break;
|
|
581
|
+
case "spot":
|
|
582
|
+
c = new ut(u), c.distance = l, o.spot = o.spot || {}, o.spot.innerConeAngle = o.spot.innerConeAngle !== void 0 ? o.spot.innerConeAngle : 0, o.spot.outerConeAngle = o.spot.outerConeAngle !== void 0 ? o.spot.outerConeAngle : Math.PI / 4, c.angle = o.spot.outerConeAngle, c.penumbra = 1 - o.spot.innerConeAngle / o.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target);
|
|
583
|
+
break;
|
|
584
|
+
default:
|
|
585
|
+
throw new Error("THREE.GLTFLoader: Unexpected light type: " + o.type);
|
|
586
|
+
}
|
|
587
|
+
return c.position.set(0, 0, 0), U(c, o), o.intensity !== void 0 && (c.intensity = o.intensity), c.name = t.createUniqueName(o.name || "light_" + e), n = Promise.resolve(c), t.cache.add(r, n), n;
|
|
588
|
+
}
|
|
589
|
+
getDependency(e, t) {
|
|
590
|
+
if (e === "light")
|
|
591
|
+
return this._loadLight(t);
|
|
592
|
+
}
|
|
593
|
+
createNodeAttachment(e) {
|
|
594
|
+
const t = this, r = this.parser, s = r.json.nodes[e], a = (s.extensions && s.extensions[this.name] || {}).light;
|
|
595
|
+
return a === void 0 ? null : this._loadLight(a).then(function(o) {
|
|
596
|
+
return r._getNodeRef(t.cache, a, o);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
class cn {
|
|
601
|
+
constructor() {
|
|
602
|
+
this.name = R.KHR_MATERIALS_UNLIT;
|
|
603
|
+
}
|
|
604
|
+
getMaterialType() {
|
|
605
|
+
return re;
|
|
606
|
+
}
|
|
607
|
+
extendParams(e, t, r) {
|
|
608
|
+
const n = [];
|
|
609
|
+
e.color = new G(1, 1, 1), e.opacity = 1;
|
|
610
|
+
const s = t.pbrMetallicRoughness;
|
|
611
|
+
if (s) {
|
|
612
|
+
if (Array.isArray(s.baseColorFactor)) {
|
|
613
|
+
const i = s.baseColorFactor;
|
|
614
|
+
e.color.setRGB(i[0], i[1], i[2], F), e.opacity = i[3];
|
|
615
|
+
}
|
|
616
|
+
s.baseColorTexture !== void 0 && n.push(r.assignTexture(e, "map", s.baseColorTexture, V));
|
|
617
|
+
}
|
|
618
|
+
return Promise.all(n);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
class ln {
|
|
622
|
+
constructor(e) {
|
|
623
|
+
this.parser = e, this.name = R.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
624
|
+
}
|
|
625
|
+
extendMaterialParams(e, t) {
|
|
626
|
+
const n = this.parser.json.materials[e];
|
|
627
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
628
|
+
return Promise.resolve();
|
|
629
|
+
const s = n.extensions[this.name].emissiveStrength;
|
|
630
|
+
return s !== void 0 && (t.emissiveIntensity = s), Promise.resolve();
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
class un {
|
|
634
|
+
constructor(e) {
|
|
635
|
+
this.parser = e, this.name = R.KHR_MATERIALS_CLEARCOAT;
|
|
636
|
+
}
|
|
637
|
+
getMaterialType(e) {
|
|
638
|
+
const r = this.parser.json.materials[e];
|
|
639
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
640
|
+
}
|
|
641
|
+
extendMaterialParams(e, t) {
|
|
642
|
+
const r = this.parser, n = r.json.materials[e];
|
|
643
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
644
|
+
return Promise.resolve();
|
|
645
|
+
const s = [], i = n.extensions[this.name];
|
|
646
|
+
if (i.clearcoatFactor !== void 0 && (t.clearcoat = i.clearcoatFactor), i.clearcoatTexture !== void 0 && s.push(r.assignTexture(t, "clearcoatMap", i.clearcoatTexture)), i.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = i.clearcoatRoughnessFactor), i.clearcoatRoughnessTexture !== void 0 && s.push(r.assignTexture(t, "clearcoatRoughnessMap", i.clearcoatRoughnessTexture)), i.clearcoatNormalTexture !== void 0 && (s.push(r.assignTexture(t, "clearcoatNormalMap", i.clearcoatNormalTexture)), i.clearcoatNormalTexture.scale !== void 0)) {
|
|
647
|
+
const a = i.clearcoatNormalTexture.scale;
|
|
648
|
+
t.clearcoatNormalScale = new Se(a, a);
|
|
649
|
+
}
|
|
650
|
+
return Promise.all(s);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
class dn {
|
|
654
|
+
constructor(e) {
|
|
655
|
+
this.parser = e, this.name = R.KHR_MATERIALS_DISPERSION;
|
|
656
|
+
}
|
|
657
|
+
getMaterialType(e) {
|
|
658
|
+
const r = this.parser.json.materials[e];
|
|
659
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
660
|
+
}
|
|
661
|
+
extendMaterialParams(e, t) {
|
|
662
|
+
const n = this.parser.json.materials[e];
|
|
663
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
664
|
+
return Promise.resolve();
|
|
665
|
+
const s = n.extensions[this.name];
|
|
666
|
+
return t.dispersion = s.dispersion !== void 0 ? s.dispersion : 0, Promise.resolve();
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
class hn {
|
|
670
|
+
constructor(e) {
|
|
671
|
+
this.parser = e, this.name = R.KHR_MATERIALS_IRIDESCENCE;
|
|
672
|
+
}
|
|
673
|
+
getMaterialType(e) {
|
|
674
|
+
const r = this.parser.json.materials[e];
|
|
675
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
676
|
+
}
|
|
677
|
+
extendMaterialParams(e, t) {
|
|
678
|
+
const r = this.parser, n = r.json.materials[e];
|
|
679
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
680
|
+
return Promise.resolve();
|
|
681
|
+
const s = [], i = n.extensions[this.name];
|
|
682
|
+
return i.iridescenceFactor !== void 0 && (t.iridescence = i.iridescenceFactor), i.iridescenceTexture !== void 0 && s.push(r.assignTexture(t, "iridescenceMap", i.iridescenceTexture)), i.iridescenceIor !== void 0 && (t.iridescenceIOR = i.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), i.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = i.iridescenceThicknessMinimum), i.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = i.iridescenceThicknessMaximum), i.iridescenceThicknessTexture !== void 0 && s.push(r.assignTexture(t, "iridescenceThicknessMap", i.iridescenceThicknessTexture)), Promise.all(s);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
class fn {
|
|
686
|
+
constructor(e) {
|
|
687
|
+
this.parser = e, this.name = R.KHR_MATERIALS_SHEEN;
|
|
688
|
+
}
|
|
689
|
+
getMaterialType(e) {
|
|
690
|
+
const r = this.parser.json.materials[e];
|
|
691
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
692
|
+
}
|
|
693
|
+
extendMaterialParams(e, t) {
|
|
694
|
+
const r = this.parser, n = r.json.materials[e];
|
|
695
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
696
|
+
return Promise.resolve();
|
|
697
|
+
const s = [];
|
|
698
|
+
t.sheenColor = new G(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1;
|
|
699
|
+
const i = n.extensions[this.name];
|
|
700
|
+
if (i.sheenColorFactor !== void 0) {
|
|
701
|
+
const a = i.sheenColorFactor;
|
|
702
|
+
t.sheenColor.setRGB(a[0], a[1], a[2], F);
|
|
703
|
+
}
|
|
704
|
+
return i.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = i.sheenRoughnessFactor), i.sheenColorTexture !== void 0 && s.push(r.assignTexture(t, "sheenColorMap", i.sheenColorTexture, V)), i.sheenRoughnessTexture !== void 0 && s.push(r.assignTexture(t, "sheenRoughnessMap", i.sheenRoughnessTexture)), Promise.all(s);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
class pn {
|
|
708
|
+
constructor(e) {
|
|
709
|
+
this.parser = e, this.name = R.KHR_MATERIALS_TRANSMISSION;
|
|
710
|
+
}
|
|
711
|
+
getMaterialType(e) {
|
|
712
|
+
const r = this.parser.json.materials[e];
|
|
713
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
714
|
+
}
|
|
715
|
+
extendMaterialParams(e, t) {
|
|
716
|
+
const r = this.parser, n = r.json.materials[e];
|
|
717
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
718
|
+
return Promise.resolve();
|
|
719
|
+
const s = [], i = n.extensions[this.name];
|
|
720
|
+
return i.transmissionFactor !== void 0 && (t.transmission = i.transmissionFactor), i.transmissionTexture !== void 0 && s.push(r.assignTexture(t, "transmissionMap", i.transmissionTexture)), Promise.all(s);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
class mn {
|
|
724
|
+
constructor(e) {
|
|
725
|
+
this.parser = e, this.name = R.KHR_MATERIALS_VOLUME;
|
|
726
|
+
}
|
|
727
|
+
getMaterialType(e) {
|
|
728
|
+
const r = this.parser.json.materials[e];
|
|
729
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
730
|
+
}
|
|
731
|
+
extendMaterialParams(e, t) {
|
|
732
|
+
const r = this.parser, n = r.json.materials[e];
|
|
733
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
734
|
+
return Promise.resolve();
|
|
735
|
+
const s = [], i = n.extensions[this.name];
|
|
736
|
+
t.thickness = i.thicknessFactor !== void 0 ? i.thicknessFactor : 0, i.thicknessTexture !== void 0 && s.push(r.assignTexture(t, "thicknessMap", i.thicknessTexture)), t.attenuationDistance = i.attenuationDistance || 1 / 0;
|
|
737
|
+
const a = i.attenuationColor || [1, 1, 1];
|
|
738
|
+
return t.attenuationColor = new G().setRGB(a[0], a[1], a[2], F), Promise.all(s);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
class gn {
|
|
742
|
+
constructor(e) {
|
|
743
|
+
this.parser = e, this.name = R.KHR_MATERIALS_IOR;
|
|
744
|
+
}
|
|
745
|
+
getMaterialType(e) {
|
|
746
|
+
const r = this.parser.json.materials[e];
|
|
747
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
748
|
+
}
|
|
749
|
+
extendMaterialParams(e, t) {
|
|
750
|
+
const n = this.parser.json.materials[e];
|
|
751
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
752
|
+
return Promise.resolve();
|
|
753
|
+
const s = n.extensions[this.name];
|
|
754
|
+
return t.ior = s.ior !== void 0 ? s.ior : 1.5, Promise.resolve();
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
class Tn {
|
|
758
|
+
constructor(e) {
|
|
759
|
+
this.parser = e, this.name = R.KHR_MATERIALS_SPECULAR;
|
|
760
|
+
}
|
|
761
|
+
getMaterialType(e) {
|
|
762
|
+
const r = this.parser.json.materials[e];
|
|
763
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
764
|
+
}
|
|
765
|
+
extendMaterialParams(e, t) {
|
|
766
|
+
const r = this.parser, n = r.json.materials[e];
|
|
767
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
768
|
+
return Promise.resolve();
|
|
769
|
+
const s = [], i = n.extensions[this.name];
|
|
770
|
+
t.specularIntensity = i.specularFactor !== void 0 ? i.specularFactor : 1, i.specularTexture !== void 0 && s.push(r.assignTexture(t, "specularIntensityMap", i.specularTexture));
|
|
771
|
+
const a = i.specularColorFactor || [1, 1, 1];
|
|
772
|
+
return t.specularColor = new G().setRGB(a[0], a[1], a[2], F), i.specularColorTexture !== void 0 && s.push(r.assignTexture(t, "specularColorMap", i.specularColorTexture, V)), Promise.all(s);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
class xn {
|
|
776
|
+
constructor(e) {
|
|
777
|
+
this.parser = e, this.name = R.EXT_MATERIALS_BUMP;
|
|
778
|
+
}
|
|
779
|
+
getMaterialType(e) {
|
|
780
|
+
const r = this.parser.json.materials[e];
|
|
781
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
782
|
+
}
|
|
783
|
+
extendMaterialParams(e, t) {
|
|
784
|
+
const r = this.parser, n = r.json.materials[e];
|
|
785
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
786
|
+
return Promise.resolve();
|
|
787
|
+
const s = [], i = n.extensions[this.name];
|
|
788
|
+
return t.bumpScale = i.bumpFactor !== void 0 ? i.bumpFactor : 1, i.bumpTexture !== void 0 && s.push(r.assignTexture(t, "bumpMap", i.bumpTexture)), Promise.all(s);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
class yn {
|
|
792
|
+
constructor(e) {
|
|
793
|
+
this.parser = e, this.name = R.KHR_MATERIALS_ANISOTROPY;
|
|
794
|
+
}
|
|
795
|
+
getMaterialType(e) {
|
|
796
|
+
const r = this.parser.json.materials[e];
|
|
797
|
+
return !r.extensions || !r.extensions[this.name] ? null : v;
|
|
798
|
+
}
|
|
799
|
+
extendMaterialParams(e, t) {
|
|
800
|
+
const r = this.parser, n = r.json.materials[e];
|
|
801
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
802
|
+
return Promise.resolve();
|
|
803
|
+
const s = [], i = n.extensions[this.name];
|
|
804
|
+
return i.anisotropyStrength !== void 0 && (t.anisotropy = i.anisotropyStrength), i.anisotropyRotation !== void 0 && (t.anisotropyRotation = i.anisotropyRotation), i.anisotropyTexture !== void 0 && s.push(r.assignTexture(t, "anisotropyMap", i.anisotropyTexture)), Promise.all(s);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
class Rn {
|
|
808
|
+
constructor(e) {
|
|
809
|
+
this.parser = e, this.name = R.KHR_TEXTURE_BASISU;
|
|
810
|
+
}
|
|
811
|
+
loadTexture(e) {
|
|
812
|
+
const t = this.parser, r = t.json, n = r.textures[e];
|
|
813
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
814
|
+
return null;
|
|
815
|
+
const s = n.extensions[this.name], i = t.options.ktx2Loader;
|
|
816
|
+
if (!i) {
|
|
817
|
+
if (r.extensionsRequired && r.extensionsRequired.indexOf(this.name) >= 0)
|
|
818
|
+
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
821
|
+
return t.loadTextureImage(e, s.source, i);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
class bn {
|
|
825
|
+
constructor(e) {
|
|
826
|
+
this.parser = e, this.name = R.EXT_TEXTURE_WEBP;
|
|
827
|
+
}
|
|
828
|
+
loadTexture(e) {
|
|
829
|
+
const t = this.name, r = this.parser, n = r.json, s = n.textures[e];
|
|
830
|
+
if (!s.extensions || !s.extensions[t])
|
|
831
|
+
return null;
|
|
832
|
+
const i = s.extensions[t], a = n.images[i.source];
|
|
833
|
+
let o = r.textureLoader;
|
|
834
|
+
if (a.uri) {
|
|
835
|
+
const c = r.options.manager.getHandler(a.uri);
|
|
836
|
+
c !== null && (o = c);
|
|
837
|
+
}
|
|
838
|
+
return r.loadTextureImage(e, i.source, o);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
class An {
|
|
842
|
+
constructor(e) {
|
|
843
|
+
this.parser = e, this.name = R.EXT_TEXTURE_AVIF;
|
|
844
|
+
}
|
|
845
|
+
loadTexture(e) {
|
|
846
|
+
const t = this.name, r = this.parser, n = r.json, s = n.textures[e];
|
|
847
|
+
if (!s.extensions || !s.extensions[t])
|
|
848
|
+
return null;
|
|
849
|
+
const i = s.extensions[t], a = n.images[i.source];
|
|
850
|
+
let o = r.textureLoader;
|
|
851
|
+
if (a.uri) {
|
|
852
|
+
const c = r.options.manager.getHandler(a.uri);
|
|
853
|
+
c !== null && (o = c);
|
|
854
|
+
}
|
|
855
|
+
return r.loadTextureImage(e, i.source, o);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
class wn {
|
|
859
|
+
constructor(e) {
|
|
860
|
+
this.name = R.EXT_MESHOPT_COMPRESSION, this.parser = e;
|
|
861
|
+
}
|
|
862
|
+
loadBufferView(e) {
|
|
863
|
+
const t = this.parser.json, r = t.bufferViews[e];
|
|
864
|
+
if (r.extensions && r.extensions[this.name]) {
|
|
865
|
+
const n = r.extensions[this.name], s = this.parser.getDependency("buffer", n.buffer), i = this.parser.options.meshoptDecoder;
|
|
866
|
+
if (!i || !i.supported) {
|
|
867
|
+
if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0)
|
|
868
|
+
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
return s.then(function(a) {
|
|
872
|
+
const o = n.byteOffset || 0, c = n.byteLength || 0, u = n.count, l = n.byteStride, d = new Uint8Array(a, o, c);
|
|
873
|
+
return i.decodeGltfBufferAsync ? i.decodeGltfBufferAsync(u, l, d, n.mode, n.filter).then(function(f) {
|
|
874
|
+
return f.buffer;
|
|
875
|
+
}) : i.ready.then(function() {
|
|
876
|
+
const f = new ArrayBuffer(u * l);
|
|
877
|
+
return i.decodeGltfBuffer(new Uint8Array(f), u, l, d, n.mode, n.filter), f;
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
} else
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
class _n {
|
|
885
|
+
constructor(e) {
|
|
886
|
+
this.name = R.EXT_MESH_GPU_INSTANCING, this.parser = e;
|
|
887
|
+
}
|
|
888
|
+
createNodeMesh(e) {
|
|
889
|
+
const t = this.parser.json, r = t.nodes[e];
|
|
890
|
+
if (!r.extensions || !r.extensions[this.name] || r.mesh === void 0)
|
|
891
|
+
return null;
|
|
892
|
+
const n = t.meshes[r.mesh];
|
|
893
|
+
for (const c of n.primitives)
|
|
894
|
+
if (c.mode !== O.TRIANGLES && c.mode !== O.TRIANGLE_STRIP && c.mode !== O.TRIANGLE_FAN && c.mode !== void 0)
|
|
895
|
+
return null;
|
|
896
|
+
const i = r.extensions[this.name].attributes, a = [], o = {};
|
|
897
|
+
for (const c in i)
|
|
898
|
+
a.push(this.parser.getDependency("accessor", i[c]).then((u) => (o[c] = u, o[c])));
|
|
899
|
+
return a.length < 1 ? null : (a.push(this.parser.createNodeMesh(e)), Promise.all(a).then((c) => {
|
|
900
|
+
const u = c.pop(), l = u.isGroup ? u.children : [u], d = c[0].count, f = [];
|
|
901
|
+
for (const p of l) {
|
|
902
|
+
const T = new ee(), m = new _(), g = new We(), b = new _(1, 1, 1), S = new ft(p.geometry, p.material, d);
|
|
903
|
+
for (let y = 0; y < d; y++)
|
|
904
|
+
o.TRANSLATION && m.fromBufferAttribute(o.TRANSLATION, y), o.ROTATION && g.fromBufferAttribute(o.ROTATION, y), o.SCALE && b.fromBufferAttribute(o.SCALE, y), S.setMatrixAt(y, T.compose(m, g, b));
|
|
905
|
+
for (const y in o)
|
|
906
|
+
if (y === "_COLOR_0") {
|
|
907
|
+
const I = o[y];
|
|
908
|
+
S.instanceColor = new pt(I.array, I.itemSize, I.normalized);
|
|
909
|
+
} else y !== "TRANSLATION" && y !== "ROTATION" && y !== "SCALE" && p.geometry.setAttribute(y, o[y]);
|
|
910
|
+
Ye.prototype.copy.call(S, p), this.parser.assignFinalMaterial(S), f.push(S);
|
|
911
|
+
}
|
|
912
|
+
return u.isGroup ? (u.clear(), u.add(...f), u) : f[0];
|
|
913
|
+
}));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const nt = "glTF", se = 12, Fe = { JSON: 1313821514, BIN: 5130562 };
|
|
917
|
+
class En {
|
|
918
|
+
constructor(e) {
|
|
919
|
+
this.name = R.KHR_BINARY_GLTF, this.content = null, this.body = null;
|
|
920
|
+
const t = new DataView(e, 0, se), r = new TextDecoder();
|
|
921
|
+
if (this.header = {
|
|
922
|
+
magic: r.decode(new Uint8Array(e.slice(0, 4))),
|
|
923
|
+
version: t.getUint32(4, !0),
|
|
924
|
+
length: t.getUint32(8, !0)
|
|
925
|
+
}, this.header.magic !== nt)
|
|
926
|
+
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
|
|
927
|
+
if (this.header.version < 2)
|
|
928
|
+
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
|
|
929
|
+
const n = this.header.length - se, s = new DataView(e, se);
|
|
930
|
+
let i = 0;
|
|
931
|
+
for (; i < n; ) {
|
|
932
|
+
const a = s.getUint32(i, !0);
|
|
933
|
+
i += 4;
|
|
934
|
+
const o = s.getUint32(i, !0);
|
|
935
|
+
if (i += 4, o === Fe.JSON) {
|
|
936
|
+
const c = new Uint8Array(e, se + i, a);
|
|
937
|
+
this.content = r.decode(c);
|
|
938
|
+
} else if (o === Fe.BIN) {
|
|
939
|
+
const c = se + i;
|
|
940
|
+
this.body = e.slice(c, c + a);
|
|
941
|
+
}
|
|
942
|
+
i += a;
|
|
943
|
+
}
|
|
944
|
+
if (this.content === null)
|
|
945
|
+
throw new Error("THREE.GLTFLoader: JSON content not found.");
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
class Sn {
|
|
949
|
+
constructor(e, t) {
|
|
950
|
+
if (!t)
|
|
951
|
+
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
|
|
952
|
+
this.name = R.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload();
|
|
953
|
+
}
|
|
954
|
+
decodePrimitive(e, t) {
|
|
955
|
+
const r = this.json, n = this.dracoLoader, s = e.extensions[this.name].bufferView, i = e.extensions[this.name].attributes, a = {}, o = {}, c = {};
|
|
956
|
+
for (const u in i) {
|
|
957
|
+
const l = we[u] || u.toLowerCase();
|
|
958
|
+
a[l] = i[u];
|
|
959
|
+
}
|
|
960
|
+
for (const u in e.attributes) {
|
|
961
|
+
const l = we[u] || u.toLowerCase();
|
|
962
|
+
if (i[u] !== void 0) {
|
|
963
|
+
const d = r.accessors[e.attributes[u]], f = $[d.componentType];
|
|
964
|
+
c[l] = f.name, o[l] = d.normalized === !0;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return t.getDependency("bufferView", s).then(function(u) {
|
|
968
|
+
return new Promise(function(l, d) {
|
|
969
|
+
n.decodeDracoFile(u, function(f) {
|
|
970
|
+
for (const p in f.attributes) {
|
|
971
|
+
const T = f.attributes[p], m = o[p];
|
|
972
|
+
m !== void 0 && (T.normalized = m);
|
|
973
|
+
}
|
|
974
|
+
l(f);
|
|
975
|
+
}, a, c, F, d);
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
class Ln {
|
|
981
|
+
constructor() {
|
|
982
|
+
this.name = R.KHR_TEXTURE_TRANSFORM;
|
|
983
|
+
}
|
|
984
|
+
extendTexture(e, t) {
|
|
985
|
+
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;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
class Mn {
|
|
989
|
+
constructor() {
|
|
990
|
+
this.name = R.KHR_MESH_QUANTIZATION;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
class st extends Gt {
|
|
994
|
+
constructor(e, t, r, n) {
|
|
995
|
+
super(e, t, r, n);
|
|
996
|
+
}
|
|
997
|
+
copySampleValue_(e) {
|
|
998
|
+
const t = this.resultBuffer, r = this.sampleValues, n = this.valueSize, s = e * n * 3 + n;
|
|
999
|
+
for (let i = 0; i !== n; i++)
|
|
1000
|
+
t[i] = r[s + i];
|
|
1001
|
+
return t;
|
|
1002
|
+
}
|
|
1003
|
+
interpolate_(e, t, r, n) {
|
|
1004
|
+
const s = this.resultBuffer, i = this.sampleValues, a = this.valueSize, o = a * 2, c = a * 3, u = n - t, l = (r - t) / u, d = l * l, f = d * l, p = e * c, T = p - c, m = -2 * f + 3 * d, g = f - d, b = 1 - m, S = g - d + l;
|
|
1005
|
+
for (let y = 0; y !== a; y++) {
|
|
1006
|
+
const I = i[T + y + a], P = i[T + y + o] * u, C = i[p + y + a], B = i[p + y] * u;
|
|
1007
|
+
s[y] = b * I + S * P + m * C + g * B;
|
|
1008
|
+
}
|
|
1009
|
+
return s;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
const In = new We();
|
|
1013
|
+
class Cn extends st {
|
|
1014
|
+
interpolate_(e, t, r, n) {
|
|
1015
|
+
const s = super.interpolate_(e, t, r, n);
|
|
1016
|
+
return In.fromArray(s).normalize().toArray(s), s;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
const O = {
|
|
1020
|
+
POINTS: 0,
|
|
1021
|
+
LINES: 1,
|
|
1022
|
+
LINE_LOOP: 2,
|
|
1023
|
+
LINE_STRIP: 3,
|
|
1024
|
+
TRIANGLES: 4,
|
|
1025
|
+
TRIANGLE_STRIP: 5,
|
|
1026
|
+
TRIANGLE_FAN: 6
|
|
1027
|
+
}, $ = {
|
|
1028
|
+
5120: Int8Array,
|
|
1029
|
+
5121: Uint8Array,
|
|
1030
|
+
5122: Int16Array,
|
|
1031
|
+
5123: Uint16Array,
|
|
1032
|
+
5125: Uint32Array,
|
|
1033
|
+
5126: Float32Array
|
|
1034
|
+
}, ve = {
|
|
1035
|
+
9728: Qe,
|
|
1036
|
+
9729: be,
|
|
1037
|
+
9984: bt,
|
|
1038
|
+
9985: Rt,
|
|
1039
|
+
9986: yt,
|
|
1040
|
+
9987: Je
|
|
1041
|
+
}, He = {
|
|
1042
|
+
33071: wt,
|
|
1043
|
+
33648: At,
|
|
1044
|
+
10497: Ae
|
|
1045
|
+
}, ge = {
|
|
1046
|
+
SCALAR: 1,
|
|
1047
|
+
VEC2: 2,
|
|
1048
|
+
VEC3: 3,
|
|
1049
|
+
VEC4: 4,
|
|
1050
|
+
MAT2: 4,
|
|
1051
|
+
MAT3: 9,
|
|
1052
|
+
MAT4: 16
|
|
1053
|
+
}, we = {
|
|
1054
|
+
POSITION: "position",
|
|
1055
|
+
NORMAL: "normal",
|
|
1056
|
+
TANGENT: "tangent",
|
|
1057
|
+
TEXCOORD_0: "uv",
|
|
1058
|
+
TEXCOORD_1: "uv1",
|
|
1059
|
+
TEXCOORD_2: "uv2",
|
|
1060
|
+
TEXCOORD_3: "uv3",
|
|
1061
|
+
COLOR_0: "color",
|
|
1062
|
+
WEIGHTS_0: "skinWeight",
|
|
1063
|
+
JOINTS_0: "skinIndex"
|
|
1064
|
+
}, K = {
|
|
1065
|
+
scale: "scale",
|
|
1066
|
+
translation: "position",
|
|
1067
|
+
rotation: "quaternion",
|
|
1068
|
+
weights: "morphTargetInfluences"
|
|
1069
|
+
}, Nn = {
|
|
1070
|
+
CUBICSPLINE: void 0,
|
|
1071
|
+
// We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
|
1072
|
+
// keyframe track will be initialized with a default interpolation type, then modified.
|
|
1073
|
+
LINEAR: et,
|
|
1074
|
+
STEP: Ht
|
|
1075
|
+
}, Te = {
|
|
1076
|
+
OPAQUE: "OPAQUE",
|
|
1077
|
+
MASK: "MASK",
|
|
1078
|
+
BLEND: "BLEND"
|
|
1079
|
+
};
|
|
1080
|
+
function On(h) {
|
|
1081
|
+
return h.DefaultMaterial === void 0 && (h.DefaultMaterial = new Ze({
|
|
1082
|
+
color: 16777215,
|
|
1083
|
+
emissive: 0,
|
|
1084
|
+
metalness: 1,
|
|
1085
|
+
roughness: 1,
|
|
1086
|
+
transparent: !1,
|
|
1087
|
+
depthTest: !0,
|
|
1088
|
+
side: Ut
|
|
1089
|
+
})), h.DefaultMaterial;
|
|
1090
|
+
}
|
|
1091
|
+
function q(h, e, t) {
|
|
1092
|
+
for (const r in t.extensions)
|
|
1093
|
+
h[r] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[r] = t.extensions[r]);
|
|
1094
|
+
}
|
|
1095
|
+
function U(h, e) {
|
|
1096
|
+
e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(h.userData, e.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + e.extras));
|
|
1097
|
+
}
|
|
1098
|
+
function Dn(h, e, t) {
|
|
1099
|
+
let r = !1, n = !1, s = !1;
|
|
1100
|
+
for (let c = 0, u = e.length; c < u; c++) {
|
|
1101
|
+
const l = e[c];
|
|
1102
|
+
if (l.POSITION !== void 0 && (r = !0), l.NORMAL !== void 0 && (n = !0), l.COLOR_0 !== void 0 && (s = !0), r && n && s) break;
|
|
1103
|
+
}
|
|
1104
|
+
if (!r && !n && !s) return Promise.resolve(h);
|
|
1105
|
+
const i = [], a = [], o = [];
|
|
1106
|
+
for (let c = 0, u = e.length; c < u; c++) {
|
|
1107
|
+
const l = e[c];
|
|
1108
|
+
if (r) {
|
|
1109
|
+
const d = l.POSITION !== void 0 ? t.getDependency("accessor", l.POSITION) : h.attributes.position;
|
|
1110
|
+
i.push(d);
|
|
1111
|
+
}
|
|
1112
|
+
if (n) {
|
|
1113
|
+
const d = l.NORMAL !== void 0 ? t.getDependency("accessor", l.NORMAL) : h.attributes.normal;
|
|
1114
|
+
a.push(d);
|
|
1115
|
+
}
|
|
1116
|
+
if (s) {
|
|
1117
|
+
const d = l.COLOR_0 !== void 0 ? t.getDependency("accessor", l.COLOR_0) : h.attributes.color;
|
|
1118
|
+
o.push(d);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return Promise.all([
|
|
1122
|
+
Promise.all(i),
|
|
1123
|
+
Promise.all(a),
|
|
1124
|
+
Promise.all(o)
|
|
1125
|
+
]).then(function(c) {
|
|
1126
|
+
const u = c[0], l = c[1], d = c[2];
|
|
1127
|
+
return r && (h.morphAttributes.position = u), n && (h.morphAttributes.normal = l), s && (h.morphAttributes.color = d), h.morphTargetsRelative = !0, h;
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
function Pn(h, e) {
|
|
1131
|
+
if (h.updateMorphTargets(), e.weights !== void 0)
|
|
1132
|
+
for (let t = 0, r = e.weights.length; t < r; t++)
|
|
1133
|
+
h.morphTargetInfluences[t] = e.weights[t];
|
|
1134
|
+
if (e.extras && Array.isArray(e.extras.targetNames)) {
|
|
1135
|
+
const t = e.extras.targetNames;
|
|
1136
|
+
if (h.morphTargetInfluences.length === t.length) {
|
|
1137
|
+
h.morphTargetDictionary = {};
|
|
1138
|
+
for (let r = 0, n = t.length; r < n; r++)
|
|
1139
|
+
h.morphTargetDictionary[t[r]] = r;
|
|
1140
|
+
} else
|
|
1141
|
+
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
function kn(h) {
|
|
1145
|
+
let e;
|
|
1146
|
+
const t = h.extensions && h.extensions[R.KHR_DRACO_MESH_COMPRESSION];
|
|
1147
|
+
if (t ? e = "draco:" + t.bufferView + ":" + t.indices + ":" + xe(t.attributes) : e = h.indices + ":" + xe(h.attributes) + ":" + h.mode, h.targets !== void 0)
|
|
1148
|
+
for (let r = 0, n = h.targets.length; r < n; r++)
|
|
1149
|
+
e += ":" + xe(h.targets[r]);
|
|
1150
|
+
return e;
|
|
1151
|
+
}
|
|
1152
|
+
function xe(h) {
|
|
1153
|
+
let e = "";
|
|
1154
|
+
const t = Object.keys(h).sort();
|
|
1155
|
+
for (let r = 0, n = t.length; r < n; r++)
|
|
1156
|
+
e += t[r] + ":" + h[t[r]] + ";";
|
|
1157
|
+
return e;
|
|
1158
|
+
}
|
|
1159
|
+
function _e(h) {
|
|
1160
|
+
switch (h) {
|
|
1161
|
+
case Int8Array:
|
|
1162
|
+
return 1 / 127;
|
|
1163
|
+
case Uint8Array:
|
|
1164
|
+
return 1 / 255;
|
|
1165
|
+
case Int16Array:
|
|
1166
|
+
return 1 / 32767;
|
|
1167
|
+
case Uint16Array:
|
|
1168
|
+
return 1 / 65535;
|
|
1169
|
+
default:
|
|
1170
|
+
throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
function Fn(h) {
|
|
1174
|
+
return h.search(/\.jpe?g($|\?)/i) > 0 || h.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : h.search(/\.webp($|\?)/i) > 0 || h.search(/^data\:image\/webp/) === 0 ? "image/webp" : h.search(/\.ktx2($|\?)/i) > 0 || h.search(/^data\:image\/ktx2/) === 0 ? "image/ktx2" : "image/png";
|
|
1175
|
+
}
|
|
1176
|
+
const vn = new ee();
|
|
1177
|
+
class Hn {
|
|
1178
|
+
constructor(e = {}, t = {}) {
|
|
1179
|
+
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new on(), 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 = {};
|
|
1180
|
+
let r = !1, n = -1, s = !1, i = -1;
|
|
1181
|
+
if (typeof navigator < "u") {
|
|
1182
|
+
const a = navigator.userAgent;
|
|
1183
|
+
r = /^((?!chrome|android).)*safari/i.test(a) === !0;
|
|
1184
|
+
const o = a.match(/Version\/(\d+)/);
|
|
1185
|
+
n = r && o ? parseInt(o[1], 10) : -1, s = a.indexOf("Firefox") > -1, i = s ? a.match(/Firefox\/([0-9]+)\./)[1] : -1;
|
|
1186
|
+
}
|
|
1187
|
+
typeof createImageBitmap > "u" || r && n < 17 || s && i < 98 ? this.textureLoader = new mt(this.options.manager) : this.textureLoader = new gt(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new le(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
|
|
1188
|
+
}
|
|
1189
|
+
setExtensions(e) {
|
|
1190
|
+
this.extensions = e;
|
|
1191
|
+
}
|
|
1192
|
+
setPlugins(e) {
|
|
1193
|
+
this.plugins = e;
|
|
1194
|
+
}
|
|
1195
|
+
parse(e, t) {
|
|
1196
|
+
const r = this, n = this.json, s = this.extensions;
|
|
1197
|
+
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(i) {
|
|
1198
|
+
return i._markDefs && i._markDefs();
|
|
1199
|
+
}), Promise.all(this._invokeAll(function(i) {
|
|
1200
|
+
return i.beforeRoot && i.beforeRoot();
|
|
1201
|
+
})).then(function() {
|
|
1202
|
+
return Promise.all([
|
|
1203
|
+
r.getDependencies("scene"),
|
|
1204
|
+
r.getDependencies("animation"),
|
|
1205
|
+
r.getDependencies("camera")
|
|
1206
|
+
]);
|
|
1207
|
+
}).then(function(i) {
|
|
1208
|
+
const a = {
|
|
1209
|
+
scene: i[0][n.scene || 0],
|
|
1210
|
+
scenes: i[0],
|
|
1211
|
+
animations: i[1],
|
|
1212
|
+
cameras: i[2],
|
|
1213
|
+
asset: n.asset,
|
|
1214
|
+
parser: r,
|
|
1215
|
+
userData: {}
|
|
1216
|
+
};
|
|
1217
|
+
return q(s, a, n), U(a, n), Promise.all(r._invokeAll(function(o) {
|
|
1218
|
+
return o.afterRoot && o.afterRoot(a);
|
|
1219
|
+
})).then(function() {
|
|
1220
|
+
for (const o of a.scenes)
|
|
1221
|
+
o.updateMatrixWorld();
|
|
1222
|
+
e(a);
|
|
1223
|
+
});
|
|
1224
|
+
}).catch(t);
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Marks the special nodes/meshes in json for efficient parse.
|
|
1228
|
+
*
|
|
1229
|
+
* @private
|
|
1230
|
+
*/
|
|
1231
|
+
_markDefs() {
|
|
1232
|
+
const e = this.json.nodes || [], t = this.json.skins || [], r = this.json.meshes || [];
|
|
1233
|
+
for (let n = 0, s = t.length; n < s; n++) {
|
|
1234
|
+
const i = t[n].joints;
|
|
1235
|
+
for (let a = 0, o = i.length; a < o; a++)
|
|
1236
|
+
e[i[a]].isBone = !0;
|
|
1237
|
+
}
|
|
1238
|
+
for (let n = 0, s = e.length; n < s; n++) {
|
|
1239
|
+
const i = e[n];
|
|
1240
|
+
i.mesh !== void 0 && (this._addNodeRef(this.meshCache, i.mesh), i.skin !== void 0 && (r[i.mesh].isSkinnedMesh = !0)), i.camera !== void 0 && this._addNodeRef(this.cameraCache, i.camera);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Counts references to shared node / Object3D resources. These resources
|
|
1245
|
+
* can be reused, or "instantiated", at multiple nodes in the scene
|
|
1246
|
+
* hierarchy. Mesh, Camera, and Light instances are instantiated and must
|
|
1247
|
+
* be marked. Non-scenegraph resources (like Materials, Geometries, and
|
|
1248
|
+
* Textures) can be reused directly and are not marked here.
|
|
1249
|
+
*
|
|
1250
|
+
* Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
|
|
1251
|
+
*
|
|
1252
|
+
* @private
|
|
1253
|
+
* @param {Object} cache
|
|
1254
|
+
* @param {Object3D} index
|
|
1255
|
+
*/
|
|
1256
|
+
_addNodeRef(e, t) {
|
|
1257
|
+
t !== void 0 && (e.refs[t] === void 0 && (e.refs[t] = e.uses[t] = 0), e.refs[t]++);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Returns a reference to a shared resource, cloning it if necessary.
|
|
1261
|
+
*
|
|
1262
|
+
* @private
|
|
1263
|
+
* @param {Object} cache
|
|
1264
|
+
* @param {number} index
|
|
1265
|
+
* @param {Object} object
|
|
1266
|
+
* @return {Object}
|
|
1267
|
+
*/
|
|
1268
|
+
_getNodeRef(e, t, r) {
|
|
1269
|
+
if (e.refs[t] <= 1) return r;
|
|
1270
|
+
const n = r.clone(), s = (i, a) => {
|
|
1271
|
+
const o = this.associations.get(i);
|
|
1272
|
+
o != null && this.associations.set(a, o);
|
|
1273
|
+
for (const [c, u] of i.children.entries())
|
|
1274
|
+
s(u, a.children[c]);
|
|
1275
|
+
};
|
|
1276
|
+
return s(r, n), n.name += "_instance_" + e.uses[t]++, n;
|
|
1277
|
+
}
|
|
1278
|
+
_invokeOne(e) {
|
|
1279
|
+
const t = Object.values(this.plugins);
|
|
1280
|
+
t.push(this);
|
|
1281
|
+
for (let r = 0; r < t.length; r++) {
|
|
1282
|
+
const n = e(t[r]);
|
|
1283
|
+
if (n) return n;
|
|
1284
|
+
}
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
_invokeAll(e) {
|
|
1288
|
+
const t = Object.values(this.plugins);
|
|
1289
|
+
t.unshift(this);
|
|
1290
|
+
const r = [];
|
|
1291
|
+
for (let n = 0; n < t.length; n++) {
|
|
1292
|
+
const s = e(t[n]);
|
|
1293
|
+
s && r.push(s);
|
|
1294
|
+
}
|
|
1295
|
+
return r;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Requests the specified dependency asynchronously, with caching.
|
|
1299
|
+
*
|
|
1300
|
+
* @private
|
|
1301
|
+
* @param {string} type
|
|
1302
|
+
* @param {number} index
|
|
1303
|
+
* @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
|
|
1304
|
+
*/
|
|
1305
|
+
getDependency(e, t) {
|
|
1306
|
+
const r = e + ":" + t;
|
|
1307
|
+
let n = this.cache.get(r);
|
|
1308
|
+
if (!n) {
|
|
1309
|
+
switch (e) {
|
|
1310
|
+
case "scene":
|
|
1311
|
+
n = this.loadScene(t);
|
|
1312
|
+
break;
|
|
1313
|
+
case "node":
|
|
1314
|
+
n = this._invokeOne(function(s) {
|
|
1315
|
+
return s.loadNode && s.loadNode(t);
|
|
1316
|
+
});
|
|
1317
|
+
break;
|
|
1318
|
+
case "mesh":
|
|
1319
|
+
n = this._invokeOne(function(s) {
|
|
1320
|
+
return s.loadMesh && s.loadMesh(t);
|
|
1321
|
+
});
|
|
1322
|
+
break;
|
|
1323
|
+
case "accessor":
|
|
1324
|
+
n = this.loadAccessor(t);
|
|
1325
|
+
break;
|
|
1326
|
+
case "bufferView":
|
|
1327
|
+
n = this._invokeOne(function(s) {
|
|
1328
|
+
return s.loadBufferView && s.loadBufferView(t);
|
|
1329
|
+
});
|
|
1330
|
+
break;
|
|
1331
|
+
case "buffer":
|
|
1332
|
+
n = this.loadBuffer(t);
|
|
1333
|
+
break;
|
|
1334
|
+
case "material":
|
|
1335
|
+
n = this._invokeOne(function(s) {
|
|
1336
|
+
return s.loadMaterial && s.loadMaterial(t);
|
|
1337
|
+
});
|
|
1338
|
+
break;
|
|
1339
|
+
case "texture":
|
|
1340
|
+
n = this._invokeOne(function(s) {
|
|
1341
|
+
return s.loadTexture && s.loadTexture(t);
|
|
1342
|
+
});
|
|
1343
|
+
break;
|
|
1344
|
+
case "skin":
|
|
1345
|
+
n = this.loadSkin(t);
|
|
1346
|
+
break;
|
|
1347
|
+
case "animation":
|
|
1348
|
+
n = this._invokeOne(function(s) {
|
|
1349
|
+
return s.loadAnimation && s.loadAnimation(t);
|
|
1350
|
+
});
|
|
1351
|
+
break;
|
|
1352
|
+
case "camera":
|
|
1353
|
+
n = this.loadCamera(t);
|
|
1354
|
+
break;
|
|
1355
|
+
default:
|
|
1356
|
+
if (n = this._invokeOne(function(s) {
|
|
1357
|
+
return s != this && s.getDependency && s.getDependency(e, t);
|
|
1358
|
+
}), !n)
|
|
1359
|
+
throw new Error("Unknown type: " + e);
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
this.cache.add(r, n);
|
|
1363
|
+
}
|
|
1364
|
+
return n;
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Requests all dependencies of the specified type asynchronously, with caching.
|
|
1368
|
+
*
|
|
1369
|
+
* @private
|
|
1370
|
+
* @param {string} type
|
|
1371
|
+
* @return {Promise<Array<Object>>}
|
|
1372
|
+
*/
|
|
1373
|
+
getDependencies(e) {
|
|
1374
|
+
let t = this.cache.get(e);
|
|
1375
|
+
if (!t) {
|
|
1376
|
+
const r = this, n = this.json[e + (e === "mesh" ? "es" : "s")] || [];
|
|
1377
|
+
t = Promise.all(n.map(function(s, i) {
|
|
1378
|
+
return r.getDependency(e, i);
|
|
1379
|
+
})), this.cache.add(e, t);
|
|
1380
|
+
}
|
|
1381
|
+
return t;
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1385
|
+
*
|
|
1386
|
+
* @private
|
|
1387
|
+
* @param {number} bufferIndex
|
|
1388
|
+
* @return {Promise<ArrayBuffer>}
|
|
1389
|
+
*/
|
|
1390
|
+
loadBuffer(e) {
|
|
1391
|
+
const t = this.json.buffers[e], r = this.fileLoader;
|
|
1392
|
+
if (t.type && t.type !== "arraybuffer")
|
|
1393
|
+
throw new Error("THREE.GLTFLoader: " + t.type + " buffer type is not supported.");
|
|
1394
|
+
if (t.uri === void 0 && e === 0)
|
|
1395
|
+
return Promise.resolve(this.extensions[R.KHR_BINARY_GLTF].body);
|
|
1396
|
+
const n = this.options;
|
|
1397
|
+
return new Promise(function(s, i) {
|
|
1398
|
+
r.load(oe.resolveURL(t.uri, n.path), s, void 0, function() {
|
|
1399
|
+
i(new Error('THREE.GLTFLoader: Failed to load buffer "' + t.uri + '".'));
|
|
1400
|
+
});
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1405
|
+
*
|
|
1406
|
+
* @private
|
|
1407
|
+
* @param {number} bufferViewIndex
|
|
1408
|
+
* @return {Promise<ArrayBuffer>}
|
|
1409
|
+
*/
|
|
1410
|
+
loadBufferView(e) {
|
|
1411
|
+
const t = this.json.bufferViews[e];
|
|
1412
|
+
return this.getDependency("buffer", t.buffer).then(function(r) {
|
|
1413
|
+
const n = t.byteLength || 0, s = t.byteOffset || 0;
|
|
1414
|
+
return r.slice(s, s + n);
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
|
|
1419
|
+
*
|
|
1420
|
+
* @private
|
|
1421
|
+
* @param {number} accessorIndex
|
|
1422
|
+
* @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
|
|
1423
|
+
*/
|
|
1424
|
+
loadAccessor(e) {
|
|
1425
|
+
const t = this, r = this.json, n = this.json.accessors[e];
|
|
1426
|
+
if (n.bufferView === void 0 && n.sparse === void 0) {
|
|
1427
|
+
const i = ge[n.type], a = $[n.componentType], o = n.normalized === !0, c = new a(n.count * i);
|
|
1428
|
+
return Promise.resolve(new ie(c, i, o));
|
|
1429
|
+
}
|
|
1430
|
+
const s = [];
|
|
1431
|
+
return n.bufferView !== void 0 ? s.push(this.getDependency("bufferView", n.bufferView)) : s.push(null), n.sparse !== void 0 && (s.push(this.getDependency("bufferView", n.sparse.indices.bufferView)), s.push(this.getDependency("bufferView", n.sparse.values.bufferView))), Promise.all(s).then(function(i) {
|
|
1432
|
+
const a = i[0], o = ge[n.type], c = $[n.componentType], u = c.BYTES_PER_ELEMENT, l = u * o, d = n.byteOffset || 0, f = n.bufferView !== void 0 ? r.bufferViews[n.bufferView].byteStride : void 0, p = n.normalized === !0;
|
|
1433
|
+
let T, m;
|
|
1434
|
+
if (f && f !== l) {
|
|
1435
|
+
const g = Math.floor(d / f), b = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + g + ":" + n.count;
|
|
1436
|
+
let S = t.cache.get(b);
|
|
1437
|
+
S || (T = new c(a, g * f, n.count * f / u), S = new Tt(T, f / u), t.cache.add(b, S)), m = new xt(S, o, d % f / u, p);
|
|
1438
|
+
} else
|
|
1439
|
+
a === null ? T = new c(n.count * o) : T = new c(a, d, n.count * o), m = new ie(T, o, p);
|
|
1440
|
+
if (n.sparse !== void 0) {
|
|
1441
|
+
const g = ge.SCALAR, b = $[n.sparse.indices.componentType], S = n.sparse.indices.byteOffset || 0, y = n.sparse.values.byteOffset || 0, I = new b(i[1], S, n.sparse.count * g), P = new c(i[2], y, n.sparse.count * o);
|
|
1442
|
+
a !== null && (m = new ie(m.array.slice(), m.itemSize, m.normalized)), m.normalized = !1;
|
|
1443
|
+
for (let C = 0, B = I.length; C < B; C++) {
|
|
1444
|
+
const k = I[C];
|
|
1445
|
+
if (m.setX(k, P[C * o]), o >= 2 && m.setY(k, P[C * o + 1]), o >= 3 && m.setZ(k, P[C * o + 2]), o >= 4 && m.setW(k, P[C * o + 3]), o >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
|
|
1446
|
+
}
|
|
1447
|
+
m.normalized = p;
|
|
1448
|
+
}
|
|
1449
|
+
return m;
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
|
|
1454
|
+
*
|
|
1455
|
+
* @private
|
|
1456
|
+
* @param {number} textureIndex
|
|
1457
|
+
* @return {Promise<THREE.Texture|null>}
|
|
1458
|
+
*/
|
|
1459
|
+
loadTexture(e) {
|
|
1460
|
+
const t = this.json, r = this.options, s = t.textures[e].source, i = t.images[s];
|
|
1461
|
+
let a = this.textureLoader;
|
|
1462
|
+
if (i.uri) {
|
|
1463
|
+
const o = r.manager.getHandler(i.uri);
|
|
1464
|
+
o !== null && (a = o);
|
|
1465
|
+
}
|
|
1466
|
+
return this.loadTextureImage(e, s, a);
|
|
1467
|
+
}
|
|
1468
|
+
loadTextureImage(e, t, r) {
|
|
1469
|
+
const n = this, s = this.json, i = s.textures[e], a = s.images[t], o = (a.uri || a.bufferView) + ":" + i.sampler;
|
|
1470
|
+
if (this.textureCache[o])
|
|
1471
|
+
return this.textureCache[o];
|
|
1472
|
+
const c = this.loadImageSource(t, r).then(function(u) {
|
|
1473
|
+
u.flipY = !1, u.name = i.name || a.name || "", u.name === "" && typeof a.uri == "string" && a.uri.startsWith("data:image/") === !1 && (u.name = a.uri);
|
|
1474
|
+
const d = (s.samplers || {})[i.sampler] || {};
|
|
1475
|
+
return u.magFilter = ve[d.magFilter] || be, u.minFilter = ve[d.minFilter] || Je, u.wrapS = He[d.wrapS] || Ae, u.wrapT = He[d.wrapT] || Ae, u.generateMipmaps = !u.isCompressedTexture && u.minFilter !== Qe && u.minFilter !== be, n.associations.set(u, { textures: e }), u;
|
|
1476
|
+
}).catch(function() {
|
|
1477
|
+
return null;
|
|
1478
|
+
});
|
|
1479
|
+
return this.textureCache[o] = c, c;
|
|
1480
|
+
}
|
|
1481
|
+
loadImageSource(e, t) {
|
|
1482
|
+
const r = this, n = this.json, s = this.options;
|
|
1483
|
+
if (this.sourceCache[e] !== void 0)
|
|
1484
|
+
return this.sourceCache[e].then((l) => l.clone());
|
|
1485
|
+
const i = n.images[e], a = self.URL || self.webkitURL;
|
|
1486
|
+
let o = i.uri || "", c = !1;
|
|
1487
|
+
if (i.bufferView !== void 0)
|
|
1488
|
+
o = r.getDependency("bufferView", i.bufferView).then(function(l) {
|
|
1489
|
+
c = !0;
|
|
1490
|
+
const d = new Blob([l], { type: i.mimeType });
|
|
1491
|
+
return o = a.createObjectURL(d), o;
|
|
1492
|
+
});
|
|
1493
|
+
else if (i.uri === void 0)
|
|
1494
|
+
throw new Error("THREE.GLTFLoader: Image " + e + " is missing URI and bufferView");
|
|
1495
|
+
const u = Promise.resolve(o).then(function(l) {
|
|
1496
|
+
return new Promise(function(d, f) {
|
|
1497
|
+
let p = d;
|
|
1498
|
+
t.isImageBitmapLoader === !0 && (p = function(T) {
|
|
1499
|
+
const m = new Ce(T);
|
|
1500
|
+
m.needsUpdate = !0, d(m);
|
|
1501
|
+
}), t.load(oe.resolveURL(l, s.path), p, void 0, f);
|
|
1502
|
+
});
|
|
1503
|
+
}).then(function(l) {
|
|
1504
|
+
return c === !0 && a.revokeObjectURL(o), U(l, i), l.userData.mimeType = i.mimeType || Fn(i.uri), l;
|
|
1505
|
+
}).catch(function(l) {
|
|
1506
|
+
throw console.error("THREE.GLTFLoader: Couldn't load texture", o), l;
|
|
1507
|
+
});
|
|
1508
|
+
return this.sourceCache[e] = u, u;
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Asynchronously assigns a texture to the given material parameters.
|
|
1512
|
+
*
|
|
1513
|
+
* @private
|
|
1514
|
+
* @param {Object} materialParams
|
|
1515
|
+
* @param {string} mapName
|
|
1516
|
+
* @param {Object} mapDef
|
|
1517
|
+
* @param {string} [colorSpace]
|
|
1518
|
+
* @return {Promise<Texture>}
|
|
1519
|
+
*/
|
|
1520
|
+
assignTexture(e, t, r, n) {
|
|
1521
|
+
const s = this;
|
|
1522
|
+
return this.getDependency("texture", r.index).then(function(i) {
|
|
1523
|
+
if (!i) return null;
|
|
1524
|
+
if (r.texCoord !== void 0 && r.texCoord > 0 && (i = i.clone(), i.channel = r.texCoord), s.extensions[R.KHR_TEXTURE_TRANSFORM]) {
|
|
1525
|
+
const a = r.extensions !== void 0 ? r.extensions[R.KHR_TEXTURE_TRANSFORM] : void 0;
|
|
1526
|
+
if (a) {
|
|
1527
|
+
const o = s.associations.get(i);
|
|
1528
|
+
i = s.extensions[R.KHR_TEXTURE_TRANSFORM].extendTexture(i, a), s.associations.set(i, o);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return n !== void 0 && (i.colorSpace = n), e[t] = i, i;
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Assigns final material to a Mesh, Line, or Points instance. The instance
|
|
1536
|
+
* already has a material (generated from the glTF material options alone)
|
|
1537
|
+
* but reuse of the same glTF material may require multiple threejs materials
|
|
1538
|
+
* to accommodate different primitive types, defines, etc. New materials will
|
|
1539
|
+
* be created if necessary, and reused from a cache.
|
|
1540
|
+
*
|
|
1541
|
+
* @private
|
|
1542
|
+
* @param {Object3D} mesh Mesh, Line, or Points instance.
|
|
1543
|
+
*/
|
|
1544
|
+
assignFinalMaterial(e) {
|
|
1545
|
+
const t = e.geometry;
|
|
1546
|
+
let r = e.material;
|
|
1547
|
+
const n = t.attributes.tangent === void 0, s = t.attributes.color !== void 0, i = t.attributes.normal === void 0;
|
|
1548
|
+
if (e.isPoints) {
|
|
1549
|
+
const a = "PointsMaterial:" + r.uuid;
|
|
1550
|
+
let o = this.cache.get(a);
|
|
1551
|
+
o || (o = new _t(), he.prototype.copy.call(o, r), o.color.copy(r.color), o.map = r.map, o.sizeAttenuation = !1, this.cache.add(a, o)), r = o;
|
|
1552
|
+
} else if (e.isLine) {
|
|
1553
|
+
const a = "LineBasicMaterial:" + r.uuid;
|
|
1554
|
+
let o = this.cache.get(a);
|
|
1555
|
+
o || (o = new Et(), he.prototype.copy.call(o, r), o.color.copy(r.color), o.map = r.map, this.cache.add(a, o)), r = o;
|
|
1556
|
+
}
|
|
1557
|
+
if (n || s || i) {
|
|
1558
|
+
let a = "ClonedMaterial:" + r.uuid + ":";
|
|
1559
|
+
n && (a += "derivative-tangents:"), s && (a += "vertex-colors:"), i && (a += "flat-shading:");
|
|
1560
|
+
let o = this.cache.get(a);
|
|
1561
|
+
o || (o = r.clone(), s && (o.vertexColors = !0), i && (o.flatShading = !0), n && (o.normalScale && (o.normalScale.y *= -1), o.clearcoatNormalScale && (o.clearcoatNormalScale.y *= -1)), this.cache.add(a, o), this.associations.set(o, this.associations.get(r))), r = o;
|
|
1562
|
+
}
|
|
1563
|
+
e.material = r;
|
|
1564
|
+
}
|
|
1565
|
+
getMaterialType() {
|
|
1566
|
+
return Ze;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
|
|
1570
|
+
*
|
|
1571
|
+
* @private
|
|
1572
|
+
* @param {number} materialIndex
|
|
1573
|
+
* @return {Promise<Material>}
|
|
1574
|
+
*/
|
|
1575
|
+
loadMaterial(e) {
|
|
1576
|
+
const t = this, r = this.json, n = this.extensions, s = r.materials[e];
|
|
1577
|
+
let i;
|
|
1578
|
+
const a = {}, o = s.extensions || {}, c = [];
|
|
1579
|
+
if (o[R.KHR_MATERIALS_UNLIT]) {
|
|
1580
|
+
const l = n[R.KHR_MATERIALS_UNLIT];
|
|
1581
|
+
i = l.getMaterialType(), c.push(l.extendParams(a, s, t));
|
|
1582
|
+
} else {
|
|
1583
|
+
const l = s.pbrMetallicRoughness || {};
|
|
1584
|
+
if (a.color = new G(1, 1, 1), a.opacity = 1, Array.isArray(l.baseColorFactor)) {
|
|
1585
|
+
const d = l.baseColorFactor;
|
|
1586
|
+
a.color.setRGB(d[0], d[1], d[2], F), a.opacity = d[3];
|
|
1587
|
+
}
|
|
1588
|
+
l.baseColorTexture !== void 0 && c.push(t.assignTexture(a, "map", l.baseColorTexture, V)), a.metalness = l.metallicFactor !== void 0 ? l.metallicFactor : 1, a.roughness = l.roughnessFactor !== void 0 ? l.roughnessFactor : 1, l.metallicRoughnessTexture !== void 0 && (c.push(t.assignTexture(a, "metalnessMap", l.metallicRoughnessTexture)), c.push(t.assignTexture(a, "roughnessMap", l.metallicRoughnessTexture))), i = this._invokeOne(function(d) {
|
|
1589
|
+
return d.getMaterialType && d.getMaterialType(e);
|
|
1590
|
+
}), c.push(Promise.all(this._invokeAll(function(d) {
|
|
1591
|
+
return d.extendMaterialParams && d.extendMaterialParams(e, a);
|
|
1592
|
+
})));
|
|
1593
|
+
}
|
|
1594
|
+
s.doubleSided === !0 && (a.side = St);
|
|
1595
|
+
const u = s.alphaMode || Te.OPAQUE;
|
|
1596
|
+
if (u === Te.BLEND ? (a.transparent = !0, a.depthWrite = !1) : (a.transparent = !1, u === Te.MASK && (a.alphaTest = s.alphaCutoff !== void 0 ? s.alphaCutoff : 0.5)), s.normalTexture !== void 0 && i !== re && (c.push(t.assignTexture(a, "normalMap", s.normalTexture)), a.normalScale = new Se(1, 1), s.normalTexture.scale !== void 0)) {
|
|
1597
|
+
const l = s.normalTexture.scale;
|
|
1598
|
+
a.normalScale.set(l, l);
|
|
1599
|
+
}
|
|
1600
|
+
if (s.occlusionTexture !== void 0 && i !== re && (c.push(t.assignTexture(a, "aoMap", s.occlusionTexture)), s.occlusionTexture.strength !== void 0 && (a.aoMapIntensity = s.occlusionTexture.strength)), s.emissiveFactor !== void 0 && i !== re) {
|
|
1601
|
+
const l = s.emissiveFactor;
|
|
1602
|
+
a.emissive = new G().setRGB(l[0], l[1], l[2], F);
|
|
1603
|
+
}
|
|
1604
|
+
return s.emissiveTexture !== void 0 && i !== re && c.push(t.assignTexture(a, "emissiveMap", s.emissiveTexture, V)), Promise.all(c).then(function() {
|
|
1605
|
+
const l = new i(a);
|
|
1606
|
+
return s.name && (l.name = s.name), U(l, s), t.associations.set(l, { materials: e }), s.extensions && q(n, l, s), l;
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* When Object3D instances are targeted by animation, they need unique names.
|
|
1611
|
+
*
|
|
1612
|
+
* @private
|
|
1613
|
+
* @param {string} originalName
|
|
1614
|
+
* @return {string}
|
|
1615
|
+
*/
|
|
1616
|
+
createUniqueName(e) {
|
|
1617
|
+
const t = Lt.sanitizeNodeName(e || "");
|
|
1618
|
+
return t in this.nodeNamesUsed ? t + "_" + ++this.nodeNamesUsed[t] : (this.nodeNamesUsed[t] = 0, t);
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
|
1622
|
+
*
|
|
1623
|
+
* Creates BufferGeometries from primitives.
|
|
1624
|
+
*
|
|
1625
|
+
* @private
|
|
1626
|
+
* @param {Array<GLTF.Primitive>} primitives
|
|
1627
|
+
* @return {Promise<Array<BufferGeometry>>}
|
|
1628
|
+
*/
|
|
1629
|
+
loadGeometries(e) {
|
|
1630
|
+
const t = this, r = this.extensions, n = this.primitiveCache;
|
|
1631
|
+
function s(a) {
|
|
1632
|
+
return r[R.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a, t).then(function(o) {
|
|
1633
|
+
return Ue(o, a, t);
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
const i = [];
|
|
1637
|
+
for (let a = 0, o = e.length; a < o; a++) {
|
|
1638
|
+
const c = e[a], u = kn(c), l = n[u];
|
|
1639
|
+
if (l)
|
|
1640
|
+
i.push(l.promise);
|
|
1641
|
+
else {
|
|
1642
|
+
let d;
|
|
1643
|
+
c.extensions && c.extensions[R.KHR_DRACO_MESH_COMPRESSION] ? d = s(c) : d = Ue(new qe(), c, t), n[u] = { primitive: c, promise: d }, i.push(d);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
return Promise.all(i);
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
|
|
1650
|
+
*
|
|
1651
|
+
* @private
|
|
1652
|
+
* @param {number} meshIndex
|
|
1653
|
+
* @return {Promise<Group|Mesh|SkinnedMesh|Line|Points>}
|
|
1654
|
+
*/
|
|
1655
|
+
loadMesh(e) {
|
|
1656
|
+
const t = this, r = this.json, n = this.extensions, s = r.meshes[e], i = s.primitives, a = [];
|
|
1657
|
+
for (let o = 0, c = i.length; o < c; o++) {
|
|
1658
|
+
const u = i[o].material === void 0 ? On(this.cache) : this.getDependency("material", i[o].material);
|
|
1659
|
+
a.push(u);
|
|
1660
|
+
}
|
|
1661
|
+
return a.push(t.loadGeometries(i)), Promise.all(a).then(function(o) {
|
|
1662
|
+
const c = o.slice(0, o.length - 1), u = o[o.length - 1], l = [];
|
|
1663
|
+
for (let f = 0, p = u.length; f < p; f++) {
|
|
1664
|
+
const T = u[f], m = i[f];
|
|
1665
|
+
let g;
|
|
1666
|
+
const b = c[f];
|
|
1667
|
+
if (m.mode === O.TRIANGLES || m.mode === O.TRIANGLE_STRIP || m.mode === O.TRIANGLE_FAN || m.mode === void 0)
|
|
1668
|
+
g = s.isSkinnedMesh === !0 ? new Mt(T, b) : new It(T, b), g.isSkinnedMesh === !0 && g.normalizeSkinWeights(), m.mode === O.TRIANGLE_STRIP ? g.geometry = ke(g.geometry, Ve) : m.mode === O.TRIANGLE_FAN && (g.geometry = ke(g.geometry, ye));
|
|
1669
|
+
else if (m.mode === O.LINES)
|
|
1670
|
+
g = new Ct(T, b);
|
|
1671
|
+
else if (m.mode === O.LINE_STRIP)
|
|
1672
|
+
g = new Nt(T, b);
|
|
1673
|
+
else if (m.mode === O.LINE_LOOP)
|
|
1674
|
+
g = new Ot(T, b);
|
|
1675
|
+
else if (m.mode === O.POINTS)
|
|
1676
|
+
g = new Dt(T, b);
|
|
1677
|
+
else
|
|
1678
|
+
throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + m.mode);
|
|
1679
|
+
Object.keys(g.geometry.morphAttributes).length > 0 && Pn(g, s), g.name = t.createUniqueName(s.name || "mesh_" + e), U(g, s), m.extensions && q(n, g, m), t.assignFinalMaterial(g), l.push(g);
|
|
1680
|
+
}
|
|
1681
|
+
for (let f = 0, p = l.length; f < p; f++)
|
|
1682
|
+
t.associations.set(l[f], {
|
|
1683
|
+
meshes: e,
|
|
1684
|
+
primitives: f
|
|
1685
|
+
});
|
|
1686
|
+
if (l.length === 1)
|
|
1687
|
+
return s.extensions && q(n, l[0], s), l[0];
|
|
1688
|
+
const d = new fe();
|
|
1689
|
+
s.extensions && q(n, d, s), t.associations.set(d, { meshes: e });
|
|
1690
|
+
for (let f = 0, p = l.length; f < p; f++)
|
|
1691
|
+
d.add(l[f]);
|
|
1692
|
+
return d;
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
|
|
1697
|
+
*
|
|
1698
|
+
* @private
|
|
1699
|
+
* @param {number} cameraIndex
|
|
1700
|
+
* @return {Promise<THREE.Camera>}
|
|
1701
|
+
*/
|
|
1702
|
+
loadCamera(e) {
|
|
1703
|
+
let t;
|
|
1704
|
+
const r = this.json.cameras[e], n = r[r.type];
|
|
1705
|
+
if (!n) {
|
|
1706
|
+
console.warn("THREE.GLTFLoader: Missing camera parameters.");
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
return r.type === "perspective" ? t = new $e(Z.radToDeg(n.yfov), n.aspectRatio || 1, n.znear || 1, n.zfar || 2e6) : r.type === "orthographic" && (t = new Pt(-n.xmag, n.xmag, n.ymag, -n.ymag, n.znear, n.zfar)), r.name && (t.name = this.createUniqueName(r.name)), U(t, r), Promise.resolve(t);
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
|
|
1713
|
+
*
|
|
1714
|
+
* @private
|
|
1715
|
+
* @param {number} skinIndex
|
|
1716
|
+
* @return {Promise<Skeleton>}
|
|
1717
|
+
*/
|
|
1718
|
+
loadSkin(e) {
|
|
1719
|
+
const t = this.json.skins[e], r = [];
|
|
1720
|
+
for (let n = 0, s = t.joints.length; n < s; n++)
|
|
1721
|
+
r.push(this._loadNodeShallow(t.joints[n]));
|
|
1722
|
+
return t.inverseBindMatrices !== void 0 ? r.push(this.getDependency("accessor", t.inverseBindMatrices)) : r.push(null), Promise.all(r).then(function(n) {
|
|
1723
|
+
const s = n.pop(), i = n, a = [], o = [];
|
|
1724
|
+
for (let c = 0, u = i.length; c < u; c++) {
|
|
1725
|
+
const l = i[c];
|
|
1726
|
+
if (l) {
|
|
1727
|
+
a.push(l);
|
|
1728
|
+
const d = new ee();
|
|
1729
|
+
s !== null && d.fromArray(s.array, c * 16), o.push(d);
|
|
1730
|
+
} else
|
|
1731
|
+
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', t.joints[c]);
|
|
1732
|
+
}
|
|
1733
|
+
return new kt(a, o);
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
|
1738
|
+
*
|
|
1739
|
+
* @private
|
|
1740
|
+
* @param {number} animationIndex
|
|
1741
|
+
* @return {Promise<AnimationClip>}
|
|
1742
|
+
*/
|
|
1743
|
+
loadAnimation(e) {
|
|
1744
|
+
const t = this.json, r = this, n = t.animations[e], s = n.name ? n.name : "animation_" + e, i = [], a = [], o = [], c = [], u = [];
|
|
1745
|
+
for (let l = 0, d = n.channels.length; l < d; l++) {
|
|
1746
|
+
const f = n.channels[l], p = n.samplers[f.sampler], T = f.target, m = T.node, g = n.parameters !== void 0 ? n.parameters[p.input] : p.input, b = n.parameters !== void 0 ? n.parameters[p.output] : p.output;
|
|
1747
|
+
T.node !== void 0 && (i.push(this.getDependency("node", m)), a.push(this.getDependency("accessor", g)), o.push(this.getDependency("accessor", b)), c.push(p), u.push(T));
|
|
1748
|
+
}
|
|
1749
|
+
return Promise.all([
|
|
1750
|
+
Promise.all(i),
|
|
1751
|
+
Promise.all(a),
|
|
1752
|
+
Promise.all(o),
|
|
1753
|
+
Promise.all(c),
|
|
1754
|
+
Promise.all(u)
|
|
1755
|
+
]).then(function(l) {
|
|
1756
|
+
const d = l[0], f = l[1], p = l[2], T = l[3], m = l[4], g = [];
|
|
1757
|
+
for (let b = 0, S = d.length; b < S; b++) {
|
|
1758
|
+
const y = d[b], I = f[b], P = p[b], C = T[b], B = m[b];
|
|
1759
|
+
if (y === void 0) continue;
|
|
1760
|
+
y.updateMatrix && y.updateMatrix();
|
|
1761
|
+
const k = r._createAnimationTracks(y, I, P, C, B);
|
|
1762
|
+
if (k)
|
|
1763
|
+
for (let te = 0; te < k.length; te++)
|
|
1764
|
+
g.push(k[te]);
|
|
1765
|
+
}
|
|
1766
|
+
return new Ft(s, void 0, g);
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
createNodeMesh(e) {
|
|
1770
|
+
const t = this.json, r = this, n = t.nodes[e];
|
|
1771
|
+
return n.mesh === void 0 ? null : r.getDependency("mesh", n.mesh).then(function(s) {
|
|
1772
|
+
const i = r._getNodeRef(r.meshCache, n.mesh, s);
|
|
1773
|
+
return n.weights !== void 0 && i.traverse(function(a) {
|
|
1774
|
+
if (a.isMesh)
|
|
1775
|
+
for (let o = 0, c = n.weights.length; o < c; o++)
|
|
1776
|
+
a.morphTargetInfluences[o] = n.weights[o];
|
|
1777
|
+
}), i;
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
|
|
1782
|
+
*
|
|
1783
|
+
* @private
|
|
1784
|
+
* @param {number} nodeIndex
|
|
1785
|
+
* @return {Promise<Object3D>}
|
|
1786
|
+
*/
|
|
1787
|
+
loadNode(e) {
|
|
1788
|
+
const t = this.json, r = this, n = t.nodes[e], s = r._loadNodeShallow(e), i = [], a = n.children || [];
|
|
1789
|
+
for (let c = 0, u = a.length; c < u; c++)
|
|
1790
|
+
i.push(r.getDependency("node", a[c]));
|
|
1791
|
+
const o = n.skin === void 0 ? Promise.resolve(null) : r.getDependency("skin", n.skin);
|
|
1792
|
+
return Promise.all([
|
|
1793
|
+
s,
|
|
1794
|
+
Promise.all(i),
|
|
1795
|
+
o
|
|
1796
|
+
]).then(function(c) {
|
|
1797
|
+
const u = c[0], l = c[1], d = c[2];
|
|
1798
|
+
d !== null && u.traverse(function(f) {
|
|
1799
|
+
f.isSkinnedMesh && f.bind(d, vn);
|
|
1800
|
+
});
|
|
1801
|
+
for (let f = 0, p = l.length; f < p; f++)
|
|
1802
|
+
u.add(l[f]);
|
|
1803
|
+
return u;
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
// ._loadNodeShallow() parses a single node.
|
|
1807
|
+
// skin and child nodes are created and added in .loadNode() (no '_' prefix).
|
|
1808
|
+
_loadNodeShallow(e) {
|
|
1809
|
+
const t = this.json, r = this.extensions, n = this;
|
|
1810
|
+
if (this.nodeCache[e] !== void 0)
|
|
1811
|
+
return this.nodeCache[e];
|
|
1812
|
+
const s = t.nodes[e], i = s.name ? n.createUniqueName(s.name) : "", a = [], o = n._invokeOne(function(c) {
|
|
1813
|
+
return c.createNodeMesh && c.createNodeMesh(e);
|
|
1814
|
+
});
|
|
1815
|
+
return o && a.push(o), s.camera !== void 0 && a.push(n.getDependency("camera", s.camera).then(function(c) {
|
|
1816
|
+
return n._getNodeRef(n.cameraCache, s.camera, c);
|
|
1817
|
+
})), n._invokeAll(function(c) {
|
|
1818
|
+
return c.createNodeAttachment && c.createNodeAttachment(e);
|
|
1819
|
+
}).forEach(function(c) {
|
|
1820
|
+
a.push(c);
|
|
1821
|
+
}), this.nodeCache[e] = Promise.all(a).then(function(c) {
|
|
1822
|
+
let u;
|
|
1823
|
+
if (s.isBone === !0 ? u = new vt() : c.length > 1 ? u = new fe() : c.length === 1 ? u = c[0] : u = new Ye(), u !== c[0])
|
|
1824
|
+
for (let l = 0, d = c.length; l < d; l++)
|
|
1825
|
+
u.add(c[l]);
|
|
1826
|
+
if (s.name && (u.userData.name = s.name, u.name = i), U(u, s), s.extensions && q(r, u, s), s.matrix !== void 0) {
|
|
1827
|
+
const l = new ee();
|
|
1828
|
+
l.fromArray(s.matrix), u.applyMatrix4(l);
|
|
1829
|
+
} else
|
|
1830
|
+
s.translation !== void 0 && u.position.fromArray(s.translation), s.rotation !== void 0 && u.quaternion.fromArray(s.rotation), s.scale !== void 0 && u.scale.fromArray(s.scale);
|
|
1831
|
+
if (!n.associations.has(u))
|
|
1832
|
+
n.associations.set(u, {});
|
|
1833
|
+
else if (s.mesh !== void 0 && n.meshCache.refs[s.mesh] > 1) {
|
|
1834
|
+
const l = n.associations.get(u);
|
|
1835
|
+
n.associations.set(u, { ...l });
|
|
1836
|
+
}
|
|
1837
|
+
return n.associations.get(u).nodes = e, u;
|
|
1838
|
+
}), this.nodeCache[e];
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
|
1842
|
+
*
|
|
1843
|
+
* @private
|
|
1844
|
+
* @param {number} sceneIndex
|
|
1845
|
+
* @return {Promise<Group>}
|
|
1846
|
+
*/
|
|
1847
|
+
loadScene(e) {
|
|
1848
|
+
const t = this.extensions, r = this.json.scenes[e], n = this, s = new fe();
|
|
1849
|
+
r.name && (s.name = n.createUniqueName(r.name)), U(s, r), r.extensions && q(t, s, r);
|
|
1850
|
+
const i = r.nodes || [], a = [];
|
|
1851
|
+
for (let o = 0, c = i.length; o < c; o++)
|
|
1852
|
+
a.push(n.getDependency("node", i[o]));
|
|
1853
|
+
return Promise.all(a).then(function(o) {
|
|
1854
|
+
for (let u = 0, l = o.length; u < l; u++)
|
|
1855
|
+
s.add(o[u]);
|
|
1856
|
+
const c = (u) => {
|
|
1857
|
+
const l = /* @__PURE__ */ new Map();
|
|
1858
|
+
for (const [d, f] of n.associations)
|
|
1859
|
+
(d instanceof he || d instanceof Ce) && l.set(d, f);
|
|
1860
|
+
return u.traverse((d) => {
|
|
1861
|
+
const f = n.associations.get(d);
|
|
1862
|
+
f != null && l.set(d, f);
|
|
1863
|
+
}), l;
|
|
1864
|
+
};
|
|
1865
|
+
return n.associations = c(s), s;
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
_createAnimationTracks(e, t, r, n, s) {
|
|
1869
|
+
const i = [], a = e.name ? e.name : e.uuid, o = [];
|
|
1870
|
+
K[s.path] === K.weights ? e.traverse(function(d) {
|
|
1871
|
+
d.morphTargetInfluences && o.push(d.name ? d.name : d.uuid);
|
|
1872
|
+
}) : o.push(a);
|
|
1873
|
+
let c;
|
|
1874
|
+
switch (K[s.path]) {
|
|
1875
|
+
case K.weights:
|
|
1876
|
+
c = Oe;
|
|
1877
|
+
break;
|
|
1878
|
+
case K.rotation:
|
|
1879
|
+
c = De;
|
|
1880
|
+
break;
|
|
1881
|
+
case K.translation:
|
|
1882
|
+
case K.scale:
|
|
1883
|
+
c = Ne;
|
|
1884
|
+
break;
|
|
1885
|
+
default:
|
|
1886
|
+
switch (r.itemSize) {
|
|
1887
|
+
case 1:
|
|
1888
|
+
c = Oe;
|
|
1889
|
+
break;
|
|
1890
|
+
case 2:
|
|
1891
|
+
case 3:
|
|
1892
|
+
default:
|
|
1893
|
+
c = Ne;
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
break;
|
|
1897
|
+
}
|
|
1898
|
+
const u = n.interpolation !== void 0 ? Nn[n.interpolation] : et, l = this._getArrayFromAccessor(r);
|
|
1899
|
+
for (let d = 0, f = o.length; d < f; d++) {
|
|
1900
|
+
const p = new c(
|
|
1901
|
+
o[d] + "." + K[s.path],
|
|
1902
|
+
t.array,
|
|
1903
|
+
l,
|
|
1904
|
+
u
|
|
1905
|
+
);
|
|
1906
|
+
n.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(p), i.push(p);
|
|
1907
|
+
}
|
|
1908
|
+
return i;
|
|
1909
|
+
}
|
|
1910
|
+
_getArrayFromAccessor(e) {
|
|
1911
|
+
let t = e.array;
|
|
1912
|
+
if (e.normalized) {
|
|
1913
|
+
const r = _e(t.constructor), n = new Float32Array(t.length);
|
|
1914
|
+
for (let s = 0, i = t.length; s < i; s++)
|
|
1915
|
+
n[s] = t[s] * r;
|
|
1916
|
+
t = n;
|
|
1917
|
+
}
|
|
1918
|
+
return t;
|
|
1919
|
+
}
|
|
1920
|
+
_createCubicSplineTrackInterpolant(e) {
|
|
1921
|
+
e.createInterpolant = function(r) {
|
|
1922
|
+
const n = this instanceof De ? Cn : st;
|
|
1923
|
+
return new n(this.times, this.values, this.getValueSize() / 3, r);
|
|
1924
|
+
}, e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
function Un(h, e, t) {
|
|
1928
|
+
const r = e.attributes, n = new ue();
|
|
1929
|
+
if (r.POSITION !== void 0) {
|
|
1930
|
+
const a = t.json.accessors[r.POSITION], o = a.min, c = a.max;
|
|
1931
|
+
if (o !== void 0 && c !== void 0) {
|
|
1932
|
+
if (n.set(
|
|
1933
|
+
new _(o[0], o[1], o[2]),
|
|
1934
|
+
new _(c[0], c[1], c[2])
|
|
1935
|
+
), a.normalized) {
|
|
1936
|
+
const u = _e($[a.componentType]);
|
|
1937
|
+
n.min.multiplyScalar(u), n.max.multiplyScalar(u);
|
|
1938
|
+
}
|
|
1939
|
+
} else {
|
|
1940
|
+
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
} else
|
|
1944
|
+
return;
|
|
1945
|
+
const s = e.targets;
|
|
1946
|
+
if (s !== void 0) {
|
|
1947
|
+
const a = new _(), o = new _();
|
|
1948
|
+
for (let c = 0, u = s.length; c < u; c++) {
|
|
1949
|
+
const l = s[c];
|
|
1950
|
+
if (l.POSITION !== void 0) {
|
|
1951
|
+
const d = t.json.accessors[l.POSITION], f = d.min, p = d.max;
|
|
1952
|
+
if (f !== void 0 && p !== void 0) {
|
|
1953
|
+
if (o.setX(Math.max(Math.abs(f[0]), Math.abs(p[0]))), o.setY(Math.max(Math.abs(f[1]), Math.abs(p[1]))), o.setZ(Math.max(Math.abs(f[2]), Math.abs(p[2]))), d.normalized) {
|
|
1954
|
+
const T = _e($[d.componentType]);
|
|
1955
|
+
o.multiplyScalar(T);
|
|
1956
|
+
}
|
|
1957
|
+
a.max(o);
|
|
1958
|
+
} else
|
|
1959
|
+
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
n.expandByVector(a);
|
|
1963
|
+
}
|
|
1964
|
+
h.boundingBox = n;
|
|
1965
|
+
const i = new Bt();
|
|
1966
|
+
n.getCenter(i.center), i.radius = n.min.distanceTo(n.max) / 2, h.boundingSphere = i;
|
|
1967
|
+
}
|
|
1968
|
+
function Ue(h, e, t) {
|
|
1969
|
+
const r = e.attributes, n = [];
|
|
1970
|
+
function s(i, a) {
|
|
1971
|
+
return t.getDependency("accessor", i).then(function(o) {
|
|
1972
|
+
h.setAttribute(a, o);
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
for (const i in r) {
|
|
1976
|
+
const a = we[i] || i.toLowerCase();
|
|
1977
|
+
a in h.attributes || n.push(s(r[i], a));
|
|
1978
|
+
}
|
|
1979
|
+
if (e.indices !== void 0 && !h.index) {
|
|
1980
|
+
const i = t.getDependency("accessor", e.indices).then(function(a) {
|
|
1981
|
+
h.setIndex(a);
|
|
1982
|
+
});
|
|
1983
|
+
n.push(i);
|
|
1984
|
+
}
|
|
1985
|
+
return Re.workingColorSpace !== F && "COLOR_0" in r && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Re.workingColorSpace}" not supported.`), U(h, e), Un(h, e, t), Promise.all(n).then(function() {
|
|
1986
|
+
return e.targets !== void 0 ? Dn(h, e.targets, t) : h;
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
const A = {
|
|
1990
|
+
c: null,
|
|
1991
|
+
// center
|
|
1992
|
+
u: [new _(), new _(), new _()],
|
|
1993
|
+
// basis vectors
|
|
1994
|
+
e: []
|
|
1995
|
+
// half width
|
|
1996
|
+
}, w = {
|
|
1997
|
+
c: null,
|
|
1998
|
+
// center
|
|
1999
|
+
u: [new _(), new _(), new _()],
|
|
2000
|
+
// basis vectors
|
|
2001
|
+
e: []
|
|
2002
|
+
// half width
|
|
2003
|
+
}, L = [[], [], []], x = [[], [], []], E = [], W = new _(), Y = new _(), J = new _(), M = new _(), Ge = new _(), Be = new _(), D = new tt(), je = new ue(), ae = new ee(), ze = new ee(), Ke = new jt();
|
|
2004
|
+
class Ee {
|
|
2005
|
+
/**
|
|
2006
|
+
* Constructs a new OBB.
|
|
2007
|
+
*
|
|
2008
|
+
* @param {Vector3} [center] - The center of the OBB.
|
|
2009
|
+
* @param {Vector3} [halfSize] - Positive halfwidth extents of the OBB along each axis.
|
|
2010
|
+
* @param {Matrix3} [rotation] - The rotation of the OBB.
|
|
2011
|
+
*/
|
|
2012
|
+
constructor(e = new _(), t = new _(), r = new tt()) {
|
|
2013
|
+
this.center = e, this.halfSize = t, this.rotation = r;
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* Sets the OBBs components to the given values.
|
|
2017
|
+
*
|
|
2018
|
+
* @param {Vector3} [center] - The center of the OBB.
|
|
2019
|
+
* @param {Vector3} [halfSize] - Positive halfwidth extents of the OBB along each axis.
|
|
2020
|
+
* @param {Matrix3} [rotation] - The rotation of the OBB.
|
|
2021
|
+
* @return {OBB} A reference to this OBB.
|
|
2022
|
+
*/
|
|
2023
|
+
set(e, t, r) {
|
|
2024
|
+
return this.center = e, this.halfSize = t, this.rotation = r, this;
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Copies the values of the given OBB to this instance.
|
|
2028
|
+
*
|
|
2029
|
+
* @param {OBB} obb - The OBB to copy.
|
|
2030
|
+
* @return {OBB} A reference to this OBB.
|
|
2031
|
+
*/
|
|
2032
|
+
copy(e) {
|
|
2033
|
+
return this.center.copy(e.center), this.halfSize.copy(e.halfSize), this.rotation.copy(e.rotation), this;
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Returns a new OBB with copied values from this instance.
|
|
2037
|
+
*
|
|
2038
|
+
* @return {OBB} A clone of this instance.
|
|
2039
|
+
*/
|
|
2040
|
+
clone() {
|
|
2041
|
+
return new this.constructor().copy(this);
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Returns the size of this OBB.
|
|
2045
|
+
*
|
|
2046
|
+
* @param {Vector3} target - The target vector that is used to store the method's result.
|
|
2047
|
+
* @return {Vector3} The size.
|
|
2048
|
+
*/
|
|
2049
|
+
getSize(e) {
|
|
2050
|
+
return e.copy(this.halfSize).multiplyScalar(2);
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Clamps the given point within the bounds of this OBB.
|
|
2054
|
+
*
|
|
2055
|
+
* @param {Vector3} point - The point that should be clamped within the bounds of this OBB.
|
|
2056
|
+
* @param {Vector3} target - The target vector that is used to store the method's result.
|
|
2057
|
+
* @returns {Vector3} - The clamped point.
|
|
2058
|
+
*/
|
|
2059
|
+
clampPoint(e, t) {
|
|
2060
|
+
const r = this.halfSize;
|
|
2061
|
+
M.subVectors(e, this.center), this.rotation.extractBasis(W, Y, J), t.copy(this.center);
|
|
2062
|
+
const n = Z.clamp(M.dot(W), -r.x, r.x);
|
|
2063
|
+
t.add(W.multiplyScalar(n));
|
|
2064
|
+
const s = Z.clamp(M.dot(Y), -r.y, r.y);
|
|
2065
|
+
t.add(Y.multiplyScalar(s));
|
|
2066
|
+
const i = Z.clamp(M.dot(J), -r.z, r.z);
|
|
2067
|
+
return t.add(J.multiplyScalar(i)), t;
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* Returns `true` if the given point lies within this OBB.
|
|
2071
|
+
*
|
|
2072
|
+
* @param {Vector3} point - The point to test.
|
|
2073
|
+
* @returns {boolean} - Whether the given point lies within this OBB or not.
|
|
2074
|
+
*/
|
|
2075
|
+
containsPoint(e) {
|
|
2076
|
+
return M.subVectors(e, this.center), this.rotation.extractBasis(W, Y, J), Math.abs(M.dot(W)) <= this.halfSize.x && Math.abs(M.dot(Y)) <= this.halfSize.y && Math.abs(M.dot(J)) <= this.halfSize.z;
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* Returns `true` if the given AABB intersects this OBB.
|
|
2080
|
+
*
|
|
2081
|
+
* @param {Box3} box3 - The AABB to test.
|
|
2082
|
+
* @returns {boolean} - Whether the given AABB intersects this OBB or not.
|
|
2083
|
+
*/
|
|
2084
|
+
intersectsBox3(e) {
|
|
2085
|
+
return this.intersectsOBB(Gn.fromBox3(e));
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* Returns `true` if the given bounding sphere intersects this OBB.
|
|
2089
|
+
*
|
|
2090
|
+
* @param {Sphere} sphere - The bounding sphere to test.
|
|
2091
|
+
* @returns {boolean} - Whether the given bounding sphere intersects this OBB or not.
|
|
2092
|
+
*/
|
|
2093
|
+
intersectsSphere(e) {
|
|
2094
|
+
return this.clampPoint(e.center, Be), Be.distanceToSquared(e.center) <= e.radius * e.radius;
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Returns `true` if the given OBB intersects this OBB.
|
|
2098
|
+
*
|
|
2099
|
+
* @param {OBB} obb - The OBB to test.
|
|
2100
|
+
* @param {number} [epsilon=Number.EPSILON] - A small value to prevent arithmetic errors.
|
|
2101
|
+
* @returns {boolean} - Whether the given OBB intersects this OBB or not.
|
|
2102
|
+
*/
|
|
2103
|
+
intersectsOBB(e, t = Number.EPSILON) {
|
|
2104
|
+
A.c = this.center, A.e[0] = this.halfSize.x, A.e[1] = this.halfSize.y, A.e[2] = this.halfSize.z, this.rotation.extractBasis(A.u[0], A.u[1], A.u[2]), w.c = e.center, w.e[0] = e.halfSize.x, w.e[1] = e.halfSize.y, w.e[2] = e.halfSize.z, e.rotation.extractBasis(w.u[0], w.u[1], w.u[2]);
|
|
2105
|
+
for (let s = 0; s < 3; s++)
|
|
2106
|
+
for (let i = 0; i < 3; i++)
|
|
2107
|
+
L[s][i] = A.u[s].dot(w.u[i]);
|
|
2108
|
+
M.subVectors(w.c, A.c), E[0] = M.dot(A.u[0]), E[1] = M.dot(A.u[1]), E[2] = M.dot(A.u[2]);
|
|
2109
|
+
for (let s = 0; s < 3; s++)
|
|
2110
|
+
for (let i = 0; i < 3; i++)
|
|
2111
|
+
x[s][i] = Math.abs(L[s][i]) + t;
|
|
2112
|
+
let r, n;
|
|
2113
|
+
for (let s = 0; s < 3; s++)
|
|
2114
|
+
if (r = A.e[s], n = w.e[0] * x[s][0] + w.e[1] * x[s][1] + w.e[2] * x[s][2], Math.abs(E[s]) > r + n) return !1;
|
|
2115
|
+
for (let s = 0; s < 3; s++)
|
|
2116
|
+
if (r = A.e[0] * x[0][s] + A.e[1] * x[1][s] + A.e[2] * x[2][s], n = w.e[s], Math.abs(E[0] * L[0][s] + E[1] * L[1][s] + E[2] * L[2][s]) > r + n) return !1;
|
|
2117
|
+
return r = A.e[1] * x[2][0] + A.e[2] * x[1][0], n = w.e[1] * x[0][2] + w.e[2] * x[0][1], !(Math.abs(E[2] * L[1][0] - E[1] * L[2][0]) > r + n || (r = A.e[1] * x[2][1] + A.e[2] * x[1][1], n = w.e[0] * x[0][2] + w.e[2] * x[0][0], Math.abs(E[2] * L[1][1] - E[1] * L[2][1]) > r + n) || (r = A.e[1] * x[2][2] + A.e[2] * x[1][2], n = w.e[0] * x[0][1] + w.e[1] * x[0][0], Math.abs(E[2] * L[1][2] - E[1] * L[2][2]) > r + n) || (r = A.e[0] * x[2][0] + A.e[2] * x[0][0], n = w.e[1] * x[1][2] + w.e[2] * x[1][1], Math.abs(E[0] * L[2][0] - E[2] * L[0][0]) > r + n) || (r = A.e[0] * x[2][1] + A.e[2] * x[0][1], n = w.e[0] * x[1][2] + w.e[2] * x[1][0], Math.abs(E[0] * L[2][1] - E[2] * L[0][1]) > r + n) || (r = A.e[0] * x[2][2] + A.e[2] * x[0][2], n = w.e[0] * x[1][1] + w.e[1] * x[1][0], Math.abs(E[0] * L[2][2] - E[2] * L[0][2]) > r + n) || (r = A.e[0] * x[1][0] + A.e[1] * x[0][0], n = w.e[1] * x[2][2] + w.e[2] * x[2][1], Math.abs(E[1] * L[0][0] - E[0] * L[1][0]) > r + n) || (r = A.e[0] * x[1][1] + A.e[1] * x[0][1], n = w.e[0] * x[2][2] + w.e[2] * x[2][0], Math.abs(E[1] * L[0][1] - E[0] * L[1][1]) > r + n) || (r = A.e[0] * x[1][2] + A.e[1] * x[0][2], n = w.e[0] * x[2][1] + w.e[1] * x[2][0], Math.abs(E[1] * L[0][2] - E[0] * L[1][2]) > r + n));
|
|
2118
|
+
}
|
|
2119
|
+
/**
|
|
2120
|
+
* Returns `true` if the given plane intersects this OBB.
|
|
2121
|
+
*
|
|
2122
|
+
* @param {Plane} plane - The plane to test.
|
|
2123
|
+
* @returns {boolean} Whether the given plane intersects this OBB or not.
|
|
2124
|
+
*/
|
|
2125
|
+
intersectsPlane(e) {
|
|
2126
|
+
this.rotation.extractBasis(W, Y, J);
|
|
2127
|
+
const t = this.halfSize.x * Math.abs(e.normal.dot(W)) + this.halfSize.y * Math.abs(e.normal.dot(Y)) + this.halfSize.z * Math.abs(e.normal.dot(J)), r = e.normal.dot(this.center) - e.constant;
|
|
2128
|
+
return Math.abs(r) <= t;
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Performs a ray/OBB intersection test and stores the intersection point
|
|
2132
|
+
* in the given 3D vector.
|
|
2133
|
+
*
|
|
2134
|
+
* @param {Ray} ray - The ray to test.
|
|
2135
|
+
* @param {Vector3} target - The target vector that is used to store the method's result.
|
|
2136
|
+
* @return {?Vector3} The intersection point. If no intersection is detected, `null` is returned.
|
|
2137
|
+
*/
|
|
2138
|
+
intersectRay(e, t) {
|
|
2139
|
+
return this.getSize(Ge), je.setFromCenterAndSize(M.set(0, 0, 0), Ge), ae.setFromMatrix3(this.rotation), ae.setPosition(this.center), ze.copy(ae).invert(), Ke.copy(e).applyMatrix4(ze), Ke.intersectBox(je, t) ? t.applyMatrix4(ae) : null;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Returns `true` if the given ray intersects this OBB.
|
|
2143
|
+
*
|
|
2144
|
+
* @param {Ray} ray - The ray to test.
|
|
2145
|
+
* @returns {boolean} Whether the given ray intersects this OBB or not.
|
|
2146
|
+
*/
|
|
2147
|
+
intersectsRay(e) {
|
|
2148
|
+
return this.intersectRay(e, M) !== null;
|
|
2149
|
+
}
|
|
2150
|
+
/**
|
|
2151
|
+
* Defines an OBB based on the given AABB.
|
|
2152
|
+
*
|
|
2153
|
+
* @param {Box3} box3 - The AABB to setup the OBB from.
|
|
2154
|
+
* @return {OBB} A reference of this OBB.
|
|
2155
|
+
*/
|
|
2156
|
+
fromBox3(e) {
|
|
2157
|
+
return e.getCenter(this.center), e.getSize(this.halfSize).multiplyScalar(0.5), this.rotation.identity(), this;
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Returns `true` if the given OBB is equal to this OBB.
|
|
2161
|
+
*
|
|
2162
|
+
* @param {OBB} obb - The OBB to test.
|
|
2163
|
+
* @returns {boolean} Whether the given OBB is equal to this OBB or not.
|
|
2164
|
+
*/
|
|
2165
|
+
equals(e) {
|
|
2166
|
+
return e.center.equals(this.center) && e.halfSize.equals(this.halfSize) && e.rotation.equals(this.rotation);
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Applies the given transformation matrix to this OBB. This method can be
|
|
2170
|
+
* used to transform the bounding volume with the world matrix of a 3D object
|
|
2171
|
+
* in order to keep both entities in sync.
|
|
2172
|
+
*
|
|
2173
|
+
* @param {Matrix4} matrix - The matrix to apply.
|
|
2174
|
+
* @return {OBB} A reference of this OBB.
|
|
2175
|
+
*/
|
|
2176
|
+
applyMatrix4(e) {
|
|
2177
|
+
const t = e.elements;
|
|
2178
|
+
let r = M.set(t[0], t[1], t[2]).length();
|
|
2179
|
+
const n = M.set(t[4], t[5], t[6]).length(), s = M.set(t[8], t[9], t[10]).length();
|
|
2180
|
+
e.determinant() < 0 && (r = -r), D.setFromMatrix4(e);
|
|
2181
|
+
const a = 1 / r, o = 1 / n, c = 1 / s;
|
|
2182
|
+
return D.elements[0] *= a, D.elements[1] *= a, D.elements[2] *= a, D.elements[3] *= o, D.elements[4] *= o, D.elements[5] *= o, D.elements[6] *= c, D.elements[7] *= c, D.elements[8] *= c, this.rotation.multiply(D), this.halfSize.x *= r, this.halfSize.y *= n, this.halfSize.z *= s, M.setFromMatrixPosition(e), this.center.add(M), this;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
const Gn = new Ee(), Bn = {
|
|
2186
|
+
enableDamping: !0,
|
|
2187
|
+
dampingFactor: 0.25,
|
|
2188
|
+
screenSpacePanning: !1,
|
|
2189
|
+
minDistance: 0.1,
|
|
2190
|
+
maxDistance: 1e3,
|
|
2191
|
+
maxPolarAngle: Z.degToRad(60)
|
|
2192
|
+
};
|
|
2193
|
+
function Yn(h, e) {
|
|
2194
|
+
const t = Object.assign(
|
|
2195
|
+
{
|
|
2196
|
+
css3d: !1,
|
|
2197
|
+
stats: !1,
|
|
2198
|
+
renderType: "change",
|
|
2199
|
+
control: {
|
|
2200
|
+
init: !0,
|
|
2201
|
+
options: {}
|
|
2202
|
+
}
|
|
2203
|
+
},
|
|
2204
|
+
e || {}
|
|
2205
|
+
);
|
|
2206
|
+
let r, n, s, i = [];
|
|
2207
|
+
const a = pe(!1), o = Xt(), c = pe(0), u = pe(0), l = new zt({
|
|
2208
|
+
antialias: !0,
|
|
2209
|
+
alpha: !0,
|
|
2210
|
+
precision: "mediump",
|
|
2211
|
+
logarithmicDepthBuffer: !0
|
|
2212
|
+
}), d = new Kt({}), f = new $e(50, 1, 0.1, 2e3), p = Math.tan(Math.PI / 180 * f.fov / 2);
|
|
2213
|
+
let T = !1;
|
|
2214
|
+
l.setPixelRatio(window.devicePixelRatio);
|
|
2215
|
+
function m() {
|
|
2216
|
+
a.value = !1;
|
|
2217
|
+
const N = B();
|
|
2218
|
+
c.value = N[0], u.value = N[1], f.aspect = c.value / u.value, f.position.set(47, 39, 100), f.fov = 360 / Math.PI * Math.atan(p * (u.value / c.value)), f.lookAt(0, 0, 0), f.updateProjectionMatrix(), l.setSize(c.value, u.value), r.appendChild(l.domElement), t.stats && k(), t.css3d && rt();
|
|
2219
|
+
let j;
|
|
2220
|
+
if (t.control && t.control.init) {
|
|
2221
|
+
j = Yt(f, l.domElement);
|
|
2222
|
+
const z = Object.assign(
|
|
2223
|
+
Bn,
|
|
2224
|
+
t.control.options || {}
|
|
2225
|
+
);
|
|
2226
|
+
Object.keys(z).forEach((ne) => {
|
|
2227
|
+
j[ne] = z[ne];
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
return Pe(() => a.value = !0), j;
|
|
2231
|
+
}
|
|
2232
|
+
function g(N) {
|
|
2233
|
+
N.preventDefault(), cancelAnimationFrame(y);
|
|
2234
|
+
}
|
|
2235
|
+
function b(N) {
|
|
2236
|
+
N.preventDefault(), m(), y();
|
|
2237
|
+
}
|
|
2238
|
+
function S(N) {
|
|
2239
|
+
i.push(N);
|
|
2240
|
+
}
|
|
2241
|
+
function y(N) {
|
|
2242
|
+
i && i.length && i.forEach((j) => {
|
|
2243
|
+
typeof j == "function" && j();
|
|
2244
|
+
}), t.renderType === "loop" && I(), requestAnimationFrame(y);
|
|
2245
|
+
}
|
|
2246
|
+
function I() {
|
|
2247
|
+
T = !1, n && n.update(), o.value && o.value.update(), l.render(d, f), s && s.render(d, f);
|
|
2248
|
+
}
|
|
2249
|
+
function P() {
|
|
2250
|
+
T || (T = !0, requestAnimationFrame(I));
|
|
2251
|
+
}
|
|
2252
|
+
function C() {
|
|
2253
|
+
Pe(() => {
|
|
2254
|
+
const N = B();
|
|
2255
|
+
c.value = N[0], u.value = N[1], f.aspect = c.value / u.value, f.fov = 360 / Math.PI * Math.atan(p * (u.value / c.value)), f.updateProjectionMatrix(), f.lookAt(d.position), l.setSize(c.value, u.value), s && s.setSize(c.value, u.value), I();
|
|
2256
|
+
});
|
|
2257
|
+
}
|
|
2258
|
+
function B() {
|
|
2259
|
+
return r = document.querySelector(h), r ? [r.clientWidth, r.clientHeight] : [0, 0];
|
|
2260
|
+
}
|
|
2261
|
+
function k() {
|
|
2262
|
+
n = new Qt(), n.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", r.appendChild(n.dom);
|
|
2263
|
+
}
|
|
2264
|
+
function te(N, j, z, ne, Le) {
|
|
2265
|
+
const Me = new ue().setFromObject(N), Ie = Me.getSize(new _()).length(), X = Me.getCenter(new _());
|
|
2266
|
+
Le && X.add(Le);
|
|
2267
|
+
const ot = Ie * j * 0.5, at = Z.degToRad(z.fov * 0.5), ct = ot / Math.tan(at), de = new _().subVectors(z.position, X).multiply(new _(1, 1, 1)).normalize().multiplyScalar(ct).add(X), Q = {
|
|
2268
|
+
x: de.x,
|
|
2269
|
+
y: de.y,
|
|
2270
|
+
z: de.z,
|
|
2271
|
+
lookAt_x: X.x,
|
|
2272
|
+
lookAt_y: X.y,
|
|
2273
|
+
lookAt_z: X.z
|
|
2274
|
+
};
|
|
2275
|
+
return z.position.set(Q.x, Q.y, Q.z), z.lookAt(
|
|
2276
|
+
Q.lookAt_x,
|
|
2277
|
+
Q.lookAt_y,
|
|
2278
|
+
Q.lookAt_z
|
|
2279
|
+
), z.updateProjectionMatrix(), ne.target.copy(X), ne.update(), Ie;
|
|
2280
|
+
}
|
|
2281
|
+
function rt() {
|
|
2282
|
+
s = new Zt(), s.setSize(c.value, u.value), s.domElement.style.position = "absolute", s.domElement.style.top = 0, s.domElement.style.left = 0, s.domElement.style.pointerEvents = "none", r.appendChild(s.domElement);
|
|
2283
|
+
}
|
|
2284
|
+
function it() {
|
|
2285
|
+
Jt(d);
|
|
2286
|
+
}
|
|
2287
|
+
return qt(() => {
|
|
2288
|
+
o.value = m(), window.addEventListener("resize", C, !1), l.domElement.addEventListener(
|
|
2289
|
+
"webglcontextlost",
|
|
2290
|
+
g,
|
|
2291
|
+
!1
|
|
2292
|
+
), l.domElement.addEventListener(
|
|
2293
|
+
"webglcontextrestored",
|
|
2294
|
+
b,
|
|
2295
|
+
!1
|
|
2296
|
+
), t.renderType === "loop" ? requestAnimationFrame(y) : t.renderType === "change" && o.value && o.value.addEventListener("change", P);
|
|
2297
|
+
}), Wt(() => {
|
|
2298
|
+
cancelAnimationFrame(y), l.domElement.removeEventListener("resize", C, !1), l.domElement.removeEventListener(
|
|
2299
|
+
"webglcontextlost",
|
|
2300
|
+
g,
|
|
2301
|
+
!1
|
|
2302
|
+
), l.domElement.removeEventListener(
|
|
2303
|
+
"webglcontextrestored",
|
|
2304
|
+
b,
|
|
2305
|
+
!1
|
|
2306
|
+
), it();
|
|
2307
|
+
}), {
|
|
2308
|
+
addAnimate: S,
|
|
2309
|
+
frameArea: te,
|
|
2310
|
+
onRender: I,
|
|
2311
|
+
css3dRenderer: s,
|
|
2312
|
+
scene: d,
|
|
2313
|
+
camera: f,
|
|
2314
|
+
control: o,
|
|
2315
|
+
renderer: l,
|
|
2316
|
+
domWidth: c,
|
|
2317
|
+
domHeight: u,
|
|
2318
|
+
isReady: a
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
const Jn = (h = "app") => {
|
|
2322
|
+
const e = new Vt();
|
|
2323
|
+
e.params.Line.threshold = 8;
|
|
2324
|
+
const t = new Se(), r = document.getElementById(h);
|
|
2325
|
+
function n(a, o) {
|
|
2326
|
+
const { scaleX: c, scaleY: u } = i(r), { clientWidth: l, clientHeight: d } = o, f = o.getBoundingClientRect(), p = l * c, T = d * u, m = a.clientX - f.left, g = a.clientY - f.top;
|
|
2327
|
+
return t.x = (a.clientX - f.left) / p * 2 - 1, t.y = -((a.clientY - f.top) / T) * 2 + 1, { pointer: t, x: m, y: g };
|
|
2328
|
+
}
|
|
2329
|
+
function s(a, o, c, u) {
|
|
2330
|
+
const { pointer: l, x: d, y: f } = n(a, o);
|
|
2331
|
+
return e.setFromCamera(l, c), { intersects: e.intersectObjects(u), pointer: l, x: d, y: f };
|
|
2332
|
+
}
|
|
2333
|
+
function i(a) {
|
|
2334
|
+
const o = window.getComputedStyle(a), c = o.transform || o.webkitTransform || o.mozTransform;
|
|
2335
|
+
if (c && c !== "none") {
|
|
2336
|
+
const u = c.match(/^matrix\((.+)\)$/);
|
|
2337
|
+
if (u) {
|
|
2338
|
+
const l = u[1].split(", "), d = parseFloat(l[0]), f = parseFloat(l[3]);
|
|
2339
|
+
return { scaleX: d, scaleY: f };
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
return { scaleX: 1, scaleY: 1 };
|
|
2343
|
+
}
|
|
2344
|
+
return {
|
|
2345
|
+
raycaster: e,
|
|
2346
|
+
pointer: t,
|
|
2347
|
+
getPointer: n,
|
|
2348
|
+
getScale: i,
|
|
2349
|
+
getIntersects: s
|
|
2350
|
+
};
|
|
2351
|
+
}, H = [], Qn = new G(16711680), Zn = () => {
|
|
2352
|
+
const h = () => {
|
|
2353
|
+
H.splice(0);
|
|
2354
|
+
}, e = (a, o) => {
|
|
2355
|
+
o.traverse((c) => {
|
|
2356
|
+
c && t(a, c);
|
|
2357
|
+
});
|
|
2358
|
+
}, t = (a, o) => {
|
|
2359
|
+
if (o.userData.needCheck && (o.autoUpdateMatrix = !1, o.updateMatrix(), o.updateMatrixWorld(), o.isMesh)) {
|
|
2360
|
+
const c = new ue(new _()).setFromObject(o);
|
|
2361
|
+
o.geometry.userData.obb = new Ee(), o.geometry.userData.obb.halfSize.copy(c.getSize(new _())).multiplyScalar(0.5).multiplyScalar(0.88), o.userData.obb = new Ee(), o.userData.originColor = o.material.color.clone(), o.userData.parentUid = a, H.push({
|
|
2362
|
+
object: o,
|
|
2363
|
+
parentUid: a
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
};
|
|
2367
|
+
return {
|
|
2368
|
+
resetObbs: h,
|
|
2369
|
+
initObb: e,
|
|
2370
|
+
getObbObjectByParentUid: (a) => H.filter((o) => o.parentUid === a),
|
|
2371
|
+
addObbFromArray: (a, o) => {
|
|
2372
|
+
for (let c = 0, u = o.length; c < u; c++)
|
|
2373
|
+
t(a, o[c]);
|
|
2374
|
+
},
|
|
2375
|
+
removeObbFromArray: (a) => {
|
|
2376
|
+
const o = H.filter((c) => !a.includes(c.object));
|
|
2377
|
+
H.splice(0, H.length, ...o);
|
|
2378
|
+
},
|
|
2379
|
+
removeUidObb: (a) => {
|
|
2380
|
+
for (let o = H.length - 1; o >= 0; o--)
|
|
2381
|
+
H[o].parentUid === a && H.splice(o, 1);
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
};
|
|
2385
|
+
class jn {
|
|
2386
|
+
/**
|
|
2387
|
+
* 构造函数
|
|
2388
|
+
* @param {string} dbName - 数据库名称
|
|
2389
|
+
* @param {Object} tableDefinitions - 表定义对象,例如 { models: "&path, data" }
|
|
2390
|
+
* @param {number} version - 数据库版本号
|
|
2391
|
+
*/
|
|
2392
|
+
constructor(e = "threeJsIDBCache", t = 3) {
|
|
2393
|
+
this.version = t, this.dbName = e, this.dbInit();
|
|
2394
|
+
}
|
|
2395
|
+
dbInit() {
|
|
2396
|
+
this.db = new tn(this.dbName), this.materialMap = {}, this.db.version(this.version).stores({ models: "&path, version, data" });
|
|
2397
|
+
}
|
|
2398
|
+
/**
|
|
2399
|
+
* 获取 Dexie 数据库实例
|
|
2400
|
+
* @returns {Dexie} Dexie 实例
|
|
2401
|
+
*/
|
|
2402
|
+
getDatabase() {
|
|
2403
|
+
return this.db;
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* 缓存模型到 IndexedDB
|
|
2407
|
+
* @param {string} path - 主键值
|
|
2408
|
+
* @param {THREE.Object3D} model - 要缓存的模型
|
|
2409
|
+
* @param {string} [version] - 缓存模型版本
|
|
2410
|
+
*/
|
|
2411
|
+
async cacheModel(e, t, r) {
|
|
2412
|
+
try {
|
|
2413
|
+
this.db.table("models").put({ version: r, path: e, data: t }).then(() => {
|
|
2414
|
+
console.log(`Model "${e}" cached successfully in table models`);
|
|
2415
|
+
});
|
|
2416
|
+
} catch {
|
|
2417
|
+
console.log(" 缓存模型失败 =====> ");
|
|
2418
|
+
}
|
|
2419
|
+
return t;
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* 从 IndexedDB 加载缓存的模型
|
|
2423
|
+
* @param {string} path - 主键值
|
|
2424
|
+
* @returns {THREE.Object3D | null} 加载的模型
|
|
2425
|
+
*/
|
|
2426
|
+
async loadCachedModel(e, t) {
|
|
2427
|
+
let r = null;
|
|
2428
|
+
try {
|
|
2429
|
+
if (r = await this.db.table("models").get(e), !r)
|
|
2430
|
+
return console.warn(`Model "${t}" not found in table models`), null;
|
|
2431
|
+
if (r.version !== t)
|
|
2432
|
+
return console.log(" =====> 模型版本不一致, 清除当前记录"), await this.db.table("models").delete(e), null;
|
|
2433
|
+
} catch {
|
|
2434
|
+
return console.log(" =====> 查询表中模型失败"), this.db.delete().then(() => {
|
|
2435
|
+
this.init();
|
|
2436
|
+
}), null;
|
|
2437
|
+
}
|
|
2438
|
+
return r.data;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
let ce;
|
|
2442
|
+
const $n = () => {
|
|
2443
|
+
const h = new rn(), e = new nn();
|
|
2444
|
+
e.setDecoderPath("/draco/"), h.setDRACOLoader(e);
|
|
2445
|
+
function t(s, i, a, o) {
|
|
2446
|
+
return h.load(s, i, a, o);
|
|
2447
|
+
}
|
|
2448
|
+
function r(s, i) {
|
|
2449
|
+
return new Promise((a, o) => {
|
|
2450
|
+
h.load(s, a, i, o);
|
|
2451
|
+
});
|
|
2452
|
+
}
|
|
2453
|
+
async function n(s, i, a = !0, o) {
|
|
2454
|
+
ce || (ce = new jn());
|
|
2455
|
+
const c = await ce.loadCachedModel(s, i);
|
|
2456
|
+
return c ? a ? $t(c) : c : new Promise((u, l) => {
|
|
2457
|
+
h.load(s, u, o, l);
|
|
2458
|
+
}).then(async (u) => {
|
|
2459
|
+
const l = en(u);
|
|
2460
|
+
return ce.cacheModel(s, u.scene, i), a ? u.scene : l;
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
return {
|
|
2464
|
+
load: t,
|
|
2465
|
+
asyncLoad: r,
|
|
2466
|
+
asyncCacheLoad: n
|
|
2467
|
+
};
|
|
2468
|
+
};
|
|
2469
|
+
export {
|
|
2470
|
+
jn as I,
|
|
2471
|
+
Jn as a,
|
|
2472
|
+
Zn as b,
|
|
2473
|
+
$n as c,
|
|
2474
|
+
Qn as i,
|
|
2475
|
+
H as o,
|
|
2476
|
+
Yn as u
|
|
2477
|
+
};
|