From 5670f060461c138c3676a9c193ccf3c1ae79d978 Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Wed, 18 Jan 2023 03:45:11 +0800 Subject: [PATCH] Rig node order and tree structure should match that of default order in mesh --- src/Libraries/MeshCompiler.cpp | 9 ++++----- src/Libraries/MeshWriter.cpp | 30 ++++++++++++++++++------------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Libraries/MeshCompiler.cpp b/src/Libraries/MeshCompiler.cpp index 50da796..cd64052 100644 --- a/src/Libraries/MeshCompiler.cpp +++ b/src/Libraries/MeshCompiler.cpp @@ -290,8 +290,6 @@ namespace SH_COMP nodeStack.emplace(PairHelper(baseNode)); rig.root = nodeStack.top().first; - rig.header.nodeCount++; - rig.header.charCounts.push_back(rig.root->name.length()); while(!nodeStack.empty()) { @@ -300,14 +298,15 @@ namespace SH_COMP auto currNode = currPair.first; auto const& currAiNode = currPair.second; int const iStart {static_cast(currAiNode->mNumChildren - 1)}; + + rig.header.nodeCount++; + rig.header.charCounts.push_back(currNode->name.length()); + for (int i {iStart}; i >= 0 ; --i) { auto newPair = PairHelper(currAiNode->mChildren[i]); currNode->children.push_back(newPair.first); nodeStack.push(newPair); - - rig.header.nodeCount++; - rig.header.charCounts.push_back(newPair.first->name.length()); } } } diff --git a/src/Libraries/MeshWriter.cpp b/src/Libraries/MeshWriter.cpp index 1c8d604..187830c 100644 --- a/src/Libraries/MeshWriter.cpp +++ b/src/Libraries/MeshWriter.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace SH_COMP { @@ -189,7 +190,6 @@ namespace SH_COMP treeRoot->id = 0; treeRoot->children.clear(); nodeStack.emplace(std::make_pair(treeRoot, rig.root)); - dataToWrite.emplace_back(rig.root->name, rig.root->transform); while(!nodeStack.empty()) { @@ -198,15 +198,17 @@ namespace SH_COMP auto currWriteNode = currPair.first; auto currDataNode = currPair.second; - for (int i {static_cast(currDataNode->children.size() - 1)}; i >= 0; --i) + dataToWrite.emplace_back(currDataNode->name, currDataNode->transform); + uint32_t idCounter = dataToWrite.size() + currDataNode->children.size() - 1; + + for (auto i{0}; i < currDataNode->children.size(); ++i) { auto child = currDataNode->children[i]; auto newPair = std::make_pair(new RigWriteNode(), child); - newPair.first->id = dataToWrite.size(); + + newPair.first->id = idCounter - i; currWriteNode->children.push_back(newPair.first); nodeStack.push(newPair); - - dataToWrite.emplace_back(child->name, child->transform); } delete currDataNode; @@ -224,29 +226,33 @@ namespace SH_COMP void MeshWriter::WriteRigTree(FileReference file, RigWriteNode const* root) { - std::stack nodeStack; - nodeStack.push(root); + std::queue nodeQueue; + nodeQueue.push(root); - while(!nodeStack.empty()) + int ctr = 0; + + while(!nodeQueue.empty()) { - auto node = nodeStack.top(); - nodeStack.pop(); + auto node = nodeQueue.front(); + nodeQueue.pop(); file.write( reinterpret_cast(&node->id), sizeof(uint32_t) ); - uint32_t size = node->children.size(); + uint32_t size = static_cast(node->children.size()); file.write( reinterpret_cast(&size), sizeof(uint32_t) ); + std::cout << "Write Node: " << node->id << ", " << node->children.size() << std::endl;; + for (auto child : node->children) { - nodeStack.push(child); + nodeQueue.push(child); } } }