@galacean/engine-loader 1.2.0-alpha.3 → 1.2.0-alpha.5

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
@@ -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,365 @@ 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
+ var _entityConfig_isActive;
984
+ entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
985
+ var _entityConfig_name;
986
+ entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
987
+ var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
988
+ if (position) entity.transform.position.copyFrom(position);
989
+ if (rotation) entity.transform.rotation.copyFrom(rotation);
990
+ if (scale) entity.transform.scale.copyFrom(scale);
991
+ return entity;
992
+ };
993
+ _proto._traverseAddEntityToMap = function _traverseAddEntityToMap(entity, context, path) {
994
+ var entityMap = context.entityMap, components = context.components;
995
+ entityMap.set(path, entity);
996
+ // @ts-ignore
997
+ entity._components.forEach(function(component) {
998
+ // @ts-ignore
999
+ var name = engineCore.Loader.getClassName(component.constructor);
1000
+ components.set(path + ":" + name, component);
1001
+ });
1002
+ for(var i = 0; i < entity.children.length; i++){
1003
+ var child = entity.children[i];
1004
+ var childPath = path ? path + "/" + child.name : child.name;
1005
+ this._traverseAddEntityToMap(child, context, childPath);
1006
+ }
1007
+ };
1008
+ return HierarchyParser;
690
1009
  }();
691
1010
 
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
- };
1011
+ var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
1012
+ _inherits(PrefabParser, HierarchyParser1);
1013
+ function PrefabParser() {
1014
+ return HierarchyParser1.apply(this, arguments);
1015
+ }
1016
+ var _proto = PrefabParser.prototype;
1017
+ _proto.handleRootEntity = function handleRootEntity(id) {
1018
+ this.context.target = this.context.entityMap.get(id);
1019
+ };
1020
+ /**
1021
+ * Parse prefab data.
1022
+ * @param engine - the engine of the parser context
1023
+ * @param prefabData - prefab data which is exported by editor
1024
+ * @returns a promise of prefab
1025
+ */ PrefabParser.parse = function parse(engine, prefabData) {
1026
+ var context = new PrefabParserContext(prefabData, engine);
1027
+ var parser = new PrefabParser(context);
1028
+ parser.start();
1029
+ return parser;
1030
+ };
1031
+ return PrefabParser;
1032
+ }(HierarchyParser);
706
1033
 
707
1034
  exports.InterpolableValueType = void 0;
708
1035
  (function(InterpolableValueType) {
@@ -736,7 +1063,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
736
1063
  for(var i1 = 0; i1 < curveBindingsLen; ++i1){
737
1064
  var relativePath = bufferReader.nextStr();
738
1065
  var componentStr = bufferReader.nextStr();
739
- var componentType = ComponentMap[componentStr];
1066
+ var componentType = engineCore.Loader.getClass(componentStr);
740
1067
  var property = bufferReader.nextStr();
741
1068
  var getProperty = bufferReader.nextStr();
742
1069
  var curve = void 0;
@@ -915,145 +1242,28 @@ exports.SpecularMode = void 0;
915
1242
  SpecularMode["Custom"] = "Custom";
916
1243
  })(exports.SpecularMode || (exports.SpecularMode = {}));
917
1244
 
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;
1245
+ var SceneParserContext = /*#__PURE__*/ function(ParserContext1) {
1246
+ _inherits(SceneParserContext, ParserContext1);
1247
+ function SceneParserContext(originalData, engine, scene) {
1248
+ var _this;
1249
+ _this = ParserContext1.call(this, originalData, engine, scene) || this;
1250
+ _this.originalData = originalData;
1251
+ _this.engine = engine;
1252
+ _this.scene = scene;
1253
+ return _this;
968
1254
  }
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
1255
  return SceneParserContext;
978
- }();
1256
+ }(ParserContext);
979
1257
 
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);
1258
+ /** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
1259
+ _inherits(SceneParser, HierarchyParser1);
1260
+ function SceneParser() {
1261
+ return HierarchyParser1.apply(this, arguments);
993
1262
  }
994
1263
  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;
1264
+ _proto.handleRootEntity = function handleRootEntity(id) {
1265
+ var _this_context = this.context, target = _this_context.target, entityMap = _this_context.entityMap;
1266
+ target.addRootEntity(entityMap.get(id));
1057
1267
  };
1058
1268
  /**
1059
1269
  * Parse scene data.
@@ -1062,13 +1272,13 @@ var SceneParserContext = /*#__PURE__*/ function() {
1062
1272
  * @returns a promise of scene
1063
1273
  */ SceneParser.parse = function parse(engine, sceneData) {
1064
1274
  var scene = new engineCore.Scene(engine);
1065
- var context = new SceneParserContext(sceneData, scene);
1275
+ var context = new SceneParserContext(sceneData, engine, scene);
1066
1276
  var parser = new SceneParser(context);
1067
1277
  parser.start();
1068
1278
  return parser.promise;
1069
1279
  };
1070
1280
  return SceneParser;
1071
- }();
1281
+ }(HierarchyParser);
1072
1282
 
1073
1283
  exports.MeshLoader = /*#__PURE__*/ function(Loader1) {
1074
1284
  _inherits(MeshLoader, Loader1);
@@ -1173,7 +1383,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
1173
1383
  resourceManager// @ts-ignore
1174
1384
  .getResourceByRef(value).then(function(asset) {
1175
1385
  keyframe.value = asset;
1176
- resolve(keyframe);
1386
+ resolve(keyframe.value);
1177
1387
  });
1178
1388
  });
1179
1389
  } else {
@@ -6535,12 +6745,12 @@ KHR_materials_anisotropy = __decorate([
6535
6745
  ], KHR_materials_anisotropy);
6536
6746
 
6537
6747
  exports.BufferInfo = BufferInfo;
6538
- exports.ComponentMap = ComponentMap;
6539
6748
  exports.GLTFExtensionParser = GLTFExtensionParser;
6540
6749
  exports.GLTFParser = GLTFParser;
6541
6750
  exports.GLTFParserContext = GLTFParserContext;
6542
6751
  exports.GLTFResource = GLTFResource;
6543
6752
  exports.GLTFUtils = GLTFUtils;
6753
+ exports.ParserContext = ParserContext;
6544
6754
  exports.PrefabParser = PrefabParser;
6545
6755
  exports.ReflectionParser = ReflectionParser;
6546
6756
  exports.SceneParser = SceneParser;