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

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.
@@ -641,8 +641,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
641
641
  var assetRefId = entityConfig.assetRefId;
642
642
  var engine = this._context.engine;
643
643
  if (assetRefId) {
644
- return engine.resourceManager// @ts-ignore
645
- .getResourceByRef({
644
+ return engine.resourceManager.getResourceByRef({
646
645
  refId: assetRefId,
647
646
  key: entityConfig.key,
648
647
  isClone: entityConfig.isClone
@@ -673,37 +672,365 @@ var ReflectionParser = /*#__PURE__*/ function() {
673
672
  ReflectionParser.customParseComponentHandles = new Map();
674
673
  })();
675
674
 
676
- var PrefabParser = /*#__PURE__*/ function() {
677
- function PrefabParser() {}
678
- PrefabParser.parseChildren = function parseChildren(entitiesConfig, entities, parentId) {
679
- var children = entitiesConfig.get(parentId).children;
675
+ /**
676
+ * Parser context
677
+ * @export
678
+ * @abstract
679
+ * @class ParserContext
680
+ * @template T
681
+ * @template I
682
+ */ var ParserContext = /*#__PURE__*/ function() {
683
+ function ParserContext(originalData, engine, target) {
684
+ this.originalData = originalData;
685
+ this.engine = engine;
686
+ this.target = target;
687
+ this.entityMap = new Map();
688
+ this.components = new Map();
689
+ this.assets = new Map();
690
+ this.entityConfigMap = new Map();
691
+ this.rootIds = [];
692
+ this.strippedIds = [];
693
+ this.resourceManager = engine.resourceManager;
694
+ }
695
+ var _proto = ParserContext.prototype;
696
+ /**
697
+ * Destroy the context.
698
+ * @abstract
699
+ * @memberof ParserContext
700
+ */ _proto.destroy = function destroy() {
701
+ this.entityMap.clear();
702
+ this.components.clear();
703
+ this.assets.clear();
704
+ this.entityConfigMap.clear();
705
+ this.rootIds.length = 0;
706
+ };
707
+ return ParserContext;
708
+ }();
709
+
710
+ var PrefabParserContext = /*#__PURE__*/ function(ParserContext1) {
711
+ _inherits(PrefabParserContext, ParserContext1);
712
+ function PrefabParserContext() {
713
+ return ParserContext1.apply(this, arguments);
714
+ }
715
+ return PrefabParserContext;
716
+ }(ParserContext);
717
+
718
+ function _array_like_to_array(arr, len) {
719
+ if (len == null || len > arr.length) len = arr.length;
720
+
721
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
722
+
723
+ return arr2;
724
+ }
725
+
726
+ function _unsupported_iterable_to_array(o, minLen) {
727
+ if (!o) return;
728
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
729
+
730
+ var n = Object.prototype.toString.call(o).slice(8, -1);
731
+
732
+ if (n === "Object" && o.constructor) n = o.constructor.name;
733
+ if (n === "Map" || n === "Set") return Array.from(n);
734
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
735
+ }
736
+
737
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
738
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
739
+
740
+ if (it) return (it = it.call(o)).next.bind(it);
741
+ // Fallback for engines without symbol support
742
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
743
+ if (it) o = it;
744
+
745
+ var i = 0;
746
+
747
+ return function() {
748
+ if (i >= o.length) return { done: true };
749
+
750
+ return { done: false, value: o[i++] };
751
+ };
752
+ }
753
+
754
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
755
+ }
756
+
757
+ var HierarchyParser = /*#__PURE__*/ function() {
758
+ function HierarchyParser(context) {
759
+ var _this = this;
760
+ this.context = context;
761
+ this.prefabContextMap = new WeakMap();
762
+ this.prefabPromiseMap = new Map();
763
+ this._engine = this.context.engine;
764
+ this._organizeEntities = this._organizeEntities.bind(this);
765
+ this._parseComponents = this._parseComponents.bind(this);
766
+ this._parsePrefabModification = this._parsePrefabModification.bind(this);
767
+ this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
768
+ this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
769
+ this._clearAndResolve = this._clearAndResolve.bind(this);
770
+ this.promise = new Promise(function(resolve, reject) {
771
+ _this._reject = reject;
772
+ _this._resolve = resolve;
773
+ });
774
+ this._reflectionParser = new ReflectionParser(context);
775
+ }
776
+ var _proto = HierarchyParser.prototype;
777
+ /** start parse the scene or prefab or others */ _proto.start = function start() {
778
+ 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);
779
+ };
780
+ _proto._parseEntities = function _parseEntities() {
781
+ var _this = this;
782
+ var entitiesConfig = this.context.originalData.entities;
783
+ var entityConfigMap = this.context.entityConfigMap;
784
+ var entityMap = this.context.entityMap;
785
+ var engine = this._engine;
786
+ var promises = entitiesConfig.map(function(entityConfig) {
787
+ var _entityConfig_strippedId;
788
+ var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
789
+ entityConfig.id = id;
790
+ entityConfigMap.set(id, entityConfig);
791
+ return _this._getEntityByConfig(entityConfig, engine);
792
+ });
793
+ return Promise.all(promises).then(function(entities) {
794
+ for(var i = 0, l = entities.length; i < l; i++){
795
+ entityMap.set(entitiesConfig[i].id, entities[i]);
796
+ }
797
+ return entities;
798
+ });
799
+ };
800
+ _proto._parseComponents = function _parseComponents() {
801
+ var entitiesConfig = this.context.originalData.entities;
802
+ var entityMap = this.context.entityMap;
803
+ var components = this.context.components;
804
+ var promises = [];
805
+ for(var i = 0, l = entitiesConfig.length; i < l; i++){
806
+ var entityConfig = entitiesConfig[i];
807
+ var entity = entityMap.get(entityConfig.id);
808
+ for(var i1 = 0; i1 < entityConfig.components.length; i1++){
809
+ var componentConfig = entityConfig.components[i1];
810
+ var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
811
+ var component = entity.addComponent(miniprogram.Loader.getClass(key));
812
+ components.set(componentConfig.id, component);
813
+ var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
814
+ promises.push(promise);
815
+ }
816
+ }
817
+ return Promise.all(promises);
818
+ };
819
+ _proto._parsePrefabModification = function _parsePrefabModification() {
820
+ var _loop = function(i, l) {
821
+ var _modifications;
822
+ var entityConfig = entitiesConfig[i];
823
+ var id = entityConfig.id, modifications = entityConfig.modifications;
824
+ if ((_modifications = modifications) == null ? void 0 : _modifications.length) {
825
+ var _promises;
826
+ var rootEntity = entityMap.get(id);
827
+ (_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
828
+ var target = modification.target, props = modification.props, methods = modification.methods;
829
+ var entityId = target.entityId, componentId = target.componentId;
830
+ var context = _this.prefabContextMap.get(rootEntity);
831
+ var targetEntity = context.entityMap.get(entityId);
832
+ var targetComponent = context.components.get(componentId);
833
+ if (targetComponent) {
834
+ return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
835
+ props: props,
836
+ methods: methods
837
+ });
838
+ } else if (targetEntity) {
839
+ return Promise.resolve(_this._applyEntityData(targetEntity, props));
840
+ }
841
+ })));
842
+ }
843
+ };
844
+ var _this = this;
845
+ var entitiesConfig = this.context.originalData.entities;
846
+ var entityMap = this.context.entityMap;
847
+ var promises = [];
848
+ for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
849
+ return Promise.all(promises);
850
+ };
851
+ _proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
852
+ var _loop = function(i, l) {
853
+ var _removedEntities;
854
+ var entityConfig = entitiesConfig[i];
855
+ var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
856
+ if ((_removedEntities = removedEntities) == null ? void 0 : _removedEntities.length) {
857
+ var _promises;
858
+ var rootEntity = entityMap.get(id);
859
+ (_promises = promises).push.apply(_promises, [].concat(removedEntities.map(function(target) {
860
+ var entityId = target.entityId;
861
+ var context = _this.prefabContextMap.get(rootEntity);
862
+ var targetEntity = context.entityMap.get(entityId);
863
+ if (targetEntity) {
864
+ targetEntity.destroy();
865
+ }
866
+ })));
867
+ }
868
+ };
869
+ var _this = this;
870
+ var entitiesConfig = this.context.originalData.entities;
871
+ var entityMap = this.context.entityMap;
872
+ var promises = [];
873
+ for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
874
+ return Promise.all(promises);
875
+ };
876
+ _proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
877
+ var _loop = function(i, l) {
878
+ var _removedComponents;
879
+ var entityConfig = entitiesConfig[i];
880
+ var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
881
+ if ((_removedComponents = removedComponents) == null ? void 0 : _removedComponents.length) {
882
+ var _promises;
883
+ var rootEntity = entityMap.get(id);
884
+ (_promises = promises).concat.apply(_promises, [].concat(removedComponents.map(function(target) {
885
+ var componentId = target.componentId;
886
+ var context = _this.prefabContextMap.get(rootEntity);
887
+ var targetComponent = context.components.get(componentId);
888
+ if (targetComponent) {
889
+ targetComponent.destroy();
890
+ }
891
+ })));
892
+ }
893
+ };
894
+ var _this = this;
895
+ var entitiesConfig = this.context.originalData.entities;
896
+ var entityMap = this.context.entityMap;
897
+ var promises = [];
898
+ for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
899
+ return Promise.all(promises);
900
+ };
901
+ _proto._clearAndResolve = function _clearAndResolve() {
902
+ var target = this.context.target;
903
+ return target;
904
+ };
905
+ _proto._organizeEntities = function _organizeEntities() {
906
+ var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
907
+ var parentIds = rootIds.concat(strippedIds);
908
+ for(var _iterator = _create_for_of_iterator_helper_loose(parentIds), _step; !(_step = _iterator()).done;){
909
+ var parentId = _step.value;
910
+ this._parseChildren(parentId);
911
+ }
912
+ for(var i = 0; i < rootIds.length; i++){
913
+ this.handleRootEntity(rootIds[i]);
914
+ }
915
+ };
916
+ _proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
917
+ var _this = this;
918
+ var entityPromise;
919
+ if (entityConfig.assetRefId) {
920
+ entityPromise = this._parseGLTF(entityConfig, engine);
921
+ } else if (entityConfig.strippedId) {
922
+ entityPromise = this._parseStrippedEntity(entityConfig);
923
+ } else {
924
+ entityPromise = this._parseEntity(entityConfig, engine);
925
+ }
926
+ return entityPromise.then(function(entity) {
927
+ return _this._applyEntityData(entity, entityConfig);
928
+ });
929
+ };
930
+ _proto._parseEntity = function _parseEntity(entityConfig, engine) {
931
+ var entity = new miniprogram.Entity(engine, entityConfig.name);
932
+ if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
933
+ return Promise.resolve(entity);
934
+ };
935
+ _proto._parseGLTF = function _parseGLTF(entityConfig, engine) {
936
+ var _this = this;
937
+ var assetRefId = entityConfig.assetRefId;
938
+ var context = new ParserContext(null, engine);
939
+ return engine.resourceManager// @ts-ignore
940
+ .getResourceByRef({
941
+ refId: assetRefId
942
+ }).then(function(glTFResource) {
943
+ var entity = glTFResource.instantiateSceneRoot();
944
+ if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
945
+ _this._traverseAddEntityToMap(entity, context, "");
946
+ _this.prefabContextMap.set(entity, context);
947
+ var cbArray = _this.prefabPromiseMap.get(entityConfig.id);
948
+ cbArray && cbArray.forEach(function(cb) {
949
+ cb.resolve(context);
950
+ });
951
+ return entity;
952
+ });
953
+ };
954
+ _proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
955
+ var _this = this;
956
+ this.context.strippedIds.push(entityConfig.id);
957
+ return new Promise(function(resolve, reject) {
958
+ var _this_prefabPromiseMap_get;
959
+ var cbArray = (_this_prefabPromiseMap_get = _this.prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this_prefabPromiseMap_get : [];
960
+ cbArray.push({
961
+ resolve: resolve,
962
+ reject: reject
963
+ });
964
+ _this.prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
965
+ }).then(function(context) {
966
+ var entityId = entityConfig.prefabSource.entityId;
967
+ return context.entityMap.get(entityId);
968
+ });
969
+ };
970
+ _proto._parseChildren = function _parseChildren(parentId) {
971
+ var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
972
+ var children = entityConfigMap.get(parentId).children;
680
973
  if (children && children.length > 0) {
681
- var parent = entities.get(parentId);
974
+ var parent = entityMap.get(parentId);
682
975
  for(var i = 0; i < children.length; i++){
683
976
  var childId = children[i];
684
- var entity = entities.get(childId);
977
+ var entity = entityMap.get(childId);
685
978
  parent.addChild(entity);
686
- this.parseChildren(entitiesConfig, entities, childId);
979
+ this._parseChildren(childId);
687
980
  }
688
981
  }
689
982
  };
690
- return PrefabParser;
983
+ _proto._applyEntityData = function _applyEntityData(entity, 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
+ entityMap.set(path, entity);
997
+ // @ts-ignore
998
+ entity._components.forEach(function(component) {
999
+ // @ts-ignore
1000
+ var name = miniprogram.Loader.getClassName(component.constructor);
1001
+ components.set(path + ":" + name, component);
1002
+ });
1003
+ for(var i = 0; i < entity.children.length; i++){
1004
+ var child = entity.children[i];
1005
+ var childPath = path ? path + "/" + child.name : child.name;
1006
+ this._traverseAddEntityToMap(child, context, childPath);
1007
+ }
1008
+ };
1009
+ return HierarchyParser;
691
1010
  }();
692
1011
 
693
- var ComponentMap = {
694
- Transform: miniprogram.Transform,
695
- Animator: miniprogram.Animator,
696
- DirectLight: miniprogram.DirectLight,
697
- Camera: miniprogram.Camera,
698
- MeshRenderer: miniprogram.MeshRenderer,
699
- ParticleRenderer: miniprogram.ParticleRenderer,
700
- PointLight: miniprogram.PointLight,
701
- SpotLight: miniprogram.SpotLight,
702
- Script: miniprogram.Script,
703
- SpriteMask: miniprogram.SpriteMask,
704
- SpriteRenderer: miniprogram.SpriteRenderer,
705
- TextRenderer: miniprogram.TextRenderer
706
- };
1012
+ var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
1013
+ _inherits(PrefabParser, HierarchyParser1);
1014
+ function PrefabParser() {
1015
+ return HierarchyParser1.apply(this, arguments);
1016
+ }
1017
+ var _proto = PrefabParser.prototype;
1018
+ _proto.handleRootEntity = function handleRootEntity(id) {
1019
+ this.context.target = this.context.entityMap.get(id);
1020
+ };
1021
+ /**
1022
+ * Parse prefab data.
1023
+ * @param engine - the engine of the parser context
1024
+ * @param prefabData - prefab data which is exported by editor
1025
+ * @returns a promise of prefab
1026
+ */ PrefabParser.parse = function parse(engine, prefabData) {
1027
+ var context = new PrefabParserContext(prefabData, engine);
1028
+ var parser = new PrefabParser(context);
1029
+ parser.start();
1030
+ return parser;
1031
+ };
1032
+ return PrefabParser;
1033
+ }(HierarchyParser);
707
1034
 
