@ridp/threejs 1.3.3 → 1.4.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/ImageLoader-Br_nvMOg.js +1444 -0
- package/dist/ImageLoader-DL32KyTh.cjs +24 -0
- package/dist/PredictiveLoader-CZfMSjv-.js +3731 -0
- package/dist/PredictiveLoader-DDxh7dDg.cjs +2 -0
- package/dist/assets/gltfParser.worker-Bqz8BBJx.js +6 -0
- package/dist/assets/gltfParserOptimized.worker-DfipxPjm.js +6 -0
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +7 -5
- package/dist/modelOptimizer-A0Cs6f9e.cjs +1 -0
- package/dist/modelOptimizer-BRPnM2RH.js +179 -0
- package/dist/threejs.cjs +3 -1
- package/dist/threejs.js +334 -118
- package/dist/useBatchGLTFLoader-B5EUagWI.js +493 -0
- package/dist/useBatchGLTFLoader-BjAvIpyB.cjs +5 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +32 -20
- package/package.json +1 -1
- package/readme.md +1186 -94
- package/dist/ImageLoader-DwvBWW6h.cjs +0 -5
- package/dist/ImageLoader-xzOH4Owt.js +0 -860
- package/dist/modelSerialize-B8gu_KnK.cjs +0 -15
- package/dist/modelSerialize-DWUt6OcZ.js +0 -276
- package/dist/useGLTFLoader-D01iU8lB.cjs +0 -2
- package/dist/useGLTFLoader-MhUFIZp1.js +0 -2510
|
@@ -1,2510 +0,0 @@
|
|
|
1
|
-
import { TrianglesDrawMode as ut, TriangleFanDrawMode as xe, TriangleStripDrawMode as Xe, Loader as qe, FileLoader as le, SRGBColorSpace as V, LinearSRGBColorSpace as F, BufferGeometry as We, BufferAttribute as oe, Color as B, ColorManagement as Re, LoaderUtils as ie, MeshPhysicalMaterial as v, Vector2 as Se, SpotLight as dt, PointLight as ft, DirectionalLight as ht, Matrix4 as ee, Vector3 as E, Quaternion as Ye, InstancedMesh as pt, InstancedBufferAttribute as mt, Object3D as Je, TextureLoader as gt, ImageBitmapLoader as Tt, InterleavedBuffer as yt, InterleavedBufferAttribute as xt, LinearMipmapLinearFilter as Qe, NearestMipmapLinearFilter as Rt, LinearMipmapNearestFilter as bt, NearestMipmapNearestFilter as At, LinearFilter as be, NearestFilter as $e, RepeatWrapping as Ae, MirroredRepeatWrapping as wt, ClampToEdgeWrapping as Et, PointsMaterial as _t, Material as fe, LineBasicMaterial as St, MeshStandardMaterial as Ze, DoubleSide as Lt, MeshBasicMaterial as re, PropertyBinding as Mt, SkinnedMesh as It, Mesh as Ct, LineSegments as Nt, Line as Ot, LineLoop as Pt, Points as kt, Group as he, PerspectiveCamera as et, MathUtils as $, OrthographicCamera as Dt, Skeleton as Ft, AnimationClip as vt, Bone as Ht, InterpolateDiscrete as Ut, InterpolateLinear as tt, Texture as Ce, VectorKeyframeTrack as Ne, NumberKeyframeTrack as Oe, QuaternionKeyframeTrack as Pe, FrontSide as Bt, Interpolant as Gt, Box3 as ue, Sphere as jt, Matrix3 as nt, Ray as zt, WebGLRenderer as Kt, Scene as Vt, Raycaster as Xt } from "three";
|
|
2
|
-
import { ref as pe, shallowRef as qt, onMounted as Wt, onUnmounted as Yt, nextTick as ke } from "vue";
|
|
3
|
-
import { d as Jt, j as Qt, S as $t, C as Zt } from "./ImageLoader-xzOH4Owt.js";
|
|
4
|
-
import en from "dexie";
|
|
5
|
-
function De(f, e) {
|
|
6
|
-
if (e === ut)
|
|
7
|
-
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), f;
|
|
8
|
-
if (e === xe || e === Xe) {
|
|
9
|
-
let t = f.getIndex();
|
|
10
|
-
if (t === null) {
|
|
11
|
-
const o = [], a = f.getAttribute("position");
|
|
12
|
-
if (a !== void 0) {
|
|
13
|
-
for (let i = 0; i < a.count; i++)
|
|
14
|
-
o.push(i);
|
|
15
|
-
f.setIndex(o), t = f.getIndex();
|
|
16
|
-
} else
|
|
17
|
-
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), f;
|
|
18
|
-
}
|
|
19
|
-
const s = t.count - 2, n = [];
|
|
20
|
-
if (e === xe)
|
|
21
|
-
for (let o = 1; o <= s; o++)
|
|
22
|
-
n.push(t.getX(0)), n.push(t.getX(o)), n.push(t.getX(o + 1));
|
|
23
|
-
else
|
|
24
|
-
for (let o = 0; o < s; o++)
|
|
25
|
-
o % 2 === 0 ? (n.push(t.getX(o)), n.push(t.getX(o + 1)), n.push(t.getX(o + 2))) : (n.push(t.getX(o + 2)), n.push(t.getX(o + 1)), n.push(t.getX(o)));
|
|
26
|
-
n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
|
|
27
|
-
const r = f.clone();
|
|
28
|
-
return r.setIndex(n), r.clearGroups(), r;
|
|
29
|
-
} else
|
|
30
|
-
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), f;
|
|
31
|
-
}
|
|
32
|
-
const me = /* @__PURE__ */ new WeakMap();
|
|
33
|
-
class tn extends qe {
|
|
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, s, n) {
|
|
90
|
-
const r = new le(this.manager);
|
|
91
|
-
r.setPath(this.path), r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setWithCredentials(this.withCredentials), r.load(e, (o) => {
|
|
92
|
-
this.parse(o, t, n);
|
|
93
|
-
}, s, 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, s = () => {
|
|
103
|
-
}) {
|
|
104
|
-
this.decodeDracoFile(e, t, null, null, V, s).catch(s);
|
|
105
|
-
}
|
|
106
|
-
//
|
|
107
|
-
decodeDracoFile(e, t, s, n, r = F, o = () => {
|
|
108
|
-
}) {
|
|
109
|
-
const a = {
|
|
110
|
-
attributeIDs: s || this.defaultAttributeIDs,
|
|
111
|
-
attributeTypes: n || this.defaultAttributeTypes,
|
|
112
|
-
useUniqueIDs: !!s,
|
|
113
|
-
vertexColorSpace: r
|
|
114
|
-
};
|
|
115
|
-
return this.decodeGeometry(e, a).then(t).catch(o);
|
|
116
|
-
}
|
|
117
|
-
decodeGeometry(e, t) {
|
|
118
|
-
const s = JSON.stringify(t);
|
|
119
|
-
if (me.has(e)) {
|
|
120
|
-
const i = me.get(e);
|
|
121
|
-
if (i.key === s)
|
|
122
|
-
return i.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 r = this.workerNextTaskID++, o = e.byteLength, a = this._getWorker(r, o).then((i) => (n = i, new Promise((c, l) => {
|
|
130
|
-
n._callbacks[r] = { resolve: c, reject: l }, n.postMessage({ type: "decode", id: r, taskConfig: t, buffer: e }, [e]);
|
|
131
|
-
}))).then((i) => this._createGeometry(i.geometry));
|
|
132
|
-
return a.catch(() => !0).then(() => {
|
|
133
|
-
n && r && this._releaseTask(n, r);
|
|
134
|
-
}), me.set(e, {
|
|
135
|
-
key: s,
|
|
136
|
-
promise: a
|
|
137
|
-
}), a;
|
|
138
|
-
}
|
|
139
|
-
_createGeometry(e) {
|
|
140
|
-
const t = new We();
|
|
141
|
-
e.index && t.setIndex(new oe(e.index.array, 1));
|
|
142
|
-
for (let s = 0; s < e.attributes.length; s++) {
|
|
143
|
-
const n = e.attributes[s], r = n.name, o = n.array, a = n.itemSize, i = new oe(o, a);
|
|
144
|
-
r === "color" && (this._assignVertexColorSpace(i, n.vertexColorSpace), i.normalized = !(o instanceof Float32Array)), t.setAttribute(r, i);
|
|
145
|
-
}
|
|
146
|
-
return t;
|
|
147
|
-
}
|
|
148
|
-
_assignVertexColorSpace(e, t) {
|
|
149
|
-
if (t !== V) return;
|
|
150
|
-
const s = new B();
|
|
151
|
-
for (let n = 0, r = e.count; n < r; n++)
|
|
152
|
-
s.fromBufferAttribute(e, n), Re.colorSpaceToWorking(s, V), e.setXYZ(n, s.r, s.g, s.b);
|
|
153
|
-
}
|
|
154
|
-
_loadLibrary(e, t) {
|
|
155
|
-
const s = new le(this.manager);
|
|
156
|
-
return s.setPath(this.decoderPath), s.setResponseType(t), s.setWithCredentials(this.withCredentials), new Promise((n, r) => {
|
|
157
|
-
s.load(e, n, void 0, r);
|
|
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((s) => {
|
|
167
|
-
const n = s[0];
|
|
168
|
-
e || (this.decoderConfig.wasmBinary = s[1]);
|
|
169
|
-
const r = nn.toString(), o = [
|
|
170
|
-
"/* draco decoder */",
|
|
171
|
-
n,
|
|
172
|
-
"",
|
|
173
|
-
"/* worker */",
|
|
174
|
-
r.substring(r.indexOf("{") + 1, r.lastIndexOf("}"))
|
|
175
|
-
].join(`
|
|
176
|
-
`);
|
|
177
|
-
this.workerSourceURL = URL.createObjectURL(new Blob([o]));
|
|
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(r) {
|
|
185
|
-
const o = r.data;
|
|
186
|
-
switch (o.type) {
|
|
187
|
-
case "decode":
|
|
188
|
-
n._callbacks[o.id].resolve(o);
|
|
189
|
-
break;
|
|
190
|
-
case "error":
|
|
191
|
-
n._callbacks[o.id].reject(o);
|
|
192
|
-
break;
|
|
193
|
-
default:
|
|
194
|
-
console.error('THREE.DRACOLoader: Unexpected message, "' + o.type + '"');
|
|
195
|
-
}
|
|
196
|
-
}, this.workerPool.push(n);
|
|
197
|
-
} else
|
|
198
|
-
this.workerPool.sort(function(n, r) {
|
|
199
|
-
return n._taskLoad > r._taskLoad ? -1 : 1;
|
|
200
|
-
});
|
|
201
|
-
const s = this.workerPool[this.workerPool.length - 1];
|
|
202
|
-
return s._taskCosts[e] = t, s._taskLoad += t, s;
|
|
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 nn() {
|
|
218
|
-
let f, e;
|
|
219
|
-
onmessage = function(o) {
|
|
220
|
-
const a = o.data;
|
|
221
|
-
switch (a.type) {
|
|
222
|
-
case "init":
|
|
223
|
-
f = a.decoderConfig, e = new Promise(function(l) {
|
|
224
|
-
f.onModuleLoaded = function(u) {
|
|
225
|
-
l({ draco: u });
|
|
226
|
-
}, DracoDecoderModule(f);
|
|
227
|
-
});
|
|
228
|
-
break;
|
|
229
|
-
case "decode":
|
|
230
|
-
const i = a.buffer, c = a.taskConfig;
|
|
231
|
-
e.then((l) => {
|
|
232
|
-
const u = l.draco, d = new u.Decoder();
|
|
233
|
-
try {
|
|
234
|
-
const h = t(u, d, new Int8Array(i), c), p = h.attributes.map((T) => T.array.buffer);
|
|
235
|
-
h.index && p.push(h.index.array.buffer), self.postMessage({ type: "decode", id: a.id, geometry: h }, p);
|
|
236
|
-
} catch (h) {
|
|
237
|
-
console.error(h), self.postMessage({ type: "error", id: a.id, error: h.message });
|
|
238
|
-
} finally {
|
|
239
|
-
u.destroy(d);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
function t(o, a, i, c) {
|
|
246
|
-
const l = c.attributeIDs, u = c.attributeTypes;
|
|
247
|
-
let d, h;
|
|
248
|
-
const p = a.GetEncodedGeometryType(i);
|
|
249
|
-
if (p === o.TRIANGULAR_MESH)
|
|
250
|
-
d = new o.Mesh(), h = a.DecodeArrayToMesh(i, i.byteLength, d);
|
|
251
|
-
else if (p === o.POINT_CLOUD)
|
|
252
|
-
d = new o.PointCloud(), h = a.DecodeArrayToPointCloud(i, i.byteLength, d);
|
|
253
|
-
else
|
|
254
|
-
throw new Error("THREE.DRACOLoader: Unexpected geometry type.");
|
|
255
|
-
if (!h.ok() || d.ptr === 0)
|
|
256
|
-
throw new Error("THREE.DRACOLoader: Decoding failed: " + h.error_msg());
|
|
257
|
-
const T = { index: null, attributes: [] };
|
|
258
|
-
for (const m in l) {
|
|
259
|
-
const g = self[u[m]];
|
|
260
|
-
let b, S;
|
|
261
|
-
if (c.useUniqueIDs)
|
|
262
|
-
S = l[m], b = a.GetAttributeByUniqueId(d, S);
|
|
263
|
-
else {
|
|
264
|
-
if (S = a.GetAttributeId(d, o[l[m]]), S === -1) continue;
|
|
265
|
-
b = a.GetAttribute(d, S);
|
|
266
|
-
}
|
|
267
|
-
const x = n(o, a, d, m, g, b);
|
|
268
|
-
m === "color" && (x.vertexColorSpace = c.vertexColorSpace), T.attributes.push(x);
|
|
269
|
-
}
|
|
270
|
-
return p === o.TRIANGULAR_MESH && (T.index = s(o, a, d)), o.destroy(d), T;
|
|
271
|
-
}
|
|
272
|
-
function s(o, a, i) {
|
|
273
|
-
const l = i.num_faces() * 3, u = l * 4, d = o._malloc(u);
|
|
274
|
-
a.GetTrianglesUInt32Array(i, u, d);
|
|
275
|
-
const h = new Uint32Array(o.HEAPF32.buffer, d, l).slice();
|
|
276
|
-
return o._free(d), { array: h, itemSize: 1 };
|
|
277
|
-
}
|
|
278
|
-
function n(o, a, i, c, l, u) {
|
|
279
|
-
const d = u.num_components(), p = i.num_points() * d, T = p * l.BYTES_PER_ELEMENT, m = r(o, l), g = o._malloc(T);
|
|
280
|
-
a.GetAttributeDataArrayForAllPoints(i, u, m, T, g);
|
|
281
|
-
const b = new l(o.HEAPF32.buffer, g, p).slice();
|
|
282
|
-
return o._free(g), {
|
|
283
|
-
name: c,
|
|
284
|
-
array: b,
|
|
285
|
-
itemSize: d
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function r(o, a) {
|
|
289
|
-
switch (a) {
|
|
290
|
-
case Float32Array:
|
|
291
|
-
return o.DT_FLOAT32;
|
|
292
|
-
case Int8Array:
|
|
293
|
-
return o.DT_INT8;
|
|
294
|
-
case Int16Array:
|
|
295
|
-
return o.DT_INT16;
|
|
296
|
-
case Int32Array:
|
|
297
|
-
return o.DT_INT32;
|
|
298
|
-
case Uint8Array:
|
|
299
|
-
return o.DT_UINT8;
|
|
300
|
-
case Uint16Array:
|
|
301
|
-
return o.DT_UINT16;
|
|
302
|
-
case Uint32Array:
|
|
303
|
-
return o.DT_UINT32;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
class sn extends qe {
|
|
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 ln(t);
|
|
316
|
-
}), this.register(function(t) {
|
|
317
|
-
return new un(t);
|
|
318
|
-
}), this.register(function(t) {
|
|
319
|
-
return new xn(t);
|
|
320
|
-
}), this.register(function(t) {
|
|
321
|
-
return new Rn(t);
|
|
322
|
-
}), this.register(function(t) {
|
|
323
|
-
return new bn(t);
|
|
324
|
-
}), this.register(function(t) {
|
|
325
|
-
return new fn(t);
|
|
326
|
-
}), this.register(function(t) {
|
|
327
|
-
return new hn(t);
|
|
328
|
-
}), this.register(function(t) {
|
|
329
|
-
return new pn(t);
|
|
330
|
-
}), this.register(function(t) {
|
|
331
|
-
return new mn(t);
|
|
332
|
-
}), this.register(function(t) {
|
|
333
|
-
return new cn(t);
|
|
334
|
-
}), this.register(function(t) {
|
|
335
|
-
return new gn(t);
|
|
336
|
-
}), this.register(function(t) {
|
|
337
|
-
return new dn(t);
|
|
338
|
-
}), this.register(function(t) {
|
|
339
|
-
return new yn(t);
|
|
340
|
-
}), this.register(function(t) {
|
|
341
|
-
return new Tn(t);
|
|
342
|
-
}), this.register(function(t) {
|
|
343
|
-
return new on(t);
|
|
344
|
-
}), this.register(function(t) {
|
|
345
|
-
return new An(t);
|
|
346
|
-
}), this.register(function(t) {
|
|
347
|
-
return new wn(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, s, n) {
|
|
360
|
-
const r = this;
|
|
361
|
-
let o;
|
|
362
|
-
if (this.resourcePath !== "")
|
|
363
|
-
o = this.resourcePath;
|
|
364
|
-
else if (this.path !== "") {
|
|
365
|
-
const c = ie.extractUrlBase(e);
|
|
366
|
-
o = ie.resolveURL(c, this.path);
|
|
367
|
-
} else
|
|
368
|
-
o = ie.extractUrlBase(e);
|
|
369
|
-
this.manager.itemStart(e);
|
|
370
|
-
const a = function(c) {
|
|
371
|
-
n ? n(c) : console.error(c), r.manager.itemError(e), r.manager.itemEnd(e);
|
|
372
|
-
}, i = new le(this.manager);
|
|
373
|
-
i.setPath(this.path), i.setResponseType("arraybuffer"), i.setRequestHeader(this.requestHeader), i.setWithCredentials(this.withCredentials), i.load(e, function(c) {
|
|
374
|
-
try {
|
|
375
|
-
r.parse(c, o, function(l) {
|
|
376
|
-
t(l), r.manager.itemEnd(e);
|
|
377
|
-
}, a);
|
|
378
|
-
} catch (l) {
|
|
379
|
-
a(l);
|
|
380
|
-
}
|
|
381
|
-
}, s, 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, s, n) {
|
|
442
|
-
let r;
|
|
443
|
-
const o = {}, a = {}, i = new TextDecoder();
|
|
444
|
-
if (typeof e == "string")
|
|
445
|
-
r = JSON.parse(e);
|
|
446
|
-
else if (e instanceof ArrayBuffer)
|
|
447
|
-
if (i.decode(new Uint8Array(e, 0, 4)) === st) {
|
|
448
|
-
try {
|
|
449
|
-
o[R.KHR_BINARY_GLTF] = new En(e);
|
|
450
|
-
} catch (u) {
|
|
451
|
-
n && n(u);
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
r = JSON.parse(o[R.KHR_BINARY_GLTF].content);
|
|
455
|
-
} else
|
|
456
|
-
r = JSON.parse(i.decode(e));
|
|
457
|
-
else
|
|
458
|
-
r = e;
|
|
459
|
-
if (r.asset === void 0 || r.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 vn(r, {
|
|
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 l = 0; l < this.pluginCallbacks.length; l++) {
|
|
473
|
-
const u = this.pluginCallbacks[l](c);
|
|
474
|
-
u.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[u.name] = u, o[u.name] = !0;
|
|
475
|
-
}
|
|
476
|
-
if (r.extensionsUsed)
|
|
477
|
-
for (let l = 0; l < r.extensionsUsed.length; ++l) {
|
|
478
|
-
const u = r.extensionsUsed[l], d = r.extensionsRequired || [];
|
|
479
|
-
switch (u) {
|
|
480
|
-
case R.KHR_MATERIALS_UNLIT:
|
|
481
|
-
o[u] = new an();
|
|
482
|
-
break;
|
|
483
|
-
case R.KHR_DRACO_MESH_COMPRESSION:
|
|
484
|
-
o[u] = new _n(r, this.dracoLoader);
|
|
485
|
-
break;
|
|
486
|
-
case R.KHR_TEXTURE_TRANSFORM:
|
|
487
|
-
o[u] = new Sn();
|
|
488
|
-
break;
|
|
489
|
-
case R.KHR_MESH_QUANTIZATION:
|
|
490
|
-
o[u] = new Ln();
|
|
491
|
-
break;
|
|
492
|
-
default:
|
|
493
|
-
d.indexOf(u) >= 0 && a[u] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + u + '".');
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
c.setExtensions(o), c.setPlugins(a), c.parse(s, 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 s = this;
|
|
508
|
-
return new Promise(function(n, r) {
|
|
509
|
-
s.parse(e, t, n, r);
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
function rn() {
|
|
514
|
-
let f = {};
|
|
515
|
-
return {
|
|
516
|
-
get: function(e) {
|
|
517
|
-
return f[e];
|
|
518
|
-
},
|
|
519
|
-
add: function(e, t) {
|
|
520
|
-
f[e] = t;
|
|
521
|
-
},
|
|
522
|
-
remove: function(e) {
|
|
523
|
-
delete f[e];
|
|
524
|
-
},
|
|
525
|
-
removeAll: function() {
|
|
526
|
-
f = {};
|
|
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 on {
|
|
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 s = 0, n = t.length; s < n; s++) {
|
|
561
|
-
const r = t[s];
|
|
562
|
-
r.extensions && r.extensions[this.name] && r.extensions[this.name].light !== void 0 && e._addNodeRef(this.cache, r.extensions[this.name].light);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
_loadLight(e) {
|
|
566
|
-
const t = this.parser, s = "light:" + e;
|
|
567
|
-
let n = t.cache.get(s);
|
|
568
|
-
if (n) return n;
|
|
569
|
-
const r = t.json, i = ((r.extensions && r.extensions[this.name] || {}).lights || [])[e];
|
|
570
|
-
let c;
|
|
571
|
-
const l = new B(16777215);
|
|
572
|
-
i.color !== void 0 && l.setRGB(i.color[0], i.color[1], i.color[2], F);
|
|
573
|
-
const u = i.range !== void 0 ? i.range : 0;
|
|
574
|
-
switch (i.type) {
|
|
575
|
-
case "directional":
|
|
576
|
-
c = new ht(l), c.target.position.set(0, 0, -1), c.add(c.target);
|
|
577
|
-
break;
|
|
578
|
-
case "point":
|
|
579
|
-
c = new ft(l), c.distance = u;
|
|
580
|
-
break;
|
|
581
|
-
case "spot":
|
|
582
|
-
c = new dt(l), c.distance = u, i.spot = i.spot || {}, i.spot.innerConeAngle = i.spot.innerConeAngle !== void 0 ? i.spot.innerConeAngle : 0, i.spot.outerConeAngle = i.spot.outerConeAngle !== void 0 ? i.spot.outerConeAngle : Math.PI / 4, c.angle = i.spot.outerConeAngle, c.penumbra = 1 - i.spot.innerConeAngle / i.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: " + i.type);
|
|
586
|
-
}
|
|
587
|
-
return c.position.set(0, 0, 0), U(c, i), i.intensity !== void 0 && (c.intensity = i.intensity), c.name = t.createUniqueName(i.name || "light_" + e), n = Promise.resolve(c), t.cache.add(s, n), n;
|
|
588
|
-
}
|
|
589
|
-
getDependency(e, t) {
|
|
590
|
-
if (e === "light")
|
|
591
|
-
return this._loadLight(t);
|
|
592
|
-
}
|
|
593
|
-
createNodeAttachment(e) {
|
|
594
|
-
const t = this, s = this.parser, r = s.json.nodes[e], a = (r.extensions && r.extensions[this.name] || {}).light;
|
|
595
|
-
return a === void 0 ? null : this._loadLight(a).then(function(i) {
|
|
596
|
-
return s._getNodeRef(t.cache, a, i);
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
class an {
|
|
601
|
-
constructor() {
|
|
602
|
-
this.name = R.KHR_MATERIALS_UNLIT;
|
|
603
|
-
}
|
|
604
|
-
getMaterialType() {
|
|
605
|
-
return re;
|
|
606
|
-
}
|
|
607
|
-
extendParams(e, t, s) {
|
|
608
|
-
const n = [];
|
|
609
|
-
e.color = new B(1, 1, 1), e.opacity = 1;
|
|
610
|
-
const r = t.pbrMetallicRoughness;
|
|
611
|
-
if (r) {
|
|
612
|
-
if (Array.isArray(r.baseColorFactor)) {
|
|
613
|
-
const o = r.baseColorFactor;
|
|
614
|
-
e.color.setRGB(o[0], o[1], o[2], F), e.opacity = o[3];
|
|
615
|
-
}
|
|
616
|
-
r.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", r.baseColorTexture, V));
|
|
617
|
-
}
|
|
618
|
-
return Promise.all(n);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
class cn {
|
|
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 r = n.extensions[this.name].emissiveStrength;
|
|
630
|
-
return r !== void 0 && (t.emissiveIntensity = r), Promise.resolve();
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
class ln {
|
|
634
|
-
constructor(e) {
|
|
635
|
-
this.parser = e, this.name = R.KHR_MATERIALS_CLEARCOAT;
|
|
636
|
-
}
|
|
637
|
-
getMaterialType(e) {
|
|
638
|
-
const s = this.parser.json.materials[e];
|
|
639
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
640
|
-
}
|
|
641
|
-
extendMaterialParams(e, t) {
|
|
642
|
-
const s = this.parser, n = s.json.materials[e];
|
|
643
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
644
|
-
return Promise.resolve();
|
|
645
|
-
const r = [], o = n.extensions[this.name];
|
|
646
|
-
if (o.clearcoatFactor !== void 0 && (t.clearcoat = o.clearcoatFactor), o.clearcoatTexture !== void 0 && r.push(s.assignTexture(t, "clearcoatMap", o.clearcoatTexture)), o.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = o.clearcoatRoughnessFactor), o.clearcoatRoughnessTexture !== void 0 && r.push(s.assignTexture(t, "clearcoatRoughnessMap", o.clearcoatRoughnessTexture)), o.clearcoatNormalTexture !== void 0 && (r.push(s.assignTexture(t, "clearcoatNormalMap", o.clearcoatNormalTexture)), o.clearcoatNormalTexture.scale !== void 0)) {
|
|
647
|
-
const a = o.clearcoatNormalTexture.scale;
|
|
648
|
-
t.clearcoatNormalScale = new Se(a, a);
|
|
649
|
-
}
|
|
650
|
-
return Promise.all(r);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
class un {
|
|
654
|
-
constructor(e) {
|
|
655
|
-
this.parser = e, this.name = R.KHR_MATERIALS_DISPERSION;
|
|
656
|
-
}
|
|
657
|
-
getMaterialType(e) {
|
|
658
|
-
const s = this.parser.json.materials[e];
|
|
659
|
-
return !s.extensions || !s.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 r = n.extensions[this.name];
|
|
666
|
-
return t.dispersion = r.dispersion !== void 0 ? r.dispersion : 0, Promise.resolve();
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
class dn {
|
|
670
|
-
constructor(e) {
|
|
671
|
-
this.parser = e, this.name = R.KHR_MATERIALS_IRIDESCENCE;
|
|
672
|
-
}
|
|
673
|
-
getMaterialType(e) {
|
|
674
|
-
const s = this.parser.json.materials[e];
|
|
675
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
676
|
-
}
|
|
677
|
-
extendMaterialParams(e, t) {
|
|
678
|
-
const s = this.parser, n = s.json.materials[e];
|
|
679
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
680
|
-
return Promise.resolve();
|
|
681
|
-
const r = [], o = n.extensions[this.name];
|
|
682
|
-
return o.iridescenceFactor !== void 0 && (t.iridescence = o.iridescenceFactor), o.iridescenceTexture !== void 0 && r.push(s.assignTexture(t, "iridescenceMap", o.iridescenceTexture)), o.iridescenceIor !== void 0 && (t.iridescenceIOR = o.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), o.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = o.iridescenceThicknessMinimum), o.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = o.iridescenceThicknessMaximum), o.iridescenceThicknessTexture !== void 0 && r.push(s.assignTexture(t, "iridescenceThicknessMap", o.iridescenceThicknessTexture)), Promise.all(r);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
class fn {
|
|
686
|
-
constructor(e) {
|
|
687
|
-
this.parser = e, this.name = R.KHR_MATERIALS_SHEEN;
|
|
688
|
-
}
|
|
689
|
-
getMaterialType(e) {
|
|
690
|
-
const s = this.parser.json.materials[e];
|
|
691
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
692
|
-
}
|
|
693
|
-
extendMaterialParams(e, t) {
|
|
694
|
-
const s = this.parser, n = s.json.materials[e];
|
|
695
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
696
|
-
return Promise.resolve();
|
|
697
|
-
const r = [];
|
|
698
|
-
t.sheenColor = new B(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1;
|
|
699
|
-
const o = n.extensions[this.name];
|
|
700
|
-
if (o.sheenColorFactor !== void 0) {
|
|
701
|
-
const a = o.sheenColorFactor;
|
|
702
|
-
t.sheenColor.setRGB(a[0], a[1], a[2], F);
|
|
703
|
-
}
|
|
704
|
-
return o.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = o.sheenRoughnessFactor), o.sheenColorTexture !== void 0 && r.push(s.assignTexture(t, "sheenColorMap", o.sheenColorTexture, V)), o.sheenRoughnessTexture !== void 0 && r.push(s.assignTexture(t, "sheenRoughnessMap", o.sheenRoughnessTexture)), Promise.all(r);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
class hn {
|
|
708
|
-
constructor(e) {
|
|
709
|
-
this.parser = e, this.name = R.KHR_MATERIALS_TRANSMISSION;
|
|
710
|
-
}
|
|
711
|
-
getMaterialType(e) {
|
|
712
|
-
const s = this.parser.json.materials[e];
|
|
713
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
714
|
-
}
|
|
715
|
-
extendMaterialParams(e, t) {
|
|
716
|
-
const s = this.parser, n = s.json.materials[e];
|
|
717
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
718
|
-
return Promise.resolve();
|
|
719
|
-
const r = [], o = n.extensions[this.name];
|
|
720
|
-
return o.transmissionFactor !== void 0 && (t.transmission = o.transmissionFactor), o.transmissionTexture !== void 0 && r.push(s.assignTexture(t, "transmissionMap", o.transmissionTexture)), Promise.all(r);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
class pn {
|
|
724
|
-
constructor(e) {
|
|
725
|
-
this.parser = e, this.name = R.KHR_MATERIALS_VOLUME;
|
|
726
|
-
}
|
|
727
|
-
getMaterialType(e) {
|
|
728
|
-
const s = this.parser.json.materials[e];
|
|
729
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
730
|
-
}
|
|
731
|
-
extendMaterialParams(e, t) {
|
|
732
|
-
const s = this.parser, n = s.json.materials[e];
|
|
733
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
734
|
-
return Promise.resolve();
|
|
735
|
-
const r = [], o = n.extensions[this.name];
|
|
736
|
-
t.thickness = o.thicknessFactor !== void 0 ? o.thicknessFactor : 0, o.thicknessTexture !== void 0 && r.push(s.assignTexture(t, "thicknessMap", o.thicknessTexture)), t.attenuationDistance = o.attenuationDistance || 1 / 0;
|
|
737
|
-
const a = o.attenuationColor || [1, 1, 1];
|
|
738
|
-
return t.attenuationColor = new B().setRGB(a[0], a[1], a[2], F), Promise.all(r);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
class mn {
|
|
742
|
-
constructor(e) {
|
|
743
|
-
this.parser = e, this.name = R.KHR_MATERIALS_IOR;
|
|
744
|
-
}
|
|
745
|
-
getMaterialType(e) {
|
|
746
|
-
const s = this.parser.json.materials[e];
|
|
747
|
-
return !s.extensions || !s.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 r = n.extensions[this.name];
|
|
754
|
-
return t.ior = r.ior !== void 0 ? r.ior : 1.5, Promise.resolve();
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
class gn {
|
|
758
|
-
constructor(e) {
|
|
759
|
-
this.parser = e, this.name = R.KHR_MATERIALS_SPECULAR;
|
|
760
|
-
}
|
|
761
|
-
getMaterialType(e) {
|
|
762
|
-
const s = this.parser.json.materials[e];
|
|
763
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
764
|
-
}
|
|
765
|
-
extendMaterialParams(e, t) {
|
|
766
|
-
const s = this.parser, n = s.json.materials[e];
|
|
767
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
768
|
-
return Promise.resolve();
|
|
769
|
-
const r = [], o = n.extensions[this.name];
|
|
770
|
-
t.specularIntensity = o.specularFactor !== void 0 ? o.specularFactor : 1, o.specularTexture !== void 0 && r.push(s.assignTexture(t, "specularIntensityMap", o.specularTexture));
|
|
771
|
-
const a = o.specularColorFactor || [1, 1, 1];
|
|
772
|
-
return t.specularColor = new B().setRGB(a[0], a[1], a[2], F), o.specularColorTexture !== void 0 && r.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, V)), Promise.all(r);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
class Tn {
|
|
776
|
-
constructor(e) {
|
|
777
|
-
this.parser = e, this.name = R.EXT_MATERIALS_BUMP;
|
|
778
|
-
}
|
|
779
|
-
getMaterialType(e) {
|
|
780
|
-
const s = this.parser.json.materials[e];
|
|
781
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
782
|
-
}
|
|
783
|
-
extendMaterialParams(e, t) {
|
|
784
|
-
const s = this.parser, n = s.json.materials[e];
|
|
785
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
786
|
-
return Promise.resolve();
|
|
787
|
-
const r = [], o = n.extensions[this.name];
|
|
788
|
-
return t.bumpScale = o.bumpFactor !== void 0 ? o.bumpFactor : 1, o.bumpTexture !== void 0 && r.push(s.assignTexture(t, "bumpMap", o.bumpTexture)), Promise.all(r);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
class yn {
|
|
792
|
-
constructor(e) {
|
|
793
|
-
this.parser = e, this.name = R.KHR_MATERIALS_ANISOTROPY;
|
|
794
|
-
}
|
|
795
|
-
getMaterialType(e) {
|
|
796
|
-
const s = this.parser.json.materials[e];
|
|
797
|
-
return !s.extensions || !s.extensions[this.name] ? null : v;
|
|
798
|
-
}
|
|
799
|
-
extendMaterialParams(e, t) {
|
|
800
|
-
const s = this.parser, n = s.json.materials[e];
|
|
801
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
802
|
-
return Promise.resolve();
|
|
803
|
-
const r = [], o = n.extensions[this.name];
|
|
804
|
-
return o.anisotropyStrength !== void 0 && (t.anisotropy = o.anisotropyStrength), o.anisotropyRotation !== void 0 && (t.anisotropyRotation = o.anisotropyRotation), o.anisotropyTexture !== void 0 && r.push(s.assignTexture(t, "anisotropyMap", o.anisotropyTexture)), Promise.all(r);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
class xn {
|
|
808
|
-
constructor(e) {
|
|
809
|
-
this.parser = e, this.name = R.KHR_TEXTURE_BASISU;
|
|
810
|
-
}
|
|
811
|
-
loadTexture(e) {
|
|
812
|
-
const t = this.parser, s = t.json, n = s.textures[e];
|
|
813
|
-
if (!n.extensions || !n.extensions[this.name])
|
|
814
|
-
return null;
|
|
815
|
-
const r = n.extensions[this.name], o = t.options.ktx2Loader;
|
|
816
|
-
if (!o) {
|
|
817
|
-
if (s.extensionsRequired && s.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, r.source, o);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
class Rn {
|
|
825
|
-
constructor(e) {
|
|
826
|
-
this.parser = e, this.name = R.EXT_TEXTURE_WEBP;
|
|
827
|
-
}
|
|
828
|
-
loadTexture(e) {
|
|
829
|
-
const t = this.name, s = this.parser, n = s.json, r = n.textures[e];
|
|
830
|
-
if (!r.extensions || !r.extensions[t])
|
|
831
|
-
return null;
|
|
832
|
-
const o = r.extensions[t], a = n.images[o.source];
|
|
833
|
-
let i = s.textureLoader;
|
|
834
|
-
if (a.uri) {
|
|
835
|
-
const c = s.options.manager.getHandler(a.uri);
|
|
836
|
-
c !== null && (i = c);
|
|
837
|
-
}
|
|
838
|
-
return s.loadTextureImage(e, o.source, i);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
class bn {
|
|
842
|
-
constructor(e) {
|
|
843
|
-
this.parser = e, this.name = R.EXT_TEXTURE_AVIF;
|
|
844
|
-
}
|
|
845
|
-
loadTexture(e) {
|
|
846
|
-
const t = this.name, s = this.parser, n = s.json, r = n.textures[e];
|
|
847
|
-
if (!r.extensions || !r.extensions[t])
|
|
848
|
-
return null;
|
|
849
|
-
const o = r.extensions[t], a = n.images[o.source];
|
|
850
|
-
let i = s.textureLoader;
|
|
851
|
-
if (a.uri) {
|
|
852
|
-
const c = s.options.manager.getHandler(a.uri);
|
|
853
|
-
c !== null && (i = c);
|
|
854
|
-
}
|
|
855
|
-
return s.loadTextureImage(e, o.source, i);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
class An {
|
|
859
|
-
constructor(e) {
|
|
860
|
-
this.name = R.EXT_MESHOPT_COMPRESSION, this.parser = e;
|
|
861
|
-
}
|
|
862
|
-
loadBufferView(e) {
|
|
863
|
-
const t = this.parser.json, s = t.bufferViews[e];
|
|
864
|
-
if (s.extensions && s.extensions[this.name]) {
|
|
865
|
-
const n = s.extensions[this.name], r = this.parser.getDependency("buffer", n.buffer), o = this.parser.options.meshoptDecoder;
|
|
866
|
-
if (!o || !o.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 r.then(function(a) {
|
|
872
|
-
const i = n.byteOffset || 0, c = n.byteLength || 0, l = n.count, u = n.byteStride, d = new Uint8Array(a, i, c);
|
|
873
|
-
return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(l, u, d, n.mode, n.filter).then(function(h) {
|
|
874
|
-
return h.buffer;
|
|
875
|
-
}) : o.ready.then(function() {
|
|
876
|
-
const h = new ArrayBuffer(l * u);
|
|
877
|
-
return o.decodeGltfBuffer(new Uint8Array(h), l, u, d, n.mode, n.filter), h;
|
|
878
|
-
});
|
|
879
|
-
});
|
|
880
|
-
} else
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
class wn {
|
|
885
|
-
constructor(e) {
|
|
886
|
-
this.name = R.EXT_MESH_GPU_INSTANCING, this.parser = e;
|
|
887
|
-
}
|
|
888
|
-
createNodeMesh(e) {
|
|
889
|
-
const t = this.parser.json, s = t.nodes[e];
|
|
890
|
-
if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0)
|
|
891
|
-
return null;
|
|
892
|
-
const n = t.meshes[s.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 o = s.extensions[this.name].attributes, a = [], i = {};
|
|
897
|
-
for (const c in o)
|
|
898
|
-
a.push(this.parser.getDependency("accessor", o[c]).then((l) => (i[c] = l, i[c])));
|
|
899
|
-
return a.length < 1 ? null : (a.push(this.parser.createNodeMesh(e)), Promise.all(a).then((c) => {
|
|
900
|
-
const l = c.pop(), u = l.isGroup ? l.children : [l], d = c[0].count, h = [];
|
|
901
|
-
for (const p of u) {
|
|
902
|
-
const T = new ee(), m = new E(), g = new Ye(), b = new E(1, 1, 1), S = new pt(p.geometry, p.material, d);
|
|
903
|
-
for (let x = 0; x < d; x++)
|
|
904
|
-
i.TRANSLATION && m.fromBufferAttribute(i.TRANSLATION, x), i.ROTATION && g.fromBufferAttribute(i.ROTATION, x), i.SCALE && b.fromBufferAttribute(i.SCALE, x), S.setMatrixAt(x, T.compose(m, g, b));
|
|
905
|
-
for (const x in i)
|
|
906
|
-
if (x === "_COLOR_0") {
|
|
907
|
-
const I = i[x];
|
|
908
|
-
S.instanceColor = new mt(I.array, I.itemSize, I.normalized);
|
|
909
|
-
} else x !== "TRANSLATION" && x !== "ROTATION" && x !== "SCALE" && p.geometry.setAttribute(x, i[x]);
|
|
910
|
-
Je.prototype.copy.call(S, p), this.parser.assignFinalMaterial(S), h.push(S);
|
|
911
|
-
}
|
|
912
|
-
return l.isGroup ? (l.clear(), l.add(...h), l) : h[0];
|
|
913
|
-
}));
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
const st = "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), s = new TextDecoder();
|
|
921
|
-
if (this.header = {
|
|
922
|
-
magic: s.decode(new Uint8Array(e.slice(0, 4))),
|
|
923
|
-
version: t.getUint32(4, !0),
|
|
924
|
-
length: t.getUint32(8, !0)
|
|
925
|
-
}, this.header.magic !== st)
|
|
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, r = new DataView(e, se);
|
|
930
|
-
let o = 0;
|
|
931
|
-
for (; o < n; ) {
|
|
932
|
-
const a = r.getUint32(o, !0);
|
|
933
|
-
o += 4;
|
|
934
|
-
const i = r.getUint32(o, !0);
|
|
935
|
-
if (o += 4, i === Fe.JSON) {
|
|
936
|
-
const c = new Uint8Array(e, se + o, a);
|
|
937
|
-
this.content = s.decode(c);
|
|
938
|
-
} else if (i === Fe.BIN) {
|
|
939
|
-
const c = se + o;
|
|
940
|
-
this.body = e.slice(c, c + a);
|
|
941
|
-
}
|
|
942
|
-
o += a;
|
|
943
|
-
}
|
|
944
|
-
if (this.content === null)
|
|
945
|
-
throw new Error("THREE.GLTFLoader: JSON content not found.");
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
class _n {
|
|
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 s = this.json, n = this.dracoLoader, r = e.extensions[this.name].bufferView, o = e.extensions[this.name].attributes, a = {}, i = {}, c = {};
|
|
956
|
-
for (const l in o) {
|
|
957
|
-
const u = we[l] || l.toLowerCase();
|
|
958
|
-
a[u] = o[l];
|
|
959
|
-
}
|
|
960
|
-
for (const l in e.attributes) {
|
|
961
|
-
const u = we[l] || l.toLowerCase();
|
|
962
|
-
if (o[l] !== void 0) {
|
|
963
|
-
const d = s.accessors[e.attributes[l]], h = Z[d.componentType];
|
|
964
|
-
c[u] = h.name, i[u] = d.normalized === !0;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
return t.getDependency("bufferView", r).then(function(l) {
|
|
968
|
-
return new Promise(function(u, d) {
|
|
969
|
-
n.decodeDracoFile(l, function(h) {
|
|
970
|
-
for (const p in h.attributes) {
|
|
971
|
-
const T = h.attributes[p], m = i[p];
|
|
972
|
-
m !== void 0 && (T.normalized = m);
|
|
973
|
-
}
|
|
974
|
-
u(h);
|
|
975
|
-
}, a, c, F, d);
|
|
976
|
-
});
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
class Sn {
|
|
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 Ln {
|
|
989
|
-
constructor() {
|
|
990
|
-
this.name = R.KHR_MESH_QUANTIZATION;
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
class rt extends Gt {
|
|
994
|
-
constructor(e, t, s, n) {
|
|
995
|
-
super(e, t, s, n);
|
|
996
|
-
}
|
|
997
|
-
copySampleValue_(e) {
|
|
998
|
-
const t = this.resultBuffer, s = this.sampleValues, n = this.valueSize, r = e * n * 3 + n;
|
|
999
|
-
for (let o = 0; o !== n; o++)
|
|
1000
|
-
t[o] = s[r + o];
|
|
1001
|
-
return t;
|
|
1002
|
-
}
|
|
1003
|
-
interpolate_(e, t, s, n) {
|
|
1004
|
-
const r = this.resultBuffer, o = this.sampleValues, a = this.valueSize, i = a * 2, c = a * 3, l = n - t, u = (s - t) / l, d = u * u, h = d * u, p = e * c, T = p - c, m = -2 * h + 3 * d, g = h - d, b = 1 - m, S = g - d + u;
|
|
1005
|
-
for (let x = 0; x !== a; x++) {
|
|
1006
|
-
const I = o[T + x + a], k = o[T + x + i] * l, C = o[p + x + a], G = o[p + x] * l;
|
|
1007
|
-
r[x] = b * I + S * k + m * C + g * G;
|
|
1008
|
-
}
|
|
1009
|
-
return r;
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
const Mn = new Ye();
|
|
1013
|
-
class In extends rt {
|
|
1014
|
-
interpolate_(e, t, s, n) {
|
|
1015
|
-
const r = super.interpolate_(e, t, s, n);
|
|
1016
|
-
return Mn.fromArray(r).normalize().toArray(r), r;
|
|
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
|
-
}, Z = {
|
|
1028
|
-
5120: Int8Array,
|
|
1029
|
-
5121: Uint8Array,
|
|
1030
|
-
5122: Int16Array,
|
|
1031
|
-
5123: Uint16Array,
|
|
1032
|
-
5125: Uint32Array,
|
|
1033
|
-
5126: Float32Array
|
|
1034
|
-
}, ve = {
|
|
1035
|
-
9728: $e,
|
|
1036
|
-
9729: be,
|
|
1037
|
-
9984: At,
|
|
1038
|
-
9985: bt,
|
|
1039
|
-
9986: Rt,
|
|
1040
|
-
9987: Qe
|
|
1041
|
-
}, He = {
|
|
1042
|
-
33071: Et,
|
|
1043
|
-
33648: wt,
|
|
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
|
-
}, Cn = {
|
|
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: tt,
|
|
1074
|
-
STEP: Ut
|
|
1075
|
-
}, Te = {
|
|
1076
|
-
OPAQUE: "OPAQUE",
|
|
1077
|
-
MASK: "MASK",
|
|
1078
|
-
BLEND: "BLEND"
|
|
1079
|
-
};
|
|
1080
|
-
function Nn(f) {
|
|
1081
|
-
return f.DefaultMaterial === void 0 && (f.DefaultMaterial = new Ze({
|
|
1082
|
-
color: 16777215,
|
|
1083
|
-
emissive: 0,
|
|
1084
|
-
metalness: 1,
|
|
1085
|
-
roughness: 1,
|
|
1086
|
-
transparent: !1,
|
|
1087
|
-
depthTest: !0,
|
|
1088
|
-
side: Bt
|
|
1089
|
-
})), f.DefaultMaterial;
|
|
1090
|
-
}
|
|
1091
|
-
function q(f, e, t) {
|
|
1092
|
-
for (const s in t.extensions)
|
|
1093
|
-
f[s] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[s] = t.extensions[s]);
|
|
1094
|
-
}
|
|
1095
|
-
function U(f, e) {
|
|
1096
|
-
e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(f.userData, e.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + e.extras));
|
|
1097
|
-
}
|
|
1098
|
-
function On(f, e, t) {
|
|
1099
|
-
let s = !1, n = !1, r = !1;
|
|
1100
|
-
for (let c = 0, l = e.length; c < l; c++) {
|
|
1101
|
-
const u = e[c];
|
|
1102
|
-
if (u.POSITION !== void 0 && (s = !0), u.NORMAL !== void 0 && (n = !0), u.COLOR_0 !== void 0 && (r = !0), s && n && r) break;
|
|
1103
|
-
}
|
|
1104
|
-
if (!s && !n && !r) return Promise.resolve(f);
|
|
1105
|
-
const o = [], a = [], i = [];
|
|
1106
|
-
for (let c = 0, l = e.length; c < l; c++) {
|
|
1107
|
-
const u = e[c];
|
|
1108
|
-
if (s) {
|
|
1109
|
-
const d = u.POSITION !== void 0 ? t.getDependency("accessor", u.POSITION) : f.attributes.position;
|
|
1110
|
-
o.push(d);
|
|
1111
|
-
}
|
|
1112
|
-
if (n) {
|
|
1113
|
-
const d = u.NORMAL !== void 0 ? t.getDependency("accessor", u.NORMAL) : f.attributes.normal;
|
|
1114
|
-
a.push(d);
|
|
1115
|
-
}
|
|
1116
|
-
if (r) {
|
|
1117
|
-
const d = u.COLOR_0 !== void 0 ? t.getDependency("accessor", u.COLOR_0) : f.attributes.color;
|
|
1118
|
-
i.push(d);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
return Promise.all([
|
|
1122
|
-
Promise.all(o),
|
|
1123
|
-
Promise.all(a),
|
|
1124
|
-
Promise.all(i)
|
|
1125
|
-
]).then(function(c) {
|
|
1126
|
-
const l = c[0], u = c[1], d = c[2];
|
|
1127
|
-
return s && (f.morphAttributes.position = l), n && (f.morphAttributes.normal = u), r && (f.morphAttributes.color = d), f.morphTargetsRelative = !0, f;
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
function Pn(f, e) {
|
|
1131
|
-
if (f.updateMorphTargets(), e.weights !== void 0)
|
|
1132
|
-
for (let t = 0, s = e.weights.length; t < s; t++)
|
|
1133
|
-
f.morphTargetInfluences[t] = e.weights[t];
|
|
1134
|
-
if (e.extras && Array.isArray(e.extras.targetNames)) {
|
|
1135
|
-
const t = e.extras.targetNames;
|
|
1136
|
-
if (f.morphTargetInfluences.length === t.length) {
|
|
1137
|
-
f.morphTargetDictionary = {};
|
|
1138
|
-
for (let s = 0, n = t.length; s < n; s++)
|
|
1139
|
-
f.morphTargetDictionary[t[s]] = s;
|
|
1140
|
-
} else
|
|
1141
|
-
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
function kn(f) {
|
|
1145
|
-
let e;
|
|
1146
|
-
const t = f.extensions && f.extensions[R.KHR_DRACO_MESH_COMPRESSION];
|
|
1147
|
-
if (t ? e = "draco:" + t.bufferView + ":" + t.indices + ":" + ye(t.attributes) : e = f.indices + ":" + ye(f.attributes) + ":" + f.mode, f.targets !== void 0)
|
|
1148
|
-
for (let s = 0, n = f.targets.length; s < n; s++)
|
|
1149
|
-
e += ":" + ye(f.targets[s]);
|
|
1150
|
-
return e;
|
|
1151
|
-
}
|
|
1152
|
-
function ye(f) {
|
|
1153
|
-
let e = "";
|
|
1154
|
-
const t = Object.keys(f).sort();
|
|
1155
|
-
for (let s = 0, n = t.length; s < n; s++)
|
|
1156
|
-
e += t[s] + ":" + f[t[s]] + ";";
|
|
1157
|
-
return e;
|
|
1158
|
-
}
|
|
1159
|
-
function Ee(f) {
|
|
1160
|
-
switch (f) {
|
|
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 Dn(f) {
|
|
1174
|
-
return f.search(/\.jpe?g($|\?)/i) > 0 || f.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : f.search(/\.webp($|\?)/i) > 0 || f.search(/^data\:image\/webp/) === 0 ? "image/webp" : f.search(/\.ktx2($|\?)/i) > 0 || f.search(/^data\:image\/ktx2/) === 0 ? "image/ktx2" : "image/png";
|
|
1175
|
-
}
|
|
1176
|
-
const Fn = new ee();
|
|
1177
|
-
class vn {
|
|
1178
|
-
constructor(e = {}, t = {}) {
|
|
1179
|
-
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new rn(), 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 s = !1, n = -1, r = !1, o = -1;
|
|
1181
|
-
if (typeof navigator < "u") {
|
|
1182
|
-
const a = navigator.userAgent;
|
|
1183
|
-
s = /^((?!chrome|android).)*safari/i.test(a) === !0;
|
|
1184
|
-
const i = a.match(/Version\/(\d+)/);
|
|
1185
|
-
n = s && i ? parseInt(i[1], 10) : -1, r = a.indexOf("Firefox") > -1, o = r ? a.match(/Firefox\/([0-9]+)\./)[1] : -1;
|
|
1186
|
-
}
|
|
1187
|
-
typeof createImageBitmap > "u" || s && n < 17 || r && o < 98 ? this.textureLoader = new gt(this.options.manager) : this.textureLoader = new Tt(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 s = this, n = this.json, r = this.extensions;
|
|
1197
|
-
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(o) {
|
|
1198
|
-
return o._markDefs && o._markDefs();
|
|
1199
|
-
}), Promise.all(this._invokeAll(function(o) {
|
|
1200
|
-
return o.beforeRoot && o.beforeRoot();
|
|
1201
|
-
})).then(function() {
|
|
1202
|
-
return Promise.all([
|
|
1203
|
-
s.getDependencies("scene"),
|
|
1204
|
-
s.getDependencies("animation"),
|
|
1205
|
-
s.getDependencies("camera")
|
|
1206
|
-
]);
|
|
1207
|
-
}).then(function(o) {
|
|
1208
|
-
const a = {
|
|
1209
|
-
scene: o[0][n.scene || 0],
|
|
1210
|
-
scenes: o[0],
|
|
1211
|
-
animations: o[1],
|
|
1212
|
-
cameras: o[2],
|
|
1213
|
-
asset: n.asset,
|
|
1214
|
-
parser: s,
|
|
1215
|
-
userData: {}
|
|
1216
|
-
};
|
|
1217
|
-
return q(r, a, n), U(a, n), Promise.all(s._invokeAll(function(i) {
|
|
1218
|
-
return i.afterRoot && i.afterRoot(a);
|
|
1219
|
-
})).then(function() {
|
|
1220
|
-
for (const i of a.scenes)
|
|
1221
|
-
i.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 || [], s = this.json.meshes || [];
|
|
1233
|
-
for (let n = 0, r = t.length; n < r; n++) {
|
|
1234
|
-
const o = t[n].joints;
|
|
1235
|
-
for (let a = 0, i = o.length; a < i; a++)
|
|
1236
|
-
e[o[a]].isBone = !0;
|
|
1237
|
-
}
|
|
1238
|
-
for (let n = 0, r = e.length; n < r; n++) {
|
|
1239
|
-
const o = e[n];
|
|
1240
|
-
o.mesh !== void 0 && (this._addNodeRef(this.meshCache, o.mesh), o.skin !== void 0 && (s[o.mesh].isSkinnedMesh = !0)), o.camera !== void 0 && this._addNodeRef(this.cameraCache, o.camera);
|
|
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, s) {
|
|
1269
|
-
if (e.refs[t] <= 1) return s;
|
|
1270
|
-
const n = s.clone(), r = (o, a) => {
|
|
1271
|
-
const i = this.associations.get(o);
|
|
1272
|
-
i != null && this.associations.set(a, i);
|
|
1273
|
-
for (const [c, l] of o.children.entries())
|
|
1274
|
-
r(l, a.children[c]);
|
|
1275
|
-
};
|
|
1276
|
-
return r(s, 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 s = 0; s < t.length; s++) {
|
|
1282
|
-
const n = e(t[s]);
|
|
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 s = [];
|
|
1291
|
-
for (let n = 0; n < t.length; n++) {
|
|
1292
|
-
const r = e(t[n]);
|
|
1293
|
-
r && s.push(r);
|
|
1294
|
-
}
|
|
1295
|
-
return s;
|
|
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 s = e + ":" + t;
|
|
1307
|
-
let n = this.cache.get(s);
|
|
1308
|
-
if (!n) {
|
|
1309
|
-
switch (e) {
|
|
1310
|
-
case "scene":
|
|
1311
|
-
n = this.loadScene(t);
|
|
1312
|
-
break;
|
|
1313
|
-
case "node":
|
|
1314
|
-
n = this._invokeOne(function(r) {
|
|
1315
|
-
return r.loadNode && r.loadNode(t);
|
|
1316
|
-
});
|
|
1317
|
-
break;
|
|
1318
|
-
case "mesh":
|
|
1319
|
-
n = this._invokeOne(function(r) {
|
|
1320
|
-
return r.loadMesh && r.loadMesh(t);
|
|
1321
|
-
});
|
|
1322
|
-
break;
|
|
1323
|
-
case "accessor":
|
|
1324
|
-
n = this.loadAccessor(t);
|
|
1325
|
-
break;
|
|
1326
|
-
case "bufferView":
|
|
1327
|
-
n = this._invokeOne(function(r) {
|
|
1328
|
-
return r.loadBufferView && r.loadBufferView(t);
|
|
1329
|
-
});
|
|
1330
|
-
break;
|
|
1331
|
-
case "buffer":
|
|
1332
|
-
n = this.loadBuffer(t);
|
|
1333
|
-
break;
|
|
1334
|
-
case "material":
|
|
1335
|
-
n = this._invokeOne(function(r) {
|
|
1336
|
-
return r.loadMaterial && r.loadMaterial(t);
|
|
1337
|
-
});
|
|
1338
|
-
break;
|
|
1339
|
-
case "texture":
|
|
1340
|
-
n = this._invokeOne(function(r) {
|
|
1341
|
-
return r.loadTexture && r.loadTexture(t);
|
|
1342
|
-
});
|
|
1343
|
-
break;
|
|
1344
|
-
case "skin":
|
|
1345
|
-
n = this.loadSkin(t);
|
|
1346
|
-
break;
|
|
1347
|
-
case "animation":
|
|
1348
|
-
n = this._invokeOne(function(r) {
|
|
1349
|
-
return r.loadAnimation && r.loadAnimation(t);
|
|
1350
|
-
});
|
|
1351
|
-
break;
|
|
1352
|
-
case "camera":
|
|
1353
|
-
n = this.loadCamera(t);
|
|
1354
|
-
break;
|
|
1355
|
-
default:
|
|
1356
|
-
if (n = this._invokeOne(function(r) {
|
|
1357
|
-
return r != this && r.getDependency && r.getDependency(e, t);
|
|
1358
|
-
}), !n)
|
|
1359
|
-
throw new Error("Unknown type: " + e);
|
|
1360
|
-
break;
|
|
1361
|
-
}
|
|
1362
|
-
this.cache.add(s, 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 s = this, n = this.json[e + (e === "mesh" ? "es" : "s")] || [];
|
|
1377
|
-
t = Promise.all(n.map(function(r, o) {
|
|
1378
|
-
return s.getDependency(e, o);
|
|
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], s = 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(r, o) {
|
|
1398
|
-
s.load(ie.resolveURL(t.uri, n.path), r, void 0, function() {
|
|
1399
|
-
o(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(s) {
|
|
1413
|
-
const n = t.byteLength || 0, r = t.byteOffset || 0;
|
|
1414
|
-
return s.slice(r, r + 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, s = this.json, n = this.json.accessors[e];
|
|
1426
|
-
if (n.bufferView === void 0 && n.sparse === void 0) {
|
|
1427
|
-
const o = ge[n.type], a = Z[n.componentType], i = n.normalized === !0, c = new a(n.count * o);
|
|
1428
|
-
return Promise.resolve(new oe(c, o, i));
|
|
1429
|
-
}
|
|
1430
|
-
const r = [];
|
|
1431
|
-
return n.bufferView !== void 0 ? r.push(this.getDependency("bufferView", n.bufferView)) : r.push(null), n.sparse !== void 0 && (r.push(this.getDependency("bufferView", n.sparse.indices.bufferView)), r.push(this.getDependency("bufferView", n.sparse.values.bufferView))), Promise.all(r).then(function(o) {
|
|
1432
|
-
const a = o[0], i = ge[n.type], c = Z[n.componentType], l = c.BYTES_PER_ELEMENT, u = l * i, d = n.byteOffset || 0, h = n.bufferView !== void 0 ? s.bufferViews[n.bufferView].byteStride : void 0, p = n.normalized === !0;
|
|
1433
|
-
let T, m;
|
|
1434
|
-
if (h && h !== u) {
|
|
1435
|
-
const g = Math.floor(d / h), b = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + g + ":" + n.count;
|
|
1436
|
-
let S = t.cache.get(b);
|
|
1437
|
-
S || (T = new c(a, g * h, n.count * h / l), S = new yt(T, h / l), t.cache.add(b, S)), m = new xt(S, i, d % h / l, p);
|
|
1438
|
-
} else
|
|
1439
|
-
a === null ? T = new c(n.count * i) : T = new c(a, d, n.count * i), m = new oe(T, i, p);
|
|
1440
|
-
if (n.sparse !== void 0) {
|
|
1441
|
-
const g = ge.SCALAR, b = Z[n.sparse.indices.componentType], S = n.sparse.indices.byteOffset || 0, x = n.sparse.values.byteOffset || 0, I = new b(o[1], S, n.sparse.count * g), k = new c(o[2], x, n.sparse.count * i);
|
|
1442
|
-
a !== null && (m = new oe(m.array.slice(), m.itemSize, m.normalized)), m.normalized = !1;
|
|
1443
|
-
for (let C = 0, G = I.length; C < G; C++) {
|
|
1444
|
-
const D = I[C];
|
|
1445
|
-
if (m.setX(D, k[C * i]), i >= 2 && m.setY(D, k[C * i + 1]), i >= 3 && m.setZ(D, k[C * i + 2]), i >= 4 && m.setW(D, k[C * i + 3]), i >= 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, s = this.options, r = t.textures[e].source, o = t.images[r];
|
|
1461
|
-
let a = this.textureLoader;
|
|
1462
|
-
if (o.uri) {
|
|
1463
|
-
const i = s.manager.getHandler(o.uri);
|
|
1464
|
-
i !== null && (a = i);
|
|
1465
|
-
}
|
|
1466
|
-
return this.loadTextureImage(e, r, a);
|
|
1467
|
-
}
|
|
1468
|
-
loadTextureImage(e, t, s) {
|
|
1469
|
-
const n = this, r = this.json, o = r.textures[e], a = r.images[t], i = (a.uri || a.bufferView) + ":" + o.sampler;
|
|
1470
|
-
if (this.textureCache[i])
|
|
1471
|
-
return this.textureCache[i];
|
|
1472
|
-
const c = this.loadImageSource(t, s).then(function(l) {
|
|
1473
|
-
l.flipY = !1, l.name = o.name || a.name || "", l.name === "" && typeof a.uri == "string" && a.uri.startsWith("data:image/") === !1 && (l.name = a.uri);
|
|
1474
|
-
const d = (r.samplers || {})[o.sampler] || {};
|
|
1475
|
-
return l.magFilter = ve[d.magFilter] || be, l.minFilter = ve[d.minFilter] || Qe, l.wrapS = He[d.wrapS] || Ae, l.wrapT = He[d.wrapT] || Ae, l.generateMipmaps = !l.isCompressedTexture && l.minFilter !== $e && l.minFilter !== be, n.associations.set(l, { textures: e }), l;
|
|
1476
|
-
}).catch(function() {
|
|
1477
|
-
return null;
|
|
1478
|
-
});
|
|
1479
|
-
return this.textureCache[i] = c, c;
|
|
1480
|
-
}
|
|
1481
|
-
loadImageSource(e, t) {
|
|
1482
|
-
const s = this, n = this.json, r = this.options;
|
|
1483
|
-
if (this.sourceCache[e] !== void 0)
|
|
1484
|
-
return this.sourceCache[e].then((u) => u.clone());
|
|
1485
|
-
const o = n.images[e], a = self.URL || self.webkitURL;
|
|
1486
|
-
let i = o.uri || "", c = !1;
|
|
1487
|
-
if (o.bufferView !== void 0)
|
|
1488
|
-
i = s.getDependency("bufferView", o.bufferView).then(function(u) {
|
|
1489
|
-
c = !0;
|
|
1490
|
-
const d = new Blob([u], { type: o.mimeType });
|
|
1491
|
-
return i = a.createObjectURL(d), i;
|
|
1492
|
-
});
|
|
1493
|
-
else if (o.uri === void 0)
|
|
1494
|
-
throw new Error("THREE.GLTFLoader: Image " + e + " is missing URI and bufferView");
|
|
1495
|
-
const l = Promise.resolve(i).then(function(u) {
|
|
1496
|
-
return new Promise(function(d, h) {
|
|
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(ie.resolveURL(u, r.path), p, void 0, h);
|
|
1502
|
-
});
|
|
1503
|
-
}).then(function(u) {
|
|
1504
|
-
return c === !0 && a.revokeObjectURL(i), U(u, o), u.userData.mimeType = o.mimeType || Dn(o.uri), u;
|
|
1505
|
-
}).catch(function(u) {
|
|
1506
|
-
throw console.error("THREE.GLTFLoader: Couldn't load texture", i), u;
|
|
1507
|
-
});
|
|
1508
|
-
return this.sourceCache[e] = l, l;
|
|
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, s, n) {
|
|
1521
|
-
const r = this;
|
|
1522
|
-
return this.getDependency("texture", s.index).then(function(o) {
|
|
1523
|
-
if (!o) return null;
|
|
1524
|
-
if (s.texCoord !== void 0 && s.texCoord > 0 && (o = o.clone(), o.channel = s.texCoord), r.extensions[R.KHR_TEXTURE_TRANSFORM]) {
|
|
1525
|
-
const a = s.extensions !== void 0 ? s.extensions[R.KHR_TEXTURE_TRANSFORM] : void 0;
|
|
1526
|
-
if (a) {
|
|
1527
|
-
const i = r.associations.get(o);
|
|
1528
|
-
o = r.extensions[R.KHR_TEXTURE_TRANSFORM].extendTexture(o, a), r.associations.set(o, i);
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
return n !== void 0 && (o.colorSpace = n), e[t] = o, o;
|
|
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 s = e.material;
|
|
1547
|
-
const n = t.attributes.tangent === void 0, r = t.attributes.color !== void 0, o = t.attributes.normal === void 0;
|
|
1548
|
-
if (e.isPoints) {
|
|
1549
|
-
const a = "PointsMaterial:" + s.uuid;
|
|
1550
|
-
let i = this.cache.get(a);
|
|
1551
|
-
i || (i = new _t(), fe.prototype.copy.call(i, s), i.color.copy(s.color), i.map = s.map, i.sizeAttenuation = !1, this.cache.add(a, i)), s = i;
|
|
1552
|
-
} else if (e.isLine) {
|
|
1553
|
-
const a = "LineBasicMaterial:" + s.uuid;
|
|
1554
|
-
let i = this.cache.get(a);
|
|
1555
|
-
i || (i = new St(), fe.prototype.copy.call(i, s), i.color.copy(s.color), i.map = s.map, this.cache.add(a, i)), s = i;
|
|
1556
|
-
}
|
|
1557
|
-
if (n || r || o) {
|
|
1558
|
-
let a = "ClonedMaterial:" + s.uuid + ":";
|
|
1559
|
-
n && (a += "derivative-tangents:"), r && (a += "vertex-colors:"), o && (a += "flat-shading:");
|
|
1560
|
-
let i = this.cache.get(a);
|
|
1561
|
-
i || (i = s.clone(), r && (i.vertexColors = !0), o && (i.flatShading = !0), n && (i.normalScale && (i.normalScale.y *= -1), i.clearcoatNormalScale && (i.clearcoatNormalScale.y *= -1)), this.cache.add(a, i), this.associations.set(i, this.associations.get(s))), s = i;
|
|
1562
|
-
}
|
|
1563
|
-
e.material = s;
|
|
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, s = this.json, n = this.extensions, r = s.materials[e];
|
|
1577
|
-
let o;
|
|
1578
|
-
const a = {}, i = r.extensions || {}, c = [];
|
|
1579
|
-
if (i[R.KHR_MATERIALS_UNLIT]) {
|
|
1580
|
-
const u = n[R.KHR_MATERIALS_UNLIT];
|
|
1581
|
-
o = u.getMaterialType(), c.push(u.extendParams(a, r, t));
|
|
1582
|
-
} else {
|
|
1583
|
-
const u = r.pbrMetallicRoughness || {};
|
|
1584
|
-
if (a.color = new B(1, 1, 1), a.opacity = 1, Array.isArray(u.baseColorFactor)) {
|
|
1585
|
-
const d = u.baseColorFactor;
|
|
1586
|
-
a.color.setRGB(d[0], d[1], d[2], F), a.opacity = d[3];
|
|
1587
|
-
}
|
|
1588
|
-
u.baseColorTexture !== void 0 && c.push(t.assignTexture(a, "map", u.baseColorTexture, V)), a.metalness = u.metallicFactor !== void 0 ? u.metallicFactor : 1, a.roughness = u.roughnessFactor !== void 0 ? u.roughnessFactor : 1, u.metallicRoughnessTexture !== void 0 && (c.push(t.assignTexture(a, "metalnessMap", u.metallicRoughnessTexture)), c.push(t.assignTexture(a, "roughnessMap", u.metallicRoughnessTexture))), o = 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
|
-
r.doubleSided === !0 && (a.side = Lt);
|
|
1595
|
-
const l = r.alphaMode || Te.OPAQUE;
|
|
1596
|
-
if (l === Te.BLEND ? (a.transparent = !0, a.depthWrite = !1) : (a.transparent = !1, l === Te.MASK && (a.alphaTest = r.alphaCutoff !== void 0 ? r.alphaCutoff : 0.5)), r.normalTexture !== void 0 && o !== re && (c.push(t.assignTexture(a, "normalMap", r.normalTexture)), a.normalScale = new Se(1, 1), r.normalTexture.scale !== void 0)) {
|
|
1597
|
-
const u = r.normalTexture.scale;
|
|
1598
|
-
a.normalScale.set(u, u);
|
|
1599
|
-
}
|
|
1600
|
-
if (r.occlusionTexture !== void 0 && o !== re && (c.push(t.assignTexture(a, "aoMap", r.occlusionTexture)), r.occlusionTexture.strength !== void 0 && (a.aoMapIntensity = r.occlusionTexture.strength)), r.emissiveFactor !== void 0 && o !== re) {
|
|
1601
|
-
const u = r.emissiveFactor;
|
|
1602
|
-
a.emissive = new B().setRGB(u[0], u[1], u[2], F);
|
|
1603
|
-
}
|
|
1604
|
-
return r.emissiveTexture !== void 0 && o !== re && c.push(t.assignTexture(a, "emissiveMap", r.emissiveTexture, V)), Promise.all(c).then(function() {
|
|
1605
|
-
const u = new o(a);
|
|
1606
|
-
return r.name && (u.name = r.name), U(u, r), t.associations.set(u, { materials: e }), r.extensions && q(n, u, r), u;
|
|
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 = Mt.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, s = this.extensions, n = this.primitiveCache;
|
|
1631
|
-
function r(a) {
|
|
1632
|
-
return s[R.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a, t).then(function(i) {
|
|
1633
|
-
return Ue(i, a, t);
|
|
1634
|
-
});
|
|
1635
|
-
}
|
|
1636
|
-
const o = [];
|
|
1637
|
-
for (let a = 0, i = e.length; a < i; a++) {
|
|
1638
|
-
const c = e[a], l = kn(c), u = n[l];
|
|
1639
|
-
if (u)
|
|
1640
|
-
o.push(u.promise);
|
|
1641
|
-
else {
|
|
1642
|
-
let d;
|
|
1643
|
-
c.extensions && c.extensions[R.KHR_DRACO_MESH_COMPRESSION] ? d = r(c) : d = Ue(new We(), c, t), n[l] = { primitive: c, promise: d }, o.push(d);
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
return Promise.all(o);
|
|
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, s = this.json, n = this.extensions, r = s.meshes[e], o = r.primitives, a = [];
|
|
1657
|
-
for (let i = 0, c = o.length; i < c; i++) {
|
|
1658
|
-
const l = o[i].material === void 0 ? Nn(this.cache) : this.getDependency("material", o[i].material);
|
|
1659
|
-
a.push(l);
|
|
1660
|
-
}
|
|
1661
|
-
return a.push(t.loadGeometries(o)), Promise.all(a).then(function(i) {
|
|
1662
|
-
const c = i.slice(0, i.length - 1), l = i[i.length - 1], u = [];
|
|
1663
|
-
for (let h = 0, p = l.length; h < p; h++) {
|
|
1664
|
-
const T = l[h], m = o[h];
|
|
1665
|
-
let g;
|
|
1666
|
-
const b = c[h];
|
|
1667
|
-
if (m.mode === O.TRIANGLES || m.mode === O.TRIANGLE_STRIP || m.mode === O.TRIANGLE_FAN || m.mode === void 0)
|
|
1668
|
-
g = r.isSkinnedMesh === !0 ? new It(T, b) : new Ct(T, b), g.isSkinnedMesh === !0 && g.normalizeSkinWeights(), m.mode === O.TRIANGLE_STRIP ? g.geometry = De(g.geometry, Xe) : m.mode === O.TRIANGLE_FAN && (g.geometry = De(g.geometry, xe));
|
|
1669
|
-
else if (m.mode === O.LINES)
|
|
1670
|
-
g = new Nt(T, b);
|
|
1671
|
-
else if (m.mode === O.LINE_STRIP)
|
|
1672
|
-
g = new Ot(T, b);
|
|
1673
|
-
else if (m.mode === O.LINE_LOOP)
|
|
1674
|
-
g = new Pt(T, b);
|
|
1675
|
-
else if (m.mode === O.POINTS)
|
|
1676
|
-
g = new kt(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, r), g.name = t.createUniqueName(r.name || "mesh_" + e), U(g, r), m.extensions && q(n, g, m), t.assignFinalMaterial(g), u.push(g);
|
|
1680
|
-
}
|
|
1681
|
-
for (let h = 0, p = u.length; h < p; h++)
|
|
1682
|
-
t.associations.set(u[h], {
|
|
1683
|
-
meshes: e,
|
|
1684
|
-
primitives: h
|
|
1685
|
-
});
|
|
1686
|
-
if (u.length === 1)
|
|
1687
|
-
return r.extensions && q(n, u[0], r), u[0];
|
|
1688
|
-
const d = new he();
|
|
1689
|
-
r.extensions && q(n, d, r), t.associations.set(d, { meshes: e });
|
|
1690
|
-
for (let h = 0, p = u.length; h < p; h++)
|
|
1691
|
-
d.add(u[h]);
|
|
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 s = this.json.cameras[e], n = s[s.type];
|
|
1705
|
-
if (!n) {
|
|
1706
|
-
console.warn("THREE.GLTFLoader: Missing camera parameters.");
|
|
1707
|
-
return;
|
|
1708
|
-
}
|
|
1709
|
-
return s.type === "perspective" ? t = new et($.radToDeg(n.yfov), n.aspectRatio || 1, n.znear || 1, n.zfar || 2e6) : s.type === "orthographic" && (t = new Dt(-n.xmag, n.xmag, n.ymag, -n.ymag, n.znear, n.zfar)), s.name && (t.name = this.createUniqueName(s.name)), U(t, s), 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], s = [];
|
|
1720
|
-
for (let n = 0, r = t.joints.length; n < r; n++)
|
|
1721
|
-
s.push(this._loadNodeShallow(t.joints[n]));
|
|
1722
|
-
return t.inverseBindMatrices !== void 0 ? s.push(this.getDependency("accessor", t.inverseBindMatrices)) : s.push(null), Promise.all(s).then(function(n) {
|
|
1723
|
-
const r = n.pop(), o = n, a = [], i = [];
|
|
1724
|
-
for (let c = 0, l = o.length; c < l; c++) {
|
|
1725
|
-
const u = o[c];
|
|
1726
|
-
if (u) {
|
|
1727
|
-
a.push(u);
|
|
1728
|
-
const d = new ee();
|
|
1729
|
-
r !== null && d.fromArray(r.array, c * 16), i.push(d);
|
|
1730
|
-
} else
|
|
1731
|
-
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', t.joints[c]);
|
|
1732
|
-
}
|
|
1733
|
-
return new Ft(a, i);
|
|
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, s = this, n = t.animations[e], r = n.name ? n.name : "animation_" + e, o = [], a = [], i = [], c = [], l = [];
|
|
1745
|
-
for (let u = 0, d = n.channels.length; u < d; u++) {
|
|
1746
|
-
const h = n.channels[u], p = n.samplers[h.sampler], T = h.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 && (o.push(this.getDependency("node", m)), a.push(this.getDependency("accessor", g)), i.push(this.getDependency("accessor", b)), c.push(p), l.push(T));
|
|
1748
|
-
}
|
|
1749
|
-
return Promise.all([
|
|
1750
|
-
Promise.all(o),
|
|
1751
|
-
Promise.all(a),
|
|
1752
|
-
Promise.all(i),
|
|
1753
|
-
Promise.all(c),
|
|
1754
|
-
Promise.all(l)
|
|
1755
|
-
]).then(function(u) {
|
|
1756
|
-
const d = u[0], h = u[1], p = u[2], T = u[3], m = u[4], g = [];
|
|
1757
|
-
for (let b = 0, S = d.length; b < S; b++) {
|
|
1758
|
-
const x = d[b], I = h[b], k = p[b], C = T[b], G = m[b];
|
|
1759
|
-
if (x === void 0) continue;
|
|
1760
|
-
x.updateMatrix && x.updateMatrix();
|
|
1761
|
-
const D = s._createAnimationTracks(x, I, k, C, G);
|
|
1762
|
-
if (D)
|
|
1763
|
-
for (let te = 0; te < D.length; te++)
|
|
1764
|
-
g.push(D[te]);
|
|
1765
|
-
}
|
|
1766
|
-
return new vt(r, void 0, g);
|
|
1767
|
-
});
|
|
1768
|
-
}
|
|
1769
|
-
createNodeMesh(e) {
|
|
1770
|
-
const t = this.json, s = this, n = t.nodes[e];
|
|
1771
|
-
return n.mesh === void 0 ? null : s.getDependency("mesh", n.mesh).then(function(r) {
|
|
1772
|
-
const o = s._getNodeRef(s.meshCache, n.mesh, r);
|
|
1773
|
-
return n.weights !== void 0 && o.traverse(function(a) {
|
|
1774
|
-
if (a.isMesh)
|
|
1775
|
-
for (let i = 0, c = n.weights.length; i < c; i++)
|
|
1776
|
-
a.morphTargetInfluences[i] = n.weights[i];
|
|
1777
|
-
}), o;
|
|
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, s = this, n = t.nodes[e], r = s._loadNodeShallow(e), o = [], a = n.children || [];
|
|
1789
|
-
for (let c = 0, l = a.length; c < l; c++)
|
|
1790
|
-
o.push(s.getDependency("node", a[c]));
|
|
1791
|
-
const i = n.skin === void 0 ? Promise.resolve(null) : s.getDependency("skin", n.skin);
|
|
1792
|
-
return Promise.all([
|
|
1793
|
-
r,
|
|
1794
|
-
Promise.all(o),
|
|
1795
|
-
i
|
|
1796
|
-
]).then(function(c) {
|
|
1797
|
-
const l = c[0], u = c[1], d = c[2];
|
|
1798
|
-
d !== null && l.traverse(function(h) {
|
|
1799
|
-
h.isSkinnedMesh && h.bind(d, Fn);
|
|
1800
|
-
});
|
|
1801
|
-
for (let h = 0, p = u.length; h < p; h++)
|
|
1802
|
-
l.add(u[h]);
|
|
1803
|
-
return l;
|
|
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, s = this.extensions, n = this;
|
|
1810
|
-
if (this.nodeCache[e] !== void 0)
|
|
1811
|
-
return this.nodeCache[e];
|
|
1812
|
-
const r = t.nodes[e], o = r.name ? n.createUniqueName(r.name) : "", a = [], i = n._invokeOne(function(c) {
|
|
1813
|
-
return c.createNodeMesh && c.createNodeMesh(e);
|
|
1814
|
-
});
|
|
1815
|
-
return i && a.push(i), r.camera !== void 0 && a.push(n.getDependency("camera", r.camera).then(function(c) {
|
|
1816
|
-
return n._getNodeRef(n.cameraCache, r.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 l;
|
|
1823
|
-
if (r.isBone === !0 ? l = new Ht() : c.length > 1 ? l = new he() : c.length === 1 ? l = c[0] : l = new Je(), l !== c[0])
|
|
1824
|
-
for (let u = 0, d = c.length; u < d; u++)
|
|
1825
|
-
l.add(c[u]);
|
|
1826
|
-
if (r.name && (l.userData.name = r.name, l.name = o), U(l, r), r.extensions && q(s, l, r), r.matrix !== void 0) {
|
|
1827
|
-
const u = new ee();
|
|
1828
|
-
u.fromArray(r.matrix), l.applyMatrix4(u);
|
|
1829
|
-
} else
|
|
1830
|
-
r.translation !== void 0 && l.position.fromArray(r.translation), r.rotation !== void 0 && l.quaternion.fromArray(r.rotation), r.scale !== void 0 && l.scale.fromArray(r.scale);
|
|
1831
|
-
if (!n.associations.has(l))
|
|
1832
|
-
n.associations.set(l, {});
|
|
1833
|
-
else if (r.mesh !== void 0 && n.meshCache.refs[r.mesh] > 1) {
|
|
1834
|
-
const u = n.associations.get(l);
|
|
1835
|
-
n.associations.set(l, { ...u });
|
|
1836
|
-
}
|
|
1837
|
-
return n.associations.get(l).nodes = e, l;
|
|
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, s = this.json.scenes[e], n = this, r = new he();
|
|
1849
|
-
s.name && (r.name = n.createUniqueName(s.name)), U(r, s), s.extensions && q(t, r, s);
|
|
1850
|
-
const o = s.nodes || [], a = [];
|
|
1851
|
-
for (let i = 0, c = o.length; i < c; i++)
|
|
1852
|
-
a.push(n.getDependency("node", o[i]));
|
|
1853
|
-
return Promise.all(a).then(function(i) {
|
|
1854
|
-
for (let l = 0, u = i.length; l < u; l++)
|
|
1855
|
-
r.add(i[l]);
|
|
1856
|
-
const c = (l) => {
|
|
1857
|
-
const u = /* @__PURE__ */ new Map();
|
|
1858
|
-
for (const [d, h] of n.associations)
|
|
1859
|
-
(d instanceof fe || d instanceof Ce) && u.set(d, h);
|
|
1860
|
-
return l.traverse((d) => {
|
|
1861
|
-
const h = n.associations.get(d);
|
|
1862
|
-
h != null && u.set(d, h);
|
|
1863
|
-
}), u;
|
|
1864
|
-
};
|
|
1865
|
-
return n.associations = c(r), r;
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1868
|
-
_createAnimationTracks(e, t, s, n, r) {
|
|
1869
|
-
const o = [], a = e.name ? e.name : e.uuid, i = [];
|
|
1870
|
-
K[r.path] === K.weights ? e.traverse(function(d) {
|
|
1871
|
-
d.morphTargetInfluences && i.push(d.name ? d.name : d.uuid);
|
|
1872
|
-
}) : i.push(a);
|
|
1873
|
-
let c;
|
|
1874
|
-
switch (K[r.path]) {
|
|
1875
|
-
case K.weights:
|
|
1876
|
-
c = Oe;
|
|
1877
|
-
break;
|
|
1878
|
-
case K.rotation:
|
|
1879
|
-
c = Pe;
|
|
1880
|
-
break;
|
|
1881
|
-
case K.translation:
|
|
1882
|
-
case K.scale:
|
|
1883
|
-
c = Ne;
|
|
1884
|
-
break;
|
|
1885
|
-
default:
|
|
1886
|
-
switch (s.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 l = n.interpolation !== void 0 ? Cn[n.interpolation] : tt, u = this._getArrayFromAccessor(s);
|
|
1899
|
-
for (let d = 0, h = i.length; d < h; d++) {
|
|
1900
|
-
const p = new c(
|
|
1901
|
-
i[d] + "." + K[r.path],
|
|
1902
|
-
t.array,
|
|
1903
|
-
u,
|
|
1904
|
-
l
|
|
1905
|
-
);
|
|
1906
|
-
n.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(p), o.push(p);
|
|
1907
|
-
}
|
|
1908
|
-
return o;
|
|
1909
|
-
}
|
|
1910
|
-
_getArrayFromAccessor(e) {
|
|
1911
|
-
let t = e.array;
|
|
1912
|
-
if (e.normalized) {
|
|
1913
|
-
const s = Ee(t.constructor), n = new Float32Array(t.length);
|
|
1914
|
-
for (let r = 0, o = t.length; r < o; r++)
|
|
1915
|
-
n[r] = t[r] * s;
|
|
1916
|
-
t = n;
|
|
1917
|
-
}
|
|
1918
|
-
return t;
|
|
1919
|
-
}
|
|
1920
|
-
_createCubicSplineTrackInterpolant(e) {
|
|
1921
|
-
e.createInterpolant = function(s) {
|
|
1922
|
-
const n = this instanceof Pe ? In : rt;
|
|
1923
|
-
return new n(this.times, this.values, this.getValueSize() / 3, s);
|
|
1924
|
-
}, e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
function Hn(f, e, t) {
|
|
1928
|
-
const s = e.attributes, n = new ue();
|
|
1929
|
-
if (s.POSITION !== void 0) {
|
|
1930
|
-
const a = t.json.accessors[s.POSITION], i = a.min, c = a.max;
|
|
1931
|
-
if (i !== void 0 && c !== void 0) {
|
|
1932
|
-
if (n.set(
|
|
1933
|
-
new E(i[0], i[1], i[2]),
|
|
1934
|
-
new E(c[0], c[1], c[2])
|
|
1935
|
-
), a.normalized) {
|
|
1936
|
-
const l = Ee(Z[a.componentType]);
|
|
1937
|
-
n.min.multiplyScalar(l), n.max.multiplyScalar(l);
|
|
1938
|
-
}
|
|
1939
|
-
} else {
|
|
1940
|
-
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
1941
|
-
return;
|
|
1942
|
-
}
|
|
1943
|
-
} else
|
|
1944
|
-
return;
|
|
1945
|
-
const r = e.targets;
|
|
1946
|
-
if (r !== void 0) {
|
|
1947
|
-
const a = new E(), i = new E();
|
|
1948
|
-
for (let c = 0, l = r.length; c < l; c++) {
|
|
1949
|
-
const u = r[c];
|
|
1950
|
-
if (u.POSITION !== void 0) {
|
|
1951
|
-
const d = t.json.accessors[u.POSITION], h = d.min, p = d.max;
|
|
1952
|
-
if (h !== void 0 && p !== void 0) {
|
|
1953
|
-
if (i.setX(Math.max(Math.abs(h[0]), Math.abs(p[0]))), i.setY(Math.max(Math.abs(h[1]), Math.abs(p[1]))), i.setZ(Math.max(Math.abs(h[2]), Math.abs(p[2]))), d.normalized) {
|
|
1954
|
-
const T = Ee(Z[d.componentType]);
|
|
1955
|
-
i.multiplyScalar(T);
|
|
1956
|
-
}
|
|
1957
|
-
a.max(i);
|
|
1958
|
-
} else
|
|
1959
|
-
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
n.expandByVector(a);
|
|
1963
|
-
}
|
|
1964
|
-
f.boundingBox = n;
|
|
1965
|
-
const o = new jt();
|
|
1966
|
-
n.getCenter(o.center), o.radius = n.min.distanceTo(n.max) / 2, f.boundingSphere = o;
|
|
1967
|
-
}
|
|
1968
|
-
function Ue(f, e, t) {
|
|
1969
|
-
const s = e.attributes, n = [];
|
|
1970
|
-
function r(o, a) {
|
|
1971
|
-
return t.getDependency("accessor", o).then(function(i) {
|
|
1972
|
-
f.setAttribute(a, i);
|
|
1973
|
-
});
|
|
1974
|
-
}
|
|
1975
|
-
for (const o in s) {
|
|
1976
|
-
const a = we[o] || o.toLowerCase();
|
|
1977
|
-
a in f.attributes || n.push(r(s[o], a));
|
|
1978
|
-
}
|
|
1979
|
-
if (e.indices !== void 0 && !f.index) {
|
|
1980
|
-
const o = t.getDependency("accessor", e.indices).then(function(a) {
|
|
1981
|
-
f.setIndex(a);
|
|
1982
|
-
});
|
|
1983
|
-
n.push(o);
|
|
1984
|
-
}
|
|
1985
|
-
return Re.workingColorSpace !== F && "COLOR_0" in s && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Re.workingColorSpace}" not supported.`), U(f, e), Hn(f, e, t), Promise.all(n).then(function() {
|
|
1986
|
-
return e.targets !== void 0 ? On(f, e.targets, t) : f;
|
|
1987
|
-
});
|
|
1988
|
-
}
|
|
1989
|
-
const A = {
|
|
1990
|
-
c: null,
|
|
1991
|
-
// center
|
|
1992
|
-
u: [new E(), new E(), new E()],
|
|
1993
|
-
// basis vectors
|
|
1994
|
-
e: []
|
|
1995
|
-
// half width
|
|
1996
|
-
}, w = {
|
|
1997
|
-
c: null,
|
|
1998
|
-
// center
|
|
1999
|
-
u: [new E(), new E(), new E()],
|
|
2000
|
-
// basis vectors
|
|
2001
|
-
e: []
|
|
2002
|
-
// half width
|
|
2003
|
-
}, L = [[], [], []], y = [[], [], []], _ = [], W = new E(), Y = new E(), J = new E(), M = new E(), Be = new E(), Ge = new E(), P = new nt(), je = new ue(), ae = new ee(), ze = new ee(), Ke = new zt();
|
|
2004
|
-
class _e {
|
|
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 E(), t = new E(), s = new nt()) {
|
|
2013
|
-
this.center = e, this.halfSize = t, this.rotation = s;
|
|
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, s) {
|
|
2024
|
-
return this.center = e, this.halfSize = t, this.rotation = s, 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 s = this.halfSize;
|
|
2061
|
-
M.subVectors(e, this.center), this.rotation.extractBasis(W, Y, J), t.copy(this.center);
|
|
2062
|
-
const n = $.clamp(M.dot(W), -s.x, s.x);
|
|
2063
|
-
t.add(W.multiplyScalar(n));
|
|
2064
|
-
const r = $.clamp(M.dot(Y), -s.y, s.y);
|
|
2065
|
-
t.add(Y.multiplyScalar(r));
|
|
2066
|
-
const o = $.clamp(M.dot(J), -s.z, s.z);
|
|
2067
|
-
return t.add(J.multiplyScalar(o)), 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(Un.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, Ge), Ge.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 r = 0; r < 3; r++)
|
|
2106
|
-
for (let o = 0; o < 3; o++)
|
|
2107
|
-
L[r][o] = A.u[r].dot(w.u[o]);
|
|
2108
|
-
M.subVectors(w.c, A.c), _[0] = M.dot(A.u[0]), _[1] = M.dot(A.u[1]), _[2] = M.dot(A.u[2]);
|
|
2109
|
-
for (let r = 0; r < 3; r++)
|
|
2110
|
-
for (let o = 0; o < 3; o++)
|
|
2111
|
-
y[r][o] = Math.abs(L[r][o]) + t;
|
|
2112
|
-
let s, n;
|
|
2113
|
-
for (let r = 0; r < 3; r++)
|
|
2114
|
-
if (s = A.e[r], n = w.e[0] * y[r][0] + w.e[1] * y[r][1] + w.e[2] * y[r][2], Math.abs(_[r]) > s + n) return !1;
|
|
2115
|
-
for (let r = 0; r < 3; r++)
|
|
2116
|
-
if (s = A.e[0] * y[0][r] + A.e[1] * y[1][r] + A.e[2] * y[2][r], n = w.e[r], Math.abs(_[0] * L[0][r] + _[1] * L[1][r] + _[2] * L[2][r]) > s + n) return !1;
|
|
2117
|
-
return s = A.e[1] * y[2][0] + A.e[2] * y[1][0], n = w.e[1] * y[0][2] + w.e[2] * y[0][1], !(Math.abs(_[2] * L[1][0] - _[1] * L[2][0]) > s + n || (s = A.e[1] * y[2][1] + A.e[2] * y[1][1], n = w.e[0] * y[0][2] + w.e[2] * y[0][0], Math.abs(_[2] * L[1][1] - _[1] * L[2][1]) > s + n) || (s = A.e[1] * y[2][2] + A.e[2] * y[1][2], n = w.e[0] * y[0][1] + w.e[1] * y[0][0], Math.abs(_[2] * L[1][2] - _[1] * L[2][2]) > s + n) || (s = A.e[0] * y[2][0] + A.e[2] * y[0][0], n = w.e[1] * y[1][2] + w.e[2] * y[1][1], Math.abs(_[0] * L[2][0] - _[2] * L[0][0]) > s + n) || (s = A.e[0] * y[2][1] + A.e[2] * y[0][1], n = w.e[0] * y[1][2] + w.e[2] * y[1][0], Math.abs(_[0] * L[2][1] - _[2] * L[0][1]) > s + n) || (s = A.e[0] * y[2][2] + A.e[2] * y[0][2], n = w.e[0] * y[1][1] + w.e[1] * y[1][0], Math.abs(_[0] * L[2][2] - _[2] * L[0][2]) > s + n) || (s = A.e[0] * y[1][0] + A.e[1] * y[0][0], n = w.e[1] * y[2][2] + w.e[2] * y[2][1], Math.abs(_[1] * L[0][0] - _[0] * L[1][0]) > s + n) || (s = A.e[0] * y[1][1] + A.e[1] * y[0][1], n = w.e[0] * y[2][2] + w.e[2] * y[2][0], Math.abs(_[1] * L[0][1] - _[0] * L[1][1]) > s + n) || (s = A.e[0] * y[1][2] + A.e[1] * y[0][2], n = w.e[0] * y[2][1] + w.e[1] * y[2][0], Math.abs(_[1] * L[0][2] - _[0] * L[1][2]) > s + 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)), s = e.normal.dot(this.center) - e.constant;
|
|
2128
|
-
return Math.abs(s) <= 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(Be), je.setFromCenterAndSize(M.set(0, 0, 0), Be), 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 s = M.set(t[0], t[1], t[2]).length();
|
|
2179
|
-
const n = M.set(t[4], t[5], t[6]).length(), r = M.set(t[8], t[9], t[10]).length();
|
|
2180
|
-
e.determinant() < 0 && (s = -s), P.setFromMatrix4(e);
|
|
2181
|
-
const a = 1 / s, i = 1 / n, c = 1 / r;
|
|
2182
|
-
return P.elements[0] *= a, P.elements[1] *= a, P.elements[2] *= a, P.elements[3] *= i, P.elements[4] *= i, P.elements[5] *= i, P.elements[6] *= c, P.elements[7] *= c, P.elements[8] *= c, this.rotation.multiply(P), this.halfSize.x *= s, this.halfSize.y *= n, this.halfSize.z *= r, M.setFromMatrixPosition(e), this.center.add(M), this;
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
const Un = new _e(), Bn = {
|
|
2186
|
-
enableDamping: !0,
|
|
2187
|
-
dampingFactor: 0.25,
|
|
2188
|
-
screenSpacePanning: !1,
|
|
2189
|
-
minDistance: 0.1,
|
|
2190
|
-
maxDistance: 1e3,
|
|
2191
|
-
maxPolarAngle: $.degToRad(60)
|
|
2192
|
-
};
|
|
2193
|
-
function Wn(f, 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 s, n, r, o = [];
|
|
2207
|
-
const a = pe(!1), i = qt(), c = pe(0), l = pe(0), u = new Kt({
|
|
2208
|
-
antialias: !0,
|
|
2209
|
-
alpha: !0,
|
|
2210
|
-
precision: "mediump",
|
|
2211
|
-
logarithmicDepthBuffer: !0
|
|
2212
|
-
}), d = new Vt({}), h = new et(50, 1, 0.1, 2e3), p = Math.tan(Math.PI / 180 * h.fov / 2);
|
|
2213
|
-
let T = !1;
|
|
2214
|
-
u.setPixelRatio(window.devicePixelRatio);
|
|
2215
|
-
function m() {
|
|
2216
|
-
a.value = !1;
|
|
2217
|
-
const N = G();
|
|
2218
|
-
c.value = N[0], l.value = N[1], h.aspect = c.value / l.value, h.position.set(47, 39, 100), h.fov = 360 / Math.PI * Math.atan(p * (l.value / c.value)), h.lookAt(0, 0, 0), h.updateProjectionMatrix(), u.setSize(c.value, l.value), s.appendChild(u.domElement), t.stats && D(), t.css3d && ot();
|
|
2219
|
-
let j;
|
|
2220
|
-
if (t.control && t.control.init) {
|
|
2221
|
-
j = Jt(h, u.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 ke(() => a.value = !0), j;
|
|
2231
|
-
}
|
|
2232
|
-
function g(N) {
|
|
2233
|
-
N.preventDefault(), cancelAnimationFrame(x);
|
|
2234
|
-
}
|
|
2235
|
-
function b(N) {
|
|
2236
|
-
N.preventDefault(), m(), x();
|
|
2237
|
-
}
|
|
2238
|
-
function S(N) {
|
|
2239
|
-
o.push(N);
|
|
2240
|
-
}
|
|
2241
|
-
function x(N) {
|
|
2242
|
-
o && o.length && o.forEach((j) => {
|
|
2243
|
-
typeof j == "function" && j();
|
|
2244
|
-
}), t.renderType === "loop" && I(), requestAnimationFrame(x);
|
|
2245
|
-
}
|
|
2246
|
-
function I() {
|
|
2247
|
-
T = !1, n && n.update(), i.value && i.value.update(), u.render(d, h), r && r.render(d, h);
|
|
2248
|
-
}
|
|
2249
|
-
function k() {
|
|
2250
|
-
T || (T = !0, requestAnimationFrame(I));
|
|
2251
|
-
}
|
|
2252
|
-
function C() {
|
|
2253
|
-
ke(() => {
|
|
2254
|
-
const N = G();
|
|
2255
|
-
c.value = N[0], l.value = N[1], h.aspect = c.value / l.value, h.fov = 360 / Math.PI * Math.atan(p * (l.value / c.value)), h.updateProjectionMatrix(), h.lookAt(d.position), u.setSize(c.value, l.value), r && r.setSize(c.value, l.value), I();
|
|
2256
|
-
});
|
|
2257
|
-
}
|
|
2258
|
-
function G() {
|
|
2259
|
-
return s = document.querySelector(f), s ? [s.clientWidth, s.clientHeight] : [0, 0];
|
|
2260
|
-
}
|
|
2261
|
-
function D() {
|
|
2262
|
-
n = new $t(), n.dom.style.cssText = "position:absolute;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", s.appendChild(n.dom);
|
|
2263
|
-
}
|
|
2264
|
-
function te(N, j, z, ne, Le) {
|
|
2265
|
-
const Me = new ue().setFromObject(N), Ie = Me.getSize(new E()).length(), X = Me.getCenter(new E());
|
|
2266
|
-
Le && X.add(Le);
|
|
2267
|
-
const at = Ie * j * 0.5, ct = $.degToRad(z.fov * 0.5), lt = at / Math.tan(ct), de = new E().subVectors(z.position, X).multiply(new E(1, 1, 1)).normalize().multiplyScalar(lt).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 ot() {
|
|
2282
|
-
r = new Zt(), r.setSize(c.value, l.value), r.domElement.style.position = "absolute", r.domElement.style.top = 0, r.domElement.style.left = 0, r.domElement.style.pointerEvents = "none", s.appendChild(r.domElement);
|
|
2283
|
-
}
|
|
2284
|
-
function it() {
|
|
2285
|
-
Qt(d);
|
|
2286
|
-
}
|
|
2287
|
-
return Wt(() => {
|
|
2288
|
-
i.value = m(), window.addEventListener("resize", C, !1), u.domElement.addEventListener(
|
|
2289
|
-
"webglcontextlost",
|
|
2290
|
-
g,
|
|
2291
|
-
!1
|
|
2292
|
-
), u.domElement.addEventListener(
|
|
2293
|
-
"webglcontextrestored",
|
|
2294
|
-
b,
|
|
2295
|
-
!1
|
|
2296
|
-
), t.renderType === "loop" ? requestAnimationFrame(x) : t.renderType === "change" && i.value && i.value.addEventListener("change", k);
|
|
2297
|
-
}), Yt(() => {
|
|
2298
|
-
cancelAnimationFrame(x), u.domElement.removeEventListener("resize", C, !1), u.domElement.removeEventListener(
|
|
2299
|
-
"webglcontextlost",
|
|
2300
|
-
g,
|
|
2301
|
-
!1
|
|
2302
|
-
), u.domElement.removeEventListener(
|
|
2303
|
-
"webglcontextrestored",
|
|
2304
|
-
b,
|
|
2305
|
-
!1
|
|
2306
|
-
), it();
|
|
2307
|
-
}), {
|
|
2308
|
-
addAnimate: S,
|
|
2309
|
-
frameArea: te,
|
|
2310
|
-
onRender: I,
|
|
2311
|
-
css3dRenderer: r,
|
|
2312
|
-
scene: d,
|
|
2313
|
-
camera: h,
|
|
2314
|
-
control: i,
|
|
2315
|
-
renderer: u,
|
|
2316
|
-
domWidth: c,
|
|
2317
|
-
domHeight: l,
|
|
2318
|
-
isReady: a
|
|
2319
|
-
};
|
|
2320
|
-
}
|
|
2321
|
-
const Yn = (f = "app") => {
|
|
2322
|
-
const e = new Xt();
|
|
2323
|
-
e.params.Line.threshold = 8;
|
|
2324
|
-
const t = new Se(), s = document.getElementById(f);
|
|
2325
|
-
function n(a, i) {
|
|
2326
|
-
const { scaleX: c, scaleY: l } = o(s), { clientWidth: u, clientHeight: d } = i, h = i.getBoundingClientRect(), p = u * c, T = d * l, m = a.clientX - h.left, g = a.clientY - h.top;
|
|
2327
|
-
return t.x = (a.clientX - h.left) / p * 2 - 1, t.y = -((a.clientY - h.top) / T) * 2 + 1, { pointer: t, x: m, y: g };
|
|
2328
|
-
}
|
|
2329
|
-
function r(a, i, c, l) {
|
|
2330
|
-
const { pointer: u, x: d, y: h } = n(a, i);
|
|
2331
|
-
return e.setFromCamera(u, c), { intersects: e.intersectObjects(l), pointer: u, x: d, y: h };
|
|
2332
|
-
}
|
|
2333
|
-
function o(a) {
|
|
2334
|
-
const i = window.getComputedStyle(a), c = i.transform || i.webkitTransform || i.mozTransform;
|
|
2335
|
-
if (c && c !== "none") {
|
|
2336
|
-
const l = c.match(/^matrix\((.+)\)$/);
|
|
2337
|
-
if (l) {
|
|
2338
|
-
const u = l[1].split(", "), d = parseFloat(u[0]), h = parseFloat(u[3]);
|
|
2339
|
-
return { scaleX: d, scaleY: h };
|
|
2340
|
-
}
|
|
2341
|
-
}
|
|
2342
|
-
return { scaleX: 1, scaleY: 1 };
|
|
2343
|
-
}
|
|
2344
|
-
return {
|
|
2345
|
-
raycaster: e,
|
|
2346
|
-
pointer: t,
|
|
2347
|
-
getPointer: n,
|
|
2348
|
-
getScale: o,
|
|
2349
|
-
getIntersects: r
|
|
2350
|
-
};
|
|
2351
|
-
}, H = [], Jn = new B(16711680), Qn = () => {
|
|
2352
|
-
const f = () => {
|
|
2353
|
-
H.splice(0);
|
|
2354
|
-
}, e = (a, i) => {
|
|
2355
|
-
i.traverse((c) => {
|
|
2356
|
-
c && t(a, c);
|
|
2357
|
-
});
|
|
2358
|
-
}, t = (a, i) => {
|
|
2359
|
-
if (i.userData.needCheck && (i.autoUpdateMatrix = !1, i.updateMatrix(), i.updateMatrixWorld(), i.isMesh)) {
|
|
2360
|
-
const c = new ue(new E()).setFromObject(i);
|
|
2361
|
-
i.geometry.userData.obb = new _e(), i.geometry.userData.obb.halfSize.copy(c.getSize(new E())).multiplyScalar(0.5).multiplyScalar(0.88), i.userData.obb = new _e(), i.userData.originColor = i.material.color.clone(), i.userData.parentUid = a, H.push({
|
|
2362
|
-
object: i,
|
|
2363
|
-
parentUid: a
|
|
2364
|
-
});
|
|
2365
|
-
}
|
|
2366
|
-
};
|
|
2367
|
-
return {
|
|
2368
|
-
resetObbs: f,
|
|
2369
|
-
initObb: e,
|
|
2370
|
-
getObbObjectByParentUid: (a) => H.filter((i) => i.parentUid === a),
|
|
2371
|
-
addObbFromArray: (a, i) => {
|
|
2372
|
-
for (let c = 0, l = i.length; c < l; c++)
|
|
2373
|
-
t(a, i[c]);
|
|
2374
|
-
},
|
|
2375
|
-
removeObbFromArray: (a) => {
|
|
2376
|
-
const i = H.filter((c) => !a.includes(c.object));
|
|
2377
|
-
H.splice(0, H.length, ...i);
|
|
2378
|
-
},
|
|
2379
|
-
removeUidObb: (a) => {
|
|
2380
|
-
for (let i = H.length - 1; i >= 0; i--)
|
|
2381
|
-
H[i].parentUid === a && H.splice(i, 1);
|
|
2382
|
-
}
|
|
2383
|
-
};
|
|
2384
|
-
}, Ve = 4;
|
|
2385
|
-
class Gn {
|
|
2386
|
-
/**
|
|
2387
|
-
* 构造函数
|
|
2388
|
-
* @param {string} dbName - 数据库名称
|
|
2389
|
-
* @param {Object} tableDefinitions - 表定义对象,例如 { models: "&path, data" }
|
|
2390
|
-
* @param {number} version - 数据库版本号
|
|
2391
|
-
*/
|
|
2392
|
-
constructor(e = "threeJsIDBCache") {
|
|
2393
|
-
this.version = Ve, this.dbName = e, this.dbInit();
|
|
2394
|
-
}
|
|
2395
|
-
dbInit() {
|
|
2396
|
-
this.db = new en(this.dbName), this.db.version(this.version).stores({ models: "&path, version" }).upgrade(async (e) => {
|
|
2397
|
-
console.log("[ IDBCache 版本更新 ] ====> version", Ve);
|
|
2398
|
-
const t = e.table("models"), s = await t.toArray();
|
|
2399
|
-
for (const n of s)
|
|
2400
|
-
n.data instanceof ArrayBuffer || await t.delete(n.path);
|
|
2401
|
-
});
|
|
2402
|
-
}
|
|
2403
|
-
/**
|
|
2404
|
-
* 获取 Dexie 数据库实例
|
|
2405
|
-
* @returns {Dexie} Dexie 实例
|
|
2406
|
-
*/
|
|
2407
|
-
getDatabase() {
|
|
2408
|
-
return this.db;
|
|
2409
|
-
}
|
|
2410
|
-
async saveModel(e, t, s) {
|
|
2411
|
-
await this.db.table("models").put({ path: e, version: t, data: s });
|
|
2412
|
-
}
|
|
2413
|
-
async getModel(e, t) {
|
|
2414
|
-
const s = await this.db.table("models").get(e);
|
|
2415
|
-
return s ? s.version !== t ? (console.log("模型版本不一致, 清除当前记录"), await this.db.table("models").delete(e), null) : s.data : (console.warn(`Model "${e}" not found in table models`), null);
|
|
2416
|
-
}
|
|
2417
|
-
// ---------------------------- ---------------------------------
|
|
2418
|
-
/**
|
|
2419
|
-
* 缓存模型到 IndexedDB
|
|
2420
|
-
* @param {string} path - 主键值
|
|
2421
|
-
* @param {THREE.Object3D} model - 要缓存的模型
|
|
2422
|
-
* @param {string} [version] - 缓存模型版本
|
|
2423
|
-
*/
|
|
2424
|
-
async cacheModel(e, t, s) {
|
|
2425
|
-
console.log("[ ] ====> path, modelData, version", e, t, s);
|
|
2426
|
-
try {
|
|
2427
|
-
this.db.table("models").put({ version: s, path: e, data: t }).then(() => {
|
|
2428
|
-
console.log(`Model "${e}" cached successfully in table models`);
|
|
2429
|
-
});
|
|
2430
|
-
} catch {
|
|
2431
|
-
console.log(" 缓存模型失败 =====> ");
|
|
2432
|
-
}
|
|
2433
|
-
return t;
|
|
2434
|
-
}
|
|
2435
|
-
/**
|
|
2436
|
-
* 从 IndexedDB 加载缓存的模型
|
|
2437
|
-
* @param {string} path - 主键值
|
|
2438
|
-
* @returns {THREE.Object3D | null} 加载的模型
|
|
2439
|
-
*/
|
|
2440
|
-
async loadCachedModel(e, t) {
|
|
2441
|
-
let s = null;
|
|
2442
|
-
try {
|
|
2443
|
-
if (s = await this.db.table("models").get(e), !s)
|
|
2444
|
-
return console.warn(`Model "${t}" not found in table models`), null;
|
|
2445
|
-
if (s.version !== t)
|
|
2446
|
-
return console.log(" =====> 模型版本不一致, 清除当前记录"), await this.db.table("models").delete(e), null;
|
|
2447
|
-
} catch {
|
|
2448
|
-
return console.log(" =====> 查询表中模型失败"), this.db.delete().then(() => {
|
|
2449
|
-
this.init();
|
|
2450
|
-
}), null;
|
|
2451
|
-
}
|
|
2452
|
-
return s.data;
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
let ce;
|
|
2456
|
-
const $n = () => {
|
|
2457
|
-
const f = new sn(), e = new tn();
|
|
2458
|
-
e.setDecoderPath("/draco/"), f.setDRACOLoader(e);
|
|
2459
|
-
function t(i, c, l, u) {
|
|
2460
|
-
return f.load(i, c, l, u);
|
|
2461
|
-
}
|
|
2462
|
-
function s(i, c) {
|
|
2463
|
-
return new Promise((l, u) => {
|
|
2464
|
-
f.load(i, l, c, u);
|
|
2465
|
-
});
|
|
2466
|
-
}
|
|
2467
|
-
async function n(i, c) {
|
|
2468
|
-
try {
|
|
2469
|
-
console.log("[ 读取缓存 ] ====> "), console.time("[ 读取缓存耗时 ] ");
|
|
2470
|
-
let l = await o(i, c);
|
|
2471
|
-
console.timeEnd("[ 读取缓存耗时 ] "), l || (console.log("[ 读取缓存 ] ====> 缓存未命中,开始加载模型"), console.time("[ fetchArrayBuffer ] ====> 加载模型耗时"), l = await r(i), console.log("[ asyncFetch ] ====> arrayBuffer", l), console.timeEnd("[ fetchArrayBuffer ] ====> 加载模型耗时"), ce.saveModel(i, c, l)), console.log("[ 开始解析模型 ] ====> "), console.time("[ 解析模型耗时 ]");
|
|
2472
|
-
const u = await a(l);
|
|
2473
|
-
return console.timeEnd("[ 解析模型耗时 ]"), u.scene;
|
|
2474
|
-
} catch (l) {
|
|
2475
|
-
return console.error(`加载模型 ${i} 失败:`, l), null;
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
async function r(i) {
|
|
2479
|
-
return new Promise((c, l) => {
|
|
2480
|
-
fetch(i).then((u) => u.arrayBuffer()).then((u) => {
|
|
2481
|
-
c(u);
|
|
2482
|
-
}).catch((u) => {
|
|
2483
|
-
l(u);
|
|
2484
|
-
});
|
|
2485
|
-
});
|
|
2486
|
-
}
|
|
2487
|
-
async function o(i, c) {
|
|
2488
|
-
return ce || (ce = new Gn()), ce.getModel(i, c);
|
|
2489
|
-
}
|
|
2490
|
-
async function a(i) {
|
|
2491
|
-
return new Promise((c, l) => {
|
|
2492
|
-
f.parse(i, "", c, l);
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2495
|
-
return {
|
|
2496
|
-
load: t,
|
|
2497
|
-
asyncLoad: s,
|
|
2498
|
-
asyncCacheLoad: n,
|
|
2499
|
-
asyncFetch: n
|
|
2500
|
-
};
|
|
2501
|
-
};
|
|
2502
|
-
export {
|
|
2503
|
-
Gn as I,
|
|
2504
|
-
Yn as a,
|
|
2505
|
-
Qn as b,
|
|
2506
|
-
$n as c,
|
|
2507
|
-
Jn as i,
|
|
2508
|
-
H as o,
|
|
2509
|
-
Wn as u
|
|
2510
|
-
};
|