threepipe
Version:
A modern 3D viewer framework built on top of three.js, written in TypeScript, designed to make creating high-quality, modular, and extensible 3D experiences on the web simple and enjoyable.
144 lines • 7.19 kB
TypeScript
import { Serializer } from 'ts-browser-helpers';
import { Color, Euler, Matrix2, Matrix3, Matrix4, ObjectLoader, Quaternion, Spherical, Texture, Vector2, Vector3, Vector4 } from 'three';
import { AssetImporter, AssetManager, BlobExt, IAssetImporter, ImportResultExtras } from '../assetmanager';
import { ThreeViewer } from '../viewer';
import { IMaterial, IObject3D, ITexture } from '../core';
import { RenderManager } from '../rendering';
export declare class ThreeSerialization {
static Primitives: readonly [readonly [typeof Vector2, "isVector2", readonly ["x", "y"], 1], readonly [typeof Vector3, "isVector3", readonly ["x", "y", "z"], 1], readonly [typeof Vector4, "isVector4", readonly ["x", "y", "z", "w"], 1], readonly [typeof Quaternion, "isQuaternion", readonly ["x", "y", "z", "w"], 1], readonly [typeof Euler, "isEuler", readonly ["x", "y", "z", "order"], 1], readonly [typeof Color, "isColor", readonly ["r", "g", "b"], 1], readonly [typeof Matrix2, "isMatrix2", readonly ["elements"], 1], readonly [typeof Matrix3, "isMatrix3", readonly ["elements"], 1], readonly [typeof Matrix4, "isMatrix4", readonly ["elements"], 1], readonly [typeof Spherical, "isSpherical", readonly ["radius", "phi", "theta"], 1]];
static PrimitiveSerializer(cls: any, isType: string, props: string[] | Readonly<string[]>, priority?: number): Serializer;
static Texture: Serializer;
static SerializableMaterials: Set<{
new (...args: any[]): IMaterial;
TYPE: string;
TypeSlug: string;
TypeAlias?: string[];
MaterialProperties?: Record<string, any>;
MapProperties?: string[];
InterpolateProperties?: string[];
}>;
static Material: Serializer;
static RenderTarget: Serializer;
private static _init;
static Init(): void;
static MakeSerializable(constructor: ObjectConstructor, type: string, props?: (string | [string, string])[]): void;
/**
* Serialize an object
* {@link Serialization.Serialize}
*/
static Serialize(obj: any, meta?: Partial<SerializationMetaType>, isThis?: boolean): any;
/**
* Deserialize an object
* {@link Serialization.Deserialize}
*/
static Deserialize(data: any, obj: any, meta?: Partial<SerializationMetaType>, isThis?: boolean): any;
}
/**
* Deep copy/clone from source to dest, assuming both are userData objects for three.js objects/materials/textures etc.
* This will clone any property that can be cloned (apart from Object3D, Texture, Material) and deep copy the objects and arrays.
* @note Keep synced with copyMaterialUserData in three.js -> Material.js todo: merge these functions? by putting this inside three.js?
* @param dest
* @param source
* @param ignoredKeysInRoot - keys to ignore in the root object
*/
export declare function copyUserData(dest: any, source: any, ignoredKeysInRoot?: (string | symbol)[]): any;
/**
* Deep copy/clone from source to dest, assuming both are userData objects in Textures.
* Same as {@link copyUserData} but ignores uuid in the root object.
* @param dest
* @param source
* @param ignoredKeysInRoot
*/
export declare function copyTextureUserData(dest: any, source: any, ignoredKeysInRoot?: string[]): any;
/**
* Deep copy/clone from source to dest, assuming both are userData objects in Materials.
* Same as {@link copyUserData} but ignores uuid in the root object.
* @note Keep synced with copyMaterialUserData in three.js -> Material.js
* @param dest
* @param source
* @param ignoredKeysInRoot
*/
export declare function copyMaterialUserData(dest: any, source: any, ignoredKeysInRoot?: string[]): any;
/**
* Deep copy/clone from source to dest, assuming both are userData objects in Object3D.
* Same as {@link copyUserData} but ignores uuid in the root object.
* @param dest
* @param source
* @param ignoredKeysInRoot
*/
export declare function copyObject3DUserData(dest: any, source: any, ignoredKeysInRoot?: string[]): any;
/**
* Converts array buffers to base64 strings in meta.
* This is useful when storing .json files, as storing as number arrays takes a lot of space.
* Used in viewer.toJSON()
* @param meta
*/
export declare function convertArrayBufferToStringsInMeta(meta: SerializationMetaType): void;
/**
* Converts strings(base64 or utf-8) to array buffers in meta. This is the reverse of {@link convertArrayBufferToStringsInMeta}
* Used in viewer.fromJSON()
*/
export declare function convertStringsToArrayBuffersInMeta(meta: SerializationMetaType): void;
export declare function getEmptyMeta(res?: Partial<SerializationResourcesType>): SerializationMetaType;
export interface SerializationResourcesType {
geometries: Record<string, any>;
materials: Record<string, any>;
textures: Record<string, any>;
images: Record<string, any>;
shapes: Record<string, any>;
skeletons: Record<string, any>;
animations: Record<string, any>;
extras: Record<string, any>;
typed: Record<string, any>;
object?: any;
[key: string]: any;
}
export interface SerializationMetaType extends SerializationResourcesType {
_context: {
assetImporter?: AssetImporter;
objectLoader?: ObjectLoader;
assetManager?: AssetManager;
renderManager?: RenderManager;
imagePromises?: Promise<any>[];
viewer?: ThreeViewer;
[key: string]: any;
};
__isLoadedResources?: boolean;
}
export declare class MetaImporter {
/**
* @param json
* @param extraResources - preloaded resources in the format of viewer config resources.
*/
static ImportMeta(json: SerializationMetaType, extraResources?: Partial<SerializationResourcesType>): Promise<SerializationMetaType>;
static LoadRootPathTextures({ textures, images }: Pick<SerializationMetaType, 'textures' | 'images'>, importer: IAssetImporter, usePreviewImages?: boolean): Promise<void>;
}
export declare function metaToResources(meta?: SerializationMetaType): Partial<SerializationResourcesType>;
export declare function mergeResources(target: Partial<SerializationResourcesType>, source: Partial<SerializationResourcesType>): Partial<SerializationResourcesType>;
export declare function metaFromResources(resources?: Partial<SerializationResourcesType>, viewer?: ThreeViewer): SerializationMetaType;
export declare function jsonToBlob(json: any): BlobExt;
/**
* Used in {@link LUTCubeTextureWrapper} and {@link KTX2LoadPlugin} and imported in {@link ThreeViewer.loadConfigResources}
* @param texture
* @param meta
* @param name
* @param mime
*/
export declare function serializeTextureInExtras(texture: ITexture & ImportResultExtras, meta: any, name?: string, mime?: string): {
uuid: string;
url: any;
userData: any;
type: import('three').TextureDataType;
name: string;
} | {
uuid: string;
resource: string;
};
declare module 'three' {
interface Source {
['__texCtor']?: typeof Texture;
}
}
export declare function getPartialProps(obj: IObject3D | IMaterial, props1?: string[]): Record<string, any>;
export declare function setPartialProps(props: Record<string, any>, obj: IMaterial | IObject3D): void;
//# sourceMappingURL=../src/utils/serialization.d.ts.map