@galacean/engine-loader 1.0.0 → 1.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/main.js +1520 -1080
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +1538 -1098
  4. package/dist/module.js +1507 -1082
  5. package/dist/module.js.map +1 -1
  6. package/package.json +5 -5
  7. package/types/AnimationClipLoader.d.ts +1 -0
  8. package/types/GLTFContentRestorer.d.ts +82 -0
  9. package/types/GLTFLoader.d.ts +3 -0
  10. package/types/Texture2DContentRestorer.d.ts +11 -0
  11. package/types/TextureCubeContentRestorer.d.ts +11 -0
  12. package/types/gltf/GLTFPipeline.d.ts +23 -0
  13. package/types/gltf/GLTFResource.d.ts +8 -12
  14. package/types/gltf/GLTFSchema.d.ts +816 -0
  15. package/types/gltf/GLTFUtil.d.ts +1 -1
  16. package/types/gltf/GLTFUtils.d.ts +47 -0
  17. package/types/gltf/extensions/GALACEAN_animation_event.d.ts +1 -0
  18. package/types/gltf/extensions/GLTFExtensionParser.d.ts +52 -0
  19. package/types/gltf/extensions/GLTFExtensionSchema.d.ts +149 -0
  20. package/types/gltf/extensions/KHR_materials_ior.d.ts +1 -0
  21. package/types/gltf/extensions/KHR_materials_variants.d.ts +6 -1
  22. package/types/gltf/extensions/index.d.ts +5 -1
  23. package/types/gltf/index.d.ts +6 -0
  24. package/types/gltf/parser/GLTFAnimationParser.d.ts +12 -0
  25. package/types/gltf/parser/GLTFBufferParser.d.ts +7 -0
  26. package/types/gltf/parser/GLTFEntityParser.d.ts +9 -0
  27. package/types/gltf/parser/GLTFMaterialParser.d.ts +15 -0
  28. package/types/gltf/parser/GLTFMeshParser.d.ts +19 -0
  29. package/types/gltf/parser/GLTFParser.d.ts +63 -0
  30. package/types/gltf/parser/GLTFParserContext.d.ts +48 -0
  31. package/types/gltf/parser/GLTFSceneParser.d.ts +11 -0
  32. package/types/gltf/parser/GLTFSkinParser.d.ts +6 -0
  33. package/types/gltf/parser/GLTFTextureParser.d.ts +8 -0
  34. package/types/gltf/parser/GLTFValidator.d.ts +6 -0
  35. package/types/gltf/parser/index.d.ts +11 -0
  36. package/types/index.d.ts +2 -2
  37. package/types/resource-deserialize/index.d.ts +3 -3
  38. package/types/resource-deserialize/resources/mesh/MeshDecoder.d.ts +1 -1
  39. package/types/resource-deserialize/resources/parser/PrefabParser.d.ts +5 -0
  40. package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +14 -0
  41. package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
  42. package/types/resource-deserialize/resources/scene/SceneParser.d.ts +1 -1
  43. package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +1 -1
  44. package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +61 -0
  45. package/types/resource-deserialize/resources/schema/MaterialSchema.d.ts +91 -0
  46. package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +41 -0
  47. package/types/resource-deserialize/resources/schema/index.d.ts +3 -0
@@ -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 assign(target) {
@@ -91,10 +91,10 @@ function __generator(thisArg, body) {
91
91
  }
92
92
  }
93
93
 
94
- var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
95
- _inherits(AnimatorControllerLoader, Loader);
94
+ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
95
+ _inherits(AnimatorControllerLoader, Loader1);
96
96
  function AnimatorControllerLoader() {
97
- return Loader.apply(this, arguments);
97
+ return Loader1.apply(this, arguments);
98
98
  }
99
99
  var _proto = AnimatorControllerLoader.prototype;
100
100
  _proto.load = function load(item, resourceManager) {
@@ -115,13 +115,16 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
115
115
  var states = stateMachineData.states;
116
116
  var stateMachine = layer.stateMachine = new miniprogram.AnimatorStateMachine();
117
117
  states.forEach(function(stateData, stateIndex) {
118
- var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
118
+ 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;
119
119
  var state = stateMachine.addState(name);
120
120
  isDefaultState && (stateMachine.defaultState = state);
121
121
  state.speed = speed;
122
122
  state.wrapMode = wrapMode;
123
123
  state.clipStartTime = clipStartNormalizedTime;
124
124
  state.clipEndTime = clipEndNormalizedTime;
125
+ scripts == null ? void 0 : scripts.forEach(function(script) {
126
+ state.addStateMachineScript(miniprogram.Loader.getClass(script));
127
+ });
125
128
  if (clipData) {
126
129
  promises.push(new Promise(function(resolve) {
127
130
  //@ts-ignore
@@ -342,52 +345,194 @@ FontLoader = __decorate([
342
345
  ], false)
343
346
  ], FontLoader);
344
347
 
348
+ function _array_like_to_array(arr, len) {
349
+ if (len == null || len > arr.length) len = arr.length;
350
+
351
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
352
+
353
+ return arr2;
354
+ }
355
+
356
+ function _unsupported_iterable_to_array(o, minLen) {
357
+ if (!o) return;
358
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
359
+
360
+ var n = Object.prototype.toString.call(o).slice(8, -1);
361
+
362
+ if (n === "Object" && o.constructor) n = o.constructor.name;
363
+ if (n === "Map" || n === "Set") return Array.from(n);
364
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
365
+ }
366
+
367
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
368
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
369
+
370
+ if (it) return (it = it.call(o)).next.bind(it);
371
+ // Fallback for engines without symbol support
372
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
373
+ if (it) o = it;
374
+
375
+ var i = 0;
376
+
377
+ return function() {
378
+ if (i >= o.length) return { done: true };
379
+
380
+ return { done: false, value: o[i++] };
381
+ };
382
+ }
383
+
384
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
385
+ }
386
+
345
387
  /**
346
388
  * @internal
347
- */ var ParserContext = /*#__PURE__*/ function() {
348
- function ParserContext(url) {
349
- this.hasSkinned = false;
350
- /** chain asset promise */ this.chainPromises = [];
351
- this.accessorBufferCache = {};
352
- this.texturesPromiseInfo = new PromiseInfo();
353
- this.materialsPromiseInfo = new PromiseInfo();
354
- this.meshesPromiseInfo = new PromiseInfo();
355
- this.animationClipsPromiseInfo = new PromiseInfo();
356
- this.defaultSceneRootPromiseInfo = new PromiseInfo();
357
- this.masterPromiseInfo = new PromiseInfo();
358
- this.promiseMap = {};
359
- var promiseMap = this.promiseMap;
360
- promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
361
- promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
362
- promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
363
- promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
364
- promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
365
- promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
389
+ */ var GLTFContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
390
+ _inherits(GLTFContentRestorer, ContentRestorer);
391
+ function GLTFContentRestorer() {
392
+ var _this;
393
+ _this = ContentRestorer.apply(this, arguments) || this;
394
+ _this.bufferRequests = [];
395
+ _this.glbBufferSlices = [];
396
+ _this.bufferTextures = [];
397
+ _this.meshes = [];
398
+ return _this;
366
399
  }
367
- var _proto = ParserContext.prototype;
368
- _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
369
- var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
370
- promiseInfo.resolve = resolve;
371
- promiseInfo.reject = reject;
372
- promiseInfo.setProgress = setProgress;
373
- promiseInfo.onCancel = onCancel;
400
+ var _proto = GLTFContentRestorer.prototype;
401
+ _proto.restoreContent = function restoreContent() {
402
+ var _this = this;
403
+ return new miniprogram.AssetPromise(function(resolve, reject) {
404
+ Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
405
+ return miniprogram.request(bufferRequestInfo.url, bufferRequestInfo.config);
406
+ })).then(function(buffers) {
407
+ // Buffer parse
408
+ if (_this.isGLB) {
409
+ var glbBufferSlice = _this.glbBufferSlices;
410
+ var bigBuffer = buffers[0];
411
+ var bufferCount = glbBufferSlice.length;
412
+ buffers.length = bufferCount;
413
+ for(var i = 0; i < bufferCount; i++){
414
+ var slice = glbBufferSlice[i];
415
+ buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
416
+ }
417
+ }
418
+ // Restore texture
419
+ miniprogram.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
420
+ var bufferView = textureRestoreInfo.bufferView;
421
+ var buffer = buffers[bufferView.buffer];
422
+ var _bufferView_byteOffset;
423
+ var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
424
+ return GLTFUtils.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
425
+ textureRestoreInfo.texture.setImageSource(image);
426
+ textureRestoreInfo.texture.generateMipmaps();
427
+ });
428
+ })).then(function() {
429
+ // Restore mesh
430
+ for(var _iterator = _create_for_of_iterator_helper_loose(_this.meshes), _step; !(_step = _iterator()).done;){
431
+ var meshInfo = _step.value;
432
+ var mesh = meshInfo.mesh;
433
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
434
+ var bufferRestoreInfo = _step1.value;
435
+ var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
436
+ bufferRestoreInfo.buffer.setData(vertexData);
437
+ }
438
+ if (meshInfo.indexBuffer) {
439
+ var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
440
+ mesh.setIndices(indexData);
441
+ }
442
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
443
+ var restoreInfo = _step2.value;
444
+ var frame = restoreInfo.blendShape.frames[0];
445
+ var positionData = _this._getBufferData(buffers, restoreInfo.position);
446
+ frame.deltaPositions = GLTFUtils.floatBufferToVector3Array(positionData);
447
+ if (restoreInfo.normal) {
448
+ var normalData = _this._getBufferData(buffers, restoreInfo.normal);
449
+ frame.deltaNormals = GLTFUtils.floatBufferToVector3Array(normalData);
450
+ }
451
+ if (restoreInfo.tangent) {
452
+ var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
453
+ frame.deltaTangents = GLTFUtils.floatBufferToVector3Array(tangentData);
454
+ }
455
+ }
456
+ mesh.uploadData(true);
457
+ }
458
+ resolve(_this.resource);
459
+ }).catch(reject);
460
+ }).catch(reject);
374
461
  });
375
- promiseInfo.promise = promise;
376
- return promise;
377
462
  };
378
- return ParserContext;
379
- }();
463
+ _proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
464
+ var main = restoreInfo.main;
465
+ var buffer = buffers[main.bufferIndex];
466
+ var data = new main.TypedArray(buffer, main.byteOffset, main.length);
467
+ var sparseCount = restoreInfo.sparseCount;
468
+ if (sparseCount) {
469
+ var sparseIndex = restoreInfo.sparseIndices;
470
+ var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
471
+ var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
472
+ var sparseValue = restoreInfo.sparseValues;
473
+ var sparseValueBuffer = buffers[sparseValue.bufferIndex];
474
+ var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
475
+ var typeSize = restoreInfo.typeSize;
476
+ for(var i = 0; i < sparseCount; i++){
477
+ var replaceIndex = sparseIndexData[i];
478
+ for(var j = 0; j < typeSize; j++){
479
+ data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
480
+ }
481
+ }
482
+ }
483
+ return data;
484
+ };
485
+ return GLTFContentRestorer;
486
+ }(miniprogram.ContentRestorer);
380
487
  /**
381
488
  * @internal
382
- */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
489
+ */ var BufferRequestInfo = function BufferRequestInfo(url, config) {
490
+ this.url = url;
491
+ this.config = config;
492
+ };
493
+ /**
494
+ * @internal
495
+ */ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
496
+ this.texture = texture;
497
+ this.bufferView = bufferView;
498
+ this.mimeType = mimeType;
499
+ };
500
+ /**
501
+ * @internal
502
+ */ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
503
+ this.vertexBuffers = [];
504
+ this.blendShapes = [];
505
+ };
506
+ /**
507
+ * @internal
508
+ */ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
509
+ this.buffer = buffer;
383
510
  this.data = data;
384
- this.interleaved = interleaved;
385
- this.stride = stride;
386
- this.vertexBindingInfos = {};
387
511
  };
388
512
  /**
389
513
  * @internal
390
- */ var PromiseInfo = function PromiseInfo() {
514
+ */ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
515
+ this.main = main;
516
+ this.typeSize = typeSize;
517
+ this.sparseCount = sparseCount;
518
+ this.sparseIndices = sparseIndices;
519
+ this.sparseValues = sparseValues;
520
+ };
521
+ /**
522
+ * @internal
523
+ */ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
524
+ this.bufferIndex = bufferIndex;
525
+ this.TypedArray = TypedArray;
526
+ this.byteOffset = byteOffset;
527
+ this.length = length;
528
+ };
529
+ /**
530
+ * @internal
531
+ */ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
532
+ this.blendShape = blendShape;
533
+ this.position = position;
534
+ this.normal = normal;
535
+ this.tangent = tangent;
391
536
  };
392
537
 
393
538
  /**
@@ -539,9 +684,57 @@ var TextureWrapMode;
539
684
 
540
685
  /**
541
686
  * @internal
542
- */ var GLTFUtil = /*#__PURE__*/ function() {
543
- function GLTFUtil() {}
544
- GLTFUtil.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
687
+ */ var GLTFParserContext = /*#__PURE__*/ function() {
688
+ function GLTFParserContext(url) {
689
+ this.hasSkinned = false;
690
+ this.chainPromises = [];
691
+ this.accessorBufferCache = {};
692
+ this.texturesPromiseInfo = new PromiseInfo();
693
+ this.materialsPromiseInfo = new PromiseInfo();
694
+ this.meshesPromiseInfo = new PromiseInfo();
695
+ this.animationClipsPromiseInfo = new PromiseInfo();
696
+ this.defaultSceneRootPromiseInfo = new PromiseInfo();
697
+ this.masterPromiseInfo = new PromiseInfo();
698
+ this.promiseMap = {};
699
+ var promiseMap = this.promiseMap;
700
+ promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
701
+ promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
702
+ promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
703
+ promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
704
+ promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
705
+ promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
706
+ }
707
+ var _proto = GLTFParserContext.prototype;
708
+ _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
709
+ var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
710
+ promiseInfo.resolve = resolve;
711
+ promiseInfo.reject = reject;
712
+ promiseInfo.setProgress = setProgress;
713
+ promiseInfo.onCancel = onCancel;
714
+ });
715
+ promiseInfo.promise = promise;
716
+ return promise;
717
+ };
718
+ return GLTFParserContext;
719
+ }();
720
+ /**
721
+ * @internal
722
+ */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
723
+ this.data = data;
724
+ this.interleaved = interleaved;
725
+ this.stride = stride;
726
+ this.vertexBindingInfos = {};
727
+ };
728
+ /**
729
+ * @internal
730
+ */ var PromiseInfo = function PromiseInfo() {
731
+ };
732
+
733
+ /**
734
+ * @internal
735
+ */ var GLTFUtils = /*#__PURE__*/ function() {
736
+ function GLTFUtils() {}
737
+ GLTFUtils.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
545
738
  var bufferLen = buffer.length;
546
739
  var array = new Array(bufferLen / 2);
547
740
  for(var i = 0; i < bufferLen; i += 2){
@@ -549,7 +742,7 @@ var TextureWrapMode;
549
742
  }
550
743
  return array;
551
744
  };
552
- GLTFUtil.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
745
+ GLTFUtils.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
553
746
  var bufferLen = buffer.length;
554
747
  var array = new Array(bufferLen / 3);
555
748
  for(var i = 0; i < bufferLen; i += 3){
@@ -557,7 +750,7 @@ var TextureWrapMode;
557
750
  }
558
751
  return array;
559
752
  };
560
- GLTFUtil.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
753
+ GLTFUtils.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
561
754
  var bufferLen = buffer.length;
562
755
  var array = new Array(bufferLen / 4);
563
756
  for(var i = 0; i < bufferLen; i += 4){
@@ -565,7 +758,7 @@ var TextureWrapMode;
565
758
  }
566
759
  return array;
567
760
  };
568
- GLTFUtil.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
761
+ GLTFUtils.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
569
762
  var bufferLen = buffer.length;
570
763
  var colors = new Array(bufferLen / (isColor3 ? 3 : 4));
571
764
  if (isColor3) {
@@ -580,21 +773,8 @@ var TextureWrapMode;
580
773
  return colors;
581
774
  };
582
775
  /**
583
- * Parse binary text for glb loader.
584
- */ GLTFUtil.decodeText = function decodeText(array) {
585
- if (typeof TextDecoder !== "undefined") {
586
- return new TextDecoder().decode(array);
587
- }
588
- // TextDecoder polyfill
589
- var s = "";
590
- for(var i = 0, il = array.length; i < il; i++){
591
- s += String.fromCharCode(array[i]);
592
- }
593
- return decodeURIComponent(encodeURIComponent(s));
594
- };
595
- /**
596
776
  * Get the number of bytes occupied by accessor type.
597
- */ GLTFUtil.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
777
+ */ GLTFUtils.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
598
778
  switch(accessorType){
599
779
  case AccessorType.SCALAR:
600
780
  return 1;
@@ -614,7 +794,7 @@ var TextureWrapMode;
614
794
  };
615
795
  /**
616
796
  * Get the TypedArray corresponding to the component type.
617
- */ GLTFUtil.getComponentType = function getComponentType(componentType) {
797
+ */ GLTFUtils.getComponentType = function getComponentType(componentType) {
618
798
  switch(componentType){
619
799
  case AccessorComponentType.BYTE:
620
800
  return Int8Array;
@@ -630,7 +810,7 @@ var TextureWrapMode;
630
810
  return Float32Array;
631
811
  }
632
812
  };
633
- GLTFUtil.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
813
+ GLTFUtils.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
634
814
  // Reference: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
635
815
  switch(componentType){
636
816
  case AccessorComponentType.BYTE:
@@ -645,18 +825,18 @@ var TextureWrapMode;
645
825
  throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
646
826
  }
647
827
  };
648
- GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
828
+ GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
649
829
  var buffers = context.buffers;
650
- var bufferViews = gltf.bufferViews;
651
830
  var componentType = accessor.componentType;
652
831
  var bufferView = bufferViews[accessor.bufferView];
653
- var buffer = buffers[bufferView.buffer];
832
+ var bufferIndex = bufferView.buffer;
833
+ var buffer = buffers[bufferIndex];
654
834
  var bufferByteOffset = bufferView.byteOffset || 0;
655
835
  var byteOffset = accessor.byteOffset || 0;
