@galacean/engine-loader 0.9.0-beta.80 → 1.0.0-alpha.6

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.
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var miniprogram = require('@galacean/engine-core/dist/miniprogram');
6
6
  var engineMiniprogramAdapter = require('@galacean/engine-miniprogram-adapter');
7
7
  var miniprogram$1 = require('@galacean/engine-math/dist/miniprogram');
8
- var miniprogram$2 = require('@galacean/engine-draco/dist/miniprogram');
9
- var miniprogram$3 = require('@galacean/engine-rhi-webgl/dist/miniprogram');
8
+ var miniprogram$2 = require('@galacean/engine-rhi-webgl/dist/miniprogram');
9
+ var miniprogram$3 = require('@galacean/engine-draco/dist/miniprogram');
10
10
 
11
11
  function extends_() {
12
12
  extends_ = Object.assign || function (target) {
@@ -108,10 +108,10 @@ function __generator(thisArg, body) {
108
108
  }
109
109
  }
110
110
 
111
- var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
112
- _inherits(AnimatorControllerLoader, Loader);
111
+ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
112
+ _inherits(AnimatorControllerLoader, Loader1);
113
113
  function AnimatorControllerLoader() {
114
- return Loader.apply(this, arguments);
114
+ return Loader1.apply(this, arguments);
115
115
  }
116
116
  var _proto = AnimatorControllerLoader.prototype;
117
117
  _proto.load = function load(item, resourceManager) {
@@ -132,13 +132,16 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
132
132
  var states = stateMachineData.states;
133
133
  var stateMachine = layer.stateMachine = new miniprogram.AnimatorStateMachine();
134
134
  states.forEach(function(stateData, stateIndex) {
135
- var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
135
+ 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;
136
136
  var state = stateMachine.addState(name);
137
137
  isDefaultState && (stateMachine.defaultState = state);
138
138
  state.speed = speed;
139
139
  state.wrapMode = wrapMode;
140
140
  state.clipStartTime = clipStartNormalizedTime;
141
141
  state.clipEndTime = clipEndNormalizedTime;
142
+ scripts == null ? void 0 : scripts.forEach(function(script) {
143
+ state.addStateMachineScript(miniprogram.Loader.getClass(script));
144
+ });
142
145
  if (clipData) {
143
146
  promises.push(new Promise(function(resolve) {
144
147
  //@ts-ignore
@@ -364,52 +367,192 @@ FontLoader = __decorate([
364
367
  ], false)
365
368
  ], FontLoader);
366
369
 
370
+ function _arrayLikeToArray(arr, len) {
371
+ if (len == null || len > arr.length) len = arr.length;
372
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
373
+ return arr2;
374
+ }
375
+
376
+ function _unsupportedIterableToArray(o, minLen) {
377
+ if (!o) return;
378
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
379
+ var n = Object.prototype.toString.call(o).slice(8, -1);
380
+ if (n === "Object" && o.constructor) n = o.constructor.name;
381
+ if (n === "Map" || n === "Set") return Array.from(n);
382
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
383
+ return _arrayLikeToArray(o, minLen);
384
+ }
385
+
386
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
387
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
388
+ if (it) return (it = it.call(o)).next.bind(it);
389
+ // Fallback for engines without symbol support
390
+ if (
391
+ Array.isArray(o) ||
392
+ (it = _unsupportedIterableToArray(o)) ||
393
+ (allowArrayLike && o && typeof o.length === "number")
394
+ ) {
395
+ if (it) o = it;
396
+ var i = 0;
397
+ return function () {
398
+ if (i >= o.length) return { done: true };
399
+ return { done: false, value: o[i++] };
400
+ }
401
+ }
402
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
403
+ }
404
+
367
405
  /**
368
406
  * @internal
369
- */ var ParserContext = /*#__PURE__*/ function() {
370
- function ParserContext(url) {
371
- this.hasSkinned = false;
372
- /** chain asset promise */ this.chainPromises = [];
373
- this.accessorBufferCache = {};
374
- this.texturesPromiseInfo = new PromiseInfo();
375
- this.materialsPromiseInfo = new PromiseInfo();
376
- this.meshesPromiseInfo = new PromiseInfo();
377
- this.animationClipsPromiseInfo = new PromiseInfo();
378
- this.defaultSceneRootPromiseInfo = new PromiseInfo();
379
- this.masterPromiseInfo = new PromiseInfo();
380
- this.promiseMap = {};
381
- var promiseMap = this.promiseMap;
382
- promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
383
- promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
384
- promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
385
- promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
386
- promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
387
- promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
407
+ */ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
408
+ _inherits(GLTFContentRestorer, ContentRestorer);
409
+ function GLTFContentRestorer() {
410
+ var _this;
411
+ _this = ContentRestorer.apply(this, arguments) || this;
412
+ _this.bufferRequests = [];
413
+ _this.glbBufferSlices = [];
414
+ _this.bufferTextures = [];
415
+ _this.meshes = [];
416
+ return _this;
388
417
  }
389
- var _proto = ParserContext.prototype;
390
- _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
391
- var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
392
- promiseInfo.resolve = resolve;
393
- promiseInfo.reject = reject;
394
- promiseInfo.setProgress = setProgress;
395
- promiseInfo.onCancel = onCancel;
418
+ var _proto = GLTFContentRestorer.prototype;
419
+ /**
420
+ * @override
421
+ */ _proto.restoreContent = function restoreContent() {
422
+ var _this = this;
423
+ return new miniprogram.AssetPromise(function(resolve, reject) {
424
+ Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
425
+ return miniprogram.request(bufferRequestInfo.url, bufferRequestInfo.config);
426
+ })).then(function(buffers) {
427
+ // Buffer parse
428
+ if (_this.isGLB) {
429
+ var glbBufferSlice = _this.glbBufferSlices;
430
+ var bigBuffer = buffers[0];
431
+ var bufferCount = glbBufferSlice.length;
432
+ buffers.length = bufferCount;
433
+ for(var i = 0; i < bufferCount; i++){
434
+ var slice = glbBufferSlice[i];
435
+ buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
436
+ }
437
+ }
438
+ // Restore texture
439
+ miniprogram.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
440
+ var bufferView = textureRestoreInfo.bufferView;
441
+ var buffer = buffers[bufferView.buffer];
442
+ var _bufferView_byteOffset;
443
+ var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
444
+ return GLTFUtil.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
445
+ textureRestoreInfo.texture.setImageSource(image);
446
+ textureRestoreInfo.texture.generateMipmaps();
447
+ });
448
+ })).then(function() {
449
+ // Restore mesh
450
+ for(var _iterator = _createForOfIteratorHelperLoose(_this.meshes), _step; !(_step = _iterator()).done;){
451
+ var meshInfo = _step.value;
452
+ var mesh = meshInfo.mesh;
453
+ for(var _iterator1 = _createForOfIteratorHelperLoose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
454
+ var bufferRestoreInfo = _step1.value;
455
+ var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
456
+ bufferRestoreInfo.buffer.setData(vertexData);
457
+ }
458
+ if (meshInfo.indexBuffer) {
459
+ var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
460
+ mesh.setIndices(indexData);
461
+ }
462
+ for(var _iterator2 = _createForOfIteratorHelperLoose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
463
+ var restoreInfo = _step2.value;
464
+ var frame = restoreInfo.blendShape.frames[0];
465
+ var positionData = _this._getBufferData(buffers, restoreInfo.position);
466
+ frame.deltaPositions = GLTFUtil.floatBufferToVector3Array(positionData);
467
+ if (restoreInfo.normal) {
468
+ var normalData = _this._getBufferData(buffers, restoreInfo.normal);
469
+ frame.deltaNormals = GLTFUtil.floatBufferToVector3Array(normalData);
470
+ }
471
+ if (restoreInfo.tangent) {
472
+ var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
473
+ frame.deltaTangents = GLTFUtil.floatBufferToVector3Array(tangentData);
474
+ }
475
+ }
476
+ mesh.uploadData(true);
477
+ }
478
+ resolve(_this.resource);
479
+ }).catch(reject);
480
+ }).catch(reject);
396
481
  });
397
- promiseInfo.promise = promise;
398
- return promise;
399
482
  };
400
- return ParserContext;
401
- }();
483
+ _proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
484
+ var main = restoreInfo.main;
485
+ var buffer = buffers[main.bufferIndex];
486
+ var data = new main.TypedArray(buffer, main.byteOffset, main.length);
487
+ var sparseCount = restoreInfo.sparseCount;
488
+ if (sparseCount) {
489
+ var sparseIndex = restoreInfo.sparseIndices;
490
+ var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
491
+ var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
492
+ var sparseValue = restoreInfo.sparseValues;
493
+ var sparseValueBuffer = buffers[sparseValue.bufferIndex];
494
+ var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
495
+ var typeSize = restoreInfo.typeSize;
496
+ for(var i = 0; i < sparseCount; i++){
497
+ var replaceIndex = sparseIndexData[i];
498
+ for(var j = 0; j < typeSize; j++){
499
+ data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
500
+ }
501
+ }
502
+ }
503
+ return data;
504
+ };
505
+ return GLTFContentRestorer;
506
+ }(miniprogram.ContentRestorer);
402
507
  /**
403
508
  * @internal
404
- */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
509
+ */ var BufferRequestInfo = function BufferRequestInfo(url, config) {
510
+ this.url = url;
511
+ this.config = config;
512
+ };
513
+ /**
514
+ * @internal
515
+ */ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
516
+ this.texture = texture;
517
+ this.bufferView = bufferView;
518
+ this.mimeType = mimeType;
519
+ };
520
+ /**
521
+ * @internal
522
+ */ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
523
+ this.vertexBuffers = [];
524
+ this.blendShapes = [];
525
+ };
526
+ /**
527
+ * @internal
528
+ */ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
529
+ this.buffer = buffer;
405
530
  this.data = data;
406
- this.interleaved = interleaved;
407
- this.stride = stride;
408
- this.vertexBindingInfos = {};
409
531
  };
410
532
  /**
411
533
  * @internal
412
- */ var PromiseInfo = function PromiseInfo() {
534
+ */ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
535
+ this.main = main;
536
+ this.typeSize = typeSize;
537
+ this.sparseCount = sparseCount;
538
+ this.sparseIndices = sparseIndices;
539
+ this.sparseValues = sparseValues;
540
+ };
541
+ /**
542
+ * @internal
543
+ */ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
544
+ this.bufferIndex = bufferIndex;
545
+ this.TypedArray = TypedArray;
546
+ this.byteOffset = byteOffset;
547
+ this.length = length;
548
+ };
549
+ /**
550
+ * @internal
551
+ */ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
552
+ this.blendShape = blendShape;
553
+ this.position = position;
554
+ this.normal = normal;
555
+ this.tangent = tangent;
413
556
  };
414
557
 
415
558
  /**
@@ -559,6 +702,54 @@ var TextureWrapMode;
559
702
  */ "REPEAT"] = 10497] = "REPEAT";
560
703
  })(TextureWrapMode || (TextureWrapMode = {}));
561
704
 
705
+ /**
706
+ * @internal
707
+ */ var GLTFParserContext = /*#__PURE__*/ function() {
708
+ function GLTFParserContext(url) {
709
+ this.hasSkinned = false;
710
+ this.chainPromises = [];
711
+ this.accessorBufferCache = {};
712
+ this.texturesPromiseInfo = new PromiseInfo();
713
+ this.materialsPromiseInfo = new PromiseInfo();
714
+ this.meshesPromiseInfo = new PromiseInfo();
715
+ this.animationClipsPromiseInfo = new PromiseInfo();
716
+ this.defaultSceneRootPromiseInfo = new PromiseInfo();
717
+ this.masterPromiseInfo = new PromiseInfo();
718
+ this.promiseMap = {};
719
+ var promiseMap = this.promiseMap;
720
+ promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
721
+ promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
722
+ promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
723
+ promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
724
+ promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
725
+ promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
726
+ }
727
+ var _proto = GLTFParserContext.prototype;
728
+ _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
729
+ var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
730
+ promiseInfo.resolve = resolve;
731
+ promiseInfo.reject = reject;
732
+ promiseInfo.setProgress = setProgress;
733
+ promiseInfo.onCancel = onCancel;
734
+ });
735
+ promiseInfo.promise = promise;
736
+ return promise;
737
+ };
738
+ return GLTFParserContext;
739
+ }();
740
+ /**
741
+ * @internal
742
+ */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
743
+ this.data = data;
744
+ this.interleaved = interleaved;
745
+ this.stride = stride;
746
+ this.vertexBindingInfos = {};
747
+ };
748
+ /**
749
+ * @internal
750
+ */ var PromiseInfo = function PromiseInfo() {
751
+ };
752
+
562
753
  /**
563
754
  * @internal
564
755
  */ var GLTFUtil = /*#__PURE__*/ function() {
@@ -667,18 +858,18 @@ var TextureWrapMode;
667
858
  throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
668
859
  }
669
860
  };
670
- GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
861
+ GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
671
862
  var buffers = context.buffers;
672
- var bufferViews = gltf.bufferViews;
673
863
  var componentType = accessor.componentType;
674
864
  var bufferView = bufferViews[accessor.bufferView];
675
- var buffer = buffers[bufferView.buffer];
865
+ var bufferIndex = bufferView.buffer;
866
+ var buffer = buffers[bufferIndex];
676
867
  var bufferByteOffset = bufferView.byteOffset || 0;
677
868
  var byteOffset = accessor.byteOffset || 0;
678
869
  var TypedArray = GLTFUtil.getComponentType(componentType);
679
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
870
+ var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
680
871
  var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
681
- var elementStride = dataElmentSize * dataElementBytes;
872
+ var elementStride = dataElementSize * dataElementBytes;
682
873
  var accessorCount = accessor.count;
683
874
  var bufferStride = bufferView.byteStride;
684
875
  var bufferInfo;
@@ -693,24 +884,25 @@ var TextureWrapMode;
693
884
  var count = accessorCount * (bufferStride / dataElementBytes);
694
885
  var data = new TypedArray(buffer, offset, count);
695
886
  accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
887
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
696
888
  }
697
889
  } else {
698
890
  var offset1 = bufferByteOffset + byteOffset;
699
- var count1 = accessorCount * dataElmentSize;
891
+ var count1 = accessorCount * dataElementSize;
700
892
  var data1 = new TypedArray(buffer, offset1, count1);
701
893
  bufferInfo = new BufferInfo(data1, false, elementStride);
894
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
702
895
  }
703
896
  if (accessor.sparse) {
704
- var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
705
- bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
897
+ GLTFUtil.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
706
898
  }
707
899
  return bufferInfo;
708
900
  };
709
901
  /**
710
902
  * @deprecated
711
903
  * Get accessor data.
712
- */ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
713
- var bufferViews = gltf.bufferViews;
904
+ */ GLTFUtil.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
905
+ var bufferViews = glTF.bufferViews;
714
906
  var bufferView = bufferViews[accessor.bufferView];
715
907
  var arrayBuffer = buffers[bufferView.buffer];
716
908
  var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
@@ -760,38 +952,46 @@ var TextureWrapMode;
760
952
  return typedArray;
761
953
  };
762
954
  GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
763
- var buffer = bufferView.buffer, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength;
764
- var arrayBuffer = buffers[buffer];
765
- return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
955
+ var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
956
+ var arrayBuffer = buffers[bufferView.buffer];
957
+ return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
766
958
  };
