@aixa-transformation/pptx-viewer 2.0.2

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