Open 3D Engine EMotionFX Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
EMotionFX::Mesh Class Reference

#include <Mesh.h>

Inherits EMotionFX::BaseObject.

Public Types

enum  : uint32 {
  ATTRIB_POSITIONS = 0 , ATTRIB_NORMALS = 1 , ATTRIB_TANGENTS = 2 , ATTRIB_UVCOORDS = 3 ,
  ATTRIB_ORGVTXNUMBERS = 5 , ATTRIB_BITANGENTS = 7
}
 
enum  { MEMORYBLOCK_ID = 100 }
 
enum  EMeshType { MESHTYPE_STATIC = 0 , MESHTYPE_CPU_DEFORMED = 1 , MESHTYPE_GPU_DEFORMED = 2 }
 

Public Member Functions

void CalcNormals (bool useDuplicates=false)
 
bool CalcTangents (uint32 uvLayer=0, bool storeBitangents=false)
 
void Allocate (uint32 numVerts, uint32 numIndices, uint32 numPolygons, uint32 numOrgVerts)
 
void ReleaseData ()
 
MCORE_INLINE uint32 GetNumVertices () const
 
size_t CalcNumUVLayers () const
 
size_t CalcNumAttributeLayers (uint32 type) const
 
MCORE_INLINE uint32 GetNumOrgVertices () const
 
void ResetToOriginalData ()
 
MCORE_INLINE uint32 * GetIndices () const
 
MCORE_INLINE uint8 * GetPolygonVertexCounts () const
 
MCORE_INLINE uint32 GetNumIndices () const
 
MCORE_INLINE uint32 GetNumPolygons () const
 
MCORE_INLINE void AddSubMesh (SubMesh *subMesh)
 
MCORE_INLINE size_t GetNumSubMeshes () const
 
MCORE_INLINE SubMeshGetSubMesh (size_t nr) const
 
MCORE_INLINE void SetSubMesh (size_t nr, SubMesh *subMesh)
 
MCORE_INLINE void SetNumSubMeshes (size_t numSubMeshes)
 
void RemoveSubMesh (size_t nr, bool delFromMem=true)
 
void InsertSubMesh (size_t insertIndex, SubMesh *subMesh)
 
VertexAttributeLayerGetSharedVertexAttributeLayer (size_t layerNr)
 
void AddSharedVertexAttributeLayer (VertexAttributeLayer *layer)
 
size_t GetNumSharedVertexAttributeLayers () const
 
size_t FindSharedVertexAttributeLayerNumber (uint32 layerTypeID, size_t occurrence=0) const
 
VertexAttributeLayerFindSharedVertexAttributeLayer (uint32 layerTypeID, size_t occurence=0) const
 
void RemoveAllSharedVertexAttributeLayers ()
 
void RemoveSharedVertexAttributeLayer (size_t layerNr)
 
size_t GetNumVertexAttributeLayers () const
 
VertexAttributeLayerGetVertexAttributeLayer (size_t layerNr)
 
void AddVertexAttributeLayer (VertexAttributeLayer *layer)
 
void ReserveVertexAttributeLayerSpace (uint32 numLayers)
 
size_t FindVertexAttributeLayerNumber (uint32 layerTypeID, size_t occurrence=0) const
 
size_t FindVertexAttributeLayerNumberByName (uint32 layerTypeID, const char *name) const
 
VertexAttributeLayerFindVertexAttributeLayerByName (uint32 layerTypeID, const char *name) const
 
VertexAttributeLayerFindVertexAttributeLayer (uint32 layerTypeID, size_t occurence=0) const
 
size_t FindVertexAttributeLayerIndexByName (const char *name) const
 
size_t FindVertexAttributeLayerIndexByNameString (const AZStd::string &name) const
 
size_t FindVertexAttributeLayerIndexByNameID (uint32 nameID) const
 
size_t FindSharedVertexAttributeLayerIndexByName (const char *name) const
 
size_t FindSharedVertexAttributeLayerIndexByNameString (const AZStd::string &name) const
 
size_t FindSharedVertexAttributeLayerIndexByNameID (uint32 nameID) const
 
void RemoveAllVertexAttributeLayers ()
 
void RemoveVertexAttributeLayer (size_t layerNr)
 
bool Intersects (const Transform &transform, const MCore::Ray &ray)
 
bool Intersects (const Transform &transform, const MCore::Ray &ray, AZ::Vector3 *outIntersect, float *outBaryU=nullptr, float *outBaryV=nullptr, uint32 *outIndices=nullptr)
 
void GatherBonesForFace (uint32 startIndexOfFace, AZStd::vector< Node * > &outBones, Actor *actor)
 
uint32 CalcMaxNumInfluencesForFace (uint32 startIndexOfFace) const
 
size_t CalcMaxNumInfluences () const
 
size_t CalcMaxNumInfluences (AZStd::vector< size_t > &outVertexCounts) const
 
void ExtractOriginalVertexPositions (AZStd::vector< AZ::Vector3 > &outPoints) const
 
MeshClone ()
 
void SwapVertex (uint32 vertexA, uint32 vertexB)
 
void RemoveVertices (uint32 startVertexNr, uint32 endVertexNr, bool changeIndexBuffer=true, bool removeEmptySubMeshes=false)
 
size_t RemoveEmptySubMeshes (bool onlyRemoveOnZeroVertsAndTriangles=true)
 
void * FindVertexData (uint32 layerID, size_t occurrence=0) const
 
void * FindVertexDataByName (uint32 layerID, const char *name) const
 
