Skip to content

Commit

Permalink
fix uv-triangles with untextured materials causing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenwave committed Feb 6, 2021
1 parent 82bef62 commit fa04c50
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,23 @@ VoxelMap<WeightedColor> voxelizeObj(VoxelizationArgs args)
}
}
else if (hasTexCoords) {
const std::string &textureName = materials[static_cast<usize>(materialIndex)].diffuse_texname;
const tinyobj::material_t &material = materials[static_cast<usize>(materialIndex)];
const std::string &textureName = material.diffuse_texname;
if (textureName.empty()) {
goto untextured;
}
auto location = voxelizer.textures.find(textureName);
if (location == voxelizer.textures.end()) {
VXIO_LOG(ERROR, "Face has invalid texture name \"" + textureName + '"');
VXIO_LOG(ERROR,
"Face with material \"" + material.name + "\" has unloaded texture name \"" + textureName +
'"');
std::exit(1);
}
triangle.texture = &location->second;
triangle.type = TriangleType::TEXTURED;
}
else {
untextured:
Vec3 color{materials[static_cast<usize>(materialIndex)].diffuse};
triangle.color = color.cast<float>();
triangle.type = TriangleType::UNTEXTURED;
Expand Down

0 comments on commit fa04c50

Please sign in to comment.