@galacean/engine-loader 1.0.0 → 1.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 (65) hide show
  1. package/dist/main.js +1764 -1208
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +1784 -1228
  4. package/dist/module.js +1751 -1210
  5. package/dist/module.js.map +1 -1
  6. package/package.json +5 -5
  7. package/types/AnimationClipLoader.d.ts +1 -0
  8. package/types/GLTFContentRestorer.d.ts +92 -0
  9. package/types/GLTFLoader.d.ts +3 -0
  10. package/types/ProjectLoader.d.ts +1 -0
  11. package/types/Texture2DContentRestorer.d.ts +11 -0
  12. package/types/TextureCubeContentRestorer.d.ts +11 -0
  13. package/types/gltf/GLTFPipeline.d.ts +23 -0
  14. package/types/gltf/GLTFResource.d.ts +7 -15
  15. package/types/gltf/GLTFSchema.d.ts +816 -0
  16. package/types/gltf/GLTFUtil.d.ts +1 -1
  17. package/types/gltf/GLTFUtils.d.ts +48 -0
  18. package/types/gltf/extensions/GALACEAN_animation_event.d.ts +1 -0
  19. package/types/gltf/extensions/GLTFExtensionParser.d.ts +52 -0
  20. package/types/gltf/extensions/GLTFExtensionSchema.d.ts +149 -0
  21. package/types/gltf/extensions/KHR_materials_ior.d.ts +1 -0
  22. package/types/gltf/extensions/KHR_materials_variants.d.ts +6 -1
  23. package/types/gltf/extensions/index.d.ts +5 -1
  24. package/types/gltf/index.d.ts +6 -0
  25. package/types/gltf/parser/GLTFAnimationParser.d.ts +12 -0
  26. package/types/gltf/parser/GLTFBufferParser.d.ts +7 -0
  27. package/types/gltf/parser/GLTFEntityParser.d.ts +9 -0
  28. package/types/gltf/parser/GLTFMaterialParser.d.ts +15 -0
  29. package/types/gltf/parser/GLTFMeshParser.d.ts +19 -0
  30. package/types/gltf/parser/GLTFParser.d.ts +63 -0
  31. package/types/gltf/parser/GLTFParserContext.d.ts +53 -0
  32. package/types/gltf/parser/GLTFSceneParser.d.ts +11 -0
  33. package/types/gltf/parser/GLTFSchemaParser.d.ts +7 -0
  34. package/types/gltf/parser/GLTFSkinParser.d.ts +7 -0
  35. package/types/gltf/parser/GLTFTextureParser.d.ts +9 -0
  36. package/types/gltf/parser/GLTFValidator.d.ts +6 -0
  37. package/types/gltf/parser/index.d.ts +11 -0
  38. package/types/index.d.ts +2 -2
  39. package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +13 -0
  40. package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +33 -0
  41. package/types/ktx2/KTX2Container.d.ts +72 -0
  42. package/types/ktx2/KTX2Loader.d.ts +53 -0
  43. package/types/ktx2/KTX2TargetFormat.d.ts +21 -0
  44. package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +17 -0
  45. package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +34 -0
  46. package/types/ktx2/TranscodeResult.d.ts +10 -0
  47. package/types/ktx2/WorkerPool.d.ts +32 -0
  48. package/types/ktx2/constants.d.ts +7 -0
  49. package/types/ktx2/transcoder/AbstractTranscoder.d.ts +55 -0
  50. package/types/ktx2/transcoder/BinomialLLCTranscoder.d.ts +8 -0
  51. package/types/ktx2/transcoder/BinomialLLCWorkerCode.d.ts +6 -0
  52. package/types/ktx2/transcoder/KhronosTranscoder.d.ts +13 -0
  53. package/types/ktx2/transcoder/KhronosWorkerCode.d.ts +1 -0
  54. package/types/ktx2/zstddec.d.ts +62 -0
  55. package/types/resource-deserialize/index.d.ts +3 -3
  56. package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +1 -1
  57. package/types/resource-deserialize/resources/parser/PrefabParser.d.ts +5 -0
  58. package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +14 -0
  59. package/types/resource-deserialize/resources/scene/SceneParser.d.ts +1 -1
  60. package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +1 -1
  61. package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +61 -0
  62. package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +91 -0
  63. package/types/resource-deserialize/resources/schema/ProjectSchema.d.ts +9 -0
  64. package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +41 -0
  65. package/types/resource-deserialize/resources/schema/index.d.ts +3 -0
package/dist/main.js CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var engineCore = require('@galacean/engine-core');
6
6
  var engineMath = require('@galacean/engine-math');
7
- var engineDraco = require('@galacean/engine-draco');
8
7
  var engineRhiWebgl = require('@galacean/engine-rhi-webgl');
8
+ var engineDraco = require('@galacean/engine-draco');
9
9
 
10
10
  function _extends() {
11
11
  _extends = Object.assign || function assign(target) {
@@ -90,10 +90,10 @@ function __generator(thisArg, body) {
90
90
  }
91
91
  }
92
92
 
93
- var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
94
- _inherits(AnimatorControllerLoader, Loader);
93
+ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
94
+ _inherits(AnimatorControllerLoader, Loader1);
95
95
  function AnimatorControllerLoader() {
96
- return Loader.apply(this, arguments);
96
+ return Loader1.apply(this, arguments);
97
97
  }
98
98
  var _proto = AnimatorControllerLoader.prototype;
99
99
  _proto.load = function load(item, resourceManager) {
@@ -114,13 +114,17 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
114
114
  var states = stateMachineData.states;
115
115
  var stateMachine = layer.stateMachine = new engineCore.AnimatorStateMachine();
116
116
  states.forEach(function(stateData, stateIndex) {
117
- var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
117
+ var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip, scripts = stateData.scripts;
118
118
  var state = stateMachine.addState(name);
119
119
  isDefaultState && (stateMachine.defaultState = state);
120
120
  state.speed = speed;
121
121
  state.wrapMode = wrapMode;
122
122
  state.clipStartTime = clipStartNormalizedTime;
123
123
  state.clipEndTime = clipEndNormalizedTime;
124
+ var scriptsObject = JSON.parse(scripts);
125
+ scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
126
+ state.addStateMachineScript(engineCore.Loader.getClass(script));
127
+ });
124
128
  if (clipData) {
125
129
  promises.push(new Promise(function(resolve) {
126
130
  //@ts-ignore
@@ -218,7 +222,8 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
218
222
  var shArray = new Float32Array(arraybuffer, 0, 27);
219
223
  var shByteLength = 27 * 4;
220
224
  var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
221
- var texture = new engineCore.TextureCube(resourceManager.engine, size);
225
+ var engine = resourceManager.engine;
226
+ var texture = new engineCore.TextureCube(engine, size);
222
227
  texture.filterMode = engineCore.TextureFilterMode.Trilinear;
223
228
  var mipmapCount = texture.mipmapCount;
224
229
  var offset = shByteLength + 2;
@@ -231,7 +236,7 @@ var EnvLoader = /*#__PURE__*/ function(Loader) {
231
236
  texture.setPixelBuffer(engineCore.TextureCubeFace.PositiveX + face, data, mipLevel);
232
237
  }
233
238
  }
234
- var ambientLight = new engineCore.AmbientLight();
239
+ var ambientLight = new engineCore.AmbientLight(engine);
235
240
  var sh = new engineMath.SphericalHarmonics3();
236
241
  ambientLight.diffuseMode = engineCore.DiffuseMode.SphericalHarmonics;
237
242
  sh.copyFromArray(shArray);
@@ -341,52 +346,205 @@ FontLoader = __decorate([
341
346
  ], false)
342
347
  ], FontLoader);
343
348
 
349
+ function _array_like_to_array(arr, len) {
350
+ if (len == null || len > arr.length) len = arr.length;
351
+
352
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
353
+
354
+ return arr2;
355
+ }
356
+
357
+ function _unsupported_iterable_to_array(o, minLen) {
358
+ if (!o) return;
359
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
360
+
361
+ var n = Object.prototype.toString.call(o).slice(8, -1);
362
+
363
+ if (n === "Object" && o.constructor) n = o.constructor.name;
364
+ if (n === "Map" || n === "Set") return Array.from(n);
365
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
366
+ }
367
+
368
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
369
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
370
+
371
+ if (it) return (it = it.call(o)).next.bind(it);
372
+ // Fallback for engines without symbol support
373
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
374
+ if (it) o = it;
375
+
376
+ var i = 0;
377
+
378
+ return function() {
379
+ if (i >= o.length) return { done: true };
380
+
381
+ return { done: false, value: o[i++] };
382
+ };
383
+ }
384
+
385
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
386
+ }
387
+
344
388
  /**
345
389
  * @internal
346
- */ var ParserContext = /*#__PURE__*/ function() {
347
- function ParserContext(url) {
348
- this.hasSkinned = false;
349
- /** chain asset promise */ this.chainPromises = [];
350
- this.accessorBufferCache = {};
351
- this.texturesPromiseInfo = new PromiseInfo();
352
- this.materialsPromiseInfo = new PromiseInfo();
353
- this.meshesPromiseInfo = new PromiseInfo();
354
- this.animationClipsPromiseInfo = new PromiseInfo();
355
- this.defaultSceneRootPromiseInfo = new PromiseInfo();
356
- this.masterPromiseInfo = new PromiseInfo();
357
- this.promiseMap = {};
358
- var promiseMap = this.promiseMap;
359
- promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
360
- promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
361
- promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
362
- promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
363
- promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
364
- promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
390
+ */ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
391
+ _inherits(GLTFContentRestorer, ContentRestorer);
392
+ function GLTFContentRestorer() {
393
+ var _this;
394
+ _this = ContentRestorer.apply(this, arguments) || this;
395
+ _this.bufferRequests = [];
396
+ _this.glbBufferSlices = [];
397
+ _this.bufferTextures = [];
398
+ _this.meshes = [];
399
+ return _this;
365
400
  }
366
- var _proto = ParserContext.prototype;
367
- _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
368
- var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
369
- promiseInfo.resolve = resolve;
370
- promiseInfo.reject = reject;
371
- promiseInfo.setProgress = setProgress;
372
- promiseInfo.onCancel = onCancel;
401
+ var _proto = GLTFContentRestorer.prototype;
402
+ _proto.restoreContent = function restoreContent() {
403
+ var _this = this;
404
+ return new engineCore.AssetPromise(function(resolve, reject) {
405
+ Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
406
+ return engineCore.request(bufferRequestInfo.url, bufferRequestInfo.config);
407
+ })).then(function(buffers) {
408
+ // Buffer parse
409
+ if (_this.isGLB) {
410
+ var glbBufferSlice = _this.glbBufferSlices;
411
+ var bigBuffer = buffers[0];
412
+ var bufferCount = glbBufferSlice.length;
413
+ buffers.length = bufferCount;
414
+ for(var i = 0; i < bufferCount; i++){
415
+ var slice = glbBufferSlice[i];
416
+ buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
417
+ }
418
+ }
419
+ // Restore texture
420
+ engineCore.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
421
+ var bufferView = textureRestoreInfo.bufferView;
422
+ var buffer = buffers[bufferView.buffer];
423
+ var _bufferView_byteOffset;
424
+ var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
425
+ return GLTFUtils.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
426
+ textureRestoreInfo.texture.setImageSource(image);
427
+ textureRestoreInfo.texture.generateMipmaps();
428
+ });
429
+ })).then(function() {
430
+ // Restore mesh
431
+ for(var _iterator = _create_for_of_iterator_helper_loose(_this.meshes), _step; !(_step = _iterator()).done;){
432
+ var meshInfo = _step.value;
433
+ var mesh = meshInfo.mesh;
434
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
435
+ var bufferRestoreInfo = _step1.value;
436
+ var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
437
+ bufferRestoreInfo.buffer.setData(vertexData);
438
+ }
439
+ if (meshInfo.indexBuffer) {
440
+ var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
441
+ mesh.setIndices(indexData);
442
+ }
443
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
444
+ var restoreInfo = _step2.value;
445
+ var frame = restoreInfo.blendShape.frames[0];
446
+ var position = restoreInfo.position;
447
+ var positionData = _this._getBufferData(buffers, position.buffer);
448
+ frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
449
+ if (restoreInfo.normal) {
450
+ var normal = restoreInfo.normal;
451
+ var normalData = _this._getBufferData(buffers, normal.buffer);
452
+ frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
453
+ }
454
+ if (restoreInfo.tangent) {
455
+ var tangent = restoreInfo.tangent;
456
+ var tangentData = _this._getBufferData(buffers, tangent.buffer);
457
+ frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
458
+ }
459
+ }
460
+ mesh.uploadData(true);
461
+ }
462
+ resolve(_this.resource);
463
+ }).catch(reject);
464
+ }).catch(reject);
373
465
  });
374
- promiseInfo.promise = promise;
375
- return promise;
376
466
  };
377
- return ParserContext;
378
- }();
467
+ _proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
468
+ var main = restoreInfo.main;
469
+ var buffer = buffers[main.bufferIndex];
470
+ var data = new main.TypedArray(buffer, main.byteOffset, main.length);
471
+ var sparseCount = restoreInfo.sparseCount;
472
+ if (sparseCount) {
473
+ var sparseIndex = restoreInfo.sparseIndices;
474
+ var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
475
+ var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
476
+ var sparseValue = restoreInfo.sparseValues;
477
+ var sparseValueBuffer = buffers[sparseValue.bufferIndex];
478
+ var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
479
+ var typeSize = restoreInfo.typeSize;
480
+ for(var i = 0; i < sparseCount; i++){
481
+ var replaceIndex = sparseIndexData[i];
482
+ for(var j = 0; j < typeSize; j++){
483
+ data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
484
+ }
485
+ }
486
+ }
487
+ return data;
488
+ };
489
+ return GLTFContentRestorer;
490
+ }(engineCore.ContentRestorer);
379
491
  /**
380
492
  * @internal
381
- */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
493
+ */ var BufferRequestInfo = function BufferRequestInfo(url, config) {
494
+ this.url = url;
495
+ this.config = config;
496
+ };
497
+ /**
498
+ * @internal
499
+ */ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
500
+ this.texture = texture;
501
+ this.bufferView = bufferView;
502
+ this.mimeType = mimeType;
503
+ };
504
+ /**
505
+ * @internal
506
+ */ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
507
+ this.vertexBuffers = [];
508
+ this.blendShapes = [];
509
+ };
510
+ /**
511
+ * @internal
512
+ */ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
513
+ this.buffer = buffer;
382
514
  this.data = data;
383
- this.interleaved = interleaved;
384
- this.stride = stride;
385
- this.vertexBindingInfos = {};
386
515
  };
387
516
  /**
388
517
  * @internal
389
- */ var PromiseInfo = function PromiseInfo() {
518
+ */ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
519
+ this.main = main;
520
+ this.typeSize = typeSize;
521
+ this.sparseCount = sparseCount;
522
+ this.sparseIndices = sparseIndices;
523
+ this.sparseValues = sparseValues;
524
+ };
525
+ /**
526
+ * @internal
527
+ */ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
528
+ this.bufferIndex = bufferIndex;
529
+ this.TypedArray = TypedArray;
530
+ this.byteOffset = byteOffset;
531
+ this.length = length;
532
+ };
533
+ /**
534
+ * @internal
535
+ */ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
536
+ this.blendShape = blendShape;
537
+ this.position = position;
538
+ this.normal = normal;
539
+ this.tangent = tangent;
540
+ };
541
+ /**
542
+ * @internal
543
+ */ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
544
+ this.buffer = buffer;
545
+ this.stride = stride;
546
+ this.byteOffset = byteOffset;
547
+ this.count = count;
390
548
  };
391
549
 
392
550
  /**
@@ -538,9 +696,62 @@ var TextureWrapMode;
538
696
 
539
697
  /**
540
698
  * @internal
541
- */ var GLTFUtil = /*#__PURE__*/ function() {
542
- function GLTFUtil() {}
543
- GLTFUtil.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
699
+ */ var GLTFParserContext = /*#__PURE__*/ function() {
700
+ function GLTFParserContext(url) {
701
+ this.hasSkinned = false;
702
+ this.chainPromises = [];
703
+ this.accessorBufferCache = {};
704
+ this.texturesPromiseInfo = new PromiseInfo();
705
+ this.materialsPromiseInfo = new PromiseInfo();
706
+ this.meshesPromiseInfo = new PromiseInfo();
707
+ this.animationClipsPromiseInfo = new PromiseInfo();
708
+ this.defaultSceneRootPromiseInfo = new PromiseInfo();
709
+ this.masterPromiseInfo = new PromiseInfo();
710
+ this.promiseMap = {};
711
+ var promiseMap = this.promiseMap;
712
+ promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
713
+ promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
714
+ promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
715
+ promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
716
+ promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
717
+ promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
718
+ }
719
+ var _proto = GLTFParserContext.prototype;
720
+ /**
721
+ * Get all the buffer data.
722
+ */ _proto.getBuffers = function getBuffers() {
723
+ return Promise.resolve(this._buffers);
724
+ };
725
+ _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
726
+ var promise = new engineCore.AssetPromise(function(resolve, reject, setProgress, onCancel) {
727
+ promiseInfo.resolve = resolve;
728
+ promiseInfo.reject = reject;
729
+ promiseInfo.setProgress = setProgress;
730
+ promiseInfo.onCancel = onCancel;
731
+ });
732
+ promiseInfo.promise = promise;
733
+ return promise;
734
+ };
735
+ return GLTFParserContext;
736
+ }();
737
+ /**
738
+ * @internal
739
+ */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
740
+ this.data = data;
741
+ this.interleaved = interleaved;
742
+ this.stride = stride;
743
+ this.vertexBindingInfos = {};
744
+ };
745
+ /**
746
+ * @internal
747
+ */ var PromiseInfo = function PromiseInfo() {
748
+ };
749
+
750
+ /**
751
+ * @internal
752
+ */ var GLTFUtils = /*#__PURE__*/ function() {
753
+ function GLTFUtils() {}
754
+ GLTFUtils.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
544
755
  var bufferLen = buffer.length;
545
756
  var array = new Array(bufferLen / 2);
546
757
  for(var i = 0; i < bufferLen; i += 2){
@@ -548,7 +759,7 @@ var TextureWrapMode;
548
759
  }
549
760
  return array;
550
761
  };
551
- GLTFUtil.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
762
+ GLTFUtils.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
552
763
  var bufferLen = buffer.length;
553
764
  var array = new Array(bufferLen / 3);
554
765
  for(var i = 0; i < bufferLen; i += 3){
@@ -556,7 +767,7 @@ var TextureWrapMode;
556
767
  }
557
768
  return array;
558
769
  };
559
- GLTFUtil.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
770
+ GLTFUtils.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
560
771
  var bufferLen = buffer.length;
561
772
  var array = new Array(bufferLen / 4);
562
773
  for(var i = 0; i < bufferLen; i += 4){
@@ -564,7 +775,7 @@ var TextureWrapMode;
564
775
  }
565
776
  return array;
566
777
  };
567
- GLTFUtil.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
778
+ GLTFUtils.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
568
779
  var bufferLen = buffer.length;
569
780
  var colors = new Array(bufferLen / (isColor3 ? 3 : 4));
570
781
  if (isColor3) {
@@ -579,21 +790,8 @@ var TextureWrapMode;
579
790
  return colors;
580
791
  };
581
792
  /**
582
- * Parse binary text for glb loader.
583
- */ GLTFUtil.decodeText = function decodeText(array) {
584
- if (typeof TextDecoder !== "undefined") {
585
- return new TextDecoder().decode(array);
586
- }
587
- // TextDecoder polyfill
588
- var s = "";
589
- for(var i = 0, il = array.length; i < il; i++){
590
- s += String.fromCharCode(array[i]);
591
- }
592
- return decodeURIComponent(encodeURIComponent(s));
593
- };
594
- /**
595
793
  * Get the number of bytes occupied by accessor type.
596
- */ GLTFUtil.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
794
+ */ GLTFUtils.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
597
795
  switch(accessorType){
598
796
  case AccessorType.SCALAR:
599
797
  return 1;
@@ -613,7 +811,7 @@ var TextureWrapMode;
613
811
  };