void * FindOriginalVertexData (uint32 layerID, size_t occurrence=0) const
 
void * FindOriginalVertexDataByName (uint32 layerID, const char *name) const
 
void CalcAabb (AZ::Aabb *outBoundingBox, const Transform &transform, uint32 vertexFrequency=1)
 
EMeshType ClassifyMeshType (size_t lodLevel, Actor *actor, size_t nodeIndex, bool forceCPUSkinning, uint32 maxInfluences, uint32 maxBonesPerSubMesh) const
 
void Log ()
 
bool ConvertTo16BitIndices ()
 
bool CheckIfIsTriangleMesh () const
 
bool CheckIfIsQuadMesh () const
 
uint32 CalcNumTriangles () const
 
void Scale (float scaleFactor)
 
uint16 GetNumUniqueJoints () const
 
void SetNumUniqueJoints (uint16 numUniqueJoints)
 
uint16 GetHighestJointIndex () const
 
void SetHighestJointIndex (uint16 highestJointIndex)
 
MCORE_INLINE bool GetIsCollisionMesh () const
 
void SetIsCollisionMesh (bool isCollisionMesh)
 
- Public Member Functions inherited from EMotionFX::BaseObject
 BaseObject ()
 
virtual ~BaseObject ()
 
- Public Member Functions inherited from MCore::MemoryObject
 MemoryObject ()
 
virtual ~MemoryObject ()
 
void IncreaseReferenceCount ()
 
void DecreaseReferenceCount ()
 
void Destroy ()
 
uint32 GetReferenceCount () const
 

Static Public Member Functions

static MeshCreate ()
 
static MeshCreate (uint32 numVerts, uint32 numIndices, uint32 numPolygons, uint32 numOrgVerts, bool isCollisionMesh)
 
static MeshCreateFromModelLod (const AZ::Data::Asset< AZ::RPI::ModelLodAsset > &sourceModelLod, const AZStd::unordered_map< AZ::u16, AZ::u16 > &skinToSkeletonIndexMap)
 
static void CalcTangentAndBitangentForFace (const AZ::Vector3 &posA, const AZ::Vector3 &posB, const AZ::Vector3 &posC, const AZ::Vector2 &uvA, const AZ::Vector2 &uvB, const AZ::Vector2 &uvC, AZ::Vector3 *outTangent, AZ::Vector3 *outBitangent)
 

Protected Member Functions

 Mesh ()
 
 Mesh (uint32 numVerts, uint32 numIndices, uint32 numPolygons, uint32 numOrgVerts, bool isCollisionMesh)
 
 ~Mesh ()
 
- Protected Member Functions inherited from EMotionFX::BaseObject
void Delete () override
 
virtual void Delete ()
 

Protected Attributes

AZStd::vector< SubMesh * > m_subMeshes
 
uint32 * m_indices
 
uint8 * m_polyVertexCounts
 
uint32 m_numPolygons
 
uint32 m_numOrgVerts
 
uint32 m_numVertices
 
uint32 m_numIndices
 
uint16 m_numUniqueJoints
 
uint16 m_highestJointIndex
 
bool m_isCollisionMesh
 
AZStd::vector< VertexAttributeLayer * > m_sharedVertexAttributes
 
AZStd::vector< VertexAttributeLayer * > m_vertexAttributes
 

Detailed Description

The mesh base class. Every mesh contains a list of vertex data (positions, normals and uv coordinates) and a set of indices. The indices describe the polygons and point into the vertex data. The vertex data is stored in seperate layers. So the position, normal, uv and tangent data is stored in three layers/arrays. You can access the vertex data with FindVertexData() and FindOriginalVertexData(). The length of all these arrays equals the value returned by GetNumVertices(). So this means that there are ALWAYS the same amount of positions, normals and uv coordinates in the mesh. Vertices automatically are duplicated when needed. This means that a flat shaded cube of triangles which normally has 8 vertices will have 24 vertices in this mesh. This is done, because you can use this vertex data directly to render it on the graphics hardware and it allows multiple normals and texture coordinates per vertex, which is needed for good texture mapping support and support for smoothing groups and flat shading. Still, each of the 24 vertices in the 'cube' example will have indices to their original vertices (which are not stored). This array of indices can be accessed by calling GetOrgVerts(). The values stored in this array will range from [0..7]. The mesh also contains a set of vertex attributes, which are user defined attributes per vertex. Next to that there also are shared vertex attributes, which are only there for the real number of vertices. All vertices have the same number of attributes, and attribute number 'n' has to be of the same type for all vertices as well.

See also
SubMesh.
FindVertexData.
FindOriginalVertexData.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : uint32

VertexAttributeLayerAbstractData::GetType() values for the vertex data Use these with the Mesh::FindVertexData() and Mesh::FindOriginalVertexData() methods.

Enumerator
ATTRIB_POSITIONS 

Vertex positions. Typecast to AZ::Vector3. Positions are always exist.

ATTRIB_NORMALS 

Vertex normals. Typecast to AZ::Vector3. Normals are always exist.

ATTRIB_TANGENTS 

Vertex tangents. Typecast to AZ::Vector4 .

ATTRIB_UVCOORDS 

Vertex uv coordinates. Typecast to AZ::Vector2.

ATTRIB_ORGVTXNUMBERS 

Original vertex numbers. Typecast to uint32. Original vertex numbers always exist.

ATTRIB_BITANGENTS 

