Added Mesh::Transform
Former-commit-id: c0680b23ff81a10a580934fc24d1ae4a13780595
This commit is contained in:
parent
6b2af70f1d
commit
f3d0618ae6
|
|
@ -108,6 +108,8 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
|||
void SetMaterial(unsigned int matIndex, const NzString& materialPath);
|
||||
void SetMaterialCount(unsigned int matCount);
|
||||
|
||||
void Transform(const NzMatrix4f& matrix);
|
||||
|
||||
static const NzVertexDeclaration* GetDeclaration();
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -915,6 +915,50 @@ void NzMesh::SetMaterialCount(unsigned int matCount)
|
|||
#endif
|
||||
}
|
||||
|
||||
void NzMesh::Transform(const NzMatrix4f& matrix)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Mesh not created");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_impl->animationType != nzAnimationType_Static)
|
||||
{
|
||||
NazaraError("Mesh must be static");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (matrix.IsIdentity())
|
||||
return;
|
||||
|
||||
for (NzSubMesh* subMesh : m_impl->subMeshes)
|
||||
{
|
||||
NzStaticMesh* staticMesh = static_cast<NzStaticMesh*>(subMesh);
|
||||
|
||||
NzBufferMapper<NzVertexBuffer> mapper(staticMesh->GetVertexBuffer(), nzBufferAccess_ReadWrite);
|
||||
NzMeshVertex* vertices = static_cast<NzMeshVertex*>(mapper.GetPointer());
|
||||
|
||||
NzBoxf aabb(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f);
|
||||
|
||||
unsigned int vertexCount = staticMesh->GetVertexCount();
|
||||
for (unsigned int i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
vertices->position = matrix.Transform(vertices->position);
|
||||
aabb.ExtendTo(vertices->position);
|
||||
|
||||
vertices++;
|
||||
}
|
||||
|
||||
staticMesh->SetAABB(aabb);
|
||||
}
|
||||
|
||||
// Il ne faut pas oublier d'invalider notre AABB
|
||||
m_impl->aabbUpdated = false;
|
||||
}
|
||||
|
||||
const NzVertexDeclaration* NzMesh::GetDeclaration()
|
||||
{
|
||||
static NzVertexDeclaration declaration;
|
||||
|
|
|
|||
Loading…
Reference in New Issue