614
812
  /**
615
813
  * Get the TypedArray corresponding to the component type.
616
- */ GLTFUtil.getComponentType = function getComponentType(componentType) {
814
+ */ GLTFUtils.getComponentType = function getComponentType(componentType) {
617
815
  switch(componentType){
618
816
  case AccessorComponentType.BYTE:
619
817
  return Int8Array;
@@ -629,7 +827,7 @@ var TextureWrapMode;
629
827
  return Float32Array;
630
828
  }
631
829
  };
632
- GLTFUtil.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
830
+ GLTFUtils.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
633
831
  // Reference: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
634
832
  switch(componentType){
635
833
  case AccessorComponentType.BYTE:
@@ -644,60 +842,75 @@ var TextureWrapMode;
644
842
  throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
645
843
  }
646
844
  };
647
- GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
648
- var buffers = context.buffers;
649
- var bufferViews = gltf.bufferViews;
845
+ GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
650
846
  var componentType = accessor.componentType;
651
847
  var bufferView = bufferViews[accessor.bufferView];
652
- var buffer = buffers[bufferView.buffer];
653
- var bufferByteOffset = bufferView.byteOffset || 0;
654
- var byteOffset = accessor.byteOffset || 0;
655
- var TypedArray = GLTFUtil.getComponentType(componentType);
656
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
657
- var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
658
- var elementStride = dataElmentSize * dataElementBytes;
659
- var accessorCount = accessor.count;
660
- var bufferStride = bufferView.byteStride;
661
- var bufferInfo;
662
- // According to the glTF official documentation only byteStride not undefined is allowed
663
- if (bufferStride !== undefined && bufferStride !== elementStride) {
664
- var bufferSlice = Math.floor(byteOffset / bufferStride);
665
- var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
666
- var accessorBufferCache = context.accessorBufferCache;
667
- bufferInfo = accessorBufferCache[bufferCacheKey];
668
- if (!bufferInfo) {
669
- var offset = bufferByteOffset + bufferSlice * bufferStride;
670
- var count = accessorCount * (bufferStride / dataElementBytes);
671
- var data = new TypedArray(buffer, offset, count);
672
- accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
848
+ return context.getBuffers().then(function(buffers) {
849
+ var bufferIndex = bufferView.buffer;
850
+ var buffer = buffers[bufferIndex];
851
+ var _bufferView_byteOffset;
852
+ var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
853
+ var _accessor_byteOffset;
854
+ var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
855
+ var TypedArray = GLTFUtils.getComponentType(componentType);
856
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
857
+ var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
858
+ var elementStride = dataElementSize * dataElementBytes;
859
+ var accessorCount = accessor.count;
860
+ var bufferStride = bufferView.byteStride;
861
+ var bufferInfo;
862
+ // According to the glTF official documentation only byteStride not undefined is allowed
863
+ if (bufferStride !== undefined && bufferStride !== elementStride) {
864
+ var bufferSlice = Math.floor(byteOffset / bufferStride);
865
+ var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
866
+ var accessorBufferCache = context.accessorBufferCache;
867
+ bufferInfo = accessorBufferCache[bufferCacheKey];
868
+ if (!bufferInfo) {
869
+ var offset = bufferByteOffset + bufferSlice * bufferStride;
870
+ var count = accessorCount * (bufferStride / dataElementBytes);
871
+ var data = new TypedArray(buffer, offset, count);
872
+ accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
873
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
874
+ }
875
+ } else {
876
+ var offset1 = bufferByteOffset + byteOffset;
877
+ var count1 = accessorCount * dataElementSize;
878
+ var data1 = new TypedArray(buffer, offset1, count1);
879
+ bufferInfo = new BufferInfo(data1, false, elementStride);
880
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
673
881
  }
674
- } else {
675
- var offset1 = bufferByteOffset + byteOffset;
676
- var count1 = accessorCount * dataElmentSize;
677
- var data1 = new TypedArray(buffer, offset1, count1);
678
- bufferInfo = new BufferInfo(data1, false, elementStride);
679
- }
680
- if (accessor.sparse) {
681
- var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
682
- bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
882
+ if (accessor.sparse) {
883
+ GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
884
+ }
885
+ return bufferInfo;
886
+ });
887
+ };
888
+ GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
889
+ var bytesPerElement = data.BYTES_PER_ELEMENT;
890
+ var offset = accessorByteOffset % byteStride / bytesPerElement;
891
+ var stride = byteStride / bytesPerElement;
892
+ var vector3s = new Array(count);
893
+ for(var i = 0; i < count; i++){
894
+ var index = offset + i * stride;
895
+ vector3s[i] = new engineMath.Vector3(data[index], data[index + 1], data[index + 2]);
683
896
  }
684
- return bufferInfo;
897
+ return vector3s;
685
898
  };
686
899
  /**
687
900
  * @deprecated
688
901
  * Get accessor data.
689
- */ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
690
- var bufferViews = gltf.bufferViews;
902
+ */ GLTFUtils.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
903
+ var bufferViews = glTF.bufferViews;
691
904
  var bufferView = bufferViews[accessor.bufferView];
692
905
  var arrayBuffer = buffers[bufferView.buffer];
693
906
  var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
694
907
  var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
695
908
  var byteOffset = accessorByteOffset + bufferViewByteOffset;
696
- var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
909
+ var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
697
910
  var length = accessorTypeSize * accessor.count;
698
911
  var _bufferView_byteStride;
699
912
  var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
700
- var arrayType = GLTFUtil.getComponentType(accessor.componentType);
913
+ var arrayType = GLTFUtils.getComponentType(accessor.componentType);
701
914
  var uint8Array;
702
915
  if (byteStride) {
703
916
  var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
@@ -724,7 +937,7 @@ var TextureWrapMode;
724
937
  var _values_byteOffset, _valuesBufferView_byteOffset;
725
938
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
726
939
  var valuesByteLength = valuesBufferView.byteLength;
727
- var indicesType = GLTFUtil.getComponentType(indices.componentType);
940
+ var indicesType = GLTFUtils.getComponentType(indices.componentType);
728
941
  var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
729
942
  var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
730
943
  for(var i1 = 0; i1 < count; i1++){
@@ -736,41 +949,49 @@ var TextureWrapMode;
736
949
  }
737
950
  return typedArray;
738
951
  };
739
- GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
740
- var buffer = bufferView.buffer, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength;
741
- var arrayBuffer = buffers[buffer];
742
- return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
952
+ GLTFUtils.getBufferViewData = function getBufferViewData(bufferView, buffers) {
953
+ var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
954
+ var arrayBuffer = buffers[bufferView.buffer];
955
+ return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
743
956
  };
744
957
  /**
745
958
  * Get accessor data.
746
- */ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
747
- var bufferViews = gltf.bufferViews;
748
- var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
749
- var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
750
- var data = originData.slice();
959
+ */ GLTFUtils.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
960
+ var restoreInfo = bufferInfo.restoreInfo;
961
+ var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
962
+ var TypedArray = GLTFUtils.getComponentType(accessor.componentType);
963
+ var data = bufferInfo.data.slice();
751
964
  var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
752
965
  var indicesBufferView = bufferViews[indices.bufferView];
753
966
  var valuesBufferView = bufferViews[values.bufferView];
754
- var indicesArrayBuffer = buffers[indicesBufferView.buffer];
755
- var valuesArrayBuffer = buffers[valuesBufferView.buffer];
967
+ var indicesBufferIndex = indicesBufferView.buffer;
968
+ var valuesBufferIndex = valuesBufferView.buffer;
969
+ var indicesArrayBuffer = buffers[indicesBufferIndex];
970
+ var valuesArrayBuffer = buffers[valuesBufferIndex];
756
971
  var _indices_byteOffset, _indicesBufferView_byteOffset;
757
972
  var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
758
973
  var indicesByteLength = indicesBufferView.byteLength;
759
974
  var _values_byteOffset, _valuesBufferView_byteOffset;
760
975
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
761
976
  var valuesByteLength = valuesBufferView.byteLength;
762
- var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
763
- var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
764
- var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
977
+ restoreInfo.typeSize = accessorTypeSize;
978
+ restoreInfo.sparseCount = count;
979
+ var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
980
+ var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
981
+ var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
982
+ restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
983
+ var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
984
+ var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
985
+ restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
765
986
  for(var i = 0; i < count; i++){
766
987
  var replaceIndex = indicesArray[i];
767
988
  for(var j = 0; j < accessorTypeSize; j++){
768
989
  data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
769
990
  }
770
991
  }
771
- return data;
992
+ bufferInfo.data = data;
772
993
  };
773
- GLTFUtil.getIndexFormat = function getIndexFormat(type) {
994
+ GLTFUtils.getIndexFormat = function getIndexFormat(type) {
774
995
  switch(type){
775
996
  case AccessorComponentType.UNSIGNED_BYTE:
776
997
  return engineCore.IndexFormat.UInt8;
@@ -780,7 +1001,7 @@ var TextureWrapMode;
780
1001
  return engineCore.IndexFormat.UInt32;
781
1002
  }
782
1003
  };
783
- GLTFUtil.getElementFormat = function getElementFormat(type, size, normalized) {
1004
+ GLTFUtils.getElementFormat = function getElementFormat(type, size, normalized) {
784
1005
  if (normalized === void 0) normalized = false;
785
1006
  if (type == AccessorComponentType.FLOAT) {
786
1007
  switch(size){
@@ -831,7 +1052,7 @@ var TextureWrapMode;
831
1052
  };
832
1053
  /**
833
1054
  * Load image buffer
834
- */ GLTFUtil.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
1055
+ */ GLTFUtils.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
835
1056
  return new Promise(function(resolve, reject) {
836
1057
  var blob = new window.Blob([
837
1058
  imageBuffer
@@ -855,18 +1076,9 @@ var TextureWrapMode;
855
1076
  img.src = URL.createObjectURL(blob);
856
1077
  });
857
1078
  };
858
- GLTFUtil.isAbsoluteUrl = function isAbsoluteUrl(url) {
859
- return /^(?:http|blob|data:|\/)/.test(url);
860
- };
861
- GLTFUtil.parseRelativeUrl = function parseRelativeUrl(baseUrl, relativeUrl) {
862
- if (GLTFUtil.isAbsoluteUrl(relativeUrl)) {
863
- return relativeUrl;
864
- }
865
- return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + GLTFUtil._formatRelativePath(relativeUrl);
866
- };
867
1079
  /**
868
1080
  * Parse the glb format.
869
- */ GLTFUtil.parseGLB = function parseGLB(glb) {
1081
+ */ GLTFUtils.parseGLB = function parseGLB(context, glb) {
870
1082
  var UINT32_LENGTH = 4;
871
1083
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
872
1084
  var GLB_HEADER_LENGTH = 12;
@@ -894,10 +1106,11 @@ var TextureWrapMode;
894
1106
  return null;
895
1107
  }
896
1108
  var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
897
- var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
1109
+ var glTF = JSON.parse(engineCore.Utils.decodeText(glTFData));
898
1110
  // read all buffers
899
1111
  var buffers = [];
900
1112
  var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
1113
+ var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
901
1114
  while(byteOffset < header.length){
902
1115
  chunkLength = dataView.getUint32(byteOffset, true);
903
1116
  chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
@@ -908,14 +1121,15 @@ var TextureWrapMode;
908
1121
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
909
1122
  var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
910
1123
  buffers.push(buffer);
1124
+ restoreGLBBufferSlice.push(new engineMath.Vector2(currentOffset, chunkLength));
911
1125
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
912
1126
  }
913
1127
  return {
914
- gltf: gltf,
1128
+ glTF: glTF,
915
1129
  buffers: buffers
916
1130
  };
917
1131
  };
918
- GLTFUtil._formatRelativePath = function _formatRelativePath(path) {
1132
+ GLTFUtils._formatRelativePath = function _formatRelativePath(path) {
919
1133
  // For example input is "a/b", "/a/b", "./a/b", "./a/./b", "./a/../a/b", output is "a/b"
920
1134
  return path.split("/").filter(Boolean).reduce(function(acc, cur) {
921
1135
  if (cur === "..") acc.pop();
@@ -923,17 +1137,9 @@ var TextureWrapMode;
923
1137
  return acc;
924
1138
  }, []).join("/");
925
1139
  };
926
- return GLTFUtil;
1140
+ return GLTFUtils;
927
1141
  }();
928
1142
 
929
- function _array_like_to_array(arr, len) {
930
- if (len == null || len > arr.length) len = arr.length;
931
-
932
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
933
-
934
- return arr2;
935
- }
936
-
937
1143
  function _array_without_holes(arr) {
938
1144
  if (Array.isArray(arr)) return _array_like_to_array(arr);
939
1145
  }
@@ -948,527 +1154,260 @@ function _non_iterable_spread() {
948
1154
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
949
1155
  }
950
1156
 
951
- function _unsupported_iterable_to_array(o, minLen) {
952
- if (!o) return;
953
- if (typeof o === "string") return _array_like_to_array(o, minLen);
954
-
955
- var n = Object.prototype.toString.call(o).slice(8, -1);
956
-
957
- if (n === "Object" && o.constructor) n = o.constructor.name;
958
- if (n === "Map" || n === "Set") return Array.from(n);
959
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
960
- }
961
-
962
1157
  function _to_consumable_array(arr) {
963
1158
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
964
1159
  }
965
1160
 
966
- var Parser = /*#__PURE__*/ function() {
967
- function Parser() {}
968
- Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
1161
+ /**
1162
+ * Base class of glTF extension parser.
1163
+ */ var GLTFExtensionParser = /*#__PURE__*/ function() {
1164
+ function GLTFExtensionParser() {}
1165
+ var _proto = GLTFExtensionParser.prototype;
1166
+ /**
1167
+ * Initialize the parser.
1168
+ * @remarks Some plugins require initialization.
1169
+ * @returns The void or promise
1170
+ */ _proto.initialize = function initialize() {};
1171
+ /**
1172
+ * Create and parse the resource.
1173
+ * @remarks This method overrides the default resource creation.
1174
+ * @param context - The parser context
1175
+ * @param extensionSchema - The extension schema
1176
+ * @param extensionOwnerSchema - The extension owner schema
1177
+ * @returns The resource or promise
1178
+ */ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
1179
+ for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1180
+ extra[_key - 3] = arguments[_key];
1181
+ }
1182
+ throw "Not implemented.";
1183
+ };
1184
+ /**
1185
+ * Additive parse to the resource.
1186
+ * @param context - The parser context
1187
+ * @param parseResource - The parsed resource
1188
+ * @param extensionSchema - The extension schema
1189
+ * @param extensionOwnerSchema - The extension owner schema
1190
+ * @returns The void or promise
1191
+ */ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
969
1192
  for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
970
1193
  extra[_key - 4] = arguments[_key];
971
1194
  }
972
- var parsers = Parser._extensionParsers[extensionName];
973
- if (parsers == null ? void 0 : parsers.length) {
974
- for(var i = 0; i < parsers.length; i++){
975
- var _parsers_i;
976
- (_parsers_i = parsers[i]).parseEngineResource.apply(_parsers_i, [
977
- extensionSchema,
978
- parseResource,
979
- context
980
- ].concat(_to_consumable_array(extra)));
981
- }
1195
+ throw "Not implemented.";
1196
+ };
1197
+ return GLTFExtensionParser;
1198
+ }();
1199
+ exports.GLTFExtensionMode = void 0;
1200
+ (function(GLTFExtensionMode) {
1201
+ GLTFExtensionMode[GLTFExtensionMode[/**
1202
+ * Cerate instance and parse mode.
1203
+ * @remarks
1204
+ * If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
1205
+ * If this method is registered, the default pipeline processing will be ignored.
1206
+ */ "CreateAndParse"] = 0] = "CreateAndParse";
1207
+ GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
1208
+ })(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
1209
+
1210
+ /**
1211
+ * Base class of glTF parser.
1212
+ */ var GLTFParser = /*#__PURE__*/ function() {
1213
+ function GLTFParser() {}
1214
+ /**
1215
+ * Execute all parses of extension to initialize plugin.
1216
+ * @remarks Some plugins require initialization.
1217
+ * @returns The void or promise
1218
+ */ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
1219
+ var parsers = GLTFParser._extensionParsers[extensionName];
1220
+ var length = parsers == null ? void 0 : parsers.length;
1221
+ if (length) {
1222
+ return parsers[length - 1].initialize();
982
1223
  }
983
1224
  };
984
- Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
1225
+ /**
1226
+ * Execute all parses of extension to create resource.
1227
+ * @param extensions - Related extensions field
1228
+ * @param context - The parser context
1229
+ * @param ownerSchema - The extension owner schema
1230
+ * @param extra - Extra params
1231
+ * @returns
1232
+ */ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
1233
+ if (extensions === void 0) extensions = {};
985
1234
  for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
986
1235
  extra[_key - 3] = arguments[_key];
987
1236
  }
988
- var parsers = Parser._extensionParsers[extensionName];
989
- if (parsers == null ? void 0 : parsers.length) {
990
- var _parsers_;
991
- return (_parsers_ = parsers[0]).createEngineResource.apply(_parsers_, [
1237
+ var resource = null;
1238
+ var extensionArray = Object.keys(extensions);
1239
+ for(var i = extensionArray.length - 1; i >= 0; --i){
1240
+ var _GLTFParser;
1241
+ var extensionName = extensionArray[i];
1242
+ var extensionSchema = extensions[extensionName];
1243
+ resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
1244
+ extensionName,
1245
+ context,
1246
+ extensionSchema,
1247
+ ownerSchema
1248
+ ].concat(_to_consumable_array(extra)));
1249
+ if (resource) {
1250
+ return resource;
1251
+ }
1252
+ }
1253
+ };
1254
+ /**
1255
+ * Execute all parses of extension to parse resource.
1256
+ * @param extensions - Related extensions field
1257
+ * @param context - The parser context
1258
+ * @param parseResource - The parsed resource
1259
+ * @param ownerSchema - The extension owner schema
1260
+ * @param extra - Extra params
1261
+ */ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
1262
+ for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1263
+ extra[_key - 4] = arguments[_key];
1264
+ }
1265
+ for(var extensionName in extensions){
1266
+ var _GLTFParser;
1267
+ var extensionSchema = extensions[extensionName];
1268
+ (_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
1269
+ extensionName,
1270
+ context,
1271
+ parseResource,
992
1272
  extensionSchema,
993
- context
1273
+ ownerSchema
994
1274
  ].concat(_to_consumable_array(extra)));
995
1275
  }
996
1276
  };
997
- Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
998
- var parsers = Parser._extensionParsers[extensionName];
999
- return !!(parsers == null ? void 0 : parsers.length);
1277
+ /**
1278
+ * Whether the plugin is registered.
1279
+ * @param extensionName - Extension name
1280
+ * @returns Boolean
1281
+ */ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
1282
+ var _GLTFParser__extensionParsers_extensionName;
1283
+ return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
1000
1284
  };
