mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-30 14:22:56 +02:00
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:
commit
a78b83c1dd
1 changed files with 23 additions and 30 deletions
|
@ -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) {
|
||||||
|
@ -63,3 +55,4 @@ void CalculateMeshTangentsTask::run(const baker::BakeContextPointer& context, co
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue