From e0c9f2c7d8e4fc18f03586899821335f50cd3925 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Wed, 27 Jul 2022 17:33:55 +0200 Subject: [PATCH] Structure for exporting --- CMakeLists.txt | 6 +++--- src/Model-Extractor.c | 20 ++++++++++++------- src/hob_struct.h | 2 +- src/obj_exporter.c | 46 +++++++++++++++++++++++++++++++++++++++++++ src/obj_exporter.h | 13 ++++++++++++ 5 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 src/obj_exporter.c create mode 100644 src/obj_exporter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 222220a..30a6a90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,8 @@ include(CheckCSourceCompiles) # needed packages -find_package(GLEW REQUIRED) -include_directories(${GLEW_INCLUDE_DIR}) +#find_package(GLEW REQUIRED) +#include_directories(${GLEW_INCLUDE_DIR}) # define src/headers files @@ -45,7 +45,7 @@ if(MSVC) set_target_properties(rse-model PROPERTIES PREFIX "lib") set_target_properties(rse-model PROPERTIES IMPORT_PREFIX "lib") endif() -target_link_libraries(rse-model ${GLEW_LIBRARIES}) +target_link_libraries(rse-model m) # add GPG signature command #add_custom_command( diff --git a/src/Model-Extractor.c b/src/Model-Extractor.c index 16009d7..76b4aa7 100644 --- a/src/Model-Extractor.c +++ b/src/Model-Extractor.c @@ -21,7 +21,7 @@ #include "options.h" #include "hob_struct.h" #include "hob_parser.h" -//#include "rlk/obj.h" +#include "obj_exporter.h" /* @@ -72,6 +72,7 @@ int main(int argc, char *argv[]) { static unsigned int mainProcess(int args_cnt, char *args_value[]) { unsigned short file_index; T_HOB* hobStruct = NULL; + int i; // Manage multiple inputs files for (file_index=(_options >> 8) & 0xFF; file_index < args_cnt; file_index++) @@ -84,16 +85,21 @@ static unsigned int mainProcess(int args_cnt, char *args_value[]) { free(hobStruct); return ERROR_PROCESS; } + + if (hobStruct->obj_count > 0) { + if (_options & OUTPUT_DIR) createSubDir(args_value[file_index]); + + for ( i = 0; i < hobStruct->obj_count; i++ ) { + if (exportOBJModel(&(hobStruct->objects[i]), args_value[file_index]) != NO_ERROR) + printf("[ERR] Failed to export %s object in OBJ format!\n", hobStruct->objects[i].name); + else + printf("[INFO] Successfully exported %s object in OBJ format.\n", hobStruct->objects[i].name); + } + } } cleanUpMemory(hobStruct); - - /* - if (exportTextures(hmt_fdatas, argv[file_index]) == EXIT_FAILURE) return EXIT_FAILURE; - purgeHMTFromMemory(hmt_fdatas); // Clean up memory (because I'm a good boy) - */ - return NO_ERROR; } diff --git a/src/hob_struct.h b/src/hob_struct.h index b68df84..55b1697 100644 --- a/src/hob_struct.h +++ b/src/hob_struct.h @@ -72,7 +72,7 @@ typedef struct hob_face_group { } T_HOB_FACE_GROUP; typedef struct hob_object { - unsigned char name[16]; + char name[16]; unsigned int face_group_offset; unsigned int face_group_header_offset; unsigned int face_group_header2_offset; diff --git a/src/obj_exporter.c b/src/obj_exporter.c new file mode 100644 index 0000000..6448553 --- /dev/null +++ b/src/obj_exporter.c @@ -0,0 +1,46 @@ +/* + * obj_exporter.c + * + * Created on: 27 juil. 2022 + * Author: JackCarterSmith + */ + +#include +#include +#include +#include "errors_types.h" +#include "options.h" +#include "hob_struct.h" +#include "rlk/obj.h" +#include "obj_exporter.h" + + +unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path) { + char export_path[128]; + obj* objConstruct = NULL; + + if (hob_objects == NULL || out_path == NULL) + return ERROR_ARGS_NULL; + + if (_options & OUTPUT_DIR) { + strcpy(export_path, out_path); + #ifdef _WIN32 + strcat(export_path, "-out\\"); + #else + strcat(export_path, "-out/"); + #endif + strcat(export_path, hob_objects->name); + } else { + strcpy(export_path, hob_objects->name); + } + strcat(export_path, ".obj"); + + objConstruct = obj_create(NULL); + + //TODO: Write datas to obj file! + + obj_write(objConstruct, hob_objects->name, export_path, 8); + obj_delete(objConstruct); + + return NO_ERROR; +} diff --git a/src/obj_exporter.h b/src/obj_exporter.h new file mode 100644 index 0000000..f6e7945 --- /dev/null +++ b/src/obj_exporter.h @@ -0,0 +1,13 @@ +/* + * obj_exporter.h + * + * Created on: 27 juil. 2022 + * Author: JackCarterSmith + */ + +#ifndef SRC_OBJ_EXPORTER_H_ +#define SRC_OBJ_EXPORTER_H_ + +unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path); + +#endif /* SRC_OBJ_EXPORTER_H_ */