I'm currently working on a project that requires me to load .md5mesh format and draw it.
Following this link I've managed to load the mesh into the engine successfully, but a problem arises when calculating normals; they just don't seem to smooth.
To clarify that it was not my rendering or shader code that was the problem, I loaded a model of .OBJ format, and that lights smoothly.
The mesh is calculated correctly too, as I am able to load in complex models with multiple joints and mesh parts.
Here's a screenshot of the lighting.
And here is how I currently calculate the normals (All normals are set to zero before computing):
for (unsigned int i = 0; i < NumberOfTriangles; i++)
{
Math3::vec3 r, s, result;
Math3::vec3 p1, p2, p3;
p1 = Triangle[i].Vertex[0];
p2 = Triangle[i].Vertex[1];
p3 = Triangle[i].Vertex[2];
r = p2 - p1;
s = p3 - p1;
result = Math3::Cross(s, r);
// Add the triangles face normal to each vertex
Triangle[i].Vertex[0].Normal += result;
Triangle[i].Vertex[1].Normal += result;
Triangle[i].Vertex[2].Normal += result;
}
After the loop I normalise each vertex normal to find the average normal.
As you can see in the image the .md5mesh model is shading flat instead of shading smoothly like the .OBJ model.
So what am I missing?