Added Mesh::Recenter()

Former-commit-id: 07ef8b3296b835e207bfa904af29546f724e6dc3
This commit is contained in:
Lynix 2013-06-09 16:15:13 +02:00
parent 346415e860
commit e689f6f09f
2 changed files with 43 additions and 0 deletions

View File

@ -99,6 +99,8 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams());
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams());
void Recenter();
void RemoveSubMesh(const NzString& identifier);
void RemoveSubMesh(unsigned int index);

View File

@ -758,6 +758,47 @@ bool NzMesh::LoadFromStream(NzInputStream& stream, const NzMeshParams& params)
return NzMeshLoader::LoadFromStream(this, stream, params);
}
void NzMesh::Recenter()
{
#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
NzVector3f center = GetAABB().GetCenter();
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());
unsigned int vertexCount = staticMesh->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i)
{
vertices->position -= center;
vertices++;
}
NzBoxf aabb = staticMesh->GetAABB();
aabb.Translate(-center);
staticMesh->SetAABB(aabb);
}
m_impl->aabbUpdated = false; // Notre AABB a changée
}
void NzMesh::RemoveSubMesh(const NzString& identifier)
{
#if NAZARA_UTILITY_SAFE