@galacean/engine-loader 1.0.0-beta.0 → 1.0.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 +1050 -1449
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +1069 -1468
  4. package/dist/module.js +1052 -1436
  5. package/dist/module.js.map +1 -1
  6. package/package.json +5 -5
  7. package/types/AnimationClipLoader.d.ts +0 -1
  8. package/types/GLTFLoader.d.ts +0 -6
  9. package/types/gltf/GLTFParser.d.ts +9 -0
  10. package/types/gltf/GLTFResource.d.ts +11 -7
  11. package/types/gltf/{GLTFUtils.d.ts → GLTFUtil.d.ts} +15 -9
  12. package/types/gltf/{GLTFSchema.d.ts → Schema.d.ts} +0 -2
  13. package/types/gltf/extensions/ExtensionParser.d.ts +8 -0
  14. package/types/gltf/extensions/KHR_materials_variants.d.ts +1 -6
  15. package/types/gltf/extensions/{GLTFExtensionSchema.d.ts → Schema.d.ts} +2 -9
  16. package/types/gltf/extensions/index.d.ts +1 -4
  17. package/types/gltf/parser/AnimationParser.d.ts +7 -0
  18. package/types/gltf/parser/BufferParser.d.ts +7 -0
  19. package/types/gltf/parser/EntityParser.d.ts +9 -0
  20. package/types/gltf/parser/MaterialParser.d.ts +8 -0
  21. package/types/gltf/parser/MeshParser.d.ts +13 -0
  22. package/types/gltf/parser/Parser.d.ts +21 -0
  23. package/types/gltf/parser/{GLTFParserContext.d.ts → ParserContext.d.ts} +4 -6
  24. package/types/gltf/parser/SceneParser.d.ts +11 -0
  25. package/types/gltf/parser/SkinParser.d.ts +6 -0
  26. package/types/gltf/parser/TextureParser.d.ts +8 -0
  27. package/types/gltf/parser/Validator.d.ts +5 -0
  28. package/types/index.d.ts +2 -2
  29. package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +4 -4
  30. package/types/GLTFContentRestorer.d.ts +0 -85
  31. package/types/Texture2DContentRestorer.d.ts +0 -14
  32. package/types/TextureCubeContentRestorer.d.ts +0 -14
  33. package/types/gltf/GLTFPipeline.d.ts +0 -23
  34. package/types/gltf/extensions/GALACEAN_animation_event.d.ts +0 -1
  35. package/types/gltf/extensions/GLTFExtensionParser.d.ts +0 -52
  36. package/types/gltf/index.d.ts +0 -6
  37. package/types/gltf/parser/GLTFAnimationParser.d.ts +0 -12
  38. package/types/gltf/parser/GLTFBufferParser.d.ts +0 -7
  39. package/types/gltf/parser/GLTFEntityParser.d.ts +0 -9
  40. package/types/gltf/parser/GLTFMaterialParser.d.ts +0 -15
  41. package/types/gltf/parser/GLTFMeshParser.d.ts +0 -19
  42. package/types/gltf/parser/GLTFParser.d.ts +0 -63
  43. package/types/gltf/parser/GLTFSceneParser.d.ts +0 -11
  44. package/types/gltf/parser/GLTFSkinParser.d.ts +0 -6
  45. package/types/gltf/parser/GLTFTextureParser.d.ts +0 -8
  46. package/types/gltf/parser/GLTFValidator.d.ts +0 -6
  47. package/types/gltf/parser/index.d.ts +0 -11
@@ -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-rhi-webgl/dist/miniprogram');
9
- var miniprogram$3 = require('@galacean/engine-draco/dist/miniprogram');
8
+ var miniprogram$2 = require('@galacean/engine-draco/dist/miniprogram');
9
+ var miniprogram$3 = require('@galacean/engine-rhi-webgl/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(Loader1) {
95
- _inherits(AnimatorControllerLoader, Loader1);
94
+ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader) {
95
+ _inherits(AnimatorControllerLoader, Loader);
96
96
  function AnimatorControllerLoader() {
97
- return Loader1.apply(this, arguments);
97
+ return Loader.apply(this, arguments);
98
98
  }
99
99
  var _proto = AnimatorControllerLoader.prototype;
100
100
  _proto.load = function load(item, resourceManager) {
@@ -115,16 +115,13 @@ var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
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, scripts = stateData.scripts;
118
+ var name = stateData.name, speed = stateData.speed, wrapMode = stateData.wrapMode, clipStartNormalizedTime = stateData.clipStartNormalizedTime, clipEndNormalizedTime = stateData.clipEndNormalizedTime, isDefaultState = stateData.isDefaultState, clipData = stateData.clip;
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
- });
128
125
  if (clipData) {
129
126
  promises.push(new Promise(function(resolve) {
130
127
  //@ts-ignore
@@ -345,196 +342,52 @@ FontLoader = __decorate([
345
342
  ], false)
346
343
  ], FontLoader);
347
344
 
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
-
387
345
  /**
388
346
  * @internal
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;
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);
399
366
  }
400
- var _proto = GLTFContentRestorer.prototype;
401
- /**
402
- * @override
403
- */ _proto.restoreContent = function restoreContent() {
404
- var _this = this;
405
- return new miniprogram.AssetPromise(function(resolve, reject) {
406
- Promise.all(_this.bufferRequests.map(function(bufferRequestInfo) {
407
- return miniprogram.request(bufferRequestInfo.url, bufferRequestInfo.config);
408
- })).then(function(buffers) {
409
- // Buffer parse
410
- if (_this.isGLB) {
411
- var glbBufferSlice = _this.glbBufferSlices;
412
- var bigBuffer = buffers[0];
413
- var bufferCount = glbBufferSlice.length;
414
- buffers.length = bufferCount;
415
- for(var i = 0; i < bufferCount; i++){
416
- var slice = glbBufferSlice[i];
417
- buffers[i] = bigBuffer.slice(slice.x, slice.x + slice.y);
418
- }
419
- }
420
- // Restore texture
421
- miniprogram.AssetPromise.all(_this.bufferTextures.map(function(textureRestoreInfo) {
422
- var bufferView = textureRestoreInfo.bufferView;
423
- var buffer = buffers[bufferView.buffer];
424
- var _bufferView_byteOffset;
425
- var bufferData = new Uint8Array(buffer, (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0, bufferView.byteLength);
426
- return GLTFUtils.loadImageBuffer(bufferData, textureRestoreInfo.mimeType).then(function(image) {
427
- textureRestoreInfo.texture.setImageSource(image);
428
- textureRestoreInfo.texture.generateMipmaps();
429
- });
430
- })).then(function() {
431
- // Restore mesh
432
- for(var _iterator = _create_for_of_iterator_helper_loose(_this.meshes), _step; !(_step = _iterator()).done;){
433
- var meshInfo = _step.value;
434
- var mesh = meshInfo.mesh;
435
- for(var _iterator1 = _create_for_of_iterator_helper_loose(meshInfo.vertexBuffers), _step1; !(_step1 = _iterator1()).done;){
436
- var bufferRestoreInfo = _step1.value;
437
- var vertexData = _this._getBufferData(buffers, bufferRestoreInfo.data);
438
- bufferRestoreInfo.buffer.setData(vertexData);
439
- }
440
- if (meshInfo.indexBuffer) {
441
- var indexData = _this._getBufferData(buffers, meshInfo.indexBuffer);
442
- mesh.setIndices(indexData);
443
- }
444
- for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
445
- var restoreInfo = _step2.value;
446
- var frame = restoreInfo.blendShape.frames[0];
447
- var positionData = _this._getBufferData(buffers, restoreInfo.position);
448
- frame.deltaPositions = GLTFUtils.floatBufferToVector3Array(positionData);
449
- if (restoreInfo.normal) {
450
- var normalData = _this._getBufferData(buffers, restoreInfo.normal);
451
- frame.deltaNormals = GLTFUtils.floatBufferToVector3Array(normalData);
452
- }
453
- if (restoreInfo.tangent) {
454
- var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
455
- frame.deltaTangents = GLTFUtils.floatBufferToVector3Array(tangentData);
456
- }
457
- }
458
- mesh.uploadData(true);
459
- }
460
- resolve(_this.resource);
461
- }).catch(reject);
462
- }).catch(reject);
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;
463
374
  });
375
+ promiseInfo.promise = promise;
376
+ return promise;
464
377
  };
465
- _proto._getBufferData = function _getBufferData(buffers, restoreInfo) {
466
- var main = restoreInfo.main;
467
- var buffer = buffers[main.bufferIndex];
468
- var data = new main.TypedArray(buffer, main.byteOffset, main.length);
469
- var sparseCount = restoreInfo.sparseCount;
470
- if (sparseCount) {
471
- var sparseIndex = restoreInfo.sparseIndices;
472
- var sparseIndexBuffer = buffers[sparseIndex.bufferIndex];
473
- var sparseIndexData = new sparseIndex.TypedArray(sparseIndexBuffer, sparseIndex.byteOffset, sparseIndex.length);
474
- var sparseValue = restoreInfo.sparseValues;
475
- var sparseValueBuffer = buffers[sparseValue.bufferIndex];
476
- var sparseValueData = new sparseValue.TypedArray(sparseValueBuffer, sparseValue.byteOffset, sparseValue.length);
477
- var typeSize = restoreInfo.typeSize;
478
- for(var i = 0; i < sparseCount; i++){
479
- var replaceIndex = sparseIndexData[i];
480
- for(var j = 0; j < typeSize; j++){
481
- data[replaceIndex * typeSize + j] = sparseValueData[i * typeSize + j];
482
- }
483
- }
484
- }
485
- return data;
486
- };
487
- return GLTFContentRestorer;
488
- }(miniprogram.ContentRestorer);
489
- /**
490
- * @internal
491
- */ var BufferRequestInfo = function BufferRequestInfo(url, config) {
492
- this.url = url;
493
- this.config = config;
494
- };
495
- /**
496
- * @internal
497
- */ var BufferTextureRestoreInfo = function BufferTextureRestoreInfo(texture, bufferView, mimeType) {
498
- this.texture = texture;
499
- this.bufferView = bufferView;
500
- this.mimeType = mimeType;
501
- };
502
- /**
503
- * @internal
504
- */ var ModelMeshRestoreInfo = function ModelMeshRestoreInfo() {
505
- this.vertexBuffers = [];
506
- this.blendShapes = [];
507
- };
378
+ return ParserContext;
379
+ }();
508
380
  /**
509
381
  * @internal
510
- */ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
511
- this.buffer = buffer;
382
+ */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
512
383
  this.data = data;
384
+ this.interleaved = interleaved;
385
+ this.stride = stride;
386
+ this.vertexBindingInfos = {};
513
387
  };