767
959
  /**
768
960
  * Get accessor data.
769
- */ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
770
- var bufferViews = gltf.bufferViews;
961
+ */ GLTFUtil.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
962
+ var restoreInfo = bufferInfo.restoreInfo;
771
963
  var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
772
964
  var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
773
- var data = originData.slice();
965
+ var data = bufferInfo.data.slice();
774
966
  var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
775
967
  var indicesBufferView = bufferViews[indices.bufferView];
776
968
  var valuesBufferView = bufferViews[values.bufferView];
777
- var indicesArrayBuffer = buffers[indicesBufferView.buffer];
778
- var valuesArrayBuffer = buffers[valuesBufferView.buffer];
969
+ var indicesBufferIndex = indicesBufferView.buffer;
970
+ var valuesBufferIndex = valuesBufferView.buffer;
971
+ var indicesArrayBuffer = buffers[indicesBufferIndex];
972
+ var valuesArrayBuffer = buffers[valuesBufferIndex];
779
973
  var _indices_byteOffset, _indicesBufferView_byteOffset;
780
974
  var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
781
975
  var indicesByteLength = indicesBufferView.byteLength;
782
976
  var _values_byteOffset, _valuesBufferView_byteOffset;
783
977
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
784
978
  var valuesByteLength = valuesBufferView.byteLength;
979
+ restoreInfo.typeSize = accessorTypeSize;
980
+ restoreInfo.sparseCount = count;
785
981
  var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
786
- var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
787
- var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
982
+ var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
983
+ var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
984
+ restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
985
+ var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
986
+ var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
987
+ restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
788
988
  for(var i = 0; i < count; i++){
789
989
  var replaceIndex = indicesArray[i];
790
990
  for(var j = 0; j < accessorTypeSize; j++){
791
991
  data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
792
992
  }
793
993
  }
794
- return data;
994
+ bufferInfo.data = data;
795
995
  };
796
996
  GLTFUtil.getIndexFormat = function getIndexFormat(type) {
797
997
  switch(type){
@@ -889,7 +1089,7 @@ var TextureWrapMode;
889
1089
  };
890
1090
  /**
891
1091
  * Parse the glb format.
892
- */ GLTFUtil.parseGLB = function parseGLB(glb) {
1092
+ */ GLTFUtil.parseGLB = function parseGLB(context, glb) {
893
1093
  var UINT32_LENGTH = 4;
894
1094
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
895
1095
  var GLB_HEADER_LENGTH = 12;
@@ -917,10 +1117,11 @@ var TextureWrapMode;
917
1117
  return null;
918
1118
  }
919
1119
  var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
920
- var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
1120
+ var glTF = JSON.parse(GLTFUtil.decodeText(glTFData));
921
1121
  // read all buffers
922
1122
  var buffers = [];
923
1123
  var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
1124
+ var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
924
1125
  while(byteOffset < header.length){
925
1126
  chunkLength = dataView.getUint32(byteOffset, true);
926
1127
  chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
@@ -931,10 +1132,11 @@ var TextureWrapMode;
931
1132
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
932
1133
  var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
933
1134
  buffers.push(buffer);
1135
+ restoreGLBBufferSlice.push(new miniprogram$1.Vector2(currentOffset, chunkLength));
934
1136
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
935
1137
  }
936
1138
  return {
937
- gltf: gltf,
1139
+ glTF: glTF,
938
1140
  buffers: buffers
939
1141
  };
940
1142
  };
@@ -949,12 +1151,6 @@ var TextureWrapMode;
949
1151
  return GLTFUtil;
950
1152
  }();
951
1153
 
952
- function _arrayLikeToArray(arr, len) {
953
- if (len == null || len > arr.length) len = arr.length;
954
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
955
- return arr2;
956
- }
957
-
958
1154
  function _arrayWithoutHoles(arr) {
959
1155
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
960
1156
  }
@@ -967,604 +1163,325 @@ function _nonIterableSpread() {
967
1163
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
968
1164
  }
969
1165
 
970
- function _unsupportedIterableToArray(o, minLen) {
971
- if (!o) return;
972
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
973
- var n = Object.prototype.toString.call(o).slice(8, -1);
974
- if (n === "Object" && o.constructor) n = o.constructor.name;
975
- if (n === "Map" || n === "Set") return Array.from(n);
976
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
977
- return _arrayLikeToArray(o, minLen);
978
- }
979
-
980
1166
  function _toConsumableArray(arr) {
981
1167
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
982
1168
  }
983
1169
 
984
- var Parser = /*#__PURE__*/ function() {
985
- function Parser() {}
986
- Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
1170
+ /**
1171
+ * Base class of glTF extension parser.
1172
+ */ var GLTFExtensionParser = /*#__PURE__*/ function() {
1173
+ function GLTFExtensionParser() {}
1174
+ var _proto = GLTFExtensionParser.prototype;
1175
+ /**
1176
+ * Initialize the parser.
1177
+ * @remarks Some plugins require initialization.
1178
+ * @returns The void or promise
1179
+ */ _proto.initialize = function initialize() {};
1180
+ /**
1181
+ * Create and parse the resource.
1182
+ * @remarks This method overrides the default resource creation.
1183
+ * @param context - The parser context
1184
+ * @param extensionSchema - The extension schema
1185
+ * @param extensionOwnerSchema - The extension owner schema
1186
+ * @returns The resource or promise
1187
+ */ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
1188
+ for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1189
+ extra[_key - 3] = arguments[_key];
1190
+ }
1191
+ throw "Not implemented.";
1192
+ };
1193
+ /**
1194
+ * Additive parse to the resource.
1195
+ * @param context - The parser context
1196
+ * @param parseResource - The parsed resource
1197
+ * @param extensionSchema - The extension schema
1198
+ * @param extensionOwnerSchema - The extension owner schema
1199
+ * @returns The void or promise
1200
+ */ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
987
1201
  for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
988
1202
  extra[_key - 4] = arguments[_key];
989
1203
  }
990
- var parsers = Parser._extensionParsers[extensionName];
991
- if (parsers == null ? void 0 : parsers.length) {
992
- for(var i = 0; i < parsers.length; i++){
993
- var _parsers_i;
994
- (_parsers_i = parsers[i]).parseEngineResource.apply(_parsers_i, [
995
- extensionSchema,
996
- parseResource,
997
- context
998
- ].concat(_toConsumableArray(extra)));
999
- }
1204
+ throw "Not implemented.";
1205
+ };
1206
+ return GLTFExtensionParser;
1207
+ }();
1208
+ exports.GLTFExtensionMode = void 0;
1209
+ (function(GLTFExtensionMode) {
1210
+ GLTFExtensionMode[GLTFExtensionMode[/**
1211
+ * Cerate instance and parse mode.
1212
+ * @remarks
1213
+ * If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
1214
+ * If this method is registered, the default pipeline processing will be ignored.
1215
+ */ "CreateAndParse"] = 0] = "CreateAndParse";
1216
+ GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
1217
+ })(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
1218
+
1219
+ /**
1220
+ * Base class of glTF parser.
1221
+ */ var GLTFParser = /*#__PURE__*/ function() {
1222
+ function GLTFParser() {}
1223
+ /**
1224
+ * Execute all parses of extension to initialize plugin.
1225
+ * @remarks Some plugins require initialization.
1226
+ * @returns The void or promise
1227
+ */ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
1228
+ var parsers = GLTFParser._extensionParsers[extensionName];
1229
+ var length = parsers == null ? void 0 : parsers.length;
1230
+ if (length) {
1231
+ return parsers[length - 1].initialize();
1000
1232
  }
1001
1233
  };
1002
- Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
1234
+ /**
1235
+ * Execute all parses of extension to create resource.
1236
+ * @param extensions - Related extensions field
1237
+ * @param context - The parser context
1238
+ * @param ownerSchema - The extension owner schema
1239
+ * @param extra - Extra params
1240
+ * @returns
1241
+ */ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
1242
+ if (extensions === void 0) extensions = {};
1003
1243
  for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1004
1244
  extra[_key - 3] = arguments[_key];
1005
1245
  }
1006
- var parsers = Parser._extensionParsers[extensionName];
1007
- if (parsers == null ? void 0 : parsers.length) {
1008
- var _parsers_;
1009
- return (_parsers_ = parsers[0]).createEngineResource.apply(_parsers_, [
1246
+ var resource = null;
1247
+ var extensionArray = Object.keys(extensions);
1248
+ for(var i = extensionArray.length - 1; i >= 0; --i){
1249
+ var _GLTFParser;
1250
+ var extensionName = extensionArray[i];
1251
+ var extensionSchema = extensions[extensionName];
1252
+ resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
1253
+ extensionName,
1254
+ context,
1255
+ extensionSchema,
1256
+ ownerSchema
1257
+ ].concat(_toConsumableArray(extra)));
1258
+ if (resource) {
1259
+ return resource;
1260
+ }
1261
+ }
1262
+ };
1263
+ /**
1264
+ * Execute all parses of extension to parse resource.
1265
+ * @param extensions - Related extensions field
1266
+ * @param context - The parser context
1267
+ * @param parseResource - The parsed resource
1268
+ * @param ownerSchema - The extension owner schema
1269
+ * @param extra - Extra params
1270
+ */ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
1271
+ for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1272
+ extra[_key - 4] = arguments[_key];
1273
+ }
1274
+ for(var extensionName in extensions){
1275
+ var _GLTFParser;
1276
+ var extensionSchema = extensions[extensionName];
1277
+ (_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
1278
+ extensionName,
1279
+ context,
1280
+ parseResource,
1010
1281
  extensionSchema,
1011
- context
1282
+ ownerSchema
1012
1283
  ].concat(_toConsumableArray(extra)));
1013
1284
  }
1014
1285
  };
1015
- Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
1016
- var parsers = Parser._extensionParsers[extensionName];
1017
- return !!(parsers == null ? void 0 : parsers.length);
1286
+ /**
1287
+ * Whether the plugin is registered.
1288
+ * @param extensionName - Extension name
1289
+ * @returns Boolean
1290
+ */ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
1291
+ var _GLTFParser__extensionParsers_extensionName;
1292
+ return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
1018
1293
  };
1019
- Parser.initialize = function initialize(extensionName) {
1020
- var parsers = Parser._extensionParsers[extensionName];
1021
- if (parsers == null ? void 0 : parsers.length) {
1022
- for(var i = 0; i < parsers.length; i++){
1023
- parsers[i].initialize();
1294
+ /**
1295
+ * Get the last plugin by glTF extension mode.
1296
+ * @param extensionName - Extension name
1297
+ * @param mode - GLTF extension mode
1298
+ * @returns GLTF extension parser
1299
+ */ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
1300
+ var parsers = GLTFParser._extensionParsers[extensionName];
1301
+ var length = parsers == null ? void 0 : parsers.length;
1302
+ if (length) {
1303
+ // only use the last parser.
1304
+ for(var i = length - 1; i >= 0; --i){
1305
+ var currentParser = parsers[i];
1306
+ if (currentParser._mode === mode) {
1307
+ return currentParser;
1308
+ }
1024
1309
  }
1025
1310
  }
1026
1311
  };
1027
1312
  /**
1028
1313
  * @internal
1029
- */ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1030
- if (!Parser._extensionParsers[extensionName]) {
1031
- Parser._extensionParsers[extensionName] = [];
1314
+ */ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1315
+ if (!GLTFParser._extensionParsers[extensionName]) {
1316
+ GLTFParser._extensionParsers[extensionName] = [];
1317
+ }
1318
+ GLTFParser._extensionParsers[extensionName].push(extensionParser);
1319
+ };
1320
+ GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
1321
+ for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1322
+ extra[_key - 4] = arguments[_key];
1323
+ }
1324
+ var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
1325
+ if (parser) {
1326
+ var _parser;
1327
+ return (_parser = parser).createAndParse.apply(_parser, [
1328
+ context,
1329
+ extensionSchema,
1330
+ ownerSchema
1331
+ ].concat(_toConsumableArray(extra)));
1032
1332
  }
1033
- Parser._extensionParsers[extensionName].push(extensionParser);
1034
1333
  };
1035
- return Parser;
1334
+ GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
1335
+ for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
1336
+ extra[_key - 5] = arguments[_key];
1337
+ }
1338
+ var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
1339
+ if (parser) {
1340
+ var _parser;
1341
+ (_parser = parser).additiveParse.apply(_parser, [
1342
+ context,
1343
+ parseResource,
1344
+ extensionSchema,
1345
+ ownerSchema
1346
+ ].concat(_toConsumableArray(extra)));
1347
+ }
1348
+ };
1349
+ return GLTFParser;
1036
1350
  }();