1001
- Parser.initialize = function initialize(extensionName) {
1002
- var parsers = Parser._extensionParsers[extensionName];
1003
- if (parsers == null ? void 0 : parsers.length) {
1004
- for(var i = 0; i < parsers.length; i++){
1005
- parsers[i].initialize();
1285
+ /**
1286
+ * Get the last plugin by glTF extension mode.
1287
+ * @param extensionName - Extension name
1288
+ * @param mode - GLTF extension mode
1289
+ * @returns GLTF extension parser
1290
+ */ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
1291
+ var parsers = GLTFParser._extensionParsers[extensionName];
1292
+ var length = parsers == null ? void 0 : parsers.length;
1293
+ if (length) {
1294
+ // only use the last parser.
1295
+ for(var i = length - 1; i >= 0; --i){
1296
+ var currentParser = parsers[i];
1297
+ if (currentParser._mode === mode) {
1298
+ return currentParser;
1299
+ }
1006
1300
  }
1007
1301
  }
1008
1302
  };
1009
1303
  /**
1010
1304
  * @internal
1011
- */ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1012
- if (!Parser._extensionParsers[extensionName]) {
1013
- Parser._extensionParsers[extensionName] = [];
1305
+ */ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1306
+ if (!GLTFParser._extensionParsers[extensionName]) {
1307
+ GLTFParser._extensionParsers[extensionName] = [];
1308
+ }
1309
+ GLTFParser._extensionParsers[extensionName].push(extensionParser);
1310
+ };
1311
+ GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
1312
+ for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1313
+ extra[_key - 4] = arguments[_key];
1314
+ }
1315
+ var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
1316
+ if (parser) {
1317
+ var _parser;
1318
+ return (_parser = parser).createAndParse.apply(_parser, [
1319
+ context,
1320
+ extensionSchema,
1321
+ ownerSchema
1322
+ ].concat(_to_consumable_array(extra)));
1323
+ }
1324
+ };
1325
+ GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
1326
+ for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
1327
+ extra[_key - 5] = arguments[_key];
1328
+ }
1329
+ var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
1330
+ if (parser) {
1331
+ var _parser;
1332
+ (_parser = parser).additiveParse.apply(_parser, [
1333
+ context,
1334
+ parseResource,
1335
+ extensionSchema,
1336
+ ownerSchema
1337
+ ].concat(_to_consumable_array(extra)));
1014
1338
  }
1015
- Parser._extensionParsers[extensionName].push(extensionParser);
1016
1339
  };
1017
- return Parser;
1340
+ return GLTFParser;
1018
1341
  }();
1019
1342
  (function() {
1020
- Parser._extensionParsers = {};
1343
+ GLTFParser._extensionParsers = {};
1021
1344
  })();
1022
1345
  /**
1023
1346
  * Declare ExtensionParser's decorator.
1024
1347
  * @param extensionName - Extension name
1025
- */ function registerExtension(extensionName) {
1348
+ */ function registerGLTFExtension(extensionName, mode) {
1026
1349
  return function(parser) {
1027
1350
  var extensionParser = new parser();
1028
- Parser._addExtensionParser(extensionName, extensionParser);
1351
+ extensionParser._mode = mode;
1352
+ GLTFParser._addExtensionParser(extensionName, extensionParser);
1029
1353
  };
1030
1354
  }
1031
1355
 
1032
- var ExtensionParser = /*#__PURE__*/ function() {
1033
- function ExtensionParser() {}
1034
- var _proto = ExtensionParser.prototype;
1035
- _proto.initialize = function initialize() {};
1036
- _proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
1037
- for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1038
- extra[_key - 3] = arguments[_key];
1356
+ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1357
+ _inherits(GLTFAnimationParser, GLTFParser1);
1358
+ function GLTFAnimationParser() {
1359
+ return GLTFParser1.apply(this, arguments);
1360
+ }
1361
+ var _proto = GLTFAnimationParser.prototype;
1362
+ _proto.parse = function parse(context) {
1363
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1364
+ glTFResource.entities;
1365
+ var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
1366
+ if (!animations) {
1367
+ return;
1039
1368
  }
1040
- };
1041
- _proto.createEngineResource = function createEngineResource(schema, context) {
1042
- for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
1043
- extra[_key - 2] = arguments[_key];
1369
+ var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1370
+ var animationClipCount = animations.length;
1371
+ var animationClipPromises = [];
1372
+ new Array(animationClipCount);
1373
+ var parseStandardPropertyPromises = new Array();
1374
+ for(var i = 0; i < animationClipCount; i++){
1375
+ var animationInfo = animations[i];
1376
+ var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
1377
+ var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
1378
+ if (!animationClip) {
1379
+ animationClip = new engineCore.AnimationClip(name);
1380
+ parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
1381
+ }
1382
+ animationClipPromises.push(animationClip);
1044
1383
  }
1045
- return null;
1384
+ return engineCore.AssetPromise.all(parseStandardPropertyPromises).then(function() {
1385
+ return engineCore.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1386
+ glTFResource.animations = animationClips;
1387
+ for(var i = 0; i < glTF.animations.length; i++){
1388
+ var animationInfo = glTF.animations[i];
1389
+ GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
1390
+ }
1391
+ animationClipsPromiseInfo.resolve(animationClips);
1392
+ return animationClipsPromiseInfo.promise;
1393
+ });
1394
+ });
1046
1395
  };
1047
- return ExtensionParser;
1048
- }();
1049
-
1050
- var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
1051
- _inherits(KHR_draco_mesh_compression1, ExtensionParser);
1052
- function KHR_draco_mesh_compression1() {
1053
- return ExtensionParser.apply(this, arguments);
1054
- }
1055
- var _proto = KHR_draco_mesh_compression1.prototype;
1056
- _proto.initialize = function initialize() {
1057
- if (!KHR_draco_mesh_compression._decoder) {
1058
- KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
1059
- }
1060
- };
1061
- _proto.createEngineResource = function createEngineResource(schema, context, gltfPrimitive) {
1062
- var gltf = context.gltf, buffers = context.buffers;
1063
- var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
1064
- var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
1065
- var attributeMap = {};
1066
- var attributeTypeMap = {};
1067
- for(var attributeName in gltfAttributeMap){
1068
- attributeMap[attributeName] = gltfAttributeMap[attributeName];
1069
- }
1070
- for(var attributeName1 in gltfPrimitive.attributes){
1071
- if (gltfAttributeMap[attributeName1] !== undefined) {
1072
- var accessorDef = accessors[gltfPrimitive.attributes[attributeName1]];
1073
- attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
1074
- }
1075
- }
1076
- var indexAccessor = accessors[gltfPrimitive.indices];
1077
- var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
1078
- var taskConfig = {
1079
- attributeIDs: attributeMap,
1080
- attributeTypes: attributeTypeMap,
1081
- useUniqueIDs: true,
1082
- indexType: indexType
1083
- };
1084
- var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
1085
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
1086
- return parsedGeometry;
1087
- });
1088
- };
1089
- return KHR_draco_mesh_compression1;
1090
- }(ExtensionParser);
1091
- KHR_draco_mesh_compression = __decorate([
1092
- registerExtension("KHR_draco_mesh_compression")
1093
- ], KHR_draco_mesh_compression);
1094
-
1095
- function _instanceof(left, right) {
1096
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1097
- return !!right[Symbol.hasInstance](left);
1098
- } else return left instanceof right;
1099
- }
1100
-
1101
- var KHR_lights_punctual = /*#__PURE__*/ function(ExtensionParser) {
1102
- _inherits(KHR_lights_punctual, ExtensionParser);
1103
- function KHR_lights_punctual() {
1104
- return ExtensionParser.apply(this, arguments);
1105
- }
1106
- var _proto = KHR_lights_punctual.prototype;
1107
- _proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
1108
- var color = schema.color, _schema_intensity = schema.intensity, intensity = _schema_intensity === void 0 ? 1 : _schema_intensity, type = schema.type, range = schema.range, spot = schema.spot;
1109
- var glTFResource = context.glTFResource;
1110
- var light;
1111
- if (type === "directional") {
1112
- light = entity.addComponent(engineCore.DirectLight);
1113
- } else if (type === "point") {
1114
- light = entity.addComponent(engineCore.PointLight);
1115
- } else if (type === "spot") {
1116
- light = entity.addComponent(engineCore.SpotLight);
1117
- }
1118
- if (color) {
1119
- light.color.set(color[0], color[1], color[2], 1);
1120
- }
1121
- light.intensity = intensity;
1122
- if (range && !_instanceof(light, engineCore.DirectLight)) {
1123
- light.distance = range;
1124
- }
1125
- if (spot && _instanceof(light, engineCore.SpotLight)) {
1126
- var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
1127
- light.angle = innerConeAngle;
1128
- light.penumbra = outerConeAngle - innerConeAngle;
1129
- }
1130
- if (!glTFResource.lights) glTFResource.lights = [];
1131
- glTFResource.lights.push(light);
1132
- };
1133
- return KHR_lights_punctual;
1134
- }(ExtensionParser);
1135
- KHR_lights_punctual = __decorate([
1136
- registerExtension("KHR_lights_punctual")
1137
- ], KHR_lights_punctual);
1138
-
1139
- var MaterialParser = /*#__PURE__*/ function(Parser1) {
1140
- _inherits(MaterialParser, Parser1);
1141
- function MaterialParser() {
1142
- return Parser1.apply(this, arguments);
1143
- }
1144
- var _proto = MaterialParser.prototype;
1145
- _proto.parse = function parse(context) {
1146
- var gltf = context.gltf, glTFResource = context.glTFResource;
1147
- var engine = glTFResource.engine, textures = glTFResource.textures;
1148
- if (!gltf.materials) return;
1149
- var materialsPromiseInfo = context.materialsPromiseInfo;
1150
- var materials = [];
1151
- for(var i = 0; i < gltf.materials.length; i++){
1152
- var _gltf_materials_i = gltf.materials[i], _gltf_materials_i_extensions = _gltf_materials_i.extensions, extensions = _gltf_materials_i_extensions === void 0 ? {} : _gltf_materials_i_extensions, pbrMetallicRoughness = _gltf_materials_i.pbrMetallicRoughness, normalTexture = _gltf_materials_i.normalTexture, occlusionTexture = _gltf_materials_i.occlusionTexture, emissiveTexture = _gltf_materials_i.emissiveTexture, emissiveFactor = _gltf_materials_i.emissiveFactor, alphaMode = _gltf_materials_i.alphaMode, alphaCutoff = _gltf_materials_i.alphaCutoff, doubleSided = _gltf_materials_i.doubleSided, _gltf_materials_i_name = _gltf_materials_i.name, name = _gltf_materials_i_name === void 0 ? "" : _gltf_materials_i_name;
1153
- var KHR_materials_unlit = extensions.KHR_materials_unlit, KHR_materials_pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness, KHR_materials_clearcoat = extensions.KHR_materials_clearcoat, OASIS_materials_remap = extensions.OASIS_materials_remap;
1154
- var material = null;
1155
- if (KHR_materials_unlit) {
1156
- material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
1157
- } else if (KHR_materials_pbrSpecularGlossiness) {
1158
- material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
1159
- } else {
1160
- material = new engineCore.PBRMaterial(engine);
1161
- }
1162
- material.name = name;
1163
- if (KHR_materials_clearcoat) {
1164
- Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
1165
- }
1166
- if (pbrMetallicRoughness) {
1167
- var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1168
- if (baseColorFactor) {
1169
- material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
1170
- }
1171
- if (baseColorTexture) {
1172
- material.baseTexture = textures[baseColorTexture.index];
1173
- MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
1174
- }
1175
- if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
1176
- var m = material;
1177
- m.metallic = metallicFactor != null ? metallicFactor : 1;
1178
- m.roughness = roughnessFactor != null ? roughnessFactor : 1;
1179
- if (metallicRoughnessTexture) {
1180
- m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1181
- MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
1182
- }
1183
- }
1184
- }
1185
- if (!KHR_materials_unlit) {
1186
- var m1 = material;
1187
- if (emissiveTexture) {
1188
- m1.emissiveTexture = textures[emissiveTexture.index];
1189
- MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
1190
- }
1191
- if (emissiveFactor) {
1192
- m1.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
1193
- }
1194
- if (normalTexture) {
1195
- var index = normalTexture.index, scale = normalTexture.scale;
1196
- m1.normalTexture = textures[index];
1197
- MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
1198
- if (scale !== undefined) {
1199
- m1.normalTextureIntensity = scale;
1200
- }
1201
- }
1202
- if (occlusionTexture) {
1203
- var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1204
- m1.occlusionTexture = textures[index1];
1205
- MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
1206
- if (strength !== undefined) {
1207
- m1.occlusionTextureIntensity = strength;
1208
- }
1209
- if (texCoord === engineCore.TextureCoordinate.UV1) {
1210
- m1.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
1211
- } else if (texCoord > engineCore.TextureCoordinate.UV1) {
1212
- engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1213
- }
1214
- }
1215
- }
1216
- if (OASIS_materials_remap) {
1217
- var _gltf_extensions;
1218
- gltf.extensions = (_gltf_extensions = gltf.extensions) != null ? _gltf_extensions : {};
1219
- var _gltf_extensions_OASIS_materials_remap;
1220
- gltf.extensions["OASIS_materials_remap"] = (_gltf_extensions_OASIS_materials_remap = gltf.extensions["OASIS_materials_remap"]) != null ? _gltf_extensions_OASIS_materials_remap : {};
1221
- gltf.extensions["OASIS_materials_remap"][i] = Parser.createEngineResource("OASIS_materials_remap", OASIS_materials_remap, context);
1222
- }
1223
- if (doubleSided) {
1224
- material.renderFace = engineCore.RenderFace.Double;
1225
- } else {
1226
- material.renderFace = engineCore.RenderFace.Front;
1227
- }
1228
- switch(alphaMode){
1229
- case MaterialAlphaMode.OPAQUE:
1230
- material.isTransparent = false;
1231
- break;
1232
- case MaterialAlphaMode.BLEND:
1233
- material.isTransparent = true;
1234
- break;
1235
- case MaterialAlphaMode.MASK:
1236
- material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1237
- break;
1238
- }
1239
- materials[i] = material;
1240
- }
1241
- glTFResource.materials = materials;
1242
- materialsPromiseInfo.resolve(materials);
1243
- return materialsPromiseInfo.promise;
1244
- };
1245
- /** @internal */ MaterialParser._parseTextureTransform = function _parseTextureTransform(material, extensions, context) {
1246
- if (extensions === void 0) extensions = {};
1247
- var schema = extensions.KHR_texture_transform;
1248
- if (schema) {
1249
- Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
1250
- }
1251
- };
1252
- return MaterialParser;
1253
- }(Parser);
1254
-
1255
- var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
1256
- _inherits(KHR_materials_clearcoat, ExtensionParser);
1257
- function KHR_materials_clearcoat() {
1258
- return ExtensionParser.apply(this, arguments);
1259
- }
1260
- var _proto = KHR_materials_clearcoat.prototype;
1261
- _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1262
- var textures = context.glTFResource.textures;
1263
- var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
1264
- material.clearCoat = clearcoatFactor;
1265
- material.clearCoatRoughness = clearcoatRoughnessFactor;
1266
- if (clearcoatTexture) {
1267
- material.clearCoatTexture = textures[clearcoatTexture.index];
1268
- MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
1269
- }
1270
- if (clearcoatRoughnessTexture) {
1271
- material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
1272
- MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
1273
- }
1274
- if (clearcoatNormalTexture) {
1275
- material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
1276
- MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
1277
- }
1278
- };
1279
- return KHR_materials_clearcoat;
1280
- }(ExtensionParser);
1281
- KHR_materials_clearcoat = __decorate([
1282
- registerExtension("KHR_materials_clearcoat")
1283
- ], KHR_materials_clearcoat);
1284
-
1285
- var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
1286
- _inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
1287
- function KHR_materials_pbrSpecularGlossiness() {
1288
- return ExtensionParser.apply(this, arguments);
1289
- }
1290
- var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
1291
- _proto.createEngineResource = function createEngineResource(schema, context) {
1292
- var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
1293
- var material = new engineCore.PBRSpecularMaterial(engine);
1294
- var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
1295
- if (diffuseFactor) {
1296
- material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
1297
- }
1298
- if (diffuseTexture) {
1299
- material.baseTexture = textures[diffuseTexture.index];
1300
- MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
1301
- }
1302
- if (specularFactor) {
1303
- material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
1304
- }
1305
- if (glossinessFactor !== undefined) {
1306
- material.glossiness = glossinessFactor;
1307
- }
1308
- if (specularGlossinessTexture) {
1309
- material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
1310
- MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
1311
- }
1312
- return material;
1313
- };
1314
- return KHR_materials_pbrSpecularGlossiness;
1315
- }(ExtensionParser);
1316
- KHR_materials_pbrSpecularGlossiness = __decorate([
1317
- registerExtension("KHR_materials_pbrSpecularGlossiness")
1318
- ], KHR_materials_pbrSpecularGlossiness);
1319
-
1320
- var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
1321
- _inherits(KHR_materials_unlit, ExtensionParser);
1322
- function KHR_materials_unlit() {
1323
- return ExtensionParser.apply(this, arguments);
1324
- }
1325
- var _proto = KHR_materials_unlit.prototype;
1326
- _proto.createEngineResource = function createEngineResource(schema, context) {
1327
- var engine = context.glTFResource.engine;
1328
- var material = new engineCore.UnlitMaterial(engine);
1329
- return material;
1330
- };
1331
- return KHR_materials_unlit;
1332
- }(ExtensionParser);
1333
- KHR_materials_unlit = __decorate([
1334
- registerExtension("KHR_materials_unlit")
1335
- ], KHR_materials_unlit);
1336
-
1337
- var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
1338
- _inherits(KHR_materials_variants, ExtensionParser);
1339
- function KHR_materials_variants() {
1340
- return ExtensionParser.apply(this, arguments);
1341
- }
1342
- var _proto = KHR_materials_variants.prototype;
1343
- _proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
1344
- var _context_gltf = context.gltf, _context_gltf_extensions = _context_gltf.extensions, _context_gltf_extensions_KHR_materials_variants = _context_gltf_extensions.KHR_materials_variants, variantNames = _context_gltf_extensions_KHR_materials_variants.variants, glTFResource = context.glTFResource;
1345
- var mappings = schema.mappings;
1346
- for(var i = 0; i < mappings.length; i++){
1347
- var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
1348
- if (!glTFResource.variants) glTFResource.variants = [];
1349
- glTFResource.variants.push({
1350
- renderer: renderer,
1351
- material: glTFResource.materials[material],
1352
- variants: variants.map(function(index) {
1353
- return variantNames[index].name;
1354
- })
1355
- });
1356
- }
1357
- };
1358
- return KHR_materials_variants;
1359
- }(ExtensionParser);
1360
- KHR_materials_variants = __decorate([
1361
- registerExtension("KHR_materials_variants")
1362
- ], KHR_materials_variants);
1363
-
1364
- var KHR_mesh_quantization = /*#__PURE__*/ function(ExtensionParser) {
1365
- _inherits(KHR_mesh_quantization, ExtensionParser);
1366
- function KHR_mesh_quantization() {
1367
- return ExtensionParser.apply(this, arguments);
1368
- }
1369
- return KHR_mesh_quantization;
1370
- }(ExtensionParser);
1371
- KHR_mesh_quantization = __decorate([
1372
- registerExtension("KHR_mesh_quantization")
1373
- ], KHR_mesh_quantization);
1374
-
1375
- var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
1376
- _inherits(KHR_texture_transform, ExtensionParser);
1377
- function KHR_texture_transform() {
1378
- return ExtensionParser.apply(this, arguments);
1379
- }
1380
- var _proto = KHR_texture_transform.prototype;
1381
- _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1382
- var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
1383
- if (offset) {
1384
- material.tilingOffset.z = offset[0];
1385
- material.tilingOffset.w = offset[1];
1386
- }
1387
- if (scale) {
1388
- material.tilingOffset.x = scale[0];
1389
- material.tilingOffset.y = scale[1];
1390
- }
1391
- if (rotation) {
1392
- engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
1393
- }
1394
- if (texCoord) {
1395
- engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
1396
- }
1397
- };
1398
- return KHR_texture_transform;
1399
- }(ExtensionParser);
1400
- KHR_texture_transform = __decorate([
1401
- registerExtension("KHR_texture_transform")
1402
- ], KHR_texture_transform);
1403
-
1404
- var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
1405
- _inherits(GalaceanMaterialsRemap, ExtensionParser);
1406
- function GalaceanMaterialsRemap() {
1407
- return ExtensionParser.apply(this, arguments);
1408
- }
1409
- var _proto = GalaceanMaterialsRemap.prototype;
1410
- _proto.createEngineResource = function createEngineResource(schema, context) {
1411
- var engine = context.glTFResource.engine;
1412
- // @ts-ignore
1413
- return engine.resourceManager.getResourceByRef(schema);
1414
- };
1415
- return GalaceanMaterialsRemap;
1416
- }(ExtensionParser);
1417
- GalaceanMaterialsRemap = __decorate([
1418
- registerExtension("OASIS_materials_remap")
1419
- ], GalaceanMaterialsRemap);
1420
-
1421
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1422
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1423
-
1424
- if (it) return (it = it.call(o)).next.bind(it);
1425
- // Fallback for engines without symbol support
1426
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
1427
- if (it) o = it;
1428
-
1429
- var i = 0;
1430
-
1431
- return function() {
1432
- if (i >= o.length) return { done: true };
1433
-
1434
- return { done: false, value: o[i++] };
1435
- };
1436
- }
1437
-
1438
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1439
- }
1440
-
1441
- var AnimationParser = /*#__PURE__*/ function(Parser) {
1442
- _inherits(AnimationParser, Parser);
1443
- function AnimationParser() {
1444
- return Parser.apply(this, arguments);
1445
- }
1446
- var _proto = AnimationParser.prototype;
1447
- _proto.parse = function parse(context) {
1448
- var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
1449
- var entities = glTFResource.entities;
1450
- var animations = gltf.animations, accessors = gltf.accessors;
1451
- if (!animations) {
1452
- return;
1453
- }
1454
- var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1455
- var animationClipCount = animations.length;
1456
- var animationClips = new Array(animationClipCount);
1457
- var animationsIndices = new Array(animationClipCount);
1458
- for(var i = 0; i < animationClipCount; i++){
1459
- var gltfAnimation = animations[i];
1460
- var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
1461
- var animationClip = new engineCore.AnimationClip(name);
1462
- var sampleDataCollection = new Array();
1463
- // parse samplers
1464
- for(var j = 0, m = samplers.length; j < m; j++){
1465
- var gltfSampler = samplers[j];
1466
- var inputAccessor = accessors[gltfSampler.input];
1467
- var outputAccessor = accessors[gltfSampler.output];
1468
- var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
1469
- var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
1396
+ /**
1397
+ * @internal
1398
+ */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
1399
+ var _loop = function(j, m) {
1400
+ var gltfSampler = samplers[j];
1401
+ var inputAccessor = accessors[gltfSampler.input];
1402
+ var outputAccessor = accessors[gltfSampler.output];
1403
+ var promise = Promise.all([
1404
+ GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
1405
+ GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
1406
+ ]).then(function(bufferInfos) {
1407
+ var input = bufferInfos[0].data;
1408
+ var output = bufferInfos[1].data;
1470
1409
  if (outputAccessor.normalized) {
1471
- var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
1410
+ var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
1472
1411
  var scaled = new Float32Array(output.length);
1473
1412
  for(var k = 0, v = output.length; k < v; k++){
1474
1413
  scaled[k] = output[k] * scale;
@@ -1478,7 +1417,7 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
1478
1417
  var outputStride = output.length / input.length;
1479
1418
  var _gltfSampler_interpolation;
1480
1419
  var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1481
- var samplerInterpolation = void 0;
1420
+ var samplerInterpolation;
1482
1421
  switch(interpolation){
1483
1422
  case AnimationSamplerInterpolation.CubicSpine:
1484
1423
  samplerInterpolation = engineCore.InterpolationType.CubicSpine;
@@ -1498,9 +1437,21 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
1498
1437
  output: output,
1499
1438
  outputSize: outputStride
1500
1439
  });
1501
- }
1502
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1503
- var gltfChannel = channels[j1];
1440
+ });
1441
+ promises.push(promise);
1442
+ };
1443
+ var _this = this;
1444
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1445
+ var entities = glTFResource.entities;
1446
+ var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
1447
+ var channels = animationInfo.channels, samplers = animationInfo.samplers;
1448
+ var sampleDataCollection = new Array();
1449
+ var promises = new Array();
1450
+ // parse samplers
1451
+ for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
1452
+ return Promise.all(promises).then(function() {
1453
+ for(var j = 0, m = channels.length; j < m; j++){
1454
+ var gltfChannel = channels[j];
1504
1455
  var target = gltfChannel.target;
1505
1456
  var channelTargetEntity = entities[target.node];
1506
1457
  var relativePath = "";
@@ -1529,25 +1480,15 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
1529
1480
  propertyName = "blendShapeWeights";
1530
1481
  break;
1531
1482
  }
1532
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1483
+ var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
1533
1484
  animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1534
1485
  }
1535
- animationClips[i] = animationClip;
1536
- animationsIndices[i] = {
1537
- name: name,
1538
- index: i
1539
- };
1540
- }
1541
- glTFResource.animations = animationClips;
1542
- // @ts-ignore for editor
1543
- glTFResource._animationsIndices = animationsIndices;
1544
- animationClipsPromiseInfo.resolve(animationClips);
1545
- return animationClipsPromiseInfo.promise;
1486
+ });
1546
1487
  };
1547
- _proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
1488
+ GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
1548
1489
  var sampleData = sampleDataCollection[gltfChannel.sampler];
1549
1490
  var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
1550
- switch(animationchannelTargetPath){
1491
+ switch(animationChannelTargetPath){
1551
1492
  case AnimationChannelTargetPath.TRANSLATION:
1552
1493
  case AnimationChannelTargetPath.SCALE:
1553
1494
  {
@@ -1612,38 +1553,43 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
1612
1553
  }
1613
1554
  }
1614
1555
  };
1615
- return AnimationParser;
1616
- }(Parser);
1556
+ return GLTFAnimationParser;
1557
+ }(GLTFParser);
1617
1558
 