656
- var TypedArray = GLTFUtil.getComponentType(componentType);
657
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
836
+ var TypedArray = GLTFUtils.getComponentType(componentType);
837
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
658
838
  var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
659
- var elementStride = dataElmentSize * dataElementBytes;
839
+ var elementStride = dataElementSize * dataElementBytes;
660
840
  var accessorCount = accessor.count;
661
841
  var bufferStride = bufferView.byteStride;
662
842
  var bufferInfo;
@@ -671,34 +851,35 @@ var TextureWrapMode;
671
851
  var count = accessorCount * (bufferStride / dataElementBytes);
672
852
  var data = new TypedArray(buffer, offset, count);
673
853
  accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
854
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
674
855
  }
675
856
  } else {
676
857
  var offset1 = bufferByteOffset + byteOffset;
677
- var count1 = accessorCount * dataElmentSize;
858
+ var count1 = accessorCount * dataElementSize;
678
859
  var data1 = new TypedArray(buffer, offset1, count1);
679
860
  bufferInfo = new BufferInfo(data1, false, elementStride);
861
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
680
862
  }
681
863
  if (accessor.sparse) {
682
- var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
683
- bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
864
+ GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
684
865
  }
685
866
  return bufferInfo;
686
867
  };
687
868
  /**
688
869
  * @deprecated
689
870
  * Get accessor data.
690
- */ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
691
- var bufferViews = gltf.bufferViews;
871
+ */ GLTFUtils.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
872
+ var bufferViews = glTF.bufferViews;
692
873
  var bufferView = bufferViews[accessor.bufferView];
693
874
  var arrayBuffer = buffers[bufferView.buffer];
694
875
  var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
695
876
  var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
696
877
  var byteOffset = accessorByteOffset + bufferViewByteOffset;
697
- var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
878
+ var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
698
879
  var length = accessorTypeSize * accessor.count;
699
880
  var _bufferView_byteStride;
700
881
  var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
701
- var arrayType = GLTFUtil.getComponentType(accessor.componentType);
882
+ var arrayType = GLTFUtils.getComponentType(accessor.componentType);
702
883
  var uint8Array;
703
884
  if (byteStride) {
704
885
  var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
@@ -725,7 +906,7 @@ var TextureWrapMode;
725
906
  var _values_byteOffset, _valuesBufferView_byteOffset;
726
907
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
727
908
  var valuesByteLength = valuesBufferView.byteLength;
728
- var indicesType = GLTFUtil.getComponentType(indices.componentType);
909
+ var indicesType = GLTFUtils.getComponentType(indices.componentType);
729
910
  var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
730
911
  var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
731
912
  for(var i1 = 0; i1 < count; i1++){
@@ -737,41 +918,49 @@ var TextureWrapMode;
737
918
  }
738
919
  return typedArray;
739
920
  };
740
- GLTFUtil.getBufferViewData = function getBufferViewData(bufferView, buffers) {
741
- var buffer = bufferView.buffer, _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset, byteLength = bufferView.byteLength;
742
- var arrayBuffer = buffers[buffer];
743
- return arrayBuffer.slice(byteOffset, byteOffset + byteLength);
921
+ GLTFUtils.getBufferViewData = function getBufferViewData(bufferView, buffers) {
922
+ var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
923
+ var arrayBuffer = buffers[bufferView.buffer];
924
+ return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
744
925
  };
745
926
  /**
746
927
  * Get accessor data.
747
- */ GLTFUtil.processingSparseData = function processingSparseData(gltf, accessor, buffers, originData) {
748
- var bufferViews = gltf.bufferViews;
749
- var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
750
- var TypedArray = GLTFUtil.getComponentType(accessor.componentType);
751
- var data = originData.slice();
928
+ */ GLTFUtils.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
929
+ var restoreInfo = bufferInfo.restoreInfo;
930
+ var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
931
+ var TypedArray = GLTFUtils.getComponentType(accessor.componentType);
932
+ var data = bufferInfo.data.slice();
752
933
  var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
753
934
  var indicesBufferView = bufferViews[indices.bufferView];
754
935
  var valuesBufferView = bufferViews[values.bufferView];
755
- var indicesArrayBuffer = buffers[indicesBufferView.buffer];
756
- var valuesArrayBuffer = buffers[valuesBufferView.buffer];
936
+ var indicesBufferIndex = indicesBufferView.buffer;
937
+ var valuesBufferIndex = valuesBufferView.buffer;
938
+ var indicesArrayBuffer = buffers[indicesBufferIndex];
939
+ var valuesArrayBuffer = buffers[valuesBufferIndex];
757
940
  var _indices_byteOffset, _indicesBufferView_byteOffset;
758
941
  var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
759
942
  var indicesByteLength = indicesBufferView.byteLength;
760
943
  var _values_byteOffset, _valuesBufferView_byteOffset;
761
944
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
762
945
  var valuesByteLength = valuesBufferView.byteLength;
763
- var IndexTypeArray = GLTFUtil.getComponentType(indices.componentType);
764
- var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT);
765
- var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valuesByteLength / TypedArray.BYTES_PER_ELEMENT);
946
+ restoreInfo.typeSize = accessorTypeSize;
947
+ restoreInfo.sparseCount = count;
948
+ var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
949
+ var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
950
+ var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
951
+ restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
952
+ var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
953
+ var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
954
+ restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
766
955
  for(var i = 0; i < count; i++){
767
956
  var replaceIndex = indicesArray[i];
768
957
  for(var j = 0; j < accessorTypeSize; j++){
769
958
  data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
770
959
  }
771
960
  }
772
- return data;
961
+ bufferInfo.data = data;
773
962
  };
774
- GLTFUtil.getIndexFormat = function getIndexFormat(type) {
963
+ GLTFUtils.getIndexFormat = function getIndexFormat(type) {
775
964
  switch(type){
776
965
  case AccessorComponentType.UNSIGNED_BYTE:
777
966
  return miniprogram.IndexFormat.UInt8;
@@ -781,7 +970,7 @@ var TextureWrapMode;
781
970
  return miniprogram.IndexFormat.UInt32;
782
971
  }
783
972
  };
784
- GLTFUtil.getElementFormat = function getElementFormat(type, size, normalized) {
973
+ GLTFUtils.getElementFormat = function getElementFormat(type, size, normalized) {
785
974
  if (normalized === void 0) normalized = false;
786
975
  if (type == AccessorComponentType.FLOAT) {
787
976
  switch(size){
@@ -832,7 +1021,7 @@ var TextureWrapMode;
832
1021
  };
833
1022
  /**
834
1023
  * Load image buffer
835
- */ GLTFUtil.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
1024
+ */ GLTFUtils.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
836
1025
  return new Promise(function(resolve, reject) {
837
1026
  var blob = new engineMiniprogramAdapter.window.Blob([
838
1027
  imageBuffer
@@ -856,18 +1045,9 @@ var TextureWrapMode;
856
1045
  img.src = engineMiniprogramAdapter.URL.createObjectURL(blob);
857
1046
  });
858
1047
  };
859
- GLTFUtil.isAbsoluteUrl = function isAbsoluteUrl(url) {
860
- return /^(?:http|blob|data:|\/)/.test(url);
861
- };
862
- GLTFUtil.parseRelativeUrl = function parseRelativeUrl(baseUrl, relativeUrl) {
863
- if (GLTFUtil.isAbsoluteUrl(relativeUrl)) {
864
- return relativeUrl;
865
- }
866
- return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + GLTFUtil._formatRelativePath(relativeUrl);
867
- };
868
1048
  /**
869
1049
  * Parse the glb format.
870
- */ GLTFUtil.parseGLB = function parseGLB(glb) {
1050
+ */ GLTFUtils.parseGLB = function parseGLB(context, glb) {
871
1051
  var UINT32_LENGTH = 4;
872
1052
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
873
1053
  var GLB_HEADER_LENGTH = 12;
@@ -895,10 +1075,11 @@ var TextureWrapMode;
895
1075
  return null;
896
1076
  }
897
1077
  var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
898
- var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
1078
+ var glTF = JSON.parse(miniprogram.Utils.decodeText(glTFData));
899
1079
  // read all buffers
900
1080
  var buffers = [];
901
1081
  var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
1082
+ var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
902
1083
  while(byteOffset < header.length){
903
1084
  chunkLength = dataView.getUint32(byteOffset, true);
904
1085
  chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
@@ -909,14 +1090,15 @@ var TextureWrapMode;
909
1090
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
910
1091
  var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
911
1092
  buffers.push(buffer);
1093
+ restoreGLBBufferSlice.push(new miniprogram$1.Vector2(currentOffset, chunkLength));
912
1094
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
913
1095
  }
914
1096
  return {
915
- gltf: gltf,
1097
+ glTF: glTF,
916
1098
  buffers: buffers
917
1099
  };
918
1100
  };
919
- GLTFUtil._formatRelativePath = function _formatRelativePath(path) {
1101
+ GLTFUtils._formatRelativePath = function _formatRelativePath(path) {
920
1102
  // For example input is "a/b", "/a/b", "./a/b", "./a/./b", "./a/../a/b", output is "a/b"
921
1103
  return path.split("/").filter(Boolean).reduce(function(acc, cur) {
922
1104
  if (cur === "..") acc.pop();
@@ -924,17 +1106,9 @@ var TextureWrapMode;
924
1106
  return acc;
925
1107
  }, []).join("/");
926
1108
  };
927
- return GLTFUtil;
1109
+ return GLTFUtils;
928
1110
  }();
929
1111
 
930
- function _array_like_to_array(arr, len) {
931
- if (len == null || len > arr.length) len = arr.length;
932
-
933
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
934
-
935
- return arr2;
936
- }
937
-
938
1112
  function _array_without_holes(arr) {
939
1113
  if (Array.isArray(arr)) return _array_like_to_array(arr);
940
1114
  }
@@ -949,606 +1123,327 @@ function _non_iterable_spread() {
949
1123
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
950
1124
  }
951
1125
 
952
- function _unsupported_iterable_to_array(o, minLen) {
953
- if (!o) return;
954
- if (typeof o === "string") return _array_like_to_array(o, minLen);
955
-
956
- var n = Object.prototype.toString.call(o).slice(8, -1);
957
-
958
- if (n === "Object" && o.constructor) n = o.constructor.name;
959
- if (n === "Map" || n === "Set") return Array.from(n);
960
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
961
- }
962
-
963
1126
  function _to_consumable_array(arr) {
964
1127
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
965
1128
  }
966
1129
 
967
- var Parser = /*#__PURE__*/ function() {
968
- function Parser() {}
969
- Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
1130
+ /**
1131
+ * Base class of glTF extension parser.
1132
+ */ var GLTFExtensionParser = /*#__PURE__*/ function() {
1133
+ function GLTFExtensionParser() {}
1134
+ var _proto = GLTFExtensionParser.prototype;
1135
+ /**
1136
+ * Initialize the parser.
1137
+ * @remarks Some plugins require initialization.
1138
+ * @returns The void or promise
1139
+ */ _proto.initialize = function initialize() {};
1140
+ /**
1141
+ * Create and parse the resource.
1142
+ * @remarks This method overrides the default resource creation.
1143
+ * @param context - The parser context
1144
+ * @param extensionSchema - The extension schema
1145
+ * @param extensionOwnerSchema - The extension owner schema
1146
+ * @returns The resource or promise
1147
+ */ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
1148
+ for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1149
+ extra[_key - 3] = arguments[_key];
1150
+ }
1151
+ throw "Not implemented.";
1152
+ };
1153
+ /**
1154
+ * Additive parse to the resource.
1155
+ * @param context - The parser context
1156
+ * @param parseResource - The parsed resource
1157
+ * @param extensionSchema - The extension schema
1158
+ * @param extensionOwnerSchema - The extension owner schema
1159
+ * @returns The void or promise
1160
+ */ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
970
1161
  for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
971
1162
  extra[_key - 4] = arguments[_key];
972
1163
  }
973
- var parsers = Parser._extensionParsers[extensionName];
974
- if (parsers == null ? void 0 : parsers.length) {
975
- for(var i = 0; i < parsers.length; i++){
976
- var _parsers_i;
977
- (_parsers_i = parsers[i]).parseEngineResource.apply(_parsers_i, [
978
- extensionSchema,
979
- parseResource,
980
- context
981
- ].concat(_to_consumable_array(extra)));
982
- }
1164
+ throw "Not implemented.";
1165
+ };
1166
+ return GLTFExtensionParser;
1167
+ }();
1168
+ exports.GLTFExtensionMode = void 0;
1169
+ (function(GLTFExtensionMode) {
1170
+ GLTFExtensionMode[GLTFExtensionMode[/**
1171
+ * Cerate instance and parse mode.
1172
+ * @remarks
1173
+ * If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
1174
+ * If this method is registered, the default pipeline processing will be ignored.
1175
+ */ "CreateAndParse"] = 0] = "CreateAndParse";
1176
+ GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
1177
+ })(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
1178
+
1179
+ /**
1180
+ * Base class of glTF parser.
1181
+ */ var GLTFParser = /*#__PURE__*/ function() {
1182
+ function GLTFParser() {}
1183
+ /**
1184
+ * Execute all parses of extension to initialize plugin.
1185
+ * @remarks Some plugins require initialization.
1186
+ * @returns The void or promise
1187
+ */ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
1188
+ var parsers = GLTFParser._extensionParsers[extensionName];
1189
+ var length = parsers == null ? void 0 : parsers.length;
1190
+ if (length) {
1191
+ return parsers[length - 1].initialize();
983
1192
  }
984
1193
  };
985
- Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
1194
+ /**
1195
+ * Execute all parses of extension to create resource.
1196
+ * @param extensions - Related extensions field
1197
+ * @param context - The parser context
1198
+ * @param ownerSchema - The extension owner schema
1199
+ * @param extra - Extra params
1200
+ * @returns
1201
+ */ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
1202
+ if (extensions === void 0) extensions = {};
986
1203
  for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
987
1204
  extra[_key - 3] = arguments[_key];
988
1205
  }
989
- var parsers = Parser._extensionParsers[extensionName];
990
- if (parsers == null ? void 0 : parsers.length) {
991
- var _parsers_;
992
- return (_parsers_ = parsers[0]).createEngineResource.apply(_parsers_, [
1206
+ var resource = null;
1207
+ var extensionArray = Object.keys(extensions);
1208
+ for(var i = extensionArray.length - 1; i >= 0; --i){
1209
+ var _GLTFParser;
1210
+ var extensionName = extensionArray[i];
1211
+ var extensionSchema = extensions[extensionName];
1212
+ resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
1213
+ extensionName,
1214
+ context,
1215
+ extensionSchema,
1216
+ ownerSchema
1217
+ ].concat(_to_consumable_array(extra)));
1218
+ if (resource) {
1219
+ return resource;
1220
+ }
1221
+ }
1222
+ };
1223
+ /**
1224
+ * Execute all parses of extension to parse resource.
1225
+ * @param extensions - Related extensions field
1226
+ * @param context - The parser context
1227
+ * @param parseResource - The parsed resource
1228
+ * @param ownerSchema - The extension owner schema
1229
+ * @param extra - Extra params
1230
+ */ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
1231
+ for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1232
+ extra[_key - 4] = arguments[_key];
1233
+ }
1234
+ for(var extensionName in extensions){
1235
+ var _GLTFParser;
1236
+ var extensionSchema = extensions[extensionName];
1237
+ (_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
1238
+ extensionName,
1239
+ context,
1240
+ parseResource,
993
1241
  extensionSchema,
994
- context
1242
+ ownerSchema
995
1243
  ].concat(_to_consumable_array(extra)));
996
1244
  }
997
1245
  };
998
- Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
999
- var parsers = Parser._extensionParsers[extensionName];
1000
- return !!(parsers == null ? void 0 : parsers.length);
1246
+ /**
1247
+ * Whether the plugin is registered.
1248
+ * @param extensionName - Extension name
1249
+ * @returns Boolean
1250
+ */ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
1251
+ var _GLTFParser__extensionParsers_extensionName;
1252
+ return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
1001
1253
  };
1002
- Parser.initialize = function initialize(extensionName) {
1003
- var parsers = Parser._extensionParsers[extensionName];
1004
- if (parsers == null ? void 0 : parsers.length) {
1005
- for(var i = 0; i < parsers.length; i++){
1006
- parsers[i].initialize();
1254
+ /**
1255
+ * Get the last plugin by glTF extension mode.
1256
+ * @param extensionName - Extension name
1257
+ * @param mode - GLTF extension mode
1258
+ * @returns GLTF extension parser
1259
+ */ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
1260
+ var parsers = GLTFParser._extensionParsers[extensionName];
1261
+ var length = parsers == null ? void 0 : parsers.length;
1262
+ if (length) {
1263
+ // only use the last parser.
1264
+ for(var i = length - 1; i >= 0; --i){
1265
+ var currentParser = parsers[i];
1266
+ if (currentParser._mode === mode) {
1267
+ return currentParser;
1268
+ }
1007
1269
  }
1008
1270
  }
1009
1271
  };
1010
1272
  /**
1011
1273
  * @internal
1012
- */ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1013
- if (!Parser._extensionParsers[extensionName]) {
1014
- Parser._extensionParsers[extensionName] = [];
1274
+ */ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1275
+ if (!GLTFParser._extensionParsers[extensionName]) {
1276
+ GLTFParser._extensionParsers[extensionName] = [];
1277
+ }
1278
+ GLTFParser._extensionParsers[extensionName].push(extensionParser);
1279
+ };
1280
+ GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
1281
+ for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1282
+ extra[_key - 4] = arguments[_key];
1283
+ }
1284
+ var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
1285
+ if (parser) {
1286
+ var _parser;
1287
+ return (_parser = parser).createAndParse.apply(_parser, [
1288
+ context,
1289
+ extensionSchema,
1290
+ ownerSchema
1291
+ ].concat(_to_consumable_array(extra)));
1292
+ }
1293
+ };
1294
+ GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
1295
+ for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
1296
+ extra[_key - 5] = arguments[_key];
1297
+ }
1298
+ var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
1299
+ if (parser) {
1300
+ var _parser;
1301
+ (_parser = parser).additiveParse.apply(_parser, [
1302
+ context,
1303
+ parseResource,
1304
+ extensionSchema,
1305
+ ownerSchema
1306
+ ].concat(_to_consumable_array(extra)));
1015
1307
  }
1016
- Parser._extensionParsers[extensionName].push(extensionParser);
1017
1308
  };