1037
- Parser._extensionParsers = {};
1351
+ GLTFParser._extensionParsers = {};
1038
1352
  /**
1039
1353
  * Declare ExtensionParser's decorator.
1040
1354
  * @param extensionName - Extension name
1041
- */ function registerExtension(extensionName) {
1355
+ */ function registerGLTFExtension(extensionName, mode) {
1042
1356
  return function(parser) {
1043
1357
  var extensionParser = new parser();
1044
- Parser._addExtensionParser(extensionName, extensionParser);
1358
+ extensionParser._mode = mode;
1359
+ GLTFParser._addExtensionParser(extensionName, extensionParser);
1045
1360
  };
1046
1361
  }
1047
1362
 
1048
- var ExtensionParser = /*#__PURE__*/ function() {
1049
- function ExtensionParser() {}
1050
- var _proto = ExtensionParser.prototype;
1051
- _proto.initialize = function initialize() {};
1052
- _proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
1053
- for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1054
- extra[_key - 3] = arguments[_key];
1055
- }
1056
- };
1057
- _proto.createEngineResource = function createEngineResource(schema, context) {
1058
- for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
1059
- extra[_key - 2] = arguments[_key];
1060
- }
1061
- return null;
1062
- };
1063
- return ExtensionParser;
1064
- }();
1065
-
1066
- var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
1067
- _inherits(KHR_draco_mesh_compression1, ExtensionParser);
1068
- function KHR_draco_mesh_compression1() {
1069
- return ExtensionParser.apply(this, arguments);
1363
+ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1364
+ _inherits(GLTFAnimationParser, GLTFParser1);
1365
+ function GLTFAnimationParser() {
1366
+ return GLTFParser1.apply(this, arguments);
1070
1367
  }
1071
- var _proto = KHR_draco_mesh_compression1.prototype;
1072
- _proto.initialize = function initialize() {
1073
- if (!KHR_draco_mesh_compression._decoder) {
1074
- KHR_draco_mesh_compression._decoder = new miniprogram$2.DRACODecoder();
1075
- }
1076
- };
1077
- _proto.createEngineResource = function createEngineResource(schema, context, gltfPrimitive) {
1078
- var gltf = context.gltf, buffers = context.buffers;
1079
- var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
1080
- var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
1081
- var attributeMap = {};
1082
- var attributeTypeMap = {};
1083
- for(var attributeName in gltfAttributeMap){
1084
- attributeMap[attributeName] = gltfAttributeMap[attributeName];
1368
+ var _proto = GLTFAnimationParser.prototype;
1369
+ _proto.parse = function parse(context) {
1370
+ var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
1371
+ glTFResource.entities;
1372
+ var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
1373
+ if (!animations) {
1374
+ return;
1085
1375
  }
1086
- for(var attributeName1 in gltfPrimitive.attributes){
1087
- if (gltfAttributeMap[attributeName1] !== undefined) {
1088
- var accessorDef = accessors[gltfPrimitive.attributes[attributeName1]];
1089
- attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
1376
+ var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1377
+ var animationClipCount = animations.length;
1378
+ var animationClipPromises = [];
1379
+ new Array(animationClipCount);
1380
+ for(var i = 0; i < animationClipCount; i++){
1381
+ var animationInfo = animations[i];
1382
+ var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
1383
+ var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
1384
+ if (!animationClip) {
1385
+ animationClip = new miniprogram.AnimationClip(name);
1386
+ GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
1090
1387
  }
1388
+ animationClipPromises.push(animationClip);
1091
1389
  }
1092
- var indexAccessor = accessors[gltfPrimitive.indices];
1093
- var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
1094
- var taskConfig = {
1095
- attributeIDs: attributeMap,
1096
- attributeTypes: attributeTypeMap,
1097
- useUniqueIDs: true,
1098
- indexType: indexType
1099
- };
1100
- var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
1101
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
1102
- return parsedGeometry;
1390
+ return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1391
+ glTFResource.animations = animationClips;
1392
+ for(var i = 0; i < glTF.animations.length; i++){
1393
+ var animationInfo = glTF.animations[i];
1394
+ GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
1395
+ }
1396
+ animationClipsPromiseInfo.resolve(animationClips);
1397
+ return animationClipsPromiseInfo.promise;
1103
1398
  });
1104
1399
  };
1105
- return KHR_draco_mesh_compression1;
1106
- }(ExtensionParser);
1107
- KHR_draco_mesh_compression = __decorate([
1108
- registerExtension("KHR_draco_mesh_compression")
1109
- ], KHR_draco_mesh_compression);
1110
-
1111
- function _instanceof(left, right) {
1112
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1113
- return !!right[Symbol.hasInstance](left);
1114
- } else {
1115
- return left instanceof right;
1116
- }
1117
- }
1118
-
1119
- var KHR_lights_punctual = /*#__PURE__*/ function(ExtensionParser) {
1120
- _inherits(KHR_lights_punctual, ExtensionParser);
1121
- function KHR_lights_punctual() {
1122
- return ExtensionParser.apply(this, arguments);
1123
- }
1124
- var _proto = KHR_lights_punctual.prototype;
1125
- _proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
1126
- 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;
1127
- var glTFResource = context.glTFResource;
1128
- var light;
1129
- if (type === "directional") {
1130
- light = entity.addComponent(miniprogram.DirectLight);
1131
- } else if (type === "point") {
1132
- light = entity.addComponent(miniprogram.PointLight);
1133
- } else if (type === "spot") {
1134
- light = entity.addComponent(miniprogram.SpotLight);
1135
- }
1136
- if (color) {
1137
- light.color.set(color[0], color[1], color[2], 1);
1138
- }
1139
- light.intensity = intensity;
1140
- if (range && !_instanceof(light, miniprogram.DirectLight)) {
1141
- light.distance = range;
1142
- }
1143
- if (spot && _instanceof(light, miniprogram.SpotLight)) {
1144
- 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;
1145
- light.angle = innerConeAngle;
1146
- light.penumbra = outerConeAngle - innerConeAngle;
1147
- }
1148
- if (!glTFResource.lights) glTFResource.lights = [];
1149
- glTFResource.lights.push(light);
1150
- };
1151
- return KHR_lights_punctual;
1152
- }(ExtensionParser);
1153
- KHR_lights_punctual = __decorate([
1154
- registerExtension("KHR_lights_punctual")
1155
- ], KHR_lights_punctual);
1156
-
1157
- var MaterialParser = /*#__PURE__*/ function(Parser1) {
1158
- _inherits(MaterialParser, Parser1);
1159
- function MaterialParser() {
1160
- return Parser1.apply(this, arguments);
1161
- }
1162
- var _proto = MaterialParser.prototype;
1163
- _proto.parse = function parse(context) {
1164
- var gltf = context.gltf, glTFResource = context.glTFResource;
1165
- var engine = glTFResource.engine, textures = glTFResource.textures;
1166
- if (!gltf.materials) return;
1167
- var materialsPromiseInfo = context.materialsPromiseInfo;
1168
- var materials = [];
1169
- for(var i = 0; i < gltf.materials.length; i++){
1170
- 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;
1171
- 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;
1172
- var material = null;
1173
- if (KHR_materials_unlit) {
1174
- material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
1175
- } else if (KHR_materials_pbrSpecularGlossiness) {
1176
- material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
1177
- } else {
1178
- material = new miniprogram.PBRMaterial(engine);
1179
- }
1180
- material.name = name;
1181
- if (KHR_materials_clearcoat) {
1182
- Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
1183
- }
1184
- if (pbrMetallicRoughness) {
1185
- var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1186
- if (baseColorFactor) {
1187
- material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(baseColorFactor[0]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[1]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
1188
- }
1189
- if (baseColorTexture) {
1190
- material.baseTexture = textures[baseColorTexture.index];
1191
- MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
1192
- }
1193
- if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
1194
- var m = material;
1195
- m.metallic = metallicFactor != null ? metallicFactor : 1;
1196
- m.roughness = roughnessFactor != null ? roughnessFactor : 1;
1197
- if (metallicRoughnessTexture) {
1198
- m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1199
- MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
1200
- }
1201
- }
1202
- }
1203
- if (!KHR_materials_unlit) {
1204
- var m1 = material;
1205
- if (emissiveTexture) {
1206
- m1.emissiveTexture = textures[emissiveTexture.index];
1207
- MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
1208
- }
1209
- if (emissiveFactor) {
1210
- m1.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
1211
- }
1212
- if (normalTexture) {
1213
- var index = normalTexture.index, scale = normalTexture.scale;
1214
- m1.normalTexture = textures[index];
1215
- MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
1216
- if (scale !== undefined) {
1217
- m1.normalTextureIntensity = scale;
1218
- }
1219
- }
1220
- if (occlusionTexture) {
1221
- var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1222
- m1.occlusionTexture = textures[index1];
1223
- MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
1224
- if (strength !== undefined) {
1225
- m1.occlusionTextureIntensity = strength;
1226
- }
1227
- if (texCoord === miniprogram.TextureCoordinate.UV1) {
1228
- m1.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
1229
- } else if (texCoord > miniprogram.TextureCoordinate.UV1) {
1230
- miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1231
- }
1400
+ /**
1401
+ * @internal
1402
+ */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
1403
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1404
+ var entities = glTFResource.entities;
1405
+ var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
1406
+ var channels = animationInfo.channels, samplers = animationInfo.samplers;
1407
+ var sampleDataCollection = new Array();
1408
+ // parse samplers
1409
+ for(var j = 0, m = samplers.length; j < m; j++){
1410
+ var gltfSampler = samplers[j];
1411
+ var inputAccessor = accessors[gltfSampler.input];
1412
+ var outputAccessor = accessors[gltfSampler.output];
1413
+ var input = GLTFUtil.getAccessorBuffer(context, bufferViews, inputAccessor).data;
1414
+ var output = GLTFUtil.getAccessorBuffer(context, bufferViews, outputAccessor).data;
1415
+ if (outputAccessor.normalized) {
1416
+ var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
1417
+ var scaled = new Float32Array(output.length);
1418
+ for(var k = 0, v = output.length; k < v; k++){
1419
+ scaled[k] = output[k] * scale;
1232
1420
  }
1421
+ output = scaled;
1233
1422
  }
1234
- if (OASIS_materials_remap) {
1235
- var _gltf_extensions;
1236
- gltf.extensions = (_gltf_extensions = gltf.extensions) != null ? _gltf_extensions : {};
1237
- var _gltf_extensions_OASIS_materials_remap;
1238
- gltf.extensions["OASIS_materials_remap"] = (_gltf_extensions_OASIS_materials_remap = gltf.extensions["OASIS_materials_remap"]) != null ? _gltf_extensions_OASIS_materials_remap : {};
1239
- gltf.extensions["OASIS_materials_remap"][i] = Parser.createEngineResource("OASIS_materials_remap", OASIS_materials_remap, context);
1240
- }
1241
- if (doubleSided) {
1242
- material.renderFace = miniprogram.RenderFace.Double;
1243
- } else {
1244
- material.renderFace = miniprogram.RenderFace.Front;
1245
- }
1246
- switch(alphaMode){
1247
- case MaterialAlphaMode.OPAQUE:
1248
- material.isTransparent = false;
1423
+ var outputStride = output.length / input.length;
1424
+ var _gltfSampler_interpolation;
1425
+ var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1426
+ var samplerInterpolation = void 0;
1427
+ switch(interpolation){
1428
+ case AnimationSamplerInterpolation.CubicSpine:
1429
+ samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
1249
1430
  break;
1250
- case MaterialAlphaMode.BLEND:
1251
- material.isTransparent = true;
1431
+ case AnimationSamplerInterpolation.Step:
1432
+ samplerInterpolation = miniprogram.InterpolationType.Step;
1252
1433
  break;
1253
- case MaterialAlphaMode.MASK:
1254
- material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1434
+ case AnimationSamplerInterpolation.Linear:
1435
+ samplerInterpolation = miniprogram.InterpolationType.Linear;
1255
1436
  break;
1256
1437
  }
1257
- materials[i] = material;
1258
- }
1259
- glTFResource.materials = materials;
1260
- materialsPromiseInfo.resolve(materials);
1261
- return materialsPromiseInfo.promise;
1262
- };
1263
- /** @internal */ MaterialParser._parseTextureTransform = function _parseTextureTransform(material, extensions, context) {
1264
- if (extensions === void 0) extensions = {};
1265
- var schema = extensions.KHR_texture_transform;
1266
- if (schema) {
1267
- Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
1268
- }
1269
- };
1270
- return MaterialParser;
1271
- }(Parser);
1272
-
1273
- var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
1274
- _inherits(KHR_materials_clearcoat, ExtensionParser);
1275
- function KHR_materials_clearcoat() {
1276
- return ExtensionParser.apply(this, arguments);
1277
- }
1278
- var _proto = KHR_materials_clearcoat.prototype;
1279
- _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1280
- var textures = context.glTFResource.textures;
1281
- 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;
1282
- material.clearCoat = clearcoatFactor;
1283
- material.clearCoatRoughness = clearcoatRoughnessFactor;
1284
- if (clearcoatTexture) {
1285
- material.clearCoatTexture = textures[clearcoatTexture.index];
1286
- MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
1287
- }
1288
- if (clearcoatRoughnessTexture) {
1289
- material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
1290
- MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
1291
- }
1292
- if (clearcoatNormalTexture) {
1293
- material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
1294
- MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
1295
- }
1296
- };
1297
- return KHR_materials_clearcoat;
1298
- }(ExtensionParser);
1299
- KHR_materials_clearcoat = __decorate([
1300
- registerExtension("KHR_materials_clearcoat")
1301
- ], KHR_materials_clearcoat);
1302
-
1303
- var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
1304
- _inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
1305
- function KHR_materials_pbrSpecularGlossiness() {
1306
- return ExtensionParser.apply(this, arguments);
1307
- }
1308
- var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
1309
- _proto.createEngineResource = function createEngineResource(schema, context) {
1310
- var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
1311
- var material = new miniprogram.PBRSpecularMaterial(engine);
1312
- var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
1313
- if (diffuseFactor) {
1314
- material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(diffuseFactor[0]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[1]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
1315
- }
1316
- if (diffuseTexture) {
1317
- material.baseTexture = textures[diffuseTexture.index];
1318
- MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
1319
- }
1320
- if (specularFactor) {
1321
- material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
1322
- }
1323
- if (glossinessFactor !== undefined) {
1324
- material.glossiness = glossinessFactor;
1325
- }
1326
- if (specularGlossinessTexture) {
1327
- material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
1328
- MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
1329
- }
1330
- return material;
1331
- };
1332
- return KHR_materials_pbrSpecularGlossiness;
1333
- }(ExtensionParser);
1334
- KHR_materials_pbrSpecularGlossiness = __decorate([
1335
- registerExtension("KHR_materials_pbrSpecularGlossiness")
1336
- ], KHR_materials_pbrSpecularGlossiness);
1337
-
1338
- var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
1339
- _inherits(KHR_materials_unlit, ExtensionParser);
1340
- function KHR_materials_unlit() {
1341
- return ExtensionParser.apply(this, arguments);
1342
- }
1343
- var _proto = KHR_materials_unlit.prototype;
1344
- _proto.createEngineResource = function createEngineResource(schema, context) {
1345
- var engine = context.glTFResource.engine;
1346
- var material = new miniprogram.UnlitMaterial(engine);
1347
- return material;
1348
- };
1349
- return KHR_materials_unlit;
1350
- }(ExtensionParser);
1351
- KHR_materials_unlit = __decorate([
1352
- registerExtension("KHR_materials_unlit")
1353
- ], KHR_materials_unlit);
1354
-
1355
- var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
1356
- _inherits(KHR_materials_variants, ExtensionParser);
1357
- function KHR_materials_variants() {
1358
- return ExtensionParser.apply(this, arguments);
1359
- }
1360
- var _proto = KHR_materials_variants.prototype;
1361
- _proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
1362
- 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;
1363
- var mappings = schema.mappings;
1364
- for(var i = 0; i < mappings.length; i++){
1365
- var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
1366
- if (!glTFResource.variants) glTFResource.variants = [];
1367
- glTFResource.variants.push({
1368
- renderer: renderer,
1369
- material: glTFResource.materials[material],
1370
- variants: variants.map(function(index) {
1371
- return variantNames[index].name;
1372
- })
1438
+ input[input.length - 1];
1439
+ sampleDataCollection.push({
1440
+ type: outputAccessor.type,
1441
+ interpolation: samplerInterpolation,
1442
+ input: input,
1443
+ output: output,
1444
+ outputSize: outputStride
1373
1445
  });
1374
1446
  }
1375
- };
1376
- return KHR_materials_variants;
1377
- }(ExtensionParser);
1378
- KHR_materials_variants = __decorate([
1379
- registerExtension("KHR_materials_variants")
1380
- ], KHR_materials_variants);
1381
-
1382
- var KHR_mesh_quantization = /*#__PURE__*/ function(ExtensionParser) {
1383
- _inherits(KHR_mesh_quantization, ExtensionParser);
1384
- function KHR_mesh_quantization() {
1385
- return ExtensionParser.apply(this, arguments);
1386
- }
1387
- return KHR_mesh_quantization;
1388
- }(ExtensionParser);
1389
- KHR_mesh_quantization = __decorate([
1390
- registerExtension("KHR_mesh_quantization")
1391
- ], KHR_mesh_quantization);
1392
-
1393
- var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
1394
- _inherits(KHR_texture_transform, ExtensionParser);
1395
- function KHR_texture_transform() {
1396
- return ExtensionParser.apply(this, arguments);
1397
- }
1398
- var _proto = KHR_texture_transform.prototype;
1399
- _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1400
- var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
1401
- if (offset) {
1402
- material.tilingOffset.z = offset[0];
1403
- material.tilingOffset.w = offset[1];
1404
- }
1405
- if (scale) {
1406
- material.tilingOffset.x = scale[0];
1407
- material.tilingOffset.y = scale[1];
1408
- }
1409
- if (rotation) {
1410
- miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
1411
- }
1412
- if (texCoord) {
1413
- miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
1414
- }
1415
- };
1416
- return KHR_texture_transform;
1417
- }(ExtensionParser);
1418
- KHR_texture_transform = __decorate([
1419
- registerExtension("KHR_texture_transform")
1420
- ], KHR_texture_transform);
1421
-
1422
- var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
1423
- _inherits(GalaceanMaterialsRemap, ExtensionParser);
1424
- function GalaceanMaterialsRemap() {
1425
- return ExtensionParser.apply(this, arguments);
1426
- }
1427
- var _proto = GalaceanMaterialsRemap.prototype;
1428
- _proto.createEngineResource = function createEngineResource(schema, context) {
1429
- var engine = context.glTFResource.engine;
1430
- // @ts-ignore
1431
- return engine.resourceManager.getResourceByRef(schema);
1432
- };
1433
- return GalaceanMaterialsRemap;
1434
- }(ExtensionParser);
1435
- GalaceanMaterialsRemap = __decorate([
1436
- registerExtension("OASIS_materials_remap")
1437
- ], GalaceanMaterialsRemap);
1438
-
1439
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
1440
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1441
- if (it) return (it = it.call(o)).next.bind(it);
1442
- // Fallback for engines without symbol support
1443
- if (
1444
- Array.isArray(o) ||
1445
- (it = _unsupportedIterableToArray(o)) ||
1446
- (allowArrayLike && o && typeof o.length === "number")
1447
- ) {
1448
- if (it) o = it;
1449
- var i = 0;
1450
- return function () {
1451
- if (i >= o.length) return { done: true };
1452
- return { done: false, value: o[i++] };
1453
- }
1454
- }
1455
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1456
- }
1457
-
1458
- var AnimationParser = /*#__PURE__*/ function(Parser) {
1459
- _inherits(AnimationParser, Parser);
1460
- function AnimationParser() {
1461
- return Parser.apply(this, arguments);
1462
- }
1463
- var _proto = AnimationParser.prototype;
1464
- _proto.parse = function parse(context) {
1465
- var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
1466
- var entities = glTFResource.entities;
1467
- var animations = gltf.animations, accessors = gltf.accessors;
1468
- if (!animations) {
1469
- return;
1470
- }
1471
- var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1472
- var animationClipCount = animations.length;
1473
- var animationClips = new Array(animationClipCount);
1474
- var animationsIndices = new Array(animationClipCount);
1475
- for(var i = 0; i < animationClipCount; i++){
1476
- var gltfAnimation = animations[i];
1477
- var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
1478
- var animationClip = new miniprogram.AnimationClip(name);
1479
- var sampleDataCollection = new Array();
1480
- // parse samplers
1481
- for(var j = 0, m = samplers.length; j < m; j++){
1482
- var gltfSampler = samplers[j];
1483
- var inputAccessor = accessors[gltfSampler.input];
1484
- var outputAccessor = accessors[gltfSampler.output];
1485
- var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
1486
- var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
1487
- if (outputAccessor.normalized) {
1488
- var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
1489
- var scaled = new Float32Array(output.length);
1490
- for(var k = 0, v = output.length; k < v; k++){
1491
- scaled[k] = output[k] * scale;
1492
- }
1493
- output = scaled;
1494
- }
1495
- var outputStride = output.length / input.length;
1496
- var _gltfSampler_interpolation;
1497
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1498
- var samplerInterpolation = void 0;
1499
- switch(interpolation){
1500
- case AnimationSamplerInterpolation.CubicSpine:
1501
- samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
1502
- break;
1503
- case AnimationSamplerInterpolation.Step:
1504
- samplerInterpolation = miniprogram.InterpolationType.Step;
1505
- break;
1506
- case AnimationSamplerInterpolation.Linear:
1507
- samplerInterpolation = miniprogram.InterpolationType.Linear;
1508
- break;
1509
- }
1510
- input[input.length - 1];
1511
- sampleDataCollection.push({
1512
- type: outputAccessor.type,
1513
- interpolation: samplerInterpolation,
1514
- input: input,
1515
- output: output,
1516
- outputSize: outputStride
1517
- });
1447
+ for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1448
+ var gltfChannel = channels[j1];
1449
+ var target = gltfChannel.target;
1450
+ var channelTargetEntity = entities[target.node];
1451
+ var relativePath = "";
1452
+ var entity = channelTargetEntity;
1453
+ while(entity.parent){
1454
+ relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1455
+ entity = entity.parent;
1518
1456
  }
1519
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1520
- var gltfChannel = channels[j1];
1521
- var target = gltfChannel.target;
1522
- var channelTargetEntity = entities[target.node];
1523
- var relativePath = "";
1524
- var entity = channelTargetEntity;
1525
- while(entity.parent){
1526
- relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1527
- entity = entity.parent;
1528
- }
1529
- var ComponentType = void 0;
1530
- var propertyName = void 0;
1531
- switch(target.path){
1532
- case AnimationChannelTargetPath.TRANSLATION:
1533
- ComponentType = miniprogram.Transform;
1534
- propertyName = "position";
1535
- break;
1536
- case AnimationChannelTargetPath.ROTATION:
1537
- ComponentType = miniprogram.Transform;
1538
- propertyName = "rotationQuaternion";
1539
- break;
1540
- case AnimationChannelTargetPath.SCALE:
1541
- ComponentType = miniprogram.Transform;
1542
- propertyName = "scale";
1543
- break;
1544
- case AnimationChannelTargetPath.WEIGHTS:
1545
- ComponentType = miniprogram.SkinnedMeshRenderer;
1546
- propertyName = "blendShapeWeights";
1547
- break;
1548
- }
1549
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1550
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1457
+ var ComponentType = void 0;
1458
+ var propertyName = void 0;
1459
+ switch(target.path){
1460
+ case AnimationChannelTargetPath.TRANSLATION:
1461
+ ComponentType = miniprogram.Transform;
1462
+ propertyName = "position";
1463
+ break;
1464
+ case AnimationChannelTargetPath.ROTATION:
1465
+ ComponentType = miniprogram.Transform;
1466
+ propertyName = "rotationQuaternion";
1467
+ break;
1468
+ case AnimationChannelTargetPath.SCALE:
1469
+ ComponentType = miniprogram.Transform;
1470
+ propertyName = "scale";
1471
+ break;
1472
+ case AnimationChannelTargetPath.WEIGHTS:
1473
+ ComponentType = miniprogram.SkinnedMeshRenderer;
1474
+ propertyName = "blendShapeWeights";
1475
+ break;
1551
1476
  }
1552
- animationClips[i] = animationClip;
1553
- animationsIndices[i] = {
1554
- name: name,
1555
- index: i
1556
- };
1477
+ var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1478
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1557
1479
  }
1558
- glTFResource.animations = animationClips;
1559
- // @ts-ignore for editor
1560
- glTFResource._animationsIndices = animationsIndices;
1561
- animationClipsPromiseInfo.resolve(animationClips);
1562
- return animationClipsPromiseInfo.promise;
1563
1480
  };
1564
- _proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
1481
+ GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
1565
1482
  var sampleData = sampleDataCollection[gltfChannel.sampler];
1566
1483
  var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
1567
- switch(animationchannelTargetPath){
1484
+ switch(animationChannelTargetPath){
1568
1485
  case AnimationChannelTargetPath.TRANSLATION:
1569
1486
  case AnimationChannelTargetPath.SCALE:
1570
1487
  {
@@ -1629,35 +1546,42 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
1629
1546
  }
1630
1547
  }
1631
1548
  };
1632
- return AnimationParser;
1633
- }(Parser);
1549
+ return GLTFAnimationParser;
1550
+ }(GLTFParser);
1634
1551
 
