This commit is contained in:
fxgen 2021-09-07 18:35:01 +02:00
commit 5963725259
3 changed files with 81 additions and 69 deletions

View File

@ -186,16 +186,16 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
ANDROID_SYSROOT ?= $(ANDROID_TOOLCHAIN)/sysroot ANDROID_SYSROOT ?= $(ANDROID_TOOLCHAIN)/sysroot
ifeq ($(ANDROID_ARCH),arm) ifeq ($(ANDROID_ARCH),arm)
ANDROID_ARCH_NAME = armeabi-v7a ANDROID_COMPILER_ARCH = armv7a
endif endif
ifeq ($(ANDROID_ARCH),arm64) ifeq ($(ANDROID_ARCH),arm64)
ANDROID_ARCH_NAME = arm64-v8a ANDROID_COMPILER_ARCH = aarch64
endif endif
ifeq ($(ANDROID_ARCH),x86) ifeq ($(ANDROID_ARCH),x86)
ANDROID_ARCH_NAME = i686 ANDROID_COMPILER_ARCH = i686
endif endif
ifeq ($(ANDROID_ARCH),x86_64) ifeq ($(ANDROID_ARCH),x86_64)
ANDROID_ARCH_NAME = x86_64 ANDROID_COMPILER_ARCH = x86_64
endif endif
endif endif
@ -254,22 +254,9 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
endif endif
ifeq ($(PLATFORM),PLATFORM_ANDROID) ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Android toolchain (must be provided for desired architecture and compiler) # Android toolchain (must be provided for desired architecture and compiler)
ifeq ($(ANDROID_ARCH),arm) CC = $(ANDROID_TOOLCHAIN)/bin/$(ANDROID_COMPILER_ARCH)-linux-androideabi$(ANDROID_API_VERSION)-clang
CC = $(ANDROID_TOOLCHAIN)/bin/armv7a-linux-androideabi$(ANDROID_API_VERSION)-clang # It seems from Android NDK r22 onwards we need to use llvm-ar
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar AR = $(ANDROID_TOOLCHAIN)/bin/llvm-ar
endif
ifeq ($(ANDROID_ARCH),arm64)
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android$(ANDROID_API_VERSION)-clang
AR = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-ar
endif
ifeq ($(ANDROID_ARCH),x86)
CC = $(ANDROID_TOOLCHAIN)/bin/i686-linux-android$(ANDROID_API_VERSION)-clang
AR = $(ANDROID_TOOLCHAIN)/bin/i686-linux-android-ar
endif
ifeq ($(ANDROID_ARCH),x86_64)
CC = $(ANDROID_TOOLCHAIN)/bin/x86_64-linux-android$(ANDROID_API_VERSION)-clang
AR = $(ANDROID_TOOLCHAIN)/bin/x86_64-linux-android-ar
endif
endif endif
# Define compiler flags: # Define compiler flags:
@ -344,10 +331,10 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),arm64) ifeq ($(ANDROID_ARCH),arm64)
CFLAGS += -target aarch64 -mfix-cortex-a53-835769 CFLAGS += -target aarch64 -mfix-cortex-a53-835769
endif endif
ifeq ($(ANDROID_ARCH), x86) ifeq ($(ANDROID_ARCH),x86)
CFLAGS += -march=i686 CFLAGS += -march=i686
endif endif
ifeq ($(ANDROID_ARCH), x86_64) ifeq ($(ANDROID_ARCH),x86_64)
CFLAGS += -march=x86-64 CFLAGS += -march=x86-64
endif endif
# Compilation functions attributes options # Compilation functions attributes options
@ -509,7 +496,7 @@ else
endif endif
ifeq ($(PLATFORM_OS),OSX) ifeq ($(PLATFORM_OS),OSX)
$(CC) -dynamiclib -o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib $(OBJS) $(LDFLAGS) -compatibility_version $(RAYLIB_API_VERSION) -current_version $(RAYLIB_VERSION) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo $(CC) -dynamiclib -o $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib $(OBJS) $(LDFLAGS) -compatibility_version $(RAYLIB_API_VERSION) -current_version $(RAYLIB_VERSION) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
install_name_tool -id "lib$(RAYLIB_LIB_NAME).$(VERSION).dylib" $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib install_name_tool -id "@rpath/lib$(RAYLIB_LIB_NAME).$(RAYLIB_API_VERSION).dylib" $(RAYLIB_RELEASE_PATH)/lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib
@echo "raylib shared library generated (lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib)!" @echo "raylib shared library generated (lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib)!"
cd $(RAYLIB_RELEASE_PATH) && ln -fs lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib lib$(RAYLIB_LIB_NAME).$(RAYLIB_API_VERSION).dylib cd $(RAYLIB_RELEASE_PATH) && ln -fs lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib lib$(RAYLIB_LIB_NAME).$(RAYLIB_API_VERSION).dylib
cd $(RAYLIB_RELEASE_PATH) && ln -fs lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib lib$(RAYLIB_LIB_NAME).dylib cd $(RAYLIB_RELEASE_PATH) && ln -fs lib$(RAYLIB_LIB_NAME).$(RAYLIB_VERSION).dylib lib$(RAYLIB_LIB_NAME).dylib