708
1035
  exports.InterpolableValueType = void 0;
709
1036
  (function(InterpolableValueType) {
@@ -737,7 +1064,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
737
1064
  for(var i1 = 0; i1 < curveBindingsLen; ++i1){
738
1065
  var relativePath = bufferReader.nextStr();
739
1066
  var componentStr = bufferReader.nextStr();
740
- var componentType = ComponentMap[componentStr];
1067
+ var componentType = miniprogram.Loader.getClass(componentStr);
741
1068
  var property = bufferReader.nextStr();
742
1069
  var getProperty = bufferReader.nextStr();
743
1070
  var curve = void 0;
@@ -916,145 +1243,28 @@ exports.SpecularMode = void 0;
916
1243
  SpecularMode["Custom"] = "Custom";
917
1244
  })(exports.SpecularMode || (exports.SpecularMode = {}));
918
1245
 
919
- function _array_like_to_array(arr, len) {
920
- if (len == null || len > arr.length) len = arr.length;
921
-
922
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
923
-
924
- return arr2;
925
- }
926
-
927
- function _unsupported_iterable_to_array(o, minLen) {
928
- if (!o) return;
929
- if (typeof o === "string") return _array_like_to_array(o, minLen);
930
-
931
- var n = Object.prototype.toString.call(o).slice(8, -1);
932
-
933
- if (n === "Object" && o.constructor) n = o.constructor.name;
934
- if (n === "Map" || n === "Set") return Array.from(n);
935
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
936
- }
937
-
938
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
939
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
940
-
941
- if (it) return (it = it.call(o)).next.bind(it);
942
- // Fallback for engines without symbol support
943
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
944
- if (it) o = it;
945
-
946
- var i = 0;
947
-
948
- return function() {
949
- if (i >= o.length) return { done: true };
950
-
951
- return { done: false, value: o[i++] };
952
- };
953
- }
954
-
955
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
956
- }
957
-
958
- var SceneParserContext = /*#__PURE__*/ function() {
959
- function SceneParserContext(originalData, scene) {
960
- this.originalData = originalData;
961
- this.scene = scene;
962
- this.entityMap = new Map();
963
- this.components = new Map();
964
- this.assets = new Map();
965
- this.entityConfigMap = new Map();
966
- this.rootIds = [];
967
- this.engine = scene.engine;
968
- this.resourceManager = scene.engine.resourceManager;
1246
+ var SceneParserContext = /*#__PURE__*/ function(ParserContext1) {
1247
+ _inherits(SceneParserContext, ParserContext1);
1248
+ function SceneParserContext(originalData, engine, scene) {
1249
+ var _this;
1250
+ _this = ParserContext1.call(this, originalData, engine, scene) || this;
1251
+ _this.originalData = originalData;
1252
+ _this.engine = engine;
1253
+ _this.scene = scene;
1254
+ return _this;
969
1255
  }
970
- var _proto = SceneParserContext.prototype;
971
- _proto.destroy = function destroy() {
972
- this.entityMap.clear();
973
- this.components.clear();
974
- this.assets.clear();
975
- this.entityConfigMap.clear();
976
- this.rootIds.length = 0;
977
- };
978
1256
  return SceneParserContext;
979
- }();
1257
+ }(ParserContext);
980
1258
 
981
- /** @Internal */ var SceneParser = /*#__PURE__*/ function() {
982
- function SceneParser(context) {
983
- var _this = this;
984
- this.context = context;
985
- this._engine = context.scene.engine;
986
- this._organizeEntities = this._organizeEntities.bind(this);
987
- this._parseComponents = this._parseComponents.bind(this);
988
- this._clearAndResolveScene = this._clearAndResolveScene.bind(this);
989
- this.promise = new Promise(function(resolve, reject) {
990
- _this._reject = reject;
991
- _this._resolve = resolve;
992
- });
993
- this._reflectionParser = new ReflectionParser(context);
1259
+ /** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
1260
+ _inherits(SceneParser, HierarchyParser1);
1261
+ function SceneParser() {
1262
+ return HierarchyParser1.apply(this, arguments);
994
1263
  }
995
1264
  var _proto = SceneParser.prototype;
996
- /** start parse the scene */ _proto.start = function start() {
997
- this._parseEntities().then(this._organizeEntities).then(this._parseComponents).then(this._clearAndResolveScene).then(this._resolve).catch(this._reject);
998
- };
999
- _proto._parseEntities = function _parseEntities() {
1000
- var _this = this;
1001
- var entitiesConfig = this.context.originalData.entities;
1002
- var entityConfigMap = this.context.entityConfigMap;
1003
- var entitiesMap = this.context.entityMap;
1004
- var rootIds = this.context.rootIds;
1005
- this._engine;
1006
- var promises = entitiesConfig.map(function(entityConfig) {
1007
- entityConfigMap.set(entityConfig.id, entityConfig);
1008
- // record root entities
1009
- if (!entityConfig.parent) rootIds.push(entityConfig.id);
1010
- return _this._reflectionParser.parseEntity(entityConfig);
1011
- });
1012
- return Promise.all(promises).then(function(entities) {
1013
- for(var i = 0, l = entities.length; i < l; i++){
1014
- entitiesMap.set(entitiesConfig[i].id, entities[i]);
1015
- }
1016
- return entities;
1017
- });
1018
- };
1019
- _proto._organizeEntities = function _organizeEntities() {
1020
- var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
1021
- for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
1022
- var rootId = _step.value;
1023
- PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
1024
- }
1025
- var rootEntities = rootIds.map(function(id) {
1026
- return entityMap.get(id);
1027
- });
1028
- for(var i = 0; i < rootEntities.length; i++){
1029
- scene.addRootEntity(rootEntities[i]);
1030
- }
1031
- };
1032
- _proto._parseComponents = function _parseComponents() {
1033
- var entitiesConfig = this.context.originalData.entities;
1034
- var entityMap = this.context.entityMap;
1035
- var promises = [];
1036
- for(var i = 0, l = entitiesConfig.length; i < l; i++){
1037
- var entityConfig = entitiesConfig[i];
1038
- var entity = entityMap.get(entityConfig.id);
1039
- for(var i1 = 0; i1 < entityConfig.components.length; i1++){
1040
- var componentConfig = entityConfig.components[i1];
1041
- var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
1042
- var component = void 0;
1043
- // TODO: remove hack code when support additional edit
1044
- if (key === "Animator") {
1045
- component = entity.getComponent(miniprogram.Loader.getClass(key));
1046
- }
1047
- component = component || entity.addComponent(miniprogram.Loader.getClass(key));
1048
- var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
1049
- promises.push(promise);
1050
- }
1051
- }
1052
- return Promise.all(promises);
1053
- };
1054
- _proto._clearAndResolveScene = function _clearAndResolveScene() {
1055
- var scene = this.context.scene;
1056
- this.context.destroy();
1057
- return scene;
1265
+ _proto.handleRootEntity = function handleRootEntity(id) {
1266
+ var _this_context = this.context, target = _this_context.target, entityMap = _this_context.entityMap;
1267
+ target.addRootEntity(entityMap.get(id));
1058
1268
  };
1059
1269
  /**
1060
1270
  * Parse scene data.
@@ -1063,13 +1273,13 @@ var SceneParserContext = /*#__PURE__*/ function() {
1063
1273
  * @returns a promise of scene
1064
1274
  */ SceneParser.parse = function parse(engine, sceneData) {
1065
1275
  var scene = new miniprogram.Scene(engine);
1066
- var context = new SceneParserContext(sceneData, scene);
1276
+ var context = new SceneParserContext(sceneData, engine, scene);
1067
1277
  var parser = new SceneParser(context);
1068
1278
  parser.start();
1069
1279
  return parser.promise;
1070
1280
  };
1071
1281
  return SceneParser;
1072
- }();
1282
+ }(HierarchyParser);
1073
1283
 
1074
1284
  exports.MeshLoader = /*#__PURE__*/ function(Loader1) {
1075
1285
  _inherits(MeshLoader, Loader1);
@@ -1174,7 +1384,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
1174
1384
  resourceManager// @ts-ignore
1175
1385
  .getResourceByRef(value).then(function(asset) {
1176
1386
  keyframe.value = asset;
1177
- resolve(keyframe);
1387
+ resolve(keyframe.value);
1178
1388
  });
1179
1389
  });
1180
1390
  } 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;