1635
- var BufferParser = /*#__PURE__*/ function(Parser) {
1636
- _inherits(BufferParser, Parser);
1637
- function BufferParser() {
1638
- return Parser.apply(this, arguments);
1552
+ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1553
+ _inherits(GLTFBufferParser, GLTFParser);
1554
+ function GLTFBufferParser() {
1555
+ return GLTFParser.apply(this, arguments);
1639
1556
  }
1640
- var _proto = BufferParser.prototype;
1557
+ var _proto = GLTFBufferParser.prototype;
1641
1558
  _proto.parse = function parse(context) {
1642
- var glTFResource = context.glTFResource;
1559
+ var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
1643
1560
  var url = glTFResource.url;
1644
- if (this._isGLB(url)) {
1645
- return miniprogram.request(url, {
1646
- type: "arraybuffer"
1647
- }).then(GLTFUtil.parseGLB).then(function(param) {
1648
- var gltf = param.gltf, buffers = param.buffers;
1649
- context.gltf = gltf;
1561
+ var restoreBufferRequests = contentRestorer.bufferRequests;
1562
+ var requestConfig = {
1563
+ type: "arraybuffer"
1564
+ };
1565
+ var isGLB = this._isGLB(url);
1566
+ contentRestorer.isGLB = isGLB;
1567
+ if (isGLB) {
1568
+ return miniprogram.request(url, requestConfig).then(function(glb) {
1569
+ restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
1570
+ return GLTFUtil.parseGLB(context, glb);
1571
+ }).then(function(param) {
1572
+ var glTF = param.glTF, buffers = param.buffers;
1573
+ context.glTF = glTF;
1650
1574
  context.buffers = buffers;
1651
1575
  });
1652
1576
  } else {
1653
1577
  return miniprogram.request(url, {
1654
1578
  type: "json"
1655
- }).then(function(gltf) {
1656
- context.gltf = gltf;
1657
- return Promise.all(gltf.buffers.map(function(buffer) {
1658
- return miniprogram.request(GLTFUtil.parseRelativeUrl(url, buffer.uri), {
1659
- type: "arraybuffer"
1660
- });
1579
+ }).then(function(glTF) {
1580
+ context.glTF = glTF;
1581
+ return Promise.all(glTF.buffers.map(function(buffer) {
1582
+ var absoluteUrl = GLTFUtil.parseRelativeUrl(url, buffer.uri);
1583
+ restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
1584
+ return miniprogram.request(absoluteUrl, requestConfig);
1661
1585
  })).then(function(buffers) {
1662
1586
  context.buffers = buffers;
1663
1587
  });
@@ -1668,24 +1592,24 @@ var BufferParser = /*#__PURE__*/ function(Parser) {
1668
1592
  var index = url.lastIndexOf(".");
1669
1593
  return url.substring(index + 1, index + 4) === "glb";
1670
1594
  };
1671
- return BufferParser;
1672
- }(Parser);
1595
+ return GLTFBufferParser;
1596
+ }(GLTFParser);
1673
1597
 
1674
- var EntityParser = /*#__PURE__*/ function(Parser) {
1675
- _inherits(EntityParser, Parser);
1676
- function EntityParser() {
1677
- return Parser.apply(this, arguments);
1598
+ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1599
+ _inherits(GLTFEntityParser, GLTFParser);
1600
+ function GLTFEntityParser() {
1601
+ return GLTFParser.apply(this, arguments);
1678
1602
  }
1679
- var _proto = EntityParser.prototype;
1603
+ var _proto = GLTFEntityParser.prototype;
1680
1604
  _proto.parse = function parse(context) {
1681
- var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
1605
+ var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
1682
1606
  var engine = glTFResource.engine;
1683
1607
  if (!nodes) return;
1684
1608
  var entities = [];
1685
1609
  for(var i = 0; i < nodes.length; i++){
1686
1610
  var gltfNode = nodes[i];
1687
1611
  var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
1688
- var entity = new miniprogram.Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
1612
+ var entity = new miniprogram.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
1689
1613
  var transform = entity.transform;
1690
1614
  if (matrix) {
1691
1615
  var localMatrix = transform.localMatrix;
@@ -1709,7 +1633,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1709
1633
  this._createSceneRoots(context, glTFResource);
1710
1634
  };
1711
1635
  _proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
1712
- var nodes = context.gltf.nodes;
1636
+ var nodes = context.glTF.nodes;
1713
1637
  var entities = glTFResource.entities;
1714
1638
  for(var i = 0; i < nodes.length; i++){
1715
1639
  var children = nodes[i].children;
@@ -1723,7 +1647,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1723
1647
  }
1724
1648
  };
1725
1649
  _proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
1726
- var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
1650
+ var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
1727
1651
  var engine = glTFResource.engine, entities = glTFResource.entities;
1728
1652
  if (!scenes) return;
1729
1653
  var sceneRoots = [];
@@ -1743,94 +1667,210 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1743
1667
  glTFResource.sceneRoots = sceneRoots;
1744
1668
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
1745
1669
  };
1746
- return EntityParser;
1747
- }(Parser);
1748
- /** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
1670
+ return GLTFEntityParser;
1671
+ }(GLTFParser);
1672
+ /** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
1749
1673
 
1750
- var MeshParser = /*#__PURE__*/ function(Parser1) {
1751
- _inherits(MeshParser, Parser1);
1752
- function MeshParser() {
1753
- return Parser1.apply(this, arguments);
1674
+ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
1675
+ _inherits(GLTFMaterialParser, GLTFParser1);
1676
+ function GLTFMaterialParser() {
1677
+ return GLTFParser1.apply(this, arguments);
1754
1678
  }
1755
- var _proto = MeshParser.prototype;
1679
+ var _proto = GLTFMaterialParser.prototype;
1756
1680
  _proto.parse = function parse(context) {
1757
- var _loop = function(i) {
1758
- var _loop = function(j) {
1759
- var gltfPrimitive = gltfMesh.primitives[j];
1760
- var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
1761
- var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
1762
- primitivePromises[j] = new Promise(function(resolve) {
1763
- var mesh = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
1764
- if (KHR_draco_mesh_compression) {
1765
- Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
1766
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1767
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
1768
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
1769
- return decodedGeometry.attributes[j].array;
1770
- }
1771
- }
1772
- return null;
1773
- }, function(attributeSemantic, shapeIndex) {
1774
- throw "BlendShape animation is not supported when using draco.";
1775
- }, function() {
1776
- return decodedGeometry.index.array;
1777
- }, context.keepMeshData);
1778
- }).then(resolve);
1779
- } else {
1780
- _this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1781
- return null;
1782
- }, function(attributeName, shapeIndex) {
1783
- var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1784
- var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1785
- if (attributeAccessorIdx) {
1786
- var accessor = gltf.accessors[attributeAccessorIdx];
1787
- return GLTFUtil.getAccessorData(gltf, accessor, buffers);
1788
- } else {
1789
- return null;
1790
- }
1791
- }, function() {
1792
- var indexAccessor = gltf.accessors[gltfPrimitive.indices];
1793
- return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
1794
- }, context.keepMeshData).then(resolve);
1795
- }
1796
- });
1797
- };
1798
- var gltfMesh = gltf.meshes[i];
1799
- var primitivePromises = [];
1800
- for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1801
- meshPromises[i] = Promise.all(primitivePromises);
1802
- };
1803
- var _this = this;
1804
- var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
1681
+ var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
1682
+ if (!glTF.materials) return;
1805
1683
  var engine = glTFResource.engine;
1806
- if (!gltf.meshes) return;
1807
- var meshesPromiseInfo = context.meshesPromiseInfo;
1808
- var meshPromises = [];
1809
- for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
1810
- miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
1811
- glTFResource.meshes = meshes;
1812
- meshesPromiseInfo.resolve(meshes);
1813
- }).catch(meshesPromiseInfo.reject);
1814
- return meshesPromiseInfo.promise;
1684
+ var materialPromises = [];
1685
+ for(var i = 0; i < glTF.materials.length; i++){
1686
+ var materialInfo = glTF.materials[i];
1687
+ var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
1688
+ if (!material) {
1689
+ material = new miniprogram.PBRMaterial(engine);
1690
+ material.name = materialInfo.name;
1691
+ GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
1692
+ }
1693
+ materialPromises.push(material);
1694
+ }
1695
+ return miniprogram.AssetPromise.all(materialPromises).then(function(materials) {
1696
+ glTFResource.materials = materials;
1697
+ for(var i = 0; i < glTF.materials.length; i++){
1698
+ var materialInfo = glTF.materials[i];
1699
+ GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
1700
+ }
1701
+ materialsPromiseInfo.resolve(materials);
1702
+ return materialsPromiseInfo.promise;
1703
+ });
1815
1704
  };
1816
- _proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1817
- var accessors = gltf.accessors;
1818
- context.buffers;
1819
- var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1820
- var engine = mesh.engine;
1821
- var vertexElements = new Array();
1822
- var vertexCount;
1823
- var bufferBindIndex = 0;
1824
- for(var attribute in attributes){
1705
+ /**
1706
+ * @internal
1707
+ */ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
1708
+ var _texture_extensions;
1709
+ if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
1710
+ miniprogram.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
1711
+ }
1712
+ };
1713
+ /**
1714
+ * @internal
1715
+ */ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
1716
+ var textures = context.glTFResource.textures;
1717
+ 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;
1718
+ if (pbrMetallicRoughness) {
1719
+ var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1720
+ if (baseColorFactor) {
1721
+ material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(baseColorFactor[0]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[1]), miniprogram$1.Color.linearToGammaSpace(baseColorFactor[2]), baseColorFactor[3]);
1722
+ }
1723
+ if (baseColorTexture) {
1724
+ material.baseTexture = textures[baseColorTexture.index];
1725
+ GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
1726
+ }
1727
+ if (material.constructor === miniprogram.PBRMaterial) {
1728
+ material.metallic = metallicFactor != null ? metallicFactor : 1;
1729
+ material.roughness = roughnessFactor != null ? roughnessFactor : 1;
1730
+ if (metallicRoughnessTexture) {
1731
+ material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1732
+ GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
1733
+ }
1734
+ }
1735
+ }
1736
+ if (material.constructor === miniprogram.PBRMaterial || material.constructor === miniprogram.PBRSpecularMaterial) {
1737
+ if (emissiveTexture) {
1738
+ material.emissiveTexture = textures[emissiveTexture.index];
1739
+ GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
1740
+ }
1741
+ if (emissiveFactor) {
1742
+ material.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
1743
+ }
1744
+ if (normalTexture) {
1745
+ var index = normalTexture.index, scale = normalTexture.scale;
1746
+ material.normalTexture = textures[index];
1747
+ GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
1748
+ if (scale !== undefined) {
1749
+ material.normalTextureIntensity = scale;
1750
+ }
1751
+ }
1752
+ if (occlusionTexture) {
1753
+ var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1754
+ material.occlusionTexture = textures[index1];
1755
+ GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
1756
+ if (strength !== undefined) {
1757
+ material.occlusionTextureIntensity = strength;
1758
+ }
1759
+ if (texCoord === miniprogram.TextureCoordinate.UV1) {
1760
+ material.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
1761
+ } else if (texCoord > miniprogram.TextureCoordinate.UV1) {
1762
+ miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1763
+ }
1764
+ }
1765
+ }
1766
+ if (doubleSided) {
1767
+ material.renderFace = miniprogram.RenderFace.Double;
1768
+ } else {
1769
+ material.renderFace = miniprogram.RenderFace.Front;
1770
+ }
1771
+ switch(alphaMode){
1772
+ case MaterialAlphaMode.OPAQUE:
1773
+ material.isTransparent = false;
1774
+ break;
1775
+ case MaterialAlphaMode.BLEND:
1776
+ material.isTransparent = true;
1777
+ break;
1778
+ case MaterialAlphaMode.MASK:
1779
+ material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1780
+ break;
1781
+ }
1782
+ };
1783
+ return GLTFMaterialParser;
1784
+ }(GLTFParser);
1785
+
1786
+ function _instanceof(left, right) {
1787
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1788
+ return !!right[Symbol.hasInstance](left);
1789
+ } else {
1790
+ return left instanceof right;
1791
+ }
1792
+ }
1793
+
1794
+ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1795
+ _inherits(GLTFMeshParser, GLTFParser1);
1796
+ function GLTFMeshParser() {
1797
+ return GLTFParser1.apply(this, arguments);
1798
+ }
1799
+ var _proto = GLTFMeshParser.prototype;
1800
+ _proto.parse = function parse(context) {
1801
+ var _loop = function(i) {
1802
+ var _loop = function(j) {
1803
+ var gltfPrimitive = gltfMesh.primitives[j];
1804
+ primitivePromises[j] = new Promise(function(resolve) {
1805
+ var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
1806
+ if (mesh) {
1807
+ if (_instanceof(mesh, miniprogram.ModelMesh)) {
1808
+ resolve(mesh);
1809
+ } else {
1810
+ mesh.then(function(mesh) {
1811
+ return resolve(mesh);
1812
+ });
1813
+ }
1814
+ } else {
1815
+ var mesh1 = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
1816
+ var meshRestoreInfo = new ModelMeshRestoreInfo();
1817
+ meshRestoreInfo.mesh = mesh1;
1818
+ context.contentRestorer.meshes.push(meshRestoreInfo);
1819
+ GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
1820
+ return null;
1821
+ }, function(attributeName, shapeIndex) {
1822
+ var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1823
+ var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1824
+ if (attributeAccessorIdx) {
1825
+ var accessor = glTF.accessors[attributeAccessorIdx];
1826
+ return GLTFUtil.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
1827
+ } else {
1828
+ return null;
1829
+ }
1830
+ }, function() {
1831
+ var indexAccessor = glTF.accessors[gltfPrimitive.indices];
1832
+ return GLTFUtil.getAccessorData(glTF, indexAccessor, buffers);
1833
+ }, context.keepMeshData).then(resolve);
1834
+ }
1835
+ });
1836
+ };
1837
+ var gltfMesh = glTF.meshes[i];
1838
+ var primitivePromises = [];
1839
+ for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1840
+ meshPromises[i] = Promise.all(primitivePromises);
1841
+ };
1842
+ var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
1843
+ var engine = glTFResource.engine;
1844
+ if (!glTF.meshes) return;
1845
+ var meshesPromiseInfo = context.meshesPromiseInfo;
1846
+ var meshPromises = [];
1847
+ for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
1848
+ miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
1849
+ glTFResource.meshes = meshes;
1850
+ meshesPromiseInfo.resolve(meshes);
1851
+ }).catch(meshesPromiseInfo.reject);
1852
+ return meshesPromiseInfo.promise;
1853
+ };
1854
+ /**
1855
+ * @internal
1856
+ */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1857
+ var accessors = gltf.accessors;
1858
+ context.buffers;
1859
+ var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1860
+ var engine = mesh.engine;
1861
+ var vertexElements = new Array();
1862
+ var vertexCount;
1863
+ var bufferBindIndex = 0;
1864
+ for(var attribute in attributes){
1825
1865
  var accessor = accessors[attributes[attribute]];
1826
- var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
1827
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1866
+ var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf.bufferViews, accessor);
1867
+ var dataElementSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1828
1868
  var attributeCount = accessor.count;
