@luma.gl/engine
Version:
3D Engine Components for luma.gl
73 lines • 3.39 kB
TypeScript
import type { Binding, BindingsByGroup, Device } from '@luma.gl/core';
import type { ShaderModule } from '@luma.gl/shadertools';
import type { Material, MaterialProps } from "./material.js";
type MaterialModuleProps = Partial<Record<string, Record<string, unknown>>>;
type MaterialBindings = Record<string, Binding | import('../dynamic-texture/dynamic-texture').DynamicTexture>;
/** Logical bind-group slot reserved for material-owned bindings. */
export declare const MATERIAL_BIND_GROUP = 3;
/** Construction props for {@link MaterialFactory}. */
export type MaterialFactoryProps = {
/** Shader modules that define the material schema for bind group `3`. */
modules?: ShaderModule[];
};
/**
* Creates typed {@link Material} instances for a stable material binding schema.
*
* @example
* ```ts
* const pbrFactory = new MaterialFactory<
* {pbrMaterial: PBRMaterialUniforms},
* PBRMaterialBindings
* >(device, {modules: [pbrMaterial]});
* const pbr = pbrFactory.createMaterial();
* pbr.setProps({pbrMaterial: {baseColorFactor: [1, 0, 0, 1]}});
* const pbrVariant = pbr.clone({bindings: {pbr_baseColorSampler: texture}});
* ```
*
* @example
* ```ts
* const phongFactory = new MaterialFactory<
* {phongMaterial: PhongMaterialProps},
* {}
* >(device, {modules: [phongMaterial]});
* const phong = phongFactory.createMaterial();
* phong.setProps({phongMaterial: {ambient: 0.4, diffuse: 0.7}});
* const phongVariant = phong.clone({moduleProps: {phongMaterial: {shininess: 64}}});
* ```
*
* @example
* ```ts
* const gouraudFactory = new MaterialFactory<
* {gouraudMaterial: GouraudMaterialProps},
* {}
* >(device, {modules: [gouraudMaterial]});
* const gouraud = gouraudFactory.createMaterial();
* gouraud.setProps({gouraudMaterial: {ambient: 0.25}});
* const gouraudVariant = gouraud.clone({moduleProps: {gouraudMaterial: {diffuse: 0.8}}});
* ```
*/
export declare class MaterialFactory<TModuleProps extends MaterialModuleProps = MaterialModuleProps, TBindings extends MaterialBindings = MaterialBindings> {
/** Device that creates materials for this schema. */
readonly device: Device;
/** Shader modules that define the material schema. */
readonly modules: ShaderModule[];
private _materialBindingNames;
private _materialModuleNames;
constructor(device: Device, props?: MaterialFactoryProps);
/** Creates one typed material instance for this factory's schema. */
createMaterial(props?: Omit<MaterialProps<TModuleProps, TBindings>, 'factory' | 'modules'>): Material<TModuleProps, TBindings>;
/** Returns the logical material-owned resource binding names. */
getBindingNames(): string[];
/** Returns `true` when the supplied binding belongs to this material schema. */
ownsBinding(bindingName: string): boolean;
/** Returns `true` when the supplied shader module is owned by this material schema. */
ownsModule(moduleName: string): boolean;
/** Packages resolved material bindings into bind group `3`. */
getBindingsByGroup(bindings: Partial<{
[K in keyof TBindings]: Binding;
}> & Record<string, Binding>): BindingsByGroup;
}
/** Returns the module name corresponding to an auto-generated `*Uniforms` binding. */
export declare function getModuleNameFromUniformBinding(bindingName: string): string | null;
export {};
//# sourceMappingURL=material-factory.d.ts.map