/** * - A parameter of a mesh instance, overriding the value of * the material for that instance. */ export type MeshInstanceParameter = { /** * - The name of the uniform. */ name: string; /** * - The value. */ data: any; /** * - The scope id, resolved on first use for scope parameters. */ scopeId: ScopeId | null; /** * - True when the uniform is stored in the material uniform buffer, so * the parameter is applied through the mesh instance's copy of it rather than through the scope. */ override: boolean; /** * - The format of the uniform in the material uniform * buffer, resolved on first use for overrides. */ uniformFormat: UniformFormat | null; /** * - The index of the texture slot of the material bind group the * parameter overrides, or -1 when it does not override a texture of the material. */ textureSlot: number; /** * - The value of the scope the parameter replaced when last applied, * such as a value set globally, restored after the draw when the material does not have the * parameter. */ replacedValue: any; }; /** * Callback used by {@link Layer} to calculate the "sort distance" for a {@link MeshInstance}, * which determines its place in the render order. */ export type CalculateSortDistanceCallback = (meshInstance: MeshInstance, cameraPosition: Vec3, cameraForward: Vec3) => number; /** * @callback CalculateSortDistanceCallback * Callback used by {@link Layer} to calculate the "sort distance" for a {@link MeshInstance}, * which determines its place in the render order. * @param {MeshInstance} meshInstance - The mesh instance. * @param {Vec3} cameraPosition - The position of the camera. * @param {Vec3} cameraForward - The forward vector of the camera. * @returns {number} The sort distance for the mesh instance. Mesh instances are sorted by this * value in ascending or descending order depending on the layer's sort mode. */ /** * An instance of a {@link Mesh}. A single mesh can be referenced by many mesh instances that can * have different transforms and materials. * * A mesh instance is created from a {@link Mesh}, a {@link Material} and the {@link GraphNode} * whose world transform places it, and it is drawn only once it belongs to a {@link Layer}. * Components such as {@link RenderComponent} create mesh instances from their assets and add them * to the layers in their `layers` list. A mesh instance you construct yourself is placed either * by assigning it to {@link RenderComponent#meshInstances} or by adding it to a layer directly * with {@link Layer#addMeshInstances}. * * Per-instance rendering state lives here rather than on the shared mesh or material: * {@link visible}, {@link castShadow} and `receiveShadow`, {@link cull} for frustum culling, * {@link drawOrder} for manual sorting, and {@link setParameter} for shader uniforms that override * the material's. {@link aabb} is the world-space bounds derived from the mesh bounds and the * node's transform, and can be assigned to override it. * * ### Instancing * * Hardware instancing lets the GPU draw many copies of the same geometry with a single draw call. * Use {@link setInstancing} to attach a vertex buffer that holds per-instance data * (for example a mat4 world-matrix for every instance). Set {@link instancingCount} * to control how many instances are rendered. Passing `null` to {@link setInstancing} * disables instancing once again. * * ```javascript * // vb is a vertex buffer with one 4×4 matrix per instance * meshInstance.setInstancing(vb); * meshInstance.instancingCount = numInstances; * ``` * * The default matrix format, {@link VertexFormat.getDefaultInstancingFormat}, occupies the * attribute locations of `TEXCOORD6` and `TEXCOORD7`. A material sampling those UV sets on an * instanced mesh needs a custom instancing vertex format on other attributes, as shown by the * instancing-custom example. * * **Examples** * * - {@link https://playcanvas.github.io/#graphics/instancing-basic graphics/instancing-basic} * - {@link https://playcanvas.github.io/#graphics/instancing-custom graphics/instancing-custom} * * ### GPU-Driven Indirect Rendering (WebGPU Only) * * Instead of issuing draw calls from the CPU, parameters are written into a GPU * storage buffer and executed via indirect draw commands. Allocate one or more slots with * `GraphicsDevice.getIndirectDrawSlot(count)`, then bind the mesh instance to those slots: * * ```javascript * const slot = app.graphicsDevice.getIndirectDrawSlot(count); * meshInstance.setIndirect(null, slot, count); // first arg can be a CameraComponent or null * ``` * * **Example** * * - {@link https://playcanvas.github.io/#compute/indirect-draw compute/indirect-draw} * * ### Multi-draw * * Multi-draw lets the engine submit multiple sub-draws with a single API call. On WebGL2 this maps * to the `WEBGL_multi_draw` extension; on WebGPU, to indirect multi-draw. Use {@link setMultiDraw} * to allocate a {@link DrawCommands} container, fill it with sub-draws using * {@link DrawCommands#add} and finalize with {@link DrawCommands#update} whenever the data changes. * * Support: {@link GraphicsDevice#supportsMultiDraw} is true on WebGPU and commonly true on WebGL2 * (high coverage). When not supported, the engine can still render by issuing a fast internal loop * of single draws using the multi-draw data. * * ```javascript * // two indexed sub-draws from a single mesh * const cmd = meshInstance.setMultiDraw(null, 2); * cmd.add(0, 36, 1, 0); * cmd.add(1, 60, 1, 36); * cmd.update(2); * ``` * * ### Precedence * * When draw commands (indirect or multi-draw, see {@link setIndirect} and {@link setMultiDraw}) * are bound, they are the source of truth for rendering: the number of draws and the per-draw * instance counts come from the draw commands, and {@link instancingCount} is ignored. In this * case setting {@link instancingCount} to 0 does not skip rendering. {@link instancingCount} only * takes effect for plain hardware instancing, when no draw commands are bound. * * @category Graphics */ export class MeshInstance { static lightmapParamNames: string[]; /** * Sets the render style for an array of mesh instances. * * @param {MeshInstance[]} meshInstances - The mesh instances to set the render style for. * @param {number} renderStyle - The render style to set. * @ignore */ static _prepareRenderStyleForArray(meshInstances: MeshInstance[], renderStyle: number): void; /** * Create a new MeshInstance instance. * * @param {Mesh} mesh - The graphics mesh to instance. * @param {Material} material - The material to use for this mesh instance. * @param {GraphNode} [node] - The graph node defining the transform for this instance. This * parameter is optional when used with {@link RenderComponent} and will use the node the * component is attached to. * @example * // Create a mesh instance pointing to a 1x1x1 'cube' mesh * const mesh = Mesh.fromGeometry(app.graphicsDevice, new BoxGeometry()); * const material = new StandardMaterial(); * * const meshInstance = new MeshInstance(mesh, material); * * const entity = new Entity(); * entity.addComponent('render', { * meshInstances: [meshInstance] * }); * * // Add the entity to the scene hierarchy * this.app.scene.root.addChild(entity); */ constructor(mesh: Mesh, material: Material, node?: GraphNode); /** * Enable shadow casting for this mesh instance. Use this property to enable/disable shadow * casting without overhead of removing from scene. Note that this property does not add the * mesh instance to appropriate list of shadow casters on a {@link Layer}, but allows mesh to * be skipped from shadow casting while it is in the list already. Defaults to false. */ castShadow: boolean; /** * Specifies a bitmask that controls which shadow cascades a mesh instance contributes * to when rendered with a {@link LIGHTTYPE_DIRECTIONAL} light source. * This setting is only effective if the {@link castShadow} property is enabled. * Defaults to {@link SHADOW_CASCADE_ALL}, which means the mesh casts shadows into all available cascades. * * @type {number} */ shadowCascadeMask: number; /** * Controls whether the mesh instance can be culled by frustum culling (see * {@link CameraComponent#frustumCulling}). Defaults to true. */ cull: boolean; /** * Determines the rendering order of mesh instances. Only used when mesh instances are added to * a {@link Layer} with {@link Layer#opaqueSortMode} or {@link Layer#transparentSortMode} * (depending on the material) set to {@link SORTMODE_MANUAL}. */ drawOrder: number; /** @ignore */ _drawBucket: number; /** * @type {GraphNode} * @private */ private _node; /** * Enable rendering for this mesh instance. Use visible property to enable/disable rendering * without overhead of removing from scene. But note that the mesh instance is still in the * hierarchy and still in the draw call list. */ visible: boolean; /** * A bitmask controlling which shader passes this mesh instance is rendered in. Bit N * corresponds to the shader pass with index N: the built-in forward pass is * {@link SHADER_FORWARD}, and indices for custom shader passes are obtained from * {@link CameraComponent#setShaderPass}. Defaults to `0xFFFFFFFF` (all passes). For example, * clearing the forward pass bit keeps the mesh in the other passes (such as the camera depth * prepass that feeds Depth of Field) while making it invisible in the rendered color image. * * @type {number} * @example * // clear the forward (color) pass bit, leaving all other pass bits set: the mesh is no longer * // drawn in the color image, but still takes part in the other passes (such as the prepass) * meshInstance.shaderPassMask &= ~(1 << SHADER_FORWARD); * @example * // set the forward (color) pass bit, leaving all other pass bits unchanged * meshInstance.shaderPassMask |= (1 << SHADER_FORWARD); * @example * // exclude the mesh from a custom shader pass set up on the camera (see * // CameraComponent#setShaderPass), leaving all other pass bits set * const customPass = cameraComponent.setShaderPass('custom_rendering'); * meshInstance.shaderPassMask &= ~(1 << customPass); * @example * // test whether the forward (color) pass bit is set * const forwardBitSet = (meshInstance.shaderPassMask & (1 << SHADER_FORWARD)) !== 0; * @example * // set every pass bit (the default value) * meshInstance.shaderPassMask = 0xFFFFFFFF; */ shaderPassMask: number; /** * Read this value in the {@link Scene.EVENT_POSTCULL} event to determine if the object is * actually going to be rendered. */ visibleThisFrame: boolean; /** * Negative scale batching support. * * @ignore */ flipFacesFactor: number; /** * @type {GSplatInstance|null} * @ignore */ gsplatInstance: GSplatInstance | null; /** @ignore */ id: number; /** * Custom function used to customize culling (e.g. for 2D UI elements). * * @type {Function|null} * @ignore */ isVisibleFunc: Function | null; /** * @type {InstancingData|null} * @ignore */ instancingData: InstancingData | null; /** * Map of {@link Camera#id} to the draw commands bound to that camera, with the null key * holding the commands shared by all cameras. Lazily allocated. Keyed by id rather than by * camera so a long-lived mesh instance cannot retain a camera, and with it the camera's node * hierarchy and render target. * * @type {Map|null} * @ignore */ drawCommands: Map | null; /** * Stores mesh metadata used for indirect rendering. Lazily allocated on first access * via getIndirectMetaData(). * * @type {Int32Array|null} * @ignore */ meshMetaData: Int32Array | null; /** * The parameters overriding the material values for this mesh instance, by name. A parameter * naming the uniform of a typed material property is applied through a per-instance copy of the * material uniform buffer (an override), any other parameter is set on the scope before the * draw. The two groups are also kept in dense lists for the render loop. * * @type {Map} * @ignore */ parameters: Map; /** * The parameters set on the scope before the draw. * * @type {MeshInstanceParameter[]} * @private */ private _scopeParameters; /** * The parameters overriding uniforms of the material uniform buffer. * * @type {MeshInstanceParameter[]} * @private */ private _materialOverrides; /** * The parameters overriding textures of the material bind group. * * @type {MeshInstanceParameter[]} * @private */ private _materialTextureOverrides; /** * The layout version of the material the parameters were last split against, see * {@link Material#layoutVersion}. * * @type {number} * @private */ private _materialLayoutVersion; /** * Incremented when an override of the material uniform buffer is added, removed or changed. * * @type {number} * @private */ private _materialOverridesVersion; /** * The per-instance copy of the material uniform buffer with the overrides applied, created on * first use, or null. * * @type {UniformBuffer|null} * @private */ private _materialUniformBuffer; /** * The bind group holding {@link MeshInstance#_materialUniformBuffer}. * * @type {BindGroup|null} * @private */ private _materialBindGroup; /** * The material uniform data version the copy was last synchronized with. * * @type {number} * @private */ private _syncedMaterialDataVersion; /** * The overrides version the copy was last synchronized with. * * @type {number} * @private */ private _syncedOverridesVersion; /** * True if the mesh instance is pickable by the {@link Picker}. Defaults to true. * * @ignore */ pick: boolean; /** * The stencil parameters for front faces or null if no stencil is enabled. * * @type {StencilParameters|null} * @ignore */ stencilFront: StencilParameters | null; /** * The stencil parameters for back faces or null if no stencil is enabled. * * @type {StencilParameters|null} * @ignore */ stencilBack: StencilParameters | null; /** * True if the material of the mesh instance is transparent. Optimization to avoid accessing * the material. Updated by the material instance itself. * * @ignore */ transparent: boolean; /** @private */ private _aabb; /** @private */ private _aabbVer; /** @private */ private _aabbMeshVer; /** * The slot of the mesh instance in the mesh instance storage of the device, or -1 when it has * none, see {@link GraphicsDevice#meshInstanceStorage}. Allocated on the first draw with a * shader reading it. * * @type {number} * @ignore */ storageSlot: number; /** * The transform version of the node the slot was last written for, see * {@link Renderer#updateStorageSlot}. * * @type {number} * @ignore */ storageSlotVersion: number; /** * @type {BoundingBox|null} * @private */ private _customAabb; /** @private */ private _updateAabb; /** @private */ private _updateAabbFunc; /** * The internal sorting key used by the shadow renderer: the id of the shadow shader the mesh * instance was last rendered with, scaled above the 22 bits of the id of its material. * * @ignore */ _sortKeyShadow: number; /** * The internal sorting key used by the forward renderer, in case SORTMODE_MATERIALMESH sorting * is used. * * @private */ private _sortKeyForward; /** * The internal sorting key used by the forward renderer, in case SORTMODE_BACK2FRONT or * SORTMODE_FRONT2BACK sorting is used. * * @ignore */ _sortKeyDynamic: number; /** @private */ private _layer; /** * @type {Material|null} * @private */ private _material; /** * @type {SkinInstance|null} * @private */ private _skinInstance; /** * @type {MorphInstance|null} * @private */ private _morphInstance; /** @private */ private _receiveShadow; /** @private */ private _renderStyle; /** @private */ private _screenSpace; /** * The cache of shaders, indexed by a hash value. * * @type {Map} * @private */ private _shaderCache; /** * The shader defines: 24 bits of flags, and the light mask in the top 8 bits, see * SHADERDEF_MASK_SHIFT. Defaults to no flags and a mask of MASK_AFFECT_DYNAMIC. * * @private */ private _shaderDefs; /** * @type {CalculateSortDistanceCallback|null} * @private */ private _calculateSortDistance; /** * Sets the graph node defining the transform for this instance. * * @type {GraphNode} */ set node(node: GraphNode); /** * Gets the graph node defining the transform for this instance. * * @type {GraphNode} */ get node(): GraphNode; _mesh: Mesh; /** * Sets the material used by this mesh instance. * * @type {Material|null} */ set material(material: Material | null); /** * Gets the material used by this mesh instance. * * @type {Material|null} */ get material(): Material | null; /** * Sets the draw bucket for mesh instances. The draw bucket, an integer from 0 to 255 (default * 127), serves as the primary sort key for mesh rendering. Meshes are sorted by draw bucket, * then by sort mode. This setting is only effective when mesh instances are added to a * {@link Layer} with its {@link Layer#opaqueSortMode} or {@link Layer#transparentSortMode} * (depending on the material) set to {@link SORTMODE_BACK2FRONT}, {@link SORTMODE_FRONT2BACK}, * or {@link SORTMODE_MATERIALMESH}. * * Note: When {@link SORTMODE_BACK2FRONT} is used, a descending sort order is used; otherwise, * an ascending sort order is used. * * @type {number} */ set drawBucket(bucket: number); /** * Gets the draw bucket for mesh instance. * * @type {number} */ get drawBucket(): number; /** * Sets the render style of the mesh instance. Can be: * * - {@link RENDERSTYLE_SOLID} * - {@link RENDERSTYLE_WIREFRAME} * - {@link RENDERSTYLE_POINTS} * * Defaults to {@link RENDERSTYLE_SOLID}. * * @type {number} */ set renderStyle(renderStyle: number); /** * Gets the render style of the mesh instance. * * @type {number} */ get renderStyle(): number; /** * Sets the graphics mesh being instanced. * * @type {Mesh|null} */ set mesh(mesh: Mesh | null); /** * Gets the graphics mesh being instanced. * * @type {Mesh|null} */ get mesh(): Mesh | null; /** * Sets the world space axis-aligned bounding box for this mesh instance. * * @type {BoundingBox} */ set aabb(aabb: BoundingBox); /** * Gets the world space axis-aligned bounding box for this mesh instance. * * @type {BoundingBox} */ get aabb(): BoundingBox; /** * Clear the internal shader cache. * * @ignore */ clearShaders(): void; /** * Returns the shader instance for the specified shader pass and lights that is compatible * with this mesh instance. * * @param {number} shaderPass - The shader pass index. * @param {LightList} lightList - The lights of the pass. * @param {Scene} scene - The scene. * @param {CameraShaderParams} cameraShaderParams - The camera shader parameters. * @param {UniformBufferFormat} [viewUniformFormat] - The format of the view uniform buffer. * @returns {ShaderInstance} - the shader instance. * @ignore */ getShaderInstance(shaderPass: number, lightList: LightList, scene: Scene, cameraShaderParams: CameraShaderParams, viewUniformFormat?: UniformBufferFormat): ShaderInstance; /** * @param {number} shaderDefs - The shader definitions to set. * @private */ private _updateShaderDefs; /** * Sets the callback to calculate sort distance. In some circumstances mesh instances are * sorted by a distance calculation to determine their rendering order. Set this callback to * override the default distance calculation, which gives the dot product of the camera forward * vector and the vector between the camera position and the center of the mesh instance's * axis-aligned bounding box. This option can be particularly useful for rendering transparent * meshes in a better order than the default. * * @type {CalculateSortDistanceCallback|null} */ set calculateSortDistance(calculateSortDistance: CalculateSortDistanceCallback | null); /** * Gets the callback to calculate sort distance. * * @type {CalculateSortDistanceCallback|null} */ get calculateSortDistance(): CalculateSortDistanceCallback | null; set receiveShadow(val: boolean); get receiveShadow(): boolean; set batching(val: boolean); get batching(): boolean; /** * Sets the skin instance managing skinning of this mesh instance. Set to null if skinning is * not used. * * @type {SkinInstance|null} */ set skinInstance(val: SkinInstance | null); /** * Gets the skin instance managing skinning of this mesh instance. * * @type {SkinInstance|null} */ get skinInstance(): SkinInstance | null; /** * Sets the morph instance managing morphing of this mesh instance. Set to null if morphing is * not used. * * @type {MorphInstance|null} */ set morphInstance(val: MorphInstance | null); /** * Gets the morph instance managing morphing of this mesh instance. * * @type {MorphInstance|null} */ get morphInstance(): MorphInstance | null; set screenSpace(val: boolean); get screenSpace(): boolean; set key(val: number); get key(): number; /** * Sets the light mask of this mesh instance: which {@link LightComponent}s light it. The value * is a combination of `MASK_AFFECT_DYNAMIC`, `MASK_AFFECT_LIGHTMAPPED` and `MASK_BAKE`, and * only its lowest 8 bits are used. Defaults to `MASK_AFFECT_DYNAMIC`. * * @type {number} */ set mask(val: number); /** * Gets the light mask of this mesh instance: which {@link LightComponent}s light it. * * @type {number} */ get mask(): number; /** * Sets the number of instances when using hardware instancing to render the mesh. * * @type {number} */ set instancingCount(value: number); /** * Gets the number of instances when using hardware instancing to render the mesh. * * @type {number} */ get instancingCount(): number; destroy(): void; destroyDrawCommands(): void; /** * Returns the shader defines with {@link SHADERDEF_INSTANCEINDEX} set when the draws of this * mesh instance use the instance index for their own data: draw commands set the first * instance of their draws, and instancing without a vertex buffer indexes the data of the * instances by it. The shaders of other draws read the mesh instance storage by it. * * @param {number} shaderDefs - The shader defines. * @returns {number} The shader defines with the flag updated. * @private */ private _applyInstanceIndexDef; /** * Test if meshInstance is visible by camera. It requires the frustum of the camera to be up to * date, which forward-renderer takes care of. This function should not be called elsewhere. * * @param {Camera} camera - The camera to test visibility against. * @returns {boolean} - True if the mesh instance is visible by the camera, false otherwise. * @ignore */ _isVisible(camera: Camera): boolean; updateKey(): void; /** * Sets up {@link MeshInstance} to be rendered using Hardware Instancing. * Note that {@link instancingCount} is automatically set to the number of vertices of the * vertex buffer when it is provided. * * @param {VertexBuffer|true|null} vertexBuffer - Vertex buffer to hold per-instance vertex data * (usually world matrices). Pass `true` to enable attributeless instancing where the instance * index is derived from `gl_InstanceID` / `instance_index` builtins rather than a vertex * buffer attribute — the caller must set {@link instancingCount} manually. Pass null to turn * off hardware instancing. * @param {boolean} cull - Whether to perform frustum culling on this instance. If true, the whole * instance will be culled by the camera frustum. This often involves setting * {@link RenderComponent#customAabb} containing all instances. Defaults to false, which means * the whole instance is always rendered. */ setInstancing(vertexBuffer: VertexBuffer | true | null, cull?: boolean): void; /** * Sets the {@link MeshInstance} to be rendered using indirect rendering, where the GPU, * typically using a Compute shader, stores draw call parameters in a buffer. * Note that this is only supported on WebGPU (see * {@link GraphicsDevice#supportsIndirectDraw}), and ignored on other platforms, where the * mesh instance renders as a normal draw call. * * @param {CameraComponent|null} camera - Camera component to set indirect data for, or * null if the indirect slot should be used for all cameras. * @param {number} slot - Slot in the buffer to set the draw call parameters. Allocate a slot * in the buffer by calling {@link GraphicsDevice#getIndirectDrawSlot}. Pass -1 to disable * indirect rendering for the specified camera (or the shared entry when camera is null). * @param {number} [count] - Optional number of consecutive slots to use. Defaults to 1. */ setIndirect(camera: CameraComponent | null, slot: number, count?: number): void; /** * Sets the {@link MeshInstance} to be rendered using multi-draw, where multiple sub-draws are * executed with a single draw call. * * Note: Each call to this method invalidates any previously stored draw command data for the * specified camera. * * @param {CameraComponent|null} camera - Camera component to bind commands to, or null to share * across all cameras. * @param {number} [maxCount] - Maximum number of sub-draws to allocate. Defaults to 1. Pass 0 * to disable multi-draw for the specified camera (or the shared entry when camera is null). * @returns {DrawCommands|undefined} The commands container to populate with sub-draw commands. */ setMultiDraw(camera: CameraComponent | null, maxCount?: number): DrawCommands | undefined; /** * Returns the cached draw commands for a key, allocating them when missing. A cached set of * the other kind is released first - indirect and multi-draw commands draw from different * backing storage, so they cannot share an instance. * * @param {number|null} key - The {@link Camera#id} the commands are bound to, or null for the * set shared by all cameras. * @param {boolean} multiDraw - True for multi-draw commands, false for indirect ones. * @returns {DrawCommands} The draw commands to populate. * @private */ private _allocDrawCommands; _deleteDrawCommandsKey(key: any): void; /** * Retrieves the draw commands for a specific camera, or the default commands when none are * bound to that camera. * * @param {Camera} camera - The camera to retrieve commands for. * @returns {DrawCommands|undefined} - The draw commands, or undefined. * @ignore */ getDrawCommands(camera: Camera): DrawCommands | undefined; /** * Retrieves the mesh metadata needed for indirect rendering. * * @returns {Int32Array} - A typed array with 4 elements representing the mesh metadata, which * is typically needed when generating indirect draw call parameters using Compute shader. These * can be provided to the Compute shader using vec4i uniform. The values are based on * {@link Mesh#primitive}, stored in this order: [count, base, baseVertex, 0]. The last value is * always zero and is reserved for future use. */ getIndirectMetaData(): Int32Array; ensureMaterial(device: any): void; clearParameters(): void; getParameters(): Map; /** * Retrieves the specified shader parameter from a mesh instance. * * @param {string} name - The name of the parameter to query. * @returns {object|undefined} The named parameter, or `undefined` if no parameter with that * name is set on this mesh instance. */ getParameter(name: string): object | undefined; /** * Sets a shader parameter on a mesh instance. Note that this parameter will take precedence * over parameter of the same name if set on Material this mesh instance uses for rendering. * To change an array value, call this method again with it; the contents of an array are not * guaranteed to be re-read on later draws. * * @param {string} name - The name of the parameter to set. * @param {number|number[]|Texture|Float32Array} data - The value for the specified parameter. */ setParameter(name: string, data: number | number[] | Texture | Float32Array): void; /** * A wrapper over settings parameter specifically for realtime baked lightmaps. This handles * reference counting of lightmaps and releases them when no longer referenced. * * @param {string} name - The name of the parameter to set. * @param {Texture|null} texture - The lightmap texture to set. * @ignore */ setRealtimeLightmap(name: string, texture: Texture | null): void; /** * Deletes a shader parameter on a mesh instance. * * @param {string} name - The name of the parameter to delete. */ deleteParameter(name: string): void; /** * Used to apply parameters from this mesh instance into scope of uniforms, called internally * by forward-renderer. Parameters overriding uniforms of the material uniform buffer are not * part of this, they are applied by {@link MeshInstance#getMaterialBindGroup}. * * @param {GraphicsDevice} device - The graphics device. * @ignore */ setParameters(device: GraphicsDevice): void; /** * Restores the scope values the parameters of this mesh instance replaced, such as values set * globally, for the parameters its material does not have - no material sets those again for * the draws that follow. The parameters the material has are restored to its values when the * next draw uses the same material. Called internally by the renderers after a draw. * * @param {Material} material - The material the mesh instance was drawn with. * @ignore */ restoreReplacedParameters(material: Material): void; /** * Adds a parameter to the scope list, or to the overrides of the material uniform buffer when * its name is the uniform of a typed property of the material. * * @param {MeshInstanceParameter} parameter - The parameter. * @private */ private _addParameter; /** * Splits the parameters between the scope and the material uniform buffer again, after the * material or its set of typed properties changed. * * @private */ private _rebuildParameterLists; /** * Returns the bind group to use at the material bind group index for this mesh instance: a * per-instance copy of the material's bind group with the overriding parameters applied, or * null when no parameter overrides anything in it, in which case the material's own bind group * is used. The copy of the uniform buffer is synchronized when the material data or the * overrides changed; the textures are assigned every time, as they are only references. * * @param {GraphicsDevice} device - The graphics device. * @returns {BindGroup|null} The bind group of the overriding copy, or null. * @ignore */ getMaterialBindGroup(device: GraphicsDevice): BindGroup | null; _debugWarnedOverridesVersion: any; /** * Releases the per-instance copy of the material uniform buffer. * * @private */ private _destroyMaterialUniformBuffer; /** * @param {boolean} value - True to enable lightmapped rendering, false to disable. * @ignore */ setLightmapped(value: boolean): void; /** * @param {BoundingBox|null} aabb - The custom axis-aligned bounding box or null to reset to * the mesh's bounding box. * @ignore */ setCustomAabb(aabb: BoundingBox | null): void; /** @private */ private _setupSkinUpdate; } import type { ScopeId } from '../platform/graphics/scope-id.js'; import type { UniformFormat } from '../platform/graphics/uniform-buffer-format.js'; import type { Vec3 } from '../core/math/vec3.js'; import type { GSplatInstance } from './gsplat/gsplat-instance.js'; /** * Internal data structure used to store data used by hardware instancing. * * @ignore */ declare class InstancingData { /** * @param {number} numObjects - The number of objects instanced. */ constructor(numObjects: number); /** @type {VertexBuffer|null} */ vertexBuffer: VertexBuffer | null; /** * True if the vertex buffer is destroyed when the mesh instance is destroyed. */ _destroyVertexBuffer: boolean; count: number; destroy(): void; } import { DrawCommands } from '../platform/graphics/draw-commands.js'; import type { StencilParameters } from '../platform/graphics/stencil-parameters.js'; import { GraphNode } from './graph-node.js'; import type { Mesh } from './mesh.js'; import type { Material } from './materials/material.js'; import { BoundingBox } from '../core/shape/bounding-box.js'; import type { LightList } from './lighting/light-list.js'; import type { Scene } from './scene.js'; import type { CameraShaderParams } from './camera-shader-params.js'; import type { UniformBufferFormat } from '../platform/graphics/uniform-buffer-format.js'; /** * Internal helper class for storing the shader and related mesh bind group in the shader cache. * * @ignore */ declare class ShaderInstance { /** * A shader. * * @type {Shader|undefined} */ shader: Shader | undefined; /** * A bind group storing mesh textures / samplers for the shader. but not the uniform buffer. * * @type {BindGroup|null} */ bindGroup: BindGroup | null; /** * A uniform buffer storing mesh uniforms for the shader. * * @type {UniformBuffer|null} */ uniformBuffer: UniformBuffer | null; /** * The full array of hashes used to lookup the pipeline, used in case of hash collision. * * @type {Uint32Array} */ hashes: Uint32Array; /** * Returns the mesh bind group for the shader. * * @param {GraphicsDevice} device - The graphics device. * @returns {BindGroup} - The mesh bind group. */ getBindGroup(device: GraphicsDevice): BindGroup; /** * Returns the uniform buffer for the shader. * * @param {GraphicsDevice} device - The graphics device. * @returns {UniformBuffer} - The uniform buffer. */ getUniformBuffer(device: GraphicsDevice): UniformBuffer; destroy(): void; } import type { SkinInstance } from './skin-instance.js'; import type { MorphInstance } from './morph-instance.js'; import type { Camera } from './camera.js'; import { VertexBuffer } from '../platform/graphics/vertex-buffer.js'; import type { CameraComponent } from '../framework/components/camera/component.js'; import type { Texture } from '../platform/graphics/texture.js'; import type { GraphicsDevice } from '../platform/graphics/graphics-device.js'; import { BindGroup } from '../platform/graphics/bind-group.js'; import type { Shader } from '../platform/graphics/shader.js'; import { UniformBuffer } from '../platform/graphics/uniform-buffer.js'; export {};