API Reference

Class List

pc.MeshInstance

An instance of a pc.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
var mesh = pc.createBox(graphicsDevice);
var material = new pc.StandardMaterial();
var node = new pc.GraphNode();
var meshInstance = new pc.MeshInstance(node, mesh, material);
// A script you can attach on an entity to test if it is visible on a Layer
var MeshVisScript = pc.createScript('meshVisScript');
MeshVisScript.prototype.initialize = function () {
    var _this = this;
    this.app.scene.layers.getLayerByName("World").onPostCull = function (cameraIndex) {
        var meshInstance = _this.entity.model.model.meshInstances[0];
        console.log("visible: " + meshInstance.visibleThisFrame);
    };
};

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

Controls whether the mesh instance casts shadows.

cull

Controls whether the mesh instance can be culled by with frustum culling (pc.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 pc.LightComponents light this mesh instance, which pc.CameraComponent sees it and in which pc.Layer it is rendered.

material

The material used by this mesh instance.

mesh

The graphics mesh being instanced.

node

The graph node defining the transform for this instance.

renderStyle

The render style of the mesh instance.

visible

Enable rendering for this mesh instance.

visibleThisFrame

Read this value in pc.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 pc.MeshInstance to be rendered using Hardware Instancing.

setParameter

Sets a shader parameter on a mesh instance.

Details

Constructor

MeshInstance(node, mesh, material)

Create a new mesh instance.

// Create a mesh instance pointing to a 1x1x1 'cube' mesh
var mesh = pc.createBox(graphicsDevice);
var material = new pc.StandardMaterial();
var node = new pc.GraphNode();
var meshInstance = new pc.MeshInstance(node, mesh, material);
// A script you can attach on an entity to test if it is visible on a Layer
var MeshVisScript = pc.createScript('meshVisScript');
MeshVisScript.prototype.initialize = function () {
    var _this = this;
    this.app.scene.layers.getLayerByName("World").onPostCull = function (cameraIndex) {
        var meshInstance = _this.entity.model.model.meshInstances[0];
        console.log("visible: " + meshInstance.visibleThisFrame);
    };
};

Parameters

nodepc.GraphNode

The graph node defining the transform for this instance.

meshpc.Mesh

The graphics mesh being instanced.

materialpc.Material

The material used to render this instance.

Properties

pc.BoundingBoxaabb

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

pc.callbacks.CalculateSortDistancecalculateSortDistance

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

Controls whether the mesh instance casts shadows. Defaults to false.

booleancull

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

numberdrawOrder

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

numberinstancingCount

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

numbermask

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

pc.Materialmaterial

The material used by this mesh instance.

pc.Meshmesh

The graphics mesh being instanced.

pc.GraphNodenode

The graph node defining the transform for this instance.

numberrenderStyle

The render style of the mesh instance. Can be:

Defaults to pc.RENDERSTYLE_SOLID.

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 pc.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 pc.MeshInstance to be rendered using Hardware Instancing.

Parameters

vertexBufferpc.VertexBuffer, 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[], pc.Texture

The value for the specified parameter.

passFlagsnumber

Mask describing which passes the material should be included in.