514
388
  /**
515
389
  * @internal
516
- */ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
517
- this.main = main;
518
- this.typeSize = typeSize;
519
- this.sparseCount = sparseCount;
520
- this.sparseIndices = sparseIndices;
521
- this.sparseValues = sparseValues;
522
- };
523
- /**
524
- * @internal
525
- */ var RestoreDataAccessor = function RestoreDataAccessor(bufferIndex, TypedArray, byteOffset, length) {
526
- this.bufferIndex = bufferIndex;
527
- this.TypedArray = TypedArray;
528
- this.byteOffset = byteOffset;
529
- this.length = length;
530
- };
531
- /**
532
- * @internal
533
- */ var BlendShapeRestoreInfo = function BlendShapeRestoreInfo(blendShape, position, normal, tangent) {
534
- this.blendShape = blendShape;
535
- this.position = position;
536
- this.normal = normal;
537
- this.tangent = tangent;
390
+ */ var PromiseInfo = function PromiseInfo() {
538
391
  };
539
392
 
540
393
  /**
@@ -686,57 +539,9 @@ var TextureWrapMode;
686
539
 
687
540
  /**
688
541
  * @internal
689
- */ var GLTFParserContext = /*#__PURE__*/ function() {
690
- function GLTFParserContext(url) {
691
- this.hasSkinned = false;
692
- this.chainPromises = [];
693
- this.accessorBufferCache = {};
694
- this.texturesPromiseInfo = new PromiseInfo();
695
- this.materialsPromiseInfo = new PromiseInfo();
696
- this.meshesPromiseInfo = new PromiseInfo();
697
- this.animationClipsPromiseInfo = new PromiseInfo();
698
- this.defaultSceneRootPromiseInfo = new PromiseInfo();
699
- this.masterPromiseInfo = new PromiseInfo();
700
- this.promiseMap = {};
701
- var promiseMap = this.promiseMap;
702
- promiseMap["" + url + "?q=textures"] = this._initPromiseInfo(this.texturesPromiseInfo);
703
- promiseMap["" + url + "?q=materials"] = this._initPromiseInfo(this.materialsPromiseInfo);
704
- promiseMap["" + url + "?q=meshes"] = this._initPromiseInfo(this.meshesPromiseInfo);
705
- promiseMap["" + url + "?q=animations"] = this._initPromiseInfo(this.animationClipsPromiseInfo);
706
- promiseMap["" + url + "?q=defaultSceneRoot"] = this._initPromiseInfo(this.defaultSceneRootPromiseInfo);
707
- promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
708
- }
709
- var _proto = GLTFParserContext.prototype;
710
- _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
711
- var promise = new miniprogram.AssetPromise(function(resolve, reject, setProgress, onCancel) {
712
- promiseInfo.resolve = resolve;
713
- promiseInfo.reject = reject;
714
- promiseInfo.setProgress = setProgress;
715
- promiseInfo.onCancel = onCancel;
716
- });
717
- promiseInfo.promise = promise;
718
- return promise;
719
- };
720
- return GLTFParserContext;
721
- }();
722
- /**
723
- * @internal
724
- */ var BufferInfo = function BufferInfo(data, interleaved, stride) {
725
- this.data = data;
726
- this.interleaved = interleaved;
727
- this.stride = stride;
728
- this.vertexBindingInfos = {};
729
- };
730
- /**
731
- * @internal
732
- */ var PromiseInfo = function PromiseInfo() {
733
- };
734
-
735
- /**
736
- * @internal
737
- */ var GLTFUtils = /*#__PURE__*/ function() {
738
- function GLTFUtils() {}
739
- GLTFUtils.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
542
+ */ var GLTFUtil = /*#__PURE__*/ function() {
543
+ function GLTFUtil() {}
544
+ GLTFUtil.floatBufferToVector2Array = function floatBufferToVector2Array(buffer) {
740
545
  var bufferLen = buffer.length;
741
546
  var array = new Array(bufferLen / 2);
742
547
  for(var i = 0; i < bufferLen; i += 2){
@@ -744,7 +549,7 @@ var TextureWrapMode;
744
549
  }
745
550
  return array;
746
551
  };
747
- GLTFUtils.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
552
+ GLTFUtil.floatBufferToVector3Array = function floatBufferToVector3Array(buffer) {
748
553
  var bufferLen = buffer.length;
749
554
  var array = new Array(bufferLen / 3);
750
555
  for(var i = 0; i < bufferLen; i += 3){
@@ -752,7 +557,7 @@ var TextureWrapMode;
752
557
  }
753
558
  return array;
754
559
  };
755
- GLTFUtils.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
560
+ GLTFUtil.floatBufferToVector4Array = function floatBufferToVector4Array(buffer) {
756
561
  var bufferLen = buffer.length;
757
562
  var array = new Array(bufferLen / 4);
758
563
  for(var i = 0; i < bufferLen; i += 4){
@@ -760,7 +565,7 @@ var TextureWrapMode;
760
565
  }
761
566
  return array;
762
567
  };
763
- GLTFUtils.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
568
+ GLTFUtil.floatBufferToColorArray = function floatBufferToColorArray(buffer, isColor3) {
764
569
  var bufferLen = buffer.length;
765
570
  var colors = new Array(bufferLen / (isColor3 ? 3 : 4));
766
571
  if (isColor3) {
@@ -775,8 +580,21 @@ var TextureWrapMode;
775
580
  return colors;
776
581
  };
777
582
  /**
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
+ /**
778
596
  * Get the number of bytes occupied by accessor type.
779
- */ GLTFUtils.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
597
+ */ GLTFUtil.getAccessorTypeSize = function getAccessorTypeSize(accessorType) {
780
598
  switch(accessorType){
781
599
  case AccessorType.SCALAR:
782
600
  return 1;
@@ -796,7 +614,7 @@ var TextureWrapMode;
796
614
  };
797
615
  /**
798
616
  * Get the TypedArray corresponding to the component type.
799
- */ GLTFUtils.getComponentType = function getComponentType(componentType) {
617
+ */ GLTFUtil.getComponentType = function getComponentType(componentType) {
800
618
  switch(componentType){
801
619
  case AccessorComponentType.BYTE:
802
620
  return Int8Array;
@@ -812,7 +630,7 @@ var TextureWrapMode;
812
630
  return Float32Array;
813
631
  }
814
632
  };
815
- GLTFUtils.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
633
+ GLTFUtil.getNormalizedComponentScale = function getNormalizedComponentScale(componentType) {
816
634
  // Reference: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
817
635
  switch(componentType){
818
636
  case AccessorComponentType.BYTE:
@@ -827,18 +645,18 @@ var TextureWrapMode;
827
645
  throw new Error("Galacean.GLTFLoader: Unsupported normalized accessor component type.");
828
646
  }
829
647
  };
830
- GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
648
+ GLTFUtil.getAccessorBuffer = function getAccessorBuffer(context, gltf, accessor) {
831
649
  var buffers = context.buffers;
650
+ var bufferViews = gltf.bufferViews;
832
651
  var componentType = accessor.componentType;
833
652
  var bufferView = bufferViews[accessor.bufferView];
834
- var bufferIndex = bufferView.buffer;
835
- var buffer = buffers[bufferIndex];
653
+ var buffer = buffers[bufferView.buffer];
836
654
  var bufferByteOffset = bufferView.byteOffset || 0;
837
655
  var byteOffset = accessor.byteOffset || 0;
838
- var TypedArray = GLTFUtils.getComponentType(componentType);
839
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
656
+ var TypedArray = GLTFUtil.getComponentType(componentType);
657
+ var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
840
658
  var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
841
- var elementStride = dataElementSize * dataElementBytes;
659
+ var elementStride = dataElmentSize * dataElementBytes;
842
660
  var accessorCount = accessor.count;
843
661
  var bufferStride = bufferView.byteStride;
844
662
  var bufferInfo;
@@ -853,35 +671,34 @@ var TextureWrapMode;
853
671
  var count = accessorCount * (bufferStride / dataElementBytes);
854
672
  var data = new TypedArray(buffer, offset, count);
855
673
  accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
856
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
857
674
  }
858
675
  } else {
859
676
  var offset1 = bufferByteOffset + byteOffset;
860
- var count1 = accessorCount * dataElementSize;
677
+ var count1 = accessorCount * dataElmentSize;
861
678
  var data1 = new TypedArray(buffer, offset1, count1);
862
679
  bufferInfo = new BufferInfo(data1, false, elementStride);
863
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
864
680
  }
865
681
  if (accessor.sparse) {
866
- GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
682
+ var data2 = GLTFUtil.processingSparseData(gltf, accessor, buffers, bufferInfo.data);
683
+ bufferInfo = new BufferInfo(data2, false, bufferInfo.stride);
867
684
  }
868
685
  return bufferInfo;
869
686
  };
870
687
  /**
871
688
  * @deprecated
872
689
  * Get accessor data.
873
- */ GLTFUtils.getAccessorData = function getAccessorData(glTF, accessor, buffers) {
874
- var bufferViews = glTF.bufferViews;
690
+ */ GLTFUtil.getAccessorData = function getAccessorData(gltf, accessor, buffers) {
691
+ var bufferViews = gltf.bufferViews;
875
692
  var bufferView = bufferViews[accessor.bufferView];
876
693
  var arrayBuffer = buffers[bufferView.buffer];
877
694
  var accessorByteOffset = accessor.hasOwnProperty("byteOffset") ? accessor.byteOffset : 0;
878
695
  var bufferViewByteOffset = bufferView.hasOwnProperty("byteOffset") ? bufferView.byteOffset : 0;
879
696
  var byteOffset = accessorByteOffset + bufferViewByteOffset;
880
- var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
697
+ var accessorTypeSize = GLTFUtil.getAccessorTypeSize(accessor.type);
881
698
  var length = accessorTypeSize * accessor.count;
882
699
  var _bufferView_byteStride;
883
700
  var byteStride = (_bufferView_byteStride = bufferView.byteStride) != null ? _bufferView_byteStride : 0;
884
- var arrayType = GLTFUtils.getComponentType(accessor.componentType);
701
+ var arrayType = GLTFUtil.getComponentType(accessor.componentType);
885
702
  var uint8Array;
886
703
  if (byteStride) {
887
704
  var accessorByteSize = accessorTypeSize * arrayType.BYTES_PER_ELEMENT;
@@ -908,7 +725,7 @@ var TextureWrapMode;
908
725
  var _values_byteOffset, _valuesBufferView_byteOffset;
909
726
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
910
727
  var valuesByteLength = valuesBufferView.byteLength;
911
- var indicesType = GLTFUtils.getComponentType(indices.componentType);
728
+ var indicesType = GLTFUtil.getComponentType(indices.componentType);
912
729
  var indicesArray = new indicesType(indicesArrayBuffer, indicesByteOffset, indicesByteLength / indicesType.BYTES_PER_ELEMENT);
913
730
  var valuesArray = new arrayType(valuesArrayBuffer, valuesByteOffset, valuesByteLength / arrayType.BYTES_PER_ELEMENT);
914
731
  for(var i1 = 0; i1 < count; i1++){
@@ -920,49 +737,41 @@ var TextureWrapMode;
920
737
  }
921
738
  return typedArray;
922
739
  };
923
- GLTFUtils.getBufferViewData = function getBufferViewData(bufferView, buffers) {
924
- var _bufferView_byteOffset = bufferView.byteOffset, byteOffset = _bufferView_byteOffset === void 0 ? 0 : _bufferView_byteOffset;
925
- var arrayBuffer = buffers[bufferView.buffer];
926
- return arrayBuffer.slice(byteOffset, byteOffset + bufferView.byteLength);
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);
927
744
  };
928
745
  /**
929
746
  * Get accessor data.
930
- */ GLTFUtils.processingSparseData = function processingSparseData(bufferViews, accessor, buffers, bufferInfo) {
931
- var restoreInfo = bufferInfo.restoreInfo;
932
- var accessorTypeSize = GLTFUtils.getAccessorTypeSize(accessor.type);
933
- var TypedArray = GLTFUtils.getComponentType(accessor.componentType);
934
- var data = bufferInfo.data.slice();
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();
935
752
  var _accessor_sparse = accessor.sparse, count = _accessor_sparse.count, indices = _accessor_sparse.indices, values = _accessor_sparse.values;
936
753
  var indicesBufferView = bufferViews[indices.bufferView];
937
754
  var valuesBufferView = bufferViews[values.bufferView];
938
- var indicesBufferIndex = indicesBufferView.buffer;
939
- var valuesBufferIndex = valuesBufferView.buffer;
940
- var indicesArrayBuffer = buffers[indicesBufferIndex];
941
- var valuesArrayBuffer = buffers[valuesBufferIndex];
755
+ var indicesArrayBuffer = buffers[indicesBufferView.buffer];
756
+ var valuesArrayBuffer = buffers[valuesBufferView.buffer];
942
757
  var _indices_byteOffset, _indicesBufferView_byteOffset;
943
758
  var indicesByteOffset = ((_indices_byteOffset = indices.byteOffset) != null ? _indices_byteOffset : 0) + ((_indicesBufferView_byteOffset = indicesBufferView.byteOffset) != null ? _indicesBufferView_byteOffset : 0);
944
759
  var indicesByteLength = indicesBufferView.byteLength;
945
760
  var _values_byteOffset, _valuesBufferView_byteOffset;
946
761
  var valuesByteOffset = ((_values_byteOffset = values.byteOffset) != null ? _values_byteOffset : 0) + ((_valuesBufferView_byteOffset = valuesBufferView.byteOffset) != null ? _valuesBufferView_byteOffset : 0);
947
762
  var valuesByteLength = valuesBufferView.byteLength;
948
- restoreInfo.typeSize = accessorTypeSize;
949
- restoreInfo.sparseCount = count;
950
- var IndexTypeArray = GLTFUtils.getComponentType(indices.componentType);
951
- var indexLength = indicesByteLength / IndexTypeArray.BYTES_PER_ELEMENT;
952
- var indicesArray = new IndexTypeArray(indicesArrayBuffer, indicesByteOffset, indexLength);
953
- restoreInfo.sparseIndices = new RestoreDataAccessor(indicesBufferIndex, IndexTypeArray, indicesByteOffset, indexLength);
954
- var valueLength = valuesByteLength / TypedArray.BYTES_PER_ELEMENT;
955
- var valuesArray = new TypedArray(valuesArrayBuffer, valuesByteOffset, valueLength);
956
- restoreInfo.sparseValues = new RestoreDataAccessor(valuesBufferIndex, TypedArray, valuesByteOffset, valueLength);
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);
957
766
  for(var i = 0; i < count; i++){
958
767
  var replaceIndex = indicesArray[i];
959
768
  for(var j = 0; j < accessorTypeSize; j++){
960
769
  data[replaceIndex * accessorTypeSize + j] = valuesArray[i * accessorTypeSize + j];
961
770
  }
962
771
  }
963
- bufferInfo.data = data;
772
+ return data;
964
773
  };
965
- GLTFUtils.getIndexFormat = function getIndexFormat(type) {
774
+ GLTFUtil.getIndexFormat = function getIndexFormat(type) {
966
775
  switch(type){
967
776
  case AccessorComponentType.UNSIGNED_BYTE:
968
777
  return miniprogram.IndexFormat.UInt8;
@@ -972,7 +781,7 @@ var TextureWrapMode;
972
781
  return miniprogram.IndexFormat.UInt32;
973
782
  }
974
783
  };
975
- GLTFUtils.getElementFormat = function getElementFormat(type, size, normalized) {
784
+ GLTFUtil.getElementFormat = function getElementFormat(type, size, normalized) {
976
785
  if (normalized === void 0) normalized = false;
977
786
  if (type == AccessorComponentType.FLOAT) {
978
787
  switch(size){
@@ -1023,7 +832,7 @@ var TextureWrapMode;
1023
832
  };
1024
833
  /**
1025
834
  * Load image buffer
1026
- */ GLTFUtils.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
835
+ */ GLTFUtil.loadImageBuffer = function loadImageBuffer(imageBuffer, type) {
1027
836
  return new Promise(function(resolve, reject) {
1028
837
  var blob = new engineMiniprogramAdapter.window.Blob([
1029
838
  imageBuffer
@@ -1047,9 +856,18 @@ var TextureWrapMode;
1047
856
  img.src = engineMiniprogramAdapter.URL.createObjectURL(blob);
1048
857
  });
1049
858
  };
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
+ };
1050
868
  /**
1051
869
  * Parse the glb format.
1052
- */ GLTFUtils.parseGLB = function parseGLB(context, glb) {
870
+ */ GLTFUtil.parseGLB = function parseGLB(glb) {
1053
871
  var UINT32_LENGTH = 4;
1054
872
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
1055
873
  var GLB_HEADER_LENGTH = 12;
@@ -1077,11 +895,10 @@ var TextureWrapMode;
1077
895
  return null;
1078
896
  }
1079
897
  var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
1080
- var glTF = JSON.parse(miniprogram.Utils.decodeText(glTFData));
898
+ var gltf = JSON.parse(GLTFUtil.decodeText(glTFData));
1081
899
  // read all buffers
1082
900
  var buffers = [];
1083
901
  var byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength;
1084
- var restoreGLBBufferSlice = context.contentRestorer.glbBufferSlices;
1085
902
  while(byteOffset < header.length){
1086
903
  chunkLength = dataView.getUint32(byteOffset, true);
1087
904
  chunkType = dataView.getUint32(byteOffset + UINT32_LENGTH, true);
@@ -1092,15 +909,14 @@ var TextureWrapMode;
1092
909
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
1093
910
  var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
1094
911
  buffers.push(buffer);
1095
- restoreGLBBufferSlice.push(new miniprogram$1.Vector2(currentOffset, chunkLength));
1096
912
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
1097
913
  }
1098
914
  return {
1099
- glTF: glTF,
915
+ gltf: gltf,
1100
916
  buffers: buffers
1101
917
  };
1102
918
  };
1103
- GLTFUtils._formatRelativePath = function _formatRelativePath(path) {
919
+ GLTFUtil._formatRelativePath = function _formatRelativePath(path) {
1104
920
  // For example input is "a/b", "/a/b", "./a/b", "./a/./b", "./a/../a/b", output is "a/b"
1105
921
  return path.split("/").filter(Boolean).reduce(function(acc, cur) {
1106
922
  if (cur === "..") acc.pop();
@@ -1108,9 +924,17 @@ var TextureWrapMode;
1108
924
  return acc;
1109
925
  }, []).join("/");
1110
926
  };
1111
- return GLTFUtils;
927
+ return GLTFUtil;
1112
928
  }();
1113
929
 
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
+
1114
938
  function _array_without_holes(arr) {
1115
939
  if (Array.isArray(arr)) return _array_like_to_array(arr);
1116
940
  }
@@ -1125,327 +949,606 @@ function _non_iterable_spread() {
1125
949
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1126
950
  }
1127
951
 
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
+
1128
963
  function _to_consumable_array(arr) {
1129
964
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
1130
965
  }
1131
966
 
1132
- /**
1133
- * Base class of glTF extension parser.
1134
- */ var GLTFExtensionParser = /*#__PURE__*/ function() {
1135
- function GLTFExtensionParser() {}
1136
- var _proto = GLTFExtensionParser.prototype;
1137
- /**
1138
- * Initialize the parser.
1139
- * @remarks Some plugins require initialization.
1140
- * @returns The void or promise
1141
- */ _proto.initialize = function initialize() {};
1142
- /**
1143
- * Create and parse the resource.
1144
- * @remarks This method overrides the default resource creation.
1145
- * @param context - The parser context
1146
- * @param extensionSchema - The extension schema
1147
- * @param extensionOwnerSchema - The extension owner schema
1148
- * @returns The resource or promise
1149
- */ _proto.createAndParse = function createAndParse(context, extensionSchema, extensionOwnerSchema) {
1150
- for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1151
- extra[_key - 3] = arguments[_key];
1152
- }
1153
- throw "Not implemented.";
1154
- };
1155
- /**
1156
- * Additive parse to the resource.
1157
- * @param context - The parser context
1158
- * @param parseResource - The parsed resource
1159
- * @param extensionSchema - The extension schema
1160
- * @param extensionOwnerSchema - The extension owner schema
1161
- * @returns The void or promise
1162
- */ _proto.additiveParse = function additiveParse(context, parseResource, extensionSchema, extensionOwnerSchema) {
967
+ var Parser = /*#__PURE__*/ function() {
968
+ function Parser() {}
969
+ Parser.parseEngineResource = function parseEngineResource(extensionName, extensionSchema, parseResource, context) {
1163
970
  for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1164
971
  extra[_key - 4] = arguments[_key];
1165
972
  }
1166
- throw "Not implemented.";
1167
- };
1168
- return GLTFExtensionParser;
1169
- }();
1170
- exports.GLTFExtensionMode = void 0;
1171
- (function(GLTFExtensionMode) {
1172
- GLTFExtensionMode[GLTFExtensionMode[/**
1173
- * Cerate instance and parse mode.
1174
- * @remarks
1175
- * If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one.
1176
- * If this method is registered, the default pipeline processing will be ignored.
1177
- */ "CreateAndParse"] = 0] = "CreateAndParse";
1178
- GLTFExtensionMode[GLTFExtensionMode[/** Additive parse mode. */ "AdditiveParse"] = 1] = "AdditiveParse";
1179
- })(exports.GLTFExtensionMode || (exports.GLTFExtensionMode = {}));
1180
-
1181
- /**
1182
- * Base class of glTF parser.
1183
- */ var GLTFParser = /*#__PURE__*/ function() {
1184
- function GLTFParser() {}
1185
- /**
1186
- * Execute all parses of extension to initialize plugin.
1187
- * @remarks Some plugins require initialization.
1188
- * @returns The void or promise
1189
- */ GLTFParser.executeExtensionsInitialize = function executeExtensionsInitialize(extensionName) {
1190
- var parsers = GLTFParser._extensionParsers[extensionName];
1191
- var length = parsers == null ? void 0 : parsers.length;
1192
- if (length) {
1193
- return parsers[length - 1].initialize();
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
+ }
1194
983
  }
1195
984
  };
1196
- /**
1197
- * Execute all parses of extension to create resource.
1198
- * @param extensions - Related extensions field
1199
- * @param context - The parser context
1200
- * @param ownerSchema - The extension owner schema
1201
- * @param extra - Extra params
1202
- * @returns
1203
- */ GLTFParser.executeExtensionsCreateAndParse = function executeExtensionsCreateAndParse(extensions, context, ownerSchema) {
1204
- if (extensions === void 0) extensions = {};
985
+ Parser.createEngineResource = function createEngineResource(extensionName, extensionSchema, context) {
1205
986
  for(var _len = arguments.length, extra = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
1206
987
  extra[_key - 3] = arguments[_key];
1207
988
  }
1208
- var resource = null;
1209
- var extensionArray = Object.keys(extensions);
1210
- for(var i = extensionArray.length - 1; i >= 0; --i){
1211
- var _GLTFParser;
1212
- var extensionName = extensionArray[i];
1213
- var extensionSchema = extensions[extensionName];
1214
- resource = (_GLTFParser = GLTFParser)._createAndParse.apply(_GLTFParser, [
1215
- extensionName,
1216
- context,
1217
- extensionSchema,
1218
- ownerSchema
1219
- ].concat(_to_consumable_array(extra)));
1220
- if (resource) {
1221
- return resource;
1222
- }
1223
- }
1224
- };
1225
- /**
1226
- * Execute all parses of extension to parse resource.
1227
- * @param extensions - Related extensions field
1228
- * @param context - The parser context
1229
- * @param parseResource - The parsed resource
1230
- * @param ownerSchema - The extension owner schema
1231
- * @param extra - Extra params
1232
- */ GLTFParser.executeExtensionsAdditiveAndParse = function executeExtensionsAdditiveAndParse(extensions, context, parseResource, ownerSchema) {
1233
- for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1234
- extra[_key - 4] = arguments[_key];
1235
- }
1236
- for(var extensionName in extensions){
1237
- var _GLTFParser;
1238
- var extensionSchema = extensions[extensionName];
1239
- (_GLTFParser = GLTFParser)._additiveParse.apply(_GLTFParser, [
1240
- extensionName,
1241
- context,
1242
- parseResource,
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_, [
1243
993
  extensionSchema,
1244
- ownerSchema
994
+ context
1245
995
  ].concat(_to_consumable_array(extra)));
1246
996
  }
1247
997
  };
1248
- /**
1249
- * Whether the plugin is registered.
1250
- * @param extensionName - Extension name
1251
- * @returns Boolean
1252
- */ GLTFParser.hasExtensionParser = function hasExtensionParser(extensionName) {
1253
- var _GLTFParser__extensionParsers_extensionName;
1254
- return !!((_GLTFParser__extensionParsers_extensionName = GLTFParser._extensionParsers[extensionName]) == null ? void 0 : _GLTFParser__extensionParsers_extensionName.length);
998
+ Parser.hasExtensionParser = function hasExtensionParser(extensionName) {
999
+ var parsers = Parser._extensionParsers[extensionName];
1000
+ return !!(parsers == null ? void 0 : parsers.length);
1255
1001
  };
1256
- /**
1257
- * Get the last plugin by glTF extension mode.
1258
- * @param extensionName - Extension name
1259
- * @param mode - GLTF extension mode
1260
- * @returns GLTF extension parser
1261
- */ GLTFParser.getExtensionParser = function getExtensionParser(extensionName, mode) {
1262
- var parsers = GLTFParser._extensionParsers[extensionName];
1263
- var length = parsers == null ? void 0 : parsers.length;
1264
- if (length) {
1265
- // only use the last parser.
1266
- for(var i = length - 1; i >= 0; --i){
1267
- var currentParser = parsers[i];
1268
- if (currentParser._mode === mode) {
1269
- return currentParser;
1270
- }
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();
1271
1007
  }
1272
1008
  }
1273
1009
  };
1274
1010
  /**
1275
1011
  * @internal
1276
- */ GLTFParser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1277
- if (!GLTFParser._extensionParsers[extensionName]) {
1278
- GLTFParser._extensionParsers[extensionName] = [];
1279
- }
1280
- GLTFParser._extensionParsers[extensionName].push(extensionParser);
1281
- };
1282
- GLTFParser._createAndParse = function _createAndParse(extensionName, context, extensionSchema, ownerSchema) {
1283
- for(var _len = arguments.length, extra = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++){
1284
- extra[_key - 4] = arguments[_key];
1285
- }
1286
- var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.CreateAndParse);
1287
- if (parser) {
1288
- var _parser;
1289
- return (_parser = parser).createAndParse.apply(_parser, [
1290
- context,
1291
- extensionSchema,
1292
- ownerSchema
1293
- ].concat(_to_consumable_array(extra)));
1294
- }
1295
- };
1296
- GLTFParser._additiveParse = function _additiveParse(extensionName, context, parseResource, extensionSchema, ownerSchema) {
1297
- for(var _len = arguments.length, extra = new Array(_len > 5 ? _len - 5 : 0), _key = 5; _key < _len; _key++){
1298
- extra[_key - 5] = arguments[_key];
1299
- }
1300
- var parser = GLTFParser.getExtensionParser(extensionName, exports.GLTFExtensionMode.AdditiveParse);
1301
- if (parser) {
1302
- var _parser;
1303
- (_parser = parser).additiveParse.apply(_parser, [
1304
- context,
1305
- parseResource,
1306
- extensionSchema,
1307
- ownerSchema
1308
- ].concat(_to_consumable_array(extra)));
1012
+ */ Parser._addExtensionParser = function _addExtensionParser(extensionName, extensionParser) {
1013
+ if (!Parser._extensionParsers[extensionName]) {
1014
+ Parser._extensionParsers[extensionName] = [];
1309
1015
  }
1016
+ Parser._extensionParsers[extensionName].push(extensionParser);
1310
1017
  };
1311
- return GLTFParser;
1018
+ return Parser;
1312
1019
  }();
1313
1020
  (function() {
1314
- GLTFParser._extensionParsers = {};
1021
+ Parser._extensionParsers = {};
1315
1022
  })();
1316
1023
  /**
1317
1024
  * Declare ExtensionParser's decorator.
1318
1025
  * @param extensionName - Extension name
1319
- */ function registerGLTFExtension(extensionName, mode) {
1026
+ */ function registerExtension(extensionName) {
1320
1027
  return function(parser) {
1321
1028
  var extensionParser = new parser();
1322
- extensionParser._mode = mode;
1323
- GLTFParser._addExtensionParser(extensionName, extensionParser);
1029
+ Parser._addExtensionParser(extensionName, extensionParser);
1324
1030
  };
1325
1031
  }
1326
1032
 
1327
- var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1328
- _inherits(GLTFAnimationParser, GLTFParser1);
1329
- function GLTFAnimationParser() {
1330
- return GLTFParser1.apply(this, arguments);
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);
1331
1055
  }
1332
- var _proto = GLTFAnimationParser.prototype;
1333
- _proto.parse = function parse(context) {
1334
- var glTF = context.glTF; context.buffers; var glTFResource = context.glTFResource;
1335
- glTFResource.entities;
1336
- var animations = glTF.animations; glTF.accessors; glTF.bufferViews;
1337
- if (!animations) {
1338
- return;
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();
1339
1060
  }
1340
- var animationClipsPromiseInfo = context.animationClipsPromiseInfo;
1341
- var animationClipCount = animations.length;
1342
- var animationClipPromises = [];
1343
- new Array(animationClipCount);
1344
- for(var i = 0; i < animationClipCount; i++){
1345
- var animationInfo = animations[i];
1346
- var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
1347
- var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
1348
- if (!animationClip) {
1349
- animationClip = new miniprogram.AnimationClip(name);
1350
- GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
1351
- }
1352
- animationClipPromises.push(animationClip);
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];
1353
1070
  }
1354
- return miniprogram.AssetPromise.all(animationClipPromises).then(function(animationClips) {
1355
- glTFResource.animations = animationClips;
1356
- for(var i = 0; i < glTF.animations.length; i++){
1357
- var animationInfo = glTF.animations[i];
1358
- GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
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;
1359
1075
  }
1360
- animationClipsPromiseInfo.resolve(animationClips);
1361
- return animationClipsPromiseInfo.promise;
1076
+ }
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;
1362
1088
  });
1363
1089
  };
1364
- /**
1365
- * @internal
1366
- */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
1367
- var glTF = context.glTF, glTFResource = context.glTFResource;
1368
- var entities = glTFResource.entities;
1369
- var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
1370
- var channels = animationInfo.channels, samplers = animationInfo.samplers;
1371
- var sampleDataCollection = new Array();
1372
- // parse samplers
1373
- for(var j = 0, m = samplers.length; j < m; j++){
1374
- var gltfSampler = samplers[j];
1375
- var inputAccessor = accessors[gltfSampler.input];
1376
- var outputAccessor = accessors[gltfSampler.output];
1377
- var input = GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor).data;
1378
- var output = GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor).data;
1379
- if (outputAccessor.normalized) {
1380
- var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
1381
- var scaled = new Float32Array(output.length);
1382
- for(var k = 0, v = output.length; k < v; k++){
1383
- scaled[k] = output[k] * scale;
1384
- }
1385
- output = scaled;
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
+ }
1215
+ }
1216
+ }
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);
1386
1223
  }
1387
- var outputStride = output.length / input.length;
1388
- var _gltfSampler_interpolation;
1389
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
1390
- var samplerInterpolation = void 0;
1391
- switch(interpolation){
1392
- case AnimationSamplerInterpolation.CubicSpine:
1393
- samplerInterpolation = miniprogram.InterpolationType.CubicSpine;
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;
1394
1232
  break;
1395
- case AnimationSamplerInterpolation.Step:
1396
- samplerInterpolation = miniprogram.InterpolationType.Step;
1233
+ case MaterialAlphaMode.BLEND:
1234
+ material.isTransparent = true;
1397
1235
  break;
1398
- case AnimationSamplerInterpolation.Linear:
1399
- samplerInterpolation = miniprogram.InterpolationType.Linear;
1236
+ case MaterialAlphaMode.MASK:
1237
+ material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1400
1238
  break;
1401
1239
  }
1402
- input[input.length - 1];
1403
- sampleDataCollection.push({
1404
- type: outputAccessor.type,
1405
- interpolation: samplerInterpolation,
1406
- input: input,
1407
- output: output,
1408
- outputSize: outputStride
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
+ })
1409
1356
  });
