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

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
@@ -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,372 @@ 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
+ if (entityConfig === void 0) entityConfig = {};
985
+ var _entityConfig_isActive;
986
+ entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
987
+ var _entityConfig_name;
988
+ entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
989
+ var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
990
+ if (position) entity.transform.position.copyFrom(position);
991
+ if (rotation) entity.transform.rotation.copyFrom(rotation);
992
+ if (scale) entity.transform.scale.copyFrom(scale);
993
+ return entity;
994
+ };
995
+ _proto._traverseAddEntityToMap = function _traverseAddEntityToMap(entity, context, path) {
996
+ var entityMap = context.entityMap, components = context.components;
997
+ var componentsMap = {};
998
+ var componentIndexMap = {};
999
+ entityMap.set(path, entity);
1000
+ // @ts-ignore
1001
+ entity._components.forEach(function(component) {
1002
+ // @ts-ignore
1003
+ var name = miniprogram.Loader.getClassName(component.constructor);
1004
+ if (!componentsMap[name]) {
1005
+ componentsMap[name] = entity.getComponents(component.constructor, []);
1006
+ componentIndexMap[name] = 0;
1007
+ }
1008
+ components.set(path + ":" + name + "/" + componentIndexMap[name]++, component);
1009
+ });
1010
+ for(var i = 0, n = entity.children.length; i < n; i++){
1011
+ var child = entity.children[i];
1012
+ var childPath = path ? path + "/" + i : "" + i;
1013
+ this._traverseAddEntityToMap(child, context, childPath);
1014
+ }
1015
+ };
1016
+ return HierarchyParser;
691
1017
  }();
692
1018
 
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
- };
1019
+ var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
1020
+ _inherits(PrefabParser, HierarchyParser1);
1021
+ function PrefabParser() {
1022
+ return HierarchyParser1.apply(this, arguments);
1023
+ }
1024
+ var _proto = PrefabParser.prototype;
1025
+ _proto.handleRootEntity = function handleRootEntity(id) {
1026
+ this.context.target = this.context.entityMap.get(id);
1027
+ };
1028
+ /**
1029
+ * Parse prefab data.
1030
+ * @param engine - the engine of the parser context
1031
+ * @param prefabData - prefab data which is exported by editor
1032
+ * @returns a promise of prefab
1033
+ */ PrefabParser.parse = function parse(engine, prefabData) {
1034
+ var context = new PrefabParserContext(prefabData, engine);
1035
+ var parser = new PrefabParser(context);
1036
+ parser.start();
1037
+ return parser;
1038
+ };
1039
+ return PrefabParser;
1040
+ }(HierarchyParser);
707
1041
 
708
1042
  exports.InterpolableValueType = void 0;
709
1043
  (function(InterpolableValueType) {
@@ -737,7 +1071,7 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
737
1071
  for(var i1 = 0; i1 < curveBindingsLen; ++i1){
738
1072
  var relativePath = bufferReader.nextStr();
739
1073
  var componentStr = bufferReader.nextStr();
740
- var componentType = ComponentMap[componentStr];
1074
+ var componentType = miniprogram.Loader.getClass(componentStr);
741
1075
  var property = bufferReader.nextStr();
742
1076
  var getProperty = bufferReader.nextStr();
743
1077
  var curve = void 0;
@@ -916,145 +1250,28 @@ exports.SpecularMode = void 0;
916
1250
  SpecularMode["Custom"] = "Custom";
917
1251
  })(exports.SpecularMode || (exports.SpecularMode = {}));
918
1252
 
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;
1253
+ var SceneParserContext = /*#__PURE__*/ function(ParserContext1) {
1254
+ _inherits(SceneParserContext, ParserContext1);
1255
+ function SceneParserContext(originalData, engine, scene) {
1256
+ var _this;
1257
+ _this = ParserContext1.call(this, originalData, engine, scene) || this;
1258
+ _this.originalData = originalData;
1259
+ _this.engine = engine;
1260
+ _this.scene = scene;
1261
+ return _this;
969
1262
  }
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
1263
  return SceneParserContext;
979
- }();
1264
+ }(ParserContext);
980
1265
 
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);
1266
+ /** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
1267
+ _inherits(SceneParser, HierarchyParser1);
1268
+ function SceneParser() {
1269
+ return HierarchyParser1.apply(this, arguments);
994
1270
  }
995
1271
  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;
1272
+ _proto.handleRootEntity = function handleRootEntity(id) {
1273
+ var _this_context = this.context, target = _this_context.target, entityMap = _this_context.entityMap;
1274
+ target.addRootEntity(entityMap.get(id));
1058
1275
  };
1059
1276
  /**
1060
1277
  * Parse scene data.
@@ -1063,13 +1280,13 @@ var SceneParserContext = /*#__PURE__*/ function() {
1063
1280
  * @returns a promise of scene
1064
1281
  */ SceneParser.parse = function parse(engine, sceneData) {
1065
1282
  var scene = new miniprogram.Scene(engine);
1066
- var context = new SceneParserContext(sceneData, scene);
1283
+ var context = new SceneParserContext(sceneData, engine, scene);
1067
1284
  var parser = new SceneParser(context);
1068
1285
  parser.start();
1069
1286
  return parser.promise;
1070
1287
  };
1071
1288
  return SceneParser;
1072
- }();
1289
+ }(HierarchyParser);
1073
1290
 