View File

@ -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].m_array = 0;
voxarray->m_arrayChunks[i].arraySize = 0; voxarray->m_arrayChunks[i].arraySize = 0;
} }
return voxarray;
} }
// Set voxel ID from its position into VoxArray3D // 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 signature;
unsigned long readed = 0; unsigned int readed = 0;
unsigned char* fileData; unsigned char* fileData;
fileData = LoadFileData(pszfileName, &readed); fileData = LoadFileData(pszfileName, &readed);
if (fileData == 0) if (fileData == 0)
@ -589,7 +587,7 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* voxarray)
unsigned char* fileDataPtr = fileData; unsigned char* fileDataPtr = fileData;
unsigned char* endfileDataPtr = fileData + readed; unsigned char* endfileDataPtr = fileData + readed;
signature = *((unsigned long*)fileDataPtr); signature = *((unsigned long *)fileDataPtr);
fileDataPtr += sizeof(unsigned long); fileDataPtr += sizeof(unsigned long);
if (signature != 0x20584F56) //56 4F 58 20 if (signature != 0x20584F56) //56 4F 58 20
@ -640,7 +638,6 @@ int Vox_LoadFileName(const char* pszfileName, VoxArray3D* voxarray)
unsigned long chunkTotalChildSize = *((unsigned long*)fileDataPtr); unsigned long chunkTotalChildSize = *((unsigned long*)fileDataPtr);
fileDataPtr += sizeof(unsigned long); fileDataPtr += sizeof(unsigned long);
if (strcmp(szChunkName, "SIZE") == 0) if (strcmp(szChunkName, "SIZE") == 0)
{ {
//(4 bytes x 3 : x, y, z ) //(4 bytes x 3 : x, y, z )

View File

@ -74,8 +74,10 @@
#endif #endif
#if defined(SUPPORT_FILEFORMAT_VOX) #if defined(SUPPORT_FILEFORMAT_VOX)
// TODO: Support custom memory allocators
#define VOX_LOADER_IMPLEMENTATION #define VOX_LOADER_IMPLEMENTATION
#include "external/vox_loader.h" // vox file format loading #include "external/vox_loader.h" // vox file format loading (MagikaVoxel)
#endif #endif
#if defined(SUPPORT_MESH_GENERATION) #if defined(SUPPORT_MESH_GENERATION)
@ -139,7 +141,7 @@ static bool ReadGLTFValue(cgltf_accessor *acc, unsigned int index, void *variabl
static void *ReadGLTFValuesAs(cgltf_accessor *acc, cgltf_component_type type, bool adjustOnDownCasting); static void *ReadGLTFValuesAs(cgltf_accessor *acc, cgltf_component_type type, bool adjustOnDownCasting);
#endif #endif
#if defined(SUPPORT_FILEFORMAT_VOX) #if defined(SUPPORT_FILEFORMAT_VOX)
static Model LoadVOX(const char* filename); //Load VOX mesh data static Model LoadVOX(const char *filename); // Load VOX mesh data
#endif #endif
#if defined(SUPPORT_FILEFORMAT_VOX) #if defined(SUPPORT_FILEFORMAT_VOX)
static Model LoadVOX(const char* filename); //Load VOX mesh data static Model LoadVOX(const char* filename); //Load VOX mesh data
@ -2422,7 +2424,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
int vCounter = 0; // Used to count vertices float by float int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float int tcCounter = 0; // Used to count texcoords float by float
int nCounter = 0; // Used to count normals float by float int nCounter = 0; // Used to count normals float by float
int trisCounter = 0; int trisCounter = 0;
Vector3 scaleFactor = { size.x/mapX, size.y/255.0f, size.z/mapZ }; Vector3 scaleFactor = { size.x/mapX, size.y/255.0f, size.z/mapZ };
@ -3565,7 +3567,7 @@ static Model LoadOBJ(const char *fileName)
for (int fi = 0; fi< attrib.num_faces; fi++) 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]; int idx = attrib.material_ids[fi];
matFaces[idx]++; matFaces[idx]++;
} }
@ -5462,18 +5464,52 @@ void LoadGLTFMesh(cgltf_data *data, cgltf_mesh *mesh, Model *outModel, Matrix cu
} }
} }
void LoadGLTFNode(cgltf_data *data, cgltf_node *node, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName) static Matrix GetNodeTransformationMatrix(cgltf_node *node, Matrix current)
{ {
Matrix nodeTransform = { if (node->has_matrix)
{
Matrix nodeTransform = {
node->matrix[0], node->matrix[4], node->matrix[8], node->matrix[12], node->matrix[0], node->matrix[4], node->matrix[8], node->matrix[12],
node->matrix[1], node->matrix[5], node->matrix[9], node->matrix[13], node->matrix[1], node->matrix[5], node->matrix[9], node->matrix[13],
node->matrix[2], node->matrix[6], node->matrix[10], node->matrix[14], node->matrix[2], node->matrix[6], node->matrix[10], node->matrix[14],
node->matrix[3], node->matrix[7], node->matrix[11], node->matrix[15] }; node->matrix[3], node->matrix[7], node->matrix[11], node->matrix[15] };
current= MatrixMultiply(nodeTransform, current);
}
if (node->has_translation)
{
Matrix tl = MatrixTranslate(node->translation[0],node->translation[1],node->translation[2]);
current = MatrixMultiply(tl, current);
}
if (node->has_rotation)
{
Matrix rot = QuaternionToMatrix((Quaternion){node->rotation[0],node->rotation[1],node->rotation[2],node->rotation[3]});
current = MatrixMultiply(rot, current);
}
if (node->has_scale)
{
Matrix scale = MatrixScale(node->scale[0],node->scale[1],node->scale[2]);
current = MatrixMultiply(scale, current);
}
return current;
}
currentTransform = MatrixMultiply(nodeTransform, currentTransform); void LoadGLTFNode(cgltf_data *data, cgltf_node *node, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName)
{
if (node->mesh != NULL) LoadGLTFMesh(data, node->mesh, outModel, currentTransform, primitiveIndex, fileName); // Apply the transforms if they exist (Will still be applied even if no mesh is present to support emptys and bone structures)
Matrix localTransform = GetNodeTransformationMatrix(node, MatrixIdentity());
currentTransform = MatrixMultiply(localTransform, currentTransform);
// Load mesh if it exists
if (node->mesh != NULL)
{
// Check if skinning is enabled and load Mesh accordingly
Matrix vertexTransform = currentTransform;
if((node->skin != NULL) && (node->parent != NULL))
{
vertexTransform = localTransform;
TRACELOG(LOG_WARNING,"MODEL: GLTF Node %s is skinned but not root node! Parent transformations will be ignored (NODE_SKINNED_MESH_NON_ROOT)",node->name);
}
LoadGLTFMesh(data, node->mesh, outModel, vertexTransform, primitiveIndex, fileName);
}
for (unsigned int i = 0; i < node->children_count; i++) LoadGLTFNode(data, node->children[i], outModel, currentTransform, primitiveIndex, fileName); for (unsigned int i = 0; i < node->children_count; i++) LoadGLTFNode(data, node->children[i], outModel, currentTransform, primitiveIndex, fileName);
} }
@ -5487,17 +5523,14 @@ static void GetGLTFPrimitiveCount(cgltf_node *node, int *outCount)
#endif #endif
#if defined(SUPPORT_FILEFORMAT_VOX) #if defined(SUPPORT_FILEFORMAT_VOX)
// Load OBJ mesh data // Load VOX (MagikaVoxel) mesh data
static Model LoadVOX(const char* fileName) static Model LoadVOX(const char *fileName)
{ {
Model model = { 0 }; Model model = { 0 };
int nbvertices = 0; int nbvertices = 0;
int meshescount = 0; int meshescount = 0;
//////////////////////////////////
// Load MagicaVoxel fileformat
VoxArray3D voxarray; VoxArray3D voxarray = { 0 };
int ret = Vox_LoadFileName(fileName, &voxarray); int ret = Vox_LoadFileName(fileName, &voxarray);
if (ret != VOX_SUCCESS) if (ret != VOX_SUCCESS)
@ -5509,74 +5542,69 @@ static Model LoadVOX(const char* fileName)
{ {
// Compute meshes count // Compute meshes count
nbvertices = voxarray.vertices.used; nbvertices = voxarray.vertices.used;
meshescount = 1 + (nbvertices / 65536); meshescount = 1 + (nbvertices/65536);
TRACELOG(LOG_INFO, "MODEL: [%s] VOX data loaded successfully : %i vertices/%i meshes", fileName, nbvertices, meshescount); TRACELOG(LOG_INFO, "MODEL: [%s] VOX data loaded successfully : %i vertices/%i meshes", fileName, nbvertices, meshescount);
} }
////////////////////////////////// // Build models from meshes
// Build model
// Build Models from meshes
model.transform = MatrixIdentity(); model.transform = MatrixIdentity();
model.meshCount = meshescount; model.meshCount = meshescount;
model.meshes = (Mesh*)MemAlloc(model.meshCount * sizeof(Mesh)); model.meshes = (Mesh *)MemAlloc(model.meshCount*sizeof(Mesh));
model.meshMaterial = (int*)MemAlloc(model.meshCount * sizeof(int)); model.meshMaterial = (int *)MemAlloc(model.meshCount*sizeof(int));
model.materialCount = 1; model.materialCount = 1;
model.materials = (Material*)MemAlloc(model.materialCount * sizeof(Material)); model.materials = (Material *)MemAlloc(model.materialCount*sizeof(Material));
model.materials[0] = LoadMaterialDefault(); model.materials[0] = LoadMaterialDefault();
// Init model meshes
// Init model's meshes
int verticesRemain = voxarray.vertices.used; int verticesRemain = voxarray.vertices.used;
int verticesMax = 65532; //5461 voxels x 12 vertices per voxel -> 65532 (must be inf 65536) 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 Vector3 *pvertices = voxarray.vertices.array; // 6*4 = 12 vertices per voxel
Color* pcolors = voxarray.colors.array; 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++) for (int idxMesh = 0; idxMesh < meshescount; idxMesh++)
{ {
Mesh* pmesh = &model.meshes[idxMesh]; Mesh *pmesh = &model.meshes[idxMesh];
memset(pmesh, 0, sizeof(Mesh)); memset(pmesh, 0, sizeof(Mesh));
// Copy Vertices // Copy vertices
pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain); pmesh->vertexCount = (int)fmin(verticesMax, verticesRemain);
size = pmesh->vertexCount * sizeof(float) * 3; size = pmesh->vertexCount*sizeof(float)*3;
pmesh->vertices = MemAlloc(size); pmesh->vertices = MemAlloc(size);
memcpy(pmesh->vertices, pvertices, 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); size = voxarray.indices.used * sizeof(unsigned short);
pmesh->indices = MemAlloc(size); pmesh->indices = MemAlloc(size);
memcpy(pmesh->indices, pindices, size); memcpy(pmesh->indices, pindices, size);
pmesh->triangleCount = (pmesh->vertexCount / 4) * 2; pmesh->triangleCount = (pmesh->vertexCount/4)*2;
// Copy Colors // Copy colors
size = pmesh->vertexCount * sizeof(Color); size = pmesh->vertexCount*sizeof(Color);
pmesh->colors = MemAlloc(size); pmesh->colors = MemAlloc(size);
memcpy(pmesh->colors, pcolors, size); memcpy(pmesh->colors, pcolors, size);
// First material index // First material index
model.meshMaterial[idxMesh] = 0; model.meshMaterial[idxMesh] = 0;
// Build GPU mesh // Upload mesh data to GPU
UploadMesh(pmesh, false); UploadMesh(pmesh, false);
//Next
verticesRemain -= verticesMax; verticesRemain -= verticesMax;
pvertices += verticesMax; pvertices += verticesMax;
pcolors += verticesMax; pcolors += verticesMax;
} }
//Free arrays
Vox_FreeArrays(&voxarray); Vox_FreeArrays(&voxarray);
return model; return model;