4 Commits

Author SHA1 Message Date
Ray
8115b7e922 Update rmodels.c 2025-12-06 20:40:23 +01:00
fd8830948e fix newer NDK version compiling errors (#5389)
target already gets assigned by the clang macro it points to, overwriting it causes it to target linux instead of android, making it check for usr directories instead of the NDK's directories
2025-12-06 20:01:47 +01:00
Ray
f9899a7182 Reviewed code formating 2025-12-06 20:00:19 +01:00
561cc27403 [rModels] Support 16 bit vec3 values in gltf reader (#5388)
* Support 16 bit vec3 values coming from gltf

* Add support for 8 bit normals
2025-12-06 19:50:59 +01:00
5 changed files with 126 additions and 4 deletions

View File

@ -130,7 +130,7 @@ ifeq ($(ANDROID_ARCH),ARM)
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
endif
ifeq ($(ANDROID_ARCH),ARM64)
CFLAGS = -std=c99 -target aarch64 -mfix-cortex-a53-835769
CFLAGS = -std=c99 -mfix-cortex-a53-835769
endif
# Compilation functions attributes options
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC

View File

@ -96,7 +96,7 @@ ifeq ($(ANDROID_ARCH),ARM)
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
endif
ifeq ($(ANDROID_ARCH),ARM64)
CFLAGS = -std=c99 -target aarch64 -mfix-cortex-a53-835769
CFLAGS = -std=c99 -mfix-cortex-a53-835769
endif
# Compilation functions attributes options
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC

View File

@ -96,7 +96,7 @@ ifeq ($(ANDROID_ARCH),ARM)
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
endif
ifeq ($(ANDROID_ARCH),ARM64)
CFLAGS = -std=c99 -target aarch64 -mfix-cortex-a53-835769
CFLAGS = -std=c99 -mfix-cortex-a53-835769
endif
# Compilation functions attributes options
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC

View File

@ -406,7 +406,7 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
endif
ifeq ($(ANDROID_ARCH),arm64)
CFLAGS += -target aarch64 -mfix-cortex-a53-835769
CFLAGS += -mfix-cortex-a53-835769
endif
ifeq ($(ANDROID_ARCH),x86)
CFLAGS += -march=i686

View File

@ -5578,6 +5578,56 @@ static Model LoadGLTF(const char *fileName)
vertices[3*k+2] = vt.z;
}
}
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_16u))
{
// Init raylib mesh vertices to copy glTF attribute data
model.meshes[meshIndex].vertexCount = (int)attribute->count;
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*3*sizeof(unsigned short));
LOAD_ATTRIBUTE(attribute, 3, unsigned short, temp);
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
for (unsigned int t = 0; t < attribute->count*3; t++) model.meshes[meshIndex].vertices[t] = (float)temp[t];
RL_FREE(temp);
// Transform the vertices
float *vertices = model.meshes[meshIndex].vertices;
for (unsigned int k = 0; k < attribute->count; k++)
{
Vector3 vt = Vector3Transform((Vector3){ vertices[3*k], vertices[3*k + 1], vertices[3*k + 2] }, worldMatrix);
vertices[3*k] = vt.x;
vertices[3*k + 1] = vt.y;
vertices[3*k + 2] = vt.z;
}
}
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_16))
{
// Init raylib mesh vertices to copy glTF attribute data
model.meshes[meshIndex].vertexCount = (int)attribute->count;
model.meshes[meshIndex].vertices = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
short *temp = (short *)RL_MALLOC(attribute->count*3*sizeof(short));
LOAD_ATTRIBUTE(attribute, 3, short, temp);
// Convert data to raylib vertex data type (float) the matrix will scale it to the correct size as a float
for (unsigned int t = 0; t < attribute->count*3; t++) model.meshes[meshIndex].vertices[t] = (float)temp[t];
RL_FREE(temp);
// Transform the vertices
float *vertices = model.meshes[meshIndex].vertices;
for (unsigned int k = 0; k < attribute->count; k++)
{
Vector3 vt = Vector3Transform((Vector3){ vertices[3*k], vertices[3*k + 1], vertices[3*k + 2] }, worldMatrix);
vertices[3*k] = vt.x;
vertices[3*k + 1] = vt.y;
vertices[3*k + 2] = vt.z;
}
}
else TRACELOG(LOG_WARNING, "MODEL: [%s] Vertices attribute data format not supported, use vec3 float", fileName);
}
}
@ -5606,6 +5656,78 @@ static Model LoadGLTF(const char *fileName)
normals[3*k+2] = nt.z;
}
}
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_16))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
short *temp = (short *)RL_MALLOC(attribute->count*3*sizeof(short));
LOAD_ATTRIBUTE(attribute, 3, short, temp);
// Convert data to raylib normal data type (float)
for (unsigned int t = 0; t < attribute->count*3; t++) model.meshes[meshIndex].normals[t] = (float)temp[t];
RL_FREE(temp);
// Transform the normals
float *normals = model.meshes[meshIndex].normals;
for (unsigned int k = 0; k < attribute->count; k++)
{
Vector3 nt = Vector3Normalize(Vector3Transform((Vector3){ normals[3*k], normals[3*k + 1], normals[3*k + 2] }, worldMatrixNormals));
normals[3*k] = nt.x;
normals[3*k + 1] = nt.y;
normals[3*k + 2] = nt.z;
}
}
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8u))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*3*sizeof(unsigned char));
LOAD_ATTRIBUTE(attribute, 3, unsigned char, temp);
// Convert data to raylib normal data type (float)
for (unsigned int t = 0; t < attribute->count*3; t++) model.meshes[meshIndex].normals[t] = (float)temp[t];
RL_FREE(temp);
// Transform the normals
float *normals = model.meshes[meshIndex].normals;
for (unsigned int k = 0; k < attribute->count; k++)
{
Vector3 nt = Vector3Normalize(Vector3Transform((Vector3){ normals[3*k], normals[3*k + 1], normals[3*k + 2] }, worldMatrixNormals));
normals[3*k] = nt.x;
normals[3*k + 1] = nt.y;
normals[3*k + 2] = nt.z;
}
}
else if ((attribute->type == cgltf_type_vec3) && (attribute->component_type == cgltf_component_type_r_8))
{
// Init raylib mesh normals to copy glTF attribute data
model.meshes[meshIndex].normals = (float *)RL_MALLOC(attribute->count*3*sizeof(float));
// Load data into a temp buffer to be converted to raylib data type
char *temp = (char *)RL_MALLOC(attribute->count*3*sizeof(char));
LOAD_ATTRIBUTE(attribute, 3, char, temp);
// Convert data to raylib normal data type (float)
for (unsigned int t = 0; t < attribute->count*3; t++) model.meshes[meshIndex].normals[t] = (float)temp[t];
RL_FREE(temp);
// Transform the normals
float *normals = model.meshes[meshIndex].normals;
for (unsigned int k = 0; k < attribute->count; k++)
{
Vector3 nt = Vector3Normalize(Vector3Transform((Vector3){ normals[3*k], normals[3*k + 1], normals[3*k + 2] }, worldMatrixNormals));
normals[3*k] = nt.x;
normals[3*k + 1] = nt.y;
normals[3*k + 2] = nt.z;
}
}
else TRACELOG(LOG_WARNING, "MODEL: [%s] Normals attribute data format not supported, use vec3 float", fileName);
}
}