diff --git a/RSPTextureLib/include/RSPTexture.h b/RSPTextureLib/include/RSPTexture.h index 9bc50a7..d5150bc 100644 --- a/RSPTextureLib/include/RSPTexture.h +++ b/RSPTextureLib/include/RSPTexture.h @@ -54,6 +54,8 @@ extern "C" { */ 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. * @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 ); +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. * @param[in] hmtStruct Pointer to data to be cleaned up. diff --git a/RSPTextureLib/include/RSPTexture_datatypes.h b/RSPTextureLib/include/RSPTexture_datatypes.h index daf9da3..2477a4e 100644 --- a/RSPTextureLib/include/RSPTexture_datatypes.h +++ b/RSPTextureLib/include/RSPTexture_datatypes.h @@ -69,6 +69,9 @@ typedef struct rsptexture_material { unsigned char name[17]; // 16 + 1 string ending \0 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_MATERIAL; diff --git a/RSPTextureLib/src/RSPTexture.c b/RSPTextureLib/src/RSPTexture.c index 2eea7d1..32f7b01 100644 --- a/RSPTextureLib/src/RSPTexture.c +++ b/RSPTextureLib/src/RSPTexture.c @@ -17,10 +17,20 @@ #include "RSPTexture.h" +/* + * Libs interface + */ inline char* RSPTexture_getVersion( void ) { 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, const RSPTEXTURE_PARAMETERS params ) { @@ -37,6 +47,9 @@ unsigned short RSPTexture_processHMTFileMemory( T_RSPTEXTURE_HMT* hmtStruct, con return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, ¶ms); } +/* + * Material utilities + */ T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHmt, const unsigned short mat_id, const RSPTEX_MAT_TYPE mat_type ) { unsigned int i; @@ -62,6 +75,24 @@ T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHm 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 ) { unsigned int i; diff --git a/RSPTextureLib/src/hmt_parser.c b/RSPTextureLib/src/hmt_parser.c index 28b84b8..5dcdcb7 100644 --- a/RSPTextureLib/src/hmt_parser.c +++ b/RSPTextureLib/src/hmt_parser.c @@ -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; pHmt->materials[i].id = ((T_HMTFILE_MATERIAL *)(pMemfile + 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 (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED) pHmt->materials[i].texture = pHmt->textures + pHmt->materials[i].id; 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) { 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) */ if (pParams->debug_mode) { - printf("[DBG] > Material reserved0: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile + - sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0); // Diffuse? / Transparent? - printf("[DBG] > Material reserved1: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile + - sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1); // Ambient? + printf("[DBG] > Material reserved0: %.8f\n", pHmt->materials[i].ambient); + printf("[DBG] > Material reserved1: %.8f\n", pHmt->materials[i].opacity); 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 + sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved3); } diff --git a/RSPTextureLib/src/hmt_struct.h b/RSPTextureLib/src/hmt_struct.h index 2a4cf18..3fb0b20 100644 --- a/RSPTextureLib/src/hmt_struct.h +++ b/RSPTextureLib/src/hmt_struct.h @@ -46,10 +46,10 @@ typedef struct PACK hmtfile_material { unsigned short type; // 1 - Material with texture / 2 - Material without texture unsigned short texture_index; - float reserved0; // misc. - float reserved1; // Always 1.0f + float reserved0; // misc. Diffuse? Transparent? + float reserved1; // Always 1.0f Ambient? - unsigned int reserved2; // Zero + unsigned int reserved2; // Zero Specular? unsigned int reserved3; // 0x0A unsigned char name[16];