1018
- return Parser;
1309
+ return GLTFParser;
1019
1310
  }();
1020
1311
  (function() {
1021
- Parser._extensionParsers = {};
1312
+ GLTFParser._extensionParsers = {};
1022
1313
  })();
1023
1314
  /**
1024
1315
  * Declare ExtensionParser's decorator.
1025
1316
  * @param extensionName - Extension name
1026
- */ function registerExtension(extensionName) {
1317
+ */ function registerGLTFExtension(extensionName, mode) {
1027
1318
  return function(parser) {
1028
1319
  var extensionParser = new parser();
1029
- Parser._addExtensionParser(extensionName, extensionParser);
1320
+ extensionParser._mode = mode;
1321
+ GLTFParser._addExtensionParser(extensionName, extensionParser);
1030
1322
  };
1031
1323
  }
1032
1324
 
1033
- var ExtensionParser = /*#__PURE__*/ function() {
1034
- function ExtensionParser() {}
1035
- var _proto = ExtensionParser.prototype;
1036
- _proto.initialize = function initialize() {};
1037
- _proto.parseEngineResource = function parseEngineResource(schema, parseResource, context) {
1038
- for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1039
- extra[_key - 3] = arguments[_key];
1040
- }
1041
- };
1042
- _proto.createEngineResource = function createEngineResource(schema, context) {
1043
- for(var _len = arguments.length, extra = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
1044
- extra[_key - 2] = arguments[_key];
1045
- }
1046
- return null;
1047
- };
1048
- return ExtensionParser;
1049
- }();
1050
-
1051
- var KHR_draco_mesh_compression = /*#__PURE__*/ function(ExtensionParser) {
1052
- _inherits(KHR_draco_mesh_compression1, ExtensionParser);
1053
- function KHR_draco_mesh_compression1() {
1054
- return ExtensionParser.apply(this, arguments);
1325
+ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1326
+ _inherits(GLTFAnimationParser, GLTFParser1);
1327
+ function GLTFAnimationParser() {
1328
+ return GLTFParser1.apply(this, arguments);
1055
1329
  }
1056
- var _proto = KHR_draco_mesh_compression1.prototype;
1057
- _proto.initialize = function initialize() {
1058
- if (!KHR_draco_mesh_compression._decoder) {
1059
- KHR_draco_mesh_compression._decoder = new miniprogram$2.DRACODecoder();
1060
- }
1061
- };
1062
- _proto.createEngineResource = function createEngineResource(schema, context, gltfPrimitive) {
1063
- var gltf = context.gltf, buffers = context.buffers;
1064
- var bufferViews = gltf.bufferViews, accessors = gltf.accessors;
1065
- var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
1066
- var attributeMap = {};
1067
- var attributeTypeMap = {};
1068
- for(var attributeName in gltfAttributeMap){
1069
- attributeMap[attributeName] = gltfAttributeMap[attributeName];
1330
+ var _proto = GLTFAnimationParser.prototype;
1331
+ _proto.parse = function parse(context) {
1332
+ var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
1333
+ glTFResource.entities;
1334
+ var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
1335
+ if (!animations) {
1336
+ return;
1070
1337
  }
1071
- for(var attributeName1 in gltfPrimitive.attributes){
1072
- if (gltfAttributeMap[attributeName1] !== undefined) {
1073
- var accessorDef = accessors[gltfPrimitive.attributes[attributeName1]];
1074
- attributeTypeMap[attributeName1] = GLTFUtil.getComponentType(accessorDef.componentType).name;
1338
+ var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1339
+ var animationClipCount = animations.length;
1340
+ var animationClipPromises = [];
1341
+ new Array(animationClipCount);
1342
+ for(var i = 0; i < animationClipCount; i++){
1343
+ var animationInfo = animations[i];
1344
+ var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
1345
+ var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
1346
+ if (!animationClip) {
1347
+ animationClip = new miniprogram.AnimationClip(name);
1348
+ GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
1075
1349
  }
1350
+ animationClipPromises.push(animationClip);
1076
1351
  }
1077
- var indexAccessor = accessors[gltfPrimitive.indices];
1078
- var indexType = GLTFUtil.getComponentType(indexAccessor.componentType).name;
1079
- var taskConfig = {
1080
- attributeIDs: attributeMap,
1081
- attributeTypes: attributeTypeMap,
1082
- useUniqueIDs: true,
1083
- indexType: indexType
1084
- };
1085
- var buffer = GLTFUtil.getBufferViewData(bufferViews[bufferViewIndex], buffers);
1086
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(parsedGeometry) {
1087
- return parsedGeometry;
1352
+ return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1353
+ glTFResource.animations = animationClips;
1354
+ for(var i = 0; i < glTF.animations.length; i++){
1355
+ var animationInfo = glTF.animations[i];
1356
+ GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
1357
+ }
1358
+ animationClipsPromiseInfo.resolve(animationClips);
1359
+ return animationClipsPromiseInfo.promise;
1088
1360
  });
1089
1361
  };
1090
- return KHR_draco_mesh_compression1;
1091
- }(ExtensionParser);
1092
- KHR_draco_mesh_compression = __decorate([
1093
- registerExtension("KHR_draco_mesh_compression")
1094
- ], KHR_draco_mesh_compression);
1095
-
1096
- function _instanceof(left, right) {
1097
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1098
- return !!right[Symbol.hasInstance](left);
1099
- } else return left instanceof right;
1100
- }
1101
-
1102
- var KHR_lights_punctual = /*#__PURE__*/ function(ExtensionParser) {
1103
- _inherits(KHR_lights_punctual, ExtensionParser);
1104
- function KHR_lights_punctual() {
1105
- return ExtensionParser.apply(this, arguments);
1106
- }
1107
- var _proto = KHR_lights_punctual.prototype;
1108
- _proto.parseEngineResource = function parseEngineResource(schema, entity, context) {
1109
- 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;
1110
- var glTFResource = context.glTFResource;
1111
- var light;
1112
- if (type === "directional") {
1113
- light = entity.addComponent(miniprogram.DirectLight);
1114
- } else if (type === "point") {
1115
- light = entity.addComponent(miniprogram.PointLight);
1116
- } else if (type === "spot") {
1117
- light = entity.addComponent(miniprogram.SpotLight);
1118
- }
1119
- if (color) {
1120
- light.color.set(color[0], color[1], color[2], 1);
1121
- }
1122
- light.intensity = intensity;
1123
- if (range && !_instanceof(light, miniprogram.DirectLight)) {
1124
- light.distance = range;
1125
- }
1126
- if (spot && _instanceof(light, miniprogram.SpotLight)) {
1127
- 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;
1128
- light.angle = innerConeAngle;
1129
- light.penumbra = outerConeAngle - innerConeAngle;
1130
- }
1131
- if (!glTFResource.lights) glTFResource.lights = [];
1132
- glTFResource.lights.push(light);
1133
- };
1134
- return KHR_lights_punctual;
1135
- }(ExtensionParser);
1136
- KHR_lights_punctual = __decorate([
1137
- registerExtension("KHR_lights_punctual")
1138
- ], KHR_lights_punctual);
1139
-
1140
- var MaterialParser = /*#__PURE__*/ function(Parser1) {
1141
- _inherits(MaterialParser, Parser1);
1142
- function MaterialParser() {
1143
- return Parser1.apply(this, arguments);
1144
- }
1145
- var _proto = MaterialParser.prototype;
1146
- _proto.parse = function parse(context) {
1147
- var gltf = context.gltf, glTFResource = context.glTFResource;
1148
- var engine = glTFResource.engine, textures = glTFResource.textures;
1149
- if (!gltf.materials) return;
1150
- var materialsPromiseInfo = context.materialsPromiseInfo;
1151
- var materials = [];
1152
- for(var i = 0; i < gltf.materials.length; i++){
1153
- 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;
1154
- 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;
1155
- var material = null;
1156
- if (KHR_materials_unlit) {
1157
- material = Parser.createEngineResource("KHR_materials_unlit", KHR_materials_unlit, context);
1158
- } else if (KHR_materials_pbrSpecularGlossiness) {
1159
- material = Parser.createEngineResource("KHR_materials_pbrSpecularGlossiness", KHR_materials_pbrSpecularGlossiness, context);
1160
- } else {
1161
- material = new miniprogram.PBRMaterial(engine);
1162
- }
1163
- material.name = name;
1164
- if (KHR_materials_clearcoat) {
1165
- Parser.parseEngineResource("KHR_materials_clearcoat", KHR_materials_clearcoat, material, context);
1166
- }
1167
- if (pbrMetallicRoughness) {
1168
- var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1169
- if (baseColorFactor) {
1170
- 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]);
1171
- }
1172
- if (baseColorTexture) {
1173
- material.baseTexture = textures[baseColorTexture.index];
1174
- MaterialParser._parseTextureTransform(material, baseColorTexture.extensions, context);
1175
- }
1176
- if (!KHR_materials_unlit && !KHR_materials_pbrSpecularGlossiness) {
1177
- var m = material;
1178
- m.metallic = metallicFactor != null ? metallicFactor : 1;
1179
- m.roughness = roughnessFactor != null ? roughnessFactor : 1;
1180
- if (metallicRoughnessTexture) {
1181
- m.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1182
- MaterialParser._parseTextureTransform(material, metallicRoughnessTexture.extensions, context);
1183
- }
1184
- }
1185
- }
1186
- if (!KHR_materials_unlit) {
1187
- var m1 = material;
1188
- if (emissiveTexture) {
1189
- m1.emissiveTexture = textures[emissiveTexture.index];
1190
- MaterialParser._parseTextureTransform(material, emissiveTexture.extensions, context);
1191
- }
1192
- if (emissiveFactor) {
1193
- m1.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
1194
- }
1195
- if (normalTexture) {
1196
- var index = normalTexture.index, scale = normalTexture.scale;
1197
- m1.normalTexture = textures[index];
1198
- MaterialParser._parseTextureTransform(material, normalTexture.extensions, context);
1199
- if (scale !== undefined) {
1200
- m1.normalTextureIntensity = scale;
1201
- }
1202
- }
1203
- if (occlusionTexture) {
1204
- var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1205
- m1.occlusionTexture = textures[index1];
1206
- MaterialParser._parseTextureTransform(material, occlusionTexture.extensions, context);
1207
- if (strength !== undefined) {
1208
- m1.occlusionTextureIntensity = strength;
1209
- }
1210
- if (texCoord === miniprogram.TextureCoordinate.UV1) {
1211
- m1.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
1212
- } else if (texCoord > miniprogram.TextureCoordinate.UV1) {
1213
- miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1214
- }
1362
+ /**
1363
+ * @internal
1364
+ */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
1365
+ var glTF = context.glTF, glTFResource = context.glTFResource;
1366
+ var entities = glTFResource.entities;
1367
+ var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
1368
+ var channels = animationInfo.channels, samplers = animationInfo.samplers;
1369
+ var sampleDataCollection = new Array();
1370
+ // parse samplers
1371
+ for(var j = 0, m = samplers.length; j < m; j++){
1372
+ var gltfSampler = samplers[j];
1373
+ var inputAccessor = accessors[gltfSampler.input];
1374
+ var outputAccessor = accessors[gltfSampler.output];
1375
+ var input = GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor).data;
1376
+ var output = GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor).data;
1377
+ if (outputAccessor.normalized) {
1378
+ var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
1379
+ var scaled = new Float32Array(output.length);
1380
+ for(var k = 0, v = output.length; k < v; k++){
1381
+ scaled[k] = output[k] * scale;
1215
1382
  }
1383
+ output = scaled;
1216
1384
  }
1217
- if (OASIS_materials_remap) {
1218
- var _gltf_extensions;
1219
- gltf.extensions = (_gltf_extensions = gltf.extensions) != null ? _gltf_extensions : {};
1220
- var _gltf_extensions_OASIS_materials_remap;
1221
- gltf.extensions["OASIS_materials_remap"] = (_gltf_extensions_OASIS_materials_remap = gltf.extensions["OASIS_materials_remap"]) != null ? _gltf_extensions_OASIS_materials_remap : {};
1222
- gltf.extensions["OASIS_materials_remap"][i] = Parser.createEngineResource("OASIS_materials_remap", OASIS_materials_remap, context);
1223
- }
1224
- if (doubleSided) {
1225
- material.renderFace = miniprogram.RenderFace.Double;
1226
- } else {
1227
- material.renderFace = miniprogram.RenderFace.Front;
1228
- }
1229
- switch(alphaMode){
1230
- case MaterialAlphaMode.OPAQUE:
1231
- material.isTransparent = false;
1385
+ var outputStride = output.length / input.length;
1386
+ var _gltfSampler_interpolation;
1387
+ var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1388
+ var samplerInterpolation = void 0;
1389
+ switch(interpolation){
1390
+ case AnimationSamplerInterpolation.CubicSpine:
1391
+ samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
1232
1392
  break;
1233
- case MaterialAlphaMode.BLEND:
1234
- material.isTransparent = true;
1393
+ case AnimationSamplerInterpolation.Step:
1394
+ samplerInterpolation = miniprogram.InterpolationType.Step;
1235
1395
  break;
1236
- case MaterialAlphaMode.MASK:
1237
- material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1396
+ case AnimationSamplerInterpolation.Linear:
1397
+ samplerInterpolation = miniprogram.InterpolationType.Linear;
1238
1398
  break;
1239
1399
  }
1240
- materials[i] = material;
1241
- }
1242
- glTFResource.materials = materials;
1243
- materialsPromiseInfo.resolve(materials);
1244
- return materialsPromiseInfo.promise;
1245
- };
1246
- /** @internal */ MaterialParser._parseTextureTransform = function _parseTextureTransform(material, extensions, context) {
1247
- if (extensions === void 0) extensions = {};
1248
- var schema = extensions.KHR_texture_transform;
1249
- if (schema) {
1250
- Parser.parseEngineResource("KHR_texture_transform", schema, material, context);
1251
- }
1252
- };
1253
- return MaterialParser;
1254
- }(Parser);
1255
-
1256
- var KHR_materials_clearcoat = /*#__PURE__*/ function(ExtensionParser) {
1257
- _inherits(KHR_materials_clearcoat, ExtensionParser);
1258
- function KHR_materials_clearcoat() {
1259
- return ExtensionParser.apply(this, arguments);
1260
- }
1261
- var _proto = KHR_materials_clearcoat.prototype;
1262
- _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1263
- var textures = context.glTFResource.textures;
1264
- 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;
1265
- material.clearCoat = clearcoatFactor;
1266
- material.clearCoatRoughness = clearcoatRoughnessFactor;
1267
- if (clearcoatTexture) {
1268
- material.clearCoatTexture = textures[clearcoatTexture.index];
1269
- MaterialParser._parseTextureTransform(material, clearcoatTexture.extensions, context);
1270
- }
1271
- if (clearcoatRoughnessTexture) {
1272
- material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
1273
- MaterialParser._parseTextureTransform(material, clearcoatRoughnessTexture.extensions, context);
1274
- }
1275
- if (clearcoatNormalTexture) {
1276
- material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
1277
- MaterialParser._parseTextureTransform(material, clearcoatNormalTexture.extensions, context);
1278
- }
1279
- };
1280
- return KHR_materials_clearcoat;
1281
- }(ExtensionParser);
1282
- KHR_materials_clearcoat = __decorate([
1283
- registerExtension("KHR_materials_clearcoat")
1284
- ], KHR_materials_clearcoat);
1285
-
1286
- var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(ExtensionParser) {
1287
- _inherits(KHR_materials_pbrSpecularGlossiness, ExtensionParser);
1288
- function KHR_materials_pbrSpecularGlossiness() {
1289
- return ExtensionParser.apply(this, arguments);
1290
- }
1291
- var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
1292
- _proto.createEngineResource = function createEngineResource(schema, context) {
1293
- var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
1294
- var material = new miniprogram.PBRSpecularMaterial(engine);
1295
- var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
1296
- if (diffuseFactor) {
1297
- 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]);
1298
- }
1299
- if (diffuseTexture) {
1300
- material.baseTexture = textures[diffuseTexture.index];
1301
- MaterialParser._parseTextureTransform(material, diffuseTexture.extensions, context);
1302
- }
1303
- if (specularFactor) {
1304
- material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
1305
- }
1306
- if (glossinessFactor !== undefined) {
1307
- material.glossiness = glossinessFactor;
1308
- }
1309
- if (specularGlossinessTexture) {
1310
- material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
1311
- MaterialParser._parseTextureTransform(material, specularGlossinessTexture.extensions, context);
1312
- }
1313
- return material;
1314
- };
1315
- return KHR_materials_pbrSpecularGlossiness;
1316
- }(ExtensionParser);
1317
- KHR_materials_pbrSpecularGlossiness = __decorate([
1318
- registerExtension("KHR_materials_pbrSpecularGlossiness")
1319
- ], KHR_materials_pbrSpecularGlossiness);
1320
-
1321
- var KHR_materials_unlit = /*#__PURE__*/ function(ExtensionParser) {
1322
- _inherits(KHR_materials_unlit, ExtensionParser);
1323
- function KHR_materials_unlit() {
1324
- return ExtensionParser.apply(this, arguments);
1325
- }
1326
- var _proto = KHR_materials_unlit.prototype;
1327
- _proto.createEngineResource = function createEngineResource(schema, context) {
1328
- var engine = context.glTFResource.engine;
1329
- var material = new miniprogram.UnlitMaterial(engine);
1330
- return material;
1331
- };
1332
- return KHR_materials_unlit;
1333
- }(ExtensionParser);
1334
- KHR_materials_unlit = __decorate([
1335
- registerExtension("KHR_materials_unlit")
1336
- ], KHR_materials_unlit);
1337
-
1338
- var KHR_materials_variants = /*#__PURE__*/ function(ExtensionParser) {
1339
- _inherits(KHR_materials_variants, ExtensionParser);
1340
- function KHR_materials_variants() {
1341
- return ExtensionParser.apply(this, arguments);
1342
- }
1343
- var _proto = KHR_materials_variants.prototype;
1344
- _proto.parseEngineResource = function parseEngineResource(schema, renderer, context) {
1345
- 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;
1346
- var mappings = schema.mappings;
1347
- for(var i = 0; i < mappings.length; i++){
1348
- var _mappings_i = mappings[i], material = _mappings_i.material, variants = _mappings_i.variants;
1349
- if (!glTFResource.variants) glTFResource.variants = [];
1350
- glTFResource.variants.push({
1351
- renderer: renderer,
1352
- material: glTFResource.materials[material],
1353
- variants: variants.map(function(index) {
1354
- return variantNames[index].name;
1355
- })
1400
+ input[input.length - 1];
1401
+ sampleDataCollection.push({
1402
+ type: outputAccessor.type,
1403
+ interpolation: samplerInterpolation,
1404
+ input: input,
1405
+ output: output,
1406
+ outputSize: outputStride
1356
1407
  });
1357
1408
  }
1358
- };
1359
- return KHR_materials_variants;
1360
- }(ExtensionParser);
1361
- KHR_materials_variants = __decorate([
1362
- registerExtension("KHR_materials_variants")
1363
- ], KHR_materials_variants);
1364
-
1365
- var KHR_mesh_quantization = /*#__PURE__*/ function(ExtensionParser) {
1366
- _inherits(KHR_mesh_quantization, ExtensionParser);
1367
- function KHR_mesh_quantization() {
1368
- return ExtensionParser.apply(this, arguments);
1369
- }
1370
- return KHR_mesh_quantization;
1371
- }(ExtensionParser);
1372
- KHR_mesh_quantization = __decorate([
1373
- registerExtension("KHR_mesh_quantization")
1374
- ], KHR_mesh_quantization);
1375
-
1376
- var KHR_texture_transform = /*#__PURE__*/ function(ExtensionParser) {
1377
- _inherits(KHR_texture_transform, ExtensionParser);
1378
- function KHR_texture_transform() {
1379
- return ExtensionParser.apply(this, arguments);
1380
- }
1381
- var _proto = KHR_texture_transform.prototype;
1382
- _proto.parseEngineResource = function parseEngineResource(schema, material, context) {
1383
- var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
1384
- if (offset) {
1385
- material.tilingOffset.z = offset[0];
1386
- material.tilingOffset.w = offset[1];
1387
- }
1388
- if (scale) {
1389
- material.tilingOffset.x = scale[0];
1390
- material.tilingOffset.y = scale[1];
1391
- }
1392
- if (rotation) {
1393
- miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
1394
- }
1395
- if (texCoord) {
1396
- miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
1397
- }
1398
- };
1399
- return KHR_texture_transform;
1400
- }(ExtensionParser);
1401
- KHR_texture_transform = __decorate([
1402
- registerExtension("KHR_texture_transform")
1403
- ], KHR_texture_transform);
1404
-
1405
- var GalaceanMaterialsRemap = /*#__PURE__*/ function(ExtensionParser) {
1406
- _inherits(GalaceanMaterialsRemap, ExtensionParser);
1407
- function GalaceanMaterialsRemap() {
1408
- return ExtensionParser.apply(this, arguments);
1409
- }
1410
- var _proto = GalaceanMaterialsRemap.prototype;
1411
- _proto.createEngineResource = function createEngineResource(schema, context) {
1412
- var engine = context.glTFResource.engine;
1413
- // @ts-ignore
1414
- return engine.resourceManager.getResourceByRef(schema);
1415
- };
1416
- return GalaceanMaterialsRemap;
1417
- }(ExtensionParser);
1418
- GalaceanMaterialsRemap = __decorate([
1419
- registerExtension("OASIS_materials_remap")
1420
- ], GalaceanMaterialsRemap);
1421
-
1422
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1423
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1424
-
1425
- if (it) return (it = it.call(o)).next.bind(it);
1426
- // Fallback for engines without symbol support
1427
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
1428
- if (it) o = it;
1429
-
1430
- var i = 0;
1431
-
1432
- return function() {
1433
- if (i >= o.length) return { done: true };
1434
-
1435
- return { done: false, value: o[i++] };
1436
- };
1437
- }
1438
-
1439
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1440
- }
1441
-
1442
- var AnimationParser = /*#__PURE__*/ function(Parser) {
1443
- _inherits(AnimationParser, Parser);
1444
- function AnimationParser() {
1445
- return Parser.apply(this, arguments);
1446
- }
1447
- var _proto = AnimationParser.prototype;
1448
- _proto.parse = function parse(context) {
1449
- var gltf = context.gltf; context.buffers; var glTFResource = context.glTFResource;
1450
- var entities = glTFResource.entities;
1451
- var animations = gltf.animations, accessors = gltf.accessors;
1452
- if (!animations) {
1453
- return;
1454
- }
1455
- var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1456
- var animationClipCount = animations.length;
1457
- var animationClips = new Array(animationClipCount);
1458
- var animationsIndices = new Array(animationClipCount);
1459
- for(var i = 0; i < animationClipCount; i++){
1460
- var gltfAnimation = animations[i];
1461
- var channels = gltfAnimation.channels, samplers = gltfAnimation.samplers, _gltfAnimation_name = gltfAnimation.name, name = _gltfAnimation_name === void 0 ? "AnimationClip" + i : _gltfAnimation_name;
1462
- var animationClip = new miniprogram.AnimationClip(name);
1463
- var sampleDataCollection = new Array();
1464
- // parse samplers
1465
- for(var j = 0, m = samplers.length; j < m; j++){
1466
- var gltfSampler = samplers[j];
1467
- var inputAccessor = accessors[gltfSampler.input];
1468
- var outputAccessor = accessors[gltfSampler.output];
1469
- var input = GLTFUtil.getAccessorBuffer(context, gltf, inputAccessor).data;
1470
- var output = GLTFUtil.getAccessorBuffer(context, gltf, outputAccessor).data;
1471
- if (outputAccessor.normalized) {
1472
- var scale = GLTFUtil.getNormalizedComponentScale(outputAccessor.componentType);
1473
- var scaled = new Float32Array(output.length);
1474
- for(var k = 0, v = output.length; k < v; k++){
1475
- scaled[k] = output[k] * scale;
1476
- }
1477
- output = scaled;
1478
- }
1479
- var outputStride = output.length / input.length;
1480
- var _gltfSampler_interpolation;
1481
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1482
- var samplerInterpolation = void 0;
1483
- switch(interpolation){
1484
- case AnimationSamplerInterpolation.CubicSpine:
1485
- samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
1486
- break;
1487
- case AnimationSamplerInterpolation.Step:
1488
- samplerInterpolation = miniprogram.InterpolationType.Step;
1489
- break;
1490
- case AnimationSamplerInterpolation.Linear:
1491
- samplerInterpolation = miniprogram.InterpolationType.Linear;
1492
- break;
1493
- }
1494
- input[input.length - 1];
1495
- sampleDataCollection.push({
1496
- type: outputAccessor.type,
1497
- interpolation: samplerInterpolation,
1498
- input: input,
1499
- output: output,
1500
- outputSize: outputStride
1501
- });
1409
+ for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1410
+ var gltfChannel = channels[j1];
1411
+ var target = gltfChannel.target;
1412
+ var channelTargetEntity = entities[target.node];
1413
+ var relativePath = "";
1414
+ var entity = channelTargetEntity;
1415
+ while(entity.parent){
1416
+ relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1417
+ entity = entity.parent;
1502
1418
  }
1503
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1504
- var gltfChannel = channels[j1];
1505
- var target = gltfChannel.target;
1506
- var channelTargetEntity = entities[target.node];
1507
- var relativePath = "";
1508
- var entity = channelTargetEntity;
1509
- while(entity.parent){
1510
- relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1511
- entity = entity.parent;
1512
- }
1513
- var ComponentType = void 0;
1514
- var propertyName = void 0;
1515
- switch(target.path){
1516
- case AnimationChannelTargetPath.TRANSLATION:
1517
- ComponentType = miniprogram.Transform;
1518
- propertyName = "position";
1519
- break;
1520
- case AnimationChannelTargetPath.ROTATION:
1521
- ComponentType = miniprogram.Transform;
1522
- propertyName = "rotationQuaternion";
1523
- break;
1524
- case AnimationChannelTargetPath.SCALE:
1525
- ComponentType = miniprogram.Transform;
1526
- propertyName = "scale";
1527
- break;
1528
- case AnimationChannelTargetPath.WEIGHTS:
1529
- ComponentType = miniprogram.SkinnedMeshRenderer;
1530
- propertyName = "blendShapeWeights";
1531
- break;
1532
- }
1533
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1534
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1419
+ var ComponentType = void 0;
1420
+ var propertyName = void 0;
1421
+ switch(target.path){
1422
+ case AnimationChannelTargetPath.TRANSLATION:
1423
+ ComponentType = miniprogram.Transform;
1424
+ propertyName = "position";
1425
+ break;
1426
+ case AnimationChannelTargetPath.ROTATION:
1427
+ ComponentType = miniprogram.Transform;
1428
+ propertyName = "rotationQuaternion";
1429
+ break;
1430
+ case AnimationChannelTargetPath.SCALE:
1431
+ ComponentType = miniprogram.Transform;
1432
+ propertyName = "scale";
1433
+ break;
1434
+ case AnimationChannelTargetPath.WEIGHTS:
1435
+ ComponentType = miniprogram.SkinnedMeshRenderer;
1436
+ propertyName = "blendShapeWeights";
1437
+ break;
1535
1438
  }
1536
- animationClips[i] = animationClip;
1537
- animationsIndices[i] = {
1538
- name: name,
1539
- index: i
1540
- };
1439
+ var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1440
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1541
1441
  }
1542
- glTFResource.animations = animationClips;
1543
- // @ts-ignore for editor
1544
- glTFResource._animationsIndices = animationsIndices;
1545
- animationClipsPromiseInfo.resolve(animationClips);
1546
- return animationClipsPromiseInfo.promise;
1547
1442
  };
1548
- _proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
1443
+ GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
1549
1444
  var sampleData = sampleDataCollection[gltfChannel.sampler];
1550
1445
  var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
1551
- switch(animationchannelTargetPath){
1446
+ switch(animationChannelTargetPath){
1552
1447
  case AnimationChannelTargetPath.TRANSLATION:
1553
1448
  case AnimationChannelTargetPath.SCALE:
1554
1449
  {
@@ -1613,35 +1508,42 @@ var AnimationParser = /*#__PURE__*/ function(Parser) {
1613
1508
  }
1614
1509
  }
1615
1510
  };
1616
- return AnimationParser;
1617
- }(Parser);
1511
+ return GLTFAnimationParser;
1512
+ }(GLTFParser);
1618
1513
 
1619
- var BufferParser = /*#__PURE__*/ function(Parser) {
1620
- _inherits(BufferParser, Parser);
1621
- function BufferParser() {
1622
- return Parser.apply(this, arguments);
1514
+ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1515
+ _inherits(GLTFBufferParser, GLTFParser);
1516
+ function GLTFBufferParser() {
1517
+ return GLTFParser.apply(this, arguments);
1623
1518
  }
1624
- var _proto = BufferParser.prototype;
1519
+ var _proto = GLTFBufferParser.prototype;
1625
1520
  _proto.parse = function parse(context) {
1626
- var glTFResource = context.glTFResource;
1521
+ var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
1627
1522
  var url = glTFResource.url;
1628
- if (this._isGLB(url)) {
1629
- return miniprogram.request(url, {
1630
- type: "arraybuffer"
1631
- }).then(GLTFUtil.parseGLB).then(function(param) {
1632
- var gltf = param.gltf, buffers = param.buffers;
1633
- context.gltf = gltf;
1523
+ var restoreBufferRequests = contentRestorer.bufferRequests;
1524
+ var requestConfig = {
1525
+ type: "arraybuffer"
1526
+ };
1527
+ var isGLB = this._isGLB(url);
1528
+ contentRestorer.isGLB = isGLB;
1529
+ if (isGLB) {
1530
+ return miniprogram.request(url, requestConfig).then(function(glb) {
1531
+ restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
1532
+ return GLTFUtils.parseGLB(context, glb);
1533
+ }).then(function(param) {
1534
+ var glTF = param.glTF, buffers = param.buffers;
1535
+ context.glTF = glTF;
1634
1536
  context.buffers = buffers;
1635
1537
  });
1636
1538
  } else {
1637
1539
  return miniprogram.request(url, {
1638
1540
  type: "json"
1639
- }).then(function(gltf) {
1640
- context.gltf = gltf;
1641
- return Promise.all(gltf.buffers.map(function(buffer) {
1642
- return miniprogram.request(GLTFUtil.parseRelativeUrl(url, buffer.uri), {
1643
- type: "arraybuffer"
1644
- });
1541
+ }).then(function(glTF) {
1542
+ context.glTF = glTF;
1543
+ return Promise.all(glTF.buffers.map(function(buffer) {
1544
+ var absoluteUrl = miniprogram.Utils.resolveAbsoluteUrl(url, buffer.uri);
1545
+ restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
1546
+ return miniprogram.request(absoluteUrl, requestConfig);
1645
1547
  })).then(function(buffers) {
1646
1548
  context.buffers = buffers;
1647
1549
  });
@@ -1652,24 +1554,24 @@ var BufferParser = /*#__PURE__*/ function(Parser) {
1652
1554
  var index = url.lastIndexOf(".");
1653
1555
  return url.substring(index + 1, index + 4) === "glb";
1654
1556
  };
1655
- return BufferParser;
1656
- }(Parser);
1557
+ return GLTFBufferParser;
1558
+ }(GLTFParser);
1657
1559
 
1658
- var EntityParser = /*#__PURE__*/ function(Parser) {
1659
- _inherits(EntityParser, Parser);
1660
- function EntityParser() {
1661
- return Parser.apply(this, arguments);
1560
+ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1561
+ _inherits(GLTFEntityParser, GLTFParser);
1562
+ function GLTFEntityParser() {
1563
+ return GLTFParser.apply(this, arguments);
1662
1564
  }
1663
- var _proto = EntityParser.prototype;
1565
+ var _proto = GLTFEntityParser.prototype;
1664
1566
  _proto.parse = function parse(context) {
1665
- var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
1567
+ var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
1666
1568
  var engine = glTFResource.engine;
1667
1569
  if (!nodes) return;
1668
1570
  var entities = [];
1669
1571
  for(var i = 0; i < nodes.length; i++){
1670
1572
  var gltfNode = nodes[i];
1671
1573
  var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
1672
- var entity = new miniprogram.Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
1574
+ var entity = new miniprogram.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
1673
1575
  var transform = entity.transform;
1674
1576
  if (matrix) {
1675
1577
  var localMatrix = transform.localMatrix;
@@ -1693,7 +1595,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1693
1595
  this._createSceneRoots(context, glTFResource);
1694
1596
  };
1695
1597
  _proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
1696
- var nodes = context.gltf.nodes;
1598
+ var nodes = context.glTF.nodes;
1697
1599
  var entities = glTFResource.entities;
1698
1600
  for(var i = 0; i < nodes.length; i++){
1699
1601
  var children = nodes[i].children;
@@ -1707,7 +1609,7 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1707
1609
  }
1708
1610
  };
1709
1611
  _proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
1710
- var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
1612
+ var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
1711
1613
  var engine = glTFResource.engine, entities = glTFResource.entities;
1712
1614
  if (!scenes) return;
1713
1615
  var sceneRoots = [];
@@ -1727,79 +1629,193 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
1727
1629
  glTFResource.sceneRoots = sceneRoots;
1728
1630
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
1729
1631
  };
1730
- return EntityParser;
1731
- }(Parser);
1632
+ return GLTFEntityParser;
1633
+ }(GLTFParser);
1732
1634
  (function() {
1733
- /** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
1635
+ /** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
1734
1636
  })();
1735
1637
 
1736
- var MeshParser = /*#__PURE__*/ function(Parser1) {
1737
- _inherits(MeshParser, Parser1);
1738
- function MeshParser() {
1739
- return Parser1.apply(this, arguments);
1638
+ var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
1639
+ _inherits(GLTFMaterialParser, GLTFParser1);
1640
+ function GLTFMaterialParser() {
1641
+ return GLTFParser1.apply(this, arguments);
1642
+ }
1643
+ var _proto = GLTFMaterialParser.prototype;
1644
+ _proto.parse = function parse(context) {
1645
+ var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
1646
+ if (!glTF.materials) return;
1647
+ var engine = glTFResource.engine;
1648
+ var materialPromises = [];
1649
+ for(var i = 0; i < glTF.materials.length; i++){
1650
+ var materialInfo = glTF.materials[i];
1651
+ var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
1652
+ if (!material) {
1653
+ material = new miniprogram.PBRMaterial(engine);
1654
+ material.name = materialInfo.name;
1655
+ GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
1656
+ }
1657
+ materialPromises.push(material);
1658
+ }
1659
+ return miniprogram.AssetPromise.all(materialPromises).then(function(materials) {
1660
+ glTFResource.materials = materials;
1661
+ for(var i = 0; i < glTF.materials.length; i++){
1662
+ var materialInfo = glTF.materials[i];
1663
+ GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
1664
+ }
1665
+ materialsPromiseInfo.resolve(materials);
1666
+ return materialsPromiseInfo.promise;
1667
+ });
1668
+ };
1669
+ /**
1670
+ * @internal
1671
+ */ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
1672
+ var _texture_extensions;
1673
+ if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
1674
+ miniprogram.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
1675
+ }
1676
+ };
1677
+ /**
1678
+ * @internal
1679
+ */ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
1680
+ var textures = context.glTFResource.textures;
1681
+ 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;
1682
+ if (pbrMetallicRoughness) {
1683
+ var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1684
+ if (baseColorFactor) {
1685
+ 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]);
1686
+ }
1687
+ if (baseColorTexture) {
1688
+ material.baseTexture = textures[baseColorTexture.index];
1689
+ GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
1690
+ }
1691
+ if (material.constructor === miniprogram.PBRMaterial) {
1692
+ material.metallic = metallicFactor != null ? metallicFactor : 1;
1693
+ material.roughness = roughnessFactor != null ? roughnessFactor : 1;
1694
+ if (metallicRoughnessTexture) {
1695
+ material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1696
+ GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
1697
+ }
1698
+ }
1699
+ }
1700
+ if (material.constructor === miniprogram.PBRMaterial || material.constructor === miniprogram.PBRSpecularMaterial) {
1701
+ if (emissiveTexture) {
1702
+ material.emissiveTexture = textures[emissiveTexture.index];
1703
+ GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
1704
+ }
1705
+ if (emissiveFactor) {
1706
+ material.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
1707
+ }
1708
+ if (normalTexture) {
1709
+ var index = normalTexture.index, scale = normalTexture.scale;
1710
+ material.normalTexture = textures[index];
1711
+ GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
1712
+ if (scale !== undefined) {
1713
+ material.normalTextureIntensity = scale;
1714
+ }
1715
+ }
1716
+ if (occlusionTexture) {
1717
+ var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1718
+ material.occlusionTexture = textures[index1];
1719
+ GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
1720
+ if (strength !== undefined) {
1721
+ material.occlusionTextureIntensity = strength;
1722
+ }
1723
+ if (texCoord === miniprogram.TextureCoordinate.UV1) {
1724
+ material.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
1725
+ } else if (texCoord > miniprogram.TextureCoordinate.UV1) {
1726
+ miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1727
+ }
1728
+ }
1729
+ }
1730
+ if (doubleSided) {
1731
+ material.renderFace = miniprogram.RenderFace.Double;
1732
+ } else {
1733
+ material.renderFace = miniprogram.RenderFace.Front;
1734
+ }
1735
+ switch(alphaMode){
1736
+ case MaterialAlphaMode.OPAQUE:
1737
+ material.isTransparent = false;
1738
+ break;
1739
+ case MaterialAlphaMode.BLEND:
1740
+ material.isTransparent = true;
1741
+ break;
1742
+ case MaterialAlphaMode.MASK:
1743
+ material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1744
+ break;
1745
+ }
1746
+ };
1747
+ return GLTFMaterialParser;
1748
+ }(GLTFParser);
1749
+
1750
+ function _instanceof(left, right) {
1751
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1752
+ return !!right[Symbol.hasInstance](left);
1753
+ } else return left instanceof right;
1754
+ }
1755
+
1756
+ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1757
+ _inherits(GLTFMeshParser, GLTFParser1);
1758
+ function GLTFMeshParser() {
1759
+ return GLTFParser1.apply(this, arguments);
1740
1760
  }
1741
- var _proto = MeshParser.prototype;
1761
+ var _proto = GLTFMeshParser.prototype;
1742
1762
  _proto.parse = function parse(context) {
1743
1763
  var _loop = function(i) {
1744
1764
  var _loop = function(j) {
1745
1765
  var gltfPrimitive = gltfMesh.primitives[j];
1746
- var _gltfPrimitive_extensions = gltfPrimitive.extensions, extensions = _gltfPrimitive_extensions === void 0 ? {} : _gltfPrimitive_extensions;
1747
- var KHR_draco_mesh_compression = extensions.KHR_draco_mesh_compression;
1748
1766
  primitivePromises[j] = new Promise(function(resolve) {
1749
- var mesh = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
1750
- if (KHR_draco_mesh_compression) {
1751
- Parser.createEngineResource("KHR_draco_mesh_compression", KHR_draco_mesh_compression, context, gltfPrimitive).then(function(decodedGeometry) {
1752
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1753
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
1754
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
1755
- return decodedGeometry.attributes[j].array;
1756
- }
1757
- }
1758
- return null;
1759
- }, function(attributeSemantic, shapeIndex) {
1760
- throw "BlendShape animation is not supported when using draco.";
1761
- }, function() {
1762
- return decodedGeometry.index.array;
1763
- }, context.keepMeshData);
1764
- }).then(resolve);
1767
+ var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
1768
+ if (mesh) {
1769
+ if (_instanceof(mesh, miniprogram.ModelMesh)) {
1770
+ resolve(mesh);
1771
+ } else {
1772
+ mesh.then(function(mesh) {
1773
+ return resolve(mesh);
1774
+ });
1775
+ }
1765
1776
  } else {
1766
- _this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1777
+ var mesh1 = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
1778
+ var meshRestoreInfo = new ModelMeshRestoreInfo();
1779
+ meshRestoreInfo.mesh = mesh1;
1780
+ context.contentRestorer.meshes.push(meshRestoreInfo);
1781
+ GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
1767
1782
  return null;
1768
1783
  }, function(attributeName, shapeIndex) {
1769
1784
  var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1770
1785
  var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1771
1786
  if (attributeAccessorIdx) {
1772
- var accessor = gltf.accessors[attributeAccessorIdx];
1773
- return GLTFUtil.getAccessorData(gltf, accessor, buffers);
1787
+ var accessor = glTF.accessors[attributeAccessorIdx];
1788
+ return GLTFUtils.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
1774
1789
  } else {
1775
1790
  return null;
1776
1791
  }
1777
1792
  }, function() {
1778
- var indexAccessor = gltf.accessors[gltfPrimitive.indices];
1779
- return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
1793
+ var indexAccessor = glTF.accessors[gltfPrimitive.indices];
1794
+ return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
1780
1795
  }, context.keepMeshData).then(resolve);
1781
1796
  }
1782
1797
  });
1783
1798
  };
1784
- var gltfMesh = gltf.meshes[i];
1799
+ var gltfMesh = glTF.meshes[i];
1785
1800
  var primitivePromises = [];
1786
1801
  for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1787
1802
  meshPromises[i] = Promise.all(primitivePromises);
1788
1803
  };
1789
- var _this = this;
1790
- var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
1804
+ var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
1791
1805
  var engine = glTFResource.engine;
1792
- if (!gltf.meshes) return;
1806
+ if (!glTF.meshes) return;
1793
1807
  var meshesPromiseInfo = context.meshesPromiseInfo;
1794
1808
  var meshPromises = [];
1795
- for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
1809
+ for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
1796
1810
  miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
1797
1811
  glTFResource.meshes = meshes;
1798
1812
  meshesPromiseInfo.resolve(meshes);
1799
1813
  }).catch(meshesPromiseInfo.reject);
1800
1814
  return meshesPromiseInfo.promise;
1801
1815
  };
1802
- _proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1816
+ /**
1817
+ * @internal
1818
+ */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1803
1819
  var accessors = gltf.accessors;
1804
1820
  context.buffers;
1805
1821
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
@@ -1808,21 +1824,31 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1808
1824
  var vertexCount;
1809
1825
  var bufferBindIndex = 0;
1810
1826
  var positions;
1811
- keepMeshData && (positions = new Array(vertexCount));
1827
+ var boneIndices;
1828
+ var boneWeights;
1829
+ if (keepMeshData) {
1830
+ positions = new Array(vertexCount);
1831
+ boneIndices = new Array(vertexCount);
1832
+ boneWeights = new Array(vertexCount);
1833
+ }
1812
1834
  for(var attribute in attributes){
1813
1835
  var accessor = accessors[attributes[attribute]];
1814
- var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
1815
- var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1816
- var attributeCount = accessor.count;
1836
+ var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
1837
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1838
+ var accessorCount = accessor.count;
1817
1839
  var vertices = accessorBuffer.data;
1818
1840
  var vertexElement = void 0;
1819
1841
  var meshId = mesh.instanceId;
1820
1842
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1821
- var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
1843
+ var elementNormalized = accessor.normalized;
1844
+ var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
1845
+ var scaleFactor = void 0;
1846
+ elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
1847
+ var elementOffset = void 0;
1822
1848
  if (accessorBuffer.interleaved) {
1823
1849
  var byteOffset = accessor.byteOffset || 0;
1824
1850
  var stride = accessorBuffer.stride;
1825
- var elementOffset = byteOffset % stride;
1851
+ elementOffset = byteOffset % stride;
1826
1852
  if (vertexBindingInfos[meshId] === undefined) {
1827
1853
  vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1828
1854
  var vertexBuffer = accessorBuffer.vertexBuffer;
@@ -1830,6 +1856,7 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1830
1856
  vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1831
1857
  vertexBuffer.setData(vertices);
1832
1858
  accessorBuffer.vertexBuffer = vertexBuffer;
1859
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1833
1860
  }
1834
1861
  mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1835
1862
  vertexBindingInfos[meshId] = bufferBindIndex++;
@@ -1837,43 +1864,70 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1837
1864
  vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
1838
1865
  }
1839
1866
  } else {
1840
- vertexElement = new miniprogram.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
1867
+ elementOffset = 0;
1868
+ vertexElement = new miniprogram.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
1841
1869
  var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1842
1870
  vertexBuffer1.setData(vertices);
1871
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1843
1872
  mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1844
1873
  vertexBindingInfos[meshId] = bufferBindIndex++;
1845
1874
  }
1846
1875
  vertexElements.push(vertexElement);
1847
1876
  if (attribute === "POSITION") {
1848
- vertexCount = attributeCount;
1877
+ vertexCount = accessorCount;
1849
1878
  var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
1850
1879
  if (accessor.min && accessor.max) {
1851
1880
  min.copyFromArray(accessor.min);
1852
1881
  max.copyFromArray(accessor.max);
1853
1882
  if (keepMeshData) {
1854
- var stride1 = vertices.length / attributeCount;
1855
- for(var j = 0; j < attributeCount; j++){
1856
- var offset = j * stride1;
1857
- positions[j] = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1883
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
1884
+ var stride1 = vertices.length / accessorCount;
1885
+ for(var j = 0; j < accessorCount; j++){
1886
+ var offset = baseOffset + j * stride1;
1887
+ var position = new miniprogram$1.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
1888
+ elementNormalized && position.scale(scaleFactor);
1889
+ positions[j] = position;
1858
1890
  }
1859
1891
  }
1860
1892
  } else {
1861
- var position = MeshParser._tempVector3;
1893
+ var position1 = GLTFMeshParser._tempVector3;
1862
1894
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1863
1895
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1864
- var stride2 = vertices.length / attributeCount;
1865
- for(var j1 = 0; j1 < attributeCount; j1++){
1866
- var offset1 = j1 * stride2;
1867
- position.copyFromArray(vertices, offset1);
1868
- miniprogram$1.Vector3.min(min, position, min);
1869
- miniprogram$1.Vector3.max(max, position, max);
1870
- keepMeshData && (positions[j1] = position.clone());
1896
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
1897
+ var stride2 = vertices.length / accessorCount;
1898
+ for(var j1 = 0; j1 < accessorCount; j1++){
1899
+ var offset1 = baseOffset1 + j1 * stride2;
1900
+ position1.copyFromArray(vertices, offset1);
1901
+ miniprogram$1.Vector3.min(min, position1, min);
1902
+ miniprogram$1.Vector3.max(max, position1, max);
1903
+ if (keepMeshData) {
1904
+ var clonePosition = position1.clone();
1905
+ elementNormalized && clonePosition.scale(scaleFactor);
1906
+ positions[j1] = clonePosition;
1907
+ }
1871
1908
  }
1872
1909
  }
1873
- if (accessor.normalized) {
1874
- var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1875
- min.scale(sacleFactor);
1876
- max.scale(sacleFactor);
1910
+ if (elementNormalized) {
1911
+ min.scale(scaleFactor);
1912
+ max.scale(scaleFactor);
1913
+ }
1914
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
1915
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
1916
+ var stride3 = vertices.length / accessorCount;
1917
+ for(var j2 = 0; j2 < accessorCount; j2++){
1918
+ var offset2 = baseOffset2 + j2 * stride3;
1919
+ var boneIndex = new miniprogram$1.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
1920
+ elementNormalized && boneIndex.scale(scaleFactor);
1921
+ boneIndices[j2] = boneIndex;
1922
+ }
1923
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
1924
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
1925
+ var stride4 = vertices.length / accessorCount;
1926
+ for(var j3 = 0; j3 < accessorCount; j3++){
1927
+ var offset3 = baseOffset3 + j3 * stride4;
1928
+ var boneWeight = new miniprogram$1.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
1929
+ elementNormalized && boneWeight.scale(scaleFactor);
1930
+ boneWeights[j3] = boneWeight;
1877
1931
  }
1878
1932
  }
1879
1933
  }
@@ -1881,179 +1935,76 @@ var MeshParser = /*#__PURE__*/ function(Parser1) {
1881
1935
  // Indices
1882
1936
  if (indices !== undefined) {
1883
1937
  var indexAccessor = gltf.accessors[indices];
1884
- var indexData = getIndexBufferData();
1885
- mesh.setIndices(indexData);
1938
+ var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
1939
+ mesh.setIndices(accessorBuffer1.data);
1886
1940
  mesh.addSubMesh(0, indexAccessor.count, mode);
1941
+ meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
1887
1942
  } else {
1888
1943
  mesh.addSubMesh(0, vertexCount, mode);
1889
1944
  }
1890
1945
  // BlendShapes
1891
- targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
1946
+ targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
1892
1947
  mesh.uploadData(!keepMeshData);
1893
1948
  //@ts-ignore
1894
1949
  mesh._positions = positions;
1950
+ //@ts-ignore
1951
+ mesh._boneIndices = boneIndices;
1952
+ //@ts-ignore
1953
+ mesh._boneWeights = boneWeights;
1895
1954
  return Promise.resolve(mesh);
1896
1955
  };
1897
- _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
1956
+ /**
1957
+ * @internal
1958
+ */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
1898
1959
  var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
1899
1960
  for(var i = 0, n = glTFTargets.length; i < n; i++){
1900
1961
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1901
- var deltaPosBuffer = getBlendShapeData("POSITION", i);
1902
- var deltaNorBuffer = getBlendShapeData("NORMAL", i);
1903
- var deltaTanBuffer = getBlendShapeData("TANGENT", i);
1904
- var deltaPositions = deltaPosBuffer ? GLTFUtil.floatBufferToVector3Array(deltaPosBuffer) : null;
1905
- var deltaNormals = deltaNorBuffer ? GLTFUtil.floatBufferToVector3Array(deltaNorBuffer) : null;
1906
- var deltaTangents = deltaTanBuffer ? GLTFUtil.floatBufferToVector3Array(deltaTanBuffer) : null;
1962
+ var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
1963
+ var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
1964
+ var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
1965
+ var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
1966
+ var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
1967
+ var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
1907
1968
  var blendShape = new miniprogram.BlendShape(name);
1908
1969
  blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
1909
1970
  mesh.addBlendShape(blendShape);
1971
+ meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
1910
1972
  }
1911
1973
  };
1912
- /**
1913
- * @deprecated
1914
- */ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1915
- var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
1916
- var vertexCount;
1917
- var accessors = gltf.accessors;
1918
- var accessor = accessors[attributes["POSITION"]];
1919
- var positionBuffer = getVertexBufferData("POSITION");
1920
- var positions = GLTFUtil.floatBufferToVector3Array(positionBuffer);
1921
- mesh.setPositions(positions);
1922
- var bounds = mesh.bounds;
1923
- vertexCount = accessor.count;
1924
- if (accessor.min && accessor.max) {
1925
- bounds.min.copyFromArray(accessor.min);
1926
- bounds.max.copyFromArray(accessor.max);
1927
- } else {
1928
- var position = MeshParser._tempVector3;
1929
- var min = bounds.min, max = bounds.max;
1930
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1931
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1932
- var stride = positionBuffer.length / vertexCount;
1933
- for(var j = 0; j < vertexCount; j++){
1934
- var offset = j * stride;
1935
- position.copyFromArray(positionBuffer, offset);
1936
- miniprogram$1.Vector3.min(min, position, min);
1937
- miniprogram$1.Vector3.max(max, position, max);
1938
- }
1939
- }
1940
- for(var attributeSemantic in attributes){
1941
- if (attributeSemantic === "POSITION") {
1942
- continue;
1943
- }
1944
- var bufferData = getVertexBufferData(attributeSemantic);
1945
- switch(attributeSemantic){
1946
- case "NORMAL":
1947
- var normals = GLTFUtil.floatBufferToVector3Array(bufferData);
1948
- mesh.setNormals(normals);
1949
- break;
1950
- case "TEXCOORD_0":
1951
- var texturecoords = GLTFUtil.floatBufferToVector2Array(bufferData);
1952
- mesh.setUVs(texturecoords, 0);
1953
- break;
1954
- case "TEXCOORD_1":
1955
- var texturecoords1 = GLTFUtil.floatBufferToVector2Array(bufferData);
1956
- mesh.setUVs(texturecoords1, 1);
1957
- break;
1958
- case "TEXCOORD_2":
1959
- var texturecoords2 = GLTFUtil.floatBufferToVector2Array(bufferData);
1960
- mesh.setUVs(texturecoords2, 2);
1961
- break;
1962
- case "TEXCOORD_3":
1963
- var texturecoords3 = GLTFUtil.floatBufferToVector2Array(bufferData);
1964
- mesh.setUVs(texturecoords3, 3);
1965
- break;
1966
- case "TEXCOORD_4":
1967
- var texturecoords4 = GLTFUtil.floatBufferToVector2Array(bufferData);
1968
- mesh.setUVs(texturecoords4, 4);
1969
- break;
1970
- case "TEXCOORD_5":
1971
- var texturecoords5 = GLTFUtil.floatBufferToVector2Array(bufferData);
1972
- mesh.setUVs(texturecoords5, 5);
1973
- break;
1974
- case "TEXCOORD_6":
1975
- var texturecoords6 = GLTFUtil.floatBufferToVector2Array(bufferData);
1976
- mesh.setUVs(texturecoords6, 6);
1977
- break;
1978
- case "TEXCOORD_7":
1979
- var texturecoords7 = GLTFUtil.floatBufferToVector2Array(bufferData);
1980
- mesh.setUVs(texturecoords7, 7);
1981
- break;
1982
- case "COLOR_0":
1983
- var colors = GLTFUtil.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
1984
- mesh.setColors(colors);
1985
- break;
1986
- case "TANGENT":
1987
- var tangents = GLTFUtil.floatBufferToVector4Array(bufferData);
1988
- mesh.setTangents(tangents);
1989
- break;
1990
- case "JOINTS_0":
1991
- var joints = GLTFUtil.floatBufferToVector4Array(bufferData);
1992
- mesh.setBoneIndices(joints);
1993
- break;
1994
- case "WEIGHTS_0":
1995
- var weights = GLTFUtil.floatBufferToVector4Array(bufferData);
1996
- mesh.setBoneWeights(weights);
1997
- break;
1998
- }
1999
- }
2000
- // Indices
2001
- if (indices !== undefined) {
2002
- var indexAccessor = gltf.accessors[indices];
2003
- var indexData = getIndexBufferData();
2004
- mesh.setIndices(indexData);
2005
- mesh.addSubMesh(0, indexAccessor.count, mode);
2006
- } else {
2007
- mesh.addSubMesh(0, vertexCount, mode);
2008
- }
2009
- // BlendShapes
2010
- targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
2011
- mesh.uploadData(!keepMeshData);
2012
- return Promise.resolve(mesh);
2013
- };
2014
- return MeshParser;
2015
- }(Parser);
1974
+ return GLTFMeshParser;
1975
+ }(GLTFParser);
2016
1976
  (function() {
2017
- MeshParser._tempVector3 = new miniprogram$1.Vector3();
1977
+ GLTFMeshParser._tempVector3 = new miniprogram$1.Vector3();
2018
1978
  })();