1618
- var BufferParser = /*#__PURE__*/ function(Parser) {
1619
- _inherits(BufferParser, Parser);
1620
- function BufferParser() {
1621
- return Parser.apply(this, arguments);
1559
+ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1560
+ _inherits(GLTFBufferParser, GLTFParser);
1561
+ function GLTFBufferParser() {
1562
+ return GLTFParser.apply(this, arguments);
1622
1563
  }
1623
- var _proto = BufferParser.prototype;
1564
+ var _proto = GLTFBufferParser.prototype;
1624
1565
  _proto.parse = function parse(context) {
1625
- var glTFResource = context.glTFResource;
1566
+ var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
1626
1567
  var url = glTFResource.url;
1627
- if (this._isGLB(url)) {
1628
- return engineCore.request(url, {
1629
- type: "arraybuffer"
1630
- }).then(GLTFUtil.parseGLB).then(function(param) {
1631
- var gltf = param.gltf, buffers = param.buffers;
1632
- context.gltf = gltf;
1633
- context.buffers = buffers;
1568
+ var restoreBufferRequests = contentRestorer.bufferRequests;
1569
+ var requestConfig = {
1570
+ type: "arraybuffer"
1571
+ };
1572
+ var isGLB = this._isGLB(url);
1573
+ contentRestorer.isGLB = isGLB;
1574
+ if (isGLB) {
1575
+ return engineCore.request(url, requestConfig).then(function(glb) {
1576
+ restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
1577
+ return GLTFUtils.parseGLB(context, glb);
1578
+ }).then(function(param) {
1579
+ var glTF = param.glTF, buffers = param.buffers;
1580
+ context.glTF = glTF;
1581
+ context._buffers = buffers;
1634
1582
  });
1635
1583
  } else {
1636
1584
  return engineCore.request(url, {
1637
1585
  type: "json"
1638
- }).then(function(gltf) {
1639
- context.gltf = gltf;
1640
- return Promise.all(gltf.buffers.map(function(buffer) {
1641
- return engineCore.request(GLTFUtil.parseRelativeUrl(url, buffer.uri), {
1642
- type: "arraybuffer"
1643
- });
1644
- })).then(function(buffers) {
1645
- context.buffers = buffers;
1646
- });
1586
+ }).then(function(glTF) {
1587
+ context.glTF = glTF;
1588
+ context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
1589
+ var absoluteUrl = engineCore.Utils.resolveAbsoluteUrl(url, buffer.uri);
1590
+ restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
1591
+ return engineCore.request(absoluteUrl, requestConfig);
1592
+ }));
1647
1593
  });
1648
1594
  }
1649
1595
  };
@@ -1651,24 +1597,24 @@ var BufferParser = /*#__PURE__*/ function(Parser) {
1651
1597
  var index = url.lastIndexOf(".");
1652
1598
  return url.substring(index + 1, index + 4) === "glb";
1653
1599
  };
1654
- return BufferParser;
1655
- }(Parser);
1600
+ return GLTFBufferParser;
1601
+ }(GLTFParser);
1656
1602
 
1657
- var EntityParser = /*#__PURE__*/ function(Parser) {
1658
- _inherits(EntityParser, Parser);
1659
- function EntityParser() {
1660
- return Parser.apply(this, arguments);
1603
+ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1604
+ _inherits(GLTFEntityParser, GLTFParser);
1605
+ function GLTFEntityParser() {
1606
+ return GLTFParser.apply(this, arguments);
1661
1607
  }
1662
- var _proto = EntityParser.prototype;
1608
+ var _proto = GLTFEntityParser.prototype;
1663
1609
  _proto.parse = function parse(context) {
1664
- var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
1610
+ var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
1665
1611
  var engine = glTFResource.engine;
1666
1612
  if (!nodes) return;
1667
1613
  var entities = [];
1668
1614
  for(var i = 0; i < nodes.length; i++){
1669
1615
  var gltfNode = nodes[i];
1670
1616
  var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
1671
- var entity = new engineCore.Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
1617
+ var entity = new engineCore.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
1672
1618
  var transform = entity.transform;
1673
1619
  if (matrix) {
1674
1620
  var localMatrix = transform.localMatrix;
@@ -1692,7 +1638,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1692
1638
  this._createSceneRoots(context, glTFResource);
1693
1639
  };
1694
1640
  _proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
1695
- var nodes = context.gltf.nodes;
1641
+ var nodes = context.glTF.nodes;
1696
1642
  var entities = glTFResource.entities;
1697
1643
  for(var i = 0; i < nodes.length; i++){
1698
1644
  var children = nodes[i].children;
@@ -1706,7 +1652,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1706
1652
  }
1707
1653
  };
1708
1654
  _proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
1709
- var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
1655
+ var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
1710
1656
  var engine = glTFResource.engine, entities = glTFResource.entities;
1711
1657
  if (!scenes) return;
1712
1658
  var sceneRoots = [];
@@ -1722,337 +1668,433 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1722
1668
  }
1723
1669
  sceneRoots[i] = rootEntity;
1724
1670
  }
1671
+ // @ts-ignore
1672
+ sceneRoots[i]._hookResource = glTFResource;
1673
+ // @ts-ignore
1674
+ glTFResource._addReferCount(1);
1725
1675
  }
1726
1676
  glTFResource.sceneRoots = sceneRoots;
1727
1677
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
1728
1678
  };
1729
- return EntityParser;
1730
- }(Parser);
1679
+ return GLTFEntityParser;
1680
+ }(GLTFParser);
1731
1681
  (function() {
1732
- /** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
1682
+ /** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
1733
1683
  })();
1734
1684
 
1735
- var MeshParser = /*#__PURE__*/ function(Parser1) {
1736
- _inherits(MeshParser, Parser1);
1737
- function MeshParser() {
1738
- return Parser1.apply(this, arguments);
1685
+ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
1686
+ _inherits(GLTFMaterialParser, GLTFParser1);
1687
+ function GLTFMaterialParser() {
1688
+ return GLTFParser1.apply(this, arguments);
1739
1689
  }
1740
- var _proto = MeshParser.prototype;
1690
+ var _proto = GLTFMaterialParser.prototype;
1741
1691
  _proto.parse = function parse(context) {
1742
- var _loop = function(i) {
1743
- var _loop = function(j) {
1744
- var gltfPrimitive = gltfMesh.primitives[j];
1745
- var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
1746
- var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
1747
- primitivePromises[j] = new Promise(function(resolve) {
1748
- var mesh = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
1749
- if (KHR_draco_mesh_compression) {
1750
- Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
1751
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1752
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
1753
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
1754
- return decodedGeometry.attributes[j].array;
1755
- }
1756
- }
1757
- return null;
1758
- }, function(attributeSemantic, shapeIndex) {
1759
- throw "BlendShape animation is not supported when using draco.";
1760
- }, function() {
1761
- return decodedGeometry.index.array;
1762
- }, context.keepMeshData);
1763
- }).then(resolve);
1764
- } else {
1765
- _this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1766
- return null;
1767
- }, function(attributeName, shapeIndex) {
1768
- var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1769
- var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1770
- if (attributeAccessorIdx) {
1771
- var accessor = gltf.accessors[attributeAccessorIdx];
1772
- return GLTFUtil.getAccessorData(gltf, accessor, buffers);
1773
- } else {
1774
- return null;
1692
+ var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
1693
+ if (!glTF.materials) return;
1694
+ var engine = glTFResource.engine;
1695
+ var materialPromises = [];
1696
+ for(var i = 0; i < glTF.materials.length; i++){
1697
+ var materialInfo = glTF.materials[i];
1698
+ var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
1699
+ if (!material) {
1700
+ material = new engineCore.PBRMaterial(engine);
1701
+ material.name = materialInfo.name;
1702
+ GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
1703
+ }
1704
+ materialPromises.push(material);
1705
+ }
1706
+ return engineCore.AssetPromise.all(materialPromises).then(function(materials) {
1707
+ glTFResource.materials = materials;
1708
+ for(var i = 0; i < glTF.materials.length; i++){
1709
+ var materialInfo = glTF.materials[i];
1710
+ GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
1711
+ }
1712
+ materialsPromiseInfo.resolve(materials);
1713
+ return materialsPromiseInfo.promise;
1714
+ });
1715
+ };
1716
+ /**
1717
+ * @internal
1718
+ */ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
1719
+ var _texture_extensions;
1720
+ if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
1721
+ engineCore.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
1722
+ }
1723
+ };
1724
+ /**
1725
+ * @internal
1726
+ */ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
1727
+ var textures = context.glTFResource.textures;
1728
+ var pbrMetallicRoughness = materialInfo.pbrMetallicRoughness, normalTexture = materialInfo.normalTexture, occlusionTexture = materialInfo.occlusionTexture, emissiveTexture = materialInfo.emissiveTexture, emissiveFactor = materialInfo.emissiveFactor, alphaMode = materialInfo.alphaMode, alphaCutoff = materialInfo.alphaCutoff, doubleSided = materialInfo.doubleSided;
1729
+ if (pbrMetallicRoughness) {
1730
+ var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1731
+ if (baseColorFactor) {
1732
+ material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(baseColorFactor[0]), engineMath.Color.linearToGammaSpace(baseColorFactor[1]), engineMath.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
1733
+ }
1734
+ if (baseColorTexture) {
1735
+ material.baseTexture = textures[baseColorTexture.index];
1736
+ GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
1737
+ }
1738
+ if (material.constructor === engineCore.PBRMaterial) {
1739
+ material.metallic = metallicFactor != null ? metallicFactor : 1;
1740
+ material.roughness = roughnessFactor != null ? roughnessFactor : 1;
1741
+ if (metallicRoughnessTexture) {
1742
+ material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1743
+ GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
1744
+ }
1745
+ }
1746
+ }
1747
+ if (material.constructor === engineCore.PBRMaterial || material.constructor === engineCore.PBRSpecularMaterial) {
1748
+ if (emissiveTexture) {
1749
+ material.emissiveTexture = textures[emissiveTexture.index];
1750
+ GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
1751
+ }
1752
+ if (emissiveFactor) {
1753
+ material.emissiveColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(emissiveFactor[0]), engineMath.Color.linearToGammaSpace(emissiveFactor[1]), engineMath.Color.linearToGammaSpace(emissiveFactor[2]));
1754
+ }
1755
+ if (normalTexture) {
1756
+ var index = normalTexture.index, scale = normalTexture.scale;
1757
+ material.normalTexture = textures[index];
1758
+ GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
1759
+ if (scale !== undefined) {
1760
+ material.normalTextureIntensity = scale;
1761
+ }
1762
+ }
1763
+ if (occlusionTexture) {
1764
+ var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1765
+ material.occlusionTexture = textures[index1];
1766
+ GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
1767
+ if (strength !== undefined) {
1768
+ material.occlusionTextureIntensity = strength;
1769
+ }
1770
+ if (texCoord === engineCore.TextureCoordinate.UV1) {
1771
+ material.occlusionTextureCoord = engineCore.TextureCoordinate.UV1;
1772
+ } else if (texCoord > engineCore.TextureCoordinate.UV1) {
1773
+ engineCore.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1774
+ }
1775
+ }
1776
+ }
1777
+ if (doubleSided) {
1778
+ material.renderFace = engineCore.RenderFace.Double;
1779
+ } else {
1780
+ material.renderFace = engineCore.RenderFace.Front;
1781
+ }
1782
+ switch(alphaMode){
1783
+ case MaterialAlphaMode.OPAQUE:
1784
+ material.isTransparent = false;
1785
+ break;
1786
+ case MaterialAlphaMode.BLEND:
1787
+ material.isTransparent = true;
1788
+ break;
1789
+ case MaterialAlphaMode.MASK:
1790
+ material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1791
+ break;
1792
+ }
1793
+ };
1794
+ return GLTFMaterialParser;
1795
+ }(GLTFParser);
1796
+
1797
+ function _instanceof(left, right) {
1798
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1799
+ return !!right[Symbol.hasInstance](left);
1800
+ } else return left instanceof right;
1801
+ }
1802
+
1803
+ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1804
+ _inherits(GLTFMeshParser, GLTFParser1);
1805
+ function GLTFMeshParser() {
1806
+ return GLTFParser1.apply(this, arguments);
1807
+ }
1808
+ var _proto = GLTFMeshParser.prototype;
1809
+ _proto.parse = function parse(context) {
1810
+ var _loop = function(i) {
1811
+ var _loop = function(j) {
1812
+ var gltfPrimitive = gltfMesh.primitives[j];
1813
+ primitivePromises[j] = new Promise(function(resolve) {
1814
+ var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
1815
+ if (mesh) {
1816
+ if (_instanceof(mesh, engineCore.ModelMesh)) {
1817
+ resolve(mesh);
1818
+ } else {
1819
+ mesh.then(function(mesh) {
1820
+ return resolve(mesh);
1821
+ });
1822
+ }
1823
+ } else {
1824
+ var mesh1 = new engineCore.ModelMesh(engine, gltfMesh.name || j + "");
1825
+ var meshRestoreInfo = new ModelMeshRestoreInfo();
1826
+ meshRestoreInfo.mesh = mesh1;
1827
+ context.contentRestorer.meshes.push(meshRestoreInfo);
1828
+ GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
1829
+ return null;
1830
+ }, function(attributeName, shapeIndex) {
1831
+ var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1832
+ var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1833
+ if (attributeAccessorIdx) {
1834
+ var accessor = glTF.accessors[attributeAccessorIdx];
1835
+ return GLTFUtils.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
1836
+ } else {
1837
+ return null;
1775
1838
  }
1776
1839
  }, function() {
1777
- var indexAccessor = gltf.accessors[gltfPrimitive.indices];
1778
- return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
1840
+ var indexAccessor = glTF.accessors[gltfPrimitive.indices];
1841
+ return context.getBuffers().then(function(buffers) {
1842
+ return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
1843
+ });
1779
1844
  }, context.keepMeshData).then(resolve);
1780
1845
  }
1781
1846
  });
1782
1847
  };
1783
- var gltfMesh = gltf.meshes[i];
1848
+ var gltfMesh = glTF.meshes[i];
1784
1849
  var primitivePromises = [];
1785
1850
  for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1786
1851
  meshPromises[i] = Promise.all(primitivePromises);
1787
1852
  };
1788
- var _this = this;
1789
- var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
1853
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1790
1854
  var engine = glTFResource.engine;
1791
- if (!gltf.meshes) return;
1855
+ if (!glTF.meshes) return;
1792
1856
  var meshesPromiseInfo = context.meshesPromiseInfo;
1793
1857
  var meshPromises = [];
