@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.
@@ -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();
@@ -4841,6 +4830,48 @@ exports.GLTFBufferViewParser = __decorate([
4841
4830
  registerGLTFParser(exports.GLTFParserType.BufferView)
4842
4831
  ], exports.GLTFBufferViewParser);
4843
4832
 
4833
+ exports.GLTFAnimatorControllerParser = /*#__PURE__*/ function(GLTFParser1) {
4834
+ _inherits(GLTFAnimatorControllerParser, GLTFParser1);
4835
+ function GLTFAnimatorControllerParser() {
4836
+ return GLTFParser1.apply(this, arguments);
4837
+ }
4838
+ var _proto = GLTFAnimatorControllerParser.prototype;
4839
+ _proto.parse = function parse(context) {
4840
+ var _this = this;
4841
+ if (!context.needAnimatorController) {
4842
+ return Promise.resolve(null);
4843
+ }
4844
+ return context.get(exports.GLTFParserType.Animation).then(function(animations) {
4845
+ var animatorController = _this._createAnimatorController(animations);
4846
+ return Promise.resolve(animatorController);
4847
+ });
4848
+ };
4849
+ _proto._createAnimatorController = function _createAnimatorController(animations) {
4850
+ var animatorController = new miniprogram.AnimatorController();
4851
+ var layer = new miniprogram.AnimatorControllerLayer("layer");
4852
+ var animatorStateMachine = new miniprogram.AnimatorStateMachine();
4853
+ animatorController.addLayer(layer);
4854
+ layer.stateMachine = animatorStateMachine;
4855
+ if (animations) {
4856
+ for(var i = 0; i < animations.length; i++){
4857
+ var animationClip = animations[i];
4858
+ var name = animationClip.name;
4859
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
4860
+ if (uniqueName !== name) {
4861
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
4862
+ }
4863
+ var animatorState = animatorStateMachine.addState(uniqueName);
4864
+ animatorState.clip = animationClip;
4865
+ }
4866
+ }
4867
+ return animatorController;
4868
+ };
4869
+ return GLTFAnimatorControllerParser;
4870
+ }(GLTFParser);
4871
+ exports.GLTFAnimatorControllerParser = __decorate([
4872
+ registerGLTFParser(exports.GLTFParserType.AnimatorController)
4873
+ ], exports.GLTFAnimatorControllerParser);
4874
+
4844
4875
  var MeshoptDecoder = function() {
4845
4876
  var unpack = function unpack(data) {
4846
4877
  var result = new Uint8Array(data.length);
@@ -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 miniprogram$1.Vector2(value.x, value.y));
5732
+ break;
5733
+ case "Vector3":
5734
+ materialShaderData.setVector3(key, new miniprogram$1.Vector3(value.x, value.y, value.z));
5735
+ break;
5736
+ case "Vector4":
5737
+ materialShaderData.setVector4(key, new miniprogram$1.Vector4(value.x, value.y, value.z, value.w));
5738
+ break;
5739
+ case "Color":
5740
+ materialShaderData.setColor(key, new miniprogram$1.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 = miniprogram.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 miniprogram.Material(engine, miniprogram.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 miniprogram$1.Vector2(value.x, value.y));
5711
- break;
5712
- case "Vector3":
5713
- materialShaderData.setVector3(key, new miniprogram$1.Vector3(value.x, value.y, value.z));
5714
- break;
5715
- case "Vector4":
5716
- materialShaderData.setVector4(key, new miniprogram$1.Vector4(value.x, value.y, value.z, value.w));
5717
- break;
5718
- case "Color":
5719
- materialShaderData.setColor(key, new miniprogram$1.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 miniprogram.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
  }(miniprogram.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 miniprogram.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: miniprogram.AssetType.ShaderChunk,
6230
- url: resource,
6231
- params: {
6232
- includeKey: path
6233
- }
6234
- });
6235
- }
6236
- })).then(function() {
6237
- return miniprogram.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
- }(miniprogram.Loader);
6247
- ShaderLoader = __decorate([
6248
- miniprogram.resourceLoader(miniprogram.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
- miniprogram.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: miniprogram.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
- }(miniprogram.Loader);
6300
- ShaderChunkLoader = __decorate([
6301
- miniprogram.resourceLoader(miniprogram.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() {