Fix indices counter reset each face group

This commit is contained in:
JackCarterSmith 2022-07-27 21:30:51 +02:00
parent f08db9a448
commit 97d66c1794
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24

View File

@ -21,6 +21,7 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) {
obj* objConstruct = NULL; obj* objConstruct = NULL;
unsigned int i,j; unsigned int i,j;
int surfID = 0, materialID = 0, tmpVertex = 0, tmpIndex = 0; 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}; float vertexBuff[3] = {0}, textureBuff[2] = {0};
int indicesBuff[3] = {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++ ) { for ( j = 0; j < hob_objects->face_groups[i].face_count; j++ ) {
tmpIndex = obj_add_poly(objConstruct, surfID); tmpIndex = obj_add_poly(objConstruct, surfID);
indicesBuff[0] = (int)hob_objects->face_groups[i].faces[j].indices[0]; indicesBuff[0] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[0];
indicesBuff[1] = (int)hob_objects->face_groups[i].faces[j].indices[1]; indicesBuff[1] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[1];
indicesBuff[2] = (int)hob_objects->face_groups[i].faces[j].indices[2]; indicesBuff[2] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[2];
obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff); 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) { if (hob_objects->face_groups[i].faces[j].flags_bits.fIsQuad) {
tmpIndex = obj_add_poly(objConstruct, surfID); tmpIndex = obj_add_poly(objConstruct, surfID);
indicesBuff[0] = (int)hob_objects->face_groups[i].faces[j].indices[0]; indicesBuff[0] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[0];
indicesBuff[1] = (int)hob_objects->face_groups[i].faces[j].indices[2]; indicesBuff[1] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[2];
indicesBuff[2] = (int)hob_objects->face_groups[i].faces[j].indices[3]; indicesBuff[2] = indexOffset + (int)hob_objects->face_groups[i].faces[j].indices[3];
obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff); obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff);
} }
} }
indexOffset = obj_num_vert(objConstruct);
} }
obj_write(objConstruct, objExport_path, NULL, 8); obj_write(objConstruct, objExport_path, NULL, 8);