class MeshUtility

Performs various operations on mesh geometry.

Public

Methods

staticCalculateNormals

static void CalculateNormals(Vector3 *vertices, u8 *indices, u32 vertexCount, u32 indexCount, Vector3 *normals, u32 indexSize = 4)

Calculates per-vertex normals based on the provided vertices and indices.

vertices
Set of vertices containing vertex positions.
indices
Set of indices containing indexes into vertex array for each triangle.
vertexCount
Number of vertices in the array.
indexCount
Number of indices in the array. Must be a multiple of three.
normals
Pre-allocated buffer that will contain the calculated normals. Must be the same size as the vertex array.
indexSize
Size of a single index in the indices array, in bytes.

staticCalculateTangents

static void CalculateTangents(Vector3 *vertices, Vector3 *normals, Vector2 *uv, u8 *indices, u32 vertexCount, u32 indexCount, Vector3 *tangents, Vector3 *bitangents, u32 indexSize = 4, u32 vertexStride = 0)

Calculates per-vertex tangents and bitangents based on the provided vertices, uv coordinates and indices.

vertices
Set of vertices containing vertex positions.
normals
Set of normals to use when calculating tangents. Must the the same length as the number of vertices.
uv
Set of UV coordinates to use when calculating tangents. Must the the same length as the number of vertices.
indices
Set of indices containing indexes into vertex array for each triangle.
vertexCount
Number of vertices in the , and arrays.
indexCount
Number of indices in the array. Must be a multiple of three.
tangents
Pre-allocated buffer that will contain the calculated tangents. Must be the same size as the vertex array.
bitangents
Pre-allocated buffer that will contain the calculated bitangents. Must be the same size as the vertex array.
indexSize
Size of a single index in the indices array, in bytes.
vertexStride
Number of bytes to advance the , and arrays with each vertex. If set to zero them each array is advanced according to its own size.

staticCalculateTangentSpace

static void CalculateTangentSpace(Vector3 *vertices, Vector2 *uv, u8 *indices, u32 vertexCount, u32 indexCount, Vector3 *normals, Vector3 *tangents, Vector3 *bitangents, u32 indexSize = 4)

Calculates per-vertex tangent space (normal, tangent, bitangent) based on the provided vertices, uv coordinates and indices.

vertices
Set of vertices containing vertex positions.
uv
Set of UV coordinates to use when calculating tangents.
indices
Set of indices containing indexes into vertex array for each triangle.
vertexCount
Number of vertices in the "vertices" array.
indexCount
Number of indices in the "indices" array. Must be a multiple of three.
normals
Pre-allocated buffer that will contain the calculated normals. Must be the same size as the vertex array.
tangents
Pre-allocated buffer that will contain the calculated tangents. Must be the same size as the vertex array.
bitangents
Pre-allocated buffer that will contain the calculated bitangents. Must be the same size as the vertex array.
indexSize
Size of a single index in the indices array, in bytes.

staticClip2D

static void Clip2D(u8 *vertices, u8 *uvs, u32 triangleCount, u32 vertexStride, const Vector<Plane> &clipPlanes, const std::function<void (Vector2 *, Vector2 *, u32)> &writeCallback)

Clips a set of two-dimensional vertices and uv coordinates against a set of arbitrary planes.

vertices
A set of vertices in Vector2 format. Each vertex should be bytes from each other.
uvs
A set of UV coordinates in Vector2 format. Each coordinate should be bytes from each other. Can be null if UV is not needed.
triangleCount
Number of triangles to clip (must be number of vertices/uvs / 3).
vertexStride
Distance in bytes between two separate vertex or UV values in the provided and buffers.
clipPlanes
A set of planes to clip the vertices against. Since the vertices are two-dimensional the plane's Z coordinate should be zero.
writeCallback
Callback that will be triggered when clipped vertices and UV coordinates are generated and need to be stored. Vertices are always generate in tuples of three, forming a single triangle.

staticClip3D

static void Clip3D(u8 *vertices, u8 *uvs, u32 triangleCount, u32 vertexStride, const Vector<Plane> &clipPlanes, const std::function<void (Vector3 *, Vector2 *, u32)> &writeCallback)

Clips a set of three-dimensional vertices and uv coordinates against a set of arbitrary planes.

vertices
A set of vertices in Vector3 format. Each vertex should be bytes from each other.
uvs
A set of UV coordinates in Vector2 format. Each coordinate should be bytes from each other. Can be null if UV is not needed.
triangleCount
Number of triangles to clip (must be number of vertices/uvs / 3).
vertexStride
Distance in bytes between two separate vertex or UV values in the provided and buffers.
clipPlanes
A set of planes to clip the vertices against.
writeCallback
Callback that will be triggered when clipped vertices and UV coordinates are generated and need to be stored. Vertices are always generate in tuples of three, forming a single triangle.

staticPackNormals

static void PackNormals(Vector3 *source, u8 *destination, u32 count, u32 inputStride, u32 outputStride)

Encodes normals from 32-bit float format into 4D 8-bit packed format.

source
Buffer containing data to encode. Must have entries.
destination
Buffer to output the data to. Must have entries, each 32-bits.
count
Number of entries in the and arrays.
inputStride
Distance between two entries in the buffer, in bytes.
outputStride
Distance between two entries in the buffer, in bytes.

staticPackNormals

static void PackNormals(Vector4 *source, u8 *destination, u32 count, u32 inputStride, u32 outputStride)

Encodes normals from 32-bit float format into 4D 8-bit packed format.

source
Buffer containing data to encode. Must have entries.
destination
Buffer to output the data to. Must have entries, each 32-bits.
count
Number of entries in the and arrays.
inputStride
Distance between two entries in the buffer, in bytes.
outputStride
Distance between two entries in the buffer, in bytes.

staticUnpackNormals

static void UnpackNormals(u8 *source, Vector3 *destination, u32 count, u32 stride)

Decodes normals from 4D 8-bit packed format into a 32-bit float format.

source
Buffer containing data to encode. Must have entries, each 32-bits.
destination
Buffer to output the data to. Must have entries.
count
Number of entries in the and arrays.
stride
Distance between two entries in the buffer, in bytes.

staticUnpackNormals

static void UnpackNormals(u8 *source, Vector4 *destination, u32 count, u32 stride)

Decodes normals from 4D 8-bit packed format into a 32-bit float format.

source
Buffer containing data to encode. Must have entries, each 32-bits.
destination
Buffer to output the data to. Must have entries.
count
Number of entries in the and arrays.
stride
Distance between two entries in the buffer, in bytes.

staticUnpackNormal

static Vector3 UnpackNormal(const u8 *source)

Decodes a normal from 4D 8-bit packed format into a 32-bit float format.