@galacean/engine-loader 2.0.0-alpha.30 → 2.0.0-alpha.32

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
@@ -709,7 +709,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
709
709
  var _proto = ReflectionParser.prototype;
710
710
  /**
711
711
  * Apply v2 props to a component/object instance.
712
- * Each prop value is resolved recursively (handling $ref, $type, $entity, $component, $signal).
712
+ * Each prop value is resolved recursively (handling $ref, $type, $class, $entity, $component, $signal).
713
713
  */ _proto.parseProps = function parseProps(instance, props) {
714
714
  var promises = [];
715
715
  if (props) {
@@ -777,10 +777,11 @@ var ReflectionParser = /*#__PURE__*/ function() {
777
777
  * 2. Array → recurse each element
778
778
  * 3. { $ref } → asset reference
779
779
  * 4. { $type } → polymorphic type construct
780
- * 5. { $entity } entity reference by path (flat index + optional children descent)
781
- * 6. { $component } component reference
782
- * 7. { $signal } signal binding
783
- * 8. plain object recurse values (modify originValue in place if exists)
780
+ * 5. { $class } registered class constructor
781
+ * 6. { $entity } entity reference by path (flat index + optional children descent)
782
+ * 7. { $component } component reference
783
+ * 8. { $signal } signal binding
784
+ * 9. plain object → recurse values (modify originValue in place if exists)
784
785
  */ _proto._resolveValue = function _resolveValue(value, originValue) {
785
786
  var _this, _loop = function(key) {
786
787
  promises.push(_this._resolveValue(obj[key], target[key]).then(function(v) {
@@ -816,14 +817,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
816
817
  var $type = obj.$type, rest = _object_without_properties_loose(obj, [
817
818
  "$type"
818
819
  ]);
819
- var typeName = $type;
820
- var Class = engineCore.Loader.getClass(typeName);
821
- if (!Class) return Promise.reject(new Error('Loader.getClass: class "' + typeName + '" is not registered'));
822
- var instance = new Class();
823
- if (Object.keys(rest).length > 0) {
824
- return this.parseProps(instance, rest);
825
- }
826
- return Promise.resolve(instance);
820
+ return this._resolveRegisteredClass($type, "$type").then(function(Class) {
821
+ var instance = new Class();
822
+ return Object.keys(rest).length > 0 ? _this1.parseProps(instance, rest) : instance;
823
+ });
824
+ }
825
+ // $class — registered class constructor for factory-style methods.
826
+ if ("$class" in obj) {
827
+ return this._resolveRegisteredClass(obj.$class, "$class");
827
828
  }
828
829
  // $entity — entity reference by path (first element = flat index, subsequent = children indices)
829
830
  if ("$entity" in obj) {
@@ -845,6 +846,21 @@ var ReflectionParser = /*#__PURE__*/ function() {
845
846
  return target;
846
847
  });
847
848
  };
849
+ _proto._getRegisteredClass = function _getRegisteredClass(value, sentinel) {
850
+ if (typeof value !== "string" || value.length === 0) {
851
+ throw new Error("" + sentinel + " must be a non-empty registered class name string");
852
+ }
853
+ var Class = engineCore.Loader.getClass(value);
854
+ if (!Class) throw new Error('Loader.getClass: class "' + value + '" is not registered');
855
+ return Class;
856
+ };
857
+ /** Promise-adapt {@link _getRegisteredClass} so $type/$class branches can fold into the resolver chain. */ _proto._resolveRegisteredClass = function _resolveRegisteredClass(value, sentinel) {
858
+ try {
859
+ return Promise.resolve(this._getRegisteredClass(value, sentinel));
860
+ } catch (error) {
861
+ return Promise.reject(error);
862
+ }
863
+ };
848
864
  _proto._resolveSignal = function _resolveSignal(signal, listeners) {
849
865
  var _this = this;
850
866
  if (!signal || typeof signal.on !== "function") {
@@ -1518,7 +1534,7 @@ function _instanceof(left, right) {
1518
1534
  }
1519
1535
  };
1520
1536
  _proto._getRootIndices = function _getRootIndices() {
1521
- return this.data.scene.entities;
1537
+ return this.data.scene.rootEntities;
1522
1538
  };
1523
1539
  _proto._handleRootEntity = function _handleRootEntity(index) {
1524
1540
  this.scene.addRootEntity(this.context.entityInstances[index]);
@@ -1531,8 +1547,8 @@ function _instanceof(left, right) {
1531
1547
  }(HierarchyParser);
1532
1548
 
1533
1549
  var SpecularMode = /*#__PURE__*/ function(SpecularMode) {
1534
- SpecularMode["Sky"] = "Sky";
1535
- SpecularMode["Custom"] = "Custom";
1550
+ SpecularMode[SpecularMode["Sky"] = 0] = "Sky";
1551
+ SpecularMode[SpecularMode["Custom"] = 1] = "Custom";
1536
1552
  return SpecularMode;
1537
1553
  }({});
1538
1554
 
@@ -5698,15 +5714,6 @@ var KTXContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
5698
5714
  return KTXContentRestorer;
5699
5715
  }(engineCore.ContentRestorer);
5700
5716
 
5701
- function parseProperty(object, key, value) {
5702
- if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
5703
- for(var subKey in value){
5704
- parseProperty(object[key], subKey, value[subKey]);
5705
- }
5706
- } else {
5707
- object[key] = value;
5708
- }
5709
- }
5710
5717
  var MaterialLoader = /*#__PURE__*/ function(Loader) {
5711
5718
  _inherits(MaterialLoader, Loader);
5712
5719
  function MaterialLoader() {
@@ -5767,7 +5774,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
5767
5774
  break;
5768
5775
  }
5769
5776
  };
5770
- var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
5777
+ var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros;
5771
5778
  var material = new engineCore.Material(engine, shader);
5772
5779
  material.name = name;
5773
5780
  var texturePromises = new Array();
@@ -5781,7 +5788,6 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
5781
5788
  materialShaderData.enableMacro(name1, value);
5782
5789
  }
5783
5790
  }
5784
- parseProperty(material, "renderState", renderState);
5785
5791
  return Promise.all(texturePromises).then(function() {
5786
5792
  return material;
5787
5793
  });
@@ -6323,51 +6329,6 @@ AudioLoader = __decorate([
6323
6329
  ])
6324
6330
  ], AudioLoader);
6325
6331
 
6326
- var ShaderChunkLoader = /*#__PURE__*/ function(Loader) {
6327
- _inherits(ShaderChunkLoader, Loader);
6328
- function ShaderChunkLoader() {
6329
- return Loader.apply(this, arguments) || this;
6330
- }
6331
- var _proto = ShaderChunkLoader.prototype;
6332
- _proto.load = function load(item, resourceManager) {
6333
- var url = item.url;
6334
- // @ts-ignore
6335
- return resourceManager._request(url, _extends({}, item, {
6336
- type: "text"
6337
- })).then(function(code) {
6338
- engineCore.ShaderFactory.registerInclude(url.substring(1), code);
6339
- return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager);
6340
- });
6341
- };
6342
- /**
6343
- * @internal
6344
- */ ShaderChunkLoader._loadChunksInCode = function _loadChunksInCode(code, basePath, resourceManager) {
6345
- var shaderChunkPaths = new Array();
6346
- var matches = code.matchAll(ShaderChunkLoader._shaderIncludeRegex);
6347
- for(var _iterator = _create_for_of_iterator_helper_loose(matches), _step; !(_step = _iterator()).done;){
6348
- var match = _step.value;
6349
- var chunkPath = engineCore.Utils.resolveAbsoluteUrl(basePath, match[1]);
6350
- if (!engineCore.ShaderLib[chunkPath.substring(1)]) {
6351
- shaderChunkPaths.push(chunkPath);
6352
- }
6353
- }
6354
- return Promise.all(shaderChunkPaths.map(function(chunkPath) {
6355
- // @ts-ignore
6356
- return resourceManager.load({
6357
- type: "ShaderChunk",
6358
- url: chunkPath
6359
- });
6360
- }));
6361
- };
6362
- return ShaderChunkLoader;
6363
- }(engineCore.Loader);
6364
- ShaderChunkLoader._shaderIncludeRegex = /#include\s+"([./][^\\"]+)"/gm;
6365
- ShaderChunkLoader = __decorate([
6366
- engineCore.resourceLoader("ShaderChunk", [
6367
- "glsl"
6368
- ])
6369
- ], ShaderChunkLoader);
6370
-
6371
6332
  var ShaderLoader = /*#__PURE__*/ function(Loader) {
6372
6333
  _inherits(ShaderLoader, Loader);
6373
6334
  function ShaderLoader() {
@@ -6377,7 +6338,7 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
6377
6338
  _proto.load = function load(item, resourceManager) {
6378
6339
  var _this = this;
6379
6340
  var url = item.url;
6380
- if (url.endsWith(".gsp")) {
6341
+ if (url.endsWith(".shaderc")) {
6381
6342
  // @ts-ignore
6382
6343
  return resourceManager._request(url, _extends({}, item, {
6383
6344
  type: "json"
@@ -6394,10 +6355,7 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
6394
6355
  if (builtinShader) {
6395
6356
  return engineCore.Shader.find(builtinShader);
6396
6357
  }
6397
- return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager).then(function() {
6398
- var shader = engineCore.Shader.create(code, undefined, url);
6399
- return shader;
6400
- });
6358
+ return engineCore.Shader.create(code, undefined, url);
6401
6359
  });
6402
6360
  };
6403
6361
  _proto._getBuiltinShader = function _getBuiltinShader(code) {
@@ -6409,7 +6367,8 @@ var ShaderLoader = /*#__PURE__*/ function(Loader) {
6409
6367
  ShaderLoader._builtinRegex = /^\s*\/\/\s*@builtin\s+(\w+)/;
6410
6368
  ShaderLoader = __decorate([
6411
6369
  engineCore.resourceLoader(engineCore.AssetType.Shader, [
6412
- "shader"
6370
+ "shader",
6371
+ "shaderc"
6413
6372
  ])
6414
6373
  ], ShaderLoader);
6415
6374