From 6ebae5e67c49097b1c55a51f4ead053bc33d8255 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Sun, 24 Jan 2021 11:04:46 +0200 Subject: [PATCH 1/5] GCC 11 build fixes --- code/AssetLib/AMF/AMFImporter_Postprocess.cpp | 4 ++-- code/Common/Importer.cpp | 1 + code/Common/Importer.h | 1 + include/assimp/Importer.hpp | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp index 98151d1c0..0236ab557 100644 --- a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp +++ b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp @@ -329,8 +329,8 @@ void AMFImporter::Postprocess_AddMetadata(const AMFMetaDataArray &metadataList, sceneNode.mMetaData = aiMetadata::Alloc(static_cast(metadataList.size())); size_t meta_idx(0); - for (const AMFMetadata &metadata : metadataList) { - sceneNode.mMetaData->Set(static_cast(meta_idx++), metadata.Type, aiString(metadata.Value)); + for (const AMFMetadata *metadata : metadataList) { + sceneNode.mMetaData->Set(static_cast(meta_idx++), metadata->Type, aiString(metadata->Value)); } } diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index 38eb63f40..ccd664d91 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -78,6 +78,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include diff --git a/code/Common/Importer.h b/code/Common/Importer.h index eb70bc38f..d07a67030 100644 --- a/code/Common/Importer.h +++ b/code/Common/Importer.h @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INCLUDED_AI_IMPORTER_H #define INCLUDED_AI_IMPORTER_H +#include #include #include #include diff --git a/include/assimp/Importer.hpp b/include/assimp/Importer.hpp index 9078fbfe6..07ffe26f9 100644 --- a/include/assimp/Importer.hpp +++ b/include/assimp/Importer.hpp @@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Public ASSIMP data structures #include +#include + namespace Assimp { // ======================================================================= // Public interface to Assimp From 4471c36c087c0a36a6dfd9aee01cdce520f8df2d Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 26 Jan 2021 20:59:21 +0100 Subject: [PATCH 2/5] Fix compiler bug for VS2019 - Check https://developercommunity.visualstudio.com/content/problem/1223143/visual-studio-2019-c-program-crash-with-stdstring.html for more details - closes https://github.com/assimp/assimp/issues/3572 --- code/AssetLib/FBX/FBXMaterial.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index 9fe4ce5be..2d727d16e 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -60,12 +60,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { namespace FBX { - using namespace Util; +using namespace Util; // ------------------------------------------------------------------------------------------------ -Material::Material(uint64_t id, const Element& element, const Document& doc, const std::string& name) -: Object(id,element,name) -{ +Material::Material(uint64_t id, const Element& element, const Document& doc, const std::string& name) : + Object(id,element,name) { const Scope& sc = GetRequiredScope(element); const Element* const ShadingModel = sc["ShadingModel"]; @@ -77,8 +76,7 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con if(ShadingModel) { shading = ParseTokenAsString(GetRequiredToken(*ShadingModel,0)); - } - else { + } else { DOMWarning("shading mode not specified, assuming phong",&element); shading = "phong"; } @@ -86,7 +84,9 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con std::string templateName; // lower-case shading because Blender (for example) writes "Phong" - std::transform(shading.data(), shading.data() + shading.size(), std::addressof(shading[0]), Assimp::ToLower); + for (size_t i = 0; i < shading.length(); ++i) { + shading[i] = tolower(shading[i]); + } if(shading == "phong") { templateName = "Material.FbxSurfacePhong"; } From c02ad323a5f41f3fb37e5fdfc2ef097860a2f426 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 27 Jan 2021 09:22:59 +0100 Subject: [PATCH 3/5] Fix VS compiler warning: convertig int to char --- code/AssetLib/FBX/FBXMaterial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index 2d727d16e..8738924ad 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -85,7 +85,7 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con // lower-case shading because Blender (for example) writes "Phong" for (size_t i = 0; i < shading.length(); ++i) { - shading[i] = tolower(shading[i]); + shading[i] = sttaic_cast(tolower(shading[i]); } if(shading == "phong") { templateName = "Material.FbxSurfacePhong"; From ac0f1f2cabb44adf29cf06da05a1387ec37b4da7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 27 Jan 2021 09:37:35 +0100 Subject: [PATCH 4/5] Update FBXMaterial.cpp --- code/AssetLib/FBX/FBXMaterial.cpp | 126 +++++++++++------------------- 1 file changed, 46 insertions(+), 80 deletions(-) diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index 8738924ad..7223f3217 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -54,7 +54,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include // std::transform #include "FBXUtil.h" namespace Assimp { @@ -81,19 +80,16 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con shading = "phong"; } - std::string templateName; - // lower-case shading because Blender (for example) writes "Phong" for (size_t i = 0; i < shading.length(); ++i) { - shading[i] = sttaic_cast(tolower(shading[i]); + shading[i] = static_cast(tolower(shading[i]); } + std::string templateName; if(shading == "phong") { templateName = "Material.FbxSurfacePhong"; - } - else if(shading == "lambert") { + } else if(shading == "lambert") { templateName = "Material.FbxSurfaceLambert"; - } - else { + } else { DOMWarning("shading mode not recognized: " + shading,&element); } @@ -102,20 +98,19 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con // resolve texture links const std::vector& conns = doc.GetConnectionsByDestinationSequenced(ID()); for(const Connection* con : conns) { - // texture link to properties, not objects - if (!con->PropertyName().length()) { + if ( 0 == con->PropertyName().length()) { continue; } const Object* const ob = con->SourceObject(); - if(!ob) { + if(nullptr == ob) { DOMWarning("failed to read source object for texture link, ignoring",&element); continue; } const Texture* const tex = dynamic_cast(ob); - if(!tex) { + if(nullptr == tex) { const LayeredTexture* const layeredTexture = dynamic_cast(ob); if(!layeredTexture) { DOMWarning("source object for texture link is not a texture or layered texture, ignoring",&element); @@ -128,9 +123,7 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con layeredTextures[prop] = layeredTexture; ((LayeredTexture*)layeredTexture)->fillTexture(doc); - } - else - { + } else { const std::string& prop = con->PropertyName(); if (textures.find(prop) != textures.end()) { DOMWarning("duplicate texture link: " + prop,&element); @@ -138,23 +131,20 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con textures[prop] = tex; } - } } // ------------------------------------------------------------------------------------------------ -Material::~Material() -{ +Material::~Material() { + // empty } - // ------------------------------------------------------------------------------------------------ -Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name) -: Object(id,element,name) -, uvScaling(1.0f,1.0f) -, media(0) -{ +Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name) : + Object(id,element,name), + uvScaling(1.0f,1.0f), + media(0) { const Scope& sc = GetRequiredScope(element); const Element* const Type = sc["Type"]; @@ -194,8 +184,7 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const crop[1] = ParseTokenAsInt(GetRequiredToken(*Cropping,1)); crop[2] = ParseTokenAsInt(GetRequiredToken(*Cropping,2)); crop[3] = ParseTokenAsInt(GetRequiredToken(*Cropping,3)); - } - else { + } else { // vc8 doesn't support the crop() syntax in initialization lists // (and vc9 WARNS about the new (i.e. compliant) behaviour). crop[0] = crop[1] = crop[2] = crop[3] = 0; @@ -226,7 +215,7 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const const std::vector& conns = doc.GetConnectionsByDestinationSequenced(ID()); for(const Connection* con : conns) { const Object* const ob = con->SourceObject(); - if(!ob) { + if (nullptr == ob) { DOMWarning("failed to read source object for texture link, ignoring",&element); continue; } @@ -240,46 +229,38 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const } -Texture::~Texture() -{ - +Texture::~Texture() { + // empty } -LayeredTexture::LayeredTexture(uint64_t id, const Element& element, const Document& /*doc*/, const std::string& name) -: Object(id,element,name) -,blendMode(BlendMode_Modulate) -,alpha(1) -{ +LayeredTexture::LayeredTexture(uint64_t id, const Element& element, const Document& /*doc*/, const std::string& name) : + Object(id,element,name), + blendMode(BlendMode_Modulate), + alpha(1) { const Scope& sc = GetRequiredScope(element); const Element* const BlendModes = sc["BlendModes"]; const Element* const Alphas = sc["Alphas"]; - - if(BlendModes!=0) - { + if (nullptr != BlendModes) { blendMode = (BlendMode)ParseTokenAsInt(GetRequiredToken(*BlendModes,0)); } - if(Alphas!=0) - { + if (nullptr != Alphas) { alpha = ParseTokenAsFloat(GetRequiredToken(*Alphas,0)); } } -LayeredTexture::~LayeredTexture() -{ - +LayeredTexture::~LayeredTexture() { + // empty } -void LayeredTexture::fillTexture(const Document& doc) -{ +void LayeredTexture::fillTexture(const Document& doc) { const std::vector& conns = doc.GetConnectionsByDestinationSequenced(ID()); - for(size_t i = 0; i < conns.size();++i) - { + for(size_t i = 0; i < conns.size();++i) { const Connection* con = conns.at(i); const Object* const ob = con->SourceObject(); - if(!ob) { + if (nullptr == ob) { DOMWarning("failed to read source object for texture link, ignoring",&element); continue; } @@ -290,13 +271,11 @@ void LayeredTexture::fillTexture(const Document& doc) } } - // ------------------------------------------------------------------------------------------------ -Video::Video(uint64_t id, const Element& element, const Document& doc, const std::string& name) -: Object(id,element,name) -, contentLength(0) -, content(0) -{ +Video::Video(uint64_t id, const Element& element, const Document& doc, const std::string& name) : + Object(id,element,name), + contentLength(0), + content(0) { const Scope& sc = GetRequiredScope(element); const Element* const Type = sc["Type"]; @@ -324,52 +303,43 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std if (!token.IsBinary()) { if (*data != '"') { DOMError("embedded content is not surrounded by quotation marks", &element); - } - else { + } else { size_t targetLength = 0; auto numTokens = Content->Tokens().size(); // First time compute size (it could be large like 64Gb and it is good to allocate it once) - for (uint32_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx) - { + for (uint32_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx) { const Token& dataToken = GetRequiredToken(*Content, tokenIdx); size_t tokenLength = dataToken.end() - dataToken.begin() - 2; // ignore double quotes const char* base64data = dataToken.begin() + 1; const size_t outLength = Util::ComputeDecodedSizeBase64(base64data, tokenLength); - if (outLength == 0) - { + if (outLength == 0) { DOMError("Corrupted embedded content found", &element); } targetLength += outLength; } - if (targetLength == 0) - { + if (targetLength == 0) { DOMError("Corrupted embedded content found", &element); } content = new uint8_t[targetLength]; contentLength = static_cast(targetLength); size_t dst_offset = 0; - for (uint32_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx) - { + for (uint32_t tokenIdx = 0; tokenIdx < numTokens; ++tokenIdx) { const Token& dataToken = GetRequiredToken(*Content, tokenIdx); size_t tokenLength = dataToken.end() - dataToken.begin() - 2; // ignore double quotes const char* base64data = dataToken.begin() + 1; dst_offset += Util::DecodeBase64(base64data, tokenLength, content + dst_offset, targetLength - dst_offset); } - if (targetLength != dst_offset) - { + if (targetLength != dst_offset) { delete[] content; contentLength = 0; DOMError("Corrupted embedded content found", &element); } } - } - else if (static_cast(token.end() - data) < 5) { + } else if (static_cast(token.end() - data) < 5) { DOMError("binary data array is too short, need five (5) bytes for type signature and element count", &element); - } - else if (*data != 'R') { + } else if (*data != 'R') { DOMWarning("video content is not raw binary data, ignoring", &element); - } - else { + } else { // read number of elements uint32_t len = 0; ::memcpy(&len, data + 1, sizeof(len)); @@ -380,8 +350,7 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std content = new uint8_t[len]; ::memcpy(content, data + 5, len); } - } catch (const runtime_error& runtimeError) - { + } catch (const runtime_error& runtimeError) { //we don't need the content data for contents that has already been loaded ASSIMP_LOG_VERBOSE_DEBUG_F("Caught exception in FBXMaterial (likely because content was already loaded): ", runtimeError.what()); @@ -392,14 +361,11 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std } -Video::~Video() -{ - if(content) { - delete[] content; - } +Video::~Video() { + delete[] content; } } //!FBX } //!Assimp -#endif +#endif // ASSIMP_BUILD_NO_FBX_IMPORTER From 1e38f84c3a66e429f8cd3f45779bcd6c61fdfff6 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 27 Jan 2021 09:40:19 +0100 Subject: [PATCH 5/5] fix typo --- code/AssetLib/FBX/FBXMaterial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXMaterial.cpp b/code/AssetLib/FBX/FBXMaterial.cpp index 7223f3217..6997388b8 100644 --- a/code/AssetLib/FBX/FBXMaterial.cpp +++ b/code/AssetLib/FBX/FBXMaterial.cpp @@ -82,7 +82,7 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con // lower-case shading because Blender (for example) writes "Phong" for (size_t i = 0; i < shading.length(); ++i) { - shading[i] = static_cast(tolower(shading[i]); + shading[i] = static_cast(tolower(shading[i])); } std::string templateName; if(shading == "phong") {