Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gltfpack: Warn when some materials could not be loaded from the .obj/.mtl #641

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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