UNPKG

@three.ez/batched-mesh-extensions

Version:
157 lines 7.06 kB
import { Color, DataTexture, Matrix3, Matrix4, PixelFormat, TextureDataType, TypedArray, Vector2, Vector3, Vector4, WebGLRenderer, WebGLUtils } from 'three'; /** * Represents the number of elements per pixel. */ export type ChannelSize = 1 | 2 | 3 | 4; /** * A constructor signature for creating TypedArray. */ export type TypedArrayConstructor = new (count: number) => TypedArray; /** * Represents the texture information including its data, size, format, and data type. */ export type TextureInfo = { array: TypedArray; size: number; format: PixelFormat; type: TextureDataType; }; /** * Represents information for updating rows in the texture, including the row index and number of rows. */ export type UpdateRowInfo = { row: number; count: number; }; /** * Defines the possible types of uniforms that can be used in shaders. */ export type UniformType = 'float' | 'vec2' | 'vec3' | 'vec4' | 'mat3' | 'mat4'; /** * Represents a value that can be used as a uniform. */ export type UniformValueObj = Vector2 | Vector3 | Vector4 | Matrix3 | Matrix4 | Color; /** * Defines a uniform value as either a number or a compatible Three.js object. */ export type UniformValue = number | UniformValueObj; /** * Represents the schema for a uniform, defining its offset, size, and type. */ export type UniformMapType = { offset: number; size: number; type: UniformType; }; /** * Represents a map of uniform names to their schema definitions. */ export type UniformMap = Map<string, UniformMapType>; /** * Calculates the square texture size based on the capacity and pixels per instance. * This ensures the texture is large enough to store all instances in a square layout. * @param capacity The maximum number of instances allowed in the texture. * @param pixelsPerInstance The number of pixels required for each instance. * @returns The size of the square texture needed to store all the instances. */ export declare function getSquareTextureSize(capacity: number, pixelsPerInstance: number): number; /** * Generates texture information (size, format, type) for a square texture based on the provided parameters. * @param arrayType The constructor for the TypedArray. * @param channels The number of channels in the texture. * @param pixelsPerInstance The number of pixels required for each instance. * @param capacity The maximum number of instances allowed in the texture. * @returns An object containing the texture's array, size, format, and data type. */ export declare function getSquareTextureInfo(arrayType: TypedArrayConstructor, channels: ChannelSize, pixelsPerInstance: number, capacity: number): TextureInfo; /** * A class that extends `DataTexture` to manage a square texture optimized for instances rendering. * It supports dynamic resizing, partial update based on rows, and allows setting/getting uniforms per instance. */ export declare class SquareDataTexture extends DataTexture { /** * Whether to enable partial texture updates by row. If `false`, the entire texture will be updated. * @default true. */ partialUpdate: boolean; /** * The maximum number of update calls per frame. * @default Infinity */ maxUpdateCalls: number; protected _channels: ChannelSize; protected _pixelsPerInstance: number; protected _stride: number; protected _rowToUpdate: boolean[]; protected _uniformMap: UniformMap; protected _fetchUniformsInFragmentShader: boolean; protected _utils: WebGLUtils; protected _needsUpdate: boolean; protected _lastWidth: number; /** * @param arrayType The constructor for the TypedArray. * @param channels The number of channels in the texture. * @param pixelsPerInstance The number of pixels required for each instance. * @param capacity The total number of instances. * @param uniformMap Optional map for handling uniform values. * @param fetchInFragmentShader Optional flag that determines if uniform values should be fetched in the fragment shader instead of the vertex shader. */ constructor(arrayType: TypedArrayConstructor, channels: ChannelSize, pixelsPerInstance: number, capacity: number, uniformMap?: UniformMap, fetchInFragmentShader?: boolean); /** * Resizes the texture to accommodate a new number of instances. * @param count The new total number of instances. */ resize(count: number): void; /** * Marks a row of the texture for update during the next render cycle. * This helps in optimizing texture updates by only modifying the rows that have changed. * @param index The index of the instance to update. */ enqueueUpdate(index: number): void; /** * Updates the texture data based on the rows that need updating. * This method is optimized to only update the rows that have changed, improving performance. * @param renderer The WebGLRenderer used for rendering. */ update(renderer: WebGLRenderer): void; protected getUpdateRowsInfo(): UpdateRowInfo[]; protected updateRows(textureProperties: any, renderer: WebGLRenderer, info: UpdateRowInfo[]): void; /** * Sets a uniform value at the specified instance ID in the texture. * @param id The instance ID to set the uniform for. * @param name The name of the uniform. * @param value The value to set for the uniform. */ setUniformAt(id: number, name: string, value: UniformValue): void; /** * Retrieves a uniform value at the specified instance ID from the texture. * @param id The instance ID to retrieve the uniform from. * @param name The name of the uniform. * @param target Optional target object to store the uniform value. * @returns The uniform value for the specified instance. */ getUniformAt(id: number, name: string, target?: UniformValueObj): UniformValue; /** * Generates the GLSL code for accessing the uniform data stored in the texture. * @param textureName The name of the texture in the GLSL shader. * @param indexName The name of the index in the GLSL shader. * @param indexType The type of the index in the GLSL shader. * @returns An object containing the GLSL code for the vertex and fragment shaders. */ getUniformsGLSL(textureName: string, indexName: string, indexType: string): { vertex: string; fragment: string; }; protected getUniformsVertexGLSL(textureName: string, indexName: string, indexType: string): string; protected getUniformsFragmentGLSL(textureName: string, indexName: string, indexType: string): string; protected texelsFetchGLSL(textureName: string, indexName: string): string; protected getFromTexelsGLSL(): string; protected getVarying(): { declareVarying: string; assignVarying: string; getVarying: string; }; protected getUniformComponents(offset: number, size: number): string; copy(source: SquareDataTexture): this; } //# sourceMappingURL=SquareDataTexture.d.ts.map