1794
- for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
1858
+ for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
1795
1859
  engineCore.AssetPromise.all(meshPromises).then(function(meshes) {
1796
1860
  glTFResource.meshes = meshes;
1797
1861
  meshesPromiseInfo.resolve(meshes);
1798
1862
  }).catch(meshesPromiseInfo.reject);
1799
1863
  return meshesPromiseInfo.promise;
1800
1864
  };
1801
- _proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1802
- var accessors = gltf.accessors;
1803
- context.buffers;
1804
- var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1805
- var engine = mesh.engine;
1806
- var vertexElements = new Array();
1807
- var vertexCount;
1808
- var bufferBindIndex = 0;
1809
- var positions;
1810
- keepMeshData && (positions = new Array(vertexCount));
1811
- for(var attribute in attributes){
1865
+ /**
1866
+ * @internal
1867
+ */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1868
+ var _loop = function(attribute) {
1812
1869
  var accessor = accessors[attributes[attribute]];
1813
- var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
1814
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1815
- var attributeCount = accessor.count;
1816
- var vertices = accessorBuffer.data;
1817
- var vertexElement = void 0;
1818
- var meshId = mesh.instanceId;
1819
- var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1820
- var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
1821
- if (accessorBuffer.interleaved) {
1822
- var byteOffset = accessor.byteOffset || 0;
1823
- var stride = accessorBuffer.stride;
1824
- var elementOffset = byteOffset % stride;
1825
- if (vertexBindingInfos[meshId] === undefined) {
1826
- vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1827
- var vertexBuffer = accessorBuffer.vertexBuffer;
1828
- if (!vertexBuffer) {
1829
- vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
1830
- vertexBuffer.setData(vertices);
1831
- accessorBuffer.vertexBuffer = vertexBuffer;
1870
+ var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
1871
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1872
+ var accessorCount = accessor.count;
1873
+ var vertices = accessorBuffer.data;
1874
+ var vertexElement;
1875
+ var meshId = mesh.instanceId;
1876
+ var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1877
+ var elementNormalized = accessor.normalized;
1878
+ var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
1879
+ var scaleFactor;
1880
+ elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
1881
+ var elementOffset;
1882
+ if (accessorBuffer.interleaved) {
1883
+ var byteOffset = accessor.byteOffset || 0;
1884
+ var stride = accessorBuffer.stride;
1885
+ elementOffset = byteOffset % stride;
1886
+ if (vertexBindingInfos[meshId] === undefined) {
1887
+ vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1888
+ var vertexBuffer = accessorBuffer.vertexBuffer;
1889
+ if (!vertexBuffer) {
1890
+ vertexBuffer = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
1891
+ vertexBuffer.setData(vertices);
1892
+ accessorBuffer.vertexBuffer = vertexBuffer;
1893
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1894
+ }
1895
+ mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1896
+ vertexBindingInfos[meshId] = bufferBindIndex++;
1897
+ } else {
1898
+ vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
1832
1899
  }
1833
- mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1834
- vertexBindingInfos[meshId] = bufferBindIndex++;
1835
1900
  } else {
1836
- vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
1901
+ elementOffset = 0;
1902
+ vertexElement = new engineCore.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1903
+ var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
1904
+ vertexBuffer1.setData(vertices);
1905
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1906
+ mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1907
+ vertexBindingInfos[meshId] = bufferBindIndex++;
1837
1908
  }
1838
- } else {
1839
- vertexElement = new engineCore.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
1840
- var vertexBuffer1 = new engineCore.Buffer(engine, engineCore.BufferBindFlag.VertexBuffer, vertices.byteLength, engineCore.BufferUsage.Static);
1841
- vertexBuffer1.setData(vertices);
1842
- mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1843
- vertexBindingInfos[meshId] = bufferBindIndex++;
1844
- }
1845
- vertexElements.push(vertexElement);
1846
- if (attribute === "POSITION") {
1847
- vertexCount = attributeCount;
1848
- var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
1849
- if (accessor.min && accessor.max) {
1850
- min.copyFromArray(accessor.min);
1851
- max.copyFromArray(accessor.max);
1852
- if (keepMeshData) {
1853
- var stride1 = vertices.length / attributeCount;
1854
- for(var j = 0; j < attributeCount; j++){
1855
- var offset = j * stride1;
1856
- positions[j] = new engineMath.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1909
+ vertexElements.push(vertexElement);
1910
+ if (attribute === "POSITION") {
1911
+ vertexCount = accessorCount;
1912
+ var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
1913
+ if (accessor.min && accessor.max) {
1914
+ min.copyFromArray(accessor.min);
1915
+ max.copyFromArray(accessor.max);
1916
+ if (keepMeshData) {
1917
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
1918
+ var stride1 = vertices.length / accessorCount;
1919
+ for(var j = 0; j < accessorCount; j++){
1920
+ var offset = baseOffset + j * stride1;
1921
+ var position = new engineMath.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1922
+ elementNormalized && position.scale(scaleFactor);
1923
+ positions[j] = position;
1924
+ }
1925
+ }
1926
+ } else {
1927
+ var position1 = GLTFMeshParser._tempVector3;
1928
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1929
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1930
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
1931
+ var stride2 = vertices.length / accessorCount;
1932
+ for(var j1 = 0; j1 < accessorCount; j1++){
1933
+ var offset1 = baseOffset1 + j1 * stride2;
1934
+ position1.copyFromArray(vertices, offset1);
1935
+ engineMath.Vector3.min(min, position1, min);
1936
+ engineMath.Vector3.max(max, position1, max);
1937
+ if (keepMeshData) {
1938
+ var clonePosition = position1.clone();
1939
+ elementNormalized && clonePosition.scale(scaleFactor);
1940
+ positions[j1] = clonePosition;
1941
+ }
1857
1942
  }
1858
1943
  }
1859
- } else {
1860
- var position = MeshParser._tempVector3;
1861
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1862
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1863
- var stride2 = vertices.length / attributeCount;
1864
- for(var j1 = 0; j1 < attributeCount; j1++){
1865
- var offset1 = j1 * stride2;
1866
- position.copyFromArray(vertices, offset1);
1867
- engineMath.Vector3.min(min, position, min);
1868
- engineMath.Vector3.max(max, position, max);
1869
- keepMeshData && (positions[j1] = position.clone());
1944
+ if (elementNormalized) {
1945
+ min.scale(scaleFactor);
1946
+ max.scale(scaleFactor);
1947
+ }
1948
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
1949
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
1950
+ var stride3 = vertices.length / accessorCount;
1951
+ for(var j2 = 0; j2 < accessorCount; j2++){
1952
+ var offset2 = baseOffset2 + j2 * stride3;
1953
+ var boneIndex = new engineMath.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
1954
+ elementNormalized && boneIndex.scale(scaleFactor);
1955
+ boneIndices[j2] = boneIndex;
1956
+ }
1957
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
1958
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
1959
+ var stride4 = vertices.length / accessorCount;
1960
+ for(var j3 = 0; j3 < accessorCount; j3++){
1961
+ var offset3 = baseOffset3 + j3 * stride4;
1962
+ var boneWeight = new engineMath.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
1963
+ elementNormalized && boneWeight.scale(scaleFactor);
1964
+ boneWeights[j3] = boneWeight;
1870
1965
  }
1871
1966
  }
1872
- if (accessor.normalized) {
1873
- var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1874
- min.scale(sacleFactor);
1875
- max.scale(sacleFactor);
1876
- }
1877
- }
1878
- }
1879
- mesh.setVertexElements(vertexElements);
1880
- // Indices
1881
- if (indices !== undefined) {
1882
- var indexAccessor = gltf.accessors[indices];
1883
- var indexData = getIndexBufferData();
1884
- mesh.setIndices(indexData);
1885
- mesh.addSubMesh(0, indexAccessor.count, mode);
1886
- } else {
1887
- mesh.addSubMesh(0, vertexCount, mode);
1888
- }
1889
- // BlendShapes
1890
- targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
1891
- mesh.uploadData(!keepMeshData);
1892
- //@ts-ignore
1893
- mesh._positions = positions;
1894
- return Promise.resolve(mesh);
1895
- };
1896
- _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
1897
- var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
1898
- for(var i = 0, n = glTFTargets.length; i < n; i++){
1899
- var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1900
- var deltaPosBuffer = getBlendShapeData("POSITION", i);
1901
- var deltaNorBuffer = getBlendShapeData("NORMAL", i);
1902
- var deltaTanBuffer = getBlendShapeData("TANGENT", i);
1903
- var deltaPositions = deltaPosBuffer ? GLTFUtil.floatBufferToVector3Array(deltaPosBuffer) : null;
1904
- var deltaNormals = deltaNorBuffer ? GLTFUtil.floatBufferToVector3Array(deltaNorBuffer) : null;
1905
- var deltaTangents = deltaTanBuffer ? GLTFUtil.floatBufferToVector3Array(deltaTanBuffer) : null;
1906
- var blendShape = new engineCore.BlendShape(name);
1907
- blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
1908
- mesh.addBlendShape(blendShape);
1909
- }
1910
- };
1911
- /**
1912
- * @deprecated
1913
- */ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1967
+ });
1968
+ promises.push(promise);
1969
+ };
1970
+ var accessors = gltf.accessors;
1914
1971
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1972
+ var engine = mesh.engine;
1973
+ var vertexElements = new Array();
1915
1974
  var vertexCount;
1916
- var accessors = gltf.accessors;
1917
- var accessor = accessors[attributes["POSITION"]];
1918
- var positionBuffer = getVertexBufferData("POSITION");
1919
- var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
1920
- mesh.setPositions(positions);
1921
- var bounds = mesh.bounds;
1922
- vertexCount = accessor.count;
1923
- if (accessor.min && accessor.max) {
1924
- bounds.min.copyFromArray(accessor.min);
1925
- bounds.max.copyFromArray(accessor.max);
1926
- } else {
1927
- var position = MeshParser._tempVector3;
1928
- var min = bounds.min, max = bounds.max;
1929
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1930
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1931
- var stride = positionBuffer.length / vertexCount;
1932
- for(var j = 0; j < vertexCount; j++){
1933
- var offset = j * stride;
1934
- position.copyFromArray(positionBuffer, offset);
1935
- engineMath.Vector3.min(min, position, min);
1936
- engineMath.Vector3.max(max, position, max);
1937
- }
1975
+ var bufferBindIndex = 0;
1976
+ var positions;
1977
+ var boneIndices;
1978
+ var boneWeights;
1979
+ if (keepMeshData) {
1980
+ positions = new Array(vertexCount);
1981
+ boneIndices = new Array(vertexCount);
1982
+ boneWeights = new Array(vertexCount);
1938
1983
  }
1939
- for(var attributeSemantic in attributes){
1940
- if (attributeSemantic === "POSITION") {
1941
- continue;
1984
+ var promises = new Array();
1985
+ for(var attribute in attributes)_loop(attribute);
1986
+ return Promise.all(promises).then(function() {
1987
+ mesh.setVertexElements(vertexElements);
1988
+ // Indices
1989
+ if (indices !== undefined) {
1990
+ var indexAccessor = gltf.accessors[indices];
1991
+ var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
1992
+ mesh.setIndices(accessorBuffer.data);
1993
+ mesh.addSubMesh(0, indexAccessor.count, mode);
1994
+ meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
1995
+ });
1996
+ promises.push(promise);
1997
+ } else {
1998
+ mesh.addSubMesh(0, vertexCount, mode);
1942
1999
  }
1943
- var bufferData = getVertexBufferData(attributeSemantic);
1944
- switch(attributeSemantic){
1945
- case "NORMAL":
1946
- var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
1947
- mesh.setNormals(normals);
1948
- break;
1949
- case "TEXCOORD_0":
1950
- var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
1951
- mesh.setUVs(texturecoords, 0);
1952
- break;
1953
- case "TEXCOORD_1":
1954
- var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
1955
- mesh.setUVs(texturecoords1, 1);
1956
- break;
1957
- case "TEXCOORD_2":
1958
- var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
1959
- mesh.setUVs(texturecoords2, 2);
1960
- break;
1961
- case "TEXCOORD_3":
1962
- var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
1963
- mesh.setUVs(texturecoords3, 3);
1964
- break;
1965
- case "TEXCOORD_4":
1966
- var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
1967
- mesh.setUVs(texturecoords4, 4);
1968
- break;
1969
- case "TEXCOORD_5":
1970
- var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
1971
- mesh.setUVs(texturecoords5, 5);
1972
- break;
1973
- case "TEXCOORD_6":
1974
- var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
1975
- mesh.setUVs(texturecoords6, 6);
1976
- break;
1977
- case "TEXCOORD_7":
1978
- var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
1979
- mesh.setUVs(texturecoords7, 7);
1980
- break;
1981
- case "COLOR_0":
1982
- var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
1983
- mesh.setColors(colors);
1984
- break;
1985
- case "TANGENT":
1986
- var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
1987
- mesh.setTangents(tangents);
1988
- break;
1989
- case "JOINTS_0":
1990
- var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
1991
- mesh.setBoneIndices(joints);
1992
- break;
1993
- case "WEIGHTS_0":
1994
- var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
1995
- mesh.setBoneWeights(weights);
1996
- break;
2000
+ // BlendShapes
2001
+ if (targets) {
2002
+ promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
1997
2003
  }
1998
- }
1999
- // Indices
2000
- if (indices !== undefined) {
2001
- var indexAccessor = gltf.accessors[indices];
2002
- var indexData = getIndexBufferData();
2003
- mesh.setIndices(indexData);
2004
- mesh.addSubMesh(0, indexAccessor.count, mode);
2005
- } else {
2006
- mesh.addSubMesh(0, vertexCount, mode);
2007
- }
2008
- // BlendShapes
2009
- targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
2010
- mesh.uploadData(!keepMeshData);
2011
- return Promise.resolve(mesh);
2004
+ return Promise.all(promises).then(function() {
2005
+ mesh.uploadData(!keepMeshData);
2006
+ //@ts-ignore
2007
+ mesh._positions = positions;
2008
+ //@ts-ignore
2009
+ mesh._boneIndices = boneIndices;
2010
+ //@ts-ignore
2011
+ mesh._boneWeights = boneWeights;
2012
+ return Promise.resolve(mesh);
2013
+ });
2014
+ });
2015
+ };
2016
+ /**
2017
+ * @internal
2018
+ */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
2019
+ var _loop = function(i, n) {
2020
+ var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
2021
+ var promise = Promise.all([
2022
+ getBlendShapeData("POSITION", i),
2023
+ getBlendShapeData("NORMAL", i),
2024
+ getBlendShapeData("TANGENT", i)
2025
+ ]).then(function(infos) {
2026
+ var posBufferInfo = infos[0];
2027
+ var norBufferInfo = infos[1];
2028
+ var tanBufferInfo = infos[2];
2029
+ var target = glTFTargets[i];
2030
+ var posAccessor;
2031
+ var norAccessor;
2032
+ var tanAccessor;
2033
+ var positions = null;
2034
+ if (posBufferInfo) {
2035
+ posAccessor = accessors[target["POSITION"]];
2036
+ var _posAccessor_byteOffset;
2037
+ positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
2038
+ }
2039
+ var normals = null;
2040
+ if (norBufferInfo) {
2041
+ norAccessor = accessors[target["NORMAL"]];
2042
+ var _norAccessor_byteOffset;
2043
+ normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
2044
+ }
2045
+ var tangents = null;
2046
+ if (tanBufferInfo) {
2047
+ tanAccessor = accessors[target["NORMAL"]];
2048
+ var _tanAccessor_byteOffset;
2049
+ tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
2050
+ }
2051
+ var blendShape = new engineCore.BlendShape(name);
2052
+ blendShape.addFrame(1.0, positions, normals, tangents);
2053
+ mesh.addBlendShape(blendShape);
2054
+ var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
2055
+ meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
2056
+ });
2057
+ promises.push(promise);
2058
+ };
2059
+ var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
2060
+ var promises = new Array();
2061
+ for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
2062
+ return Promise.all(promises);
2012
2063
  };
2013
- return MeshParser;
2014
- }(Parser);
2064
+ return GLTFMeshParser;
2065
+ }(GLTFParser);
2015
2066
  (function() {
2016
- MeshParser._tempVector3 = new engineMath.Vector3();
2067
+ GLTFMeshParser._tempVector3 = new engineMath.Vector3();
2017
2068
  })();
2018
2069
 
2019
- var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2020
- _inherits(SceneParser, Parser1);
2021
- function SceneParser() {
2022
- return Parser1.apply(this, arguments);
2070
+ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2071
+ _inherits(GLTFSceneParser, GLTFParser1);
2072
+ function GLTFSceneParser() {
2073
+ return GLTFParser1.apply(this, arguments);
2023
2074
  }
2024
- var _proto = SceneParser.prototype;
2075
+ var _proto = GLTFSceneParser.prototype;
2025
2076
  _proto.parse = function parse(context) {
2026
- var glTFResource = context.glTFResource, gltf = context.gltf;
2077
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2027
2078
  var entities = glTFResource.entities;
2028
- var nodes = gltf.nodes, gltfCameras = gltf.cameras;
2079
+ var nodes = glTF.nodes, cameras = glTF.cameras;
2029
2080
  if (!nodes) return;
2030
2081
  var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
2031
- var promises = [];
2032
2082
  for(var i = 0; i < nodes.length; i++){
2033
- var gltfNode = nodes[i];
2034
- var cameraID = gltfNode.camera, meshID = gltfNode.mesh, _gltfNode_extensions = gltfNode.extensions, extensions = _gltfNode_extensions === void 0 ? {} : _gltfNode_extensions;
2035
- var KHR_lights_punctual = extensions.KHR_lights_punctual;
2083
+ var glTFNode = nodes[i];
2084
+ var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
2036
2085
  var entity = entities[i];
2037
2086
  if (cameraID !== undefined) {
2038
- this._createCamera(glTFResource, gltfCameras[cameraID], entity);
2087
+ this._createCamera(glTFResource, cameras[cameraID], entity);
2039
2088
  }
2040
2089
  if (meshID !== undefined) {
2041
- promises.push(this._createRenderer(context, gltfNode, entity));
2042
- }
2043
- if (KHR_lights_punctual) {
2044
- var lightIndex = KHR_lights_punctual.light;
2045
- var lights = gltf.extensions.KHR_lights_punctual.lights;
2046
- Parser.parseEngineResource("KHR_lights_punctual", lights[lightIndex], entity, context);
2090
+ this._createRenderer(context, glTFNode, entity);
2047
2091
  }
2092
+ GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
2048
2093
  }
2049
2094
  if (glTFResource.defaultSceneRoot) {
2050
2095
  this._createAnimator(context);
2051
2096
  }
2052
- gltf.extensions && delete gltf.extensions["OASIS_materials_remap"];
2053
- engineCore.AssetPromise.all(promises).then(function() {
2054
- return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2055
- }).catch(defaultSceneRootPromiseInfo.reject);
2097
+ defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2056
2098
  return defaultSceneRootPromiseInfo.promise;
2057
2099
  };
2058
2100
  _proto._createCamera = function _createCamera(context, cameraSchema, entity) {
@@ -2088,8 +2130,9 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2088
2130
  // @todo: use engine camera by default
2089
2131
  camera.enabled = false;
2090
2132
  };
2091
- _proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
2133
+ _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
2092
2134
  var _loop = function(i) {
2135
+ var gltfPrimitive = glTFMeshPrimitives[i];
2093
2136
  var mesh = meshes[meshID][i];
2094
2137
  var renderer = void 0;
2095
2138
  if (skinID !== undefined || blendShapeWeights) {
@@ -2107,32 +2150,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2107
2150
  renderer = entity.addComponent(engineCore.MeshRenderer);
2108
2151
  renderer.mesh = mesh;
2109
2152
  }
2110
- var materialIndex = gltfMeshPrimitives[i].material;
2111
- var remapMaterials = gltf.extensions && gltf.extensions["OASIS_materials_remap"];
2112
- if (remapMaterials && remapMaterials[materialIndex]) {
2113
- promises.push(remapMaterials[materialIndex].then(function(mtl) {
2114
- renderer.setMaterial(mtl);
2115
- }));
2116
- } else {
2117
- var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
2118
- renderer.setMaterial(material);
2119
- }
2120
- var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
2121
- var KHR_materials_variants = extensions.KHR_materials_variants;
2122
- if (KHR_materials_variants) {
2123
- Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
2124
- }
2153
+ var materialIndex = gltfPrimitive.material;
2154
+ var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
2155
+ renderer.setMaterial(material);
2156
+ // Enable vertex color if mesh has COLOR_0 vertex element
2157
+ mesh.vertexElements.forEach(function(element) {
2158
+ if (element.semantic === "COLOR_0") {
2159
+ renderer.enableVertexColor = true;
2160
+ }
2161
+ });
2162
+ GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
2125
2163
  };
2126
- var glTFResource = context.glTFResource, gltf = context.gltf;
2127
- var gltfMeshes = gltf.meshes;
2164
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2165
+ var glTFMeshes = glTF.meshes;
2128
2166
  var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2129
- var meshID = gltfNode.mesh, skinID = gltfNode.skin;
2130
- var glTFMesh = gltfMeshes[meshID];
2131
- var gltfMeshPrimitives = glTFMesh.primitives;
2132
- var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
2133
- var promises = [];
2134
- for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
2135
- return Promise.all(promises);
2167
+ var meshID = glTFNode.mesh, skinID = glTFNode.skin;
2168
+ var glTFMesh = glTFMeshes[meshID];
2169
+ var glTFMeshPrimitives = glTFMesh.primitives;
2170
+ var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
2171
+ for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
2136
2172
  };
