Added [Sub]Mesh::GetTriangleCount()
Former-commit-id: e365bd3aa57d487186a0be5cde1d5b0ba78d740c
This commit is contained in:
parent
a951736338
commit
2f72939ad0
|
|
@ -76,6 +76,7 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
|||
const NzSubMesh* GetSubMesh(unsigned int index) const;
|
||||
unsigned int GetSubMeshCount() const;
|
||||
int GetSubMeshIndex(const NzString& identifier) const;
|
||||
unsigned int GetTriangleCount() const;
|
||||
unsigned int GetVertexCount() const;
|
||||
|
||||
bool HasSubMesh(const NzString& identifier) const;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class NAZARA_API NzSubMesh : public NzResource
|
|||
unsigned int GetMaterialIndex() const;
|
||||
const NzMesh* GetParent() const;
|
||||
nzPrimitiveType GetPrimitiveType() const;
|
||||
unsigned int GetTriangleCount() const;
|
||||
virtual unsigned int GetVertexCount() const = 0;
|
||||
|
||||
virtual bool IsAnimated() const = 0;
|
||||
|
|
|
|||
|
|
@ -472,6 +472,23 @@ int NzMesh::GetSubMeshIndex(const NzString& identifier) const
|
|||
return it->second;
|
||||
}
|
||||
|
||||
unsigned int NzMesh::GetTriangleCount() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Mesh not created");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int triangleCount = 0;
|
||||
for (NzSubMesh* subMesh : m_impl->subMeshes)
|
||||
triangleCount += subMesh->GetTriangleCount();
|
||||
|
||||
return triangleCount;
|
||||
}
|
||||
|
||||
unsigned int NzMesh::GetVertexCount() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
|
|
|
|||
|
|
@ -151,6 +151,36 @@ nzPrimitiveType NzSubMesh::GetPrimitiveType() const
|
|||
return m_primitiveType;
|
||||
}
|
||||
|
||||
unsigned int NzSubMesh::GetTriangleCount() const
|
||||
{
|
||||
const NzIndexBuffer* indexBuffer = GetIndexBuffer();
|
||||
unsigned int indexCount;
|
||||
if (indexBuffer)
|
||||
indexCount = indexBuffer->GetIndexCount();
|
||||
else
|
||||
indexCount = GetVertexCount();
|
||||
|
||||
switch (m_primitiveType)
|
||||
{
|
||||
case nzPrimitiveType_LineList:
|
||||
case nzPrimitiveType_LineStrip:
|
||||
case nzPrimitiveType_PointList:
|
||||
return 0;
|
||||
|
||||
case nzPrimitiveType_TriangleFan:
|
||||
return (indexCount - 1) / 2;
|
||||
|
||||
case nzPrimitiveType_TriangleList:
|
||||
return indexCount / 3;
|
||||
|
||||
case nzPrimitiveType_TriangleStrip:
|
||||
return indexCount - 2;
|
||||
}
|
||||
|
||||
NazaraError("Primitive type not handled (0x" + NzString::Number(m_primitiveType, 16) + ')');
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int NzSubMesh::GetMaterialIndex() const
|
||||
{
|
||||
return m_matIndex;
|
||||
|
|
|
|||
Loading…
Reference in New Issue