From 89a8f87dae08b6e0c78c4d42185c30b448936afc Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 2 Apr 2021 13:10:24 +0200 Subject: [PATCH 1/5] AMF: Remove unused macros --- code/AssetLib/AMF/AMFImporter_Macro.hpp | 113 ------------------------ 1 file changed, 113 deletions(-) diff --git a/code/AssetLib/AMF/AMFImporter_Macro.hpp b/code/AssetLib/AMF/AMFImporter_Macro.hpp index 43dcf76ba..2d44204af 100644 --- a/code/AssetLib/AMF/AMFImporter_Macro.hpp +++ b/code/AssetLib/AMF/AMFImporter_Macro.hpp @@ -48,117 +48,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AMFIMPORTER_MACRO_HPP_INCLUDED #define AMFIMPORTER_MACRO_HPP_INCLUDED -/// \def MACRO_ATTRREAD_LOOPBEG -/// Begin of loop that read attributes values. -#define MACRO_ATTRREAD_LOOPBEG \ - for(int idx = 0, idx_end = mReader->getAttributeCount(); idx < idx_end; idx++) \ - { \ - std::string an(mReader->getAttributeName(idx)); - -/// \def MACRO_ATTRREAD_LOOPEND -/// End of loop that read attributes values. -#define MACRO_ATTRREAD_LOOPEND \ - Throw_IncorrectAttr(an); \ - } - -/// \def MACRO_ATTRREAD_LOOPEND_WSKIP -/// End of loop that read attributes values. Difference from \ref MACRO_ATTRREAD_LOOPEND in that: current macro skip unknown attributes, but -/// \ref MACRO_ATTRREAD_LOOPEND throw an exception. -#define MACRO_ATTRREAD_LOOPEND_WSKIP \ - continue; \ - } - -/// \def MACRO_ATTRREAD_CHECK_REF -/// Check current attribute name and if it equal to requested then read value. Result write to output variable by reference. If result was read then -/// "continue" will called. -/// \param [in] pAttrName - attribute name. -/// \param [out] pVarName - output variable name. -/// \param [in] pFunction - function which read attribute value and write it to pVarName. -#define MACRO_ATTRREAD_CHECK_REF(pAttrName, pVarName, pFunction) \ - if(an == pAttrName) \ - { \ - pFunction(idx, pVarName); \ - continue; \ - } - -/// \def MACRO_ATTRREAD_CHECK_RET -/// Check current attribute name and if it equal to requested then read value. Result write to output variable using return value of \ref pFunction. -/// If result was read then "continue" will called. -/// \param [in] pAttrName - attribute name. -/// \param [out] pVarName - output variable name. -/// \param [in] pFunction - function which read attribute value and write it to pVarName. -#define MACRO_ATTRREAD_CHECK_RET(pAttrName, pVarName, pFunction) \ - if(an == pAttrName) \ - { \ - pVarName = pFunction(idx); \ - continue; \ - } - -/// \def MACRO_NODECHECK_LOOPBEGIN(pNodeName) -/// Begin of loop of parsing child nodes. Do not add ';' at end. -/// \param [in] pNodeName - current node name. -#define MACRO_NODECHECK_LOOPBEGIN(pNodeName) \ - do { \ - bool close_found = false; \ - \ - while(mReader->read()) \ - { \ - if(mReader->getNodeType() == irr::io::EXN_ELEMENT) \ - { - -/// \def MACRO_NODECHECK_LOOPEND(pNodeName) -/// End of loop of parsing child nodes. -/// \param [in] pNodeName - current node name. -#define MACRO_NODECHECK_LOOPEND(pNodeName) \ - XML_CheckNode_SkipUnsupported(pNodeName); \ - }/* if(mReader->getNodeType() == irr::io::EXN_ELEMENT) */ \ - else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END) \ - { \ - if(XML_CheckNode_NameEqual(pNodeName)) \ - { \ - close_found = true; \ - \ - break; \ - } \ - }/* else if(mReader->getNodeType() == irr::io::EXN_ELEMENT_END) */ \ - }/* while(mReader->read()) */ \ - \ - if(!close_found) Throw_CloseNotFound(pNodeName); \ - \ - } while(false) - -/// \def MACRO_NODECHECK_READCOMP_F -/// Check current node name and if it equal to requested then read value. Result write to output variable of type "float". -/// If result was read then "continue" will called. Also check if node data already read then raise exception. -/// \param [in] pNodeName - node name. -/// \param [in, out] pReadFlag - read flag. -/// \param [out] pVarName - output variable name. -#define MACRO_NODECHECK_READCOMP_F(pNodeName, pReadFlag, pVarName) \ - if(XML_CheckNode_NameEqual(pNodeName)) \ - { \ - /* Check if field already read before. */ \ - if(pReadFlag) Throw_MoreThanOnceDefined(pNodeName, "Only one component can be defined."); \ - /* Read color component and assign it to object. */ \ - pVarName = XML_ReadNode_GetVal_AsFloat(); \ - pReadFlag = true; \ - continue; \ - } - -/// \def MACRO_NODECHECK_READCOMP_U32 -/// Check current node name and if it equal to requested then read value. Result write to output variable of type "uint32_t". -/// If result was read then "continue" will called. Also check if node data already read then raise exception. -/// \param [in] pNodeName - node name. -/// \param [in, out] pReadFlag - read flag. -/// \param [out] pVarName - output variable name. -#define MACRO_NODECHECK_READCOMP_U32(pNodeName, pReadFlag, pVarName) \ - if(XML_CheckNode_NameEqual(pNodeName)) \ - { \ - /* Check if field already read before. */ \ - if(pReadFlag) Throw_MoreThanOnceDefined(pNodeName, "Only one component can be defined."); \ - /* Read color component and assign it to object. */ \ - pVarName = XML_ReadNode_GetVal_AsU32(); \ - pReadFlag = true; \ - continue; \ - } - #endif // AMFIMPORTER_MACRO_HPP_INCLUDED From da0543972ba21304eeb3167e3dae020a1edf7d68 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 3 Apr 2021 10:25:03 +0200 Subject: [PATCH 2/5] Fix parsing for AMF-Files. --- code/AssetLib/AMF/AMFImporter.cpp | 26 ++-- code/AssetLib/AMF/AMFImporter_Geometry.cpp | 62 ++++---- code/AssetLib/AMF/AMFImporter_Macro.hpp | 51 ------- code/AssetLib/AMF/AMFImporter_Material.cpp | 140 +++++++++--------- code/AssetLib/AMF/AMFImporter_Postprocess.cpp | 18 ++- code/AssetLib/Ogre/OgreMaterial.cpp | 4 +- code/AssetLib/Ogre/OgreParsingUtils.h | 2 +- code/AssetLib/Ogre/OgreXmlSerializer.cpp | 4 +- code/AssetLib/STEPParser/STEPFileReader.cpp | 2 +- code/CMakeLists.txt | 1 - code/Common/BaseImporter.cpp | 2 +- code/Common/Importer.cpp | 2 +- code/PostProcessing/EmbedTexturesProcess.cpp | 2 +- include/assimp/StringUtils.h | 2 +- tools/assimp_view/LogWindow.cpp | 2 +- 15 files changed, 136 insertions(+), 184 deletions(-) delete mode 100644 code/AssetLib/AMF/AMFImporter_Macro.hpp diff --git a/code/AssetLib/AMF/AMFImporter.cpp b/code/AssetLib/AMF/AMFImporter.cpp index 7d6ef2fd0..37756aea0 100644 --- a/code/AssetLib/AMF/AMFImporter.cpp +++ b/code/AssetLib/AMF/AMFImporter.cpp @@ -39,16 +39,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ -/// \file AMFImporter.cpp -/// \brief AMF-format files importer for Assimp: main algorithm implementation. -/// \date 2016 -/// \author smal.root@gmail.com - #ifndef ASSIMP_BUILD_NO_AMF_IMPORTER // Header files, Assimp. #include "AMFImporter.hpp" -#include "AMFImporter_Macro.hpp" #include #include @@ -307,14 +301,14 @@ void AMFImporter::ParseNode_Root() { throw DeadlyImportError("Root node \"amf\" not found."); } XmlNode node = *root; - mUnit = ai_str_tolower(std::string(node.attribute("unit").as_string())); + mUnit = ai_tolower(std::string(node.attribute("unit").as_string())); mVersion = node.attribute("version").as_string(); // Read attributes for node . // Check attributes if (!mUnit.empty()) { - if ((mUnit != "inch") && (mUnit != "millimeter") && (mUnit != "meter") && (mUnit != "feet") && (mUnit != "micron")) { + if ((mUnit != "inch") && (mUnit != "millimeters") && (mUnit != "millimeter") && (mUnit != "meter") && (mUnit != "feet") && (mUnit != "micron")) { Throw_IncorrectAttrValue("unit", mUnit); } } @@ -409,20 +403,20 @@ void AMFImporter::ParseNode_Instance(XmlNode &node) { if (!node.empty()) { ParseHelper_Node_Enter(ne); - for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { + for (auto ¤tNode : node.children()) { const std::string ¤tName = currentNode.name(); if (currentName == "deltax") { - als.Delta.x = (ai_real)std::atof(currentNode.value()); + XmlParser::getValueAsFloat(currentNode, als.Delta.x); } else if (currentName == "deltay") { - als.Delta.y = (ai_real)std::atof(currentNode.value()); + XmlParser::getValueAsFloat(currentNode, als.Delta.y); } else if (currentName == "deltaz") { - als.Delta.z = (ai_real)std::atof(currentNode.value()); + XmlParser::getValueAsFloat(currentNode, als.Delta.z); } else if (currentName == "rx") { - als.Delta.x = (ai_real)std::atof(currentNode.value()); + XmlParser::getValueAsFloat(currentNode, als.Delta.x); } else if (currentName == "ry") { - als.Delta.y = (ai_real)std::atof(currentNode.value()); + XmlParser::getValueAsFloat(currentNode, als.Delta.y); } else if (currentName == "rz") { - als.Delta.z = (ai_real)std::atof(currentNode.value()); + XmlParser::getValueAsFloat(currentNode, als.Delta.z); } } ParseHelper_Node_Exit(); @@ -458,7 +452,7 @@ void AMFImporter::ParseNode_Object(XmlNode &node) { // Check for child nodes if (!node.empty()) { ParseHelper_Node_Enter(ne); - for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { + for (auto ¤tNode : node.children()) { const std::string ¤tName = currentNode.name(); if (currentName == "color") { ParseNode_Color(currentNode); diff --git a/code/AssetLib/AMF/AMFImporter_Geometry.cpp b/code/AssetLib/AMF/AMFImporter_Geometry.cpp index 3d50488a2..6b01ecd63 100644 --- a/code/AssetLib/AMF/AMFImporter_Geometry.cpp +++ b/code/AssetLib/AMF/AMFImporter_Geometry.cpp @@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_AMF_IMPORTER #include "AMFImporter.hpp" -#include "AMFImporter_Macro.hpp" +//#include "AMFImporter_Macro.hpp" #include @@ -103,17 +103,23 @@ void AMFImporter::ParseNode_Vertices(XmlNode &node) { // create new mesh object. ne = new AMFVertices(mNodeElement_Cur); // Check for child nodes - pugi::xml_node vertexNode = node.child("vertex"); - if (!vertexNode.empty()) { - ParseHelper_Node_Enter(ne); - - ParseNode_Vertex(vertexNode); - - ParseHelper_Node_Exit(); - - } else { + if (node.empty()) { mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element - } // if(!mReader->isEmptyElement()) else + return; + } + ParseHelper_Node_Enter(ne); + for (XmlNode ¤tNode : node.children()) { + const std::string ¤tName = currentNode.name(); + if (currentName == "vertex") { + ParseNode_Vertex(currentNode); + } + } + ParseHelper_Node_Exit(); + //pugi::xml_node vertexNode = node.child("vertex"); + //if (!vertexNode.empty()) { + +// } else { +// } // if(!mReader->isEmptyElement()) else mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph. } @@ -166,27 +172,25 @@ void AMFImporter::ParseNode_Vertex(XmlNode &node) { // X, Y, or Z coordinate, respectively, of a vertex position in space. void AMFImporter::ParseNode_Coordinates(XmlNode &node) { AMFNodeElementBase *ne = nullptr; - - // create new color object. - ne = new AMFCoordinates(mNodeElement_Cur); - - AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience if (!node.empty()) { + ne = new AMFCoordinates(mNodeElement_Cur); ParseHelper_Node_Enter(ne); for (XmlNode ¤tNode : node.children()) { - const std::string ¤tName = currentNode.name(); - if (currentName == "X") { + // create new color object. + AMFCoordinates &als = *((AMFCoordinates *)ne); // alias for convenience + const std::string ¤tName = ai_tolower(currentNode.name()); + if (currentName == "x") { XmlParser::getValueAsFloat(currentNode, als.Coordinate.x); - } else if (currentName == "Y") { + } else if (currentName == "y") { XmlParser::getValueAsFloat(currentNode, als.Coordinate.y); - } else if (currentName == "Z") { + } else if (currentName == "z") { XmlParser::getValueAsFloat(currentNode, als.Coordinate.z); } } - ParseHelper_Node_Exit(); + } else { - mNodeElement_Cur->Child.push_back(ne); + mNodeElement_Cur->Child.push_back(new AMFCoordinates(mNodeElement_Cur)); } mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph. @@ -216,7 +220,7 @@ void AMFImporter::ParseNode_Volume(XmlNode &node) { bool col_read = false; if (!node.empty()) { ParseHelper_Node_Enter(ne); - for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { + for (auto ¤tNode : node.children()) { const std::string currentName = currentNode.name(); if (currentName == "color") { if (col_read) Throw_MoreThanOnceDefined(currentName, "color", "Only one color can be defined for ."); @@ -258,7 +262,8 @@ void AMFImporter::ParseNode_Triangle(XmlNode &node) { bool col_read = false; if (!node.empty()) { ParseHelper_Node_Enter(ne); - for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) { + std::string v; + for (auto ¤tNode : node.children()) { const std::string currentName = currentNode.name(); if (currentName == "color") { if (col_read) Throw_MoreThanOnceDefined(currentName, "color", "Only one color can be defined for ."); @@ -269,11 +274,14 @@ void AMFImporter::ParseNode_Triangle(XmlNode &node) { } else if (currentName == "map") { ParseNode_TexMap(currentNode, true); } else if (currentName == "v1") { - als.V[0] = std::atoi(currentNode.value()); + XmlParser::getValueAsString(currentNode, v); + als.V[0] = std::atoi(v.c_str()); } else if (currentName == "v2") { - als.V[1] = std::atoi(currentNode.value()); + XmlParser::getValueAsString(currentNode, v); + als.V[1] = std::atoi(v.c_str()); } else if (currentName == "v3") { - als.V[2] = std::atoi(currentNode.value()); + XmlParser::getValueAsString(currentNode, v); + als.V[2] = std::atoi(v.c_str()); } } ParseHelper_Node_Exit(); diff --git a/code/AssetLib/AMF/AMFImporter_Macro.hpp b/code/AssetLib/AMF/AMFImporter_Macro.hpp deleted file mode 100644 index 2d44204af..000000000 --- a/code/AssetLib/AMF/AMFImporter_Macro.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* ---------------------------------------------------------------------------- -Open Asset Import Library (assimp) ---------------------------------------------------------------------------- - -Copyright (c) 2006-2021, assimp team - -All rights reserved. - -Redistribution and use of this software in source and binary forms, -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. ---------------------------------------------------------------------------- -*/ - -/// \file AMFImporter_Macro.hpp -/// \brief Useful macrodefines. -/// \date 2016 -/// \author smal.root@gmail.com - -#pragma once -#ifndef AMFIMPORTER_MACRO_HPP_INCLUDED -#define AMFIMPORTER_MACRO_HPP_INCLUDED - -#endif // AMFIMPORTER_MACRO_HPP_INCLUDED diff --git a/code/AssetLib/AMF/AMFImporter_Material.cpp b/code/AssetLib/AMF/AMFImporter_Material.cpp index 1fcc7eed9..6b9300bfa 100644 --- a/code/AssetLib/AMF/AMFImporter_Material.cpp +++ b/code/AssetLib/AMF/AMFImporter_Material.cpp @@ -65,48 +65,45 @@ namespace Assimp { // Red, Greed, Blue and Alpha (transparency) component of a color in sRGB space, values ranging from 0 to 1. The // values can be specified as constants, or as a formula depending on the coordinates. void AMFImporter::ParseNode_Color(XmlNode &node) { - std::string profile = node.attribute("profile").as_string(); - - // create new color object. - AMFNodeElementBase *ne = new AMFColor(mNodeElement_Cur); - AMFColor& als = *((AMFColor*)ne);// alias for convenience + if (node.empty()) { + return; + } - als.Profile = profile; - if (!node.empty()) { - ParseHelper_Node_Enter(ne); - bool read_flag[4] = { false, false, false, false }; - for (pugi::xml_node &child : node.children()) { - std::string name = child.name(); - if ( name == "r") { - read_flag[0] = true; - XmlParser::getValueAsFloat(child, als.Color.r); - } else if (name == "g") { - read_flag[1] = true; - XmlParser::getValueAsFloat(child, als.Color.g); - } else if (name == "b") { - read_flag[2] = true; - XmlParser::getValueAsFloat(child, als.Color.b); - } else if (name == "a") { - read_flag[3] = true; - XmlParser::getValueAsFloat(child, als.Color.a); - } - ParseHelper_Node_Exit(); + const std::string &profile = node.attribute("profile").as_string(); + bool read_flag[4] = { false, false, false, false }; + AMFNodeElementBase *ne = new AMFColor(mNodeElement_Cur); + AMFColor &als = *((AMFColor *)ne); // alias for convenience + ParseHelper_Node_Enter(ne); + for (pugi::xml_node &child : node.children()) { + // create new color object. + als.Profile = profile; + + const std::string &name = child.name(); + if ( name == "r") { + read_flag[0] = true; + XmlParser::getValueAsFloat(child, als.Color.r); + } else if (name == "g") { + read_flag[1] = true; + XmlParser::getValueAsFloat(child, als.Color.g); + } else if (name == "b") { + read_flag[2] = true; + XmlParser::getValueAsFloat(child, als.Color.b); + } else if (name == "a") { + read_flag[3] = true; + XmlParser::getValueAsFloat(child, als.Color.a); } - // check that all components was defined - if (!(read_flag[0] && read_flag[1] && read_flag[2])) { - throw DeadlyImportError("Not all color components are defined."); - } - - // check if is absent. Then manually add "a == 1". - if (!read_flag[3]) { - als.Color.a = 1; - } - } else { - mNodeElement_Cur->Child.push_back(ne);// Add element to child list of current element + // check if is absent. Then manually add "a == 1". + if (!read_flag[3]) { + als.Color.a = 1; + } + } + als.Composed = false; + mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph. + ParseHelper_Node_Exit(); + // check that all components was defined + if (!(read_flag[0] && read_flag[1] && read_flag[2])) { + throw DeadlyImportError("Not all color components are defined."); } - - als.Composed = false; - mNodeElement_List.push_back(ne);// and to node element list because its a new object in graph. } // . void AMFImporter::ParseNode_Texture(XmlNode &node) { - std::string id = node.attribute("id").as_string(); - uint32_t width = node.attribute("width").as_uint(); - uint32_t height = node.attribute("height").as_uint(); - uint32_t depth = node.attribute("depth").as_uint(); - std::string type = node.attribute("type").as_string(); + const std::string id = node.attribute("id").as_string(); + const uint32_t width = node.attribute("width").as_uint(); + const uint32_t height = node.attribute("height").as_uint(); + uint32_t depth = node.attribute("depth").as_uint(); + const std::string type = node.attribute("type").as_string(); bool tiled = node.attribute("tiled").as_bool(); if (node.empty()) { @@ -174,21 +171,22 @@ void AMFImporter::ParseNode_Texture(XmlNode &node) { AMFTexture& als = *((AMFTexture*)ne);// alias for convenience - std::string enc64_data = node.value(); - // Check for child nodes + std::string enc64_data; + XmlParser::getValueAsString(node, enc64_data); + // Check for child nodes // check that all components was defined if (id.empty()) { throw DeadlyImportError("ID for texture must be defined."); } if (width < 1) { - throw DeadlyImportError("INvalid width for texture."); + throw DeadlyImportError("Invalid width for texture."); } if (height < 1) { throw DeadlyImportError("Invalid height for texture."); } if (depth < 1) { - throw DeadlyImportError("Invalid depth for texture."); + // throw DeadlyImportError("Invalid depth for texture."); } if (type != "grayscale") { throw DeadlyImportError("Invalid type for texture."); @@ -203,7 +201,9 @@ void AMFImporter::ParseNode_Texture(XmlNode &node) { als.Depth = depth; als.Tiled = tiled; ParseHelper_Decode_Base64(enc64_data, als.Data); - + if (depth == 0) { + depth = (uint32_t)(als.Data.size() / (width * height)); + } // check data size if ((width * height * depth) != als.Data.size()) { throw DeadlyImportError("Texture has incorrect data size."); @@ -233,20 +233,18 @@ void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) { AMFTexMap &als = *((AMFTexMap *)ne); // std::string rtexid, gtexid, btexid, atexid; if (!node.empty()) { - ParseHelper_Node_Enter(ne); - for (XmlNode ¤tNode : node.children()) { - const std::string ¤tName = currentNode.name(); - if (currentName == "rtexid") { - XmlParser::getValueAsString(node, rtexid); - } else if (currentName == "gtexid") { - XmlParser::getValueAsString(node, gtexid); - } else if (currentName == "btexid") { - XmlParser::getValueAsString(node, btexid); - } else if (currentName == "atexid") { - XmlParser::getValueAsString(node, atexid); + for (pugi::xml_attribute &attr : node.attributes()) { + const std::string ¤tAttr = attr.name(); + if (currentAttr == "rtexid") { + rtexid = attr.as_string(); + } else if (currentAttr == "gtexid") { + gtexid = attr.as_string(); + } else if (currentAttr == "btexid") { + btexid = attr.as_string(); + } else if (currentAttr == "atexid") { + atexid = attr.as_string(); } } - ParseHelper_Node_Exit(); } // create new texture coordinates object, alias for convenience @@ -256,7 +254,6 @@ void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) { } // Check for children nodes - //XML_CheckNode_MustHaveChildren(); if (node.children().begin() == node.children().end()) { throw DeadlyImportError("Invalid children definition."); } @@ -264,28 +261,31 @@ void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) { bool read_flag[6] = { false, false, false, false, false, false }; if (!pUseOldName) { - for (pugi::xml_attribute &attr : node.attributes()) { - const std::string name = attr.name(); + ParseHelper_Node_Enter(ne); + for ( XmlNode ¤tNode : node.children()) { + const std::string &name = currentNode.name(); if (name == "utex1") { read_flag[0] = true; - als.TextureCoordinate[0].x = attr.as_float(); + XmlParser::getValueAsFloat(node, als.TextureCoordinate[0].x); } else if (name == "utex2") { read_flag[1] = true; - als.TextureCoordinate[1].x = attr.as_float(); + XmlParser::getValueAsFloat(node, als.TextureCoordinate[1].x); } else if (name == "utex3") { read_flag[2] = true; - als.TextureCoordinate[2].x = attr.as_float(); + XmlParser::getValueAsFloat(node, als.TextureCoordinate[2].x); } else if (name == "vtex1") { read_flag[3] = true; - als.TextureCoordinate[0].y = attr.as_float(); + XmlParser::getValueAsFloat(node, als.TextureCoordinate[0].y); } else if (name == "vtex2") { read_flag[4] = true; - als.TextureCoordinate[1].y = attr.as_float(); + XmlParser::getValueAsFloat(node, als.TextureCoordinate[1].y); } else if (name == "vtex3") { read_flag[5] = true; - als.TextureCoordinate[0].y = attr.as_float(); + XmlParser::getValueAsFloat(node, als.TextureCoordinate[2].y); } } + ParseHelper_Node_Exit(); + } else { for (pugi::xml_attribute &attr : node.attributes()) { const std::string name = attr.name(); diff --git a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp index 9bbfc3249..036b647e8 100644 --- a/code/AssetLib/AMF/AMFImporter_Postprocess.cpp +++ b/code/AssetLib/AMF/AMFImporter_Postprocess.cpp @@ -62,12 +62,14 @@ aiColor4D AMFImporter::SPP_Material::GetColor(const float /*pX*/, const float /* // Check if stored data are supported. if (!Composition.empty()) { throw DeadlyImportError("IME. GetColor for composition"); - } else if (Color->Composed) { - throw DeadlyImportError("IME. GetColor, composed color"); - } else { - tcol = Color->Color; } + if (Color->Composed) { + throw DeadlyImportError("IME. GetColor, composed color"); + } + + tcol = Color->Color; + // Check if default color must be used if ((tcol.r == 0) && (tcol.g == 0) && (tcol.b == 0) && (tcol.a == 0)) { tcol.r = 0.5f; @@ -79,13 +81,13 @@ aiColor4D AMFImporter::SPP_Material::GetColor(const float /*pX*/, const float /* return tcol; } -void AMFImporter::PostprocessHelper_CreateMeshDataArray(const AMFMesh &pNodeElement, std::vector &pVertexCoordinateArray, +void AMFImporter::PostprocessHelper_CreateMeshDataArray(const AMFMesh &nodeElement, std::vector &vertexCoordinateArray, std::vector &pVertexColorArray) const { AMFVertices *vn = nullptr; size_t col_idx; // All data stored in "vertices", search for it. - for (AMFNodeElementBase *ne_child : pNodeElement.Child) { + for (AMFNodeElementBase *ne_child : nodeElement.Child) { if (ne_child->Type == AMFNodeElementBase::ENET_Vertices) { vn = (AMFVertices*)ne_child; } @@ -97,7 +99,7 @@ void AMFImporter::PostprocessHelper_CreateMeshDataArray(const AMFMesh &pNodeElem } // all coordinates stored as child and we need to reserve space for future push_back's. - pVertexCoordinateArray.reserve(vn->Child.size()); + vertexCoordinateArray.reserve(vn->Child.size()); // colors count equal vertices count. pVertexColorArray.resize(vn->Child.size()); @@ -112,7 +114,7 @@ void AMFImporter::PostprocessHelper_CreateMeshDataArray(const AMFMesh &pNodeElem for (AMFNodeElementBase *vtx : vn_child->Child) { if (vtx->Type == AMFNodeElementBase::ENET_Coordinates) { - pVertexCoordinateArray.push_back(((AMFCoordinates *)vtx)->Coordinate); + vertexCoordinateArray.push_back(((AMFCoordinates *)vtx)->Coordinate); continue; } diff --git a/code/AssetLib/Ogre/OgreMaterial.cpp b/code/AssetLib/Ogre/OgreMaterial.cpp index 35a9bf4c5..eced651f6 100644 --- a/code/AssetLib/Ogre/OgreMaterial.cpp +++ b/code/AssetLib/Ogre/OgreMaterial.cpp @@ -419,7 +419,7 @@ bool OgreImporter::ReadTextureUnit(const std::string &textureUnitName, stringstr size_t posUnderscore = textureRef.find_last_of("_"); if (posSuffix != string::npos && posUnderscore != string::npos && posSuffix > posUnderscore) { - string identifier = ai_str_tolower(textureRef.substr(posUnderscore, posSuffix - posUnderscore)); + string identifier = ai_tolower(textureRef.substr(posUnderscore, posSuffix - posUnderscore)); ASSIMP_LOG_VERBOSE_DEBUG_F("Detecting texture type from filename postfix '", identifier, "'"); if (identifier == "_n" || identifier == "_nrm" || identifier == "_nrml" || identifier == "_normal" || identifier == "_normals" || identifier == "_normalmap") { @@ -440,7 +440,7 @@ bool OgreImporter::ReadTextureUnit(const std::string &textureUnitName, stringstr // Detect from texture unit name. This cannot be too broad as // authors might give names like "LightSaber" or "NormalNinja". else { - string unitNameLower = ai_str_tolower(textureUnitName); + string unitNameLower = ai_tolower(textureUnitName); if (unitNameLower.find("normalmap") != string::npos) { textureType = aiTextureType_NORMALS; } else if (unitNameLower.find("specularmap") != string::npos) { diff --git a/code/AssetLib/Ogre/OgreParsingUtils.h b/code/AssetLib/Ogre/OgreParsingUtils.h index 70797a237..0925c0305 100644 --- a/code/AssetLib/Ogre/OgreParsingUtils.h +++ b/code/AssetLib/Ogre/OgreParsingUtils.h @@ -64,7 +64,7 @@ static inline bool EndsWith(const std::string &s, const std::string &suffix, boo } if (!caseSensitive) { - return EndsWith(ai_str_tolower(s), ai_str_tolower(suffix), true); + return EndsWith(ai_tolower(s), ai_tolower(suffix), true); } size_t len = suffix.length(); diff --git a/code/AssetLib/Ogre/OgreXmlSerializer.cpp b/code/AssetLib/Ogre/OgreXmlSerializer.cpp index 99c05a522..938ae48f3 100644 --- a/code/AssetLib/Ogre/OgreXmlSerializer.cpp +++ b/code/AssetLib/Ogre/OgreXmlSerializer.cpp @@ -120,7 +120,7 @@ std::string OgreXmlSerializer::ReadAttribute(XmlNode &xmlNode, cons template <> bool OgreXmlSerializer::ReadAttribute(XmlNode &xmlNode, const char *name) const { - std::string value = ai_str_tolower(ReadAttribute(xmlNode, name)); + std::string value = ai_tolower(ReadAttribute(xmlNode, name)); if (ASSIMP_stricmp(value, "true") == 0) { return true; } else if (ASSIMP_stricmp(value, "false") == 0) { @@ -545,7 +545,7 @@ void OgreXmlSerializer::ReadSkeleton(XmlNode &node, Skeleton *skeleton) { // Optional blend mode from root node if (XmlParser::hasAttribute(node, "blendmode")) { - skeleton->blendMode = (ai_str_tolower(ReadAttribute(node, "blendmode")) == "cumulative" ? Skeleton::ANIMBLEND_CUMULATIVE : Skeleton::ANIMBLEND_AVERAGE); + skeleton->blendMode = (ai_tolower(ReadAttribute(node, "blendmode")) == "cumulative" ? Skeleton::ANIMBLEND_CUMULATIVE : Skeleton::ANIMBLEND_AVERAGE); } for (XmlNode ¤tNode : node.children()) { diff --git a/code/AssetLib/STEPParser/STEPFileReader.cpp b/code/AssetLib/STEPParser/STEPFileReader.cpp index 113b8dd6a..cbf8c07c2 100644 --- a/code/AssetLib/STEPParser/STEPFileReader.cpp +++ b/code/AssetLib/STEPParser/STEPFileReader.cpp @@ -278,7 +278,7 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme, --ne; } while (IsSpace(s.at(ne))); std::string type = s.substr(ns, ne - ns + 1); - type = ai_str_tolower(type); + type = ai_tolower(type); const char* sz = scheme.GetStaticStringForToken(type); if(sz) { const std::string::size_type szLen = n2-n1+1; diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 815d5dd6a..ebc3e0116 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -298,7 +298,6 @@ SET(ASSIMP_EXPORTERS_DISABLED "") # disabled exporters list (used to print) ADD_ASSIMP_IMPORTER( AMF AssetLib/AMF/AMFImporter.hpp - AssetLib/AMF/AMFImporter_Macro.hpp AssetLib/AMF/AMFImporter_Node.hpp AssetLib/AMF/AMFImporter.cpp AssetLib/AMF/AMFImporter_Geometry.cpp diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index cbecbf075..0657216cf 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -276,7 +276,7 @@ std::string BaseImporter::GetExtension(const std::string &file) { // thanks to Andy Maloney for the hint std::string ret = file.substr(pos + 1); - ret = ai_str_tolower(ret); + ret = ai_tolower(ret); return ret; } diff --git a/code/Common/Importer.cpp b/code/Common/Importer.cpp index 34953074c..db7fc9e1c 100644 --- a/code/Common/Importer.cpp +++ b/code/Common/Importer.cpp @@ -982,7 +982,7 @@ size_t Importer::GetImporterIndex (const char* szExtension) const { if (ext.empty()) { return static_cast(-1); } - ext = ai_str_tolower(ext); + ext = ai_tolower(ext); std::set str; for (std::vector::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) { str.clear(); diff --git a/code/PostProcessing/EmbedTexturesProcess.cpp b/code/PostProcessing/EmbedTexturesProcess.cpp index b7aadcb23..dc304ff9c 100644 --- a/code/PostProcessing/EmbedTexturesProcess.cpp +++ b/code/PostProcessing/EmbedTexturesProcess.cpp @@ -137,7 +137,7 @@ bool EmbedTexturesProcess::addTexture(aiScene* pScene, std::string path) const { pTexture->pcData = imageContent; auto extension = path.substr(path.find_last_of('.') + 1u); - extension = ai_str_tolower(extension); + extension = ai_tolower(extension); if (extension == "jpeg") { extension = "jpg"; } diff --git a/include/assimp/StringUtils.h b/include/assimp/StringUtils.h index b612a84cc..4afd717cf 100644 --- a/include/assimp/StringUtils.h +++ b/include/assimp/StringUtils.h @@ -225,7 +225,7 @@ AI_FORCE_INLINE char_t ai_tolower(char_t in) { /// @param in The incoming string. /// @return The string as lowercase. // --------------------------------------------------------------------------------- -AI_FORCE_INLINE std::string ai_str_tolower(const std::string &in) { +AI_FORCE_INLINE std::string ai_tolower(const std::string &in) { std::string out(in); ai_trim_left(out); ai_trim_right(out); diff --git a/tools/assimp_view/LogWindow.cpp b/tools/assimp_view/LogWindow.cpp index 5397594dc..8a47b259f 100644 --- a/tools/assimp_view/LogWindow.cpp +++ b/tools/assimp_view/LogWindow.cpp @@ -105,7 +105,7 @@ void CLogWindow::Init() { // setup the log text this->szText = AI_VIEW_RTF_LOG_HEADER; - ; + this->szPlainText = ""; } From 46e49d0b8352bbd6215b72a821c8e03db854b3a3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 3 Apr 2021 10:27:54 +0200 Subject: [PATCH 3/5] Update AMFImporter_Geometry.cpp --- code/AssetLib/AMF/AMFImporter_Geometry.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/code/AssetLib/AMF/AMFImporter_Geometry.cpp b/code/AssetLib/AMF/AMFImporter_Geometry.cpp index 6b01ecd63..7d6023316 100644 --- a/code/AssetLib/AMF/AMFImporter_Geometry.cpp +++ b/code/AssetLib/AMF/AMFImporter_Geometry.cpp @@ -39,16 +39,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ -/// \file AMFImporter_Geometry.cpp -/// \brief Parsing data from geometry nodes. -/// \date 2016 -/// \author smal.root@gmail.com - #ifndef ASSIMP_BUILD_NO_AMF_IMPORTER #include "AMFImporter.hpp" -//#include "AMFImporter_Macro.hpp" - #include namespace Assimp { From d62c89557ba164be67a1df72302c1f628dc00858 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 3 Apr 2021 10:28:19 +0200 Subject: [PATCH 4/5] Remove dead code --- code/AssetLib/AMF/AMFImporter_Geometry.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/code/AssetLib/AMF/AMFImporter_Geometry.cpp b/code/AssetLib/AMF/AMFImporter_Geometry.cpp index 7d6023316..1fd2c49a4 100644 --- a/code/AssetLib/AMF/AMFImporter_Geometry.cpp +++ b/code/AssetLib/AMF/AMFImporter_Geometry.cpp @@ -108,12 +108,6 @@ void AMFImporter::ParseNode_Vertices(XmlNode &node) { } } ParseHelper_Node_Exit(); - //pugi::xml_node vertexNode = node.child("vertex"); - //if (!vertexNode.empty()) { - -// } else { -// } // if(!mReader->isEmptyElement()) else - mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph. } From 80fc8538be9098aa7b9d7fb09bdaef5b3aace627 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 3 Apr 2021 10:29:16 +0200 Subject: [PATCH 5/5] Update AMFImporter_Material.cpp --- code/AssetLib/AMF/AMFImporter_Material.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/AssetLib/AMF/AMFImporter_Material.cpp b/code/AssetLib/AMF/AMFImporter_Material.cpp index 6b9300bfa..6d93a43b6 100644 --- a/code/AssetLib/AMF/AMFImporter_Material.cpp +++ b/code/AssetLib/AMF/AMFImporter_Material.cpp @@ -185,9 +185,6 @@ void AMFImporter::ParseNode_Texture(XmlNode &node) { if (height < 1) { throw DeadlyImportError("Invalid height for texture."); } - if (depth < 1) { - // throw DeadlyImportError("Invalid depth for texture."); - } if (type != "grayscale") { throw DeadlyImportError("Invalid type for texture."); }