1410
1357
  }
1411
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
1412
- var gltfChannel = channels[j1];
1413
- var target = gltfChannel.target;
1414
- var channelTargetEntity = entities[target.node];
1415
- var relativePath = "";
1416
- var entity = channelTargetEntity;
1417
- while(entity.parent){
1418
- relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
1419
- entity = entity.parent;
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
+ });
1420
1502
  }
1421
- var ComponentType = void 0;
1422
- var propertyName = void 0;
1423
- switch(target.path){
1424
- case AnimationChannelTargetPath.TRANSLATION:
1425
- ComponentType = miniprogram.Transform;
1426
- propertyName = "position";
1427
- break;
1428
- case AnimationChannelTargetPath.ROTATION:
1429
- ComponentType = miniprogram.Transform;
1430
- propertyName = "rotationQuaternion";
1431
- break;
1432
- case AnimationChannelTargetPath.SCALE:
1433
- ComponentType = miniprogram.Transform;
1434
- propertyName = "scale";
1435
- break;
1436
- case AnimationChannelTargetPath.WEIGHTS:
1437
- ComponentType = miniprogram.SkinnedMeshRenderer;
1438
- propertyName = "blendShapeWeights";
1439
- break;
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);
1440
1535
  }
1441
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
1442
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
1536
+ animationClips[i] = animationClip;
1537
+ animationsIndices[i] = {
1538
+ name: name,
1539
+ index: i
1540
+ };
1443
1541
  }
1542
+ glTFResource.animations = animationClips;
1543
+ // @ts-ignore for editor
1544
+ glTFResource._animationsIndices = animationsIndices;
1545
+ animationClipsPromiseInfo.resolve(animationClips);
1546
+ return animationClipsPromiseInfo.promise;
1444
1547
  };
1445
- GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
1548
+ _proto._addCurve = function _addCurve(animationchannelTargetPath, gltfChannel, sampleDataCollection) {
1446
1549
  var sampleData = sampleDataCollection[gltfChannel.sampler];
1447
1550
  var input = sampleData.input, output = sampleData.output, outputSize = sampleData.outputSize;
1448
- switch(animationChannelTargetPath){
1551
+ switch(animationchannelTargetPath){
1449
1552
  case AnimationChannelTargetPath.TRANSLATION:
1450
1553
  case AnimationChannelTargetPath.SCALE:
1451
1554
  {
@@ -1510,42 +1613,35 @@ var GLTFAnimationParser = /*#__PURE__*/ function(GLTFParser1) {
1510
1613
  }
1511
1614
  }
1512
1615
  };
1513
- return GLTFAnimationParser;
1514
- }(GLTFParser);
1616
+ return AnimationParser;
1617
+ }(Parser);
1515
1618
 
