Fixing an OBJ loader bug that fragmented the loaded meshes (#4494)

The nextShapeEnd integer is a pointer in the OBJ data structures.
The faceVertIndex is a vertex index counter for the mesh we are
about to create. Both integers are not compatible, which causes
the code to finish the meshes too early, thus writing the OBJ data
incompletely into the target meshes.

It wasn't noticed because for the last mesh, it process all remaining
data, causing the last mesh to contain all remaining triangles.

This would have been noticed if the OBJ meshes used different textures
for each mesh.
This commit is contained in:
Eike Decker 2024-11-15 16:40:14 +01:00 committed by GitHub
parent 4f091f44a8
commit 7c5d74e98e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4244,7 +4244,7 @@ static Model LoadOBJ(const char *fileName)
// walk all the faces // walk all the faces
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++) for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
{ {
if (faceVertIndex >= nextShapeEnd) if (faceId >= nextShapeEnd)
{ {
// try to find the last vert in the next shape // try to find the last vert in the next shape
nextShape++; nextShape++;
@ -4295,7 +4295,7 @@ static Model LoadOBJ(const char *fileName)
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++) for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
{ {
bool newMesh = false; // do we need a new mesh? bool newMesh = false; // do we need a new mesh?
if (faceVertIndex >= nextShapeEnd) if (faceId >= nextShapeEnd)
{ {
// try to find the last vert in the next shape // try to find the last vert in the next shape
nextShape++; nextShape++;
@ -4357,7 +4357,7 @@ static Model LoadOBJ(const char *fileName)
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++) for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
{ {
bool newMesh = false; // do we need a new mesh? bool newMesh = false; // do we need a new mesh?
if (faceVertIndex >= nextShapeEnd) if (faceId >= nextShapeEnd)
{ {
// try to find the last vert in the next shape // try to find the last vert in the next shape
nextShape++; nextShape++;