Skip to content

Commit

Permalink
Merge pull request #641 from zeux/obj-mtl
Browse files Browse the repository at this point in the history
gltfpack: Warn when some materials could not be loaded from the .obj/.mtl
  • Loading branch information
zeux authored Dec 16, 2023
2 parents 95a6336 + 37c2334 commit e47e1be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extern/fast_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ typedef struct
float d; /* Disolve (alpha) */
int illum; /* Illumination model */

/* Set for materials that don't come from the associated mtllib */
int fallback;

/* Texture maps */
fastObjTexture map_Ka;
fastObjTexture map_Kd;
Expand Down Expand Up @@ -872,6 +875,8 @@ fastObjMaterial mtl_default(void)
mtl.d = 1.0;
mtl.illum = 1;

mtl.fallback = 0;

mtl.map_Ka = map_default();
mtl.map_Kd = map_default();
mtl.map_Ks = map_default();
Expand Down Expand Up @@ -919,6 +924,7 @@ const char* parse_usemtl(fastObjData* data, const char* ptr)
{
fastObjMaterial new_mtl = mtl_default();
new_mtl.name = string_copy(s, e);
new_mtl.fallback = 1;
array_push(data->mesh->materials, new_mtl);
}

Expand Down
7 changes: 7 additions & 0 deletions gltf/parseobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ cgltf_data* parseObj(const char* path, std::vector<Mesh>& meshes, const char** e
return NULL;
}

int fallback_materials = 0;
for (unsigned int mi = 0; mi < obj->material_count; ++mi)
fallback_materials += obj->materials[mi].fallback;

if (fallback_materials)
fprintf(stderr, "Warning: %d/%d materials could not be loaded from mtllib\n", fallback_materials, obj->material_count);

cgltf_data* data = (cgltf_data*)calloc(1, sizeof(cgltf_data));
data->memory.free_func = defaultFree;

Expand Down

0 comments on commit e47e1be

Please sign in to comment.