@galacean/engine-loader 1.4.0-alpha.1 → 1.4.0-alpha.2

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
@@ -537,11 +537,7 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
537
537
  return ParserType;
538
538
  }({});
539
539
  /**
540
- * Parser context
541
- * @export
542
- * @class ParserContext
543
- * @template T
544
- * @template I
540
+ * @internal
545
541
  */ var ParserContext = /*#__PURE__*/ function() {
546
542
  function ParserContext(engine, type, resource) {
547
543
  if (type === void 0) type = 1;
@@ -553,13 +549,39 @@ var ParserType = /*#__PURE__*/ function(ParserType) {
553
549
  this.components = new Map();
554
550
  this.rootIds = [];
555
551
  this.strippedIds = [];
552
+ this.componentWaitingMap = new Map();
556
553
  this.resourceManager = engine.resourceManager;
557
554
  }
558
555
  var _proto = ParserContext.prototype;
559
- /**
560
- * Destroy the context.
561
- * @memberof ParserContext
562
- */ _proto.clear = function clear() {
556
+ _proto.addComponent = function addComponent(id, component) {
557
+ this.components.set(id, component);
558
+ var waitingList = this.componentWaitingMap.get(id);
559
+ if (waitingList == null ? void 0 : waitingList.length) {
560
+ waitingList.forEach(function(resolve) {
561
+ return resolve(component);
562
+ });
563
+ this.componentWaitingMap.delete(id);
564
+ }
565
+ };
566
+ _proto.getComponentByRef = function getComponentByRef(ref) {
567
+ var _this = this;
568
+ return new Promise(function(resolve, reject) {
569
+ var component = _this.components.get(ref.componentId);
570
+ if (component) {
571
+ resolve(component);
572
+ } else {
573
+ var resolves = _this.componentWaitingMap.get(ref.componentId);
574
+ if (resolves) {
575
+ resolves.push(resolve);
576
+ } else {
577
+ _this.componentWaitingMap.set(ref.componentId, [
578
+ resolve
579
+ ]);
580
+ }
581
+ }
582
+ });
583
+ };
584
+ _proto.clear = function clear() {
563
585
  this.entityMap.clear();
564
586
  this.components.clear();
565
587
  this.entityConfigMap.clear();
@@ -659,6 +681,8 @@ var ReflectionParser = /*#__PURE__*/ function() {
659
681
  }
660
682
  return resource;
661
683
  });
684
+ } else if (ReflectionParser._isComponentRef(value)) {
685
+ return this._context.getComponentByRef(value);
662
686
  } else if (ReflectionParser._isEntityRef(value)) {
663
687
  // entity reference
664
688
  return Promise.resolve(this._context.entityMap.get(value.entityId));
@@ -720,13 +744,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
720
744
  this.customParseComponentHandles[componentType] = handle;
721
745
  };
722
746
  ReflectionParser._isClass = function _isClass(value) {
723
- return value["class"] != undefined;
747
+ return value["class"] !== undefined;
724
748
  };
725
749
  ReflectionParser._isAssetRef = function _isAssetRef(value) {
726
- return value["refId"] != undefined;
750
+ return value["refId"] !== undefined;
727
751
  };
728
752
  ReflectionParser._isEntityRef = function _isEntityRef(value) {
729
- return value["entityId"] != undefined;
753
+ return value["entityId"] !== undefined;
754
+ };
755
+ ReflectionParser._isComponentRef = function _isComponentRef(value) {
756
+ return value["ownerId"] !== undefined && value["componentId"] !== undefined;
730
757
  };
731
758
  return ReflectionParser;
732
759
  }();
@@ -1083,7 +1110,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1083
1110
  _proto._parseComponents = function _parseComponents() {
1084
1111
  var entitiesConfig = this.data.entities;
1085
1112
  var entityMap = this.context.entityMap;
1086
- var components = this.context.components;
1087
1113
  var promises = [];
1088
1114
  for(var i = 0, l = entitiesConfig.length; i < l; i++){
1089
1115
  var entityConfig = entitiesConfig[i];
@@ -1092,11 +1118,17 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1092
1118
  var componentConfig = entityConfig.components[i1];
1093
1119
  var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
1094
1120
  var component = entity.addComponent(engineCore.Loader.getClass(key));
1095
- components.set(componentConfig.id, component);
1121
+ this.context.addComponent(componentConfig.id, component);
1096
1122
  var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
1097
1123
  promises.push(promise);
1098
1124
  }
1099
1125
  }
