import type { TextureOptions, GeometryOptions, TypedArray, } from '@predy-js/render-interface'; import type { GeometryOptionsJSON, BinaryPointer, TextureJSONOptions, BezierBinaryPointer, BezierPathBinaryPointer, Item, } from '@predy-js/specification'; import type { BaseItemTransform, ItemType, Composition, BinaryType } from '@predy-js/specification'; import type { BinaryEnv } from '@predy-js/specification'; //合成场景树 export interface CompositionGraph { name: string, id: string, //没有父元素的节点都在这数组里面 //有父元素的节点在父元素的children里面 nodes: CompositionGraphNode[], } //场景树的节点 export interface CompositionGraphNode { name: string, id: string, //元素类型 type: ItemType | 'mesh' | 'light' | 'skybox' | 'camera' | 'tree' | string, transform: BaseItemTransform, parentId?: string, // 树元素的子节点 为 node // mars 其他元素没有subType subType?: string, //子节点数组 children?: CompositionGraphNode[], } export declare function getCompositionGraph (comp: Composition): CompositionGraph; export interface ItemSerializationResult { data: ArrayBuffer, items: Item[], pointers: Array, } export interface TextureSerializationResult { version: '1.0', //cube texture的所有mipmaps会被打入bins中,每个cube texture生成一个bin //image mipmaps也会被写入bins中 bins?: ArrayBuffer[], //每个image texture2D会被写入image对象中 images: Array, textures: Array, } export interface GeometrySerializationResult { version: '1.0', //所有的geometry中数据会被写入到data中, //写入时会去除重复的typedArray,减少数据冗余 data: ArrayBuffer, geometries: Array>, } export declare function getBinaryType (arr: TypedArray | ArrayBuffer): BinaryType; export declare class Serializer { /** * 将item的数据进行二进制化,其中新的item需要进行克隆,不要改变原始item的数据 * 需要进行如下处理: * item.transform二进制化, * particle的所有bezier进行二进制化 * tree的nodes进行二进制化 * @param items */ static serializeItemsAsync (items: Item[]): Promise; /** * 对Item进行反序列化,如果overwrite,直接修改原来的item, * 否则克隆item进行修改 * @param item * @param binaries */ static deserializeItem (item: Item, binaries: ArrayBuffer[], overwrite?: boolean): Item; /** * texture 序列化 * @param textures */ static serializeTexturesAsync (textures: TextureOptions[]): Promise; /** * geometry 序列化 * @param geometries * @param bufferIndex buffer所在的数组位置或者fs地址 */ static serializeGeometries(geometries: GeometryOptions[], bufferIndex?: T extends BinaryEnv.json ? number : string): GeometrySerializationResult; /** * geometry反序列化 * @param geo * @param binaries */ static deserializeGeometry (geo: GeometryOptionsJSON, binaries: ArrayBuffer[]): GeometryOptions; /** * 工具方法,按照4bytes对齐方式合并buffers,如果提供了pointer,会把原来的pointer转化为新的映射 * 返回的pointers数组和传入的pointers数组长度一致,并且一一对应 * @param buffers * @param pointers 如果不提供pointers,将返回整段buffers的pointer重映射 * @param overwrite 如果为true,将直接改写参数中的pointer值,否则生成新的pointer传出 */ static concatArrayBuffers (buffers: Array, pointers?: Array, overwrite?: boolean): { data: ArrayBuffer, pointers: BinaryPointer[], }; /** * 重构TypedArray,返回的TypedArray如果修改,会反映到原始的ArrayBuffer中 * @param binaries * @param pointer */ static typedArrayFromBinary (binaries: ArrayBuffer[], pointer: BinaryPointer): TypedArray | ArrayBuffer; }