@scenoco-three/create 0.0.0-stage → 0.7.0

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.
@@ -0,0 +1,2512 @@
1
+ import { $r as MathUtils, B as Bone, Bi as NumberKeyframeTrack, Br as LinearSRGBColorSpace, Bs as Vector3, Ci as NearestMipmapLinearFilter, Er as Line, Fo as Skeleton, Hs as VectorKeyframeTrack, J as BufferGeometry, Lo as SkinnedMesh, Mr as LineLoop, Nr as LineSegments, Or as LineBasicMaterial, Pr as LinearFilter, Qi as OrthographicCamera, Qn as InstancedMesh, Rn as Group, Rr as LinearMipmapLinearFilter, To as SRGBColorSpace, U as Box3, Ur as Loader, Vi as Object3D, Wn as ImageBitmapLoader, Wo as SpotLight, Wr as LoaderUtils, Xr as Material, Yn as InstancedBufferAttribute, Zt as DirectionalLight, _a as Quaternion, _o as RepeatWrapping, ai as MeshBasicMaterial, ar as Interpolant, at as ClampToEdgeWrapping, b as AnimationClip, bi as NearestFilter, ca as Points, cr as InterpolateLinear, ds as TextureLoader, fi as MeshPhysicalMaterial, gi as MirroredRepeatWrapping, ii as Mesh, ir as InterleavedBufferAttribute, la as PointsMaterial, lt as ColorManagement, na as PerspectiveCamera, ni as Matrix4, oa as PointLight, pa as PropertyBinding, pi as MeshStandardMaterial, q as BufferAttribute, rr as InterleavedBuffer, sr as InterpolateDiscrete, st as Color, us as Texture, va as QuaternionKeyframeTrack, vn as FileLoader, wi as NearestMipmapNearestFilter, zo as Sphere, zr as LinearMipmapNearestFilter, zs as Vector2 } from "./three.module-Dhi4sXJn.js";
2
+ import { clone } from "./three_addons_utils_SkeletonUtils__js.js";
3
+ //#region node_modules/three/examples/jsm/utils/BufferGeometryUtils.js
4
+ /**
5
+ * Returns a new indexed geometry based on `TrianglesDrawMode` draw mode.
6
+ * This mode corresponds to the `gl.TRIANGLES` primitive in WebGL.
7
+ *
8
+ * @param {BufferGeometry} geometry - The geometry to convert.
9
+ * @param {number} drawMode - The current draw mode.
10
+ * @return {BufferGeometry} The new geometry using `TrianglesDrawMode`.
11
+ */
12
+ function toTrianglesDrawMode(geometry, drawMode) {
13
+ if (drawMode === 0) {
14
+ console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.");
15
+ return geometry;
16
+ }
17
+ if (drawMode === 2 || drawMode === 1) {
18
+ let index = geometry.getIndex();
19
+ if (index === null) {
20
+ const indices = [];
21
+ const position = geometry.getAttribute("position");
22
+ if (position !== void 0) {
23
+ for (let i = 0; i < position.count; i++) indices.push(i);
24
+ geometry.setIndex(indices);
25
+ index = geometry.getIndex();
26
+ } else {
27
+ console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.");
28
+ return geometry;
29
+ }
30
+ }
31
+ const numberOfTriangles = index.count - 2;
32
+ const newIndices = [];
33
+ if (drawMode === 2) for (let i = 1; i <= numberOfTriangles; i++) {
34
+ newIndices.push(index.getX(0));
35
+ newIndices.push(index.getX(i));
36
+ newIndices.push(index.getX(i + 1));
37
+ }
38
+ else for (let i = 0; i < numberOfTriangles; i++) if (i % 2 === 0) {
39
+ newIndices.push(index.getX(i));
40
+ newIndices.push(index.getX(i + 1));
41
+ newIndices.push(index.getX(i + 2));
42
+ } else {
43
+ newIndices.push(index.getX(i + 2));
44
+ newIndices.push(index.getX(i + 1));
45
+ newIndices.push(index.getX(i));
46
+ }
47
+ if (newIndices.length / 3 !== numberOfTriangles) console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
48
+ const newGeometry = geometry.clone();
49
+ newGeometry.setIndex(newIndices);
50
+ newGeometry.clearGroups();
51
+ return newGeometry;
52
+ } else {
53
+ console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", drawMode);
54
+ return geometry;
55
+ }
56
+ }
57
+ //#endregion
58
+ //#region node_modules/three/examples/jsm/loaders/GLTFLoader.js
59
+ /**
60
+ * A loader for the glTF 2.0 format.
61
+ *
62
+ * [glTF](https://www.khronos.org/gltf/) (GL Transmission Format) is an [open format specification]{@link https://github.com/KhronosGroup/glTF/tree/main/specification/2.0)
63
+ * for efficient delivery and loading of 3D content. Assets may be provided either in JSON (.gltf) or binary (.glb)
64
+ * format. External files store textures (.jpg, .png) and additional binary data (.bin). A glTF asset may deliver
65
+ * one or more scenes, including meshes, materials, textures, skins, skeletons, morph targets, animations, lights,
66
+ * and/or cameras.
67
+ *
68
+ * `GLTFLoader` uses {@link ImageBitmapLoader} whenever possible. Be advised that image bitmaps are not
69
+ * automatically GC-collected when they are no longer referenced, and they require special handling during
70
+ * the disposal process.
71
+ *
72
+ * `GLTFLoader` supports the following glTF 2.0 extensions:
73
+ * - KHR_draco_mesh_compression
74
+ * - KHR_lights_punctual
75
+ * - KHR_materials_anisotropy
76
+ * - KHR_materials_clearcoat
77
+ * - KHR_materials_dispersion
78
+ * - KHR_materials_emissive_strength
79
+ * - KHR_materials_ior
80
+ * - KHR_materials_specular
81
+ * - KHR_materials_transmission
82
+ * - KHR_materials_iridescence
83
+ * - KHR_materials_unlit
84
+ * - KHR_materials_volume
85
+ * - KHR_mesh_quantization
86
+ * - KHR_meshopt_compression
87
+ * - KHR_texture_basisu
88
+ * - KHR_texture_transform
89
+ * - EXT_materials_bump
90
+ * - EXT_meshopt_compression
91
+ * - EXT_mesh_gpu_instancing
92
+ * - EXT_texture_avif
93
+ * - EXT_texture_webp
94
+ *
95
+ * The following glTF 2.0 extension is supported by an external user plugin:
96
+ * - [KHR_materials_variants](https://github.com/takahirox/three-gltf-extensions)
97
+ * - [MSFT_texture_dds](https://github.com/takahirox/three-gltf-extensions)
98
+ * - [KHR_animation_pointer](https://github.com/needle-tools/three-animation-pointer)
99
+ * - [NEEDLE_progressive](https://github.com/needle-tools/gltf-progressive)
100
+ *
101
+ * ```js
102
+ * const loader = new GLTFLoader();
103
+ *
104
+ * // Optional: Provide a DRACOLoader instance to decode compressed mesh data
105
+ * const dracoLoader = new DRACOLoader();
106
+ * dracoLoader.setDecoderPath( '/examples/jsm/libs/draco/' );
107
+ * loader.setDRACOLoader( dracoLoader );
108
+ *
109
+ * const gltf = await loader.loadAsync( 'models/gltf/duck/duck.gltf' );
110
+ * scene.add( gltf.scene );
111
+ * ```
112
+ *
113
+ * @augments Loader
114
+ * @three_import import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
115
+ */
116
+ var GLTFLoader = class extends Loader {
117
+ /**
118
+ * Constructs a new glTF loader.
119
+ *
120
+ * @param {LoadingManager} [manager] - The loading manager.
121
+ */
122
+ constructor(manager) {
123
+ super(manager);
124
+ this.dracoLoader = null;
125
+ this.ktx2Loader = null;
126
+ this.meshoptDecoder = null;
127
+ this.pluginCallbacks = [];
128
+ this.register(function(parser) {
129
+ return new GLTFMaterialsClearcoatExtension(parser);
130
+ });
131
+ this.register(function(parser) {
132
+ return new GLTFMaterialsDispersionExtension(parser);
133
+ });
134
+ this.register(function(parser) {
135
+ return new GLTFTextureBasisUExtension(parser);
136
+ });
137
+ this.register(function(parser) {
138
+ return new GLTFTextureWebPExtension(parser);
139
+ });
140
+ this.register(function(parser) {
141
+ return new GLTFTextureAVIFExtension(parser);
142
+ });
143
+ this.register(function(parser) {
144
+ return new GLTFMaterialsSheenExtension(parser);
145
+ });
146
+ this.register(function(parser) {
147
+ return new GLTFMaterialsTransmissionExtension(parser);
148
+ });
149
+ this.register(function(parser) {
150
+ return new GLTFMaterialsVolumeExtension(parser);
151
+ });
152
+ this.register(function(parser) {
153
+ return new GLTFMaterialsIorExtension(parser);
154
+ });
155
+ this.register(function(parser) {
156
+ return new GLTFMaterialsEmissiveStrengthExtension(parser);
157
+ });
158
+ this.register(function(parser) {
159
+ return new GLTFMaterialsSpecularExtension(parser);
160
+ });
161
+ this.register(function(parser) {
162
+ return new GLTFMaterialsIridescenceExtension(parser);
163
+ });
164
+ this.register(function(parser) {
165
+ return new GLTFMaterialsAnisotropyExtension(parser);
166
+ });
167
+ this.register(function(parser) {
168
+ return new GLTFMaterialsBumpExtension(parser);
169
+ });
170
+ this.register(function(parser) {
171
+ return new GLTFLightsExtension(parser);
172
+ });
173
+ this.register(function(parser) {
174
+ return new GLTFMeshoptCompression(parser, EXTENSIONS.EXT_MESHOPT_COMPRESSION);
175
+ });
176
+ this.register(function(parser) {
177
+ return new GLTFMeshoptCompression(parser, EXTENSIONS.KHR_MESHOPT_COMPRESSION);
178
+ });
179
+ this.register(function(parser) {
180
+ return new GLTFMeshGpuInstancing(parser);
181
+ });
182
+ }
183
+ /**
184
+ * Starts loading from the given URL and passes the loaded glTF asset
185
+ * to the `onLoad()` callback.
186
+ *
187
+ * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
188
+ * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
189
+ * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
190
+ * @param {onErrorCallback} onError - Executed when errors occur.
191
+ */
192
+ load(url, onLoad, onProgress, onError) {
193
+ const scope = this;
194
+ let resourcePath;
195
+ if (this.resourcePath !== "") resourcePath = this.resourcePath;
196
+ else if (this.path !== "") {
197
+ const relativeUrl = LoaderUtils.extractUrlBase(url);
198
+ resourcePath = LoaderUtils.resolveURL(relativeUrl, this.path);
199
+ } else resourcePath = LoaderUtils.extractUrlBase(url);
200
+ this.manager.itemStart(url);
201
+ const _onError = function(e) {
202
+ if (onError) onError(e);
203
+ else console.error(e);
204
+ scope.manager.itemError(url);
205
+ scope.manager.itemEnd(url);
206
+ };
207
+ const loader = new FileLoader(this.manager);
208
+ loader.setPath(this.path);
209
+ loader.setResponseType("arraybuffer");
210
+ loader.setRequestHeader(this.requestHeader);
211
+ loader.setWithCredentials(this.withCredentials);
212
+ loader.load(url, function(data) {
213
+ try {
214
+ scope.parse(data, resourcePath, function(gltf) {
215
+ onLoad(gltf);
216
+ scope.manager.itemEnd(url);
217
+ }, _onError);
218
+ } catch (e) {
219
+ _onError(e);
220
+ }
221
+ }, onProgress, _onError);
222
+ }
223
+ /**
224
+ * Sets the given Draco loader to this loader. Required for decoding assets
225
+ * compressed with the `KHR_draco_mesh_compression` extension.
226
+ *
227
+ * @param {DRACOLoader} dracoLoader - The Draco loader to set.
228
+ * @return {GLTFLoader} A reference to this loader.
229
+ */
230
+ setDRACOLoader(dracoLoader) {
231
+ this.dracoLoader = dracoLoader;
232
+ return this;
233
+ }
234
+ /**
235
+ * Sets the given KTX2 loader to this loader. Required for loading KTX2
236
+ * compressed textures.
237
+ *
238
+ * @param {KTX2Loader} ktx2Loader - The KTX2 loader to set.
239
+ * @return {GLTFLoader} A reference to this loader.
240
+ */
241
+ setKTX2Loader(ktx2Loader) {
242
+ this.ktx2Loader = ktx2Loader;
243
+ return this;
244
+ }
245
+ /**
246
+ * Sets the given meshopt decoder. Required for decoding assets
247
+ * compressed with the `EXT_meshopt_compression` extension.
248
+ *
249
+ * @param {Object} meshoptDecoder - The meshopt decoder to set.
250
+ * @return {GLTFLoader} A reference to this loader.
251
+ */
252
+ setMeshoptDecoder(meshoptDecoder) {
253
+ this.meshoptDecoder = meshoptDecoder;
254
+ return this;
255
+ }
256
+ /**
257
+ * Registers a plugin callback. This API is internally used to implement the various
258
+ * glTF extensions but can also used by third-party code to add additional logic
259
+ * to the loader.
260
+ *
261
+ * @param {function(parser:GLTFParser)} callback - The callback function to register.
262
+ * @return {GLTFLoader} A reference to this loader.
263
+ */
264
+ register(callback) {
265
+ if (this.pluginCallbacks.indexOf(callback) === -1) this.pluginCallbacks.push(callback);
266
+ return this;
267
+ }
268
+ /**
269
+ * Unregisters a plugin callback.
270
+ *
271
+ * @param {Function} callback - The callback function to unregister.
272
+ * @return {GLTFLoader} A reference to this loader.
273
+ */
274
+ unregister(callback) {
275
+ if (this.pluginCallbacks.indexOf(callback) !== -1) this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
276
+ return this;
277
+ }
278
+ /**
279
+ * Parses the given glTF data and returns the resulting group.
280
+ *
281
+ * @param {string|ArrayBuffer} data - The raw glTF data.
282
+ * @param {string} path - The URL base path.
283
+ * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
284
+ * @param {onErrorCallback} onError - Executed when errors occur.
285
+ */
286
+ parse(data, path, onLoad, onError) {
287
+ let json;
288
+ const extensions = {};
289
+ const plugins = {};
290
+ const textDecoder = new TextDecoder();
291
+ if (typeof data === "string") json = JSON.parse(data);
292
+ else if (data instanceof ArrayBuffer) if (textDecoder.decode(new Uint8Array(data, 0, 4)) === BINARY_EXTENSION_HEADER_MAGIC) {
293
+ try {
294
+ extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
295
+ } catch (error) {
296
+ if (onError) onError(error);
297
+ return;
298
+ }
299
+ json = JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content);
300
+ } else json = JSON.parse(textDecoder.decode(data));
301
+ else json = data;
302
+ if (json.asset === void 0 || json.asset.version[0] < 2) {
303
+ if (onError) onError(/* @__PURE__ */ new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
304
+ return;
305
+ }
306
+ const parser = new GLTFParser(json, {
307
+ path: path || this.resourcePath || "",
308
+ crossOrigin: this.crossOrigin,
309
+ requestHeader: this.requestHeader,
310
+ manager: this.manager,
311
+ ktx2Loader: this.ktx2Loader,
312
+ meshoptDecoder: this.meshoptDecoder
313
+ });
314
+ parser.fileLoader.setRequestHeader(this.requestHeader);
315
+ for (let i = 0; i < this.pluginCallbacks.length; i++) {
316
+ const plugin = this.pluginCallbacks[i](parser);
317
+ if (!plugin.name) console.error("THREE.GLTFLoader: Invalid plugin found: missing name");
318
+ plugins[plugin.name] = plugin;
319
+ extensions[plugin.name] = true;
320
+ }
321
+ if (json.extensionsUsed) for (let i = 0; i < json.extensionsUsed.length; ++i) {
322
+ const extensionName = json.extensionsUsed[i];
323
+ const extensionsRequired = json.extensionsRequired || [];
324
+ switch (extensionName) {
325
+ case EXTENSIONS.KHR_MATERIALS_UNLIT:
326
+ extensions[extensionName] = new GLTFMaterialsUnlitExtension();
327
+ break;
328
+ case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
329
+ extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
330
+ break;
331
+ case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
332
+ extensions[extensionName] = new GLTFTextureTransformExtension();
333
+ break;
334
+ case EXTENSIONS.KHR_MESH_QUANTIZATION:
335
+ extensions[extensionName] = new GLTFMeshQuantizationExtension();
336
+ break;
337
+ default: if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === void 0) console.warn("THREE.GLTFLoader: Unknown extension \"" + extensionName + "\".");
338
+ }
339
+ }
340
+ parser.setExtensions(extensions);
341
+ parser.setPlugins(plugins);
342
+ parser.parse(onLoad, onError);
343
+ }
344
+ /**
345
+ * Async version of {@link GLTFLoader#parse}.
346
+ *
347
+ * @async
348
+ * @param {string|ArrayBuffer} data - The raw glTF data.
349
+ * @param {string} path - The URL base path.
350
+ * @return {Promise<GLTFLoader~LoadObject>} A Promise that resolves with the loaded glTF when the parsing has been finished.
351
+ */
352
+ parseAsync(data, path) {
353
+ const scope = this;
354
+ return new Promise(function(resolve, reject) {
355
+ scope.parse(data, path, resolve, reject);
356
+ });
357
+ }
358
+ };
359
+ function GLTFRegistry() {
360
+ let objects = {};
361
+ return {
362
+ get: function(key) {
363
+ return objects[key];
364
+ },
365
+ add: function(key, object) {
366
+ objects[key] = object;
367
+ },
368
+ remove: function(key) {
369
+ delete objects[key];
370
+ },
371
+ removeAll: function() {
372
+ objects = {};
373
+ }
374
+ };
375
+ }
376
+ /********** EXTENSIONS ***********/
377
+ function getMaterialExtension(parser, materialIndex, extensionName) {
378
+ const materialDef = parser.json.materials[materialIndex];
379
+ if (materialDef.extensions && materialDef.extensions[extensionName]) return materialDef.extensions[extensionName];
380
+ return null;
381
+ }
382
+ var EXTENSIONS = {
383
+ KHR_BINARY_GLTF: "KHR_binary_glTF",
384
+ KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
385
+ KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
386
+ KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
387
+ KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion",
388
+ KHR_MATERIALS_IOR: "KHR_materials_ior",
389
+ KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
390
+ KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
391
+ KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
392
+ KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
393
+ KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
394
+ KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
395
+ KHR_MATERIALS_VOLUME: "KHR_materials_volume",
396
+ KHR_TEXTURE_BASISU: "KHR_texture_basisu",
397
+ KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
398
+ KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
399
+ KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
400
+ EXT_MATERIALS_BUMP: "EXT_materials_bump",
401
+ EXT_TEXTURE_WEBP: "EXT_texture_webp",
402
+ EXT_TEXTURE_AVIF: "EXT_texture_avif",
403
+ EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
404
+ KHR_MESHOPT_COMPRESSION: "KHR_meshopt_compression",
405
+ EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
406
+ };
407
+ /**
408
+ * Punctual Lights Extension
409
+ *
410
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
411
+ *
412
+ * @private
413
+ */
414
+ var GLTFLightsExtension = class {
415
+ constructor(parser) {
416
+ this.parser = parser;
417
+ this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
418
+ this.cache = {
419
+ refs: {},
420
+ uses: {}
421
+ };
422
+ }
423
+ _markDefs() {
424
+ const parser = this.parser;
425
+ const nodeDefs = this.parser.json.nodes || [];
426
+ for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
427
+ const nodeDef = nodeDefs[nodeIndex];
428
+ if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== void 0) parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
429
+ }
430
+ }
431
+ _loadLight(lightIndex) {
432
+ const parser = this.parser;
433
+ const cacheKey = "light:" + lightIndex;
434
+ let dependency = parser.cache.get(cacheKey);
435
+ if (dependency) return dependency;
436
+ const json = parser.json;
437
+ const lightDef = ((json.extensions && json.extensions[this.name] || {}).lights || [])[lightIndex];
438
+ let lightNode;
439
+ const color = new Color(16777215);
440
+ if (lightDef.color !== void 0) color.setRGB(lightDef.color[0], lightDef.color[1], lightDef.color[2], LinearSRGBColorSpace);
441
+ const range = lightDef.range !== void 0 ? lightDef.range : 0;
442
+ switch (lightDef.type) {
443
+ case "directional":
444
+ lightNode = new DirectionalLight(color);
445
+ lightNode.target.position.set(0, 0, -1);
446
+ lightNode.add(lightNode.target);
447
+ break;
448
+ case "point":
449
+ lightNode = new PointLight(color);
450
+ lightNode.distance = range;
451
+ break;
452
+ case "spot":
453
+ lightNode = new SpotLight(color);
454
+ lightNode.distance = range;
455
+ lightDef.spot = lightDef.spot || {};
456
+ lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== void 0 ? lightDef.spot.innerConeAngle : 0;
457
+ lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== void 0 ? lightDef.spot.outerConeAngle : Math.PI / 4;
458
+ lightNode.angle = lightDef.spot.outerConeAngle;
459
+ lightNode.penumbra = 1 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
460
+ lightNode.target.position.set(0, 0, -1);
461
+ lightNode.add(lightNode.target);
462
+ break;
463
+ default: throw new Error("THREE.GLTFLoader: Unexpected light type: " + lightDef.type);
464
+ }
465
+ lightNode.position.set(0, 0, 0);
466
+ assignExtrasToUserData(lightNode, lightDef);
467
+ if (lightDef.intensity !== void 0) lightNode.intensity = lightDef.intensity;
468
+ lightNode.name = parser.createUniqueName(lightDef.name || "light_" + lightIndex);
469
+ dependency = Promise.resolve(lightNode);
470
+ parser.cache.add(cacheKey, dependency);
471
+ return dependency;
472
+ }
473
+ getDependency(type, index) {
474
+ if (type !== "light") return;
475
+ return this._loadLight(index);
476
+ }
477
+ createNodeAttachment(nodeIndex) {
478
+ const self = this;
479
+ const parser = this.parser;
480
+ const nodeDef = parser.json.nodes[nodeIndex];
481
+ const lightIndex = (nodeDef.extensions && nodeDef.extensions[this.name] || {}).light;
482
+ if (lightIndex === void 0) return null;
483
+ return this._loadLight(lightIndex).then(function(light) {
484
+ return parser._getNodeRef(self.cache, lightIndex, light);
485
+ });
486
+ }
487
+ };
488
+ /**
489
+ * Unlit Materials Extension
490
+ *
491
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
492
+ *
493
+ * @private
494
+ */
495
+ var GLTFMaterialsUnlitExtension = class {
496
+ constructor() {
497
+ this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
498
+ }
499
+ getMaterialType() {
500
+ return MeshBasicMaterial;
501
+ }
502
+ extendParams(materialParams, materialDef, parser) {
503
+ const pending = [];
504
+ materialParams.color = new Color(1, 1, 1);
505
+ materialParams.opacity = 1;
506
+ const metallicRoughness = materialDef.pbrMetallicRoughness;
507
+ if (metallicRoughness) {
508
+ if (Array.isArray(metallicRoughness.baseColorFactor)) {
509
+ const array = metallicRoughness.baseColorFactor;
510
+ materialParams.color.setRGB(array[0], array[1], array[2], LinearSRGBColorSpace);
511
+ materialParams.opacity = array[3];
512
+ }
513
+ if (metallicRoughness.baseColorTexture !== void 0) pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, SRGBColorSpace));
514
+ }
515
+ return Promise.all(pending);
516
+ }
517
+ };
518
+ /**
519
+ * Materials Emissive Strength Extension
520
+ *
521
+ * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
522
+ *
523
+ * @private
524
+ */
525
+ var GLTFMaterialsEmissiveStrengthExtension = class {
526
+ constructor(parser) {
527
+ this.parser = parser;
528
+ this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
529
+ }
530
+ extendMaterialParams(materialIndex, materialParams) {
531
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
532
+ if (extension === null) return Promise.resolve();
533
+ if (extension.emissiveStrength !== void 0) materialParams.emissiveIntensity = extension.emissiveStrength;
534
+ return Promise.resolve();
535
+ }
536
+ };
537
+ /**
538
+ * Clearcoat Materials Extension
539
+ *
540
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
541
+ *
542
+ * @private
543
+ */
544
+ var GLTFMaterialsClearcoatExtension = class {
545
+ constructor(parser) {
546
+ this.parser = parser;
547
+ this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
548
+ }
549
+ getMaterialType(materialIndex) {
550
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
551
+ }
552
+ extendMaterialParams(materialIndex, materialParams) {
553
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
554
+ if (extension === null) return Promise.resolve();
555
+ const pending = [];
556
+ if (extension.clearcoatFactor !== void 0) materialParams.clearcoat = extension.clearcoatFactor;
557
+ if (extension.clearcoatTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "clearcoatMap", extension.clearcoatTexture));
558
+ if (extension.clearcoatRoughnessFactor !== void 0) materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
559
+ if (extension.clearcoatRoughnessTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "clearcoatRoughnessMap", extension.clearcoatRoughnessTexture));
560
+ if (extension.clearcoatNormalTexture !== void 0) {
561
+ pending.push(this.parser.assignTexture(materialParams, "clearcoatNormalMap", extension.clearcoatNormalTexture));
562
+ if (extension.clearcoatNormalTexture.scale !== void 0) {
563
+ const scale = extension.clearcoatNormalTexture.scale;
564
+ materialParams.clearcoatNormalScale = new Vector2(scale, scale);
565
+ }
566
+ }
567
+ return Promise.all(pending);
568
+ }
569
+ };
570
+ /**
571
+ * Materials dispersion Extension
572
+ *
573
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_dispersion
574
+ *
575
+ * @private
576
+ */
577
+ var GLTFMaterialsDispersionExtension = class {
578
+ constructor(parser) {
579
+ this.parser = parser;
580
+ this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
581
+ }
582
+ getMaterialType(materialIndex) {
583
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
584
+ }
585
+ extendMaterialParams(materialIndex, materialParams) {
586
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
587
+ if (extension === null) return Promise.resolve();
588
+ materialParams.dispersion = extension.dispersion !== void 0 ? extension.dispersion : 0;
589
+ return Promise.resolve();
590
+ }
591
+ };
592
+ /**
593
+ * Iridescence Materials Extension
594
+ *
595
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
596
+ *
597
+ * @private
598
+ */
599
+ var GLTFMaterialsIridescenceExtension = class {
600
+ constructor(parser) {
601
+ this.parser = parser;
602
+ this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
603
+ }
604
+ getMaterialType(materialIndex) {
605
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
606
+ }
607
+ extendMaterialParams(materialIndex, materialParams) {
608
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
609
+ if (extension === null) return Promise.resolve();
610
+ const pending = [];
611
+ if (extension.iridescenceFactor !== void 0) materialParams.iridescence = extension.iridescenceFactor;
612
+ if (extension.iridescenceTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "iridescenceMap", extension.iridescenceTexture));
613
+ if (extension.iridescenceIor !== void 0) materialParams.iridescenceIOR = extension.iridescenceIor;
614
+ if (materialParams.iridescenceThicknessRange === void 0) materialParams.iridescenceThicknessRange = [100, 400];
615
+ if (extension.iridescenceThicknessMinimum !== void 0) materialParams.iridescenceThicknessRange[0] = extension.iridescenceThicknessMinimum;
616
+ if (extension.iridescenceThicknessMaximum !== void 0) materialParams.iridescenceThicknessRange[1] = extension.iridescenceThicknessMaximum;
617
+ if (extension.iridescenceThicknessTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "iridescenceThicknessMap", extension.iridescenceThicknessTexture));
618
+ return Promise.all(pending);
619
+ }
620
+ };
621
+ /**
622
+ * Sheen Materials Extension
623
+ *
624
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
625
+ *
626
+ * @private
627
+ */
628
+ var GLTFMaterialsSheenExtension = class {
629
+ constructor(parser) {
630
+ this.parser = parser;
631
+ this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
632
+ }
633
+ getMaterialType(materialIndex) {
634
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
635
+ }
636
+ extendMaterialParams(materialIndex, materialParams) {
637
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
638
+ if (extension === null) return Promise.resolve();
639
+ const pending = [];
640
+ materialParams.sheenColor = new Color(0, 0, 0);
641
+ materialParams.sheenRoughness = 0;
642
+ materialParams.sheen = 1;
643
+ if (extension.sheenColorFactor !== void 0) {
644
+ const colorFactor = extension.sheenColorFactor;
645
+ materialParams.sheenColor.setRGB(colorFactor[0], colorFactor[1], colorFactor[2], LinearSRGBColorSpace);
646
+ }
647
+ if (extension.sheenRoughnessFactor !== void 0) materialParams.sheenRoughness = extension.sheenRoughnessFactor;
648
+ if (extension.sheenColorTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture, SRGBColorSpace));
649
+ if (extension.sheenRoughnessTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture));
650
+ return Promise.all(pending);
651
+ }
652
+ };
653
+ /**
654
+ * Transmission Materials Extension
655
+ *
656
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
657
+ * Draft: https://github.com/KhronosGroup/glTF/pull/1698
658
+ *
659
+ * @private
660
+ */
661
+ var GLTFMaterialsTransmissionExtension = class {
662
+ constructor(parser) {
663
+ this.parser = parser;
664
+ this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
665
+ }
666
+ getMaterialType(materialIndex) {
667
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
668
+ }
669
+ extendMaterialParams(materialIndex, materialParams) {
670
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
671
+ if (extension === null) return Promise.resolve();
672
+ const pending = [];
673
+ if (extension.transmissionFactor !== void 0) materialParams.transmission = extension.transmissionFactor;
674
+ if (extension.transmissionTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "transmissionMap", extension.transmissionTexture));
675
+ return Promise.all(pending);
676
+ }
677
+ };
678
+ /**
679
+ * Materials Volume Extension
680
+ *
681
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
682
+ *
683
+ * @private
684
+ */
685
+ var GLTFMaterialsVolumeExtension = class {
686
+ constructor(parser) {
687
+ this.parser = parser;
688
+ this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
689
+ }
690
+ getMaterialType(materialIndex) {
691
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
692
+ }
693
+ extendMaterialParams(materialIndex, materialParams) {
694
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
695
+ if (extension === null) return Promise.resolve();
696
+ const pending = [];
697
+ materialParams.thickness = extension.thicknessFactor !== void 0 ? extension.thicknessFactor : 0;
698
+ if (extension.thicknessTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "thicknessMap", extension.thicknessTexture));
699
+ materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
700
+ const colorArray = extension.attenuationColor || [
701
+ 1,
702
+ 1,
703
+ 1
704
+ ];
705
+ materialParams.attenuationColor = new Color().setRGB(colorArray[0], colorArray[1], colorArray[2], LinearSRGBColorSpace);
706
+ return Promise.all(pending);
707
+ }
708
+ };
709
+ /**
710
+ * Materials ior Extension
711
+ *
712
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
713
+ *
714
+ * @private
715
+ */
716
+ var GLTFMaterialsIorExtension = class {
717
+ constructor(parser) {
718
+ this.parser = parser;
719
+ this.name = EXTENSIONS.KHR_MATERIALS_IOR;
720
+ }
721
+ getMaterialType(materialIndex) {
722
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
723
+ }
724
+ extendMaterialParams(materialIndex, materialParams) {
725
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
726
+ if (extension === null) return Promise.resolve();
727
+ materialParams.ior = extension.ior !== void 0 ? extension.ior : 1.5;
728
+ if (materialParams.ior === 0) materialParams.ior = 1e3;
729
+ return Promise.resolve();
730
+ }
731
+ };
732
+ /**
733
+ * Materials specular Extension
734
+ *
735
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
736
+ *
737
+ * @private
738
+ */
739
+ var GLTFMaterialsSpecularExtension = class {
740
+ constructor(parser) {
741
+ this.parser = parser;
742
+ this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
743
+ }
744
+ getMaterialType(materialIndex) {
745
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
746
+ }
747
+ extendMaterialParams(materialIndex, materialParams) {
748
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
749
+ if (extension === null) return Promise.resolve();
750
+ const pending = [];
751
+ materialParams.specularIntensity = extension.specularFactor !== void 0 ? extension.specularFactor : 1;
752
+ if (extension.specularTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "specularIntensityMap", extension.specularTexture));
753
+ const colorArray = extension.specularColorFactor || [
754
+ 1,
755
+ 1,
756
+ 1
757
+ ];
758
+ materialParams.specularColor = new Color().setRGB(colorArray[0], colorArray[1], colorArray[2], LinearSRGBColorSpace);
759
+ if (extension.specularColorTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture, SRGBColorSpace));
760
+ return Promise.all(pending);
761
+ }
762
+ };
763
+ /**
764
+ * Materials bump Extension
765
+ *
766
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump
767
+ *
768
+ * @private
769
+ */
770
+ var GLTFMaterialsBumpExtension = class {
771
+ constructor(parser) {
772
+ this.parser = parser;
773
+ this.name = EXTENSIONS.EXT_MATERIALS_BUMP;
774
+ }
775
+ getMaterialType(materialIndex) {
776
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
777
+ }
778
+ extendMaterialParams(materialIndex, materialParams) {
779
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
780
+ if (extension === null) return Promise.resolve();
781
+ const pending = [];
782
+ materialParams.bumpScale = extension.bumpFactor !== void 0 ? extension.bumpFactor : 1;
783
+ if (extension.bumpTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "bumpMap", extension.bumpTexture));
784
+ return Promise.all(pending);
785
+ }
786
+ };
787
+ /**
788
+ * Materials anisotropy Extension
789
+ *
790
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_anisotropy
791
+ *
792
+ * @private
793
+ */
794
+ var GLTFMaterialsAnisotropyExtension = class {
795
+ constructor(parser) {
796
+ this.parser = parser;
797
+ this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
798
+ }
799
+ getMaterialType(materialIndex) {
800
+ return getMaterialExtension(this.parser, materialIndex, this.name) !== null ? MeshPhysicalMaterial : null;
801
+ }
802
+ extendMaterialParams(materialIndex, materialParams) {
803
+ const extension = getMaterialExtension(this.parser, materialIndex, this.name);
804
+ if (extension === null) return Promise.resolve();
805
+ const pending = [];
806
+ if (extension.anisotropyStrength !== void 0) materialParams.anisotropy = extension.anisotropyStrength;
807
+ if (extension.anisotropyRotation !== void 0) materialParams.anisotropyRotation = extension.anisotropyRotation;
808
+ if (extension.anisotropyTexture !== void 0) pending.push(this.parser.assignTexture(materialParams, "anisotropyMap", extension.anisotropyTexture));
809
+ return Promise.all(pending);
810
+ }
811
+ };
812
+ /**
813
+ * BasisU Texture Extension
814
+ *
815
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
816
+ *
817
+ * @private
818
+ */
819
+ var GLTFTextureBasisUExtension = class {
820
+ constructor(parser) {
821
+ this.parser = parser;
822
+ this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
823
+ }
824
+ loadTexture(textureIndex) {
825
+ const parser = this.parser;
826
+ const json = parser.json;
827
+ const textureDef = json.textures[textureIndex];
828
+ if (!textureDef.extensions || !textureDef.extensions[this.name]) return null;
829
+ const extension = textureDef.extensions[this.name];
830
+ const loader = parser.options.ktx2Loader;
831
+ if (!loader) if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
832
+ else return null;
833
+ return parser.loadTextureImage(textureIndex, extension.source, loader);
834
+ }
835
+ };
836
+ /**
837
+ * WebP Texture Extension
838
+ *
839
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
840
+ *
841
+ * @private
842
+ */
843
+ var GLTFTextureWebPExtension = class {
844
+ constructor(parser) {
845
+ this.parser = parser;
846
+ this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
847
+ }
848
+ loadTexture(textureIndex) {
849
+ const name = this.name;
850
+ const parser = this.parser;
851
+ const json = parser.json;
852
+ const textureDef = json.textures[textureIndex];
853
+ if (!textureDef.extensions || !textureDef.extensions[name]) return null;
854
+ const extension = textureDef.extensions[name];
855
+ const source = json.images[extension.source];
856
+ let loader = parser.textureLoader;
857
+ if (source.uri) {
858
+ const handler = parser.options.manager.getHandler(source.uri);
859
+ if (handler !== null) loader = handler;
860
+ }
861
+ return parser.loadTextureImage(textureIndex, extension.source, loader);
862
+ }
863
+ };
864
+ /**
865
+ * AVIF Texture Extension
866
+ *
867
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_avif
868
+ *
869
+ * @private
870
+ */
871
+ var GLTFTextureAVIFExtension = class {
872
+ constructor(parser) {
873
+ this.parser = parser;
874
+ this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
875
+ }
876
+ loadTexture(textureIndex) {
877
+ const name = this.name;
878
+ const parser = this.parser;
879
+ const json = parser.json;
880
+ const textureDef = json.textures[textureIndex];
881
+ if (!textureDef.extensions || !textureDef.extensions[name]) return null;
882
+ const extension = textureDef.extensions[name];
883
+ const source = json.images[extension.source];
884
+ let loader = parser.textureLoader;
885
+ if (source.uri) {
886
+ const handler = parser.options.manager.getHandler(source.uri);
887
+ if (handler !== null) loader = handler;
888
+ }
889
+ return parser.loadTextureImage(textureIndex, extension.source, loader);
890
+ }
891
+ };
892
+ /**
893
+ * meshopt BufferView Compression Extension
894
+ *
895
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
896
+ *
897
+ * @private
898
+ */
899
+ var GLTFMeshoptCompression = class {
900
+ constructor(parser, name) {
901
+ this.name = name;
902
+ this.parser = parser;
903
+ }
904
+ loadBufferView(index) {
905
+ const json = this.parser.json;
906
+ const bufferView = json.bufferViews[index];
907
+ if (bufferView.extensions && bufferView.extensions[this.name]) {
908
+ const extensionDef = bufferView.extensions[this.name];
909
+ const buffer = this.parser.getDependency("buffer", extensionDef.buffer);
910
+ const decoder = this.parser.options.meshoptDecoder;
911
+ if (!decoder || !decoder.supported) if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
912
+ else return null;
913
+ return buffer.then(function(res) {
914
+ const byteOffset = extensionDef.byteOffset || 0;
915
+ const byteLength = extensionDef.byteLength || 0;
916
+ const count = extensionDef.count;
917
+ const stride = extensionDef.byteStride;
918
+ const source = new Uint8Array(res, byteOffset, byteLength);
919
+ if (decoder.decodeGltfBufferAsync) return decoder.decodeGltfBufferAsync(count, stride, source, extensionDef.mode, extensionDef.filter).then(function(res) {
920
+ return res.buffer;
921
+ });
922
+ else return decoder.ready.then(function() {
923
+ const result = new ArrayBuffer(count * stride);
924
+ decoder.decodeGltfBuffer(new Uint8Array(result), count, stride, source, extensionDef.mode, extensionDef.filter);
925
+ return result;
926
+ });
927
+ });
928
+ } else return null;
929
+ }
930
+ };
931
+ /**
932
+ * GPU Instancing Extension
933
+ *
934
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
935
+ *
936
+ * @private
937
+ */
938
+ var GLTFMeshGpuInstancing = class {
939
+ constructor(parser) {
940
+ this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
941
+ this.parser = parser;
942
+ }
943
+ createNodeMesh(nodeIndex) {
944
+ const json = this.parser.json;
945
+ const nodeDef = json.nodes[nodeIndex];
946
+ if (!nodeDef.extensions || !nodeDef.extensions[this.name] || nodeDef.mesh === void 0) return null;
947
+ const meshDef = json.meshes[nodeDef.mesh];
948
+ for (const primitive of meshDef.primitives) if (primitive.mode !== WEBGL_CONSTANTS.TRIANGLES && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN && primitive.mode !== void 0) return null;
949
+ const attributesDef = nodeDef.extensions[this.name].attributes;
950
+ const pending = [];
951
+ const attributes = {};
952
+ for (const key in attributesDef) pending.push(this.parser.getDependency("accessor", attributesDef[key]).then((accessor) => {
953
+ attributes[key] = accessor;
954
+ return attributes[key];
955
+ }));
956
+ if (pending.length < 1) return null;
957
+ pending.push(this.parser.createNodeMesh(nodeIndex));
958
+ return Promise.all(pending).then((results) => {
959
+ const nodeObject = results.pop();
960
+ const meshes = nodeObject.isGroup ? nodeObject.children : [nodeObject];
961
+ const count = results[0].count;
962
+ const instancedMeshes = [];
963
+ for (const mesh of meshes) {
964
+ const m = new Matrix4();
965
+ const p = new Vector3();
966
+ const q = new Quaternion();
967
+ const s = new Vector3(1, 1, 1);
968
+ const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, count);
969
+ for (let i = 0; i < count; i++) {
970
+ if (attributes.TRANSLATION) p.fromBufferAttribute(attributes.TRANSLATION, i);
971
+ if (attributes.ROTATION) q.fromBufferAttribute(attributes.ROTATION, i);
972
+ if (attributes.SCALE) s.fromBufferAttribute(attributes.SCALE, i);
973
+ instancedMesh.setMatrixAt(i, m.compose(p, q, s));
974
+ }
975
+ for (const attributeName in attributes) if (attributeName === "_COLOR_0") {
976
+ const attr = attributes[attributeName];
977
+ instancedMesh.instanceColor = new InstancedBufferAttribute(attr.array, attr.itemSize, attr.normalized);
978
+ } else if (attributeName !== "TRANSLATION" && attributeName !== "ROTATION" && attributeName !== "SCALE") mesh.geometry.setAttribute(attributeName, attributes[attributeName]);
979
+ Object3D.prototype.copy.call(instancedMesh, mesh);
980
+ this.parser.assignFinalMaterial(instancedMesh);
981
+ instancedMeshes.push(instancedMesh);
982
+ }
983
+ if (nodeObject.isGroup) {
984
+ nodeObject.clear();
985
+ nodeObject.add(...instancedMeshes);
986
+ return nodeObject;
987
+ }
988
+ return instancedMeshes[0];
989
+ });
990
+ }
991
+ };
992
+ var BINARY_EXTENSION_HEADER_MAGIC = "glTF";
993
+ var BINARY_EXTENSION_HEADER_LENGTH = 12;
994
+ var BINARY_EXTENSION_CHUNK_TYPES = {
995
+ JSON: 1313821514,
996
+ BIN: 5130562
997
+ };
998
+ var GLTFBinaryExtension = class {
999
+ constructor(data) {
1000
+ this.name = EXTENSIONS.KHR_BINARY_GLTF;
1001
+ this.content = null;
1002
+ this.body = null;
1003
+ const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
1004
+ const textDecoder = new TextDecoder();
1005
+ this.header = {
1006
+ magic: textDecoder.decode(new Uint8Array(data.slice(0, 4))),
1007
+ version: headerView.getUint32(4, true),
1008
+ length: headerView.getUint32(8, true)
1009
+ };
1010
+ if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
1011
+ else if (this.header.version < 2) throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
1012
+ const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
1013
+ const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
1014
+ let chunkIndex = 0;
1015
+ while (chunkIndex < chunkContentsLength) {
1016
+ const chunkLength = chunkView.getUint32(chunkIndex, true);
1017
+ chunkIndex += 4;
1018
+ const chunkType = chunkView.getUint32(chunkIndex, true);
1019
+ chunkIndex += 4;
1020
+ if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
1021
+ const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
1022
+ this.content = textDecoder.decode(contentArray);
1023
+ } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
1024
+ const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
1025
+ this.body = data.slice(byteOffset, byteOffset + chunkLength);
1026
+ }
1027
+ chunkIndex += chunkLength;
1028
+ }
1029
+ if (this.content === null) throw new Error("THREE.GLTFLoader: JSON content not found.");
1030
+ }
1031
+ };
1032
+ /**
1033
+ * DRACO Mesh Compression Extension
1034
+ *
1035
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
1036
+ *
1037
+ * @private
1038
+ */
1039
+ var GLTFDracoMeshCompressionExtension = class {
1040
+ constructor(json, dracoLoader) {
1041
+ if (!dracoLoader) throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
1042
+ this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
1043
+ this.json = json;
1044
+ this.dracoLoader = dracoLoader;
1045
+ this.dracoLoader.preload();
1046
+ }
1047
+ decodePrimitive(primitive, parser) {
1048
+ const json = this.json;
1049
+ const dracoLoader = this.dracoLoader;
1050
+ const bufferViewIndex = primitive.extensions[this.name].bufferView;
1051
+ const gltfAttributeMap = primitive.extensions[this.name].attributes;
1052
+ const threeAttributeMap = {};
1053
+ const attributeNormalizedMap = {};
1054
+ const attributeTypeMap = {};
1055
+ for (const attributeName in gltfAttributeMap) {
1056
+ const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
1057
+ threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
1058
+ }
1059
+ for (const attributeName in primitive.attributes) {
1060
+ const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
1061
+ if (gltfAttributeMap[attributeName] !== void 0) {
1062
+ const accessorDef = json.accessors[primitive.attributes[attributeName]];
1063
+ attributeTypeMap[threeAttributeName] = WEBGL_COMPONENT_TYPES[accessorDef.componentType].name;
1064
+ attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true;
1065
+ }
1066
+ }
1067
+ return parser.getDependency("bufferView", bufferViewIndex).then(function(bufferView) {
1068
+ return new Promise(function(resolve, reject) {
1069
+ dracoLoader.decodeDracoFile(bufferView, function(geometry) {
1070
+ for (const attributeName in geometry.attributes) {
1071
+ const attribute = geometry.attributes[attributeName];
1072
+ const normalized = attributeNormalizedMap[attributeName];
1073
+ if (normalized !== void 0) attribute.normalized = normalized;
1074
+ }
1075
+ resolve(geometry);
1076
+ }, threeAttributeMap, attributeTypeMap, LinearSRGBColorSpace, reject);
1077
+ });
1078
+ });
1079
+ }
1080
+ };
1081
+ /**
1082
+ * Texture Transform Extension
1083
+ *
1084
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
1085
+ *
1086
+ * @private
1087
+ */
1088
+ var GLTFTextureTransformExtension = class {
1089
+ constructor() {
1090
+ this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
1091
+ }
1092
+ extendTexture(texture, transform) {
1093
+ if ((transform.texCoord === void 0 || transform.texCoord === texture.channel) && transform.offset === void 0 && transform.rotation === void 0 && transform.scale === void 0) return texture;
1094
+ texture = texture.clone();
1095
+ if (transform.texCoord !== void 0) texture.channel = transform.texCoord;
1096
+ if (transform.offset !== void 0) texture.offset.fromArray(transform.offset);
1097
+ if (transform.rotation !== void 0) texture.rotation = transform.rotation;
1098
+ if (transform.scale !== void 0) texture.repeat.fromArray(transform.scale);
1099
+ texture.needsUpdate = true;
1100
+ return texture;
1101
+ }
1102
+ };
1103
+ /**
1104
+ * Mesh Quantization Extension
1105
+ *
1106
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
1107
+ *
1108
+ * @private
1109
+ */
1110
+ var GLTFMeshQuantizationExtension = class {
1111
+ constructor() {
1112
+ this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
1113
+ }
1114
+ };
1115
+ /********** INTERPOLATION ********/
1116
+ var GLTFCubicSplineInterpolant = class extends Interpolant {
1117
+ constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
1118
+ super(parameterPositions, sampleValues, sampleSize, resultBuffer);
1119
+ }
1120
+ copySampleValue_(index) {
1121
+ const result = this.resultBuffer, values = this.sampleValues, valueSize = this.valueSize, offset = index * valueSize * 3 + valueSize;
1122
+ for (let i = 0; i !== valueSize; i++) result[i] = values[offset + i];
1123
+ return result;
1124
+ }
1125
+ interpolate_(i1, t0, t, t1) {
1126
+ const result = this.resultBuffer;
1127
+ const values = this.sampleValues;
1128
+ const stride = this.valueSize;
1129
+ const stride2 = stride * 2;
1130
+ const stride3 = stride * 3;
1131
+ const td = t1 - t0;
1132
+ const p = (t - t0) / td;
1133
+ const pp = p * p;
1134
+ const ppp = pp * p;
1135
+ const offset1 = i1 * stride3;
1136
+ const offset0 = offset1 - stride3;
1137
+ const s2 = -2 * ppp + 3 * pp;
1138
+ const s3 = ppp - pp;
1139
+ const s0 = 1 - s2;
1140
+ const s1 = s3 - pp + p;
1141
+ for (let i = 0; i !== stride; i++) {
1142
+ const p0 = values[offset0 + i + stride];
1143
+ const m0 = values[offset0 + i + stride2] * td;
1144
+ const p1 = values[offset1 + i + stride];
1145
+ const m1 = values[offset1 + i] * td;
1146
+ result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1147
+ }
1148
+ return result;
1149
+ }
1150
+ };
1151
+ var _quaternion = new Quaternion();
1152
+ var GLTFCubicSplineQuaternionInterpolant = class extends GLTFCubicSplineInterpolant {
1153
+ interpolate_(i1, t0, t, t1) {
1154
+ const result = super.interpolate_(i1, t0, t, t1);
1155
+ _quaternion.fromArray(result).normalize().toArray(result);
1156
+ return result;
1157
+ }
1158
+ };
1159
+ /********** INTERNALS ************/
1160
+ var WEBGL_CONSTANTS = {
1161
+ FLOAT: 5126,
1162
+ FLOAT_MAT3: 35675,
1163
+ FLOAT_MAT4: 35676,
1164
+ FLOAT_VEC2: 35664,
1165
+ FLOAT_VEC3: 35665,
1166
+ FLOAT_VEC4: 35666,
1167
+ LINEAR: 9729,
1168
+ REPEAT: 10497,
1169
+ SAMPLER_2D: 35678,
1170
+ POINTS: 0,
1171
+ LINES: 1,
1172
+ LINE_LOOP: 2,
1173
+ LINE_STRIP: 3,
1174
+ TRIANGLES: 4,
1175
+ TRIANGLE_STRIP: 5,
1176
+ TRIANGLE_FAN: 6,
1177
+ UNSIGNED_BYTE: 5121,
1178
+ UNSIGNED_SHORT: 5123
1179
+ };
1180
+ var WEBGL_COMPONENT_TYPES = {
1181
+ 5120: Int8Array,
1182
+ 5121: Uint8Array,
1183
+ 5122: Int16Array,
1184
+ 5123: Uint16Array,
1185
+ 5125: Uint32Array,
1186
+ 5126: Float32Array
1187
+ };
1188
+ var WEBGL_FILTERS = {
1189
+ 9728: NearestFilter,
1190
+ 9729: LinearFilter,
1191
+ 9984: NearestMipmapNearestFilter,
1192
+ 9985: LinearMipmapNearestFilter,
1193
+ 9986: NearestMipmapLinearFilter,
1194
+ 9987: LinearMipmapLinearFilter
1195
+ };
1196
+ var WEBGL_WRAPPINGS = {
1197
+ 33071: ClampToEdgeWrapping,
1198
+ 33648: MirroredRepeatWrapping,
1199
+ 10497: RepeatWrapping
1200
+ };
1201
+ var WEBGL_TYPE_SIZES = {
1202
+ "SCALAR": 1,
1203
+ "VEC2": 2,
1204
+ "VEC3": 3,
1205
+ "VEC4": 4,
1206
+ "MAT2": 4,
1207
+ "MAT3": 9,
1208
+ "MAT4": 16
1209
+ };
1210
+ var ATTRIBUTES = {
1211
+ POSITION: "position",
1212
+ NORMAL: "normal",
1213
+ TANGENT: "tangent",
1214
+ TEXCOORD_0: "uv",
1215
+ TEXCOORD_1: "uv1",
1216
+ TEXCOORD_2: "uv2",
1217
+ TEXCOORD_3: "uv3",
1218
+ COLOR_0: "color",
1219
+ WEIGHTS_0: "skinWeight",
1220
+ JOINTS_0: "skinIndex"
1221
+ };
1222
+ var PATH_PROPERTIES = {
1223
+ scale: "scale",
1224
+ translation: "position",
1225
+ rotation: "quaternion",
1226
+ weights: "morphTargetInfluences"
1227
+ };
1228
+ var INTERPOLATION = {
1229
+ CUBICSPLINE: void 0,
1230
+ LINEAR: InterpolateLinear,
1231
+ STEP: InterpolateDiscrete
1232
+ };
1233
+ var ALPHA_MODES = {
1234
+ OPAQUE: "OPAQUE",
1235
+ MASK: "MASK",
1236
+ BLEND: "BLEND"
1237
+ };
1238
+ /**
1239
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
1240
+ *
1241
+ * @private
1242
+ * @param {Object<string, Material>} cache
1243
+ * @return {Material}
1244
+ */
1245
+ function createDefaultMaterial(cache) {
1246
+ if (cache["DefaultMaterial"] === void 0) cache["DefaultMaterial"] = new MeshStandardMaterial({
1247
+ color: 16777215,
1248
+ emissive: 0,
1249
+ metalness: 1,
1250
+ roughness: 1,
1251
+ transparent: false,
1252
+ depthTest: true,
1253
+ side: 0
1254
+ });
1255
+ return cache["DefaultMaterial"];
1256
+ }
1257
+ function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
1258
+ for (const name in objectDef.extensions) if (knownExtensions[name] === void 0) {
1259
+ object.userData.gltfExtensions = object.userData.gltfExtensions || {};
1260
+ object.userData.gltfExtensions[name] = objectDef.extensions[name];
1261
+ }
1262
+ }
1263
+ /**
1264
+ *
1265
+ * @private
1266
+ * @param {Object3D|Material|BufferGeometry|Object|AnimationClip} object
1267
+ * @param {GLTF.definition} gltfDef
1268
+ */
1269
+ function assignExtrasToUserData(object, gltfDef) {
1270
+ if (gltfDef.extras !== void 0) if (typeof gltfDef.extras === "object") Object.assign(object.userData, gltfDef.extras);
1271
+ else console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + gltfDef.extras);
1272
+ }
1273
+ /**
1274
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
1275
+ *
1276
+ * @private
1277
+ * @param {BufferGeometry} geometry
1278
+ * @param {Array<GLTF.Target>} targets
1279
+ * @param {GLTFParser} parser
1280
+ * @return {Promise<BufferGeometry>}
1281
+ */
1282
+ function addMorphTargets(geometry, targets, parser) {
1283
+ let hasMorphPosition = false;
1284
+ let hasMorphNormal = false;
1285
+ let hasMorphColor = false;
1286
+ for (let i = 0, il = targets.length; i < il; i++) {
1287
+ const target = targets[i];
1288
+ if (target.POSITION !== void 0) hasMorphPosition = true;
1289
+ if (target.NORMAL !== void 0) hasMorphNormal = true;
1290
+ if (target.COLOR_0 !== void 0) hasMorphColor = true;
1291
+ if (hasMorphPosition && hasMorphNormal && hasMorphColor) break;
1292
+ }
1293
+ if (!hasMorphPosition && !hasMorphNormal && !hasMorphColor) return Promise.resolve(geometry);
1294
+ const pendingPositionAccessors = [];
1295
+ const pendingNormalAccessors = [];
1296
+ const pendingColorAccessors = [];
1297
+ for (let i = 0, il = targets.length; i < il; i++) {
1298
+ const target = targets[i];
1299
+ if (hasMorphPosition) {
1300
+ const pendingAccessor = target.POSITION !== void 0 ? parser.getDependency("accessor", target.POSITION) : geometry.attributes.position;
1301
+ pendingPositionAccessors.push(pendingAccessor);
1302
+ }
1303
+ if (hasMorphNormal) {
1304
+ const pendingAccessor = target.NORMAL !== void 0 ? parser.getDependency("accessor", target.NORMAL) : geometry.attributes.normal;
1305
+ pendingNormalAccessors.push(pendingAccessor);
1306
+ }
1307
+ if (hasMorphColor) {
1308
+ const pendingAccessor = target.COLOR_0 !== void 0 ? parser.getDependency("accessor", target.COLOR_0) : geometry.attributes.color;
1309
+ pendingColorAccessors.push(pendingAccessor);
1310
+ }
1311
+ }
1312
+ return Promise.all([
1313
+ Promise.all(pendingPositionAccessors),
1314
+ Promise.all(pendingNormalAccessors),
1315
+ Promise.all(pendingColorAccessors)
1316
+ ]).then(function(accessors) {
1317
+ const morphPositions = accessors[0];
1318
+ const morphNormals = accessors[1];
1319
+ const morphColors = accessors[2];
1320
+ if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
1321
+ if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
1322
+ if (hasMorphColor) geometry.morphAttributes.color = morphColors;
1323
+ geometry.morphTargetsRelative = true;
1324
+ return geometry;
1325
+ });
1326
+ }
1327
+ /**
1328
+ *
1329
+ * @private
1330
+ * @param {Mesh} mesh
1331
+ * @param {GLTF.Mesh} meshDef
1332
+ */
1333
+ function updateMorphTargets(mesh, meshDef) {
1334
+ mesh.updateMorphTargets();
1335
+ if (meshDef.weights !== void 0) for (let i = 0, il = meshDef.weights.length; i < il; i++) mesh.morphTargetInfluences[i] = meshDef.weights[i];
1336
+ if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
1337
+ const targetNames = meshDef.extras.targetNames;
1338
+ if (mesh.morphTargetInfluences.length === targetNames.length) {
1339
+ mesh.morphTargetDictionary = {};
1340
+ for (let i = 0, il = targetNames.length; i < il; i++) mesh.morphTargetDictionary[targetNames[i]] = i;
1341
+ } else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
1342
+ }
1343
+ }
1344
+ function createPrimitiveKey(primitiveDef) {
1345
+ let geometryKey;
1346
+ const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1347
+ if (dracoExtension) geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
1348
+ else geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
1349
+ if (primitiveDef.targets !== void 0) for (let i = 0, il = primitiveDef.targets.length; i < il; i++) geometryKey += ":" + createAttributesKey(primitiveDef.targets[i]);
1350
+ return geometryKey;
1351
+ }
1352
+ function createAttributesKey(attributes) {
1353
+ let attributesKey = "";
1354
+ const keys = Object.keys(attributes).sort();
1355
+ for (let i = 0, il = keys.length; i < il; i++) attributesKey += keys[i] + ":" + attributes[keys[i]] + ";";
1356
+ return attributesKey;
1357
+ }
1358
+ function getNormalizedComponentScale(constructor) {
1359
+ switch (constructor) {
1360
+ case Int8Array: return 1 / 127;
1361
+ case Uint8Array: return 1 / 255;
1362
+ case Int16Array: return 1 / 32767;
1363
+ case Uint16Array: return 1 / 65535;
1364
+ default: throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
1365
+ }
1366
+ }
1367
+ function getImageURIMimeType(uri) {
1368
+ if (uri.search(/\.jpe?g($|\?)/i) > 0 || uri.search(/^data\:image\/jpeg/) === 0) return "image/jpeg";
1369
+ if (uri.search(/\.webp($|\?)/i) > 0 || uri.search(/^data\:image\/webp/) === 0) return "image/webp";
1370
+ if (uri.search(/\.ktx2($|\?)/i) > 0 || uri.search(/^data\:image\/ktx2/) === 0) return "image/ktx2";
1371
+ return "image/png";
1372
+ }
1373
+ var _identityMatrix = new Matrix4();
1374
+ var GLTFParser = class {
1375
+ constructor(json = {}, options = {}) {
1376
+ this.json = json;
1377
+ this.extensions = {};
1378
+ this.plugins = {};
1379
+ this.options = options;
1380
+ this.cache = new GLTFRegistry();
1381
+ this.associations = /* @__PURE__ */ new Map();
1382
+ this.primitiveCache = {};
1383
+ this.nodeCache = {};
1384
+ this.meshCache = {
1385
+ refs: {},
1386
+ uses: {}
1387
+ };
1388
+ this.cameraCache = {
1389
+ refs: {},
1390
+ uses: {}
1391
+ };
1392
+ this.lightCache = {
1393
+ refs: {},
1394
+ uses: {}
1395
+ };
1396
+ this.sourceCache = {};
1397
+ this.textureCache = {};
1398
+ this.nodeNamesUsed = {};
1399
+ let isSafari = false;
1400
+ let safariVersion = -1;
1401
+ let isFirefox = false;
1402
+ let firefoxVersion = -1;
1403
+ if (typeof navigator !== "undefined" && typeof navigator.userAgent !== "undefined") {
1404
+ const userAgent = navigator.userAgent;
1405
+ isSafari = /^((?!chrome|android).)*safari/i.test(userAgent) === true;
1406
+ const safariMatch = userAgent.match(/Version\/(\d+)/);
1407
+ safariVersion = isSafari && safariMatch ? parseInt(safariMatch[1], 10) : -1;
1408
+ isFirefox = userAgent.indexOf("Firefox") > -1;
1409
+ firefoxVersion = isFirefox ? userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1;
1410
+ }
1411
+ if (typeof createImageBitmap === "undefined" || isSafari && safariVersion < 17 || isFirefox && firefoxVersion < 98) this.textureLoader = new TextureLoader(this.options.manager);
1412
+ else this.textureLoader = new ImageBitmapLoader(this.options.manager);
1413
+ this.textureLoader.setCrossOrigin(this.options.crossOrigin);
1414
+ this.textureLoader.setRequestHeader(this.options.requestHeader);
1415
+ this.fileLoader = new FileLoader(this.options.manager);
1416
+ this.fileLoader.setResponseType("arraybuffer");
1417
+ if (this.options.crossOrigin === "use-credentials") this.fileLoader.setWithCredentials(true);
1418
+ }
1419
+ setExtensions(extensions) {
1420
+ this.extensions = extensions;
1421
+ }
1422
+ setPlugins(plugins) {
1423
+ this.plugins = plugins;
1424
+ }
1425
+ parse(onLoad, onError) {
1426
+ const parser = this;
1427
+ const json = this.json;
1428
+ const extensions = this.extensions;
1429
+ this.cache.removeAll();
1430
+ this.nodeCache = {};
1431
+ this._invokeAll(function(ext) {
1432
+ return ext._markDefs && ext._markDefs();
1433
+ });
1434
+ Promise.all(this._invokeAll(function(ext) {
1435
+ return ext.beforeRoot && ext.beforeRoot();
1436
+ })).then(function() {
1437
+ return Promise.all([
1438
+ parser.getDependencies("scene"),
1439
+ parser.getDependencies("animation"),
1440
+ parser.getDependencies("camera")
1441
+ ]);
1442
+ }).then(function(dependencies) {
1443
+ const result = {
1444
+ scene: dependencies[0][json.scene || 0],
1445
+ scenes: dependencies[0],
1446
+ animations: dependencies[1],
1447
+ cameras: dependencies[2],
1448
+ asset: json.asset,
1449
+ parser,
1450
+ userData: {}
1451
+ };
1452
+ addUnknownExtensionsToUserData(extensions, result, json);
1453
+ assignExtrasToUserData(result, json);
1454
+ return Promise.all(parser._invokeAll(function(ext) {
1455
+ return ext.afterRoot && ext.afterRoot(result);
1456
+ })).then(function() {
1457
+ for (const scene of result.scenes) scene.updateMatrixWorld();
1458
+ onLoad(result);
1459
+ });
1460
+ }).catch(onError);
1461
+ }
1462
+ /**
1463
+ * Marks the special nodes/meshes in json for efficient parse.
1464
+ *
1465
+ * @private
1466
+ */
1467
+ _markDefs() {
1468
+ const nodeDefs = this.json.nodes || [];
1469
+ const skinDefs = this.json.skins || [];
1470
+ const meshDefs = this.json.meshes || [];
1471
+ for (let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
1472
+ const joints = skinDefs[skinIndex].joints;
1473
+ for (let i = 0, il = joints.length; i < il; i++) nodeDefs[joints[i]].isBone = true;
1474
+ }
1475
+ for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
1476
+ const nodeDef = nodeDefs[nodeIndex];
1477
+ if (nodeDef.mesh !== void 0) {
1478
+ this._addNodeRef(this.meshCache, nodeDef.mesh);
1479
+ if (nodeDef.skin !== void 0) meshDefs[nodeDef.mesh].isSkinnedMesh = true;
1480
+ }
1481
+ if (nodeDef.camera !== void 0) this._addNodeRef(this.cameraCache, nodeDef.camera);
1482
+ }
1483
+ }
1484
+ /**
1485
+ * Counts references to shared node / Object3D resources. These resources
1486
+ * can be reused, or "instantiated", at multiple nodes in the scene
1487
+ * hierarchy. Mesh, Camera, and Light instances are instantiated and must
1488
+ * be marked. Non-scenegraph resources (like Materials, Geometries, and
1489
+ * Textures) can be reused directly and are not marked here.
1490
+ *
1491
+ * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
1492
+ *
1493
+ * @private
1494
+ * @param {Object} cache
1495
+ * @param {Object3D} index
1496
+ */
1497
+ _addNodeRef(cache, index) {
1498
+ if (index === void 0) return;
1499
+ if (cache.refs[index] === void 0) cache.refs[index] = cache.uses[index] = 0;
1500
+ cache.refs[index]++;
1501
+ }
1502
+ /**
1503
+ * Returns a reference to a shared resource, cloning it if necessary.
1504
+ *
1505
+ * @private
1506
+ * @param {Object} cache
1507
+ * @param {number} index
1508
+ * @param {Object} object
1509
+ * @return {Object}
1510
+ */
1511
+ _getNodeRef(cache, index, object) {
1512
+ if (cache.refs[index] <= 1) return object;
1513
+ const ref = object.clone();
1514
+ const updateMappings = (original, clone) => {
1515
+ const mappings = this.associations.get(original);
1516
+ if (mappings != null) this.associations.set(clone, mappings);
1517
+ for (const [i, child] of original.children.entries()) updateMappings(child, clone.children[i]);
1518
+ };
1519
+ updateMappings(object, ref);
1520
+ ref.name += "_instance_" + cache.uses[index]++;
1521
+ return ref;
1522
+ }
1523
+ _invokeOne(func) {
1524
+ const extensions = Object.values(this.plugins);
1525
+ extensions.push(this);
1526
+ for (let i = 0; i < extensions.length; i++) {
1527
+ const result = func(extensions[i]);
1528
+ if (result) return result;
1529
+ }
1530
+ return null;
1531
+ }
1532
+ _invokeAll(func) {
1533
+ const extensions = Object.values(this.plugins);
1534
+ extensions.unshift(this);
1535
+ const pending = [];
1536
+ for (let i = 0; i < extensions.length; i++) {
1537
+ const result = func(extensions[i]);
1538
+ if (result) pending.push(result);
1539
+ }
1540
+ return pending;
1541
+ }
1542
+ /**
1543
+ * Requests the specified dependency asynchronously, with caching.
1544
+ *
1545
+ * @private
1546
+ * @param {string} type
1547
+ * @param {number} index
1548
+ * @return {Promise<Object3D|Material|Texture|AnimationClip|ArrayBuffer|Object>}
1549
+ */
1550
+ getDependency(type, index) {
1551
+ const cacheKey = type + ":" + index;
1552
+ let dependency = this.cache.get(cacheKey);
1553
+ if (!dependency) {
1554
+ switch (type) {
1555
+ case "scene":
1556
+ dependency = this.loadScene(index);
1557
+ break;
1558
+ case "node":
1559
+ dependency = this._invokeOne(function(ext) {
1560
+ return ext.loadNode && ext.loadNode(index);
1561
+ });
1562
+ break;
1563
+ case "mesh":
1564
+ dependency = this._invokeOne(function(ext) {
1565
+ return ext.loadMesh && ext.loadMesh(index);
1566
+ });
1567
+ break;
1568
+ case "accessor":
1569
+ dependency = this.loadAccessor(index);
1570
+ break;
1571
+ case "bufferView":
1572
+ dependency = this._invokeOne(function(ext) {
1573
+ return ext.loadBufferView && ext.loadBufferView(index);
1574
+ });
1575
+ break;
1576
+ case "buffer":
1577
+ dependency = this.loadBuffer(index);
1578
+ break;
1579
+ case "material":
1580
+ dependency = this._invokeOne(function(ext) {
1581
+ return ext.loadMaterial && ext.loadMaterial(index);
1582
+ });
1583
+ break;
1584
+ case "texture":
1585
+ dependency = this._invokeOne(function(ext) {
1586
+ return ext.loadTexture && ext.loadTexture(index);
1587
+ });
1588
+ break;
1589
+ case "skin":
1590
+ dependency = this.loadSkin(index);
1591
+ break;
1592
+ case "animation":
1593
+ dependency = this._invokeOne(function(ext) {
1594
+ return ext.loadAnimation && ext.loadAnimation(index);
1595
+ });
1596
+ break;
1597
+ case "camera":
1598
+ dependency = this.loadCamera(index);
1599
+ break;
1600
+ default:
1601
+ dependency = this._invokeOne(function(ext) {
1602
+ return ext != this && ext.getDependency && ext.getDependency(type, index);
1603
+ });
1604
+ if (!dependency) throw new Error("Unknown type: " + type);
1605
+ break;
1606
+ }
1607
+ this.cache.add(cacheKey, dependency);
1608
+ }
1609
+ return dependency;
1610
+ }
1611
+ /**
1612
+ * Requests all dependencies of the specified type asynchronously, with caching.
1613
+ *
1614
+ * @private
1615
+ * @param {string} type
1616
+ * @return {Promise<Array<Object>>}
1617
+ */
1618
+ getDependencies(type) {
1619
+ let dependencies = this.cache.get(type);
1620
+ if (!dependencies) {
1621
+ const parser = this;
1622
+ const defs = this.json[type + (type === "mesh" ? "es" : "s")] || [];
1623
+ dependencies = Promise.all(defs.map(function(def, index) {
1624
+ return parser.getDependency(type, index);
1625
+ }));
1626
+ this.cache.add(type, dependencies);
1627
+ }
1628
+ return dependencies;
1629
+ }
1630
+ /**
1631
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1632
+ *
1633
+ * @private
1634
+ * @param {number} bufferIndex
1635
+ * @return {Promise<ArrayBuffer>}
1636
+ */
1637
+ loadBuffer(bufferIndex) {
1638
+ const bufferDef = this.json.buffers[bufferIndex];
1639
+ const loader = this.fileLoader;
1640
+ if (bufferDef.type && bufferDef.type !== "arraybuffer") throw new Error("THREE.GLTFLoader: " + bufferDef.type + " buffer type is not supported.");
1641
+ if (bufferDef.uri === void 0 && bufferIndex === 0) return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
1642
+ const options = this.options;
1643
+ return new Promise(function(resolve, reject) {
1644
+ loader.load(LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, void 0, function() {
1645
+ reject(/* @__PURE__ */ new Error("THREE.GLTFLoader: Failed to load buffer \"" + bufferDef.uri + "\"."));
1646
+ });
1647
+ });
1648
+ }
1649
+ /**
1650
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1651
+ *
1652
+ * @private
1653
+ * @param {number} bufferViewIndex
1654
+ * @return {Promise<ArrayBuffer>}
1655
+ */
1656
+ loadBufferView(bufferViewIndex) {
1657
+ const bufferViewDef = this.json.bufferViews[bufferViewIndex];
1658
+ return this.getDependency("buffer", bufferViewDef.buffer).then(function(buffer) {
1659
+ const byteLength = bufferViewDef.byteLength || 0;
1660
+ const byteOffset = bufferViewDef.byteOffset || 0;
1661
+ return buffer.slice(byteOffset, byteOffset + byteLength);
1662
+ });
1663
+ }
1664
+ /**
1665
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
1666
+ *
1667
+ * @private
1668
+ * @param {number} accessorIndex
1669
+ * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
1670
+ */
1671
+ loadAccessor(accessorIndex) {
1672
+ const parser = this;
1673
+ const json = this.json;
1674
+ const accessorDef = this.json.accessors[accessorIndex];
1675
+ if (accessorDef.bufferView === void 0 && accessorDef.sparse === void 0) {
1676
+ const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
1677
+ const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
1678
+ const normalized = accessorDef.normalized === true;
1679
+ const array = new TypedArray(accessorDef.count * itemSize);
1680
+ return Promise.resolve(new BufferAttribute(array, itemSize, normalized));
1681
+ }
1682
+ const pendingBufferViews = [];
1683
+ if (accessorDef.bufferView !== void 0) pendingBufferViews.push(this.getDependency("bufferView", accessorDef.bufferView));
1684
+ else pendingBufferViews.push(null);
1685
+ if (accessorDef.sparse !== void 0) {
1686
+ pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.indices.bufferView));
1687
+ pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.values.bufferView));
1688
+ }
1689
+ return Promise.all(pendingBufferViews).then(function(bufferViews) {
1690
+ const bufferView = bufferViews[0];
1691
+ const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
1692
+ const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
1693
+ const elementBytes = TypedArray.BYTES_PER_ELEMENT;
1694
+ const itemBytes = elementBytes * itemSize;
1695
+ const byteOffset = accessorDef.byteOffset || 0;
1696
+ const byteStride = accessorDef.bufferView !== void 0 ? json.bufferViews[accessorDef.bufferView].byteStride : void 0;
1697
+ const normalized = accessorDef.normalized === true;
1698
+ let array, bufferAttribute;
1699
+ if (byteStride && byteStride !== itemBytes) {
1700
+ const ibSlice = Math.floor(byteOffset / byteStride);
1701
+ const ibCacheKey = "InterleavedBuffer:" + accessorDef.bufferView + ":" + accessorDef.componentType + ":" + ibSlice + ":" + accessorDef.count;
1702
+ let ib = parser.cache.get(ibCacheKey);
1703
+ if (!ib) {
1704
+ array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes);
1705
+ ib = new InterleavedBuffer(array, byteStride / elementBytes);
1706
+ parser.cache.add(ibCacheKey, ib);
1707
+ }
1708
+ bufferAttribute = new InterleavedBufferAttribute(ib, itemSize, byteOffset % byteStride / elementBytes, normalized);
1709
+ } else {
1710
+ if (bufferView === null) array = new TypedArray(accessorDef.count * itemSize);
1711
+ else array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
1712
+ bufferAttribute = new BufferAttribute(array, itemSize, normalized);
1713
+ }
1714
+ if (accessorDef.sparse !== void 0) {
1715
+ const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
1716
+ const TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
1717
+ const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
1718
+ const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
1719
+ const sparseIndices = new TypedArrayIndices(bufferViews[1], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices);
1720
+ const sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
1721
+ if (bufferView !== null) bufferAttribute = new BufferAttribute(bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized);
1722
+ bufferAttribute.normalized = false;
1723
+ for (let i = 0, il = sparseIndices.length; i < il; i++) {
1724
+ const index = sparseIndices[i];
1725
+ bufferAttribute.setX(index, sparseValues[i * itemSize]);
1726
+ if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
1727
+ if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
1728
+ if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
1729
+ if (itemSize >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
1730
+ }
1731
+ bufferAttribute.normalized = normalized;
1732
+ }
1733
+ return bufferAttribute;
1734
+ });
1735
+ }
1736
+ /**
1737
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
1738
+ *
1739
+ * @private
1740
+ * @param {number} textureIndex
1741
+ * @return {Promise<?Texture>}
1742
+ */
1743
+ loadTexture(textureIndex) {
1744
+ const json = this.json;
1745
+ const options = this.options;
1746
+ const sourceIndex = json.textures[textureIndex].source;
1747
+ const sourceDef = json.images[sourceIndex];
1748
+ let loader = this.textureLoader;
1749
+ if (sourceDef.uri) {
1750
+ const handler = options.manager.getHandler(sourceDef.uri);
1751
+ if (handler !== null) loader = handler;
1752
+ }
1753
+ return this.loadTextureImage(textureIndex, sourceIndex, loader);
1754
+ }
1755
+ loadTextureImage(textureIndex, sourceIndex, loader) {
1756
+ const parser = this;
1757
+ const json = this.json;
1758
+ const textureDef = json.textures[textureIndex];
1759
+ const sourceDef = json.images[sourceIndex];
1760
+ const cacheKey = (sourceDef.uri || sourceDef.bufferView) + ":" + textureDef.sampler;
1761
+ if (this.textureCache[cacheKey]) return this.textureCache[cacheKey];
1762
+ const promise = this.loadImageSource(sourceIndex, loader).then(function(texture) {
1763
+ texture.flipY = false;
1764
+ texture.name = textureDef.name || sourceDef.name || "";
1765
+ if (texture.name === "" && typeof sourceDef.uri === "string" && sourceDef.uri.startsWith("data:image/") === false) texture.name = sourceDef.uri;
1766
+ const sampler = (json.samplers || {})[textureDef.sampler] || {};
1767
+ texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || 1006;
1768
+ texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || 1008;
1769
+ texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || 1e3;
1770
+ texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || 1e3;
1771
+ texture.generateMipmaps = !texture.isCompressedTexture && texture.minFilter !== 1003 && texture.minFilter !== 1006;
1772
+ parser.associations.set(texture, { textures: textureIndex });
1773
+ return texture;
1774
+ }).catch(function() {
1775
+ return null;
1776
+ });
1777
+ this.textureCache[cacheKey] = promise;
1778
+ return promise;
1779
+ }
1780
+ loadImageSource(sourceIndex, loader) {
1781
+ const parser = this;
1782
+ const json = this.json;
1783
+ const options = this.options;
1784
+ if (this.sourceCache[sourceIndex] !== void 0) return this.sourceCache[sourceIndex].then((texture) => texture.clone());
1785
+ const sourceDef = json.images[sourceIndex];
1786
+ const URL = self.URL || self.webkitURL;
1787
+ let sourceURI = sourceDef.uri || "";
1788
+ let isObjectURL = false;
1789
+ if (sourceDef.bufferView !== void 0) sourceURI = parser.getDependency("bufferView", sourceDef.bufferView).then(function(bufferView) {
1790
+ isObjectURL = true;
1791
+ const blob = new Blob([bufferView], { type: sourceDef.mimeType });
1792
+ sourceURI = URL.createObjectURL(blob);
1793
+ return sourceURI;
1794
+ });
1795
+ else if (sourceDef.uri === void 0) throw new Error("THREE.GLTFLoader: Image " + sourceIndex + " is missing URI and bufferView");
1796
+ const promise = Promise.resolve(sourceURI).then(function(sourceURI) {
1797
+ return new Promise(function(resolve, reject) {
1798
+ let onLoad = resolve;
1799
+ if (loader.isImageBitmapLoader === true) onLoad = function(imageBitmap) {
1800
+ const texture = new Texture(imageBitmap);
1801
+ texture.needsUpdate = true;
1802
+ resolve(texture);
1803
+ };
1804
+ loader.load(LoaderUtils.resolveURL(sourceURI, options.path), onLoad, void 0, reject);
1805
+ });
1806
+ }).then(function(texture) {
1807
+ if (isObjectURL === true) URL.revokeObjectURL(sourceURI);
1808
+ assignExtrasToUserData(texture, sourceDef);
1809
+ texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType(sourceDef.uri);
1810
+ return texture;
1811
+ }).catch(function(error) {
1812
+ console.error("THREE.GLTFLoader: Couldn't load texture", sourceURI);
1813
+ throw error;
1814
+ });
1815
+ this.sourceCache[sourceIndex] = promise;
1816
+ return promise;
1817
+ }
1818
+ /**
1819
+ * Asynchronously assigns a texture to the given material parameters.
1820
+ *
1821
+ * @private
1822
+ * @param {Object} materialParams
1823
+ * @param {string} mapName
1824
+ * @param {Object} mapDef
1825
+ * @param {string} [colorSpace]
1826
+ * @return {Promise<Texture>}
1827
+ */
1828
+ assignTexture(materialParams, mapName, mapDef, colorSpace) {
1829
+ const parser = this;
1830
+ return this.getDependency("texture", mapDef.index).then(function(texture) {
1831
+ if (!texture) return null;
1832
+ if (mapDef.texCoord !== void 0 && mapDef.texCoord > 0) {
1833
+ texture = texture.clone();
1834
+ texture.channel = mapDef.texCoord;
1835
+ }
1836
+ if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
1837
+ const transform = mapDef.extensions !== void 0 ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : void 0;
1838
+ if (transform) {
1839
+ const gltfReference = parser.associations.get(texture);
1840
+ texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
1841
+ parser.associations.set(texture, gltfReference);
1842
+ }
1843
+ }
1844
+ if (colorSpace !== void 0) texture.colorSpace = colorSpace;
1845
+ materialParams[mapName] = texture;
1846
+ return texture;
1847
+ });
1848
+ }
1849
+ /**
1850
+ * Assigns final material to a Mesh, Line, or Points instance. The instance
1851
+ * already has a material (generated from the glTF material options alone)
1852
+ * but reuse of the same glTF material may require multiple threejs materials
1853
+ * to accommodate different primitive types, defines, etc. New materials will
1854
+ * be created if necessary, and reused from a cache.
1855
+ *
1856
+ * @private
1857
+ * @param {Object3D} mesh Mesh, Line, or Points instance.
1858
+ */
1859
+ assignFinalMaterial(mesh) {
1860
+ const geometry = mesh.geometry;
1861
+ let material = mesh.material;
1862
+ const useDerivativeTangents = geometry.attributes.tangent === void 0;
1863
+ const useVertexColors = geometry.attributes.color !== void 0;
1864
+ const useFlatShading = geometry.attributes.normal === void 0;
1865
+ if (mesh.isPoints) {
1866
+ const cacheKey = "PointsMaterial:" + material.uuid;
1867
+ let pointsMaterial = this.cache.get(cacheKey);
1868
+ if (!pointsMaterial) {
1869
+ pointsMaterial = new PointsMaterial();
1870
+ Material.prototype.copy.call(pointsMaterial, material);
1871
+ pointsMaterial.color.copy(material.color);
1872
+ pointsMaterial.map = material.map;
1873
+ pointsMaterial.sizeAttenuation = false;
1874
+ this.cache.add(cacheKey, pointsMaterial);
1875
+ }
1876
+ material = pointsMaterial;
1877
+ } else if (mesh.isLine) {
1878
+ const cacheKey = "LineBasicMaterial:" + material.uuid;
1879
+ let lineMaterial = this.cache.get(cacheKey);
1880
+ if (!lineMaterial) {
1881
+ lineMaterial = new LineBasicMaterial();
1882
+ Material.prototype.copy.call(lineMaterial, material);
1883
+ lineMaterial.color.copy(material.color);
1884
+ lineMaterial.map = material.map;
1885
+ this.cache.add(cacheKey, lineMaterial);
1886
+ }
1887
+ material = lineMaterial;
1888
+ }
1889
+ if (useDerivativeTangents || useVertexColors || useFlatShading) {
1890
+ let cacheKey = "ClonedMaterial:" + material.uuid + ":";
1891
+ if (useDerivativeTangents) cacheKey += "derivative-tangents:";
1892
+ if (useVertexColors) cacheKey += "vertex-colors:";
1893
+ if (useFlatShading) cacheKey += "flat-shading:";
1894
+ let cachedMaterial = this.cache.get(cacheKey);
1895
+ if (!cachedMaterial) {
1896
+ cachedMaterial = material.clone();
1897
+ if (useVertexColors) cachedMaterial.vertexColors = true;
1898
+ if (useFlatShading) cachedMaterial.flatShading = true;
1899
+ if (useDerivativeTangents) {
1900
+ if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
1901
+ if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
1902
+ }
1903
+ this.cache.add(cacheKey, cachedMaterial);
1904
+ this.associations.set(cachedMaterial, this.associations.get(material));
1905
+ }
1906
+ material = cachedMaterial;
1907
+ }
1908
+ mesh.material = material;
1909
+ }
1910
+ getMaterialType() {
1911
+ return MeshStandardMaterial;
1912
+ }
1913
+ /**
1914
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
1915
+ *
1916
+ * @private
1917
+ * @param {number} materialIndex
1918
+ * @return {Promise<Material>}
1919
+ */
1920
+ loadMaterial(materialIndex) {
1921
+ const parser = this;
1922
+ const json = this.json;
1923
+ const extensions = this.extensions;
1924
+ const materialDef = json.materials[materialIndex];
1925
+ let materialType;
1926
+ const materialParams = {};
1927
+ const materialExtensions = materialDef.extensions || {};
1928
+ const pending = [];
1929
+ if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
1930
+ const kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
1931
+ materialType = kmuExtension.getMaterialType();
1932
+ pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
1933
+ } else {
1934
+ const metallicRoughness = materialDef.pbrMetallicRoughness || {};
1935
+ materialParams.color = new Color(1, 1, 1);
1936
+ materialParams.opacity = 1;
1937
+ if (Array.isArray(metallicRoughness.baseColorFactor)) {
1938
+ const array = metallicRoughness.baseColorFactor;
1939
+ materialParams.color.setRGB(array[0], array[1], array[2], LinearSRGBColorSpace);
1940
+ materialParams.opacity = array[3];
1941
+ }
1942
+ if (metallicRoughness.baseColorTexture !== void 0) pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture, SRGBColorSpace));
1943
+ materialParams.metalness = metallicRoughness.metallicFactor !== void 0 ? metallicRoughness.metallicFactor : 1;
1944
+ materialParams.roughness = metallicRoughness.roughnessFactor !== void 0 ? metallicRoughness.roughnessFactor : 1;
1945
+ if (metallicRoughness.metallicRoughnessTexture !== void 0) {
1946
+ pending.push(parser.assignTexture(materialParams, "metalnessMap", metallicRoughness.metallicRoughnessTexture));
1947
+ pending.push(parser.assignTexture(materialParams, "roughnessMap", metallicRoughness.metallicRoughnessTexture));
1948
+ }
1949
+ materialType = this._invokeOne(function(ext) {
1950
+ return ext.getMaterialType && ext.getMaterialType(materialIndex);
1951
+ });
1952
+ pending.push(Promise.all(this._invokeAll(function(ext) {
1953
+ return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
1954
+ })));
1955
+ }
1956
+ if (materialDef.doubleSided === true) materialParams.side = 2;
1957
+ const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
1958
+ if (alphaMode === ALPHA_MODES.BLEND) {
1959
+ materialParams.transparent = true;
1960
+ materialParams.depthWrite = false;
1961
+ } else {
1962
+ materialParams.transparent = false;
1963
+ if (alphaMode === ALPHA_MODES.MASK) materialParams.alphaTest = materialDef.alphaCutoff !== void 0 ? materialDef.alphaCutoff : .5;
1964
+ }
1965
+ if (materialDef.normalTexture !== void 0 && materialType !== MeshBasicMaterial) {
1966
+ pending.push(parser.assignTexture(materialParams, "normalMap", materialDef.normalTexture));
1967
+ materialParams.normalScale = new Vector2(1, 1);
1968
+ if (materialDef.normalTexture.scale !== void 0) {
1969
+ const scale = materialDef.normalTexture.scale;
1970
+ materialParams.normalScale.set(scale, scale);
1971
+ }
1972
+ }
1973
+ if (materialDef.occlusionTexture !== void 0 && materialType !== MeshBasicMaterial) {
1974
+ pending.push(parser.assignTexture(materialParams, "aoMap", materialDef.occlusionTexture));
1975
+ if (materialDef.occlusionTexture.strength !== void 0) materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
1976
+ }
1977
+ if (materialDef.emissiveFactor !== void 0 && materialType !== MeshBasicMaterial) {
1978
+ const emissiveFactor = materialDef.emissiveFactor;
1979
+ materialParams.emissive = new Color().setRGB(emissiveFactor[0], emissiveFactor[1], emissiveFactor[2], LinearSRGBColorSpace);
1980
+ }
1981
+ if (materialDef.emissiveTexture !== void 0 && materialType !== MeshBasicMaterial) pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture, SRGBColorSpace));
1982
+ return Promise.all(pending).then(function() {
1983
+ const material = new materialType(materialParams);
1984
+ if (materialDef.name) material.name = materialDef.name;
1985
+ assignExtrasToUserData(material, materialDef);
1986
+ parser.associations.set(material, { materials: materialIndex });
1987
+ if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
1988
+ return material;
1989
+ });
1990
+ }
1991
+ /**
1992
+ * When Object3D instances are targeted by animation, they need unique names.
1993
+ *
1994
+ * @private
1995
+ * @param {string} originalName
1996
+ * @return {string}
1997
+ */
1998
+ createUniqueName(originalName) {
1999
+ const sanitizedName = PropertyBinding.sanitizeNodeName(originalName || "");
2000
+ if (sanitizedName in this.nodeNamesUsed) return sanitizedName + "_" + ++this.nodeNamesUsed[sanitizedName];
2001
+ else {
2002
+ this.nodeNamesUsed[sanitizedName] = 0;
2003
+ return sanitizedName;
2004
+ }
2005
+ }
2006
+ /**
2007
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
2008
+ *
2009
+ * Creates BufferGeometries from primitives.
2010
+ *
2011
+ * @private
2012
+ * @param {Array<GLTF.Primitive>} primitives
2013
+ * @return {Promise<Array<BufferGeometry>>}
2014
+ */
2015
+ loadGeometries(primitives) {
2016
+ const parser = this;
2017
+ const extensions = this.extensions;
2018
+ const cache = this.primitiveCache;
2019
+ function createDracoPrimitive(primitive) {
2020
+ return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function(geometry) {
2021
+ return addPrimitiveAttributes(geometry, primitive, parser);
2022
+ });
2023
+ }
2024
+ const pending = [];
2025
+ for (let i = 0, il = primitives.length; i < il; i++) {
2026
+ const primitive = primitives[i];
2027
+ const cacheKey = createPrimitiveKey(primitive);
2028
+ const cached = cache[cacheKey];
2029
+ if (cached) pending.push(cached.promise);
2030
+ else {
2031
+ let geometryPromise;
2032
+ if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) geometryPromise = createDracoPrimitive(primitive);
2033
+ else geometryPromise = addPrimitiveAttributes(new BufferGeometry(), primitive, parser);
2034
+ cache[cacheKey] = {
2035
+ primitive,
2036
+ promise: geometryPromise
2037
+ };
2038
+ pending.push(geometryPromise);
2039
+ }
2040
+ }
2041
+ return Promise.all(pending);
2042
+ }
2043
+ /**
2044
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
2045
+ *
2046
+ * @private
2047
+ * @param {number} meshIndex
2048
+ * @return {Promise<Group|Mesh|SkinnedMesh|Line|Points>}
2049
+ */
2050
+ loadMesh(meshIndex) {
2051
+ const parser = this;
2052
+ const json = this.json;
2053
+ const extensions = this.extensions;
2054
+ const meshDef = json.meshes[meshIndex];
2055
+ const primitives = meshDef.primitives;
2056
+ const pending = [];
2057
+ for (let i = 0, il = primitives.length; i < il; i++) {
2058
+ const material = primitives[i].material === void 0 ? createDefaultMaterial(this.cache) : this.getDependency("material", primitives[i].material);
2059
+ pending.push(material);
2060
+ }
2061
+ pending.push(parser.loadGeometries(primitives));
2062
+ return Promise.all(pending).then(function(results) {
2063
+ const materials = results.slice(0, results.length - 1);
2064
+ const geometries = results[results.length - 1];
2065
+ const meshes = [];
2066
+ for (let i = 0, il = geometries.length; i < il; i++) {
2067
+ const geometry = geometries[i];
2068
+ const primitive = primitives[i];
2069
+ let mesh;
2070
+ const material = materials[i];
2071
+ if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === void 0) {
2072
+ mesh = meshDef.isSkinnedMesh === true ? new SkinnedMesh(geometry, material) : new Mesh(geometry, material);
2073
+ if (mesh.isSkinnedMesh === true) mesh.normalizeSkinWeights();
2074
+ if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) mesh.geometry = toTrianglesDrawMode(mesh.geometry, 1);
2075
+ else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) mesh.geometry = toTrianglesDrawMode(mesh.geometry, 2);
2076
+ } else if (primitive.mode === WEBGL_CONSTANTS.LINES) mesh = new LineSegments(geometry, material);
2077
+ else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) mesh = new Line(geometry, material);
2078
+ else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) mesh = new LineLoop(geometry, material);
2079
+ else if (primitive.mode === WEBGL_CONSTANTS.POINTS) mesh = new Points(geometry, material);
2080
+ else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + primitive.mode);
2081
+ if (Object.keys(mesh.geometry.morphAttributes).length > 0) updateMorphTargets(mesh, meshDef);
2082
+ mesh.name = parser.createUniqueName(meshDef.name || "mesh_" + meshIndex);
2083
+ assignExtrasToUserData(mesh, meshDef);
2084
+ if (primitive.extensions) addUnknownExtensionsToUserData(extensions, mesh, primitive);
2085
+ parser.assignFinalMaterial(mesh);
2086
+ meshes.push(mesh);
2087
+ }
2088
+ for (let i = 0, il = meshes.length; i < il; i++) parser.associations.set(meshes[i], {
2089
+ meshes: meshIndex,
2090
+ primitives: i
2091
+ });
2092
+ if (meshes.length === 1) {
2093
+ if (meshDef.extensions) addUnknownExtensionsToUserData(extensions, meshes[0], meshDef);
2094
+ return meshes[0];
2095
+ }
2096
+ const group = new Group();
2097
+ if (meshDef.extensions) addUnknownExtensionsToUserData(extensions, group, meshDef);
2098
+ parser.associations.set(group, { meshes: meshIndex });
2099
+ for (let i = 0, il = meshes.length; i < il; i++) group.add(meshes[i]);
2100
+ return group;
2101
+ });
2102
+ }
2103
+ /**
2104
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
2105
+ *
2106
+ * @private
2107
+ * @param {number} cameraIndex
2108
+ * @return {Promise<Camera>|undefined}
2109
+ */
2110
+ loadCamera(cameraIndex) {
2111
+ let camera;
2112
+ const cameraDef = this.json.cameras[cameraIndex];
2113
+ const params = cameraDef[cameraDef.type];
2114
+ if (!params) {
2115
+ console.warn("THREE.GLTFLoader: Missing camera parameters.");
2116
+ return;
2117
+ }
2118
+ if (cameraDef.type === "perspective") camera = new PerspectiveCamera(MathUtils.radToDeg(params.yfov), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6);
2119
+ else if (cameraDef.type === "orthographic") camera = new OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
2120
+ if (cameraDef.name) camera.name = this.createUniqueName(cameraDef.name);
2121
+ assignExtrasToUserData(camera, cameraDef);
2122
+ return Promise.resolve(camera);
2123
+ }
2124
+ /**
2125
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
2126
+ *
2127
+ * @private
2128
+ * @param {number} skinIndex
2129
+ * @return {Promise<Skeleton>}
2130
+ */
2131
+ loadSkin(skinIndex) {
2132
+ const skinDef = this.json.skins[skinIndex];
2133
+ const pending = [];
2134
+ for (let i = 0, il = skinDef.joints.length; i < il; i++) pending.push(this._loadNodeShallow(skinDef.joints[i]));
2135
+ if (skinDef.inverseBindMatrices !== void 0) pending.push(this.getDependency("accessor", skinDef.inverseBindMatrices));
2136
+ else pending.push(null);
2137
+ return Promise.all(pending).then(function(results) {
2138
+ const inverseBindMatrices = results.pop();
2139
+ const jointNodes = results;
2140
+ const bones = [];
2141
+ const boneInverses = [];
2142
+ for (let i = 0, il = jointNodes.length; i < il; i++) {
2143
+ const jointNode = jointNodes[i];
2144
+ if (jointNode) {
2145
+ bones.push(jointNode);
2146
+ const mat = new Matrix4();
2147
+ if (inverseBindMatrices !== null) mat.fromArray(inverseBindMatrices.array, i * 16);
2148
+ boneInverses.push(mat);
2149
+ } else console.warn("THREE.GLTFLoader: Joint \"%s\" could not be found.", skinDef.joints[i]);
2150
+ }
2151
+ return new Skeleton(bones, boneInverses);
2152
+ });
2153
+ }
2154
+ /**
2155
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
2156
+ *
2157
+ * @private
2158
+ * @param {number} animationIndex
2159
+ * @return {Promise<AnimationClip>}
2160
+ */
2161
+ loadAnimation(animationIndex) {
2162
+ const json = this.json;
2163
+ const parser = this;
2164
+ const animationDef = json.animations[animationIndex];
2165
+ const animationName = animationDef.name ? animationDef.name : "animation_" + animationIndex;
2166
+ const pendingNodes = [];
2167
+ const pendingInputAccessors = [];
2168
+ const pendingOutputAccessors = [];
2169
+ const pendingSamplers = [];
2170
+ const pendingTargets = [];
2171
+ for (let i = 0, il = animationDef.channels.length; i < il; i++) {
2172
+ const channel = animationDef.channels[i];
2173
+ const sampler = animationDef.samplers[channel.sampler];
2174
+ const target = channel.target;
2175
+ const name = target.node;
2176
+ const input = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.input] : sampler.input;
2177
+ const output = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.output] : sampler.output;
2178
+ if (target.node === void 0) continue;
2179
+ pendingNodes.push(this.getDependency("node", name));
2180
+ pendingInputAccessors.push(this.getDependency("accessor", input));
2181
+ pendingOutputAccessors.push(this.getDependency("accessor", output));
2182
+ pendingSamplers.push(sampler);
2183
+ pendingTargets.push(target);
2184
+ }
2185
+ return Promise.all([
2186
+ Promise.all(pendingNodes),
2187
+ Promise.all(pendingInputAccessors),
2188
+ Promise.all(pendingOutputAccessors),
2189
+ Promise.all(pendingSamplers),
2190
+ Promise.all(pendingTargets)
2191
+ ]).then(function(dependencies) {
2192
+ const nodes = dependencies[0];
2193
+ const inputAccessors = dependencies[1];
2194
+ const outputAccessors = dependencies[2];
2195
+ const samplers = dependencies[3];
2196
+ const targets = dependencies[4];
2197
+ const tracks = [];
2198
+ for (let i = 0, il = nodes.length; i < il; i++) {
2199
+ const node = nodes[i];
2200
+ const inputAccessor = inputAccessors[i];
2201
+ const outputAccessor = outputAccessors[i];
2202
+ const sampler = samplers[i];
2203
+ const target = targets[i];
2204
+ if (node === void 0) continue;
2205
+ if (node.updateMatrix) node.updateMatrix();
2206
+ const createdTracks = parser._createAnimationTracks(node, inputAccessor, outputAccessor, sampler, target);
2207
+ if (createdTracks) for (let k = 0; k < createdTracks.length; k++) tracks.push(createdTracks[k]);
2208
+ }
2209
+ const animation = new AnimationClip(animationName, void 0, tracks);
2210
+ assignExtrasToUserData(animation, animationDef);
2211
+ return animation;
2212
+ });
2213
+ }
2214
+ createNodeMesh(nodeIndex) {
2215
+ const json = this.json;
2216
+ const parser = this;
2217
+ const nodeDef = json.nodes[nodeIndex];
2218
+ if (nodeDef.mesh === void 0) return null;
2219
+ return parser.getDependency("mesh", nodeDef.mesh).then(function(mesh) {
2220
+ const node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh);
2221
+ if (nodeDef.weights !== void 0) node.traverse(function(o) {
2222
+ if (!o.isMesh) return;
2223
+ for (let i = 0, il = nodeDef.weights.length; i < il; i++) o.morphTargetInfluences[i] = nodeDef.weights[i];
2224
+ });
2225
+ return node;
2226
+ });
2227
+ }
2228
+ /**
2229
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
2230
+ *
2231
+ * @private
2232
+ * @param {number} nodeIndex
2233
+ * @return {Promise<Object3D>}
2234
+ */
2235
+ loadNode(nodeIndex) {
2236
+ const json = this.json;
2237
+ const parser = this;
2238
+ const nodeDef = json.nodes[nodeIndex];
2239
+ const nodePending = parser._loadNodeShallow(nodeIndex);
2240
+ const childPending = [];
2241
+ const childrenDef = nodeDef.children || [];
2242
+ for (let i = 0, il = childrenDef.length; i < il; i++) childPending.push(parser.getDependency("node", childrenDef[i]));
2243
+ const skeletonPending = nodeDef.skin === void 0 ? Promise.resolve(null) : parser.getDependency("skin", nodeDef.skin);
2244
+ return Promise.all([
2245
+ nodePending,
2246
+ Promise.all(childPending),
2247
+ skeletonPending
2248
+ ]).then(function(results) {
2249
+ const node = results[0];
2250
+ const children = results[1];
2251
+ const skeleton = results[2];
2252
+ if (skeleton !== null) node.traverse(function(mesh) {
2253
+ if (!mesh.isSkinnedMesh) return;
2254
+ mesh.bind(skeleton, _identityMatrix);
2255
+ });
2256
+ for (let i = 0, il = children.length; i < il; i++) node.add(children[i]);
2257
+ if (node.userData.pivot !== void 0 && children.length > 0) {
2258
+ const pivot = node.userData.pivot;
2259
+ const pivotChild = children[0];
2260
+ node.pivot = new Vector3().fromArray(pivot);
2261
+ node.position.x -= pivot[0];
2262
+ node.position.y -= pivot[1];
2263
+ node.position.z -= pivot[2];
2264
+ pivotChild.position.set(0, 0, 0);
2265
+ delete node.userData.pivot;
2266
+ }
2267
+ return node;
2268
+ });
2269
+ }
2270
+ _loadNodeShallow(nodeIndex) {
2271
+ const json = this.json;
2272
+ const extensions = this.extensions;
2273
+ const parser = this;
2274
+ if (this.nodeCache[nodeIndex] !== void 0) return this.nodeCache[nodeIndex];
2275
+ const nodeDef = json.nodes[nodeIndex];
2276
+ const nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : "";
2277
+ const pending = [];
2278
+ const meshPromise = parser._invokeOne(function(ext) {
2279
+ return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
2280
+ });
2281
+ if (meshPromise) pending.push(meshPromise);
2282
+ if (nodeDef.camera !== void 0) pending.push(parser.getDependency("camera", nodeDef.camera).then(function(camera) {
2283
+ return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
2284
+ }));
2285
+ parser._invokeAll(function(ext) {
2286
+ return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
2287
+ }).forEach(function(promise) {
2288
+ pending.push(promise);
2289
+ });
2290
+ this.nodeCache[nodeIndex] = Promise.all(pending).then(function(objects) {
2291
+ let node;
2292
+ if (nodeDef.isBone === true) node = new Bone();
2293
+ else if (objects.length > 1) node = new Group();
2294
+ else if (objects.length === 1) node = objects[0];
2295
+ else node = new Object3D();
2296
+ if (node !== objects[0]) for (let i = 0, il = objects.length; i < il; i++) node.add(objects[i]);
2297
+ if (nodeDef.name) {
2298
+ node.userData.name = nodeDef.name;
2299
+ node.name = nodeName;
2300
+ }
2301
+ assignExtrasToUserData(node, nodeDef);
2302
+ if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
2303
+ if (nodeDef.matrix !== void 0) {
2304
+ const matrix = new Matrix4();
2305
+ matrix.fromArray(nodeDef.matrix);
2306
+ node.applyMatrix4(matrix);
2307
+ } else {
2308
+ if (nodeDef.translation !== void 0) node.position.fromArray(nodeDef.translation);
2309
+ if (nodeDef.rotation !== void 0) node.quaternion.fromArray(nodeDef.rotation);
2310
+ if (nodeDef.scale !== void 0) node.scale.fromArray(nodeDef.scale);
2311
+ }
2312
+ if (!parser.associations.has(node)) parser.associations.set(node, {});
2313
+ else if (nodeDef.mesh !== void 0 && parser.meshCache.refs[nodeDef.mesh] > 1) {
2314
+ const mapping = parser.associations.get(node);
2315
+ parser.associations.set(node, { ...mapping });
2316
+ }
2317
+ parser.associations.get(node).nodes = nodeIndex;
2318
+ return node;
2319
+ });
2320
+ return this.nodeCache[nodeIndex];
2321
+ }
2322
+ /**
2323
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
2324
+ *
2325
+ * @private
2326
+ * @param {number} sceneIndex
2327
+ * @return {Promise<Group>}
2328
+ */
2329
+ loadScene(sceneIndex) {
2330
+ const extensions = this.extensions;
2331
+ const sceneDef = this.json.scenes[sceneIndex];
2332
+ const parser = this;
2333
+ const scene = new Group();
2334
+ if (sceneDef.name) scene.name = parser.createUniqueName(sceneDef.name);
2335
+ assignExtrasToUserData(scene, sceneDef);
2336
+ if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
2337
+ const nodeIds = sceneDef.nodes || [];
2338
+ const pending = [];
2339
+ for (let i = 0, il = nodeIds.length; i < il; i++) pending.push(parser.getDependency("node", nodeIds[i]));
2340
+ return Promise.all(pending).then(function(nodes) {
2341
+ for (let i = 0, il = nodes.length; i < il; i++) {
2342
+ const node = nodes[i];
2343
+ if (node.parent !== null) scene.add(clone(node));
2344
+ else scene.add(node);
2345
+ }
2346
+ const reduceAssociations = (node) => {
2347
+ const reducedAssociations = /* @__PURE__ */ new Map();
2348
+ for (const [key, value] of parser.associations) if (key instanceof Material || key instanceof Texture) reducedAssociations.set(key, value);
2349
+ node.traverse((node) => {
2350
+ const mappings = parser.associations.get(node);
2351
+ if (mappings != null) reducedAssociations.set(node, mappings);
2352
+ });
2353
+ return reducedAssociations;
2354
+ };
2355
+ parser.associations = reduceAssociations(scene);
2356
+ return scene;
2357
+ });
2358
+ }
2359
+ _createAnimationTracks(node, inputAccessor, outputAccessor, sampler, target) {
2360
+ const tracks = [];
2361
+ const targetName = node.name ? node.name : node.uuid;
2362
+ const targetNames = [];
2363
+ function collectMorphTargets(object) {
2364
+ if (object.morphTargetInfluences) targetNames.push(object.name ? object.name : object.uuid);
2365
+ }
2366
+ if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
2367
+ collectMorphTargets(node);
2368
+ if (node.isGroup) node.children.forEach(collectMorphTargets);
2369
+ } else targetNames.push(targetName);
2370
+ let TypedKeyframeTrack;
2371
+ switch (PATH_PROPERTIES[target.path]) {
2372
+ case PATH_PROPERTIES.weights:
2373
+ TypedKeyframeTrack = NumberKeyframeTrack;
2374
+ break;
2375
+ case PATH_PROPERTIES.rotation:
2376
+ TypedKeyframeTrack = QuaternionKeyframeTrack;
2377
+ break;
2378
+ case PATH_PROPERTIES.translation:
2379
+ case PATH_PROPERTIES.scale:
2380
+ TypedKeyframeTrack = VectorKeyframeTrack;
2381
+ break;
2382
+ default:
2383
+ switch (outputAccessor.itemSize) {
2384
+ case 1:
2385
+ TypedKeyframeTrack = NumberKeyframeTrack;
2386
+ break;
2387
+ default:
2388
+ TypedKeyframeTrack = VectorKeyframeTrack;
2389
+ break;
2390
+ }
2391
+ break;
2392
+ }
2393
+ const interpolation = sampler.interpolation !== void 0 ? INTERPOLATION[sampler.interpolation] : InterpolateLinear;
2394
+ const outputArray = this._getArrayFromAccessor(outputAccessor);
2395
+ for (let j = 0, jl = targetNames.length; j < jl; j++) {
2396
+ const track = new TypedKeyframeTrack(targetNames[j] + "." + PATH_PROPERTIES[target.path], inputAccessor.array, outputArray, interpolation);
2397
+ if (sampler.interpolation === "CUBICSPLINE") this._createCubicSplineTrackInterpolant(track);
2398
+ tracks.push(track);
2399
+ }
2400
+ return tracks;
2401
+ }
2402
+ _getArrayFromAccessor(accessor) {
2403
+ let outputArray = accessor.array;
2404
+ if (accessor.normalized) {
2405
+ const scale = getNormalizedComponentScale(outputArray.constructor);
2406
+ const scaled = new Float32Array(outputArray.length);
2407
+ for (let j = 0, jl = outputArray.length; j < jl; j++) scaled[j] = outputArray[j] * scale;
2408
+ outputArray = scaled;
2409
+ }
2410
+ return outputArray;
2411
+ }
2412
+ _createCubicSplineTrackInterpolant(track) {
2413
+ track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
2414
+ return new (this instanceof QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant)(this.times, this.values, this.getValueSize() / 3, result);
2415
+ };
2416
+ track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
2417
+ }
2418
+ };
2419
+ /**
2420
+ *
2421
+ * @private
2422
+ * @param {BufferGeometry} geometry
2423
+ * @param {GLTF.Primitive} primitiveDef
2424
+ * @param {GLTFParser} parser
2425
+ */
2426
+ function computeBounds(geometry, primitiveDef, parser) {
2427
+ const attributes = primitiveDef.attributes;
2428
+ const box = new Box3();
2429
+ if (attributes.POSITION !== void 0) {
2430
+ const accessor = parser.json.accessors[attributes.POSITION];
2431
+ const min = accessor.min;
2432
+ const max = accessor.max;
2433
+ if (min !== void 0 && max !== void 0) {
2434
+ box.set(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]));
2435
+ if (accessor.normalized) {
2436
+ const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
2437
+ box.min.multiplyScalar(boxScale);
2438
+ box.max.multiplyScalar(boxScale);
2439
+ }
2440
+ } else {
2441
+ console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
2442
+ return;
2443
+ }
2444
+ } else return;
2445
+ const targets = primitiveDef.targets;
2446
+ if (targets !== void 0) {
2447
+ const maxDisplacement = new Vector3();
2448
+ const vector = new Vector3();
2449
+ for (let i = 0, il = targets.length; i < il; i++) {
2450
+ const target = targets[i];
2451
+ if (target.POSITION !== void 0) {
2452
+ const accessor = parser.json.accessors[target.POSITION];
2453
+ const min = accessor.min;
2454
+ const max = accessor.max;
2455
+ if (min !== void 0 && max !== void 0) {
2456
+ vector.setX(Math.max(Math.abs(min[0]), Math.abs(max[0])));
2457
+ vector.setY(Math.max(Math.abs(min[1]), Math.abs(max[1])));
2458
+ vector.setZ(Math.max(Math.abs(min[2]), Math.abs(max[2])));
2459
+ if (accessor.normalized) {
2460
+ const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
2461
+ vector.multiplyScalar(boxScale);
2462
+ }
2463
+ maxDisplacement.max(vector);
2464
+ } else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
2465
+ }
2466
+ }
2467
+ box.expandByVector(maxDisplacement);
2468
+ }
2469
+ geometry.boundingBox = box;
2470
+ const sphere = new Sphere();
2471
+ box.getCenter(sphere.center);
2472
+ sphere.radius = box.min.distanceTo(box.max) / 2;
2473
+ geometry.boundingSphere = sphere;
2474
+ }
2475
+ /**
2476
+ *
2477
+ * @private
2478
+ * @param {BufferGeometry} geometry
2479
+ * @param {GLTF.Primitive} primitiveDef
2480
+ * @param {GLTFParser} parser
2481
+ * @return {Promise<BufferGeometry>}
2482
+ */
2483
+ function addPrimitiveAttributes(geometry, primitiveDef, parser) {
2484
+ const attributes = primitiveDef.attributes;
2485
+ const pending = [];
2486
+ function assignAttributeAccessor(accessorIndex, attributeName) {
2487
+ return parser.getDependency("accessor", accessorIndex).then(function(accessor) {
2488
+ geometry.setAttribute(attributeName, accessor);
2489
+ });
2490
+ }
2491
+ for (const gltfAttributeName in attributes) {
2492
+ const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase();
2493
+ if (threeAttributeName in geometry.attributes) continue;
2494
+ pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
2495
+ }
2496
+ if (primitiveDef.indices !== void 0 && !geometry.index) {
2497
+ const accessor = parser.getDependency("accessor", primitiveDef.indices).then(function(accessor) {
2498
+ geometry.setIndex(accessor);
2499
+ });
2500
+ pending.push(accessor);
2501
+ }
2502
+ if (ColorManagement.workingColorSpace !== "srgb-linear" && "COLOR_0" in attributes) console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.`);
2503
+ assignExtrasToUserData(geometry, primitiveDef);
2504
+ computeBounds(geometry, primitiveDef, parser);
2505
+ return Promise.all(pending).then(function() {
2506
+ return primitiveDef.targets !== void 0 ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
2507
+ });
2508
+ }
2509
+ //#endregion
2510
+ export { GLTFLoader };
2511
+
2512
+ //# sourceMappingURL=three_addons_loaders_GLTFLoader__js.js.map