@galacean/effects-plugin-model 0.0.0-experimental-downgrade624-20240904

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 (61) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +26 -0
  3. package/dist/alipay.js +10163 -0
  4. package/dist/alipay.js.map +1 -0
  5. package/dist/alipay.mjs +10084 -0
  6. package/dist/alipay.mjs.map +1 -0
  7. package/dist/gesture/controller.d.ts +95 -0
  8. package/dist/gesture/index.d.ts +38 -0
  9. package/dist/gesture/protocol.d.ts +143 -0
  10. package/dist/gltf/index.d.ts +3 -0
  11. package/dist/gltf/loader-ext.d.ts +49 -0
  12. package/dist/gltf/loader-helper.d.ts +20 -0
  13. package/dist/gltf/loader-impl.d.ts +84 -0
  14. package/dist/gltf/protocol.d.ts +90 -0
  15. package/dist/helper/index.d.ts +2 -0
  16. package/dist/index.d.ts +37 -0
  17. package/dist/index.js +10171 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/index.min.js +9 -0
  20. package/dist/index.min.js.map +1 -0
  21. package/dist/index.mjs +10092 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/loader.d.ts +2 -0
  24. package/dist/loader.mjs +6212 -0
  25. package/dist/loader.mjs.map +1 -0
  26. package/dist/plugin/const.d.ts +2 -0
  27. package/dist/plugin/index.d.ts +6 -0
  28. package/dist/plugin/model-plugin.d.ts +48 -0
  29. package/dist/plugin/model-tree-item.d.ts +30 -0
  30. package/dist/plugin/model-tree-plugin.d.ts +13 -0
  31. package/dist/plugin/model-tree-vfx-item.d.ts +15 -0
  32. package/dist/plugin/model-vfx-item.d.ts +29 -0
  33. package/dist/runtime/anim-sampler.d.ts +13 -0
  34. package/dist/runtime/animation.d.ts +188 -0
  35. package/dist/runtime/cache.d.ts +34 -0
  36. package/dist/runtime/camera.d.ts +46 -0
  37. package/dist/runtime/common.d.ts +116 -0
  38. package/dist/runtime/index.d.ts +12 -0
  39. package/dist/runtime/light.d.ts +34 -0
  40. package/dist/runtime/material.d.ts +101 -0
  41. package/dist/runtime/math.d.ts +8 -0
  42. package/dist/runtime/mesh.d.ts +147 -0
  43. package/dist/runtime/object.d.ts +46 -0
  44. package/dist/runtime/scene.d.ts +133 -0
  45. package/dist/runtime/shader-libs/standard-shader-source.d.ts +3 -0
  46. package/dist/runtime/shader-libs/standard-shader.d.ts +6 -0
  47. package/dist/runtime/shader.d.ts +18 -0
  48. package/dist/runtime/shadow.d.ts +230 -0
  49. package/dist/runtime/skybox.d.ts +91 -0
  50. package/dist/utility/debug-helper.d.ts +7 -0
  51. package/dist/utility/hit-test-helper.d.ts +11 -0
  52. package/dist/utility/index.d.ts +6 -0
  53. package/dist/utility/plugin-helper.d.ts +197 -0
  54. package/dist/utility/ri-helper.d.ts +25 -0
  55. package/dist/utility/shader-helper.d.ts +13 -0
  56. package/dist/utility/ts-helper.d.ts +34 -0
  57. package/dist/weapp.js +10163 -0
  58. package/dist/weapp.js.map +1 -0
  59. package/dist/weapp.mjs +10084 -0
  60. package/dist/weapp.mjs.map +1 -0
  61. package/package.json +66 -0
