@galacean/engine-loader 1.2.0-alpha.1 → 1.2.0-alpha.10

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 (29) hide show
  1. package/dist/main.js +483 -219
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +483 -219
  4. package/dist/module.js +484 -220
  5. package/dist/module.js.map +1 -1
  6. package/package.json +4 -4
  7. package/types/PrimitiveMeshLoader.d.ts +1 -0
  8. package/types/gltf/GLTFUtils.d.ts +4 -3
  9. package/types/gltf/parser/GLTFJSONParser.d.ts +7 -0
  10. package/types/gltf/parser/GLTFSchemaParser.d.ts +0 -1
  11. package/types/index.d.ts +3 -2
  12. package/types/resource-deserialize/index.d.ts +2 -1
  13. package/types/resource-deserialize/resources/animationClip/AnimationClipDecoder.d.ts +0 -1
  14. package/types/resource-deserialize/resources/parser/HierarchyParser.d.ts +36 -0
  15. package/types/resource-deserialize/resources/parser/ParserContext.d.ts +29 -0
  16. package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +4 -4
  17. package/types/resource-deserialize/resources/prefab/PrefabParser.d.ts +13 -4
  18. package/types/resource-deserialize/resources/prefab/PrefabParserContext.d.ts +5 -0
  19. package/types/resource-deserialize/resources/scene/SceneParser.d.ts +3 -17
  20. package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +6 -12
  21. package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +24 -1
  22. package/types/resource-deserialize/resources/schema/SceneSchema.d.ts +1 -0
  23. package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +0 -13
  24. package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +0 -33
  25. package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +0 -17
  26. package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +0 -34
  27. package/types/ktx2/TranscodeResult.d.ts +0 -10
  28. package/types/ktx2/constants.d.ts +0 -7
  29. package/types/ktx2/zstddec.d.ts +0 -62
package/dist/main.js CHANGED
@@ -640,8 +640,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
640
640
  var assetRefId = entityConfig.assetRefId;
641
641
  var engine = this._context.engine;
642
642
  if (assetRefId) {
643
- return engine.resourceManager// @ts-ignore
644
- .getResourceByRef({
643
+ return engine.resourceManager.getResourceByRef({
645
644
  refId: assetRefId,
646
645
  key: entityConfig.key,
647
646
  isClone: entityConfig.isClone
@@ -672,37 +671,372 @@ var ReflectionParser = /*#__PURE__*/ function() {
672
671
  ReflectionParser.customParseComponentHandles = new Map();
673
672
  })();
674
673
 
675
- var PrefabParser = /*#__PURE__*/ function() {
676
- function PrefabParser() {}
677
- PrefabParser.parseChildren = function parseChildren(entitiesConfig, entities, parentId) {
678
- var children = entitiesConfig.get(parentId).children;
674
+ /**
675
+ * Parser context
676
+ * @export
677
+ * @abstract
678
+ * @class ParserContext
679
+ * @template T
680
+ * @template I
681
+ */ var ParserContext = /*#__PURE__*/ function() {
682
+ function ParserContext(originalData, engine, target) {
683
+ this.originalData = originalData;
684
+ this.engine = engine;
685
+ this.target = target;
686
+ this.entityMap = new Map();
687
+ this.components = new Map();
688
+ this.assets = new Map();
689
+ this.entityConfigMap = new Map();
690
+ this.rootIds = [];
691
+ this.strippedIds = [];
692
+ this.resourceManager = engine.resourceManager;
693
+ }
694
+ var _proto = ParserContext.prototype;
695
+ /**
696
+ * Destroy the context.
697
+ * @abstract
698
+ * @memberof ParserContext
699
+ */ _proto.destroy = function destroy() {
700
+ this.entityMap.clear();
701
+ this.components.clear();
702
+ this.assets.clear();
703
+ this.entityConfigMap.clear();
704
+ this.rootIds.length = 0;
705
+ };
706
+ return ParserContext;
707
+ }();
708
+
709
+ var PrefabParserContext = /*#__PURE__*/ function(ParserContext1) {
710
+ _inherits(PrefabParserContext, ParserContext1);
711
+ function PrefabParserContext() {
712
+ return ParserContext1.apply(this, arguments);
713
+ }
714
+ return PrefabParserContext;
715
+ }(ParserContext);
716
+
717
+ function _array_like_to_array(arr, len) {
718
+ if (len == null || len > arr.length) len = arr.length;
719
+
720
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
721
+
722
+ return arr2;
723
+ }
724
+
725
+ function _unsupported_iterable_to_array(o, minLen) {
726
+ if (!o) return;
727
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
728
+
729
+ var n = Object.prototype.toString.call(o).slice(8, -1);
730
+
731
+ if (n === "Object" && o.constructor) n = o.constructor.name;
732
+ if (n === "Map" || n === "Set") return Array.from(n);
733
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
734
+ }
735
+
736
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
737
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
738
+
739
+ if (it) return (it = it.call(o)).next.bind(it);
740
+ // Fallback for engines without symbol support
741
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
742
+ if (it) o = it;
743
+
744
+ var i = 0;
745
+
746
+ return function() {
747
+ if (i >= o.length) return { done: true };
748
+
749
+ return { done: false, value: o[i++] };
750
+ };
751
+ }
752
+
753
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
754
+ }
755
+
756
+ var HierarchyParser = /*#__PURE__*/ function() {
757
+ function HierarchyParser(context) {
758
+ var _this = this;
759
+ this.context = context;
760
+ this.prefabContextMap = new WeakMap();
761
+ this.prefabPromiseMap = new Map();
762
+ this._engine = this.context.engine;
763
+ this._organizeEntities = this._organizeEntities.bind(this);
764
+ this._parseComponents = this._parseComponents.bind(this);
765
+ this._parsePrefabModification = this._parsePrefabModification.bind(this);
766
+ this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
767
+ this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
768
+ this._clearAndResolve = this._clearAndResolve.bind(this);
769
+ this.promise = new Promise(function(resolve, reject) {
770
+ _this._reject = reject;
771
+ _this._resolve = resolve;
772
+ });
773
+ this._reflectionParser = new ReflectionParser(context);
774
+ }
775
+ var _proto = HierarchyParser.prototype;
776
+ /** start parse the scene or prefab or others */ _proto.start = function start() {
777
+ this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._parsePrefabModification).then(this._parsePrefabRemovedEntities).then(this._parsePrefabRemovedComponents).then(this._clearAndResolve).then(this._resolve).catch(this._reject);
778
+ };
779
+ _proto._parseEntities = function _parseEntities() {
780
+ var _this = this;
781
+ var entitiesConfig = this.context.originalData.entities;
782
+ var entityConfigMap = this.context.entityConfigMap;
783
+ var entityMap = this.context.entityMap;
784
+ var engine = this._engine;
785
+ var promises = entitiesConfig.map(function(entityConfig) {
786
+ var _entityConfig_strippedId;
787
+ var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
788
+ entityConfig.id = id;
789
+ entityConfigMap.set(id, entityConfig);
790
+ return _this._getEntityByConfig(entityConfig, engine);
791
+ });
792
+ return Promise.all(promises).then(function(entities) {
793
+ for(var i = 0, l = entities.length; i < l; i++){
794
+ entityMap.set(entitiesConfig[i].id, entities[i]);
795
+ }
796
+ return entities;
797
+ });
798
+ };
799
+ _proto._parseComponents = function _parseComponents() {
800
+ var entitiesConfig = this.context.originalData.entities;
801
+ var entityMap = this.context.entityMap;
802
+ var components = this.context.components;
803
+ var promises = [];
804
+ for(var i = 0, l = entitiesConfig.length; i < l; i++){
805
+ var entityConfig = entitiesConfig[i];
806
+ var entity = entityMap.get(entityConfig.id);
807
+ for(var i1 = 0; i1 < entityConfig.components.length; i1++){
808
+ var componentConfig = entityConfig.components[i1];
809
+ var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
810
+ var component = entity.addComponent(engineCore.Loader.getClass(key));
811
+ components.set(componentConfig.id, component);
812
+ var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
813
+ promises.push(promise);
814
+ }
815
+ }
816
+ return Promise.all(promises);
817
+ };
818
+ _proto._parsePrefabModification = function _parsePrefabModification() {
819
+ var _loop = function(i, l) {
820
+ var _modifications;
821
+ var entityConfig = entitiesConfig[i];
822
+ var id = entityConfig.id, modifications = entityConfig.modifications;
823
+ if ((_modifications = modifications) == null ? void 0 : _modifications.length) {
824
+ var _promises;
825
+ var rootEntity = entityMap.get(id);
826
+ (_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
827
+ var target = modification.target, props = modification.props, methods = modification.methods;
828
+ var entityId = target.entityId, componentId = target.componentId;
829
+ var context = _this.prefabContextMap.get(rootEntity);
830
+ var targetEntity = context.entityMap.get(entityId);
831
+ var targetComponent = context.components.get(componentId);
832
+ if (targetComponent) {
833
+ return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
834
+ props: props,
835
+ methods: methods
836
+ });
837
+ } else if (targetEntity) {
838
+ return Promise.resolve(_this._applyEntityData(targetEntity, props));
839
+ }
840
+ })));
841
+ }
842
+ };
843
+ var _this = this;
844
+ var entitiesConfig = this.context.originalData.entities;
845
+ var entityMap = this.context.entityMap;
846
+ var promises = [];
847
+ for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
848
+ return Promise.all(promises);
849
+ };
850
+ _proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
851
+ var _loop = function(i, l) {
852
+ var _removedEntities;
853
+ var entityConfig = entitiesConfig[i];
854
+ var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
855
+ if ((_removedEntities = removedEntities) == null ? void 0 : _removedEntities.length) {
856
+ var _promises;
857
+ var rootEntity = entityMap.get(id);
858
+ (_promises = promises).push.apply(_promises, [].concat(removedEntities.map(function(target) {
859
+ var entityId = target.entityId;
860
+ var context = _this.prefabContextMap.get(rootEntity);
861
+ var targetEntity = context.entityMap.get(entityId);
862
+ if (targetEntity) {
863
+ targetEntity.destroy();
864
+ }
865
+ })));
866
+ }
867
+ };
868
+ var _this = this;
869
+ var entitiesConfig = this.context.originalData.entities;
870
+ var entityMap = this.context.entityMap;
871
+ var promises = [];
872
+ for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
873
+ return Promise.all(promises);
874
+ };
875
+ _proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
876
+ var _loop = function(i, l) {
877
+ var _removedComponents;
878
+ var entityConfig = entitiesConfig[i];
879
+ var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
880
+ if ((_removedComponents = removedComponents) == null ? void 0 : _removedComponents.length) {
881
+ var _promises;
882
+ var rootEntity = entityMap.get(id);
883
+ (_promises = promises).concat.apply(_promises, [].concat(removedComponents.map(function(target) {
884
+ var componentId = target.componentId;
885
+ var context = _this.prefabContextMap.get(rootEntity);
886
+ var targetComponent = context.components.get(componentId);
887
+ if (targetComponent) {
888
+ targetComponent.destroy();
889
+ }
890
+ })));
891
+ }
892
+ };
893
+ var _this = this;
894
+ var entitiesConfig = this.context.originalData.entities;
895
+ var entityMap = this.context.entityMap;
896
+ var promises = [];
897
+ for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
898
+ return Promise.all(promises);
899
+ };
900
+ _proto._clearAndResolve = function _clearAndResolve() {
901
+ var target = this.context.target;
902
+ return target;
903
+ };
904
+ _proto._organizeEntities = function _organizeEntities() {
905
+ var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
906
+ var parentIds = rootIds.concat(strippedIds);
907
+ for(var _iterator = _create_for_of_iterator_helper_loose(parentIds), _step; !(_step = _iterator()).done;){
908
+ var parentId = _step.value;
909
+ this._parseChildren(parentId);
910
+ }
911
+ for(var i = 0; i < rootIds.length; i++){
912
+ this.handleRootEntity(rootIds[i]);
913
+ }
914
+ };
915
+ _proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
916
+ var _this = this;
917
+ var entityPromise;
918
+ if (entityConfig.assetRefId) {
919
+ entityPromise = this._parseGLTF(entityConfig, engine);
920
+ } else if (entityConfig.strippedId) {
921
+ entityPromise = this._parseStrippedEntity(entityConfig);
922
+ } else {
923
+ entityPromise = this._parseEntity(entityConfig, engine);
924
+ }
925
+ return entityPromise.then(function(entity) {
926
+ return _this._applyEntityData(entity, entityConfig);
927
+ });
928
+ };
929
+ _proto._parseEntity = function _parseEntity(entityConfig, engine) {
930
+ var entity = new engineCore.Entity(engine, entityConfig.name);
931
+ if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
932
+ return Promise.resolve(entity);
933
+ };
934
+ _proto._parseGLTF = function _parseGLTF(entityConfig, engine) {
935
+ var _this = this;
936
+ var assetRefId = entityConfig.assetRefId;
937
+ var context = new ParserContext(null, engine);
938
+ return engine.resourceManager// @ts-ignore
939
+ .getResourceByRef({
940
+ refId: assetRefId
941
+ }).then(function(glTFResource) {
942
+ var entity = glTFResource.instantiateSceneRoot();
943
+ if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
944
+ _this._traverseAddEntityToMap(entity, context, "");
945
+ _this.prefabContextMap.set(entity, context);
946
+ var cbArray = _this.prefabPromiseMap.get(entityConfig.id);
947
+ cbArray && cbArray.forEach(function(cb) {
948
+ cb.resolve(context);
949
+ });
950
+ return entity;
951
+ });
952
+ };
953
+ _proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
954
+ var _this = this;
955
+ this.context.strippedIds.push(entityConfig.id);
956
+ return new Promise(function(resolve, reject) {
957
+ var _this_prefabPromiseMap_get;
958
+ var cbArray = (_this_prefabPromiseMap_get = _this.prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this_prefabPromiseMap_get : [];
959
+ cbArray.push({
960
+ resolve: resolve,
961
+ reject: reject
962
+ });
963
+ _this.prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
964
+ }).then(function(context) {
965
+ var entityId = entityConfig.prefabSource.entityId;
966
+ return context.entityMap.get(entityId);
967
+ });
968
+ };
969
+ _proto._parseChildren = function _parseChildren(parentId) {
970
+ var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
971
+ var children = entityConfigMap.get(parentId).children;
679
972
  if (children && children.length > 0) {
680
- var parent = entities.get(parentId);
973
+ var parent = entityMap.get(parentId);
681
974
  for(var i = 0; i < children.length; i++){
682
975
  var childId = children[i];
683
- var entity = entities.get(childId);
976
+ var entity = entityMap.get(childId);
684
977
  parent.addChild(entity);
685
- this.parseChildren(entitiesConfig, entities, childId);
978
+ this._parseChildren(childId);
686
979
  }
687
980
  }
688
981
  };