1516
- var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1517
- _inherits(GLTFBufferParser, GLTFParser);
1518
- function GLTFBufferParser() {
1519
- return GLTFParser.apply(this, arguments);
1619
+ var BufferParser = /*#__PURE__*/ function(Parser) {
1620
+ _inherits(BufferParser, Parser);
1621
+ function BufferParser() {
1622
+ return Parser.apply(this, arguments);
1520
1623
  }
1521
- var _proto = GLTFBufferParser.prototype;
1624
+ var _proto = BufferParser.prototype;
1522
1625
  _proto.parse = function parse(context) {
1523
- var glTFResource = context.glTFResource, contentRestorer = context.contentRestorer;
1626
+ var glTFResource = context.glTFResource;
1524
1627
  var url = glTFResource.url;
1525
- var restoreBufferRequests = contentRestorer.bufferRequests;
1526
- var requestConfig = {
1527
- type: "arraybuffer"
1528
- };
1529
- var isGLB = this._isGLB(url);
1530
- contentRestorer.isGLB = isGLB;
1531
- if (isGLB) {
1532
- return miniprogram.request(url, requestConfig).then(function(glb) {
1533
- restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
1534
- return GLTFUtils.parseGLB(context, glb);
1535
- }).then(function(param) {
1536
- var glTF = param.glTF, buffers = param.buffers;
1537
- context.glTF = glTF;
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;
1538
1634
  context.buffers = buffers;
1539
1635
  });
1540
1636
  } else {
1541
1637
  return miniprogram.request(url, {
1542
1638
  type: "json"
1543
- }).then(function(glTF) {
1544
- context.glTF = glTF;
1545
- return Promise.all(glTF.buffers.map(function(buffer) {
1546
- var absoluteUrl = miniprogram.Utils.resolveAbsoluteUrl(url, buffer.uri);
1547
- restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
1548
- return miniprogram.request(absoluteUrl, requestConfig);
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
+ });
1549
1645
  })).then(function(buffers) {
1550
1646
  context.buffers = buffers;
1551
1647
  });
@@ -1556,24 +1652,24 @@ var GLTFBufferParser = /*#__PURE__*/ function(GLTFParser) {
1556
1652
  var index = url.lastIndexOf(".");
1557
1653
  return url.substring(index + 1, index + 4) === "glb";
1558
1654
  };
1559
- return GLTFBufferParser;
1560
- }(GLTFParser);
1655
+ return BufferParser;
1656
+ }(Parser);
1561
1657
 
1562
- var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1563
- _inherits(GLTFEntityParser, GLTFParser);
1564
- function GLTFEntityParser() {
1565
- return GLTFParser.apply(this, arguments);
1658
+ var EntityParser = /*#__PURE__*/ function(Parser) {
1659
+ _inherits(EntityParser, Parser);
1660
+ function EntityParser() {
1661
+ return Parser.apply(this, arguments);
1566
1662
  }
1567
- var _proto = GLTFEntityParser.prototype;
1663
+ var _proto = EntityParser.prototype;
1568
1664
  _proto.parse = function parse(context) {
1569
- var glTFResource = context.glTFResource, nodes = context.glTF.nodes;
1665
+ var glTFResource = context.glTFResource, nodes = context.gltf.nodes;
1570
1666
  var engine = glTFResource.engine;
1571
1667
  if (!nodes) return;
1572
1668
  var entities = [];
1573
1669
  for(var i = 0; i < nodes.length; i++){
1574
1670
  var gltfNode = nodes[i];
1575
1671
  var matrix = gltfNode.matrix, translation = gltfNode.translation, rotation = gltfNode.rotation, scale = gltfNode.scale;
1576
- var entity = new miniprogram.Entity(engine, gltfNode.name || "" + GLTFEntityParser._defaultName + i);
1672
+ var entity = new miniprogram.Entity(engine, gltfNode.name || "" + EntityParser._defaultName + i);
1577
1673
  var transform = entity.transform;
1578
1674
  if (matrix) {
1579
1675
  var localMatrix = transform.localMatrix;
@@ -1597,7 +1693,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1597
1693
  this._createSceneRoots(context, glTFResource);
1598
1694
  };
1599
1695
  _proto._buildEntityTree = function _buildEntityTree(context, glTFResource) {
1600
- var nodes = context.glTF.nodes;
1696
+ var nodes = context.gltf.nodes;
1601
1697
  var entities = glTFResource.entities;
1602
1698
  for(var i = 0; i < nodes.length; i++){
1603
1699
  var children = nodes[i].children;
@@ -1611,7 +1707,7 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1611
1707
  }
1612
1708
  };
1613
1709
  _proto._createSceneRoots = function _createSceneRoots(context, glTFResource) {
1614
- var _context_glTF = context.glTF, tmp = _context_glTF.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_glTF.scenes;
1710
+ var _context_gltf = context.gltf, tmp = _context_gltf.scene, sceneID = tmp === void 0 ? 0 : tmp, scenes = _context_gltf.scenes;
1615
1711
  var engine = glTFResource.engine, entities = glTFResource.entities;
1616
1712
  if (!scenes) return;
1617
1713
  var sceneRoots = [];
@@ -1631,193 +1727,79 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
1631
1727
  glTFResource.sceneRoots = sceneRoots;
1632
1728
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
1633
1729
  };
1634
- return GLTFEntityParser;
1635
- }(GLTFParser);
1730
+ return EntityParser;
1731
+ }(Parser);
1636
1732
  (function() {
1637
- /** @internal */ GLTFEntityParser._defaultName = "_GLTF_ENTITY_";
1733
+ /** @internal */ EntityParser._defaultName = "_GLTF_ENTITY_";
1638
1734
  })();
1639
1735
 
1640
- var GLTFMaterialParser = /*#__PURE__*/ function(GLTFParser1) {
1641
- _inherits(GLTFMaterialParser, GLTFParser1);
1642
- function GLTFMaterialParser() {
1643
- return GLTFParser1.apply(this, arguments);
1736
+ var MeshParser = /*#__PURE__*/ function(Parser1) {
1737
+ _inherits(MeshParser, Parser1);
1738
+ function MeshParser() {
1739
+ return Parser1.apply(this, arguments);
1644
1740
  }
1645
- var _proto = GLTFMaterialParser.prototype;
1741
+ var _proto = MeshParser.prototype;
1646
1742
  _proto.parse = function parse(context) {
1647
- var glTF = context.glTF, glTFResource = context.glTFResource, materialsPromiseInfo = context.materialsPromiseInfo;
1648
- if (!glTF.materials) return;
1743
+ var _loop = function(i) {
1744
+ var _loop = function(j) {
1745
+ 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
+ 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);
1765
+ } else {
1766
+ _this._parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, function(attributeSemantic) {
1767
+ return null;
1768
+ }, function(attributeName, shapeIndex) {
1769
+ var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1770
+ var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1771
+ if (attributeAccessorIdx) {
1772
+ var accessor = gltf.accessors[attributeAccessorIdx];
1773
+ return GLTFUtil.getAccessorData(gltf, accessor, buffers);
1774
+ } else {
1775
+ return null;
1776
+ }
1777
+ }, function() {
1778
+ var indexAccessor = gltf.accessors[gltfPrimitive.indices];
1779
+ return GLTFUtil.getAccessorData(gltf, indexAccessor, buffers);
1780
+ }, context.keepMeshData).then(resolve);
1781
+ }
1782
+ });
1783
+ };
1784
+ var gltfMesh = gltf.meshes[i];
1785
+ var primitivePromises = [];
1786
+ for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1787
+ meshPromises[i] = Promise.all(primitivePromises);
1788
+ };
1789
+ var _this = this;
1790
+ var gltf = context.gltf, buffers = context.buffers, glTFResource = context.glTFResource;
1649
1791
  var engine = glTFResource.engine;
1650
- var materialPromises = [];
1651
- for(var i = 0; i < glTF.materials.length; i++){
1652
- var materialInfo = glTF.materials[i];
1653
- var material = GLTFParser.executeExtensionsCreateAndParse(materialInfo.extensions, context, materialInfo);
1654
- if (!material) {
1655
- material = new miniprogram.PBRMaterial(engine);
1656
- material.name = materialInfo.name;
1657
- GLTFMaterialParser._parseStandardProperty(context, material, materialInfo);
1658
- }
1659
- materialPromises.push(material);
1660
- }
1661
- return miniprogram.AssetPromise.all(materialPromises).then(function(materials) {
1662
- glTFResource.materials = materials;
1663
- for(var i = 0; i < glTF.materials.length; i++){
1664
- var materialInfo = glTF.materials[i];
1665
- GLTFParser.executeExtensionsAdditiveAndParse(materialInfo.extensions, context, materials[i], materialInfo);
1666
- }
1667
- materialsPromiseInfo.resolve(materials);
1668
- return materialsPromiseInfo.promise;
1669
- });
1792
+ if (!gltf.meshes) return;
1793
+ var meshesPromiseInfo = context.meshesPromiseInfo;
1794
+ var meshPromises = [];
1795
+ for(var i = 0; i < gltf.meshes.length; i++)_loop(i);
1796
+ miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
1797
+ glTFResource.meshes = meshes;
1798
+ meshesPromiseInfo.resolve(meshes);
1799
+ }).catch(meshesPromiseInfo.reject);
1800
+ return meshesPromiseInfo.promise;
1670
1801
  };
1671
- /**
1672
- * @internal
1673
- */ GLTFMaterialParser._checkOtherTextureTransform = function _checkOtherTextureTransform(texture, textureName) {
1674
- var _texture_extensions;
1675
- if ((_texture_extensions = texture.extensions) == null ? void 0 : _texture_extensions.KHR_texture_transform) {
1676
- miniprogram.Logger.warn("" + textureName + " texture always use the KHR_texture_transform of the base texture.");
1677
- }
1678
- };
1679
- /**
1680
- * @internal
1681
- */ GLTFMaterialParser._parseStandardProperty = function _parseStandardProperty(context, material, materialInfo) {
1682
- var textures = context.glTFResource.textures;
1683
- 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;
1684
- if (pbrMetallicRoughness) {
1685
- var baseColorFactor = pbrMetallicRoughness.baseColorFactor, baseColorTexture = pbrMetallicRoughness.baseColorTexture, metallicFactor = pbrMetallicRoughness.metallicFactor, roughnessFactor = pbrMetallicRoughness.roughnessFactor, metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
1686
- if (baseColorFactor) {
1687
- 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]);
1688
- }
1689
- if (baseColorTexture) {
1690
- material.baseTexture = textures[baseColorTexture.index];
1691
- GLTFParser.executeExtensionsAdditiveAndParse(baseColorTexture.extensions, context, material, baseColorTexture);
1692
- }
1693
- if (material.constructor === miniprogram.PBRMaterial) {
1694
- material.metallic = metallicFactor != null ? metallicFactor : 1;
1695
- material.roughness = roughnessFactor != null ? roughnessFactor : 1;
1696
- if (metallicRoughnessTexture) {
1697
- material.roughnessMetallicTexture = textures[metallicRoughnessTexture.index];
1698
- GLTFMaterialParser._checkOtherTextureTransform(metallicRoughnessTexture, "Roughness metallic");
1699
- }
1700
- }
1701
- }
1702
- if (material.constructor === miniprogram.PBRMaterial || material.constructor === miniprogram.PBRSpecularMaterial) {
1703
- if (emissiveTexture) {
1704
- material.emissiveTexture = textures[emissiveTexture.index];
1705
- GLTFMaterialParser._checkOtherTextureTransform(emissiveTexture, "Emissive");
1706
- }
1707
- if (emissiveFactor) {
1708
- material.emissiveColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(emissiveFactor[0]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[1]), miniprogram$1.Color.linearToGammaSpace(emissiveFactor[2]));
1709
- }
1710
- if (normalTexture) {
1711
- var index = normalTexture.index, scale = normalTexture.scale;
1712
- material.normalTexture = textures[index];
1713
- GLTFMaterialParser._checkOtherTextureTransform(normalTexture, "Normal");
1714
- if (scale !== undefined) {
1715
- material.normalTextureIntensity = scale;
1716
- }
1717
- }
1718
- if (occlusionTexture) {
1719
- var index1 = occlusionTexture.index, strength = occlusionTexture.strength, texCoord = occlusionTexture.texCoord;
1720
- material.occlusionTexture = textures[index1];
1721
- GLTFMaterialParser._checkOtherTextureTransform(occlusionTexture, "Occlusion");
1722
- if (strength !== undefined) {
1723
- material.occlusionTextureIntensity = strength;
1724
- }
1725
- if (texCoord === miniprogram.TextureCoordinate.UV1) {
1726
- material.occlusionTextureCoord = miniprogram.TextureCoordinate.UV1;
1727
- } else if (texCoord > miniprogram.TextureCoordinate.UV1) {
1728
- miniprogram.Logger.warn("Occlusion texture uv coordinate must be UV0 or UV1.");
1729
- }
1730
- }
1731
- }
1732
- if (doubleSided) {
1733
- material.renderFace = miniprogram.RenderFace.Double;
1734
- } else {
1735
- material.renderFace = miniprogram.RenderFace.Front;
1736
- }
1737
- switch(alphaMode){
1738
- case MaterialAlphaMode.OPAQUE:
1739
- material.isTransparent = false;
1740
- break;
1741
- case MaterialAlphaMode.BLEND:
1742
- material.isTransparent = true;
1743
- break;
1744
- case MaterialAlphaMode.MASK:
1745
- material.alphaCutoff = alphaCutoff != null ? alphaCutoff : 0.5;
1746
- break;
1747
- }
1748
- };
1749
- return GLTFMaterialParser;
1750
- }(GLTFParser);
1751
-
1752
- function _instanceof(left, right) {
1753
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1754
- return !!right[Symbol.hasInstance](left);
1755
- } else return left instanceof right;
1756
- }
1757
-
1758
- var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1759
- _inherits(GLTFMeshParser, GLTFParser1);
1760
- function GLTFMeshParser() {
1761
- return GLTFParser1.apply(this, arguments);
1762
- }
1763
- var _proto = GLTFMeshParser.prototype;
1764
- _proto.parse = function parse(context) {
1765
- var _loop = function(i) {
1766
- var _loop = function(j) {
1767
- var gltfPrimitive = gltfMesh.primitives[j];
1768
- primitivePromises[j] = new Promise(function(resolve) {
1769
- var mesh = GLTFParser.executeExtensionsCreateAndParse(gltfPrimitive.extensions, context, gltfPrimitive, gltfMesh);
1770
- if (mesh) {
1771
- if (_instanceof(mesh, miniprogram.ModelMesh)) {
1772
- resolve(mesh);
1773
- } else {
1774
- mesh.then(function(mesh) {
1775
- return resolve(mesh);
1776
- });
1777
- }
1778
- } else {
1779
- var mesh1 = new miniprogram.ModelMesh(engine, gltfMesh.name || j + "");
1780
- var meshRestoreInfo = new ModelMeshRestoreInfo();
1781
- meshRestoreInfo.mesh = mesh1;
1782
- context.contentRestorer.meshes.push(meshRestoreInfo);
1783
- GLTFMeshParser._parseMeshFromGLTFPrimitive(context, mesh1, meshRestoreInfo, gltfMesh, gltfPrimitive, glTF, function(attributeSemantic) {
1784
- return null;
1785
- }, function(attributeName, shapeIndex) {
1786
- var shapeAccessorIdx = gltfPrimitive.targets[shapeIndex];
1787
- var attributeAccessorIdx = shapeAccessorIdx[attributeName];
1788
- if (attributeAccessorIdx) {
1789
- var accessor = glTF.accessors[attributeAccessorIdx];
1790
- return GLTFUtils.getAccessorBuffer(context, context.glTF.bufferViews, accessor);
1791
- } else {
1792
- return null;
1793
- }
1794
- }, function() {
1795
- var indexAccessor = glTF.accessors[gltfPrimitive.indices];
1796
- return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
1797
- }, context.keepMeshData).then(resolve);
1798
- }
1799
- });
1800
- };
1801
- var gltfMesh = glTF.meshes[i];
1802
- var primitivePromises = [];
1803
- for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
1804
- meshPromises[i] = Promise.all(primitivePromises);
1805
- };
1806
- var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
1807
- var engine = glTFResource.engine;
1808
- if (!glTF.meshes) return;
1809
- var meshesPromiseInfo = context.meshesPromiseInfo;
1810
- var meshPromises = [];
1811
- for(var i = 0; i < glTF.meshes.length; i++)_loop(i);
1812
- miniprogram.AssetPromise.all(meshPromises).then(function(meshes) {
1813
- glTFResource.meshes = meshes;
1814
- meshesPromiseInfo.resolve(meshes);
1815
- }).catch(meshesPromiseInfo.reject);
1816
- return meshesPromiseInfo.promise;
1817
- };
1818
- /**
1819
- * @internal
1820
- */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1802
+ _proto._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
1821
1803
  var accessors = gltf.accessors;
