Export vertices UV map

This commit is contained in:
JackCarterSmith 2022-07-28 17:20:14 +02:00
parent 6f1c5f46ac
commit 2173acd28f
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24

View File

@ -59,24 +59,32 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) {
vertexBuff[0] = ((float)1/1024) * -hob_objects->object_parts[i].vertices[j].x; // Invert X to fix mirror display vertexBuff[0] = ((float)1/1024) * -hob_objects->object_parts[i].vertices[j].x; // Invert X to fix mirror display
vertexBuff[1] = ((float)1/1024) * -hob_objects->object_parts[i].vertices[j].y; // Invert Y to render upside up vertexBuff[1] = ((float)1/1024) * -hob_objects->object_parts[i].vertices[j].y; // Invert Y to render upside up
vertexBuff[2] = ((float)1/1024) * hob_objects->object_parts[i].vertices[j].z; vertexBuff[2] = ((float)1/1024) * hob_objects->object_parts[i].vertices[j].z;
obj_set_vert_v(objConstruct, tmpVertex, vertexBuff); obj_set_vert_v(objConstruct, tmpVertex, vertexBuff);
//textureBuff[0] = ((float)1/1) * hob_objects->face_groups[i].
//obj_set_vert_t(objConstruct, tmpVertex, textureBuff);
} }
// Build indices container // Build indices container and UV mapping
for ( j = 0; j < hob_objects->object_parts[i].face_count; j++ ) { for ( j = 0; j < hob_objects->object_parts[i].face_count; j++ ) {
tmpIndex = obj_add_poly(objConstruct, surfID); tmpIndex = obj_add_poly(objConstruct, surfID);
indicesBuff[0] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[0]; indicesBuff[0] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[0];
indicesBuff[1] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[1]; indicesBuff[1] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[1];
indicesBuff[2] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[2]; indicesBuff[2] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[2];
obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff); obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff);
if (hob_objects->object_parts[i].faces[j].flags_bits.fHasTexture) {
textureBuff[0] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[0].u;
textureBuff[1] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[0].v;
obj_set_vert_t(objConstruct, indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[0], textureBuff);
textureBuff[0] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[1].u;
textureBuff[1] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[1].v;
obj_set_vert_t(objConstruct, indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[1], textureBuff);
textureBuff[0] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[2].u;
textureBuff[1] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[2].v;
obj_set_vert_t(objConstruct, indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[2], textureBuff);
}
// Process 2 triangles if face is Quad // Process 2 triangles if face is Quad
if (hob_objects->object_parts[i].faces[j].flags_bits.fIsQuad) { if (hob_objects->object_parts[i].faces[j].flags_bits.fIsQuad) {
tmpIndex = obj_add_poly(objConstruct, surfID); tmpIndex = obj_add_poly(objConstruct, surfID);
@ -84,8 +92,13 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) {
indicesBuff[0] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[0]; indicesBuff[0] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[0];
indicesBuff[1] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[2]; indicesBuff[1] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[2];
indicesBuff[2] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[3]; indicesBuff[2] = indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[3];
obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff); obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff);
if (hob_objects->object_parts[i].faces[j].flags_bits.fHasTexture) {
textureBuff[0] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[3].u;
textureBuff[1] = ((float)1/4096) * hob_objects->object_parts[i].faces[j].tex_coords[3].v;
obj_set_vert_t(objConstruct, indexOffset + (int)hob_objects->object_parts[i].faces[j].indices[3], textureBuff);
}
} }
} }