689
- return PrefabParser;
982
+ _proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
983
+ if (entityConfig === void 0) entityConfig = {};
984
+ var _entityConfig_isActive;
985
+ entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
986
+ var _entityConfig_name;
987
+ entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
988
+ var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
989
+ if (position) entity.transform.position.copyFrom(position);
990
+ if (rotation) entity.transform.rotation.copyFrom(rotation);
991
+ if (scale) entity.transform.scale.copyFrom(scale);
992
+ return entity;
993
+ };
994
+ _proto._traverseAddEntityToMap = function _traverseAddEntityToMap(entity, context, path) {
995
+ var entityMap = context.entityMap, components = context.components;
996
+ var componentsMap = {};
997
+ var componentIndexMap = {};
998
+ entityMap.set(path, entity);
999
+ // @ts-ignore
1000
+ entity._components.forEach(function(component) {
1001
+ // @ts-ignore
1002
+ var name = engineCore.Loader.getClassName(component.constructor);
1003
+ if (!componentsMap[name]) {
1004
+ componentsMap[name] = entity.getComponents(component.constructor, []);
1005
+ componentIndexMap[name] = 0;
1006
+ }
1007
+ components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
1008
+ });
1009
+ for(var i = 0, n = entity.children.length; i < n; i++){
1010
+ var child = entity.children[i];
1011
+ var childPath = path ? path + "/" + i : "" + i;
1012
+ this._traverseAddEntityToMap(child, context, childPath);
1013
+ }
1014
+ };
1015
+ return HierarchyParser;
690
1016
  }();
