Create a new Triangle.
Optional
vertexData: Float32ArrayIf supplied, uses this vertex data for the triangle, with the same format as vertexData. If not supplied, then creates a new vertex data array where all vertices have values of 0 for all attributes.
Private
bitGeneric data of this triangle, packed in a single integer.
Bits 0-5: Which edge of another triangle is each respective edge connected to?
Other triangle's edge index can be 0, 1 or 2. If 3, then the edge is not connected.
Bits 6-31: 25-bit material ID. Triangles with different material IDs will be put in different WL.Mesh instances, but the same manifold if they are connected.
Private
edgeThe triangle connected to edge 0
Private
edgeThe triangle connected to edge 1
Private
edgeThe triangle connected to edge 2
A generic helper variable intended to be used as an index.
Readonly
vertexThe positions, normals and UVs of each triangle. Even though normals and UVs are optional, space will still be reserved for them.
The format is interleaved:
Get a list of triangles that are connected to this triangle by checking the connected edges.
A list of triangles that are connected to this triangle. Will have at most a length of 3.
The material ID of this triangle. This will map to a WL.Material instance once the Triangle is converted to a WL.Mesh.
Automatically make tangents for this triangle, by using the direction of an edge of the triangle as the tangent.
The index of the edge to use as the direction. For example, if 0 is used, then the direction from vertex 0 to vertex 1 is used as the direction of the tangent.
If true, then the direction of the edge will be flipped. False by default.
Connect a given edge to any other triangle's edge. When connecting, the other triangle is modified. If there is already a connection on the edge, then the edge is diconnected (same for the other triangle's edge).
The index of the edge in counter-clockwise order. For example, edge 0 is the edge between vertex 0 and vertex 1.
The index of the edge of the other triangle in counter-clockwise order. For example, edge 0 is the edge between vertex 0 and vertex 1.
The other triangle to connect to.
Disconnect a given edge from any other triangle that it's connected to. When disconnecting, the other triangle is modified.
The index of the edge in counter-clockwise order. For example, edge 0 is the edge between vertex 0 and vertex 1.
Get the edge that is connected to a given edge of this triangle, as a pair containing the other edge index and the other triangle.
If the edge is not connected, returns null, otherwise, returns a tuple containing the other edge index and the other triangle.
The index of the edge in counter-clockwise order. For example, edge 0 is the edge between vertex 0 and vertex 1.
Get the face normal of this triangle. Equivalent to calling normalFromTriangle with this triangle's vertex positions.
Check whether the edge between 2 given vertices matches any edge from another triangle
0 to 2 if an edge of another triangle matches with the input edge, where the returned number is the matching edge index, or null if no edge matches.
The index of the vertex, from 0 to 2, of the first point in the edge of this triangle.
The index of the vertex, from 0 to 2, of the second point in the edge of this triangle.
The other triangle to compare edges with.
Get the offset on the vertexData buffer for a specific vertex.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
Get the vertex star of a specific vertex. The star of a vertex is a list of triangles that are connected to a vertex.
A list of triangles and vertex indices that share the given vertex. Given as a list of pairs, where each pair contains the connected triangle, and the vertex index in that triangle.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
Check if the position of a vertex matches the position of another vertex from another triangle.
True if the position matches, false otherwise.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
The index of the vertex in the other triangle, from 0 to 2. 0 is the first vertex of the triangle, etc...
The triangle which has the other vertex.
Rotate the triangle by a given rotation.
The quaternion to rotate by.
Should the normals of the triangle be rotated? Defaults to true.
Should the tangents of the triangle be rotated? Defaults to true.
Set the colors of all vertices in this triangle.
The new color for the vertex (vertex 0).
The new color for the vertex (vertex 1).
The new color for the vertex (vertex 2).
Private
setSet the normal of a vertex at a given vertex index.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
The new normal for the vertex.
Set the normals of all vertices in this triangle.
The new normal for the vertex (vertex 0).
The new normal for the vertex (vertex 1).
The new normal for the vertex (vertex 2).
Set the position of a vertex at a given vertex index.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
The new position for the vertex.
Set the positions of all vertices in this triangle.
The new position for the vertex (vertex 0).
The new position for the vertex (vertex 1).
The new position for the vertex (vertex 2).
Set the tangent of a vertex at a given vertex index.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
The new tangent for the vertex.
Set the tangents of all vertices in this triangle.
The new tangent for the vertex (vertex 0).
The new tangent for the vertex (vertex 1).
The new tangent for the vertex (vertex 2).
Set the texture coordinates of a vertex at a given vertex index.
The index of the vertex, from 0 to 2. 0 is the first vertex of the triangle, etc...
The new texture coordinates for the vertex.
Set the UVs of all vertices in this triangle.
The new UV for the vertex (vertex 0).
The new UV for the vertex (vertex 1).
The new UV for the vertex (vertex 2).
Transform vertices by a given transformation matrix. By default, normals and tangents are also transformed. If they are transformed, then a normal matrix needs to be supplied, otherwise they are not transformed.
The transformation matrix to transform positions by.
Optional
normalMatrix: mat3The transformation matrix to transform normals and tangents by. Will be ignored if normals and tangents aren't transformed. If not supplied and normals or tangents are to be transformed, then the triangle's normals and tangents will not be transformed.
Should the normals of the triangle be transformed? Defaults to true.
Should the tangents of the triangle be transformed? Defaults to true.
Static
fromCreate a new Triangle from WL.Mesh data.
The index of the first vertex in the given mesh attributes
The index of the second vertex in the given mesh attributes
The index of the third vertex in the given mesh attributes
A mesh attribute accessor for the mesh's vertex positions
An optional mesh attribute accessor for the mesh's vertex normals
An optional mesh attribute accessor for the mesh's vertex texture coordinates
An optional mesh attribute accessor for the mesh's vertex tangents
An optional mesh attribute accessor for the mesh's vertex colors
Static
fromCreate a new Triangle from a list of vertices, in counter-clockwise order. Each vertex has the same interleaved format as vertexData, but only has a single vertex instead of 3.
The first vertex.
The second vertex.
The third vertex.
Generated using TypeDoc
An easy-to-use triangle representation. Memory efficient per triangle, but not per whole mesh, as it does not share vertex data with other triangles. Represents a manifold by providing which triangle an edge is connected to. Winding order is counter-clockwise.