Browse Source

Updated tinyobjloader

pull/1433/head
raysan5 4 years ago
parent
commit
4d5ee7953c
2 changed files with 16 additions and 19 deletions
  1. +8
    -8
      src/external/tinyobj_loader_c.h
  2. +8
    -11
      src/models.c

+ 8
- 8
src/external/tinyobj_loader_c.h View File

@ -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.
*/
extern int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
unsigned char *num_shapes, tinyobj_material_t **materials,
unsigned char *num_materials, const char *file_name, file_reader_callback file_reader,
unsigned int *num_shapes, tinyobj_material_t **materials,
unsigned int *num_materials, const char *file_name, file_reader_callback file_reader,
unsigned int flags);
/* 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.
*/
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);
extern void tinyobj_attrib_init(tinyobj_attrib_t *attrib);
@ -799,7 +799,7 @@ typedef struct {
} LineInfo;
/* 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 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;
int has_previous_material = 0;
const char *line_end = NULL;
unsigned char num_lines = 0;
unsigned int num_lines = 0;
LineInfo *line_infos = NULL;
unsigned char i = 0;
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,
unsigned char *num_materials_out,
unsigned int *num_materials_out,
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);
}
@ -1348,8 +1348,8 @@ static char *get_dirname(char *path)
int tinyobj_parse_obj(tinyobj_attrib_t *attrib, tinyobj_shape_t **shapes,
unsigned char *num_shapes, tinyobj_material_t **materials_out,
unsigned char *num_materials_out, const char *obj_filename, file_reader_callback file_reader,
unsigned int *num_shapes, tinyobj_material_t **materials_out,
unsigned int *num_materials_out, const char *obj_filename, file_reader_callback file_reader,
unsigned int flags) {
LineInfo *line_infos = NULL;
Command *commands = NULL;

+ 8
- 11
src/models.c View File

@ -898,10 +898,8 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
{
tinyobj_material_t *mats = NULL;
int result = tinyobj_parse_mtl_file(&mats, &count, fileName);
if (result != TINYOBJ_SUCCESS) {
TRACELOG(LOG_WARNING, "MATERIAL: [%s] Failed to parse materials file", fileName);
}
int result = tinyobj_parse_mtl_file(&mats, &count, fileName, NULL, NULL);
if (result != TINYOBJ_SUCCESS) TRACELOG(LOG_WARNING, "MATERIAL: [%s] Failed to parse materials file", fileName);
// TODO: Process materials to return
@ -2999,8 +2997,10 @@ static Model LoadOBJ(const char *fileName)
// count the faces for each material
int* matFaces = RL_CALLOC(meshCount, sizeof(int));
for (int mi=0; mi<meshCount; mi++) {
for (int fi=0; fi<meshes[mi].length; fi++) {
for (int mi=0; mi<meshCount; mi++)
{
for (int fi=0; fi<meshes[mi].length; 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)
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
if (materials[m].diffuse_texname != NULL) {
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();
}
if (materials[m].diffuse_texname != NULL) 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();
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;

Loading…
Cancel
Save