1074
1291
  exports.MeshLoader = /*#__PURE__*/ function(Loader1) {
1075
1292
  _inherits(MeshLoader, Loader1);
@@ -1174,7 +1391,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
1174
1391
  resourceManager// @ts-ignore
1175
1392
  .getResourceByRef(value).then(function(asset) {
1176
1393
  keyframe.value = asset;
1177
- resolve(keyframe);
1394
+ resolve(keyframe.value);
1178
1395
  });
1179
1396
  });
1180
1397
  } else {
@@ -2186,7 +2403,7 @@ function registerGLTFParser(pipeline) {
2186
2403
  };
2187
2404
  /**
2188
2405
  * Parse the glb format.
2189
- */ GLTFUtils.parseGLB = function parseGLB(context, glb) {
2406
+ */ GLTFUtils.parseGLB = function parseGLB(context, originBuffer) {
2190
2407
  var UINT32_LENGTH = 4;
2191
2408
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
2192
2409
  var GLB_HEADER_LENGTH = 12;
@@ -2194,7 +2411,7 @@ function registerGLTFParser(pipeline) {
2194
2411
  JSON: 0x4e4f534a,
2195
2412
  BIN: 0x004e4942
2196
2413
  };
2197
- var dataView = new DataView(glb);
2414
+ var dataView = new DataView(originBuffer);
2198
2415
  // read header
2199
2416
  var header = {
2200
2417
  magic: dataView.getUint32(0, true),
@@ -2202,8 +2419,9 @@ function registerGLTFParser(pipeline) {
2202
2419
  length: dataView.getUint32(2 * UINT32_LENGTH, true)
2203
2420
  };
2204
2421
  if (header.magic !== GLB_HEADER_MAGIC) {
2205
- console.error("Invalid glb magic number. Expected 0x46546C67, found 0x" + header.magic.toString(16));
2206
- return null;
2422
+ return {
2423
+ originBuffer: originBuffer
2424
+ };
2207
2425
  }
2208
2426
  // read main data
2209
2427
  var chunkLength = dataView.getUint32(GLB_HEADER_LENGTH, true);
@@ -2213,7 +2431,7 @@ function registerGLTFParser(pipeline) {
2213
2431
  console.error("Invalid glb chunk type. Expected 0x4E4F534A, found 0x" + chunkType.toString(16));
2214
2432
  return null;
2215
2433
  }
2216
- var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2434
+ var glTFData = new Uint8Array(originBuffer, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2217
2435
  var glTF = JSON.parse(miniprogram.Utils.decodeText(glTFData));
2218
2436
  // read all buffers
2219
2437
  var buffers = [];
@@ -2227,7 +2445,7 @@ function registerGLTFParser(pipeline) {
2227
2445
  return null;
2228
2446
  }
2229
2447
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
2230
- var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
2448
+ var buffer = originBuffer.slice(currentOffset, currentOffset + chunkLength);
2231
2449
  buffers.push(buffer);
2232
2450
  restoreGLBBufferSlice.push(new miniprogram$1.Vector2(currentOffset, chunkLength));
2233
2451
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
@@ -3641,23 +3859,20 @@ exports.GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3641
3859
  var requestConfig = {
3642
3860
  type: "arraybuffer"
3643
3861
  };
3644
- var isGLB = this._isGLB(url);
3645
- contentRestorer.isGLB = isGLB;
3646
- var promise = isGLB ? miniprogram.request(url, requestConfig).onProgress(undefined, context._onTaskDetail).then(function(glb) {
3862
+ return miniprogram.request(url, requestConfig).onProgress(undefined, context._onTaskDetail).then(function(buffer) {
3647
3863
  restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3648
- return GLTFUtils.parseGLB(context, glb);
3649
- }).then(function(param) {
3650
- var glTF = param.glTF, buffers = param.buffers;
3651
- context.buffers = buffers;
3652
- return glTF;
3653
- }) : miniprogram.request(url, {
3654
- type: "json"
3655
- }).onProgress(undefined, context._onTaskDetail);
3656
- return promise;
3657
- };
3658
- _proto._isGLB = function _isGLB(url) {
3659
- var index = url.lastIndexOf(".");
3660
- return url.substring(index + 1, index + 4) === "glb";
3864
+ return GLTFUtils.parseGLB(context, buffer);
3865
+ }).then(function(result) {
3866
+ var _result;
3867
+ if ((_result = result) == null ? void 0 : _result.glTF) {
3868
+ contentRestorer.isGLB = true;
3869
+ context.buffers = result.buffers;
3870
+ return result.glTF;
3871
+ } else {
3872
+ contentRestorer.isGLB = false;
3873
+ return JSON.parse(miniprogram.Utils.decodeText(new Uint8Array(result.originBuffer)));
3874
+ }
3875
+ });
3661
3876
  };
3662
3877
  return GLTFSchemaParser;
3663
3878
  }(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 miniprogram.PrimitiveMesh.createSubdivisionSurfaceSphere(engine, data.sphereRadius, data.sphereStep);
5860
+ case "capsule":
5861
+ return miniprogram.PrimitiveMesh.createCapsule(engine, data.capsuleRadius, data.capsuleHeight, data.capsuleRadialSegments, data.capsuleHeightSegments);
5862
+ case "cone":
5863
+ return miniprogram.PrimitiveMesh.createCone(engine, data.coneRadius, data.coneHeight, data.coneRadialSegment, data.coneHeightSegment);
5864
+ case "cuboid":
5865
+ return miniprogram.PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth);
5866
+ case "cylinder":
5867
+ return miniprogram.PrimitiveMesh.createCylinder(engine, data.cylinderRadiusTop, data.cylinderRadiusBottom, data.cylinderHeight, data.cylinderRadialSegment, data.cylinderHeightSegment);
5868
+ case "plane":
5869
+ return miniprogram.PrimitiveMesh.createPlane(engine, data.planeWidth, data.planeHeight, data.planeHorizontalSegments, data.planeVerticalSegments);
5870
+ case "torus":
5871
+ return miniprogram.PrimitiveMesh.createTorus(engine, data.torusRadius, data.torusTubeRadius, data.torusRadialSegments, data.torusTubularSegments, data.torusArc);
5872
+ }
5873
+ });
5874
+ };
5875
+ return PrimitiveMeshLoader;
5876
+ }(miniprogram.Loader);
5877
+ PrimitiveMeshLoader = __decorate([
5878
+ miniprogram.resourceLoader(miniprogram.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 miniprogram.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: miniprogram.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
+ }(miniprogram.Loader);
5920
+ ProjectLoader = __decorate([
5921
+ miniprogram.resourceLoader(miniprogram.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 miniprogram.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: miniprogram.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
- }(miniprogram.Loader);
5993
- ProjectLoader = __decorate([
5994
- miniprogram.resourceLoader(miniprogram.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 === miniprogram.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;