Vertex bitangents (aka binormal). Typecast to AZ::Vector3. When tangents exists bitangents may still not exist!

◆ anonymous enum

anonymous enum

The memory block ID where mesh data will be allocated in. Giving mesh data their own memory blocks can reduce the amount of used total blocks when memory gets deleted again.

◆ EMeshType

The mesh type used to indicate if a mesh is either static, like a cube or building, cpu deformed, if it needs to be processed on the CPU, or GPU deformed if it can be processed fully on the GPU.

Enumerator
MESHTYPE_STATIC 

Static rigid mesh, like a cube or building (can still be position/scale/rotation animated though).

MESHTYPE_CPU_DEFORMED 

Deformed on the CPU.

MESHTYPE_GPU_DEFORMED 

Deformed on the GPU.

Constructor & Destructor Documentation

◆ Mesh() [1/2]

EMotionFX::Mesh::Mesh ( )
protected

Default constructor.

◆ Mesh() [2/2]

EMotionFX::Mesh::Mesh ( uint32  numVerts,
uint32  numIndices,
uint32  numPolygons,
uint32  numOrgVerts,
bool  isCollisionMesh 
)
protected

Constructor which allocates mesh data. Please keep in mind that this does not create and add any layers for position, normal, tangent, uv data etc.

Parameters
numVertsThe number of vertices to allocate.
numIndicesThe number of indices to allocate.
numPolygonsThe number of polygons to allocate.
numOrgVertsThe number of original vertices.
isCollisionMeshSet to true if this mesh is a collision mesh.

◆ ~Mesh()

EMotionFX::Mesh::~Mesh ( )
protected

Destructor. Automatically releases all data.

Member Function Documentation

◆ AddSharedVertexAttributeLayer()

void EMotionFX::Mesh::AddSharedVertexAttributeLayer ( VertexAttributeLayer layer)

Adds a new layer of shared vertex attributes. The data will automatically be deleted from memory on destruction of the mesh.

Parameters
layerThe layer to add. The array must contain GetNumOrgVertices() elements.

◆ AddSubMesh()

MCORE_INLINE void Mesh::AddSubMesh ( SubMesh subMesh)

Add a SubMesh to this mesh.

Parameters
subMeshA pointer to the SubMesh to add.

◆ AddVertexAttributeLayer()

void EMotionFX::Mesh::AddVertexAttributeLayer ( VertexAttributeLayer layer)

Adds a new layer of vertex attributes. The data will automatically be deleted from memory on destruction of the mesh.

Parameters
layerThe layer to add. The array must contain GetNumVertices() elements.

◆ Allocate()

void EMotionFX::Mesh::Allocate ( uint32  numVerts,
uint32  numIndices,
uint32  numPolygons,
uint32  numOrgVerts 
)

Allocate mesh data. If there is already data allocated, this data will be deleted first. Please keep in mind this does not create and add any layers for position, normal, uv and tangent data etc. Only indices will be allocated.

Parameters
numVertsThe number of vertices to allocate.
numIndicesThe number of indices to allocate.
numPolygonsThe number of polygons to allocate.
numOrgVertsThe number of original vertices.

◆ CalcAabb()

void EMotionFX::Mesh::CalcAabb ( AZ::Aabb *  outBoundingBox,
const Transform &  transform,
uint32  vertexFrequency = 1 
)

Calculate the axis aligned bounding box of this mesh, after transforming the positions with the provided transform.

Parameters
outBoundingBoxThe bounding box that will contain the bounds after executing this method.
TransformThe transformation to transform all vertex positions with.
vertexFrequencyThis is the for loop increase counter value. A value of 1 means every vertex will be processed while a value of 2 means every second vertex, etc. The value must be 1 or higher.

◆ CalcMaxNumInfluences() [1/2]

size_t EMotionFX::Mesh::CalcMaxNumInfluences ( ) const

Calculates the maximum number of bone influences. This is calculated by for each vertex checking the number of bone influences, and take the maximum of that amount.

Returns
The maximum number of influences. This will be 0 for non-softskinned objects.

◆ CalcMaxNumInfluences() [2/2]

size_t EMotionFX::Mesh::CalcMaxNumInfluences ( AZStd::vector< size_t > &  outVertexCounts) const

Calculates the maximum number of bone influences. This is calculated by for each vertex checking the number of bone influences, and take the maximum of that amount.

Parameters
vertexCountsReference to an interger array, which will be filled by this function with vertex counts for specific number of influences. array[0] e.g. holds the number of vertices which have no influences, so non-skinned; array[4] holds the number of vertices which are effected by 4 bones.
Returns
The maximum number of influences. This will be 0 for non-softskinned objects.

◆ CalcMaxNumInfluencesForFace()

uint32 EMotionFX::Mesh::CalcMaxNumInfluencesForFace ( uint32  startIndexOfFace) const

Calculates the maximum number of bone influences for a given face. This is calculated by for each vertex checking the number of bone influences, and take the maximum of that amount.

Parameters
startIndexOfFaceThe start index of the first vertex of the face. So not the vertex number, but the offset in the index array of this mesh.
Returns
The maximum number of influences of the given face. This will be 0 for non-softskinned objects.

◆ CalcNormals()

void EMotionFX::Mesh::CalcNormals ( bool  useDuplicates = false)

Recalculates the vertex normals.

Parameters
useDuplicatesSetting this to true will cause hard borders at vertices that have been duplicated. Setting to false (default) will use the original mesh vertex positions only which results in the mesh being fully smoothed. On a cube however that would not work well, as it won't preserve the hard face normals, but it will smooth the normals. Most of the time on character you would want to set this to false though, to prevent seams from showing up in areas between the neck and body.

