Utility/OBJSaver: Handle case where normal and/or texcoords are not present
This commit is contained in:
@@ -537,6 +537,8 @@ namespace Nz
|
|||||||
}
|
}
|
||||||
EmitLine();
|
EmitLine();
|
||||||
|
|
||||||
|
if (!m_normals.empty())
|
||||||
|
{
|
||||||
Emit("# normal count: ");
|
Emit("# normal count: ");
|
||||||
EmitLine(m_normals.size());
|
EmitLine(m_normals.size());
|
||||||
|
|
||||||
@@ -551,7 +553,10 @@ namespace Nz
|
|||||||
EmitLine();
|
EmitLine();
|
||||||
}
|
}
|
||||||
EmitLine();
|
EmitLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_texCoords.empty())
|
||||||
|
{
|
||||||
Emit("# texcoords count: ");
|
Emit("# texcoords count: ");
|
||||||
EmitLine(m_texCoords.size());
|
EmitLine(m_texCoords.size());
|
||||||
|
|
||||||
@@ -569,6 +574,7 @@ namespace Nz
|
|||||||
EmitLine();
|
EmitLine();
|
||||||
}
|
}
|
||||||
EmitLine();
|
EmitLine();
|
||||||
|
}
|
||||||
|
|
||||||
std::unordered_map<std::size_t /* mesh */, std::vector<std::size_t> /* meshes*/> meshesByMaterials;
|
std::unordered_map<std::size_t /* mesh */, std::vector<std::size_t> /* meshes*/> meshesByMaterials;
|
||||||
std::size_t meshIndex = 0;
|
std::size_t meshIndex = 0;
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace Nz
|
|||||||
SparsePtr<Vector2f> texCoordsPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
|
SparsePtr<Vector2f> texCoordsPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
|
||||||
|
|
||||||
std::size_t faceIndex = 0;
|
std::size_t faceIndex = 0;
|
||||||
TriangleIterator triangle(staticMesh);
|
TriangleIterator triangleIt(staticMesh);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
OBJParser::Face& face = meshes[i].faces[faceIndex];
|
OBJParser::Face& face = meshes[i].faces[faceIndex];
|
||||||
@@ -171,15 +171,23 @@ namespace Nz
|
|||||||
{
|
{
|
||||||
OBJParser::FaceVertex& vertexIndices = meshes[i].vertices[face.firstVertex + j];
|
OBJParser::FaceVertex& vertexIndices = meshes[i].vertices[face.firstVertex + j];
|
||||||
|
|
||||||
std::size_t index = triangle[j];
|
std::size_t index = triangleIt[j];
|
||||||
vertexIndices.normal = normalCache.Insert(normalPtr[index]);
|
|
||||||
vertexIndices.position = positionCache.Insert(positionPtr[index]);
|
vertexIndices.position = positionCache.Insert(positionPtr[index]);
|
||||||
|
|
||||||
|
if (normalPtr)
|
||||||
|
vertexIndices.normal = normalCache.Insert(normalPtr[index]);
|
||||||
|
else
|
||||||
|
vertexIndices.normal = 0;
|
||||||
|
|
||||||
|
if (texCoordsPtr)
|
||||||
vertexIndices.texCoord = texCoordsCache.Insert(texCoordsPtr[index]);
|
vertexIndices.texCoord = texCoordsCache.Insert(texCoordsPtr[index]);
|
||||||
|
else
|
||||||
|
vertexIndices.texCoord = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
faceIndex++;
|
faceIndex++;
|
||||||
}
|
}
|
||||||
while (triangle.Advance());
|
while (triangleIt.Advance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user