From 84eb9547f5391cd9aead8efc871b08d28d121e42 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Wed, 20 Feb 2019 12:17:37 -0800 Subject: [PATCH] Tangent-related fixups in MeshAssimp. Assimp's CalcTangentSpace deviates from de facto glTF 2.0 so we were compensating for this with an unconditional fixup in MeshAssimp. However the fixup should apply only when CalcTangentSpace is active, i.e. when the model is missing tangents. This makes it so that NormalTangentMirrorTest (has tangents) and NormalTangentTest (needs tangents) both look reasonable. I also noticed that MeshAssimp was inexplicably applying aiProcess_CalcTangentSpace twice: once as a flag, and once as a post-process. I removed the latter. This will be fixed in the upcoming cgltf-based loader, which will use our officially-sanctioned utility method in VertexBuffer. See #528 --- samples/app/MeshAssimp.cpp | 8 +------- third_party/libassimp/code/CalcTangentsProcess.cpp | 8 ++++---- third_party/libassimp/tnt/README.md | 4 ++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/samples/app/MeshAssimp.cpp b/samples/app/MeshAssimp.cpp index af4e8c9401..78b9b17d9a 100644 --- a/samples/app/MeshAssimp.cpp +++ b/samples/app/MeshAssimp.cpp @@ -648,8 +648,6 @@ bool MeshAssimp::setFromFile(Asset& asset, std::map::packTangentFrame({tangent, bitangent, normal}); diff --git a/third_party/libassimp/code/CalcTangentsProcess.cpp b/third_party/libassimp/code/CalcTangentsProcess.cpp index 54e55fc5a7..a25fbb27c8 100644 --- a/third_party/libassimp/code/CalcTangentsProcess.cpp +++ b/third_party/libassimp/code/CalcTangentsProcess.cpp @@ -196,14 +196,14 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) } // tangent points in the direction where to positive X axis of the texture coord's would point in model space - // bitangent's points along the positive Y axis of the texture coord's, respectively + // bitangent's points along the negative Y axis of the texture coord's, respectively aiVector3D tangent, bitangent; tangent.x = (w.x * sy - v.x * ty) * dirCorrection; tangent.y = (w.y * sy - v.y * ty) * dirCorrection; tangent.z = (w.z * sy - v.z * ty) * dirCorrection; - bitangent.x = (w.x * sx - v.x * tx) * dirCorrection; - bitangent.y = (w.y * sx - v.y * tx) * dirCorrection; - bitangent.z = (w.z * sx - v.z * tx) * dirCorrection; + bitangent.x = (v.x * tx - w.x * sx) * dirCorrection; + bitangent.y = (v.y * tx - w.y * sx) * dirCorrection; + bitangent.z = (v.z * tx - w.z * sx) * dirCorrection; // store for every vertex of that face for( unsigned int b = 0; b < face.mNumIndices; ++b ) { diff --git a/third_party/libassimp/tnt/README.md b/third_party/libassimp/tnt/README.md index 9eae75e58c..e14adb70e4 100644 --- a/third_party/libassimp/tnt/README.md +++ b/third_party/libassimp/tnt/README.md @@ -29,3 +29,7 @@ In glTF2Importer.cpp, change from: ai_anim->mNumChannels = r.skins[0].jointNames.size(); to: ai_anim->mNumChannels = r.skins.Size() > 0 ? r.skins[0].jointNames.size() : 0; + +(2) + +Negate the bitangent in CalcTangentsProcess.cpp