2137
2173
  _proto._createAnimator = function _createAnimator(context) {
2138
2174
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -2159,67 +2195,74 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2159
2195
  }
2160
2196
  }
2161
2197
  };
2162
- SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2163
- if (!SceneParser._defaultMaterial) {
2164
- SceneParser._defaultMaterial = new engineCore.BlinnPhongMaterial(engine);
2198
+ GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2199
+ if (!GLTFSceneParser._defaultMaterial) {
2200
+ GLTFSceneParser._defaultMaterial = new engineCore.BlinnPhongMaterial(engine);
2165
2201
  }
2166
- return SceneParser._defaultMaterial;
2202
+ return GLTFSceneParser._defaultMaterial;
2167
2203
  };
2168
- return SceneParser;
2169
- }(Parser);
2204
+ return GLTFSceneParser;
2205
+ }(GLTFParser);
2170
2206
 
2171
- var SkinParser = /*#__PURE__*/ function(Parser) {
2172
- _inherits(SkinParser, Parser);
2173
- function SkinParser() {
2174
- return Parser.apply(this, arguments);
2207
+ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2208
+ _inherits(GLTFSkinParser, GLTFParser);
2209
+ function GLTFSkinParser() {
2210
+ return GLTFParser.apply(this, arguments);
2175
2211
  }
2176
- var _proto = SkinParser.prototype;
2212
+ var _proto = GLTFSkinParser.prototype;
2177
2213
  _proto.parse = function parse(context) {
2178
- var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
2179
- var entities = glTFResource.entities;
2180
- var gltfSkins = gltf.skins;
2181
- if (!gltfSkins) return;
2182
- var count = gltfSkins.length;
2183
- var skins = new Array(count);
2184
- for(var i = 0; i < count; i++){
2214
+ var _loop = function(i) {
2185
2215
  var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
2186
2216
  var jointCount = joints.length;
2187
2217
  var skin = new engineCore.Skin(name);
2188
2218
  skin.inverseBindMatrices.length = jointCount;
2189
2219
  // parse IBM
2190
- var accessor = gltf.accessors[inverseBindMatrices];
2191
- var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
2192
- for(var i1 = 0; i1 < jointCount; i1++){
2193
- var inverseBindMatrix = new engineMath.Matrix();
2194
- inverseBindMatrix.copyFromArray(buffer, i1 * 16);
2195
- skin.inverseBindMatrices[i1] = inverseBindMatrix;
2196
- }
2197
- // get joints
2198
- for(var i2 = 0; i2 < jointCount; i2++){
2199
- var jointIndex = joints[i2];
2200
- var jointName = entities[jointIndex].name;
2201
- skin.joints[i2] = jointName;
2202
- // @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
2203
- for(var j = entities.length - 1; j >= 0; j--){
2204
- if (jointIndex !== j && entities[j].name === jointName) {
2205
- entities[j].name = jointName + "_" + j;
2220
+ var accessor = glTF.accessors[inverseBindMatrices];
2221
+ var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
2222
+ var buffer = bufferInfo.data;
2223
+ for(var i = 0; i < jointCount; i++){
2224
+ var inverseBindMatrix = new engineMath.Matrix();
2225
+ inverseBindMatrix.copyFromArray(buffer, i * 16);
2226
+ skin.inverseBindMatrices[i] = inverseBindMatrix;
2227
+ // get joints
2228
+ for(var i1 = 0; i1 < jointCount; i1++){
2229
+ var jointIndex = joints[i1];
2230
+ var jointName = entities[jointIndex].name;
2231
+ skin.joints[i1] = jointName;
2232
+ // @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
2233
+ for(var j = entities.length - 1; j >= 0; j--){
2234
+ if (jointIndex !== j && entities[j].name === jointName) {
2235
+ entities[j].name = jointName + "_" + j;
2236
+ }
2237
+ }
2238
+ }
2239
+ // get skeleton
2240
+ if (skeleton !== undefined) {
2241
+ skin.skeleton = entities[skeleton].name;
2242
+ } else {
2243
+ var rootBone = _this._findSkeletonRootBone(joints, entities);
2244
+ if (rootBone) {
2245
+ skin.skeleton = rootBone.name;
2246
+ } else {
2247
+ throw "Failed to find skeleton root bone.";
2248
+ }
2206
2249
  }
2207
2250
  }
2208
- }
2209
- // get skeleton
2210
- if (skeleton !== undefined) {
2211
- skin.skeleton = entities[skeleton].name;
2212
- } else {
2213
- var rootBone = this._findSkeletonRootBone(joints, entities);
2214
- if (rootBone) {
2215
- skin.skeleton = rootBone.name;
2216
- } else {
2217
- throw "Failed to find skeleton root bone.";
2218
- }
2219
- }
2220
- skins[i] = skin;
2221
- }
2222
- glTFResource.skins = skins;
2251
+ return skin;
2252
+ });
2253
+ promises.push(promise);
2254
+ };
2255
+ var _this = this;
2256
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2257
+ var entities = glTFResource.entities;
2258
+ var gltfSkins = glTF.skins;
2259
+ if (!gltfSkins) return;
2260
+ var count = gltfSkins.length;
2261
+ var promises = new Array();
2262
+ for(var i = 0; i < count; i++)_loop(i);
2263
+ return engineCore.AssetPromise.all(promises).then(function(skins) {
2264
+ glTFResource.skins = skins;
2265
+ });
2223
2266
  };
2224
2267
  _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
2225
2268
  var paths = {};
@@ -2249,53 +2292,62 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
2249
2292
  rootNode = entity1;
2250
2293
  }
2251
2294
  };
2252
- return SkinParser;
2253
- }(Parser);
2295
+ return GLTFSkinParser;
2296
+ }(GLTFParser);
2254
2297
 
