From c4039d5cf0014c6e6b56a56f280d8a077ba10074 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 21 Sep 2020 20:05:16 +0200 Subject: [PATCH] fix collada data parsing. --- code/AssetLib/Collada/ColladaParser.cpp | 5 +++++ include/assimp/StringUtils.h | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/code/AssetLib/Collada/ColladaParser.cpp b/code/AssetLib/Collada/ColladaParser.cpp index 12cc24797..b353264a3 100644 --- a/code/AssetLib/Collada/ColladaParser.cpp +++ b/code/AssetLib/Collada/ColladaParser.cpp @@ -256,6 +256,7 @@ void ColladaParser::ReadContents(XmlNode &node) { void ColladaParser::ReadStructure(XmlNode &node) { for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { const std::string name = std::string(currentNode.name()); + ASSIMP_LOG_DEBUG("last name" + name); if (name == "asset") ReadAssetInfo(currentNode); else if (name == "library_animations") @@ -404,6 +405,9 @@ void ColladaParser::PostProcessControllers() { std::string meshId; for (ControllerLibrary::iterator it = mControllerLibrary.begin(); it != mControllerLibrary.end(); ++it) { meshId = it->second.mMeshId; + if (meshId.empty()) { + continue; + } ControllerLibrary::iterator findItr = mControllerLibrary.find(meshId); while (findItr != mControllerLibrary.end()) { meshId = findItr->second.mMeshId; @@ -1404,6 +1408,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) { XmlParser::getUIntAttribute(node, "count", count); std::string v; XmlParser::getValueAsString(node, v); + trim(v); const char *content = v.c_str(); // read values and store inside an array in the data library diff --git a/include/assimp/StringUtils.h b/include/assimp/StringUtils.h index 7e1cb4ce0..9ebff9406 100644 --- a/include/assimp/StringUtils.h +++ b/include/assimp/StringUtils.h @@ -162,4 +162,24 @@ AI_FORCE_INLINE std::string Rgba2Hex(int r, int g, int b, int a, bool with_head) return ss.str(); } +// trim from start (in place) +inline void ltrim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); +} + +// trim from end (in place) +inline void rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(),s.end()); +} + +// trim from both ends (in place) +inline void trim(std::string &s) { + ltrim(s); + rtrim(s); +} + #endif // INCLUDED_AI_STRINGUTILS_H