2019
1979
 
2020
- var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2021
- _inherits(SceneParser, Parser1);
2022
- function SceneParser() {
2023
- return Parser1.apply(this, arguments);
1980
+ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
1981
+ _inherits(GLTFSceneParser, GLTFParser1);
1982
+ function GLTFSceneParser() {
1983
+ return GLTFParser1.apply(this, arguments);
2024
1984
  }
2025
- var _proto = SceneParser.prototype;
1985
+ var _proto = GLTFSceneParser.prototype;
2026
1986
  _proto.parse = function parse(context) {
2027
- var glTFResource = context.glTFResource, gltf = context.gltf;
1987
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2028
1988
  var entities = glTFResource.entities;
2029
- var nodes = gltf.nodes, gltfCameras = gltf.cameras;
1989
+ var nodes = glTF.nodes, cameras = glTF.cameras;
2030
1990
  if (!nodes) return;
2031
1991
  var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
2032
- var promises = [];
2033
1992
  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;
1993
+ var glTFNode = nodes[i];
1994
+ var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
2037
1995
  var entity = entities[i];
2038
1996
  if (cameraID !== undefined) {
2039
- this._createCamera(glTFResource, gltfCameras[cameraID], entity);
1997
+ this._createCamera(glTFResource, cameras[cameraID], entity);
2040
1998
  }
2041
1999
  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);
2000
+ this._createRenderer(context, glTFNode, entity);
2048
2001
  }
