Obj file export basic
This commit is contained in:
parent
e0c9f2c7d8
commit
068fdff8fd
@ -19,7 +19,7 @@ unsigned char parseHOBFile(const char* fileName, T_HOB* hob_struct) {
|
||||
long fileSize;
|
||||
FILE* fStream = NULL;
|
||||
char* memFile = NULL;
|
||||
int i,j,k;
|
||||
unsigned int i,j,k;
|
||||
unsigned int facesExtraOffset;
|
||||
int* offset_index = NULL;
|
||||
|
||||
|
@ -16,30 +16,78 @@
|
||||
|
||||
|
||||
unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) {
|
||||
char export_path[128];
|
||||
char objExport_path[128];
|
||||
char mtlExport_path[128];
|
||||
obj* objConstruct = NULL;
|
||||
unsigned int i,j;
|
||||
int surfID = 0, materialID = 0, tmpVertex = 0, tmpIndex = 0;
|
||||
float vertexBuff[3] = {0}, textureBuff[2] = {0};
|
||||
int indicesBuff[3] = {0};
|
||||
|
||||
if (hob_objects == NULL || out_path == NULL)
|
||||
return ERROR_ARGS_NULL;
|
||||
|
||||
if (_options & OUTPUT_DIR) {
|
||||
strcpy(export_path, out_path);
|
||||
strcpy(objExport_path, out_path);
|
||||
#ifdef _WIN32
|
||||
strcat(export_path, "-out\\");
|
||||
strcat(objExport_path, "-out\\");
|
||||
#else
|
||||
strcat(export_path, "-out/");
|
||||
strcat(objExport_path, "-out/");
|
||||
#endif
|
||||
strcat(export_path, hob_objects->name);
|
||||
strcat(objExport_path, hob_objects->name);
|
||||
} else {
|
||||
strcpy(export_path, hob_objects->name);
|
||||
strcpy(objExport_path, hob_objects->name);
|
||||
}
|
||||
strcat(export_path, ".obj");
|
||||
strcpy(mtlExport_path, objExport_path);
|
||||
strcat(objExport_path, ".obj");
|
||||
strcat(mtlExport_path, ".mtl");
|
||||
|
||||
objConstruct = obj_create(NULL);
|
||||
|
||||
//TODO: Write datas to obj file!
|
||||
// Build face/surface material group
|
||||
for ( i = 0; i < hob_objects->face_group_count; i++) {
|
||||
surfID = obj_add_surf(objConstruct);
|
||||
materialID = obj_add_mtrl(objConstruct);
|
||||
|
||||
obj_write(objConstruct, hob_objects->name, export_path, 8);
|
||||
// Build vertex container
|
||||
for ( j = 0; j < hob_objects->face_groups[i].vertex_count; j++ ) {
|
||||
tmpVertex = obj_add_vert(objConstruct);
|
||||
|
||||
vertexBuff[0] = ((float)1/1024) * -hob_objects->face_groups[i].vertices[j].x; // Invert X to fix mirror display
|
||||
vertexBuff[1] = ((float)1/1024) * -hob_objects->face_groups[i].vertices[j].y; // Invert Y to render upside up
|
||||
vertexBuff[2] = ((float)1/1024) * hob_objects->face_groups[i].vertices[j].z;
|
||||
|
||||
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
|
||||
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];
|
||||
|
||||
obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff);
|
||||
|
||||
// Process 2 triangles if face is Quad
|
||||
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];
|
||||
|
||||
obj_set_poly(objConstruct, surfID, tmpIndex, indicesBuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obj_write(objConstruct, objExport_path, NULL, 8);
|
||||
obj_delete(objConstruct);
|
||||
|
||||
return NO_ERROR;
|
||||
|
@ -8,6 +8,13 @@
|
||||
#ifndef SRC_OBJ_EXPORTER_H_
|
||||
#define SRC_OBJ_EXPORTER_H_
|
||||
|
||||
|
||||
typedef struct t_material {
|
||||
unsigned short hasTexture;
|
||||
unsigned short bpp;
|
||||
unsigned int gl_tex_id;
|
||||
} T_MATERIAL;
|
||||
|
||||
unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path);
|
||||
|
||||
#endif /* SRC_OBJ_EXPORTER_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user