mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-04 17:06:27 +00:00
feat: vox_loader normals and new voxels shader (#3843)
This commit is contained in:
17
src/external/vox_loader.h
vendored
17
src/external/vox_loader.h
vendored
@@ -123,6 +123,7 @@ typedef struct {
|
||||
|
||||
// Arrays for mesh build
|
||||
ArrayVector3 vertices;
|
||||
ArrayVector3 normals;
|
||||
ArrayUShort indices;
|
||||
ArrayColor colors;
|
||||
|
||||
@@ -292,6 +293,16 @@ const VoxVector3 SolidVertex[] = {
|
||||
{1, 1, 1} //7
|
||||
};
|
||||
|
||||
const VoxVector3 FacesPerSideNormal[] = {
|
||||
{ -1, 0, 0 }, //-X
|
||||
{1, 0, 0 }, //+X
|
||||
{0,-1, 0}, //-Y
|
||||
{0, 1, 0}, //+Y
|
||||
{0, 0, -1}, //-Z
|
||||
{0, 0, 1}, //+Z
|
||||
};
|
||||
|
||||
|
||||
// Allocated VoxArray3D size
|
||||
static void Vox_AllocArray(VoxArray3D* pvoxarray, int _sx, int _sy, int _sz)
|
||||
{
|
||||
@@ -508,6 +519,11 @@ static void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matI
|
||||
insertArrayVector3(&pvoxArray->vertices, vertComputed[v2]);
|
||||
insertArrayVector3(&pvoxArray->vertices, vertComputed[v3]);
|
||||
|
||||
insertArrayVector3(&pvoxArray->normals, FacesPerSideNormal[i]);
|
||||
insertArrayVector3(&pvoxArray->normals, FacesPerSideNormal[i]);
|
||||
insertArrayVector3(&pvoxArray->normals, FacesPerSideNormal[i]);
|
||||
insertArrayVector3(&pvoxArray->normals, FacesPerSideNormal[i]);
|
||||
|
||||
VoxColor col = pvoxArray->palette[matID];
|
||||
|
||||
insertArrayColor(&pvoxArray->colors, col);
|
||||
@@ -653,6 +669,7 @@ int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArr
|
||||
|
||||
// Init Arrays
|
||||
initArrayVector3(&pvoxarray->vertices, 3 * 1024);
|
||||
initArrayVector3(&pvoxarray->normals, 3 * 1024);
|
||||
initArrayUShort(&pvoxarray->indices, 3 * 1024);
|
||||
initArrayColor(&pvoxarray->colors, 3 * 1024);
|
||||
|
||||
|
@@ -5641,6 +5641,7 @@ static Model LoadVOX(const char *fileName)
|
||||
|
||||
// 6*4 = 12 vertices per voxel
|
||||
Vector3 *pvertices = (Vector3 *)voxarray.vertices.array;
|
||||
Vector3* pnormals = (Vector3*)voxarray.normals.array;
|
||||
Color *pcolors = (Color *)voxarray.colors.array;
|
||||
|
||||
unsigned short *pindices = voxarray.indices.array; // 5461*6*6 = 196596 indices max per mesh
|
||||
@@ -5659,6 +5660,10 @@ static Model LoadVOX(const char *fileName)
|
||||
pmesh->vertices = RL_MALLOC(size);
|
||||
memcpy(pmesh->vertices, pvertices, size);
|
||||
|
||||
// Copy normals
|
||||
pmesh->normals = RL_MALLOC(size); //Rk. size as vertices
|
||||
memcpy(pmesh->normals, pnormals, size);
|
||||
|
||||
// Copy indices
|
||||
size = voxarray.indices.used*sizeof(unsigned short);
|
||||
pmesh->indices = RL_MALLOC(size);
|
||||
@@ -5676,6 +5681,7 @@ static Model LoadVOX(const char *fileName)
|
||||
|
||||
verticesRemain -= verticesMax;
|
||||
pvertices += verticesMax;
|
||||
pnormals += verticesMax;
|
||||
pcolors += verticesMax;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user