diff options
| author | procfxgen <[email protected]> | 2021-09-10 15:24:01 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-10 15:24:01 +0200 |
| commit | a422d2fc8b633ba14bba922f9a74c1be6a72ce39 (patch) | |
| tree | ed2297327f473280530fc37ab1dff86bcf62ac2b /src/models.c | |
| parent | 803094f41f887c43852a09870d8d0e05ee5f687f (diff) | |
| download | raylib-a422d2fc8b633ba14bba922f9a74c1be6a72ce39.tar.gz raylib-a422d2fc8b633ba14bba922f9a74c1be6a72ce39.zip | |
Vox loaded (#1981)
* new models_magicavoxel_loading example
* Portable header-only file "magicavoxel_loader.h" for MagicaVoxel loader example.
* models_magicavoxel_loading example added to CMakeLists.txt and Makefile
* fix models_magicavoxel_loading example for linux.
* * vox_loader into "src/external/vox_loader.h"
* vox file support for "models.c"
* updated example "models/models_magicavoxel_loading.c"
* * Fix Vox_FreeArrays (removed memory leak)
* * removed magicavoxel_loader.h
* * Revert vs2019 solution
* * vox_loader.h -> Support custom memory allocators
* vox_loader.h -> Reverse Y<>Z for left to right handed system
* models/models_magicavoxel_loading.c -> fix model center
* * vox_loader.h -> Removed Raylib dependencies
* * Changed Vox_LoadFileName to Vox_LoadFromMemory
Diffstat (limited to 'src/models.c')
| -rw-r--r-- | src/models.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/models.c b/src/models.c index ab3d0dd0..d645a4f6 100644 --- a/src/models.c +++ b/src/models.c @@ -74,7 +74,19 @@ #endif #if defined(SUPPORT_FILEFORMAT_VOX) - // TODO: Support custom memory allocators + // 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) @@ -5529,24 +5541,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); @@ -5611,7 +5637,9 @@ static Model LoadVOX(const char *fileName) pcolors += verticesMax; } + //Free buffers Vox_FreeArrays(&voxarray); + UnloadFileData(fileData); return model; } |
