Skip to content

Commit

Permalink
Prevent loading lightmaps if mesh is a glb file
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Oct 4, 2023
1 parent 0e866d8 commit fd64d7e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
this->GenerateTextureName(_scene, assimpMat, "Roughness"));
pbr.SetRoughnessMap(texName, texData);
}
// Load lightmap only if it is not a glb/glTF mesh that contains a
// MetallicRoughness texture
// It was found that lightmap field just stores the entire MetallicRoughness
// texture. Issues were also reported in assimp:
// https://github.com/assimp/assimp/issues/3120
// https://github.com/assimp/assimp/issues/4637
unsigned int uvIdx = 0;
ret = assimpMat->GetTexture(
aiTextureType_LIGHTMAP, 0, &texturePath, NULL, &uvIdx);
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Lightmap"));
pbr.SetLightMap(texName, uvIdx, texData);
}
}
#endif
ret = assimpMat->GetTexture(aiTextureType_NORMALS, 0, &texturePath);
Expand All @@ -442,15 +457,6 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
this->GenerateTextureName(_scene, assimpMat, "Emissive"));
pbr.SetEmissiveMap(texName, texData);
}
unsigned int uvIdx = 0;
ret = assimpMat->GetTexture(
aiTextureType_LIGHTMAP, 0, &texturePath, NULL, &uvIdx);
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Lightmap"));
pbr.SetLightMap(texName, uvIdx, texData);
}
#ifndef GZ_ASSIMP_PRE_5_2_0
float value;
ret = assimpMat->Get(AI_MATKEY_METALLIC_FACTOR, value);
Expand Down

0 comments on commit fd64d7e

Please sign in to comment.