MeshData

MeshData

Stores all buffers for geometric data and similar attributes

Constructor

new MeshData(attributeMap, vertexCount, indexCount)

Parameters:
Name Type Description
attributeMap Object

Describes which buffers to use and their format/sizes

vertexCount number

Number of vertices in buffer

indexCount number

Number of indices in buffer

Example
// Constructing a quad entity
var attributes = [MeshData.POSITION, MeshData.NORMAL, MeshData.TEXCOORD0];
var attributeMap = MeshData.defaultMap(attributes);
var vertexCount = 4;
var indexCount = 6;
var meshData = new MeshData(attributeMap, vertexCount, indexCount);
meshData.getAttributeBuffer(MeshData.POSITION).set([
    -1, -1, 0, // 0
    -1, 1, 0,  // 1
     1, 1, 0,  // 2
     1, -1, 0  // 3
]);
meshData.getAttributeBuffer(MeshData.NORMAL).set([
    0,0,1,  0,0,1,  0,0,1,  0,0,1
]);
meshData.getAttributeBuffer(MeshData.TEXCOORD0).set([
    0,0,  0,1,  1,1,  1,0
]);
meshData.getIndexBuffer().set([0,3,1, 1,3,2]);

var quadEntity = world.createEntity(meshData, new Material(ShaderLib.textured)).addToWorld();

Members

(static, readonly) COLOR :string

(static, readonly) JOINTIDS :string

(static, readonly) NORMAL :string

(static, readonly) POSITION :string

(static, readonly) TANGENT :string

(static, readonly) TEXCOORD0 :string

(static, readonly) TEXCOORD1 :string

(static, readonly) TEXCOORD2 :string

(static, readonly) TEXCOORD3 :string

(static, readonly) WEIGHTS :string

indexCount :number

The total number of indices in the buffer.

(nullable) indexLengths :Array.<number>

The number of indices used by each segment, or null to indicate only one segment that uses the whole index buffer.

indexModes :Array.<string>

The primitive rendering types to use, for each segment. Default value of this property is ['Triangles'], but also TriangleStrip, TriangleFan, Lines, LineStrip, LineLoop and Points are available.

vertexCount :number

The total number of vertices in the buffer.

Methods

(static) createAttribute(count, type, normalizedopt) → {Object}

Creates a definition for a vertex attribute

Parameters:
Name Type Attributes Default Description
count number

Tuple size of attribute

type string

Data type

normalized boolean <optional>
false

If data should be normalized (true) or converted direction (false)

(static) defaultMap(typesopt) → {Object}

Creates an attribute given the types

Parameters:
Name Type Attributes Description
types Array.<string> <optional>

An array of default types. If not provided you get an attributeMap with all default attributes

Example
var map = MeshData.defaultMap([MeshData.POSITION, MeshData.TEXCOORD0]);

applyFunction(attributeName, fun) → {MeshData}

Applies a function on the vertices of a specified attribute buffer

Parameters:
Name Type Description
attributeName string
fun function

applyTransform(attributeName, transform) → {MeshData}

Applies a transformation on a specified attribute buffer

Parameters:
Name Type Description
attributeName string
transform Transform

buildFlatMeshData() → {MeshData}

Builds flat meshdata from mesh

buildWireframeData() → {MeshData}

Builds the wireframe MeshData from an existing mesh

clone() → {MeshData}

Returns a clone of this mesh data

destroy(context)

Destroys all attached vertex and index data.

Parameters:
Name Type Description
context WebGLRenderingContext

getNormalsMeshData(sizeopt) → {MeshData}

Creates a new MeshData object representing the normals of the current MeshData object

Parameters:
Name Type Attributes Default Description
size number <optional>
1

The size of the normals

getPrimitiveCount() → {number}

getPrimitiveVertices(primitiveIndex, section, store) → {array}

Parameters:
Name Type Description
primitiveIndex number
section number
store array

getSectionCount() → {number}

getTotalPrimitiveCount() → {number}

Get the total primitive count. Note that you need to run .updatePrimitiveCounts() before use.

rebuildData(vertexCount, indexCount, saveOldData)

Rebuilds the mesh vertex and index data

Parameters:
Name Type Description
vertexCount number
indexCount number
saveOldData boolean

setAttributeDataUpdated()

Should be called if an attribute was updated during runtime.

Example
// Updating the vertex position during runtime
var data = meshData.getAttributeBuffer(MeshData.POSITION);
data.set([-1,-1,0, -1,1,0, 1,1,0, 1,-1,0]);
meshData.setAttributeDataUpdated(MeshData.POSITION);

setVertexDataUpdated()

Requests a refresh on the vertex data