From 0bacc7134db4ae3cf66ba3535a5fa9599eb2363a Mon Sep 17 00:00:00 2001 From: PencilAmazing <16854231+PencilAmazing@users.noreply.github.com> Date: Fri, 30 Jun 2023 19:57:09 -0400 Subject: [PATCH] Remove debugging code, clean up some notes --- code/AssetLib/Irr/IRRLoader.cpp | 77 ++++++++++------------------- code/AssetLib/Irr/IRRMeshLoader.cpp | 4 +- code/AssetLib/Irr/IRRShared.h | 2 +- 3 files changed, 30 insertions(+), 53 deletions(-) diff --git a/code/AssetLib/Irr/IRRLoader.cpp b/code/AssetLib/Irr/IRRLoader.cpp index 2ca6bfd65..ba6ebc964 100644 --- a/code/AssetLib/Irr/IRRLoader.cpp +++ b/code/AssetLib/Irr/IRRLoader.cpp @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @brief Implementation of the Irr importer class */ +#include "assimp/Exceptional.h" #include "assimp/StringComparison.h" #ifndef ASSIMP_BUILD_NO_IRR_IMPORTER @@ -63,10 +64,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include -#include -#include - using namespace Assimp; static const aiImporterDesc desc = { @@ -1160,45 +1157,37 @@ IRRImporter::Node *IRRImporter::ParseNode(pugi::xml_node &node, BatchLoader &bat } // TODO: consolidate all into one loop - // Collect node attributes first - for (pugi::xml_node attr_node : node.children()) { - if (!ASSIMP_stricmp(attr_node.name(), "attributes")) { - ParseNodeAttributes(attr_node, nd, batch); // Parse attributes into this node - } - } + for (pugi::xml_node subNode : node.children()) { + // Collect node attributes first + if (!ASSIMP_stricmp(subNode.name(), "attributes")) { + ParseNodeAttributes(subNode, nd, batch); // Parse attributes into this node + } else if (!ASSIMP_stricmp(subNode.name(), "animators")) { + // Then parse any animators + // All animators should contain an tag - // Then parse any materials - // Materials are available to almost all node types - if (nd->type != Node::DUMMY) { - for (pugi::xml_node materialNode : node.children()) { - if (!ASSIMP_stricmp(materialNode.name(), "materials")) { + // This is an animation path - add a new animator + // to the list. + ParseAnimators(subNode, nd); // Function modifies nd's animator vector + guessedAnimCnt += 1; + } + + // Then parse any materials + // Materials are available to almost all node types + if (nd->type != Node::DUMMY) { + if (!ASSIMP_stricmp(subNode.name(), "materials")) { // Parse material description directly // Each material should contain an node // with everything specified nd->materials.emplace_back(); std::pair &p = nd->materials.back(); - p.first = ParseMaterial(materialNode, p.second); + p.first = ParseMaterial(subNode, p.second); guessedMatCnt += 1; } } } - // Then parse any animators - for (pugi::xml_node animatorNode : node.children()) { - if (!ASSIMP_stricmp(animatorNode.name(), "animators")) { - // All animators should contain an tag - // This is an animation path - add a new animator - // to the list. - ParseAnimators(animatorNode, nd); // Function modifies nd's animator vector - guessedAnimCnt += 1; - } - } // Then parse any child nodes - /* Attach the newly created node to the scene-graph - */ - // curNode = nd; - // nd->parent = curParent; - // curParent->children.push_back(nd); + // Attach the newly created node to the scene-graph for (pugi::xml_node child : node.children()) { if (!ASSIMP_stricmp(child.name(), "node")) { // Is a child node Node *childNd = ParseNode(child, batch); // Repeat this function for all children @@ -1206,6 +1195,7 @@ IRRImporter::Node *IRRImporter::ParseNode(pugi::xml_node &node, BatchLoader &bat }; } + // Return fully specified node return nd; } @@ -1223,17 +1213,9 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy if (!st.parse(file.get())) { throw DeadlyImportError("XML parse error while loading IRR file ", pFile); } - pugi::xml_node rootElement = st.getRootNode(); + pugi::xml_node documentRoot = st.getRootNode(); - std::stringstream ss; - ss << "Document name: " << rootElement.name() << std::endl; - ss << "Document content: " << std::endl; - rootElement.print(ss); - ss << std::endl; - std::cout << "IrrImporter with"; - std::cout << ss.str() << std::endl; // The root node of the scene - // TODO: Appearantly root node is specified somewhere? Node *root = new Node(Node::DUMMY); root->parent = nullptr; root->name = ""; @@ -1250,18 +1232,13 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy this->guessedMatCnt = 0; // Parse the XML - // First node is the xml header. Awkwardly skip to sibling's children - // I don't like recursion - // TODO clean up - std::vector nextNodes; - for (auto &node : rootElement.children().begin()->next_sibling().children()) { - nextNodes.push_back(node); // Find second node, , and push it's children to queue - } - for (pugi::xml_node &child : nextNodes) { - if (child.type() != pugi::node_element) continue; // Only semantically valuable nodes + // Find the scene root from document root. + const pugi::xml_node &sceneRoot = documentRoot.child("irr_scene"); + if (!sceneRoot) throw new DeadlyImportError("IRR: not found in file"); + for (pugi::xml_node &child : sceneRoot.children()) { // XML elements are either nodes, animators, attributes, or materials if (!ASSIMP_stricmp(child.name(), "node")) { - // Recursive ollect subtree children + // Recursive collect subtree children Node *nd = ParseNode(child, batch); // Attach to root root->children.push_back(nd); diff --git a/code/AssetLib/Irr/IRRMeshLoader.cpp b/code/AssetLib/Irr/IRRMeshLoader.cpp index 88c4f6346..8161a2997 100644 --- a/code/AssetLib/Irr/IRRMeshLoader.cpp +++ b/code/AssetLib/Irr/IRRMeshLoader.cpp @@ -157,8 +157,8 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile, */ // Parse the XML file - // FIXME get not root - for (pugi::xml_node bufferNode : root.children()) { + pugi::xml_node const &meshNode = root.child("mesh"); + for (pugi::xml_node bufferNode : meshNode.children()) { if (ASSIMP_stricmp(bufferNode.name(), "buffer")) { // Might be a useless warning ASSIMP_LOG_WARN("IRRMESH: Ignoring non buffer node <", bufferNode.name(), "> in mesh declaration"); diff --git a/code/AssetLib/Irr/IRRShared.h b/code/AssetLib/Irr/IRRShared.h index a8997451d..c04d20e52 100644 --- a/code/AssetLib/Irr/IRRShared.h +++ b/code/AssetLib/Irr/IRRShared.h @@ -92,7 +92,7 @@ protected: // ------------------------------------------------------------------- /** Read a property of the specified type from the current XML element. * @param out Receives output data - * @param node XML attribute element data + * @param node XML attribute element containing data */ void ReadHexProperty(HexProperty &out, pugi::xml_node& hexnode); void ReadStringProperty(StringProperty &out, pugi::xml_node& stringnode);