Added Mesh::Recenter()
Former-commit-id: 07ef8b3296b835e207bfa904af29546f724e6dc3
This commit is contained in:
parent
346415e860
commit
e689f6f09f
|
|
@ -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 LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams());
|
||||||
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams());
|
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams());
|
||||||
|
|
||||||
|
void Recenter();
|
||||||
|
|
||||||
void RemoveSubMesh(const NzString& identifier);
|
void RemoveSubMesh(const NzString& identifier);
|
||||||
void RemoveSubMesh(unsigned int index);
|
void RemoveSubMesh(unsigned int index);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -758,6 +758,47 @@ bool NzMesh::LoadFromStream(NzInputStream& stream, const NzMeshParams& params)
|
||||||
return NzMeshLoader::LoadFromStream(this, stream, 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)
|
void NzMesh::RemoveSubMesh(const NzString& identifier)
|
||||||
{
|
{
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue