From 1afe7e625585557a38ec0ac51075ed4e52903ba8 Mon Sep 17 00:00:00 2001 From: "Vyacheslav.Vanin" Date: Thu, 16 Dec 2021 12:09:06 +0300 Subject: [PATCH 1/8] fix fbx import metalness Can't import metalness textures in fbx importer --- code/AssetLib/FBX/FBXConverter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 5a3ae0ae7..b1be6ed37 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -2070,6 +2070,7 @@ void FBXConverter::SetTextureProperties(aiMaterial *out_mat, const LayeredTextur TrySetTextureProperties(out_mat, layeredTextures, "ShininessExponent", aiTextureType_SHININESS, mesh); TrySetTextureProperties(out_mat, layeredTextures, "EmissiveFactor", aiTextureType_EMISSIVE, mesh); TrySetTextureProperties(out_mat, layeredTextures, "TransparencyFactor", aiTextureType_OPACITY, mesh); + TrySetTextureProperties(out_mat, layeredTextures, "ReflectionFactor", aiTextureType_METALNESS, mesh); } aiColor3D FBXConverter::GetColorPropertyFactored(const PropertyTable &props, const std::string &colorName, From 2eb86d75b86baff7c81b3dcb53de9a6c47dea5f8 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 22 Dec 2021 19:45:19 +0100 Subject: [PATCH 2/8] Make sure no overflow can happen - During UTF32 LE with BOM make sure that the byteswap operation will have enough space when iterating through the text buffer, which shall get encoded. - closes https://github.com/assimp/assimp/issues/4230 --- code/Common/BaseImporter.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index d7e24afab..c0a87b632 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -65,6 +65,7 @@ using namespace Assimp; // Constructor to be privately used by Importer BaseImporter::BaseImporter() AI_NO_EXCEPT : m_progress() { + // empty } // ------------------------------------------------------------------------------------------------ @@ -371,11 +372,16 @@ void BaseImporter::ConvertToUTF8(std::vector &data) { } // UTF 16 BE with BOM + size_t index = 0; if (*((uint16_t *)&data.front()) == 0xFFFE) { - // swap the endianness .. for (uint16_t *p = (uint16_t *)&data.front(), *end = (uint16_t *)&data.back(); p <= end; ++p) { - ByteSwap::Swap2(p); + // Check to ensure no overflow can happen + if ((index+2) < data.Size()) { + // Swap the data + ByteSwap::Swap2(p); + index += 2; + } } } From 215f4e1f4dcca57f1dee9f18519df1af659ad62c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 22 Dec 2021 20:02:29 +0100 Subject: [PATCH 3/8] Fix typo --- code/Common/BaseImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index c0a87b632..570ba7f7b 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -377,7 +377,7 @@ void BaseImporter::ConvertToUTF8(std::vector &data) { // swap the endianness .. for (uint16_t *p = (uint16_t *)&data.front(), *end = (uint16_t *)&data.back(); p <= end; ++p) { // Check to ensure no overflow can happen - if ((index+2) < data.Size()) { + if ((index+2) < data.size()) { // Swap the data ByteSwap::Swap2(p); index += 2; From 2c66d4d3a2c7b9b6c74f38c8a4ef847f4e624740 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 22 Dec 2021 20:43:44 +0100 Subject: [PATCH 4/8] Optimize the check --- code/Common/BaseImporter.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 570ba7f7b..82b8f12fc 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -372,16 +372,14 @@ void BaseImporter::ConvertToUTF8(std::vector &data) { } // UTF 16 BE with BOM - size_t index = 0; if (*((uint16_t *)&data.front()) == 0xFFFE) { + // Check to ensure no overflow can happen + if(data.size() % 2 != 0) { + return; + } // swap the endianness .. for (uint16_t *p = (uint16_t *)&data.front(), *end = (uint16_t *)&data.back(); p <= end; ++p) { - // Check to ensure no overflow can happen - if ((index+2) < data.size()) { - // Swap the data - ByteSwap::Swap2(p); - index += 2; - } + ByteSwap::Swap2(p); } } From 635153b3a4d5e203e446f0b1f547365f7c2769c4 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 22 Dec 2021 21:08:28 +0100 Subject: [PATCH 5/8] LWS-Import: Avoid access to empty string token - Fix invalid access to string pointer when string token is empty - closes https://github.com/assimp/assimp/issues/4222 --- code/AssetLib/LWS/LWSLoader.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/AssetLib/LWS/LWSLoader.cpp b/code/AssetLib/LWS/LWSLoader.cpp index cb07787fa..cf04579b0 100644 --- a/code/AssetLib/LWS/LWSLoader.cpp +++ b/code/AssetLib/LWS/LWSLoader.cpp @@ -537,6 +537,11 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy // get file format version and print to log ++it; + + if ((*it).tokens[0].empty()) { + ASSIMP_LOG_ERROR("Invalid LWS file detectedm abort import."); + return; + } unsigned int version = strtoul10((*it).tokens[0].c_str()); ASSIMP_LOG_INFO("LWS file format version is ", (*it).tokens[0]); first = 0.; From db2500c39341f8169ffd4fbd2e26cd4aee293437 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 23 Dec 2021 12:28:43 +0100 Subject: [PATCH 6/8] MDL: Do not try to copy empty embedded texture - When an embedded texture is empty, skip it instead of trying to copy it. This must fail. - closes https://github.com/assimp/assimp/issues/4238 - Found from the Google fuzzer. --- code/AssetLib/MDL/MDLMaterialLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/MDL/MDLMaterialLoader.cpp b/code/AssetLib/MDL/MDLMaterialLoader.cpp index 62320814a..4f441a054 100644 --- a/code/AssetLib/MDL/MDLMaterialLoader.cpp +++ b/code/AssetLib/MDL/MDLMaterialLoader.cpp @@ -463,8 +463,12 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7( ASSIMP_LOG_WARN("Found a reference to an embedded DDS texture, " "but texture height is not equal to 1, which is not supported by MED"); } - - pcNew.reset(new aiTexture()); + if (iWidth == 0) { + ASSIMP_LOG_ERROR("Found a reference to an embedded DDS texture, but texture width is zero, aborting import."); + return; + } + + pcNew.reset(new aiTexture); pcNew->mHeight = 0; pcNew->mWidth = iWidth; From d44641398fff18f151d5f7d986736b7d5b0450d5 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 26 Dec 2021 11:16:02 +0100 Subject: [PATCH 7/8] Add console progresshandler --- code/Common/DefaultProgressHandler.h | 17 ++++++++------- code/Common/Importer.cpp | 2 +- include/assimp/ProgressHandler.hpp | 1 + tools/assimp_cmd/Main.cpp | 31 ++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/code/Common/DefaultProgressHandler.h b/code/Common/DefaultProgressHandler.h index 4626204af..ebf4a0e74 100644 --- a/code/Common/DefaultProgressHandler.h +++ b/code/Common/DefaultProgressHandler.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -48,18 +47,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -namespace Assimp { +namespace Assimp { // ------------------------------------------------------------------------------------ -/** @brief Internal default implementation of the #ProgressHandler interface. */ +/** + * @brief Internal default implementation of the #ProgressHandler interface. + */ class DefaultProgressHandler : public ProgressHandler { - - virtual bool Update(float /*percentage*/) { +public: + /// @brief Ignores the update callback. + bool Update(float) override { return false; } +}; - -}; // !class DefaultProgressHandler } // Namespace Assimp -#endif +#endif // INCLUDED_AI_DEFAULTPROGRESSHANDLER_H diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index 41b73fd12..2f9c23bec 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -329,7 +329,7 @@ bool Importer::IsDefaultIOHandler() const { // ------------------------------------------------------------------------------------------------ // Supplies a custom progress handler to get regular callbacks during importing -void Importer::SetProgressHandler ( ProgressHandler* pHandler ) { +void Importer::SetProgressHandler(ProgressHandler* pHandler) { ai_assert(nullptr != pimpl); ASSIMP_BEGIN_EXCEPTION_REGION(); diff --git a/include/assimp/ProgressHandler.hpp b/include/assimp/ProgressHandler.hpp index a42015400..40661fba8 100644 --- a/include/assimp/ProgressHandler.hpp +++ b/include/assimp/ProgressHandler.hpp @@ -74,6 +74,7 @@ protected: public: /// @brief Virtual destructor. virtual ~ProgressHandler () { + // empty } // ------------------------------------------------------------------- diff --git a/tools/assimp_cmd/Main.cpp b/tools/assimp_cmd/Main.cpp index 8d76e1f5e..87467579f 100644 --- a/tools/assimp_cmd/Main.cpp +++ b/tools/assimp_cmd/Main.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2021, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -47,6 +45,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Main.h" +#include +#include + +class ConsoleProgressHandler : public ProgressHandler { +public: + ConsoleProgressHandler() : + ProgressHandler() { + // empty + } + + ~ConsoleProgressHandler() override { + // empty + } + + bool Update(float percentage) override { + std::cout << percentage * 100.0f << " %\n"; + return true; + } +}; const char* AICMD_MSG_ABOUT = "------------------------------------------------------ \n" "Open Asset Import Library (\"Assimp\", https://github.com/assimp/assimp) \n" @@ -73,10 +90,10 @@ const char* AICMD_MSG_HELP = "\n Use \'assimp --help\' for detailed help on a command.\n" ; -/*extern*/ Assimp::Importer* globalImporter = NULL; +/*extern*/ Assimp::Importer* globalImporter = nullptr; #ifndef ASSIMP_BUILD_NO_EXPORT -/*extern*/ Assimp::Exporter* globalExporter = NULL; +/*extern*/ Assimp::Exporter* globalExporter = nullptr; #endif // ------------------------------------------------------------------------------ @@ -286,6 +303,9 @@ const aiScene* ImportModel( // do the actual import, measure time const clock_t first = clock(); + ConsoleProgressHandler *ph = new ConsoleProgressHandler; + globalImporter->SetProgressHandler(ph); + const aiScene* scene = globalImporter->ReadFile(path,imp.ppFlags); if (imp.showLog) { @@ -305,6 +325,9 @@ const aiScene* ImportModel( if (imp.log) { FreeLogStreams(); } + globalImporter->SetProgressHandler(nullptr); + delete ph; + return scene; } From 81fc50f6122bbc445fc1aef9c9238e613b9f2186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Tue, 28 Dec 2021 14:59:37 +0100 Subject: [PATCH 8/8] CMake: Replace CMAKE_COMPILER_IS_MINGW by MINGW See https://discourse.cmake.org/t/cmake-compiler-is-mingw-removed/4539 and https://cmake.org/cmake/help/latest/variable/MINGW.html --- CMakeLists.txt | 4 ++-- code/CMakeLists.txt | 4 ++-- contrib/android-cmake/android.toolchain.cmake | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 570c29305..13b2ef936 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,7 +246,7 @@ IF( UNIX ) ENDIF() # Grouped compiler settings ######################################## -IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT CMAKE_COMPILER_IS_MINGW) +IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT MINGW) IF(NOT ASSIMP_HUNTER_ENABLED) SET(CMAKE_CXX_STANDARD 11) SET(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -283,7 +283,7 @@ ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) ENDIF() SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long ${CMAKE_CXX_FLAGS}" ) SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}") -ELSEIF( CMAKE_COMPILER_IS_MINGW ) +ELSEIF( MINGW ) IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) message(FATAL_ERROR "MinGW is too old to be supported. Please update MinGW and try again.") ELSEIF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 1af9407d2..08efd28df 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -557,7 +557,7 @@ ADD_ASSIMP_IMPORTER( IFC if (ASSIMP_BUILD_IFC_IMPORTER) if (MSVC) set_source_files_properties(Importer/IFC/IFCReaderGen1_2x3.cpp Importer/IFC/IFCReaderGen2_2x3.cpp PROPERTIES COMPILE_FLAGS "/bigobj") - elseif(CMAKE_COMPILER_IS_MINGW) + elseif(MINGW) set_source_files_properties(Importer/IFC/IFCReaderGen1_2x3.cpp Importer/IFC/IFCReaderGen2_2x3.cpp PROPERTIES COMPILE_FLAGS "-O2 -Wa,-mbig-obj") endif() endif () @@ -862,7 +862,7 @@ ADD_ASSIMP_IMPORTER( MMD # optimizations that take up extra space. Given that the issue is a string table overflowing, -Os seemed appropriate # Also, I'm not positive if both link & compile flags are needed, but this hopefully ensures that the issue should not # recur for edge cases such as static builds. -if ((CMAKE_COMPILER_IS_MINGW) AND (CMAKE_BUILD_TYPE MATCHES Debug)) +if ((MINGW) AND (CMAKE_BUILD_TYPE MATCHES Debug)) message("-- Applying MinGW StepFileGen1.cpp Debug Workaround") SET_SOURCE_FILES_PROPERTIES(Importer/StepFile/StepFileGen1.cpp PROPERTIES COMPILE_FLAGS -Os ) SET_SOURCE_FILES_PROPERTIES(Importer/StepFile/StepFileGen1.cpp PROPERTIES LINK_FLAGS -Os ) diff --git a/contrib/android-cmake/android.toolchain.cmake b/contrib/android-cmake/android.toolchain.cmake index ffa26126a..c2b8a0730 100644 --- a/contrib/android-cmake/android.toolchain.cmake +++ b/contrib/android-cmake/android.toolchain.cmake @@ -1616,6 +1616,7 @@ endif() if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) # it is a bad hack after all # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW + set( MINGW TRUE ) # tell CMake that we are MinGW set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion enable_language( C )