API Reference

Class List

MeshInstance

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

// Create a mesh instance pointing to a 1x1x1 'cube' mesh
const mesh = pc.createBox(graphicsDevice);
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);

Summary

Properties

aabb

The world space axis-aligned bounding box for this mesh instance.

calculateSortDistance

In some circumstances mesh instances are sorted by a distance calculation to determine their rendering order.

castShadow

Enable shadow casting for this mesh instance.

cull

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

drawOrder

Use this value to affect rendering order of mesh instances.

instancingCount

Number of instances when using hardware instancing to render the mesh.

mask

Mask controlling which LightComponents light this mesh instance, which CameraComponent sees it and in which Layer it is rendered.

material

The material used by this mesh instance.

mesh

The graphics mesh being instanced.

morphInstance

The morph instance managing morphing of this mesh instance, or null if morphing is not used.

node

The graph node defining the transform for this instance.

renderStyle

The render style of the mesh instance.

skinInstance

The skin instance managing skinning of this mesh instance, or null if skinning is not used.

visible

Enable rendering for this mesh instance.

visibleThisFrame

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

Methods

deleteParameter

Deletes a shader parameter on a mesh instance.

getParameter

Retrieves the specified shader parameter from a mesh instance.

setInstancing

Sets up MeshInstance to be rendered using Hardware Instancing.

setParameter

Sets a shader parameter on a mesh instance.

Details

Constructor

MeshInstance(mesh, material, [node])

Create a new MeshInstance instance.

// Create a mesh instance pointing to a 1x1x1 'cube' mesh
const mesh = pc.createBox(graphicsDevice);
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);

Parameters

meshMesh

The graphics mesh to instance.

materialMaterial

The material to use for this mesh instance.

nodeGraphNode

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.

Properties

BoundingBoxaabb

The world space axis-aligned bounding box for this mesh instance.

CalculateSortDistanceCallbackcalculateSortDistance

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.

booleancastShadow

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.

booleancull

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

numberdrawOrder

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.

numberinstancingCount

Number of instances when using hardware instancing to render the mesh.

numbermask

Mask controlling which LightComponents light this mesh instance, which CameraComponent sees it and in which Layer it is rendered. Defaults to 1.

Materialmaterial

The material used by this mesh instance.

Meshmesh

The graphics mesh being instanced.

MorphInstancemorphInstance

The morph instance managing morphing of this mesh instance, or null if morphing is not used.

GraphNodenode

The graph node defining the transform for this instance.

numberrenderStyle

The render style of the mesh instance. Can be:

Defaults to RENDERSTYLE_SOLID.

SkinInstanceskinInstance

The skin instance managing skinning of this mesh instance, or null if skinning is not used.

booleanvisible

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.

booleanvisibleThisFrame

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

Methods

deleteParameter(name)

Deletes a shader parameter on a mesh instance.

Parameters

namestring

The name of the parameter to delete.

getParameter(name)

Retrieves the specified shader parameter from a mesh instance.

Parameters

namestring

The name of the parameter to query.

Returns

object

The named parameter.

setInstancing(vertexBuffer)

Sets up MeshInstance to be rendered using Hardware Instancing.

Parameters

vertexBufferVertexBuffer, null

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

setParameter(name, data, [passFlags])

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

namestring

The name of the parameter to set.

datanumber, number[], Texture

The value for the specified parameter.

passFlagsnumber

Mask describing which passes the material should be included in.