/** * @file RSPTerrain.c * @date 22/08/2022 * @author JackCarterSmith * @copyright GPL-v3.0 * @brief HMP terrain datas parser and export to Waveform OBJ format and greyscale PNG heightmap. * */ #if defined(RSPTERRAIN_DLL) #define RSPTERRAIN_DLLBUILD #endif #include #include #include #include "config.h" #include "RSPTerrain_errordefs.h" #include "RSPTerrain_datatypes.h" #include "hmp_parser.h" #include "data_builders.h" #include "RSPTerrain.h" inline char* RSPTerrain_getVersion( void ) { return PRG_VERSION; } unsigned short RSPTerrain_processHMPFile( T_RSPTERRAIN_HMP* hmpStruct, const char* const filePath, const RSPTERRAIN_PARAMETERS params ) { if ( hmpStruct == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL; return RSP_TerrainLib_ParseHMPFile(filePath, hmpStruct, ¶ms); } unsigned short RSPTerrain_processHMPFileMemory( T_RSPTERRAIN_HMP* hmpStruct, const void* const memFilePtr, const long memFileSize, const RSPTERRAIN_PARAMETERS params ) { if ( hmpStruct == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL; return RSP_TerrainLib_ParseHMPMemFile((MEMFILE)memFilePtr, hmpStruct, ¶ms); } unsigned short RSPTerrain_terrainToHeightmap( T_RSPTERRAIN_HEIGHTMAP* heightmap, const T_RSPTERRAIN_HMP* hmpStruct ) { if ( hmpStruct == NULL ) return RSPLIB_ERROR_ARGS_NULL; return RSP_TerrainLib_ConstructHeightmap(heightmap, hmpStruct); } unsigned short RSPTerrain_terrainToMesh( T_RSPTERRAIN_MESH* mesh, const T_RSPTERRAIN_HMP* hmpStruct, const float scale ) { if ( hmpStruct == NULL ) return RSPLIB_ERROR_ARGS_NULL; return RSP_TerrainLib_ConstructMesh(mesh, hmpStruct, scale); } unsigned short RSPTerrain_terrainToGL( void* glTerrainObj, const T_RSPTERRAIN_HMP* hmpStruct ) { #ifndef GL_SUPPORT return RSPLIB_ERROR_MOD_DISABLED; #endif return RSPLIB_SUCCESS; } unsigned short RSPTerrain_terrainToD3D( void* D3DTerrainObj, const T_RSPTERRAIN_HMP* hmpStruct ) { #ifndef D3D_SUPPORT return RSPLIB_ERROR_MOD_DISABLED; #endif return RSPLIB_SUCCESS; } void RSPTerrain_freeHMP(T_RSPTERRAIN_HMP* hmpStruct) { if (hmpStruct == NULL) return; if (hmpStruct->tilesmap) free(hmpStruct->tilesmap); free(hmpStruct); } void RSPTerrain_freeHeightmap(T_RSPTERRAIN_HEIGHTMAP* heightmap) { unsigned int i; if (heightmap == NULL) return; for ( i = 0; i < heightmap->width * RSPTERRAINLIB_TILE_SAMPLING; i++ ) if (heightmap->heightmap[i]) free(heightmap->heightmap[i]); free(heightmap); } void RSPTerrain_freeMesh(T_RSPTERRAIN_MESH* mesh) { if (mesh == NULL) return; if (mesh->verticesmap) free(mesh->verticesmap); free(mesh); }