1829
1869
  var vertices = accessorBuffer.data;
1830
1870
  var vertexElement = void 0;
1831
1871
  var meshId = mesh.instanceId;
1832
1872
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1833
- var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
1873
+ var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
1834
1874
  if (accessorBuffer.interleaved) {
1835
1875
  var byteOffset = accessor.byteOffset || 0;
1836
1876
  var stride = accessorBuffer.stride;
@@ -1842,6 +1882,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1842
1882
  vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1843
1883
  vertexBuffer.setData(vertices);
1844
1884
  accessorBuffer.vertexBuffer = vertexBuffer;
1885
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1845
1886
  }
1846
1887
  mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1847
1888
  vertexBindingInfos[meshId] = bufferBindIndex++;
@@ -1852,6 +1893,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1852
1893
  vertexElement = new miniprogram.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
1853
1894
  var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1854
1895
  vertexBuffer1.setData(vertices);
1896
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1855
1897
  mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1856
1898
  vertexBindingInfos[meshId] = bufferBindIndex++;
1857
1899
  }
@@ -1863,7 +1905,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1863
1905
  min.copyFromArray(accessor.min);
1864
1906
  max.copyFromArray(accessor.max);
1865
1907
  } else {
1866
- var position = MeshParser._tempVector3;
1908
+ var position = GLTFMeshParser._tempVector3;
1867
1909
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1868
1910
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1869
1911
  var stride1 = vertices.length / attributeCount;
@@ -1875,9 +1917,9 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1875
1917
  }
1876
1918
  }
1877
1919
  if (accessor.normalized) {
1878
- var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1879
- min.scale(sacleFactor);
1880
- max.scale(sacleFactor);
1920
+ var scaleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1921
+ min.scale(scaleFactor);
1922
+ max.scale(scaleFactor);
1881
1923
  }
1882
1924
  }
1883
1925
  }
@@ -1885,175 +1927,68 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1885
1927
  // Indices
1886
1928
  if (indices !== undefined) {
1887
1929
  var indexAccessor = gltf.accessors[indices];
1888
- var indexData = getIndexBufferData();
1889
- mesh.setIndices(indexData);
1930
+ var accessorBuffer1 = GLTFUtil.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
1931
+ mesh.setIndices(accessorBuffer1.data);
1890
1932
  mesh.addSubMesh(0, indexAccessor.count, mode);
1933
+ meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
1891
1934
  } else {
1892
1935
  mesh.addSubMesh(0, vertexCount, mode);
1893
1936
  }
1894
1937
  // BlendShapes
1895
- targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
1938
+ targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
1896
1939
  mesh.uploadData(!keepMeshData);
1897
1940
  return Promise.resolve(mesh);
1898
1941
  };
1899
- _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
1942
+ /**
1943
+ * @internal
1944
+ */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
1900
1945
  var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
1901
1946
  for(var i = 0, n = glTFTargets.length; i < n; i++){
1902
1947
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1903
- var deltaPosBuffer = getBlendShapeData("POSITION", i);
1904
- var deltaNorBuffer = getBlendShapeData("NORMAL", i);
1905
- var deltaTanBuffer = getBlendShapeData("TANGENT", i);
1906
- var deltaPositions = deltaPosBuffer ? GLTFUtil.floatBufferToVector3Array(deltaPosBuffer) : null;
1907
- var deltaNormals = deltaNorBuffer ? GLTFUtil.floatBufferToVector3Array(deltaNorBuffer) : null;
1908
- var deltaTangents = deltaTanBuffer ? GLTFUtil.floatBufferToVector3Array(deltaTanBuffer) : null;
1948
+ var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
1949
+ var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
1950
+ var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
1951
+ var deltaPositions = deltaPosBufferInfo.data ? GLTFUtil.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
1952
+ var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtil.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
1953
+ var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtil.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
1909
1954
  var blendShape = new miniprogram.BlendShape(name);
1910
1955
  blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
1911
1956
  mesh.addBlendShape(blendShape);
1957
+ meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
1912
1958
  }
1913
1959
  };
1914
- /**
1915
- * @deprecated
1916
- */ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1917
- var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1918
- var vertexCount;
1919
- var accessors = gltf.accessors;
1920
- var accessor = accessors[attributes["POSITION"]];
1921
- var positionBuffer = getVertexBufferData("POSITION");
1922
- var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
1923
- mesh.setPositions(positions);
1924
- var bounds = mesh.bounds;
1925
- vertexCount = accessor.count;
1926
- if (accessor.min && accessor.max) {
1927
- bounds.min.copyFromArray(accessor.min);
1928
- bounds.max.copyFromArray(accessor.max);
1929
- } else {
1930
- var position = MeshParser._tempVector3;
1931
- var min = bounds.min, max = bounds.max;
1932
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1933
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1934
- var stride = positionBuffer.length / vertexCount;
1935
- for(var j = 0; j < vertexCount; j++){
1936
- var offset = j * stride;
1937
- position.copyFromArray(positionBuffer, offset);
1938
- miniprogram$1.Vector3.min(min, position, min);
1939
- miniprogram$1.Vector3.max(max, position, max);
1940
- }
1941
- }
1942
- for(var attributeSemantic in attributes){
1943
- if (attributeSemantic === "POSITION") {
1944
- continue;
1945
- }
1946
- var bufferData = getVertexBufferData(attributeSemantic);
1947
- switch(attributeSemantic){
1948
- case "NORMAL":
1949
- var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
1950
- mesh.setNormals(normals);
1951
- break;
1952
- case "TEXCOORD_0":
1953
- var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
1954
- mesh.setUVs(texturecoords, 0);
1955
- break;
1956
- case "TEXCOORD_1":
1957
- var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
1958
- mesh.setUVs(texturecoords1, 1);
1959
- break;
1960
- case "TEXCOORD_2":
1961
- var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
1962
- mesh.setUVs(texturecoords2, 2);
1963
- break;
1964
- case "TEXCOORD_3":
1965
- var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
1966
- mesh.setUVs(texturecoords3, 3);
1967
- break;
1968
- case "TEXCOORD_4":
1969
- var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
1970
- mesh.setUVs(texturecoords4, 4);
1971
- break;
1972
- case "TEXCOORD_5":
1973
- var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
1974
- mesh.setUVs(texturecoords5, 5);
1975
- break;
1976
- case "TEXCOORD_6":
1977
- var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
1978
- mesh.setUVs(texturecoords6, 6);
1979
- break;
1980
- case "TEXCOORD_7":
1981
- var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
1982
- mesh.setUVs(texturecoords7, 7);
1983
- break;
1984
- case "COLOR_0":
1985
- var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
1986
- mesh.setColors(colors);
1987
- break;
1988
- case "TANGENT":
1989
- var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
1990
- mesh.setTangents(tangents);
1991
- break;
1992
- case "JOINTS_0":
1993
- var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
1994
- mesh.setBoneIndices(joints);
1995
- break;
1996
- case "WEIGHTS_0":
1997
- var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
1998
- mesh.setBoneWeights(weights);
1999
- break;
2000
- }
2001
- }
2002
- // Indices
2003
- if (indices !== undefined) {
2004
- var indexAccessor = gltf.accessors[indices];
2005
- var indexData = getIndexBufferData();
2006
- mesh.setIndices(indexData);
2007
- mesh.addSubMesh(0, indexAccessor.count, mode);
2008
- } else {
2009
- mesh.addSubMesh(0, vertexCount, mode);
2010
- }
2011
- // BlendShapes
2012
- targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
2013
- mesh.uploadData(!keepMeshData);
2014
- return Promise.resolve(mesh);
2015
- };
2016
- return MeshParser;
2017
- }(Parser);
2018
- MeshParser._tempVector3 = new miniprogram$1.Vector3();
1960
+ return GLTFMeshParser;
1961
+ }(GLTFParser);
1962
+ GLTFMeshParser._tempVector3 = new miniprogram$1.Vector3();
2019
1963
 
