@galacean/engine-loader 1.2.0-beta.3 → 1.2.0-beta.5

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 (40) hide show
  1. package/LICENSE +2 -2
  2. package/dist/main.js +116 -81
  3. package/dist/main.js.map +1 -1
  4. package/dist/miniprogram.js +116 -81
  5. package/dist/module.js +117 -82
  6. package/dist/module.js.map +1 -1
  7. package/package.json +4 -4
  8. package/types/gltf/GLTFParser.d.ts +9 -0
  9. package/types/gltf/GLTFPipeline.d.ts +23 -0
  10. package/types/gltf/GLTFResource.d.ts +8 -6
  11. package/types/gltf/GLTFUtil.d.ts +53 -0
  12. package/types/gltf/Schema.d.ts +814 -0
  13. package/types/gltf/extensions/ExtensionParser.d.ts +8 -0
  14. package/types/gltf/extensions/KHR_draco_mesh_compression.d.ts +1 -0
  15. package/types/gltf/extensions/Schema.d.ts +142 -0
  16. package/types/gltf/parser/AnimationParser.d.ts +7 -0
  17. package/types/gltf/parser/BufferParser.d.ts +7 -0
  18. package/types/gltf/parser/EntityParser.d.ts +9 -0
  19. package/types/gltf/parser/GLTFAnimatorControllerParser.d.ts +7 -0
  20. package/types/gltf/parser/GLTFParserContext.d.ts +4 -2
  21. package/types/gltf/parser/MaterialParser.d.ts +8 -0
  22. package/types/gltf/parser/MeshParser.d.ts +13 -0
  23. package/types/gltf/parser/Parser.d.ts +21 -0
  24. package/types/gltf/parser/ParserContext.d.ts +46 -0
  25. package/types/gltf/parser/SceneParser.d.ts +11 -0
  26. package/types/gltf/parser/SkinParser.d.ts +6 -0
  27. package/types/gltf/parser/TextureParser.d.ts +8 -0
  28. package/types/gltf/parser/Validator.d.ts +5 -0
  29. package/types/gltf/parser/index.d.ts +1 -0
  30. package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +13 -0
  31. package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +33 -0
  32. package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +17 -0
  33. package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +34 -0
  34. package/types/ktx2/TranscodeResult.d.ts +10 -0
  35. package/types/ktx2/constants.d.ts +7 -0
  36. package/types/ktx2/zstddec.d.ts +62 -0
  37. package/types/resource-deserialize/resources/animationClip/ComponentMap.d.ts +2 -0
  38. package/types/resource-deserialize/resources/parser/PrefabParser.d.ts +5 -0
  39. package/types/resource-deserialize/resources/prefab/PrefabDesign.d.ts +70 -0
  40. package/types/resource-deserialize/resources/prefab/ReflectionParser.d.ts +14 -0
@@ -1887,6 +1887,7 @@ var TextureWrapMode;
1887
1887
  this.resourceManager = resourceManager;
1888
1888
  this.params = params;
1889
1889
  this.accessorBufferCache = {};
1890
+ this.needAnimatorController = false;
1890
1891
  this._resourceCache = new Map();
1891
1892
  this._progress = {
1892
1893
  taskDetail: {},
@@ -1914,16 +1915,15 @@ var TextureWrapMode;
1914
1915
  return Promise.resolve(null);
1915
1916
  }
1916
1917
  var cache = this._resourceCache;
1917
- var isOnlyOne = type === 0 || type === 1;
1918
- var cacheKey = isOnlyOne || index === undefined ? "" + type : type + ":" + index;
1918
+ var cacheKey = index === undefined ? "" + type : type + ":" + index;
1919
1919
  var resource = cache.get(cacheKey);
1920
1920
  if (resource) {
1921
1921
  return resource;
1922
1922
  }
1923
- if (isOnlyOne) {
1924
- resource = parser.parse(this);
1925
- } else {
1926
- var glTFItems = this.glTF[glTFSchemaMap[type]];
1923
+ var glTFSchemaKey = glTFSchemaMap[type];
1924
+ var isSubAsset = !!glTFResourceMap[type];
1925
+ if (glTFSchemaKey) {
1926
+ var glTFItems = this.glTF[glTFSchemaKey];
1927
1927
  if (glTFItems && (index === undefined || glTFItems[index])) {
1928
1928
  if (index === undefined) {
1929
1929
  resource = type === 8 ? glTFItems.map(function(_, index) {
@@ -1933,11 +1933,14 @@ var TextureWrapMode;
1933
1933
  }));
1934
1934
  } else {
1935
1935
  resource = parser.parse(this, index);
1936
- this._handleSubAsset(resource, type, index);
1936
+ isSubAsset && this._handleSubAsset(resource, type, index);
1937
1937
  }
1938
1938
  } else {
1939
1939
  resource = Promise.resolve(null);
1940
1940
  }
1941
+ } else {
1942
+ resource = parser.parse(this, index);
1943
+ isSubAsset && this._handleSubAsset(resource, type, index);
1941
1944
  }
1942
1945
  cache.set(cacheKey, resource);
1943
1946
  return resource;
@@ -1946,6 +1949,7 @@ var TextureWrapMode;
1946
1949
  var _this = this;
1947
1950
  var promise = this.get(0).then(function(json) {
1948
1951
  _this.glTF = json;
1952
+ _this.needAnimatorController = !!(json.skins || json.animations);
1949
1953
  return Promise.all([
1950
1954
  _this.get(1),
1951
1955
  _this.get(5),
@@ -1953,11 +1957,14 @@ var TextureWrapMode;
1953
1957
  _this.get(7),
1954
1958
  _this.get(9),
1955
1959
  _this.get(10),
1960
+ _this.get(11),
1956
1961
  _this.get(2)
1957
1962
  ]).then(function() {
1958
1963
  var glTFResource = _this.glTFResource;
1959
- if (glTFResource.skins || glTFResource.animations) {
1960
- _this._createAnimator(_this, glTFResource.animations);
1964
+ var animatorController = glTFResource.animatorController;
1965
+ if (animatorController) {
1966
+ var animator = glTFResource._defaultSceneRoot.addComponent(miniprogram.Animator);
1967
+ animator.animatorController = animatorController;
1961
1968
  }
1962
1969
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1963
1970
  return glTFResource;
@@ -1976,40 +1983,21 @@ var TextureWrapMode;
1976
1983
  _this._setTaskCompleteProgress(++task.loaded, task.total);
1977
1984
  });
1978
1985
  };
1979
- _proto._createAnimator = function _createAnimator(context, animations) {
1980
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1981
- var animator = defaultSceneRoot.addComponent(miniprogram.Animator);
1982
- var animatorController = new miniprogram.AnimatorController();
1983
- var layer = new miniprogram.AnimatorControllerLayer("layer");
1984
- var animatorStateMachine = new miniprogram.AnimatorStateMachine();
1985
- animatorController.addLayer(layer);
1986
- animator.animatorController = animatorController;
1987
- layer.stateMachine = animatorStateMachine;
1988
- if (animations) {
1989
- for(var i = 0; i < animations.length; i++){
1990
- var animationClip = animations[i];
1991
- var name = animationClip.name;
1992
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1993
- if (uniqueName !== name) {
1994
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1995
- }
1996
- var animatorState = animatorStateMachine.addState(uniqueName);
1997
- animatorState.clip = animationClip;
1998
- }
1999
- }
2000
- };
2001
1986
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
2002
1987
  var _this = this;
2003
1988
  var glTFResourceKey = glTFResourceMap[type];
2004
- if (!glTFResourceKey) return;
2005
1989
  if (type === 8) {
2006
1990
  var _this_glTFResource, _glTFResourceKey;
2007
1991
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
2008
1992
  } else {
2009
1993
  var url = this.glTFResource.url;
2010
1994
  resource.then(function(item) {
2011
- var _this_glTFResource, _glTFResourceKey;
2012
- ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
1995
+ if (index == undefined) {
1996
+ _this.glTFResource[glTFResourceKey] = item;
1997
+ } else {
1998
+ var _this_glTFResource, _glTFResourceKey;
1999
+ ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
2000
+ }
2013
2001
  if (type === 7) {
2014
2002
  for(var i = 0, length = item.length; i < length; i++){
2015
2003
  var mesh = item[i];
@@ -2057,11 +2045,12 @@ exports.GLTFParserType = void 0;
2057
2045
  GLTFParserType[GLTFParserType["Entity"] = 8] = "Entity";
2058
2046
  GLTFParserType[GLTFParserType["Skin"] = 9] = "Skin";
2059
2047
  GLTFParserType[GLTFParserType["Animation"] = 10] = "Animation";
2048
+ GLTFParserType[GLTFParserType["AnimatorController"] = 11] = "AnimatorController";
2060
2049
  })(exports.GLTFParserType || (exports.GLTFParserType = {}));
2061
2050
  var _obj;
2062
2051
  var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[5] = "textures", _obj[6] = "materials", _obj[7] = "meshes", _obj[8] = "nodes", _obj[9] = "skins", _obj[10] = "animations", _obj[4] = "bufferViews", _obj);
2063
2052
  var _obj1;
2064
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1);
2053
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1[11] = "animatorController", _obj1);
2065
2054
  function registerGLTFParser(pipeline) {
2066
2055
  return function(Parser) {
2067
2056
  var parser = new Parser();
@@ -4546,25 +4535,31 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4546
4535
  camera.enabled = false;
4547
4536
  };
4548
4537
  _proto._createRenderer = function _createRenderer(context, entityInfo, entity) {
4549
- var _loop = function(i) {
4550
- var glTFPrimitive = glTFMeshPrimitives[i];
4551
- var materialIndex = glTFPrimitive.material;
4552
- promises.push(Promise.all([
4553
- context.get(exports.GLTFParserType.Mesh, meshID),
4554
- skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
4555
- materialIndex !== undefined && context.get(exports.GLTFParserType.Material, materialIndex)
4556
- ]).then(function(param) {
4557
- var meshes = param[0], skin = param[1], material = param[2];
4538
+ var _this = this;
4539
+ var meshID = entityInfo.mesh, skinID = entityInfo.skin;
4540
+ var glTFMesh = context.glTF.meshes[meshID];
4541
+ var glTFMeshPrimitives = glTFMesh.primitives;
4542
+ var rendererCount = glTFMeshPrimitives.length;
4543
+ var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
4544
+ var materialPromises = new Array(rendererCount);
4545
+ for(var i = 0; i < rendererCount; i++){
4546
+ materialPromises[i] = context.get(exports.GLTFParserType.Material, glTFMeshPrimitives[i].material);
4547
+ }
4548
+ return Promise.all([
4549
+ context.get(exports.GLTFParserType.Mesh, meshID),
4550
+ skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
4551
+ Promise.all(materialPromises)
4552
+ ]).then(function(param) {
4553
+ var _loop = function(i) {
4554
+ var material = materials[i] || exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine);
4555
+ var glTFPrimitive = glTFMeshPrimitives[i];
4558
4556
  var mesh = meshes[i];
4559
- var renderer;
4560
- material || (material = exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
4557
+ var renderer = void 0;
4561
4558
  if (skin || blendShapeWeights) {
4562
4559
  var skinRenderer = entity.addComponent(miniprogram.SkinnedMeshRenderer);
4563
4560
  skinRenderer.mesh = mesh;
4564
4561
  if (skin) {
4565
- skinRenderer.rootBone = skin._rootBone;
4566
- skinRenderer.bones = skin._bones;
4567
- _this._computeLocalBounds(skinRenderer, mesh, skin._bones, skin._rootBone, skin.inverseBindMatrices);
4562
+ _this._computeLocalBounds(skinRenderer, mesh, skin.bones, skin.rootBone, skin.inverseBindMatrices);
4568
4563
  skinRenderer.skin = skin;
4569
4564
  }
4570
4565
  if (blendShapeWeights) {
@@ -4583,17 +4578,10 @@ exports.GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4583
4578
  }
4584
4579
  });
4585
4580
  GLTFParser.executeExtensionsAdditiveAndParse(glTFPrimitive.extensions, context, renderer, glTFPrimitive);
4586
- }));
4587
- };
4588
- var _this = this;
4589
- var glTFMeshes = context.glTF.meshes;
4590
- var meshID = entityInfo.mesh, skinID = entityInfo.skin;
4591
- var glTFMesh = glTFMeshes[meshID];
4592
- var glTFMeshPrimitives = glTFMesh.primitives;
4593
- var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
4594
- var promises = new Array();
4595
- for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
4596
- return Promise.all(promises);
4581
+ };
4582
+ var meshes = param[0], skin = param[1], materials = param[2];
4583
+ for(var i = 0; i < rendererCount; i++)_loop(i);
4584
+ });
4597
4585
  };
4598
4586
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
4599
4587
  var rootBoneIndex = bones.indexOf(rootBone);
@@ -4647,7 +4635,7 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser1) {
4647
4635
  var jointCount = joints.length;
4648
4636
  var skin = new miniprogram.Skin(name);
4649
4637
  skin.inverseBindMatrices.length = jointCount;
4650
- skin._bones.length = jointCount;
4638
+ var bones = new Array(jointCount);
4651
4639
  // parse IBM
4652
4640
  var accessor = glTF.accessors[inverseBindMatrices];
4653
4641
  var skinPromise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
@@ -4659,21 +4647,20 @@ exports.GLTFSkinParser = /*#__PURE__*/ function(GLTFParser1) {
4659
4647
  skin.inverseBindMatrices[i] = inverseBindMatrix;
4660
4648
  // Get bones
4661
4649
  var bone = entities[joints[i]];
4662
- skin._bones[i] = bone;
4650
+ bones[i] = bone;
4663
4651
  skin.joints[i] = bone.name;
4664
- // Get skeleton
4665
- if (skeleton !== undefined) {
4666
- var rootBone = entities[skeleton];
4667
- skin._rootBone = rootBone;
4668
- skin.skeleton = rootBone.name;
4652
+ }
4653
+ skin.bones = bones;
4654
+ // Get skeleton
4655
+ if (skeleton !== undefined) {
4656
+ var rootBone = entities[skeleton];
4657
+ skin.rootBone = rootBone;
4658
+ } else {
4659
+ var rootBone1 = _this._findSkeletonRootBone(joints, entities);
4660
+ if (rootBone1) {
4661
+ skin.rootBone = rootBone1;
4669
4662
  } else {
4670
- var rootBone1 = _this._findSkeletonRootBone(joints, entities);
4671
- if (rootBone1) {
4672
- skin._rootBone = rootBone1;
4673
- skin.skeleton = rootBone1.name;
4674
- } else {
4675
- throw "Failed to find skeleton root bone.";
4676
- }
4663
+ throw "Failed to find skeleton root bone.";
4677
4664
  }
4678
4665
  }
4679
4666
  return skin;
@@ -4841,6 +4828,48 @@ exports.GLTFBufferViewParser = __decorate([
4841
4828
  registerGLTFParser(exports.GLTFParserType.BufferView)
4842
4829
  ], exports.GLTFBufferViewParser);
4843
4830
 
4831
+ exports.GLTFAnimatorControllerParser = /*#__PURE__*/ function(GLTFParser1) {
4832
+ _inherits(GLTFAnimatorControllerParser, GLTFParser1);
4833
+ function GLTFAnimatorControllerParser() {
4834
+ return GLTFParser1.apply(this, arguments);
4835
+ }
4836
+ var _proto = GLTFAnimatorControllerParser.prototype;
4837
+ _proto.parse = function parse(context) {
4838
+ var _this = this;
4839
+ if (!context.needAnimatorController) {
4840
+ return Promise.resolve(null);
4841
+ }
4842
+ return context.get(exports.GLTFParserType.Animation).then(function(animations) {
4843
+ var animatorController = _this._createAnimatorController(animations);
4844
+ return Promise.resolve(animatorController);
4845
+ });
4846
+ };
4847
+ _proto._createAnimatorController = function _createAnimatorController(animations) {
4848
+ var animatorController = new miniprogram.AnimatorController();
4849
+ var layer = new miniprogram.AnimatorControllerLayer("layer");
4850
+ var animatorStateMachine = new miniprogram.AnimatorStateMachine();
4851
+ animatorController.addLayer(layer);
4852
+ layer.stateMachine = animatorStateMachine;
4853
+ if (animations) {
4854
+ for(var i = 0; i < animations.length; i++){
4855
+ var animationClip = animations[i];
4856
+ var name = animationClip.name;
4857
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4858
+ if (uniqueName !== name) {
4859
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4860
+ }
4861
+ var animatorState = animatorStateMachine.addState(uniqueName);
4862
+ animatorState.clip = animationClip;
4863
+ }
4864
+ }
4865
+ return animatorController;
4866
+ };
4867
+ return GLTFAnimatorControllerParser;
4868
+ }(GLTFParser);
4869
+ exports.GLTFAnimatorControllerParser = __decorate([
4870
+ registerGLTFParser(exports.GLTFParserType.AnimatorController)
4871
+ ], exports.GLTFAnimatorControllerParser);
4872
+
4844
4873
  var MeshoptDecoder = function() {
4845
4874
  var unpack = function unpack(data) {
4846
4875
  var result = new Uint8Array(data.length);
@@ -5077,7 +5106,8 @@ exports.GLTFLoader = __decorate([
5077
5106
 
5078
5107
  var _HDRLoader;
5079
5108
  var PI = Math.PI;
5080
- var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
5109
+ var HDRLoader = (_HDRLoader = // referenece: https://www.flipcode.com/archives/HDR_Image_Reader.shtml
5110
+ /*#__PURE__*/ function(Loader1) {
5081
5111
  _inherits(HDRLoader1, Loader1);
5082
5112
  function HDRLoader1() {
5083
5113
  return Loader1.apply(this, arguments);
@@ -5247,15 +5277,20 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
5247
5277
  var dataRGBA = new Uint8Array(4 * width * height);
5248
5278
  var offset = 0, pos = 0;
5249
5279
  var ptrEnd = 4 * scanLineWidth;
5250
- var rgbeStart = new Uint8Array(4);
5251
5280
  var scanLineBuffer = new Uint8Array(ptrEnd);
5252
5281
  var numScanLines = height; // read in each successive scanLine
5253
5282
  while(numScanLines > 0 && pos < byteLength){
5254
- rgbeStart[0] = buffer[pos++];
5255
- rgbeStart[1] = buffer[pos++];
5256
- rgbeStart[2] = buffer[pos++];
5257
- rgbeStart[3] = buffer[pos++];
5258
- if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanLineWidth) {
5283
+ var a = buffer[pos++];
5284
+ var b = buffer[pos++];
5285
+ var c = buffer[pos++];
5286
+ var d = buffer[pos++];
5287
+ if (a != 2 || b != 2 || c & 0x80 || width < 8 || width > 32767) {
5288
+ // this file is not run length encoded
5289
+ // read values sequentially
5290
+ return buffer;
5291
+ }
5292
+ if ((c << 8 | d) != scanLineWidth) {
5293
+ // eslint-disable-next-line no-throw-literal
5259
5294
  throw "HDR Bad header format, wrong scan line width";
5260
5295
  }
5261
5296
  // read each of the four channels for the scanline into the buffer
package/dist/module.js CHANGED
@@ -1882,6 +1882,7 @@ var TextureWrapMode;
1882
1882
  this.resourceManager = resourceManager;
1883
1883
  this.params = params;
1884
1884
  this.accessorBufferCache = {};
1885
+ this.needAnimatorController = false;
1885
1886
  this._resourceCache = new Map();
1886
1887
  this._progress = {
1887
1888
  taskDetail: {},
@@ -1909,16 +1910,15 @@ var TextureWrapMode;
1909
1910
  return Promise.resolve(null);
1910
1911
  }
1911
1912
  var cache = this._resourceCache;
1912
- var isOnlyOne = type === 0 || type === 1;
1913
- var cacheKey = isOnlyOne || index === undefined ? "" + type : type + ":" + index;
1913
+ var cacheKey = index === undefined ? "" + type : type + ":" + index;
1914
1914
  var resource = cache.get(cacheKey);
1915
1915
  if (resource) {
1916
1916
  return resource;
1917
1917
  }
1918
- if (isOnlyOne) {
1919
- resource = parser.parse(this);
1920
- } else {
1921
- var glTFItems = this.glTF[glTFSchemaMap[type]];
1918
+ var glTFSchemaKey = glTFSchemaMap[type];
1919
+ var isSubAsset = !!glTFResourceMap[type];
1920
+ if (glTFSchemaKey) {
1921
+ var glTFItems = this.glTF[glTFSchemaKey];
1922
1922
  if (glTFItems && (index === undefined || glTFItems[index])) {
1923
1923
  if (index === undefined) {
1924
1924
  resource = type === 8 ? glTFItems.map(function(_, index) {
@@ -1928,11 +1928,14 @@ var TextureWrapMode;
1928
1928
  }));
1929
1929
  } else {
1930
1930
  resource = parser.parse(this, index);
1931
- this._handleSubAsset(resource, type, index);
1931
+ isSubAsset && this._handleSubAsset(resource, type, index);
1932
1932
  }
1933
1933
  } else {
1934
1934
  resource = Promise.resolve(null);
1935
1935
  }
1936
+ } else {
1937
+ resource = parser.parse(this, index);
1938
+ isSubAsset && this._handleSubAsset(resource, type, index);
1936
1939
  }
1937
1940
  cache.set(cacheKey, resource);
1938
1941
  return resource;
@@ -1941,6 +1944,7 @@ var TextureWrapMode;
1941
1944
  var _this = this;
1942
1945
  var promise = this.get(0).then(function(json) {
1943
1946
  _this.glTF = json;
1947
+ _this.needAnimatorController = !!(json.skins || json.animations);
1944
1948
  return Promise.all([
1945
1949
  _this.get(1),
1946
1950
  _this.get(5),
@@ -1948,11 +1952,14 @@ var TextureWrapMode;
1948
1952
  _this.get(7),
1949
1953
  _this.get(9),
1950
1954
  _this.get(10),
1955
+ _this.get(11),
1951
1956
  _this.get(2)
1952
1957
  ]).then(function() {
1953
1958
  var glTFResource = _this.glTFResource;
1954
- if (glTFResource.skins || glTFResource.animations) {
1955
- _this._createAnimator(_this, glTFResource.animations);
1959
+ var animatorController = glTFResource.animatorController;
1960
+ if (animatorController) {
1961
+ var animator = glTFResource._defaultSceneRoot.addComponent(Animator);
1962
+ animator.animatorController = animatorController;
1956
1963
  }
1957
1964
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1958
1965
  return glTFResource;
@@ -1971,40 +1978,21 @@ var TextureWrapMode;
1971
1978
  _this._setTaskCompleteProgress(++task.loaded, task.total);
1972
1979
  });
1973
1980
  };
1974
- _proto._createAnimator = function _createAnimator(context, animations) {
1975
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1976
- var animator = defaultSceneRoot.addComponent(Animator);
1977
- var animatorController = new AnimatorController();
1978
- var layer = new AnimatorControllerLayer("layer");
1979
- var animatorStateMachine = new AnimatorStateMachine();
1980
- animatorController.addLayer(layer);
1981
- animator.animatorController = animatorController;
1982
- layer.stateMachine = animatorStateMachine;
1983
- if (animations) {
1984
- for(var i = 0; i < animations.length; i++){
1985
- var animationClip = animations[i];
1986
- var name = animationClip.name;
1987
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1988
- if (uniqueName !== name) {
1989
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1990
- }
1991
- var animatorState = animatorStateMachine.addState(uniqueName);
1992
- animatorState.clip = animationClip;
1993
- }
1994
- }
1995
- };
1996
1981
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
1997
1982
  var _this = this;
1998
1983
  var glTFResourceKey = glTFResourceMap[type];
1999
- if (!glTFResourceKey) return;
2000
1984
  if (type === 8) {
2001
1985
  var _this_glTFResource, _glTFResourceKey;
2002
1986
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
2003
1987
  } else {
2004
1988
  var url = this.glTFResource.url;
2005
1989
  resource.then(function(item) {
2006
- var _this_glTFResource, _glTFResourceKey;
2007
- ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
1990
+ if (index == undefined) {
1991
+ _this.glTFResource[glTFResourceKey] = item;
1992
+ } else {
1993
+ var _this_glTFResource, _glTFResourceKey;
1994
+ ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
1995
+ }
2008
1996
  if (type === 7) {
2009
1997
  for(var i = 0, length = item.length; i < length; i++){
2010
1998
  var mesh = item[i];
@@ -2052,11 +2040,12 @@ var GLTFParserType;
2052
2040
  GLTFParserType[GLTFParserType["Entity"] = 8] = "Entity";
2053
2041
  GLTFParserType[GLTFParserType["Skin"] = 9] = "Skin";
2054
2042
  GLTFParserType[GLTFParserType["Animation"] = 10] = "Animation";
2043
+ GLTFParserType[GLTFParserType["AnimatorController"] = 11] = "AnimatorController";
2055
2044
  })(GLTFParserType || (GLTFParserType = {}));
2056
2045
  var _obj;
2057
2046
  var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[5] = "textures", _obj[6] = "materials", _obj[7] = "meshes", _obj[8] = "nodes", _obj[9] = "skins", _obj[10] = "animations", _obj[4] = "bufferViews", _obj);
2058
2047
  var _obj1;
2059
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1);
2048
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1[11] = "animatorController", _obj1);
2060
2049
  function registerGLTFParser(pipeline) {
2061
2050
  return function(Parser) {
2062
2051
  var parser = new Parser();
@@ -4541,25 +4530,31 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4541
4530
  camera.enabled = false;
4542
4531
  };
4543
4532
  _proto._createRenderer = function _createRenderer(context, entityInfo, entity) {
4544
- var _loop = function(i) {
4545
- var glTFPrimitive = glTFMeshPrimitives[i];
4546
- var materialIndex = glTFPrimitive.material;
4547
- promises.push(Promise.all([
4548
- context.get(GLTFParserType.Mesh, meshID),
4549
- skinID !== undefined && context.get(GLTFParserType.Skin, skinID),
4550
- materialIndex !== undefined && context.get(GLTFParserType.Material, materialIndex)
4551
- ]).then(function(param) {
4552
- var meshes = param[0], skin = param[1], material = param[2];
4533
+ var _this = this;
4534
+ var meshID = entityInfo.mesh, skinID = entityInfo.skin;
4535
+ var glTFMesh = context.glTF.meshes[meshID];
4536
+ var glTFMeshPrimitives = glTFMesh.primitives;
4537
+ var rendererCount = glTFMeshPrimitives.length;
4538
+ var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
4539
+ var materialPromises = new Array(rendererCount);
4540
+ for(var i = 0; i < rendererCount; i++){
4541
+ materialPromises[i] = context.get(GLTFParserType.Material, glTFMeshPrimitives[i].material);
4542
+ }
4543
+ return Promise.all([
4544
+ context.get(GLTFParserType.Mesh, meshID),
4545
+ skinID !== undefined && context.get(GLTFParserType.Skin, skinID),
4546
+ Promise.all(materialPromises)
4547
+ ]).then(function(param) {
4548
+ var _loop = function(i) {
4549
+ var material = materials[i] || GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine);
4550
+ var glTFPrimitive = glTFMeshPrimitives[i];
4553
4551
  var mesh = meshes[i];
4554
- var renderer;
4555
- material || (material = GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
4552
+ var renderer = void 0;
4556
4553
  if (skin || blendShapeWeights) {
4557
4554
  var skinRenderer = entity.addComponent(SkinnedMeshRenderer);
4558
4555
  skinRenderer.mesh = mesh;
4559
4556
  if (skin) {
4560
- skinRenderer.rootBone = skin._rootBone;
4561
- skinRenderer.bones = skin._bones;
4562
- _this._computeLocalBounds(skinRenderer, mesh, skin._bones, skin._rootBone, skin.inverseBindMatrices);
4557
+ _this._computeLocalBounds(skinRenderer, mesh, skin.bones, skin.rootBone, skin.inverseBindMatrices);
4563
4558
  skinRenderer.skin = skin;
4564
4559
  }
4565
4560
  if (blendShapeWeights) {
@@ -4578,17 +4573,10 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
4578
4573
  }
4579
4574
  });
4580
4575
  GLTFParser.executeExtensionsAdditiveAndParse(glTFPrimitive.extensions, context, renderer, glTFPrimitive);
4581
- }));
4582
- };
4583
- var _this = this;
4584
- var glTFMeshes = context.glTF.meshes;
4585
- var meshID = entityInfo.mesh, skinID = entityInfo.skin;
4586
- var glTFMesh = glTFMeshes[meshID];
4587
- var glTFMeshPrimitives = glTFMesh.primitives;
4588
- var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
4589
- var promises = new Array();
4590
- for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
4591
- return Promise.all(promises);
4576
+ };
4577
+ var meshes = param[0], skin = param[1], materials = param[2];
4578
+ for(var i = 0; i < rendererCount; i++)_loop(i);
4579
+ });
4592
4580
  };
4593
4581
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
4594
4582
  var rootBoneIndex = bones.indexOf(rootBone);
@@ -4642,7 +4630,7 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser1) {
4642
4630
  var jointCount = joints.length;
4643
4631
  var skin = new Skin(name);
4644
4632
  skin.inverseBindMatrices.length = jointCount;
4645
- skin._bones.length = jointCount;
4633
+ var bones = new Array(jointCount);
4646
4634
  // parse IBM
4647
4635
  var accessor = glTF.accessors[inverseBindMatrices];
4648
4636
  var skinPromise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
@@ -4654,21 +4642,20 @@ var GLTFSkinParser = /*#__PURE__*/ function(GLTFParser1) {
4654
4642
  skin.inverseBindMatrices[i] = inverseBindMatrix;
4655
4643
  // Get bones
4656
4644
  var bone = entities[joints[i]];
4657
- skin._bones[i] = bone;
4645
+ bones[i] = bone;
4658
4646
  skin.joints[i] = bone.name;
4659
- // Get skeleton
4660
- if (skeleton !== undefined) {
4661
- var rootBone = entities[skeleton];
4662
- skin._rootBone = rootBone;
4663
- skin.skeleton = rootBone.name;
4647
+ }
4648
+ skin.bones = bones;
4649
+ // Get skeleton
4650
+ if (skeleton !== undefined) {
4651
+ var rootBone = entities[skeleton];
4652
+ skin.rootBone = rootBone;
4653
+ } else {
4654
+ var rootBone1 = _this._findSkeletonRootBone(joints, entities);
4655
+ if (rootBone1) {
4656
+ skin.rootBone = rootBone1;
4664
4657
  } else {
4665
- var rootBone1 = _this._findSkeletonRootBone(joints, entities);
4666
- if (rootBone1) {
4667
- skin._rootBone = rootBone1;
4668
- skin.skeleton = rootBone1.name;
4669
- } else {
4670
- throw "Failed to find skeleton root bone.";
4671
- }
4658
+ throw "Failed to find skeleton root bone.";
4672
4659
  }
4673
4660
  }
4674
4661
  return skin;
@@ -4836,6 +4823,48 @@ GLTFBufferViewParser = __decorate([
4836
4823
  registerGLTFParser(GLTFParserType.BufferView)
4837
4824
  ], GLTFBufferViewParser);
4838
4825
 
4826
+ var GLTFAnimatorControllerParser = /*#__PURE__*/ function(GLTFParser1) {
4827
+ _inherits(GLTFAnimatorControllerParser, GLTFParser1);
4828
+ function GLTFAnimatorControllerParser() {
4829
+ return GLTFParser1.apply(this, arguments);
4830
+ }
4831
+ var _proto = GLTFAnimatorControllerParser.prototype;
4832
+ _proto.parse = function parse(context) {
4833
+ var _this = this;
4834
+ if (!context.needAnimatorController) {
4835
+ return Promise.resolve(null);
4836
+ }
4837
+ return context.get(GLTFParserType.Animation).then(function(animations) {
4838
+ var animatorController = _this._createAnimatorController(animations);
4839
+ return Promise.resolve(animatorController);
4840
+ });
4841
+ };
4842
+ _proto._createAnimatorController = function _createAnimatorController(animations) {
4843
+ var animatorController = new AnimatorController();
4844
+ var layer = new AnimatorControllerLayer("layer");
4845
+ var animatorStateMachine = new AnimatorStateMachine();
4846
+ animatorController.addLayer(layer);
4847
+ layer.stateMachine = animatorStateMachine;
4848
+ if (animations) {
4849
+ for(var i = 0; i < animations.length; i++){
4850
+ var animationClip = animations[i];
4851
+ var name = animationClip.name;
4852
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4853
+ if (uniqueName !== name) {
4854
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4855
+ }
4856
+ var animatorState = animatorStateMachine.addState(uniqueName);
4857
+ animatorState.clip = animationClip;
4858
+ }
4859
+ }
4860
+ return animatorController;
4861
+ };
4862
+ return GLTFAnimatorControllerParser;
4863
+ }(GLTFParser);
4864
+ GLTFAnimatorControllerParser = __decorate([
4865
+ registerGLTFParser(GLTFParserType.AnimatorController)
4866
+ ], GLTFAnimatorControllerParser);
4867
+
4839
4868
  // Source: https://github.com/zeux/meshoptimizer/blob/master/js/meshopt_decoder.js
4840
4869
  var MeshoptDecoder = function() {
4841
4870
  var unpack = function unpack(data) {
@@ -5073,7 +5102,8 @@ GLTFLoader = __decorate([
5073
5102
 
5074
5103
  var _HDRLoader;
5075
5104
  var PI = Math.PI;
5076
- var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
5105
+ var HDRLoader = (_HDRLoader = // referenece: https://www.flipcode.com/archives/HDR_Image_Reader.shtml
5106
+ /*#__PURE__*/ function(Loader1) {
5077
5107
  _inherits(HDRLoader1, Loader1);
5078
5108
  function HDRLoader1() {
5079
5109
  return Loader1.apply(this, arguments);
@@ -5243,15 +5273,20 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
5243
5273
  var dataRGBA = new Uint8Array(4 * width * height);
5244
5274
  var offset = 0, pos = 0;
5245
5275
  var ptrEnd = 4 * scanLineWidth;
5246
- var rgbeStart = new Uint8Array(4);
5247
5276
  var scanLineBuffer = new Uint8Array(ptrEnd);
5248
5277
  var numScanLines = height; // read in each successive scanLine
5249
5278
  while(numScanLines > 0 && pos < byteLength){
5250
- rgbeStart[0] = buffer[pos++];
5251
- rgbeStart[1] = buffer[pos++];
5252
- rgbeStart[2] = buffer[pos++];
5253
- rgbeStart[3] = buffer[pos++];
5254
- if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanLineWidth) {
5279
+ var a = buffer[pos++];
5280
+ var b = buffer[pos++];
5281
+ var c = buffer[pos++];
5282
+ var d = buffer[pos++];
5283
+ if (a != 2 || b != 2 || c & 0x80 || width < 8 || width > 32767) {
5284
+ // this file is not run length encoded
5285
+ // read values sequentially
5286
+ return buffer;
5287
+ }
5288
+ if ((c << 8 | d) != scanLineWidth) {
5289
+ // eslint-disable-next-line no-throw-literal
5255
5290
  throw "HDR Bad header format, wrong scan line width";
5256
5291
  }
5257
5292
  // read each of the four channels for the scanline into the buffer
@@ -6689,5 +6724,5 @@ KHR_materials_anisotropy = __decorate([
6689
6724
  registerGLTFExtension("KHR_materials_anisotropy", GLTFExtensionMode.AdditiveParse)
6690
6725
  ], KHR_materials_anisotropy);
6691
6726
 
6692
- export { AccessorType, AnimationClipDecoder, BufferInfo, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, KTX2Loader, KTX2TargetFormat, KTX2Transcoder, MeshDecoder, MeshLoader$1 as MeshLoader, ParserContext, PrefabParser, ReflectionParser, SceneParser, SpecularMode, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension, registerGLTFParser };
6727
+ export { AccessorType, AnimationClipDecoder, BufferInfo, EditorTextureLoader, GLTFAnimationParser, GLTFAnimatorControllerParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, KTX2Loader, KTX2TargetFormat, KTX2Transcoder, MeshDecoder, MeshLoader$1 as MeshLoader, ParserContext, PrefabParser, ReflectionParser, SceneParser, SpecularMode, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension, registerGLTFParser };
6693
6728
  //# sourceMappingURL=module.js.map