Upgraded obj lib and interface
This commit is contained in:
parent
35ed66466b
commit
be65b73bb6
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -1,3 +1,3 @@
|
||||
[submodule "RSEModel/src/rlk"]
|
||||
path = RSEModel/src/rlk
|
||||
url = https://github.com/rlk/obj.git
|
||||
[submodule "RSEModel/src/obj"]
|
||||
path = RSEModel/src/obj
|
||||
url = https://git.jcsmith.fr/jackcartersmith/obj.git
|
@ -25,7 +25,7 @@ This module can do:
|
||||
|
||||
### Using
|
||||
|
||||
`RSE-Model_"version" [options] <hob files...>` or you can simply drag&drop HOB files on it.
|
||||
`RSEModel [options] <hob files...>` or you can simply drag&drop HOB files on it.
|
||||
|
||||
A futur main program can extract all HOB files directly from DAT file.
|
||||
Due to issue with copyrights, I can't provide samples... You need to extract HOB files yourself.
|
||||
@ -37,11 +37,11 @@ Due to issue with copyrights, I can't provide samples... You need to extract HOB
|
||||
- -h Print this message
|
||||
- -v,-vv Activate verbose/debug output mode respectively
|
||||
- -no-subdir Extract textures directly inside current folder
|
||||
- -no-mtl Disable materials datas export with OBJ model
|
||||
- -mtl Export materials datas with OBJ model
|
||||
|
||||
### Dependencies
|
||||
|
||||
- obj-lib: as obj file exporter. (https://github.com/rlk/obj)
|
||||
- obj-lib: as obj file exporter. (https://git.jcsmith.fr/jackcartersmith/obj)
|
||||
|
||||
### Compiling
|
||||
|
||||
|
@ -130,7 +130,7 @@ static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char
|
||||
opt_ptr->output_dir = 0;
|
||||
printf("[OPTN] Export to current directory.\n");
|
||||
} else if (strcmp(p_args[i], "-mtl") == 0) {
|
||||
opt_ptr->export_mtl = 0;
|
||||
opt_ptr->export_mtl = 1;
|
||||
printf("[OPTN] Export materials datas.\n");
|
||||
} else {
|
||||
printf("[ERR] Unknown option: %s\n", p_args[i]);
|
||||
@ -179,7 +179,7 @@ static void dispHelp() {
|
||||
printf("Options:\n -h Print this message\n");
|
||||
printf(" -v -vv Activate verbose console output\n");
|
||||
printf(" -no-subdir Export models inside current folder\n");
|
||||
//printf(" -mtl Export materials datas with model\n");
|
||||
printf(" -mtl Export materials datas with model\n");
|
||||
printf("\n");
|
||||
printf("Usage: RSE-Model_%s [options] <hob files...>\n", PRG_VERSION);
|
||||
printf("\n");
|
||||
|
1
RSEModel/src/obj
Submodule
1
RSEModel/src/obj
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 09f87160bb80d1ad331c697000ecd7a122f9ef60
|
@ -13,15 +13,14 @@
|
||||
#include "options.h"
|
||||
#include <RSPModel_datatypes.h>
|
||||
#include <RSPModel_errordefs.h>
|
||||
#include "rlk/obj.h"
|
||||
#include "obj/obj.h"
|
||||
#include "obj_exporter.h"
|
||||
|
||||
|
||||
static void mtlPathPatch(const char* out_file, const char* obj_name) ;
|
||||
|
||||
unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts) {
|
||||
char objExport_path[128];
|
||||
char mtlExport_path[128];
|
||||
char exportPath[1024];
|
||||
char objExport_name[128];
|
||||
char mtlExport_name[128];
|
||||
obj* objConstruct = NULL;
|
||||
unsigned int i,j;
|
||||
int surfID = 0, materialID = 0, tmpVertex = 0, tmpIndex = 0;
|
||||
@ -32,20 +31,13 @@ unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_pat
|
||||
if (hob_objects == NULL || out_path == NULL)
|
||||
return RSPLIB_ERROR_ARGS_NULL;
|
||||
|
||||
if (p_opts->output_dir) {
|
||||
strcpy(objExport_path, out_path);
|
||||
#ifdef _WIN32
|
||||
strcat(objExport_path, "-out\\");
|
||||
#else
|
||||
strcat(objExport_path, "-out/");
|
||||
#endif
|
||||
strcat(objExport_path, hob_objects->name);
|
||||
} else {
|
||||
strcpy(objExport_path, hob_objects->name);
|
||||
}
|
||||
strcpy(mtlExport_path, objExport_path);
|
||||
strcat(objExport_path, ".obj\0");
|
||||
strcat(mtlExport_path, ".mtl\0");
|
||||
#ifdef _WIN32
|
||||
sprintf_s(exportPath, 1024, "%s-out\\", out_path, hob_objects->name);
|
||||
#else
|
||||
sprintf_s(exportPath, 1024, "%s-out/", out_path, hob_objects->name);
|
||||
#endif
|
||||
sprintf_s(objExport_name, 128, "%s.obj", hob_objects->name);
|
||||
sprintf_s(mtlExport_name, 128, "%s.mtl", hob_objects->name);
|
||||
|
||||
objConstruct = obj_create(NULL);
|
||||
|
||||
@ -108,61 +100,18 @@ unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_pat
|
||||
}
|
||||
|
||||
if (p_opts->export_mtl) {
|
||||
obj_write(objConstruct, objExport_path, mtlExport_path, 8);
|
||||
#if defined(__GNUC__) //TODO: review MSVC file management or include and rewrite obj lib?
|
||||
if (p_opts->output_dir) mtlPathPatch(objExport_path, hob_objects->name);
|
||||
#endif
|
||||
} else obj_write(objConstruct, objExport_path, NULL, 8);
|
||||
if (p_opts->output_dir)
|
||||
obj_write(objConstruct, objExport_name, mtlExport_name, exportPath, 8);
|
||||
else
|
||||
obj_write(objConstruct, objExport_name, mtlExport_name, NULL, 8);
|
||||
} else {
|
||||
if (p_opts->output_dir)
|
||||
obj_write(objConstruct, objExport_name, NULL, exportPath, 8);
|
||||
else
|
||||
obj_write(objConstruct, objExport_name, NULL, NULL, 8);
|
||||
}
|
||||
|
||||
obj_delete(objConstruct);
|
||||
|
||||
return RSPLIB_SUCCESS;
|
||||
}
|
||||
|
||||
static void mtlPathPatch(const char* out_file, const char* obj_name) {
|
||||
FILE* obj = NULL;
|
||||
char* memFile = NULL;
|
||||
long fileSize,i,pos = 0,lines = 0;
|
||||
char _path[128],b;
|
||||
|
||||
obj = fopen(out_file, "r");
|
||||
if ( obj != NULL ) {
|
||||
fseek(obj, 0, SEEK_END);
|
||||
fileSize = ftell(obj);
|
||||
fseek(obj, 0, SEEK_SET);
|
||||
|
||||
// Find the end of first line
|
||||
for ( i = 0; i < fileSize + 1; i++) {
|
||||
b = (char)fgetc(obj);
|
||||
if (b == '\n') {
|
||||
if (pos == 0) pos = i;
|
||||
lines++;
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare mtl path for output
|
||||
strcpy(_path, obj_name);
|
||||
strcat(_path, ".mtl");
|
||||
|
||||
memFile = malloc(fileSize - (pos + lines));
|
||||
if ( memFile != NULL ) {
|
||||
// Read the rest of file in memory
|
||||
fseek(obj, pos, SEEK_SET);
|
||||
fread(memFile, fileSize - (pos + lines), 1, obj);
|
||||
fclose(obj);
|
||||
|
||||
// Begin rewrite file
|
||||
obj = fopen(out_file, "w");
|
||||
fprintf(obj, "mtllib %s", _path);
|
||||
#if defined(_MSC_VER)
|
||||
fwrite(memFile, fileSize - pos , 1, obj);
|
||||
#elif defined(__GNUC__)
|
||||
fwrite(memFile, fileSize - (pos + lines), 1, obj);
|
||||
#endif
|
||||
|
||||
free(memFile);
|
||||
}
|
||||
|
||||
fclose(obj);
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 48a6916526d043691bb3f9e38676fbc99995da10
|
Loading…
x
Reference in New Issue
Block a user