1126
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.context.componentWaitingMap.values()), _step; !(_step = _iterator()).done;){
1127
+ var waitingList = _step.value;
1128
+ waitingList.forEach(function(resolve) {
1129
+ return resolve(null);
1130
+ });
1131
+ }
1100
1132
  return Promise.all(promises);
1101
1133
  };
1102
1134
  _proto._parsePrefabModification = function _parsePrefabModification() {
@@ -6473,6 +6505,34 @@ ShaderLoader = __decorate([
6473
6505
  ])
6474
6506
  ], ShaderLoader);
6475
6507
 
6508
+ var PhysicsMaterialLoader = /*#__PURE__*/ function(Loader) {
6509
+ _inherits(PhysicsMaterialLoader, Loader);
6510
+ function PhysicsMaterialLoader() {
6511
+ return Loader.apply(this, arguments) || this;
6512
+ }
6513
+ var _proto = PhysicsMaterialLoader.prototype;
6514
+ _proto.load = function load(item, resourceManager) {
6515
+ return resourceManager// @ts-ignore
6516
+ ._request(item.url, _extends({}, item, {
6517
+ type: "json"
6518
+ })).then(function(data) {
6519
+ var physicsMaterial = new engineCore.PhysicsMaterial();
6520
+ physicsMaterial.bounciness = data.bounciness;
6521
+ physicsMaterial.dynamicFriction = data.dynamicFriction;
6522
+ physicsMaterial.staticFriction = data.staticFriction;
6523
+ physicsMaterial.bounceCombine = data.bounceCombine;
6524
+ physicsMaterial.frictionCombine = data.frictionCombine;
6525
+ return physicsMaterial;
6526
+ });
6527
+ };
6528
+ return PhysicsMaterialLoader;
6529
+ }(engineCore.Loader);
6530
+ PhysicsMaterialLoader = __decorate([
6531
+ engineCore.resourceLoader(engineCore.AssetType.PhysicsMaterial, [
6532
+ "mesh"
6533
+ ])
6534
+ ], PhysicsMaterialLoader);
6535
+
6476
6536
  var SceneLoader = /*#__PURE__*/ function(Loader) {
6477
6537
  _inherits(SceneLoader, Loader);
6478
6538
  function SceneLoader() {
@@ -6580,28 +6640,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
6580
6640
  // Post Process
6581
6641
  var postProcessData = data.scene.postProcess;
6582
6642
  if (postProcessData) {
6583
- // @ts-ignore
6584
- var postProcessManager = scene._postProcessManager;
6585
- var bloomEffect = postProcessManager._bloomEffect;
6586
- var tonemappingEffect = postProcessManager._tonemappingEffect;
6587
- postProcessManager.isActive = postProcessData.isActive;
6588
- bloomEffect.enabled = postProcessData.bloom.enabled;
6589
- bloomEffect.downScale = postProcessData.bloom.downScale;
6590
- bloomEffect.threshold = postProcessData.bloom.threshold;
6591
- bloomEffect.scatter = postProcessData.bloom.scatter;
6592
- bloomEffect.intensity = postProcessData.bloom.intensity;
6593
- bloomEffect.tint.copyFrom(postProcessData.bloom.tint);
6594
- bloomEffect.dirtIntensity = postProcessData.bloom.dirtIntensity;
6595
- tonemappingEffect.enabled = postProcessData.tonemapping.enabled;
6596
- tonemappingEffect.mode = postProcessData.tonemapping.mode;
6597
- if (postProcessData.bloom.dirtTexture) {
6598
- // @ts-ignore
6599
- // prettier-ignore
6600
- var dirtTexturePromise = resourceManager.getResourceByRef(postProcessData.bloom.dirtTexture).then(function(texture) {
6601
- bloomEffect.dirtTexture = texture;
6602
- });
6603
- promises.push(dirtTexturePromise);
6604
- }
6643
+ engineCore.Logger.warn("Post Process is not supported in scene yet, please add PostProcess component in entity instead.");
6605
6644
  }
6606
6645
  return Promise.all(promises).then(function() {
6607
6646
  resolve(scene);
@@ -6796,6 +6835,28 @@ KHR_materials_sheen = __decorate([
6796
6835
  registerGLTFExtension("KHR_materials_sheen", GLTFExtensionMode.AdditiveParse)
6797
6836
  ], KHR_materials_sheen);
6798
6837
 
6838
+ var KHR_materials_transmission = /*#__PURE__*/ function(GLTFExtensionParser) {
6839
+ _inherits(KHR_materials_transmission, GLTFExtensionParser);
6840
+ function KHR_materials_transmission() {
6841
+ return GLTFExtensionParser.apply(this, arguments) || this;
6842
+ }
6843
+ var _proto = KHR_materials_transmission.prototype;
6844
+ _proto.additiveParse = function additiveParse(context, material, schema) {
6845
+ var _schema_transmissionFactor = schema.transmissionFactor, transmissionFactor = _schema_transmissionFactor === void 0 ? 0 : _schema_transmissionFactor, transmissionTexture = schema.transmissionTexture;
6846
+ material.transmission = transmissionFactor;
6847
+ if (transmissionTexture) {
6848
+ exports.GLTFMaterialParser._checkOtherTextureTransform(transmissionTexture, "Transmission texture");
6849
+ context.get(GLTFParserType.Texture, transmissionTexture.index).then(function(texture) {
6850
+ material.transmissionTexture = texture;
6851
+ });
6852
+ }
6853
+ };
6854
+ return KHR_materials_transmission;
6855
+ }(GLTFExtensionParser);
6856
+ KHR_materials_transmission = __decorate([
6857
+ registerGLTFExtension("KHR_materials_transmission", GLTFExtensionMode.AdditiveParse)
6858
+ ], KHR_materials_transmission);
6859
+
6799
6860
  var KHR_materials_unlit = /*#__PURE__*/ function(GLTFExtensionParser) {
6800
6861
  _inherits(KHR_materials_unlit, GLTFExtensionParser);
6801
6862
  function KHR_materials_unlit() {
@@ -6848,6 +6909,32 @@ KHR_materials_variants = __decorate([
6848
6909
  registerGLTFExtension("KHR_materials_variants", GLTFExtensionMode.AdditiveParse)
6849
6910
  ], KHR_materials_variants);
6850
6911
 
6912
+ var KHR_materials_volume = /*#__PURE__*/ function(GLTFExtensionParser) {
6913
+ _inherits(KHR_materials_volume, GLTFExtensionParser);
6914
+ function KHR_materials_volume() {
6915
+ return GLTFExtensionParser.apply(this, arguments) || this;
6916
+ }
6917
+ var _proto = KHR_materials_volume.prototype;
6918
+ _proto.additiveParse = function additiveParse(context, material, schema) {
6919
+ var _schema_thicknessFactor = schema.thicknessFactor, thicknessFactor = _schema_thicknessFactor === void 0 ? 0 : _schema_thicknessFactor, thicknessTexture = schema.thicknessTexture, _schema_attenuationDistance = schema.attenuationDistance, attenuationDistance = _schema_attenuationDistance === void 0 ? Infinity : _schema_attenuationDistance, attenuationColor = schema.attenuationColor;
6920
+ material.thickness = thicknessFactor;
6921
+ material.attenuationDistance = attenuationDistance;
6922
+ if (attenuationColor) {
6923
+ material.attenuationColor.set(engineMath.Color.linearToGammaSpace(attenuationColor[0]), engineMath.Color.linearToGammaSpace(attenuationColor[1]), engineMath.Color.linearToGammaSpace(attenuationColor[2]), undefined);
6924
+ }
6925
+ if (thicknessTexture) {
6926
+ exports.GLTFMaterialParser._checkOtherTextureTransform(thicknessTexture, "Thickness texture");
6927
+ context.get(GLTFParserType.Texture, thicknessTexture.index).then(function(texture) {
6928
+ material.thicknessTexture = texture;
6929
+ });
6930
+ }
6931
+ };
6932
+ return KHR_materials_volume;
6933
+ }(GLTFExtensionParser);
6934
+ KHR_materials_volume = __decorate([
6935
+ registerGLTFExtension("KHR_materials_volume", GLTFExtensionMode.AdditiveParse)
6936
+ ], KHR_materials_volume);
6937
+
6851
6938
  var KHR_mesh_quantization = /*#__PURE__*/ function(GLTFExtensionParser) {
6852
6939
  _inherits(KHR_mesh_quantization, GLTFExtensionParser);
6853
6940
  function KHR_mesh_quantization() {