@@ -5121,14 +5121,6 @@ static Model LoadGLTF(const char *fileName)
5121
5121
{
5122
5122
// Support up to 2 texture coordinates attributes
5123
5123
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
- }
5132
5124
5133
5125
cgltf_accessor * attribute = data -> meshes [i ].primitives [p ].attributes [j ].data ;
5134
5126
@@ -5137,18 +5129,18 @@ static Model LoadGLTF(const char *fileName)
5137
5129
if (attribute -> component_type == cgltf_component_type_r_32f ) // vec2, float
5138
5130
{
5139
5131
// 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 ));
5141
5133
5142
5134
// Load 3 components of float data type into mesh.texcoords
5143
5135
LOAD_ATTRIBUTE (attribute , 2 , float , texcoordPtr )
5144
5136
}
5145
5137
else if (attribute -> component_type == cgltf_component_type_r_8u ) // vec2, u8n
5146
5138
{
5147
5139
// 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 ));
5149
5141
5150
5142
// 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 ));
5152
5144
LOAD_ATTRIBUTE (attribute , 2 , unsigned char , temp );
5153
5145
5154
5146
// Convert data to raylib texcoord data type (float)
@@ -5159,10 +5151,10 @@ static Model LoadGLTF(const char *fileName)
5159
5151
else if (attribute -> component_type == cgltf_component_type_r_16u ) // vec2, u16n
5160
5152
{
5161
5153
// 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 ));
5163
5155
5164
5156
// 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 ));
5166
5158
LOAD_ATTRIBUTE (attribute , 2 , unsigned short , temp );
5167
5159
5168
5160
// Convert data to raylib texcoord data type (float)
@@ -5173,6 +5165,15 @@ static Model LoadGLTF(const char *fileName)
5173
5165
else TRACELOG (LOG_WARNING , "MODEL: [%s] Texcoords attribute data format not supported" , fileName );
5174
5166
}
5175
5167
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
+ }
5176
5177
}
5177
5178
else if (data -> meshes [i ].primitives [p ].attributes [j ].type == cgltf_attribute_type_color ) // COLOR_n, vec3/vec4, float/u8n/u16n
5178
5179
{
0 commit comments