Lib interface with better parameters options
Some checks failed
JCS-Prod/RSE-Model/pipeline/pr-master There was a failure building this commit

This commit is contained in:
JackCarterSmith 2022-08-19 18:23:53 +02:00
parent aa2d52768a
commit c5589c0199
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
8 changed files with 93 additions and 115 deletions

View File

@ -66,16 +66,19 @@ int main(int argc, char *argv[]) {
static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* p_opts) { static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* p_opts) {
unsigned short file_index; unsigned short file_index;
RSPMODEL_PARAMETERS libParams;
T_RSPMODEL_HOB* hobStruct = NULL; T_RSPMODEL_HOB* hobStruct = NULL;
int i; int i;
libParams.raw = p_opts->raw & 0x7;
// Manage multiple inputs files // Manage multiple inputs files
for ( file_index = p_opts->input_files_cnt; file_index < args_cnt; file_index++) for ( file_index = p_opts->input_files_cnt; file_index < args_cnt; file_index++)
{ {
printf("\n=============================================\n[INFO] - Parsing file: %s ...\n", args_value[file_index]); printf("\n=============================================\n[INFO] - Parsing file: %s ...\n", args_value[file_index]);
hobStruct = calloc(1, sizeof(T_RSPMODEL_HOB)); hobStruct = calloc(1, sizeof(T_RSPMODEL_HOB));
// Parse data from HOB file and put in T_HOB structure. // Parse data from HOB file and put in T_HOB structure.
if (RSPModel_processHOBFile(hobStruct, args_value[file_index]) != RSPLIB_SUCCESS) { if (RSPModel_processHOBFile(hobStruct, args_value[file_index], libParams) != RSPLIB_SUCCESS) {
printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]); printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]);
free(hobStruct); free(hobStruct);
return RSPLIB_ERROR_PROCESS; return RSPLIB_ERROR_PROCESS;

View File

@ -14,16 +14,13 @@
typedef union u_prog_options { typedef union u_prog_options {
struct { struct {
unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things. unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things.
unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things.
unsigned char god_mode:1; //!< Dev only. Output experimental values.
unsigned char output_dir:1; //!< Export extracted datas to a sub-directory. unsigned char output_dir:1; //!< Export extracted datas to a sub-directory.
unsigned char export_mtl:1; //!< Export materials datas with object. unsigned char export_mtl:1; //!< Export materials datas with object.
unsigned char reserved0:5; //!< For future use. unsigned short reserved0:11; //!< For future use.
unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things.
unsigned char god_mode:1; //!< Dev only. Output experimental values.
unsigned char reserved1:6; //!< For future use.
unsigned short input_files_cnt; //!< Internal files counters. unsigned short input_files_cnt; //!< Internal files counters.
}; };

View File

@ -61,11 +61,13 @@ RSPMODEL_EXTERN char* RSPModel_getVersion( void );
* *
* @param[out] hob HOB structure to be filled with parsed datas. * @param[out] hob HOB structure to be filled with parsed datas.
* @param[in] filePath Path to the HOB file in system. * @param[in] filePath Path to the HOB file in system.
* @param[in] params Parser options. See RSPMODEL_PARAMETERS.
* *
* @return Error status, return RSPLIB_SUCCESS in nominal case. * @return Error status, return RSPLIB_SUCCESS in nominal case.
*/ */
RSPMODEL_EXTERN unsigned short RSPModel_processHOBFile( RSPMODEL_EXTERN unsigned short RSPModel_processHOBFile(
T_RSPMODEL_HOB* hob, const char* const filePath T_RSPMODEL_HOB* hob, const char* const filePath,
const RSPMODEL_PARAMETERS params
); );
/** /**
@ -77,11 +79,13 @@ RSPMODEL_EXTERN unsigned short RSPModel_processHOBFile(
* @param[out] hob HOB structure to be filled with parsed datas. * @param[out] hob HOB structure to be filled with parsed datas.
* @param[in] memFilePtr Pointer to the beginning of the file in memory. * @param[in] memFilePtr Pointer to the beginning of the file in memory.
* @param[in] memFileSize Size of the file in bytes. * @param[in] memFileSize Size of the file in bytes.
* @param[in] params Parser options. See RSPMODEL_PARAMETERS.
* *
* @return Error status, return RSPLIB_SUCCESS in nominal case. * @return Error status, return RSPLIB_SUCCESS in nominal case.
*/ */
RSPMODEL_EXTERN unsigned short RSPModel_processHOBFileMemory( RSPMODEL_EXTERN unsigned short RSPModel_processHOBFileMemory(
T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize,
const RSPMODEL_PARAMETERS params
); );
/** /**

View File

@ -14,6 +14,22 @@
extern "C" { extern "C" {
#endif #endif
///////////////////////////////////////////////////////////////////////////////
// Configuration structure
///////////////////////////////////////////////////////////////////////////////
typedef union u_rspmodel_parameters {
struct {
unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things.
unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things.
unsigned char god_mode:1; //!< Dev only. Output experimental values.
unsigned char reserved0:5; //!< For future use.
};
unsigned char raw; //!< Raw options access for bit-masking or memory copy/compare.
} RSPMODEL_PARAMETERS ;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Lib's structure definitions // Lib's structure definitions
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -11,7 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
#include "options.h"
#include "RSPModel_errordefs.h" #include "RSPModel_errordefs.h"
#include "hob_parser.h" #include "hob_parser.h"
#include "RSPModel.h" #include "RSPModel.h"
@ -21,26 +20,22 @@ char* RSPModel_getVersion( void ) {
return PRG_VERSION; return PRG_VERSION;
} }
unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath ) { unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath,
const RSPMODEL_PARAMETERS params ) {
if ( hob == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL; if ( hob == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL;
T_PROG_OPTIONS canard; RSP_ModelLib_ParseHOBFile(filePath, hob, &params);
canard.god_mode = 1;
canard.debug_mode = 1;
canard.verbose_mode = 1;
RSP_ModelLib_ParseHOBFile(filePath, hob, &canard);
return RSPLIB_SUCCESS; return RSPLIB_SUCCESS;
} }
unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize ) { unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr,
const long memFileSize, const RSPMODEL_PARAMETERS params ) {
if ( hob == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL; if ( hob == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL;
T_PROG_OPTIONS canard; RSP_ModelLib_ParseHOBMemFile((MEMFILE)memFilePtr, hob, &params);
canard.god_mode = 1;
canard.debug_mode = 1;
canard.verbose_mode = 1;
RSP_ModelLib_ParseHOBMemFile((MEMFILE)memFilePtr, hob, &canard);
return RSPLIB_SUCCESS; return RSPLIB_SUCCESS;
} }

View File

@ -12,7 +12,6 @@
#include <string.h> #include <string.h>
#include "RSPModel_errordefs.h" #include "RSPModel_errordefs.h"
#include "RSPModel_datatypes.h" #include "RSPModel_datatypes.h"
#include "options.h"
#include "hob_struct.h" #include "hob_struct.h"
#include "hob_parser.h" #include "hob_parser.h"
@ -21,9 +20,9 @@
// Private functions declarations // Private functions declarations
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static unsigned int ExtractObjects(T_RSPMODEL_HOB*, const MEMFILE, const unsigned char); static unsigned int ExtractObjects(T_RSPMODEL_HOB*, const MEMFILE, const RSPMODEL_PARAMETERS*);
static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT*, const MEMFILE, const unsigned char); static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT*, const MEMFILE, const RSPMODEL_PARAMETERS*);
static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS*, const MEMFILE, const unsigned char); static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS*, const MEMFILE, const RSPMODEL_PARAMETERS*);
static inline unsigned int ExtractObjpart_Face_Colors(T_RSPMODEL_FACE*, const char*); static inline unsigned int ExtractObjpart_Face_Colors(T_RSPMODEL_FACE*, const char*);
static inline unsigned int ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE*, const char*); static inline unsigned int ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE*, const char*);
@ -32,24 +31,24 @@ static inline unsigned int ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE*, const ch
// Public functions definition // Public functions definition
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts) { unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) {
unsigned char err = RSPLIB_SUCCESS; unsigned char err = RSPLIB_SUCCESS;
if (hob_struct != NULL && pMemFile != NULL) { if (hobStruct != NULL && pMemFile != NULL) {
// Do the magic! // Do the magic!
err = ExtractObjects(hob_struct, pMemFile, p_opts->verbose_mode + p_opts->debug_mode + p_opts->god_mode); err = ExtractObjects(hobStruct, pMemFile, pParams);
} else err = RSPLIB_ERROR_ARGS_NULL; } else err = RSPLIB_ERROR_ARGS_NULL;
return err; return err;
} }
unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts) { unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) {
unsigned char err = RSPLIB_SUCCESS; unsigned char err = RSPLIB_SUCCESS;
long fileSize; long fileSize;
FILE* fStream = NULL; FILE* fStream = NULL;
MEMFILE memFile = NULL; MEMFILE memFile = NULL;
if (hob_struct != NULL && fileName != NULL) { if (hobStruct != NULL && fileName != NULL) {
// Open file // Open file
fStream = fopen(fileName, "rb"); fStream = fopen(fileName, "rb");
@ -58,7 +57,7 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho
fseek(fStream, 0, SEEK_END); fseek(fStream, 0, SEEK_END);
fileSize = ftell(fStream); fileSize = ftell(fStream);
fseek(fStream, 0, SEEK_SET); fseek(fStream, 0, SEEK_SET);
if (p_opts->verbose_mode) printf("[DBG] > Input file size: %ld bytes\n", fileSize); if (pParams->verbose_mode) printf("[DBG] > Input file size: %ld bytes\n", fileSize);
memFile = malloc(fileSize + 1); memFile = malloc(fileSize + 1);
if (memFile != NULL) { if (memFile != NULL) {
@ -67,18 +66,18 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho
fclose(fStream); fclose(fStream);
// Do the magic! // Do the magic!
err = ExtractObjects(hob_struct, memFile, p_opts->verbose_mode + p_opts->debug_mode + p_opts->god_mode); err = ExtractObjects(hobStruct, memFile, pParams);
free(memFile); free(memFile);
} else { } else {
fclose(fStream); fclose(fStream);
err = RSPLIB_ERROR_MEMORY; err = RSPLIB_ERROR_MEMORY;
if (p_opts->verbose_mode) printf("[ERR] Can't allocate enough memory for file processing!\n"); if (pParams->verbose_mode) printf("[ERR] Can't allocate enough memory for file processing!\n");
} }
} else { } else {
err = RSPLIB_ERROR_IO; err = RSPLIB_ERROR_IO;
if (p_opts->verbose_mode) printf("[ERR] Input file %s not found!\n", fileName); if (pParams->verbose_mode) printf("[ERR] Input file %s not found!\n", fileName);
} }
} else err = RSPLIB_ERROR_ARGS_NULL; } else err = RSPLIB_ERROR_ARGS_NULL;
@ -99,7 +98,7 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho
* *
* @return Error code, RSPLIB_SUCCESS when no error. * @return Error code, RSPLIB_SUCCESS when no error.
*/ */
static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMemfile, const unsigned char verbose) { static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) {
unsigned int i; unsigned int i;
if (pHobStruct == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; if (pHobStruct == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
@ -117,28 +116,28 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe
if (pHobStruct->objects == NULL) return RSPLIB_ERROR_MEMORY; if (pHobStruct->objects == NULL) return RSPLIB_ERROR_MEMORY;
for ( i = 0; i < pHobStruct->obj_count; i++ ) { for ( i = 0; i < pHobStruct->obj_count; i++ ) {
if (verbose == 2) printf("\n-=====================-Begin of Object part-======================-\n"); if (pParams->debug_mode) printf("\n-=====================-Begin of Object part-======================-\n");
// Get object name // Get object name
memcpy(pHobStruct->objects[i].name, ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) memcpy(pHobStruct->objects[i].name, ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER)
+ sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->object_name, 16); + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->object_name, 16);
if (verbose == 1) printf("\n"); if (pParams->verbose_mode) printf("\n");
printf("[INFO] - Process %s object...\n", pHobStruct->objects[i].name); printf("[INFO] - Process %s object...\n", pHobStruct->objects[i].name);
// Get offsets // Get offsets
pHobStruct->objects[i].face_group_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) pHobStruct->objects[i].face_group_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER)
+ sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->facegroup_offset; + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->facegroup_offset;
if (verbose == 1) printf("[DBG] > Face group offset: 0x%X\n", pHobStruct->objects[i].face_group_offset); if (pParams->verbose_mode) printf("[DBG] > Face group offset: 0x%X\n", pHobStruct->objects[i].face_group_offset);
pHobStruct->objects[i].object_part_header_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) pHobStruct->objects[i].object_part_header_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER)
+ sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->object_parts_offset; + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->object_parts_offset;
if (verbose == 1) printf("[DBG] > Face group header/object parts offset: 0x%X\n", pHobStruct->objects[i].object_part_header_offset); if (pParams->verbose_mode) printf("[DBG] > Face group header/object parts offset: 0x%X\n", pHobStruct->objects[i].object_part_header_offset);
pHobStruct->objects[i].face_group_header_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) pHobStruct->objects[i].face_group_header_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER)
+ sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->facegroup_header_2_offset; + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->facegroup_header_2_offset;
if (verbose == 1) printf("[DBG] > Face group header2 offset: 0x%X\n", pHobStruct->objects[i].face_group_header_offset); if (pParams->verbose_mode) printf("[DBG] > Face group header2 offset: 0x%X\n", pHobStruct->objects[i].face_group_header_offset);
if (verbose == 3) { if (pParams->god_mode) {
printf("[DBG] > Face group unknown1: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset1); printf("[DBG] > Face group unknown1: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset1);
printf("[DBG] > Face group unknown2: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset2); printf("[DBG] > Face group unknown2: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset2);
printf("[DBG] > Face group unknown3: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset3); printf("[DBG] > Face group unknown3: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset3);
@ -148,15 +147,15 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe
// Get count and offsets from the facegroup header // Get count and offsets from the facegroup header
pHobStruct->objects[i].object_part_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile pHobStruct->objects[i].object_part_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile
+ pHobStruct->objects[i].object_part_header_offset))->object_part_count; + pHobStruct->objects[i].object_part_header_offset))->object_part_count;
if (verbose == 1) printf("[DBG] > Object parts count: %d\n", pHobStruct->objects[i].object_part_count); if (pParams->verbose_mode) printf("[DBG] > Object parts count: %d\n", pHobStruct->objects[i].object_part_count);
pHobStruct->objects[i].face_group_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile pHobStruct->objects[i].face_group_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile
+ pHobStruct->objects[i].object_part_header_offset))->facegroup_count; + pHobStruct->objects[i].object_part_header_offset))->facegroup_count;
if (verbose == 1) printf("[DBG] > Face groups count: %d\n", pHobStruct->objects[i].face_group_count); if (pParams->verbose_mode) printf("[DBG] > Face groups count: %d\n", pHobStruct->objects[i].face_group_count);
if (pHobStruct->objects[i].object_part_count != pHobStruct->objects[i].face_group_count && (verbose == 1)) if (pHobStruct->objects[i].object_part_count != pHobStruct->objects[i].face_group_count && (pParams->verbose_mode))
printf("[DBG] > Object parts / facegroup count are different!\n"); printf("[DBG] > Object parts / facegroup count are different!\n");
// Get facegroup datas // Get facegroup datas
ExtractObjParts(&pHobStruct->objects[i], pMemfile, verbose); ExtractObjParts(&pHobStruct->objects[i], pMemfile, pParams);
} }
return RSPLIB_SUCCESS; return RSPLIB_SUCCESS;
@ -171,7 +170,7 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe
* *
* @return Error code, RSPLIB_SUCCESS when no error. * @return Error code, RSPLIB_SUCCESS when no error.
*/ */
static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pMemfile, const unsigned char verbose) { static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) {
unsigned int i, subpart_offset = 0; unsigned int i, subpart_offset = 0;
if (pObject == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; if (pObject == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
@ -180,28 +179,28 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM
if (pObject->object_parts == NULL) return RSPLIB_ERROR_MEMORY; if (pObject->object_parts == NULL) return RSPLIB_ERROR_MEMORY;
for ( i = 0; i < pObject->object_part_count; i++ ) { for ( i = 0; i < pObject->object_part_count; i++ ) {
if (verbose == 2) printf("\n-----------------------Begin of Mesh part-------------------------\n"); if (pParams->debug_mode) printf("\n-----------------------Begin of Mesh part-------------------------\n");
subpart_offset = ((T_HOBFILE_FACEGROUP_OFFSET *)(pMemfile + pObject->object_part_header_offset subpart_offset = ((T_HOBFILE_FACEGROUP_OFFSET *)(pMemfile + pObject->object_part_header_offset
+ sizeof(T_HOBFILE_FACEGROUP_HEADER) + sizeof(T_HOBFILE_FACEGROUP_OFFSET) * i))->facegroup_offset; + sizeof(T_HOBFILE_FACEGROUP_HEADER) + sizeof(T_HOBFILE_FACEGROUP_OFFSET) * i))->facegroup_offset;
if (verbose == 1) printf("\n[DBG] > Face group meshdef0 offset: 0x%X\n", subpart_offset); if (pParams->verbose_mode) printf("\n[DBG] > Face group meshdef0 offset: 0x%X\n", subpart_offset);
// Get meshdef0 datas // Get meshdef0 datas
if (verbose == 3) printf("[DBG] > meshdef0 offset1: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset1); if (pParams->god_mode) printf("[DBG] > meshdef0 offset1: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset1);
if (verbose == 3) printf("[DBG] > meshdef0 offset2: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset2); if (pParams->god_mode) printf("[DBG] > meshdef0 offset2: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset2);
if (verbose == 1) printf("[DBG] > Prev meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->prev_meshdef0_offset); if (pParams->verbose_mode) printf("[DBG] > Prev meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->prev_meshdef0_offset);
if (verbose == 1) printf("[DBG] > Next meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->next_meshdef0_offset); if (pParams->verbose_mode) printf("[DBG] > Next meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->next_meshdef0_offset);
if (verbose == 3) printf("[DBG] > meshdef0 unknown3: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown3); if (pParams->god_mode) printf("[DBG] > meshdef0 unknown3: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown3);
if (verbose == 3) printf("[DBG] > meshdef0 unknown4: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown4); if (pParams->god_mode) printf("[DBG] > meshdef0 unknown4: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown4);
if (verbose == 3) printf("[DBG] > meshdef0 unknown5: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown5); if (pParams->god_mode) printf("[DBG] > meshdef0 unknown5: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown5);
// Get meshdef1 (mesh descriptor) offset // Get meshdef1 (mesh descriptor) offset
pObject->object_parts[i].meshdef1_offset = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->meshdef1_offset_plus_4; pObject->object_parts[i].meshdef1_offset = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->meshdef1_offset_plus_4;
if (verbose == 1) printf("\n[DBG] > Face group meshdef1 offset: 0x%X\n", pObject->object_parts[i].meshdef1_offset); if (pParams->verbose_mode) printf("\n[DBG] > Face group meshdef1 offset: 0x%X\n", pObject->object_parts[i].meshdef1_offset);
if( ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved1 != 0 || if( ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved1 != 0 ||
((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved2 != 0 ) { ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved2 != 0 ) {
if (verbose == 3) printf("[DBG] > Face group meshdef0: no 0!\n"); if (pParams->god_mode) printf("[DBG] > Face group meshdef0: no 0!\n");
} }
if (pObject->object_parts[i].meshdef1_offset > 0) { if (pObject->object_parts[i].meshdef1_offset > 0) {
@ -212,33 +211,33 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM
+ pObject->object_parts[i].meshdef1_offset - 4))->vertex_count; + pObject->object_parts[i].meshdef1_offset - 4))->vertex_count;
pObject->object_parts[i].face_block_offset = ((T_HOBFILE_MESHDEF1 *)(pMemfile pObject->object_parts[i].face_block_offset = ((T_HOBFILE_MESHDEF1 *)(pMemfile
+ pObject->object_parts[i].meshdef1_offset - 4))->faceblock_offset; + pObject->object_parts[i].meshdef1_offset - 4))->faceblock_offset;
if (verbose == 1) printf("[DBG] > Faces offset: 0x%X\n", pObject->object_parts[i].face_block_offset); if (pParams->verbose_mode) printf("[DBG] > Faces offset: 0x%X\n", pObject->object_parts[i].face_block_offset);
pObject->object_parts[i].vertex_block_offset = ((T_HOBFILE_MESHDEF1 *)(pMemfile pObject->object_parts[i].vertex_block_offset = ((T_HOBFILE_MESHDEF1 *)(pMemfile
+ pObject->object_parts[i].meshdef1_offset - 4))->vertexblocks_offset; + pObject->object_parts[i].meshdef1_offset - 4))->vertexblocks_offset;
if (verbose == 1) printf("[DBG] > Vertex offset: 0x%X\n\n", pObject->object_parts[i].vertex_block_offset); if (pParams->verbose_mode) printf("[DBG] > Vertex offset: 0x%X\n\n", pObject->object_parts[i].vertex_block_offset);
// Get faces datas // Get faces datas
ExtractObjParts_faces(&pObject->object_parts[i], pMemfile, verbose); ExtractObjParts_faces(&pObject->object_parts[i], pMemfile, pParams);
} }
// Get object part ID, used by animation? bones? // Get object part ID, used by animation? bones?
pObject->object_parts[i].id = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->object_id; pObject->object_parts[i].id = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->object_id;
if (verbose == 1) printf("\n[DBG] > Facegroup/object ID: %d\n", pObject->object_parts[i].id); if (pParams->verbose_mode) printf("\n[DBG] > Facegroup/object ID: %d\n", pObject->object_parts[i].id);
// Get the transform matrix, used by at-st and at-at (at this time) // Get the transform matrix, used by at-st and at-at (at this time)
pObject->object_parts[i].transform.x = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_x; pObject->object_parts[i].transform.x = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_x;
pObject->object_parts[i].transform.y = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_y; pObject->object_parts[i].transform.y = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_y;
pObject->object_parts[i].transform.z = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_z; pObject->object_parts[i].transform.z = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_z;
if (verbose == 3) printf("\n[DBG] > Facegroup/object transform matrix: [%.8f %.8f %.8f]\n", if (pParams->god_mode) printf("\n[DBG] > Facegroup/object transform matrix: [%.8f %.8f %.8f]\n",
pObject->object_parts[i].transform.x, pObject->object_parts[i].transform.x,
pObject->object_parts[i].transform.y, pObject->object_parts[i].transform.y,
pObject->object_parts[i].transform.z pObject->object_parts[i].transform.z
); );
if (verbose == 2) printf("\n-----------------------End of Mesh part---------------------------\n"); if (pParams->debug_mode) printf("\n-----------------------End of Mesh part---------------------------\n");
} }
if (verbose == 2) printf("\n-=====================-End of Object part-========================-\n"); if (pParams->debug_mode) printf("\n-=====================-End of Object part-========================-\n");
return RSPLIB_SUCCESS; return RSPLIB_SUCCESS;
} }
@ -252,24 +251,24 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM
* *
* @return Error code, RSPLIB_SUCCESS when no error. * @return Error code, RSPLIB_SUCCESS when no error.
*/ */
static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const unsigned char verbose) { static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) {
unsigned int i, facesExtraOffset = 0; unsigned int i, facesExtraOffset = 0;
if (pObjPart == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; if (pObjPart == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
if( ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->reserved1 != 0 || if( ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->reserved1 != 0 ||
((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->reserved2 != 0 ) { ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->reserved2 != 0 ) {
if (verbose == 3) printf("[DBG] > Face block: uncommon zero header!\n"); if (pParams->god_mode) printf("[DBG] > Face block: uncommon zero header!\n");
} }
if ( ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->facesOffset != if ( ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->facesOffset !=
pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK)) { pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK)) {
if (verbose == 3) printf("[DBG] > Face block: uncommon face data offset position!\n"); if (pParams->god_mode) printf("[DBG] > Face block: uncommon face data offset position!\n");
} }
pObjPart->face_count = ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->faceCounts; pObjPart->face_count = ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->faceCounts;
pObjPart->faces = calloc(pObjPart->face_count, sizeof(T_RSPMODEL_FACE)); pObjPart->faces = calloc(pObjPart->face_count, sizeof(T_RSPMODEL_FACE));
for ( i = 0; i < pObjPart->face_count; i++ ) { for ( i = 0; i < pObjPart->face_count; i++ ) {
if (verbose == 2) printf("\n----------------------Begin of FaceGroup part----------------------\n"); if (pParams->debug_mode) printf("\n----------------------Begin of FaceGroup part----------------------\n");
// Get flags // Get flags
pObjPart->faces[i].flags = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset pObjPart->faces[i].flags = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset
@ -287,7 +286,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const
+ sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->faceBlockIntSize * 4; // Multiply by 4 to get the bytes exact number + sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->faceBlockIntSize * 4; // Multiply by 4 to get the bytes exact number
if (((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK) if (((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK)
+ sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->headerSeparator != 0) { + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->headerSeparator != 0) {
if (verbose == 3) printf("[DBG] > Face header: uncommon separator!\n"); if (pParams->god_mode) printf("[DBG] > Face header: uncommon separator!\n");
} }
// Get materials index // Get materials index
@ -316,7 +315,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const
+ facesExtraOffset); + facesExtraOffset);
} }
if (verbose == 2) { if (pParams->debug_mode) {
printf("[DBG] > Face %d details: flags:0x%X b1:%d b2:%d b3%d bsize:%d\n", i, pObjPart->faces[i].flags, printf("[DBG] > Face %d details: flags:0x%X b1:%d b2:%d b3%d bsize:%d\n", i, pObjPart->faces[i].flags,
pObjPart->faces[i].b1, pObjPart->faces[i].b2, pObjPart->faces[i].b3, pObjPart->faces[i].bsize); pObjPart->faces[i].b1, pObjPart->faces[i].b2, pObjPart->faces[i].b3, pObjPart->faces[i].bsize);
printf("[DBG] - Type is Quad: %d\n", pObjPart->faces[i].flags_bits.fIsQuad); printf("[DBG] - Type is Quad: %d\n", pObjPart->faces[i].flags_bits.fIsQuad);
@ -353,7 +352,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const
printf("\n"); printf("\n");
} }
if (verbose == 2) printf("\n-----------------------End of FaceGroup part-----------------------\n"); if (pParams->debug_mode) printf("\n-----------------------End of FaceGroup part-----------------------\n");
} }
// Get vertex datas // Get vertex datas
@ -373,7 +372,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const
pObjPart->vertices[i].w = pObjPart->vertices[i].w =
((T_HOBFILE_VERTEX *)(pMemfile + pObjPart->vertex_block_offset + sizeof(T_VERTEX) * i))->w; // Always 0??? ((T_HOBFILE_VERTEX *)(pMemfile + pObjPart->vertex_block_offset + sizeof(T_VERTEX) * i))->w; // Always 0???
if (verbose == 2) printf("[DBG] > Found vertex %d: (%d, %d, %d)\n", i, if (pParams->debug_mode) printf("[DBG] > Found vertex %d: (%d, %d, %d)\n", i,
pObjPart->vertices[i].x, pObjPart->vertices[i].y, pObjPart->vertices[i].z pObjPart->vertices[i].x, pObjPart->vertices[i].y, pObjPart->vertices[i].z
); );
} }

View File

@ -7,7 +7,6 @@
* *
*/ */
#include "options.h"
#include "RSPModel_datatypes.h" #include "RSPModel_datatypes.h"
@ -21,14 +20,14 @@
* @note Unmanaged mode * @note Unmanaged mode
* *
* @param[in] pMemFile Pointer to an in-memory HOB file location. * @param[in] pMemFile Pointer to an in-memory HOB file location.
* @param[out] hob_struct Allocated empty T_RSPMODEL_HOB structure instance to * @param[out] hobStruct Allocated empty T_RSPMODEL_HOB structure instance to
* be filled with HOB datas. * be filled with HOB datas.
* @param[in] p_opts Parser options. DEPRECATED. * @param[in] pParams Parser options. See RSPMODEL_PARAMETERS.
* *
* @return Processing error code, RSPLIB_SUCCESS if no error. * @return Processing error code, RSPLIB_SUCCESS if no error.
*/ */
unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile,
T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts); T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams);
/** /**
* @brief Process HOB file in file system. * @brief Process HOB file in file system.
@ -40,13 +39,13 @@ unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile,
* @note Managed mode * @note Managed mode
* *
* @param[in] fileName String value of file name/path. * @param[in] fileName String value of file name/path.
* @param[out] hob_struct Allocated empty T_RSPMODEL_HOB structure instance to * @param[out] hobStruct Allocated empty T_RSPMODEL_HOB structure instance to
* be filled with HOB datas. * be filled with HOB datas.
* @param[in] p_opts Parser options. DEPRECATED. * @param[in] pParams Parser options. See RSPMODEL_PARAMETERS.
* *
* @return Processing error code, RSPLIB_SUCCESS if no error. * @return Processing error code, RSPLIB_SUCCESS if no error.
*/ */
unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName,
T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts); T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams);
#endif /* SRC_HOB_PARSER_H_ */ #endif /* SRC_HOB_PARSER_H_ */

View File

@ -1,35 +0,0 @@
/**
* @file options.h
* @date 29/07/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Shared options structure definition and declaration.
*
*/
#ifndef OPTIONS_H_
#define OPTIONS_H_
#define RSPMODEL_DLLBUILD
/// Options structure
typedef union u_prog_options {
struct {
unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things.
unsigned char output_dir:1; //!< Export extracted datas to a sub-directory.
unsigned char export_mtl:1; //!< Export materials datas with object.
unsigned char reserved0:5; //!< For future use.
unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things.
unsigned char god_mode:1; //!< Dev only. Output experimental values.
unsigned char reserved1:6; //!< For future use.
unsigned short input_files_cnt; //!< Internal files counters.
};
unsigned int raw; //!< Raw options access for bit-masking or memory copy/compare.
} T_PROG_OPTIONS ;
#endif /* OPTIONS_H_ */