JackCarterSmith a6ba8fe15a
All checks were successful
JCS-Prod/RSE-Model/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Model/pipeline/head This commit looks good
Fix HOB deallocation
Removed logging in library by default
2023-01-22 01:00:44 +01:00

112 lines
2.8 KiB
C

/**
* @file RSPModel.c
* @date 18/01/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief HOB model parser and export to Waveform OBJ format.
*
*/
#if defined(RSPMODEL_DLL)
#define RSPMODEL_DLLBUILD
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "RSPModel_errordefs.h"
#include "RSPModel_datatypes.h"
#include "hob_parser.h"
#include "RSPModel.h"
inline char* RSPModel_getVersion( void ) {
return PRG_VERSION;
}
unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath,
const RSPMODEL_PARAMETERS params ) {
unsigned short result = RSPLIB_SUCCESS;
MEMFILE pMemFile = NULL;
if ( hob == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL;
RSP_ModelLib_LoadHOBFile(&pMemFile, filePath, &params);
result = RSP_ModelLib_ProcessHOBMemFile(hob, pMemFile, &params);
RSP_ModelLib_FreeHOBFile(&pMemFile);
return result;
}
unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr,
const long memFileSize, const RSPMODEL_PARAMETERS params ) {
unsigned short result = RSPLIB_SUCCESS;
if ( hob == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL;
result = RSP_ModelLib_ProcessHOBMemFile(hob, (MEMFILE)memFilePtr, &params);
return result;
}
void RSPModel_freeHOB( T_RSPMODEL_HOB* hobStruct ) {
int i,j;
if (hobStruct == NULL) return;
if (hobStruct->objects) {
for ( i=0; i<hobStruct->obj_count; i++ ) {
if (hobStruct->objects[i].object_parts) {
for ( j=0; j<hobStruct->objects[i].object_part_count; j++ ) {
if (hobStruct->objects[i].object_parts[j].faces)
free(hobStruct->objects[i].object_parts[j].faces);
if (hobStruct->objects[i].object_parts[j].vertices)
free(hobStruct->objects[i].object_parts[j].vertices);
}
free(hobStruct->objects[i].object_parts);
}
}
free(hobStruct->objects);
}
}
/* ------------------------------------------------------------------------- */
unsigned int RSPModel_getHOBFileObjCount( const char* const filePath ) {
unsigned int result = 0;
MEMFILE pMemFile = NULL;
if (filePath != NULL) {
RSP_ModelLib_LoadHOBFile(&pMemFile, filePath, 0);
result = RSP_ModelLib_getObjectsCount(pMemFile);
RSP_ModelLib_FreeHOBFile(&pMemFile);
}
return result;
}
unsigned int RSPModel_getHOBFileMemObjCount( const void* const memFilePtr ) {
return RSP_ModelLib_getObjectsCount((MEMFILE)memFilePtr);
}
/* ------------------------------------------------------------------------- */
unsigned short RSPModel_objectToGL( const T_RSPMODEL_OBJECT* objStruct, void* glObj ) {
#ifndef GL_SUPPORT
return RSPLIB_ERROR_MOD_DISABLED;
#endif
return RSPLIB_SUCCESS;
}
unsigned short RSPModel_objectToD3D( const T_RSPMODEL_OBJECT* objStruct, void* D3DObj ) {
#ifndef D3D_SUPPORT
return RSPLIB_ERROR_MOD_DISABLED;
#endif
return RSPLIB_SUCCESS;
}