import type { Engine, math, VFXItem, Renderer, Geometry } from '@galacean/effects'; import { spec, Material } from '@galacean/effects'; import type { ModelMeshComponentData } from '../index'; import { PEntity } from './object'; import type { PMaterial } from './material'; import { Matrix4, Vector3, Box3 } from './math'; import { PSkin, PMorph } from './animation'; import type { PSceneManager, PSceneStates } from './scene'; import type { PSkybox } from './skybox'; import { BoxMesh } from '../utility/ri-helper'; import type { ModelMeshComponent } from '../plugin/model-item'; type Box3 = math.Box3; /** * Mesh 类,负责 Mesh 相关的骨骼动画和 PBR 渲染 */ export declare class PMesh extends PEntity { private engine; /** * 所属的 Mesh 组件 */ owner?: ModelMeshComponent; /** * 父节点索引 */ parentIndex: number; /** * 父元素 */ parentItem?: VFXItem; /** * 父元素索引 */ parentItemId?: string; rootBoneItem?: VFXItem; /** * 蒙皮 */ skin?: PSkin; /** * morph 动画状态数据,主要是 weights 数组 */ morph?: PMorph; /** * primitive 对象数组 */ subMeshes: PSubMesh[]; /** * 是否隐藏,默认是隐藏 */ hide: boolean; /** * 优先级 */ priority: number; /** * 包围盒 */ boundingBox: Box3; /** * 是否显示包围盒 */ visBoundingBox: boolean; /** * 包围盒 Mesh */ boundingBoxMesh?: BoxMesh; /** * 是否调用 Build */ isBuilt: boolean; /** * 是否销毁 */ isDisposed: boolean; /** * 构造函数,创建 Mesh 对象,并与所属组件和父元素相关联 * @param engine - 引擎 * @param name - 名称 * @param meshData - Mesh 参数 * @param owner - 所属的 Mesh 组件 * @param parentId - 父元素索引 * @param parent - 父元素 */ constructor(engine: Engine, name: string, meshData: ModelMeshComponentData, owner: ModelMeshComponent, parentId?: string, parent?: VFXItem); /** * 创建 GE 的 Mesh、Geometry 和 Material 对象 * @param scene - 场景管理器 * @returns */ build(scene: PSceneManager): void; /** * 更新变换数据和蒙皮数据 */ update(): void; /** * 更新骨骼动画 */ lateUpdate(): void; /** * 渲染 Mesh 对象,需要将内部相关数据传给渲染器 * @param scene - 场景 * @param renderer - 渲染器 */ render(scene: PSceneManager, renderer: Renderer): void; /** * 销毁,需要主动释放蒙皮、morph 和 Mesh 等相关的对象 * @returns */ dispose(): void; /** * 更新 Morph 动画权重 * 每帧都会更新 Morph 动画权重,需要小心检查 Morph 动画参数 * 对于数组长度对不上的情况,直接报错 * * @param weightsArray - Morph 动画的权重数组 */ updateMorphWeights(weightsArray: Float32Array): void; /** * 更新父 VFX 元素 * @param parentId - 父元素索引 * @param parentItem - 父 VFX 元素 */ updateParentInfo(parentId: string, parentItem: VFXItem): void; /** * 根据当前场景状态更新内部材质数据 * @param scene - 场景管理器 */ updateMaterial(scene: PSceneManager): void; /** * 点击测试,对于编辑器模式会进行精准的点击测试,否则就和内部的包围盒进行测试 * @param rayOrigin - 射线原点 * @param rayDirection - 射线方向 * @returns 交点列表 */ hitTesting(rayOrigin: Vector3, rayDirection: Vector3): Vector3[]; /** * 计算包围盒,根据传入的世界矩阵 * @param worldMatrix - 世界矩阵 * @returns */ computeBoundingBox(worldMatrix: Matrix4): Box3; private getItemBoundingBox; /** * 获取父节点 id * @returns */ getParentId(): string | undefined; /** * 是否有蒙皮 */ get hasSkin(): boolean; } /** * PSubMesh 类,负责 Sub Mesh相关的功能,支持骨骼动画和 PBR 渲染 */ export declare class PSubMesh { private engine; /** * 宿主 Mesh,包含了当前 Primitive */ private parent?; private skin?; /** * Morph 动画状态数据,来自 Mesh 对象,这里不创建不删除 */ private morph?; private geometry; private material; private jointMatrixList?; private jointNormalMatList?; private jointMatrixTexture?; private jointNormalMatTexture?; /** * 名称 */ name: string; /** * 渲染优先级 */ effectsPriority: number; /** * 包围盒 */ boundingBox: math.Box3; /** * 是否压缩,模式不压缩 */ isCompressed: boolean; constructor(engine: Engine); /** * 创建 Primitive 对象 * @param data - Primitive 参数 * @param parent - 所属 Mesh 对象 */ create(geometry: Geometry, material: Material, parent: PMesh): void; /** * 创建 GE Mesh、Geometry 和 Material 对象,用于后面的渲染 * @param lightCount - 灯光数目 * @param skybox - 天空盒 */ build(lightCount: number, skybox?: PSkybox): void; private getFeatureList; private getMacroList; /** * 销毁,需要释放创建的 GE 对象 */ dispose(): void; /** * 更新内部 GE 材质着色器 Uniform 数据,根据场景状态 * @param worldMatrix - 世界矩阵 * @param nomralMatrix - 法线矩阵 * @param sceneStates - 场景状态 */ updateMaterial(worldMatrix: Matrix4, nomralMatrix: Matrix4, sceneStates: PSceneStates): void; /** * 点击测试,先进行简单的包围合测试,然后再计算精准的点击测试,这个测试非常耗时不要在移动端上使用 * @param newOrigin - 射线原点 * @param newDirection - 射线方向 * @param worldMatrix - 世界矩阵 * @param invWorldMatrix - 逆世界矩阵 * @returns 射线的 t 参数 */ hitTesting(newOrigin: Vector3, newDirection: Vector3, worldMatrix: Matrix4, invWorldMatrix: Matrix4): number | undefined; /** * 计算包围盒 * @param inverseWorldMatrix - 逆世界矩阵 * @returns */ computeBoundingBox(inverseWorldMatrix: Matrix4): Box3; /** * 渲染输出模式转成着色器中的宏定义 * @param mode - 渲染输出模式 * @returns 返回相应的宏定义 */ getRenderMode3DDefine(mode: spec.RenderMode3D): string | undefined; private updateUniformsByAnimation; private updateUniformsByScene; /** * 是否有蒙皮 * @returns */ hasSkin(): boolean; /** * 获取 GE 几何体 * @returns */ getEffectsGeometry(): Geometry; /** * 设置几何体 * @param val - 插件或 GE 几何体 */ setGeometry(val: PGeometry | Geometry): void; /** * 设置材质 * @param val - 插件材质对象或材质参数 */ setMaterial(val: PMaterial | Material): void; /** * 获取 GE 材质 * @returns */ getEffectsMaterial(): Material; /** * 是否无光照材质 * @returns */ isUnlitMaterial(): boolean; /** * 是否有 Morph 动画: * 需要注意 Morph 对象存在,但还是没有 Morph 动画的情况 * @returns 返回是否有 Morph 动画 */ hasMorph(): boolean; /** * 获取世界坐标下的包围盒 * @returns */ getWorldBoundingBox(): Box3; } /** * 3D 几何类 */ export declare class PGeometry { geometry: Geometry; /** * 属性名称数组 */ attributeNames: string[]; /** * 创建 3D 几何体,根据 GE 几何体 * @param geometry - GE 几何体 */ constructor(geometry: Geometry); /** * 销毁 */ dispose(): void; /** * 是否有某个属性 * @param name - 属性名 * @returns */ hasAttribute(name: string): boolean; /** * 设置隐藏,通过修改几何体中的渲染数目 * @param hide - 隐藏值 */ setHide(hide: boolean): void; /** * 是否压缩格式 * @returns */ isCompressed(): boolean; /** * 是否有位置属性 * @returns */ hasPositions(): boolean; /** * 是否有法线属性 * @returns */ hasNormals(): boolean; /** * 是否有切线属性 * @returns */ hasTangents(): boolean; /** * 是否有纹理坐标属性 * @param index - 纹理坐标索引 * @returns */ hasUVCoords(index: number): boolean; /** * 是否有颜色属性 * @returns */ hasColors(): boolean; /** * 是否有关节点属性 * @returns */ hasJoints(): boolean; /** * 是否有权重属性 * @returns */ hasWeights(): boolean; } export interface MacroInfo { name: string; value?: boolean | number; } export {};