REVIEWED: Vox loader
This commit is contained in:
parent
a422d2fc8b
commit
352ea80a1f
2 changed files with 127 additions and 167 deletions
151
src/external/vox_loader.h
vendored
151
src/external/vox_loader.h
vendored
|
@ -41,19 +41,28 @@ revision history:
|
||||||
1.01 (2021-09-07) Support custom memory allocators
|
1.01 (2021-09-07) Support custom memory allocators
|
||||||
Removed Raylib dependencies
|
Removed Raylib dependencies
|
||||||
Changed Vox_LoadFileName to Vox_LoadFromMemory
|
Changed Vox_LoadFileName to Vox_LoadFromMemory
|
||||||
|
1.02 (2021-09-10) @raysan5: Reviewed some formating
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef VOX_LOADER_H
|
#ifndef VOX_LOADER_H
|
||||||
#define VOX_LOADER_H
|
#define VOX_LOADER_H
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// Allow custom memory allocators
|
||||||
#ifdef __cplusplus
|
#ifndef VOX_MALLOC
|
||||||
extern "C" {
|
#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
|
#endif
|
||||||
|
|
||||||
#define VOX_SUCCESS (0)
|
#define VOX_SUCCESS (0)
|
||||||
|
@ -71,43 +80,35 @@ extern "C" {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
} VoxVector3;
|
} VoxVector3;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int* array;
|
int* array;
|
||||||
int used, size;
|
int used, size;
|
||||||
} ArrayInt;
|
} ArrayInt;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
VoxVector3* array;
|
VoxVector3* array;
|
||||||
int used, size;
|
int used, size;
|
||||||
} ArrayVector3;
|
} ArrayVector3;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
VoxColor* array;
|
VoxColor* array;
|
||||||
int used, size;
|
int used, size;
|
||||||
} ArrayColor;
|
} ArrayColor;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
unsigned short* array;
|
unsigned short* array;
|
||||||
int used, size;
|
int used, size;
|
||||||
} ArrayUShort;
|
} ArrayUShort;
|
||||||
|
|
||||||
|
|
||||||
// A chunk that contain voxels
|
// A chunk that contain voxels
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
unsigned char* m_array; //If Sparse != null
|
unsigned char* m_array; //If Sparse != null
|
||||||
int arraySize; //Size for m_array in bytes (DEBUG ONLY)
|
int arraySize; //Size for m_array in bytes (DEBUG ONLY)
|
||||||
} CubeChunk3D;
|
} CubeChunk3D;
|
||||||
|
|
||||||
// Array for voxels
|
// Array for voxels
|
||||||
// Array is divised into chunks of CHUNKSIZE*CHUNKSIZE*CHUNKSIZE voxels size
|
// Array is divised into chunks of CHUNKSIZE*CHUNKSIZE*CHUNKSIZE voxels size
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
// Array size in voxels
|
// Array size in voxels
|
||||||
int sizeX;
|
int sizeX;
|
||||||
int sizeY;
|
int sizeY;
|
||||||
|
@ -136,21 +137,20 @@ extern "C" {
|
||||||
|
|
||||||
} VoxArray3D;
|
} VoxArray3D;
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" { // Prevents name mangling of functions
|
||||||
|
#endif
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
extern int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray);
|
int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray);
|
||||||
extern void Vox_FreeArrays(VoxArray3D* voxarray);
|
void Vox_FreeArrays(VoxArray3D* voxarray);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//// end header file /////////////////////////////////////////////////////
|
|
||||||
#endif // VOX_LOADER_H
|
#endif // VOX_LOADER_H
|
||||||
|
//// end header file /////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -161,30 +161,29 @@ extern "C" {
|
||||||
|
|
||||||
#ifdef VOX_LOADER_IMPLEMENTATION
|
#ifdef VOX_LOADER_IMPLEMENTATION
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// ArrayInt helper
|
// ArrayInt helper
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void initArrayInt(ArrayInt* a, int initialSize)
|
static void initArrayInt(ArrayInt* a, int initialSize)
|
||||||
{
|
{
|
||||||
a->array = VOX_MALLOC(initialSize * sizeof(int));
|
a->array = VOX_MALLOC(initialSize * sizeof(int));
|
||||||
a->used = 0;
|
a->used = 0;
|
||||||
a->size = initialSize;
|
a->size = initialSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertArrayInt(ArrayInt* a, int element)
|
static void insertArrayInt(ArrayInt* a, int element)
|
||||||
{
|
{
|
||||||
if (a->used == a->size)
|
if (a->used == a->size)
|
||||||
{
|
{
|
||||||
a->size *= 2;
|
a->size *= 2;
|
||||||
a->array = VOX_REALLOC(a->array, a->size * sizeof(int));
|
a->array = VOX_REALLOC(a->array, a->size * sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
a->array[a->used++] = element;
|
a->array[a->used++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeArrayInt(ArrayInt* a)
|
static void freeArrayInt(ArrayInt* a)
|
||||||
{
|
{
|
||||||
VOX_FREE(a->array);
|
VOX_FREE(a->array);
|
||||||
a->array = NULL;
|
a->array = NULL;
|
||||||
|
@ -195,14 +194,14 @@ void freeArrayInt(ArrayInt* a)
|
||||||
// ArrayUShort helper
|
// ArrayUShort helper
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void initArrayUShort(ArrayUShort* a, int initialSize)
|
static void initArrayUShort(ArrayUShort* a, int initialSize)
|
||||||
{
|
{
|
||||||
a->array = VOX_MALLOC(initialSize * sizeof(unsigned short));
|
a->array = VOX_MALLOC(initialSize * sizeof(unsigned short));
|
||||||
a->used = 0;
|
a->used = 0;
|
||||||
a->size = initialSize;
|
a->size = initialSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertArrayUShort(ArrayUShort* a, unsigned short element)
|
static void insertArrayUShort(ArrayUShort* a, unsigned short element)
|
||||||
{
|
{
|
||||||
if (a->used == a->size)
|
if (a->used == a->size)
|
||||||
{
|
{
|
||||||
|
@ -212,7 +211,7 @@ void insertArrayUShort(ArrayUShort* a, unsigned short element)
|
||||||
a->array[a->used++] = element;
|
a->array[a->used++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeArrayUShort(ArrayUShort* a)
|
static void freeArrayUShort(ArrayUShort* a)
|
||||||
{
|
{
|
||||||
VOX_FREE(a->array);
|
VOX_FREE(a->array);
|
||||||
a->array = NULL;
|
a->array = NULL;
|
||||||
|
@ -224,14 +223,14 @@ void freeArrayUShort(ArrayUShort* a)
|
||||||
// ArrayVector3 helper
|
// ArrayVector3 helper
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void initArrayVector3(ArrayVector3* a, int initialSize)
|
static void initArrayVector3(ArrayVector3* a, int initialSize)
|
||||||
{
|
{
|
||||||
a->array = VOX_MALLOC(initialSize * sizeof(VoxVector3));
|
a->array = VOX_MALLOC(initialSize * sizeof(VoxVector3));
|
||||||
a->used = 0;
|
a->used = 0;
|
||||||
a->size = initialSize;
|
a->size = initialSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertArrayVector3(ArrayVector3* a, VoxVector3 element)
|
static void insertArrayVector3(ArrayVector3* a, VoxVector3 element)
|
||||||
{
|
{
|
||||||
if (a->used == a->size)
|
if (a->used == a->size)
|
||||||
{
|
{
|
||||||
|
@ -241,7 +240,7 @@ void insertArrayVector3(ArrayVector3* a, VoxVector3 element)
|
||||||
a->array[a->used++] = element;
|
a->array[a->used++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeArrayVector3(ArrayVector3* a)
|
static void freeArrayVector3(ArrayVector3* a)
|
||||||
{
|
{
|
||||||
VOX_FREE(a->array);
|
VOX_FREE(a->array);
|
||||||
a->array = NULL;
|
a->array = NULL;
|
||||||
|
@ -252,14 +251,14 @@ void freeArrayVector3(ArrayVector3* a)
|
||||||
// ArrayColor helper
|
// ArrayColor helper
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void initArrayColor(ArrayColor* a, int initialSize)
|
static void initArrayColor(ArrayColor* a, int initialSize)
|
||||||
{
|
{
|
||||||
a->array = VOX_MALLOC(initialSize * sizeof(VoxColor));
|
a->array = VOX_MALLOC(initialSize * sizeof(VoxColor));
|
||||||
a->used = 0;
|
a->used = 0;
|
||||||
a->size = initialSize;
|
a->size = initialSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertArrayColor(ArrayColor* a, VoxColor element)
|
static void insertArrayColor(ArrayColor* a, VoxColor element)
|
||||||
{
|
{
|
||||||
if (a->used == a->size)
|
if (a->used == a->size)
|
||||||
{
|
{
|
||||||
|
@ -269,7 +268,7 @@ void insertArrayColor(ArrayColor* a, VoxColor element)
|
||||||
a->array[a->used++] = element;
|
a->array[a->used++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeArrayColor(ArrayColor* a)
|
static void freeArrayColor(ArrayColor* a)
|
||||||
{
|
{
|
||||||
VOX_FREE(a->array);
|
VOX_FREE(a->array);
|
||||||
a->array = NULL;
|
a->array = NULL;
|
||||||
|
@ -311,8 +310,8 @@ const int fv[6][4] = {
|
||||||
{0, 4, 5, 1 }, //-y
|
{0, 4, 5, 1 }, //-y
|
||||||
{6, 2, 3, 7 }, //+y
|
{6, 2, 3, 7 }, //+y
|
||||||
{1, 3, 2, 0 }, //-Z
|
{1, 3, 2, 0 }, //-Z
|
||||||
{4, 6, 7, 5 } };//+Z
|
{4, 6, 7, 5 } //+Z
|
||||||
|
};
|
||||||
|
|
||||||
const VoxVector3 SolidVertex[] = {
|
const VoxVector3 SolidVertex[] = {
|
||||||
{0, 0, 0}, //0
|
{0, 0, 0}, //0
|
||||||
|
@ -322,14 +321,11 @@ const VoxVector3 SolidVertex[] = {
|
||||||
{0, 0, 1}, //4
|
{0, 0, 1}, //4
|
||||||
{1, 0, 1}, //5
|
{1, 0, 1}, //5
|
||||||
{0, 1, 1}, //6
|
{0, 1, 1}, //6
|
||||||
{1, 1, 1} }; //7
|
{1, 1, 1} //7
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Allocated VoxArray3D size
|
// Allocated VoxArray3D size
|
||||||
void Vox_AllocArray(VoxArray3D* pvoxarray, int _sx, int _sy, int _sz)
|
static void Vox_AllocArray(VoxArray3D* pvoxarray, int _sx, int _sy, int _sz)
|
||||||
{
|
{
|
||||||
int sx = _sx + ((CHUNKSIZE - (_sx % CHUNKSIZE)) % CHUNKSIZE);
|
int sx = _sx + ((CHUNKSIZE - (_sx % CHUNKSIZE)) % CHUNKSIZE);
|
||||||
int sy = _sy + ((CHUNKSIZE - (_sy % CHUNKSIZE)) % CHUNKSIZE);
|
int sy = _sy + ((CHUNKSIZE - (_sy % CHUNKSIZE)) % CHUNKSIZE);
|
||||||
|
@ -355,7 +351,6 @@ void Vox_AllocArray(VoxArray3D* pvoxarray, int _sx, int _sy, int _sz)
|
||||||
pvoxarray->m_arrayChunks = VOX_MALLOC(size);
|
pvoxarray->m_arrayChunks = VOX_MALLOC(size);
|
||||||
pvoxarray->arrayChunksSize = size;
|
pvoxarray->arrayChunksSize = size;
|
||||||
|
|
||||||
|
|
||||||
// Init chunks array
|
// Init chunks array
|
||||||
size = chx * chy * chz;
|
size = chx * chy * chz;
|
||||||
pvoxarray->chunksTotal = size;
|
pvoxarray->chunksTotal = size;
|
||||||
|
@ -369,7 +364,7 @@ void Vox_AllocArray(VoxArray3D* pvoxarray, int _sx, int _sy, int _sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set voxel ID from its position into VoxArray3D
|
// Set voxel ID from its position into VoxArray3D
|
||||||
void Vox_SetVoxel(VoxArray3D* pvoxarray, int x, int y, int z, unsigned char id)
|
static void Vox_SetVoxel(VoxArray3D* pvoxarray, int x, int y, int z, unsigned char id)
|
||||||
{
|
{
|
||||||
// Get chunk from array pos
|
// Get chunk from array pos
|
||||||
int chX = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
|
int chX = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
|
||||||
|
@ -407,18 +402,14 @@ void Vox_SetVoxel(VoxArray3D* pvoxarray, int x, int y, int z, unsigned char id)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
chunk->m_array[offset] = id;
|
chunk->m_array[offset] = id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get voxel ID from its position into VoxArray3D
|
// Get voxel ID from its position into VoxArray3D
|
||||||
unsigned char Vox_GetVoxel(VoxArray3D* pvoxarray, int x, int y, int z)
|
static unsigned char Vox_GetVoxel(VoxArray3D* pvoxarray, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if (x < 0 || y < 0 || z < 0)
|
if (x < 0 || y < 0 || z < 0) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (x >= pvoxarray->sizeX || y >= pvoxarray->sizeY || z >= pvoxarray->sizeZ)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
if (x >= pvoxarray->sizeX || y >= pvoxarray->sizeY || z >= pvoxarray->sizeZ) return 0;
|
||||||
|
|
||||||
// Get chunk from array pos
|
// Get chunk from array pos
|
||||||
int chX = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
|
int chX = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
|
||||||
|
@ -454,7 +445,7 @@ unsigned char Vox_GetVoxel(VoxArray3D* pvoxarray, int x, int y, int z)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calc visibles faces from a voxel position
|
// Calc visibles faces from a voxel position
|
||||||
unsigned char Vox_CalcFacesVisible(VoxArray3D* pvoxArray, int cx, int cy, int cz)
|
static unsigned char Vox_CalcFacesVisible(VoxArray3D* pvoxArray, int cx, int cy, int cz)
|
||||||
{
|
{
|
||||||
unsigned char idXm1 = Vox_GetVoxel(pvoxArray, cx - 1, cy, cz);
|
unsigned char idXm1 = Vox_GetVoxel(pvoxArray, cx - 1, cy, cz);
|
||||||
unsigned char idXp1 = Vox_GetVoxel(pvoxArray, cx + 1, cy, cz);
|
unsigned char idXp1 = Vox_GetVoxel(pvoxArray, cx + 1, cy, cz);
|
||||||
|
@ -468,51 +459,45 @@ unsigned char Vox_CalcFacesVisible(VoxArray3D* pvoxArray, int cx, int cy, int cz
|
||||||
unsigned char byVFMask = 0;
|
unsigned char byVFMask = 0;
|
||||||
|
|
||||||
//#-x
|
//#-x
|
||||||
if (idXm1 == 0)
|
if (idXm1 == 0) byVFMask |= (1 << 0);
|
||||||
byVFMask |= (1 << 0);
|
|
||||||
|
|
||||||
//#+x
|
//#+x
|
||||||
if (idXp1 == 0)
|
if (idXp1 == 0) byVFMask |= (1 << 1);
|
||||||
byVFMask |= (1 << 1);
|
|
||||||
|
|
||||||
//#-y
|
//#-y
|
||||||
if (idYm1 == 0)
|
if (idYm1 == 0) byVFMask |= (1 << 2);
|
||||||
byVFMask |= (1 << 2);
|
|
||||||
|
|
||||||
//#+y
|
//#+y
|
||||||
if (idYp1 == 0)
|
if (idYp1 == 0) byVFMask |= (1 << 3);
|
||||||
byVFMask |= (1 << 3);
|
|
||||||
|
|
||||||
//#-z
|
//#-z
|
||||||
if (idZm1 == 0)
|
if (idZm1 == 0) byVFMask |= (1 << 4);
|
||||||
byVFMask |= (1 << 4);
|
|
||||||
|
|
||||||
//#+z
|
//#+z
|
||||||
if (idZp1 == 0)
|
if (idZp1 == 0) byVFMask |= (1 << 5);
|
||||||
byVFMask |= (1 << 5);
|
|
||||||
|
|
||||||
return byVFMask;
|
return byVFMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a vertex position from a voxel's corner
|
// Get a vertex position from a voxel's corner
|
||||||
VoxVector3 Vox_GetVertexPosition(int _wcx, int _wcy, int _wcz, int _nNumVertex)
|
static VoxVector3 Vox_GetVertexPosition(int _wcx, int _wcy, int _wcz, int _nNumVertex)
|
||||||
{
|
{
|
||||||
float scale = 0.25;
|
float scale = 0.25;
|
||||||
|
|
||||||
VoxVector3 vtx = SolidVertex[_nNumVertex];
|
VoxVector3 vtx = SolidVertex[_nNumVertex];
|
||||||
vtx.x = (vtx.x + _wcx) * scale;
|
vtx.x = (vtx.x + _wcx) * scale;
|
||||||
vtx.y = (vtx.y + _wcy) * scale;
|
vtx.y = (vtx.y + _wcy) * scale;
|
||||||
vtx.z = (vtx.z + _wcz) * scale;
|
vtx.z = (vtx.z + _wcz) * scale;
|
||||||
|
|
||||||
return vtx;
|
return vtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a voxel vertices/colors/indices
|
// Build a voxel vertices/colors/indices
|
||||||
void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matID)
|
static void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matID)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned char byVFMask = Vox_CalcFacesVisible(pvoxArray, x, y, z);
|
unsigned char byVFMask = Vox_CalcFacesVisible(pvoxArray, x, y, z);
|
||||||
|
|
||||||
if (byVFMask == 0)
|
if (byVFMask == 0) return;
|
||||||
return;
|
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
VoxVector3 vertComputed[8];
|
VoxVector3 vertComputed[8];
|
||||||
|
@ -520,7 +505,6 @@ void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matID)
|
||||||
memset(vertComputed, 0, sizeof(vertComputed));
|
memset(vertComputed, 0, sizeof(vertComputed));
|
||||||
memset(bVertexComputed, 0, sizeof(bVertexComputed));
|
memset(bVertexComputed, 0, sizeof(bVertexComputed));
|
||||||
|
|
||||||
|
|
||||||
//For each Cube's faces
|
//For each Cube's faces
|
||||||
for (i = 0; i < 6; i++) // 6 faces
|
for (i = 0; i < 6; i++) // 6 faces
|
||||||
{
|
{
|
||||||
|
@ -572,17 +556,12 @@ void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matID)
|
||||||
insertArrayUShort(&pvoxArray->indices, idx + 0);
|
insertArrayUShort(&pvoxArray->indices, idx + 0);
|
||||||
insertArrayUShort(&pvoxArray->indices, idx + 3);
|
insertArrayUShort(&pvoxArray->indices, idx + 3);
|
||||||
insertArrayUShort(&pvoxArray->indices, idx + 2);
|
insertArrayUShort(&pvoxArray->indices, idx + 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MagicaVoxel *.vox file format Loader
|
// MagicaVoxel *.vox file format Loader
|
||||||
int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray)
|
int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray)
|
||||||
{
|
{
|
||||||
|
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
//Read VOX file
|
//Read VOX file
|
||||||
//4 bytes: magic number ('V' 'O' 'X' 'space' )
|
//4 bytes: magic number ('V' 'O' 'X' 'space' )
|
||||||
|
@ -702,18 +681,10 @@ int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TraceLog(LOG_INFO, TextFormat("Vox Size : %dx%dx%d", sizeX, sizeY, sizeZ));
|
|
||||||
|
|
||||||
//TraceLog(LOG_INFO, TextFormat("Vox Chunks Count : %d/%d", pvoxArray->chunksAllocated, pvoxArray->chunksTotal));
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
// Building Mesh
|
// Building Mesh
|
||||||
// TODO compute globals indices array
|
// TODO compute globals indices array
|
||||||
|
|
||||||
//TraceLog(LOG_INFO, TextFormat("Building VOX Mesh : %s", pszfileName));
|
|
||||||
|
|
||||||
// Init Arrays
|
// Init Arrays
|
||||||
initArrayVector3(&pvoxarray->vertices, 3 * 1024);
|
initArrayVector3(&pvoxarray->vertices, 3 * 1024);
|
||||||
initArrayUShort(&pvoxarray->indices, 3 * 1024);
|
initArrayUShort(&pvoxarray->indices, 3 * 1024);
|
||||||
|
@ -735,8 +706,6 @@ int Vox_LoadFromMemory(const unsigned char* pvoxData, unsigned int voxDataSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return VOX_SUCCESS;
|
return VOX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,19 +74,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||||
// Allow custom memory allocators
|
|
||||||
#ifndef VOX_MALLOC
|
|
||||||
#define VOX_MALLOC RL_MALLOC
|
#define VOX_MALLOC RL_MALLOC
|
||||||
#endif
|
|
||||||
#ifndef VOX_CALLOC
|
|
||||||
#define VOX_CALLOC RL_CALLOC
|
#define VOX_CALLOC RL_CALLOC
|
||||||
#endif
|
|
||||||
#ifndef VOX_REALLOC
|
|
||||||
#define VOX_REALLOC RL_REALLOC
|
#define VOX_REALLOC RL_REALLOC
|
||||||
#endif
|
|
||||||
#ifndef VOX_FREE
|
|
||||||
#define VOX_FREE RL_FREE
|
#define VOX_FREE RL_FREE
|
||||||
#endif
|
|
||||||
|
|
||||||
#define VOX_LOADER_IMPLEMENTATION
|
#define VOX_LOADER_IMPLEMENTATION
|
||||||
#include "external/vox_loader.h" // vox file format loading (MagikaVoxel)
|
#include "external/vox_loader.h" // vox file format loading (MagikaVoxel)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue