@galacean/engine-loader 0.0.0-experimental-shaderlab.2 → 0.0.0-experimental-stateMachine.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.
package/dist/main.js CHANGED
@@ -1886,6 +1886,7 @@ var TextureWrapMode;
1886
1886
  this.resourceManager = resourceManager;
1887
1887
  this.params = params;
1888
1888
  this.accessorBufferCache = {};
1889
+ this.needAnimatorController = false;
1889
1890
  this._resourceCache = new Map();
1890
1891
  this._progress = {
1891
1892
  taskDetail: {},
@@ -1913,16 +1914,15 @@ var TextureWrapMode;
1913
1914
  return Promise.resolve(null);
1914
1915
  }
1915
1916
  var cache = this._resourceCache;
1916
- var isOnlyOne = type === 0 || type === 1;
1917
- var cacheKey = isOnlyOne || index === undefined ? "" + type : type + ":" + index;
1917
+ var cacheKey = index === undefined ? "" + type : type + ":" + index;
1918
1918
  var resource = cache.get(cacheKey);
1919
1919
  if (resource) {
1920
1920
  return resource;
1921
1921
  }
1922
- if (isOnlyOne) {
1923
- resource = parser.parse(this);
1924
- } else {
1925
- var glTFItems = this.glTF[glTFSchemaMap[type]];
1922
+ var glTFSchemaKey = glTFSchemaMap[type];
1923
+ var isSubAsset = !!glTFResourceMap[type];
1924
+ if (glTFSchemaKey) {
1925
+ var glTFItems = this.glTF[glTFSchemaKey];
1926
1926
  if (glTFItems && (index === undefined || glTFItems[index])) {
1927
1927
  if (index === undefined) {
1928
1928
  resource = type === 8 ? glTFItems.map(function(_, index) {
@@ -1932,11 +1932,14 @@ var TextureWrapMode;
1932
1932
  }));
1933
1933
  } else {
1934
1934
  resource = parser.parse(this, index);
1935
- this._handleSubAsset(resource, type, index);
1935
+ isSubAsset && this._handleSubAsset(resource, type, index);
1936
1936
  }
1937
1937
  } else {
1938
1938
  resource = Promise.resolve(null);
1939
1939
  }
1940
+ } else {
1941
+ resource = parser.parse(this, index);
1942
+ isSubAsset && this._handleSubAsset(resource, type, index);
1940
1943
  }
1941
1944
  cache.set(cacheKey, resource);
1942
1945
  return resource;
@@ -1945,6 +1948,7 @@ var TextureWrapMode;
1945
1948
  var _this = this;
1946
1949
  var promise = this.get(0).then(function(json) {
1947
1950
  _this.glTF = json;
1951
+ _this.needAnimatorController = !!(json.skins || json.animations);
1948
1952
  return Promise.all([
1949
1953
  _this.get(1),
1950
1954
  _this.get(5),
@@ -1952,11 +1956,14 @@ var TextureWrapMode;
1952
1956
  _this.get(7),
1953
1957
  _this.get(9),
1954
1958
  _this.get(10),
1959
+ _this.get(11),
1955
1960
  _this.get(2)
1956
1961
  ]).then(function() {
1957
1962
  var glTFResource = _this.glTFResource;
1958
- if (glTFResource.skins || glTFResource.animations) {
1959
- _this._createAnimator(_this, glTFResource.animations);
1963
+ var animatorController = glTFResource.animatorController;
1964
+ if (animatorController) {
1965
+ var animator = glTFResource._defaultSceneRoot.addComponent(engineCore.Animator);
1966
+ animator.animatorController = animatorController;
1960
1967
  }
1961
1968
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
1962
1969
  return glTFResource;
@@ -1975,40 +1982,21 @@ var TextureWrapMode;
1975
1982
  _this._setTaskCompleteProgress(++task.loaded, task.total);
1976
1983
  });
1977
1984
  };
1978
- _proto._createAnimator = function _createAnimator(context, animations) {
1979
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
1980
- var animator = defaultSceneRoot.addComponent(engineCore.Animator);
1981
- var animatorController = new engineCore.AnimatorController();
1982
- var layer = new engineCore.AnimatorControllerLayer("layer");
1983
- var animatorStateMachine = new engineCore.AnimatorStateMachine();
1984
- animatorController.addLayer(layer);
1985
- animator.animatorController = animatorController;
1986
- layer.stateMachine = animatorStateMachine;
1987
- if (animations) {
1988
- for(var i = 0; i < animations.length; i++){
1989
- var animationClip = animations[i];
1990
- var name = animationClip.name;
1991
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
1992
- if (uniqueName !== name) {
1993
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
1994
- }
1995
- var animatorState = animatorStateMachine.addState(uniqueName);
1996
- animatorState.clip = animationClip;
1997
- }
1998
- }
1999
- };
2000
1985
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
2001
1986
  var _this = this;
2002
1987
  var glTFResourceKey = glTFResourceMap[type];
2003
- if (!glTFResourceKey) return;
2004
1988
  if (type === 8) {
2005
1989
  var _this_glTFResource, _glTFResourceKey;
2006
1990
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
2007
1991
  } else {
2008
1992
  var url = this.glTFResource.url;
2009
1993
  resource.then(function(item) {
2010
- var _this_glTFResource, _glTFResourceKey;
2011
- ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
1994
+ if (index == undefined) {
1995
+ _this.glTFResource[glTFResourceKey] = item;
1996
+ } else {
1997
+ var _this_glTFResource, _glTFResourceKey;
1998
+ ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
1999
+ }
2012
2000
  if (type === 7) {
2013
2001
  for(var i = 0, length = item.length; i < length; i++){
2014
2002
  var mesh = item[i];
@@ -2056,11 +2044,12 @@ exports.GLTFParserType = void 0;
2056
2044
  GLTFParserType[GLTFParserType["Entity"] = 8] = "Entity";
2057
2045
  GLTFParserType[GLTFParserType["Skin"] = 9] = "Skin";
2058
2046
  GLTFParserType[GLTFParserType["Animation"] = 10] = "Animation";
2047
+ GLTFParserType[GLTFParserType["AnimatorController"] = 11] = "AnimatorController";
2059
2048
  })(exports.GLTFParserType || (exports.GLTFParserType = {}));
2060
2049
  var _obj;
2061
2050
  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);
2062
2051
  var _obj1;
2063
- 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);
2052
+ 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);
2064
2053
  function registerGLTFParser(pipeline) {
2065
2054
  return function(Parser) {
2066
2055
  var parser = new Parser();
@@ -4840,6 +4829,48 @@ exports.GLTFBufferViewParser = __decorate([
4840
4829
  registerGLTFParser(exports.GLTFParserType.BufferView)
4841
4830
  ], exports.GLTFBufferViewParser);
4842
4831
 
4832
+ exports.GLTFAnimatorControllerParser = /*#__PURE__*/ function(GLTFParser1) {
4833
+ _inherits(GLTFAnimatorControllerParser, GLTFParser1);
4834
+ function GLTFAnimatorControllerParser() {
4835
+ return GLTFParser1.apply(this, arguments);
4836
+ }
4837
+ var _proto = GLTFAnimatorControllerParser.prototype;
4838
+ _proto.parse = function parse(context) {
4839
+ var _this = this;
4840
+ if (!context.needAnimatorController) {
4841
+ return Promise.resolve(null);
4842
+ }
4843
+ return context.get(exports.GLTFParserType.Animation).then(function(animations) {
4844
+ var animatorController = _this._createAnimatorController(animations);
4845
+ return Promise.resolve(animatorController);
4846
+ });
4847
+ };
4848
+ _proto._createAnimatorController = function _createAnimatorController(animations) {
4849
+ var animatorController = new engineCore.AnimatorController();
4850
+ var layer = new engineCore.AnimatorControllerLayer("layer");
4851
+ var animatorStateMachine = new engineCore.AnimatorStateMachine();
4852
+ animatorController.addLayer(layer);
4853
+ layer.stateMachine = animatorStateMachine;
4854
+ if (animations) {
4855
+ for(var i = 0; i < animations.length; i++){
4856
+ var animationClip = animations[i];
4857
+ var name = animationClip.name;
4858
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4859
+ if (uniqueName !== name) {
4860
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4861
+ }
4862
+ var animatorState = animatorStateMachine.addState(uniqueName);
4863
+ animatorState.clip = animationClip;
4864
+ }
4865
+ }
4866
+ return animatorController;
4867
+ };
4868
+ return GLTFAnimatorControllerParser;
4869
+ }(GLTFParser);
4870
+ exports.GLTFAnimatorControllerParser = __decorate([
4871
+ registerGLTFParser(exports.GLTFParserType.AnimatorController)
4872
+ ], exports.GLTFAnimatorControllerParser);
4873
+
4843
4874
  // Source: https://github.com/zeux/meshoptimizer/blob/master/js/meshopt_decoder.js
4844
4875
  var MeshoptDecoder = function() {
4845
4876
  var unpack = function unpack(data) {
@@ -5077,7 +5108,8 @@ exports.GLTFLoader = __decorate([
5077
5108
 
5078
5109
  var _HDRLoader;
5079
5110
  var PI = Math.PI;
5080
- var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
5111
+ var HDRLoader = (_HDRLoader = // referenece: https://www.flipcode.com/archives/HDR_Image_Reader.shtml
5112
+ /*#__PURE__*/ function(Loader1) {
5081
5113
  _inherits(HDRLoader1, Loader1);
5082
5114
  function HDRLoader1() {
5083
5115
  return Loader1.apply(this, arguments);
@@ -5247,15 +5279,20 @@ var HDRLoader = (_HDRLoader = /*#__PURE__*/ function(Loader1) {
5247
5279
  var dataRGBA = new Uint8Array(4 * width * height);
5248
5280
  var offset = 0, pos = 0;
5249
5281
  var ptrEnd = 4 * scanLineWidth;
5250
- var rgbeStart = new Uint8Array(4);
5251
5282
  var scanLineBuffer = new Uint8Array(ptrEnd);
5252
5283
  var numScanLines = height; // read in each successive scanLine
5253
5284
  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) {
5285
+ var a = buffer[pos++];
5286
+ var b = buffer[pos++];
5287
+ var c = buffer[pos++];
5288
+ var d = buffer[pos++];
5289
+ if (a != 2 || b != 2 || c & 0x80 || width < 8 || width > 32767) {
5290
+ // this file is not run length encoded
5291
+ // read values sequentially
5292
+ return buffer;
5293
+ }
5294
+ if ((c << 8 | d) != scanLineWidth) {
5295
+ // eslint-disable-next-line no-throw-literal
5259
5296
  throw "HDR Bad header format, wrong scan line width";
5260
5297
  }
5261
5298
  // read each of the four channels for the scanline into the buffer
@@ -5687,73 +5724,60 @@ var MaterialLoader = /*#__PURE__*/ function(Loader1) {
5687
5724
  _this.request(item.url, _extends({}, item, {
5688
5725
  type: "json"
5689
5726
  })).then(function(materialSchema) {
5727
+ var _loop = function(key) {
5728
+ var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
5729
+ switch(type){
5730
+ case "Vector2":
5731
+ materialShaderData.setVector2(key, new engineMath.Vector2(value.x, value.y));
5732
+ break;
5733
+ case "Vector3":
5734
+ materialShaderData.setVector3(key, new engineMath.Vector3(value.x, value.y, value.z));
5735
+ break;
5736
+ case "Vector4":
5737
+ materialShaderData.setVector4(key, new engineMath.Vector4(value.x, value.y, value.z, value.w));
5738
+ break;
5739
+ case "Color":
5740
+ materialShaderData.setColor(key, new engineMath.Color(value.r, value.g, value.b, value.a));
5741
+ break;
5742
+ case "Float":
5743
+ materialShaderData.setFloat(key, value);
5744
+ break;
5745
+ case "Texture":
5746
+ texturePromises.push(// @ts-ignore
5747
+ resourceManager.getResourceByRef(value).then(function(texture) {
5748
+ materialShaderData.setTexture(key, texture);
5749
+ }));
5750
+ break;
5751
+ case "Boolean":
5752
+ materialShaderData.setInt(key, value ? 1 : 0);
5753
+ break;
5754
+ case "Integer":
5755
+ materialShaderData.setInt(key, Number(value));
5756
+ break;
5757
+ }
5758
+ };
5690
5759
  var engine = resourceManager.engine;
5691
- var shaderRef = materialSchema.shaderRef, shader = materialSchema.shader;
5692
- if (shaderRef) {
5693
- resolve(resourceManager// @ts-ignore
5694
- .getResourceByRef(shaderRef).then(function(shaderObject) {
5695
- return _this.getMaterialByShader(materialSchema, shaderObject, engine);
5696
- }));
5697
- } else {
5698
- // compatible with 1.2-pre version material schema
5699
- var shaderObject = engineCore.Shader.find(shader);
5700
- resolve(_this.getMaterialByShader(materialSchema, shaderObject, engine));
5760
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
5761
+ var material = new engineCore.Material(engine, engineCore.Shader.find(shader));
5762
+ material.name = name;
5763
+ var texturePromises = new Array();
5764
+ var materialShaderData = material.shaderData;
5765
+ for(var key in shaderData)_loop(key);
5766
+ for(var i = 0, length = macros.length; i < length; i++){
5767
+ var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
5768
+ if (value == undefined) {
5769
+ materialShaderData.enableMacro(name1);
5770
+ } else {
5771
+ materialShaderData.enableMacro(name1, value);
5772
+ }
5701
5773
  }
5774
+ parseProperty(material, "renderState", renderState);
5775
+ return Promise.all(texturePromises).then(function() {
5776
+ resolve(material);
5777
+ });
5702
5778
  }).catch(reject);
5703
5779
  });
5704
5780
  };
5705
- _proto.getMaterialByShader = function getMaterialByShader(materialSchema, shader, engine) {
5706
- var _loop = function(key) {
5707
- var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
5708
- switch(type){
5709
- case "Vector2":
5710
- materialShaderData.setVector2(key, new engineMath.Vector2(value.x, value.y));
5711
- break;
5712
- case "Vector3":
5713
- materialShaderData.setVector3(key, new engineMath.Vector3(value.x, value.y, value.z));
5714
- break;
5715
- case "Vector4":
5716
- materialShaderData.setVector4(key, new engineMath.Vector4(value.x, value.y, value.z, value.w));
5717
- break;
5718
- case "Color":
5719
- materialShaderData.setColor(key, new engineMath.Color(value.r, value.g, value.b, value.a));
5720
- break;
5721
- case "Float":
5722
- materialShaderData.setFloat(key, value);
5723
- break;
5724
- case "Texture":
5725
- texturePromises.push(// @ts-ignore
5726
- engine.resourceManager.getResourceByRef(value).then(function(texture) {
5727
- materialShaderData.setTexture(key, texture);
5728
- }));
5729
- break;
5730
- case "Boolean":
5731
- materialShaderData.setInt(key, value ? 1 : 0);
5732
- break;
5733
- case "Integer":
5734
- materialShaderData.setInt(key, Number(value));
5735
- break;
5736
- }
5737
- };
5738
- var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
5739
- var material = new engineCore.Material(engine, shader);
5740
- material.name = name;
5741
- var texturePromises = new Array();
5742
- var materialShaderData = material.shaderData;
5743
- for(var key in shaderData)_loop(key);
5744
- for(var i = 0, length = macros.length; i < length; i++){
5745
- var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
5746
- if (value == undefined) {
5747
- materialShaderData.enableMacro(name1);
5748
- } else {
5749
- materialShaderData.enableMacro(name1, value);
5750
- }
5751
- }
5752
- parseProperty(material, "renderState", renderState);
5753
- return Promise.all(texturePromises).then(function() {
5754
- return material;
5755
- });
5756
- };
5757
5781
  return MaterialLoader;
5758
5782
  }(engineCore.Loader);
5759
5783
  MaterialLoader = __decorate([
@@ -6203,106 +6227,6 @@ TextureCubeLoader = __decorate([
6203
6227
  ])
6204
6228
  ], TextureCubeLoader);
6205
6229
 
6206
- var ShaderLoader = /*#__PURE__*/ function(Loader1) {
6207
- _inherits(ShaderLoader, Loader1);
6208
- function ShaderLoader() {
6209
- return Loader1.apply(this, arguments);
6210
- }
6211
- var _proto = ShaderLoader.prototype;
6212
- _proto.load = function load(item, resourceManager) {
6213
- var _this = this;
6214
- return this.request(item.url, _extends({}, item, {
6215
- type: "text"
6216
- })).then(function(code) {
6217
- var builtinShader = _this.getBuiltinShader(code);
6218
- if (builtinShader) {
6219
- return engineCore.Shader.find(builtinShader);
6220
- }
6221
- var matches = code.matchAll(/^[ \t]*#include +"([^$\\"]+)"/gm);
6222
- return Promise.all(Array.from(matches).map(function(m) {
6223
- var path = m[1];
6224
- if (path) {
6225
- // @ts-ignore
6226
- var resource = resourceManager._virtualPathMap[path];
6227
- if (!resource) return;
6228
- return resourceManager.load({
6229
- type: engineCore.AssetType.ShaderChunk,
6230
- url: resource,
6231
- params: {
6232
- includeKey: path
6233
- }
6234
- });
6235
- }
6236
- })).then(function() {
6237
- return engineCore.Shader.create(code);
6238
- });
6239
- });
6240
- };
6241
- _proto.getBuiltinShader = function getBuiltinShader(code) {
6242
- var match = code.match(/^\s*\/\/\s*@builtin\s+(\w+)/);
6243
- if (match && match[1]) return match[1];
6244
- };
6245
- return ShaderLoader;
6246
- }(engineCore.Loader);
6247
- ShaderLoader = __decorate([
6248
- engineCore.resourceLoader(engineCore.AssetType.Shader, [
6249
- "gs",
6250
- "gsl"
6251
- ], false)
6252
- ], ShaderLoader);
6253
-
6254
- var ShaderChunkLoader = /*#__PURE__*/ function(Loader1) {
6255
- _inherits(ShaderChunkLoader, Loader1);
6256
- function ShaderChunkLoader() {
6257
- return Loader1.apply(this, arguments);
6258
- }
6259
- var _proto = ShaderChunkLoader.prototype;
6260
- _proto.load = function load(item, resourceManager) {
6261
- return this.request(item.url, _extends({}, item, {
6262
- type: "text"
6263
- })).then(/*#__PURE__*/ _async_to_generator(function(code) {
6264
- var includeKey, matches;
6265
- return __generator(this, function(_state) {
6266
- switch(_state.label){
6267
- case 0:
6268
- includeKey = item.params.includeKey;
6269
- engineCore.ShaderFactory.registerInclude(includeKey, code);
6270
- matches = code.matchAll(/^[ \t]*#include +"([^$\\"]+)"/gm);
6271
- return [
6272
- 4,
6273
- Promise.all(Array.from(matches).map(function(m) {
6274
- var path = m[1];
6275
- if (path) {
6276
- // @ts-ignore
6277
- var resource = resourceManager._virtualPathMap[path];
6278
- if (!resource) return;
6279
- return resourceManager.load({
6280
- type: engineCore.AssetType.ShaderChunk,
6281
- url: resource,
6282
- params: {
6283
- includeKey: path
6284
- }
6285
- });
6286
- }
6287
- }))
6288
- ];
6289
- case 1:
6290
- _state.sent();
6291
- return [
6292
- 2
6293
- ];
6294
- }
6295
- });
6296
- }));
6297
- };
6298
- return ShaderChunkLoader;
6299
- }(engineCore.Loader);
6300
- ShaderChunkLoader = __decorate([
6301
- engineCore.resourceLoader(engineCore.AssetType.ShaderChunk, [
6302
- "glsl"
6303
- ], false)
6304
- ], ShaderChunkLoader);
6305
-
6306
6230
  var SceneLoader = /*#__PURE__*/ function(Loader1) {
6307
6231
  _inherits(SceneLoader, Loader1);
6308
6232
  function SceneLoader() {