2020
- var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2021
- _inherits(SceneParser, Parser1);
2022
- function SceneParser() {
2023
- return Parser1.apply(this, arguments);
1964
+ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
1965
+ _inherits(GLTFSceneParser, GLTFParser1);
1966
+ function GLTFSceneParser() {
1967
+ return GLTFParser1.apply(this, arguments);
2024
1968
  }
2025
- var _proto = SceneParser.prototype;
1969
+ var _proto = GLTFSceneParser.prototype;
2026
1970
  _proto.parse = function parse(context) {
2027
- var glTFResource = context.glTFResource, gltf = context.gltf;
1971
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2028
1972
  var entities = glTFResource.entities;
2029
- var nodes = gltf.nodes, gltfCameras = gltf.cameras;
1973
+ var nodes = glTF.nodes, cameras = glTF.cameras;
2030
1974
  if (!nodes) return;
2031
1975
  var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
2032
- var promises = [];
2033
1976
  for(var i = 0; i < nodes.length; i++){
2034
- var gltfNode = nodes[i];
2035
- var cameraID = gltfNode.camera, meshID = gltfNode.mesh, _gltfNode_extensions = gltfNode.extensions, extensions = _gltfNode_extensions === void 0 ? {} : _gltfNode_extensions;
2036
- var KHR_lights_punctual = extensions.KHR_lights_punctual;
1977
+ var glTFNode = nodes[i];
1978
+ var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
2037
1979
  var entity = entities[i];
2038
1980
  if (cameraID !== undefined) {
2039
- this._createCamera(glTFResource, gltfCameras[cameraID], entity);
1981
+ this._createCamera(glTFResource, cameras[cameraID], entity);
2040
1982
  }
2041
1983
  if (meshID !== undefined) {
2042
- promises.push(this._createRenderer(context, gltfNode, entity));
2043
- }
2044
- if (KHR_lights_punctual) {
2045
- var lightIndex = KHR_lights_punctual.light;
2046
- var lights = gltf.extensions.KHR_lights_punctual.lights;
2047
- Parser.parseEngineResource("KHR_lights_punctual", lights[lightIndex], entity, context);
1984
+ this._createRenderer(context, glTFNode, entity);
2048
1985
  }
1986
+ GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
2049
1987
  }
2050
1988
  if (glTFResource.defaultSceneRoot) {
2051
1989
  this._createAnimator(context);
2052
1990
  }
2053
- gltf.extensions && delete gltf.extensions["OASIS_materials_remap"];
2054
- miniprogram.AssetPromise.all(promises).then(function() {
2055
- return defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2056
- }).catch(defaultSceneRootPromiseInfo.reject);
1991
+ defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2057
1992
  return defaultSceneRootPromiseInfo.promise;
2058
1993
  };
2059
1994
  _proto._createCamera = function _createCamera(context, cameraSchema, entity) {
@@ -2089,8 +2024,16 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2089
2024
  // @todo: use engine camera by default
2090
2025
  camera.enabled = false;
2091
2026
  };
2092
- _proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
2093
- var _loop = function(i) {
2027
+ _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
2028
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2029
+ var glTFMeshes = glTF.meshes;
2030
+ var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2031
+ var meshID = glTFNode.mesh, skinID = glTFNode.skin;
2032
+ var glTFMesh = glTFMeshes[meshID];
2033
+ var glTFMeshPrimitives = glTFMesh.primitives;
2034
+ var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
2035
+ for(var i = 0; i < glTFMeshPrimitives.length; i++){
2036
+ var gltfPrimitive = glTFMeshPrimitives[i];
2094
2037
  var mesh = meshes[meshID][i];
2095
2038
  var renderer = void 0;
2096
2039
  if (skinID !== undefined || blendShapeWeights) {
@@ -2108,32 +2051,11 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2108
2051
  renderer = entity.addComponent(miniprogram.MeshRenderer);
2109
2052
  renderer.mesh = mesh;
2110
2053
  }
2111
- var materialIndex = gltfMeshPrimitives[i].material;
2112
- var remapMaterials = gltf.extensions && gltf.extensions["OASIS_materials_remap"];
2113
- if (remapMaterials && remapMaterials[materialIndex]) {
2114
- promises.push(remapMaterials[materialIndex].then(function(mtl) {
2115
- renderer.setMaterial(mtl);
2116
- }));
2117
- } else {
2118
- var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
2119
- renderer.setMaterial(material);
2120
- }
2121
- var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
2122
- var KHR_materials_variants = extensions.KHR_materials_variants;
2123
- if (KHR_materials_variants) {
2124
- Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
2125
- }
2126
- };
2127
- var glTFResource = context.glTFResource, gltf = context.gltf;
2128
- var gltfMeshes = gltf.meshes;
2129
- var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2130
- var meshID = gltfNode.mesh, skinID = gltfNode.skin;
2131
- var glTFMesh = gltfMeshes[meshID];
2132
- var gltfMeshPrimitives = glTFMesh.primitives;
2133
- var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
2134
- var promises = [];
2135
- for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
2136
- return Promise.all(promises);
2054
+ var materialIndex = gltfPrimitive.material;
2055
+ var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
2056
+ renderer.setMaterial(material);
2057
+ GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
2058
+ }
2137
2059
  };
2138
2060
  _proto._createAnimator = function _createAnimator(context) {
2139
2061
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -2160,25 +2082,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2160
2082
  }
2161
2083
  }
2162
2084
  };
2163
- SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2164
- if (!SceneParser._defaultMaterial) {
2165
- SceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
2085
+ GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2086
+ if (!GLTFSceneParser._defaultMaterial) {
2087
+ GLTFSceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
2166
2088
  }
2167
- return SceneParser._defaultMaterial;
2089
+ return GLTFSceneParser._defaultMaterial;
2168
2090
  };
2169
- return SceneParser;
2170
- }(Parser);
2091
+ return GLTFSceneParser;
2092
+ }(GLTFParser);
2171
2093
 
2172
- var SkinParser = /*#__PURE__*/ function(Parser) {
2173
- _inherits(SkinParser, Parser);
2174
- function SkinParser() {
2175
- return Parser.apply(this, arguments);
2094
+ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2095
+ _inherits(GLTFSkinParser, GLTFParser);
2096
+ function GLTFSkinParser() {
2097
+ return GLTFParser.apply(this, arguments);
2176
2098
  }
2177
- var _proto = SkinParser.prototype;
2099
+ var _proto = GLTFSkinParser.prototype;
2178
2100
  _proto.parse = function parse(context) {
2179
- var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
2101
+ var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
2180
2102
  var entities = glTFResource.entities;
2181
- var gltfSkins = gltf.skins;
2103
+ var gltfSkins = glTF.skins;
2182
2104
  if (!gltfSkins) return;
2183
2105
  var count = gltfSkins.length;
2184
2106
  var skins = new Array(count);
@@ -2188,8 +2110,8 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
2188
2110
  var skin = new miniprogram.Skin(name);
2189
2111
  skin.inverseBindMatrices.length = jointCount;
2190
2112
  // parse IBM
2191
- var accessor = gltf.accessors[inverseBindMatrices];
2192
- var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
2113
+ var accessor = glTF.accessors[inverseBindMatrices];
2114
+ var buffer = GLTFUtil.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
2193
2115
  for(var i1 = 0; i1 < jointCount; i1++){
2194
2116
  var inverseBindMatrix = new miniprogram$1.Matrix();
2195
2117
  inverseBindMatrix.copyFromArray(buffer, i1 * 16);
@@ -2250,24 +2172,24 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
2250
2172
  rootNode = entity1;
2251
2173
  }
2252
2174
  };
2253
- return SkinParser;
2254
- }(Parser);
2175
+ return GLTFSkinParser;
2176
+ }(GLTFParser);
2255
2177
 
2256
- var TextureParser = /*#__PURE__*/ function(Parser) {
2257
- _inherits(TextureParser, Parser);
2258
- function TextureParser() {
2259
- return Parser.apply(this, arguments);
2178
+ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2179
+ _inherits(GLTFTextureParser, GLTFParser);
2180
+ function GLTFTextureParser() {
2181
+ return GLTFParser.apply(this, arguments);
2260
2182
  }
2261
- var _proto = TextureParser.prototype;
2183
+ var _proto = GLTFTextureParser.prototype;
2262
2184
  _proto.parse = function parse(context) {
2263
2185
  var _this = this;
2264
- var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
2186
+ var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
2265
2187
  var engine = glTFResource.engine, url = glTFResource.url;
2266
- if (gltf.textures) {
2188
+ if (glTF.textures) {
2267
2189
  var texturesPromiseInfo = context.texturesPromiseInfo;
2268
- miniprogram.AssetPromise.all(gltf.textures.map(function(param, index) {
2190
+ miniprogram.AssetPromise.all(glTF.textures.map(function(param, index) {
2269
2191
  var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
2270
- 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;
2192
+ 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;
2271
2193
  if (uri) {
2272
2194
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
2273
2195
  var index1 = uri.lastIndexOf(".");
@@ -2281,21 +2203,24 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
2281
2203
  texture.name = textureName || imageName || "texture_" + index1;
2282
2204
  }
2283
2205
  if (sampler !== undefined) {
2284
- _this._parseSampler(texture, gltf.samplers[sampler]);
2206
+ _this._parseSampler(texture, glTF.samplers[sampler]);
2285
2207
  }
2286
2208
  return texture;
2287
2209
  });
2288
2210
  } else {
2289
- var bufferView = gltf.bufferViews[bufferViewIndex];
2290
- var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
2291
- return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
2211
+ var bufferView = glTF.bufferViews[bufferViewIndex];
2212
+ var buffer = buffers[bufferView.buffer];
2213
+ var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2214
+ return GLTFUtil.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2292
2215
  var texture = new miniprogram.Texture2D(engine, image.width, image.height);
2293
2216
  texture.setImageSource(image);
2294
2217
  texture.generateMipmaps();
2295
2218
  texture.name = textureName || imageName || "texture_" + index;
2296
2219
  if (sampler !== undefined) {
2297
- _this._parseSampler(texture, gltf.samplers[sampler]);
2220
+ _this._parseSampler(texture, glTF.samplers[sampler]);
2298
2221
  }
2222
+ var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2223
+ context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2299
2224
  return texture;
2300
2225
  });
2301
2226
  }
@@ -2318,34 +2243,36 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
2318
2243
  }
2319
2244
  }
2320
2245
  if (wrapS) {
2321
- texture.wrapModeU = TextureParser._wrapMap[wrapS];
2246
+ texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2322
2247
  }
2323
2248
  if (wrapT) {
2324
- texture.wrapModeV = TextureParser._wrapMap[wrapT];
2249
+ texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2325
2250
  }
2326
2251
  };
2327
- return TextureParser;
2328
- }(Parser);
2252
+ return GLTFTextureParser;
2253
+ }(GLTFParser);
2329
2254
  var _obj;
2330
- TextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = miniprogram.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = miniprogram.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = miniprogram.TextureWrapMode.Repeat, _obj);
2255
+ GLTFTextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = miniprogram.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = miniprogram.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = miniprogram.TextureWrapMode.Repeat, _obj);
2331
2256
 
