From 002d6dc016f275c6018d67367388a8d2dae4b9a0 Mon Sep 17 00:00:00 2001 From: tanolino Date: Wed, 18 May 2022 15:22:11 +0200 Subject: [PATCH 1/4] Inifinite loop on bad import files I had an import file that caused an infinite loop. I don't exactly know how this algorithm works here but maybe we should change it more. Probably calculate the amount of steps and chop linear. --- code/AssetLib/FBX/FBXConverter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 4de142075..7558c27a7 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -3325,6 +3325,10 @@ FBXConverter::KeyFrameListList FBXConverter::GetRotationKeyframeList(const std:: Keys->push_back(tnew); Values->push_back(vnew); } + else { + // Something broke + break; + } tp = tnew; vp = vnew; } From 1b53f4178768bec5d5ac2174ce35abf8ffb9bc20 Mon Sep 17 00:00:00 2001 From: Onur Berk Tore Date: Mon, 20 Jun 2022 23:46:29 +0300 Subject: [PATCH 2/4] Feature: Utilizes removeEmptyBones flag for Collada --- code/AssetLib/Collada/ColladaLoader.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 775ba44d2..3c06c8c37 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + namespace Assimp { using namespace Assimp::Formatter; @@ -102,6 +104,7 @@ ColladaLoader::ColladaLoader() : mTextures(), mAnims(), noSkeletonMesh(false), + removeEmptyBones(false), ignoreUpDirection(false), useColladaName(false), mNodeNameCounter(0) { @@ -130,6 +133,7 @@ bool ColladaLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool // ------------------------------------------------------------------------------------------------ void ColladaLoader::SetupProperties(const Importer *pImp) { noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES, 0) != 0; + removeEmptyBones = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true) != 0; ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, 0) != 0; useColladaName = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES, 0) != 0; } @@ -798,9 +802,11 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc // count the number of bones which influence vertices of the current submesh size_t numRemainingBones = 0; for (const auto & dstBone : dstBones) { - if (!dstBone.empty()) { - ++numRemainingBones; + if (dstBone.empty() && removeEmptyBones) { + continue; } + ++numRemainingBones; + } // create bone array and copy bone weights one by one @@ -809,7 +815,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc size_t boneCount = 0; for (size_t a = 0; a < numBones; ++a) { // omit bones without weights - if (dstBones[a].empty()) { + if (dstBones[a].empty() && removeEmptyBones) { continue; } @@ -828,6 +834,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc bone->mOffsetMatrix.c2 = ReadFloat(jointMatrixAcc, jointMatrices, a, 9); bone->mOffsetMatrix.c3 = ReadFloat(jointMatrixAcc, jointMatrices, a, 10); bone->mOffsetMatrix.c4 = ReadFloat(jointMatrixAcc, jointMatrices, a, 11); + bone->mNumWeights = static_cast(dstBones[a].size()); bone->mWeights = new aiVertexWeight[bone->mNumWeights]; std::copy(dstBones[a].begin(), dstBones[a].end(), bone->mWeights); @@ -1826,3 +1833,4 @@ std::string ColladaLoader::FindNameForNode(const Node *pNode) { } // Namespace Assimp #endif // !! ASSIMP_BUILD_NO_DAE_IMPORTER + From c2060a1f7e9a189db275178e65a3c1a7ced9f790 Mon Sep 17 00:00:00 2001 From: Onur Berk Tore Date: Mon, 20 Jun 2022 23:48:00 +0300 Subject: [PATCH 3/4] Deletion: Removed unnessary header --- code/AssetLib/Collada/ColladaLoader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 3c06c8c37..327319283 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -59,8 +59,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include - namespace Assimp { using namespace Assimp::Formatter; From 4f06c41802ff2dfadbeef9890eebf54433499d94 Mon Sep 17 00:00:00 2001 From: Onur Berk Tore Date: Tue, 21 Jun 2022 00:09:20 +0300 Subject: [PATCH 4/4] Fix: Collada header updated --- code/AssetLib/Collada/ColladaLoader.cpp | 3 --- code/AssetLib/Collada/ColladaLoader.h | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 327319283..fdc9c1c8f 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -804,7 +804,6 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc continue; } ++numRemainingBones; - } // create bone array and copy bone weights one by one @@ -832,7 +831,6 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc bone->mOffsetMatrix.c2 = ReadFloat(jointMatrixAcc, jointMatrices, a, 9); bone->mOffsetMatrix.c3 = ReadFloat(jointMatrixAcc, jointMatrices, a, 10); bone->mOffsetMatrix.c4 = ReadFloat(jointMatrixAcc, jointMatrices, a, 11); - bone->mNumWeights = static_cast(dstBones[a].size()); bone->mWeights = new aiVertexWeight[bone->mNumWeights]; std::copy(dstBones[a].begin(), dstBones[a].end(), bone->mWeights); @@ -1831,4 +1829,3 @@ std::string ColladaLoader::FindNameForNode(const Node *pNode) { } // Namespace Assimp #endif // !! ASSIMP_BUILD_NO_DAE_IMPORTER - diff --git a/code/AssetLib/Collada/ColladaLoader.h b/code/AssetLib/Collada/ColladaLoader.h index 246abed22..870c12a5a 100644 --- a/code/AssetLib/Collada/ColladaLoader.h +++ b/code/AssetLib/Collada/ColladaLoader.h @@ -237,6 +237,7 @@ protected: std::vector mAnims; bool noSkeletonMesh; + bool removeEmptyBones; bool ignoreUpDirection; bool useColladaName;