* Changed Vox_LoadFileName to Vox_LoadFromMemory
This commit is contained in:
parent
25984caa18
commit
c719eba3a0
25
src/external/vox_loader.h
vendored
25
src/external/vox_loader.h
vendored
|
|
@ -40,6 +40,7 @@ revision history:
|
|||
1.00 (2021-09-03) first released version
|
||||
1.01 (2021-09-07) Support custom memory allocators
|
||||
Removed Raylib dependencies
|
||||
Changed Vox_LoadFileName to Vox_LoadFromMemory
|
||||
|
||||
*/
|
||||
|
||||
|
|
@ -137,7 +138,7 @@ extern "C" {
|
|||
|
||||
|
||||
// Functions
|
||||
extern int Vox_LoadFileName(const char* pszfileName, VoxArray3D* voxarray);
|
||||
extern int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray);
|
||||
extern void Vox_FreeArrays(VoxArray3D* voxarray);
|
||||
|
||||
|
||||
|
|
@ -579,7 +580,7 @@ void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matID)
|
|||
}
|
||||
|
||||
// MagicaVoxel *.vox file format Loader
|
||||
int Vox_LoadFileName(const char* pszfileName, VoxArray3D* pvoxarray)
|
||||
int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray)
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
|
@ -589,25 +590,17 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* pvoxarray)
|
|||
|
||||
unsigned long signature;
|
||||
|
||||
unsigned int readed = 0;
|
||||
unsigned char* fileData;
|
||||
fileData = LoadFileData(pszfileName, &readed);
|
||||
if (fileData == 0)
|
||||
{
|
||||
return VOX_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
unsigned char* fileData = pvoxData;
|
||||
|
||||
unsigned char* fileDataPtr = fileData;
|
||||
unsigned char* endfileDataPtr = fileData + readed;
|
||||
unsigned char* endfileDataPtr = fileData + voxDataSize;
|
||||
|
||||
signature = *((unsigned long *)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
if (signature != 0x20584F56) //56 4F 58 20
|
||||
{
|
||||
UnloadFileData(fileData);
|
||||
//TraceLog(LOG_ERROR, "Not an MagicaVoxel File format");
|
||||
return VOX_ERROR_INVALID_FORMAT;
|
||||
return VOX_ERROR_INVALID_FORMAT; //"Not an MagicaVoxel File format"
|
||||
}
|
||||
|
||||
unsigned long version;
|
||||
|
|
@ -617,9 +610,7 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* pvoxarray)
|
|||
|
||||
if (version < 150)
|
||||
{
|
||||
UnloadFileData(fileData);
|
||||
//TraceLog(LOG_ERROR, "MagicaVoxel version too old");
|
||||
return VOX_ERROR_FILE_VERSION_TOO_OLD;
|
||||
return VOX_ERROR_FILE_VERSION_TOO_OLD; //"MagicaVoxel version too old"
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -744,8 +735,6 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* pvoxarray)
|
|||
}
|
||||
}
|
||||
|
||||
//Free file data
|
||||
UnloadFileData(fileData);
|
||||
|
||||
|
||||
return VOX_SUCCESS;
|
||||
|
|
|
|||
35
src/models.c
35
src/models.c
|
|
@ -74,9 +74,19 @@
|
|||
#endif
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||
// Allow custom memory allocators
|
||||
#ifndef VOX_MALLOC
|
||||
#define VOX_MALLOC RL_MALLOC
|
||||
#endif
|
||||
#ifndef VOX_CALLOC
|
||||
#define VOX_CALLOC RL_CALLOC
|
||||
#endif
|
||||
#ifndef VOX_REALLOC
|
||||
#define VOX_REALLOC RL_REALLOC
|
||||
#endif
|
||||
#ifndef VOX_FREE
|
||||
#define VOX_FREE RL_FREE
|
||||
#endif
|
||||
|
||||
#define VOX_LOADER_IMPLEMENTATION
|
||||
#include "external/vox_loader.h" // vox file format loading (MagikaVoxel)
|
||||
|
|
@ -145,9 +155,6 @@ static void *ReadGLTFValuesAs(cgltf_accessor *acc, cgltf_component_type type, bo
|
|||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||
static Model LoadVOX(const char *filename); // Load VOX mesh data
|
||||
#endif
|
||||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||
static Model LoadVOX(const char* filename); //Load VOX mesh data
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
|
|
@ -5525,24 +5532,38 @@ static void GetGLTFPrimitiveCount(cgltf_node *node, int *outCount)
|
|||
#endif
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||
// Load VOX (MagikaVoxel) mesh data
|
||||
// Load VOX (MagicaVoxel) mesh data
|
||||
static Model LoadVOX(const char *fileName)
|
||||
{
|
||||
Model model = { 0 };
|
||||
int nbvertices = 0;
|
||||
int meshescount = 0;
|
||||
unsigned int readed = 0;
|
||||
unsigned char* fileData;
|
||||
|
||||
//Read vox file into buffer
|
||||
fileData = LoadFileData(fileName, &readed);
|
||||
if (fileData == 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load VOX file", fileName);
|
||||
return model;
|
||||
}
|
||||
|
||||
//Read and build voxarray description
|
||||
VoxArray3D voxarray = { 0 };
|
||||
int ret = Vox_LoadFileName(fileName, &voxarray);
|
||||
int ret = Vox_LoadFromMemory(fileData, readed, &voxarray);
|
||||
|
||||
if (ret != VOX_SUCCESS)
|
||||
{
|
||||
// Error
|
||||
UnloadFileData(fileData);
|
||||
|
||||
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load VOX data", fileName);
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute meshes count
|
||||
// Success: Compute meshes count
|
||||
nbvertices = voxarray.vertices.used;
|
||||
meshescount = 1 + (nbvertices/65536);
|
||||
|
||||
|
|
@ -5607,7 +5628,9 @@ static Model LoadVOX(const char *fileName)
|
|||
pcolors += verticesMax;
|
||||
}
|
||||
|
||||
//Free buffers
|
||||
Vox_FreeArrays(&voxarray);
|
||||
UnloadFileData(fileData);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user