@galacean/effects-plugin-model 2.0.0-alpha.2 → 2.0.0-alpha.21

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.
@@ -1,4 +1,4 @@
1
- import type { Composition, CameraOptionsEx, spec, VFXItem, VFXItemContent } from '@galacean/effects';
1
+ import type { Composition, CameraOptionsEx, spec, VFXItem } from '@galacean/effects';
2
2
  import { Transform } from '@galacean/effects';
3
3
  import type { CameraGestureHandler, CameraKeyEvent } from './protocol';
4
4
  import { CameraGestureType } from './protocol';
@@ -8,7 +8,7 @@ export declare class CameraGestureHandlerImp implements CameraGestureHandler {
8
8
  private cameraCoordiante;
9
9
  private startParams;
10
10
  constructor(composition: Composition);
11
- getItem(): VFXItem<VFXItemContent> | undefined;
11
+ getItem(): VFXItem | undefined;
12
12
  getCurrentTarget(): string;
13
13
  getCurrentType(): CameraGestureType;
14
14
  onKeyEvent(event: CameraKeyEvent): CameraOptionsEx;
@@ -1,3 +1,4 @@
1
1
  export * from './loader-helper';
2
- export * from './loader-impl';
3
2
  export * from './protocol';
3
+ export * from './json-converter';
4
+ export * from './loader-impl';
@@ -0,0 +1,53 @@
1
+ import { spec, Downloader } from '@galacean/effects';
2
+ import type { Engine, Player, Renderer, GeometryProps } from '@galacean/effects';
3
+ export declare class JSONConverter {
4
+ newScene: spec.JSONScene;
5
+ engine: Engine;
6
+ renderer: Renderer;
7
+ downloader: Downloader;
8
+ treeInfo: TreeInfo;
9
+ constructor(player: Player);
10
+ processScene(sceneData: string | Record<string | symbol, unknown>): Promise<spec.JSONScene>;
11
+ setImage(newScene: spec.JSONScene, oldScene: spec.JSONScene): void;
12
+ setTexture(newScene: spec.JSONScene, oldScene: spec.JSONScene): Promise<void>;
13
+ setComponent(newScene: spec.JSONScene, oldScene: spec.JSONScene): void;
14
+ setItem(newScene: spec.JSONScene, oldScene: spec.JSONScene): void;
15
+ setComposition(newScene: spec.JSONScene, oldScene: spec.JSONScene): void;
16
+ private loadJSON;
17
+ private loadBins;
18
+ private loadMipmapImage;
19
+ private createSkyboxComponent;
20
+ private createMeshComponent;
21
+ private createItemsFromTreeComponent;
22
+ private createLightComponent;
23
+ private createAnimationComponent;
24
+ private getMaterialData;
25
+ private setupMaterial;
26
+ private getTextureData;
27
+ private getTransformData;
28
+ private setupBoneData;
29
+ }
30
+ declare class TreeInfo {
31
+ tree2NodeList: Record<string, spec.VFXItemData[]>;
32
+ nodeList2Tree: Record<string, spec.VFXItemData>;
33
+ nodeId2Node: Record<string, spec.VFXItemData>;
34
+ node2Path: Record<string, string>;
35
+ add(treeItem: spec.VFXItemData, treeNodeList: spec.VFXItemData[]): void;
36
+ setNodePath(node: spec.VFXItemData): void;
37
+ getTreeNodeListByTreeId(id: string): spec.VFXItemData[];
38
+ getTreeNodeListByNodeId(id: string): spec.VFXItemData[];
39
+ getTreeItemByNodeId(id: string): spec.VFXItemData;
40
+ getTreeNode(treeId: string, nodeIndex: number): spec.VFXItemData;
41
+ getAllTreeNodeList(): spec.VFXItemData[];
42
+ getNodePath(id: string): string;
43
+ }
44
+ export interface ModelData {
45
+ vertices: spec.TypedArray;
46
+ uvs: spec.TypedArray;
47
+ normals: spec.TypedArray;
48
+ indices: spec.TypedArray;
49
+ name: string;
50
+ }
51
+ export declare function getGeometryDataFromOptions(geomOptions: GeometryProps): spec.GeometryData;
52
+ export declare function getGeometryDataFromPropsList(geomPropsList: GeometryProps[]): spec.GeometryData | undefined;
53
+ export {};
@@ -1,49 +1,18 @@
1
- import type { GLTFResources } from '@vvfx/resource-detection';
2
- import type { Player, spec } from '@galacean/effects';
1
+ import type { Player } from '@galacean/effects';
3
2
  import type { LoadSceneOptions, LoadSceneResult } from './protocol';
3
+ import { spec } from '@galacean/effects';
4
4
  import { LoaderImpl } from './loader-impl';
5
5
  export declare class LoaderImplEx extends LoaderImpl {
6
6
  loadScene(options: LoadSceneOptions): Promise<LoadSceneResult>;
7
- /**
8
- * 检查序列化和反序列逻辑,排查渲染场景中渲染正常和编辑器中渲染错误的问题。
9
- * 针对Image、Texture、Material、Mesh、Scene、Animation和IBL的检查。
10
- *
11
- * @param res 加载的GLTF场景资源
12
- */
13
- checkSerializer(res: GLTFResources): Promise<void>;
14
7
  }
15
- export interface LoadGLTFSceneOptions {
8
+ export interface LoadGLTFOptions {
16
9
  url: string;
17
10
  player: Player;
18
- playAnimation?: number | string;
11
+ playAnimation?: number;
12
+ playAllAnimation?: boolean;
19
13
  camera?: {
20
14
  position?: spec.vec3;
21
15
  rotation?: spec.vec3;
22
16
  };
23
17
  }
24
- export declare function loadGLTFScene(options: LoadGLTFSceneOptions): Promise<{
25
- compositionId: number;
26
- requires: never[];
27
- compositions: {
28
- name: string;
29
- id: number;
30
- duration: number;
31
- endBehavior: number;
32
- camera: {
33
- fov: number;
34
- far: number;
35
- near: number;
36
- position: number[];
37
- clipMode: number;
38
- };
39
- items: spec.BaseItem[];
40
- meta: {
41
- previewSize: number[];
42
- };
43
- }[];
44
- gltf: never[];
45
- images: never[];
46
- shapes: never[];
47
- plugins: string[];
48
- version: string;
49
- }>;
18
+ export declare function loadGLTF(options: LoadGLTFOptions): Promise<spec.JSONScene>;
@@ -1,56 +1,62 @@
1
- import type { Texture, Engine } from '@galacean/effects';
2
- import { spec, Geometry } from '@galacean/effects';
3
- import type { Loader, LoaderOptions, SkyboxType, LoadSceneOptions, LoadSceneResult } from './protocol';
4
- import type { ModelAnimationOptions, ModelCameraOptions, ModelMaterialOptions, ModelLightOptions, ModelSkyboxOptions, ModelTreeOptions } from '../index';
5
- import type { GLTFImage, GLTFMaterial, GLTFTexture, GLTFScene, GLTFPrimitive, GLTFTextureInfo, GLTFLight, GLTFCamera, GLTFAnimation, GLTFImageBasedLight } from '@vvfx/resource-detection';
6
- import { PSkyboxType } from '../runtime/skybox';
7
- import type { CubeImage } from '@vvfx/resource-detection/dist/src/gltf-tools/gltf-image-based-light';
8
- export declare function getDefaultEffectsGLTFLoader(engine: Engine, options?: LoaderOptions): Loader;
1
+ import { spec } from '@galacean/effects';
2
+ import type { TextureSourceOptions, math } from '@galacean/effects';
3
+ import type { SkyboxType, LoadSceneOptions, LoadSceneResult, Loader, ModelCamera, ModelLight, ModelSkybox, ModelImageLike } from './protocol';
4
+ import type { ModelMeshComponentData, ModelSkyboxComponentData, ModelTreeOptions, ModelLightComponentData, ModelCameraComponentData } from '../index';
5
+ import { PSkyboxType } from '../runtime';
6
+ import type { GLTFResources } from '@vvfx/resource-detection';
7
+ export interface LoaderOptions {
8
+ compatibleMode?: 'gltf' | 'tiny3d';
9
+ }
10
+ export declare function getDefaultEffectsGLTFLoader(options?: LoaderOptions): Loader;
9
11
  export declare function setDefaultEffectsGLTFLoader(loader: Loader): void;
10
12
  export declare class LoaderImpl implements Loader {
11
- private _sceneOptions;
12
- private _loaderOptions;
13
- private _gltfScene;
14
- private _gltfSkins;
15
- private _gltfMeshs;
16
- private _gltfLights;
17
- private _gltfCameras;
18
- private _gltfImages;
19
- private _gltfTextures;
20
- private _gltfMaterials;
21
- private _gltfAnimations;
22
- private _gltfImageBasedLights;
23
- private _textureManager?;
24
- private _skyboxOptions?;
25
- engine: Engine;
26
- initial(engine: Engine, options?: LoaderOptions): void;
27
- processLight(lights: GLTFLight[], fromGLTF: boolean): void;
28
- processCamera(cameras: GLTFCamera[], fromGLTF: boolean): void;
29
- processMaterial(materials: GLTFMaterial[], fromGLTF: boolean): void;
30
- createTreeOptions(scene: GLTFScene): ModelTreeOptions;
31
- createAnimations(animations: GLTFAnimation[]): ModelAnimationOptions[];
32
- createGeometry(primitive: GLTFPrimitive, hasSkinAnim: boolean): Geometry;
33
- createMaterial(material: GLTFMaterial): ModelMaterialOptions;
34
- createTexture2D(image: GLTFImage, texture: GLTFTexture, isBaseColor: boolean): Promise<Texture>;
35
- createTextureCube(cubeImages: CubeImage[], level0Size?: number): Promise<Texture>;
36
- createSkybox(ibl: GLTFImageBasedLight): Promise<ModelSkyboxOptions>;
37
- createDefaultSkybox(typeName: SkyboxType): Promise<ModelSkyboxOptions>;
38
- scaleColorVal(val: number, fromGLTF: boolean): number;
39
- scaleColorVec(vec: number[], fromGLTF: boolean): number[];
13
+ private sceneOptions;
14
+ private loaderOptions;
15
+ private gltfScene;
16
+ private gltfSkins;
17
+ private gltfMeshs;
18
+ private gltfLights;
19
+ private gltfCameras;
20
+ private gltfImages;
21
+ private gltfTextures;
22
+ private gltfMaterials;
23
+ private gltfAnimations;
24
+ private gltfImageBasedLights;
25
+ composition: spec.CompositionData;
26
+ timelineAssetId: string;
27
+ images: spec.Image[];
28
+ imageElements: ModelImageLike[];
29
+ textures: spec.TextureDefine[];
30
+ items: spec.VFXItemData[];
31
+ components: spec.ComponentData[];
32
+ materials: spec.MaterialData[];
33
+ shaders: spec.ShaderData[];
34
+ geometries: spec.GeometryData[];
35
+ animations: spec.AnimationClipData[];
36
+ sceneAABB: math.Box3;
37
+ constructor(composition?: spec.CompositionData);
40
38
  loadScene(options: LoadSceneOptions): Promise<LoadSceneResult>;
41
- private _preprocess;
42
- tryAddTexture2D(matIndex: number, texInfo: GLTFTextureInfo | undefined, isBaseColor: boolean): Promise<void> | undefined;
43
- getTexture2D(matIndex: number, texInfo: GLTFTextureInfo | undefined, isBaseColor: boolean, noWarning?: boolean): Texture | undefined;
44
- private _gltfData2PlayerData;
45
- private _createItemTree;
46
- private _createItemMesh;
47
- private _createItemLight;
48
- private _createItemCamera;
49
- private _createItemSkybox;
50
- private _computeSceneAABB;
51
- createLightOptions(light: GLTFLight): ModelLightOptions;
52
- createCameraOptions(camera: GLTFCamera): ModelCameraOptions | undefined;
53
- private _clear;
39
+ processGLTFResource(resource: GLTFResources, imageElements: ModelImageLike[]): void;
40
+ processComponentData(components: spec.EffectComponentData[]): void;
41
+ processLightComponentData(light: ModelLightComponentData): void;
42
+ processCameraComponentData(camera: ModelCameraComponentData): void;
43
+ processSkyboxComponentData(skybox: ModelSkyboxComponentData): void;
44
+ processMaterialData(material: spec.MaterialData): void;
45
+ processTextureOptions(options: TextureSourceOptions, isBaseColor: boolean, image?: ModelImageLike): void;
46
+ initial(options?: LoaderOptions): void;
47
+ checkMeshComponentData(mesh: ModelMeshComponentData, resource: GLTFResources): void;
48
+ processMaterialTexture(material: spec.MaterialData, textureName: string, isBaseColor: boolean, textureDataMap: Record<string, TextureSourceOptions>, imageElements: ModelImageLike[]): void;
49
+ getLoadResult(): LoadSceneResult;
50
+ addLight(data: ModelLight): void;
51
+ addCamera(camera: ModelCamera): void;
52
+ tryAddSkybox(skybox: ModelSkybox): Promise<void>;
53
+ createSkyboxComponentData(typeName: SkyboxType): {
54
+ imageList: spec.Image[];
55
+ textureOptionsList: TextureSourceOptions[];
56
+ component: spec.SkyboxComponentData;
57
+ };
58
+ private clear;
59
+ private computeSceneAABB;
54
60
  /**
55
61
  * 按照传入的动画播放参数,计算需要播放的动画索引
56
62
  *
@@ -61,8 +67,8 @@ export declare class LoaderImpl implements Loader {
61
67
  isPlayAnimation(): boolean;
62
68
  isPlayAllAnimation(): boolean;
63
69
  getRemarkString(): string;
70
+ getCompositionDuration(): number;
64
71
  isTiny3dMode(): boolean;
65
- getTextureManager(): TextureManager;
66
72
  getItemDuration(): number;
67
73
  getItemEndBehavior(): spec.ItemEndBehavior;
68
74
  getSkyboxType(): PSkyboxType | undefined;
@@ -70,15 +76,7 @@ export declare class LoaderImpl implements Loader {
70
76
  ignoreSkybox(): boolean;
71
77
  isEnvironmentTest(): boolean;
72
78
  }
73
- declare class TextureManager {
74
- private _owner;
75
- private _gltfImages;
76
- private _gltfTextures;
77
- private _textureMap;
78
- constructor(owner: LoaderImpl);
79
- initial(gltfImages: GLTFImage[], gltfTextures: GLTFTexture[]): void;
80
- dispose(): void;
81
- addTexture(matIndex: number, texIndex: number, tex: Texture, isBaseColor: boolean): void;
82
- getTexture(matIndex: number, texIndex: number, isBaseColor: boolean): Texture | undefined;
83
- }
84
- export {};
79
+ export declare function getPBRShaderProperties(): string;
80
+ export declare function getUnlitShaderProperties(): string;
81
+ export declare function getDefaultPBRMaterialData(): spec.MaterialData;
82
+ export declare function getDefaultUnlitMaterialData(): spec.MaterialData;
@@ -1,8 +1,6 @@
1
- import type { GLTFMaterial, GLTFPrimitive, GLTFLight, GLTFScene, GLTFImage, GLTFTexture, GLTFCamera, GLTFAnimation, GLTFImageBasedLight } from '@vvfx/resource-detection';
2
- import type { CubeImage } from '@vvfx/resource-detection/dist/src/gltf-tools/gltf-image-based-light';
3
- import type { GLTFResources } from '@vvfx/resource-detection/dist/src/gltf-tools';
4
- import type { spec, Renderer, Texture, Geometry } from '@galacean/effects';
5
- import type { ModelAnimationOptions, ModelMaterialOptions, ModelSkyboxOptions, ModelTreeOptions, ModelBaseItem } from '../index';
1
+ import type { GLTFResources } from '@vvfx/resource-detection';
2
+ import type { spec, TextureSourceOptions, EffectComponentData } from '@galacean/effects';
3
+ import type { ModelLightComponentData, ModelCameraComponentData, ModelSkyboxComponentData } from '../index';
6
4
  /**
7
5
  * glTF 场景文件加载选项,主要用于 Demo 测试或外部测试调用
8
6
  */
@@ -17,9 +15,9 @@ export interface LoadSceneOptions {
17
15
  */
18
16
  resource: string | Uint8Array | GLTFResources;
19
17
  /**
20
- * 兼容模式,目前只支持tiny3d
18
+ * 兼容模式,目前支持 gltf 和 tiny3d
21
19
  */
22
- compatibleMode?: 'gltf' | 'tiny3d' | 'oasis';
20
+ compatibleMode?: 'gltf' | 'tiny3d';
23
21
  /**
24
22
  * 检查ResourceDetection序列化和反序列逻辑
25
23
  */
@@ -38,10 +36,6 @@ export interface LoadSceneOptions {
38
36
  ignoreSkybox?: boolean;
39
37
  };
40
38
  effects: {
41
- /**
42
- * Renderer
43
- */
44
- renderer?: Renderer;
45
39
  /**
46
40
  * 播放时间,单位秒
47
41
  */
@@ -53,7 +47,7 @@ export interface LoadSceneOptions {
53
47
  /**
54
48
  * 播放动画索引或名称
55
49
  */
56
- playAnimation?: number | string;
50
+ playAnimation?: number;
57
51
  /**
58
52
  * 是否播放全部动画
59
53
  */
@@ -62,29 +56,57 @@ export interface LoadSceneOptions {
62
56
  }
63
57
  export interface LoadSceneResult {
64
58
  source: string;
65
- items: ModelBaseItem[];
59
+ jsonScene: spec.JSONScene;
66
60
  sceneAABB: {
67
61
  min: spec.vec3;
68
62
  max: spec.vec3;
69
63
  };
70
64
  }
71
- export interface LoaderOptions {
72
- compatibleMode?: 'gltf' | 'tiny3d' | 'oasis';
73
- }
74
65
  export type SkyboxType = 'NFT' | 'FARM';
66
+ export interface ModelCamera {
67
+ fov: number;
68
+ near: number;
69
+ far: number;
70
+ clipMode: spec.CameraClipMode;
71
+ name: string;
72
+ position: spec.vec3;
73
+ rotation: spec.vec3;
74
+ duration: number;
75
+ endBehavior: spec.ItemEndBehavior;
76
+ }
77
+ export interface ModelLight {
78
+ lightType: spec.LightType;
79
+ color: spec.ColorData;
80
+ intensity: number;
81
+ range?: number;
82
+ innerConeAngle?: number;
83
+ outerConeAngle?: number;
84
+ name: string;
85
+ position: spec.vec3;
86
+ rotation: spec.vec3;
87
+ scale: spec.vec3;
88
+ duration: number;
89
+ endBehavior: spec.ItemEndBehavior;
90
+ }
91
+ export interface ModelSkybox {
92
+ skyboxType?: string;
93
+ renderable?: boolean;
94
+ intensity?: number;
95
+ reflectionsIntensity?: number;
96
+ duration?: number;
97
+ }
98
+ export interface ModelImageLike {
99
+ name?: string;
100
+ width: number;
101
+ height: number;
102
+ }
75
103
  export interface Loader {
76
104
  loadScene(options: LoadSceneOptions): Promise<LoadSceneResult>;
77
- processLight(lights: GLTFLight[], fromGLTF: boolean): void;
78
- processCamera(cameras: GLTFCamera[], fromGLTF: boolean): void;
79
- processMaterial(materials: GLTFMaterial[], fromGLTF: boolean): void;
80
- createTreeOptions(scene: GLTFScene): ModelTreeOptions;
81
- createAnimations(animations: GLTFAnimation[]): ModelAnimationOptions[];
82
- createGeometry(primitive: GLTFPrimitive, hasSkinAnim: boolean): Geometry;
83
- createMaterial(material: GLTFMaterial): ModelMaterialOptions;
84
- createTexture2D(images: GLTFImage, textures: GLTFTexture, isBaseColor: boolean): Promise<Texture>;
85
- createTextureCube(cubeImages: CubeImage[], level0Size?: number): Promise<Texture>;
86
- createSkybox(ibl: GLTFImageBasedLight): Promise<ModelSkyboxOptions>;
87
- createDefaultSkybox(typeName: SkyboxType): Promise<ModelSkyboxOptions>;
88
- scaleColorVal(val: number, fromGLTF: boolean): number;
89
- scaleColorVec(vec: number[], fromGLTF: boolean): number[];
105
+ processGLTFResource(resource: GLTFResources, imageElements: ModelImageLike[]): void;
106
+ processComponentData(components: EffectComponentData[]): void;
107
+ processLightComponentData(light: ModelLightComponentData): void;
108
+ processCameraComponentData(camera: ModelCameraComponentData): void;
109
+ processSkyboxComponentData(skybox: ModelSkyboxComponentData): void;
110
+ processMaterialData(material: spec.MaterialData): void;
111
+ processTextureOptions(options: TextureSourceOptions, isBaseColor: boolean, image?: ModelImageLike): void;
90
112
  }
package/dist/index.d.ts CHANGED
@@ -34,6 +34,15 @@ export type ModelTreeOptions = spec.ModelTreeOptions<'studio'>;
34
34
  export type ModelTreeContent = spec.ModelTreeContent<'studio'>;
35
35
  export type ModelAnimTrackOptions = spec.ModelAnimTrackOptions<'studio'>;
36
36
  export type ModelAnimationOptions = spec.ModelAnimationOptions<'studio'>;
37
+ export type ModelMeshSkinData = spec.SkinData;
38
+ export type ModelMeshMorphData = spec.MorphData;
39
+ export type ModelMeshPrimitiveData = spec.PrimitiveData;
40
+ export type ModelMeshComponentData = spec.ModelMeshComponentData;
41
+ export type ModelLightType = spec.LightType;
42
+ export type ModelLightComponentData = spec.ModelLightComponentData;
43
+ export type ModelCameraComponentData = spec.ModelCameraComponentData;
44
+ export type ModelSkyboxComponentData = spec.SkyboxComponentData;
45
+ export type AnimationComponentData = spec.AnimationComponentData;
37
46
  export * from './gesture';
38
47
  export * from './gltf';
39
48
  export * from './plugin';