An instance of a Mesh. A single mesh can be referenced by many mesh instances that can have different transforms and materials.

Constructors

  • Create a new MeshInstance instance.

    Parameters

    • mesh: Mesh

      The graphics mesh to instance.

    • material: Material

      The material to use for this mesh instance.

    • Optional node: GraphNode = null

      The graph node defining the transform for this instance. This parameter is optional when used with RenderComponent and will use the node the component is attached to.

    Returns MeshInstance

    Example

    // Create a mesh instance pointing to a 1x1x1 'cube' mesh
    const mesh = pc.Mesh.fromGeometry(app.graphicsDevice, new pc.BoxGeometry());
    const material = new pc.StandardMaterial();

    const meshInstance = new pc.MeshInstance(mesh, material);

    const entity = new pc.Entity();
    entity.addComponent('render', {
    meshInstances: [meshInstance]
    });

    // Add the entity to the scene hierarchy
    this.app.scene.root.addChild(entity);

Properties

_material: Material = null
_shaderCache: ShaderCacheEntry[] = []

An array of shader cache entries, indexed by the shader pass constant (SHADER_FORWARD..). The value stores all shaders and bind groups for the shader pass for various light combinations.

castShadow: boolean = false

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 Layer, but allows mesh to be skipped from shadow casting while it is in the list already. Defaults to false.

cull: boolean

Controls whether the mesh instance can be culled by frustum culling (CameraComponent#frustumCulling). Defaults to true.

drawOrder: number

Use this value to affect rendering order of mesh instances. Only used when mesh instances are added to a Layer with Layer#opaqueSortMode or Layer#transparentSortMode (depending on the material) set to SORTMODE_MANUAL.

node: GraphNode

The graph node defining the transform for this instance.

visible: boolean = true

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.

visibleThisFrame: boolean

Read this value in Layer#onPostCull to determine if the object is actually going to be rendered.

Accessors

  • get calculateSortDistance(): any
  • Returns any

  • set calculateSortDistance(calculateSortDistance): void
  • 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 default.

    Parameters

    • calculateSortDistance: any

    Returns void

Methods

  • Deletes a shader parameter on a mesh instance.

    Parameters

    • name: string

      The name of the parameter to delete.

    Returns void

  • Retrieves the specified shader parameter from a mesh instance.

    Parameters

    • name: string

      The name of the parameter to query.

    Returns object

    The named parameter.

  • Sets up MeshInstance to be rendered using Hardware Instancing.

    Parameters

    • vertexBuffer: VertexBuffer

      Vertex buffer to hold per-instance vertex data (usually world matrices). Pass null to turn off hardware instancing.

    • cull: boolean = false

      Whether to perform frustum culling on this instance. If true, the whole instance will be culled by the camera frustum. This often involves setting RenderComponent#customAabb containing all instances. Defaults to false, which means the whole instance is always rendered.

    Returns void

  • 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.

    Parameters

    • name: string

      The name of the parameter to set.

    • data: number | number[] | Texture

      The value for the specified parameter.

    • Optional passFlags: number = -262141

      Mask describing which passes the material should be included in.

    Returns void