Merge pull request #14874 from sabrina-shanman/bug_no-normal-textures

(case 21076) Fix missing normal textures on models (RC80)
This commit is contained in:
Shannon Romano 2019-02-08 11:19:22 -08:00 committed by GitHub
commit a78b83c1dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,17 @@
#include "ModelMath.h" #include "ModelMath.h"
bool needTangents(const hfm::Mesh& mesh, const QHash<QString, hfm::Material>& materials) {
// Check if we actually need to calculate the tangents
for (const auto& meshPart : mesh.parts) {
auto materialIt = materials.find(meshPart.materialID);
if (materialIt != materials.end() && (*materialIt).needTangentSpace()) {
return true;
}
}
return false;
}
void CalculateMeshTangentsTask::run(const baker::BakeContextPointer& context, const Input& input, Output& output) { void CalculateMeshTangentsTask::run(const baker::BakeContextPointer& context, const Input& input, Output& output) {
const auto& normalsPerMesh = input.get0(); const auto& normalsPerMesh = input.get0();
const std::vector<hfm::Mesh>& meshes = input.get1(); const std::vector<hfm::Mesh>& meshes = input.get1();
@ -28,29 +39,10 @@ void CalculateMeshTangentsTask::run(const baker::BakeContextPointer& context, co
auto& tangentsOut = tangentsPerMeshOut[tangentsPerMeshOut.size()-1]; auto& tangentsOut = tangentsPerMeshOut[tangentsPerMeshOut.size()-1];
// Check if we already have tangents and therefore do not need to do any calculation // Check if we already have tangents and therefore do not need to do any calculation
// Otherwise confirm if we have the normals needed, and need to calculate the tangents
if (!tangentsIn.empty()) { if (!tangentsIn.empty()) {
tangentsOut = tangentsIn.toStdVector(); tangentsOut = tangentsIn.toStdVector();
continue; } else if (!normals.empty() && needTangents(mesh, materials)) {
}
// Check if we have normals, and if not then tangents can't be calculated
if (normals.empty()) {
continue;
}
// Check if we actually need to calculate the tangents
bool needTangents = false;
for (const auto& meshPart : mesh.parts) {
auto materialIt = materials.find(meshPart.materialID);
if (materialIt != materials.end() && (*materialIt).needTangentSpace()) {
needTangents = true;
break;
}
}
if (needTangents) {
continue;
}
tangentsOut.resize(normals.size()); tangentsOut.resize(normals.size());
baker::calculateTangents(mesh, baker::calculateTangents(mesh,
[&mesh, &normals, &tangentsOut](int firstIndex, int secondIndex, glm::vec3* outVertices, glm::vec2* outTexCoords, glm::vec3& outNormal) { [&mesh, &normals, &tangentsOut](int firstIndex, int secondIndex, glm::vec3* outVertices, glm::vec2* outTexCoords, glm::vec3& outNormal) {
@ -62,4 +54,5 @@ void CalculateMeshTangentsTask::run(const baker::BakeContextPointer& context, co
return &(tangentsOut[firstIndex]); return &(tangentsOut[firstIndex]);
}); });
} }
}
} }