Class: Mesh

Mesh

Mesh contains the geometry of a renderable object. A MeshInstance component is used to combine a Mesh with a Material for rendering.

A Mesh can have vertex attributes spread out over several "streams". Every stream means a separate vertex buffer will be used.

A Mesh should have its layout defined using addVertexAttribute, and initial data supplied using setVertexData, before passing it on to a Model. These values will be used to calculate its local bounding box. After this, setVertexData can be called to change data, but it will not change the model


new Mesh(vertexUsage, indexUsage)

Parameters:
Name Type Description
vertexUsage BufferUsage

A usage hint for the vertex buffer.

indexUsage BufferUsage

A usage hint for the index buffer.

Properties:
Name Type Description
elementType

An ElementType to describe the type of elements to render.

Author:
  • derschmale <http://www.derschmale.com>

Members


<static> DEFAULT_VERTEX_SIZE

The vertex stride for meshes created with Mesh#createDefaultEmpty


bounds

The object-space bounding volume. Setting this value only changes the type of volume.


dynamicBounds

The object-space bounding volume. Setting this value only changes the type of volume.


hasMorphData

Whether or not this Mesh supports morph target animations. This is the case if Mesh#generateMorphData was called.


numIndices

The amount of face indices contained in the Mesh.


numStreams

The amount of streams (vertex buffers) used for this Mesh/


numVertexAttributes

The amount of vertex attributes contained in the Mesh.


numVertices

The amount of vertices contained in the Mesh.

Methods


<static> createDefaultEmpty()

Creates an empty Mesh with a default layout.


addMorphTarget()

Adds a MorphTarget object for animators to work with.


addVertexAttribute(name, numComponents, streamIndex, normalized)

Adds a named vertex attribute. All properties are given manually to make it easier to support multiple streams in the future.

Parameters:
Name Type Description
name

The name of the attribute, matching the attribute name used in the vertex shaders.

numComponents

The amount of components used by the attribute value.

streamIndex

[Optional] The stream index indicating which vertex buffer is used, defaults to 0

normalized

[Optional] Whether or not the input of the attribute should be normalized to [-1, 1]


clone()

Returns a duplicate of this Mesh.


extractAttributeData()

Extracts the vertex attribute data for the given attribute name as a flat Array.


generateMorphData()

Generates the required data to support morph target animations.


getIndexData()

Returns the index data uploaded to the index buffer.


getMorphTarget(index)

Gets the morph target by name.

Parameters:
Name Type Description
index name

The name of the MorphTarget

Returns:
Type
MorphTarget

getVertexAttributeByIndex()

Gets the vertex attribute data according to the index.


getVertexAttributeByName()

Gets the vertex attribute data according to the attribute name.


getVertexData()

Gets the vertex data for a given stream.


getVertexStride()

Gets the vertex stride (number of components used per stream per vertex) for a given stream


hasVertexAttribute()

Returns whether the Mesh has a vertex attribute with the given name.


hasVertexData()

Returns whether or not vertex data was uploaded to the given stream index.


removeMorphTarget()

Adds a MorphTarget object for animators to work with.


setIndexData()

Uploads index data from an Array or a Uint16Array


setVertexData()

Uploads vertex data from an Array or a Float32Array. This method must be called after the layout for the stream has been finalized using setVertexAttribute calls. The data in the stream should be an interleaved array of floats, with each attribute data in the order specified with the setVertexAttribute calls.