REVIEWED: Vox loading, mostly formating
This commit is contained in:
parent
dfc465ca6d
commit
4120f12375
2 changed files with 31 additions and 40 deletions
5
src/external/vox_loader.h
vendored
5
src/external/vox_loader.h
vendored
|
@ -352,8 +352,6 @@ void Vox_AllocArray(VoxArray3D* voxarray, int _sx, int _sy, int _sz)
|
|||
voxarray->m_arrayChunks[i].m_array = 0;
|
||||
voxarray->m_arrayChunks[i].arraySize = 0;
|
||||
}
|
||||
|
||||
return voxarray;
|
||||
}
|
||||
|
||||
// Set voxel ID from its position into VoxArray3D
|
||||
|
@ -578,7 +576,7 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* voxarray)
|
|||
|
||||
unsigned long signature;
|
||||
|
||||
unsigned long readed = 0;
|
||||
unsigned int readed = 0;
|
||||
unsigned char* fileData;
|
||||
fileData = LoadFileData(pszfileName, &readed);
|
||||
if (fileData == 0)
|
||||
|
@ -640,7 +638,6 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* voxarray)
|
|||
unsigned long chunkTotalChildSize = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
|
||||
if (strcmp(szChunkName, "SIZE") == 0)
|
||||
{
|
||||
//(4 bytes x 3 : x, y, z )
|
||||
|
|
36
src/models.c
36
src/models.c
|
@ -74,8 +74,10 @@
|
|||
#endif
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||
// TODO: Support custom memory allocators
|
||||
|
||||
#define VOX_LOADER_IMPLEMENTATION
|
||||
#include "external/vox_loader.h" // vox file format loading
|
||||
#include "external/vox_loader.h" // vox file format loading (MagikaVoxel)
|
||||
#endif
|
||||
|
||||
#if defined(SUPPORT_MESH_GENERATION)
|
||||
|
@ -3562,7 +3564,7 @@ static Model LoadOBJ(const char *fileName)
|
|||
|
||||
for (int fi = 0; fi< attrib.num_faces; fi++)
|
||||
{
|
||||
tinyobj_vertex_index_t face = attrib.faces[fi];
|
||||
//tinyobj_vertex_index_t face = attrib.faces[fi];
|
||||
int idx = attrib.material_ids[fi];
|
||||
matFaces[idx]++;
|
||||
}
|
||||
|
@ -5484,17 +5486,14 @@ static void GetGLTFPrimitiveCount(cgltf_node *node, int *outCount)
|
|||
#endif
|
||||
|
||||
#if defined(SUPPORT_FILEFORMAT_VOX)
|
||||
// Load OBJ mesh data
|
||||
// Load VOX (MagikaVoxel) mesh data
|
||||
static Model LoadVOX(const char *fileName)
|
||||
{
|
||||
Model model = { 0 };
|
||||
int nbvertices = 0;
|
||||
int meshescount = 0;
|
||||
|
||||
//////////////////////////////////
|
||||
// Load MagicaVoxel fileformat
|
||||
|
||||
VoxArray3D voxarray;
|
||||
VoxArray3D voxarray = { 0 };
|
||||
int ret = Vox_LoadFileName(fileName, &voxarray);
|
||||
|
||||
if (ret != VOX_SUCCESS)
|
||||
|
@ -5511,10 +5510,7 @@ static Model LoadVOX(const char* fileName)
|
|||
TRACELOG(LOG_INFO, "MODEL: [%s] VOX data loaded successfully : %i vertices/%i meshes", fileName, nbvertices, meshescount);
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// Build model
|
||||
|
||||
// Build Models from meshes
|
||||
// Build models from meshes
|
||||
model.transform = MatrixIdentity();
|
||||
|
||||
model.meshCount = meshescount;
|
||||
|
@ -5526,37 +5522,37 @@ static Model LoadVOX(const char* fileName)
|
|||
model.materials = (Material *)MemAlloc(model.materialCount*sizeof(Material));
|
||||
model.materials[0] = LoadMaterialDefault();
|
||||
|
||||
|
||||
// Init model's meshes
|
||||
// Init model meshes
|
||||
int verticesRemain = voxarray.vertices.used;
|
||||
int verticesMax = 65532; // 5461 voxels x 12 vertices per voxel -> 65532 (must be inf 65536)
|
||||
|
||||
Vector3 *pvertices = voxarray.vertices.array; // 6*4 = 12 vertices per voxel
|
||||
Color *pcolors = voxarray.colors.array;
|
||||
unsigned short* pindices = voxarray.indices.array; //5461 * 6 * 6 -> 196596 indices max per mesh
|
||||
unsigned short *pindices = voxarray.indices.array; // 5461*6*6 = 196596 indices max per mesh
|
||||
|
||||
int size;
|
||||
int size = 0;
|
||||
|
||||
for (int idxMesh = 0; idxMesh < meshescount; idxMesh++)
|
||||
{
|
||||
Mesh *pmesh = &model.meshes[idxMesh];
|
||||
memset(pmesh, 0, sizeof(Mesh));
|
||||
|
||||
// Copy Vertices
|
||||
// Copy vertices
|
||||
pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain);
|
||||
|
||||
size = pmesh->vertexCount*sizeof(float)*3;
|
||||
pmesh->vertices = MemAlloc(size);
|
||||
memcpy(pmesh->vertices, pvertices, size);
|
||||
|
||||
//Copy Indices TODO compute globals indices array
|
||||
// Copy indices
|
||||
// TODO: compute globals indices array
|
||||
size = voxarray.indices.used * sizeof(unsigned short);
|
||||
pmesh->indices = MemAlloc(size);
|
||||
memcpy(pmesh->indices, pindices, size);
|
||||
|
||||
pmesh->triangleCount = (pmesh->vertexCount/4)*2;
|
||||
|
||||
// Copy Colors
|
||||
// Copy colors
|
||||
size = pmesh->vertexCount*sizeof(Color);
|
||||
pmesh->colors = MemAlloc(size);
|
||||
memcpy(pmesh->colors, pcolors, size);
|
||||
|
@ -5564,16 +5560,14 @@ static Model LoadVOX(const char* fileName)
|
|||
// First material index
|
||||
model.meshMaterial[idxMesh] = 0;
|
||||
|
||||
// Build GPU mesh
|
||||
// Upload mesh data to GPU
|
||||
UploadMesh(pmesh, false);
|
||||
|
||||
//Next
|
||||
verticesRemain -= verticesMax;
|
||||
pvertices += verticesMax;
|
||||
pcolors += verticesMax;
|
||||
}
|
||||
|
||||
//Free arrays
|
||||
Vox_FreeArrays(&voxarray);
|
||||
|
||||
return model;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue