Skip to content

Commit e47ebec

Browse files
committed
FIX: Issue with texcoords loading for glTF
1 parent 2e77443 commit e47ebec

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/rmodels.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -5121,14 +5121,6 @@ static Model LoadGLTF(const char *fileName)
51215121
{
51225122
// Support up to 2 texture coordinates attributes
51235123
float *texcoordPtr = NULL;
5124-
int index = data->meshes[i].primitives[p].attributes[j].index;
5125-
if (index == 0) texcoordPtr = model.meshes[meshIndex].texcoords;
5126-
else if (index == 1) texcoordPtr = model.meshes[meshIndex].texcoords2;
5127-
else
5128-
{
5129-
TRACELOG(LOG_WARNING, "MODEL: [%s] No more than 2 texture coordinates attributes supported", fileName);
5130-
continue;
5131-
}
51325124

51335125
cgltf_accessor *attribute = data->meshes[i].primitives[p].attributes[j].data;
51345126

@@ -5137,18 +5129,18 @@ static Model LoadGLTF(const char *fileName)
51375129
if (attribute->component_type == cgltf_component_type_r_32f) // vec2, float
51385130
{
51395131
// Init raylib mesh texcoords to copy glTF attribute data
5140-
texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float));
5132+
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
51415133

51425134
// Load 3 components of float data type into mesh.texcoords
51435135
LOAD_ATTRIBUTE(attribute, 2, float, texcoordPtr)
51445136
}
51455137
else if (attribute->component_type == cgltf_component_type_r_8u) // vec2, u8n
51465138
{
51475139
// Init raylib mesh texcoords to copy glTF attribute data
5148-
texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float));
5140+
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
51495141

51505142
// Load data into a temp buffer to be converted to raylib data type
5151-
unsigned short *temp = RL_MALLOC(attribute->count*2*sizeof(unsigned char));
5143+
unsigned char *temp = (unsigned char *)RL_MALLOC(attribute->count*2*sizeof(unsigned char));
51525144
LOAD_ATTRIBUTE(attribute, 2, unsigned char, temp);
51535145

51545146
// Convert data to raylib texcoord data type (float)
@@ -5159,10 +5151,10 @@ static Model LoadGLTF(const char *fileName)
51595151
else if (attribute->component_type == cgltf_component_type_r_16u) // vec2, u16n
51605152
{
51615153
// Init raylib mesh texcoords to copy glTF attribute data
5162-
texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float));
5154+
texcoordPtr = (float *)RL_MALLOC(attribute->count*2*sizeof(float));
51635155

51645156
// Load data into a temp buffer to be converted to raylib data type
5165-
unsigned short *temp = RL_MALLOC(attribute->count*2*sizeof(unsigned short));
5157+
unsigned short *temp = (unsigned short *)RL_MALLOC(attribute->count*2*sizeof(unsigned short));
51665158
LOAD_ATTRIBUTE(attribute, 2, unsigned short, temp);
51675159

51685160
// Convert data to raylib texcoord data type (float)
@@ -5173,6 +5165,15 @@ static Model LoadGLTF(const char *fileName)
51735165
else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported", fileName);
51745166
}
51755167
else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported, use vec2 float", fileName);
5168+
5169+
int index = data->meshes[i].primitives[p].attributes[j].index;
5170+
if (index == 0) model.meshes[meshIndex].texcoords = texcoordPtr;
5171+
else if (index == 1) model.meshes[meshIndex].texcoords2 = texcoordPtr;
5172+
else
5173+
{
5174+
TRACELOG(LOG_WARNING, "MODEL: [%s] No more than 2 texture coordinates attributes supported", fileName);
5175+
if (texcoordPtr != NULL) RL_FREE(texcoordPtr);
5176+
}
51765177
}
51775178
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_color) // COLOR_n, vec3/vec4, float/u8n/u16n
51785179
{

0 commit comments

Comments
 (0)