@galacean/engine-loader 1.2.0-beta.5 → 1.3.0-alpha.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-loader",
3
- "version": "1.2.0-beta.5",
3
+ "version": "1.3.0-alpha.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -15,9 +15,9 @@
15
15
  "types/**/*"
16
16
  ],
17
17
  "dependencies": {
18
- "@galacean/engine-math": "1.2.0-beta.5",
19
- "@galacean/engine-rhi-webgl": "1.2.0-beta.5",
20
- "@galacean/engine-core": "1.2.0-beta.5"
18
+ "@galacean/engine-core": "1.3.0-alpha.0",
19
+ "@galacean/engine-math": "1.3.0-alpha.0",
20
+ "@galacean/engine-rhi-webgl": "1.3.0-alpha.0"
21
21
  },
22
22
  "scripts": {
23
23
  "b:types": "tsc"
@@ -0,0 +1,5 @@
1
+ import { AssetPromise, Loader, LoadItem, ResourceManager } from "@galacean/engine-core";
2
+ import { PrefabResource } from "./prefab/PrefabResource";
3
+ export declare class PrefabLoader extends Loader<PrefabResource> {
4
+ load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<PrefabResource>;
5
+ }
@@ -1,6 +1,6 @@
1
1
  import { AnimationClip, AnimatorController, Camera, Engine, Entity, Light, Material, ModelMesh, ReferResource, Skin, Texture2D } from "@galacean/engine-core";
2
2
  /**
3
- * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
3
+ * The glTF resource.
4
4
  */
5
5
  export declare class GLTFResource extends ReferResource {
6
6
  /** glTF file url. */
@@ -694,7 +694,7 @@ export interface IScene extends IChildRootProperty {
694
694
  /**
695
695
  * The indices of each root node
696
696
  */
697
- nodes: number[];
697
+ nodes?: number[];
698
698
  }
699
699
  /**
700
700
  * Joints and matrices defining a skin
package/types/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import "./BufferLoader";
4
4
  import "./EnvLoader";
5
5
  import "./FontLoader";
6
6
  import "./GLTFLoader";
7
+ import "./PrefabLoader";
7
8
  import "./HDRLoader";
8
9
  import "./JSONLoader";
9
10
  import "./KTXCubeLoader";
@@ -27,3 +28,5 @@ export * from "./gltf";
27
28
  export { KTX2Loader, KTX2Transcoder } from "./ktx2/KTX2Loader";
28
29
  export { KTX2TargetFormat } from "./ktx2/KTX2TargetFormat";
29
30
  export * from "./resource-deserialize";
31
+ export * from "./prefab/PrefabResource";
32
+ export { PrefabLoader } from "./PrefabLoader";
@@ -0,0 +1,11 @@
1
+ import { Engine, Entity } from "@galacean/engine-core";
2
+ import { HierarchyParser } from "../resource-deserialize/resources/parser/HierarchyParser";
3
+ import { PrefabResource } from "./PrefabResource";
4
+ import { IHierarchyFile, ParserContext } from "../resource-deserialize";
5
+ export declare class PrefabParser extends HierarchyParser<PrefabResource, ParserContext<IHierarchyFile, Entity>> {
6
+ readonly prefabResource: PrefabResource;
7
+ static parse(engine: Engine, url: string, data: IHierarchyFile): Promise<PrefabResource>;
8
+ constructor(data: IHierarchyFile, context: ParserContext<IHierarchyFile, Entity>, prefabResource: PrefabResource);
9
+ protected _handleRootEntity(id: string): void;
10
+ protected _clearAndResolve(): PrefabResource;
11
+ }
@@ -0,0 +1,25 @@
1
+ import { Engine, Entity, ReferResource } from "@galacean/engine-core";
2
+ /**
3
+ * The Prefab resource.
4
+ */
5
+ export declare class PrefabResource extends ReferResource {
6
+ readonly url: string;
7
+ /** @internal */
8
+ _root: Entity;
9
+ private _dependenceAssets;
10
+ /**
11
+ * @internal
12
+ * @param url - The url of the prefab
13
+ */
14
+ constructor(engine: Engine, url: string);
15
+ /**
16
+ * Instantiate prefab.
17
+ * @returns prefab's root entity
18
+ */
19
+ instantiate(): Entity;
20
+ /**
21
+ * @internal
22
+ */
23
+ _addDependenceAsset(resource: ReferResource): void;
24
+ protected _onDestroy(): void;
25
+ }
@@ -2,7 +2,6 @@ import { Engine } from "@galacean/engine-core";
2
2
  export { MeshDecoder } from "./resources/mesh/MeshDecoder";
3
3
  export { Texture2DDecoder } from "./resources/texture2D/TextureDecoder";
4
4
  export { ReflectionParser } from "./resources/parser/ReflectionParser";
5
- export { PrefabParser } from "./resources/prefab/PrefabParser";
6
5
  export * from "./resources/animationClip/AnimationClipDecoder";
7
6
  export type { IModelMesh } from "./resources/mesh/IModelMesh";
8
7
  /**
@@ -1,9 +1,11 @@
1
- import { Entity, Engine, Scene } from "@galacean/engine-core";
2
- import type { IPrefabFile } from "../schema";
1
+ import { Engine, Scene } from "@galacean/engine-core";
2
+ import type { IHierarchyFile } from "../schema";
3
3
  import { ReflectionParser } from "./ReflectionParser";
4
4
  import { ParserContext } from "./ParserContext";
5
+ import { PrefabResource } from "../../../prefab/PrefabResource";
5
6
  /** @Internal */
6
- export default abstract class HierarchyParser<T extends Scene | Entity, V extends ParserContext<IPrefabFile, T>> {
7
+ export declare abstract class HierarchyParser<T extends Scene | PrefabResource, V extends ParserContext<IHierarchyFile, T>> {
8
+ readonly data: IHierarchyFile;
7
9
  readonly context: V;
8
10
  /**
9
11
  * The promise of parsed object.
@@ -13,24 +15,24 @@ export default abstract class HierarchyParser<T extends Scene | Entity, V extend
13
15
  protected _reject: (reason: any) => void;
14
16
  protected _engine: Engine;
15
17
  protected _reflectionParser: ReflectionParser;
16
- private prefabContextMap;
17
- private prefabPromiseMap;
18
- constructor(context: V);
18
+ private _prefabContextMap;
19
+ private _prefabPromiseMap;
20
+ constructor(data: IHierarchyFile, context: V);
19
21
  /** start parse the scene or prefab or others */
20
22
  start(): void;
21
- protected abstract handleRootEntity(id: string): void;
23
+ protected abstract _handleRootEntity(id: string): void;
24
+ protected abstract _clearAndResolve(): Scene | PrefabResource;
22
25
  private _parseEntities;
23
26
  private _parseComponents;
24
27
  private _parsePrefabModification;
25
28
  private _parsePrefabRemovedEntities;
26
29
  private _parsePrefabRemovedComponents;
27
- private _clearAndResolve;
28
30
  private _organizeEntities;
29
31
  private _getEntityByConfig;
30
32
  private _parseEntity;
31
- private _parseGLTF;
33
+ private _parsePrefab;
32
34
  private _parseStrippedEntity;
33
35
  private _parseChildren;
34
36
  private _applyEntityData;
35
- private _traverseAddEntityToMap;
37
+ private _generateInstanceContext;
36
38
  }
@@ -1,29 +1,30 @@
1
- import { Component, EngineObject, Entity, ResourceManager } from "@galacean/engine-core";
2
- import type { IEntity } from "../schema";
1
+ import { Component, Engine, EngineObject, Entity, ReferResource, ResourceManager, Scene } from "@galacean/engine-core";
2
+ import type { IEntity, IHierarchyFile } from "../schema";
3
+ export declare enum ParserType {
4
+ Prefab = 0,
5
+ Scene = 1
6
+ }
3
7
  /**
4
8
  * Parser context
5
9
  * @export
6
- * @abstract
7
10
  * @class ParserContext
8
11
  * @template T
9
12
  * @template I
10
13
  */
11
- export declare class ParserContext<T extends Object, I extends EngineObject> {
12
- readonly originalData: T;
13
- readonly engine: any;
14
- target?: I;
14
+ export declare class ParserContext<T extends IHierarchyFile, I extends EngineObject> {
15
+ readonly engine: Engine;
16
+ readonly type: ParserType;
17
+ readonly resource: ReferResource | Scene;
15
18
  entityMap: Map<string, Entity>;
16
- components: Map<string, Component>;
17
- assets: Map<string, any>;
18
19
  entityConfigMap: Map<string, IEntity>;
20
+ components: Map<string, Component>;
19
21
  rootIds: string[];
20
22
  strippedIds: string[];
21
23
  readonly resourceManager: ResourceManager;
22
- constructor(originalData: T, engine: any, target?: I);
24
+ constructor(engine: Engine, type: ParserType, resource: ReferResource | Scene);
23
25
  /**
24
26
  * Destroy the context.
25
- * @abstract
26
27
  * @memberof ParserContext
27
28
  */
28
- destroy(): void;
29
+ clear(): void;
29
30
  }
@@ -1,11 +1,11 @@
1
1
  import { EngineObject, Entity } from "@galacean/engine-core";
2
- import type { IBasicType, IClassObject, IEntity, IPrefabFile } from "../schema";
2
+ import type { IBasicType, IClassObject, IEntity, IHierarchyFile } from "../schema";
3
3
  import { ParserContext } from "./ParserContext";
4
4
  export declare class ReflectionParser {
5
5
  private readonly _context;
6
6
  static customParseComponentHandles: Map<string, Function>;
7
7
  static registerCustomParseComponent(componentType: string, handle: Function): void;
8
- constructor(_context: ParserContext<IPrefabFile, EngineObject>);
8
+ constructor(_context: ParserContext<IHierarchyFile, EngineObject>);
9
9
  parseEntity(entityConfig: IEntity): Promise<Entity>;
10
10
  parseClassObject(item: IClassObject): Promise<any>;
11
11
  parsePropsAndMethods(instance: any, item: Omit<IClassObject, "class">): Promise<any>;
@@ -1,9 +1,10 @@
1
1
  import { Engine, Scene } from "@galacean/engine-core";
2
2
  import type { IScene } from "../schema";
3
- import { SceneParserContext } from "./SceneParserContext";
4
- import HierarchyParser from "../parser/HierarchyParser";
3
+ import { HierarchyParser } from "../parser/HierarchyParser";
4
+ import { ParserContext } from "../parser/ParserContext";
5
5
  /** @Internal */
6
- export declare class SceneParser extends HierarchyParser<Scene, SceneParserContext> {
6
+ export declare class SceneParser extends HierarchyParser<Scene, ParserContext<IScene, Scene>> {
7
+ readonly scene: Scene;
7
8
  /**
8
9
  * Parse scene data.
9
10
  * @param engine - the engine of the parser context
@@ -11,5 +12,7 @@ export declare class SceneParser extends HierarchyParser<Scene, SceneParserConte
11
12
  * @returns a promise of scene
12
13
  */
13
14
  static parse(engine: Engine, sceneData: IScene): Promise<Scene>;
14
- protected handleRootEntity(id: string): void;
15
+ constructor(data: IScene, context: ParserContext<IScene, Scene>, scene: Scene);
16
+ protected _handleRootEntity(id: string): void;
17
+ protected _clearAndResolve(): Scene;
15
18
  }
@@ -20,7 +20,7 @@ export interface IColor {
20
20
  b: number;
21
21
  a: number;
22
22
  }
23
- export interface IPrefabFile {
23
+ export interface IHierarchyFile {
24
24
  entities: Array<IEntity>;
25
25
  }
26
26
  export type IMethodParams = Array<IBasicType>;
@@ -1,16 +1,17 @@
1
- import { BackgroundMode, DiffuseMode, FogMode, ShadowCascadesMode, ShadowResolution } from "@galacean/engine-core";
1
+ import { BackgroundMode, BackgroundTextureFillMode, DiffuseMode, FogMode, ShadowCascadesMode, ShadowResolution } from "@galacean/engine-core";
2
2
  import type { IReferable } from "@galacean/engine-core/types/asset/IReferable";
3
- import type { IColor, IPrefabFile, IVector3 } from "./BasicSchema";
3
+ import type { IColor, IHierarchyFile, IVector3 } from "./BasicSchema";
4
4
  export declare enum SpecularMode {
5
5
  Sky = "Sky",
6
6
  Custom = "Custom"
7
7
  }
8
- export interface IScene extends IPrefabFile {
8
+ export interface IScene extends IHierarchyFile {
9
9
  scene: {
10
10
  background: {
11
11
  mode: BackgroundMode;
12
12
  color: IColor;
13
13
  texture?: IReferable;
14
+ textureFillMode?: BackgroundTextureFillMode;
14
15
  skyMesh?: IReferable;
15
16
  skyMaterial?: IReferable;
16
17
  };