◆ CalcNumAttributeLayers()

size_t EMotionFX::Mesh::CalcNumAttributeLayers ( uint32  type) const

Calculate the number of vertex attribute layers of the given type. It is recommended NOT to put this function inside a loop, because it is not very fast.

Parameters
[in]typeThe type of the vertex attribute layer to count.
Returns
The number of layers/sets currently present inside this mesh.

◆ CalcNumTriangles()

uint32 EMotionFX::Mesh::CalcNumTriangles ( ) const

Calculate how many triangles this mesh has. In case the mesh contains polygons of more than 3 vertices, triangulation will be taken into account.

Returns
The number of triangles that are needed to draw this mesh.

◆ CalcNumUVLayers()

size_t EMotionFX::Mesh::CalcNumUVLayers ( ) const

Extract the number of UV coordinate layers. It is recommended NOT to put this function inside a loop, because it is not very fast.

Returns
The number of UV layers/sets currently present inside this mesh.

◆ CalcTangentAndBitangentForFace()

static void EMotionFX::Mesh::CalcTangentAndBitangentForFace ( const AZ::Vector3 &  posA,
const AZ::Vector3 &  posB,
const AZ::Vector3 &  posC,
const AZ::Vector2 &  uvA,
const AZ::Vector2 &  uvB,
const AZ::Vector2 &  uvC,
AZ::Vector3 *  outTangent,
AZ::Vector3 *  outBitangent 
)
static

Calculates the tangent and bitangent for a given triangle.

Parameters
posAThe position of the first vertex.
posBThe position of the second vertex.
posCThe position of the third vertex.
uvAThe texture coordinate of the first vertex.
uvBThe texture coordinate of the second vertex.
uvCThe texture coordinate of the third vertex.
outTangentA pointer to the vector to store the calculated tangent vector.
outBitangentA pointer to the vector to store the calculated bitangent vector (calculated using the gradients).

◆ CalcTangents()

bool EMotionFX::Mesh::CalcTangents ( uint32  uvLayer = 0,
bool  storeBitangents = false 
)

Calculates the tangent vectors which can be used for per pixel lighting. These are vectors also known as S and T, used in per pixel lighting techniques, like bumpmapping. You can calculate the bitangent for the given tangent by taking the cross product between the normal and the tangent for the given vertex. These three vectors (normal, tangent and bitangent) are used to build a matrix which transforms the lights into tangent space. You can only call this method after you have passed all other vertex and index data to the mesh. So after all that has been initialized, call this method to calculate these vectors automatically. If you specify a UV set that doesn't exist, this method will fall back to UV set 0.

Parameters
uvLayer[in]The UV texture coordinate layer number. This is not the vertex attribute layer number, but the UV layer number. This means that 0 means the first UV set, and 1 would mean the second UV set, etc. When the UV layer doesn't exist, this method does nothing.
storeBitangentsSet to true when you want the mesh to store its bitangents in its own layer. This will generate a bitangents layer inside the mesh. False will no do this.
Returns
Returns true on success, or false on failure. A failure can happen when no UV data can be found.

◆ CheckIfIsQuadMesh()

bool EMotionFX::Mesh::CheckIfIsQuadMesh ( ) const

Check if this mesh is a pure quad mesh. Please keep in mind that this method is quite heavy to process as it iterates over all polygons to check if the vertex count equals to 4 for all polygons in the worst case.

Returns
Returns true in case this mesh contains only quads, otherwise false is returned.

◆ CheckIfIsTriangleMesh()

bool EMotionFX::Mesh::CheckIfIsTriangleMesh ( ) const

Check if this mesh is a pure triangle mesh. Please keep in mind that this method is quite heavy to process as it iterates over all polygons to check if the vertex count equals to 3 for all polygons in the worst case.

Returns
Returns true in case this mesh contains only triangles, otherwise false is returned.

◆ ClassifyMeshType()

EMeshType EMotionFX::Mesh::ClassifyMeshType ( size_t  lodLevel,
Actor actor,
size_t  nodeIndex,
bool  forceCPUSkinning,
uint32  maxInfluences,
uint32  maxBonesPerSubMesh 
) const

Check for a given mesh how we categorize it. A mesh can be either static, like a cube or building, dynamic if it has mesh deformers which have to be processed on the CPU like a morphing deformer or gpu skinned if they only have a skinning deformer applied. There are additional criteria like the maximum number of influences and the maximum number of bones per submesh to make it fit to different hardware specifications.

Parameters
lodLevelThe geometry LOD level of the mesh to check.
actorThe actor where this mesh belongs to.
nodeIndexThe index of the node that has this mesh.
forceCPUSkinningIf true the function will never return MESHTYPE_GPUSKINNED which means that no hardware processing will be used.
maxInfluencesThe maximum number of influences per vertex that can be processed on hardware. If there will be more influences the mesh will be processed in software which will be very slow.
maxBonesPerSubMeshThe maximum number of bones per submesh can be processed on hardware. If there will be more bones per submesh the mesh will be processed in software which will be very slow.
Returns
The mesh type meaning if the given mesh is static like a cube or building or if is deformed by the GPU or CPU.

◆ Clone()

Mesh * EMotionFX::Mesh::Clone ( )

Clone the mesh.

Returns
A pointer to a mesh that contains exactly the same data as this mesh.

◆ ConvertTo16BitIndices()

