From 32c8ca0a37fd701b0b8824604b01ba2bc8e7ebd4 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Thu, 3 Mar 2011 11:36:22 +0000 Subject: [PATCH] # PretransformVertices step now (re-)normalizes normals and tangents after applying transformations on them. See [https://sourceforge.net/projects/assimp/forums/forum/817653/topic/4378272?message=9501683]. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@912 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/PretransformVertices.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 16afd0eb9..ccd148677 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -196,15 +196,15 @@ void PretransformVertices::CollectData( aiScene* pcScene, aiNode* pcNode, unsign // copy normals, transform them to worldspace for (unsigned int n = 0; n < pcMesh->mNumVertices;++n) { pcMeshOut->mNormals[aiCurrent[AI_PTVS_VERTEX]+n] = - m * pcMesh->mNormals[n]; + (m * pcMesh->mNormals[n]).Normalize(); } } if (iVFormat & 0x4) { // copy tangents and bitangents, transform them to worldspace for (unsigned int n = 0; n < pcMesh->mNumVertices;++n) { - pcMeshOut->mTangents [aiCurrent[AI_PTVS_VERTEX]+n] = m * pcMesh->mTangents[n]; - pcMeshOut->mBitangents[aiCurrent[AI_PTVS_VERTEX]+n] = m * pcMesh->mBitangents[n]; + pcMeshOut->mTangents [aiCurrent[AI_PTVS_VERTEX]+n] = (m * pcMesh->mTangents[n]).Normalize(); + pcMeshOut->mBitangents[aiCurrent[AI_PTVS_VERTEX]+n] = (m * pcMesh->mBitangents[n]).Normalize(); } } } @@ -334,13 +334,13 @@ void PretransformVertices::ApplyTransform(aiMesh* mesh, const aiMatrix4x4& mat) if (mesh->HasNormals()) { for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { - mesh->mNormals[i] = m * mesh->mNormals[i]; + mesh->mNormals[i] = (m * mesh->mNormals[i]).Normalize(); } } if (mesh->HasTangentsAndBitangents()) { for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { - mesh->mTangents[i] = m * mesh->mTangents[i]; - mesh->mBitangents[i] = m * mesh->mBitangents[i]; + mesh->mTangents[i] = (m * mesh->mTangents[i]).Normalize(); + mesh->mBitangents[i] = (m * mesh->mBitangents[i]).Normalize(); } } }