Methods
# destroy()
Triangle meshes create buffers on the graphics card. When you're done with a mesh, you must explicitly destroy it to free these buffers. (It's not done automatically because pawns can share meshes.)
# addFace(vertices, colors, coordinates, normalsopt)
Adds a set of triangles to the local geometry buffers to create a convex polygonal face. You need to specify the coordinates of the vertices and their color and texture coordinates. Vertex 0 is shared by all triangles in the face.
Name | Type | Attributes | Description |
---|---|---|---|
vertices |
Array.<Array.<number>> | [xyz] coordinates ordered CCW around face. |
|
colors |
Array.<Array.<number>> | [rgba] vertex colors |
|
coordinates |
Array.<Array.<number>> | [uv] vertex texture coordinates |
|
normals |
Array.<Array.<number>> |
<optional> |
[xyz] vertex normals (Automatically generated if not specified) |
const myMesh = new Triangles();
myMesh.addFace( // Add two triangles to makes a square face with black, red, green blue corners.
[[0,0,0], [1,0,0], [1,1,0], [0,1,0]],
[[0,0,0,1], [0,1,0,1], [0,0,1,1], [0,0,1,1]],
[[0,0], [1,0], [1,1], [0,1]]
)
# copy(triangles)
Copies another triangle mesh into this one. Only copies the local buffers, so you'll want to do a load afterwards.
Name | Type | Description |
---|---|---|
triangles |
Triangles |
# merge(triangles)
Merges another triangle mesh into this one. Only merges the local buffers, so you'll want to do a load afterwards.
Name | Type | Description |
---|---|---|
triangles |
Triangles |
# transform(matrix)
Transforms the vertex coordinates by 4x4 matrix. Also transforms the normals. Only affects the local coordinates, so you'll want to do a load afterwards.
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
# load()
Loads the local geometry buffers onto the graphics card. After you've created a triangle mesh, you must load it before it will be drawn.
# clear()
Clears the local geometry buffers. If you don't need to reuse the geometry, you can do this after you load to save memory.