Linked datas to export

This commit is contained in:
JackCarterSmith 2022-09-01 18:52:42 +02:00
parent 6fa5719957
commit 3ffc546e1e
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
5 changed files with 52 additions and 9 deletions

View File

@ -54,6 +54,8 @@ extern "C" {
*/ */
RSPTEXTURE_EXTERN char* RSPTexture_getVersion( void ); RSPTEXTURE_EXTERN char* RSPTexture_getVersion( void );
RSPTEXTURE_EXTERN T_RSPTEXTURE_HMT* RSPTexture_createHMT( void );
/** /**
* @brief Run texture parser for the specified file in file system. * @brief Run texture parser for the specified file in file system.
* @details Texture library can process HMT file from file system. It's a easy * @details Texture library can process HMT file from file system. It's a easy
@ -104,6 +106,12 @@ RSPTEXTURE_EXTERN T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID(
const RSPTEX_MAT_TYPE mat_type const RSPTEX_MAT_TYPE mat_type
); );
RSPTEXTURE_EXTERN char* RSPTexture_getMaterialName( const T_RSPTEXTURE_MATERIAL* mat );
RSPTEXTURE_EXTERN float RSPTexture_getMaterialOpacity( const T_RSPTEXTURE_MATERIAL* mat );
RSPTEXTURE_EXTERN float RSPTexture_getMaterialAmbient( const T_RSPTEXTURE_MATERIAL* mat );
/** /**
* @brief Clean HMT object and it's childrens from memory. * @brief Clean HMT object and it's childrens from memory.
* @param[in] hmtStruct Pointer to data to be cleaned up. * @param[in] hmtStruct Pointer to data to be cleaned up.

View File

@ -69,6 +69,9 @@ typedef struct rsptexture_material {
unsigned char name[17]; // 16 + 1 string ending \0 unsigned char name[17]; // 16 + 1 string ending \0
RSPTEX_MAT_TYPE type; RSPTEX_MAT_TYPE type;
float opacity; //TODO: temporary, need to be defined
float ambient; //TODO: temporary, need to be defined
T_RSPTEXTURE_TEXTURE* texture; T_RSPTEXTURE_TEXTURE* texture;
} T_RSPTEXTURE_MATERIAL; } T_RSPTEXTURE_MATERIAL;

View File

@ -17,10 +17,20 @@
#include "RSPTexture.h" #include "RSPTexture.h"
/*
* Libs interface
*/
inline char* RSPTexture_getVersion( void ) { inline char* RSPTexture_getVersion( void ) {
return PRG_VERSION; return PRG_VERSION;
} }
/*
* HMT parser
*/
T_RSPTEXTURE_HMT* RSPTexture_createHMT( void ) {
return calloc(1, sizeof(T_RSPTEXTURE_HMT));
}
unsigned short RSPTexture_processHMTFile( T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath, unsigned short RSPTexture_processHMTFile( T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath,
const RSPTEXTURE_PARAMETERS params ) { const RSPTEXTURE_PARAMETERS params ) {
@ -37,6 +47,9 @@ unsigned short RSPTexture_processHMTFileMemory( T_RSPTEXTURE_HMT* hmtStruct, con
return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, &params); return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, &params);
} }
/*
* Material utilities
*/
T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHmt, T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHmt,
const unsigned short mat_id, const RSPTEX_MAT_TYPE mat_type ) { const unsigned short mat_id, const RSPTEX_MAT_TYPE mat_type ) {
unsigned int i; unsigned int i;
@ -62,6 +75,24 @@ T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHm
return NULL; return NULL;
} }
char* RSPTexture_getMaterialName( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return NULL;
return (char*)mat->name;
}
float RSPTexture_getMaterialOpacity( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return 1.0;
return mat->opacity;
}
float RSPTexture_getMaterialAmbient( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return 1.0;
return mat->ambient;
}
void RSPTexture_freeHMT( T_RSPTEXTURE_HMT* hmtStruct ) { void RSPTexture_freeHMT( T_RSPTEXTURE_HMT* hmtStruct ) {
unsigned int i; unsigned int i;

View File

@ -159,10 +159,13 @@ static unsigned short ExtractMaterials(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMe
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->type; sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->type;
pHmt->materials[i].id = ((T_HMTFILE_MATERIAL *)(pMemfile + pHmt->materials[i].id = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->texture_index; sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->texture_index;
// If material is textured, the linked texture correspond to tex_index in textures array. // If material is textured, the linked texture correspond to tex_index in textures array.
if (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED) pHmt->materials[i].texture = pHmt->textures + pHmt->materials[i].id; if (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED) pHmt->materials[i].texture = pHmt->textures + pHmt->materials[i].id;
else pHmt->materials[i].texture = NULL; else pHmt->materials[i].texture = NULL;
pHmt->materials[i].opacity = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1;
pHmt->materials[i].ambient = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0;
if (pParams->verbose_mode) { if (pParams->verbose_mode) {
printf("[INFO] > Material name: %s\n", pHmt->materials[i].name); printf("[INFO] > Material name: %s\n", pHmt->materials[i].name);
@ -180,12 +183,10 @@ static unsigned short ExtractMaterials(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMe
* - Specular (self) * - Specular (self)
*/ */
if (pParams->debug_mode) { if (pParams->debug_mode) {
printf("[DBG] > Material reserved0: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile + printf("[DBG] > Material reserved0: %.8f\n", pHmt->materials[i].ambient);
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0); // Diffuse? / Transparent? printf("[DBG] > Material reserved1: %.8f\n", pHmt->materials[i].opacity);
printf("[DBG] > Material reserved1: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1); // Ambient?
printf("[DBG] > Material reserved2 (zero): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile + printf("[DBG] > Material reserved2 (zero): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved2); // Specular? sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved2);
printf("[DBG] > Material reserved3 (0xA): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile + printf("[DBG] > Material reserved3 (0xA): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved3); sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved3);
} }

View File

@ -46,10 +46,10 @@ typedef struct PACK hmtfile_material {
unsigned short type; // 1 - Material with texture / 2 - Material without texture unsigned short type; // 1 - Material with texture / 2 - Material without texture
unsigned short texture_index; unsigned short texture_index;
float reserved0; // misc. float reserved0; // misc. Diffuse? Transparent?
float reserved1; // Always 1.0f float reserved1; // Always 1.0f Ambient?
unsigned int reserved2; // Zero unsigned int reserved2; // Zero Specular?
unsigned int reserved3; // 0x0A unsigned int reserved3; // 0x0A
unsigned char name[16]; unsigned char name[16];