2002
+ GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
2049
2003
  }
2050
2004
  if (glTFResource.defaultSceneRoot) {
2051
2005
  this._createAnimator(context);
2052
2006
  }
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);
2007
+ defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
2057
2008
  return defaultSceneRootPromiseInfo.promise;
2058
2009
  };
2059
2010
  _proto._createCamera = function _createCamera(context, cameraSchema, entity) {
@@ -2089,8 +2040,9 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2089
2040
  // @todo: use engine camera by default
2090
2041
  camera.enabled = false;
2091
2042
  };
2092
- _proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
2043
+ _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
2093
2044
  var _loop = function(i) {
2045
+ var gltfPrimitive = glTFMeshPrimitives[i];
2094
2046
  var mesh = meshes[meshID][i];
2095
2047
  var renderer = void 0;
2096
2048
  if (skinID !== undefined || blendShapeWeights) {
@@ -2108,32 +2060,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2108
2060
  renderer = entity.addComponent(miniprogram.MeshRenderer);
2109
2061
  renderer.mesh = mesh;
2110
2062
  }
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
- }
2063
+ var materialIndex = gltfPrimitive.material;
2064
+ var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
2065
+ renderer.setMaterial(material);
2066
+ // Enable vertex color if mesh has COLOR_0 vertex element
2067
+ mesh.vertexElements.forEach(function(element) {
2068
+ if (element.semantic === "COLOR_0") {
2069
+ renderer.enableVertexColor = true;
2070
+ }
2071
+ });
2072
+ GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
2126
2073
  };