bool EMotionFX::Mesh::ConvertTo16BitIndices ( )

Convert the 32-bit vertex indices to 16-bit index values. Do not call this function more than once per mesh. The number of indices will stay the same while the size of the index buffer will be half as big as before. When calling GetIndices() make sure to type-cast the returned pointer to an uint16*.

Returns
True in case all indices have been ported correctly, false if any of the indices was out of the 16-bit range.

◆ Create() [1/2]

static Mesh * EMotionFX::Mesh::Create ( )
static

Default constructor.

◆ Create() [2/2]

static Mesh * EMotionFX::Mesh::Create ( uint32  numVerts,
uint32  numIndices,
uint32  numPolygons,
uint32  numOrgVerts,
bool  isCollisionMesh 
)
static

Constructor which allocates mesh data. Please keep in mind that this does not create and add any layers for position, normal, tangent, uv data etc.

Parameters
numVertsThe number of vertices to allocate.
numIndicesThe number of indices to allocate.
numPolygonsThe number of polygons to allocate.
numOrgVertsThe number of original vertices.
isCollisionMeshSet to true if this mesh is a collision mesh.

◆ ExtractOriginalVertexPositions()

void EMotionFX::Mesh::ExtractOriginalVertexPositions ( AZStd::vector< AZ::Vector3 > &  outPoints) const

Extract a list of positions of the original vertices. For a cube, which normally might have 32 vertices, it will result in 8 positions.

Parameters
outPointsThe output array to store the points in. The array will be automatically resized.

◆ FindOriginalVertexData()

void * EMotionFX::Mesh::FindOriginalVertexData ( uint32  layerID,
size_t  occurrence = 0 
) const

Find specific original vertex data in the mesh. The difference between the original vertex data and current vertex data as returned by FindVertexData is that the original vertex data is the data stored in the base pose, before any mesh deformers are being applied to it. Here are some examples to get common vertex data:

Vector3* positions = (Vector3*)mesh->FindOriginalVertexData( Mesh::ATTRIB_POSITIONS );   // the positions
Vector3* normals   = (Vector3*)mesh->FindOriginalVertexData( Mesh::ATTRIB_NORMALS   );   // the normals
Vector4* tangents  = (Vector4*)mesh->FindOriginalVertexData( Mesh::ATTRIB_TANGENTS  );   // first set of tangents, can be nullptr, and note the Vector4!
AZ::Vector2* uvCoords  = static_cast<AZ::Vector2*>(mesh->FindOriginalVertexData( Mesh::ATTRIB_UVCOORDS  ));  // the first set of UVs, can be nullptr
AZ::Vector2* uvCoords2 = static_cast<AZ::Vector2*>(mesh->FindOriginalVertexData( Mesh::ATTRIB_UVCOORDS, 1 ));    // the second set of UVs, can be nullptr
Parameters
layerIDThe layer type ID to get the information from.
occurrenceThe layer number to get. Where 0 means the first layer, 1 means the second, etc. This is used when there are multiple layers of the same type. An example is a mesh having multiple UV layers.
Returns
A void pointer to the layer data. You have to typecast yourself.

◆ FindSharedVertexAttributeLayer()

VertexAttributeLayer * EMotionFX::Mesh::FindSharedVertexAttributeLayer ( uint32  layerTypeID,
size_t  occurence = 0 
) const

Find and return the shared vertex attribute layer of a given type. If you like to find the first layer of the given type, the occurence parameter must be set to a value of 0. If you like to find the second layer of this type, the occurence parameter must be set to a value of of 1, etc. This function will return nullptr when the layer cannot be found.

Parameters
layerTypeIDthe layer type ID to search for.
occurenceThe occurence to search for. Set to 0 when you want the first layer of this type, set to 1 if you want the second layer of the given type, etc.
Returns
A pointer to the vertex attribute layer, or nullptr when none could be found.

◆ FindSharedVertexAttributeLayerNumber()

size_t EMotionFX::Mesh::FindSharedVertexAttributeLayerNumber ( uint32  layerTypeID,
size_t  occurrence = 0 
) const

Find and return the shared vertex attribute layer of a given type. If you like to find the first layer of the given type, the occurence parameter must be set to a value of 0. If you like to find the second layer of this type, the occurence parameter must be set to a value of of 1, etc. This function will return nullptr when the layer cannot be found.

Parameters
layerTypeIDthe layer type ID to search for.
occurrenceThe occurence to search for. Set to 0 when you want the first layer of this type, set to 1 if you want the second layer of the given type, etc.
Returns
The vertex attribute layer index number that you can pass to GetSharedVertexAttributeLayer. A value of MCORE_INVALIDINDEX32 is returned when no result could be found.

◆ FindVertexAttributeLayer()

VertexAttributeLayer * EMotionFX::Mesh::FindVertexAttributeLayer ( uint32  layerTypeID,
size_t  occurence = 0 
) const

Find and return the non-shared vertex attribute layer of a given type. If you like to find the first layer of the given type, the occurence parameter must be set to a value of 0. If you like to find the second layer of this type, the occurence parameter must be set to a value of of 1, etc. This function will return nullptr when the layer cannot be found.

Parameters
layerTypeIDthe layer type ID to search for.
occurenceThe occurence to search for. Set to 0 when you want the first layer of this type, set to 1 if you want the second layer of the given type, etc.
Returns
A pointer to the vertex attribute layer, or nullptr when none could be found.

◆ FindVertexAttributeLayerNumber()

