@luma.gl/engine
Version:
3D Engine Components for luma.gl
84 lines • 4.69 kB
TypeScript
import type { Binding, BindingsByGroup, Device } from '@luma.gl/core';
import type { ShaderModule } from '@luma.gl/shadertools';
import { DynamicTexture } from "../dynamic-texture/dynamic-texture.js";
import { ShaderInputs } from "../shader-inputs.js";
import { MaterialFactory } from "./material-factory.js";
type MaterialModuleProps = Partial<Record<string, Record<string, unknown>>>;
type MaterialBindings = Record<string, Binding | DynamicTexture>;
type MaterialPropsUpdate<TModuleProps extends MaterialModuleProps> = Partial<{
[P in keyof TModuleProps]?: Partial<TModuleProps[P]>;
}>;
/** Construction props for one typed {@link Material}. */
export type MaterialProps<TModuleProps extends MaterialModuleProps = MaterialModuleProps, TBindings extends MaterialBindings = MaterialBindings> = {
/** Optional application-provided identifier. */
id?: string;
/** Factory that owns the material schema. */
factory?: MaterialFactory<TModuleProps, TBindings>;
/** Optional pre-created shader inputs for the material modules. */
shaderInputs?: ShaderInputs<TModuleProps>;
/** Shader modules used when a factory is not supplied. */
modules?: ShaderModule[];
/** Initial material-owned resource bindings. */
bindings?: Partial<TBindings>;
};
/** Structural overrides applied when cloning a {@link Material}. */
export type MaterialCloneProps<TModuleProps extends MaterialModuleProps = MaterialModuleProps, TBindings extends MaterialBindings = MaterialBindings> = {
/** Optional identifier for the cloned material. */
id?: string;
/** Replacement material-owned resource bindings. */
bindings?: Partial<TBindings>;
/** Additional uniform/module props applied to the clone. */
moduleProps?: MaterialPropsUpdate<TModuleProps>;
/** Optional full replacement shader-input store. */
shaderInputs?: ShaderInputs<TModuleProps>;
};
/**
* Material owns bind group `3` resources and uniforms for one material instance.
*
* `setProps()` mutates uniform values in place. Structural resource changes are
* expressed through `clone({...})`, which creates a new material identity.
*/
export declare class Material<TModuleProps extends MaterialModuleProps = MaterialModuleProps, TBindings extends MaterialBindings = MaterialBindings> {
/** Application-provided identifier. */
readonly id: string;
/** Device that owns the material resources. */
readonly device: Device;
/** Factory that defines the material schema. */
readonly factory: MaterialFactory<TModuleProps, TBindings>;
/** Shader inputs for the material-owned modules. */
readonly shaderInputs: ShaderInputs<TModuleProps>;
/** Internal binding store including uniform buffers and resource bindings. */
readonly bindings: Record<string, Binding | DynamicTexture>;
private _uniformStore;
private _bindGroupCacheToken;
constructor(device: Device, props?: MaterialProps<TModuleProps, TBindings>);
/** Destroys managed uniform-buffer resources owned by this material. */
destroy(): void;
/** Creates a new material variant with optional structural and uniform overrides. */
clone(props?: MaterialCloneProps<TModuleProps, TBindings>): Material<TModuleProps, TBindings>;
/** Returns `true` if this material owns the supplied binding name. */
ownsBinding(bindingName: string): boolean;
/** Returns `true` if this material owns the supplied shader module. */
ownsModule(moduleName: string): boolean;
/** Updates material uniform/module props in place without changing material identity. */
setProps(props: MaterialPropsUpdate<TModuleProps>): void;
/** Updates managed uniform buffers and shader-input-owned bindings. */
updateShaderInputs(): void;
/** Returns the material-owned resource bindings without internal uniform buffers. */
getResourceBindings(): Partial<TBindings>;
/** Returns the resolved bindings, including internal uniform buffers and ready textures. */
getBindings(): Partial<{
[K in keyof TBindings]: Binding;
}> & Record<string, Binding>;
/** Packages resolved material bindings into logical bind group `3`. */
getBindingsByGroup(): BindingsByGroup;
/** Returns the stable bind-group cache token for the requested bind group. */
getBindGroupCacheKey(group: number): object | null;
/** Returns the latest update timestamp across material-owned resources. */
getBindingsUpdateTimestamp(): number;
/** Replaces owned resource bindings and invalidates the material cache identity when needed. */
private _replaceOwnedBindings;
private _setOwnedBindings;
}
export {};
//# sourceMappingURL=material.d.ts.map