Utility/Mesh: Fix Recenter() method for other vertex layouts

This commit is contained in:
Jérôme Leclercq 2021-06-05 19:09:12 +02:00
parent 613b3b8627
commit 0411271851
2 changed files with 4 additions and 6 deletions

View File

@ -83,6 +83,7 @@ int main()
Nz::MeshParams meshParams;
meshParams.storage = Nz::DataStorage::Software;
meshParams.center = true;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV);

View File

@ -515,15 +515,12 @@ namespace Nz
{
StaticMesh& staticMesh = static_cast<StaticMesh&>(*data.subMesh);
BufferMapper<VertexBuffer> mapper(*staticMesh.GetVertexBuffer(), BufferAccess::ReadWrite);
MeshVertex* vertices = static_cast<MeshVertex*>(mapper.GetPointer());
VertexMapper mapper(*staticMesh.GetVertexBuffer());
SparsePtr<Vector3f> position = mapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
std::size_t vertexCount = staticMesh.GetVertexCount();
for (std::size_t i = 0; i < vertexCount; ++i)
{
vertices->position -= center;
vertices++;
}
*position++ -= center;
// Our AABB doesn't change shape, only position
Boxf aabb = staticMesh.GetAABB();