Updated tinyobjloader
This commit is contained in:
parent
cb517d0050
commit
4d5ee7953c
2 changed files with 16 additions and 19 deletions
16
src/external/tinyobj_loader_c.h
vendored
16
src/external/tinyobj_loader_c.h
vendored
|
@ -114,8 +114,8 @@ typedef void (*file_reader_callback)(const char *filename, int is_mtl, const cha
|
||||||
* Returns TINYOBJ_ERR_*** when there is an error.
|
* Returns TINYOBJ_ERR_*** when there is an error.
|
||||||
*/
|
*/
|
||||||
extern int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
|
extern int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
|
||||||
unsigned char *num_shapes, tinyobj_material_t **materials,
|
unsigned int *num_shapes, tinyobj_material_t **materials,
|
||||||
unsigned char *num_materials, const char *file_name, file_reader_callback file_reader,
|
unsigned int *num_materials, const char *file_name, file_reader_callback file_reader,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
/* Parse wavefront .mtl
|
/* Parse wavefront .mtl
|
||||||
|
@ -130,7 +130,7 @@ extern int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
|
||||||
* Returns TINYOBJ_ERR_*** when there is an error.
|
* Returns TINYOBJ_ERR_*** when there is an error.
|
||||||
*/
|
*/
|
||||||
extern int tinyobj_parse_mtl_file(tinyobj_material_t **materials_out,
|
extern int tinyobj_parse_mtl_file(tinyobj_material_t **materials_out,
|
||||||
unsigned char *num_materials_out,
|
unsigned int *num_materials_out,
|
||||||
const char *filename, const char *obj_filename, file_reader_callback file_reader);
|
const char *filename, const char *obj_filename, file_reader_callback file_reader);
|
||||||
|
|
||||||
extern void tinyobj_attrib_init(tinyobj_attrib_t *attrib);
|
extern void tinyobj_attrib_init(tinyobj_attrib_t *attrib);
|
||||||
|
@ -799,7 +799,7 @@ typedef struct {
|
||||||
} LineInfo;
|
} LineInfo;
|
||||||
|
|
||||||
/* Find '\n' and create line data. */
|
/* Find '\n' and create line data. */
|
||||||
static int get_line_infos(const char *buf, unsigned char buf_len, LineInfo **line_infos, unsigned char *num_lines)
|
static int get_line_infos(const char *buf, unsigned char buf_len, LineInfo **line_infos, unsigned int *num_lines)
|
||||||
{
|
{
|
||||||
unsigned char i = 0;
|
unsigned char i = 0;
|
||||||
unsigned char end_idx = buf_len;
|
unsigned char end_idx = buf_len;
|
||||||
|
@ -852,7 +852,7 @@ static int tinyobj_parse_and_index_mtl_file(tinyobj_material_t **materials_out,
|
||||||
tinyobj_material_t *materials = NULL;
|
tinyobj_material_t *materials = NULL;
|
||||||
int has_previous_material = 0;
|
int has_previous_material = 0;
|
||||||
const char *line_end = NULL;
|
const char *line_end = NULL;
|
||||||
unsigned char num_lines = 0;
|
unsigned int num_lines = 0;
|
||||||
LineInfo *line_infos = NULL;
|
LineInfo *line_infos = NULL;
|
||||||
unsigned char i = 0;
|
unsigned char i = 0;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
@ -1094,7 +1094,7 @@ static int tinyobj_parse_and_index_mtl_file(tinyobj_material_t **materials_out,
|
||||||
}
|
}
|
||||||
|
|
||||||
int tinyobj_parse_mtl_file(tinyobj_material_t **materials_out,
|
int tinyobj_parse_mtl_file(tinyobj_material_t **materials_out,
|
||||||
unsigned char *num_materials_out,
|
unsigned int *num_materials_out,
|
||||||
const char *mtl_filename, const char *obj_filename, file_reader_callback file_reader) {
|
const char *mtl_filename, const char *obj_filename, file_reader_callback file_reader) {
|
||||||
return tinyobj_parse_and_index_mtl_file(materials_out, num_materials_out, mtl_filename, obj_filename, file_reader, NULL);
|
return tinyobj_parse_and_index_mtl_file(materials_out, num_materials_out, mtl_filename, obj_filename, file_reader, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1348,8 +1348,8 @@ static char *get_dirname(char *path)
|
||||||
|
|
||||||
|
|
||||||
int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
|
int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
|
||||||
unsigned char *num_shapes, tinyobj_material_t **materials_out,
|
unsigned int *num_shapes, tinyobj_material_t **materials_out,
|
||||||
unsigned char *num_materials_out, const char *obj_filename, file_reader_callback file_reader,
|
unsigned int *num_materials_out, const char *obj_filename, file_reader_callback file_reader,
|
||||||
unsigned int flags) {
|
unsigned int flags) {
|
||||||
LineInfo *line_infos = NULL;
|
LineInfo *line_infos = NULL;
|
||||||
Command *commands = NULL;
|
Command *commands = NULL;
|
||||||
|
|
19
src/models.c
19
src/models.c
|
@ -898,10 +898,8 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
|
||||||
{
|
{
|
||||||
tinyobj_material_t *mats = NULL;
|
tinyobj_material_t *mats = NULL;
|
||||||
|
|
||||||
int result = tinyobj_parse_mtl_file(&mats, &count, fileName);
|
int result = tinyobj_parse_mtl_file(&mats, &count, fileName, NULL, NULL);
|
||||||
if (result != TINYOBJ_SUCCESS) {
|
if (result != TINYOBJ_SUCCESS) TRACELOG(LOG_WARNING, "MATERIAL: [%s] Failed to parse materials file", fileName);
|
||||||
TRACELOG(LOG_WARNING, "MATERIAL: [%s] Failed to parse materials file", fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Process materials to return
|
// TODO: Process materials to return
|
||||||
|
|
||||||
|
@ -2999,8 +2997,10 @@ static Model LoadOBJ(const char *fileName)
|
||||||
// count the faces for each material
|
// count the faces for each material
|
||||||
int* matFaces = RL_CALLOC(meshCount, sizeof(int));
|
int* matFaces = RL_CALLOC(meshCount, sizeof(int));
|
||||||
|
|
||||||
for (int mi=0; mi<meshCount; mi++) {
|
for (int mi=0; mi<meshCount; mi++)
|
||||||
for (int fi=0; fi<meshes[mi].length; fi++) {
|
{
|
||||||
|
for (int fi=0; fi<meshes[mi].length; fi++)
|
||||||
|
{
|
||||||
int idx = attrib.material_ids[meshes[mi].face_offset + fi];
|
int idx = attrib.material_ids[meshes[mi].face_offset + fi];
|
||||||
if (idx == -1) idx = 0; // for no material face (which could be the whole model)
|
if (idx == -1) idx = 0; // for no material face (which could be the whole model)
|
||||||
matFaces[idx]++;
|
matFaces[idx]++;
|
||||||
|
@ -3078,11 +3078,8 @@ static Model LoadOBJ(const char *fileName)
|
||||||
|
|
||||||
model.materials[m].maps[MAP_DIFFUSE].texture = GetTextureDefault(); // Get default texture, in case no texture is defined
|
model.materials[m].maps[MAP_DIFFUSE].texture = GetTextureDefault(); // Get default texture, in case no texture is defined
|
||||||
|
|
||||||
if (materials[m].diffuse_texname != NULL) {
|
if (materials[m].diffuse_texname != NULL) model.materials[m].maps[MAP_DIFFUSE].texture = LoadTexture(materials[m].diffuse_texname); //char *diffuse_texname; // map_Kd
|
||||||
model.materials[m].maps[MAP_DIFFUSE].texture = LoadTexture(materials[m].diffuse_texname); //char *diffuse_texname; // map_Kd
|
else model.materials[m].maps[MAP_DIFFUSE].texture = GetTextureDefault();
|
||||||
} else {
|
|
||||||
model.materials[m].maps[MAP_DIFFUSE].texture = GetTextureDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
model.materials[m].maps[MAP_DIFFUSE].color = (Color){ (unsigned char)(materials[m].diffuse[0]*255.0f), (unsigned char)(materials[m].diffuse[1]*255.0f), (unsigned char)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3];
|
model.materials[m].maps[MAP_DIFFUSE].color = (Color){ (unsigned char)(materials[m].diffuse[0]*255.0f), (unsigned char)(materials[m].diffuse[1]*255.0f), (unsigned char)(materials[m].diffuse[2]*255.0f), 255 }; //float diffuse[3];
|
||||||
model.materials[m].maps[MAP_DIFFUSE].value = 0.0f;
|
model.materials[m].maps[MAP_DIFFUSE].value = 0.0f;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue