import { Mat4 } from '@gglib/math'; import { Device } from '../Device'; import { VertexLayout, VertexAttribute } from '../VertexLayout'; import { FrontFace } from '../enums'; import type { Model, ModelOptions } from './Model'; import { ModelMeshPart, ModelMeshPartOptions } from './ModelMeshPart'; import { ModelMeshOptions, ModelMesh } from './ModelMesh'; /** * A function that adds geometry into a given {@link ModelBuilder} * * @public */ export declare type ModelBuilderFunction = (b: ModelBuilder, options?: T) => void; /** * Constructor options for {@link ModelBuilder} * * @public */ export interface ModelBuilderOptions { /** * Mapping of attribute name to its default value */ defaults?: { [key: string]: number[]; }; /** * The vertex buffer layout */ layout?: string | VertexLayout | Array; } /** * A helper class for building 3d geometries * * @public */ export declare class ModelBuilder { /** * Creates a new model builder * * @remarks simply calls the constructor with given options * * @param options - the constructor options */ static begin(options?: ModelBuilderOptions): ModelBuilder; /** * Gets the indices in current state */ get indices(): ReadonlyArray; /** * The index count in current state */ get indexCount(): number; /** * The vertex count in current state */ get vertexCount(): number; /** * A map of default attributes * * @remarks * If {@link addVertex} is called with missing attributes, this is where * the default values are resolved from */ defaults: { [key: string]: number[]; }; private layout; private meshParts; private meshes; private bBox; private bSphere; private iBuffer; private vBuffer; private vCount; private partUtil; private transformStack; private tmp; /** * Creates a new instance of the ModelBuilder * * @param options * @example * new ModelBuilder({ layout: 'PositionTexture' }) */ constructor(options?: ModelBuilderOptions); /** * Pushes a transform matrix to transform all subsequent vertices (positions and normals) * * @param transform - the transform matrix */ beginTransform(transform: Mat4): number; /** * Pops transform matrices from stack up until the given id * * @param id - the id that has been returned byt a call to `beginTransform` */ endTransform(id: number): void; /** * Pushes and pops transform matrix to/from the stack around the given callback * * @param transform - the transform matrix * @param callback - the callback */ withTransform(transform: Mat4, callback: (builder: ModelBuilder) => void): this; /** * Gets a data channel of current state by its semantic name * * @param name - the data channel name e.g. 'position' */ private resetData; /** * Resets the builder state. * * @remarks * Any open state will be lost */ reset(): this; /** * Pushes a single index into current state. */ addIndex(index: number): this; /** * Pushes a single vertex definition into current state * * @remarks * The given vertex should contain all attributes for current layout. If any attribute is missing * a default value will be used: see {@link defaults} */ addVertex(vertex: { [key: string]: ReadonlyArray | number | { toArray: (buf: number[]) => void; }; }): this; readVertex(index: number, channels?: string[]): { [k: string]: number[]; }; calculateBoundings(): this; calculateNormals(create?: boolean, frontFace?: FrontFace): this; calculateTangents(create?: boolean, frontFace?: FrontFace): this; calculateNormalsAndTangents(create?: boolean, frontFace?: FrontFace): this; /** * For current state it ensures that the vertex buffer contains a channel with given semantic name * * @remarks * Does nothing if a channel with given semantic name already exists. * Otherwise adds a channel with given name to the vertex buffer and fills it with default values: see {@link defaults} * * This does not operate on already closed mesh parts. When building a model with multiple * meshes or parts, this must be called each time before closing a part. */ ensureLayoutChannel(name: string, channel?: VertexAttribute): void; /** * Same as {@link endMeshPart} but returns the builder for chaining * * @param options - options for `endMeshPart` */ closeMeshPart(options?: ModelMeshPartOptions): this; /** * Creates new mesh options with current index and vertex buffer and saves them in the meshes array. * * @param options - options to start with * @returns ModelMeshPartOptions or null if current state has no mesh part data */ endMeshPart(options?: ModelMeshPartOptions): ModelMeshPartOptions | null; /** * Creates new mesh with current index and vertex buffer and saves them in the meshes array. * * @param device - the graphics device * @param options - options to start with * @returns ModelMeshPart or null if current state has no mesh part data */ endMeshPart(device: Device, options?: ModelMeshPartOptions): ModelMeshPart | null; /** * Same as {@link endMesh} but returns the builder for chaining * * @param options - options for `endMesh` */ closeMesh(options?: ModelMeshOptions): this; /** * From current state it creates {@link ModelMeshOptions} and prepares the builder for the next mesh * * @param options - Additional {@link ModelMeshOptions} . The {@link ModelMeshOptions.parts} option is ignored. * @returns `ModelMeshOptions` or `null` if current state has no mesh data */ endMesh(options?: ModelMeshOptions): ModelMeshOptions | null; /** * From current state it creates in instance of {@link ModelMesh} and prepares the builder for the next mesh * * @param device - The graphics device * @param options - Additional {@link ModelMeshOptions} . The {@link ModelMeshOptions.parts} option is ignored. * @returns `ModelMesh` or `null` if current state has no mesh data */ endMesh(device: Device, options?: ModelMeshOptions): ModelMesh | null; /** * From current state it creates {@link ModelOptions} and resets the builder * * @param options - Additional {@link ModelOptions}. The {@link ModelOptions.meshes} option is ignored. * @returns ModelOptions or null if current state has no model data */ endModel(options?: ModelOptions): ModelOptions | null; /** * From current state it creates a {@link Model} instance and resets the builder * * @param device - The graphics device * @param options - Additional {@link ModelOptions}. The {@link ModelOptions.meshes} option is ignored. * @returns Model or null if current state has no model data */ endModel(device: Device, options?: ModelOptions): Model | null; /** * Calls the given model builder function to add geometry to current state * * @param builderFn - The model builder function to call * @param options - The model builder options to use */ append(builderFn: ModelBuilderFunction, options?: T): this; } //# sourceMappingURL=ModelBuilder.d.ts.map