From 97d66c1794ffdb73c5cbf5d447868aad4ecf69ad Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Wed, 27 Jul 2022 21:30:51 +0200 Subject: [PATCH] Fix indices counter reset each face group --- src/obj_exporter.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/obj_exporter.c b/src/obj_exporter.c index d042dfe..c5eb52b 100644 --- a/src/obj_exporter.c +++ b/src/obj_exporter.c @@ -21,6 +21,7 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) { obj* objConstruct = NULL; unsigned int i,j; int surfID = 0, materialID = 0, tmpVertex = 0, tmpIndex = 0; + int indexOffset = 0; // Used to compensate reset of indices between face group float vertexBuff[3] = {0}, textureBuff[2] = {0}; int indicesBuff[3] = {0}; @@ -68,9 +69,9 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) { for ( j = 0; j < hob_objects->face_groups[i].face_count; j++ ) { tmpIndex = obj_add_poly(objConstruct, surfID); - indicesBuff[0] = (int)hob_objects->face_groups[i].faces[j].indices[0]; - indicesBuff[1] = (int)hob_objects->face_groups[i].faces[j].indices[1]; - indicesBuff[2] = (int)hob_objects->face_groups[i].faces[j].indices[2]; + indicesBuff[0] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[0]; + indicesBuff[1] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[1]; + indicesBuff[2] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[2]; obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff); @@ -78,13 +79,15 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) { if (hob_objects->face_groups[i].faces[j].flags_bits.fIsQuad) { tmpIndex = obj_add_poly(objConstruct, surfID); - indicesBuff[0] = (int)hob_objects->face_groups[i].faces[j].indices[0]; - indicesBuff[1] = (int)hob_objects->face_groups[i].faces[j].indices[2]; - indicesBuff[2] = (int)hob_objects->face_groups[i].faces[j].indices[3]; + indicesBuff[0] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[0]; + indicesBuff[1] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[2]; + indicesBuff[2] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[3]; obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff); } } + + indexOffset = obj_num_vert(objConstruct); } obj_write(objConstruct, objExport_path, NULL, 8);