2332
- var Validator = /*#__PURE__*/ function(Parser1) {
2333
- _inherits(Validator, Parser1);
2334
- function Validator() {
2335
- return Parser1.apply(this, arguments);
2257
+ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2258
+ _inherits(GLTFValidator, GLTFParser1);
2259
+ function GLTFValidator() {
2260
+ return GLTFParser1.apply(this, arguments);
2336
2261
  }
2337
- var _proto = Validator.prototype;
2262
+ var _proto = GLTFValidator.prototype;
2338
2263
  _proto.parse = function parse(context) {
2339
- var _context_gltf = context.gltf, version = _context_gltf.asset.version, extensionsUsed = _context_gltf.extensionsUsed, extensionsRequired = _context_gltf.extensionsRequired;
2340
- var gltfVersion = Number(version);
2341
- if (!(gltfVersion >= 2 && gltfVersion < 3)) {
2342
- throw "Only support gltf 2.x.";
2264
+ var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
2265
+ var glTFVersion = Number(version);
2266
+ if (!(glTFVersion >= 2 && glTFVersion < 3)) {
2267
+ throw "Only support glTF 2.x.";
2343
2268
  }
2269
+ var promises = [];
2344
2270
  if (extensionsUsed) {
2345
2271
  miniprogram.Logger.info("extensionsUsed: ", extensionsUsed);
2346
2272
  for(var i = 0; i < extensionsUsed.length; i++){
2347
- if (!Parser.hasExtensionParser(extensionsUsed[i])) {
2348
- miniprogram.Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
2273
+ var extensionUsed = extensionsUsed[i];
2274
+ if (!GLTFParser.hasExtensionParser(extensionUsed)) {
2275
+ miniprogram.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
2349
2276
  }
2350
2277
  }
2351
2278
  }
@@ -2353,66 +2280,66 @@ var Validator = /*#__PURE__*/ function(Parser1) {
2353
2280
  miniprogram.Logger.info("extensionsRequired: " + extensionsRequired);
2354
2281
  for(var i1 = 0; i1 < extensionsRequired.length; i1++){
2355
2282
  var extensionRequired = extensionsRequired[i1];
2356
- if (!Parser.hasExtensionParser(extensionRequired)) {
2283
+ if (!GLTFParser.hasExtensionParser(extensionRequired)) {
2357
2284
  miniprogram.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
2358
2285
  } else {
2359
- Parser.initialize(extensionRequired);
2286
+ promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
2360
2287
  }
2361
2288
  }
2362
2289
  }
2290
+ return miniprogram.AssetPromise.all(promises).then(null);
2363
2291
  };
2364
- return Validator;
2365
- }(Parser);
2292
+ return GLTFValidator;
2293
+ }(GLTFParser);
2366
2294
 
2367
- var GLTFParser = /*#__PURE__*/ function() {
2368
- function GLTFParser(pipes) {
2295
+ /**
2296
+ * GLTF pipeline.
2297
+ */ var GLTFPipeline = /*#__PURE__*/ function() {
2298
+ function GLTFPipeline() {
2299
+ for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
2300
+ parsers[_key] = arguments[_key];
2301
+ }
2369
2302
  var _this = this;
2370
- this._pipes = [];
2371
- pipes.forEach(function(pipe, index) {
2372
- _this._pipes[index] = new pipe();
2303
+ this._parsers = [];
2304
+ parsers.forEach(function(pipe, index) {
2305
+ _this._parsers[index] = new pipe();
2373
2306
  });
2374
2307
  }
2375
- var _proto = GLTFParser.prototype;
2376
- _proto.parse = function parse(context) {
2308
+ var _proto = GLTFPipeline.prototype;
2309
+ /**
2310
+ * @internal
2311
+ */ _proto._parse = function _parse(context) {
2377
2312
  var _this = this;
2378
2313
  var glTFResource = context.glTFResource;
2379
- var lastPipe;
2314
+ var lastParser;
2380
2315
  return new miniprogram.AssetPromise(function(resolve, reject) {
2381
- _this._pipes.forEach(function(parser) {
2382
- if (lastPipe) {
2383
- lastPipe = lastPipe.then(function() {
2316
+ _this._parsers.forEach(function(parser) {
2317
+ if (lastParser) {
2318
+ lastParser = lastParser.then(function() {
2384
2319
  return parser.parse(context);
2385
2320
  });
2386
- if (lastPipe.cancel) {
2387
- context.chainPromises.push(lastPipe);
2321
+ if (lastParser.cancel) {
2322
+ context.chainPromises.push(lastParser);
2388
2323
  }
2389
2324
  } else {
2390
- lastPipe = parser.parse(context);
2325
+ lastParser = parser.parse(context);
2391
2326
  }
2392
2327
  });
2393
- if (lastPipe) {
2394
- lastPipe.then(function() {
2328
+ if (lastParser) {
2329
+ lastParser.then(function() {
2395
2330
  resolve(glTFResource);
2396
2331
  }).catch(reject);
2397
2332
  }
2398
2333
  });
2399
2334
  };
2400
- return GLTFParser;
2335
+ return GLTFPipeline;
2401
2336
  }();
2402
- GLTFParser.defaultPipeline = new GLTFParser([
2403
- BufferParser,
2404
- Validator,
2405
- TextureParser,
2406
- MaterialParser,
2407
- MeshParser,
2408
- EntityParser,
2409
- SkinParser,
2410
- AnimationParser,
2411
- SceneParser$1
2412
- ]);
2337
+ /**
2338
+ * Default pipeline.
2339
+ */ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
2413
2340
 
2414
2341
  /**
2415
- * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
2342
+ * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
2416
2343
  */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
2417
2344
  _inherits(GLTFResource, EngineObject);
2418
2345
  function GLTFResource(engine, url) {
@@ -2424,11 +2351,8 @@ GLTFParser.defaultPipeline = new GLTFParser([
2424
2351
  var _proto = GLTFResource.prototype;
2425
2352
  /**
2426
2353
  * @override
2427
- */ _proto.destroy = function destroy() {
2428
- if (this._destroyed) {
2429
- return;
2430
- }
2431
- EngineObject.prototype.destroy.call(this);
2354
+ */ _proto._onDestroy = function _onDestroy() {
2355
+ EngineObject.prototype._onDestroy.call(this);
2432
2356
  this.defaultSceneRoot.destroy();
2433
2357
  this.textures = null;
2434
2358
  this.materials = null;
@@ -2439,7 +2363,7 @@ GLTFParser.defaultPipeline = new GLTFParser([
2439
2363
  this.cameras = null;
2440
2364
  this.lights = null;
2441
2365
  this.sceneRoots = null;
2442
- this.variants = null;
2366
+ this.extensionsData = null;
2443
2367
  };
2444
2368
  return GLTFResource;
2445
2369
  }(miniprogram.EngineObject);
@@ -2450,15 +2374,19 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2450
2374
  return Loader.apply(this, arguments);
2451
2375
  }
2452
2376
  var _proto = GLTFLoader.prototype;
2453
- _proto.load = function load(item, resourceManager) {
2454
- var _item_params;
2377
+ /**
2378
+ * @override
2379
+ */ _proto.load = function load(item, resourceManager) {
2455
2380
  var url = item.url;
2456
- var context = new ParserContext(url);
2381
+ var params = item.params;
2382
+ var context = new GLTFParserContext(url);
2457
2383
  var glTFResource = new GLTFResource(resourceManager.engine, url);
2384
+ var restorer = new GLTFContentRestorer(glTFResource);
2458
2385
  var masterPromiseInfo = context.masterPromiseInfo;
2386
+ context.contentRestorer = restorer;
2459
2387
  context.glTFResource = glTFResource;
2460
- var _item_params_keepMeshData;
2461
- context.keepMeshData = (_item_params_keepMeshData = (_item_params = item.params) == null ? void 0 : _item_params.keepMeshData) != null ? _item_params_keepMeshData : false;
2388
+ var _params_keepMeshData;
2389
+ context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
2462
2390
  masterPromiseInfo.onCancel(function() {
2463
2391
  var chainPromises = context.chainPromises;
2464
2392
  for(var _iterator = _createForOfIteratorHelperLoose(chainPromises), _step; !(_step = _iterator()).done;){
@@ -2466,7 +2394,10 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2466
2394
  promise.cancel();
2467
2395
  }
2468
2396
  });
2469
- GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
2397
+ ((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
2398
+ resourceManager.addContentRestorer(restorer);
2399
+ masterPromiseInfo.resolve(glTFResource);
2400
+ }).catch(function(e) {
2470
2401
  console.error(e);
2471
2402
  masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
2472
2403
  });
@@ -2475,7 +2406,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2475
2406
  return GLTFLoader;
2476
2407
  }(miniprogram.Loader);
2477
2408
  GLTFLoader = __decorate([
2478
- miniprogram.resourceLoader(miniprogram.AssetType.Prefab, [
2409
+ miniprogram.resourceLoader(miniprogram.AssetType.GLTF, [
2479
2410
  "gltf",
2480
2411
  "glb"
2481
2412
  ])
@@ -2825,40 +2756,40 @@ function getEngineFormat(internalFormat) {
2825
2756
  // case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT3_EXT:
2826
2757
  // case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2827
2758
  // break;
2828
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
2759
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
2829
2760
  return miniprogram.TextureFormat.DXT1;
2830
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2761
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2831
2762
  return miniprogram.TextureFormat.DXT5;
2832
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
2763
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
2833
2764
  return miniprogram.TextureFormat.ETC1_RGB;
2834
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_ETC2:
2765
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_ETC2:
2835
2766
  return miniprogram.TextureFormat.ETC2_RGB;
2836
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
2767
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
2837
2768
  return miniprogram.TextureFormat.ETC2_RGBA5;
2838
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
2769
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
2839
2770
  return miniprogram.TextureFormat.ETC2_RGBA8;
2840
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
2771
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
2841
2772
  return miniprogram.TextureFormat.PVRTC_RGB2;
2842
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
2773
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
2843
2774
  return miniprogram.TextureFormat.PVRTC_RGBA2;
2844
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
2775
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
2845
2776
  return miniprogram.TextureFormat.PVRTC_RGB4;
2846
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
2777
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
2847
2778
  return miniprogram.TextureFormat.PVRTC_RGBA4;
2848
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
2779
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
2849
2780
  return miniprogram.TextureFormat.ASTC_4x4;
2850
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
2781
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
2851
2782
  return miniprogram.TextureFormat.ASTC_5x5;
2852
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
2783
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
2853
2784
  return miniprogram.TextureFormat.ASTC_6x6;
2854
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
2785
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
2855
2786
  return miniprogram.TextureFormat.ASTC_8x8;
2856
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
2787
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
2857
2788
  return miniprogram.TextureFormat.ASTC_10x10;
2858
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
2789
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
2859
2790
  return miniprogram.TextureFormat.ASTC_12x12;
2860
2791
  default:
2861
- var formatName = miniprogram$3.GLCompressedTextureInternalFormat[internalFormat];
2792
+ var formatName = miniprogram$2.GLCompressedTextureInternalFormat[internalFormat];
2862
2793
  throw new Error("this format is not supported in Galacean Engine: " + formatName);
2863
2794
  }
2864
2795
  }
@@ -4223,28 +4154,57 @@ SpriteLoader = __decorate([
4223
4154
  ], false)
4224
4155
  ], SpriteLoader);
4225
4156
 
4157
+ /**
4158
+ * @internal
4159
+ */ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4160
+ _inherits(Texture2DContentRestorer, ContentRestorer);
4161
+ function Texture2DContentRestorer(resource, url, requestConfig) {
4162
+ var _this;
4163
+ _this = ContentRestorer.call(this, resource) || this;
4164
+ _this.url = url;
4165
+ _this.requestConfig = requestConfig;
4166
+ return _this;
4167
+ }
4168
+ var _proto = Texture2DContentRestorer.prototype;
4169
+ /**
4170
+ * @override
4171
+ */ _proto.restoreContent = function restoreContent() {
4172
+ var _this = this;
4173
+ return miniprogram.request(this.url, this.requestConfig).then(function(image) {
4174
+ var resource = _this.resource;
4175
+ resource.setImageSource(image);
4176
+ resource.generateMipmaps();
4177
+ return resource;
4178
+ });
4179
+ };
4180
+ return Texture2DContentRestorer;
4181
+ }(miniprogram.ContentRestorer);
4182
+
4226
4183
  var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4227
4184
  _inherits(Texture2DLoader, Loader);
4228
4185
  function Texture2DLoader() {
4229
4186
  return Loader.apply(this, arguments);
4230
4187
  }
4231
4188
  var _proto = Texture2DLoader.prototype;
4232
- _proto.load = function load(item, resourceManager) {
4189
+ /**
4190
+ * @override
4191
+ */ _proto.load = function load(item, resourceManager) {
4233
4192
  var _this = this;
4234
4193
  return new miniprogram.AssetPromise(function(resolve, reject) {
4235
- _this.request(item.url, _extends({}, item, {
4194
+ var url = item.url;
4195
+ var requestConfig = _extends({}, item, {
4236
4196
  type: "image"
4237
- })).then(function(image) {
4238
- var _item_params;
4239
- var params = (_item_params = item.params) != null ? _item_params : {};
4240
- var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
4241
- /** @ts-ignore */ if (!texture._platformTexture) return;
4197
+ });
4198
+ _this.request(url, requestConfig).then(function(image) {
4199
+ var params = item.params;
4200
+ var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
4242
4201
  texture.setImageSource(image);
4243
4202
  texture.generateMipmaps();
4244
- if (item.url.indexOf("data:") !== 0) {
4245
- var splitPath = item.url.split("/");
4246
- texture.name = splitPath[splitPath.length - 1];
4203
+ if (url.indexOf("data:") !== 0) {
4204
+ var index = url.lastIndexOf("/");
4205
+ texture.name = url.substring(index + 1);
4247
4206
  }
4207
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
4248
4208
  resolve(texture);
4249
4209
  }).catch(function(e) {
4250
4210
  reject(e);
@@ -4262,45 +4222,107 @@ Texture2DLoader = __decorate([
4262
4222
  ])
4263
4223
  ], Texture2DLoader);
4264
4224
 
4265
- var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4266
- _inherits(TextureCubeLoader, Loader);
4267
- function TextureCubeLoader() {
4268
- return Loader.apply(this, arguments);
4225
+ /**
4226
+ * @internal
4227
+ */ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4228
+ _inherits(TextureCubeContentRestorer, ContentRestorer);
4229
+ function TextureCubeContentRestorer(resource, urls, requestConfig) {
4230
+ var _this;
4231
+ _this = ContentRestorer.call(this, resource) || this;
4232
+ _this.urls = urls;
4233
+ _this.requestConfig = requestConfig;
4234
+ return _this;
4269
4235
  }
4270
- var _proto = TextureCubeLoader.prototype;
4271
- _proto.load = function load(item, resourceManager) {
4236
+ var _proto = TextureCubeContentRestorer.prototype;
4237
+ /**
4238
+ * @override
4239
+ */ _proto.restoreContent = function restoreContent() {
4272
4240
  var _this = this;
4273
4241
  return new miniprogram.AssetPromise(function(resolve, reject) {
4274
- Promise.all(item.urls.map(function(url) {
4275
- return _this.request(url, _extends({}, item, {
4276
- type: "image"
4277
- }));
4242
+ Promise.all(_this.urls.map(function(url) {
4243
+ return miniprogram.request(url, _this.requestConfig);
4278
4244
  })).then(function(images) {
4279
- var _images_ = images[0], width = _images_.width, height = _images_.height;
4280
- if (width !== height) {
4281
- console.error("The cube texture must have the same width and height");
4282
- return;
4283
- }
4284
- var tex = new miniprogram.TextureCube(resourceManager.engine, width);
4285
- /** @ts-ignore */ if (!tex._platformTexture) return;
4245
+ var resource = _this.resource;
4286
4246
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4287
- tex.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4247
+ resource.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4288
4248
  }
4289
- tex.generateMipmaps();
4290
- resolve(tex);
4249
+ resource.generateMipmaps();
4250
+ resolve(resource);
4291
4251
  }).catch(function(e) {
4292
4252
  reject(e);
4293
4253
  });
4294
4254
  });
4295
4255
  };
4296
- return TextureCubeLoader;
4297
- }(miniprogram.Loader);
4298
- TextureCubeLoader = __decorate([
4299
- miniprogram.resourceLoader(miniprogram.AssetType.TextureCube, [
4256
+ return TextureCubeContentRestorer;
4257
+ }(miniprogram.ContentRestorer);
4258
+
4259
+ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4260
+ _inherits(TextureCubeLoader, Loader);
4261
+ function TextureCubeLoader() {
4262
+ return Loader.apply(this, arguments);
4263
+ }
4264
+ var _proto = TextureCubeLoader.prototype;
4265
+ /**
4266
+ * @override
4267
+ */ _proto.load = function load(item, resourceManager) {
4268
+ var _this = this;
4269
+ return new miniprogram.AssetPromise(function(resolve, reject) {
4270
+ var urls = item.urls;
4271
+ var requestConfig = _extends({}, item, {
4272
+ type: "image"
4273
+ });
4274
+ Promise.all(urls.map(function(url) {
4275
+ return _this.request(url, requestConfig);
4276
+ })).then(function(images) {
4277
+ var _images_ = images[0], width = _images_.width, height = _images_.height;
4278
+ if (width !== height) {
4279
+ console.error("The cube texture must have the same width and height");
4280
+ return;
4281
+ }
4282
+ var texture = new miniprogram.TextureCube(resourceManager.engine, width);
4283
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4284
+ texture.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4285
+ }
4286
+ texture.generateMipmaps();
4287
+ resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
4288
+ resolve(texture);
4289
+ }).catch(function(e) {
4290
+ reject(e);
4291
+ });
4292
+ });
4293
+ };
4294
+ return TextureCubeLoader;
4295
+ }(miniprogram.Loader);
4296
+ TextureCubeLoader = __decorate([
4297
+ miniprogram.resourceLoader(miniprogram.AssetType.TextureCube, [
4300
4298
  ""
4301
4299
  ])
4302
4300
  ], TextureCubeLoader);
4303
4301
 
4302
+ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
4303
+ _inherits(AnimationClipLoader, Loader);
4304
+ function AnimationClipLoader() {
4305
+ return Loader.apply(this, arguments);
4306
+ }
4307
+ var _proto = AnimationClipLoader.prototype;
4308
+ _proto.load = function load(item, resourceManager) {
4309
+ var _this = this;
4310
+ return new miniprogram.AssetPromise(function(resolve, reject) {
4311
+ _this.request(item.url, _extends({}, item, {
4312
+ type: "arraybuffer"
4313
+ })).then(function(data) {
4314
+ return decode(data, resourceManager.engine);
4315
+ }).catch(reject);
4316
+ });
4317
+ };
4318
+ return AnimationClipLoader;
4319
+ }(miniprogram.Loader);
4320
+ AnimationClipLoader = __decorate([
4321
+ miniprogram.resourceLoader(miniprogram.AssetType.AnimationClip, [
4322
+ "ani"
4323
+ ])
4324
+ ], AnimationClipLoader);
4325
+
4304
4326
  var SceneLoader = /*#__PURE__*/ function(Loader) {
4305
4327
  _inherits(SceneLoader, Loader);
4306
4328
  function SceneLoader() {
@@ -4401,10 +4423,408 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
4401
4423
  });
4402
4424
  }));
4403
4425
 
4426
+ var _KHR_draco_mesh_compression;
4427
+ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
4428
+ _inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
4429
+ function KHR_draco_mesh_compression1() {
4430
+ return GLTFExtensionParser.apply(this, arguments);
4431
+ }
4432
+ var _proto = KHR_draco_mesh_compression1.prototype;
4433
+ /**
4434
+ * @override
4435
+ */ _proto.initialize = function initialize() {
4436
+ if (!KHR_draco_mesh_compression._decoder) {
4437
+ KHR_draco_mesh_compression._decoder = new miniprogram$3.DRACODecoder();
4438
+ }
4439
+ };
4440
+ /**
4441
+ * @override
4442
+ */ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
4443
+ var _this = this;
4444
+ var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
4445
+ var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
4446
+ var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
4447
+ var attributeMap = {};
4448
+ var attributeTypeMap = {};
4449
+ for(var attributeName in gltfAttributeMap){
4450
+ attributeMap[attributeName] = gltfAttributeMap[attributeName];
4451
+ }
4452
+ for(var attributeName1 in glTFPrimitive.attributes){
4453
+ if (gltfAttributeMap[attributeName1] !== undefined) {
4454
+ var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
4455
+ attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
4456
+ }
4457
+ }
4458
+ var indexAccessor = accessors[glTFPrimitive.indices];
4459
+ var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
4460
+ var taskConfig = {
4461
+ attributeIDs: attributeMap,
4462
+ attributeTypes: attributeTypeMap,
4463
+ useUniqueIDs: true,
4464
+ indexType: indexType
4465
+ };
4466
+ var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4467
+ return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4468
+ var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
4469
+ return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4470
+ for(var j = 0; j < decodedGeometry.attributes.length; j++){
4471
+ if (decodedGeometry.attributes[j].name === attributeSemantic) {
4472
+ return decodedGeometry.attributes[j].array;
4473
+ }
4474
+ }
4475
+ return null;
4476
+ }, function(attributeSemantic, shapeIndex) {
4477
+ throw "BlendShape animation is not supported when using draco.";
4478
+ }, function() {
4479
+ return decodedGeometry.index.array;
4480
+ }, context.keepMeshData);
4481
+ });
4482
+ };
4483
+ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
4484
+ var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
4485
+ var vertexCount;
4486
+ var accessors = gltf.accessors;
4487
+ var accessor = accessors[attributes["POSITION"]];
4488
+ var positionBuffer = getVertexBufferData("POSITION");
4489
+ var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
4490
+ mesh.setPositions(positions);
4491
+ var bounds = mesh.bounds;
4492
+ vertexCount = accessor.count;
4493
+ if (accessor.min && accessor.max) {
4494
+ bounds.min.copyFromArray(accessor.min);
4495
+ bounds.max.copyFromArray(accessor.max);
4496
+ } else {
4497
+ var position = KHR_draco_mesh_compression._tempVector3;
4498
+ var min = bounds.min, max = bounds.max;
4499
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
4500
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
4501
+ var stride = positionBuffer.length / vertexCount;
4502
+ for(var j = 0; j < vertexCount; j++){
4503
+ var offset = j * stride;
4504
+ position.copyFromArray(positionBuffer, offset);
4505
+ miniprogram$1.Vector3.min(min, position, min);
4506
+ miniprogram$1.Vector3.max(max, position, max);
4507
+ }
4508
+ }
4509
+ for(var attributeSemantic in attributes){
4510
+ if (attributeSemantic === "POSITION") {
4511
+ continue;
4512
+ }
4513
+ var bufferData = getVertexBufferData(attributeSemantic);
4514
+ switch(attributeSemantic){
4515
+ case "NORMAL":
4516
+ var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
4517
+ mesh.setNormals(normals);
4518
+ break;
4519
+ case "TEXCOORD_0":
4520
+ var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
4521
+ mesh.setUVs(texturecoords, 0);
4522
+ break;
4523
+ case "TEXCOORD_1":
4524
+ var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
4525
+ mesh.setUVs(texturecoords1, 1);
4526
+ break;
4527
+ case "TEXCOORD_2":
4528
+ var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
4529
+ mesh.setUVs(texturecoords2, 2);
4530
+ break;
4531
+ case "TEXCOORD_3":
4532
+ var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
4533
+ mesh.setUVs(texturecoords3, 3);
4534
+ break;
4535
+ case "TEXCOORD_4":
4536
+ var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
4537
+ mesh.setUVs(texturecoords4, 4);
4538
+ break;
4539
+ case "TEXCOORD_5":
4540
+ var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
4541
+ mesh.setUVs(texturecoords5, 5);
4542
+ break;
4543
+ case "TEXCOORD_6":
4544
+ var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
4545
+ mesh.setUVs(texturecoords6, 6);
4546
+ break;
4547
+ case "TEXCOORD_7":
4548
+ var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
4549
+ mesh.setUVs(texturecoords7, 7);
4550
+ break;
4551
+ case "COLOR_0":
4552
+ var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
4553
+ mesh.setColors(colors);
4554
+ break;
4555
+ case "TANGENT":
4556
+ var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
4557
+ mesh.setTangents(tangents);
4558
+ break;
4559
+ case "JOINTS_0":
4560
+ var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
4561
+ mesh.setBoneIndices(joints);
4562
+ break;
4563
+ case "WEIGHTS_0":
4564
+ var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
4565
+ mesh.setBoneWeights(weights);
4566
+ break;
4567
+ }
4568
+ }
4569
+ // Indices
4570
+ if (indices !== undefined) {
4571
+ var indexAccessor = gltf.accessors[indices];
4572
+ var indexData = getIndexBufferData();
4573
+ mesh.setIndices(indexData);
4574
+ mesh.addSubMesh(0, indexAccessor.count, mode);
4575
+ } else {
4576
+ mesh.addSubMesh(0, vertexCount, mode);
4577
+ }
4578
+ // BlendShapes
4579
+ targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
4580
+ mesh.uploadData(!keepMeshData);
4581
+ return Promise.resolve(mesh);
4582
+ };
4583
+ return KHR_draco_mesh_compression1;
4584
+ }(GLTFExtensionParser), _KHR_draco_mesh_compression._tempVector3 = new miniprogram$1.Vector3(), _KHR_draco_mesh_compression);
4585
+ KHR_draco_mesh_compression = __decorate([
4586
+ registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
4587
+ ], KHR_draco_mesh_compression);
4588
+
4589
+ var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
4590
+ _inherits(KHR_lights_punctual, GLTFExtensionParser);
4591
+ function KHR_lights_punctual() {
4592
+ return GLTFExtensionParser.apply(this, arguments);
4593
+ }
4594
+ var _proto = KHR_lights_punctual.prototype;
4595
+ /**
4596
+ * @override
4597
+ */ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
4598
+ var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
4599
+ var lightSchema = lightsSchema[extensionSchema.light];
4600
+ 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;
4601
+ var glTFResource = context.glTFResource;
4602
+ var light;
4603
+ if (type === "directional") {
4604
+ light = entity.addComponent(miniprogram.DirectLight);
4605
+ } else if (type === "point") {
4606
+ light = entity.addComponent(miniprogram.PointLight);
4607
+ } else if (type === "spot") {
4608
+ light = entity.addComponent(miniprogram.SpotLight);
4609
+ }
4610
+ if (color) {
4611
+ light.color.set(color[0], color[1], color[2], 1);
4612
+ }
4613
+ light.intensity = intensity;
4614
+ if (range && !_instanceof(light, miniprogram.DirectLight)) {
4615
+ light.distance = range;
4616
+ }
4617
+ if (spot && _instanceof(light, miniprogram.SpotLight)) {
4618
+ 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;
4619
+ light.angle = innerConeAngle;
4620
+ light.penumbra = outerConeAngle - innerConeAngle;
4621
+ }
4622
+ if (!glTFResource.lights) glTFResource.lights = [];
4623
+ glTFResource.lights.push(light);
4624
+ };
4625
+ return KHR_lights_punctual;
4626
+ }(GLTFExtensionParser);
4627
+ KHR_lights_punctual = __decorate([
4628
+ registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
4629
+ ], KHR_lights_punctual);
4630
+
4631
+ var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
4632
+ _inherits(KHR_materials_clearcoat, GLTFExtensionParser);
4633
+ function KHR_materials_clearcoat() {
4634
+ return GLTFExtensionParser.apply(this, arguments);
4635
+ }
4636
+ var _proto = KHR_materials_clearcoat.prototype;
4637
+ /**
4638
+ * @override
4639
+ */ _proto.additiveParse = function additiveParse(context, material, schema) {
4640
+ var textures = context.glTFResource.textures;
4641
+ 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;
4642
+ material.clearCoat = clearcoatFactor;
4643
+ material.clearCoatRoughness = clearcoatRoughnessFactor;
4644
+ if (clearcoatTexture) {
4645
+ material.clearCoatTexture = textures[clearcoatTexture.index];
4646
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
4647
+ }
4648
+ if (clearcoatRoughnessTexture) {
4649
+ material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
4650
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
4651
+ }
4652
+ if (clearcoatNormalTexture) {
4653
+ material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
4654
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
4655
+ }
4656
+ };
4657
+ return KHR_materials_clearcoat;
4658
+ }(GLTFExtensionParser);
4659
+ KHR_materials_clearcoat = __decorate([
4660
+ registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
4661
+ ], KHR_materials_clearcoat);
4662
+
4663
+ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
4664
+ _inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
4665
+ function KHR_materials_pbrSpecularGlossiness() {
4666
+ return GLTFExtensionParser.apply(this, arguments);
4667
+ }
4668
+ var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
4669
+ /**
4670
+ * @override
4671
+ */ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
4672
+ var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
4673
+ var material = new miniprogram.PBRSpecularMaterial(engine);
4674
+ var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
4675
+ if (diffuseFactor) {
4676
+ material.baseColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(diffuseFactor[0]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[1]), miniprogram$1.Color.linearToGammaSpace(diffuseFactor[2]), diffuseFactor[3]);
4677
+ }
4678
+ if (diffuseTexture) {
4679
+ material.baseTexture = textures[diffuseTexture.index];
4680
+ GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
4681
+ }
4682
+ if (specularFactor) {
4683
+ material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
4684
+ }
4685
+ if (glossinessFactor !== undefined) {
4686
+ material.glossiness = glossinessFactor;
4687
+ }
4688
+ if (specularGlossinessTexture) {
4689
+ material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
4690
+ GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
4691
+ }
4692
+ material.name = ownerSchema.name;
4693
+ GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4694
+ return material;
4695
+ };
4696
+ return KHR_materials_pbrSpecularGlossiness;
4697
+ }(GLTFExtensionParser);
4698
+ KHR_materials_pbrSpecularGlossiness = __decorate([
4699
+ registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
4700
+ ], KHR_materials_pbrSpecularGlossiness);
4701
+
4702
+ var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
4703
+ _inherits(KHR_materials_unlit, GLTFExtensionParser);
4704
+ function KHR_materials_unlit() {
4705
+ return GLTFExtensionParser.apply(this, arguments);
4706
+ }
4707
+ var _proto = KHR_materials_unlit.prototype;
4708
+ /**
4709
+ * @override
4710
+ */ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
4711
+ var engine = context.glTFResource.engine;
4712
+ var material = new miniprogram.UnlitMaterial(engine);
4713
+ material.name = ownerSchema.name;
4714
+ GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4715
+ return material;
4716
+ };
4717
+ return KHR_materials_unlit;
4718
+ }(GLTFExtensionParser);
4719
+ KHR_materials_unlit = __decorate([
4720
+ registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
4721
+ ], KHR_materials_unlit);
4722
+
4723
+ var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
4724
+ _inherits(KHR_mesh_quantization, GLTFExtensionParser);
4725
+ function KHR_mesh_quantization() {
4726
+ return GLTFExtensionParser.apply(this, arguments);
4727
+ }
4728
+ return KHR_mesh_quantization;
4729
+ }(GLTFExtensionParser);
4730
+ KHR_mesh_quantization = __decorate([
4731
+ registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
4732
+ ], KHR_mesh_quantization);
4733
+
4734
+ var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
4735
+ _inherits(KHR_texture_transform, GLTFExtensionParser);
4736
+ function KHR_texture_transform() {
4737
+ return GLTFExtensionParser.apply(this, arguments);
4738
+ }
4739
+ var _proto = KHR_texture_transform.prototype;
4740
+ /**
4741
+ * @override
4742
+ */ _proto.additiveParse = function additiveParse(context, material, schema) {
4743
+ var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
4744
+ if (offset) {
4745
+ material.tilingOffset.z = offset[0];
4746
+ material.tilingOffset.w = offset[1];
4747
+ }
4748
+ if (scale) {
4749
+ material.tilingOffset.x = scale[0];
4750
+ material.tilingOffset.y = scale[1];
4751
+ }
4752
+ if (rotation) {
4753
+ miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
4754
+ }
4755
+ if (texCoord) {
4756
+ miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
4757
+ }
4758
+ };
4759
+ return KHR_texture_transform;
4760
+ }(GLTFExtensionParser);
4761
+ KHR_texture_transform = __decorate([
4762
+ registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
4763
+ ], KHR_texture_transform);
4764
+
4765
+ var GalaceanMaterialsRemap = /*#__PURE__*/ function(GLTFExtensionParser) {
4766
+ _inherits(GalaceanMaterialsRemap, GLTFExtensionParser);
4767
+ function GalaceanMaterialsRemap() {
4768
+ return GLTFExtensionParser.apply(this, arguments);
4769
+ }
4770
+ var _proto = GalaceanMaterialsRemap.prototype;
4771
+ /**
4772
+ * @override
4773
+ */ _proto.createAndParse = function createAndParse(context, schema) {
4774
+ var engine = context.glTFResource.engine;
4775
+ // @ts-ignore
4776
+ return engine.resourceManager.getResourceByRef(schema);
4777
+ };
4778
+ return GalaceanMaterialsRemap;
4779
+ }(GLTFExtensionParser);
4780
+ GalaceanMaterialsRemap = __decorate([
4781
+ registerGLTFExtension("OASIS_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
4782
+ ], GalaceanMaterialsRemap);
4783
+
4784
+ var OASIS_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
4785
+ _inherits(OASIS_animation_event, GLTFExtensionParser);
4786
+ function OASIS_animation_event() {
4787
+ return GLTFExtensionParser.apply(this, arguments);
4788
+ }
4789
+ var _proto = OASIS_animation_event.prototype;
4790
+ /**
4791
+ * @override
4792
+ */ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
4793
+ context.glTFResource.engine;
4794
+ var events = schema.events;
4795
+ events.map(function(eventData) {
4796
+ var event = new miniprogram.AnimationEvent();
4797
+ event.functionName = eventData.functionName;
4798
+ event.time = eventData.time;
4799
+ event.parameter = eventData.parameter;
4800
+ animationClip.addEvent(event);
4801
+ });
4802
+ };
4803
+ return OASIS_animation_event;
4804
+ }(GLTFExtensionParser);
4805
+ OASIS_animation_event = __decorate([
4806
+ registerGLTFExtension("OASIS_animation_event", exports.GLTFExtensionMode.AdditiveParse)
4807
+ ], OASIS_animation_event);
4808
+
4404
4809
  exports.ComponentMap = ComponentMap;
4810
+ exports.GLTFAnimationParser = GLTFAnimationParser;
4811
+ exports.GLTFBufferParser = GLTFBufferParser;
4812
+ exports.GLTFEntityParser = GLTFEntityParser;
4813
+ exports.GLTFExtensionParser = GLTFExtensionParser;
4814
+ exports.GLTFMaterialParser = GLTFMaterialParser;
4815
+ exports.GLTFMeshParser = GLTFMeshParser;
4816
+ exports.GLTFParser = GLTFParser;
4817
+ exports.GLTFParserContext = GLTFParserContext;
4818
+ exports.GLTFPipeline = GLTFPipeline;
4405
4819
  exports.GLTFResource = GLTFResource;
4820
+ exports.GLTFSceneParser = GLTFSceneParser;
4821
+ exports.GLTFSkinParser = GLTFSkinParser;
4822
+ exports.GLTFTextureParser = GLTFTextureParser;
4823
+ exports.GLTFUtil = GLTFUtil;
4824
+ exports.GLTFValidator = GLTFValidator;
4406
4825
  exports.PrefabParser = PrefabParser;
4407
4826
  exports.ReflectionParser = ReflectionParser;
4408
4827
  exports.SceneParser = SceneParser;
4409
4828
  exports.decode = decode;
4410
4829
  exports.parseSingleKTX = parseSingleKTX;
4830
+ exports.registerGLTFExtension = registerGLTFExtension;