|
|
@ -5109,9 +5109,18 @@ static Model LoadGLTF(const char *fileName) |
|
|
|
} |
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Tangent attribute data format not supported, use vec4 float", fileName); |
|
|
|
} |
|
|
|
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_texcoord) // TEXCOORD_0, vec2, float/u8n/u16n |
|
|
|
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_texcoord) // TEXCOORD_n, vec2, float/u8n/u16n |
|
|
|
{ |
|
|
|
// TODO: Support additional texture coordinates: TEXCOORD_1 -> mesh.texcoords2 |
|
|
|
// Support up to 2 texture coordinates attributes |
|
|
|
float *texcoordPtr = NULL; |
|
|
|
int index = data->meshes[i].primitives[p].attributes[j].index; |
|
|
|
if (index == 0) texcoordPtr = model.meshes[meshIndex].texcoords; |
|
|
|
else if (index == 1) texcoordPtr = model.meshes[meshIndex].texcoords2; |
|
|
|
else |
|
|
|
{ |
|
|
|
TRACELOG(LOG_WARNING, "MODEL: [%s] No more than 2 texture coordinates attributes supported", fileName); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
cgltf_accessor *attribute = data->meshes[i].primitives[p].attributes[j].data; |
|
|
|
|
|
|
@ -5120,44 +5129,44 @@ static Model LoadGLTF(const char *fileName) |
|
|
|
if (attribute->component_type == cgltf_component_type_r_32f) // vec2, float |
|
|
|
{ |
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data |
|
|
|
model.meshes[meshIndex].texcoords = RL_MALLOC(attribute->count*2*sizeof(float)); |
|
|
|
texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float)); |
|
|
|
|
|
|
|
// Load 3 components of float data type into mesh.texcoords |
|
|
|
LOAD_ATTRIBUTE(attribute, 2, float, model.meshes[meshIndex].texcoords) |
|
|
|
LOAD_ATTRIBUTE(attribute, 2, float, texcoordPtr) |
|
|
|
} |
|
|
|
else if (attribute->component_type == cgltf_component_type_r_8u) // vec2, u8n |
|
|
|
{ |
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data |
|
|
|
model.meshes[meshIndex].texcoords = RL_MALLOC(attribute->count*2*sizeof(float)); |
|
|
|
texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float)); |
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type |
|
|
|
unsigned short *temp = RL_MALLOC(attribute->count*2*sizeof(unsigned char)); |
|
|
|
LOAD_ATTRIBUTE(attribute, 2, unsigned char, temp); |
|
|
|
|
|
|
|
// Convert data to raylib texcoord data type (float) |
|
|
|
for (unsigned int t = 0; t < attribute->count*2; t++) model.meshes[meshIndex].texcoords[t] = (float)temp[t]/255.0f; |
|
|
|
for (unsigned int t = 0; t < attribute->count*2; t++) texcoordPtr[t] = (float)temp[t]/255.0f; |
|
|
|
|
|
|
|
RL_FREE(temp); |
|
|
|
} |
|
|
|
else if (attribute->component_type == cgltf_component_type_r_16u) // vec2, u16n |
|
|
|
{ |
|
|
|
// Init raylib mesh texcoords to copy glTF attribute data |
|
|
|
model.meshes[meshIndex].texcoords = RL_MALLOC(attribute->count*2*sizeof(float)); |
|
|
|
texcoordPtr = RL_MALLOC(attribute->count*2*sizeof(float)); |
|
|
|
|
|
|
|
// Load data into a temp buffer to be converted to raylib data type |
|
|
|
unsigned short *temp = RL_MALLOC(attribute->count*2*sizeof(unsigned short)); |
|
|
|
LOAD_ATTRIBUTE(attribute, 2, unsigned short, temp); |
|
|
|
|
|
|
|
// Convert data to raylib texcoord data type (float) |
|
|
|
for (unsigned int t = 0; t < attribute->count*2; t++) model.meshes[meshIndex].texcoords[t] = (float)temp[t]/65535.0f; |
|
|
|
for (unsigned int t = 0; t < attribute->count*2; t++) texcoordPtr[t] = (float)temp[t]/65535.0f; |
|
|
|
|
|
|
|
RL_FREE(temp); |
|
|
|
} |
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported, use vec2 float", fileName); |
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported", fileName); |
|
|
|
} |
|
|
|
else TRACELOG(LOG_WARNING, "MODEL: [%s] Texcoords attribute data format not supported, use vec2 float", fileName); |
|
|
|
} |
|
|
|
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_color) // COLOR_0, vec3/vec4, float/u8n/u16n |
|
|
|
else if (data->meshes[i].primitives[p].attributes[j].type == cgltf_attribute_type_color) // COLOR_n, vec3/vec4, float/u8n/u16n |
|
|
|
{ |
|
|
|
cgltf_accessor *attribute = data->meshes[i].primitives[p].attributes[j].data; |
|
|
|
|
|
|
|