Utility/OBJSaver: Handle case where normal and/or texcoords are not present

This commit is contained in:
Lynix
2022-01-21 14:57:07 +01:00
parent b917738ed4
commit 213c7d8a1e
2 changed files with 44 additions and 30 deletions

View File

@@ -160,7 +160,7 @@ namespace Nz
SparsePtr<Vector2f> texCoordsPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
std::size_t faceIndex = 0;
TriangleIterator triangle(staticMesh);
TriangleIterator triangleIt(staticMesh);
do
{
OBJParser::Face& face = meshes[i].faces[faceIndex];
@@ -171,15 +171,23 @@ namespace Nz
{
OBJParser::FaceVertex& vertexIndices = meshes[i].vertices[face.firstVertex + j];
std::size_t index = triangle[j];
vertexIndices.normal = normalCache.Insert(normalPtr[index]);
std::size_t index = triangleIt[j];
vertexIndices.position = positionCache.Insert(positionPtr[index]);
vertexIndices.texCoord = texCoordsCache.Insert(texCoordsPtr[index]);
if (normalPtr)
vertexIndices.normal = normalCache.Insert(normalPtr[index]);
else
vertexIndices.normal = 0;
if (texCoordsPtr)
vertexIndices.texCoord = texCoordsCache.Insert(texCoordsPtr[index]);
else
vertexIndices.texCoord = 0;
}
faceIndex++;
}
while (triangle.Advance());
while (triangleIt.Advance());
}
}