import type { Scene, Attribute, GeometryProps, TextureSourceOptions, TextureSourceCubeData, TextureConfigOptions, Engine, math, RenderPass } from '@galacean/effects'; import { Player, spec, Transform, Material, Mesh, Texture, Geometry } from '@galacean/effects'; import type { GLTFCamera, GLTFImage, GLTFLight, GLTFTexture } from '@vvfx/resource-detection'; import type { ModelAnimationOptions, ModelMeshOptions, ModelMaterialOptions, ModelLightOptions, ModelCameraOptions, ModelSkyboxOptions, ModelSkinOptions, ModelPrimitiveOptions, ModelTextureTransform, ModelTreeOptions, ModelAnimTrackOptions, ModelMeshComponent } from '../index'; import type { PMaterialBase, PImageBufferData } from '../runtime'; import { Matrix3, Matrix4, Vector3, Vector4 } from '../runtime'; type Box3 = math.Box3; type VertexArray = Float32Array | Int32Array | Int16Array | Int8Array | Uint32Array | Uint16Array | Uint8Array; /** * WebGL 辅助类,负责 WebGL 相关对象的创建 */ export declare class WebGLHelper { /** * 立方体纹理参数 */ static cubemapTexConfig: TextureConfigOptions; /** * 立方体纹理参数,带 Mipmap 滤波 */ static cubemapMipTexConfig: TextureConfigOptions; /** * 创建二维纹理对象 * @param engine - 引擎 * @param image - glTF 图像参数 * @param texture - glTF 纹理参数 * @param isBaseColor - 是否基础颜色 * @param tiny3dMode - 是否 Tiny3d 模式 * @returns 二维纹理对象 */ static createTexture2D(engine: Engine, image: GLTFImage, texture: GLTFTexture, isBaseColor?: boolean, tiny3dMode?: boolean): Promise; /** * 创建纹理对象列表 * @param engine - 引擎 * @param images - glTF 图像列表 * @param textures - glTF 纹理参数列表 * @returns 纹理对象列表 */ static createTextureList(engine: Engine, images: GLTFImage[], textures: GLTFTexture[]): Promise; /** * 获取立方体纹理数据 * @param images - 图像数据列表 * @returns */ static getTextureCubeData(images: PImageBufferData[]): Promise; /** * 获取立方体纹理 Mipmap 数据 * @param images - 图像数据二维列表 * @returns 立方体纹理数据 */ static getTextureCubeMipmapData(images: PImageBufferData[][]): Promise; /** * 从 URL 创建立方体纹理 * @param engine - 引擎 * @param cubeImage - 立方体图像 URL * @returns 纹理对象 */ static createTextureCubeFromURL(engine: Engine, cubeImage: string[]): Promise; /** * 从 URL 创建带 Mipmap 立方体纹理 * @param engine - 引擎 * @param cubeImages - 立方体 Mipmap 图像 URL * @returns 纹理对象 */ static createTextureCubeMipmapFromURL(engine: Engine, cubeImages: string[][]): Promise; /** * 从缓冲区创建立方体纹理 * @param engine - 引擎 * @param cubeImages - 图像缓冲区数据列表 * @returns 纹理对象 */ static createTextureCubeFromBuffer(engine: Engine, cubeImages: PImageBufferData[]): Promise; /** * 从缓冲区创建带 Mipmap 立方体纹理 * @param engine - 引擎 * @param cubeImages - 图像缓冲区数据二维列表 * @param level0Size - 第 0 层 Mip 的图像大小 * @returns 纹理对象 */ static createTextureCubeMipmapFromBuffer(engine: Engine, cubeImages: PImageBufferData[][], level0Size: number): Promise; /** * 获取纹理对象 * @param index - 索引 * @param textures - 纹理数组 * @returns 纹理获取或 undefined */ static getTexture(index: number, textures: Texture[]): Texture | null; /** * 从图像创建纹理 * @param engine - 引擎 * @param image - HTML 图像元素 * @returns */ static createTextureFromImage(engine: Engine, image: HTMLImageElement | HTMLCanvasElement): Texture; /** * 删除纹理 * @param texture - 纹理对象 */ static deleteTexture(texture: Texture): void; /** * 删除 Mesh * @param mesh - Mesh 对象 */ static deleteMesh(mesh: Mesh): void; /** * 删除几何 * @param geometry - 几何体 */ static deleteGeometry(geometry: Geometry): void; /** * 删除渲染 Pass * @param pass - 渲染 Pass */ static deleteRenderPass(pass: RenderPass): void; /** * 返回 Mesh 是否半透明 * @param component - ModelMeshComponent 对象 * @return 是否半透明 */ static isTransparentMesh(component: ModelMeshComponent): boolean; /** * renderer 是否支持 Float 纹理 * @param engine - 引擎对象 * @returns */ static isSupportFloatTexture(engine: Engine): boolean; /** * renderer 是否支持 HalfFloat 纹理 * @returns */ static isSupportHalfFloatTexture(engine: Engine): boolean; /** * 是否 2 的幂次 * @param v - 数值 * @returns */ static isPow2(v: number): boolean; } /** * Mesh 辅助类,负责 Mesh 相关的基础对象创建 */ export declare class MeshHelper { /** * 创建滤波 Mesh * @param engine - 引擎 * @param name - 名称 * @param material - 3D 材质 * @returns Mesh 对象 */ static createFilterMesh(engine: Engine, name: string, material: PMaterialBase): Mesh; /** * 获取平面的几何参数 * @returns 几何参数 */ static getPlaneGeometry(): GeometryProps; /** * 获取平面顶点数组 * @returns 浮点数组 */ static getPlaneVertexArray(): Float32Array; } export interface EffectsSceneInfo { loadSkybox?: boolean; } /** * 3D 插件辅助类,为插件提供基础的函数 */ export declare class PluginHelper { /** * 创建 3D 灯光参数,从 glTF 灯光参数 * @param light - glTF 灯光参数 * @returns 3D 灯光参数 */ static createLightOptions(light: GLTFLight): ModelLightOptions; /** * 创建 3D 相机参数,从 glTF 相机参数 * @param camera - glTF 相机参数 * @returns 3D 相机参数 */ static createCameraOptions(camera: GLTFCamera): ModelCameraOptions | undefined; /** * 转成播放器中 [0, 255] 区间的颜色值 * @param color - RGB 颜色值 * @returns RGB 颜色值 */ static toPlayerColor3(color: spec.vec3): spec.vec3; /** * 转成播放器中 [0, 255] 区间的颜色值 * @param color - RGBA 颜色值 * @returns RGBA 颜色值 */ static toPlayerColor4(color: spec.vec4): spec.vec4; /** * 转成插件中 [0, 1] 区间的颜色值 * @param color - RGB 颜色值 * @returns RGB 颜色值 */ static toPluginColor3(color: spec.vec3): spec.vec3; /** * 转成插件中 [0, 1] 区间的颜色值 * @param color - RGBA 颜色值 * @returns RGBA 颜色值 */ static toPluginColor4(color: spec.vec4): spec.vec4; /** * 创建 UV 变换矩阵,从 UV 变换参数中 * @param stValue - UV 的缩放和平移参数 * @param rotateValue - UV 的旋转参数 * @returns 3阶变换矩阵 */ static createUVTransform(material: Material, stName: string, rotateName: string): Matrix3; /** * 获取截断后的数值 * @param val - 数值 * @param minv - 最小值 * @param maxv - 最大值 * @returns */ static clamp(val: number, minv: number, maxv: number): number; /** * 转换成 [0, 255] 区间数值 * @param val - [0, 1] 区间数值 * @returns */ static scaleTo255(val: number): number; /** * 转换成 [0, 1] 区间数值 * @param val - [0, 255] 区间数值 * @returns */ static scaleTo1(val: number): number; /** * 根据相机的位置、Y 轴旋转角度和目标点位置来计算相机变换, * 使得相机能够专注于目标点上 * @param cameraPosition - 相机位置 * @param YRotationAngle - Y 轴旋转角度 * @param targetPoint - 目标点 * @returns 相机变换 */ static focusOnPoint(cameraPosition: spec.vec3, YRotationAngle: number, targetPoint: spec.vec3): Transform; /** * 场景预处理,在移动端 3D 插件会对场景进行预处理,调整纹理参数 * @param scene - 场景 * @param runtimeEnv - 运行时环境 * @param compatibleMode - 兼容模式 * @param autoAdjustScene - 是否自动调整 * @returns 场景信息描述 */ static preprocessScene(scene: Scene, runtimeEnv: string, compatibleMode: string): EffectsSceneInfo; /** * 纹理参数预处理,设置环绕模式和滤波器 * @param index - 纹理索引 * @param textures - 纹理数组 * @param isBaseColor - 是否基础颜色 * @param tiny3dMode - 是否 Tiny3d 模式 * @returns */ static preprocessTextureOptions(dataMap: Record, textureInfo: spec.MaterialTextureProperty | spec.DataPath, isBaseColor: boolean, tiny3dMode: boolean): void; /** * 创建几何体,根据几何参数描述 JSON 和数据数组 * @param engine - 引擎 * @param geomJson - 几何参数描述 JSON * @param bins - 数据数组 * @returns 几何体 */ static createGeometry(engine: Engine, geomJson: spec.GeometryOptionsJSON, bins: ArrayBuffer[]): Geometry; /** * 索引数组类型转换 * @param type - 类型 * @param array - 索引数组 * @returns 索引数组 */ static getIndexArray(type: number, array: spec.TypedArray): Uint32Array | Uint8Array | Uint16Array | undefined; /** * 属性名称转换 * @param name - 旧名称 * @returns 新名称 */ static getAttributeName(name: string): string; /** * 获取纹理对象 * @param textures - 纹理数组 * @param index - 索引 * @returns */ static getTextureObj(textures: Texture[], index?: number): Texture | null; } /** * Web 辅助类,负责 Web 相关的基础功能 */ export declare class WebHelper { /** * 获取图像文件名,从 URL 链接中 * @param url - 链接 * @param ext - 扩展名 * @returns */ static getImageFileName(url: string, ext?: string): string; /** * 获取当前时间字符串 * @returns */ static getCurrnetTimeStr(): string; /** * 将 URL 链接保存成文件 * @param url - 链接 * @param filename - 文件名 */ static saveFileForURL(url: string, filename: string): void; /** * 创建播放器 * @param manualRender - 是否手动渲染 * @returns */ static createPlayer(manualRender?: boolean): Player; /** * 休眠 * @param ms - 时间,单位是毫秒 * @returns */ static sleep(ms: number): Promise; /** * 从 glTF 图像加载 HTML 图像元素 * @param image - glTF 图像 * @returns HTML 图像元素 */ static loadImageFromGLTFImage(image: GLTFImage): Promise; /** * 从图像缓存区数据加载 HTML 图像元素 * @param image - 图像缓冲区数据 * @returns */ static loadImageFromImageData(image: PImageBufferData): Promise; /** * 获取画布渲染的内容,转成 PNG 图片数据 * @param canvas - HTML 画布元素 * @returns PNG 图片数据 */ static getCanvasArrayBuffer(canvas: HTMLCanvasElement): Promise; /** * 从 HTML 图像、视频或位图图像对象获取图像数据 * @param image - HTML 图像、视频或位图图像 * @returns PNG 图片数据 */ static getImageArrayBuffer(image: HTMLImageElement | ImageBitmap | HTMLVideoElement): Promise; /** * 获取画布元素渲染结果 * @param canvas - 画布元素 * @returns */ static getCanvasImageData(canvas: HTMLCanvasElement): ImageData; /** * 翻转图像 * @param imageData - 图像数据 * @returns 翻转后的图像 */ static flipImageData(imageData: ImageData): ImageData; /** * 从 HTML 图像、视频或位图图像对象获取翻转后的图像数据 * @param image - HTML 图像、视频或位图图像 * @returns PNG 图片数据 */ static getImageData(image: HTMLImageElement | ImageBitmap | HTMLVideoElement): ImageData; /** * 获取位图数据,从 HTML 画布元素 * @param canvas - HTML 画布元素 * @returns uint8 数组 */ static getWebGLCanvasImageBuffer(canvas: HTMLCanvasElement): Uint8Array; } /** * 顶点属性缓冲区 */ export declare class VertexAttribBuffer { /** * 顶点数组 */ data: VertexArray; /** * 分量数 */ component: number; /** * 长度 */ length: number; /** * 偏移 */ offset: number; /** * 步长 */ stride: number; /** * 类型大小 */ typeSize: number; /** * 获取包围盒,根据顶点数据 * @param box - 包围盒,会被修改 * @returns 包围盒 */ getBoundingBox(box: Box3): math.Box3; } declare class AttributeArray { data: spec.TypedArray; length: number; offset: number; stride: number; typeSize: number; compCount: number; signed: boolean; compressed: boolean; compressScale: number; create(inAttrib: Attribute, inArray: spec.TypedArray): void; getData(index: number): [number, number, number, number] | undefined; getLength(): number; } /** * 几何包围盒代理类 */ export declare class GeometryBoxProxy { /** * 渲染开始索引 */ drawStart: number; /** * 渲染索引数目 */ drawCount: number; /** * 索引数组 */ index?: spec.TypedArray; /** * 位置数组 */ position: AttributeArray; /** * 关节点数组 */ joint?: AttributeArray; /** * 权重数组 */ weight?: AttributeArray; /** * 绑定矩阵数组 */ bindMatrices: Matrix4[]; /** * 创建函数,根据几何体和绑定矩阵数组 * @param geometry - 几何体 * @param bindMatrices - 绑定矩阵数组 */ create(geometry: Geometry, bindMatrices: Matrix4[]): void; /** * 获取包围盒,如果有骨骼动画,需要先更新位置 * @param box - 包围盒,会被修改 * @returns 包围盒 */ getBoundingBox(box: Box3): math.Box3; } /** * 点击测试代理类, */ export declare class HitTestingProxy { /** * 渲染开始索引 */ drawStart: number; /** * 渲染索引数目 */ drawCount: number; /** * 索引数组 */ index?: spec.TypedArray; /** * 位置数组 */ position: AttributeArray; /** * 关节点数组 */ joint?: AttributeArray; /** * 权重数组 */ weight?: AttributeArray; /** * 是否双面 */ doubleSided: boolean; /** * 绑定矩阵数组 */ bindMatrices: Matrix4[]; /** * 是否有动画 */ hasAnimation: boolean; /** * 蒙皮矩阵 */ skinMatrix: math.Matrix4; /** * 创建对象,传入几何体、是否双面和绑定矩阵列表 * @param geometry - 几何体 * @param doubleSided - 是否双面 * @param bindMatrices - 绑定矩阵列表 */ create(geometry: Geometry, doubleSided: boolean, bindMatrices: Matrix4[]): void; /** * 点击测试,返回射线参数值 * @param rayOrigin - 射线原点 * @param rayDirection - 射线方向 * @returns 射线参数值或 undefined */ getHitPoint(rayOrigin: Vector3, rayDirection: Vector3): number | undefined; /** * 获取顶点位置 * @param index - 顶点索引 * @param vec3 - 顶点位置,会被修改和返回 * @param vec4 - 临时变量,用于骨骼动画时的计算 * @returns 顶点位置 */ getPosition(index: number, vec3: Vector3, vec4: Vector4): Vector3 | null; } /** * 检查辅助类,负责 3D 插件元素数据格式检查和报错 */ export declare class CheckerHelper { /** * 检查数值 * @param v - 数值 * @returns */ static checkNumber(v: number): boolean; /** * 检查数值或未定义 * @param v - 数值或未定义 * @returns */ static checkNumberUndef(v?: number): boolean; /** * 检查 0 和 1 之间数值 * @param v - 数值 * @returns */ static checkNumber01(v: number): boolean; /** * 检查 0 和 1 之间数值或未定义 * @param v - 数值或未定义 * @returns */ static checkNumber01Undef(v?: number): boolean; /** * 检查正数 * @param v - 数值 * @returns */ static checkPositive(v: number): boolean; /** * 检查非负数 * @param v - 数值 * @returns */ static checkNonnegative(v: number): boolean; /** * 检查非负数或未定义 * @param v - 数值 * @returns */ static checkNonnegativeUndef(v?: number): boolean; /** * 检查布尔类型 * @param v - 布尔值 * @returns */ static checkBoolean(v: boolean): boolean; /** * 检查布尔类型或未定义 * @param v - 布尔值或未定义 * @returns */ static checkBooleanUndef(v?: boolean): boolean; /** * 检查字符串类型 * @param v - 字符串 * @returns */ static checkString(v: string): boolean; /** * 检查字符串类型或未定义 * @param v - 字符串或未定义 * @returns */ static checkStringUndef(v?: string): boolean; /** * 检查浮点数组 * @param v - 浮点数组 * @returns */ static checkFloat32Array(v: Float32Array): boolean; /** * 检查浮点数组或未定义 * @param v - 浮点数组或未定义 * @returns */ static checkFloat32ArrayUndef(v?: Float32Array): boolean; /** * 检查父节点索引 * @param v - 数值或未定义 * @returns */ static checkParent(v?: number): boolean; /** * 检查纹理坐标 * @param v - 纹理坐标或未定义 * @returns */ static checkTexCoord(v?: number): boolean; /** * 检查二维向量 * @param v - 二维向量 * @returns */ static checkVec2(v: spec.vec2): boolean; /** * 检查二维向量或未定义 * @param v - 二维向量或未定义 * @returns */ static checkVec2Undef(v?: spec.vec2): boolean; /** * 检查三维向量 * @param v - 三维向量 * @returns */ static checkVec3(v: spec.vec3): boolean; /** * 检查三维非负向量 * @param v - 三维向量 * @returns */ static checkNonnegative3(v: spec.vec3): boolean; /** * 检查四维向量 * @param v - 四维向量 * @returns */ static checkVec4(v: spec.vec4): boolean; /** * 检查四维向量或未定义 * @param v - 四维向量或未定义 * @returns */ static checkNonnegative4(v: spec.vec4): boolean; /** * 检查数值数组 * @param v - 数值数组 * @returns */ static checkNumberArray(v: number[]): boolean; /** * 检查纹理对象 * @param v - 纹理对象 * @returns */ static checkTexture(v: Texture): boolean; /** * 检查纹理对象或未定义 * @param v - 纹理对象或未定义 * @returns */ static checkTextureUndef(v?: Texture): boolean; /** * 检查纹理变换参数 * @param v - 纹理变换参数 * @returns */ static checkTexTransform(v: ModelTextureTransform): boolean; /** * 检查纹理变换参数或未定义 * @param v - 纹理变换参数或未定义 * @returns */ static checkTexTransformUndef(v?: ModelTextureTransform): boolean; /** * 检查材质混合参数或未定义 * @param v - 材质混合参数或未定义 * @returns */ static checkMatBlending(v?: spec.MaterialBlending): boolean; /** * 检查材质单双面模式或未定义 * @param v - 材质单双面模式或未定义 * @returns */ static checkMatSide(v?: spec.SideMode): boolean; /** * 检查动画路径模式 * @param v - 动画路径模式 * @returns */ static checkAnimPath(v: string): boolean; /** * 检查动画插值模式 * @param v - 动画插值模式 * @returns */ static checkAnimInterp(v: string): boolean; /** * 检查几何体 * @param v - 几何体 * @param s - 蒙皮参数 */ static assertGeometry(v: Geometry, s?: ModelSkinOptions): void; /** * 检查几何体缓冲区 * @param v - 几何体 * @param name - 名称 * @param drawCount - 渲染数目 */ static assertGeometryBuffer(v: Geometry, name: string, drawCount: number): void; /** * 创建属性数组 * @param v - 几何体 * @param name - 名称 * @returns */ static createAttributeArray(v: Geometry, name: string): AttributeArray | undefined; /** * 检查蒙皮参数 * @param v - 蒙皮参数 */ static assertModelSkinOptions(v: ModelSkinOptions): void; /** * 检查材质参数 * @param v - 材质参数 */ static assertMatOptions(v: ModelMaterialOptions): void; /** * 检查 Primitive 参数 * @param v - Primitive 参数 * @param s - 蒙皮参数 * @returns */ static assertPrimOptions(v: ModelPrimitiveOptions, s?: ModelSkinOptions): boolean; /** * 检查 Model 插件 Mesh 参数 * @param v - Model 插件 Mesh 参数 */ static assertModelMeshOptions(v: ModelMeshOptions): void; /** * 检查 Model 插件相机参数 * @param v - Model 插件相机参数 */ static assertModelCameraOptions(v: ModelCameraOptions): void; /** * 检查 Model 插件灯光参数 * @param v - Model 插件灯光参数 */ static assertModelLightOptions(v: ModelLightOptions): void; /** * 检查 Model 插件天空盒参数 * @param v - Model 插件天空盒参数 */ static assertModelSkyboxOptions(v: ModelSkyboxOptions): void; /** * 检查 Model 插件动画轨道参数 * @param v - Model 插件动画轨道参数 * @returns */ static checkModelAnimTrackOptions(v: ModelAnimTrackOptions): boolean; /** * 检查 Model 插件动画参数 * @param v - Model 插件动画参数 */ static assertModelAnimOptions(v: ModelAnimationOptions): void; /** * 检查场景树参数 * @param v - 场景树参数 */ static assertTreeOptions(v: ModelTreeOptions): void; /** * 将对象转成 JSON 字符串,需要忽略函数和渲染相关的对象 * @param object - 目标对象 * @returns */ static stringify(object: any): string; /** * 获取 2 的 index 指数结果 * @param index - 指数 * @returns */ static pow2(index: number): number; } /** * 半精度浮点数组类 */ export declare class Float16ArrayWrapper { /** * 大小 */ size: number; /** * 数组 */ data: Uint16Array; constructor(size: number); /** * 将类数值数组转成半进度浮点,并从起始索引开始添加 * @param number - 类数值数组 * @param startIndex - 起始索引 */ set(number: ArrayLike, startIndex: number): void; /** * 获取数组字节数 */ get bytes(): number; } export {};