2127
- var glTFResource = context.glTFResource, gltf = context.gltf;
2128
- var gltfMeshes = gltf.meshes;
2074
+ var glTFResource = context.glTFResource, glTF = context.glTF;
2075
+ var glTFMeshes = glTF.meshes;
2129
2076
  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);
2077
+ var meshID = glTFNode.mesh, skinID = glTFNode.skin;
2078
+ var glTFMesh = glTFMeshes[meshID];
2079
+ var glTFMeshPrimitives = glTFMesh.primitives;
2080
+ var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
2081
+ for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
2137
2082
  };
2138
2083
  _proto._createAnimator = function _createAnimator(context) {
2139
2084
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -2160,25 +2105,25 @@ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2160
2105
  }
2161
2106
  }
2162
2107
  };
2163
- SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2164
- if (!SceneParser._defaultMaterial) {
2165
- SceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
2108
+ GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2109
+ if (!GLTFSceneParser._defaultMaterial) {
2110
+ GLTFSceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
2166
2111
  }
2167
- return SceneParser._defaultMaterial;
2112
+ return GLTFSceneParser._defaultMaterial;
2168
2113
  };
2169
- return SceneParser;
2170
- }(Parser);
2114
+ return GLTFSceneParser;
2115
+ }(GLTFParser);
2171
2116
 