@@ -0,0 +1,101 @@
1
+ import type { Material, Texture } from '@galacean/effects';
2
+ import { spec } from '@galacean/effects';
3
+ import type { ModelMaterialOptions, ModelMaterialUnlitOptions, ModelMaterialPBROptions } from '../index';
4
+ import { Vector3, Vector4, Matrix3 } from './math';
5
+ import { PMaterialType, PBlendMode, PFaceSideMode } from './common';
6
+ import { PObject } from './object';
7
+ export declare abstract class PMaterialBase extends PObject {
8
+ materialType: PMaterialType;
9
+ vertexShaderCode: string;
10
+ fragmentShaderCode: string;
11
+ /**
12
+ * 深度是否写入,默认是写入(true)
13
+ */
14
+ depthMask: boolean;
15
+ depthTestHint: boolean;
16
+ blendMode: PBlendMode;
17
+ alphaCutOff: number;
18
+ faceSideMode: PFaceSideMode;
19
+ getShaderFeatures(): string[];
20
+ updateUniforms(material: Material): void;
21
+ build(inFeatureList?: string[]): void;
22
+ getBlendMode(mode?: spec.MaterialBlending): PBlendMode;
23
+ getFaceSideMode(mode?: spec.SideMode): PFaceSideMode;
24
+ setMaterialStates(material: Material): void;
25
+ protected setFaceSideStates(material: Material): void;
26
+ dispose(): void;
27
+ isValid(): boolean;
28
+ isOpaque(): boolean;
29
+ isMasked(): boolean;
30
+ isTranslucent(): boolean;
31
+ isAdditive(): boolean;
32
+ requireBlend(): boolean;
33
+ isFrontFace(): boolean;
34
+ isBackFace(): boolean;
35
+ isBothFace(): boolean;
36
+ }
37
+ export declare class PMaterialUnlit extends PMaterialBase {
38
+ private baseColorFactor;
39
+ private baseColorTexture?;
40
+ create(options: ModelMaterialUnlitOptions): void;
41
+ dispose(): void;
42
+ getShaderFeatures(): string[];
43
+ updateUniforms(material: Material): void;
44
+ hasBaseColorTexture(): boolean;
45
+ getBaseColorTexture(): Texture;
46
+ setBaseColorTexture(val: Texture): void;
47
+ getBaseColorFactor(): Vector4;
48
+ setBaseColorFactor(val: Vector4 | spec.vec4): void;
49
+ }
50
+ export declare class PMaterialPBR extends PMaterialBase {
51
+ baseColorTexture?: Texture;
52
+ baseColorTextureTrans?: Matrix3;
53
+ baseColorFactor: Vector4;
54
+ metallicRoughnessTexture?: Texture;
55
+ metallicRoughnessTextureTrans?: Matrix3;
56
+ useSpecularAA: boolean;
57
+ metallicFactor: number;
58
+ roughnessFactor: number;
59
+ normalTexture?: Texture;
60
+ normalTextureTrans?: Matrix3;
61
+ normalTextureScale: number;
62
+ occlusionTexture?: Texture;
63
+ occlusionTextureTrans?: Matrix3;
64
+ occlusionTextureStrength: number;
65
+ emissiveTexture?: Texture;
66
+ emissiveTextureTrans?: Matrix3;
67
+ emissiveFactor: Vector3;
68
+ emissiveIntensity: number;
69
+ enableShadow: boolean;
70
+ create(options: ModelMaterialPBROptions): void;
71
+ dispose(): void;
72
+ getShaderFeatures(): string[];
73
+ updateUniforms(material: Material): void;
74
+ hasBaseColorTexture(): boolean;
75
+ hasBaseColorTextureTrans(): boolean;
76
+ setBaseColorTexture(val: Texture): void;
77
+ getBaseColorFactor(): Vector4;
78
+ setBaseColorFactor(val: Vector4 | spec.vec4): void;
79
+ hasMetallicRoughnessTexture(): boolean;
80
+ hasMetallicRoughnessTextureTrans(): boolean;
81
+ getMetallicRoughnessTexture(): Texture;
82
+ setMetallicRoughnessTexture(val: Texture): void;
83
+ hasNormalTexture(): boolean;
84
+ hasNormalTextureTrans(): boolean;
85
+ getNormalTexture(): Texture;
86
+ setNormalTexture(val: Texture): void;
87
+ hasOcclusionTexture(): boolean;
88
+ hasOcclusionTextureTrans(): boolean;
89
+ getOcclusionTexture(): Texture;
90
+ setOcclusionTexture(val: Texture): void;
91
+ hasEmissiveTexture(): boolean;
92
+ hasEmissiveTextureTrans(): boolean;
93
+ getEmissiveTexture(): Texture;
94
+ setEmissiveTexture(val: Texture): void;
95
+ hasEmissiveFactor(): boolean;
96
+ getEmissiveFactor(): Vector3;
97
+ setEmissiveFactor(val: Vector3 | spec.vec3): void;
98
+ }
99
+ export type PMaterial = PMaterialUnlit | PMaterialPBR;
100
+ export declare function createPluginMaterial(options: ModelMaterialOptions): PMaterial;
101
+ export declare function createInternalMaterial(options: {}): {};
@@ -0,0 +1,8 @@
1
+ import { math } from '@galacean/effects';
2
+ export declare const Vector2: typeof math.Vector2, Vector3: typeof math.Vector3, Vector4: typeof math.Vector4, Matrix3: typeof math.Matrix3, Matrix4: typeof math.Matrix4, Euler: typeof math.Euler, EulerOrder: typeof math.EulerOrder, Quaternion: typeof math.Quaternion, Box3: typeof math.Box3, Sphere: typeof math.Sphere, Ray: typeof math.Ray, DEG2RAD: number;
3
+ export type Vector2 = math.Vector2;
4
+ export type Vector3 = math.Vector3;
5
+ export type Vector4 = math.Vector4;
6
+ export type Matrix3 = math.Matrix3;
7
+ export type Matrix4 = math.Matrix4;
8
+ export type Quaternion = math.Quaternion;
@@ -0,0 +1,147 @@
1
+ import type { Geometry, Engine, math } from '@galacean/effects';
2
+ import { spec, Mesh, Material } from '@galacean/effects';
3
+ import type { ModelItemMesh, ModelMaterialOptions, ModelPrimitiveOptions } from '../index';
4
+ import { PShadowType } from './common';
5
+ import { PEntity } from './object';
6
+ import type { PMaterial } from './material';
7
+ import { Matrix4, Vector3, Box3 } from './math';
8
+ import { PSkin, PMorph } from './animation';
9
+ import type { PSceneStates } from './scene';
10
+ import type { PSkybox } from './skybox';
11
+ import type { PMaterialShadowBase, PShadowRuntimeOptions } from './shadow';
12
+ import type { ModelVFXItem } from '../plugin/model-vfx-item';
13
+ import { BoxMesh } from '../utility/ri-helper';
14
+ import type { ModelTreeVFXItem } from '../plugin';
15
+ type Box3 = math.Box3;
16
+ export declare class PMesh extends PEntity {
17
+ private engine;
18
+ /**
19
+ * 3D 元素父节点
20
+ */
21
+ parentIndex: number;
22
+ /**
23
+ * 元素的父节点
24
+ */
25
+ parentItem?: ModelTreeVFXItem;
26
+ /**
27
+ * 元素的父节点 Id
28
+ */
29
+ parentItemId?: string;
30
+ skin?: PSkin;
31
+ /**
32
+ * morph 动画状态数据,主要是 weights 数组
33
+ */
34
+ morph?: PMorph;
35
+ primitives: PPrimitive[];
36
+ hide: boolean;
37
+ priority: number;
38
+ boundingBox: Box3;
39
+ visBoundingBox: boolean;
40
+ boundingBoxMesh?: BoxMesh;
41
+ isBuilt: boolean;
42
+ isDisposed: boolean;
43
+ constructor(engine: Engine, itemMesh: ModelItemMesh, ownerItem?: ModelVFXItem, parentItem?: ModelTreeVFXItem);
44
+ build(lightCount: number, uniformSemantics: {
45
+ [k: string]: any;
46
+ }, skybox?: PSkybox): void;
47
+ tick(deltaSeconds: number): void;
48
+ addToRenderObjectSet(renderObjectSet: Set<Mesh>): void;
49
+ dispose(): void;
50
+ /**
51
+ * 更新 Morph 动画权重
52
+ * 每帧都会更新 Morph 动画权重,需要小心检查 Morph 动画参数
53
+ * 对于数组长度对不上的情况,直接报错
54
+ *
55
+ * @param weightsArray - Morph 动画的权重数组
56
+ */
57
+ updateMorphWeights(weightsArray: Float32Array): void;
58
+ updateParentItem(parentItem: ModelTreeVFXItem): void;
59
+ updateUniformsForScene(sceneStates: PSceneStates): void;
60
+ updateUniformForShadow(shadowOptions: PShadowRuntimeOptions): void;
61
+ hitTesting(rayOrigin: Vector3, rayDirection: Vector3): Vector3[];
62
+ computeBoundingBox(worldMatrix: Matrix4): Box3;
63
+ private getItemBoundingBox;
64
+ getParentId(): string | undefined;
65
+ get hasSkin(): boolean;
66
+ get mriMeshs(): Mesh[];
67
+ }
68
+ export declare class PPrimitive {
69
+ private engine;
70
+ /**
71
+ * 宿主 Mesh,包含了当前 Primitive
72
+ */
73
+ private parent?;
74
+ private skin?;
75
+ /**
76
+ * Morph 动画状态数据,来自 Mesh 对象,这里不创建不删除
77
+ */
78
+ private morph?;
79
+ private geometry;
80
+ private material;
81
+ private jointMatrixList?;
82
+ private jointNormalMatList?;
83
+ private jointMatrixTexture?;
84
+ private jointNormalMatTexture?;
85
+ name: string;
86
+ effectsMesh: Mesh;
87
+ effectsPriority: number;
88
+ boundingBox: math.Box3;
89
+ isCompressed: boolean;
90
+ shadowType: PShadowType;
91
+ shadowMesh?: Mesh;
92
+ shadowMaterial?: PMaterialShadowBase;
93
+ constructor(engine: Engine);
94
+ create(options: ModelPrimitiveOptions, parent: PMesh): void;
95
+ build(lightCount: number, uniformSemantics: {
96
+ [k: string]: any;
97
+ }, skybox?: PSkybox): void;
98
+ private getFeatureList;
99
+ addToRenderObjectSet(renderObjectSet: Set<Mesh>): void;
100
+ dispose(): void;
101
+ updateUniformsForScene(worldMatrix: Matrix4, nomralMatrix: Matrix4, sceneStates: PSceneStates): void;
102
+ updateUniformForShadow(shadowOpts: PShadowRuntimeOptions): void;
103
+ hitTesting(newOrigin: Vector3, newDirection: Vector3, worldMatrix: Matrix4, invWorldMatrix: Matrix4): number | undefined;
104
+ computeBoundingBox(inverseWorldMatrix: Matrix4): Box3;
105
+ /**
106
+ * 渲染输出模式转成 Shader 中的宏定义
107
+ *
108
+ * @param mode - 渲染输出模式
109
+ * @returns none 模式返回 undefined,其他模式返回相应宏定义
110
+ */
111
+ getRenderMode3DDefine(mode: spec.RenderMode3D): string | undefined;
112
+ private updateUniformsByAnimation;
113
+ private updateUniformsByScene;
114
+ hasSkin(): boolean;
115
+ getEffectsGeometry(): Geometry;
116
+ setGeometry(val: PGeometry | Geometry): void;
117
+ setMaterial(val: PMaterial | ModelMaterialOptions): void;
118
+ getModelMaterial(): Material;
119
+ getShadowModelMaterial(): Material | undefined;
120
+ isEnableShadow(): boolean;
121
+ isUnlitMaterial(): boolean;
122
+ /**
123
+ * 是否有 Morph 动画:
124
+ * 需要注意 Morph 对象存在,但还是没有 Morph 动画的情况
125
+ *
126
+ * @returns 返回是否有 Morph 动画
127
+ */
128
+ hasMorph(): boolean;
129
+ getWorldBoundingBox(): Box3;
130
+ }
131
+ export declare class PGeometry {
132
+ geometry: Geometry;
133
+ attributeNames: string[];
134
+ constructor(geometry: Geometry);
135
+ dispose(): void;
136
+ hasAttribute(name: string): boolean;
137
+ setHide(hide: boolean): void;
138
+ isCompressed(): boolean;
139
+ hasPositions(): boolean;
140
+ hasNormals(): boolean;
141
+ hasTangents(): boolean;
142
+ hasUVCoords(index: number): boolean;
143
+ hasColors(): boolean;
144
+ hasJoints(): boolean;
145
+ hasWeights(): boolean;
146
+ }
147
+ export {};
@@ -0,0 +1,46 @@
1
+ import type { spec, Mesh, math } from '@galacean/effects';
2
+ import type { ModelVFXItem } from '../plugin/model-vfx-item';
3
+ import type { BaseTransform } from '../index';
4
+ import type { Quaternion, Euler, Vector3, Matrix4 } from './math';
5
+ import { PObjectType, PTransform, PCoordinate } from './common';
6
+ import type { PSceneStates } from './scene';
7
+ type Euler = math.Euler;
8
+ export declare abstract class PObject {
9
+ name: string;
10
+ type: PObjectType;
11
+ dispose(): void;
12
+ isNone(): boolean;
13
+ isValid(): boolean;
14
+ protected genName(name: string): string;
15
+ }
16
+ export declare abstract class PEntity extends PObject {
17
+ private _visible;
18
+ private _transform;
19
+ deleted: boolean;
20
+ ownerItem?: ModelVFXItem;
21
+ tick(deltaSeconds: number): void;
22
+ onVisibleChanged(visible: boolean): void;
23
+ addToRenderObjectSet(renderObjectSet: Set<Mesh>): void;
24
+ updateUniformsForScene(sceneStates: PSceneStates): void;
25
+ /**
26
+ * 仅标记不可见和删除状态,但不进行 WebGL 相关资源的释放
27
+ * 最终释放 WebGL 相关资源是在 plugin destroy 的时候
28
+ */
29
+ onEntityRemoved(): void;
30
+ get visible(): boolean;
31
+ set visible(val: boolean);
32
+ get transform(): PTransform;
33
+ set transform(val: PTransform | BaseTransform);
34
+ get translation(): Vector3;
35
+ set translation(val: Vector3 | spec.vec3);
36
+ get position(): Vector3;
37
+ set position(val: Vector3 | spec.vec3);
38
+ get rotation(): Quaternion;
39
+ set rotation(val: Quaternion | Euler | Vector3 | spec.vec4 | spec.vec3);
40
+ get scale(): Vector3;
41
+ set scale(val: Vector3 | spec.vec3);
42
+ get matrix(): Matrix4;
43
+ set matrix(val: Matrix4);
44
+ get coordinate(): PCoordinate;
45
+ }
46
+ export {};
@@ -0,0 +1,133 @@
1
+ import type { RenderFrame, Mesh, Renderer, Texture, Engine, math, CameraOptionsEx } from '@galacean/effects';
2
+ import { spec } from '@galacean/effects';
3
+ import type { ModelItem, ModelVFXItem } from '../plugin/model-vfx-item';
4
+ import { PMesh } from './mesh';
5
+ import type { PCamera } from './camera';
6
+ import { PCameraManager } from './camera';
7
+ import { PLight, PLightManager } from './light';
8
+ import { Vector3, Matrix4, Box3 } from './math';
9
+ import { PSkybox } from './skybox';
10
+ import type { CompositionCache } from './cache';
11
+ import { PShadowManager } from './shadow';
12
+ import type { PEntity } from './object';
13
+ import { TwoStatesSet } from '../utility/ts-helper';
14
+ type Box3 = math.Box3;
15
+ type Vector2 = math.Vector2;
16
+ export interface PSceneOptions {
17
+ componentName: string;
18
+ renderer: Renderer;
19
+ sceneCache: CompositionCache;
20
+ wireframeOnly?: boolean;
21
+ runtimeEnv?: string;
22
+ compatibleMode?: string;
23
+ visBoundingBox?: boolean;
24
+ enableDynamicSort?: boolean;
25
+ renderMode3D?: spec.RenderMode3D;
26
+ renderMode3DUVGridSize?: number;
27
+ renderSkybox: boolean;
28
+ lightItemCount: number;
29
+ }
30
+ export interface PSceneStates {
31
+ deltaSeconds: number;
32
+ camera: PCamera;
33
+ cameraPosition: Vector3;
34
+ viewMatrix: Matrix4;
35
+ projectionMatrix: Matrix4;
36
+ viewProjectionMatrix: Matrix4;
37
+ winSize: Vector2;
38
+ sceneRadius: number;
39
+ shadowMapSizeInv?: Vector2;
40
+ lightViewMatrix?: Matrix4;
41
+ lightProjectionMatrix?: Matrix4;
42
+ lightViewProjectionMatrix?: Matrix4;
43
+ lightList: PLight[];
44
+ maxLightCount: number;
45
+ skybox?: PSkybox;
46
+ }
47
+ export declare class PSceneManager {
48
+ compName: string;
49
+ itemList: PEntity[];
50
+ meshList: PMesh[];
51
+ lightManager: PLightManager;
52
+ cameraManager: PCameraManager;
53
+ shadowManager: PShadowManager;
54
+ /**
55
+ * 是否动态排序 Mesh 渲染优先级
56
+ * 默认 false,需要和 Tiny 对齐时为 true
57
+ */
58
+ enableDynamicSort: boolean;
59
+ brdfLUT?: Texture;
60
+ skybox?: PSkybox;
61
+ tickCount: number;
62
+ lastTickSecond: number;
63
+ /**
64
+ * 当前场景包围盒缓存,在阴影渲染中使用
65
+ */
66
+ sceneAABBCache: Box3;
67
+ /**
68
+ * 场景前帧和当前帧渲染的 Mesh 集合
69
+ */
70
+ renderedMeshSet: TwoStatesSet<Mesh>;
71
+ /**
72
+ * 场景中所有渲染过的 Mesh 集合
73
+ */
74
+ allRenderedMeshSet: Set<Mesh>;
75
+ private renderer?;
76
+ private sceneCache?;
77
+ private parentId2Mesh;
78
+ private maxLightCount;
79
+ private renderSkybox;
80
+ private engine;
81
+ constructor(engine: Engine);
82
+ initial(opts: PSceneOptions): void;
83
+ private initGlobalState;
84
+ private clean;
85
+ dispose(): void;
86
+ addItem(item: ModelVFXItem): void;
87
+ removeItem(item: ModelVFXItem): void;
88
+ updateDefaultCamera(camera: CameraOptionsEx): void;
89
+ buildItem(item: ModelItem): void;
90
+ /**
91
+ * 编译运行时需要的 Shader 代码,包括 PBR、天空盒与阴影。
92
+ */
93
+ private build;
94
+ tick(deltaTime: number): void;
95
+ /**
96
+ * 更新 RI 帧对象中默认 Pass 的渲染队列
97
+ * 如果是动态排序模式,需要重新添加所有的 mesh,这样优先级才能生效
98
+ * 如果是正常模式,那就增量添加和删除
99
+ *
100
+ * @param frame - RI 帧对象
101
+ */
102
+ updateDefaultRenderPass(frame: RenderFrame): void;
103
+ /**
104
+ * 动态调整 Mesh 渲染优先级
105
+ * 主要是为了和 Tiny 渲染对齐,正常渲染不进行调整
106
+ *
107
+ * @param states - 场景中的状态数据
108
+ */
109
+ dynamicSortMeshes(states: PSceneStates): void;
110
+ /**
111
+ * 查询场景中的 Mesh
112
+ * 通过 parentId 查询 Mesh 对象,可能找不到 Mesh 对象
113
+ *
114
+ * @param parentId - Item 中定义的 parentId
115
+ * @returns 查询到的 PMesh,或者是没找到。如果 Mesh 不可见,也是没找到。
116
+ */
117
+ queryMesh(parentId: string): PMesh | undefined;
118
+ /**
119
+ * 删除 RenderFrame DefaultRenderPass 中添加的 Mesh,Player 要执行 Reset 操作
120
+ *
121
+ * @param renderFrame - 当前渲染帧对象
122
+ */
123
+ removeAllMeshesFromDefaultPass(renderFrame: RenderFrame): void;
124
+ getSceneAABB(box?: Box3): Box3;
125
+ printDebugInfo(): void;
126
+ getRenderer(): Renderer;
127
+ getSceneCache(): CompositionCache;
128
+ get activeCamera(): PCamera;
129
+ get lightCount(): number;
130
+ get shaderLightCount(): number;
131
+ get enableShadowPass(): boolean;
132
+ }
133
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare namespace StandardShaderSource {
2
+ function build(source: string, features: string[], isWebGL2: boolean): string;
3
+ }
@@ -0,0 +1,6 @@
1
+ import type { PShaderContext } from '../shader';
2
+ export declare class StandardShader {
3
+ static environment: string;
4
+ static getVertexShaderCode(context: PShaderContext): string;
5
+ static getFragmentShaderCode(context: PShaderContext): string;
6
+ }
@@ -0,0 +1,18 @@
1
+ import type { PMaterialBase } from './material';
2
+ export interface PShaderContext {
3
+ material: PMaterialBase;
4
+ isWebGL2: boolean;
5
+ featureList: string[];
6
+ }
7
+ export interface PShaderResults {
8
+ vertexShaderCode: string;
9
+ fragmentShaderCode: string;
10
+ }
11
+ export type ShaderCodeFuncType = (context: PShaderContext) => PShaderResults;
12
+ export declare class PShaderManager {
13
+ private funcMap;
14
+ private static _instance;
15
+ static getInstance(): PShaderManager;
16
+ private constructor();
17
+ genShaderCode(context: PShaderContext): PShaderResults;
18
+ }
@@ -0,0 +1,230 @@
1
+ import type { RenderFrame, Mesh, Material, RenderPass, SemanticMap, Renderer, Engine } from '@galacean/effects';
2
+ import { math } from '@galacean/effects';
3
+ import { Matrix4, Vector2, Box3 } from './math';
4
+ import type { PShadowType } from './common';
5
+ import type { PMesh, PPrimitive } from './mesh';
6
+ import { PMaterialBase } from './material';
7
+ import type { PLight } from './light';
8
+ import type { PSceneManager, PSceneStates } from './scene';
9
+ import { FBOOptions } from '../utility/ri-helper';
10
+ import { TwoStatesSet } from '../utility/ts-helper';
11
+ type Box3 = math.Box3;
12
+ export interface PMaterialShadowBaseOptions {
13
+ name: string;
14
+ shadowType: PShadowType;
15
+ }
16
+ export declare class PMaterialShadowBase extends PMaterialBase {
17
+ shadowType: PShadowType;
18
+ create(options: PMaterialShadowBaseOptions): void;
19
+ getShaderFeatures(): string[];
20
+ updateUniforms(material: Material): void;
21
+ }
22
+ export declare class PMaterialShadowBaseTest extends PMaterialBase {
23
+ shadowType: PShadowType;
24
+ create(options: PMaterialShadowBaseOptions): void;
25
+ getShaderFeatures(): string[];
26
+ updateUniforms(material: Material): void;
27
+ }
28
+ export interface PMaterialShadowFilterOptions {
29
+ name: string;
30
+ blurScale: Vector2;
31
+ }
32
+ export declare class PMaterialShadowFilter extends PMaterialBase {
33
+ blurScale: Vector2;
34
+ create(options: PMaterialShadowFilterOptions): void;
35
+ getShaderFeatures(): string[];
36
+ updateUniforms(material: Material): void;
37
+ }
38
+ /**
39
+ * 阴影初始化选项,包括控制选项和纹理选项
40
+ */
41
+ export interface PShadowInitOptions {
42
+ /**
43
+ * 控制相关的参数
44
+ */
45
+ enable?: boolean;
46
+ quality?: 'low' | 'medium' | 'high';
47
+ softness?: number;
48
+ /**
49
+ * 纹理相关的参数
50
+ */
51
+ width?: number;
52
+ height?: number;
53
+ type?: GLenum;
54
+ format?: GLenum;
55
+ filter?: GLenum;
56
+ }
57
+ /**
58
+ * 阴影运行时选项,包括 light 的变换矩阵和柔软度
59
+ */
60
+ export interface PShadowRuntimeOptions {
61
+ viewProjectionMatrix: Matrix4;
62
+ softness: number;
63
+ }
64
+ export declare class PShadowManager {
65
+ /**
66
+ * 是否启用阴影效果,会根据硬件等情况进行设置
67
+ */
68
+ enable: boolean;
69
+ /**
70
+ * 阴影质量参数,一般都用 medium
71
+ */
72
+ quality: 'low' | 'medium' | 'high';
73
+ /**
74
+ * 阴影柔软度,范围[0, 2]
75
+ */
76
+ softness: number;
77
+ /**
78
+ * 阴影纹理相关参数
79
+ */
80
+ width: number;
81
+ height: number;
82
+ type: GLenum;
83
+ format: GLenum;
84
+ filter: GLenum;
85
+ /**
86
+ * shadow map 渲染时 FBO
87
+ */
88
+ baseFBOOpts: FBOOptions;
89
+ /**
90
+ * shadow map 滤波时 FBO
91
+ */
92
+ filterFBOOpts: FBOOptions;
93
+ /**
94
+ * 是否激活运行时阴影
95
+ */
96
+ runtimeEnable: boolean;
97
+ /**
98
+ * 启用阴影效果的 Mesh 列表,来自场景中的 Mesh 列表
99
+ */
100
+ meshList: PMesh[];
101
+ /**
102
+ * 当前帧启用阴影效果的 Primitive 列表,来自上面的 Mesh 列表
103
+ */
104
+ primitiveList: PPrimitive[];
105
+ viewAABB: Box3;
106
+ sceneAABB: Box3;
107
+ shadowAABB: Box3;
108
+ shadowLight?: PLight;
109
+ lightView: Matrix4;
110
+ lightProjection: Matrix4;
111
+ lightViewProjection: Matrix4;
112
+ renderer?: Renderer;
113
+ sceneManager: PSceneManager;
114
+ xFilterMaterial: PMaterialShadowFilter;
115
+ yFilterMaterial: PMaterialShadowFilter;
116
+ basePass?: RenderPass;
117
+ xFilterPass?: RenderPass;
118
+ yFilterPass?: RenderPass;
119
+ /**
120
+ * Primitive 与 RenderPass 的前一帧与当前帧状态缓存
121
+ */
122
+ meshCacheSet: TwoStatesSet<Mesh>;
123
+ renderPassCacheSet: TwoStatesSet<RenderPass>;
124
+ engine: Engine;
125
+ constructor();
126
+ initial(sceneManager: PSceneManager, options?: PShadowInitOptions): void;
127
+ build(): void;
128
+ tick(sceneStates: PSceneStates): void;
129
+ /**
130
+ * 更新当前阴影物体的包围盒数据
131
+ * TODO: 需要注意动画物体的包围盒更新
132
+ */
133
+ private updateAABBInfo;
134
+ private updateLightViewProjection;
135
+ private updateDirectionalLightViewProjection;
136
+ private updateSpotLightViewProjection;
137
+ private getShadowOptions;
138
+ private updateShadowUniforms;
139
+ private getShadowLight;
140
+ /**
141
+ * 统计场景中启用阴影的 Primitive 数目
142
+ *
143
+ * @param sceneManager - Model 场景的场景管理器
144
+ * @returns 启用阴影的 Primitve 数目
145
+ */
146
+ private getShadowPrimitiveCount;
147
+ /**
148
+ * 更新阴影渲染时 Pass 中渲染的对象,注意阴影有 3 个渲染 Pass
149
+ * 开始时 Frame 中没有阴影 Pass,会先添加阴影 Pass
150
+ *
151
+ * @param frame - RI 帧对象
152
+ */
153
+ updateRenderPass(frame: RenderFrame): void;
154
+ updateFrameSemantics(map: SemanticMap, addSemantic: boolean): void;
155
+ /**
156
+ * 是否启用了阴影效果
157
+ * 是否有需要启用阴影效果的物体,以及当前硬件是否支持启用阴影效果
158
+ * @return 是否启用
159
+ */
160
+ isEnable(): boolean;
161
+ /**
162
+ * 是否有需要渲染的对象,需要先启用阴影
163
+ * @return 是否有渲染对象
164
+ */
165
+ hasRenderObject(): boolean;
166
+ /**
167
+ * 在当前 PMesh 列表中,查找需要在阴影 Pass 中渲染的 Primitive
168
+ *
169
+ * @returns 当前阴影 Pass 要渲染的 Primitive 列表
170
+ */
171
+ getCurrentPrimitiveList(): PPrimitive[];
172
+ isSupportTextureOptions(): boolean;
173
+ /**
174
+ * 根据当前阴影参数生成 BasePass 的 FBO 对象
175
+ *
176
+ * @returns BasePass 的 FBO 对象
177
+ */
178
+ getBaseFBOOptions(): FBOOptions;
179
+ /**
180
+ * 根据当前阴影参数生成 FilterPass 的 FBO 对象
181
+ *
182
+ * @returns FilterPass 的 FBO 对象
183
+ */
184
+ getFilterFBOOptions(): FBOOptions;
185
+ /**
186
+ * 返回 softness 值,并检查是否在指定范围内
187
+ *
188
+ * @param options - 阴影相关的初始化参数
189
+ * @returns 阴影柔软度值
190
+ */
191
+ getSoftness(options?: PShadowInitOptions): number;
192
+ /**
193
+ * 返回贴图大小,并检查是否在指定范围内
194
+ *
195
+ * @param options - 阴影相关的初始化参数
196
+ * @returns 阴影贴图大小
197
+ */
198
+ getTextureSize(options?: PShadowInitOptions): [number, number];
199
+ /**
200
+ * 返回纹理类型,并检查是否指定类型
201
+ *
202
+ * @param options - 阴影相关的初始化参数
203
+ * @returns 纹理类型
204
+ */
205
+ getTextureType(options?: PShadowInitOptions): GLenum;
206
+ /**
207
+ * 返回纹理格式,并检查是否指定格式
208
+ *
209
+ * @param options - 阴影相关的初始化参数
210
+ * @returns 纹理格式
211
+ */
212
+ getTextureFormat(options?: PShadowInitOptions): GLenum;
213
+ /**
214
+ * 返回纹理滤波格式,并检查是否指定滤波格式
215
+ *
216
+ * @param options - 阴影相关的初始化参数
217
+ * @returns 纹理滤波格式
218
+ */
219
+ getTextureFilter(options?: PShadowInitOptions): GLenum;
220
+ get mainPassUniformSemantics(): {
221
+ u_ShadowSampler: string;
222
+ };
223
+ get basePassName(): string;
224
+ get xFilterPassName(): string;
225
+ get yFilterPassName(): string;
226
+ get xFilterMeshName(): string;
227
+ get yFilterMeshName(): string;
228
+ get shadowPassList(): RenderPass[];
229
+ }
230
+ export {};