1822
1804
  context.buffers;
1823
1805
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
@@ -1829,14 +1811,14 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1829
1811
  keepMeshData && (positions = new Array(vertexCount));
1830
1812
  for(var attribute in attributes){
1831
1813
  var accessor = accessors[attributes[attribute]];
1832
- var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
1833
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
1814
+ var accessorBuffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor);
1815
+ var dataElmentSize = GLTFUtil.getAccessorTypeSize(accessor.type);
1834
1816
  var attributeCount = accessor.count;
1835
1817
  var vertices = accessorBuffer.data;
1836
1818
  var vertexElement = void 0;
1837
1819
  var meshId = mesh.instanceId;
1838
1820
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
1839
- var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
1821
+ var elementFormat = GLTFUtil.getElementFormat(accessor.componentType, dataElmentSize, accessor.normalized);
1840
1822
  if (accessorBuffer.interleaved) {
1841
1823
  var byteOffset = accessor.byteOffset || 0;
1842
1824
  var stride = accessorBuffer.stride;
@@ -1848,7 +1830,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1848
1830
  vertexBuffer = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1849
1831
  vertexBuffer.setData(vertices);
1850
1832
  accessorBuffer.vertexBuffer = vertexBuffer;
1851
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
1852
1833
  }
1853
1834
  mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
1854
1835
  vertexBindingInfos[meshId] = bufferBindIndex++;
@@ -1859,7 +1840,6 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1859
1840
  vertexElement = new miniprogram.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
1860
1841
  var vertexBuffer1 = new miniprogram.Buffer(engine, miniprogram.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram.BufferUsage.Static);
1861
1842
  vertexBuffer1.setData(vertices);
1862
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
1863
1843
  mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
1864
1844
  vertexBindingInfos[meshId] = bufferBindIndex++;
1865
1845
  }
@@ -1878,7 +1858,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1878
1858
  }
1879
1859
  }
1880
1860
  } else {
1881
- var position = GLTFMeshParser._tempVector3;
1861
+ var position = MeshParser._tempVector3;
1882
1862
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1883
1863
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1884
1864
  var stride2 = vertices.length / attributeCount;
@@ -1887,12 +1867,13 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1887
1867
  position.copyFromArray(vertices, offset1);
1888
1868
  miniprogram$1.Vector3.min(min, position, min);
1889
1869
  miniprogram$1.Vector3.max(max, position, max);
1870
+ keepMeshData && (positions[j1] = position.clone());
1890
1871
  }
1891
1872
  }
1892
1873
  if (accessor.normalized) {
1893
- var scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType);
1894
- min.scale(scaleFactor);
1895
- max.scale(scaleFactor);
1874
+ var sacleFactor = GLTFUtil.getNormalizedComponentScale(accessor.componentType);
1875
+ min.scale(sacleFactor);
1876
+ max.scale(sacleFactor);
1896
1877
  }
1897
1878
  }
1898
1879
  }
@@ -1900,72 +1881,179 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1900
1881
  // Indices
1901
1882
  if (indices !== undefined) {
1902
1883
  var indexAccessor = gltf.accessors[indices];
1903
- var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
1904
- mesh.setIndices(accessorBuffer1.data);
1884
+ var indexData = getIndexBufferData();
1885
+ mesh.setIndices(indexData);
1905
1886
  mesh.addSubMesh(0, indexAccessor.count, mode);
1906
- meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
1907
1887
  } else {
1908
1888
  mesh.addSubMesh(0, vertexCount, mode);
1909
1889
  }
1910
1890
  // BlendShapes
1911
- targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
1891
+ targets && this._createBlendShape(mesh, gltfMesh, targets, getBlendShapeData);
1912
1892
  mesh.uploadData(!keepMeshData);
1913
1893
  //@ts-ignore
1914
1894
  mesh._positions = positions;
1915
1895
  return Promise.resolve(mesh);
1916
1896
  };
1917
- /**
1918
- * @internal
1919
- */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
1897
+ _proto._createBlendShape = function _createBlendShape(mesh, glTFMesh, glTFTargets, getBlendShapeData) {
1920
1898
  var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
1921
1899
  for(var i = 0, n = glTFTargets.length; i < n; i++){
1922
1900
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1923
- var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
1924
- var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
1925
- var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
1926
- var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
1927
- var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
1928
- var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
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;
1929
1907
  var blendShape = new miniprogram.BlendShape(name);
1930
1908
  blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
1931
1909
  mesh.addBlendShape(blendShape);
1932
- meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
1933
1910
  }
1934
1911
  };
1935
- return GLTFMeshParser;
1936
- }(GLTFParser);
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);
1937
2016
  (function() {
1938
- GLTFMeshParser._tempVector3 = new miniprogram$1.Vector3();
2017
+ MeshParser._tempVector3 = new miniprogram$1.Vector3();
1939
2018
  })();
1940
2019
 
1941
- var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
1942
- _inherits(GLTFSceneParser, GLTFParser1);
1943
- function GLTFSceneParser() {
1944
- return GLTFParser1.apply(this, arguments);
2020
+ var SceneParser$1 = /*#__PURE__*/ function(Parser1) {
2021
+ _inherits(SceneParser, Parser1);
2022
+ function SceneParser() {
2023
+ return Parser1.apply(this, arguments);
1945
2024
  }
1946
- var _proto = GLTFSceneParser.prototype;
2025
+ var _proto = SceneParser.prototype;
1947
2026
  _proto.parse = function parse(context) {
1948
- var glTFResource = context.glTFResource, glTF = context.glTF;
2027
+ var glTFResource = context.glTFResource, gltf = context.gltf;
1949
2028
  var entities = glTFResource.entities;
1950
- var nodes = glTF.nodes, cameras = glTF.cameras;
2029
+ var nodes = gltf.nodes, gltfCameras = gltf.cameras;
1951
2030
  if (!nodes) return;
1952
2031
  var defaultSceneRootPromiseInfo = context.defaultSceneRootPromiseInfo;
2032
+ var promises = [];
1953
2033
  for(var i = 0; i < nodes.length; i++){
1954
- var glTFNode = nodes[i];
1955
- var cameraID = glTFNode.camera, meshID = glTFNode.mesh, extensions = glTFNode.extensions;
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;
1956
2037
  var entity = entities[i];
1957
2038
  if (cameraID !== undefined) {
1958
- this._createCamera(glTFResource, cameras[cameraID], entity);
2039
+ this._createCamera(glTFResource, gltfCameras[cameraID], entity);
1959
2040
  }
1960
2041
  if (meshID !== undefined) {
1961
- this._createRenderer(context, glTFNode, entity);
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);
1962
2048
  }
1963
- GLTFParser.executeExtensionsAdditiveAndParse(extensions, context, entity, glTFNode);
1964
2049
  }
1965
2050
  if (glTFResource.defaultSceneRoot) {
1966
2051
  this._createAnimator(context);
1967
2052
  }
1968
- defaultSceneRootPromiseInfo.resolve(glTFResource.defaultSceneRoot);
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);
1969
2057
  return defaultSceneRootPromiseInfo.promise;
1970
2058
  };
1971
2059
  _proto._createCamera = function _createCamera(context, cameraSchema, entity) {
@@ -2001,16 +2089,8 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2001
2089
  // @todo: use engine camera by default
2002
2090
  camera.enabled = false;
2003
2091
  };
2004
- _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
2005
- var glTFResource = context.glTFResource, glTF = context.glTF;
2006
- var glTFMeshes = glTF.meshes;
2007
- var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2008
- var meshID = glTFNode.mesh, skinID = glTFNode.skin;
2009
- var glTFMesh = glTFMeshes[meshID];
2010
- var glTFMeshPrimitives = glTFMesh.primitives;
2011
- var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
2012
- for(var i = 0; i < glTFMeshPrimitives.length; i++){
2013
- var gltfPrimitive = glTFMeshPrimitives[i];
2092
+ _proto._createRenderer = function _createRenderer(context, gltfNode, entity) {
2093
+ var _loop = function(i) {
2014
2094
  var mesh = meshes[meshID][i];
2015
2095
  var renderer = void 0;
2016
2096
  if (skinID !== undefined || blendShapeWeights) {
@@ -2028,11 +2108,32 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2028
2108
  renderer = entity.addComponent(miniprogram.MeshRenderer);
2029
2109
  renderer.mesh = mesh;
2030
2110
  }
2031
- var materialIndex = gltfPrimitive.material;
2032
- var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
2033
- renderer.setMaterial(material);
2034
- GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
2035
- }
2111
+ var materialIndex = gltfMeshPrimitives[i].material;
2112
+ var remapMaterials = gltf.extensions && gltf.extensions["OASIS_materials_remap"];
2113
+ if (remapMaterials && remapMaterials[materialIndex]) {
2114
+ promises.push(remapMaterials[materialIndex].then(function(mtl) {
2115
+ renderer.setMaterial(mtl);
2116
+ }));
2117
+ } else {
2118
+ var material = (materials == null ? void 0 : materials[materialIndex]) || SceneParser._getDefaultMaterial(engine);
2119
+ renderer.setMaterial(material);
2120
+ }
2121
+ var _gltfMeshPrimitives_i = gltfMeshPrimitives[i], _gltfMeshPrimitives_i_extensions = _gltfMeshPrimitives_i.extensions, extensions = _gltfMeshPrimitives_i_extensions === void 0 ? {} : _gltfMeshPrimitives_i_extensions;
2122
+ var KHR_materials_variants = extensions.KHR_materials_variants;
2123
+ if (KHR_materials_variants) {
2124
+ Parser.parseEngineResource("KHR_materials_variants", KHR_materials_variants, renderer, context);
2125
+ }
2126
+ };
2127
+ var glTFResource = context.glTFResource, gltf = context.gltf;
2128
+ var gltfMeshes = gltf.meshes;
2129
+ var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
2130
+ var meshID = gltfNode.mesh, skinID = gltfNode.skin;
2131
+ var glTFMesh = gltfMeshes[meshID];
2132
+ var gltfMeshPrimitives = glTFMesh.primitives;
2133
+ var blendShapeWeights = gltfNode.weights || glTFMesh.weights;
2134
+ var promises = [];
2135
+ for(var i = 0; i < gltfMeshPrimitives.length; i++)_loop(i);
2136
+ return Promise.all(promises);
2036
2137
  };
2037
2138
  _proto._createAnimator = function _createAnimator(context) {
2038
2139
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -2059,25 +2160,25 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
2059
2160
  }
2060
2161
  }
2061
2162
  };
2062
- GLTFSceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2063
- if (!GLTFSceneParser._defaultMaterial) {
2064
- GLTFSceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
2163
+ SceneParser._getDefaultMaterial = function _getDefaultMaterial(engine) {
2164
+ if (!SceneParser._defaultMaterial) {
2165
+ SceneParser._defaultMaterial = new miniprogram.BlinnPhongMaterial(engine);
2065
2166
  }
2066
- return GLTFSceneParser._defaultMaterial;
2167
+ return SceneParser._defaultMaterial;
2067
2168
  };
2068
- return GLTFSceneParser;
2069
- }(GLTFParser);
2169
+ return SceneParser;
2170
+ }(Parser);
2070
2171
 
2071
- var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2072
- _inherits(GLTFSkinParser, GLTFParser);
2073
- function GLTFSkinParser() {
2074
- return GLTFParser.apply(this, arguments);
2172
+ var SkinParser = /*#__PURE__*/ function(Parser) {
2173
+ _inherits(SkinParser, Parser);
2174
+ function SkinParser() {
2175
+ return Parser.apply(this, arguments);
2075
2176
  }
2076
- var _proto = GLTFSkinParser.prototype;
2177
+ var _proto = SkinParser.prototype;
2077
2178
  _proto.parse = function parse(context) {
2078
- var glTFResource = context.glTFResource, glTF = context.glTF; context.buffers;
2179
+ var glTFResource = context.glTFResource, gltf = context.gltf; context.buffers;
2079
2180
  var entities = glTFResource.entities;
2080
- var gltfSkins = glTF.skins;
2181
+ var gltfSkins = gltf.skins;
2081
2182
  if (!gltfSkins) return;
2082
2183
  var count = gltfSkins.length;
2083
2184
  var skins = new Array(count);
@@ -2087,8 +2188,8 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2087
2188
  var skin = new miniprogram.Skin(name);
2088
2189
  skin.inverseBindMatrices.length = jointCount;
2089
2190
  // parse IBM
2090
- var accessor = glTF.accessors[inverseBindMatrices];
2091
- var buffer = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
2191
+ var accessor = gltf.accessors[inverseBindMatrices];
2192
+ var buffer = GLTFUtil.getAccessorBuffer(context, gltf, accessor).data;
2092
2193
  for(var i1 = 0; i1 < jointCount; i1++){
2093
2194
  var inverseBindMatrix = new miniprogram$1.Matrix();
2094
2195
  inverseBindMatrix.copyFromArray(buffer, i1 * 16);
@@ -2149,55 +2250,52 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser) {
2149
2250
  rootNode = entity1;
2150
2251
  }
2151
2252
  };
2152
- return GLTFSkinParser;
2153
- }(GLTFParser);
2253
+ return SkinParser;
2254
+ }(Parser);
2154
2255
 
