B.Render.Mesh()

Represents a mesh, contains vertices and indexed primitives.

To create the object use device.makeMesh().

METHODS:

device()

Returns linked rendering device.

RETURNS:

attributes()

Returns array of vertex attributes names.

RETURNS:

{Array.<string>}

attribute(name, type)

Sets vertex attribute.

mesh.
    attribute("position", B.Render.Attribute.POSITION).
    attribute("normal", B.Render.Attribute.NORMAL).
    attribute("uv", B.Render.Attribute.VECTOR2);

mesh.attribute("uv", B.Render.Attribute.UV); // changing

mesh.attribute("uv", null); // removing

PARAMETERS:

{string} name

if the name is not found a new attribute will be pushed

{B.Render.Attribute | null} type

use the null value to remove existing attribute

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if attributes configuration is incorrect

attribute(name)

Gets vertex attribute.

PARAMETERS:

{string} name

if the name is not found the null value will be returned

RETURNS:

attribute(name, newName)

Renames vertex attribute.

mesh.attribute("uv", "uv0");

PARAMETERS:

{string} name

{string} newName

RETURNS:

{B.Render.Mesh}

this

vertexCount()

Returns vertex count.

RETURNS:

{number}

vertices(source, usage)

Sets vertex data.

If B.Render.Usage.DYNAMIC usage is specified the data source won't be preserved.

PARAMETERS:

{Array.<number> | Float32Array} source

{B.Render.Usage} [usage] = B.Render.Usage.STATIC

pattern of the data store

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if the data source is incorrect

vertices(vertexCount, usage)

Allocates specified vertex count (the data will be initialized to 0).

If B.Render.Usage.DYNAMIC usage is specified the data source won't be preserved.

PARAMETERS:

{number} vertexCount

{B.Render.Usage} [usage] = B.Render.Usage.STATIC

pattern of the data store

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if the vertex count is incorrect

vertices()

Gets the vertex data source.

RETURNS:

{Float32Array | null}

updateVertices(source, offset)

Updates vertices from a new or existent data source.

Note: if you repeatedly updates vertices it's highly recommended to use B.Render.Usage.DYNAMIC to avoid performance penalty.

PARAMETERS:

{Array.<number> | Float32Array} [source]

omit if you want to use existent data source

{number} [offset] = 0

elements offset where data replacement will begin

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if vertices are not initialized or the source has invalid type or the source data is out of range

flushVertices()

Flush linked vertex data source.

Note: the vertex data won't be restored after device lost.

RETURNS:

{B.Render.Mesh}

this

index()

Returns index type.

RETURNS:

indexCount()

Returns index count.

RETURNS:

{number}

indices(source, usage)

Sets index data.

If B.Render.Usage.DYNAMIC usage is specified the data source won't be preserved.

Some hardware supports 32-bit indices. To check it use device.caps().indexUInt flag.

PARAMETERS:

{Array.<number> | Uint16Array | Uint32Array} source

{B.Render.Usage} [usage] = B.Render.Usage.STATIC

pattern of the data store

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if the data source is incorrect

indices(indexCount, usage)

Allocate specified index count (the data will be initialized to 0).

If B.Render.Usage.DYNAMIC usage is specified the data source won't be preserved.

Some hardware supports 32-bit indices. To check it use device.caps().indexUInt flag.

PARAMETERS:

{number} indexCount

{B.Render.Usage} [usage] = B.Render.Usage.STATIC

pattern of the data store

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if the index count is incorrect

indices()

Gets the index data source.

RETURNS:

{Uint16Array | Uint32Array | null}

updateIndices(source, offset)

Updates indices from a new or existent data source.

Note: if you repeatedly updates indices it's highly recommended to use B.Render.Usage.DYNAMIC to avoid performance penalty.

PARAMETERS:

{Array.<number> | Uint16Array | Uint32Array} [source]

omit if you want to use existent data source

{number} [offset] = 0

elements offset where data replacement will begin

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if indices are not initialized or the source has invalid type or the source data is out of range

flushIndices()

Flush linked index data source.

Note: the index data won't be restored after device lost.

RETURNS:

{B.Render.Mesh}

this

primitive(type)

Sets primitive type.

PARAMETERS:

RETURNS:

{B.Render.Mesh}

this

primitive()

Gets primitive type.

RETURNS:

primitiveCount()

Returns primitive count.

RETURNS:

{number}

bounds(box)

Sets bounds.

PARAMETERS:

{B.Math.AABox} box

RETURNS:

{B.Render.Mesh}

this

bounds()

Gets bounds.

RETURNS:

computeBounds()

Computes bounds from vertex positions.

RETURNS:

{B.Render.Mesh}

this

THROWS:

{B.Render.Error}

if a vertex data source is not linked or the B.Render.Attribute.POSITION attribute is not found

free()

Frees all internal data and detach the resource from linked rendering device.

METHODS: