Class MeshData
Data container for the common model meshes data. Supports holding all types of data related to the models pipeline.
Inheritance
Assembly: FlaxEngine.dll
File: Engine/Graphics/Models/ModelData.h
Syntax
public class MeshData
Fields
BitangentSigns
Bitangents vectors signs (used for bitangent reconstruction). Can be +1 or -1. bitangent = cross(normal, tangent) * sign sign = dot(cross(bitangent, normal), tangent)
Declaration
public Array<float> BitangentSigns
Field Value
Array<float>
|
BlendIndices
Skinned mesh blend indices (max 4 per bone)
Declaration
public Array<Int4> BlendIndices
Field Value
Array<Int4>
|
BlendShapes
Blend shapes used by this mesh
Declaration
public Array<BlendShape> BlendShapes
Field Value
Array<BlendShape>
|
BlendWeights
Skinned mesh index buffer (max 4 per bone)
Declaration
public Array<Float4> BlendWeights
Field Value
Array<Float4>
|
Colors
Vertex colors
Declaration
public Array<Color> Colors
Field Value
Array<Color>
|
Indices
Mesh index buffer
Declaration
public Array<uint32> Indices
Field Value
Array<uint32>
|
LightmapUVsIndex
Lightmap texture coordinates channel index. Value -1 indicates that channel is not available.
Declaration
public int32 LightmapUVsIndex = -1
Field Value
int32
|
MaterialSlotIndex
The slot index in the model materials to use during rendering.
Declaration
public int32 MaterialSlotIndex = 0
Field Value
int32
|
Name
NodeIndex
The model skeleton node index. Used during importing and by the animated models.
Declaration
public int32 NodeIndex = 0
Field Value
int32
|
Normals
Normals vector
Declaration
public Array<Float3> Normals
Field Value
Array<Float3>
|
OriginOrientation
Orientation for this mesh at its local origin.
Declaration
public Quaternion OriginOrientation = Quaternion::Identity
Field Value
Quaternion
|
OriginTranslation
Local translation for this mesh to be at it's local origin.
Declaration
public Vector3 OriginTranslation = Vector3::Zero
Field Value
Vector3
|
Positions
Mesh positions buffer
Declaration
public Array<Float3> Positions
Field Value
Array<Float3>
|
Scaling
Meshes scaling.
Declaration
public Vector3 Scaling = Vector3::One
Field Value
Vector3
|
Tangents
Tangents vectors
Declaration
public Array<Float3> Tangents
Field Value
Array<Float3>
|
UVs
Texture coordinates (list of channels)
Declaration
public Array<Array<Float2>, FixedAllocation<MODEL_MAX_UV>> UVs
Field Value
Array<Array<Float2>, FixedAllocation<MODEL_MAX_UV>>
|
Methods
BuildIndexBuffer()
Iterates over the vertex buffers to remove the duplicated vertices and generate the optimized index buffer.
Declaration
public void BuildIndexBuffer()
CalculateBounds(BoundingBox& box, BoundingSphere& sphere)
Calculates bounding box and sphere for the mesh.
Declaration
public void CalculateBounds(BoundingBox& box, BoundingSphere& sphere) const
Parameters
BoundingBox
box
Output box. |
BoundingSphere
sphere
Output sphere. |
CalculateBox(BoundingBox& result)
Calculate bounding box for the mesh
Declaration
public void CalculateBox(BoundingBox& result) const
Parameters
BoundingBox
result
Output box |
CalculateSphere(BoundingSphere& result)
Calculate bounding sphere for the mesh
Declaration
public void CalculateSphere(BoundingSphere& result) const
Parameters
BoundingSphere
result
Output sphere |
CalculateTrianglesArea()
Sums the area of all triangles in the mesh.
Declaration
public float CalculateTrianglesArea() const
Returns
float
The area sum of all mesh triangles. |
Clear()
Clear arrays
Declaration
public void Clear()
EnsureCapacity(int32 vertices, int32 indices, bool preserveContents=false, bool withColors=true, bool withSkin=true, int32 texcoords=1)
Ensure that buffers will have given space for data
Declaration
public void EnsureCapacity(int32 vertices, int32 indices, bool preserveContents=false, bool withColors=true, bool withSkin=true, int32 texcoords=1)
Parameters
int32
vertices
Amount of vertices. |
int32
indices
Amount of indices. |
bool
preserveContents
Failed if clear data otherwise will try to preserve the buffers contents. |
bool
withColors
True if use vertex colors buffer. |
bool
withSkin
True if use vertex blend indices and weights buffer. |
int32
texcoords
Amount of texture coordinate channels to use. |
FindPositions(const Float3& position, float epsilon, Array<int32>& result)
Generate lightmap uvs for the mesh entry
Declaration
public void FindPositions(const Float3& position, float epsilon, Array<int32>& result)
Parameters
Float3
position
The target position to check. |
float
epsilon
The position comparision epsilon. |
Array<int32>
result
The output vertices indices array. |
GenerateLightmapUVs()
Generate lightmap uvs for the mesh entry
Declaration
public bool GenerateLightmapUVs()
Returns
bool
True if generating lightmap uvs failed, otherwise false |
GenerateNormals(float smoothingAngle=175.0f)
Generates the normal vectors for the mesh geometry.
Declaration
public bool GenerateNormals(float smoothingAngle=175.0f)
Parameters
float
smoothingAngle
Specifies the maximum angle (in degrees) that may be between two face normals at the same vertex position that their are smoothed together. |
Returns
bool
True if generating failed, otherwise false |
GenerateTangents(float smoothingAngle=45.0f)
Generates the tangent vectors for the mesh geometry. Requires normal vector and texture coords channel to be valid.
Declaration
public bool GenerateTangents(float smoothingAngle=45.0f)
Parameters
float
smoothingAngle
Specifies the maximum angle (in degrees) that may be between two vertex tangents that their tangents and bi-tangents are smoothed. |
Returns
bool
True if generating failed, otherwise false. |
ImproveCacheLocality()
Reorders all triangles for improved vertex cache locality. It tries to arrange all triangles to fans and to render triangles which share vertices directly one after the other.
Declaration
public void ImproveCacheLocality()
InitFromModelVertices(ModelVertex19* vertices, uint32 verticesCount)
Init from model vertices array
Declaration
public PRAGMA_DISABLE_DEPRECATION_WARNINGS void InitFromModelVertices(ModelVertex19* vertices, uint32 verticesCount)
Parameters
ModelVertex19
vertices
Array of vertices |
uint32
verticesCount
Amount of vertices |
Returns
PRAGMA_DISABLE_DEPRECATION_WARNINGS void
|
InitFromModelVertices(VB0ElementType18* vb0, VB1ElementType18* vb1, uint32 verticesCount)
Init from model vertices array
Declaration
public void InitFromModelVertices(VB0ElementType18* vb0, VB1ElementType18* vb1, uint32 verticesCount)
Parameters
VB0ElementType18
vb0
Array of data for vertex buffer 0 |
VB1ElementType18
vb1
Array of data for vertex buffer 1 |
uint32
verticesCount
Amount of vertices |
InitFromModelVertices(VB0ElementType18* vb0, VB1ElementType18* vb1, VB2ElementType18* vb2, uint32 verticesCount)
Init from model vertices array
Declaration
public void InitFromModelVertices(VB0ElementType18* vb0, VB1ElementType18* vb1, VB2ElementType18* vb2, uint32 verticesCount)
Parameters
VB0ElementType18
vb0
Array of data for vertex buffer 0 |
VB1ElementType18
vb1
Array of data for vertex buffer 1 |
VB2ElementType18
vb2
Array of data for vertex buffer 2 |
uint32
verticesCount
Amount of vertices |
Merge(MeshData& other)
Merges this mesh data with the specified other mesh.
Declaration
public void Merge(MeshData& other)
Parameters
MeshData
other
The other mesh to merge with. |
NormalizeBlendWeights()
Normalizes the blend weights. Requires to have vertices with positions and blend weights setup.
Declaration
public void NormalizeBlendWeights()
Release()
Clean data
Declaration
public void Release()
SetIndexBuffer(void* data, uint32 indicesCount)
Sets the index buffer data.
Declaration
public PRAGMA_ENABLE_DEPRECATION_WARNINGS void SetIndexBuffer(void* data, uint32 indicesCount)
Parameters
void
data
The data. |
uint32
indicesCount
The indices count. |
Returns
PRAGMA_ENABLE_DEPRECATION_WARNINGS void
|
SetLightmapUVsSource(ModelLightmapUVsSource source)
Setups Lightmap UVs based on the option.
Declaration
public void SetLightmapUVsSource(ModelLightmapUVsSource source)
Parameters
ModelLightmapUVsSource
source
|
SwapBuffers(MeshData& other)
Swaps the vertex and index buffers contents (without a data copy) with the other mesh.
Declaration
public void SwapBuffers(MeshData& other)
Parameters
MeshData
other
The other mesh to swap data with. |
TransformBuffer(const Matrix& matrix)
Transform a vertex buffer positions, normals, tangents and bitangents using the given matrix.
Declaration
public void TransformBuffer(const Matrix& matrix)
Parameters
Matrix
matrix
The matrix to use for the transformation. |