691
1017
 
692
- var ComponentMap = {
693
- Transform: engineCore.Transform,
694
- Animator: engineCore.Animator,
695
- DirectLight: engineCore.DirectLight,
696
- Camera: engineCore.Camera,
697
- MeshRenderer: engineCore.MeshRenderer,
698
- ParticleRenderer: engineCore.ParticleRenderer,
699
- PointLight: engineCore.PointLight,
700
- SpotLight: engineCore.SpotLight,
701
- Script: engineCore.Script,
702
- SpriteMask: engineCore.SpriteMask,
703
- SpriteRenderer: engineCore.SpriteRenderer,
704
- TextRenderer: engineCore.TextRenderer
705
- };
1018
+ var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
1019
+ _inherits(PrefabParser, HierarchyParser1);
1020
+ function PrefabParser() {
1021
+ return HierarchyParser1.apply(this, arguments);
1022
+ }
1023
+ var _proto = PrefabParser.prototype;
1024
+ _proto.handleRootEntity = function handleRootEntity(id) {
1025
+ this.context.target = this.context.entityMap.get(id);
1026
+ };
1027
+ /**
1028
+ * Parse prefab data.
1029
+ * @param engine - the engine of the parser context
1030
+ * @param prefabData - prefab data which is exported by editor
1031
+ * @returns a promise of prefab
1032
+ */ PrefabParser.parse = function parse(engine, prefabData) {
1033
+ var context = new PrefabParserContext(prefabData, engine);
1034
+ var parser = new PrefabParser(context);
1035
+ parser.start();
1036
+ return parser;
1037
+ };
1038
+ return PrefabParser;
1039
+ }(HierarchyParser);
706
1040
 
707
1041
  exports.InterpolableValueType = void 0;
