From cd7df53a72625424b985ee15c121828a967e5957 Mon Sep 17 00:00:00 2001 From: eyhn Date: Tue, 15 Mar 2022 14:46:30 +0800 Subject: [PATCH 01/14] Add USE_STATIC_CRT option --- CMakeLists.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cbbfef2c..f48391edf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,27 @@ IF (WIN32) # Multibyte character set is deprecated since at least MSVC2015 (possibly earlier) ADD_DEFINITIONS( -DUNICODE -D_UNICODE ) ENDIF() + + # Link statically against c/c++ lib to avoid missing redistriburable such as + # "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users + # a choice to opt for the shared runtime if they want. + option(USE_STATIC_CRT "Link against the static runtime libraries." OFF) + + # The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative + # global method here: + if (${USE_STATIC_CRT}) + add_compile_options( + $<$:/MT> + $<$:/MTd> + $<$:/MT> + ) + else() + add_compile_options( + $<$:/MD> + $<$:/MDd> + $<$:/MD> + ) + endif() ENDIF() ENDIF() From 552f3a308d23a3f9981125ee08555e4b69fd6d31 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 16 Mar 2022 10:08:20 +0100 Subject: [PATCH 02/14] Fix nullptr dereferencing - Check if we have any texture coordinates before calculating them - closes https://github.com/assimp/assimp/issues/4445 --- code/AssetLib/MDL/MDLLoader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/AssetLib/MDL/MDLLoader.cpp b/code/AssetLib/MDL/MDLLoader.cpp index 1e90c8e71..9c9cf910c 100644 --- a/code/AssetLib/MDL/MDLLoader.cpp +++ b/code/AssetLib/MDL/MDLLoader.cpp @@ -857,6 +857,9 @@ void MDLImporter::CalculateUVCoordinates_MDL5() { const float fHeight = (float)iHeight; aiMesh *pcMesh = this->pScene->mMeshes[0]; for (unsigned int i = 0; i < pcMesh->mNumVertices; ++i) { + if (!pcMesh->HasTextureCoords(0)) { + continue; + } pcMesh->mTextureCoords[0][i].x /= fWidth; pcMesh->mTextureCoords[0][i].y /= fHeight; pcMesh->mTextureCoords[0][i].y = 1.0f - pcMesh->mTextureCoords[0][i].y; // DX to OGL From c2b05acaa6f57cef04a6be3f875873f45ec76a7d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 16 Mar 2022 13:59:21 +0100 Subject: [PATCH 03/14] Fix stack-overflow in MDLLoader - Use correct len to copy filename. - Closes https://github.com/assimp/assimp/issues/4447 --- code/AssetLib/MDL/MDLMaterialLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/MDL/MDLMaterialLoader.cpp b/code/AssetLib/MDL/MDLMaterialLoader.cpp index eebb9d15e..2de43d241 100644 --- a/code/AssetLib/MDL/MDLMaterialLoader.cpp +++ b/code/AssetLib/MDL/MDLMaterialLoader.cpp @@ -493,7 +493,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7( size_t iLen2 = iLen + 1; iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; memcpy(szFile.data, (const char *)szCurrent, iLen2); - szFile.length = (ai_uint32)iLen; + szFile.length = static_cast(iLen2); szCurrent += iLen2; From 765b38cf04a7c0e4575f594533eb6e12a6d98cd8 Mon Sep 17 00:00:00 2001 From: Promit Roy Date: Wed, 16 Mar 2022 16:49:45 -0400 Subject: [PATCH 04/14] Update glTF2Asset.inl Fixing mistakes in attribute names for GLTF. This causes attribute index to not be parsed out correctly (e.g. JOINTS_1) and fails the scene load. --- code/AssetLib/glTF2/glTF2Asset.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index ec481a729..a74866e6c 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -179,11 +179,11 @@ inline bool GetAttribVector(Mesh::Primitive &p, const char *attr, Mesh::Accessor v = &(p.attributes.texcoord); } else if ((pos = Compare(attr, "COLOR"))) { v = &(p.attributes.color); - } else if ((pos = Compare(attr, "JOINT"))) { + } else if ((pos = Compare(attr, "JOINTS"))) { v = &(p.attributes.joint); } else if ((pos = Compare(attr, "JOINTMATRIX"))) { v = &(p.attributes.jointmatrix); - } else if ((pos = Compare(attr, "WEIGHT"))) { + } else if ((pos = Compare(attr, "WEIGHTS"))) { v = &(p.attributes.weight); } else return false; From 0a56065962e3e2f4732445505fcff7c44935b843 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 24 Mar 2022 00:41:07 +0100 Subject: [PATCH 05/14] Use static runtime only on option is selected --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f48391edf..ab4d45e88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,12 +164,6 @@ IF (WIN32) $<$:/MTd> $<$:/MT> ) - else() - add_compile_options( - $<$:/MD> - $<$:/MDd> - $<$:/MD> - ) endif() ENDIF() ENDIF() From 4175198d045674b6f5a62600a0e7d188403cebfa Mon Sep 17 00:00:00 2001 From: Filip Lundgren <45687559+ifiddynine@users.noreply.github.com> Date: Sat, 26 Mar 2022 22:33:10 +0100 Subject: [PATCH 06/14] Detect Roughness factor exported by Blender Matches the logic used by Blender's own FBX exporter / importer. --- code/AssetLib/FBX/FBXConverter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 32872108b..d446fd2e9 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -2161,6 +2161,9 @@ void FBXConverter::SetShadingPropertiesCommon(aiMaterial *out_mat, const Propert const float ShininessExponent = PropertyGet(props, "ShininessExponent", ok); if (ok) { out_mat->AddProperty(&ShininessExponent, 1, AI_MATKEY_SHININESS); + // Match Blender behavior to extract roughness when only shininess is present + const float roughness = 1.0 - (sqrt(ShininessExponent) / 10.0); + out_mat->AddProperty(&roughness, 1, AI_MATKEY_ROUGHNESS_FACTOR); } // TransparentColor / TransparencyFactor... gee thanks FBX :rolleyes: From f985fe12ccf7dc0a6a7ed61bab741207d0b79cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=E8=AE=B8?= Date: Thu, 31 Mar 2022 11:20:18 +0800 Subject: [PATCH 07/14] Fix compile error When enable macro ASSIMP_DOUBLE_PRECISION --- include/assimp/material.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 0b30a6839..cdf272201 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -157,7 +157,7 @@ AI_FORCE_INLINE case aiPTI_Float: case aiPTI_Double: { // Read as float and cast to bool - float value = 0.0f; + ai_real value = 0.0f; if (AI_SUCCESS == ::aiGetMaterialFloat(this, pKey, type, idx, &value)) { pOut = static_cast(value); return AI_SUCCESS; From 18c4ebaa130d2b9bc9fe3b5ba4941c96dbddc949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=E8=AE=B8?= Date: Thu, 31 Mar 2022 14:28:35 +0800 Subject: [PATCH 08/14] Fix compile in VC140 --- code/AssetLib/Obj/ObjFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 1786c0d9f..fb2ce78ea 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -55,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -constexpr char ObjFileParser::DEFAULT_MATERIAL[]; +constexpr char ObjFileParser::DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME; ObjFileParser::ObjFileParser() : m_DataIt(), From 8e075ce7133bf1ebc9727925356f3840a9807b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=E8=AE=B8?= Date: Thu, 31 Mar 2022 14:53:33 +0800 Subject: [PATCH 09/14] Update ObjFileParser.cpp --- code/AssetLib/Obj/ObjFileParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index fb2ce78ea..1786c0d9f 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -55,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -constexpr char ObjFileParser::DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME; +constexpr char ObjFileParser::DEFAULT_MATERIAL[]; ObjFileParser::ObjFileParser() : m_DataIt(), From cc515746f73d43ba5dabe0af5227200e0f5939aa Mon Sep 17 00:00:00 2001 From: xiaohunqupo Date: Thu, 31 Mar 2022 14:58:31 +0800 Subject: [PATCH 10/14] Fix v140 compile errror --- code/AssetLib/Obj/ObjFileParser.cpp | 2 +- code/AssetLib/Obj/ObjFileParser.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 1786c0d9f..4e50d5dae 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -55,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -constexpr char ObjFileParser::DEFAULT_MATERIAL[]; +constexpr const char ObjFileParser::DEFAULT_MATERIAL[]; ObjFileParser::ObjFileParser() : m_DataIt(), diff --git a/code/AssetLib/Obj/ObjFileParser.h b/code/AssetLib/Obj/ObjFileParser.h index fbd2f2c89..1bf11a0c8 100644 --- a/code/AssetLib/Obj/ObjFileParser.h +++ b/code/AssetLib/Obj/ObjFileParser.h @@ -141,7 +141,7 @@ private: // because the class contains pointer to allocated memory /// Default material name - static constexpr char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME; + static constexpr const char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME; //! Iterator to current position in buffer DataArrayIt m_DataIt; //! Iterator to end position of buffer From b08c04b87a13c737ad7decd1a760129d6d161956 Mon Sep 17 00:00:00 2001 From: xiaohunqupo Date: Thu, 31 Mar 2022 15:08:12 +0800 Subject: [PATCH 11/14] Fix compile errro in VC140 --- include/assimp/Bitmap.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/assimp/Bitmap.h b/include/assimp/Bitmap.h index 6a614f7cf..94dd0b81b 100644 --- a/include/assimp/Bitmap.h +++ b/include/assimp/Bitmap.h @@ -78,11 +78,11 @@ protected: // We define the struct size because sizeof(Header) might return a wrong result because of structure padding. static constexpr std::size_t header_size = - sizeof(type) + - sizeof(size) + - sizeof(reserved1) + - sizeof(reserved2) + - sizeof(offset); + sizeof(uint16_t) + + sizeof(uint32_t) + + sizeof(uint16_t) + + sizeof(uint16_t) + + sizeof(uint32_t); }; struct DIB { @@ -100,17 +100,17 @@ protected: // We define the struct size because sizeof(DIB) might return a wrong result because of structure padding. static constexpr std::size_t dib_size = - sizeof(size) + - sizeof(width) + - sizeof(height) + - sizeof(planes) + - sizeof(bits_per_pixel) + - sizeof(compression) + - sizeof(image_size) + - sizeof(x_resolution) + - sizeof(y_resolution) + - sizeof(nb_colors) + - sizeof(nb_important_colors); + sizeof(uint32_t) + + sizeof(int32_t) + + sizeof(int32_t) + + sizeof(uint16_t) + + sizeof(uint16_t) + + sizeof(uint32_t) + + sizeof(uint32_t) + + sizeof(int32_t) + + sizeof(int32_t) + + sizeof(uint32_t) + + sizeof(uint32_t); }; static constexpr std::size_t mBytesPerPixel = 4; From 2152aae2a3a95e0ce65ea35e9c9ac0b73fdb66fe Mon Sep 17 00:00:00 2001 From: xiaohunqupo Date: Thu, 31 Mar 2022 15:34:49 +0800 Subject: [PATCH 12/14] Fix compile error due to namespace conflicts in VC140. --- code/AssetLib/glTF/glTFAsset.inl | 2 +- code/AssetLib/glTF2/glTF2Asset.inl | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/glTF/glTFAsset.inl b/code/AssetLib/glTF/glTFAsset.inl index 2b76a30ab..1f4544156 100644 --- a/code/AssetLib/glTF/glTFAsset.inl +++ b/code/AssetLib/glTF/glTFAsset.inl @@ -53,9 +53,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif using namespace Assimp; -using namespace glTFCommon; namespace glTF { +using namespace glTFCommon; #if _MSC_VER #pragma warning(push) diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index a74866e6c..e9108a5da 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -82,7 +82,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // clang-format on using namespace Assimp; -using namespace glTFCommon; +using glTFCommon::FindStringInContext; +using glTFCommon::FindNumberInContext; +using glTFCommon::FindUIntInContext; +using glTFCommon::FindArrayInContext; +using glTFCommon::FindObjectInContext; +using glTFCommon::FindExtensionInContext; +using glTFCommon::MemberOrDefault; +using glTFCommon::ReadMember; +using glTFCommon::FindMember; +using glTFCommon::FindObject; +using glTFCommon::FindUInt; +using glTFCommon::FindArray; +using glTFCommon::FindArray; namespace glTF2 { From de6e90a657ba46ed8672518bbf249e193465f227 Mon Sep 17 00:00:00 2001 From: xiaohunqupo Date: Thu, 31 Mar 2022 15:36:57 +0800 Subject: [PATCH 13/14] Fix commit error --- code/AssetLib/glTF2/glTF2Asset.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index e9108a5da..db47915d6 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -82,6 +82,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // clang-format on using namespace Assimp; + +namespace glTF2 { using glTFCommon::FindStringInContext; using glTFCommon::FindNumberInContext; using glTFCommon::FindUIntInContext; @@ -96,8 +98,6 @@ using glTFCommon::FindUInt; using glTFCommon::FindArray; using glTFCommon::FindArray; -namespace glTF2 { - namespace { // From a050dee09689292ad36df095e4a0cbff07dccded Mon Sep 17 00:00:00 2001 From: xiaohunqupo Date: Thu, 31 Mar 2022 16:08:39 +0800 Subject: [PATCH 14/14] Fix compile error:When enable macro ASSIMP_DOUBLE_PRECISION --- code/AssetLib/IFC/IFCOpenings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/IFC/IFCOpenings.cpp b/code/AssetLib/IFC/IFCOpenings.cpp index 74200195b..6b8b565c2 100644 --- a/code/AssetLib/IFC/IFCOpenings.cpp +++ b/code/AssetLib/IFC/IFCOpenings.cpp @@ -1476,7 +1476,7 @@ std::vector GetContourInPlane2D(std::shared_ptr mesh,IfcMa return contour; } -const float close{ ai_epsilon }; +const ai_real close{ ai_epsilon }; static bool isClose(IfcVector2 first,IfcVector2 second) { auto diff = (second - first);