size_t EMotionFX::Mesh::FindVertexAttributeLayerNumber ( uint32  layerTypeID,
size_t  occurrence = 0 
) const

Find and return the non-shared vertex attribute layer of a given type. If you like to find the first layer of the given type, the occurence parameter must be set to a value of 0. If you like to find the second layer of this type, the occurence parameter must be set to a value of of 1, etc. This function will return nullptr when the layer cannot be found.

Parameters
layerTypeIDthe layer type ID to search for.
occurrenceThe occurence to search for. Set to 0 when you want the first layer of this type, set to 1 if you want the second layer of the given type, etc.
Returns
The vertex attribute layer index number that you can pass to GetSharedVertexAttributeLayer. A value of MCORE_INVALIDINDEX32 os returned when no result could be found.

◆ FindVertexData()

void * EMotionFX::Mesh::FindVertexData ( uint32  layerID,
size_t  occurrence = 0 
) const

Find specific current vertex data in the mesh. This contains the vertex data after mesh deformers have been applied to them. If you want the vertex data before any mesh deformers have been applied to it, use the method named FindOriginalVertexData instead. Here are some examples to get common vertex data:

Vector3* positions = (Vector3*)mesh->FindVertexData( Mesh::ATTRIB_POSITIONS );   // the positions
Vector3* normals   = (Vector3*)mesh->FindVertexData( Mesh::ATTRIB_NORMALS   );   // the normals
Vector4* tangents  = (Vector4*)mesh->FindVertexData( Mesh::ATTRIB_TANGENTS  );   // first set of tangents, can be nullptr, and note the Vector4!
AZ::Vector2* uvCoords  = static_cast<AZ::Vector2*>(mesh->FindVertexData( Mesh::ATTRIB_UVCOORDS  ));  // the first set of UVs, can be nullptr
AZ::Vector2* uvCoords2 = static_cast<AZ::Vector2*>(mesh->FindVertexData( Mesh::ATTRIB_UVCOORDS, 1 ));    // the second set of UVs, can be nullptr
Parameters
layerIDThe layer type ID to get the information from.
occurrenceThe layer number to get. Where 0 means the first layer, 1 means the second, etc. This is used when there are multiple layers of the same type. An example is a mesh having multiple UV layers.
Returns
A void pointer to the layer data. You have to typecast yourself.

◆ GatherBonesForFace()

void EMotionFX::Mesh::GatherBonesForFace ( uint32  startIndexOfFace,
AZStd::vector< Node * > &  outBones,
Actor actor 
)

Gather all bones influencing a specified face into a specified array. The outBones array will be cleared when it enters the method.

Parameters
startIndexOfFaceThe start index of the first vertex of the face. So not the vertex number, but the offset in the index array of this mesh.
outBonesThe array to store the pointers to the bones in. Any existing array contents will be cleared when it enters the method.
actorThe actor to search the bones in.

◆ GetHighestJointIndex()

MCORE_INLINE uint16 Mesh::GetHighestJointIndex ( ) const

Get the highest id of all the jointId's used by this mesh

◆ GetIndices()

MCORE_INLINE uint32 * Mesh::GetIndices ( ) const

Get a pointer to the face indices. Every face has 3 indices and all faces indices are stored after eachother.

Returns
A pointer to the face index data.

◆ GetNumIndices()

MCORE_INLINE uint32 Mesh::GetNumIndices ( ) const

Returns the number of indices in the mesh, which is the sum of all polygon vertex counts.

Returns
The number of indices in the mesh.

◆ GetNumOrgVertices()

MCORE_INLINE uint32 Mesh::GetNumOrgVertices ( ) const

Get the number of original vertices. This can be lower compared to the value returned by GetNumVertices(). For the example of the cube with 8 real vertices, but 24 vertices in this mesh, this method would return a value of 8, while the method GetNumVertices() would return 24. Please keep in mind that the number of elements in the array returned by GetOrgVerts() however equals the amount returned by GetNumVertices() and not the amount returned by this method!

Returns
The number of original vertices in the mesh (which are not stored).

◆ GetNumPolygons()

MCORE_INLINE uint32 Mesh::GetNumPolygons ( ) const

Returns the number of polygons.

Returns
The number of polygons inside this mesh.

◆ GetNumSharedVertexAttributeLayers()

size_t EMotionFX::Mesh::GetNumSharedVertexAttributeLayers ( ) const

Get the number of shared vertex attributes. This value is the same for all shared vertices.

Returns
The number of shared vertex attributes for every vertex.

◆ GetNumSubMeshes()

MCORE_INLINE size_t Mesh::GetNumSubMeshes ( ) const

Get the number of sub meshes currently in the mesh.

Returns
The number of sub meshes.

◆ GetNumUniqueJoints()

MCORE_INLINE uint16 Mesh::GetNumUniqueJoints ( ) const

Get the total number of unique joints that impact this mesh

◆ GetNumVertexAttributeLayers()

size_t EMotionFX::Mesh::GetNumVertexAttributeLayers ( ) const

Get the number of vertex attributes. This value is the same for all vertices.

Returns
The number of vertex attributes for every vertex.

◆ GetNumVertices()

MCORE_INLINE uint32 Mesh::GetNumVertices ( ) const

Get the number of vertices in the mesh. The number of positions, normals and uv coordinates is equal to the value returned by this method.

Returns
The number of vertices.

◆ GetPolygonVertexCounts()

MCORE_INLINE uint8 * Mesh::GetPolygonVertexCounts ( ) const

