From d04df3e7c52e5566c30875236567a1656b365d9f Mon Sep 17 00:00:00 2001 From: Inho Lee Date: Fri, 14 Feb 2020 08:41:55 +0100 Subject: [PATCH 01/30] A bug when importing multiple gltf files meshOffsets are not cleared when importing multiple gltf files --- code/glTF/glTFImporter.cpp | 1 + code/glTF2/glTF2Importer.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/code/glTF/glTFImporter.cpp b/code/glTF/glTFImporter.cpp index 16addc977..b410e1002 100644 --- a/code/glTF/glTFImporter.cpp +++ b/code/glTF/glTFImporter.cpp @@ -222,6 +222,7 @@ void glTFImporter::ImportMeshes(glTF::Asset& r) std::vector meshes; unsigned int k = 0; + meshOffsets.clear(); for (unsigned int m = 0; m < r.meshes.Size(); ++m) { Mesh& mesh = r.meshes[m]; diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index af98076a7..7a0a92d7c 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -335,6 +335,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) { std::vector meshes; unsigned int k = 0; + meshOffsets.clear(); for (unsigned int m = 0; m < r.meshes.Size(); ++m) { Mesh &mesh = r.meshes[m]; From 1e828cb8bb18218735a8a5fa00f18ba2c544f7bd Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Fri, 14 Feb 2020 15:57:06 +0100 Subject: [PATCH 02/30] pkg-config: fix include path --- assimp.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assimp.pc.in b/assimp.pc.in index c659e19f2..02cf59dc4 100644 --- a/assimp.pc.in +++ b/assimp.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@/ libdir=@CMAKE_INSTALL_PREFIX@/@ASSIMP_LIB_INSTALL_DIR@ -includedir=@CMAKE_INSTALL_PREFIX@/../include/@ASSIMP_INCLUDE_INSTALL_DIR@ +includedir=@CMAKE_INSTALL_PREFIX@/@ASSIMP_INCLUDE_INSTALL_DIR@ Name: @CMAKE_PROJECT_NAME@ Description: Import various well-known 3D model formats in an uniform manner. From be4fe131d5fee47c6e407e76f46b12edf29edba9 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Sat, 15 Feb 2020 13:10:11 -0500 Subject: [PATCH 03/30] Made changes to write compiled binaries to a common directory. The following changes were tested with the following projects: - assimp DLL - unit tests - tools/assimp_cmd - tools/assimp viewer - samples/SimpleOpenGL - samples/SimpleTexturedDirectx11 - samples/SimpleTexturedOpenGL For each program listed above, the results were tested when (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) is true and false. Also, the "lib" in SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/lib") was changed to "bin" to allow DLLs to be written to executables/launchables programs directory. --- CMakeLists.txt | 6 +++++- test/CMakeLists.txt | 7 ------- tools/assimp_cmd/CMakeLists.txt | 7 ------- tools/assimp_view/CMakeLists.txt | 7 ------- 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38ebf3480..08a1f3010 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,9 +342,13 @@ INCLUDE (PrecompiledHeader) # source tree. During an out-of-source build, however, do not litter this # directory, since that is probably what the user wanted to avoid. IF ( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) - SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/lib" ) + SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin" ) SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/lib" ) SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin" ) +ELSE() + SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") + SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") ENDIF ( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) # Cache these to allow the user to override them manually. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8624a065f..b1d918a86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -205,13 +205,6 @@ ELSE( WIN32 ) SET( platform_libs pthread ) ENDIF( WIN32 ) -IF( WIN32 ) - ADD_CUSTOM_COMMAND(TARGET unit - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - MAIN_DEPENDENCY assimp) -ENDIF( WIN32 ) - IF(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) ENDIF(MSVC) diff --git a/tools/assimp_cmd/CMakeLists.txt b/tools/assimp_cmd/CMakeLists.txt index fcf36c356..848b8f81c 100644 --- a/tools/assimp_cmd/CMakeLists.txt +++ b/tools/assimp_cmd/CMakeLists.txt @@ -61,13 +61,6 @@ ADD_EXECUTABLE( assimp_cmd SET_PROPERTY(TARGET assimp_cmd PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -IF( WIN32 ) - ADD_CUSTOM_COMMAND(TARGET assimp_cmd - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - MAIN_DEPENDENCY assimp) -ENDIF( WIN32 ) - TARGET_LINK_LIBRARIES( assimp_cmd assimp ${ZLIB_LIBRARIES} ) SET_TARGET_PROPERTIES( assimp_cmd PROPERTIES OUTPUT_NAME assimp diff --git a/tools/assimp_view/CMakeLists.txt b/tools/assimp_view/CMakeLists.txt index 001444e0e..dc1cee0d2 100644 --- a/tools/assimp_view/CMakeLists.txt +++ b/tools/assimp_view/CMakeLists.txt @@ -92,13 +92,6 @@ IF ( MSVC ) REMOVE_DEFINITIONS( -DUNICODE -D_UNICODE ) ENDIF ( MSVC ) - -# -ADD_CUSTOM_COMMAND(TARGET assimp_viewer - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - MAIN_DEPENDENCY assimp) - # Link the executable to the assimp + dx libs. TARGET_LINK_LIBRARIES ( assimp_viewer assimp ${DirectX_LIBRARY} ${DirectX_D3DX9_LIBRARY} comctl32.lib winmm.lib ) From 5c99d6a864f9e2fc43960eb3113f212f32c7cb21 Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Sat, 15 Feb 2020 23:29:04 +0200 Subject: [PATCH 04/30] very small changes - FIND_PACKAGE(DirectX) is already used in the samples and assimp tool cmake files - so is not needed in the main cmake fil - other small changes --- CMakeLists.txt | 4 ---- code/Obj/ObjFileParser.cpp | 17 ++++++++--------- code/Obj/ObjFileParser.h | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38ebf3480..7be4f6d5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -437,10 +437,6 @@ ELSE(HUNTER_ENABLED) DESTINATION "${ASSIMP_LIB_INSTALL_DIR}/cmake/assimp-${ASSIMP_VERSION_MAJOR}.${ASSIMP_VERSION_MINOR}" COMPONENT ${LIBASSIMP-DEV_COMPONENT}) ENDIF(HUNTER_ENABLED) -if (ASSIMP_BUILD_SAMPLES OR ASSIMP_BUILD_SAMPLES) - FIND_PACKAGE(DirectX) -endif(ASSIMP_BUILD_SAMPLES OR ASSIMP_BUILD_SAMPLES) - IF( BUILD_DOCS ) ADD_SUBDIRECTORY(doc) ENDIF( BUILD_DOCS ) diff --git a/code/Obj/ObjFileParser.cpp b/code/Obj/ObjFileParser.cpp index 48129c02c..8b1572067 100644 --- a/code/Obj/ObjFileParser.cpp +++ b/code/Obj/ObjFileParser.cpp @@ -53,6 +53,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include namespace Assimp { @@ -71,19 +73,19 @@ ObjFileParser::ObjFileParser() ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem *io, ProgressHandler* progress, - const std::string &originalObjFileName) : + std::string originalObjFileName) : m_DataIt(), m_DataItEnd(), m_pModel(nullptr), m_uiLine(0), - m_pIO( io ), + m_pIO(io), m_progress(progress), - m_originalObjFileName(originalObjFileName) + m_originalObjFileName(std::move(originalObjFileName)) { - std::fill_n(m_buffer,Buffersize,0); + std::fill_n(m_buffer, Buffersize,0); // Create the model instance to store all the data - m_pModel.reset(new ObjFile::Model()); + m_pModel = std::make_unique(); m_pModel->m_ModelName = modelName; // create default material and store it @@ -96,9 +98,6 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str parseFile( streamBuffer ); } -ObjFileParser::~ObjFileParser() { -} - void ObjFileParser::setBuffer( std::vector &buffer ) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); @@ -128,7 +127,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { processed = static_cast(filePos); lastFilePos = filePos; progressCounter++; - m_progress->UpdateFileRead( processed, progressTotal ); + m_progress->UpdateFileRead(processed, progressTotal); } // parse line diff --git a/code/Obj/ObjFileParser.h b/code/Obj/ObjFileParser.h index 124527413..9bbee66dd 100644 --- a/code/Obj/ObjFileParser.h +++ b/code/Obj/ObjFileParser.h @@ -78,9 +78,9 @@ public: /// @brief The default constructor. ObjFileParser(); /// @brief Constructor with data array. - ObjFileParser( IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem* io, ProgressHandler* progress, const std::string &originalObjFileName); + ObjFileParser(IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem* io, ProgressHandler* progress, std::string originalObjFileName); /// @brief Destructor - ~ObjFileParser(); + ~ObjFileParser() = default; /// @brief If you want to load in-core data. void setBuffer( std::vector &buffer ); /// @brief Model getter. From a65bac27e9ee0dca6c4178f5134b1bb10ce7ef91 Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 18:01:53 +0200 Subject: [PATCH 05/30] fixed the make_unique --- code/Obj/ObjFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Obj/ObjFileParser.cpp b/code/Obj/ObjFileParser.cpp index 8b1572067..bfddb8461 100644 --- a/code/Obj/ObjFileParser.cpp +++ b/code/Obj/ObjFileParser.cpp @@ -85,7 +85,7 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str std::fill_n(m_buffer, Buffersize,0); // Create the model instance to store all the data - m_pModel = std::make_unique(); + m_pModel.reset(new ObjFile::Model()); m_pModel->m_ModelName = modelName; // create default material and store it From d0922230a93c2a9bac8676cf7f2f7d96f8aa6deb Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 18:24:52 +0200 Subject: [PATCH 06/30] fixed the = default on the destructor --- code/Obj/ObjFileParser.cpp | 4 ++++ code/Obj/ObjFileParser.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/code/Obj/ObjFileParser.cpp b/code/Obj/ObjFileParser.cpp index bfddb8461..7ba2216ae 100644 --- a/code/Obj/ObjFileParser.cpp +++ b/code/Obj/ObjFileParser.cpp @@ -98,6 +98,10 @@ ObjFileParser::ObjFileParser( IOStreamBuffer &streamBuffer, const std::str parseFile( streamBuffer ); } +ObjFileParser::~ObjFileParser() +{ +} + void ObjFileParser::setBuffer( std::vector &buffer ) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end(); diff --git a/code/Obj/ObjFileParser.h b/code/Obj/ObjFileParser.h index 9bbee66dd..f0f5a2dc1 100644 --- a/code/Obj/ObjFileParser.h +++ b/code/Obj/ObjFileParser.h @@ -80,7 +80,7 @@ public: /// @brief Constructor with data array. ObjFileParser(IOStreamBuffer &streamBuffer, const std::string &modelName, IOSystem* io, ProgressHandler* progress, std::string originalObjFileName); /// @brief Destructor - ~ObjFileParser() = default; + ~ObjFileParser(); /// @brief If you want to load in-core data. void setBuffer( std::vector &buffer ); /// @brief Model getter. From 016c0a866557b7a22e6d47c9c89cc13939f121ce Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 18:42:59 +0200 Subject: [PATCH 07/30] small changes --- code/Common/BaseImporter.cpp | 7 +++---- code/Common/Importer.cpp | 8 ++++---- include/assimp/Importer.hpp | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 660a6a965..8d7b029ba 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -191,7 +191,7 @@ void BaseImporter::GetExtensionList(std::set& extensions) { } std::unique_ptr pStream (pIOHandler->Open(pFile)); - if (pStream.get() ) { + if (pStream) { // read 200 characters from the file std::unique_ptr _buffer (new char[searchBytes+1 /* for the '\0' */]); char *buffer( _buffer.get() ); @@ -283,7 +283,6 @@ std::string BaseImporter::GetExtension( const std::string& file ) { return ""; } - // thanks to Andy Maloney for the hint std::string ret = file.substr( pos + 1 ); std::transform( ret.begin(), ret.end(), ret.begin(), ToLower); @@ -309,7 +308,7 @@ std::string BaseImporter::GetExtension( const std::string& file ) { }; magic = reinterpret_cast(_magic); std::unique_ptr pStream (pIOHandler->Open(pFile)); - if (pStream.get() ) { + if (pStream) { // skip to offset pStream->Seek(offset,aiOrigin_SET); @@ -603,7 +602,7 @@ unsigned int BatchLoader::AddLoadRequest(const std::string& file, } // no, we don't have it. So add it to the queue ... - m_data->requests.push_back(LoadRequest(file,steps,map, m_data->next_id)); + m_data->requests.emplace_back(file, steps, map, m_data->next_id); return m_data->next_id++; } diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index 5601298f1..a59ec9812 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -1071,7 +1071,7 @@ ai_real Importer::GetPropertyFloat(const char* szName, ai_real iErrorReturn /*= // ------------------------------------------------------------------------------------------------ // Get a configuration property -const std::string Importer::GetPropertyString(const char* szName, const std::string& iErrorReturn /*= ""*/) const { +std::string Importer::GetPropertyString(const char* szName, const std::string& iErrorReturn /*= ""*/) const { ai_assert(nullptr != pimpl); return GetGenericProperty(pimpl->mStringProperties,szName,iErrorReturn); @@ -1079,7 +1079,7 @@ const std::string Importer::GetPropertyString(const char* szName, const std::str // ------------------------------------------------------------------------------------------------ // Get a configuration property -const aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName, const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const { +aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName, const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const { ai_assert(nullptr != pimpl); return GetGenericProperty(pimpl->mMatrixProperties,szName,iErrorReturn); @@ -1110,10 +1110,9 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const { aiScene* mScene = pimpl->mScene; // return if we have no scene loaded - if (!pimpl->mScene) + if (!mScene) return; - in.total = sizeof(aiScene); // add all meshes @@ -1202,5 +1201,6 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const { in.materials += pc->mProperties[a]->mDataLength; } } + in.total += in.materials; } diff --git a/include/assimp/Importer.hpp b/include/assimp/Importer.hpp index 7ec4f519c..df52471a9 100644 --- a/include/assimp/Importer.hpp +++ b/include/assimp/Importer.hpp @@ -285,7 +285,7 @@ public: * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ - const std::string GetPropertyString(const char* szName, + std::string GetPropertyString(const char* szName, const std::string& sErrorReturn = "") const; // ------------------------------------------------------------------- @@ -294,7 +294,7 @@ public: * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ - const aiMatrix4x4 GetPropertyMatrix(const char* szName, + aiMatrix4x4 GetPropertyMatrix(const char* szName, const aiMatrix4x4& sErrorReturn = aiMatrix4x4()) const; // ------------------------------------------------------------------- From bf85fc1386fa06c184be5874d0a54cb11828347e Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 18:50:48 +0200 Subject: [PATCH 08/30] small changes --- code/Obj/ObjFileData.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/code/Obj/ObjFileData.h b/code/Obj/ObjFileData.h index 985a49a42..d0ea8d507 100644 --- a/code/Obj/ObjFileData.h +++ b/code/Obj/ObjFileData.h @@ -110,10 +110,7 @@ struct Object { std::vector m_Meshes; //! \brief Default constructor - Object() - : m_strObjName("") { - // empty - } + Object() = default; //! \brief Destructor ~Object() { @@ -191,16 +188,12 @@ struct Material { , illumination_model (1) , ior ( ai_real( 1.0 ) ) , transparent( ai_real( 1.0), ai_real (1.0), ai_real(1.0)) { - // empty - for (size_t i = 0; i < TextureTypeCount; ++i) { - clamp[ i ] = false; - } + + std::fill_n(clamp, TextureTypeCount,false); } // Destructor - ~Material() { - // empty - } + ~Material() = default; }; // ------------------------------------------------------------------------------------------------ From ad52c5c5f6ac771124c3bd3585f24daa61fbbdbd Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 18:56:09 +0200 Subject: [PATCH 09/30] .clear in destructor is redundant --- code/Common/ZipArchiveIOSystem.cpp | 2 -- code/Obj/ObjFileData.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/code/Common/ZipArchiveIOSystem.cpp b/code/Common/ZipArchiveIOSystem.cpp index e83d3e50d..8d00da912 100644 --- a/code/Common/ZipArchiveIOSystem.cpp +++ b/code/Common/ZipArchiveIOSystem.cpp @@ -343,8 +343,6 @@ namespace Assimp { } ZipArchiveIOSystem::Implement::~Implement() { - m_ArchiveMap.clear(); - if (m_ZipFileHandle != nullptr) { unzClose(m_ZipFileHandle); m_ZipFileHandle = nullptr; diff --git a/code/Obj/ObjFileData.h b/code/Obj/ObjFileData.h index d0ea8d507..33184ce82 100644 --- a/code/Obj/ObjFileData.h +++ b/code/Obj/ObjFileData.h @@ -189,7 +189,7 @@ struct Material { , ior ( ai_real( 1.0 ) ) , transparent( ai_real( 1.0), ai_real (1.0), ai_real(1.0)) { - std::fill_n(clamp, TextureTypeCount,false); + std::fill_n(clamp, TextureTypeCount, false); } // Destructor From a5524ffcd9befe3f008e27d65b6de620b897c49c Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 19:02:14 +0200 Subject: [PATCH 10/30] more changes --- code/PostProcessing/TextureTransform.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/code/PostProcessing/TextureTransform.cpp b/code/PostProcessing/TextureTransform.cpp index cebbd8042..bf60e2970 100644 --- a/code/PostProcessing/TextureTransform.cpp +++ b/code/PostProcessing/TextureTransform.cpp @@ -92,9 +92,8 @@ void TextureTransformStep::PreProcessUVTransform(STransformVecInfo& info) * are applied is - as always - scaling, rotation, translation. */ - char szTemp[512]; - int rounded = 0; - + int rounded; + char szTemp[512]; /* Optimize the rotation angle. That's slightly difficult as * we have an inprecise floating-point number (when comparing @@ -185,7 +184,6 @@ void TextureTransformStep::PreProcessUVTransform(STransformVecInfo& info) info.mTranslation.y = out; } } - return; } // ------------------------------------------------------------------------------------------------ @@ -428,7 +426,7 @@ void TextureTransformStep::Execute( aiScene* pScene) // at the end of the list bool ref[AI_MAX_NUMBER_OF_TEXTURECOORDS]; for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n) - ref[n] = (!mesh->mTextureCoords[n] ? true : false); + ref[n] = !mesh->mTextureCoords[n]; for (it = trafo.begin();it != trafo.end(); ++it) ref[(*it).uvIndex] = true; From 4de0237167dd8019838cb28a5622bba522f74842 Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Tue, 18 Feb 2020 21:55:35 +0200 Subject: [PATCH 11/30] small fix --- code/Obj/ObjFileData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Obj/ObjFileData.h b/code/Obj/ObjFileData.h index 33184ce82..298d1e1b7 100644 --- a/code/Obj/ObjFileData.h +++ b/code/Obj/ObjFileData.h @@ -189,7 +189,7 @@ struct Material { , ior ( ai_real( 1.0 ) ) , transparent( ai_real( 1.0), ai_real (1.0), ai_real(1.0)) { - std::fill_n(clamp, TextureTypeCount, false); + std::fill_n(clamp, static_cast(TextureTypeCount), false); } // Destructor From 8d6d8e2e3820c89fc6a2ff9758795c00e9aa0f77 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 19 Feb 2020 10:42:30 +0100 Subject: [PATCH 12/30] Update .clang-format Update clang.format to keep formatting of hashes in include file to optimize readabilaty. --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 70e0945fe..c8b8ab856 100644 --- a/.clang-format +++ b/.clang-format @@ -71,7 +71,7 @@ IncludeCategories: Priority: 3 # IncludeIsMainRegex: '(Test)?$' IndentCaseLabels: true -# IndentPPDirectives: None +IndentPPDirectives: AfterHash IndentWidth: 4 # IndentWrappedFunctionNames: false # JavaScriptQuotes: Leave From 4d27fccd0bec68a5d2525a740b1ab1eb34d0be1a Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Wed, 19 Feb 2020 13:17:45 -0500 Subject: [PATCH 13/30] Fixed memory leaks in SimpleTexturedOpenGL sample. - Added function "cleanup" to centralize release of resources. - Added function "freeTextureIds" to free textureIds memory. - Added call to freeTextureIds in LoadGLTextures to free memory before it is allocated again. - Made several changes in KillGLWindow to prevent certain Win32 handle/resources from being released more than once. --- .../src/model_loading.cpp | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp index 8428248d1..8c2a08b2e 100644 --- a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp +++ b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp @@ -202,8 +202,21 @@ std::string getBasePath(const std::string& path) return (std::string::npos == pos) ? "" : path.substr(0, pos + 1); } +void freeTextureIds() +{ + textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) + + if (textureIds) + { + delete[] textureIds; + textureIds = NULL; + } +} + int LoadGLTextures(const aiScene* scene) { + freeTextureIds(); + //ILboolean success; /* Before calling ilInit() version should be checked. */ @@ -576,21 +589,24 @@ void KillGLWindow() // Properly Kill The Window hRC = NULL; } - if (hDC && !ReleaseDC(hWnd, hDC)) // Are We able to Release The DC? + if (hDC) { - MessageBox(NULL, TEXT("Release Device Context Failed."), TEXT("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION); - hDC=NULL; + if (!ReleaseDC(hWnd, hDC)) // Are We able to Release The DC? + MessageBox(NULL, TEXT("Release Device Context Failed."), TEXT("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION); + hDC = NULL; } - if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window + if (hWnd) { - MessageBox(NULL, TEXT("Could Not Release hWnd."), TEXT("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION); + if (!DestroyWindow(hWnd)) // Are We Able To Destroy The Window + MessageBox(NULL, TEXT("Could Not Release hWnd."), TEXT("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION); hWnd = NULL; - } + } - if (!UnregisterClass(TEXT("OpenGL"), hInstance)) // Are We Able To Unregister Class + if (hInstance) { - MessageBox(NULL, TEXT("Could Not Unregister Class."), TEXT("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION); + if (!UnregisterClass(TEXT("OpenGL"), hInstance)) // Are We Able To Unregister Class + MessageBox(NULL, TEXT("Could Not Unregister Class."), TEXT("SHUTDOWN ERROR"), MB_OK | MB_ICONINFORMATION); hInstance = NULL; } } @@ -761,6 +777,16 @@ BOOL CreateGLWindow(const char* title, int width, int height, int bits, bool ful return TRUE; } +void cleanup() +{ + freeTextureIds(); + + destroyAILogger(); + + if (hWnd) + KillGLWindow(); +}; + LRESULT CALLBACK WndProc(HWND hWnd, // Handles for this Window UINT uMsg, // Message for this Window WPARAM wParam, // additional message Info @@ -842,7 +868,11 @@ int WINAPI WinMain( HINSTANCE hInstance, // The instance modelpath = UTFConverter(modelpathW).str(); } - if (!Import3DFromFile(modelpath)) return 0; + if (!Import3DFromFile(modelpath)) + { + cleanup(); + return 0; + } logInfo("=============== Post Import ===================="); @@ -853,6 +883,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // The instance if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { + cleanup(); return 0; } @@ -893,6 +924,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // The instance fullscreen=!fullscreen; if (!CreateGLWindow(windowTitle, 640, 480, 16, fullscreen)) { + cleanup(); return 0; } } @@ -900,18 +932,6 @@ int WINAPI WinMain( HINSTANCE hInstance, // The instance } // *** cleanup *** - - textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step) - - if (textureIds) - { - delete[] textureIds; - textureIds = NULL; - } - - // *** cleanup end *** - - destroyAILogger(); - KillGLWindow(); + cleanup(); return static_cast(msg.wParam); } From f28b087d163e0f027e027e6d634d4e42d55b727d Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Fri, 21 Feb 2020 20:17:38 +0200 Subject: [PATCH 14/30] small improvements in the CMakeLists.txt file If ASSIMP_NO_EXPORT is not defined: - don't add the macro for the exporters - don't include the files for all the exporter - don't display any messages about what exporters are enabled or not --- code/CMakeLists.txt | 232 +++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 119 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 91f099c02..1d4586494 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -252,35 +252,39 @@ MACRO(ADD_ASSIMP_IMPORTER name) ENDIF() ENDMACRO() -# if this variable is set to TRUE, the user can manually disable exporters by setting -# ASSIMP_BUILD_XXX_EXPORTER to FALSE for each exporter -# if this variable is set to FALSE, the user can manually enable exporters by setting -# ASSIMP_BUILD_XXX_EXPORTER to TRUE for each exporter -OPTION(ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT "default value of all ASSIMP_BUILD_XXX_EXPORTER values" TRUE) +if (NOT ASSIMP_NO_EXPORT) -# macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader -# this way selective loaders can be compiled (reduces filesize + compile time) -MACRO(ADD_ASSIMP_EXPORTER name) - IF (ASSIMP_NO_EXPORT) - set(ASSIMP_EXPORTER_ENABLED FALSE) - ELSEIF (ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT) - set(ASSIMP_EXPORTER_ENABLED TRUE) - IF (DEFINED ASSIMP_BUILD_${name}_EXPORTER AND NOT ASSIMP_BUILD_${name}_EXPORTER) + # if this variable is set to TRUE, the user can manually disable exporters by setting + # ASSIMP_BUILD_XXX_EXPORTER to FALSE for each exporter + # if this variable is set to FALSE, the user can manually enable exporters by setting + # ASSIMP_BUILD_XXX_EXPORTER to TRUE for each exporter + OPTION(ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT "default value of all ASSIMP_BUILD_XXX_EXPORTER values" TRUE) + + # macro to add the CMake Option ADD_ASSIMP_IMPORTER_ which enables compile of loader + # this way selective loaders can be compiled (reduces filesize + compile time) + MACRO(ADD_ASSIMP_EXPORTER name) + IF (ASSIMP_NO_EXPORT) set(ASSIMP_EXPORTER_ENABLED FALSE) + ELSEIF (ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT) + set(ASSIMP_EXPORTER_ENABLED TRUE) + IF (DEFINED ASSIMP_BUILD_${name}_EXPORTER AND NOT ASSIMP_BUILD_${name}_EXPORTER) + set(ASSIMP_EXPORTER_ENABLED FALSE) + ENDIF () + ELSE () + set(ASSIMP_EXPORTER_ENABLED ${ASSIMP_BUILD_${name}_EXPORTER}) ENDIF () - ELSE () - set(ASSIMP_EXPORTER_ENABLED ${ASSIMP_BUILD_${name}_EXPORTER}) - ENDIF () - IF (ASSIMP_EXPORTER_ENABLED) - SET(ASSIMP_EXPORTERS_ENABLED "${ASSIMP_EXPORTERS_ENABLED} ${name}") - LIST(APPEND ASSIMP_EXPORTER_SRCS ${ARGN}) - SOURCE_GROUP(${name}_EXPORTER FILES ${ARGN}) - ELSE() - SET(ASSIMP_EXPORTERS_DISABLED "${ASSIMP_EXPORTERS_DISABLED} ${name}") - add_definitions(-DASSIMP_BUILD_NO_${name}_EXPORTER) - ENDIF() -ENDMACRO() + IF (ASSIMP_EXPORTER_ENABLED) + SET(ASSIMP_EXPORTERS_ENABLED "${ASSIMP_EXPORTERS_ENABLED} ${name}") + LIST(APPEND ASSIMP_EXPORTER_SRCS ${ARGN}) + SOURCE_GROUP(${name}_EXPORTER FILES ${ARGN}) + ELSE() + SET(ASSIMP_EXPORTERS_DISABLED "${ASSIMP_EXPORTERS_DISABLED} ${name}") + add_definitions(-DASSIMP_BUILD_NO_${name}_EXPORTER) + ENDIF() + ENDMACRO() + +endif() SET(ASSIMP_LOADER_SRCS "") SET(ASSIMP_IMPORTERS_ENABLED "") # list of enabled importers @@ -307,11 +311,6 @@ ADD_ASSIMP_IMPORTER( 3DS 3DS/3DSLoader.h ) -ADD_ASSIMP_EXPORTER( 3DS - 3DS/3DSExporter.h - 3DS/3DSExporter.cpp -) - ADD_ASSIMP_IMPORTER( AC AC/ACLoader.cpp AC/ACLoader.h @@ -329,20 +328,6 @@ ADD_ASSIMP_IMPORTER( ASSBIN Assbin/AssbinLoader.cpp ) -ADD_ASSIMP_EXPORTER( ASSBIN - Assbin/AssbinExporter.h - Assbin/AssbinExporter.cpp - Assbin/AssbinFileWriter.h - Assbin/AssbinFileWriter.cpp -) - -ADD_ASSIMP_EXPORTER( ASSXML - Assxml/AssxmlExporter.h - Assxml/AssxmlExporter.cpp - Assxml/AssxmlFileWriter.h - Assxml/AssxmlFileWriter.cpp -) - ADD_ASSIMP_IMPORTER( B3D B3D/B3DImporter.cpp B3D/B3DImporter.h @@ -362,11 +347,6 @@ ADD_ASSIMP_IMPORTER( COLLADA Collada/ColladaParser.h ) -ADD_ASSIMP_EXPORTER( COLLADA - Collada/ColladaExporter.h - Collada/ColladaExporter.cpp -) - ADD_ASSIMP_IMPORTER( DXF DXF/DXFLoader.cpp DXF/DXFLoader.h @@ -423,11 +403,6 @@ ADD_ASSIMP_IMPORTER( M3D M3D/m3d.h ) -ADD_ASSIMP_EXPORTER( M3D - M3D/M3DExporter.h - M3D/M3DExporter.cpp -) - ADD_ASSIMP_IMPORTER( MD2 MD2/MD2FileData.h MD2/MD2Loader.cpp @@ -505,11 +480,6 @@ ADD_ASSIMP_IMPORTER( OBJ Obj/ObjTools.h ) -ADD_ASSIMP_EXPORTER( OBJ - Obj/ObjExporter.h - Obj/ObjExporter.cpp -) - ADD_ASSIMP_IMPORTER( OGRE Ogre/OgreImporter.h Ogre/OgreStructs.h @@ -529,11 +499,6 @@ ADD_ASSIMP_IMPORTER( OPENGEX OpenGEX/OpenGEXStructs.h ) -ADD_ASSIMP_EXPORTER( OPENGEX - OpenGEX/OpenGEXExporter.cpp - OpenGEX/OpenGEXExporter.h -) - ADD_ASSIMP_IMPORTER( PLY Ply/PlyLoader.cpp Ply/PlyLoader.h @@ -541,11 +506,6 @@ ADD_ASSIMP_IMPORTER( PLY Ply/PlyParser.h ) -ADD_ASSIMP_EXPORTER( PLY - Ply/PlyExporter.cpp - Ply/PlyExporter.h -) - ADD_ASSIMP_IMPORTER( MS3D MS3D/MS3DLoader.cpp MS3D/MS3DLoader.h @@ -635,14 +595,86 @@ ADD_ASSIMP_IMPORTER( FBX FBX/FBXCommon.h ) -ADD_ASSIMP_EXPORTER( FBX - FBX/FBXExporter.h - FBX/FBXExporter.cpp - FBX/FBXExportNode.h - FBX/FBXExportNode.cpp - FBX/FBXExportProperty.h - FBX/FBXExportProperty.cpp -) +if (NOT ASSIMP_NO_EXPORT) + + ADD_ASSIMP_EXPORTER( OBJ + Obj/ObjExporter.h + Obj/ObjExporter.cpp) + + ADD_ASSIMP_EXPORTER( OPENGEX + OpenGEX/OpenGEXExporter.cpp + OpenGEX/OpenGEXExporter.h) + + ADD_ASSIMP_EXPORTER( PLY + Ply/PlyExporter.cpp + Ply/PlyExporter.h) + + ADD_ASSIMP_EXPORTER( 3DS + 3DS/3DSExporter.h + 3DS/3DSExporter.cpp) + + ADD_ASSIMP_EXPORTER( ASSBIN + Assbin/AssbinExporter.h + Assbin/AssbinExporter.cpp + Assbin/AssbinFileWriter.h + Assbin/AssbinFileWriter.cpp) + + ADD_ASSIMP_EXPORTER( ASSXML + Assxml/AssxmlExporter.h + Assxml/AssxmlExporter.cpp + Assxml/AssxmlFileWriter.h + Assxml/AssxmlFileWriter.cpp) + + ADD_ASSIMP_EXPORTER(M3D + M3D/M3DExporter.h + M3D/M3DExporter.cpp) + + ADD_ASSIMP_EXPORTER(COLLADA + Collada/ColladaExporter.h + Collada/ColladaExporter.cpp) + + ADD_ASSIMP_EXPORTER( FBX + FBX/FBXExporter.h + FBX/FBXExporter.cpp + FBX/FBXExportNode.h + FBX/FBXExportNode.cpp + FBX/FBXExportProperty.h + FBX/FBXExportProperty.cpp) + + ADD_ASSIMP_EXPORTER( STL + STL/STLExporter.h + STL/STLExporter.cpp) + + ADD_ASSIMP_EXPORTER( X + X/XFileExporter.h + X/XFileExporter.cpp) + + ADD_ASSIMP_EXPORTER( X3D + X3D/X3DExporter.cpp + X3D/X3DExporter.hpp) + + ADD_ASSIMP_EXPORTER( GLTF + glTF/glTFExporter.h + glTF/glTFExporter.cpp + glTF2/glTF2Exporter.h + glTF2/glTF2Exporter.cpp) + + ADD_ASSIMP_EXPORTER( 3MF + 3MF/D3MFExporter.h + 3MF/D3MFExporter.cpp) + + ADD_ASSIMP_EXPORTER( ASSJSON + Assjson/cencode.c + Assjson/cencode.h + Assjson/json_exporter.cpp + Assjson/mesh_splitter.cpp + Assjson/mesh_splitter.h) + + ADD_ASSIMP_EXPORTER( STEP + Step/StepExporter.h + Step/StepExporter.cpp) + +endif() SET( PostProcessing_SRCS PostProcessing/CalcTangentsProcess.cpp @@ -744,11 +776,6 @@ ADD_ASSIMP_IMPORTER( STL STL/STLLoader.h ) -ADD_ASSIMP_EXPORTER( STL - STL/STLExporter.h - STL/STLExporter.cpp -) - ADD_ASSIMP_IMPORTER( TERRAGEN Terragen/TerragenLoader.cpp Terragen/TerragenLoader.h @@ -767,11 +794,6 @@ ADD_ASSIMP_IMPORTER( X X/XFileParser.h ) -ADD_ASSIMP_EXPORTER( X - X/XFileExporter.h - X/XFileExporter.cpp -) - ADD_ASSIMP_IMPORTER( X3D X3D/X3DImporter.cpp X3D/X3DImporter.hpp @@ -792,11 +814,6 @@ ADD_ASSIMP_IMPORTER( X3D X3D/X3DVocabulary.cpp ) -ADD_ASSIMP_EXPORTER( X3D - X3D/X3DExporter.cpp - X3D/X3DExporter.hpp -) - ADD_ASSIMP_IMPORTER( GLTF glTF/glTFCommon.h glTF/glTFCommon.cpp @@ -814,13 +831,6 @@ ADD_ASSIMP_IMPORTER( GLTF glTF2/glTF2Importer.h ) -ADD_ASSIMP_EXPORTER( GLTF - glTF/glTFExporter.h - glTF/glTFExporter.cpp - glTF2/glTF2Exporter.h - glTF2/glTF2Exporter.cpp -) - ADD_ASSIMP_IMPORTER( 3MF 3MF/D3MFImporter.h 3MF/D3MFImporter.cpp @@ -829,11 +839,6 @@ ADD_ASSIMP_IMPORTER( 3MF 3MF/3MFXmlTags.h ) -ADD_ASSIMP_EXPORTER( 3MF - 3MF/D3MFExporter.h - 3MF/D3MFExporter.cpp -) - ADD_ASSIMP_IMPORTER( MMD MMD/MMDCpp14.h MMD/MMDImporter.cpp @@ -844,14 +849,6 @@ ADD_ASSIMP_IMPORTER( MMD MMD/MMDVmdParser.h ) -ADD_ASSIMP_EXPORTER( ASSJSON - Assjson/cencode.c - Assjson/cencode.h - Assjson/json_exporter.cpp - Assjson/mesh_splitter.cpp - Assjson/mesh_splitter.h -) - # Workaround for issue #2406 - force problematic large file to be optimized to prevent string table overflow error # Used -Os instead of -O2 as previous issues had mentioned, since -Os is roughly speaking -O2, excluding any # optimizations that take up extra space. Given that the issue is a string table overflowing, -Os seemed appropriate @@ -874,11 +871,6 @@ ADD_ASSIMP_IMPORTER( STEP Importer/StepFile/StepReaderGen.h ) -ADD_ASSIMP_EXPORTER( STEP - Step/StepExporter.h - Step/StepExporter.cpp -) - if ((NOT ASSIMP_NO_EXPORT) OR (NOT ASSIMP_EXPORTERS_ENABLED STREQUAL "")) SET( Exporter_SRCS Common/Exporter.cpp @@ -1088,8 +1080,10 @@ ENDIF(NOT HUNTER_ENABLED) MESSAGE(STATUS "Enabled importer formats:${ASSIMP_IMPORTERS_ENABLED}") MESSAGE(STATUS "Disabled importer formats:${ASSIMP_IMPORTERS_DISABLED}") -MESSAGE(STATUS "Enabled exporter formats:${ASSIMP_EXPORTERS_ENABLED}") -MESSAGE(STATUS "Disabled exporter formats:${ASSIMP_EXPORTERS_DISABLED}") +if (NOT ASSIMP_NO_EXPORT) + MESSAGE(STATUS "Enabled exporter formats:${ASSIMP_EXPORTERS_ENABLED}") + MESSAGE(STATUS "Disabled exporter formats:${ASSIMP_EXPORTERS_DISABLED}") +endif() SOURCE_GROUP( include\\assimp FILES ${PUBLIC_HEADERS} ) From edfaaed56fb656a3923807cac1c875cc8ff2f4ba Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Sun, 23 Feb 2020 07:09:35 -0500 Subject: [PATCH 15/30] Removed uneeded expression in else() and endif() constructs. The following changes were tested against building with a master copy. For a more detailed report, please read the followings below: The flags that were checked were the ones checked by default + the following: ASSIMP_BUILD_ASSIMP_VIEW ASSIMP_BUILD_SAMPLES The list of compilable projects in Visual Studio were the following: - assimp - assimp_cmd - assimp_simpleogl - assimp_simpletextureddirectx11 - assimp_simpletexturedogl - assimp_viewer - INSTALL - IrrXML - uninstall - unit - UpdateAssimpLibsDebugSymbolsAndDLLs - ZERO_CHECK - zlib - zlibstatic The solution that was generated with the new changes comprised the same number of projects as the one from the master, unmodified. All projects except UpdateAssimpLibsDebugSymbolsAndDLLs were built without any error. All tests were run. UpdateAssimpLibsDebugSymbolsAndDLLs could not be built because of the reasons explained in issue #3004. --- CMakeLists.txt | 88 +++++++++---------- code/CMakeLists.txt | 86 +++++++++--------- contrib/CMakeLists.txt | 2 +- doc/CMakeLists.txt | 4 +- samples/SimpleOpenGL/CMakeLists.txt | 12 +-- .../SimpleTexturedDirectx11/CMakeLists.txt | 4 +- samples/SimpleTexturedOpenGL/CMakeLists.txt | 8 +- test/CMakeLists.txt | 6 +- test/headercheck/CMakeLists.txt | 2 +- tools/assimp_view/CMakeLists.txt | 2 +- 10 files changed, 107 insertions(+), 107 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b98d1f78a..59b79d1c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ IF(HUNTER_ENABLED) ) add_definitions(-DASSIMP_USE_HUNTER) -ENDIF(HUNTER_ENABLED) +ENDIF() PROJECT( Assimp VERSION 5.0.1 ) @@ -141,9 +141,9 @@ OPTION ( IGNORE_GIT_HASH IF (IOS AND NOT HUNTER_ENABLED) IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Release") - ENDIF (NOT CMAKE_BUILD_TYPE) + ENDIF () ADD_DEFINITIONS(-DENABLE_BITCODE) -ENDIF (IOS AND NOT HUNTER_ENABLED) +ENDIF () # Use subset of Windows.h if (WIN32) @@ -159,19 +159,19 @@ IF(MSVC) # Multibyte character set is deprecated since at least MSVC2015 (possibly earlier) ADD_DEFINITIONS( -DUNICODE -D_UNICODE ) ENDIF() -ENDIF(MSVC) +ENDIF() IF (BUILD_FRAMEWORK) SET (BUILD_SHARED_LIBS ON) MESSAGE(STATUS "Framework bundle building enabled") -ENDIF(BUILD_FRAMEWORK) +ENDIF() IF(NOT BUILD_SHARED_LIBS) MESSAGE(STATUS "Shared libraries disabled") SET(LINK_SEARCH_START_STATIC TRUE) ELSE() MESSAGE(STATUS "Shared libraries enabled") -ENDIF(NOT BUILD_SHARED_LIBS) +ENDIF() # Define here the needed parameters SET (ASSIMP_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) @@ -208,11 +208,11 @@ ENDIF() IF(NOT GIT_COMMIT_HASH) SET(GIT_COMMIT_HASH 0) -ENDIF(NOT GIT_COMMIT_HASH) +ENDIF() IF(ASSIMP_DOUBLE_PRECISION) ADD_DEFINITIONS(-DASSIMP_DOUBLE_PRECISION) -ENDIF(ASSIMP_DOUBLE_PRECISION) +ENDIF() CONFIGURE_FILE( ${CMAKE_CURRENT_LIST_DIR}/revision.h.in @@ -241,7 +241,7 @@ SET(ASSIMP_LIBRARY_SUFFIX "" CACHE STRING "Suffix to append to library names") IF( UNIX ) # Use GNUInstallDirs for Unix predefined directories INCLUDE(GNUInstallDirs) -ENDIF( UNIX ) +ENDIF() # Grouped compiler settings IF ((CMAKE_C_COMPILER_ID MATCHES "GNU") AND NOT CMAKE_COMPILER_IS_MINGW) @@ -293,7 +293,7 @@ IF ( IOS AND NOT HUNTER_ENABLED) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode -O3") # Experimental for pdb generation ENDIF() -ENDIF( IOS AND NOT HUNTER_ENABLED) +ENDIF() IF (ASSIMP_COVERALLS) MESSAGE(STATUS "Coveralls enabled") @@ -349,7 +349,7 @@ ELSE() SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") -ENDIF ( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR ) +ENDIF () # Cache these to allow the user to override them manually. SET( ASSIMP_LIB_INSTALL_DIR "lib" CACHE STRING @@ -411,7 +411,7 @@ IF(HUNTER_ENABLED) NAMESPACE "${NAMESPACE}" DESTINATION "${CONFIG_INSTALL_DIR}" ) -ELSE(HUNTER_ENABLED) +ELSE() # cmake configuration files if(${BUILD_SHARED_LIBS}) set(BUILD_LIB_TYPE SHARED) @@ -439,16 +439,16 @@ ELSE(HUNTER_ENABLED) "${CMAKE_CURRENT_BINARY_DIR}/assimpTargets.cmake" ${PACKAGE_TARGETS_FILE} DESTINATION "${ASSIMP_LIB_INSTALL_DIR}/cmake/assimp-${ASSIMP_VERSION_MAJOR}.${ASSIMP_VERSION_MINOR}" COMPONENT ${LIBASSIMP-DEV_COMPONENT}) -ENDIF(HUNTER_ENABLED) +ENDIF() IF( BUILD_DOCS ) ADD_SUBDIRECTORY(doc) -ENDIF( BUILD_DOCS ) +ENDIF() # Look for system installed irrXML IF ( SYSTEM_IRRXML ) FIND_PACKAGE( IrrXML REQUIRED ) -ENDIF( SYSTEM_IRRXML ) +ENDIF() # Search for external dependencies, and build them from source if not found # Search for zlib @@ -460,10 +460,10 @@ IF(HUNTER_ENABLED) set(ZLIB_FOUND TRUE) set(ZLIB_LIBRARIES ZLIB::zlib) set(ASSIMP_BUILD_MINIZIP TRUE) -ELSE(HUNTER_ENABLED) +ELSE() IF ( NOT ASSIMP_BUILD_ZLIB ) FIND_PACKAGE(ZLIB) - ENDIF( NOT ASSIMP_BUILD_ZLIB ) + ENDIF() IF( NOT ZLIB_FOUND ) MESSAGE(STATUS "compiling zlib from sources") @@ -486,46 +486,46 @@ ELSE(HUNTER_ENABLED) SET(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contrib/zlib ${CMAKE_CURRENT_BINARY_DIR}/contrib/zlib) # need to ensure we don't link with system zlib or minizip as well. SET(ASSIMP_BUILD_MINIZIP 1) - ELSE(NOT ZLIB_FOUND) + ELSE() ADD_DEFINITIONS(-DASSIMP_BUILD_NO_OWN_ZLIB) SET(ZLIB_LIBRARIES_LINKED -lz) - ENDIF(NOT ZLIB_FOUND) + ENDIF() INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) -ENDIF(HUNTER_ENABLED) +ENDIF() IF( NOT IOS ) IF( NOT ASSIMP_BUILD_MINIZIP ) use_pkgconfig(UNZIP minizip) - ENDIF( NOT ASSIMP_BUILD_MINIZIP ) -ELSE ( NOT IOS ) + ENDIF() +ELSE () IF( NOT BUILD_SHARED_LIBS ) IF( NOT ASSIMP_BUILD_MINIZIP ) use_pkgconfig(UNZIP minizip) - ENDIF( NOT ASSIMP_BUILD_MINIZIP ) - ENDIF ( NOT BUILD_SHARED_LIBS ) -ENDIF ( NOT IOS ) + ENDIF() + ENDIF () +ENDIF () IF ( ASSIMP_NO_EXPORT ) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_EXPORT) MESSAGE( STATUS "Build an import-only version of Assimp." ) -ENDIF( ASSIMP_NO_EXPORT ) +ENDIF() SET ( ASSIMP_BUILD_ARCHITECTURE "" CACHE STRING "describe the current architecture." ) IF ( ASSIMP_BUILD_ARCHITECTURE STREQUAL "") -ELSE ( ASSIMP_BUILD_ARCHITECTURE STREQUAL "") +ELSE () ADD_DEFINITIONS ( -D'ASSIMP_BUILD_ARCHITECTURE="${ASSIMP_BUILD_ARCHITECTURE}"' ) -ENDIF ( ASSIMP_BUILD_ARCHITECTURE STREQUAL "") +ENDIF () # ${CMAKE_GENERATOR} SET ( ASSIMP_BUILD_COMPILER "" CACHE STRING "describe the current compiler." ) IF ( ASSIMP_BUILD_COMPILER STREQUAL "") -ELSE ( ASSIMP_BUILD_COMPILER STREQUAL "") +ELSE () ADD_DEFINITIONS ( -D'ASSIMP_BUILD_COMPILER="${ASSIMP_BUILD_COMPILER}"' ) -ENDIF ( ASSIMP_BUILD_COMPILER STREQUAL "") +ENDIF () MARK_AS_ADVANCED ( ASSIMP_BUILD_ARCHITECTURE ASSIMP_BUILD_COMPILER ) @@ -571,14 +571,14 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) MESSAGE( FATAL_ERROR "C4D is currently only available on Windows with melange SDK installed in contrib/Melange" ) - ENDIF ( MSVC ) -ELSE (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) + ENDIF () +ELSE () ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER ) -ENDIF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) +ENDIF () IF(NOT HUNTER_ENABLED) ADD_SUBDIRECTORY(contrib) -ENDIF(NOT HUNTER_ENABLED) +ENDIF() ADD_SUBDIRECTORY( code/ ) IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) @@ -587,29 +587,29 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) OPTION ( ASSIMP_BUILD_ASSIMP_VIEW "If the Assimp view tool is built. (requires DirectX)" ${DirectX_FOUND} ) IF ( ASSIMP_BUILD_ASSIMP_VIEW ) ADD_SUBDIRECTORY( tools/assimp_view/ ) - ENDIF ( ASSIMP_BUILD_ASSIMP_VIEW ) - ENDIF ( WIN32 AND DirectX_D3DX9_LIBRARY ) + ENDIF () + ENDIF () # Te command line tool ADD_SUBDIRECTORY( tools/assimp_cmd/ ) -ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS ) +ENDIF () IF ( ASSIMP_BUILD_SAMPLES) IF ( WIN32 ) ADD_SUBDIRECTORY( samples/SimpleTexturedOpenGL/ ) ADD_SUBDIRECTORY( samples/SimpleTexturedDirectx11 ) - ENDIF ( WIN32 ) + ENDIF () ADD_SUBDIRECTORY( samples/SimpleOpenGL/ ) -ENDIF ( ASSIMP_BUILD_SAMPLES ) +ENDIF () IF ( ASSIMP_BUILD_TESTS ) ADD_SUBDIRECTORY( test/ ) -ENDIF ( ASSIMP_BUILD_TESTS ) +ENDIF () # Generate a pkg-config .pc for the Assimp library. CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/assimp.pc.in" "${PROJECT_BINARY_DIR}/assimp.pc" @ONLY ) IF ( ASSIMP_INSTALL ) INSTALL( FILES "${PROJECT_BINARY_DIR}/assimp.pc" DESTINATION ${ASSIMP_LIB_INSTALL_DIR}/pkgconfig/ COMPONENT ${LIBASSIMP-DEV_COMPONENT}) -ENDIF( ASSIMP_INSTALL ) +ENDIF() IF ( ASSIMP_INSTALL ) IF(CMAKE_CPACK_COMMAND AND UNIX AND ASSIMP_OPT_BUILD_PACKAGES) @@ -680,7 +680,7 @@ if(WIN32) SET(ASSIMP_MSVC_VERSION "vc140") ELSEIF(MSVC15) SET(ASSIMP_MSVC_VERSION "vc141") - ENDIF(MSVC12) + ENDIF() ENDIF() IF(MSVC12 OR MSVC14 OR MSVC15 ) @@ -705,5 +705,5 @@ if(WIN32) ADD_CUSTOM_COMMAND(TARGET UpdateAssimpLibsDebugSymbolsAndDLLs COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/code/assimp-${ASSIMP_MSVC_VERSION}-mtd.pdb ${LIB_DIR}assimp-${ASSIMP_MSVC_VERSION}-mtd.pdb VERBATIM) ADD_CUSTOM_COMMAND(TARGET UpdateAssimpLibsDebugSymbolsAndDLLs COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/code/assimp-${ASSIMP_MSVC_VERSION}-mtd.pdb ${LIB_DIR}assimp-${ASSIMP_MSVC_VERSION}-mtd.pdb VERBATIM) ENDIF() - ENDIF(MSVC12 OR MSVC14 OR MSVC15 ) -ENDIF (WIN32) + ENDIF() +ENDIF () diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 91f099c02..0cef480f2 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -49,7 +49,7 @@ SET( HEADER_PATH ../include/assimp ) if(NOT ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM) message(WARNING "Requesting Android JNI I/O-System in non-Android toolchain. Resetting ASSIMP_ANDROID_JNIIOSYSTEM to OFF.") set(ASSIMP_ANDROID_JNIIOSYSTEM OFF) -endif(NOT ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM) +endif() SET( COMPILER_HEADERS ${HEADER_PATH}/Compiler/pushpack1.h @@ -148,7 +148,7 @@ SET( Core_SRCS IF(MSVC) list(APPEND Core_SRCS "res/assimp.rc") -ENDIF(MSVC) +ENDIF() SET( Logging_SRCS ${HEADER_PATH}/DefaultLogger.hpp @@ -222,7 +222,7 @@ IF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) C4D/C4DImporter.h ) SOURCE_GROUP( C4D FILES ${C4D_SRCS}) -ENDIF ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER ) +ENDIF () # if this variable is set to TRUE, the user can manually disable importers by setting # ASSIMP_BUILD_XXX_IMPORTER to FALSE for each importer @@ -599,7 +599,7 @@ if (ASSIMP_BUILD_IFC_IMPORTER) elseif(CMAKE_COMPILER_IS_MINGW) set_source_files_properties(Importer/IFC/IFCReaderGen1_2x3.cpp Importer/IFC/IFCReaderGen2_2x3.cpp PROPERTIES COMPILE_FLAGS "-O2 -Wa,-mbig-obj") endif() -endif (ASSIMP_BUILD_IFC_IMPORTER) +endif () ADD_ASSIMP_IMPORTER( XGL XGL/XGLLoader.cpp @@ -897,35 +897,35 @@ SOURCE_GROUP( Extra FILES ${Extra_SRCS}) IF(HUNTER_ENABLED) hunter_add_package(irrXML) find_package(irrXML CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() # irrXML already included in contrib directory by parent CMakeLists.txt. -ENDIF(HUNTER_ENABLED) +ENDIF() # utf8 IF(HUNTER_ENABLED) hunter_add_package(utf8) find_package(utf8 CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() # utf8 is header-only, so Assimp doesn't need to do anything. -ENDIF(HUNTER_ENABLED) +ENDIF() # polyclipping IF(HUNTER_ENABLED) hunter_add_package(polyclipping) find_package(polyclipping CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() SET( Clipper_SRCS ../contrib/clipper/clipper.hpp ../contrib/clipper/clipper.cpp ) SOURCE_GROUP( Contrib\\Clipper FILES ${Clipper_SRCS}) -ENDIF(HUNTER_ENABLED) +ENDIF() # poly2tri IF(HUNTER_ENABLED) hunter_add_package(poly2tri) find_package(poly2tri CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() SET( Poly2Tri_SRCS ../contrib/poly2tri/poly2tri/common/shapes.cc ../contrib/poly2tri/poly2tri/common/shapes.h @@ -940,13 +940,13 @@ ELSE(HUNTER_ENABLED) ../contrib/poly2tri/poly2tri/sweep/sweep_context.h ) SOURCE_GROUP( Contrib\\Poly2Tri FILES ${Poly2Tri_SRCS}) -ENDIF(HUNTER_ENABLED) +ENDIF() # minizip/unzip IF(HUNTER_ENABLED) hunter_add_package(minizip) find_package(minizip CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() SET( unzip_SRCS ../contrib/unzip/crypt.h ../contrib/unzip/ioapi.c @@ -955,13 +955,13 @@ ELSE(HUNTER_ENABLED) ../contrib/unzip/unzip.h ) SOURCE_GROUP(Contrib\\unzip FILES ${unzip_SRCS}) -ENDIF(HUNTER_ENABLED) +ENDIF() # zip (https://github.com/kuba--/zip) IF(HUNTER_ENABLED) hunter_add_package(zip) find_package(zip CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() SET( ziplib_SRCS ../contrib/zip/src/miniz.h ../contrib/zip/src/zip.c @@ -976,13 +976,13 @@ ELSE(HUNTER_ENABLED) endif() SOURCE_GROUP( ziplib FILES ${ziplib_SRCS} ) -ENDIF(HUNTER_ENABLED) +ENDIF() # openddlparser IF(HUNTER_ENABLED) hunter_add_package(openddlparser) find_package(openddlparser CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() SET ( openddl_parser_SRCS ../contrib/openddlparser/code/OpenDDLParser.cpp ../contrib/openddlparser/code/DDLNode.cpp @@ -999,12 +999,12 @@ ELSE(HUNTER_ENABLED) ../contrib/openddlparser/include/openddlparser/Value.h ) SOURCE_GROUP( Contrib\\openddl_parser FILES ${openddl_parser_SRCS}) -ENDIF(HUNTER_ENABLED) +ENDIF() # Open3DGC IF(HUNTER_ENABLED) # Nothing to do, not available in Hunter yet. -ELSE(HUNTER_ENABLED) +ELSE() SET ( open3dgc_SRCS ../contrib/Open3DGC/o3dgcAdjacencyInfo.h ../contrib/Open3DGC/o3dgcArithmeticCodec.cpp @@ -1037,7 +1037,7 @@ ELSE(HUNTER_ENABLED) ../contrib/Open3DGC/o3dgcVector.inl ) SOURCE_GROUP( Contrib\\open3dgc FILES ${open3dgc_SRCS}) -ENDIF(HUNTER_ENABLED) +ENDIF() # Check dependencies for glTF importer with Open3DGC-compression. # RT-extensions is used in "contrib/Open3DGC/o3dgcTimer.h" for collecting statistics. Pointed file @@ -1056,34 +1056,34 @@ ENDIF () IF(HUNTER_ENABLED) hunter_add_package(RapidJSON) find_package(RapidJSON CONFIG REQUIRED) -ELSE(HUNTER_ENABLED) +ELSE() INCLUDE_DIRECTORIES( "../contrib/rapidjson/include" ) INCLUDE_DIRECTORIES( "../contrib" ) -ENDIF(HUNTER_ENABLED) +ENDIF() # VC2010 fixes if(MSVC10) option( VC10_STDINT_FIX "Fix for VC10 Compiler regarding pstdint.h redefinition errors" OFF ) if( VC10_STDINT_FIX ) ADD_DEFINITIONS( -D_STDINT ) - endif( VC10_STDINT_FIX ) -endif(MSVC10) + endif() +endif() ADD_DEFINITIONS( -DASSIMP_BUILD_DLL_EXPORT ) if ( MSVC ) ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) -endif ( MSVC ) +endif () IF(NOT HUNTER_ENABLED) if (UNZIP_FOUND) SET (unzip_compile_SRCS "") - else (UNZIP_FOUND) + else () SET (unzip_compile_SRCS ${unzip_SRCS}) INCLUDE_DIRECTORIES( "../contrib/unzip/" ) - endif (UNZIP_FOUND) -ENDIF(NOT HUNTER_ENABLED) + endif () +ENDIF() MESSAGE(STATUS "Enabled importer formats:${ASSIMP_IMPORTERS_ENABLED}") MESSAGE(STATUS "Disabled importer formats:${ASSIMP_IMPORTERS_DISABLED}") @@ -1129,12 +1129,12 @@ IF(NOT HUNTER_ENABLED) ${IRRXML_INCLUDE_DIR} ../contrib/openddlparser/include ) -ENDIF(NOT HUNTER_ENABLED) +ENDIF() IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) SET( assimp_src ${assimp_src} ${C4D_SRCS}) INCLUDE_DIRECTORIES(${C4D_INCLUDES}) -ENDIF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) +ENDIF () ADD_LIBRARY( assimp ${assimp_src} ) ADD_LIBRARY(assimp::assimp ALIAS assimp) @@ -1158,21 +1158,21 @@ IF(HUNTER_ENABLED) utf8::utf8 zip::zip ) -ELSE(HUNTER_ENABLED) +ELSE() TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES} ${OPENDDL_PARSER_LIBRARIES} ${IRRXML_LIBRARY} ) -ENDIF(HUNTER_ENABLED) +ENDIF() if(ASSIMP_ANDROID_JNIIOSYSTEM) set(ASSIMP_ANDROID_JNIIOSYSTEM_PATH port/AndroidJNI) add_subdirectory(../${ASSIMP_ANDROID_JNIIOSYSTEM_PATH}/ ../${ASSIMP_ANDROID_JNIIOSYSTEM_PATH}/) target_link_libraries(assimp android_jniiosystem) -endif(ASSIMP_ANDROID_JNIIOSYSTEM) +endif() IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) TARGET_LINK_LIBRARIES(assimp optimized ${C4D_RELEASE_LIBRARIES}) TARGET_LINK_LIBRARIES(assimp debug ${C4D_DEBUG_LIBRARIES}) TARGET_LINK_LIBRARIES(assimp ${C4D_EXTRA_LIBRARIES}) -ENDIF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) +ENDIF () if( MSVC ) # in order to prevent DLL hell, each of the DLLs have to be suffixed with the major version and msvc prefix @@ -1233,8 +1233,8 @@ if (APPLE) "../${HEADER_PATH}/Compiler" assimp.framework/Headers/Compiler COMMENT "Copying public ./Compiler/ header files to framework bundle's Headers/Compiler/") - ENDIF(BUILD_FRAMEWORK) -ENDIF(APPLE) + ENDIF() +ENDIF() # Build against external unzip, or add ../contrib/unzip so # assimp can #include "unzip.h" @@ -1242,15 +1242,15 @@ IF(NOT HUNTER_ENABLED) if (UNZIP_FOUND) INCLUDE_DIRECTORIES(${UNZIP_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(assimp ${UNZIP_LIBRARIES}) - else (UNZIP_FOUND) + else () INCLUDE_DIRECTORIES("../") - endif (UNZIP_FOUND) -ENDIF(NOT HUNTER_ENABLED) + endif () +ENDIF() # Add RT-extension library for glTF importer with Open3DGC-compression. IF (RT_FOUND AND ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC) TARGET_LINK_LIBRARIES(assimp ${RT_LIBRARY}) -ENDIF (RT_FOUND AND ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC) +ENDIF () IF(HUNTER_ENABLED) INSTALL( TARGETS assimp @@ -1261,14 +1261,14 @@ IF(HUNTER_ENABLED) FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT} INCLUDES DESTINATION "include") -ELSE(HUNTER_ENABLED) +ELSE() INSTALL( TARGETS assimp LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} COMPONENT ${LIBASSIMP_COMPONENT}) -ENDIF(HUNTER_ENABLED) +ENDIF() INSTALL( FILES ${PUBLIC_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp COMPONENT assimp-dev) INSTALL( FILES ${COMPILER_HEADERS} DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR}/assimp/Compiler COMPONENT assimp-dev) @@ -1276,7 +1276,7 @@ if (ASSIMP_ANDROID_JNIIOSYSTEM) INSTALL(FILES ${HEADER_PATH}/${ASSIMP_ANDROID_JNIIOSYSTEM_PATH}/AndroidJNIIOSystem.h DESTINATION ${ASSIMP_INCLUDE_INSTALL_DIR} COMPONENT assimp-dev) -ENDIF(ASSIMP_ANDROID_JNIIOSYSTEM) +ENDIF() if(MSVC AND ASSIMP_INSTALL_PDB) # When only the static library is built, these properties must diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 362f1653d..8394ad703 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -1,4 +1,4 @@ # Compile internal irrXML only if system is not requested if( NOT SYSTEM_IRRXML ) add_subdirectory(irrXML) -endif( NOT SYSTEM_IRRXML ) +endif() diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index f7ce7b726..b510d8c37 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -6,7 +6,7 @@ set( HTML_OUTPUT "AssimpDoc_Html" CACHE STRING "Output directory for generated H set( MICROSOFT_HELP_WORKSHOP "NO") if( MSVC ) set( MICROSOFT_HELP_WORKSHOP "YES" ) -endif( MSVC ) +endif() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in @@ -38,5 +38,5 @@ if( DEFINED CMAKE_INSTALL_DOCDIR ) ${CMAKE_CURRENT_SOURCE_DIR}/AssimpDoc_Html/dragonsplash.png DESTINATION ${CMAKE_INSTALL_DOCDIR}/${HTML_OUTPUT} ) -endif( DEFINED CMAKE_INSTALL_DOCDIR ) +endif() diff --git a/samples/SimpleOpenGL/CMakeLists.txt b/samples/SimpleOpenGL/CMakeLists.txt index 93f389741..39593fdb9 100644 --- a/samples/SimpleOpenGL/CMakeLists.txt +++ b/samples/SimpleOpenGL/CMakeLists.txt @@ -2,24 +2,24 @@ FIND_PACKAGE(OpenGL) FIND_PACKAGE(GLUT) IF ( MSVC ) SET(M_LIB) -ELSE ( MSVC ) +ELSE () find_library(M_LIB m) -ENDIF ( MSVC ) +ENDIF () IF ( NOT GLUT_FOUND ) IF ( MSVC ) SET ( GLUT_FOUND 1 ) SET ( GLUT_INCLUDE_DIR ${Assimp_SOURCE_DIR}/samples/freeglut/ ) SET ( GLUT_LIBRARIES ${Assimp_SOURCE_DIR}/samples/freeglut/lib/freeglut.lib ) - ELSE ( MSVC ) + ELSE () MESSAGE( WARNING "Please install glut." ) - ENDIF ( MSVC ) -ENDIF ( NOT GLUT_FOUND ) + ENDIF () +ENDIF () if ( MSVC ) ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) -endif ( MSVC ) +endif () INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/include diff --git a/samples/SimpleTexturedDirectx11/CMakeLists.txt b/samples/SimpleTexturedDirectx11/CMakeLists.txt index 373b5a9db..b1882500e 100644 --- a/samples/SimpleTexturedDirectx11/CMakeLists.txt +++ b/samples/SimpleTexturedDirectx11/CMakeLists.txt @@ -2,13 +2,13 @@ FIND_PACKAGE(DirectX) IF ( MSVC ) SET(M_LIB) -ENDIF ( MSVC ) +ENDIF () if ( MSVC ) ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) REMOVE_DEFINITIONS( -DUNICODE -D_UNICODE ) -endif ( MSVC ) +endif () INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/include diff --git a/samples/SimpleTexturedOpenGL/CMakeLists.txt b/samples/SimpleTexturedOpenGL/CMakeLists.txt index 941e18cea..adcf882a8 100644 --- a/samples/SimpleTexturedOpenGL/CMakeLists.txt +++ b/samples/SimpleTexturedOpenGL/CMakeLists.txt @@ -6,15 +6,15 @@ IF ( NOT GLUT_FOUND ) SET ( GLUT_FOUND 1 ) SET ( GLUT_INCLUDE_DIR ${Assimp_SOURCE_DIR}/samples/freeglut/ ) SET ( GLUT_LIBRARIES ${Assimp_SOURCE_DIR}/samples/freeglut/lib/freeglut.lib ) - ELSE ( MSVC ) + ELSE () MESSAGE( WARNING "Please install glut." ) - ENDIF ( MSVC ) -ENDIF ( NOT GLUT_FOUND ) + ENDIF () +ENDIF () if ( MSVC ) ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) -endif ( MSVC ) +endif () INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b1d918a86..c5c414639 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -201,13 +201,13 @@ SET_PROPERTY( TARGET assimp PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} ) IF( WIN32 ) SET( platform_libs ) -ELSE( WIN32 ) +ELSE() SET( platform_libs pthread ) -ENDIF( WIN32 ) +ENDIF() IF(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) -ENDIF(MSVC) +ENDIF() target_link_libraries( unit assimp ${platform_libs} ) diff --git a/test/headercheck/CMakeLists.txt b/test/headercheck/CMakeLists.txt index fa6b35c66..b77e023a8 100644 --- a/test/headercheck/CMakeLists.txt +++ b/test/headercheck/CMakeLists.txt @@ -30,7 +30,7 @@ FOREACH( HEADER ${headers} ) # add library add_library( ${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_FILE} ) list(APPEND headerchecklibs ${TEST_NAME}) -ENDFOREACH( HEADER ) +ENDFOREACH() add_custom_target(headercheck DEPENDS ${headerchecklibs}) diff --git a/tools/assimp_view/CMakeLists.txt b/tools/assimp_view/CMakeLists.txt index dc1cee0d2..a77f13041 100644 --- a/tools/assimp_view/CMakeLists.txt +++ b/tools/assimp_view/CMakeLists.txt @@ -90,7 +90,7 @@ IF ( MSVC ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) # assimp_viewer is ANSI (MBCS) throughout REMOVE_DEFINITIONS( -DUNICODE -D_UNICODE ) -ENDIF ( MSVC ) +ENDIF () # Link the executable to the assimp + dx libs. TARGET_LINK_LIBRARIES ( assimp_viewer assimp ${DirectX_LIBRARY} ${DirectX_D3DX9_LIBRARY} comctl32.lib winmm.lib ) From 957abaa15adfccda8c1b78a41c062e1cd4750320 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Wed, 26 Feb 2020 08:00:49 -0500 Subject: [PATCH 16/30] Raised minimum CMake version to 3.0 for assimp_cmd and assimp_view. This is a follow-up to PR #3024, in which I explained that I would then change the version of CMake to 3.0 in several files to match the changes that were originally made by OP in PR #3008. The minimum CMake version have been raised to 3.0 in both assimp_cmd and assimp_view projects. The same CMake configuration as in PR #3024 was used. All projects from PR #3024 are found in the solution with the current changes. All projects built. All tests were run. --- tools/assimp_cmd/CMakeLists.txt | 2 +- tools/assimp_view/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/assimp_cmd/CMakeLists.txt b/tools/assimp_cmd/CMakeLists.txt index 848b8f81c..d46d09c2b 100644 --- a/tools/assimp_cmd/CMakeLists.txt +++ b/tools/assimp_cmd/CMakeLists.txt @@ -37,7 +37,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # #---------------------------------------------------------------------- -cmake_minimum_required( VERSION 2.6 ) +cmake_minimum_required( VERSION 3.0 ) INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/include diff --git a/tools/assimp_view/CMakeLists.txt b/tools/assimp_view/CMakeLists.txt index a77f13041..96b21db40 100644 --- a/tools/assimp_view/CMakeLists.txt +++ b/tools/assimp_view/CMakeLists.txt @@ -37,7 +37,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # #---------------------------------------------------------------------- -cmake_minimum_required( VERSION 2.6 ) +cmake_minimum_required( VERSION 3.0 ) FIND_PACKAGE(DirectX REQUIRED) From 4182d6fb60ee205c4f784c7e252e553687e85f27 Mon Sep 17 00:00:00 2001 From: Nikita Shubin Date: Wed, 26 Feb 2020 16:24:34 +0300 Subject: [PATCH 17/30] cmake: double quotes around the see https://cmake.org/cmake/help/latest/command/file.html#to-native-path --- assimpTargets-debug.cmake.in | 2 +- assimpTargets-release.cmake.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assimpTargets-debug.cmake.in b/assimpTargets-debug.cmake.in index e4ccbfba9..4cb917fd8 100644 --- a/assimpTargets-debug.cmake.in +++ b/assimpTargets-debug.cmake.in @@ -35,7 +35,7 @@ if(MSVC) endif() set(ASSIMP_LIBRARY_SUFFIX "@ASSIMP_LIBRARY_SUFFIX@-${MSVC_PREFIX}-mt" CACHE STRING "the suffix for the assimp windows library" ) - file(TO_NATIVE_PATH ${_IMPORT_PREFIX} _IMPORT_PREFIX) + file(TO_NATIVE_PATH "${_IMPORT_PREFIX}" _IMPORT_PREFIX) if(ASSIMP_BUILD_SHARED_LIBS) set(sharedLibraryName "assimp${ASSIMP_LIBRARY_SUFFIX}@CMAKE_DEBUG_POSTFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@") diff --git a/assimpTargets-release.cmake.in b/assimpTargets-release.cmake.in index 79b643a9a..702109305 100644 --- a/assimpTargets-release.cmake.in +++ b/assimpTargets-release.cmake.in @@ -35,7 +35,7 @@ if(MSVC) endif() set(ASSIMP_LIBRARY_SUFFIX "@ASSIMP_LIBRARY_SUFFIX@-${MSVC_PREFIX}-mt" CACHE STRING "the suffix for the assimp windows library" ) - file(TO_NATIVE_PATH ${_IMPORT_PREFIX} _IMPORT_PREFIX) + file(TO_NATIVE_PATH "${_IMPORT_PREFIX}" _IMPORT_PREFIX) if(ASSIMP_BUILD_SHARED_LIBS) set(sharedLibraryName "assimp${ASSIMP_LIBRARY_SUFFIX}@CMAKE_SHARED_LIBRARY_SUFFIX@") From 22311883ce2aca0477f764bb300541f02834645f Mon Sep 17 00:00:00 2001 From: Sebastian Matusik Date: Fri, 28 Feb 2020 18:39:40 -0800 Subject: [PATCH 18/30] Fix for #3037 [FATAL] SplitByBoneCountProcess::SplitMesh goes into infinite loop --- code/Common/SplitByBoneCountProcess.cpp | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/code/Common/SplitByBoneCountProcess.cpp b/code/Common/SplitByBoneCountProcess.cpp index b472cb359..e8e216478 100644 --- a/code/Common/SplitByBoneCountProcess.cpp +++ b/code/Common/SplitByBoneCountProcess.cpp @@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include using namespace Assimp; using namespace Assimp::Formatter; @@ -94,7 +95,10 @@ void SplitByBoneCountProcess::Execute( aiScene* pScene) bool isNecessary = false; for( unsigned int a = 0; a < pScene->mNumMeshes; ++a) if( pScene->mMeshes[a]->mNumBones > mMaxBoneCount ) + { isNecessary = true; + break; + } if( !isNecessary ) { @@ -155,7 +159,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormNumBones <= mMaxBoneCount ) + { return; + } // necessary optimisation: build a list of all affecting bones for each vertex // TODO: (thom) maybe add a custom allocator here to avoid allocating tens of thousands of small arrays @@ -165,7 +171,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormBones[a]; for( unsigned int b = 0; b < bone->mNumWeights; ++b) + { vertexBones[ bone->mWeights[b].mVertexId ].push_back( BoneWeight( a, bone->mWeights[b].mWeight)); + } } unsigned int numFacesHandled = 0; @@ -189,7 +197,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormFaces[a]; // check every vertex if its bones would still fit into the current submesh @@ -201,17 +211,27 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector mMaxBoneCount) + { + throw DeadlyImportError("SplitByBoneCountProcess: Single face requires more bones than specified max bone count!"); + } // leave out the face if the new bones required for this face don't fit the bone count limit anymore if( numBones + newBonesAtCurrentFace.size() > mMaxBoneCount ) + { continue; + } // mark all new bones as necessary while( !newBonesAtCurrentFace.empty() ) @@ -219,7 +239,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormName.length > 0 ) + { newMesh->mName.Set( format() << pMesh->mName.data << "_sub" << poNewMeshes.size()); + } newMesh->mMaterialIndex = pMesh->mMaterialIndex; newMesh->mPrimitiveTypes = pMesh->mPrimitiveTypes; poNewMeshes.push_back( newMesh); @@ -247,7 +271,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormNumFaces = static_cast(subMeshFaces.size()); newMesh->mVertices = new aiVector3D[newMesh->mNumVertices]; if( pMesh->HasNormals() ) + { newMesh->mNormals = new aiVector3D[newMesh->mNumVertices]; + } if( pMesh->HasTangentsAndBitangents() ) { newMesh->mTangents = new aiVector3D[newMesh->mNumVertices]; @@ -256,13 +282,17 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectorHasTextureCoords( a) ) + { newMesh->mTextureCoords[a] = new aiVector3D[newMesh->mNumVertices]; + } newMesh->mNumUVComponents[a] = pMesh->mNumUVComponents[a]; } for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a ) { if( pMesh->HasVertexColors( a) ) + { newMesh->mColors[a] = new aiColor4D[newMesh->mNumVertices]; + } } // and copy over the data, generating faces with linear indices along the way @@ -285,7 +315,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormVertices[nvi] = pMesh->mVertices[srcIndex]; if( pMesh->HasNormals() ) + { newMesh->mNormals[nvi] = pMesh->mNormals[srcIndex]; + } if( pMesh->HasTangentsAndBitangents() ) { newMesh->mTangents[nvi] = pMesh->mTangents[srcIndex]; @@ -294,12 +326,16 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectorHasTextureCoords( c) ) + { newMesh->mTextureCoords[c][nvi] = pMesh->mTextureCoords[c][srcIndex]; + } } for( unsigned int c = 0; c < AI_MAX_NUMBER_OF_COLOR_SETS; ++c ) { if( pMesh->HasVertexColors( c) ) + { newMesh->mColors[c][nvi] = pMesh->mColors[c][srcIndex]; + } } nvi++; @@ -316,7 +352,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vectormNumBones; ++a ) { if( !isBoneUsed[a] ) + { continue; + } // create the new bone const aiBone* srcBone = pMesh->mBones[a]; @@ -340,7 +378,9 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector::max() ) + { newMesh->mBones[newBoneIndex]->mNumWeights++; + } } } From 5f35d62d612fbc4af6a4dd48653192b08c0a26ad Mon Sep 17 00:00:00 2001 From: Sebastian Matusik Date: Fri, 28 Feb 2020 18:41:29 -0800 Subject: [PATCH 19/30] Fix for #3037 cause glTF2Importer creating bunch of bones with 0 for vertex with index 0 --- code/glTF2/glTF2Importer.cpp | 77 ++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index 5e137ed79..34591a461 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -111,8 +111,9 @@ const aiImporterDesc *glTF2Importer::GetInfo() const { bool glTF2Importer::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /* checkSig */) const { const std::string &extension = GetExtension(pFile); - if (extension != "gltf" && extension != "glb") + if (extension != "gltf" && extension != "glb") { return false; + } if (pIOHandler) { glTF2::Asset asset(pIOHandler); @@ -323,8 +324,9 @@ static inline bool CheckValidFacesIndices(aiFace *faces, unsigned nFaces, unsign for (unsigned i = 0; i < nFaces; ++i) { for (unsigned j = 0; j < faces[i].mNumIndices; ++j) { unsigned idx = faces[i].mIndices[j]; - if (idx >= nVerts) + if (idx >= nVerts) { return false; + } } } return true; @@ -861,7 +863,19 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector & if (node.skin) { for (int primitiveNo = 0; primitiveNo < count; ++primitiveNo) { aiMesh *mesh = pScene->mMeshes[meshOffsets[mesh_idx] + primitiveNo]; - mesh->mNumBones = static_cast(node.skin->jointNames.size()); + unsigned int numBones =static_cast(node.skin->jointNames.size()); + + std::vector> weighting(numBones); + BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting); + + unsigned int realNumBones = 0; + for (uint32_t i = 0; i < numBones; ++i) { + if (weighting[i].size() > 0) { + realNumBones++; + } + } + + mesh->mNumBones = static_cast(realNumBones); mesh->mBones = new aiBone *[mesh->mNumBones]; // GLTF and Assimp choose to store bone weights differently. @@ -873,43 +887,33 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector & // both because it's somewhat slow and because, for many applications, // we then need to reconvert the data back into the vertex-to-bone // mapping which makes things doubly-slow. - std::vector> weighting(mesh->mNumBones); - BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting); mat4 *pbindMatrices = nullptr; node.skin->inverseBindMatrices->ExtractData(pbindMatrices); + + int cb = 0; + for (uint32_t i = 0; i < numBones; ++i) { + const std::vector &weights = weighting[i]; + if (weights.size() > 0) { + aiBone *bone = new aiBone(); - for (uint32_t i = 0; i < mesh->mNumBones; ++i) { - aiBone *bone = new aiBone(); - - Ref joint = node.skin->jointNames[i]; - if (!joint->name.empty()) { - bone->mName = joint->name; - } else { - // Assimp expects each bone to have a unique name. - static const std::string kDefaultName = "bone_"; - char postfix[10] = { 0 }; - ASSIMP_itoa10(postfix, i); - bone->mName = (kDefaultName + postfix); - } - GetNodeTransform(bone->mOffsetMatrix, *joint); - - CopyValue(pbindMatrices[i], bone->mOffsetMatrix); - - std::vector &weights = weighting[i]; - - bone->mNumWeights = static_cast(weights.size()); - if (bone->mNumWeights > 0) { + Ref joint = node.skin->jointNames[i]; + if (!joint->name.empty()) { + bone->mName = joint->name; + } else { + // Assimp expects each bone to have a unique name. + static const std::string kDefaultName = "bone_"; + char postfix[10] = { 0 }; + ASSIMP_itoa10(postfix, i); + bone->mName = (kDefaultName + postfix); + } + GetNodeTransform(bone->mOffsetMatrix, *joint); + CopyValue(pbindMatrices[i], bone->mOffsetMatrix); + bone->mNumWeights = static_cast(weights.size()); bone->mWeights = new aiVertexWeight[bone->mNumWeights]; memcpy(bone->mWeights, weights.data(), bone->mNumWeights * sizeof(aiVertexWeight)); - } else { - // Assimp expects all bones to have at least 1 weight. - bone->mWeights = new aiVertexWeight[1]; - bone->mNumWeights = 1; - bone->mWeights->mVertexId = 0; - bone->mWeights->mWeight = 0.f; + mesh->mBones[cb++] = bone; } - mesh->mBones[i] = bone; } if (pbindMatrices) { @@ -1232,8 +1236,9 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { int numEmbeddedTexs = 0; for (size_t i = 0; i < r.images.Size(); ++i) { - if (r.images[i].HasData()) + if (r.images[i].HasData()) { numEmbeddedTexs += 1; + } } if (numEmbeddedTexs == 0) @@ -1244,7 +1249,9 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { // Add the embedded textures for (size_t i = 0; i < r.images.Size(); ++i) { Image &img = r.images[i]; - if (!img.HasData()) continue; + if (!img.HasData()) { + continue; + } int idx = mScene->mNumTextures++; embeddedTexIdxs[i] = idx; From 496fcd35c19b8ae4521487ad6d498d5476f69cfa Mon Sep 17 00:00:00 2001 From: Sebastian Matusik Date: Fri, 28 Feb 2020 19:17:53 -0800 Subject: [PATCH 20/30] Trimmed trailing whitespaces --- code/Common/SplitByBoneCountProcess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Common/SplitByBoneCountProcess.cpp b/code/Common/SplitByBoneCountProcess.cpp index e8e216478..ab7a1fe00 100644 --- a/code/Common/SplitByBoneCountProcess.cpp +++ b/code/Common/SplitByBoneCountProcess.cpp @@ -224,7 +224,7 @@ void SplitByBoneCountProcess::SplitMesh( const aiMesh* pMesh, std::vector mMaxBoneCount) - { + { throw DeadlyImportError("SplitByBoneCountProcess: Single face requires more bones than specified max bone count!"); } // leave out the face if the new bones required for this face don't fit the bone count limit anymore From 710dbba52dee0f4ac2f1e59a1f495ed287d88372 Mon Sep 17 00:00:00 2001 From: Sebastian Matusik Date: Fri, 28 Feb 2020 19:19:10 -0800 Subject: [PATCH 21/30] Trimmed trailing whitespaces --- code/glTF2/glTF2Importer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index 34591a461..8c33674e1 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -864,17 +864,17 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector & for (int primitiveNo = 0; primitiveNo < count; ++primitiveNo) { aiMesh *mesh = pScene->mMeshes[meshOffsets[mesh_idx] + primitiveNo]; unsigned int numBones =static_cast(node.skin->jointNames.size()); - + std::vector> weighting(numBones); BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting); - + unsigned int realNumBones = 0; for (uint32_t i = 0; i < numBones; ++i) { if (weighting[i].size() > 0) { realNumBones++; } } - + mesh->mNumBones = static_cast(realNumBones); mesh->mBones = new aiBone *[mesh->mNumBones]; @@ -890,7 +890,7 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector & mat4 *pbindMatrices = nullptr; node.skin->inverseBindMatrices->ExtractData(pbindMatrices); - + int cb = 0; for (uint32_t i = 0; i < numBones; ++i) { const std::vector &weights = weighting[i]; From aa8a6122cefb8286817a1250d87528105be1de34 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Fri, 6 Mar 2020 10:26:51 -0500 Subject: [PATCH 22/30] Fixed SimpleTexturedDirectX11 sample. - Removed OpenGL/Glut references in SimpleTexturedDirectX11 CMakeFile - Moved UTFConverter from SimpleTexturedOpenGL to its own file to be able to reuse it. - Added compile definition SHADER_PATH to allow to locate the shader files in CMakeFile - Fixed compile warnings - Made global pointers null to help prevent dangling references. - Added missing members initialization in class constructors. - Removed references to missing model "Models/mymodel.fbx" - Fixed error when extracting model file directory - Added missing device context assignment in ModelLoader Load method - Fixed memory leak caused by variable 'ourModel' not deleted. - Removed call to dev->Release() in ModelLoader.cpp - Adjusted Release() calls in reverse order when cleaning up D3D - Made Throwanerror implementation throw an error instead of displaying a message box - Fixed leaking D3D resources - Added a pointer to an ID3D11Debug to dump live objects. --- CMakeLists.txt | 2 + samples/SharedCode/UTFConverter.cpp | 52 +++++ samples/SharedCode/UTFConverter.h | 92 +++++++++ .../SimpleTexturedDirectx11/CMakeLists.txt | 9 +- .../SimpleTexturedDirectx11/Mesh.h | 47 +++-- .../SimpleTexturedDirectx11/ModelLoader.cpp | 16 +- .../SimpleTexturedDirectx11/SafeRelease.hpp | 57 ++++++ .../SimpleTexturedDirectx11/main.cpp | 183 +++++++++++++----- samples/SimpleTexturedOpenGL/CMakeLists.txt | 3 + .../src/model_loading.cpp | 34 +--- 10 files changed, 386 insertions(+), 109 deletions(-) create mode 100644 samples/SharedCode/UTFConverter.cpp create mode 100644 samples/SharedCode/UTFConverter.h create mode 100644 samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/SafeRelease.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 59b79d1c6..0a7f8eeae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -594,6 +594,8 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) ENDIF () IF ( ASSIMP_BUILD_SAMPLES) + SET( SAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples ) + SET( SAMPLES_SHARED_CODE_DIR ${SAMPLES_DIR}/SharedCode ) IF ( WIN32 ) ADD_SUBDIRECTORY( samples/SimpleTexturedOpenGL/ ) ADD_SUBDIRECTORY( samples/SimpleTexturedDirectx11 ) diff --git a/samples/SharedCode/UTFConverter.cpp b/samples/SharedCode/UTFConverter.cpp new file mode 100644 index 000000000..a1bff7e4b --- /dev/null +++ b/samples/SharedCode/UTFConverter.cpp @@ -0,0 +1,52 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2020, assimp team + + + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + +#include "UTFConverter.h" + +namespace AssimpSamples { +namespace SharedCode { + +typename UTFConverter::UTFConverterImpl UTFConverter::impl_; + +} +} diff --git a/samples/SharedCode/UTFConverter.h b/samples/SharedCode/UTFConverter.h new file mode 100644 index 000000000..17e89ee4d --- /dev/null +++ b/samples/SharedCode/UTFConverter.h @@ -0,0 +1,92 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2020, assimp team + + + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + +#ifndef ASSIMP_SAMPLES_SHARED_CODE_UTFCONVERTER_H +#define ASSIMP_SAMPLES_SHARED_CODE_UTFCONVERTER_H + +#include +#include +#include + +namespace AssimpSamples { +namespace SharedCode { + +// Used to convert between multibyte and unicode strings. +class UTFConverter { + using UTFConverterImpl = std::wstring_convert, wchar_t>; +public: + UTFConverter(const char* s) : + s_(s), + ws_(impl_.from_bytes(s)) { + } + UTFConverter(const wchar_t* s) : + s_(impl_.to_bytes(s)), + ws_(s) { + } + UTFConverter(const std::string& s) : + s_(s), + ws_(impl_.from_bytes(s)) { + } + UTFConverter(const std::wstring& s) : + s_(impl_.to_bytes(s)), + ws_(s) { + } + inline const char* c_str() const { + return s_.c_str(); + } + inline const std::string& str() const { + return s_; + } + inline const wchar_t* c_wstr() const { + return ws_.c_str(); + } +private: + static UTFConverterImpl impl_; + std::string s_; + std::wstring ws_; +}; + +} +} + +#endif // ASSIMP_SAMPLES_SHARED_CODE_UTFCONVERTER_H diff --git a/samples/SimpleTexturedDirectx11/CMakeLists.txt b/samples/SimpleTexturedDirectx11/CMakeLists.txt index b1882500e..9016b8869 100644 --- a/samples/SimpleTexturedDirectx11/CMakeLists.txt +++ b/samples/SimpleTexturedDirectx11/CMakeLists.txt @@ -10,12 +10,12 @@ if ( MSVC ) REMOVE_DEFINITIONS( -DUNICODE -D_UNICODE ) endif () +ADD_COMPILE_DEFINITIONS(SHADER_PATH="${CMAKE_CURRENT_SOURCE_DIR}/SimpleTexturedDirectx11/") + INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/include ${Assimp_SOURCE_DIR}/code - ${OPENGL_INCLUDE_DIR} - ${GLUT_INCLUDE_DIR} - ${Assimp_SOURCE_DIR}/samples/freeglut/include + ${SAMPLES_SHARED_CODE_DIR} ) LINK_DIRECTORIES( @@ -32,6 +32,9 @@ ADD_EXECUTABLE( assimp_simpletextureddirectx11 WIN32 SimpleTexturedDirectx11/TextureLoader.h #SimpleTexturedDirectx11/VertexShader.hlsl SimpleTexturedDirectx11/main.cpp + SimpleTexturedDirectx11/SafeRelease.hpp + ${SAMPLES_SHARED_CODE_DIR}/UTFConverter.cpp + ${SAMPLES_SHARED_CODE_DIR}/UTFConverter.h ) SET_PROPERTY(TARGET assimp_simpletextureddirectx11 PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h index 87433219f..3a2875a1f 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h @@ -6,6 +6,7 @@ #include #include #include +#include using namespace std; #include @@ -13,6 +14,8 @@ using namespace std; #include using namespace DirectX; +#include "SafeRelease.hpp" + struct VERTEX { FLOAT X, Y, Z; XMFLOAT2 texcoord; @@ -22,6 +25,10 @@ struct Texture { string type; string path; ID3D11ShaderResourceView *texture; + + inline void Release() { + SafeRelease(texture); + } }; class Mesh { @@ -31,15 +38,15 @@ public: vector textures; ID3D11Device *dev; - Mesh(ID3D11Device *dev, vector vertices, vector indices, vector textures) + Mesh(ID3D11Device *dev, const vector& vertices, const vector& indices, const vector& textures) : + vertices(vertices), + indices(indices), + textures(textures), + dev(dev), + VertexBuffer(nullptr), + IndexBuffer(nullptr) { - this->vertices = vertices; - this->indices = indices; - this->textures = textures; - - this->dev = dev; - - this->setupMesh(dev); + this->setupMesh(this->dev); } void Draw(ID3D11DeviceContext *devcon) @@ -52,13 +59,13 @@ public: devcon->PSSetShaderResources(0, 1, &textures[0].texture); - devcon->DrawIndexed(indices.size(), 0, 0); + devcon->DrawIndexed(static_cast(indices.size()), 0, 0); } void Close() { - VertexBuffer->Release(); - IndexBuffer->Release(); + SafeRelease(VertexBuffer); + SafeRelease(IndexBuffer); } private: /* Render data */ @@ -66,13 +73,13 @@ private: /* Functions */ // Initializes all the buffer objects/arrays - bool setupMesh(ID3D11Device *dev) + void setupMesh(ID3D11Device *dev) { HRESULT hr; D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; - vbd.ByteWidth = sizeof(VERTEX) * vertices.size(); + vbd.ByteWidth = static_cast(sizeof(VERTEX) * vertices.size()); vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; @@ -81,12 +88,14 @@ private: initData.pSysMem = &vertices[0]; hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer); - if (FAILED(hr)) - return false; + if (FAILED(hr)) { + Close(); + throw std::runtime_error("Failed to create vertex buffer."); + } D3D11_BUFFER_DESC ibd; ibd.Usage = D3D11_USAGE_IMMUTABLE; - ibd.ByteWidth = sizeof(UINT) * indices.size(); + ibd.ByteWidth = static_cast(sizeof(UINT) * indices.size()); ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; ibd.CPUAccessFlags = 0; ibd.MiscFlags = 0; @@ -94,8 +103,10 @@ private: initData.pSysMem = &indices[0]; hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer); - if (FAILED(hr)) - return false; + if (FAILED(hr)) { + Close(); + throw std::runtime_error("Failed to create index buffer."); + } } }; diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index 10ba07a98..b0f086a5d 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -1,6 +1,12 @@ #include "ModelLoader.h" -ModelLoader::ModelLoader() +ModelLoader::ModelLoader() : + dev(nullptr), + devcon(nullptr), + meshes(), + directory(), + textures_loaded(), + hwnd(nullptr) { } @@ -20,9 +26,10 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc if (pScene == NULL) return false; - this->directory = filename.substr(0, filename.find_last_of('/')); + this->directory = filename.substr(0, filename.find_last_of("/\\")); this->dev = dev; + this->devcon = devcon; this->hwnd = hwnd; processNode(pScene->mRootNode, pScene); @@ -138,12 +145,13 @@ vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureTyp void ModelLoader::Close() { + for (auto& t : textures_loaded) + t.Release(); + for (int i = 0; i < meshes.size(); i++) { meshes[i].Close(); } - - dev->Release(); } void ModelLoader::processNode(aiNode * node, const aiScene * scene) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/SafeRelease.hpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/SafeRelease.hpp new file mode 100644 index 000000000..2fd80db6c --- /dev/null +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/SafeRelease.hpp @@ -0,0 +1,57 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (assimp) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2020, assimp team + + + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the following +conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--------------------------------------------------------------------------- +*/ + +#ifdef _MSC_VER +#pragma once +#endif + +/* Used to reduce to reduce the number of lines when calling Release() + on a D3D interface. Implemented as a template instead of a 'SAFE_RELEASE' + MACRO to ease debugging. */ +template +inline void SafeRelease(T*& x) { + if (x) { + x->Release(); + x = nullptr; + } +} diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp index 2d847095a..781fe89e5 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/main.cpp @@ -14,12 +14,16 @@ // --------------------------------------------------------------------------- #include +#include +#include #include #include #include #include #include #include "ModelLoader.h" +#include "UTFConverter.h" +#include "SafeRelease.hpp" #pragma comment (lib, "d3d11.lib") #pragma comment (lib, "Dxgi.lib") @@ -27,6 +31,10 @@ #pragma comment (lib, "dxguid.lib") using namespace DirectX; +using namespace AssimpSamples::SharedCode; + +#define VERTEX_SHADER_FILE L"VertexShader.hlsl" +#define PIXEL_SHADER_FILE L"PixelShader.hlsl" // ------------------------------------------------------------ // Structs @@ -45,29 +53,32 @@ struct ConstantBuffer { const char g_szClassName[] = "directxWindowClass"; +static std::string g_ModelPath; UINT width, height; -HWND hwnd; +HWND hwnd = nullptr; // ------------------------------------------------------------ // DirectX Variables // ------------------------------------------------------------ D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; -ID3D11Device *dev; -ID3D11Device1 *dev1; -ID3D11DeviceContext *devcon; -ID3D11DeviceContext1 *devcon1; -IDXGISwapChain *swapchain; -IDXGISwapChain1 *swapchain1; -ID3D11RenderTargetView *backbuffer; -ID3D11VertexShader *pVS; -ID3D11PixelShader *pPS; -ID3D11InputLayout *pLayout; -ID3D11Buffer *pConstantBuffer; -ID3D11Texture2D *g_pDepthStencil; -ID3D11DepthStencilView *g_pDepthStencilView; -ID3D11SamplerState *TexSamplerState; +ID3D11Device *dev = nullptr; +ID3D11Device1 *dev1 = nullptr; +ID3D11DeviceContext *devcon = nullptr; +ID3D11DeviceContext1 *devcon1 = nullptr; +IDXGISwapChain *swapchain = nullptr; +IDXGISwapChain1 *swapchain1 = nullptr; +ID3D11RenderTargetView *backbuffer = nullptr; +ID3D11VertexShader *pVS = nullptr; +ID3D11PixelShader *pPS = nullptr; +ID3D11InputLayout *pLayout = nullptr; +ID3D11Buffer *pConstantBuffer = nullptr; +ID3D11Texture2D *g_pDepthStencil = nullptr; +ID3D11DepthStencilView *g_pDepthStencilView = nullptr; +ID3D11SamplerState *TexSamplerState = nullptr; +ID3D11RasterizerState *rasterstate = nullptr; +ID3D11Debug* d3d11debug = nullptr; XMMATRIX m_World; XMMATRIX m_View; @@ -91,7 +102,7 @@ void Throwanerror(LPCSTR errormessage); // Our Model // ------------------------------------------------------------ -ModelLoader *ourModel; +ModelLoader *ourModel = nullptr; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -109,9 +120,42 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return 0; } -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, int nCmdShow) +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPWSTR lpCmdLine, int nCmdShow) { + int argc; + LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); + if (!argv) { + MessageBox(NULL, + TEXT("An error occured while reading command line arguments."), + TEXT("Error!"), + MB_ICONERROR | MB_OK); + return EXIT_FAILURE; + } + + // Free memory allocated from CommandLineToArgvW. + auto free_command_line_allocated_memory = [&argv]() { + if (argv) { + LocalFree(argv); + argv = nullptr; + } + }; + + // Ensure that a model file has been specified. + if (argc < 2) { + MessageBox(NULL, + TEXT("No model file specified. The program will now close."), + TEXT("Error!"), + MB_ICONERROR | MB_OK); + free_command_line_allocated_memory(); + return EXIT_FAILURE; + } + + // Retrieve the model file path. + g_ModelPath = UTFConverter(argv[1]).str(); + + free_command_line_allocated_memory(); + WNDCLASSEX wc; MSG msg; @@ -160,26 +204,35 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, width = wr.right - wr.left; height = wr.bottom - wr.top; - InitD3D(hInstance, hwnd); + try { + InitD3D(hInstance, hwnd); - while (true) - { - - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + while (true) { - TranslateMessage(&msg); - DispatchMessage(&msg); - if (msg.message == WM_QUIT) - break; + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + + if (msg.message == WM_QUIT) + break; + } + + RenderFrame(); } - RenderFrame(); + CleanD3D(); + return static_cast(msg.wParam); + } catch (const std::exception& e) { + MessageBox(hwnd, e.what(), TEXT("Error!"), MB_ICONERROR | MB_OK); + CleanD3D(); + return EXIT_FAILURE; + } catch (...) { + MessageBox(hwnd, TEXT("Caught an unknown exception."), TEXT("Error!"), MB_ICONERROR | MB_OK); + CleanD3D(); + return EXIT_FAILURE; } - - CleanD3D(); - - return msg.wParam; } void InitD3D(HINSTANCE hinstance, HWND hWnd) @@ -227,6 +280,12 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd) if (FAILED(hr)) Throwanerror("Directx Device Creation Failed!"); +#if _DEBUG + hr = dev->QueryInterface(IID_PPV_ARGS(&d3d11debug)); + if (FAILED(hr)) + OutputDebugString(TEXT("Failed to retrieve DirectX 11 debug interface.\n")); +#endif + UINT m4xMsaaQuality; dev->CheckMultisampleQualityLevels( DXGI_FORMAT_R8G8B8A8_UNORM, 4, &m4xMsaaQuality); @@ -348,7 +407,6 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd) devcon->OMSetRenderTargets(1, &backbuffer, g_pDepthStencilView); D3D11_RASTERIZER_DESC rasterDesc; - ID3D11RasterizerState *rasterState; rasterDesc.AntialiasedLineEnable = false; rasterDesc.CullMode = D3D11_CULL_BACK; rasterDesc.DepthBias = 0; @@ -360,8 +418,8 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd) rasterDesc.ScissorEnable = false; rasterDesc.SlopeScaledDepthBias = 0.0f; - dev->CreateRasterizerState(&rasterDesc, &rasterState); - devcon->RSSetState(rasterState); + dev->CreateRasterizerState(&rasterDesc, &rasterstate); + devcon->RSSetState(rasterstate); D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); @@ -381,19 +439,38 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd) void CleanD3D(void) { - swapchain->SetFullscreenState(FALSE, NULL); + if (swapchain) + swapchain->SetFullscreenState(FALSE, NULL); - ourModel->Close(); - g_pDepthStencil->Release(); - g_pDepthStencilView->Release(); - pLayout->Release(); - pVS->Release(); - pPS->Release(); - pConstantBuffer->Release(); - swapchain->Release(); - backbuffer->Release(); - dev->Release(); - devcon->Release(); + if (ourModel) { + ourModel->Close(); + delete ourModel; + ourModel = nullptr; + } + SafeRelease(TexSamplerState); + SafeRelease(pConstantBuffer); + SafeRelease(pLayout); + SafeRelease(pVS); + SafeRelease(pPS); + SafeRelease(rasterstate); + SafeRelease(g_pDepthStencilView); + SafeRelease(g_pDepthStencil); + SafeRelease(backbuffer); + SafeRelease(swapchain); + SafeRelease(swapchain1); + SafeRelease(devcon1); + SafeRelease(dev1); + SafeRelease(devcon); +#if _DEBUG + if (d3d11debug) { + OutputDebugString(TEXT("Dumping DirectX 11 live objects.\n")); + d3d11debug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL); + SafeRelease(d3d11debug); + } else { + OutputDebugString(TEXT("Unable to dump live objects: no DirectX 11 debug interface available.\n")); + } +#endif + SafeRelease(dev); } void RenderFrame(void) @@ -431,8 +508,10 @@ void RenderFrame(void) void InitPipeline() { ID3DBlob *VS, *PS; - CompileShaderFromFile(L"VertexShader.hlsl", 0, "main", "vs_4_0", &VS); - CompileShaderFromFile(L"PixelShader.hlsl", 0, "main", "ps_4_0", &PS); + if(FAILED(CompileShaderFromFile(SHADER_PATH VERTEX_SHADER_FILE, 0, "main", "vs_4_0", &VS))) + Throwanerror(UTFConverter(L"Failed to compile shader from file " VERTEX_SHADER_FILE).c_str()); + if(FAILED(CompileShaderFromFile(SHADER_PATH PIXEL_SHADER_FILE, 0, "main", "ps_4_0", &PS))) + Throwanerror(UTFConverter(L"Failed to compile shader from file " PIXEL_SHADER_FILE).c_str()); dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS); dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS); @@ -485,7 +564,7 @@ void InitGraphics() m_View = XMMatrixLookAtLH(Eye, At, Up); ourModel = new ModelLoader; - if (!ourModel->Load(hwnd, dev, devcon, "Models/myModel.fbx")) + if (!ourModel->Load(hwnd, dev, devcon, g_ModelPath)) Throwanerror("Model couldn't be loaded"); } @@ -514,5 +593,5 @@ HRESULT CompileShaderFromFile(LPCWSTR pFileName, const D3D_SHADER_MACRO* pDefine void Throwanerror(LPCSTR errormessage) { - MessageBox(hwnd, errormessage, "Error!", MB_ICONERROR | MB_OK); -} \ No newline at end of file + throw std::runtime_error(errormessage); +} diff --git a/samples/SimpleTexturedOpenGL/CMakeLists.txt b/samples/SimpleTexturedOpenGL/CMakeLists.txt index adcf882a8..e40c40f29 100644 --- a/samples/SimpleTexturedOpenGL/CMakeLists.txt +++ b/samples/SimpleTexturedOpenGL/CMakeLists.txt @@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES( ${Assimp_SOURCE_DIR}/code ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} + ${SAMPLES_SHARED_CODE_DIR} ) LINK_DIRECTORIES( @@ -31,6 +32,8 @@ LINK_DIRECTORIES( ADD_EXECUTABLE( assimp_simpletexturedogl WIN32 SimpleTexturedOpenGL/include/boost_includes.h SimpleTexturedOpenGL/src/model_loading.cpp + ${SAMPLES_SHARED_CODE_DIR}/UTFConverter.cpp + ${SAMPLES_SHARED_CODE_DIR}/UTFConverter.h ) SET_PROPERTY(TARGET assimp_simpletexturedogl PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) diff --git a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp index 8c2a08b2e..452c0715c 100644 --- a/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp +++ b/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp @@ -21,8 +21,6 @@ #define STB_IMAGE_IMPLEMENTATION #include "contrib/stb_image/stb_image.h" -#include -#include #include //to map image filenames to textureIds @@ -35,7 +33,7 @@ #include #include #include - +#include "UTFConverter.h" // The default hard-coded path. Can be overridden by supplying a path through the command line. static std::string modelpath = "../../test/models/OBJ/spider.obj"; @@ -77,35 +75,7 @@ GLuint* textureIds; // pointer to texture Array // Create an instance of the Importer class Assimp::Importer importer; -// Used to convert between multibyte and unicode strings. -class UTFConverter { - using UTFConverterImpl = std::wstring_convert, wchar_t>; -public: - UTFConverter(const char* s) : - s_(s), - ws_(impl_.from_bytes(s)) { - } - UTFConverter(const std::string& s) : - s_(s), - ws_(impl_.from_bytes(s)) { - } - UTFConverter(const std::wstring& s) : - s_(impl_.to_bytes(s)), - ws_(s) { - } - inline const std::string& str() const { - return s_; - } - inline const wchar_t* c_wstr() const { - return ws_.c_str(); - } -private: - static UTFConverterImpl impl_; - std::string s_; - std::wstring ws_; -}; - -typename UTFConverter::UTFConverterImpl UTFConverter::impl_; +using namespace AssimpSamples::SharedCode; void createAILogger() { From 31c6f0db928add0e4ff22877bd4c91b5418aa2e4 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 7 Mar 2020 12:19:55 +0100 Subject: [PATCH 23/30] Update Mesh.h Apply code style. --- .../SimpleTexturedDirectx11/Mesh.h | 124 +++++++++--------- 1 file changed, 59 insertions(+), 65 deletions(-) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h index 3a2875a1f..fb2f7f7db 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h @@ -7,11 +7,9 @@ #include #include #include -using namespace std; - -#include #include #include + using namespace DirectX; #include "SafeRelease.hpp" @@ -26,88 +24,84 @@ struct Texture { string path; ID3D11ShaderResourceView *texture; - inline void Release() { + void Release() { SafeRelease(texture); } }; class Mesh { public: - vector vertices; - vector indices; - vector textures; - ID3D11Device *dev; + std::vector vertices; + std::vector indices; + std::vector textures; + ID3D11Device *dev; - Mesh(ID3D11Device *dev, const vector& vertices, const vector& indices, const vector& textures) : - vertices(vertices), - indices(indices), - textures(textures), - dev(dev), - VertexBuffer(nullptr), - IndexBuffer(nullptr) - { - this->setupMesh(this->dev); - } + Mesh(ID3D11Device *dev, const vector& vertices, const vector& indices, const vector& textures) : + vertices(vertices), + indices(indices), + textures(textures), + dev(dev), + VertexBuffer(nullptr), + IndexBuffer(nullptr) { + this->setupMesh(this->dev); + } - void Draw(ID3D11DeviceContext *devcon) - { - UINT stride = sizeof(VERTEX); - UINT offset = 0; + void Draw(ID3D11DeviceContext *devcon) { + UINT stride = sizeof(VERTEX); + UINT offset = 0; - devcon->IASetVertexBuffers(0, 1, &VertexBuffer, &stride, &offset); - devcon->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0); + devcon->IASetVertexBuffers(0, 1, &VertexBuffer, &stride, &offset); + devcon->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0); - devcon->PSSetShaderResources(0, 1, &textures[0].texture); + devcon->PSSetShaderResources(0, 1, &textures[0].texture); - devcon->DrawIndexed(static_cast(indices.size()), 0, 0); - } + devcon->DrawIndexed(static_cast(indices.size()), 0, 0); + } - void Close() - { - SafeRelease(VertexBuffer); - SafeRelease(IndexBuffer); - } + void Close() { + SafeRelease(VertexBuffer); + SafeRelease(IndexBuffer); + } private: - /* Render data */ - ID3D11Buffer *VertexBuffer, *IndexBuffer; + // Render data + ID3D11Buffer *VertexBuffer, *IndexBuffer; - /* Functions */ - // Initializes all the buffer objects/arrays - void setupMesh(ID3D11Device *dev) - { - HRESULT hr; + // Functions + // Initializes all the buffer objects/arrays + void setupMesh(ID3D11Device *dev) { + HRESULT hr; - D3D11_BUFFER_DESC vbd; - vbd.Usage = D3D11_USAGE_IMMUTABLE; - vbd.ByteWidth = static_cast(sizeof(VERTEX) * vertices.size()); - vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vbd.CPUAccessFlags = 0; - vbd.MiscFlags = 0; + D3D11_BUFFER_DESC vbd; + vbd.Usage = D3D11_USAGE_IMMUTABLE; + vbd.ByteWidth = static_cast(sizeof(VERTEX) * vertices.size()); + vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; + vbd.CPUAccessFlags = 0; + vbd.MiscFlags = 0; - D3D11_SUBRESOURCE_DATA initData; - initData.pSysMem = &vertices[0]; + D3D11_SUBRESOURCE_DATA initData; + initData.pSysMem = &vertices[0]; - hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer); - if (FAILED(hr)) { - Close(); - throw std::runtime_error("Failed to create vertex buffer."); - } + hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer); + if (FAILED(hr)) { + Close(); + throw std::runtime_error("Failed to create vertex buffer."); + } - D3D11_BUFFER_DESC ibd; - ibd.Usage = D3D11_USAGE_IMMUTABLE; - ibd.ByteWidth = static_cast(sizeof(UINT) * indices.size()); - ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; - ibd.CPUAccessFlags = 0; - ibd.MiscFlags = 0; + D3D11_BUFFER_DESC ibd; + ibd.Usage = D3D11_USAGE_IMMUTABLE; + ibd.ByteWidth = static_cast(sizeof(UINT) * indices.size()); + ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; + ibd.CPUAccessFlags = 0; + ibd.MiscFlags = 0; - initData.pSysMem = &indices[0]; + initData.pSysMem = &indices[0]; - hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer); - if (FAILED(hr)) { - Close(); - throw std::runtime_error("Failed to create index buffer."); - } - } + hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer); + if (FAILED(hr)) { + Close(); + throw std::runtime_error("Failed to create index buffer."); + } + } }; #endif From b5d65bf94e2cedd5dd60443d66de92d61f3ccf6d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 7 Mar 2020 12:22:57 +0100 Subject: [PATCH 24/30] Update ModelLoader.cpp Apply asimp-code-style. --- .../SimpleTexturedDirectx11/ModelLoader.cpp | 108 +++++++----------- 1 file changed, 40 insertions(+), 68 deletions(-) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index b0f086a5d..1ab5b61fb 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -1,22 +1,21 @@ #include "ModelLoader.h" ModelLoader::ModelLoader() : - dev(nullptr), - devcon(nullptr), - meshes(), - directory(), - textures_loaded(), - hwnd(nullptr) -{ + dev(nullptr), + devcon(nullptr), + meshes(), + directory(), + textures_loaded(), + hwnd(nullptr) { + // empty } -ModelLoader::~ModelLoader() -{ +ModelLoader::~ModelLoader() { + // empty } -bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devcon, std::string filename) -{ +bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devcon, std::string filename) { Assimp::Importer importer; const aiScene* pScene = importer.ReadFile(filename, @@ -37,41 +36,37 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc return true; } -void ModelLoader::Draw(ID3D11DeviceContext * devcon) -{ - for (int i = 0; i < meshes.size(); i++) - { +void ModelLoader::Draw(ID3D11DeviceContext * devcon) { + for (int i = 0; i < meshes.size(); ++i ) { meshes[i].Draw(devcon); } } string textype; -Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) -{ +Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) { // Data to fill vector vertices; vector indices; vector textures; - if (mesh->mMaterialIndex >= 0) - { + if (mesh->mMaterialIndex >= 0) { aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex]; - if (textype.empty()) textype = determineTextureType(scene, mat); + if (textype.empty()) { + textype = determineTextureType(scene, mat); + } } // Walk through each of the mesh's vertices - for (UINT i = 0; i < mesh->mNumVertices; i++) - { + for (UINT i = 0; i < mesh->mNumVertices; i++) { VERTEX vertex; vertex.X = mesh->mVertices[i].x; vertex.Y = mesh->mVertices[i].y; vertex.Z = mesh->mVertices[i].z; - if (mesh->mTextureCoords[0]) - { + if (mesh->mTextureCoords[0]) { vertex.texcoord.x = (float)mesh->mTextureCoords[0][i].x; vertex.texcoord.y = (float)mesh->mTextureCoords[0][i].y; } @@ -79,16 +74,14 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) vertices.push_back(vertex); } - for (UINT i = 0; i < mesh->mNumFaces; i++) - { + for (UINT i = 0; i < mesh->mNumFaces; i++) { aiFace face = mesh->mFaces[i]; for (UINT j = 0; j < face.mNumIndices; j++) indices.push_back(face.mIndices[j]); } - if (mesh->mMaterialIndex >= 0) - { + if (mesh->mMaterialIndex >= 0) { aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; vector diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse", scene); @@ -98,35 +91,27 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) return Mesh(dev, vertices, indices, textures); } -vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, string typeName, const aiScene * scene) -{ +vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, string typeName, const aiScene * scene) { vector textures; - for (UINT i = 0; i < mat->GetTextureCount(type); i++) - { + for (UINT i = 0; i < mat->GetTextureCount(type); i++) { aiString str; mat->GetTexture(type, i, &str); // Check if texture was loaded before and if so, continue to next iteration: skip loading a new texture bool skip = false; - for (UINT j = 0; j < textures_loaded.size(); j++) - { - if (std::strcmp(textures_loaded[j].path.c_str(), str.C_Str()) == 0) - { + for (UINT j = 0; j < textures_loaded.size(); j++) { + if (std::strcmp(textures_loaded[j].path.c_str(), str.C_Str()) == 0) { textures.push_back(textures_loaded[j]); skip = true; // A texture with the same filepath has already been loaded, continue to next one. (optimization) break; } } - if (!skip) - { // If texture hasn't been loaded already, load it + if (!skip) { // If texture hasn't been loaded already, load it HRESULT hr; Texture texture; - if (textype == "embedded compressed texture") - { + if (textype == "embedded compressed texture") { int textureindex = getTextureIndex(&str); texture.texture = getTextureFromModel(scene, textureindex); - } - else - { + } else { string filename = string(str.C_Str()); filename = directory + '/' + filename; wstring filenamews = wstring(filename.begin(), filename.end()); @@ -143,65 +128,52 @@ vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureTyp return textures; } -void ModelLoader::Close() -{ +void ModelLoader::Close() { for (auto& t : textures_loaded) t.Release(); - for (int i = 0; i < meshes.size(); i++) - { + for (int i = 0; i < meshes.size(); i++) { meshes[i].Close(); } } -void ModelLoader::processNode(aiNode * node, const aiScene * scene) -{ - for (UINT i = 0; i < node->mNumMeshes; i++) - { +void ModelLoader::processNode(aiNode * node, const aiScene * scene) { + for (UINT i = 0; i < node->mNumMeshes; i++) { aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; meshes.push_back(this->processMesh(mesh, scene)); } - for (UINT i = 0; i < node->mNumChildren; i++) - { + for (UINT i = 0; i < node->mNumChildren; i++) { this->processNode(node->mChildren[i], scene); } } -string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat) -{ +string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat) { aiString textypeStr; mat->GetTexture(aiTextureType_DIFFUSE, 0, &textypeStr); string textypeteststr = textypeStr.C_Str(); - if (textypeteststr == "*0" || textypeteststr == "*1" || textypeteststr == "*2" || textypeteststr == "*3" || textypeteststr == "*4" || textypeteststr == "*5") - { - if (scene->mTextures[0]->mHeight == 0) - { + if (textypeteststr == "*0" || textypeteststr == "*1" || textypeteststr == "*2" || textypeteststr == "*3" || textypeteststr == "*4" || textypeteststr == "*5") { + if (scene->mTextures[0]->mHeight == 0) { return "embedded compressed texture"; - } - else - { + } else { return "embedded non-compressed texture"; } } - if (textypeteststr.find('.') != string::npos) - { + if (textypeteststr.find('.') != string::npos) { return "textures are on disk"; } return "."; } -int ModelLoader::getTextureIndex(aiString * str) -{ +int ModelLoader::getTextureIndex(aiString * str) { string tistr; tistr = str->C_Str(); tistr = tistr.substr(1); return stoi(tistr); } -ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scene, int textureindex) -{ +ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scene, int textureindex) { HRESULT hr; ID3D11ShaderResourceView *texture; From dda083fa7bd7034f8fb31bf8ffc0a4d2bccf80fd Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Sun, 8 Mar 2020 10:50:18 -0400 Subject: [PATCH 25/30] Added missing std namespace prefix to std types. --- .../SimpleTexturedDirectx11/Mesh.h | 6 ++--- .../SimpleTexturedDirectx11/ModelLoader.cpp | 26 +++++++++---------- .../SimpleTexturedDirectx11/ModelLoader.h | 8 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h index fb2f7f7db..125b3e585 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/Mesh.h @@ -20,8 +20,8 @@ struct VERTEX { }; struct Texture { - string type; - string path; + std::string type; + std::string path; ID3D11ShaderResourceView *texture; void Release() { @@ -36,7 +36,7 @@ public: std::vector textures; ID3D11Device *dev; - Mesh(ID3D11Device *dev, const vector& vertices, const vector& indices, const vector& textures) : + Mesh(ID3D11Device *dev, const std::vector& vertices, const std::vector& indices, const std::vector& textures) : vertices(vertices), indices(indices), textures(textures), diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index 1ab5b61fb..806320144 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -42,13 +42,13 @@ void ModelLoader::Draw(ID3D11DeviceContext * devcon) { } } -string textype; +std::string textype; Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) { // Data to fill - vector vertices; - vector indices; - vector textures; + std::vector vertices; + std::vector indices; + std::vector textures; if (mesh->mMaterialIndex >= 0) { aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex]; @@ -84,15 +84,15 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) { if (mesh->mMaterialIndex >= 0) { aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex]; - vector diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse", scene); + std::vector diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse", scene); textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end()); } return Mesh(dev, vertices, indices, textures); } -vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, string typeName, const aiScene * scene) { - vector textures; +std::vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, std::string typeName, const aiScene * scene) { + std::vector textures; for (UINT i = 0; i < mat->GetTextureCount(type); i++) { aiString str; mat->GetTexture(type, i, &str); @@ -112,9 +112,9 @@ vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureTyp int textureindex = getTextureIndex(&str); texture.texture = getTextureFromModel(scene, textureindex); } else { - string filename = string(str.C_Str()); + std::string filename = std::string(str.C_Str()); filename = directory + '/' + filename; - wstring filenamews = wstring(filename.begin(), filename.end()); + std::wstring filenamews = std::wstring(filename.begin(), filename.end()); hr = CreateWICTextureFromFile(dev, devcon, filenamews.c_str(), nullptr, &texture.texture); if (FAILED(hr)) MessageBox(hwnd, "Texture couldn't be loaded", "Error!", MB_ICONERROR | MB_OK); @@ -148,10 +148,10 @@ void ModelLoader::processNode(aiNode * node, const aiScene * scene) { } } -string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat) { +std::string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat) { aiString textypeStr; mat->GetTexture(aiTextureType_DIFFUSE, 0, &textypeStr); - string textypeteststr = textypeStr.C_Str(); + std::string textypeteststr = textypeStr.C_Str(); if (textypeteststr == "*0" || textypeteststr == "*1" || textypeteststr == "*2" || textypeteststr == "*3" || textypeteststr == "*4" || textypeteststr == "*5") { if (scene->mTextures[0]->mHeight == 0) { return "embedded compressed texture"; @@ -159,7 +159,7 @@ string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat return "embedded non-compressed texture"; } } - if (textypeteststr.find('.') != string::npos) { + if (textypeteststr.find('.') != std::string::npos) { return "textures are on disk"; } @@ -167,7 +167,7 @@ string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat } int ModelLoader::getTextureIndex(aiString * str) { - string tistr; + std::string tistr; tistr = str->C_Str(); tistr = tistr.substr(1); return stoi(tistr); diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h index 9b4a53c27..18ad03fa0 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h @@ -28,14 +28,14 @@ private: ID3D11Device *dev; ID3D11DeviceContext *devcon; std::vector meshes; - string directory; - vector textures_loaded; + std::string directory; + std::vector textures_loaded; HWND hwnd; void processNode(aiNode* node, const aiScene* scene); Mesh processMesh(aiMesh* mesh, const aiScene* scene); - vector loadMaterialTextures(aiMaterial* mat, aiTextureType type, string typeName, const aiScene* scene); - string determineTextureType(const aiScene* scene, aiMaterial* mat); + std::vector loadMaterialTextures(aiMaterial* mat, aiTextureType type, std::string typeName, const aiScene* scene); + std::string determineTextureType(const aiScene* scene, aiMaterial* mat); int getTextureIndex(aiString* str); ID3D11ShaderResourceView* getTextureFromModel(const aiScene* scene, int textureindex); }; From 424f5e939f2c8f87116d757efe4f937583780028 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Sun, 8 Mar 2020 12:18:09 -0400 Subject: [PATCH 26/30] Fixed wrong matrix type used in comparaison operators. --- include/assimp/matrix3x3.h | 6 +++--- include/assimp/matrix3x3.inl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/assimp/matrix3x3.h b/include/assimp/matrix3x3.h index f9880ab9e..9f11b6b83 100644 --- a/include/assimp/matrix3x3.h +++ b/include/assimp/matrix3x3.h @@ -93,10 +93,10 @@ public: const TReal* operator[] (unsigned int p_iIndex) const; // comparison operators - bool operator== (const aiMatrix4x4t& m) const; - bool operator!= (const aiMatrix4x4t& m) const; + bool operator== (const aiMatrix3x3t& m) const; + bool operator!= (const aiMatrix3x3t& m) const; - bool Equal(const aiMatrix4x4t& m, TReal epsilon = 1e-6) const; + bool Equal(const aiMatrix3x3t& m, TReal epsilon = 1e-6) const; template operator aiMatrix3x3t () const; diff --git a/include/assimp/matrix3x3.inl b/include/assimp/matrix3x3.inl index b11e036b1..0b9565604 100644 --- a/include/assimp/matrix3x3.inl +++ b/include/assimp/matrix3x3.inl @@ -141,7 +141,7 @@ const TReal* aiMatrix3x3t::operator[] (unsigned int p_iIndex) const { // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE -bool aiMatrix3x3t::operator== (const aiMatrix4x4t& m) const { +bool aiMatrix3x3t::operator== (const aiMatrix3x3t& m) const { return a1 == m.a1 && a2 == m.a2 && a3 == m.a3 && b1 == m.b1 && b2 == m.b2 && b3 == m.b3 && c1 == m.c1 && c2 == m.c2 && c3 == m.c3; @@ -150,14 +150,14 @@ bool aiMatrix3x3t::operator== (const aiMatrix4x4t& m) const { // ------------------------------------------------------------------------------------------------ template AI_FORCE_INLINE -bool aiMatrix3x3t::operator!= (const aiMatrix4x4t& m) const { +bool aiMatrix3x3t::operator!= (const aiMatrix3x3t& m) const { return !(*this == m); } // --------------------------------------------------------------------------- template AI_FORCE_INLINE -bool aiMatrix3x3t::Equal(const aiMatrix4x4t& m, TReal epsilon) const { +bool aiMatrix3x3t::Equal(const aiMatrix3x3t& m, TReal epsilon) const { return std::abs(a1 - m.a1) <= epsilon && std::abs(a2 - m.a2) <= epsilon && From f305f105512237d7b44ec6c28492ac943e47fbcc Mon Sep 17 00:00:00 2001 From: Shawn Presser Date: Mon, 9 Mar 2020 00:05:17 -0700 Subject: [PATCH 27/30] Only try to initialize members whose name starts with 'm' followed by an uppercase character --- port/PyAssimp/pyassimp/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/PyAssimp/pyassimp/core.py b/port/PyAssimp/pyassimp/core.py index c346e2652..85cfe8233 100644 --- a/port/PyAssimp/pyassimp/core.py +++ b/port/PyAssimp/pyassimp/core.py @@ -138,7 +138,7 @@ def _init(self, target = None, parent = None): logger.debug(str(self) + ": Added array " + str(getattr(target, name)) + " as self." + name.lower()) continue - if m.startswith('m'): + if m.startswith('m') and len(m) > 1 and m[1].upper() == m[1]: if name == "parent": setattr(target, name, parent) From bb3db0ebaffc6b76de256e597ec1d1e4d2a6663f Mon Sep 17 00:00:00 2001 From: kimkulling Date: Mon, 9 Mar 2020 10:51:26 +0100 Subject: [PATCH 28/30] closes https://github.com/assimp/assimp/issues/2954: upgrade to latest greatest. --- contrib/zip/CMakeLists.txt | 8 ++---- contrib/zip/README.md | 51 +++++++++++++++++++++++++++++++-- contrib/zip/src/zip.c | 17 ++++++++++- contrib/zip/src/zip.h | 13 ++++++++- contrib/zip/test/CMakeLists.txt | 5 ---- contrib/zip/test/test.c | 4 ++- 6 files changed, 81 insertions(+), 17 deletions(-) diff --git a/contrib/zip/CMakeLists.txt b/contrib/zip/CMakeLists.txt index 77916d2e1..f194649ed 100644 --- a/contrib/zip/CMakeLists.txt +++ b/contrib/zip/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(zip LANGUAGES C - VERSION "0.1.15") + VERSION "0.1.18") set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) option(CMAKE_DISABLE_TESTING "Disable test creation" OFF) @@ -16,10 +16,6 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -pedantic") - if(ENABLE_COVERAGE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") - endif() endif (MSVC) # zip @@ -35,7 +31,7 @@ if (NOT CMAKE_DISABLE_TESTING) enable_testing() add_subdirectory(test) find_package(Sanitizers) - add_sanitizers(${PROJECT_NAME} ${test_out} ${test_miniz_out}) + add_sanitizers(${PROJECT_NAME} ${test_out}) endif() #### diff --git a/contrib/zip/README.md b/contrib/zip/README.md index 14eb9a34c..bdd0822b6 100644 --- a/contrib/zip/README.md +++ b/contrib/zip/README.md @@ -1,10 +1,8 @@ ### A portable (OSX/Linux/Windows), simple zip library written in C This is done by hacking awesome [miniz](https://code.google.com/p/miniz) library and layering functions on top of the miniz v1.15 API. -[![Windows](https://ci.appveyor.com/api/projects/status/bph8dr3jacgmjv32/branch/master?svg=true&label=windows)](https://ci.appveyor.com/project/kuba--/zip) -[![Linux](https://travis-ci.org/kuba--/zip.svg?branch=master&label=linux%2fosx)](https://travis-ci.org/kuba--/zip) +[![Build](https://github.com/kuba--/zip/workflows/build/badge.svg)](https://github.com/kuba--/zip/actions?query=workflow%3Abuild) [![Version](https://badge.fury.io/gh/kuba--%2Fzip.svg)](https://github.com/kuba--/zip/releases) -[![Codecov](https://codecov.io/gh/kuba--/zip/branch/master/graph/badge.svg)](https://codecov.io/gh/kuba--/zip) # The Idea @@ -213,6 +211,53 @@ func main() { } ``` +### Rust (ffi) +```rust +extern crate libc; +use std::ffi::CString; + +#[repr(C)] +pub struct Zip { + _private: [u8; 0], +} + +#[link(name = "zip")] +extern "C" { + fn zip_open(path: *const libc::c_char, level: libc::c_int, mode: libc::c_char) -> *mut Zip; + fn zip_close(zip: *mut Zip) -> libc::c_void; + + fn zip_entry_open(zip: *mut Zip, entryname: *const libc::c_char) -> libc::c_int; + fn zip_entry_close(zip: *mut Zip) -> libc::c_int; + fn zip_entry_write( + zip: *mut Zip, + buf: *const libc::c_void, + bufsize: libc::size_t, + ) -> libc::c_int; +} + +fn main() { + let path = CString::new("/tmp/test.zip").unwrap(); + let mode: libc::c_char = 'w' as libc::c_char; + + let entryname = CString::new("test.txt").unwrap(); + let content = "test content\0"; + + unsafe { + let zip: *mut Zip = zip_open(path.as_ptr(), 5, mode); + { + zip_entry_open(zip, entryname.as_ptr()); + { + let buf = content.as_ptr() as *const libc::c_void; + let bufsize = content.len() as libc::size_t; + zip_entry_write(zip, buf, bufsize); + } + zip_entry_close(zip); + } + zip_close(zip); + } +} +``` + ### Ruby (ffi) Install _ffi_ gem. ```shell diff --git a/contrib/zip/src/zip.c b/contrib/zip/src/zip.c index 1abcfd8fd..3b2821e6a 100644 --- a/contrib/zip/src/zip.c +++ b/contrib/zip/src/zip.c @@ -222,6 +222,20 @@ void zip_close(struct zip_t *zip) { } } +int zip_is64(struct zip_t *zip) { + if (!zip) { + // zip_t handler is not initialized + return -1; + } + + if (!zip->archive.m_pState) { + // zip state is not initialized + return -1; + } + + return (int)zip->archive.m_pState->m_zip64; +} + int zip_entry_open(struct zip_t *zip, const char *entryname) { size_t entrylen = 0; mz_zip_archive *pzip = NULL; @@ -794,7 +808,8 @@ int zip_create(const char *zipname, const char *filenames[], size_t len) { if (MZ_FILE_STAT(name, &file_stat) != 0) { // problem getting information - check errno - return -1; + status = -1; + break; } if ((file_stat.st_mode & 0200) == 0) { diff --git a/contrib/zip/src/zip.h b/contrib/zip/src/zip.h index a48d64d6d..cd3ab5cd0 100644 --- a/contrib/zip/src/zip.h +++ b/contrib/zip/src/zip.h @@ -21,7 +21,7 @@ extern "C" { #if !defined(_SSIZE_T_DEFINED) && !defined(_SSIZE_T_DEFINED_) && \ !defined(__DEFINED_ssize_t) && !defined(__ssize_t_defined) && \ - !defined(_SSIZE_T) && !defined(_SSIZE_T_) + !defined(_SSIZE_T) && !defined(_SSIZE_T_) && !defined(_SSIZE_T_DECLARED) // 64-bit Windows is the only mainstream platform // where sizeof(long) != sizeof(void*) @@ -37,6 +37,7 @@ typedef long ssize_t; /* byte count or error */ #define __ssize_t_defined #define _SSIZE_T #define _SSIZE_T_ +#define _SSIZE_T_DECLARED #endif @@ -90,6 +91,16 @@ extern struct zip_t *zip_open(const char *zipname, int level, char mode); */ extern void zip_close(struct zip_t *zip); +/** + * Determines if the archive has a zip64 end of central directory headers. + * + * @param zip zip archive handler. + * + * @return the return code - 1 (true), 0 (false), negative number (< 0) on + * error. + */ +extern int zip_is64(struct zip_t *zip); + /** * Opens an entry by name in the zip archive. * diff --git a/contrib/zip/test/CMakeLists.txt b/contrib/zip/test/CMakeLists.txt index cc060b00f..122411585 100644 --- a/contrib/zip/test/CMakeLists.txt +++ b/contrib/zip/test/CMakeLists.txt @@ -2,15 +2,10 @@ cmake_minimum_required(VERSION 2.8) # test set(test_out test.out) -set(test_miniz_out test_miniz.out) add_executable(${test_out} test.c) target_link_libraries(${test_out} zip) -add_executable(${test_miniz_out} test_miniz.c) -target_link_libraries(${test_miniz_out} zip) add_test(NAME ${test_out} COMMAND ${test_out}) -add_test(NAME ${test_miniz_out} COMMAND ${test_miniz_out}) set(test_out ${test_out} PARENT_SCOPE) -set(test_miniz_out ${test_miniz_out} PARENT_SCOPE) diff --git a/contrib/zip/test/test.c b/contrib/zip/test/test.c index a9b2ddab1..9cc2248ac 100644 --- a/contrib/zip/test/test.c +++ b/contrib/zip/test/test.c @@ -47,7 +47,7 @@ static void test_write(void) { assert(CRC32DATA1 == zip_entry_crc32(zip)); ++total_entries; assert(0 == zip_entry_close(zip)); - + assert(0 == zip_is64(zip)); zip_close(zip); } @@ -92,6 +92,7 @@ static void test_read(void) { size_t buftmp; struct zip_t *zip = zip_open(ZIPNAME, 0, 'r'); assert(zip != NULL); + assert(0 == zip_is64(zip)); assert(0 == zip_entry_open(zip, "test\\test-1.txt")); assert(strlen(TESTDATA1) == zip_entry_size(zip)); @@ -310,6 +311,7 @@ static void test_fwrite(void) { assert(0 == zip_entry_open(zip, WFILE)); assert(0 == zip_entry_fwrite(zip, WFILE)); assert(0 == zip_entry_close(zip)); + assert(0 == zip_is64(zip)); zip_close(zip); remove(WFILE); From f3b6b78d4d0a758380ca1c256c21fcd90cc20987 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Mon, 9 Mar 2020 10:55:32 +0100 Subject: [PATCH 29/30] small refactorings. --- CMakeLists.txt | 2 +- code/CMakeLists.txt | 4 +- code/Common/BaseProcess.cpp | 39 +++--- code/Common/BaseProcess.h | 129 ++++++------------ code/Common/PostStepRegistry.cpp | 2 +- .../SplitByBoneCountProcess.cpp | 0 .../SplitByBoneCountProcess.h | 2 +- include/assimp/GenericProperty.h | 39 +++--- 8 files changed, 83 insertions(+), 134 deletions(-) rename code/{Common => PostProcessing}/SplitByBoneCountProcess.cpp (100%) rename code/{Common => PostProcessing}/SplitByBoneCountProcess.h (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a7f8eeae..16b1f9620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -589,7 +589,7 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) ADD_SUBDIRECTORY( tools/assimp_view/ ) ENDIF () ENDIF () - # Te command line tool + # The command line tool ADD_SUBDIRECTORY( tools/assimp_cmd/ ) ENDIF () diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index eec66a305..0dff5d9e4 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -185,8 +185,6 @@ SET( Common_SRCS Common/ScenePreprocessor.cpp Common/ScenePreprocessor.h Common/SkeletonMeshBuilder.cpp - Common/SplitByBoneCountProcess.cpp - Common/SplitByBoneCountProcess.h Common/StandardShapes.cpp Common/TargetAnimation.cpp Common/TargetAnimation.h @@ -737,6 +735,8 @@ SET( PostProcessing_SRCS PostProcessing/ArmaturePopulate.h PostProcessing/GenBoundingBoxesProcess.cpp PostProcessing/GenBoundingBoxesProcess.h + PostProcessing/SplitByBoneCountProcess.cpp + PostProcessing/SplitByBoneCountProcess.h ) SOURCE_GROUP( PostProcessing FILES ${PostProcessing_SRCS}) diff --git a/code/Common/BaseProcess.cpp b/code/Common/BaseProcess.cpp index 974af68db..d02653cf2 100644 --- a/code/Common/BaseProcess.cpp +++ b/code/Common/BaseProcess.cpp @@ -5,8 +5,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2020, assimp team - - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -43,45 +41,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file Implementation of BaseProcess */ -#include #include "BaseProcess.h" -#include -#include #include "Importer.h" +#include +#include +#include using namespace Assimp; // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer BaseProcess::BaseProcess() AI_NO_EXCEPT -: shared() -, progress() -{ + : shared(), + progress() { + // empty } // ------------------------------------------------------------------------------------------------ // Destructor, private as well -BaseProcess::~BaseProcess() -{ +BaseProcess::~BaseProcess() { // nothing to do here } // ------------------------------------------------------------------------------------------------ -void BaseProcess::ExecuteOnScene( Importer* pImp) -{ - ai_assert(NULL != pImp && NULL != pImp->Pimpl()->mScene); +void BaseProcess::ExecuteOnScene(Importer *pImp) { + ai_assert( nullptr != pImp ); + ai_assert( nullptr != pImp->Pimpl()->mScene); progress = pImp->GetProgressHandler(); - ai_assert(progress); + ai_assert(nullptr != progress); - SetupProperties( pImp ); + SetupProperties(pImp); // catch exceptions thrown inside the PostProcess-Step - try - { + try { Execute(pImp->Pimpl()->mScene); - } catch( const std::exception& err ) { + } catch (const std::exception &err) { // extract error description pImp->Pimpl()->mErrorString = err.what(); @@ -94,14 +90,11 @@ void BaseProcess::ExecuteOnScene( Importer* pImp) } // ------------------------------------------------------------------------------------------------ -void BaseProcess::SetupProperties(const Importer* /*pImp*/) -{ +void BaseProcess::SetupProperties(const Importer * /*pImp*/) { // the default implementation does nothing } // ------------------------------------------------------------------------------------------------ -bool BaseProcess::RequireVerboseFormat() const -{ +bool BaseProcess::RequireVerboseFormat() const { return true; } - diff --git a/code/Common/BaseProcess.h b/code/Common/BaseProcess.h index a7e48bba3..bf1f2586f 100644 --- a/code/Common/BaseProcess.h +++ b/code/Common/BaseProcess.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2020, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -44,12 +43,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INCLUDED_AI_BASEPROCESS_H #define INCLUDED_AI_BASEPROCESS_H -#include #include +#include + struct aiScene; -namespace Assimp { +namespace Assimp { class Importer; @@ -60,64 +60,50 @@ class Importer; * to provide additional information to other steps. This is primarily * intended for cross-step optimizations. */ -class SharedPostProcessInfo -{ +class SharedPostProcessInfo { public: - - struct Base - { - virtual ~Base() - {} + struct Base { + virtual ~Base() {} }; //! Represents data that is allocated on the heap, thus needs to be deleted template - struct THeapData : public Base - { - explicit THeapData(T* in) - : data (in) - {} + struct THeapData : public Base { + explicit THeapData(T *in) : + data(in) {} - ~THeapData() - { + ~THeapData() { delete data; } - T* data; + T *data; }; //! Represents static, by-value data not allocated on the heap template - struct TStaticData : public Base - { - explicit TStaticData(T in) - : data (in) - {} + struct TStaticData : public Base { + explicit TStaticData(T in) : + data(in) {} - ~TStaticData() - {} + ~TStaticData() {} T data; }; // some typedefs for cleaner code typedef unsigned int KeyType; - typedef std::map PropertyMap; + typedef std::map PropertyMap; public: - //! Destructor - ~SharedPostProcessInfo() - { + ~SharedPostProcessInfo() { Clean(); } //! Remove all stored properties from the table - void Clean() - { + void Clean() { // invoke the virtual destructor for all stored properties for (PropertyMap::iterator it = pmap.begin(), end = pmap.end(); - it != end; ++it) - { + it != end; ++it) { delete (*it).second; } pmap.clear(); @@ -125,24 +111,21 @@ public: //! Add a heap property to the list template - void AddProperty( const char* name, T* in ){ - AddProperty(name,(Base*)new THeapData(in)); + void AddProperty(const char *name, T *in) { + AddProperty(name, (Base *)new THeapData(in)); } //! Add a static by-value property to the list template - void AddProperty( const char* name, T in ){ - AddProperty(name,(Base*)new TStaticData(in)); + void AddProperty(const char *name, T in) { + AddProperty(name, (Base *)new TStaticData(in)); } - //! Get a heap property template - bool GetProperty( const char* name, T*& out ) const - { - THeapData* t = (THeapData*)GetPropertyInternal(name); - if(!t) - { + bool GetProperty(const char *name, T *&out) const { + THeapData *t = (THeapData *)GetPropertyInternal(name); + if (!t) { out = NULL; return false; } @@ -152,53 +135,34 @@ public: //! Get a static, by-value property template - bool GetProperty( const char* name, T& out ) const - { - TStaticData* t = (TStaticData*)GetPropertyInternal(name); - if(!t)return false; + bool GetProperty(const char *name, T &out) const { + TStaticData *t = (TStaticData *)GetPropertyInternal(name); + if ( nullptr == t) { + return false; + } out = t->data; return true; } //! Remove a property of a specific type - void RemoveProperty( const char* name) { - SetGenericPropertyPtr(pmap,name,NULL); + void RemoveProperty(const char *name) { + SetGenericPropertyPtr(pmap, name, nullptr ); } private: - - void AddProperty( const char* name, Base* data) { - SetGenericPropertyPtr(pmap,name,data); + void AddProperty(const char *name, Base *data) { + SetGenericPropertyPtr(pmap, name, data); } - Base* GetPropertyInternal( const char* name) const { - return GetGenericProperty(pmap,name,NULL); + Base *GetPropertyInternal(const char *name) const { + return GetGenericProperty(pmap, name, nullptr ); } private: - //! Map of all stored properties PropertyMap pmap; }; -#if 0 - -// --------------------------------------------------------------------------- -/** @brief Represents a dependency table for a postprocessing steps. - * - * For future use. - */ - struct PPDependencyTable - { - unsigned int execute_me_before_these; - unsigned int execute_me_after_these; - unsigned int only_if_these_are_not_specified; - unsigned int mutually_exclusive_with; - }; - -#endif - - #define AI_SPP_SPATIAL_SORT "$Spat" // --------------------------------------------------------------------------- @@ -228,7 +192,7 @@ public: * @return true if the process is present in this flag fields, * false if not. */ - virtual bool IsActive( unsigned int pFlags) const = 0; + virtual bool IsActive(unsigned int pFlags) const = 0; // ------------------------------------------------------------------- /** Check whether this step expects its input vertex data to be @@ -241,14 +205,14 @@ public: * the object pointer will be set to NULL). * @param pImp Importer instance (pImp->mScene must be valid) */ - void ExecuteOnScene( Importer* pImp); + void ExecuteOnScene(Importer *pImp); // ------------------------------------------------------------------- /** Called prior to ExecuteOnScene(). * The function is a request to the process to update its configuration * basing on the Importer's configuration property list. */ - virtual void SetupProperties(const Importer* pImp); + virtual void SetupProperties(const Importer *pImp); // ------------------------------------------------------------------- /** Executes the post processing step on the given imported data. @@ -256,35 +220,32 @@ public: * This method must be implemented by deriving classes. * @param pScene The imported data to work at. */ - virtual void Execute( aiScene* pScene) = 0; - + virtual void Execute(aiScene *pScene) = 0; // ------------------------------------------------------------------- /** Assign a new SharedPostProcessInfo to the step. This object * allows multiple postprocess steps to share data. * @param sh May be NULL */ - inline void SetSharedData(SharedPostProcessInfo* sh) { + inline void SetSharedData(SharedPostProcessInfo *sh) { shared = sh; } // ------------------------------------------------------------------- /** Get the shared data that is assigned to the step. */ - inline SharedPostProcessInfo* GetSharedData() { + inline SharedPostProcessInfo *GetSharedData() { return shared; } protected: - /** See the doc of #SharedPostProcessInfo for more details */ - SharedPostProcessInfo* shared; + SharedPostProcessInfo *shared; /** Currently active progress handler */ - ProgressHandler* progress; + ProgressHandler *progress; }; - } // end of namespace Assimp #endif // AI_BASEPROCESS_H_INC diff --git a/code/Common/PostStepRegistry.cpp b/code/Common/PostStepRegistry.cpp index 21bd2af95..19382165f 100644 --- a/code/Common/PostStepRegistry.cpp +++ b/code/Common/PostStepRegistry.cpp @@ -123,7 +123,7 @@ corresponding preprocessor flag to selectively disable steps. # include "PostProcessing/OptimizeGraph.h" #endif #ifndef ASSIMP_BUILD_NO_SPLITBYBONECOUNT_PROCESS -# include "Common/SplitByBoneCountProcess.h" +# include "PostProcessing/SplitByBoneCountProcess.h" #endif #ifndef ASSIMP_BUILD_NO_DEBONE_PROCESS # include "PostProcessing/DeboneProcess.h" diff --git a/code/Common/SplitByBoneCountProcess.cpp b/code/PostProcessing/SplitByBoneCountProcess.cpp similarity index 100% rename from code/Common/SplitByBoneCountProcess.cpp rename to code/PostProcessing/SplitByBoneCountProcess.cpp diff --git a/code/Common/SplitByBoneCountProcess.h b/code/PostProcessing/SplitByBoneCountProcess.h similarity index 99% rename from code/Common/SplitByBoneCountProcess.h rename to code/PostProcessing/SplitByBoneCountProcess.h index 7185d0330..b99830fde 100644 --- a/code/Common/SplitByBoneCountProcess.h +++ b/code/PostProcessing/SplitByBoneCountProcess.h @@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_SPLITBYBONECOUNTPROCESS_H_INC #include -#include "BaseProcess.h" +#include "Common/BaseProcess.h" #include #include diff --git a/include/assimp/GenericProperty.h b/include/assimp/GenericProperty.h index 30f4988f9..c1891c7b6 100644 --- a/include/assimp/GenericProperty.h +++ b/include/assimp/GenericProperty.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2020, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -45,26 +44,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_GENERIC_PROPERTY_H_INCLUDED #ifdef __GNUC__ -# pragma GCC system_header +# pragma GCC system_header #endif -#include -#include #include +#include +#include #include // ------------------------------------------------------------------------------------------------ template -inline -bool SetGenericProperty(std::map< unsigned int, T >& list, - const char* szName, const T& value) { +inline bool SetGenericProperty(std::map &list, + const char *szName, const T &value) { ai_assert(nullptr != szName); const uint32_t hash = SuperFastHash(szName); typename std::map::iterator it = list.find(hash); - if (it == list.end()) { - list.insert(std::pair( hash, value )); + if (it == list.end()) { + list.insert(std::pair(hash, value)); return false; } (*it).second = value; @@ -74,9 +72,8 @@ bool SetGenericProperty(std::map< unsigned int, T >& list, // ------------------------------------------------------------------------------------------------ template -inline -const T& GetGenericProperty(const std::map< unsigned int, T >& list, - const char* szName, const T& errorReturn) { +inline const T &GetGenericProperty(const std::map &list, + const char *szName, const T &errorReturn) { ai_assert(nullptr != szName); const uint32_t hash = SuperFastHash(szName); @@ -92,22 +89,21 @@ const T& GetGenericProperty(const std::map< unsigned int, T >& list, // Special version for pointer types - they will be deleted when replaced with another value // passing NULL removes the whole property template -inline -void SetGenericPropertyPtr(std::map< unsigned int, T* >& list, - const char* szName, T* value, bool* bWasExisting = nullptr ) { +inline void SetGenericPropertyPtr(std::map &list, + const char *szName, T *value, bool *bWasExisting = nullptr) { ai_assert(nullptr != szName); const uint32_t hash = SuperFastHash(szName); - typename std::map::iterator it = list.find(hash); - if (it == list.end()) { + typename std::map::iterator it = list.find(hash); + if (it == list.end()) { if (bWasExisting) { *bWasExisting = false; } - list.insert(std::pair( hash, value )); + list.insert(std::pair(hash, value)); return; } - if ((*it).second != value) { + if ((*it).second != value) { delete (*it).second; (*it).second = value; } @@ -121,9 +117,8 @@ void SetGenericPropertyPtr(std::map< unsigned int, T* >& list, // ------------------------------------------------------------------------------------------------ template -inline -bool HasGenericProperty(const std::map< unsigned int, T >& list, - const char* szName) { +inline bool HasGenericProperty(const std::map &list, + const char *szName) { ai_assert(nullptr != szName); const uint32_t hash = SuperFastHash(szName); From ed62ed9e7c7965719a99d0b2c0eeb14be04cff2e Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Tue, 10 Mar 2020 13:47:10 -0400 Subject: [PATCH 30/30] Minor changes in CMakeLists files. - Fixed condition preventing ASSIMP_BUILD_ASSIMP_VIEW showing up on first time - Set ASSIMP_BUILD_ASSIMP_VIEW to off by default. - Removed unnecessary reference to DirectX 9 library. --- CMakeLists.txt | 4 ++-- samples/SimpleTexturedDirectx11/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16b1f9620..42f975c79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -583,8 +583,8 @@ ENDIF() ADD_SUBDIRECTORY( code/ ) IF ( ASSIMP_BUILD_ASSIMP_TOOLS ) # The viewer for windows only - IF ( WIN32 AND DirectX_D3DX9_LIBRARY ) - OPTION ( ASSIMP_BUILD_ASSIMP_VIEW "If the Assimp view tool is built. (requires DirectX)" ${DirectX_FOUND} ) + IF ( WIN32 ) + OPTION ( ASSIMP_BUILD_ASSIMP_VIEW "If the Assimp view tool is built. (requires DirectX)" OFF ) IF ( ASSIMP_BUILD_ASSIMP_VIEW ) ADD_SUBDIRECTORY( tools/assimp_view/ ) ENDIF () diff --git a/samples/SimpleTexturedDirectx11/CMakeLists.txt b/samples/SimpleTexturedDirectx11/CMakeLists.txt index 9016b8869..9eec738f5 100644 --- a/samples/SimpleTexturedDirectx11/CMakeLists.txt +++ b/samples/SimpleTexturedDirectx11/CMakeLists.txt @@ -39,7 +39,7 @@ ADD_EXECUTABLE( assimp_simpletextureddirectx11 WIN32 SET_PROPERTY(TARGET assimp_simpletextureddirectx11 PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) -TARGET_LINK_LIBRARIES( assimp_simpletextureddirectx11 assimp ${DirectX_LIBRARY} comctl32.lib winmm.lib ) +TARGET_LINK_LIBRARIES( assimp_simpletextureddirectx11 assimp comctl32.lib winmm.lib ) SET_TARGET_PROPERTIES( assimp_simpletextureddirectx11 PROPERTIES OUTPUT_NAME assimp_simpletextureddirectx11 )