708
1042
  (function(InterpolableValueType) {
@@ -736,7 +1070,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
736
1070
  for(var i1 = 0; i1 < curveBindingsLen; ++i1){
737
1071
  var relativePath = bufferReader.nextStr();
738
1072
  var componentStr = bufferReader.nextStr();
739
- var componentType = ComponentMap[componentStr];
1073
+ var componentType = engineCore.Loader.getClass(componentStr);
740
1074
  var property = bufferReader.nextStr();
741
1075
  var getProperty = bufferReader.nextStr();
742
1076
  var curve = void 0;
@@ -915,145 +1249,28 @@ exports.SpecularMode = void 0;
915
1249
  SpecularMode["Custom"] = "Custom";
916
1250
  })(exports.SpecularMode || (exports.SpecularMode = {}));
917
1251
 
918
- function _array_like_to_array(arr, len) {
919
- if (len == null || len > arr.length) len = arr.length;
920
-
921
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
922
-
923
- return arr2;
924
- }
925
-
926
- function _unsupported_iterable_to_array(o, minLen) {
927
- if (!o) return;
928
- if (typeof o === "string") return _array_like_to_array(o, minLen);
929
-
930
- var n = Object.prototype.toString.call(o).slice(8, -1);
931
-
932
- if (n === "Object" && o.constructor) n = o.constructor.name;
933
- if (n === "Map" || n === "Set") return Array.from(n);
934
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
935
- }
936
-
937
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
938
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
939
-
940
- if (it) return (it = it.call(o)).next.bind(it);
941
- // Fallback for engines without symbol support
942
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
943
- if (it) o = it;
944
-
945
- var i = 0;
946
-
947
- return function() {
948
- if (i >= o.length) return { done: true };
949
-
950
- return { done: false, value: o[i++] };
951
- };
952
- }
953
-
954
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
955
- }
956
-
957
- var SceneParserContext = /*#__PURE__*/ function() {
958
- function SceneParserContext(originalData, scene) {
959
- this.originalData = originalData;
960
- this.scene = scene;
961
- this.entityMap = new Map();
962
- this.components = new Map();
963
- this.assets = new Map();
964
- this.entityConfigMap = new Map();
965
- this.rootIds = [];
966
- this.engine = scene.engine;
967
- this.resourceManager = scene.engine.resourceManager;
1252
+ var SceneParserContext = /*#__PURE__*/ function(ParserContext1) {
1253
+ _inherits(SceneParserContext, ParserContext1);
1254
+ function SceneParserContext(originalData, engine, scene) {
1255
+ var _this;
1256
+ _this = ParserContext1.call(this, originalData, engine, scene) || this;
1257
+ _this.originalData = originalData;
1258
+ _this.engine = engine;
1259
+ _this.scene = scene;
1260
+ return _this;
968
1261
  }
969
- var _proto = SceneParserContext.prototype;
970
- _proto.destroy = function destroy() {
971
- this.entityMap.clear();
972
- this.components.clear();
973
- this.assets.clear();
974
- this.entityConfigMap.clear();
975
- this.rootIds.length = 0;
976
- };
977
1262
  return SceneParserContext;
978
- }();
1263
+ }(ParserContext);
979
1264
 
980
- /** @Internal */ var SceneParser = /*#__PURE__*/ function() {
981
- function SceneParser(context) {
982
- var _this = this;
983
- this.context = context;
984
- this._engine = context.scene.engine;
985
- this._organizeEntities = this._organizeEntities.bind(this);
986
- this._parseComponents = this._parseComponents.bind(this);
987
- this._clearAndResolveScene = this._clearAndResolveScene.bind(this);
988
- this.promise = new Promise(function(resolve, reject) {
989
- _this._reject = reject;
990
- _this._resolve = resolve;
991
- });
992
- this._reflectionParser = new ReflectionParser(context);
1265
+ /** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
1266
+ _inherits(SceneParser, HierarchyParser1);
1267
+ function SceneParser() {
1268
+ return HierarchyParser1.apply(this, arguments);
993
1269
  }
994
1270
  var _proto = SceneParser.prototype;
995
- /** start parse the scene */ _proto.start = function start() {
996
- this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._clearAndResolveScene).then(this._resolve).catch(this._reject);
997
- };
998
- _proto._parseEntities = function _parseEntities() {
999
- var _this = this;
1000
- var entitiesConfig = this.context.originalData.entities;
1001
- var entityConfigMap = this.context.entityConfigMap;
1002
- var entitiesMap = this.context.entityMap;
1003
- var rootIds = this.context.rootIds;
1004
- this._engine;
1005
- var promises = entitiesConfig.map(function(entityConfig) {
1006
- entityConfigMap.set(entityConfig.id, entityConfig);
1007
- // record root entities
1008
- if (!entityConfig.parent) rootIds.push(entityConfig.id);
1009
- return _this._reflectionParser.parseEntity(entityConfig);
1010
- });
1011
- return Promise.all(promises).then(function(entities) {
1012
- for(var i = 0, l = entities.length; i < l; i++){
1013
- entitiesMap.set(entitiesConfig[i].id, entities[i]);
1014
- }
1015
- return entities;
1016
- });
1017
- };
1018
- _proto._organizeEntities = function _organizeEntities() {
1019
- var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
1020
- for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
1021
- var rootId = _step.value;
1022
- PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
1023
- }
1024
- var rootEntities = rootIds.map(function(id) {
1025
- return entityMap.get(id);
1026
- });
1027
- for(var i = 0; i < rootEntities.length; i++){
1028
- scene.addRootEntity(rootEntities[i]);
1029
- }
1030
- };
1031
- _proto._parseComponents = function _parseComponents() {
1032
- var entitiesConfig = this.context.originalData.entities;
1033
- var entityMap = this.context.entityMap;
1034
- var promises = [];
1035
- for(var i = 0, l = entitiesConfig.length; i < l; i++){
1036
- var entityConfig = entitiesConfig[i];
1037
- var entity = entityMap.get(entityConfig.id);
1038
- for(var i1 = 0; i1 < entityConfig.components.length; i1++){
1039
- var componentConfig = entityConfig.components[i1];
1040
- var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
1041
- var component = void 0;
1042
- // TODO: remove hack code when support additional edit
1043
- if (key === "Animator") {
1044
- component = entity.getComponent(engineCore.Loader.getClass(key));
1045
- }
1046
- component = component || entity.addComponent(engineCore.Loader.getClass(key));
1047
- var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
1048
- promises.push(promise);
1049
- }
1050
- }
1051
- return Promise.all(promises);
1052
- };
1053
- _proto._clearAndResolveScene = function _clearAndResolveScene() {
1054
- var scene = this.context.scene;
1055
- this.context.destroy();
1056
- return scene;
1271
+ _proto.handleRootEntity = function handleRootEntity(id) {
1272
+ var _this_context = this.context, target = _this_context.target, entityMap = _this_context.entityMap;
1273
+ target.addRootEntity(entityMap.get(id));
1057
1274
  };
1058
1275
  /**
1059
1276
  * Parse scene data.
@@ -1062,13 +1279,13 @@ var SceneParserContext = /*#__PURE__*/ function() {
1062
1279
  * @returns a promise of scene
1063
1280
  */ SceneParser.parse = function parse(engine, sceneData) {
1064
1281
  var scene = new engineCore.Scene(engine);
1065
- var context = new SceneParserContext(sceneData, scene);
1282
+ var context = new SceneParserContext(sceneData, engine, scene);
1066
1283
  var parser = new SceneParser(context);
1067
1284
  parser.start();
1068
1285
  return parser.promise;
1069
1286
  };
1070
1287
  return SceneParser;
1071
- }();
1288
+ }(HierarchyParser);
1072
1289
 
1073
1290
  exports.MeshLoader = /*#__PURE__*/ function(Loader1) {
1074
1291
  _inherits(MeshLoader, Loader1);
@@ -1173,7 +1390,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
1173
1390
  resourceManager// @ts-ignore
1174
1391
  .getResourceByRef(value).then(function(asset) {
1175
1392
  keyframe.value = asset;
1176
- resolve(keyframe);
1393
+ resolve(keyframe.value);
1177
1394
  });
1178
1395
  });