Get a pointer to the polygon vertex count. Every polygon stores an integer which represents the number of vertices/indices this polygon stores. The length of this array equals GetNumPolygons().

Returns
A pointer to the polygon vertex count.

◆ GetSharedVertexAttributeLayer()

VertexAttributeLayer * EMotionFX::Mesh::GetSharedVertexAttributeLayer ( size_t  layerNr)

Get the shared vertex attribute data of a given layer. The number of arrays inside the array returned equals the value returned by GetNumOrgVertices().

Parameters
layerNrThe layer number to get the attributes from. Must be below the value returned by GetNumSharedVertexAttributeLayers().
Returns
A pointer to the array of shared vertex attributes. You can typecast this pointer if you know the type of the vertex attributes.

◆ GetSubMesh()

MCORE_INLINE SubMesh * Mesh::GetSubMesh ( size_t  nr) const

Get a given SubMesh.

Parameters
nrThe SubMesh number to get.
Returns
A pointer to the SubMesh.

◆ GetVertexAttributeLayer()

VertexAttributeLayer * EMotionFX::Mesh::GetVertexAttributeLayer ( size_t  layerNr)

Get the vertex attribute data of a given layer. The number of arrays inside the array returned equals the value returned by GetNumVertices().

Parameters
layerNrThe layer number to get the attributes from. Must be below the value returned by GetNumVertexAttributeLayers().
Returns
A pointer to the array of vertex attributes. You can typecast this pointer if you know the type of the vertex attributes.

◆ InsertSubMesh()

void EMotionFX::Mesh::InsertSubMesh ( size_t  insertIndex,
SubMesh subMesh 
)

Insert a submesh into the array of submeshes.

Parameters
insertIndexThe position in the submesh array to insert this new submesh.
subMeshA pointer to the submesh to insert into this mesh.

◆ Intersects() [1/2]

bool EMotionFX::Mesh::Intersects ( const Transform &  transform,
const MCore::Ray ray 
)

Checks for an intersection between the mesh and a given ray.

Parameters
transformThe transformation of the mesh.
rayThe ray to test with.
Returns
Returns true when an intersection has occurred, otherwise false.

◆ Intersects() [2/2]

bool EMotionFX::Mesh::Intersects ( const Transform &  transform,
const MCore::Ray ray,
AZ::Vector3 *  outIntersect,
float *  outBaryU = nullptr,
float *  outBaryV = nullptr,
uint32 *  outIndices = nullptr 
)

Check for an intersection between the mesh a given ray, and calculate the closest intersection point. If you do NOT need to know the intersection point, use the other Intersects method, because that one is faster, since it doesn't need to calculate the closest intersection point. The intersection point returned is in object space.

Parameters
transformThe transformation of the mesh.
rayThe ray to test with.
outIntersectA pointer to the vector to store the intersection point in, in case of a collision (nullptr allowed).
outBaryUA pointer to a float in which the method will store the barycentric U coordinate, to be used to interpolate values on the triangle (nullptr allowed).
outBaryVA pointer to a float in which the method will store the barycentric V coordinate, to be used to interpolate values on the triangle (nullptr allowed).
outIndicesA pointer to an array of 3 integers, which will contain the 3 vertex indices of the closest intersecting triangle. Even on polygon meshes with polygons of more than 3 vertices three indices are returned. In that case the indices represent a sub-triangle inside the polygon. A value of nullptr is allowed, which will skip storing the resulting triangle indices.
Returns
Returns true when an intersection has occurred, otherwise false.

◆ Log()

void EMotionFX::Mesh::Log ( )

Debug log information. Information will be logged using LOGLEVEL_DEBUG.

◆ ReleaseData()

void EMotionFX::Mesh::ReleaseData ( )

Releases all allocated mesh data.

◆ RemoveAllSharedVertexAttributeLayers()

void EMotionFX::Mesh::RemoveAllSharedVertexAttributeLayers ( )

Removes all shared vertex attributes for all shared vertices. The previously allocated attributes will be deleted from memory automatically.

◆ RemoveAllVertexAttributeLayers()

void EMotionFX::Mesh::RemoveAllVertexAttributeLayers ( )

Removes all vertex attributes for all vertices. The previously allocated attributes will be deleted from memory automatically.

◆ RemoveEmptySubMeshes()

size_t EMotionFX::Mesh::RemoveEmptySubMeshes ( bool  onlyRemoveOnZeroVertsAndTriangles = true)

Remove all empty submeshes. A submesh is either empty if it has no vertices or no indices or a combination of both.

Parameters
onlyRemoveOnZeroVertsAndTrianglesOnly remove when both the number of vertices and number of indices/triangles are zero.
Returns
Returns the number of removed submeshes.

◆ RemoveSharedVertexAttributeLayer()

void EMotionFX::Mesh::RemoveSharedVertexAttributeLayer ( size_t  layerNr)

Remove a layer of shared vertex attributes. Automatically deletes the data from memory.

Parameters
layerNrThe layer number to remove, must be below the value returned by GetNumSharedVertexAttributeLayers().

◆ RemoveSubMesh()

void EMotionFX::Mesh::RemoveSubMesh ( size_t  nr,
bool  delFromMem = true 
)

Remove a given submesh from this mesh.

Parameters
nrThe submesh index number to remove, which must be in range of 0..GetNumSubMeshes()-1.
delFromMemSet to true when you want to delete the submesh from memory as well, otherwise set to false.

◆ RemoveVertexAttributeLayer()

