Utility: Handle vertex color loading

This commit is contained in:
Jérôme Leclercq
2021-09-08 19:07:59 +02:00
parent 0961baa5ac
commit 75f927b414
4 changed files with 82 additions and 30 deletions

View File

@@ -294,8 +294,11 @@ namespace Nz
const OBJParser::FaceVertex& vertexIndices = vertexPair.first;
unsigned int index = vertexPair.second;
const Vector4f& vec = positions[vertexIndices.position-1];
posPtr[index] = Vector3f(parameters.matrix * vec);
if (posPtr)
{
const Vector4f& vec = positions[vertexIndices.position - 1];
posPtr[index] = Vector3f(parameters.matrix * vec);
}
if (hasNormals)
{
@@ -319,6 +322,13 @@ namespace Nz
}
}
// Official .obj files have no vertex color, fill it with white
if (auto colorPtr = vertexMapper.GetComponentPtr<Color>(VertexComponent::Color))
{
for (unsigned int i = 0; i < vertexCount; ++i)
colorPtr[i] = Nz::Color::White;
}
vertexMapper.Unmap();
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(std::move(vertexBuffer), indexBuffer);