1179
1396
  } else {
@@ -2185,7 +2402,7 @@ function registerGLTFParser(pipeline) {
2185
2402
  };
2186
2403
  /**
2187
2404
  * Parse the glb format.
2188
- */ GLTFUtils.parseGLB = function parseGLB(context, glb) {
2405
+ */ GLTFUtils.parseGLB = function parseGLB(context, originBuffer) {
2189
2406
  var UINT32_LENGTH = 4;
2190
2407
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
2191
2408
  var GLB_HEADER_LENGTH = 12;
@@ -2193,7 +2410,7 @@ function registerGLTFParser(pipeline) {
2193
2410
  JSON: 0x4e4f534a,
2194
2411
  BIN: 0x004e4942
2195
2412
  };
2196
- var dataView = new DataView(glb);
2413
+ var dataView = new DataView(originBuffer);
2197
2414
  // read header
2198
2415
  var header = {
2199
2416
  magic: dataView.getUint32(0, true),
@@ -2201,8 +2418,9 @@ function registerGLTFParser(pipeline) {
2201
2418
  length: dataView.getUint32(2 * UINT32_LENGTH, true)
2202
2419
  };
2203
2420
  if (header.magic !== GLB_HEADER_MAGIC) {
2204
- console.error("Invalid glb magic number. Expected 0x46546C67, found 0x" + header.magic.toString(16));
2205
- return null;
2421
+ return {
2422
+ originBuffer: originBuffer
2423
+ };
2206
2424
  }
2207
2425
  // read main data
2208
2426
  var chunkLength = dataView.getUint32(GLB_HEADER_LENGTH, true);
@@ -2212,7 +2430,7 @@ function registerGLTFParser(pipeline) {
2212
2430
  console.error("Invalid glb chunk type. Expected 0x4E4F534A, found 0x" + chunkType.toString(16));
2213
2431
  return null;
2214
2432
  }
2215
- var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2433
+ var glTFData = new Uint8Array(originBuffer, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2216
2434
  var glTF = JSON.parse(engineCore.Utils.decodeText(glTFData));
2217
2435
  // read all buffers
2218
2436
  var buffers = [];
@@ -2226,7 +2444,7 @@ function registerGLTFParser(pipeline) {
2226
2444
  return null;
2227
2445
  }
2228
2446
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
2229
- var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
2447
+ var buffer = originBuffer.slice(currentOffset, currentOffset + chunkLength);
2230
2448
  buffers.push(buffer);
2231
2449
  restoreGLBBufferSlice.push(new engineMath.Vector2(currentOffset, chunkLength));
2232
2450
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
@@ -3640,23 +3858,20 @@ exports.GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3640
3858
  var requestConfig = {
3641
3859
  type: "arraybuffer"
3642
3860
  };
3643
- var isGLB = this._isGLB(url);
3644
- contentRestorer.isGLB = isGLB;
3645
- var promise = isGLB ? engineCore.request(url, requestConfig).onProgress(undefined, context._onTaskDetail).then(function(glb) {
3861
+ return engineCore.request(url, requestConfig).onProgress(undefined, context._onTaskDetail).then(function(buffer) {
3646
3862
  restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3647
- return GLTFUtils.parseGLB(context, glb);
3648
- }).then(function(param) {
3649
- var glTF = param.glTF, buffers = param.buffers;
3650
- context.buffers = buffers;
3651
- return glTF;
3652
- }) : engineCore.request(url, {
3653
- type: "json"
3654
- }).onProgress(undefined, context._onTaskDetail);
3655
- return promise;
3656
- };
3657
- _proto._isGLB = function _isGLB(url) {
3658
- var index = url.lastIndexOf(".");
3659
- return url.substring(index + 1, index + 4) === "glb";
3863
+ return GLTFUtils.parseGLB(context, buffer);
3864
+ }).then(function(result) {
3865
+ var _result;
3866
+ if ((_result = result) == null ? void 0 : _result.glTF) {
3867
+ contentRestorer.isGLB = true;
3868
+ context.buffers = result.buffers;
3869
+ return result.glTF;
3870
+ } else {
3871
+ contentRestorer.isGLB = false;
3872
+ return JSON.parse(engineCore.Utils.decodeText(new Uint8Array(result.originBuffer)));
3873
+ }
3874
+ });
3660
3875
  };
3661
3876
  return GLTFSchemaParser;
3662
3877
  }(GLTFParser);
@@ -5628,6 +5843,86 @@ MeshLoader = __decorate([
5628
5843
  ])
5629
5844
  ], MeshLoader);
5630
5845
 
5846
+ var PrimitiveMeshLoader = /*#__PURE__*/ function(Loader1) {
5847
+ _inherits(PrimitiveMeshLoader, Loader1);
5848
+ function PrimitiveMeshLoader() {
5849
+ return Loader1.apply(this, arguments);
5850
+ }
5851
+ var _proto = PrimitiveMeshLoader.prototype;
5852
+ _proto.load = function load(item, param) {
5853
+ var engine = param.engine;
5854
+ return this.request(item.url, _extends({}, item, {
5855
+ type: "json"
5856
+ })).then(function(data) {
5857
+ switch(data.type){
5858
+ case "sphere":
5859
+ return engineCore.PrimitiveMesh.createSubdivisionSurfaceSphere(engine, data.sphereRadius, data.sphereStep);
5860
+ case "capsule":
5861
+ return engineCore.PrimitiveMesh.createCapsule(engine, data.capsuleRadius, data.capsuleHeight, data.capsuleRadialSegments, data.capsuleHeightSegments);
5862
+ case "cone":
5863
+ return engineCore.PrimitiveMesh.createCone(engine, data.coneRadius, data.coneHeight, data.coneRadialSegment, data.coneHeightSegment);
5864
+ case "cuboid":
5865
+ return engineCore.PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth);
5866
+ case "cylinder":
5867
+ return engineCore.PrimitiveMesh.createCylinder(engine, data.cylinderRadiusTop, data.cylinderRadiusBottom, data.cylinderHeight, data.cylinderRadialSegment, data.cylinderHeightSegment);
5868
+ case "plane":
5869
+ return engineCore.PrimitiveMesh.createPlane(engine, data.planeWidth, data.planeHeight, data.planeHorizontalSegments, data.planeVerticalSegments);
5870
+ case "torus":
5871
+ return engineCore.PrimitiveMesh.createTorus(engine, data.torusRadius, data.torusTubeRadius, data.torusRadialSegments, data.torusTubularSegments, data.torusArc);
5872
+ }
5873
+ });
5874
+ };
5875
+ return PrimitiveMeshLoader;
5876
+ }(engineCore.Loader);
5877
+ PrimitiveMeshLoader = __decorate([
5878
+ engineCore.resourceLoader(engineCore.AssetType.PrimitiveMesh, [
5879
+ "mesh"
5880
+ ], false)
5881
+ ], PrimitiveMeshLoader);
5882
+ var /** @internal */ PrimitiveMeshType;
5883
+ (function(PrimitiveMeshType) {
5884
+ PrimitiveMeshType["Sphere"] = "sphere";
5885
+ PrimitiveMeshType["Cuboid"] = "cuboid";
5886
+ PrimitiveMeshType["Plane"] = "plane";
5887
+ PrimitiveMeshType["Cylinder"] = "cylinder";
5888
+ PrimitiveMeshType["Torus"] = "torus";
5889
+ PrimitiveMeshType["Cone"] = "cone";
5890
+ PrimitiveMeshType["Capsule"] = "capsule";
5891
+ })(PrimitiveMeshType || (PrimitiveMeshType = {}));
5892
+
5893
+ var ProjectLoader = /*#__PURE__*/ function(Loader1) {
5894
+ _inherits(ProjectLoader, Loader1);
5895
+ function ProjectLoader() {
5896
+ return Loader1.apply(this, arguments);
5897
+ }
5898
+ var _proto = ProjectLoader.prototype;
5899
+ _proto.load = function load(item, resourceManager) {
5900
+ var _this = this;
5901
+ var engine = resourceManager.engine;
5902
+ return new engineCore.AssetPromise(function(resolve, reject) {
5903
+ _this.request(item.url, {
5904
+ type: "json"
5905
+ }).then(function(data) {
5906
+ // @ts-ignore
5907
+ engine.resourceManager.initVirtualResources(data.files);
5908
+ return resourceManager.load({
5909
+ type: engineCore.AssetType.Scene,
5910
+ url: data.scene
5911
+ }).then(function(scene) {
5912
+ engine.sceneManager.activeScene = scene;
5913
+ resolve();
5914
+ });
5915
+ }).catch(reject);
5916
+ });
5917
+ };
5918
+ return ProjectLoader;
5919
+ }(engineCore.Loader);
5920
+ ProjectLoader = __decorate([
5921
+ engineCore.resourceLoader(engineCore.AssetType.Project, [
5922
+ "proj"
5923
+ ], false)
5924
+ ], ProjectLoader);
5925
+
5631
5926
  var SourceFontLoader = /*#__PURE__*/ function(Loader1) {
5632
5927
  _inherits(SourceFontLoader, Loader1);
5633
5928
  function SourceFontLoader() {
@@ -5963,39 +6258,6 @@ TextureCubeLoader = __decorate([
5963
6258
  ])
5964
6259
  ], TextureCubeLoader);
5965
6260
 
5966
- var ProjectLoader = /*#__PURE__*/ function(Loader1) {
5967
- _inherits(ProjectLoader, Loader1);
5968
- function ProjectLoader() {
5969
- return Loader1.apply(this, arguments);
5970
- }
5971
- var _proto = ProjectLoader.prototype;
5972
- _proto.load = function load(item, resourceManager) {
5973
- var _this = this;
5974
- var engine = resourceManager.engine;
5975
- return new engineCore.AssetPromise(function(resolve, reject) {
5976
- _this.request(item.url, {
5977
- type: "json"
5978
- }).then(function(data) {
5979
- // @ts-ignore
5980
- engine.resourceManager.initVirtualResources(data.files);
5981
- return resourceManager.load({
5982
- type: engineCore.AssetType.Scene,
5983
- url: data.scene
5984
- }).then(function(scene) {
5985
- engine.sceneManager.activeScene = scene;
5986
- resolve();
5987
- });
5988
- }).catch(reject);
5989
- });
5990
- };
5991
- return ProjectLoader;
5992
- }(engineCore.Loader);
5993
- ProjectLoader = __decorate([
5994
- engineCore.resourceLoader(engineCore.AssetType.Project, [
5995
- "proj"
5996
- ], false)
5997
- ], ProjectLoader);
5998
-
5999
6261
  var SceneLoader = /*#__PURE__*/ function(Loader1) {
6000
6262
  _inherits(SceneLoader, Loader1);
6001
6263
  function SceneLoader() {
@@ -6014,7 +6276,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
6014
6276
  // parse ambient light
6015
6277
  var ambient = data.scene.ambient;
6016
6278
  if (ambient) {
6017
- var useCustomAmbient = ambient.specularMode === "Custom";
6279
+ var useCustomAmbient = ambient.specularMode === exports.SpecularMode.Custom;
6018
6280
  var useSH = ambient.diffuseMode === engineCore.DiffuseMode.SphericalHarmonics;
6019
6281
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
6020
6282
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
@@ -6085,6 +6347,8 @@ var SceneLoader = /*#__PURE__*/ function(Loader1) {
6085
6347
  var _shadow_shadowTwoCascadeSplits;
6086
6348
  scene.shadowTwoCascadeSplits = (_shadow_shadowTwoCascadeSplits = shadow.shadowTwoCascadeSplits) != null ? _shadow_shadowTwoCascadeSplits : scene.shadowTwoCascadeSplits;
6087
6349
  shadow.shadowFourCascadeSplits && scene.shadowFourCascadeSplits.copyFrom(shadow.shadowFourCascadeSplits);
6350
+ var _shadow_shadowFadeBorder;
6351
+ scene.shadowFadeBorder = (_shadow_shadowFadeBorder = shadow.shadowFadeBorder) != null ? _shadow_shadowFadeBorder : scene.shadowFadeBorder;
6088
6352
  }
6089
6353
  return Promise.all(promises).then(function() {
6090
6354
  resolve(scene);
@@ -6488,12 +6752,12 @@ KHR_materials_anisotropy = __decorate([
6488
6752
  ], KHR_materials_anisotropy);
6489
6753
 
6490
6754
  exports.BufferInfo = BufferInfo;
6491
- exports.ComponentMap = ComponentMap;
6492
6755
  exports.GLTFExtensionParser = GLTFExtensionParser;
6493
6756
  exports.GLTFParser = GLTFParser;
6494
6757
  exports.GLTFParserContext = GLTFParserContext;
6495
6758
  exports.GLTFResource = GLTFResource;
6496
6759
  exports.GLTFUtils = GLTFUtils;
6760
+ exports.ParserContext = ParserContext;
6497
6761
  exports.PrefabParser = PrefabParser;
6498
6762
  exports.ReflectionParser = ReflectionParser;
6499
6763
  exports.SceneParser = SceneParser;