void EMotionFX::Mesh::RemoveVertexAttributeLayer ( size_t  layerNr)

Remove a layer of vertex attributes. Automatically deletes the data from memory.

Parameters
layerNrThe layer number to remove, must be below the value returned by GetNumVertexAttributeLayers().

◆ RemoveVertices()

void EMotionFX::Mesh::RemoveVertices ( uint32  startVertexNr,
uint32  endVertexNr,
bool  changeIndexBuffer = true,
bool  removeEmptySubMeshes = false 
)

Remove a specific range of vertices from the mesh. This also might change all pointers to vertex and index data returned by this mesh and its submeshes. This automatically also adjusts the index buffer as well. Please note that the specified end vertex will also be removed!

Parameters
startVertexNrThe vertex number to start removing from.
endVertexNrThe last vertex number to remove, this value must be bigger or equal than the start vertex number.
changeIndexBufferIf this is set to true, the index buffer will be modified on such a way that all vertex number indexed by the index buffer, which are above the startVertexNr parameter value, will be decreased by the amount of removed vertices.
removeEmptySubMeshesWhen set to true (default) submeshes that become empty will be removed from memory.

◆ ReserveVertexAttributeLayerSpace()

void EMotionFX::Mesh::ReserveVertexAttributeLayerSpace ( uint32  numLayers)

Reserve space for the given amount of vertex attribute layers. This just pre-allocates array data to prevent reallocs.

Parameters
numLayersThe number of layers to reserve space for.

◆ ResetToOriginalData()

void EMotionFX::Mesh::ResetToOriginalData ( )

Resets all final/output vertex data to its original data, as it was before any deformers where applied. This will copy the original positions over the final positions, the original normals over the final normals and the original uv coordinates over the final uv coordinates.

◆ Scale()

void EMotionFX::Mesh::Scale ( float  scaleFactor)

Scale all positional data. This is a slow operation and is used to convert between different unit systems (cm, meters, etc).

Parameters
scaleFactorThe scale factor to scale the current data by.

◆ SetHighestJointIndex()

MCORE_INLINE void Mesh::SetHighestJointIndex ( uint16  highestJointIndex)

Get the highest id of all the jointId's used by this mesh

◆ SetNumSubMeshes()

MCORE_INLINE void EMotionFX::Mesh::SetNumSubMeshes ( size_t  numSubMeshes)
inline

Set the number of submeshes. This adjusts the number returned by GetNumSubMeshes(). Do not forget to use SetSubMesh() to initialize all submeshes!

Parameters
numSubMeshesThe number of submeshes to use.

◆ SetNumUniqueJoints()

MCORE_INLINE void Mesh::SetNumUniqueJoints ( uint16  numUniqueJoints)

Set the total number of unique joints that impact this mesh

◆ SetSubMesh()

MCORE_INLINE void EMotionFX::Mesh::SetSubMesh ( size_t  nr,
SubMesh subMesh 
)
inline

Set the value for a given submesh.

Parameters
nrThe submesh number, which must be in range of [0..GetNumSubMeshes()-1].
subMeshThe submesh to use.

◆ SwapVertex()

void EMotionFX::Mesh::SwapVertex ( uint32  vertexA,
uint32  vertexB 
)

Swap two vertices. This will swap all data elements, such as position and normals. Not only it will swap the basic data like position and normals, but also all vertex attributes. This method is used by the meshes support inside GetEMotionFX().

Parameters
vertexAThe first vertex number.
vertexBThe second vertex number.
Note
This does NOT update the index buffer!

Member Data Documentation

◆ m_highestJointIndex

uint16 EMotionFX::Mesh::m_highestJointIndex
protected

The highest id of all the joints used by this mesh

◆ m_indices

uint32* EMotionFX::Mesh::m_indices
protected

The array of indices, which define the faces.

◆ m_isCollisionMesh

bool EMotionFX::Mesh::m_isCollisionMesh
protected

Is this mesh a collision mesh?

◆ m_numIndices

uint32 EMotionFX::Mesh::m_numIndices
protected

Number of indices.

◆ m_numOrgVerts

uint32 EMotionFX::Mesh::m_numOrgVerts
protected

The number of original vertices.

◆ m_numPolygons

uint32 EMotionFX::Mesh::m_numPolygons
protected

The number of polygons in this mesh.

◆ m_numUniqueJoints

uint16 EMotionFX::Mesh::m_numUniqueJoints
protected

Number of unique joints

◆ m_numVertices

uint32 EMotionFX::Mesh::m_numVertices
protected

Number of vertices.

◆ m_polyVertexCounts

uint8* EMotionFX::Mesh::m_polyVertexCounts
protected

The number of vertices for each polygon, where the length of this array equals the number of polygons.

◆ m_sharedVertexAttributes

AZStd::vector< VertexAttributeLayer* > EMotionFX::Mesh::m_sharedVertexAttributes
protected

The array of shared vertex attribute layers. The number of attributes in each shared layer will be equal to the value returned by Mesh::GetNumOrgVertices().

◆ m_subMeshes

AZStd::vector<SubMesh*> EMotionFX::Mesh::m_subMeshes
protected

The collection of sub meshes.

◆ m_vertexAttributes

AZStd::vector< VertexAttributeLayer* > EMotionFX::Mesh::m_vertexAttributes
protected

The array of non-shared vertex attribute layers. The number of attributes in each shared layer will be equal to the value returned by Mesh::GetNumVertices().


The documentation for this class was generated from the following files: