@galacean/engine-loader 2.0.0-alpha.14 → 2.0.0-alpha.16

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/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Utils, AssetPromise, AnimationClip, AnimationEvent, Loader, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ModelMesh, BlendShape, Entity, Transform, Texture2D, ReferResource, DiffuseMode, BackgroundMode, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, BufferAsset, GLCapabilityType, TextureCube, TextureCubeFace, Logger, TextureFormat, ContentRestorer, AmbientLight, TextureFilterMode, Font, SystemInfo, Animator, IndexFormat, VertexElementFormat, request, InterpolationType, SkinnedMeshRenderer, PBRMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, TextureUtils, AnimatorStateMachine, JSONAsset, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, TextAsset, AudioClip, AudioManager, ShaderFactory, ShaderLib, PhysicsMaterial, RenderTarget, Scene, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
1
+ import { Utils, AssetPromise, AnimationClip, AnimationEvent, Loader, AnimationStringCurve, Keyframe, AnimationBoolCurve, AnimationRefCurve, AnimationQuaternionCurve, AnimationColorCurve, AnimationVector4Curve, AnimationVector3Curve, AnimationVector2Curve, AnimationFloatArrayCurve, AnimationArrayCurve, AnimationFloatCurve, ModelMesh, BlendShape, Signal, Entity, Transform, Texture2D, ReferResource, DiffuseMode, BackgroundMode, resourceLoader, AssetType, AnimatorController, AnimatorControllerLayer, AnimatorStateTransition, BufferAsset, GLCapabilityType, TextureCube, TextureCubeFace, Logger, TextureFormat, ContentRestorer, AmbientLight, TextureFilterMode, Font, SystemInfo, Animator, IndexFormat, VertexElementFormat, request, InterpolationType, SkinnedMeshRenderer, PBRMaterial, TextureCoordinate, RenderFace, VertexElement, Buffer, BufferBindFlag, BufferUsage, Camera, MeshRenderer, Skin, TextureWrapMode as TextureWrapMode$1, TextureUtils, AnimatorStateMachine, JSONAsset, Shader, Material, PrimitiveMesh, SpriteAtlas, Sprite, TextAsset, AudioClip, AudioManager, ShaderFactory, ShaderLib, PhysicsMaterial, RenderTarget, Scene, DirectLight, PointLight, SpotLight, UnlitMaterial } from '@galacean/engine-core';
2
2
  import { Quaternion, Vector4, Color, Vector3, Vector2, MathUtil, SphericalHarmonics3, BoundingBox, Matrix, Rect } from '@galacean/engine-math';
3
3
  import { GLCompressedTextureInternalFormat } from '@galacean/engine-rhi-webgl';
4
4
 
@@ -799,6 +799,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
799
799
  }
800
800
  });
801
801
  };
802
+ _proto.parseSignal = function parseSignal(signalRef) {
803
+ var _this = this;
804
+ var signal = new Signal();
805
+ return Promise.all(signalRef.listeners.map(function(listener) {
806
+ return Promise.all([
807
+ _this.parseBasicType(listener.target),
808
+ listener.arguments ? Promise.all(listener.arguments.map(function(a) {
809
+ return _this.parseBasicType(a);
810
+ })) : Promise.resolve([])
811
+ ]).then(function(param) {
812
+ var target = param[0], resolvedArgs = param[1];
813
+ if (target) {
814
+ var _signal;
815
+ (_signal = signal).on.apply(_signal, [].concat([
816
+ target,
817
+ listener.methodName
818
+ ], resolvedArgs));
819
+ }
820
+ });
821
+ })).then(function() {
822
+ return signal;
823
+ });
824
+ };
802
825
  _proto.parseBasicType = function parseBasicType(value, originValue) {
803
826
  var _this = this;
804
827
  if (Array.isArray(value)) {
@@ -823,11 +846,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
823
846
  return resource;
824
847
  });
825
848
  } else if (ReflectionParser._isComponentRef(value)) {
826
- var _this__context_components_get;
827
- return Promise.resolve((_this__context_components_get = this._context.components.get(value.componentId)) != null ? _this__context_components_get : null);
849
+ var entity = this._resolveEntityByPath(value.entityPath);
850
+ if (!entity) return Promise.resolve(null);
851
+ var type = Loader.getClass(value.componentType);
852
+ if (!type) return Promise.resolve(null);
853
+ var _entity_getComponents_value_componentIndex;
854
+ return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
828
855
  } else if (ReflectionParser._isEntityRef(value)) {
829
- // entity reference
830
- return Promise.resolve(this._context.entityMap.get(value.entityId));
856
+ return Promise.resolve(this._resolveEntityByPath(value.entityPath));
857
+ } else if (ReflectionParser._isSignalRef(value)) {
858
+ return this.parseSignal(value);
831
859
  } else if (originValue) {
832
860
  var _this2, _loop = function(key) {
833
861
  if (key === "methods") {
@@ -883,6 +911,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
883
911
  return Promise.resolve(entity);
884
912
  }
885
913
  };
914
+ _proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
915
+ var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
916
+ if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
917
+ var entity = entityMap.get(rootIds[entityPath[0]]);
918
+ for(var i = 1; i < entityPath.length; i++){
919
+ if (!entity || entityPath[i] >= entity.children.length) return null;
920
+ entity = entity.children[entityPath[i]];
921
+ }
922
+ return entity;
923
+ };
886
924
  ReflectionParser._isClass = function _isClass(value) {
887
925
  return value["class"] !== undefined;
888
926
  };
@@ -893,10 +931,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
893
931
  return value["url"] !== undefined;
894
932
  };
895
933
  ReflectionParser._isEntityRef = function _isEntityRef(value) {
896
- return value["entityId"] !== undefined;
934
+ return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
897
935
  };
898
936
  ReflectionParser._isComponentRef = function _isComponentRef(value) {
899
- return value["ownerId"] !== undefined && value["componentId"] !== undefined;
937
+ return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
938
+ };
939
+ ReflectionParser._isSignalRef = function _isSignalRef(value) {
940
+ return value["listeners"] !== undefined;
900
941
  };
901
942
  ReflectionParser._isMethodObject = function _isMethodObject(value) {
902
943
  return Array.isArray(value == null ? void 0 : value.params);
@@ -1130,6 +1171,13 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1130
1171
  for(var i = 0, l = entities.length; i < l; i++){
1131
1172
  entityMap.set(entitiesConfig[i].id, entities[i]);
1132
1173
  }
1174
+ // Build rootIds in serialization order (not async completion order)
1175
+ var rootIds = _this.context.rootIds;
1176
+ for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
1177
+ if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
1178
+ rootIds.push(entitiesConfig[i1].id);
1179
+ }
1180
+ }
1133
1181
  return entities;
1134
1182
  });
1135
1183
  };
@@ -1255,7 +1303,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1255
1303
  _proto._parseEntity = function _parseEntity(entityConfig, engine) {
1256
1304
  var transform = entityConfig.transform;
1257
1305
  var entity = new Entity(engine, entityConfig.name, transform ? Loader.getClass(transform.class) : Transform);
1258
- if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
1259
1306
  this._addEntityPlugin(entityConfig.id, entity);
1260
1307
  return Promise.resolve(entity);
1261
1308
  };
@@ -1268,7 +1315,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1268
1315
  }).then(function(prefabResource) {
1269
1316
  var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
1270
1317
  var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
1271
- if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
1272
1318
  _this._generateInstanceContext(entity, instanceContext, "");
1273
1319
  _this._prefabContextMap.set(entity, instanceContext);
1274
1320
  var cbArray = _this._prefabPromiseMap.get(entityConfig.id);