2255
- var TextureParser = /*#__PURE__*/ function(Parser) {
2256
- _inherits(TextureParser, Parser);
2257
- function TextureParser() {
2258
- return Parser.apply(this, arguments);
2298
+ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2299
+ _inherits(GLTFTextureParser, GLTFParser);
2300
+ function GLTFTextureParser() {
2301
+ return GLTFParser.apply(this, arguments);
2259
2302
  }
2260
- var _proto = TextureParser.prototype;
2303
+ var _proto = GLTFTextureParser.prototype;
2261
2304
  _proto.parse = function parse(context) {
2262
2305
  var _this = this;
2263
- var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
2306
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2264
2307
  var engine = glTFResource.engine, url = glTFResource.url;
2265
- if (gltf.textures) {
2308
+ if (glTF.textures) {
2266
2309
  var texturesPromiseInfo = context.texturesPromiseInfo;
2267
- engineCore.AssetPromise.all(gltf.textures.map(function(param, index) {
2310
+ engineCore.AssetPromise.all(glTF.textures.map(function(param, index) {
2268
2311
  var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
2269
- var _gltf_images_source = gltf.images[source], uri = _gltf_images_source.uri, bufferViewIndex = _gltf_images_source.bufferView, mimeType = _gltf_images_source.mimeType, imageName = _gltf_images_source.name;
2312
+ var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
2313
+ var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
2270
2314
  if (uri) {
2271
2315
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
2272
2316
  var index1 = uri.lastIndexOf(".");
2273
2317
  var ext = uri.substring(index1 + 1);
2274
2318
  var type = ext.startsWith("ktx") ? engineCore.AssetType.KTX : engineCore.AssetType.Texture2D;
2275
2319
  return engine.resourceManager.load({
2276
- url: GLTFUtil.parseRelativeUrl(url, uri),
2277
- type: type
2320
+ url: engineCore.Utils.resolveAbsoluteUrl(url, uri),
2321
+ type: type,
2322
+ params: {
2323
+ mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
2324
+ }
2278
2325
  }).then(function(texture) {
2279
2326
  if (!texture.name) {
2280
2327
  texture.name = textureName || imageName || "texture_" + index1;
2281
2328
  }
2282
2329
  if (sampler !== undefined) {
2283
- _this._parseSampler(texture, gltf.samplers[sampler]);
2330
+ _this._parseSampler(texture, samplerInfo);
2284
2331
  }
2285
2332
  return texture;
2286
2333
  });
2287
2334
  } else {
2288
- var bufferView = gltf.bufferViews[bufferViewIndex];
2289
- var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
2290
- return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
2291
- var texture = new engineCore.Texture2D(engine, image.width, image.height);
2292
- texture.setImageSource(image);
2293
- texture.generateMipmaps();
2294
- texture.name = textureName || imageName || "texture_" + index;
2295
- if (sampler !== undefined) {
2296
- _this._parseSampler(texture, gltf.samplers[sampler]);
2297
- }
2298
- return texture;
2335
+ var bufferView = glTF.bufferViews[bufferViewIndex];
2336
+ return context.getBuffers().then(function(buffers) {
2337
+ var buffer = buffers[bufferView.buffer];
2338
+ var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2339
+ return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2340
+ var texture = new engineCore.Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
2341
+ texture.setImageSource(image);
2342
+ texture.generateMipmaps();
2343
+ texture.name = textureName || imageName || "texture_" + index;
2344
+ if (sampler !== undefined) {
2345
+ _this._parseSampler(texture, samplerInfo);
2346
+ }
2347
+ var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2348
+ context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2349
+ return texture;
2350
+ });
2299
2351
  });
2300
2352
  }
2301
2353
  })).then(function(textures) {
@@ -2305,48 +2357,67 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
2305
2357
  return texturesPromiseInfo.promise;
2306
2358
  }
2307
2359
  };
2308
- _proto._parseSampler = function _parseSampler(texture, sampler) {
2309
- var magFilter = sampler.magFilter, minFilter = sampler.minFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
2310
- if (magFilter || minFilter) {
2360
+ _proto._getSamplerInfo = function _getSamplerInfo(sampler) {
2361
+ var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
2362
+ var info = {};
2363
+ if (minFilter || magFilter) {
2364
+ info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
2311
2365
  if (magFilter === TextureMagFilter.NEAREST) {
2312
- texture.filterMode = engineCore.TextureFilterMode.Point;
2313
- } else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
2314
- texture.filterMode = engineCore.TextureFilterMode.Bilinear;
2366
+ info.filterMode = engineCore.TextureFilterMode.Point;
2315
2367
  } else {
2316
- texture.filterMode = engineCore.TextureFilterMode.Trilinear;
2368
+ if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
2369
+ info.filterMode = engineCore.TextureFilterMode.Bilinear;
2370
+ } else {
2371
+ info.filterMode = engineCore.TextureFilterMode.Trilinear;
2372
+ }
2317
2373
  }
2318
2374
  }
2319
2375
  if (wrapS) {
2320
- texture.wrapModeU = TextureParser._wrapMap[wrapS];
2376
+ info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2321
2377
  }
2322
2378
  if (wrapT) {
2323
- texture.wrapModeV = TextureParser._wrapMap[wrapT];
2379
+ info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2324
2380
  }
2381
+ return info;
2325
2382
  };
2326
- return TextureParser;
2327
- }(Parser);
2328
- (function() {
2329
- var _obj;
2330
- TextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = engineCore.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = engineCore.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = engineCore.TextureWrapMode.Repeat, _obj);
2383
+ _proto._parseSampler = function _parseSampler(texture, samplerInfo) {
2384
+ var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
2385
+ if (filterMode !== undefined) {
2386
+ texture.filterMode = filterMode;
2387
+ }
2388
+ if (wrapModeU !== undefined) {
2389
+ texture.wrapModeU = wrapModeU;
2390
+ }
2391
+ if (wrapModeV !== undefined) {
2392
+ texture.wrapModeV = wrapModeV;
2393
+ }
2394
+ };
2395
+ return GLTFTextureParser;
2396
+ }(GLTFParser);
2397
+ (function() {
2398
+ var _obj;
2399
+ GLTFTextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = engineCore.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = engineCore.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = engineCore.TextureWrapMode.Repeat, _obj);
2331
2400
  })();
2332
2401
 
2333
- var Validator = /*#__PURE__*/ function(Parser1) {
2334
- _inherits(Validator, Parser1);
2335
- function Validator() {
2336
- return Parser1.apply(this, arguments);
2402
+ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2403
+ _inherits(GLTFValidator, GLTFParser1);
2404
+ function GLTFValidator() {
2405
+ return GLTFParser1.apply(this, arguments);
2337
2406
  }
2338
- var _proto = Validator.prototype;
2407
+ var _proto = GLTFValidator.prototype;
2339
2408
  _proto.parse = function parse(context) {
2340
- var _context_gltf = context.gltf, version = _context_gltf.asset.version, extensionsUsed = _context_gltf.extensionsUsed, extensionsRequired = _context_gltf.extensionsRequired;
2341
- var gltfVersion = Number(version);
2342
- if (!(gltfVersion >= 2 && gltfVersion < 3)) {
2343
- throw "Only support gltf 2.x.";
2409
+ var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
2410
+ var glTFVersion = Number(version);
2411
+ if (!(glTFVersion >= 2 && glTFVersion < 3)) {
2412
+ throw "Only support glTF 2.x.";
2344
2413
  }
2414
+ var promises = [];
2345
2415
  if (extensionsUsed) {
2346
2416
  engineCore.Logger.info("extensionsUsed: ", extensionsUsed);
2347
2417
  for(var i = 0; i < extensionsUsed.length; i++){
2348
- if (!Parser.hasExtensionParser(extensionsUsed[i])) {
2349
- engineCore.Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
2418
+ var extensionUsed = extensionsUsed[i];
2419
+ if (!GLTFParser.hasExtensionParser(extensionUsed)) {
2420
+ engineCore.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
2350
2421
  }
2351
2422
  }
2352
2423
  }
@@ -2354,98 +2425,78 @@ var Validator = /*#__PURE__*/ function(Parser1) {
2354
2425
  engineCore.Logger.info("extensionsRequired: " + extensionsRequired);
2355
2426
  for(var i1 = 0; i1 < extensionsRequired.length; i1++){
2356
2427
  var extensionRequired = extensionsRequired[i1];
2357
- if (!Parser.hasExtensionParser(extensionRequired)) {
2428
+ if (!GLTFParser.hasExtensionParser(extensionRequired)) {
2358
2429
  engineCore.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
2359
2430
  } else {
2360
- Parser.initialize(extensionRequired);
2431
+ promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
2361
2432
  }
2362
2433
  }
2363
2434
  }
2435
+ return engineCore.AssetPromise.all(promises).then(null);
2364
2436
  };
2365
- return Validator;
2366
- }(Parser);
2437
+ return GLTFValidator;
2438
+ }(GLTFParser);
2367
2439
 
2368
- var GLTFParser = /*#__PURE__*/ function() {
2369
- function GLTFParser(pipes) {
2440
+ /**
2441
+ * GLTF pipeline.
2442
+ */ var GLTFPipeline = /*#__PURE__*/ function() {
2443
+ function GLTFPipeline() {
2444
+ for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
2445
+ parsers[_key] = arguments[_key];
2446
+ }
2370
2447
  var _this = this;
2371
- this._pipes = [];
2372
- pipes.forEach(function(pipe, index) {
2373
- _this._pipes[index] = new pipe();
2448
+ this._parsers = [];
2449
+ parsers.forEach(function(pipe, index) {
2450
+ _this._parsers[index] = new pipe();
2374
2451
  });
2375
2452
  }
2376
- var _proto = GLTFParser.prototype;
2377
- _proto.parse = function parse(context) {
2453
+ var _proto = GLTFPipeline.prototype;
2454
+ /**
2455
+ * @internal
2456
+ */ _proto._parse = function _parse(context) {
2378
2457
  var _this = this;
2379
2458
  var glTFResource = context.glTFResource;
2380
- var lastPipe;
2459
+ var lastParser;
2381
2460
  return new engineCore.AssetPromise(function(resolve, reject) {
2382
- _this._pipes.forEach(function(parser) {
2383
- if (lastPipe) {
2384
- lastPipe = lastPipe.then(function() {
2461
+ _this._parsers.forEach(function(parser) {
2462
+ if (lastParser) {
2463
+ lastParser = lastParser.then(function() {
2385
2464
  return parser.parse(context);
2386
2465
  });
2387
- if (lastPipe.cancel) {
2388
- context.chainPromises.push(lastPipe);
2466
+ if (lastParser.cancel) {
2467
+ context.chainPromises.push(lastParser);
2389
2468
  }
2390
2469
  } else {
2391
- lastPipe = parser.parse(context);
2470
+ lastParser = parser.parse(context);
2392
2471
  }
2393
2472
  });
2394
- if (lastPipe) {
2395
- lastPipe.then(function() {
2473
+ if (lastParser) {
2474
+ lastParser.then(function() {
2396
2475
  resolve(glTFResource);
2397
2476
  }).catch(reject);
2398
2477
  }
2399
2478
  });
2400
2479
  };
2401
- return GLTFParser;
2480
+ return GLTFPipeline;
2402
2481
  }();
2403
2482
  (function() {
2404
- GLTFParser.defaultPipeline = new GLTFParser([
2405
- BufferParser,
2406
- Validator,
2407
- TextureParser,
2408
- MaterialParser,
2409
- MeshParser,
2410
- EntityParser,
2411
- SkinParser,
2412
- AnimationParser,
2413
- SceneParser$1
2414
- ]);
2483
+ /**
2484
+ * Default pipeline.
2485
+ */ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
2415
2486
  })();
2416
2487
 
2417
2488
  /**
2418
- * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
2419
- */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
2420
- _inherits(GLTFResource, EngineObject);
2489
+ * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
2490
+ */ var GLTFResource = /*#__PURE__*/ function(ReferResource) {
2491
+ _inherits(GLTFResource, ReferResource);
2421
2492
  function GLTFResource(engine, url) {
2422
2493
  var _this;
2423
- _this = EngineObject.call(this, engine) || this;
2494
+ _this = ReferResource.call(this, engine) || this;
2424
2495
  _this.url = url;
2425
2496
  return _this;
2426
2497
  }
2427
- var _proto = GLTFResource.prototype;
2428
- /**
2429
- * @override
2430
- */ _proto.destroy = function destroy() {
2431
- if (this._destroyed) {
2432
- return;
2433
- }
2434
- EngineObject.prototype.destroy.call(this);
2435
- this.defaultSceneRoot.destroy();
2436
- this.textures = null;
2437
- this.materials = null;
2438
- this.meshes = null;
2439
- this.skins = null;
2440
- this.animations = null;
2441
- this.entities = null;
2442
- this.cameras = null;
2443
- this.lights = null;
2444
- this.sceneRoots = null;
2445
- this.variants = null;
2446
- };
2447
2498
  return GLTFResource;
2448
- }(engineCore.EngineObject);
2499
+ }(engineCore.ReferResource);
2449
2500
 
2450
2501
  var GLTFLoader = /*#__PURE__*/ function(Loader) {
2451
2502
  _inherits(GLTFLoader, Loader);
@@ -2454,14 +2505,16 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2454
2505
  }
2455
2506
  var _proto = GLTFLoader.prototype;
2456
2507
  _proto.load = function load(item, resourceManager) {
2457
- var _item_params;
2458
2508
  var url = item.url;
2459
- var context = new ParserContext(url);
2509
+ var params = item.params;
2510
+ var context = new GLTFParserContext(url);
2460
2511
  var glTFResource = new GLTFResource(resourceManager.engine, url);
2512
+ var restorer = new GLTFContentRestorer(glTFResource);
2461
2513
  var masterPromiseInfo = context.masterPromiseInfo;
2514
+ context.contentRestorer = restorer;
2462
2515
  context.glTFResource = glTFResource;
2463
- var _item_params_keepMeshData;
2464
- context.keepMeshData = (_item_params_keepMeshData = (_item_params = item.params) == null ? void 0 : _item_params.keepMeshData) != null ? _item_params_keepMeshData : false;
2516
+ var _params_keepMeshData;
2517
+ context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
2465
2518
  masterPromiseInfo.onCancel(function() {
2466
2519
  var chainPromises = context.chainPromises;
2467
2520
  for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
@@ -2469,16 +2522,25 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2469
2522
  promise.cancel();
2470
2523
  }
2471
2524
  });
2472
- GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
2473
- console.error(e);
2474
- masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
2525
+ ((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
2526
+ resourceManager.addContentRestorer(restorer);
2527
+ masterPromiseInfo.resolve(glTFResource);
2528
+ }).catch(function(e) {
2529
+ var msg = "Error loading glTF model from " + url + " : " + e;
2530
+ engineCore.Logger.error(msg);
2531
+ masterPromiseInfo.reject(msg);
2532
+ context.defaultSceneRootPromiseInfo.reject(e);
2533
+ context.texturesPromiseInfo.reject(e);
2534
+ context.materialsPromiseInfo.reject(e);
2535
+ context.meshesPromiseInfo.reject(e);
2536
+ context.animationClipsPromiseInfo.reject(e);
2475
2537
  });
2476
2538
  return context.promiseMap;
2477
2539
  };
2478
2540
  return GLTFLoader;
2479
2541
  }(engineCore.Loader);
2480
2542
  GLTFLoader = __decorate([
2481
- engineCore.resourceLoader(engineCore.AssetType.Prefab, [
2543
+ engineCore.resourceLoader(engineCore.AssetType.GLTF, [
2482
2544
  "gltf",
2483
2545
  "glb"
2484
2546
  ])
@@ -2564,7 +2626,7 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
2564
2626
  return textureArray;
2565
2627
  };
2566
2628
  HDRLoader1._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
2567
- var theta = Math.atan2(vDir.z, -vDir.x);
2629
+ var theta = Math.atan2(vDir.z, vDir.x);
2568
2630
  var phi = Math.acos(vDir.y);
2569
2631
  while(theta < -PI){
2570
2632
  theta += 2 * PI;
@@ -3073,6 +3135,15 @@ KTXLoader = __decorate([
3073
3135
  ])
3074
3136
  ], KTXLoader);
3075
3137
 
3138
+ function parseProperty(object, key, value) {
3139
+ if (typeof value === "object") {
3140
+ for(var subKey in value){
3141
+ parseProperty(object[key], subKey, value[subKey]);
3142
+ }
3143
+ } else {
3144
+ object[key] = value;
3145
+ }
3146
+ }
3076
3147
  var MaterialLoader = /*#__PURE__*/ function(Loader) {
3077
3148
  _inherits(MaterialLoader, Loader);
3078
3149
  function MaterialLoader() {
@@ -3084,7 +3155,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
3084
3155
  return new engineCore.AssetPromise(function(resolve, reject) {
3085
3156
  _this.request(item.url, _extends({}, item, {
3086
3157
  type: "json"
3087
- })).then(function(json) {
3158
+ })).then(function(materialSchema) {
3088
3159
  var _loop = function(key) {
3089
3160
  var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
3090
3161
  switch(type){
@@ -3112,27 +3183,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
3112
3183
  }
3113
3184
  };
3114
3185
  var engine = resourceManager.engine;
3115
- var name = json.name, shader = json.shader, shaderData = json.shaderData, macros = json.macros, renderState = json.renderState;
3116
- var material;
3117
- switch(shader){
3118
- case "pbr":
3119
- material = new engineCore.PBRMaterial(engine);
3120
- break;
3121
- case "pbr-specular":
3122
- material = new engineCore.PBRSpecularMaterial(engine);
3123
- break;
3124
- case "unlit":
3125
- material = new engineCore.UnlitMaterial(engine);
3126
- break;
3127
- case "blinn-phong":
3128
- material = new engineCore.BlinnPhongMaterial(engine);
3129
- break;
3130
- case "bake-pbr":
3131
- // @todo refactor custom shader later
3132
- // @ts-ignore
3133
- material = new engineCore.PBRBaseMaterial(engine, engineCore.Shader.find("bake-pbr"));
3134
- break;
3135
- }
3186
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
3187
+ var material = new engineCore.Material(engine, engineCore.Shader.find(shader));
3136
3188
  material.name = name;
3137
3189
  var texturePromises = new Array();
3138
3190
  var materialShaderData = material.shaderData;
@@ -3145,9 +3197,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
3145
3197
  materialShaderData.enableMacro(name1, value);
3146
3198
  }
3147
3199
  }
3148
- for(var key1 in renderState){
3149
- material[key1] = renderState[key1];
3150
- }
3200
+ parseProperty(material, "renderState", renderState);
3151
3201
  return Promise.all(texturePromises).then(function() {
3152
3202
  resolve(material);
3153
3203
  });
@@ -3247,7 +3297,7 @@ var BufferReader = /*#__PURE__*/ function() {
3247
3297
  var strByteLength = this.nextUint16();
3248
3298
  var uint8Array = new Uint8Array(this.buffer, this._offset, strByteLength);
3249
3299
  this._offset += strByteLength;
3250
- return GLTFUtil.decodeText(uint8Array);
3300
+ return engineCore.Utils.decodeText(uint8Array);
3251
3301
  };
3252
3302
  /**
3253
3303
  * image data 放在最后
@@ -3332,8 +3382,8 @@ var FileHeader = /*#__PURE__*/ function() {
3332
3382
  var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
3333
3383
  var nameLen = dataView.getUint16(7 + typeLen, true);
3334
3384
  var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
3335
- var name = GLTFUtil.decodeText(nameUint8Array);
3336
- var type = GLTFUtil.decodeText(typeUint8Array);
3385
+ var name = engineCore.Utils.decodeText(nameUint8Array);
3386
+ var type = engineCore.Utils.decodeText(typeUint8Array);
3337
3387
  var header = new FileHeader();
3338
3388
  header.totalLength = totalLen;
3339
3389
  header.name = name;
@@ -3902,6 +3952,12 @@ exports.AnimationClipDecoder = __decorate([
3902
3952
  decoder("AnimationClip")
3903
3953
  ], exports.AnimationClipDecoder);
3904
3954
 
3955
+ exports.SpecularMode = void 0;
3956
+ (function(SpecularMode) {
3957
+ SpecularMode["Sky"] = "Sky";
3958
+ SpecularMode["Custom"] = "Custom";
3959
+ })(exports.SpecularMode || (exports.SpecularMode = {}));
3960
+
3905
3961
  var SceneParserContext = /*#__PURE__*/ function() {
3906
3962
  function SceneParserContext(originalData, scene) {
3907
3963
  this.originalData = originalData;
@@ -4029,7 +4085,7 @@ exports.MeshLoader = /*#__PURE__*/ function(Loader) {
4029
4085
  decode(data, resourceManager.engine).then(function(mesh) {
4030
4086
  resolve(mesh);
4031
4087
  });
4032
- });
4088
+ }).catch(reject);
4033
4089
  });
4034
4090
  };
4035
4091
  return MeshLoader;
@@ -4048,14 +4104,14 @@ exports.EditorTextureLoader = /*#__PURE__*/ function(Loader) {
4048
4104
  var _proto = EditorTextureLoader.prototype;
4049
4105
  _proto.load = function load(item, resourceManager) {
4050
4106
  var _this = this;
4051
- return new engineCore.AssetPromise(function(resolve) {
4107
+ return new engineCore.AssetPromise(function(resolve, reject) {
4052
4108
  _this.request(item.url, {
4053
4109
  type: "arraybuffer"
4054
4110
  }).then(function(data) {
4055
4111
  decode(data, resourceManager.engine).then(function(texture) {
4056
4112
  resolve(texture);
4057
4113
  });
4058
- });
4114
+ }).catch(reject);
4059
4115
  });
4060
4116
  };
4061
4117
  return EditorTextureLoader;
@@ -4184,7 +4240,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
4184
4240
  var atlasItem = atlasItems[i];
4185
4241
  if (atlasItem.img) {
4186
4242
  chainPromises.push(resourceManager.load({
4187
- url: atlasItem.img,
4243
+ url: engineCore.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
4188
4244
  type: engineCore.AssetType.Texture2D,
4189
4245
  params: {
4190
4246
  format: format,
@@ -4283,6 +4339,30 @@ SpriteLoader = __decorate([
4283
4339
  ], false)
4284
4340
  ], SpriteLoader);
4285
4341
 
4342
+ /**
4343
+ * @internal
4344
+ */ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4345
+ _inherits(Texture2DContentRestorer, ContentRestorer);
4346
+ function Texture2DContentRestorer(resource, url, requestConfig) {
4347
+ var _this;
4348
+ _this = ContentRestorer.call(this, resource) || this;
4349
+ _this.url = url;
4350
+ _this.requestConfig = requestConfig;
4351
+ return _this;
4352
+ }
4353
+ var _proto = Texture2DContentRestorer.prototype;
4354
+ _proto.restoreContent = function restoreContent() {
4355
+ var _this = this;
4356
+ return engineCore.request(this.url, this.requestConfig).then(function(image) {
4357
+ var resource = _this.resource;
4358
+ resource.setImageSource(image);
4359
+ resource.generateMipmaps();
4360
+ return resource;
4361
+ });
4362
+ };
4363
+ return Texture2DContentRestorer;
4364
+ }(engineCore.ContentRestorer);
4365
+
4286
4366
  var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4287
4367
  _inherits(Texture2DLoader, Loader);
4288
4368
  function Texture2DLoader() {
@@ -4292,19 +4372,20 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4292
4372
  _proto.load = function load(item, resourceManager) {
4293
4373
  var _this = this;
4294
4374
  return new engineCore.AssetPromise(function(resolve, reject) {
4295
- _this.request(item.url, _extends({}, item, {
4375
+ var url = item.url;
4376
+ var requestConfig = _extends({}, item, {
4296
4377
  type: "image"
4297
- })).then(function(image) {
4298
- var _item_params;
4299
- var params = (_item_params = item.params) != null ? _item_params : {};
4300
- var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
4301
- /** @ts-ignore */ if (!texture._platformTexture) return;
4378
+ });
4379
+ _this.request(url, requestConfig).then(function(image) {
4380
+ var params = item.params;
4381
+ var texture = new engineCore.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
4302
4382
  texture.setImageSource(image);
4303
4383
  texture.generateMipmaps();
4304
- if (item.url.indexOf("data:") !== 0) {
4305
- var splitPath = item.url.split("/");
4306
- texture.name = splitPath[splitPath.length - 1];
4384
+ if (url.indexOf("data:") !== 0) {
4385
+ var index = url.lastIndexOf("/");
4386
+ texture.name = url.substring(index + 1);
4307
4387
  }
4388
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
4308
4389
  resolve(texture);
4309
4390
  }).catch(function(e) {
4310
4391
  reject(e);
@@ -4322,6 +4403,38 @@ Texture2DLoader = __decorate([
4322
4403
  ])
4323
4404
  ], Texture2DLoader);
4324
4405
 
4406
+ /**
4407
+ * @internal
4408
+ */ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4409
+ _inherits(TextureCubeContentRestorer, ContentRestorer);
4410
+ function TextureCubeContentRestorer(resource, urls, requestConfig) {
4411
+ var _this;
4412
+ _this = ContentRestorer.call(this, resource) || this;
4413
+ _this.urls = urls;
4414
+ _this.requestConfig = requestConfig;
4415
+ return _this;
4416
+ }
4417
+ var _proto = TextureCubeContentRestorer.prototype;
4418
+ _proto.restoreContent = function restoreContent() {
4419
+ var _this = this;
4420
+ return new engineCore.AssetPromise(function(resolve, reject) {
4421
+ Promise.all(_this.urls.map(function(url) {
4422
+ return engineCore.request(url, _this.requestConfig);
4423
+ })).then(function(images) {
4424
+ var resource = _this.resource;
4425
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4426
+ resource.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4427
+ }
4428
+ resource.generateMipmaps();
4429
+ resolve(resource);
4430
+ }).catch(function(e) {
4431
+ reject(e);
4432
+ });
4433
+ });
4434
+ };
4435
+ return TextureCubeContentRestorer;
4436
+ }(engineCore.ContentRestorer);
4437
+
4325
4438
  var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4326
4439
  _inherits(TextureCubeLoader, Loader);
4327
4440
  function TextureCubeLoader() {
@@ -4331,23 +4444,25 @@ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4331
4444
  _proto.load = function load(item, resourceManager) {
4332
4445
  var _this = this;
4333
4446
  return new engineCore.AssetPromise(function(resolve, reject) {
4334
- Promise.all(item.urls.map(function(url) {
4335
- return _this.request(url, _extends({}, item, {
4336
- type: "image"
4337
- }));
4447
+ var urls = item.urls;
4448
+ var requestConfig = _extends({}, item, {
4449
+ type: "image"
4450
+ });
4451
+ Promise.all(urls.map(function(url) {
4452
+ return _this.request(url, requestConfig);
4338
4453
  })).then(function(images) {
4339
4454
  var _images_ = images[0], width = _images_.width, height = _images_.height;
4340
4455
  if (width !== height) {
4341
4456
  console.error("The cube texture must have the same width and height");
4342
4457
  return;
4343
4458
  }
4344
- var tex = new engineCore.TextureCube(resourceManager.engine, width);
4345
- /** @ts-ignore */ if (!tex._platformTexture) return;
4459
+ var texture = new engineCore.TextureCube(resourceManager.engine, width);
4346
4460
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4347
- tex.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4461
+ texture.setImageSource(engineCore.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4348
4462
  }
4349
- tex.generateMipmaps();
4350
- resolve(tex);
4463
+ texture.generateMipmaps();
4464
+ resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
4465
+ resolve(texture);
4351
4466
  }).catch(function(e) {
4352
4467
  reject(e);
4353
4468
  });
@@ -4361,6 +4476,30 @@ TextureCubeLoader = __decorate([
4361
4476
  ])
4362
4477
  ], TextureCubeLoader);
4363
4478
 
4479
+ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
4480
+ _inherits(AnimationClipLoader, Loader);
4481
+ function AnimationClipLoader() {
4482
+ return Loader.apply(this, arguments);
4483
+ }
4484
+ var _proto = AnimationClipLoader.prototype;
4485
+ _proto.load = function load(item, resourceManager) {
4486
+ var _this = this;
4487
+ return new engineCore.AssetPromise(function(resolve, reject) {
4488
+ _this.request(item.url, _extends({}, item, {
4489
+ type: "arraybuffer"
4490
+ })).then(function(data) {
4491
+ return decode(data, resourceManager.engine).then(resolve);
4492
+ }).catch(reject);
4493
+ });
4494
+ };
4495
+ return AnimationClipLoader;
4496
+ }(engineCore.Loader);
4497
+ AnimationClipLoader = __decorate([
4498
+ engineCore.resourceLoader(engineCore.AssetType.AnimationClip, [
4499
+ "ani"
4500
+ ])
4501
+ ], AnimationClipLoader);
4502
+
4364
4503
  var SceneLoader = /*#__PURE__*/ function(Loader) {
4365
4504
  _inherits(SceneLoader, Loader);
4366
4505
  function SceneLoader() {
@@ -4377,16 +4516,32 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
4377
4516
  // @ts-ignore
4378
4517
  engine.resourceManager.initVirtualResources(data.files);
4379
4518
  return SceneParser.parse(engine, data).then(function(scene) {
4519
+ var promises = [];
4380
4520
  // parse ambient light
4381
4521
  var ambient = data.scene.ambient;
4382
- var ambientLightPromise = Promise.resolve();
4383
- if (ambient.ambientLight) {
4384
- ambientLightPromise = resourceManager// @ts-ignore
4385
- .getResourceByRef(data.scene.ambient.ambientLight).then(function(light) {
4386
- scene.ambientLight = light;
4522
+ var useCustomAmbient = ambient.specularMode === "Custom";
4523
+ if (useCustomAmbient && ambient.customAmbientLight) {
4524
+ // @ts-ignore
4525
+ // prettier-ignore
4526
+ var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
4527
+ scene.ambientLight = ambientLight;
4528
+ scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
4529
+ scene.ambientLight.specularIntensity = ambient.specularIntensity;
4530
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
4531
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
4532
+ });
4533
+ promises.push(customAmbientPromise);
4534
+ } else if (!useCustomAmbient && ambient.ambientLight) {
4535
+ // @ts-ignore
4536
+ // prettier-ignore
4537
+ var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
4538
+ scene.ambientLight = ambientLight;
4387
4539
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
4388
4540
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
4541
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
4542
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
4389
4543
  });
4544
+ promises.push(ambientLightPromise);
4390
4545
  } else {
4391
4546
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
4392
4547
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
@@ -4394,30 +4549,34 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
4394
4549
  }
4395
4550
  var background = data.scene.background;
4396
4551
  scene.background.mode = background.mode;
4397
- var backgroundPromise = Promise.resolve();
4398
4552
  switch(scene.background.mode){
4399
4553
  case engineCore.BackgroundMode.SolidColor:
4400
4554
  scene.background.solidColor.copyFrom(background.color);
4401
4555
  break;
4402
4556
  case engineCore.BackgroundMode.Sky:
4403
- if (background.sky) {
4557
+ if (background.skyMesh && background.skyMaterial) {
4404
4558
  // @ts-ignore
4405
- backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
4406
- var sky = scene.background.sky;
4407
- var skyMaterial = new engineCore.SkyBoxMaterial(engine);
4408
- skyMaterial.textureCubeMap = light.specularTexture;
4409
- skyMaterial.textureDecodeRGBM = true;
4410
- sky.material = skyMaterial;
4411
- sky.mesh = engineCore.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
4559
+ var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
4560
+ scene.background.sky.mesh = mesh;
4412
4561
  });
4562
+ // @ts-ignore
4563
+ // prettier-ignore
4564
+ var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
4565
+ scene.background.sky.material = material;
4566
+ });
4567
+ promises.push(skyMeshPromise, skyMaterialPromise);
4568
+ } else {
4569
+ engineCore.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
4413
4570
  }
4414
4571
  break;
4415
4572
  case engineCore.BackgroundMode.Texture:
4416
4573
  if (background.texture) {
4417
4574
  // @ts-ignore
4418
- backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
4575
+ // prettier-ignore
4576
+ var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
4419
4577
  scene.background.texture = texture;
4420
4578
  });
4579
+ promises.push(backgroundPromise);
4421
4580
  }
4422
4581
  break;
4423
4582
  }
@@ -4429,10 +4588,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
4429
4588
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
4430
4589
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
4431
4590
  }
4432
- return Promise.all([
4433
- ambientLightPromise,
4434
- backgroundPromise
4435
- ]).then(function() {
4591
+ return Promise.all(promises).then(function() {
4436
4592
  resolve(scene);
4437
4593
  });
4438
4594
  });
@@ -4461,11 +4617,411 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
4461
4617
  });
4462
4618
  }));
4463
4619
 
4620
+ var _KHR_draco_mesh_compression;
4621
+ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
4622
+ _inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
4623
+ function KHR_draco_mesh_compression1() {
4624
+ return GLTFExtensionParser.apply(this, arguments);
4625
+ }
4626
+ var _proto = KHR_draco_mesh_compression1.prototype;
4627
+ _proto.initialize = function initialize() {
4628
+ if (!KHR_draco_mesh_compression._decoder) {
4629
+ KHR_draco_mesh_compression._decoder = new engineDraco.DRACODecoder();
4630
+ }
4631
+ };
4632
+ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
4633
+ var _this = this;
4634
+ var glTF = context.glTF, engine = context.glTFResource.engine;
4635
+ var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
4636
+ var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
4637
+ var attributeMap = {};
4638
+ var attributeTypeMap = {};
4639
+ for(var attributeName in gltfAttributeMap){
4640
+ attributeMap[attributeName] = gltfAttributeMap[attributeName];
4641
+ }
4642
+ for(var attributeName1 in glTFPrimitive.attributes){
4643
+ if (gltfAttributeMap[attributeName1] !== undefined) {
4644
+ var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
4645
+ attributeTypeMap[attributeName1] = GLTFUtils.getComponentType(accessorDef.componentType).name;
4646
+ }
4647
+ }
4648
+ var indexAccessor = accessors[glTFPrimitive.indices];
4649
+ var indexType = GLTFUtils.getComponentType(indexAccessor.componentType).name;
4650
+ var taskConfig = {
4651
+ attributeIDs: attributeMap,
4652
+ attributeTypes: attributeTypeMap,
4653
+ useUniqueIDs: true,
4654
+ indexType: indexType
4655
+ };
4656
+ return context.getBuffers().then(function(buffers) {
4657
+ var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4658
+ return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4659
+ var mesh = new engineCore.ModelMesh(engine, glTFMesh.name);
4660
+ return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4661
+ for(var j = 0; j < decodedGeometry.attributes.length; j++){
4662
+ if (decodedGeometry.attributes[j].name === attributeSemantic) {
4663
+ return decodedGeometry.attributes[j].array;
4664
+ }
4665
+ }
4666
+ return null;
4667
+ }, function(attributeSemantic, shapeIndex) {
4668
+ throw "BlendShape animation is not supported when using draco.";
4669
+ }, function() {
4670
+ return decodedGeometry.index.array;
4671
+ }, context.keepMeshData);
4672
+ });
4673
+ });
4674
+ };
4675
+ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
4676
+ var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
4677
+ var vertexCount;
4678
+ var accessors = gltf.accessors;
4679
+ var accessor = accessors[attributes["POSITION"]];
4680
+ var positionBuffer = getVertexBufferData("POSITION");
4681
+ var positions = GLTFUtils.floatBufferToVector3Array(positionBuffer);
4682
+ mesh.setPositions(positions);
4683
+ var bounds = mesh.bounds;
4684
+ vertexCount = accessor.count;
4685
+ if (accessor.min && accessor.max) {
4686
+ bounds.min.copyFromArray(accessor.min);
4687
+ bounds.max.copyFromArray(accessor.max);
4688
+ } else {
4689
+ var position = KHR_draco_mesh_compression._tempVector3;
4690
+ var min = bounds.min, max = bounds.max;
4691
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
4692
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
4693
+ var stride = positionBuffer.length / vertexCount;
4694
+ for(var j = 0; j < vertexCount; j++){
4695
+ var offset = j * stride;
4696
+ position.copyFromArray(positionBuffer, offset);
4697
+ engineMath.Vector3.min(min, position, min);
4698
+ engineMath.Vector3.max(max, position, max);
4699
+ }
4700
+ }
4701
+ for(var attributeSemantic in attributes){
4702
+ if (attributeSemantic === "POSITION") {
4703
+ continue;
4704
+ }
4705
+ var bufferData = getVertexBufferData(attributeSemantic);
4706
+ switch(attributeSemantic){
4707
+ case "NORMAL":
4708
+ var normals = GLTFUtils.floatBufferToVector3Array(bufferData);
4709
+ mesh.setNormals(normals);
4710
+ break;
4711
+ case "TEXCOORD_0":
4712
+ var texturecoords = GLTFUtils.floatBufferToVector2Array(bufferData);
4713
+ mesh.setUVs(texturecoords, 0);
4714
+ break;
4715
+ case "TEXCOORD_1":
4716
+ var texturecoords1 = GLTFUtils.floatBufferToVector2Array(bufferData);
4717
+ mesh.setUVs(texturecoords1, 1);
4718
+ break;
4719
+ case "TEXCOORD_2":
4720
+ var texturecoords2 = GLTFUtils.floatBufferToVector2Array(bufferData);
4721
+ mesh.setUVs(texturecoords2, 2);
4722
+ break;
4723
+ case "TEXCOORD_3":
4724
+ var texturecoords3 = GLTFUtils.floatBufferToVector2Array(bufferData);
4725
+ mesh.setUVs(texturecoords3, 3);
4726
+ break;
4727
+ case "TEXCOORD_4":
4728
+ var texturecoords4 = GLTFUtils.floatBufferToVector2Array(bufferData);
4729
+ mesh.setUVs(texturecoords4, 4);
4730
+ break;
4731
+ case "TEXCOORD_5":
4732
+ var texturecoords5 = GLTFUtils.floatBufferToVector2Array(bufferData);
4733
+ mesh.setUVs(texturecoords5, 5);
4734
+ break;
4735
+ case "TEXCOORD_6":
4736
+ var texturecoords6 = GLTFUtils.floatBufferToVector2Array(bufferData);
4737
+ mesh.setUVs(texturecoords6, 6);
4738
+ break;
4739
+ case "TEXCOORD_7":
4740
+ var texturecoords7 = GLTFUtils.floatBufferToVector2Array(bufferData);
4741
+ mesh.setUVs(texturecoords7, 7);
4742
+ break;
4743
+ case "COLOR_0":
4744
+ var colors = GLTFUtils.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
4745
+ mesh.setColors(colors);
4746
+ break;
4747
+ case "TANGENT":
4748
+ var tangents = GLTFUtils.floatBufferToVector4Array(bufferData);
4749
+ mesh.setTangents(tangents);
4750
+ break;
4751
+ case "JOINTS_0":
4752
+ var joints = GLTFUtils.floatBufferToVector4Array(bufferData);
4753
+ mesh.setBoneIndices(joints);
4754
+ break;
4755
+ case "WEIGHTS_0":
4756
+ var weights = GLTFUtils.floatBufferToVector4Array(bufferData);
4757
+ mesh.setBoneWeights(weights);
4758
+ break;
4759
+ }
4760
+ }
4761
+ // Indices
4762
+ if (indices !== undefined) {
4763
+ var indexAccessor = gltf.accessors[indices];
4764
+ var indexData = getIndexBufferData();
4765
+ mesh.setIndices(indexData);
4766
+ mesh.addSubMesh(0, indexAccessor.count, mode);
4767
+ } else {
4768
+ mesh.addSubMesh(0, vertexCount, mode);
4769
+ }
4770
+ // BlendShapes
4771
+ targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
4772
+ mesh.uploadData(!keepMeshData);
4773
+ return Promise.resolve(mesh);
4774
+ };
4775
+ return KHR_draco_mesh_compression1;
4776
+ }(GLTFExtensionParser), function() {
4777
+ _KHR_draco_mesh_compression._tempVector3 = new engineMath.Vector3();
4778
+ }(), _KHR_draco_mesh_compression);
4779
+ KHR_draco_mesh_compression = __decorate([
4780
+ registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
4781
+ ], KHR_draco_mesh_compression);
4782
+
4783
+ var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
4784
+ _inherits(KHR_lights_punctual, GLTFExtensionParser);
4785
+ function KHR_lights_punctual() {
4786
+ return GLTFExtensionParser.apply(this, arguments);
4787
+ }
4788
+ var _proto = KHR_lights_punctual.prototype;
4789
+ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
4790
+ var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
4791
+ var lightSchema = lightsSchema[extensionSchema.light];
4792
+ var color = lightSchema.color, _lightSchema_intensity = lightSchema.intensity, intensity = _lightSchema_intensity === void 0 ? 1 : _lightSchema_intensity, type = lightSchema.type, range = lightSchema.range, spot = lightSchema.spot;
4793
+ var glTFResource = context.glTFResource;
4794
+ var light;
4795
+ if (type === "directional") {
4796
+ light = entity.addComponent(engineCore.DirectLight);
4797
+ } else if (type === "point") {
4798
+ light = entity.addComponent(engineCore.PointLight);
4799
+ } else if (type === "spot") {
4800
+ light = entity.addComponent(engineCore.SpotLight);
4801
+ }
4802
+ if (color) {
4803
+ light.color.set(color[0], color[1], color[2], 1);
4804
+ }
4805
+ light.intensity = intensity;
4806
+ if (range && !_instanceof(light, engineCore.DirectLight)) {
4807
+ light.distance = range;
4808
+ }
4809
+ if (spot && _instanceof(light, engineCore.SpotLight)) {
4810
+ var _spot_innerConeAngle = spot.innerConeAngle, innerConeAngle = _spot_innerConeAngle === void 0 ? 0 : _spot_innerConeAngle, _spot_outerConeAngle = spot.outerConeAngle, outerConeAngle = _spot_outerConeAngle === void 0 ? Math.PI / 4 : _spot_outerConeAngle;
4811
+ light.angle = innerConeAngle;
4812
+ light.penumbra = outerConeAngle - innerConeAngle;
4813
+ }
4814
+ if (!glTFResource.lights) glTFResource.lights = [];
4815
+ glTFResource.lights.push(light);
4816
+ };
4817
+ return KHR_lights_punctual;
4818
+ }(GLTFExtensionParser);
4819
+ KHR_lights_punctual = __decorate([
4820
+ registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
4821
+ ], KHR_lights_punctual);
4822
+
4823
+ var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
4824
+ _inherits(KHR_materials_clearcoat, GLTFExtensionParser);
4825
+ function KHR_materials_clearcoat() {
4826
+ return GLTFExtensionParser.apply(this, arguments);
4827
+ }
4828
+ var _proto = KHR_materials_clearcoat.prototype;
4829
+ _proto.additiveParse = function additiveParse(context, material, schema) {
4830
+ var textures = context.glTFResource.textures;
4831
+ var _schema_clearcoatFactor = schema.clearcoatFactor, clearcoatFactor = _schema_clearcoatFactor === void 0 ? 0 : _schema_clearcoatFactor, clearcoatTexture = schema.clearcoatTexture, _schema_clearcoatRoughnessFactor = schema.clearcoatRoughnessFactor, clearcoatRoughnessFactor = _schema_clearcoatRoughnessFactor === void 0 ? 0 : _schema_clearcoatRoughnessFactor, clearcoatRoughnessTexture = schema.clearcoatRoughnessTexture, clearcoatNormalTexture = schema.clearcoatNormalTexture;
4832
+ material.clearCoat = clearcoatFactor;
4833
+ material.clearCoatRoughness = clearcoatRoughnessFactor;
4834
+ if (clearcoatTexture) {
4835
+ material.clearCoatTexture = textures[clearcoatTexture.index];
4836
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
4837
+ }
4838
+ if (clearcoatRoughnessTexture) {
4839
+ material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
4840
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
4841
+ }
4842
+ if (clearcoatNormalTexture) {
4843
+ material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
4844
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
4845
+ }
4846
+ };
4847
+ return KHR_materials_clearcoat;
4848
+ }(GLTFExtensionParser);
4849
+ KHR_materials_clearcoat = __decorate([
4850
+ registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
4851
+ ], KHR_materials_clearcoat);
4852
+
4853
+ var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
4854
+ _inherits(KHR_materials_ior, GLTFExtensionParser);
4855
+ function KHR_materials_ior() {
4856
+ return GLTFExtensionParser.apply(this, arguments);
4857
+ }
4858
+ var _proto = KHR_materials_ior.prototype;
4859
+ _proto.additiveParse = function additiveParse(context, material, schema) {
4860
+ var _schema_ior = schema.ior, ior = _schema_ior === void 0 ? 1.5 : _schema_ior;
4861
+ material.ior = ior;
4862
+ };
4863
+ return KHR_materials_ior;
4864
+ }(GLTFExtensionParser);
4865
+ KHR_materials_ior = __decorate([
4866
+ registerGLTFExtension("KHR_materials_ior", exports.GLTFExtensionMode.AdditiveParse)
4867
+ ], KHR_materials_ior);
4868
+
4869
+ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
4870
+ _inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
4871
+ function KHR_materials_pbrSpecularGlossiness() {
4872
+ return GLTFExtensionParser.apply(this, arguments);
4873
+ }
4874
+ var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
4875
+ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
4876
+ var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
4877
+ var material = new engineCore.PBRSpecularMaterial(engine);
4878
+ var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
4879
+ if (diffuseFactor) {
4880
+ material.baseColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(diffuseFactor[0]), engineMath.Color.linearToGammaSpace(diffuseFactor[1]), engineMath.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
4881
+ }
4882
+ if (diffuseTexture) {
4883
+ material.baseTexture = textures[diffuseTexture.index];
4884
+ GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
4885
+ }
4886
+ if (specularFactor) {
4887
+ material.specularColor = new engineMath.Color(engineMath.Color.linearToGammaSpace(specularFactor[0]), engineMath.Color.linearToGammaSpace(specularFactor[1]), engineMath.Color.linearToGammaSpace(specularFactor[2]));
4888
+ }
4889
+ if (glossinessFactor !== undefined) {
4890
+ material.glossiness = glossinessFactor;
4891
+ }
4892
+ if (specularGlossinessTexture) {
4893
+ material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
4894
+ GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
4895
+ }
4896
+ material.name = ownerSchema.name;
4897
+ GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4898
+ return material;
4899
+ };
4900
+ return KHR_materials_pbrSpecularGlossiness;
4901
+ }(GLTFExtensionParser);
4902
+ KHR_materials_pbrSpecularGlossiness = __decorate([
4903
+ registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
4904
+ ], KHR_materials_pbrSpecularGlossiness);
4905
+
4906
+ var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
4907
+ _inherits(KHR_materials_unlit, GLTFExtensionParser);
4908
+ function KHR_materials_unlit() {
4909
+ return GLTFExtensionParser.apply(this, arguments);
4910
+ }
4911
+ var _proto = KHR_materials_unlit.prototype;
4912
+ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
4913
+ var engine = context.glTFResource.engine;
4914
+ var material = new engineCore.UnlitMaterial(engine);
4915
+ material.name = ownerSchema.name;
4916
+ GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4917
+ return material;
4918
+ };
4919
+ return KHR_materials_unlit;
4920
+ }(GLTFExtensionParser);
4921
+ KHR_materials_unlit = __decorate([
4922
+ registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
4923
+ ], KHR_materials_unlit);
4924
+
4925
+ var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
4926
+ _inherits(KHR_mesh_quantization, GLTFExtensionParser);
4927
+ function KHR_mesh_quantization() {
4928
+ return GLTFExtensionParser.apply(this, arguments);
4929
+ }
4930
+ return KHR_mesh_quantization;
4931
+ }(GLTFExtensionParser);
4932
+ KHR_mesh_quantization = __decorate([
4933
+ registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
4934
+ ], KHR_mesh_quantization);
4935
+
4936
+ var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
4937
+ _inherits(KHR_texture_transform, GLTFExtensionParser);
4938
+ function KHR_texture_transform() {
4939
+ return GLTFExtensionParser.apply(this, arguments);
4940
+ }
4941
+ var _proto = KHR_texture_transform.prototype;
4942
+ _proto.additiveParse = function additiveParse(context, material, schema) {
4943
+ var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
4944
+ if (offset) {
4945
+ material.tilingOffset.z = offset[0];
4946
+ material.tilingOffset.w = offset[1];
4947
+ }
4948
+ if (scale) {
4949
+ material.tilingOffset.x = scale[0];
4950
+ material.tilingOffset.y = scale[1];
4951
+ }
4952
+ if (rotation) {
4953
+ engineCore.Logger.warn("rotation in KHR_texture_transform is not supported now");
4954
+ }
4955
+ if (texCoord) {
4956
+ engineCore.Logger.warn("texCoord in KHR_texture_transform is not supported now");
4957
+ }
4958
+ };
4959
+ return KHR_texture_transform;
4960
+ }(GLTFExtensionParser);
4961
+ KHR_texture_transform = __decorate([
4962
+ registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
4963
+ ], KHR_texture_transform);
4964
+
4965
+ var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser) {
4966
+ _inherits(GALACEAN_materials_remap, GLTFExtensionParser);
4967
+ function GALACEAN_materials_remap() {
4968
+ return GLTFExtensionParser.apply(this, arguments);
4969
+ }
4970
+ var _proto = GALACEAN_materials_remap.prototype;
4971
+ _proto.createAndParse = function createAndParse(context, schema) {
4972
+ var engine = context.glTFResource.engine;
4973
+ // @ts-ignore
4974
+ return engine.resourceManager.getResourceByRef(schema);
4975
+ };
4976
+ return GALACEAN_materials_remap;
4977
+ }(GLTFExtensionParser);
4978
+ GALACEAN_materials_remap = __decorate([
4979
+ registerGLTFExtension("GALACEAN_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
4980
+ ], GALACEAN_materials_remap);
4981
+
4982
+ var GALACEAN_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
4983
+ _inherits(GALACEAN_animation_event, GLTFExtensionParser);
4984
+ function GALACEAN_animation_event() {
4985
+ return GLTFExtensionParser.apply(this, arguments);
4986
+ }
4987
+ var _proto = GALACEAN_animation_event.prototype;
4988
+ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
4989
+ context.glTFResource.engine;
4990
+ var events = schema.events;
4991
+ events.map(function(eventData) {
4992
+ var event = new engineCore.AnimationEvent();
4993
+ event.functionName = eventData.functionName;
4994
+ event.time = eventData.time;
4995
+ event.parameter = eventData.parameter;
4996
+ animationClip.addEvent(event);
4997
+ });
4998
+ };
4999
+ return GALACEAN_animation_event;
5000
+ }(GLTFExtensionParser);
5001
+ GALACEAN_animation_event = __decorate([
5002
+ registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
5003
+ ], GALACEAN_animation_event);
5004
+
4464
5005
  exports.ComponentMap = ComponentMap;
5006
+ exports.GLTFAnimationParser = GLTFAnimationParser;
5007
+ exports.GLTFBufferParser = GLTFBufferParser;
5008
+ exports.GLTFEntityParser = GLTFEntityParser;
5009
+ exports.GLTFExtensionParser = GLTFExtensionParser;
5010
+ exports.GLTFMaterialParser = GLTFMaterialParser;
5011
+ exports.GLTFMeshParser = GLTFMeshParser;
5012
+ exports.GLTFParser = GLTFParser;
5013
+ exports.GLTFParserContext = GLTFParserContext;
5014
+ exports.GLTFPipeline = GLTFPipeline;
4465
5015
  exports.GLTFResource = GLTFResource;
5016
+ exports.GLTFSceneParser = GLTFSceneParser;
5017
+ exports.GLTFSkinParser = GLTFSkinParser;
5018
+ exports.GLTFTextureParser = GLTFTextureParser;
5019
+ exports.GLTFUtils = GLTFUtils;
5020
+ exports.GLTFValidator = GLTFValidator;
4466
5021
  exports.PrefabParser = PrefabParser;
4467
5022
  exports.ReflectionParser = ReflectionParser;
4468
5023
  exports.SceneParser = SceneParser;
4469
5024
  exports.decode = decode;
4470
5025
  exports.parseSingleKTX = parseSingleKTX;
5026
+ exports.registerGLTFExtension = registerGLTFExtension;
4471
5027
  //# sourceMappingURL=main.js.map