@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 +373 -163
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +373 -163
- package/dist/module.js +374 -164
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/resource-deserialize/index.d.ts +2 -1
- package/types/resource-deserialize/resources/animationClip/AnimationClipDecoder.d.ts +0 -1
- package/types/resource-deserialize/resources/parser/HierarchyParser.d.ts +36 -0
- package/types/resource-deserialize/resources/parser/ParserContext.d.ts +29 -0
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +4 -4
- package/types/resource-deserialize/resources/prefab/PrefabParser.d.ts +13 -4
- package/types/resource-deserialize/resources/prefab/PrefabParserContext.d.ts +5 -0
- package/types/resource-deserialize/resources/scene/SceneParser.d.ts +3 -17
- package/types/resource-deserialize/resources/scene/SceneParserContext.d.ts +6 -12
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +24 -1
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Utils, ModelMesh, BlendShape, Texture2D, Loader, Entity,
|
|
1
|
+
import { Utils, ModelMesh, BlendShape, Texture2D, Loader, Entity, AnimationClip, AnimationEvent, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, Scene, resourceLoader, AssetPromise, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateMachine, AnimatorStateTransition, TextureCube, TextureFilterMode, TextureCubeFace, AmbientLight, DiffuseMode, Font, ReferResource, Animator, IndexFormat, VertexElementFormat, GLCapabilityType, Logger, TextureFormat, request, ContentRestorer, InterpolationType, SkinnedMeshRenderer, Transform, PBRMaterial, BlinnPhongMaterial, PBRSpecularMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, SystemInfo, Material, Shader, PrimitiveMesh, SpriteAtlas, Sprite, BackgroundMode, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
|
|
2
2
|
import { Color, Vector4, Vector3, Vector2, Quaternion, SphericalHarmonics3, MathUtil, BoundingBox, Matrix, Rect } from '@galacean/engine-math';
|
|
3
3
|
import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
|
|
4
4
|
|
|
@@ -636,8 +636,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
636
636
|
var assetRefId = entityConfig.assetRefId;
|
|
637
637
|
var engine = this._context.engine;
|
|
638
638
|
if (assetRefId) {
|
|
639
|
-
return engine.resourceManager
|
|
640
|
-
.getResourceByRef({
|
|
639
|
+
return engine.resourceManager.getResourceByRef({
|
|
641
640
|
refId: assetRefId,
|
|
642
641
|
key: entityConfig.key,
|
|
643
642
|
isClone: entityConfig.isClone
|
|
@@ -668,37 +667,365 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
668
667
|
ReflectionParser.customParseComponentHandles = new Map();
|
|
669
668
|
})();
|
|
670
669
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Parser context
|
|
672
|
+
* @export
|
|
673
|
+
* @abstract
|
|
674
|
+
* @class ParserContext
|
|
675
|
+
* @template T
|
|
676
|
+
* @template I
|
|
677
|
+
*/ var ParserContext = /*#__PURE__*/ function() {
|
|
678
|
+
function ParserContext(originalData, engine, target) {
|
|
679
|
+
this.originalData = originalData;
|
|
680
|
+
this.engine = engine;
|
|
681
|
+
this.target = target;
|
|
682
|
+
this.entityMap = new Map();
|
|
683
|
+
this.components = new Map();
|
|
684
|
+
this.assets = new Map();
|
|
685
|
+
this.entityConfigMap = new Map();
|
|
686
|
+
this.rootIds = [];
|
|
687
|
+
this.strippedIds = [];
|
|
688
|
+
this.resourceManager = engine.resourceManager;
|
|
689
|
+
}
|
|
690
|
+
var _proto = ParserContext.prototype;
|
|
691
|
+
/**
|
|
692
|
+
* Destroy the context.
|
|
693
|
+
* @abstract
|
|
694
|
+
* @memberof ParserContext
|
|
695
|
+
*/ _proto.destroy = function destroy() {
|
|
696
|
+
this.entityMap.clear();
|
|
697
|
+
this.components.clear();
|
|
698
|
+
this.assets.clear();
|
|
699
|
+
this.entityConfigMap.clear();
|
|
700
|
+
this.rootIds.length = 0;
|
|
701
|
+
};
|
|
702
|
+
return ParserContext;
|
|
703
|
+
}();
|
|
704
|
+
|
|
705
|
+
var PrefabParserContext = /*#__PURE__*/ function(ParserContext1) {
|
|
706
|
+
_inherits(PrefabParserContext, ParserContext1);
|
|
707
|
+
function PrefabParserContext() {
|
|
708
|
+
return ParserContext1.apply(this, arguments);
|
|
709
|
+
}
|
|
710
|
+
return PrefabParserContext;
|
|
711
|
+
}(ParserContext);
|
|
712
|
+
|
|
713
|
+
function _array_like_to_array(arr, len) {
|
|
714
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
715
|
+
|
|
716
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
717
|
+
|
|
718
|
+
return arr2;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
722
|
+
if (!o) return;
|
|
723
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
724
|
+
|
|
725
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
726
|
+
|
|
727
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
728
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
729
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
733
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
734
|
+
|
|
735
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
736
|
+
// Fallback for engines without symbol support
|
|
737
|
+
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
738
|
+
if (it) o = it;
|
|
739
|
+
|
|
740
|
+
var i = 0;
|
|
741
|
+
|
|
742
|
+
return function() {
|
|
743
|
+
if (i >= o.length) return { done: true };
|
|
744
|
+
|
|
745
|
+
return { done: false, value: o[i++] };
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
var HierarchyParser = /*#__PURE__*/ function() {
|
|
753
|
+
function HierarchyParser(context) {
|
|
754
|
+
var _this = this;
|
|
755
|
+
this.context = context;
|
|
756
|
+
this.prefabContextMap = new WeakMap();
|
|
757
|
+
this.prefabPromiseMap = new Map();
|
|
758
|
+
this._engine = this.context.engine;
|
|
759
|
+
this._organizeEntities = this._organizeEntities.bind(this);
|
|
760
|
+
this._parseComponents = this._parseComponents.bind(this);
|
|
761
|
+
this._parsePrefabModification = this._parsePrefabModification.bind(this);
|
|
762
|
+
this._parsePrefabRemovedEntities = this._parsePrefabRemovedEntities.bind(this);
|
|
763
|
+
this._parsePrefabRemovedComponents = this._parsePrefabRemovedComponents.bind(this);
|
|
764
|
+
this._clearAndResolve = this._clearAndResolve.bind(this);
|
|
765
|
+
this.promise = new Promise(function(resolve, reject) {
|
|
766
|
+
_this._reject = reject;
|
|
767
|
+
_this._resolve = resolve;
|
|
768
|
+
});
|
|
769
|
+
this._reflectionParser = new ReflectionParser(context);
|
|
770
|
+
}
|
|
771
|
+
var _proto = HierarchyParser.prototype;
|
|
772
|
+
/** start parse the scene or prefab or others */ _proto.start = function start() {
|
|
773
|
+
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);
|
|
774
|
+
};
|
|
775
|
+
_proto._parseEntities = function _parseEntities() {
|
|
776
|
+
var _this = this;
|
|
777
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
778
|
+
var entityConfigMap = this.context.entityConfigMap;
|
|
779
|
+
var entityMap = this.context.entityMap;
|
|
780
|
+
var engine = this._engine;
|
|
781
|
+
var promises = entitiesConfig.map(function(entityConfig) {
|
|
782
|
+
var _entityConfig_strippedId;
|
|
783
|
+
var id = (_entityConfig_strippedId = entityConfig.strippedId) != null ? _entityConfig_strippedId : entityConfig.id;
|
|
784
|
+
entityConfig.id = id;
|
|
785
|
+
entityConfigMap.set(id, entityConfig);
|
|
786
|
+
return _this._getEntityByConfig(entityConfig, engine);
|
|
787
|
+
});
|
|
788
|
+
return Promise.all(promises).then(function(entities) {
|
|
789
|
+
for(var i = 0, l = entities.length; i < l; i++){
|
|
790
|
+
entityMap.set(entitiesConfig[i].id, entities[i]);
|
|
791
|
+
}
|
|
792
|
+
return entities;
|
|
793
|
+
});
|
|
794
|
+
};
|
|
795
|
+
_proto._parseComponents = function _parseComponents() {
|
|
796
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
797
|
+
var entityMap = this.context.entityMap;
|
|
798
|
+
var components = this.context.components;
|
|
799
|
+
var promises = [];
|
|
800
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
801
|
+
var entityConfig = entitiesConfig[i];
|
|
802
|
+
var entity = entityMap.get(entityConfig.id);
|
|
803
|
+
for(var i1 = 0; i1 < entityConfig.components.length; i1++){
|
|
804
|
+
var componentConfig = entityConfig.components[i1];
|
|
805
|
+
var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
|
|
806
|
+
var component = entity.addComponent(Loader.getClass(key));
|
|
807
|
+
components.set(componentConfig.id, component);
|
|
808
|
+
var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
|
|
809
|
+
promises.push(promise);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return Promise.all(promises);
|
|
813
|
+
};
|
|
814
|
+
_proto._parsePrefabModification = function _parsePrefabModification() {
|
|
815
|
+
var _loop = function(i, l) {
|
|
816
|
+
var _modifications;
|
|
817
|
+
var entityConfig = entitiesConfig[i];
|
|
818
|
+
var id = entityConfig.id, modifications = entityConfig.modifications;
|
|
819
|
+
if ((_modifications = modifications) == null ? void 0 : _modifications.length) {
|
|
820
|
+
var _promises;
|
|
821
|
+
var rootEntity = entityMap.get(id);
|
|
822
|
+
(_promises = promises).push.apply(_promises, [].concat(modifications.map(function(modification) {
|
|
823
|
+
var target = modification.target, props = modification.props, methods = modification.methods;
|
|
824
|
+
var entityId = target.entityId, componentId = target.componentId;
|
|
825
|
+
var context = _this.prefabContextMap.get(rootEntity);
|
|
826
|
+
var targetEntity = context.entityMap.get(entityId);
|
|
827
|
+
var targetComponent = context.components.get(componentId);
|
|
828
|
+
if (targetComponent) {
|
|
829
|
+
return _this._reflectionParser.parsePropsAndMethods(targetComponent, {
|
|
830
|
+
props: props,
|
|
831
|
+
methods: methods
|
|
832
|
+
});
|
|
833
|
+
} else if (targetEntity) {
|
|
834
|
+
return Promise.resolve(_this._applyEntityData(targetEntity, props));
|
|
835
|
+
}
|
|
836
|
+
})));
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var _this = this;
|
|
840
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
841
|
+
var entityMap = this.context.entityMap;
|
|
842
|
+
var promises = [];
|
|
843
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
844
|
+
return Promise.all(promises);
|
|
845
|
+
};
|
|
846
|
+
_proto._parsePrefabRemovedEntities = function _parsePrefabRemovedEntities() {
|
|
847
|
+
var _loop = function(i, l) {
|
|
848
|
+
var _removedEntities;
|
|
849
|
+
var entityConfig = entitiesConfig[i];
|
|
850
|
+
var id = entityConfig.id, removedEntities = entityConfig.removedEntities;
|
|
851
|
+
if ((_removedEntities = removedEntities) == null ? void 0 : _removedEntities.length) {
|
|
852
|
+
var _promises;
|
|
853
|
+
var rootEntity = entityMap.get(id);
|
|
854
|
+
(_promises = promises).push.apply(_promises, [].concat(removedEntities.map(function(target) {
|
|
855
|
+
var entityId = target.entityId;
|
|
856
|
+
var context = _this.prefabContextMap.get(rootEntity);
|
|
857
|
+
var targetEntity = context.entityMap.get(entityId);
|
|
858
|
+
if (targetEntity) {
|
|
859
|
+
targetEntity.destroy();
|
|
860
|
+
}
|
|
861
|
+
})));
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var _this = this;
|
|
865
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
866
|
+
var entityMap = this.context.entityMap;
|
|
867
|
+
var promises = [];
|
|
868
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
869
|
+
return Promise.all(promises);
|
|
870
|
+
};
|
|
871
|
+
_proto._parsePrefabRemovedComponents = function _parsePrefabRemovedComponents() {
|
|
872
|
+
var _loop = function(i, l) {
|
|
873
|
+
var _removedComponents;
|
|
874
|
+
var entityConfig = entitiesConfig[i];
|
|
875
|
+
var id = entityConfig.id, removedComponents = entityConfig.removedComponents;
|
|
876
|
+
if ((_removedComponents = removedComponents) == null ? void 0 : _removedComponents.length) {
|
|
877
|
+
var _promises;
|
|
878
|
+
var rootEntity = entityMap.get(id);
|
|
879
|
+
(_promises = promises).concat.apply(_promises, [].concat(removedComponents.map(function(target) {
|
|
880
|
+
var componentId = target.componentId;
|
|
881
|
+
var context = _this.prefabContextMap.get(rootEntity);
|
|
882
|
+
var targetComponent = context.components.get(componentId);
|
|
883
|
+
if (targetComponent) {
|
|
884
|
+
targetComponent.destroy();
|
|
885
|
+
}
|
|
886
|
+
})));
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
var _this = this;
|
|
890
|
+
var entitiesConfig = this.context.originalData.entities;
|
|
891
|
+
var entityMap = this.context.entityMap;
|
|
892
|
+
var promises = [];
|
|
893
|
+
for(var i = 0, l = entitiesConfig.length; i < l; i++)_loop(i);
|
|
894
|
+
return Promise.all(promises);
|
|
895
|
+
};
|
|
896
|
+
_proto._clearAndResolve = function _clearAndResolve() {
|
|
897
|
+
var target = this.context.target;
|
|
898
|
+
return target;
|
|
899
|
+
};
|
|
900
|
+
_proto._organizeEntities = function _organizeEntities() {
|
|
901
|
+
var _this_context = this.context, rootIds = _this_context.rootIds, strippedIds = _this_context.strippedIds;
|
|
902
|
+
var parentIds = rootIds.concat(strippedIds);
|
|
903
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(parentIds), _step; !(_step = _iterator()).done;){
|
|
904
|
+
var parentId = _step.value;
|
|
905
|
+
this._parseChildren(parentId);
|
|
906
|
+
}
|
|
907
|
+
for(var i = 0; i < rootIds.length; i++){
|
|
908
|
+
this.handleRootEntity(rootIds[i]);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
_proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
|
|
912
|
+
var _this = this;
|
|
913
|
+
var entityPromise;
|
|
914
|
+
if (entityConfig.assetRefId) {
|
|
915
|
+
entityPromise = this._parseGLTF(entityConfig, engine);
|
|
916
|
+
} else if (entityConfig.strippedId) {
|
|
917
|
+
entityPromise = this._parseStrippedEntity(entityConfig);
|
|
918
|
+
} else {
|
|
919
|
+
entityPromise = this._parseEntity(entityConfig, engine);
|
|
920
|
+
}
|
|
921
|
+
return entityPromise.then(function(entity) {
|
|
922
|
+
return _this._applyEntityData(entity, entityConfig);
|
|
923
|
+
});
|
|
924
|
+
};
|
|
925
|
+
_proto._parseEntity = function _parseEntity(entityConfig, engine) {
|
|
926
|
+
var entity = new Entity(engine, entityConfig.name);
|
|
927
|
+
if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
|
|
928
|
+
return Promise.resolve(entity);
|
|
929
|
+
};
|
|
930
|
+
_proto._parseGLTF = function _parseGLTF(entityConfig, engine) {
|
|
931
|
+
var _this = this;
|
|
932
|
+
var assetRefId = entityConfig.assetRefId;
|
|
933
|
+
var context = new ParserContext(null, engine);
|
|
934
|
+
return engine.resourceManager// @ts-ignore
|
|
935
|
+
.getResourceByRef({
|
|
936
|
+
refId: assetRefId
|
|
937
|
+
}).then(function(glTFResource) {
|
|
938
|
+
var entity = glTFResource.instantiateSceneRoot();
|
|
939
|
+
if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
|
|
940
|
+
_this._traverseAddEntityToMap(entity, context, "");
|
|
941
|
+
_this.prefabContextMap.set(entity, context);
|
|
942
|
+
var cbArray = _this.prefabPromiseMap.get(entityConfig.id);
|
|
943
|
+
cbArray && cbArray.forEach(function(cb) {
|
|
944
|
+
cb.resolve(context);
|
|
945
|
+
});
|
|
946
|
+
return entity;
|
|
947
|
+
});
|
|
948
|
+
};
|
|
949
|
+
_proto._parseStrippedEntity = function _parseStrippedEntity(entityConfig) {
|
|
950
|
+
var _this = this;
|
|
951
|
+
this.context.strippedIds.push(entityConfig.id);
|
|
952
|
+
return new Promise(function(resolve, reject) {
|
|
953
|
+
var _this_prefabPromiseMap_get;
|
|
954
|
+
var cbArray = (_this_prefabPromiseMap_get = _this.prefabPromiseMap.get(entityConfig.prefabInstanceId)) != null ? _this_prefabPromiseMap_get : [];
|
|
955
|
+
cbArray.push({
|
|
956
|
+
resolve: resolve,
|
|
957
|
+
reject: reject
|
|
958
|
+
});
|
|
959
|
+
_this.prefabPromiseMap.set(entityConfig.prefabInstanceId, cbArray);
|
|
960
|
+
}).then(function(context) {
|
|
961
|
+
var entityId = entityConfig.prefabSource.entityId;
|
|
962
|
+
return context.entityMap.get(entityId);
|
|
963
|
+
});
|
|
964
|
+
};
|
|
965
|
+
_proto._parseChildren = function _parseChildren(parentId) {
|
|
966
|
+
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap;
|
|
967
|
+
var children = entityConfigMap.get(parentId).children;
|
|
675
968
|
if (children && children.length > 0) {
|
|
676
|
-
var parent =
|
|
969
|
+
var parent = entityMap.get(parentId);
|
|
677
970
|
for(var i = 0; i < children.length; i++){
|
|
678
971
|
var childId = children[i];
|
|
679
|
-
var entity =
|
|
972
|
+
var entity = entityMap.get(childId);
|
|
680
973
|
parent.addChild(entity);
|
|
681
|
-
this.
|
|
974
|
+
this._parseChildren(childId);
|
|
682
975
|
}
|
|
683
976
|
}
|
|
684
977
|
};
|
|
685
|
-
|
|
978
|
+
_proto._applyEntityData = function _applyEntityData(entity, entityConfig) {
|
|
979
|
+
var _entityConfig_isActive;
|
|
980
|
+
entity.isActive = (_entityConfig_isActive = entityConfig.isActive) != null ? _entityConfig_isActive : entity.isActive;
|
|
981
|
+
var _entityConfig_name;
|
|
982
|
+
entity.name = (_entityConfig_name = entityConfig.name) != null ? _entityConfig_name : entity.name;
|
|
983
|
+
var position = entityConfig.position, rotation = entityConfig.rotation, scale = entityConfig.scale;
|
|
984
|
+
if (position) entity.transform.position.copyFrom(position);
|
|
985
|
+
if (rotation) entity.transform.rotation.copyFrom(rotation);
|
|
986
|
+
if (scale) entity.transform.scale.copyFrom(scale);
|
|
987
|
+
return entity;
|
|
988
|
+
};
|
|
989
|
+
_proto._traverseAddEntityToMap = function _traverseAddEntityToMap(entity, context, path) {
|
|
990
|
+
var entityMap = context.entityMap, components = context.components;
|
|
991
|
+
entityMap.set(path, entity);
|
|
992
|
+
// @ts-ignore
|
|
993
|
+
entity._components.forEach(function(component) {
|
|
994
|
+
// @ts-ignore
|
|
995
|
+
var name = Loader.getClassName(component.constructor);
|
|
996
|
+
components.set(path + ":" + name, component);
|
|
997
|
+
});
|
|
998
|
+
for(var i = 0; i < entity.children.length; i++){
|
|
999
|
+
var child = entity.children[i];
|
|
1000
|
+
var childPath = path ? path + "/" + child.name : child.name;
|
|
1001
|
+
this._traverseAddEntityToMap(child, context, childPath);
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
return HierarchyParser;
|
|
686
1005
|
}();
|
|
687
1006
|
|
|
688
|
-
var
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
1007
|
+
var PrefabParser = /*#__PURE__*/ function(HierarchyParser1) {
|
|
1008
|
+
_inherits(PrefabParser, HierarchyParser1);
|
|
1009
|
+
function PrefabParser() {
|
|
1010
|
+
return HierarchyParser1.apply(this, arguments);
|
|
1011
|
+
}
|
|
1012
|
+
var _proto = PrefabParser.prototype;
|
|
1013
|
+
_proto.handleRootEntity = function handleRootEntity(id) {
|
|
1014
|
+
this.context.target = this.context.entityMap.get(id);
|
|
1015
|
+
};
|
|
1016
|
+
/**
|
|
1017
|
+
* Parse prefab data.
|
|
1018
|
+
* @param engine - the engine of the parser context
|
|
1019
|
+
* @param prefabData - prefab data which is exported by editor
|
|
1020
|
+
* @returns a promise of prefab
|
|
1021
|
+
*/ PrefabParser.parse = function parse(engine, prefabData) {
|
|
1022
|
+
var context = new PrefabParserContext(prefabData, engine);
|
|
1023
|
+
var parser = new PrefabParser(context);
|
|
1024
|
+
parser.start();
|
|
1025
|
+
return parser;
|
|
1026
|
+
};
|
|
1027
|
+
return PrefabParser;
|
|
1028
|
+
}(HierarchyParser);
|
|
702
1029
|
|
|
703
1030
|
var InterpolableValueType;
|
|
704
1031
|
(function(InterpolableValueType) {
|
|
@@ -732,7 +1059,7 @@ var AnimationClipDecoder = /*#__PURE__*/ function() {
|
|
|
732
1059
|
for(var i1 = 0; i1 < curveBindingsLen; ++i1){
|
|
733
1060
|
var relativePath = bufferReader.nextStr();
|
|
734
1061
|
var componentStr = bufferReader.nextStr();
|
|
735
|
-
var componentType =
|
|
1062
|
+
var componentType = Loader.getClass(componentStr);
|
|
736
1063
|
var property = bufferReader.nextStr();
|
|
737
1064
|
var getProperty = bufferReader.nextStr();
|
|
738
1065
|
var curve = void 0;
|
|
@@ -911,145 +1238,28 @@ var SpecularMode;
|
|
|
911
1238
|
SpecularMode["Custom"] = "Custom";
|
|
912
1239
|
})(SpecularMode || (SpecularMode = {}));
|
|
913
1240
|
|
|
914
|
-
function
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (!o) return;
|
|
924
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
925
|
-
|
|
926
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
927
|
-
|
|
928
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
929
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
930
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
934
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
935
|
-
|
|
936
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
937
|
-
// Fallback for engines without symbol support
|
|
938
|
-
if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
939
|
-
if (it) o = it;
|
|
940
|
-
|
|
941
|
-
var i = 0;
|
|
942
|
-
|
|
943
|
-
return function() {
|
|
944
|
-
if (i >= o.length) return { done: true };
|
|
945
|
-
|
|
946
|
-
return { done: false, value: o[i++] };
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
var SceneParserContext = /*#__PURE__*/ function() {
|
|
954
|
-
function SceneParserContext(originalData, scene) {
|
|
955
|
-
this.originalData = originalData;
|
|
956
|
-
this.scene = scene;
|
|
957
|
-
this.entityMap = new Map();
|
|
958
|
-
this.components = new Map();
|
|
959
|
-
this.assets = new Map();
|
|
960
|
-
this.entityConfigMap = new Map();
|
|
961
|
-
this.rootIds = [];
|
|
962
|
-
this.engine = scene.engine;
|
|
963
|
-
this.resourceManager = scene.engine.resourceManager;
|
|
1241
|
+
var SceneParserContext = /*#__PURE__*/ function(ParserContext1) {
|
|
1242
|
+
_inherits(SceneParserContext, ParserContext1);
|
|
1243
|
+
function SceneParserContext(originalData, engine, scene) {
|
|
1244
|
+
var _this;
|
|
1245
|
+
_this = ParserContext1.call(this, originalData, engine, scene) || this;
|
|
1246
|
+
_this.originalData = originalData;
|
|
1247
|
+
_this.engine = engine;
|
|
1248
|
+
_this.scene = scene;
|
|
1249
|
+
return _this;
|
|
964
1250
|
}
|
|
965
|
-
var _proto = SceneParserContext.prototype;
|
|
966
|
-
_proto.destroy = function destroy() {
|
|
967
|
-
this.entityMap.clear();
|
|
968
|
-
this.components.clear();
|
|
969
|
-
this.assets.clear();
|
|
970
|
-
this.entityConfigMap.clear();
|
|
971
|
-
this.rootIds.length = 0;
|
|
972
|
-
};
|
|
973
1251
|
return SceneParserContext;
|
|
974
|
-
}();
|
|
1252
|
+
}(ParserContext);
|
|
975
1253
|
|
|
976
|
-
/** @Internal */ var SceneParser = /*#__PURE__*/ function() {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
this
|
|
980
|
-
this._engine = context.scene.engine;
|
|
981
|
-
this._organizeEntities = this._organizeEntities.bind(this);
|
|
982
|
-
this._parseComponents = this._parseComponents.bind(this);
|
|
983
|
-
this._clearAndResolveScene = this._clearAndResolveScene.bind(this);
|
|
984
|
-
this.promise = new Promise(function(resolve, reject) {
|
|
985
|
-
_this._reject = reject;
|
|
986
|
-
_this._resolve = resolve;
|
|
987
|
-
});
|
|
988
|
-
this._reflectionParser = new ReflectionParser(context);
|
|
1254
|
+
/** @Internal */ var SceneParser = /*#__PURE__*/ function(HierarchyParser1) {
|
|
1255
|
+
_inherits(SceneParser, HierarchyParser1);
|
|
1256
|
+
function SceneParser() {
|
|
1257
|
+
return HierarchyParser1.apply(this, arguments);
|
|
989
1258
|
}
|
|
990
1259
|
var _proto = SceneParser.prototype;
|
|
991
|
-
|
|
992
|
-
this.
|
|
993
|
-
|
|
994
|
-
_proto._parseEntities = function _parseEntities() {
|
|
995
|
-
var _this = this;
|
|
996
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
997
|
-
var entityConfigMap = this.context.entityConfigMap;
|
|
998
|
-
var entitiesMap = this.context.entityMap;
|
|
999
|
-
var rootIds = this.context.rootIds;
|
|
1000
|
-
this._engine;
|
|
1001
|
-
var promises = entitiesConfig.map(function(entityConfig) {
|
|
1002
|
-
entityConfigMap.set(entityConfig.id, entityConfig);
|
|
1003
|
-
// record root entities
|
|
1004
|
-
if (!entityConfig.parent) rootIds.push(entityConfig.id);
|
|
1005
|
-
return _this._reflectionParser.parseEntity(entityConfig);
|
|
1006
|
-
});
|
|
1007
|
-
return Promise.all(promises).then(function(entities) {
|
|
1008
|
-
for(var i = 0, l = entities.length; i < l; i++){
|
|
1009
|
-
entitiesMap.set(entitiesConfig[i].id, entities[i]);
|
|
1010
|
-
}
|
|
1011
|
-
return entities;
|
|
1012
|
-
});
|
|
1013
|
-
};
|
|
1014
|
-
_proto._organizeEntities = function _organizeEntities() {
|
|
1015
|
-
var _this_context = this.context, entityConfigMap = _this_context.entityConfigMap, entityMap = _this_context.entityMap, scene = _this_context.scene, rootIds = _this_context.rootIds;
|
|
1016
|
-
for(var _iterator = _create_for_of_iterator_helper_loose(rootIds), _step; !(_step = _iterator()).done;){
|
|
1017
|
-
var rootId = _step.value;
|
|
1018
|
-
PrefabParser.parseChildren(entityConfigMap, entityMap, rootId);
|
|
1019
|
-
}
|
|
1020
|
-
var rootEntities = rootIds.map(function(id) {
|
|
1021
|
-
return entityMap.get(id);
|
|
1022
|
-
});
|
|
1023
|
-
for(var i = 0; i < rootEntities.length; i++){
|
|
1024
|
-
scene.addRootEntity(rootEntities[i]);
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
_proto._parseComponents = function _parseComponents() {
|
|
1028
|
-
var entitiesConfig = this.context.originalData.entities;
|
|
1029
|
-
var entityMap = this.context.entityMap;
|
|
1030
|
-
var promises = [];
|
|
1031
|
-
for(var i = 0, l = entitiesConfig.length; i < l; i++){
|
|
1032
|
-
var entityConfig = entitiesConfig[i];
|
|
1033
|
-
var entity = entityMap.get(entityConfig.id);
|
|
1034
|
-
for(var i1 = 0; i1 < entityConfig.components.length; i1++){
|
|
1035
|
-
var componentConfig = entityConfig.components[i1];
|
|
1036
|
-
var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
|
|
1037
|
-
var component = void 0;
|
|
1038
|
-
// TODO: remove hack code when support additional edit
|
|
1039
|
-
if (key === "Animator") {
|
|
1040
|
-
component = entity.getComponent(Loader.getClass(key));
|
|
1041
|
-
}
|
|
1042
|
-
component = component || entity.addComponent(Loader.getClass(key));
|
|
1043
|
-
var promise = this._reflectionParser.parsePropsAndMethods(component, componentConfig);
|
|
1044
|
-
promises.push(promise);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
return Promise.all(promises);
|
|
1048
|
-
};
|
|
1049
|
-
_proto._clearAndResolveScene = function _clearAndResolveScene() {
|
|
1050
|
-
var scene = this.context.scene;
|
|
1051
|
-
this.context.destroy();
|
|
1052
|
-
return scene;
|
|
1260
|
+
_proto.handleRootEntity = function handleRootEntity(id) {
|
|
1261
|
+
var _this_context = this.context, target = _this_context.target, entityMap = _this_context.entityMap;
|
|
1262
|
+
target.addRootEntity(entityMap.get(id));
|
|
1053
1263
|
};
|
|
1054
1264
|
/**
|
|
1055
1265
|
* Parse scene data.
|
|
@@ -1058,13 +1268,13 @@ var SceneParserContext = /*#__PURE__*/ function() {
|
|
|
1058
1268
|
* @returns a promise of scene
|
|
1059
1269
|
*/ SceneParser.parse = function parse(engine, sceneData) {
|
|
1060
1270
|
var scene = new Scene(engine);
|
|
1061
|
-
var context = new SceneParserContext(sceneData, scene);
|
|
1271
|
+
var context = new SceneParserContext(sceneData, engine, scene);
|
|
1062
1272
|
var parser = new SceneParser(context);
|
|
1063
1273
|
parser.start();
|
|
1064
1274
|
return parser.promise;
|
|
1065
1275
|
};
|
|
1066
1276
|
return SceneParser;
|
|
1067
|
-
}();
|
|
1277
|
+
}(HierarchyParser);
|
|
1068
1278
|
|
|
1069
1279
|
var MeshLoader$1 = /*#__PURE__*/ function(Loader1) {
|
|
1070
1280
|
_inherits(MeshLoader, Loader1);
|
|
@@ -1169,7 +1379,7 @@ var AnimationClipLoader = /*#__PURE__*/ function(Loader1) {
|
|
|
1169
1379
|
resourceManager// @ts-ignore
|
|
1170
1380
|
.getResourceByRef(value).then(function(asset) {
|
|
1171
1381
|
keyframe.value = asset;
|
|
1172
|
-
resolve(keyframe);
|
|
1382
|
+
resolve(keyframe.value);
|
|
1173
1383
|
});
|
|
1174
1384
|
});
|
|
1175
1385
|
} else {
|
|
@@ -6530,5 +6740,5 @@ KHR_materials_anisotropy = __decorate([
|
|
|
6530
6740
|
registerGLTFExtension("KHR_materials_anisotropy", GLTFExtensionMode.AdditiveParse)
|
|
6531
6741
|
], KHR_materials_anisotropy);
|
|
6532
6742
|
|
|
6533
|
-
export { AccessorType, AnimationClipDecoder, BufferInfo,
|
|
6743
|
+
export { AccessorType, AnimationClipDecoder, BufferInfo, EditorTextureLoader, GLTFAnimationParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, InterpolableValueType, KTX2Loader, KTX2TargetFormat, KTX2Transcoder, MeshDecoder, MeshLoader$1 as MeshLoader, ParserContext, PrefabParser, ReflectionParser, SceneParser, SpecularMode, Texture2DDecoder, decode, parseSingleKTX, registerGLTFExtension, registerGLTFParser };
|
|
6534
6744
|
//# sourceMappingURL=module.js.map
|