From 8701a86c9d474bc07c2eceec72074bda98a3b128 Mon Sep 17 00:00:00 2001 From: Jean-Louis Boudrand Date: Thu, 10 Dec 2020 23:47:54 +0100 Subject: [PATCH 1/5] Fixed a crash of the Gltf 2 exporter in the case of an animation without a translation, rotation or scale animation key. --- code/AssetLib/glTF2/glTF2Exporter.cpp | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 637808877..5852dfc01 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1258,9 +1258,6 @@ inline Ref GetSamplerInputRef(Asset& asset, std::string& animId, Ref& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond, Animation::Sampler& sampler) { const unsigned int numKeyframes = nodeChannel->mNumPositionKeys; - if (numKeyframes == 0) { - return; - } std::vector times(numKeyframes); std::vector values(numKeyframes * 3); @@ -1281,9 +1278,6 @@ inline void ExtractTranslationSampler(Asset& asset, std::string& animId, Ref& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond, Animation::Sampler& sampler) { const unsigned int numKeyframes = nodeChannel->mNumScalingKeys; - if (numKeyframes == 0) { - return; - } std::vector times(numKeyframes); std::vector values(numKeyframes * 3); @@ -1304,9 +1298,6 @@ inline void ExtractScaleSampler(Asset& asset, std::string& animId, Ref& inline void ExtractRotationSampler(Asset& asset, std::string& animId, Ref& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond, Animation::Sampler& sampler) { const unsigned int numKeyframes = nodeChannel->mNumRotationKeys; - if (numKeyframes == 0) { - return; - } std::vector times(numKeyframes); std::vector values(numKeyframes * 4); @@ -1359,17 +1350,26 @@ void glTF2Exporter::ExportAnimations() Ref animNode = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str()); - Animation::Sampler translationSampler; - ExtractTranslationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, translationSampler); - AddSampler(animRef, animNode, translationSampler, AnimationPath_TRANSLATION); + if (nodeChannel->mNumPositionKeys > 0) + { + Animation::Sampler translationSampler; + ExtractTranslationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, translationSampler); + AddSampler(animRef, animNode, translationSampler, AnimationPath_TRANSLATION); + } - Animation::Sampler rotationSampler; - ExtractRotationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, rotationSampler); - AddSampler(animRef, animNode, rotationSampler, AnimationPath_ROTATION); + if (nodeChannel->mNumRotationKeys > 0) + { + Animation::Sampler rotationSampler; + ExtractRotationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, rotationSampler); + AddSampler(animRef, animNode, rotationSampler, AnimationPath_ROTATION); + } - Animation::Sampler scaleSampler; - ExtractScaleSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, scaleSampler); - AddSampler(animRef, animNode, scaleSampler, AnimationPath_SCALE); + if (nodeChannel->mNumScalingKeys > 0) + { + Animation::Sampler scaleSampler; + ExtractScaleSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, scaleSampler); + AddSampler(animRef, animNode, scaleSampler, AnimationPath_SCALE); + } } // Assimp documentation staes this is not used (not implemented) From e2af015a57a276e4bca23f03cc26e947a582e9d0 Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Fri, 11 Dec 2020 21:43:09 +0530 Subject: [PATCH 2/5] Common: Fix GCC error invalid conversion in MINGW. --- code/CMakeLists.txt | 2 +- code/Common/ZipArchiveIOSystem.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index bb83a5f97..7a017cfa4 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -1015,7 +1015,7 @@ ENDIF() # RT-extensions is used in "contrib/Open3DGC/o3dgcTimer.h" for collecting statistics. Pointed file # has implementation for different platforms: WIN32, __MACH__ and other ("else" block). FIND_PACKAGE(RT QUIET) -IF (NOT ASSIMP_HUNTER_ENABLED AND (RT_FOUND OR MSVC)) +IF (NOT ASSIMP_HUNTER_ENABLED AND (RT_FOUND OR WIN32)) SET( ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC 1 ) ADD_DEFINITIONS( -DASSIMP_IMPORTER_GLTF_USE_OPEN3DGC=1 ) ELSE () diff --git a/code/Common/ZipArchiveIOSystem.cpp b/code/Common/ZipArchiveIOSystem.cpp index f55f9ff53..6cd50739e 100644 --- a/code/Common/ZipArchiveIOSystem.cpp +++ b/code/Common/ZipArchiveIOSystem.cpp @@ -146,7 +146,7 @@ int IOSystem2Unzip::testerror(voidpf /*opaque*/, voidpf /*stream*/) { zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) { zlib_filefunc_def mapping; -#ifdef ASSIMP_USE_HUNTER +#if defined (ASSIMP_USE_HUNTER) || defined (__MINGW32__) // GH#3144 mapping.zopen_file = (open_file_func)open; mapping.zread_file = (read_file_func)read; mapping.zwrite_file = (write_file_func)write; @@ -335,7 +335,7 @@ ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFile if (pFilename[0] == 0 || nullptr == pMode) { return; } - + zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler); m_ZipFileHandle = unzOpen2(pFilename, &mapping); } From c65f2cb3fbd7dd66474ea8821fba0080f144f33d Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Sat, 12 Dec 2020 11:15:04 +0530 Subject: [PATCH 3/5] Remove extra semicolon while GCC being pedantic. --- code/AssetLib/Collada/ColladaHelper.cpp | 4 ++-- contrib/Open3DGC/o3dgcVector.inl | 4 ++-- .../SimpleTexturedOpenGL/src/model_loading.cpp | 2 +- tools/assimp_view/MeshRenderer.cpp | 2 +- tools/assimp_view/MessageProc.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/code/AssetLib/Collada/ColladaHelper.cpp b/code/AssetLib/Collada/ColladaHelper.cpp index 0a779e04e..1a4bed3b1 100644 --- a/code/AssetLib/Collada/ColladaHelper.cpp +++ b/code/AssetLib/Collada/ColladaHelper.cpp @@ -53,7 +53,7 @@ const MetaKeyPairVector MakeColladaAssimpMetaKeys() { result.emplace_back("authoring_tool", AI_METADATA_SOURCE_GENERATOR); result.emplace_back("copyright", AI_METADATA_SOURCE_COPYRIGHT); return result; -}; +} const MetaKeyPairVector &GetColladaAssimpMetaKeys() { static const MetaKeyPairVector result = MakeColladaAssimpMetaKeys(); @@ -66,7 +66,7 @@ const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() { ToCamelCase(val.first); } return result; -}; +} const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase() { static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase(); diff --git a/contrib/Open3DGC/o3dgcVector.inl b/contrib/Open3DGC/o3dgcVector.inl index 5549b00ce..de8dfd5f1 100644 --- a/contrib/Open3DGC/o3dgcVector.inl +++ b/contrib/Open3DGC/o3dgcVector.inl @@ -175,7 +175,7 @@ namespace o3dgc m_data[2] = rhs.m_data[2]; } template - inline Vec3::~Vec3(void){}; + inline Vec3::~Vec3(void){} template inline Vec3::Vec3() {} @@ -308,7 +308,7 @@ namespace o3dgc m_data[1] = rhs.m_data[1]; } template - inline Vec2::~Vec2(void){}; + inline Vec2::~Vec2(void){} template inline Vec2::Vec2() {} diff --git a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp index a36c792d4..aa2344118 100644 --- a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp +++ b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp @@ -763,7 +763,7 @@ void cleanup() if (g_hWnd) KillGLWindow(); -}; +} LRESULT CALLBACK WndProc(HWND hWnd, // Handles for this Window UINT uMsg, // Message for this Window diff --git a/tools/assimp_view/MeshRenderer.cpp b/tools/assimp_view/MeshRenderer.cpp index d93bb4aea..972b3db24 100644 --- a/tools/assimp_view/MeshRenderer.cpp +++ b/tools/assimp_view/MeshRenderer.cpp @@ -161,4 +161,4 @@ int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld) { return 1; } -}; +} diff --git a/tools/assimp_view/MessageProc.cpp b/tools/assimp_view/MessageProc.cpp index 80589e647..cebb78e22 100644 --- a/tools/assimp_view/MessageProc.cpp +++ b/tools/assimp_view/MessageProc.cpp @@ -2143,7 +2143,7 @@ INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg, } return FALSE; } -}; +} using namespace AssimpView; From d18fce3f0695173c25f855c823d0e23701257f73 Mon Sep 17 00:00:00 2001 From: Jean-Louis Boudrand Date: Sun, 13 Dec 2020 17:02:50 +0100 Subject: [PATCH 4/5] Fix https://github.com/assimp/assimp/issues/3054 Corrected the animation of each bone of an animation were exported in different animations (+tabs fixes) --- code/AssetLib/glTF2/glTF2Exporter.cpp | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 5852dfc01..6ebb54568 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1338,38 +1338,36 @@ void glTF2Exporter::ExportAnimations() if (anim->mName.length > 0) { nameAnim = anim->mName.C_Str(); } + Ref animRef = mAsset->animations.Create(nameAnim); for (unsigned int channelIndex = 0; channelIndex < anim->mNumChannels; ++channelIndex) { const aiNodeAnim* nodeChannel = anim->mChannels[channelIndex]; - // It appears that assimp stores this type of animation as multiple animations. - // where each aiNodeAnim in mChannels animates a specific node. std::string name = nameAnim + "_" + to_string(channelIndex); name = mAsset->FindUniqueID(name, "animation"); - Ref animRef = mAsset->animations.Create(name); Ref animNode = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str()); if (nodeChannel->mNumPositionKeys > 0) { - Animation::Sampler translationSampler; - ExtractTranslationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, translationSampler); - AddSampler(animRef, animNode, translationSampler, AnimationPath_TRANSLATION); - } + Animation::Sampler translationSampler; + ExtractTranslationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, translationSampler); + AddSampler(animRef, animNode, translationSampler, AnimationPath_TRANSLATION); + } if (nodeChannel->mNumRotationKeys > 0) { - Animation::Sampler rotationSampler; - ExtractRotationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, rotationSampler); - AddSampler(animRef, animNode, rotationSampler, AnimationPath_ROTATION); - } + Animation::Sampler rotationSampler; + ExtractRotationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, rotationSampler); + AddSampler(animRef, animNode, rotationSampler, AnimationPath_ROTATION); + } if (nodeChannel->mNumScalingKeys > 0) { - Animation::Sampler scaleSampler; - ExtractScaleSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, scaleSampler); - AddSampler(animRef, animNode, scaleSampler, AnimationPath_SCALE); - } + Animation::Sampler scaleSampler; + ExtractScaleSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, scaleSampler); + AddSampler(animRef, animNode, scaleSampler, AnimationPath_SCALE); + } } // Assimp documentation staes this is not used (not implemented) From 4e9176d2cdadc094228a5a24a5716340e25192b5 Mon Sep 17 00:00:00 2001 From: wasd845 <845073947@qq.com> Date: Mon, 14 Dec 2020 19:16:29 +0800 Subject: [PATCH 5/5] _dest may be destructed twice if _dest is not null in MergeScenes() --- code/Common/SceneCombiner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index bfc4899a1..193586a7c 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -183,9 +183,10 @@ void SceneCombiner::MergeScenes(aiScene **_dest, std::vector &src, un *_dest = src[0]; return; } - if (*_dest) + if (*_dest) { (*_dest)->~aiScene(); - else + new (*_dest) aiScene(); + } else *_dest = new aiScene(); // Create a dummy scene to serve as master for the others