2172
- var SkinParser = /*#__PURE__*/ function(Parser) {
2173
- _inherits(SkinParser, Parser);
2174
- function SkinParser() {
2175
- return Parser.apply(this, arguments);
2117
+ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2118
+ _inherits(GLTFSkinParser, GLTFParser);
2119
+ function GLTFSkinParser() {
2120
+ return GLTFParser.apply(this, arguments);
2176
2121
  }
2177
- var _proto = SkinParser.prototype;
2122
+ var _proto = GLTFSkinParser.prototype;
2178
2123
  _proto.parse = function parse(context) {
2179
- var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
2124
+ var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
2180
2125
  var entities = glTFResource.entities;
2181
- var gltfSkins = gltf.skins;
2126
+ var gltfSkins = glTF.skins;
2182
2127
  if (!gltfSkins) return;
2183
2128
  var count = gltfSkins.length;
2184
2129
  var skins = new Array(count);
@@ -2188,8 +2133,8 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
2188
2133
  var skin = new miniprogram.Skin(name);
2189
2134
  skin.inverseBindMatrices.length = jointCount;
2190
2135
  // parse IBM
2191
- var accessor = gltf.accessors[inverseBindMatrices];
2192
- var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
2136
+ var accessor = glTF.accessors[inverseBindMatrices];
2137
+ var buffer = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
2193
2138
  for(var i1 = 0; i1 < jointCount; i1++){
2194
2139
  var inverseBindMatrix = new miniprogram$1.Matrix();
2195
2140
  inverseBindMatrix.copyFromArray(buffer, i1 * 16);
@@ -2250,52 +2195,55 @@ var SkinParser = /*#__PURE__*/ function(Parser) {
2250
2195
  rootNode = entity1;
2251
2196
  }
2252
2197
  };
2253
- return SkinParser;
2254
- }(Parser);
2198
+ return GLTFSkinParser;
2199
+ }(GLTFParser);
2255
2200
 
2256
- var TextureParser = /*#__PURE__*/ function(Parser) {
2257
- _inherits(TextureParser, Parser);
2258
- function TextureParser() {
2259
- return Parser.apply(this, arguments);
2201
+ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2202
+ _inherits(GLTFTextureParser, GLTFParser);
2203
+ function GLTFTextureParser() {
2204
+ return GLTFParser.apply(this, arguments);
2260
2205
  }
2261
- var _proto = TextureParser.prototype;
2206
+ var _proto = GLTFTextureParser.prototype;
2262
2207
  _proto.parse = function parse(context) {
2263
2208
  var _this = this;
2264
- var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
2209
+ var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
2265
2210
  var engine = glTFResource.engine, url = glTFResource.url;
2266
- if (gltf.textures) {
2211
+ if (glTF.textures) {
2267
2212
  var texturesPromiseInfo = context.texturesPromiseInfo;
2268
- miniprogram.AssetPromise.all(gltf.textures.map(function(param, index) {
2213
+ miniprogram.AssetPromise.all(glTF.textures.map(function(param, index) {
2269
2214
  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;
2215
+ 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
2216
  if (uri) {
2272
2217
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
2273
2218
  var index1 = uri.lastIndexOf(".");
2274
2219
  var ext = uri.substring(index1 + 1);
2275
2220
  var type = ext.startsWith("ktx") ? miniprogram.AssetType.KTX : miniprogram.AssetType.Texture2D;
2276
2221
  return engine.resourceManager.load({
2277
- url: GLTFUtil.parseRelativeUrl(url, uri),
2222
+ url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
2278
2223
  type: type
2279
2224
  }).then(function(texture) {
2280
2225
  if (!texture.name) {
2281
2226
  texture.name = textureName || imageName || "texture_" + index1;
2282
2227
  }
2283
2228
  if (sampler !== undefined) {
2284
- _this._parseSampler(texture, gltf.samplers[sampler]);
2229
+ _this._parseSampler(texture, glTF.samplers[sampler]);
2285
2230
  }
2286
2231
  return texture;
2287
2232
  });
2288
2233
  } else {
2289
- var bufferView = gltf.bufferViews[bufferViewIndex];
2290
- var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
2291
- return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
2234
+ var bufferView = glTF.bufferViews[bufferViewIndex];
2235
+ var buffer = buffers[bufferView.buffer];
2236
+ var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2237
+ return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2292
2238
  var texture = new miniprogram.Texture2D(engine, image.width, image.height);
2293
2239
  texture.setImageSource(image);
2294
2240
  texture.generateMipmaps();
2295
2241
  texture.name = textureName || imageName || "texture_" + index;
2296
2242
  if (sampler !== undefined) {
2297
- _this._parseSampler(texture, gltf.samplers[sampler]);
2243
+ _this._parseSampler(texture, glTF.samplers[sampler]);
2298
2244
  }
2245
+ var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2246
+ context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2299
2247
  return texture;
2300
2248
  });
2301
2249
  }
@@ -2318,36 +2266,38 @@ var TextureParser = /*#__PURE__*/ function(Parser) {
2318
2266
  }
2319
2267
  }
2320
2268
  if (wrapS) {
2321
- texture.wrapModeU = TextureParser._wrapMap[wrapS];
2269
+ texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2322
2270
  }
2323
2271
  if (wrapT) {
2324
- texture.wrapModeV = TextureParser._wrapMap[wrapT];
2272
+ texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2325
2273
  }
2326
2274
  };
2327
- return TextureParser;
2328
- }(Parser);
2275
+ return GLTFTextureParser;
2276
+ }(GLTFParser);
2329
2277
  (function() {
2330
2278
  var _obj;
2331
- 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);
2279
+ 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);
2332
2280
  })();
2333
2281
 
2334
- var Validator = /*#__PURE__*/ function(Parser1) {
2335
- _inherits(Validator, Parser1);
2336
- function Validator() {
2337
- return Parser1.apply(this, arguments);
2282
+ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2283
+ _inherits(GLTFValidator, GLTFParser1);
2284
+ function GLTFValidator() {
2285
+ return GLTFParser1.apply(this, arguments);
2338
2286
  }
2339
- var _proto = Validator.prototype;
2287
+ var _proto = GLTFValidator.prototype;
2340
2288
  _proto.parse = function parse(context) {
2341
- var _context_gltf = context.gltf, version = _context_gltf.asset.version, extensionsUsed = _context_gltf.extensionsUsed, extensionsRequired = _context_gltf.extensionsRequired;
2342
- var gltfVersion = Number(version);
2343
- if (!(gltfVersion >= 2 && gltfVersion < 3)) {
2344
- throw "Only support gltf 2.x.";
2289
+ var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
2290
+ var glTFVersion = Number(version);
2291
+ if (!(glTFVersion >= 2 && glTFVersion < 3)) {
2292
+ throw "Only support glTF 2.x.";
2345
2293
  }
2294
+ var promises = [];
2346
2295
  if (extensionsUsed) {
2347
2296
  miniprogram.Logger.info("extensionsUsed: ", extensionsUsed);
2348
2297
  for(var i = 0; i < extensionsUsed.length; i++){
2349
- if (!Parser.hasExtensionParser(extensionsUsed[i])) {
2350
- miniprogram.Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
2298
+ var extensionUsed = extensionsUsed[i];
2299
+ if (!GLTFParser.hasExtensionParser(extensionUsed)) {
2300
+ miniprogram.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
2351
2301
  }
2352
2302
  }
2353
2303
  }
@@ -2355,68 +2305,68 @@ var Validator = /*#__PURE__*/ function(Parser1) {
2355
2305
  miniprogram.Logger.info("extensionsRequired: " + extensionsRequired);
2356
2306
  for(var i1 = 0; i1 < extensionsRequired.length; i1++){
2357
2307
  var extensionRequired = extensionsRequired[i1];
2358
- if (!Parser.hasExtensionParser(extensionRequired)) {
2308
+ if (!GLTFParser.hasExtensionParser(extensionRequired)) {
2359
2309
  miniprogram.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
2360
2310
  } else {
2361
- Parser.initialize(extensionRequired);
2311
+ promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
2362
2312
  }
2363
2313
  }
2364
2314
  }
2315
+ return miniprogram.AssetPromise.all(promises).then(null);
2365
2316
  };
2366
- return Validator;
2367
- }(Parser);
2317
+ return GLTFValidator;
2318
+ }(GLTFParser);
2368
2319
 
2369
- var GLTFParser = /*#__PURE__*/ function() {
2370
- function GLTFParser(pipes) {
2320
+ /**
2321
+ * GLTF pipeline.
2322
+ */ var GLTFPipeline = /*#__PURE__*/ function() {
2323
+ function GLTFPipeline() {
2324
+ for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
2325
+ parsers[_key] = arguments[_key];
2326
+ }
2371
2327
  var _this = this;
2372
- this._pipes = [];
2373
- pipes.forEach(function(pipe, index) {
2374
- _this._pipes[index] = new pipe();
2328
+ this._parsers = [];
2329
+ parsers.forEach(function(pipe, index) {
2330
+ _this._parsers[index] = new pipe();
2375
2331
  });
2376
2332
  }
2377
- var _proto = GLTFParser.prototype;
2378
- _proto.parse = function parse(context) {
2333
+ var _proto = GLTFPipeline.prototype;
2334
+ /**
2335
+ * @internal
2336
+ */ _proto._parse = function _parse(context) {
2379
2337
  var _this = this;
2380
2338
  var glTFResource = context.glTFResource;
2381
- var lastPipe;
2339
+ var lastParser;
2382
2340
  return new miniprogram.AssetPromise(function(resolve, reject) {
2383
- _this._pipes.forEach(function(parser) {
2384
- if (lastPipe) {
2385
- lastPipe = lastPipe.then(function() {
2341
+ _this._parsers.forEach(function(parser) {
2342
+ if (lastParser) {
2343
+ lastParser = lastParser.then(function() {
2386
2344
  return parser.parse(context);
2387
2345
  });
2388
- if (lastPipe.cancel) {
2389
- context.chainPromises.push(lastPipe);
2346
+ if (lastParser.cancel) {
2347
+ context.chainPromises.push(lastParser);
2390
2348
  }
2391
2349
  } else {
2392
- lastPipe = parser.parse(context);
2350
+ lastParser = parser.parse(context);
2393
2351
  }
2394
2352
  });
2395
- if (lastPipe) {
2396
- lastPipe.then(function() {
2353
+ if (lastParser) {
2354
+ lastParser.then(function() {
2397
2355
  resolve(glTFResource);
2398
2356
  }).catch(reject);
2399
2357
  }
2400
2358
  });
2401
2359
  };
2402
- return GLTFParser;
2360
+ return GLTFPipeline;
2403
2361
  }();
2404
2362
  (function() {
2405
- GLTFParser.defaultPipeline = new GLTFParser([
2406
- BufferParser,
2407
- Validator,
2408
- TextureParser,
2409
- MaterialParser,
2410
- MeshParser,
2411
- EntityParser,
2412
- SkinParser,
2413
- AnimationParser,
2414
- SceneParser$1
2415
- ]);
2363
+ /**
2364
+ * Default pipeline.
2365
+ */ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
2416
2366
  })();
2417
2367
 
2418
2368
  /**
2419
- * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
2369
+ * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
2420
2370
  */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
2421
2371
  _inherits(GLTFResource, EngineObject);
2422
2372
  function GLTFResource(engine, url) {
@@ -2427,12 +2377,9 @@ var GLTFParser = /*#__PURE__*/ function() {
2427
2377
  }
2428
2378
  var _proto = GLTFResource.prototype;
2429
2379
  /**
2430
- * @override
2431
- */ _proto.destroy = function destroy() {
2432
- if (this._destroyed) {
2433
- return;
2434
- }
2435
- EngineObject.prototype.destroy.call(this);
2380
+ * @internal
2381
+ */ _proto._onDestroy = function _onDestroy() {
2382
+ EngineObject.prototype._onDestroy.call(this);
2436
2383
  this.defaultSceneRoot.destroy();
2437
2384
  this.textures = null;
2438
2385
  this.materials = null;
@@ -2443,7 +2390,7 @@ var GLTFParser = /*#__PURE__*/ function() {
2443
2390
  this.cameras = null;
2444
2391
  this.lights = null;
2445
2392
  this.sceneRoots = null;
2446
- this.variants = null;
2393
+ this.extensionsData = null;
2447
2394
  };
2448
2395
  return GLTFResource;
2449
2396
  }(miniprogram.EngineObject);
@@ -2455,14 +2402,16 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2455
2402
  }
2456
2403
  var _proto = GLTFLoader.prototype;
2457
2404
  _proto.load = function load(item, resourceManager) {
2458
- var _item_params;
2459
2405
  var url = item.url;
2460
- var context = new ParserContext(url);
2406
+ var params = item.params;
2407
+ var context = new GLTFParserContext(url);
2461
2408
  var glTFResource = new GLTFResource(resourceManager.engine, url);
2409
+ var restorer = new GLTFContentRestorer(glTFResource);
2462
2410
  var masterPromiseInfo = context.masterPromiseInfo;
2411
+ context.contentRestorer = restorer;
2463
2412
  context.glTFResource = glTFResource;
2464
- var _item_params_keepMeshData;
2465
- context.keepMeshData = (_item_params_keepMeshData = (_item_params = item.params) == null ? void 0 : _item_params.keepMeshData) != null ? _item_params_keepMeshData : false;
2413
+ var _params_keepMeshData;
2414
+ context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
2466
2415
  masterPromiseInfo.onCancel(function() {
2467
2416
  var chainPromises = context.chainPromises;
2468
2417
  for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
@@ -2470,7 +2419,10 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2470
2419
  promise.cancel();
2471
2420
  }
2472
2421
  });
2473
- GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
2422
+ ((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
2423
+ resourceManager.addContentRestorer(restorer);
2424
+ masterPromiseInfo.resolve(glTFResource);
2425
+ }).catch(function(e) {
2474
2426
  console.error(e);
2475
2427
  masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
2476
2428
  });
@@ -2479,7 +2431,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2479
2431
  return GLTFLoader;
2480
2432
  }(miniprogram.Loader);
2481
2433
  GLTFLoader = __decorate([
2482
- miniprogram.resourceLoader(miniprogram.AssetType.Prefab, [
2434
+ miniprogram.resourceLoader(miniprogram.AssetType.GLTF, [
2483
2435
  "gltf",
2484
2436
  "glb"
2485
2437
  ])
@@ -2565,7 +2517,7 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
2565
2517
  return textureArray;
2566
2518
  };
2567
2519
  HDRLoader1._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
2568
- var theta = Math.atan2(vDir.z, -vDir.x);
2520
+ var theta = Math.atan2(vDir.z, vDir.x);
2569
2521
  var phi = Math.acos(vDir.y);
2570
2522
  while(theta < -PI){
2571
2523
  theta += 2 * PI;
@@ -2867,40 +2819,40 @@ function getEngineFormat(internalFormat) {
2867
2819
  // case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT3_EXT:
2868
2820
  // case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2869
2821
  // break;
2870
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
2822
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
2871
2823
  return miniprogram.TextureFormat.DXT1;
2872
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2824
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2873
2825
  return miniprogram.TextureFormat.DXT5;
2874
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
2826
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
2875
2827
  return miniprogram.TextureFormat.ETC1_RGB;
2876
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_ETC2:
2828
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_ETC2:
2877
2829
  return miniprogram.TextureFormat.ETC2_RGB;
2878
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
2830
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
2879
2831
  return miniprogram.TextureFormat.ETC2_RGBA5;
2880
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
2832
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
2881
2833
  return miniprogram.TextureFormat.ETC2_RGBA8;
2882
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
2834
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
2883
2835
  return miniprogram.TextureFormat.PVRTC_RGB2;
2884
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
2836
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
2885
2837
  return miniprogram.TextureFormat.PVRTC_RGBA2;
2886
- case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
2838
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
2887
2839
  return miniprogram.TextureFormat.PVRTC_RGB4;
2888
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
2840
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
2889
2841
  return miniprogram.TextureFormat.PVRTC_RGBA4;
2890
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
2842
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
2891
2843
  return miniprogram.TextureFormat.ASTC_4x4;
2892
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
2844
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
2893
2845
  return miniprogram.TextureFormat.ASTC_5x5;
2894
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
2846
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
2895
2847
  return miniprogram.TextureFormat.ASTC_6x6;
2896
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
2848
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
2897
2849
  return miniprogram.TextureFormat.ASTC_8x8;
2898
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
2850
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
2899
2851
  return miniprogram.TextureFormat.ASTC_10x10;
2900
- case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
2852
+ case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
2901
2853
  return miniprogram.TextureFormat.ASTC_12x12;
2902
2854
  default:
2903
- var formatName = miniprogram$3.GLCompressedTextureInternalFormat[internalFormat];
2855
+ var formatName = miniprogram$2.GLCompressedTextureInternalFormat[internalFormat];
2904
2856
  throw new Error("this format is not supported in Galacean Engine: " + formatName);
2905
2857
  }
2906
2858
  }
@@ -3074,6 +3026,15 @@ KTXLoader = __decorate([
3074
3026
  ])
3075
3027
  ], KTXLoader);
3076
3028
 
3029
+ function parseProperty(object, key, value) {
3030
+ if (typeof value === "object") {
3031
+ for(var subKey in value){
3032
+ parseProperty(object[key], subKey, value[subKey]);
3033
+ }
3034
+ } else {
3035
+ object[key] = value;
3036
+ }
3037
+ }
3077
3038
  var MaterialLoader = /*#__PURE__*/ function(Loader) {
3078
3039
  _inherits(MaterialLoader, Loader);
3079
3040
  function MaterialLoader() {
@@ -3085,7 +3046,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
3085
3046
  return new miniprogram.AssetPromise(function(resolve, reject) {
3086
3047
  _this.request(item.url, _extends({}, item, {
3087
3048
  type: "json"
3088
- })).then(function(json) {
3049
+ })).then(function(materialSchema) {
3089
3050
  var _loop = function(key) {
3090
3051
  var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
3091
3052
  switch(type){
@@ -3113,27 +3074,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
3113
3074
  }
3114
3075
  };
3115
3076
  var engine = resourceManager.engine;
3116
- var name = json.name, shader = json.shader, shaderData = json.shaderData, macros = json.macros, renderState = json.renderState;
3117
- var material;
3118
- switch(shader){
3119
- case "pbr":
3120
- material = new miniprogram.PBRMaterial(engine);
3121
- break;
3122
- case "pbr-specular":
3123
- material = new miniprogram.PBRSpecularMaterial(engine);
3124
- break;
3125
- case "unlit":
3126
- material = new miniprogram.UnlitMaterial(engine);
3127
- break;
3128
- case "blinn-phong":
3129
- material = new miniprogram.BlinnPhongMaterial(engine);
3130
- break;
3131
- case "bake-pbr":
3132
- // @todo refactor custom shader later
3133
- // @ts-ignore
3134
- material = new miniprogram.PBRBaseMaterial(engine, miniprogram.Shader.find("bake-pbr"));
3135
- break;
3136
- }
3077
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
3078
+ var material = new miniprogram.Material(engine, miniprogram.Shader.find(shader));
3137
3079
  material.name = name;
3138
3080
  var texturePromises = new Array();
3139
3081
  var materialShaderData = material.shaderData;
@@ -3146,9 +3088,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
3146
3088
  materialShaderData.enableMacro(name1, value);
3147
3089
  }
3148
3090
  }
3149
- for(var key1 in renderState){
3150
- material[key1] = renderState[key1];
3151
- }
3091
+ parseProperty(material, "renderState", renderState);
3152
3092
  return Promise.all(texturePromises).then(function() {
3153
3093
  resolve(material);
3154
3094
  });
@@ -3248,7 +3188,7 @@ var BufferReader = /*#__PURE__*/ function() {
3248
3188
  var strByteLength = this.nextUint16();
3249
3189
  var uint8Array = new Uint8Array(this.buffer, this._offset, strByteLength);
3250
3190
  this._offset += strByteLength;
3251
- return GLTFUtil.decodeText(uint8Array);
3191
+ return miniprogram.Utils.decodeText(uint8Array);
3252
3192
  };
3253
3193
  /**
3254
3194
  * image data 放在最后
@@ -3333,8 +3273,8 @@ var FileHeader = /*#__PURE__*/ function() {
3333
3273
  var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
3334
3274
  var nameLen = dataView.getUint16(7 + typeLen, true);
3335
3275
  var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
3336
- var name = GLTFUtil.decodeText(nameUint8Array);
3337
- var type = GLTFUtil.decodeText(typeUint8Array);
3276
+ var name = miniprogram.Utils.decodeText(nameUint8Array);
3277
+ var type = miniprogram.Utils.decodeText(typeUint8Array);
3338
3278
  var header = new FileHeader();
3339
3279
  header.totalLength = totalLen;
3340
3280
  header.name = name;
@@ -3903,6 +3843,12 @@ exports.AnimationClipDecoder = __decorate([
3903
3843
  decoder("AnimationClip")
3904
3844
  ], exports.AnimationClipDecoder);
3905
3845
 
3846
+ exports.SpecularMode = void 0;
3847
+ (function(SpecularMode) {
3848
+ SpecularMode["Sky"] = "Sky";
3849
+ SpecularMode["Custom"] = "Custom";
3850
+ })(exports.SpecularMode || (exports.SpecularMode = {}));
3851
+
3906
3852
  var SceneParserContext = /*#__PURE__*/ function() {
3907
3853
  function SceneParserContext(originalData, scene) {
3908
3854
  this.originalData = originalData;
@@ -4185,7 +4131,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
4185
4131
  var atlasItem = atlasItems[i];
4186
4132
  if (atlasItem.img) {
4187
4133
  chainPromises.push(resourceManager.load({
4188
- url: atlasItem.img,
4134
+ url: miniprogram.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
4189
4135
  type: miniprogram.AssetType.Texture2D,
4190
4136
  params: {
4191
4137
  format: format,
@@ -4284,6 +4230,30 @@ SpriteLoader = __decorate([
4284
4230
  ], false)
4285
4231
  ], SpriteLoader);
4286
4232
 
4233
+ /**
4234
+ * @internal
4235
+ */ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4236
+ _inherits(Texture2DContentRestorer, ContentRestorer);
4237
+ function Texture2DContentRestorer(resource, url, requestConfig) {
4238
+ var _this;
4239
+ _this = ContentRestorer.call(this, resource) || this;
4240
+ _this.url = url;
4241
+ _this.requestConfig = requestConfig;
4242
+ return _this;
4243
+ }
4244
+ var _proto = Texture2DContentRestorer.prototype;
4245
+ _proto.restoreContent = function restoreContent() {
4246
+ var _this = this;
4247
+ return miniprogram.request(this.url, this.requestConfig).then(function(image) {
4248
+ var resource = _this.resource;
4249
+ resource.setImageSource(image);
4250
+ resource.generateMipmaps();
4251
+ return resource;
4252
+ });
4253
+ };
4254
+ return Texture2DContentRestorer;
4255
+ }(miniprogram.ContentRestorer);
4256
+
4287
4257
  var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4288
4258
  _inherits(Texture2DLoader, Loader);
4289
4259
  function Texture2DLoader() {
@@ -4293,19 +4263,20 @@ var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4293
4263
  _proto.load = function load(item, resourceManager) {
4294
4264
  var _this = this;
4295
4265
  return new miniprogram.AssetPromise(function(resolve, reject) {
4296
- _this.request(item.url, _extends({}, item, {
4266
+ var url = item.url;
4267
+ var requestConfig = _extends({}, item, {
4297
4268
  type: "image"
4298
- })).then(function(image) {
4299
- var _item_params;
4300
- var params = (_item_params = item.params) != null ? _item_params : {};
4301
- var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params.format, params.mipmap);
4302
- /** @ts-ignore */ if (!texture._platformTexture) return;
4269
+ });
4270
+ _this.request(url, requestConfig).then(function(image) {
4271
+ var params = item.params;
4272
+ var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
4303
4273
  texture.setImageSource(image);
4304
4274
  texture.generateMipmaps();
4305
- if (item.url.indexOf("data:") !== 0) {
4306
- var splitPath = item.url.split("/");
4307
- texture.name = splitPath[splitPath.length - 1];
4275
+ if (url.indexOf("data:") !== 0) {
4276
+ var index = url.lastIndexOf("/");
4277
+ texture.name = url.substring(index + 1);
4308
4278
  }
4279
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
4309
4280
  resolve(texture);
4310
4281
  }).catch(function(e) {
4311
4282
  reject(e);
@@ -4323,6 +4294,38 @@ Texture2DLoader = __decorate([
4323
4294
  ])
4324
4295
  ], Texture2DLoader);
4325
4296
 
4297
+ /**
4298
+ * @internal
4299
+ */ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4300
+ _inherits(TextureCubeContentRestorer, ContentRestorer);
4301
+ function TextureCubeContentRestorer(resource, urls, requestConfig) {
4302
+ var _this;
4303
+ _this = ContentRestorer.call(this, resource) || this;
4304
+ _this.urls = urls;
4305
+ _this.requestConfig = requestConfig;
4306
+ return _this;
4307
+ }
4308
+ var _proto = TextureCubeContentRestorer.prototype;
4309
+ _proto.restoreContent = function restoreContent() {
4310
+ var _this = this;
4311
+ return new miniprogram.AssetPromise(function(resolve, reject) {
4312
+ Promise.all(_this.urls.map(function(url) {
4313
+ return miniprogram.request(url, _this.requestConfig);
4314
+ })).then(function(images) {
4315
+ var resource = _this.resource;
4316
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4317
+ resource.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4318
+ }
4319
+ resource.generateMipmaps();
4320
+ resolve(resource);
4321
+ }).catch(function(e) {
4322
+ reject(e);
4323
+ });
4324
+ });
4325
+ };
4326
+ return TextureCubeContentRestorer;
4327
+ }(miniprogram.ContentRestorer);
4328
+
4326
4329
  var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4327
4330
  _inherits(TextureCubeLoader, Loader);
4328
4331
  function TextureCubeLoader() {
@@ -4332,23 +4335,25 @@ var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4332
4335
  _proto.load = function load(item, resourceManager) {
4333
4336
  var _this = this;
4334
4337
  return new miniprogram.AssetPromise(function(resolve, reject) {
4335
- Promise.all(item.urls.map(function(url) {
4336
- return _this.request(url, _extends({}, item, {
4337
- type: "image"
4338
- }));
4338
+ var urls = item.urls;
4339
+ var requestConfig = _extends({}, item, {
4340
+ type: "image"
4341
+ });
4342
+ Promise.all(urls.map(function(url) {
4343
+ return _this.request(url, requestConfig);
4339
4344
  })).then(function(images) {
4340
4345
  var _images_ = images[0], width = _images_.width, height = _images_.height;
4341
4346
  if (width !== height) {
4342
4347
  console.error("The cube texture must have the same width and height");
4343
4348
  return;
4344
4349
  }
4345
- var tex = new miniprogram.TextureCube(resourceManager.engine, width);
4346
- /** @ts-ignore */ if (!tex._platformTexture) return;
4350
+ var texture = new miniprogram.TextureCube(resourceManager.engine, width);
4347
4351
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4348
- tex.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4352
+ texture.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4349
4353
  }
4350
- tex.generateMipmaps();
4351
- resolve(tex);
4354
+ texture.generateMipmaps();
4355
+ resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
4356
+ resolve(texture);
4352
4357
  }).catch(function(e) {
4353
4358
  reject(e);
4354
4359
  });
@@ -4362,6 +4367,30 @@ TextureCubeLoader = __decorate([
4362
4367
  ])
4363
4368
  ], TextureCubeLoader);
4364
4369
 
4370
+ var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
4371
+ _inherits(AnimationClipLoader, Loader);
4372
+ function AnimationClipLoader() {
4373
+ return Loader.apply(this, arguments);
4374
+ }
4375
+ var _proto = AnimationClipLoader.prototype;
4376
+ _proto.load = function load(item, resourceManager) {
4377
+ var _this = this;
4378
+ return new miniprogram.AssetPromise(function(resolve, reject) {
4379
+ _this.request(item.url, _extends({}, item, {
4380
+ type: "arraybuffer"
4381
+ })).then(function(data) {
4382
+ return decode(data, resourceManager.engine);
4383
+ }).catch(reject);
4384
+ });
4385
+ };
4386
+ return AnimationClipLoader;
4387
+ }(miniprogram.Loader);
4388
+ AnimationClipLoader = __decorate([
4389
+ miniprogram.resourceLoader(miniprogram.AssetType.AnimationClip, [
4390
+ "ani"
4391
+ ])
4392
+ ], AnimationClipLoader);
4393
+
4365
4394
  var SceneLoader = /*#__PURE__*/ function(Loader) {
4366
4395
  _inherits(SceneLoader, Loader);
4367
4396
  function SceneLoader() {
@@ -4378,47 +4407,63 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
4378
4407
  // @ts-ignore
4379
4408
  engine.resourceManager.initVirtualResources(data.files);
4380
4409
  return SceneParser.parse(engine, data).then(function(scene) {
4410
+ var promises = [];
4381
4411
  // parse ambient light
4382
4412
  var ambient = data.scene.ambient;
4383
- var ambientLightPromise = Promise.resolve();
4384
- if (ambient.ambientLight) {
4385
- ambientLightPromise = resourceManager// @ts-ignore
4386
- .getResourceByRef(data.scene.ambient.ambientLight).then(function(light) {
4387
- scene.ambientLight = light;
4413
+ var useCustomAmbient = ambient.specularMode === "Custom";
4414
+ if (useCustomAmbient && ambient.customAmbientLight) {
4415
+ // @ts-ignore
4416
+ // prettier-ignore
4417
+ var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
4418
+ scene.ambientLight = ambientLight;
4388
4419
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
4389
4420
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
4421
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
4422
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
4390
4423
  });
4391
- } else {
4392
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
4393
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
4394
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
4424
+ promises.push(customAmbientPromise);
4425
+ } else if (!useCustomAmbient && ambient.ambientLight) {
4426
+ // @ts-ignore
4427
+ // prettier-ignore
4428
+ var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
4429
+ scene.ambientLight = ambientLight;
4430
+ scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
4431
+ scene.ambientLight.specularIntensity = ambient.specularIntensity;
4432
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
4433
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
4434
+ });
4435
+ promises.push(ambientLightPromise);
4395
4436
  }
4396
4437
  var background = data.scene.background;
4397
4438
  scene.background.mode = background.mode;
4398
- var backgroundPromise = Promise.resolve();
4399
4439
  switch(scene.background.mode){
4400
4440
  case miniprogram.BackgroundMode.SolidColor:
4401
4441
  scene.background.solidColor.copyFrom(background.color);
4402
4442
  break;
4403
4443
  case miniprogram.BackgroundMode.Sky:
4404
- if (background.sky) {
4444
+ if (background.skyMesh && background.skyMaterial) {
4445
+ // @ts-ignore
4446
+ var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
4447
+ scene.background.sky.mesh = mesh;
4448
+ });
4405
4449
  // @ts-ignore
4406
- backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
4407
- var sky = scene.background.sky;
4408
- var skyMaterial = new miniprogram.SkyBoxMaterial(engine);
4409
- skyMaterial.textureCubeMap = light.specularTexture;
4410
- skyMaterial.textureDecodeRGBM = true;
4411
- sky.material = skyMaterial;
4412
- sky.mesh = miniprogram.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
4450
+ // prettier-ignore
4451
+ var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
4452
+ scene.background.sky.material = material;
4413
4453
  });
4454
+ promises.push(skyMeshPromise, skyMaterialPromise);
4455
+ } else {
4456
+ miniprogram.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
4414
4457
  }
4415
4458
  break;
4416
4459
  case miniprogram.BackgroundMode.Texture:
4417
4460
  if (background.texture) {
4418
4461
  // @ts-ignore
4419
- backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
4462
+ // prettier-ignore
4463
+ var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
4420
4464
  scene.background.texture = texture;
4421
4465
  });
4466
+ promises.push(backgroundPromise);
4422
4467
  }
4423
4468
  break;
4424
4469
  }
@@ -4430,10 +4475,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
4430
4475
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
4431
4476
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
4432
4477
  }
4433
- return Promise.all([
4434
- ambientLightPromise,
4435
- backgroundPromise
4436
- ]).then(function() {
4478
+ return Promise.all(promises).then(function() {
4437
4479
  resolve(scene);
4438
4480
  });
4439
4481
  });
@@ -4462,10 +4504,408 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
4462
4504
  });
4463
4505
  }));
4464
4506
 
4507
+ var _KHR_draco_mesh_compression;
4508
+ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
4509
+ _inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
4510
+ function KHR_draco_mesh_compression1() {
4511
+ return GLTFExtensionParser.apply(this, arguments);
4512
+ }
4513
+ var _proto = KHR_draco_mesh_compression1.prototype;
4514
+ _proto.initialize = function initialize() {
4515
+ if (!KHR_draco_mesh_compression._decoder) {
4516
+ KHR_draco_mesh_compression._decoder = new miniprogram$3.DRACODecoder();
4517
+ }
4518
+ };
4519
+ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
4520
+ var _this = this;
4521
+ var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
4522
+ var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
4523
+ var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
4524
+ var attributeMap = {};
4525
+ var attributeTypeMap = {};
4526
+ for(var attributeName in gltfAttributeMap){
4527
+ attributeMap[attributeName] = gltfAttributeMap[attributeName];
4528
+ }
4529
+ for(var attributeName1 in glTFPrimitive.attributes){
4530
+ if (gltfAttributeMap[attributeName1] !== undefined) {
4531
+ var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
4532
+ attributeTypeMap[attributeName1] = GLTFUtils.getComponentType(accessorDef.componentType).name;
4533
+ }
4534
+ }
4535
+ var indexAccessor = accessors[glTFPrimitive.indices];
4536
+ var indexType = GLTFUtils.getComponentType(indexAccessor.componentType).name;
4537
+ var taskConfig = {
4538
+ attributeIDs: attributeMap,
4539
+ attributeTypes: attributeTypeMap,
4540
+ useUniqueIDs: true,
4541
+ indexType: indexType
4542
+ };
4543
+ var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4544
+ return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4545
+ var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
4546
+ return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4547
+ for(var j = 0; j < decodedGeometry.attributes.length; j++){
4548
+ if (decodedGeometry.attributes[j].name === attributeSemantic) {
4549
+ return decodedGeometry.attributes[j].array;
4550
+ }
4551
+ }
4552
+ return null;
4553
+ }, function(attributeSemantic, shapeIndex) {
4554
+ throw "BlendShape animation is not supported when using draco.";
4555
+ }, function() {
4556
+ return decodedGeometry.index.array;
4557
+ }, context.keepMeshData);
4558
+ });
4559
+ };
4560
+ _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
4561
+ var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
4562
+ var vertexCount;
4563
+ var accessors = gltf.accessors;
4564
+ var accessor = accessors[attributes["POSITION"]];
4565
+ var positionBuffer = getVertexBufferData("POSITION");
4566
+ var positions = GLTFUtils.floatBufferToVector3Array(positionBuffer);
4567
+ mesh.setPositions(positions);
4568
+ var bounds = mesh.bounds;
4569
+ vertexCount = accessor.count;
4570
+ if (accessor.min && accessor.max) {
4571
+ bounds.min.copyFromArray(accessor.min);
4572
+ bounds.max.copyFromArray(accessor.max);
4573
+ } else {
4574
+ var position = KHR_draco_mesh_compression._tempVector3;
4575
+ var min = bounds.min, max = bounds.max;
4576
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
4577
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
4578
+ var stride = positionBuffer.length / vertexCount;
4579
+ for(var j = 0; j < vertexCount; j++){
4580
+ var offset = j * stride;
4581
+ position.copyFromArray(positionBuffer, offset);
4582
+ miniprogram$1.Vector3.min(min, position, min);
4583
+ miniprogram$1.Vector3.max(max, position, max);
4584
+ }
4585
+ }
4586
+ for(var attributeSemantic in attributes){
4587
+ if (attributeSemantic === "POSITION") {
4588
+ continue;
4589
+ }
4590
+ var bufferData = getVertexBufferData(attributeSemantic);
4591
+ switch(attributeSemantic){
4592
+ case "NORMAL":
4593
+ var normals = GLTFUtils.floatBufferToVector3Array(bufferData);
4594
+ mesh.setNormals(normals);
4595
+ break;
4596
+ case "TEXCOORD_0":
4597
+ var texturecoords = GLTFUtils.floatBufferToVector2Array(bufferData);
4598
+ mesh.setUVs(texturecoords, 0);
4599
+ break;
4600
+ case "TEXCOORD_1":
4601
+ var texturecoords1 = GLTFUtils.floatBufferToVector2Array(bufferData);
4602
+ mesh.setUVs(texturecoords1, 1);
4603
+ break;
4604
+ case "TEXCOORD_2":
4605
+ var texturecoords2 = GLTFUtils.floatBufferToVector2Array(bufferData);
4606
+ mesh.setUVs(texturecoords2, 2);
4607
+ break;
4608
+ case "TEXCOORD_3":
4609
+ var texturecoords3 = GLTFUtils.floatBufferToVector2Array(bufferData);
4610
+ mesh.setUVs(texturecoords3, 3);
4611
+ break;
4612
+ case "TEXCOORD_4":
4613
+ var texturecoords4 = GLTFUtils.floatBufferToVector2Array(bufferData);
4614
+ mesh.setUVs(texturecoords4, 4);
4615
+ break;
4616
+ case "TEXCOORD_5":
4617
+ var texturecoords5 = GLTFUtils.floatBufferToVector2Array(bufferData);
4618
+ mesh.setUVs(texturecoords5, 5);
4619
+ break;
4620
+ case "TEXCOORD_6":
4621
+ var texturecoords6 = GLTFUtils.floatBufferToVector2Array(bufferData);
4622
+ mesh.setUVs(texturecoords6, 6);
4623
+ break;
4624
+ case "TEXCOORD_7":
4625
+ var texturecoords7 = GLTFUtils.floatBufferToVector2Array(bufferData);
4626
+ mesh.setUVs(texturecoords7, 7);
4627
+ break;
4628
+ case "COLOR_0":
4629
+ var colors = GLTFUtils.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
4630
+ mesh.setColors(colors);
4631
+ break;
4632
+ case "TANGENT":
4633
+ var tangents = GLTFUtils.floatBufferToVector4Array(bufferData);
4634
+ mesh.setTangents(tangents);
4635
+ break;
4636
+ case "JOINTS_0":
4637
+ var joints = GLTFUtils.floatBufferToVector4Array(bufferData);
4638
+ mesh.setBoneIndices(joints);
4639
+ break;
4640
+ case "WEIGHTS_0":
4641
+ var weights = GLTFUtils.floatBufferToVector4Array(bufferData);
4642
+ mesh.setBoneWeights(weights);
4643
+ break;
4644
+ }
4645
+ }
4646
+ // Indices
4647
+ if (indices !== undefined) {
4648
+ var indexAccessor = gltf.accessors[indices];
4649
+ var indexData = getIndexBufferData();
4650
+ mesh.setIndices(indexData);
4651
+ mesh.addSubMesh(0, indexAccessor.count, mode);
4652
+ } else {
4653
+ mesh.addSubMesh(0, vertexCount, mode);
4654
+ }
4655
+ // BlendShapes
4656
+ targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
4657
+ mesh.uploadData(!keepMeshData);
4658
+ return Promise.resolve(mesh);
4659
+ };
4660
+ return KHR_draco_mesh_compression1;
4661
+ }(GLTFExtensionParser), function() {
4662
+ _KHR_draco_mesh_compression._tempVector3 = new miniprogram$1.Vector3();
4663
+ }(), _KHR_draco_mesh_compression);
4664
+ KHR_draco_mesh_compression = __decorate([
4665
+ registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
4666
+ ], KHR_draco_mesh_compression);
4667
+
4668
+ var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
4669
+ _inherits(KHR_lights_punctual, GLTFExtensionParser);
4670
+ function KHR_lights_punctual() {
4671
+ return GLTFExtensionParser.apply(this, arguments);
4672
+ }
4673
+ var _proto = KHR_lights_punctual.prototype;
4674
+ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
4675
+ var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
4676
+ var lightSchema = lightsSchema[extensionSchema.light];
4677
+ 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;
4678
+ var glTFResource = context.glTFResource;
4679
+ var light;
4680
+ if (type === "directional") {
4681
+ light = entity.addComponent(miniprogram.DirectLight);
4682
+ } else if (type === "point") {
4683
+ light = entity.addComponent(miniprogram.PointLight);
4684
+ } else if (type === "spot") {
4685
+ light = entity.addComponent(miniprogram.SpotLight);
4686
+ }
4687
+ if (color) {
4688
+ light.color.set(color[0], color[1], color[2], 1);
4689
+ }
4690
+ light.intensity = intensity;
4691
+ if (range && !_instanceof(light, miniprogram.DirectLight)) {
4692
+ light.distance = range;
4693
+ }
4694
+ if (spot && _instanceof(light, miniprogram.SpotLight)) {
4695
+ 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;
4696
+ light.angle = innerConeAngle;
4697
+ light.penumbra = outerConeAngle - innerConeAngle;
4698
+ }
4699
+ if (!glTFResource.lights) glTFResource.lights = [];
4700
+ glTFResource.lights.push(light);
4701
+ };
4702
+ return KHR_lights_punctual;
4703
+ }(GLTFExtensionParser);
4704
+ KHR_lights_punctual = __decorate([
4705
+ registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
4706
+ ], KHR_lights_punctual);
4707
+
4708
+ var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
4709
+ _inherits(KHR_materials_clearcoat, GLTFExtensionParser);
4710
+ function KHR_materials_clearcoat() {
4711
+ return GLTFExtensionParser.apply(this, arguments);
4712
+ }
4713
+ var _proto = KHR_materials_clearcoat.prototype;
4714
+ _proto.additiveParse = function additiveParse(context, material, schema) {
4715
+ var textures = context.glTFResource.textures;
4716
+ 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;
4717
+ material.clearCoat = clearcoatFactor;
4718
+ material.clearCoatRoughness = clearcoatRoughnessFactor;
4719
+ if (clearcoatTexture) {
4720
+ material.clearCoatTexture = textures[clearcoatTexture.index];
4721
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
4722
+ }
4723
+ if (clearcoatRoughnessTexture) {
4724
+ material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
4725
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
4726
+ }
4727
+ if (clearcoatNormalTexture) {
4728
+ material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
4729
+ GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
4730
+ }
4731
+ };
4732
+ return KHR_materials_clearcoat;
4733
+ }(GLTFExtensionParser);
4734
+ KHR_materials_clearcoat = __decorate([
4735
+ registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
4736
+ ], KHR_materials_clearcoat);
4737
+
4738
+ var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
4739
+ _inherits(KHR_materials_ior, GLTFExtensionParser);
4740
+ function KHR_materials_ior() {
4741
+ return GLTFExtensionParser.apply(this, arguments);
4742
+ }
4743
+ var _proto = KHR_materials_ior.prototype;
4744
+ _proto.additiveParse = function additiveParse(context, material, schema) {
4745
+ var _schema_ior = schema.ior, ior = _schema_ior === void 0 ? 1.5 : _schema_ior;
4746
+ material.ior = ior;
4747
+ };
4748
+ return KHR_materials_ior;
4749
+ }(GLTFExtensionParser);
4750
+ KHR_materials_ior = __decorate([
4751
+ registerGLTFExtension("KHR_materials_ior", exports.GLTFExtensionMode.AdditiveParse)
4752
+ ], KHR_materials_ior);
4753
+
4754
+ var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
4755
+ _inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
4756
+ function KHR_materials_pbrSpecularGlossiness() {
4757
+ return GLTFExtensionParser.apply(this, arguments);
4758
+ }
4759
+ var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
4760
+ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
4761
+ var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
4762
+ var material = new miniprogram.PBRSpecularMaterial(engine);
4763
+ var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
4764
+ if (diffuseFactor) {
4765
+ 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]);
4766
+ }
4767
+ if (diffuseTexture) {
4768
+ material.baseTexture = textures[diffuseTexture.index];
4769
+ GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
4770
+ }
4771
+ if (specularFactor) {
4772
+ material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
4773
+ }
4774
+ if (glossinessFactor !== undefined) {
4775
+ material.glossiness = glossinessFactor;
4776
+ }
4777
+ if (specularGlossinessTexture) {
4778
+ material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
4779
+ GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
4780
+ }
4781
+ material.name = ownerSchema.name;
4782
+ GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4783
+ return material;
4784
+ };
4785
+ return KHR_materials_pbrSpecularGlossiness;
4786
+ }(GLTFExtensionParser);
4787
+ KHR_materials_pbrSpecularGlossiness = __decorate([
4788
+ registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
4789
+ ], KHR_materials_pbrSpecularGlossiness);
4790
+
4791
+ var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
4792
+ _inherits(KHR_materials_unlit, GLTFExtensionParser);
4793
+ function KHR_materials_unlit() {
4794
+ return GLTFExtensionParser.apply(this, arguments);
4795
+ }
4796
+ var _proto = KHR_materials_unlit.prototype;
4797
+ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
4798
+ var engine = context.glTFResource.engine;
4799
+ var material = new miniprogram.UnlitMaterial(engine);
4800
+ material.name = ownerSchema.name;
4801
+ GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4802
+ return material;
4803
+ };
4804
+ return KHR_materials_unlit;
4805
+ }(GLTFExtensionParser);
4806
+ KHR_materials_unlit = __decorate([
4807
+ registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
4808
+ ], KHR_materials_unlit);
4809
+
4810
+ var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
4811
+ _inherits(KHR_mesh_quantization, GLTFExtensionParser);
4812
+ function KHR_mesh_quantization() {
4813
+ return GLTFExtensionParser.apply(this, arguments);
4814
+ }
4815
+ return KHR_mesh_quantization;
4816
+ }(GLTFExtensionParser);
4817
+ KHR_mesh_quantization = __decorate([
4818
+ registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
4819
+ ], KHR_mesh_quantization);
4820
+
4821
+ var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
4822
+ _inherits(KHR_texture_transform, GLTFExtensionParser);
4823
+ function KHR_texture_transform() {
4824
+ return GLTFExtensionParser.apply(this, arguments);
4825
+ }
4826
+ var _proto = KHR_texture_transform.prototype;
4827
+ _proto.additiveParse = function additiveParse(context, material, schema) {
4828
+ var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
4829
+ if (offset) {
4830
+ material.tilingOffset.z = offset[0];
4831
+ material.tilingOffset.w = offset[1];
4832
+ }
4833
+ if (scale) {
4834
+ material.tilingOffset.x = scale[0];
4835
+ material.tilingOffset.y = scale[1];
4836
+ }
4837
+ if (rotation) {
4838
+ miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
4839
+ }
4840
+ if (texCoord) {
4841
+ miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
4842
+ }
4843
+ };
4844
+ return KHR_texture_transform;
4845
+ }(GLTFExtensionParser);
4846
+ KHR_texture_transform = __decorate([
4847
+ registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
4848
+ ], KHR_texture_transform);
4849
+
4850
+ var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser) {
4851
+ _inherits(GALACEAN_materials_remap, GLTFExtensionParser);
4852
+ function GALACEAN_materials_remap() {
4853
+ return GLTFExtensionParser.apply(this, arguments);
4854
+ }
4855
+ var _proto = GALACEAN_materials_remap.prototype;
4856
+ _proto.createAndParse = function createAndParse(context, schema) {
4857
+ var engine = context.glTFResource.engine;
4858
+ // @ts-ignore
4859
+ return engine.resourceManager.getResourceByRef(schema);
4860
+ };
4861
+ return GALACEAN_materials_remap;
4862
+ }(GLTFExtensionParser);
4863
+ GALACEAN_materials_remap = __decorate([
4864
+ registerGLTFExtension("GALACEAN_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
4865
+ ], GALACEAN_materials_remap);
4866
+
4867
+ var GALACEAN_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
4868
+ _inherits(GALACEAN_animation_event, GLTFExtensionParser);
4869
+ function GALACEAN_animation_event() {
4870
+ return GLTFExtensionParser.apply(this, arguments);
4871
+ }
4872
+ var _proto = GALACEAN_animation_event.prototype;
4873
+ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
4874
+ context.glTFResource.engine;
4875
+ var events = schema.events;
4876
+ events.map(function(eventData) {
4877
+ var event = new miniprogram.AnimationEvent();
4878
+ event.functionName = eventData.functionName;
4879
+ event.time = eventData.time;
4880
+ event.parameter = eventData.parameter;
4881
+ animationClip.addEvent(event);
4882
+ });
4883
+ };
4884
+ return GALACEAN_animation_event;
4885
+ }(GLTFExtensionParser);
4886
+ GALACEAN_animation_event = __decorate([
4887
+ registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
4888
+ ], GALACEAN_animation_event);
4889
+
4465
4890
  exports.ComponentMap = ComponentMap;
4891
+ exports.GLTFAnimationParser = GLTFAnimationParser;
4892
+ exports.GLTFBufferParser = GLTFBufferParser;
4893
+ exports.GLTFEntityParser = GLTFEntityParser;
4894
+ exports.GLTFExtensionParser = GLTFExtensionParser;
4895
+ exports.GLTFMaterialParser = GLTFMaterialParser;
4896
+ exports.GLTFMeshParser = GLTFMeshParser;
4897
+ exports.GLTFParser = GLTFParser;
4898
+ exports.GLTFParserContext = GLTFParserContext;
4899
+ exports.GLTFPipeline = GLTFPipeline;
4466
4900
  exports.GLTFResource = GLTFResource;
4901
+ exports.GLTFSceneParser = GLTFSceneParser;
4902
+ exports.GLTFSkinParser = GLTFSkinParser;
4903
+ exports.GLTFTextureParser = GLTFTextureParser;
4904
+ exports.GLTFUtils = GLTFUtils;
4905
+ exports.GLTFValidator = GLTFValidator;
4467
4906
  exports.PrefabParser = PrefabParser;
4468
4907
  exports.ReflectionParser = ReflectionParser;
4469
4908
  exports.SceneParser = SceneParser;
4470
4909
  exports.decode = decode;
4471
4910
  exports.parseSingleKTX = parseSingleKTX;
4911
+ exports.registerGLTFExtension = registerGLTFExtension;