Vertices extraction
This commit is contained in:
parent
f983930e15
commit
27457ea4f9
@ -21,19 +21,19 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "hob_struct.h"
|
#include "hob_struct.h"
|
||||||
#include "hob_parser.h"
|
#include "hob_parser.h"
|
||||||
#include "rlk/obj.h"
|
//#include "rlk/obj.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal functions declarations
|
* Internal functions declarations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int mainProcess(int args_cnt, char *args_value[]);
|
static unsigned int mainProcess(int args_cnt, char *args_value[]);
|
||||||
void createSubDir(char *dirName);
|
static void createSubDir(char *dirName);
|
||||||
int checkInputArgs(int arg_nbr, char *args[]);
|
static int checkInputArgs(int arg_nbr, char *args[]);
|
||||||
void cleanUpMemory(T_HOB* hobStruct);
|
static void cleanUpMemory(T_HOB* hobStruct);
|
||||||
//int exportTextures(HMT_FILE *hmt_f, char *filename);
|
//int exportTextures(HMT_FILE *hmt_f, char *filename);
|
||||||
void dispHelp();
|
static inline void dispHelp();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -69,7 +69,7 @@ int main(int argc, char *argv[]) {
|
|||||||
* Private functions definition
|
* Private functions definition
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int mainProcess(int args_cnt, char *args_value[]) {
|
static unsigned int mainProcess(int args_cnt, char *args_value[]) {
|
||||||
unsigned short file_index;
|
unsigned short file_index;
|
||||||
T_HOB* hobStruct = NULL;
|
T_HOB* hobStruct = NULL;
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ unsigned int mainProcess(int args_cnt, char *args_value[]) {
|
|||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int checkInputArgs(int arg_nbr, char *args[]) {
|
static int checkInputArgs(int arg_nbr, char *args[]) {
|
||||||
int _o = 0x0002; // Default options parameters
|
int _o = 0x0002; // Default options parameters
|
||||||
char test[256];
|
char test[256];
|
||||||
int i;
|
int i;
|
||||||
@ -125,7 +125,7 @@ int checkInputArgs(int arg_nbr, char *args[]) {
|
|||||||
return _o;
|
return _o;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createSubDir(char *dirName) {
|
static void createSubDir(char *dirName) {
|
||||||
if (dirName == NULL) return;
|
if (dirName == NULL) return;
|
||||||
char _dir[260]; //TODO: Change directory management
|
char _dir[260]; //TODO: Change directory management
|
||||||
strcpy(_dir, dirName);
|
strcpy(_dir, dirName);
|
||||||
@ -138,23 +138,24 @@ void createSubDir(char *dirName) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanUpMemory(T_HOB* hobStruct) {
|
static void cleanUpMemory(T_HOB* hobStruct) {
|
||||||
int i,j,k;
|
int i,j;
|
||||||
|
|
||||||
for ( i=0; i<hobStruct->obj_count; i++ ) {
|
for ( i=0; i<hobStruct->obj_count; i++ ) {
|
||||||
for ( j=0; j<hobStruct->objects[i].face_group_count; j++ ) {
|
for ( j=0; j<hobStruct->objects[i].face_group_count; j++ ) {
|
||||||
|
|
||||||
|
free(hobStruct->objects[i].face_groups[j].faces);
|
||||||
free(&(hobStruct->objects[i].face_groups[j]));
|
free(hobStruct->objects[i].face_groups[j].vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(&(hobStruct->objects[i]));
|
free(hobStruct->objects[i].face_groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(hobStruct->objects);
|
||||||
free(hobStruct);
|
free(hobStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispHelp() {
|
static inline void dispHelp() {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n -h Print this message\n -v Activate verbose console output\n -no-subdir Extract textures inside current folder\n");
|
printf("Options:\n -h Print this message\n -v Activate verbose console output\n -no-subdir Extract textures inside current folder\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -19,7 +19,7 @@ unsigned char parseHOBFile(const char* fileName, T_HOB* hob_struct) {
|
|||||||
long fileSize;
|
long fileSize;
|
||||||
FILE* fStream = NULL;
|
FILE* fStream = NULL;
|
||||||
char* memFile = NULL;
|
char* memFile = NULL;
|
||||||
int i,j;
|
int i,j,k;
|
||||||
int* offset_index = NULL;
|
int* offset_index = NULL;
|
||||||
|
|
||||||
if (hob_struct != NULL && fileName != NULL) {
|
if (hob_struct != NULL && fileName != NULL) {
|
||||||
@ -83,9 +83,54 @@ unsigned char parseHOBFile(const char* fileName, T_HOB* hob_struct) {
|
|||||||
offset_index[j] = ((T_HOBFILE_FACEGROUP_OFFSET *)(memFile + hob_struct->objects[i].face_group_header_offset
|
offset_index[j] = ((T_HOBFILE_FACEGROUP_OFFSET *)(memFile + hob_struct->objects[i].face_group_header_offset
|
||||||
+ sizeof(T_HOBFILE_FACEGROUP_HEADER)
|
+ sizeof(T_HOBFILE_FACEGROUP_HEADER)
|
||||||
+ sizeof(T_HOBFILE_FACEGROUP_OFFSET) * j))->facegroup_offset;
|
+ sizeof(T_HOBFILE_FACEGROUP_OFFSET) * j))->facegroup_offset;
|
||||||
if (_options & VERBOSE_ENABLED) printf("[DBG] > Face group meshdef0 offset: 0x%X\n", offset_index[j]);
|
if (_options & VERBOSE_ENABLED) printf("\n[DBG] > Face group meshdef0 offset: 0x%X\n", offset_index[j]);
|
||||||
|
|
||||||
// TODO: READ FACEGROUP MESHDEF!!!
|
// Get meshdef1 (mesh descriptor) offset
|
||||||
|
hob_struct->objects[i].face_groups[j].meshdef1_offset = ((T_HOBFILE_MESHDEF0_0 *)(memFile
|
||||||
|
+ offset_index[j]))->meshdef1_offset_plus_4;
|
||||||
|
if (_options & VERBOSE_ENABLED) printf("[DBG] > Face group meshdef1 offset: 0x%X\n", hob_struct->objects[i].face_groups[j].meshdef1_offset);
|
||||||
|
|
||||||
|
if (hob_struct->objects[i].face_groups[j].meshdef1_offset > 0) {
|
||||||
|
// Read meshdef1 datas
|
||||||
|
hob_struct->objects[i].face_groups[j].face_block_end_offset = ((T_HOBFILE_MESHDEF1 *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].meshdef1_offset - 4))->facedef_end_offset;
|
||||||
|
hob_struct->objects[i].face_groups[j].vertex_count = ((T_HOBFILE_MESHDEF1 *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].meshdef1_offset - 4))->vertex_count;
|
||||||
|
hob_struct->objects[i].face_groups[j].face_block_offset = ((T_HOBFILE_MESHDEF1 *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].meshdef1_offset - 4))->faceblock_offset;
|
||||||
|
if (_options & VERBOSE_ENABLED) printf("[DBG] > Faces offset: 0x%X\n", hob_struct->objects[i].face_groups[j].face_block_offset);
|
||||||
|
hob_struct->objects[i].face_groups[j].vertex_block_offset = ((T_HOBFILE_MESHDEF1 *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].meshdef1_offset - 4))->vertexblocks_offset;
|
||||||
|
if (_options & VERBOSE_ENABLED) printf("[DBG] > Vertex offset: 0x%X\n", hob_struct->objects[i].face_groups[j].vertex_block_offset);
|
||||||
|
|
||||||
|
//TODO: read Faces
|
||||||
|
|
||||||
|
// Get vertices datas
|
||||||
|
hob_struct->objects[i].face_groups[j].vertices = calloc(hob_struct->objects[i].face_groups[j].vertex_count, sizeof(T_VERTEX));
|
||||||
|
for ( k = 0; k < hob_struct->objects[i].face_groups[j].vertex_count; k++ ) {
|
||||||
|
hob_struct->objects[i].face_groups[j].vertices[k].x = ((T_HOBFILE_VERTEX *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].vertex_block_offset
|
||||||
|
+ sizeof(T_VERTEX) * k))->x;
|
||||||
|
|
||||||
|
hob_struct->objects[i].face_groups[j].vertices[k].y = ((T_HOBFILE_VERTEX *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].vertex_block_offset
|
||||||
|
+ sizeof(T_VERTEX) * k))->y;
|
||||||
|
|
||||||
|
hob_struct->objects[i].face_groups[j].vertices[k].z = ((T_HOBFILE_VERTEX *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].vertex_block_offset
|
||||||
|
+ sizeof(T_VERTEX) * k))->z;
|
||||||
|
|
||||||
|
hob_struct->objects[i].face_groups[j].vertices[k].w = ((T_HOBFILE_VERTEX *)(memFile
|
||||||
|
+ hob_struct->objects[i].face_groups[j].vertex_block_offset
|
||||||
|
+ sizeof(T_VERTEX) * k))->w; // Always 0???
|
||||||
|
|
||||||
|
//if (_options & VERBOSE_ENABLED) printf("[DBG] > Found vertex: (%d, %d, %d)\n",
|
||||||
|
// hob_struct->objects[i].face_groups[j].vertices[k].x,
|
||||||
|
// hob_struct->objects[i].face_groups[j].vertices[k].y,
|
||||||
|
// hob_struct->objects[i].face_groups[j].vertices[k].z
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
typedef unsigned int T_RGBA;
|
typedef unsigned int T_RGBA;
|
||||||
|
|
||||||
|
typedef struct vertex { short x,y,z,w; } T_VERTEX;
|
||||||
|
|
||||||
typedef struct tex_coord { unsigned short u,v; } T_TEXCOORD;
|
typedef struct tex_coord { unsigned short u,v; } T_TEXCOORD;
|
||||||
|
|
||||||
typedef struct hob_face {
|
typedef struct hob_face {
|
||||||
@ -48,7 +50,7 @@ typedef struct hob_face_group {
|
|||||||
T_HOB_FACE* faces;
|
T_HOB_FACE* faces;
|
||||||
|
|
||||||
unsigned int vertex_count;
|
unsigned int vertex_count;
|
||||||
unsigned short* vertices;
|
T_VERTEX* vertices;
|
||||||
} T_HOB_FACE_GROUP;
|
} T_HOB_FACE_GROUP;
|
||||||
|
|
||||||
typedef struct hob_object {
|
typedef struct hob_object {
|
||||||
@ -197,4 +199,11 @@ typedef struct __attribute__((packed)) hobfile_meshdef1 {
|
|||||||
unsigned int reserved19;
|
unsigned int reserved19;
|
||||||
} T_HOBFILE_MESHDEF1;
|
} T_HOBFILE_MESHDEF1;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed)) hobfile_vertex {
|
||||||
|
short x;
|
||||||
|
short y;
|
||||||
|
short z;
|
||||||
|
short w;
|
||||||
|
} T_HOBFILE_VERTEX;
|
||||||
|
|
||||||
#endif /* SRC_HOB_STRUCT_H_ */
|
#endif /* SRC_HOB_STRUCT_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user