2155
- var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2156
- _inherits(GLTFTextureParser, GLTFParser);
2157
- function GLTFTextureParser() {
2158
- return GLTFParser.apply(this, arguments);
2256
+ var TextureParser = /*#__PURE__*/ function(Parser) {
2257
+ _inherits(TextureParser, Parser);
2258
+ function TextureParser() {
2259
+ return Parser.apply(this, arguments);
2159
2260
  }
2160
- var _proto = GLTFTextureParser.prototype;
2261
+ var _proto = TextureParser.prototype;
2161
2262
  _proto.parse = function parse(context) {
2162
2263
  var _this = this;
2163
- var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
2264
+ var glTFResource = context.glTFResource, gltf = context.gltf, buffers = context.buffers;
2164
2265
  var engine = glTFResource.engine, url = glTFResource.url;
2165
- if (glTF.textures) {
2266
+ if (gltf.textures) {
2166
2267
  var texturesPromiseInfo = context.texturesPromiseInfo;
2167
- miniprogram.AssetPromise.all(glTF.textures.map(function(param, index) {
2268
+ miniprogram.AssetPromise.all(gltf.textures.map(function(param, index) {
2168
2269
  var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
2169
- 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;
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;
2170
2271
  if (uri) {
2171
2272
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
2172
2273
  var index1 = uri.lastIndexOf(".");
2173
2274
  var ext = uri.substring(index1 + 1);
2174
2275
  var type = ext.startsWith("ktx") ? miniprogram.AssetType.KTX : miniprogram.AssetType.Texture2D;
2175
2276
  return engine.resourceManager.load({
2176
- url: miniprogram.Utils.resolveAbsoluteUrl(url, uri),
2277
+ url: GLTFUtil.parseRelativeUrl(url, uri),
2177
2278
  type: type
2178
2279
  }).then(function(texture) {
2179
2280
  if (!texture.name) {
2180
2281
  texture.name = textureName || imageName || "texture_" + index1;
2181
2282
  }
2182
2283
  if (sampler !== undefined) {
2183
- _this._parseSampler(texture, glTF.samplers[sampler]);
2284
+ _this._parseSampler(texture, gltf.samplers[sampler]);
2184
2285
  }
2185
2286
  return texture;
2186
2287
  });
2187
2288
  } else {
2188
- var bufferView = glTF.bufferViews[bufferViewIndex];
2189
- var buffer = buffers[bufferView.buffer];
2190
- var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
2191
- return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
2289
+ var bufferView = gltf.bufferViews[bufferViewIndex];
2290
+ var bufferViewData = GLTFUtil.getBufferViewData(bufferView, buffers);
2291
+ return GLTFUtil.loadImageBuffer(bufferViewData, mimeType).then(function(image) {
2192
2292
  var texture = new miniprogram.Texture2D(engine, image.width, image.height);
2193
2293
  texture.setImageSource(image);
2194
2294
  texture.generateMipmaps();
2195
2295
  texture.name = textureName || imageName || "texture_" + index;
2196
2296
  if (sampler !== undefined) {
2197
- _this._parseSampler(texture, glTF.samplers[sampler]);
2297
+ _this._parseSampler(texture, gltf.samplers[sampler]);
2198
2298
  }
2199
- var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
2200
- context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
2201
2299
  return texture;
2202
2300
  });
2203
2301
  }
@@ -2220,38 +2318,36 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2220
2318
  }
2221
2319
  }
2222
2320
  if (wrapS) {
2223
- texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
2321
+ texture.wrapModeU = TextureParser._wrapMap[wrapS];
2224
2322
  }
2225
2323
  if (wrapT) {
2226
- texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
2324
+ texture.wrapModeV = TextureParser._wrapMap[wrapT];
2227
2325
  }
2228
2326
  };
2229
- return GLTFTextureParser;
2230
- }(GLTFParser);
2327
+ return TextureParser;
2328
+ }(Parser);
2231
2329
  (function() {
2232
2330
  var _obj;
2233
- GLTFTextureParser._wrapMap = (_obj = {}, _obj[TextureWrapMode.CLAMP_TO_EDGE] = miniprogram.TextureWrapMode.Clamp, _obj[TextureWrapMode.MIRRORED_REPEAT] = miniprogram.TextureWrapMode.Mirror, _obj[TextureWrapMode.REPEAT] = miniprogram.TextureWrapMode.Repeat, _obj);
2331
+ 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);
2234
2332
  })();
2235
2333
 
2236
- var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2237
- _inherits(GLTFValidator, GLTFParser1);
2238
- function GLTFValidator() {
2239
- return GLTFParser1.apply(this, arguments);
2334
+ var Validator = /*#__PURE__*/ function(Parser1) {
2335
+ _inherits(Validator, Parser1);
2336
+ function Validator() {
2337
+ return Parser1.apply(this, arguments);
2240
2338
  }
2241
- var _proto = GLTFValidator.prototype;
2339
+ var _proto = Validator.prototype;
2242
2340
  _proto.parse = function parse(context) {
2243
- var _context_glTF = context.glTF, version = _context_glTF.asset.version, extensionsUsed = _context_glTF.extensionsUsed, extensionsRequired = _context_glTF.extensionsRequired;
2244
- var glTFVersion = Number(version);
2245
- if (!(glTFVersion >= 2 && glTFVersion < 3)) {
2246
- throw "Only support glTF 2.x.";
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.";
2247
2345
  }
2248
- var promises = [];
2249
2346
  if (extensionsUsed) {
2250
2347
  miniprogram.Logger.info("extensionsUsed: ", extensionsUsed);
2251
2348
  for(var i = 0; i < extensionsUsed.length; i++){
2252
- var extensionUsed = extensionsUsed[i];
2253
- if (!GLTFParser.hasExtensionParser(extensionUsed)) {
2254
- miniprogram.Logger.warn("Extension " + extensionUsed + " is not implemented, you can customize this extension in gltf.");
2349
+ if (!Parser.hasExtensionParser(extensionsUsed[i])) {
2350
+ miniprogram.Logger.warn("Extension " + extensionsUsed[i] + " is not implemented, you can customize this extension in gltf.");
2255
2351
  }
2256
2352
  }
2257
2353
  }
@@ -2259,68 +2355,68 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2259
2355
  miniprogram.Logger.info("extensionsRequired: " + extensionsRequired);
2260
2356
  for(var i1 = 0; i1 < extensionsRequired.length; i1++){
2261
2357
  var extensionRequired = extensionsRequired[i1];
2262
- if (!GLTFParser.hasExtensionParser(extensionRequired)) {
2358
+ if (!Parser.hasExtensionParser(extensionRequired)) {
2263
2359
  miniprogram.Logger.error("GLTF parser has not supported required extension " + extensionRequired + ".");
2264
2360
  } else {
2265
- promises.push(GLTFParser.executeExtensionsInitialize(extensionRequired));
2361
+ Parser.initialize(extensionRequired);
2266
2362
  }
2267
2363
  }
2268
2364
  }
2269
- return miniprogram.AssetPromise.all(promises).then(null);
2270
2365
  };
2271
- return GLTFValidator;
2272
- }(GLTFParser);
2366
+ return Validator;
2367
+ }(Parser);
2273
2368
 
2274
- /**
2275
- * GLTF pipeline.
2276
- */ var GLTFPipeline = /*#__PURE__*/ function() {
2277
- function GLTFPipeline() {
2278
- for(var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++){
2279
- parsers[_key] = arguments[_key];
2280
- }
2369
+ var GLTFParser = /*#__PURE__*/ function() {
2370
+ function GLTFParser(pipes) {
2281
2371
  var _this = this;
2282
- this._parsers = [];
2283
- parsers.forEach(function(pipe, index) {
2284
- _this._parsers[index] = new pipe();
2372
+ this._pipes = [];
2373
+ pipes.forEach(function(pipe, index) {
2374
+ _this._pipes[index] = new pipe();
2285
2375
  });
2286
2376
  }
2287
- var _proto = GLTFPipeline.prototype;
2288
- /**
2289
- * @internal
2290
- */ _proto._parse = function _parse(context) {
2377
+ var _proto = GLTFParser.prototype;
2378
+ _proto.parse = function parse(context) {
2291
2379
  var _this = this;
2292
2380
  var glTFResource = context.glTFResource;
2293
- var lastParser;
2381
+ var lastPipe;
2294
2382
  return new miniprogram.AssetPromise(function(resolve, reject) {
2295
- _this._parsers.forEach(function(parser) {
2296
- if (lastParser) {
2297
- lastParser = lastParser.then(function() {
2383
+ _this._pipes.forEach(function(parser) {
2384
+ if (lastPipe) {
2385
+ lastPipe = lastPipe.then(function() {
2298
2386
  return parser.parse(context);
2299
2387
  });
2300
- if (lastParser.cancel) {
2301
- context.chainPromises.push(lastParser);
2388
+ if (lastPipe.cancel) {
2389
+ context.chainPromises.push(lastPipe);
2302
2390
  }
2303
2391
  } else {
2304
- lastParser = parser.parse(context);
2392
+ lastPipe = parser.parse(context);
2305
2393
  }
2306
2394
  });
2307
- if (lastParser) {
2308
- lastParser.then(function() {
2395
+ if (lastPipe) {
2396
+ lastPipe.then(function() {
2309
2397
  resolve(glTFResource);
2310
2398
  }).catch(reject);
2311
2399
  }
2312
2400
  });
2313
2401
  };
2314
- return GLTFPipeline;
2402
+ return GLTFParser;
2315
2403
  }();
2316
2404
  (function() {
2317
- /**
2318
- * Default pipeline.
2319
- */ GLTFPipeline.defaultPipeline = new GLTFPipeline(GLTFBufferParser, GLTFValidator, GLTFTextureParser, GLTFMaterialParser, GLTFMeshParser, GLTFEntityParser, GLTFSkinParser, GLTFAnimationParser, GLTFSceneParser);
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
+ ]);
2320
2416
  })();
2321
2417
 
2322
2418
  /**
2323
- * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
2419
+ * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
2324
2420
  */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
2325
2421
  _inherits(GLTFResource, EngineObject);
2326
2422
  function GLTFResource(engine, url) {
@@ -2332,8 +2428,11 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2332
2428
  var _proto = GLTFResource.prototype;
2333
2429
  /**
2334
2430
  * @override
2335
- */ _proto._onDestroy = function _onDestroy() {
2336
- EngineObject.prototype._onDestroy.call(this);
2431
+ */ _proto.destroy = function destroy() {
2432
+ if (this._destroyed) {
2433
+ return;
2434
+ }
2435
+ EngineObject.prototype.destroy.call(this);
2337
2436
  this.defaultSceneRoot.destroy();
2338
2437
  this.textures = null;
2339
2438
  this.materials = null;
@@ -2344,7 +2443,7 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
2344
2443
  this.cameras = null;
2345
2444
  this.lights = null;
2346
2445
  this.sceneRoots = null;
2347
- this.extensionsData = null;
2446
+ this.variants = null;
2348
2447
  };
2349
2448
  return GLTFResource;
2350
2449
  }(miniprogram.EngineObject);
@@ -2355,19 +2454,15 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2355
2454
  return Loader.apply(this, arguments);
2356
2455
  }
2357
2456
  var _proto = GLTFLoader.prototype;
2358
- /**
2359
- * @override
2360
- */ _proto.load = function load(item, resourceManager) {
2457
+ _proto.load = function load(item, resourceManager) {
2458
+ var _item_params;
2361
2459
  var url = item.url;
2362
- var params = item.params;
2363
- var context = new GLTFParserContext(url);
2460
+ var context = new ParserContext(url);
2364
2461
  var glTFResource = new GLTFResource(resourceManager.engine, url);
2365
- var restorer = new GLTFContentRestorer(glTFResource);
2366
2462
  var masterPromiseInfo = context.masterPromiseInfo;
2367
- context.contentRestorer = restorer;
2368
2463
  context.glTFResource = glTFResource;
2369
- var _params_keepMeshData;
2370
- context.keepMeshData = (_params_keepMeshData = params == null ? void 0 : params.keepMeshData) != null ? _params_keepMeshData : false;
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;
2371
2466
  masterPromiseInfo.onCancel(function() {
2372
2467
  var chainPromises = context.chainPromises;
2373
2468
  for(var _iterator = _create_for_of_iterator_helper_loose(chainPromises), _step; !(_step = _iterator()).done;){
@@ -2375,10 +2470,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2375
2470
  promise.cancel();
2376
2471
  }
2377
2472
  });
2378
- ((params == null ? void 0 : params.pipeline) || GLTFPipeline.defaultPipeline)._parse(context).then(function(glTFResource) {
2379
- resourceManager.addContentRestorer(restorer);
2380
- masterPromiseInfo.resolve(glTFResource);
2381
- }).catch(function(e) {
2473
+ GLTFParser.defaultPipeline.parse(context).then(masterPromiseInfo.resolve).catch(function(e) {
2382
2474
  console.error(e);
2383
2475
  masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
2384
2476
  });
@@ -2387,7 +2479,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2387
2479
  return GLTFLoader;
2388
2480
  }(miniprogram.Loader);
2389
2481
  GLTFLoader = __decorate([
2390
- miniprogram.resourceLoader(miniprogram.AssetType.GLTF, [
2482
+ miniprogram.resourceLoader(miniprogram.AssetType.Prefab, [
2391
2483
  "gltf",
2392
2484
  "glb"
2393
2485
  ])
@@ -2473,7 +2565,7 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader) {
2473
2565
  return textureArray;
2474
2566
  };
2475
2567
  HDRLoader1._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
2476
- var theta = Math.atan2(vDir.z, vDir.x);
2568
+ var theta = Math.atan2(vDir.z, -vDir.x);
2477
2569
  var phi = Math.acos(vDir.y);
2478
2570
  while(theta < -PI){
2479
2571
  theta += 2 * PI;
@@ -2775,40 +2867,40 @@ function getEngineFormat(internalFormat) {
2775
2867
  // case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT3_EXT:
2776
2868
  // case GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2777
2869
  // break;
2778
- case miniprogram$2.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
2870
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT:
2779
2871
  return miniprogram.TextureFormat.DXT1;
2780
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2872
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT:
2781
2873
  return miniprogram.TextureFormat.DXT5;
2782
- case miniprogram$2.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
2874
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL:
2783
2875
  return miniprogram.TextureFormat.ETC1_RGB;
2784
- case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_ETC2:
2876
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_ETC2:
2785
2877
  return miniprogram.TextureFormat.ETC2_RGB;
2786
- case miniprogram$2.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
2878
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
2787
2879
  return miniprogram.TextureFormat.ETC2_RGBA5;
2788
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
2880
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC:
2789
2881
  return miniprogram.TextureFormat.ETC2_RGBA8;
2790
- case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
2882
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG:
2791
2883
  return miniprogram.TextureFormat.PVRTC_RGB2;
2792
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
2884
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG:
2793
2885
  return miniprogram.TextureFormat.PVRTC_RGBA2;
2794
- case miniprogram$2.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
2886
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG:
2795
2887
  return miniprogram.TextureFormat.PVRTC_RGB4;
2796
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
2888
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG:
2797
2889
  return miniprogram.TextureFormat.PVRTC_RGBA4;
2798
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
2890
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR:
2799
2891
  return miniprogram.TextureFormat.ASTC_4x4;
2800
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
2892
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR:
2801
2893
  return miniprogram.TextureFormat.ASTC_5x5;
2802
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
2894
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR:
2803
2895
  return miniprogram.TextureFormat.ASTC_6x6;
2804
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
2896
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR:
2805
2897
  return miniprogram.TextureFormat.ASTC_8x8;
2806
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
2898
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR:
2807
2899
  return miniprogram.TextureFormat.ASTC_10x10;
2808
- case miniprogram$2.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
2900
+ case miniprogram$3.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR:
2809
2901
  return miniprogram.TextureFormat.ASTC_12x12;
2810
2902
  default:
2811
- var formatName = miniprogram$2.GLCompressedTextureInternalFormat[internalFormat];
2903
+ var formatName = miniprogram$3.GLCompressedTextureInternalFormat[internalFormat];
2812
2904
  throw new Error("this format is not supported in Galacean Engine: " + formatName);
2813
2905
  }
2814
2906
  }
@@ -3156,7 +3248,7 @@ var BufferReader = /*#__PURE__*/ function() {
3156
3248
  var strByteLength = this.nextUint16();
3157
3249
  var uint8Array = new Uint8Array(this.buffer, this._offset, strByteLength);
3158
3250
  this._offset += strByteLength;
3159
- return miniprogram.Utils.decodeText(uint8Array);
3251
+ return GLTFUtil.decodeText(uint8Array);
3160
3252
  };
3161
3253
  /**
3162
3254
  * image data 放在最后
@@ -3241,8 +3333,8 @@ var FileHeader = /*#__PURE__*/ function() {
3241
3333
  var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
3242
3334
  var nameLen = dataView.getUint16(7 + typeLen, true);
3243
3335
  var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
3244
- var name = miniprogram.Utils.decodeText(nameUint8Array);
3245
- var type = miniprogram.Utils.decodeText(typeUint8Array);
3336
+ var name = GLTFUtil.decodeText(nameUint8Array);
3337
+ var type = GLTFUtil.decodeText(typeUint8Array);
3246
3338
  var header = new FileHeader();
3247
3339
  header.totalLength = totalLen;
3248
3340
  header.name = name;
@@ -4192,57 +4284,28 @@ SpriteLoader = __decorate([
4192
4284
  ], false)
4193
4285
  ], SpriteLoader);
4194
4286
 
4195
- /**
4196
- * @internal
4197
- */ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4198
- _inherits(Texture2DContentRestorer, ContentRestorer);
4199
- function Texture2DContentRestorer(resource, url, requestConfig) {
4200
- var _this;
4201
- _this = ContentRestorer.call(this, resource) || this;
4202
- _this.url = url;
4203
- _this.requestConfig = requestConfig;
4204
- return _this;
4205
- }
4206
- var _proto = Texture2DContentRestorer.prototype;
4207
- /**
4208
- * @override
4209
- */ _proto.restoreContent = function restoreContent() {
4210
- var _this = this;
4211
- return miniprogram.request(this.url, this.requestConfig).then(function(image) {
4212
- var resource = _this.resource;
4213
- resource.setImageSource(image);
4214
- resource.generateMipmaps();
4215
- return resource;
4216
- });
4217
- };
4218
- return Texture2DContentRestorer;
4219
- }(miniprogram.ContentRestorer);
4220
-
4221
4287
  var Texture2DLoader = /*#__PURE__*/ function(Loader) {
4222
4288
  _inherits(Texture2DLoader, Loader);
4223
4289
  function Texture2DLoader() {
4224
4290
  return Loader.apply(this, arguments);
4225
4291
  }
4226
4292
  var _proto = Texture2DLoader.prototype;
4227
- /**
4228
- * @override
4229
- */ _proto.load = function load(item, resourceManager) {
4293
+ _proto.load = function load(item, resourceManager) {
4230
4294
  var _this = this;
4231
4295
  return new miniprogram.AssetPromise(function(resolve, reject) {
4232
- var url = item.url;
4233
- var requestConfig = _extends({}, item, {
4296
+ _this.request(item.url, _extends({}, item, {
4234
4297
  type: "image"
4235
- });
4236
- _this.request(url, requestConfig).then(function(image) {
4237
- var params = item.params;
4238
- var texture = new miniprogram.Texture2D(resourceManager.engine, image.width, image.height, params == null ? void 0 : params.format, params == null ? void 0 : params.mipmap);
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;
4239
4303
  texture.setImageSource(image);
4240
4304
  texture.generateMipmaps();
4241
- if (url.indexOf("data:") !== 0) {
4242
- var index = url.lastIndexOf("/");
4243
- texture.name = url.substring(index + 1);
4305
+ if (item.url.indexOf("data:") !== 0) {
4306
+ var splitPath = item.url.split("/");
4307
+ texture.name = splitPath[splitPath.length - 1];
4244
4308
  }
4245
- resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
4246
4309
  resolve(texture);
4247
4310
  }).catch(function(e) {
4248
4311
  reject(e);
@@ -4260,70 +4323,32 @@ Texture2DLoader = __decorate([
4260
4323
  ])
4261
4324
  ], Texture2DLoader);
4262
4325
 
4263
- /**
4264
- * @internal
4265
- */ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
4266
- _inherits(TextureCubeContentRestorer, ContentRestorer);
4267
- function TextureCubeContentRestorer(resource, urls, requestConfig) {
4268
- var _this;
4269
- _this = ContentRestorer.call(this, resource) || this;
4270
- _this.urls = urls;
4271
- _this.requestConfig = requestConfig;
4272
- return _this;
4273
- }
4274
- var _proto = TextureCubeContentRestorer.prototype;
4275
- /**
4276
- * @override
4277
- */ _proto.restoreContent = function restoreContent() {
4278
- var _this = this;
4279
- return new miniprogram.AssetPromise(function(resolve, reject) {
4280
- Promise.all(_this.urls.map(function(url) {
4281
- return miniprogram.request(url, _this.requestConfig);
4282
- })).then(function(images) {
4283
- var resource = _this.resource;
4284
- for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4285
- resource.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4286
- }
4287
- resource.generateMipmaps();
4288
- resolve(resource);
4289
- }).catch(function(e) {
4290
- reject(e);
4291
- });
4292
- });
4293
- };
4294
- return TextureCubeContentRestorer;
4295
- }(miniprogram.ContentRestorer);
4296
-
4297
4326
  var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
4298
4327
  _inherits(TextureCubeLoader, Loader);
4299
4328
  function TextureCubeLoader() {
4300
4329
  return Loader.apply(this, arguments);
4301
4330
  }
4302
4331
  var _proto = TextureCubeLoader.prototype;
4303
- /**
4304
- * @override
4305
- */ _proto.load = function load(item, resourceManager) {
4332
+ _proto.load = function load(item, resourceManager) {
4306
4333
  var _this = this;
4307
4334
  return new miniprogram.AssetPromise(function(resolve, reject) {
4308
- var urls = item.urls;
4309
- var requestConfig = _extends({}, item, {
4310
- type: "image"
4311
- });
4312
- Promise.all(urls.map(function(url) {
4313
- return _this.request(url, requestConfig);
4335
+ Promise.all(item.urls.map(function(url) {
4336
+ return _this.request(url, _extends({}, item, {
4337
+ type: "image"
4338
+ }));
4314
4339
  })).then(function(images) {
4315
4340
  var _images_ = images[0], width = _images_.width, height = _images_.height;
4316
4341
  if (width !== height) {
4317
4342
  console.error("The cube texture must have the same width and height");
4318
4343
  return;
4319
4344
  }
4320
- var texture = new miniprogram.TextureCube(resourceManager.engine, width);
4345
+ var tex = new miniprogram.TextureCube(resourceManager.engine, width);
4346
+ /** @ts-ignore */ if (!tex._platformTexture) return;
4321
4347
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
4322
- texture.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4348
+ tex.setImageSource(miniprogram.TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
4323
4349
  }
4324
- texture.generateMipmaps();
4325
- resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
4326
- resolve(texture);
4350
+ tex.generateMipmaps();
4351
+ resolve(tex);
4327
4352
  }).catch(function(e) {
4328
4353
  reject(e);
4329
4354
  });
@@ -4337,30 +4362,6 @@ TextureCubeLoader = __decorate([
4337
4362
  ])
4338
4363
  ], TextureCubeLoader);
4339
4364
 
4340
- var AnimationClipLoader = /*#__PURE__*/ function(Loader) {
4341
- _inherits(AnimationClipLoader, Loader);
4342
- function AnimationClipLoader() {
4343
- return Loader.apply(this, arguments);
4344
- }
4345
- var _proto = AnimationClipLoader.prototype;
4346
- _proto.load = function load(item, resourceManager) {
4347
- var _this = this;
4348
- return new miniprogram.AssetPromise(function(resolve, reject) {
4349
- _this.request(item.url, _extends({}, item, {
4350
- type: "arraybuffer"
4351
- })).then(function(data) {
4352
- return decode(data, resourceManager.engine);
4353
- }).catch(reject);
4354
- });
4355
- };
4356
- return AnimationClipLoader;
4357
- }(miniprogram.Loader);
4358
- AnimationClipLoader = __decorate([
4359
- miniprogram.resourceLoader(miniprogram.AssetType.AnimationClip, [
4360
- "ani"
4361
- ])
4362
- ], AnimationClipLoader);
4363
-
4364
4365
  var SceneLoader = /*#__PURE__*/ function(Loader) {
4365
4366
  _inherits(SceneLoader, Loader);
4366
4367
  function SceneLoader() {
@@ -4405,7 +4406,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
4405
4406
  backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
4406
4407
  var sky = scene.background.sky;
4407
4408
  var skyMaterial = new miniprogram.SkyBoxMaterial(engine);
4408
- skyMaterial.texture = light.specularTexture;
4409
+ skyMaterial.textureCubeMap = light.specularTexture;
4409
4410
  skyMaterial.textureDecodeRGBM = true;
4410
4411
  sky.material = skyMaterial;
4411
4412
  sky.mesh = miniprogram.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
@@ -4461,410 +4462,10 @@ ReflectionParser.registerCustomParseComponent("TextRenderer", /*#__PURE__*/ _asy
4461
4462
  });
4462
4463
  }));
4463
4464
 
4464
- var _KHR_draco_mesh_compression;
4465
- var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ function(GLTFExtensionParser) {
4466
- _inherits(KHR_draco_mesh_compression1, GLTFExtensionParser);
4467
- function KHR_draco_mesh_compression1() {
4468
- return GLTFExtensionParser.apply(this, arguments);
4469
- }
4470
- var _proto = KHR_draco_mesh_compression1.prototype;
4471
- /**
4472
- * @override
4473
- */ _proto.initialize = function initialize() {
4474
- if (!KHR_draco_mesh_compression._decoder) {
4475
- KHR_draco_mesh_compression._decoder = new miniprogram$3.DRACODecoder();
4476
- }
4477
- };
4478
- /**
4479
- * @override
4480
- */ _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
4481
- var _this = this;
4482
- var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
4483
- var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
4484
- var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
4485
- var attributeMap = {};
4486
- var attributeTypeMap = {};
4487
- for(var attributeName in gltfAttributeMap){
4488
- attributeMap[attributeName] = gltfAttributeMap[attributeName];
4489
- }
4490
- for(var attributeName1 in glTFPrimitive.attributes){
4491
- if (gltfAttributeMap[attributeName1] !== undefined) {
4492
- var accessorDef = accessors[glTFPrimitive.attributes[attributeName1]];
4493
- attributeTypeMap[attributeName1] = GLTFUtils.getComponentType(accessorDef.componentType).name;
4494
- }
4495
- }
4496
- var indexAccessor = accessors[glTFPrimitive.indices];
4497
- var indexType = GLTFUtils.getComponentType(indexAccessor.componentType).name;
4498
- var taskConfig = {
4499
- attributeIDs: attributeMap,
4500
- attributeTypes: attributeTypeMap,
4501
- useUniqueIDs: true,
4502
- indexType: indexType
4503
- };
4504
- var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
4505
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
4506
- var mesh = new miniprogram.ModelMesh(engine, glTFMesh.name);
4507
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
4508
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
4509
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
4510
- return decodedGeometry.attributes[j].array;
4511
- }
4512
- }
4513
- return null;
4514
- }, function(attributeSemantic, shapeIndex) {
4515
- throw "BlendShape animation is not supported when using draco.";
4516
- }, function() {
4517
- return decodedGeometry.index.array;
4518
- }, context.keepMeshData);
4519
- });
4520
- };
4521
- _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
4522
- var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
4523
- var vertexCount;
4524
- var accessors = gltf.accessors;
4525
- var accessor = accessors[attributes["POSITION"]];
4526
- var positionBuffer = getVertexBufferData("POSITION");
4527
- var positions = GLTFUtils.floatBufferToVector3Array(positionBuffer);
4528
- mesh.setPositions(positions);
4529
- var bounds = mesh.bounds;
4530
- vertexCount = accessor.count;
4531
- if (accessor.min && accessor.max) {
4532
- bounds.min.copyFromArray(accessor.min);
4533
- bounds.max.copyFromArray(accessor.max);
4534
- } else {
4535
- var position = KHR_draco_mesh_compression._tempVector3;
4536
- var min = bounds.min, max = bounds.max;
4537
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
4538
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
4539
- var stride = positionBuffer.length / vertexCount;
4540
- for(var j = 0; j < vertexCount; j++){
4541
- var offset = j * stride;
4542
- position.copyFromArray(positionBuffer, offset);
4543
- miniprogram$1.Vector3.min(min, position, min);
4544
- miniprogram$1.Vector3.max(max, position, max);
4545
- }
4546
- }
4547
- for(var attributeSemantic in attributes){
4548
- if (attributeSemantic === "POSITION") {
4549
- continue;
4550
- }
4551
- var bufferData = getVertexBufferData(attributeSemantic);
4552
- switch(attributeSemantic){
4553
- case "NORMAL":
4554
- var normals = GLTFUtils.floatBufferToVector3Array(bufferData);
4555
- mesh.setNormals(normals);
4556
- break;
4557
- case "TEXCOORD_0":
4558
- var texturecoords = GLTFUtils.floatBufferToVector2Array(bufferData);
4559
- mesh.setUVs(texturecoords, 0);
4560
- break;
4561
- case "TEXCOORD_1":
4562
- var texturecoords1 = GLTFUtils.floatBufferToVector2Array(bufferData);
4563
- mesh.setUVs(texturecoords1, 1);
4564
- break;
4565
- case "TEXCOORD_2":
4566
- var texturecoords2 = GLTFUtils.floatBufferToVector2Array(bufferData);
4567
- mesh.setUVs(texturecoords2, 2);
4568
- break;
4569
- case "TEXCOORD_3":
4570
- var texturecoords3 = GLTFUtils.floatBufferToVector2Array(bufferData);
4571
- mesh.setUVs(texturecoords3, 3);
4572
- break;
4573
- case "TEXCOORD_4":
4574
- var texturecoords4 = GLTFUtils.floatBufferToVector2Array(bufferData);
4575
- mesh.setUVs(texturecoords4, 4);
4576
- break;
4577
- case "TEXCOORD_5":
4578
- var texturecoords5 = GLTFUtils.floatBufferToVector2Array(bufferData);
4579
- mesh.setUVs(texturecoords5, 5);
4580
- break;
4581
- case "TEXCOORD_6":
4582
- var texturecoords6 = GLTFUtils.floatBufferToVector2Array(bufferData);
4583
- mesh.setUVs(texturecoords6, 6);
4584
- break;
4585
- case "TEXCOORD_7":
4586
- var texturecoords7 = GLTFUtils.floatBufferToVector2Array(bufferData);
4587
- mesh.setUVs(texturecoords7, 7);
4588
- break;
4589
- case "COLOR_0":
4590
- var colors = GLTFUtils.floatBufferToColorArray(bufferData, accessors[attributes["COLOR_0"]].type === AccessorType.VEC3);
4591
- mesh.setColors(colors);
4592
- break;
4593
- case "TANGENT":
4594
- var tangents = GLTFUtils.floatBufferToVector4Array(bufferData);
4595
- mesh.setTangents(tangents);
4596
- break;
4597
- case "JOINTS_0":
4598
- var joints = GLTFUtils.floatBufferToVector4Array(bufferData);
4599
- mesh.setBoneIndices(joints);
4600
- break;
4601
- case "WEIGHTS_0":
4602
- var weights = GLTFUtils.floatBufferToVector4Array(bufferData);
4603
- mesh.setBoneWeights(weights);
4604
- break;
4605
- }
4606
- }
4607
- // Indices
4608
- if (indices !== undefined) {
4609
- var indexAccessor = gltf.accessors[indices];
4610
- var indexData = getIndexBufferData();
4611
- mesh.setIndices(indexData);
4612
- mesh.addSubMesh(0, indexAccessor.count, mode);
4613
- } else {
4614
- mesh.addSubMesh(0, vertexCount, mode);
4615
- }
4616
- // BlendShapes
4617
- targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
4618
- mesh.uploadData(!keepMeshData);
4619
- return Promise.resolve(mesh);
4620
- };
4621
- return KHR_draco_mesh_compression1;
4622
- }(GLTFExtensionParser), function() {
4623
- _KHR_draco_mesh_compression._tempVector3 = new miniprogram$1.Vector3();
4624
- }(), _KHR_draco_mesh_compression);
4625
- KHR_draco_mesh_compression = __decorate([
4626
- registerGLTFExtension("KHR_draco_mesh_compression", exports.GLTFExtensionMode.CreateAndParse)
4627
- ], KHR_draco_mesh_compression);
4628
-
4629
- var KHR_lights_punctual = /*#__PURE__*/ function(GLTFExtensionParser) {
4630
- _inherits(KHR_lights_punctual, GLTFExtensionParser);
4631
- function KHR_lights_punctual() {
4632
- return GLTFExtensionParser.apply(this, arguments);
4633
- }
4634
- var _proto = KHR_lights_punctual.prototype;
4635
- /**
4636
- * @override
4637
- */ _proto.additiveParse = function additiveParse(context, entity, extensionSchema) {
4638
- var lightsSchema = context.glTF.extensions.KHR_lights_punctual.lights;
4639
- var lightSchema = lightsSchema[extensionSchema.light];
4640
- 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;
4641
- var glTFResource = context.glTFResource;
4642
- var light;
4643
- if (type === "directional") {
4644
- light = entity.addComponent(miniprogram.DirectLight);
4645
- } else if (type === "point") {
4646
- light = entity.addComponent(miniprogram.PointLight);
4647
- } else if (type === "spot") {
4648
- light = entity.addComponent(miniprogram.SpotLight);
4649
- }
4650
- if (color) {
4651
- light.color.set(color[0], color[1], color[2], 1);
4652
- }
4653
- light.intensity = intensity;
4654
- if (range && !_instanceof(light, miniprogram.DirectLight)) {
4655
- light.distance = range;
4656
- }
4657
- if (spot && _instanceof(light, miniprogram.SpotLight)) {
4658
- 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;
4659
- light.angle = innerConeAngle;
4660
- light.penumbra = outerConeAngle - innerConeAngle;
4661
- }
4662
- if (!glTFResource.lights) glTFResource.lights = [];
4663
- glTFResource.lights.push(light);
4664
- };
4665
- return KHR_lights_punctual;
4666
- }(GLTFExtensionParser);
4667
- KHR_lights_punctual = __decorate([
4668
- registerGLTFExtension("KHR_lights_punctual", exports.GLTFExtensionMode.AdditiveParse)
4669
- ], KHR_lights_punctual);
4670
-
4671
- var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
4672
- _inherits(KHR_materials_clearcoat, GLTFExtensionParser);
4673
- function KHR_materials_clearcoat() {
4674
- return GLTFExtensionParser.apply(this, arguments);
4675
- }
4676
- var _proto = KHR_materials_clearcoat.prototype;
4677
- /**
4678
- * @override
4679
- */ _proto.additiveParse = function additiveParse(context, material, schema) {
4680
- var textures = context.glTFResource.textures;
4681
- 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;
4682
- material.clearCoat = clearcoatFactor;
4683
- material.clearCoatRoughness = clearcoatRoughnessFactor;
4684
- if (clearcoatTexture) {
4685
- material.clearCoatTexture = textures[clearcoatTexture.index];
4686
- GLTFMaterialParser._checkOtherTextureTransform(clearcoatTexture, "Clear coat");
4687
- }
4688
- if (clearcoatRoughnessTexture) {
4689
- material.clearCoatRoughnessTexture = textures[clearcoatRoughnessTexture.index];
4690
- GLTFMaterialParser._checkOtherTextureTransform(clearcoatRoughnessTexture, "Clear coat roughness");
4691
- }
4692
- if (clearcoatNormalTexture) {
4693
- material.clearCoatNormalTexture = textures[clearcoatNormalTexture.index];
4694
- GLTFMaterialParser._checkOtherTextureTransform(clearcoatNormalTexture, "Clear coat normal");
4695
- }
4696
- };
4697
- return KHR_materials_clearcoat;
4698
- }(GLTFExtensionParser);
4699
- KHR_materials_clearcoat = __decorate([
4700
- registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
4701
- ], KHR_materials_clearcoat);
4702
-
4703
- var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
4704
- _inherits(KHR_materials_pbrSpecularGlossiness, GLTFExtensionParser);
4705
- function KHR_materials_pbrSpecularGlossiness() {
4706
- return GLTFExtensionParser.apply(this, arguments);
4707
- }
4708
- var _proto = KHR_materials_pbrSpecularGlossiness.prototype;
4709
- /**
4710
- * @override
4711
- */ _proto.createAndParse = function createAndParse(context, schema, ownerSchema) {
4712
- var _context_glTFResource = context.glTFResource, engine = _context_glTFResource.engine, textures = _context_glTFResource.textures;
4713
- var material = new miniprogram.PBRSpecularMaterial(engine);
4714
- var diffuseFactor = schema.diffuseFactor, diffuseTexture = schema.diffuseTexture, specularFactor = schema.specularFactor, glossinessFactor = schema.glossinessFactor, specularGlossinessTexture = schema.specularGlossinessTexture;
4715
- if (diffuseFactor) {
4716
- 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]);
4717
- }
4718
- if (diffuseTexture) {
4719
- material.baseTexture = textures[diffuseTexture.index];
4720
- GLTFParser.executeExtensionsAdditiveAndParse(diffuseTexture.extensions, context, material, diffuseTexture);
4721
- }
4722
- if (specularFactor) {
4723
- material.specularColor = new miniprogram$1.Color(miniprogram$1.Color.linearToGammaSpace(specularFactor[0]), miniprogram$1.Color.linearToGammaSpace(specularFactor[1]), miniprogram$1.Color.linearToGammaSpace(specularFactor[2]));
4724
- }
4725
- if (glossinessFactor !== undefined) {
4726
- material.glossiness = glossinessFactor;
4727
- }
4728
- if (specularGlossinessTexture) {
4729
- material.specularGlossinessTexture = textures[specularGlossinessTexture.index];
4730
- GLTFMaterialParser._checkOtherTextureTransform(specularGlossinessTexture, "Specular glossiness");
4731
- }
4732
- material.name = ownerSchema.name;
4733
- GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4734
- return material;
4735
- };
4736
- return KHR_materials_pbrSpecularGlossiness;
4737
- }(GLTFExtensionParser);
4738
- KHR_materials_pbrSpecularGlossiness = __decorate([
4739
- registerGLTFExtension("KHR_materials_pbrSpecularGlossiness", exports.GLTFExtensionMode.CreateAndParse)
4740
- ], KHR_materials_pbrSpecularGlossiness);
4741
-
4742
- var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
4743
- _inherits(KHR_materials_unlit, GLTFExtensionParser);
4744
- function KHR_materials_unlit() {
4745
- return GLTFExtensionParser.apply(this, arguments);
4746
- }
4747
- var _proto = KHR_materials_unlit.prototype;
4748
- /**
4749
- * @override
4750
- */ _proto.createAndParse = function createAndParse(context, _, ownerSchema) {
4751
- var engine = context.glTFResource.engine;
4752
- var material = new miniprogram.UnlitMaterial(engine);
4753
- material.name = ownerSchema.name;
4754
- GLTFMaterialParser._parseStandardProperty(context, material, ownerSchema);
4755
- return material;
4756
- };
4757
- return KHR_materials_unlit;
4758
- }(GLTFExtensionParser);
4759
- KHR_materials_unlit = __decorate([
4760
- registerGLTFExtension("KHR_materials_unlit", exports.GLTFExtensionMode.CreateAndParse)
4761
- ], KHR_materials_unlit);
4762
-
4763
- var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
4764
- _inherits(KHR_mesh_quantization, GLTFExtensionParser);
4765
- function KHR_mesh_quantization() {
4766
- return GLTFExtensionParser.apply(this, arguments);
4767
- }
4768
- return KHR_mesh_quantization;
4769
- }(GLTFExtensionParser);
4770
- KHR_mesh_quantization = __decorate([
4771
- registerGLTFExtension("KHR_mesh_quantization", exports.GLTFExtensionMode.AdditiveParse)
4772
- ], KHR_mesh_quantization);
4773
-
4774
- var KHR_texture_transform = /*#__PURE__*/ function(GLTFExtensionParser) {
4775
- _inherits(KHR_texture_transform, GLTFExtensionParser);
4776
- function KHR_texture_transform() {
4777
- return GLTFExtensionParser.apply(this, arguments);
4778
- }
4779
- var _proto = KHR_texture_transform.prototype;
4780
- /**
4781
- * @override
4782
- */ _proto.additiveParse = function additiveParse(context, material, schema) {
4783
- var offset = schema.offset, rotation = schema.rotation, scale = schema.scale, texCoord = schema.texCoord;
4784
- if (offset) {
4785
- material.tilingOffset.z = offset[0];
4786
- material.tilingOffset.w = offset[1];
4787
- }
4788
- if (scale) {
4789
- material.tilingOffset.x = scale[0];
4790
- material.tilingOffset.y = scale[1];
4791
- }
4792
- if (rotation) {
4793
- miniprogram.Logger.warn("rotation in KHR_texture_transform is not supported now");
4794
- }
4795
- if (texCoord) {
4796
- miniprogram.Logger.warn("texCoord in KHR_texture_transform is not supported now");
4797
- }
4798
- };
4799
- return KHR_texture_transform;
4800
- }(GLTFExtensionParser);
4801
- KHR_texture_transform = __decorate([
4802
- registerGLTFExtension("KHR_texture_transform", exports.GLTFExtensionMode.AdditiveParse)
4803
- ], KHR_texture_transform);
4804
-
4805
- var GALACEAN_materials_remap = /*#__PURE__*/ function(GLTFExtensionParser) {
4806
- _inherits(GALACEAN_materials_remap, GLTFExtensionParser);
4807
- function GALACEAN_materials_remap() {
4808
- return GLTFExtensionParser.apply(this, arguments);
4809
- }
4810
- var _proto = GALACEAN_materials_remap.prototype;
4811
- /**
4812
- * @override
4813
- */ _proto.createAndParse = function createAndParse(context, schema) {
4814
- var engine = context.glTFResource.engine;
4815
- // @ts-ignore
4816
- return engine.resourceManager.getResourceByRef(schema);
4817
- };
4818
- return GALACEAN_materials_remap;
4819
- }(GLTFExtensionParser);
4820
- GALACEAN_materials_remap = __decorate([
4821
- registerGLTFExtension("GALACEAN_materials_remap", exports.GLTFExtensionMode.CreateAndParse)
4822
- ], GALACEAN_materials_remap);
4823
-
4824
- var GALACEAN_animation_event = /*#__PURE__*/ function(GLTFExtensionParser) {
4825
- _inherits(GALACEAN_animation_event, GLTFExtensionParser);
4826
- function GALACEAN_animation_event() {
4827
- return GLTFExtensionParser.apply(this, arguments);
4828
- }
4829
- var _proto = GALACEAN_animation_event.prototype;
4830
- /**
4831
- * @override
4832
- */ _proto.additiveParse = function additiveParse(context, animationClip, schema) {
4833
- context.glTFResource.engine;
4834
- var events = schema.events;
4835
- events.map(function(eventData) {
4836
- var event = new miniprogram.AnimationEvent();
4837
- event.functionName = eventData.functionName;
4838
- event.time = eventData.time;
4839
- event.parameter = eventData.parameter;
4840
- animationClip.addEvent(event);
4841
- });
4842
- };
4843
- return GALACEAN_animation_event;
4844
- }(GLTFExtensionParser);
4845
- GALACEAN_animation_event = __decorate([
4846
- registerGLTFExtension("GALACEAN_animation_event", exports.GLTFExtensionMode.AdditiveParse)
4847
- ], GALACEAN_animation_event);
4848
-
4849
4465
  exports.ComponentMap = ComponentMap;
4850
- exports.GLTFAnimationParser = GLTFAnimationParser;
4851
- exports.GLTFBufferParser = GLTFBufferParser;
4852
- exports.GLTFEntityParser = GLTFEntityParser;
4853
- exports.GLTFExtensionParser = GLTFExtensionParser;
4854
- exports.GLTFMaterialParser = GLTFMaterialParser;
4855
- exports.GLTFMeshParser = GLTFMeshParser;
4856
- exports.GLTFParser = GLTFParser;
4857
- exports.GLTFParserContext = GLTFParserContext;
4858
- exports.GLTFPipeline = GLTFPipeline;
4859
4466
  exports.GLTFResource = GLTFResource;
4860
- exports.GLTFSceneParser = GLTFSceneParser;
4861
- exports.GLTFSkinParser = GLTFSkinParser;
4862
- exports.GLTFTextureParser = GLTFTextureParser;
4863
- exports.GLTFUtils = GLTFUtils;
4864
- exports.GLTFValidator = GLTFValidator;
4865
4467
  exports.PrefabParser = PrefabParser;
4866
4468
  exports.ReflectionParser = ReflectionParser;
4867
4469
  exports.SceneParser = SceneParser;
4868
4470
  exports.decode = decode;
4869
4471
  exports.parseSingleKTX = parseSingleKTX;
4870
- exports.registerGLTFExtension = registerGLTFExtension;