I've been playing around with the WavefrontObjParser that's not in Juce itself but is in a couple of the example applications. I noticed that when I import Wavefront obj files with it that the normals weren't correct so lighting wasn't rendering correctly. I tracked the problem down to the comparator operator in TripleIndex.
struct TripleIndex
{
TripleIndex() noexcept : vertexIndex (-1), textureIndex (-1), normalIndex (-1) {}
bool operator< (const TripleIndex& other) const noexcept { return vertexIndex < other.vertexIndex; }
int vertexIndex, textureIndex, normalIndex;
};
It should be this instead which will cause a a new vertex to be created from a TripleIndex if it has a different vertexIndex, textureIndex, or normalIndex that any other existing vertex:
bool operator< (const TripleIndex& other) const noexcept
{
// Short cut self comparison
if (this == &other)
return false;
if (vertexIndex < other.vertexIndex)
return true;
else if (other.vertexIndex < vertexIndex)
return false;
if (textureIndex < other.textureIndex)
return true;
else if (other.textureIndex < textureIndex)
return false;
if (normalIndex < other.normalIndex)
return true;
else if (other.normalIndex < normalIndex)
return false;
return false;
}