Rig node order and tree structure should match that of default order in mesh

This commit is contained in:
Xiao Qi 2023-01-18 03:45:11 +08:00
parent 89338acbea
commit 5670f06046
2 changed files with 22 additions and 17 deletions

View File

@ -290,8 +290,6 @@ namespace SH_COMP
nodeStack.emplace(PairHelper(baseNode)); nodeStack.emplace(PairHelper(baseNode));
rig.root = nodeStack.top().first; rig.root = nodeStack.top().first;
rig.header.nodeCount++;
rig.header.charCounts.push_back(rig.root->name.length());
while(!nodeStack.empty()) while(!nodeStack.empty())
{ {
@ -300,14 +298,15 @@ namespace SH_COMP
auto currNode = currPair.first; auto currNode = currPair.first;
auto const& currAiNode = currPair.second; auto const& currAiNode = currPair.second;
int const iStart {static_cast<int>(currAiNode->mNumChildren - 1)}; int const iStart {static_cast<int>(currAiNode->mNumChildren - 1)};
rig.header.nodeCount++;
rig.header.charCounts.push_back(currNode->name.length());
for (int i {iStart}; i >= 0 ; --i) for (int i {iStart}; i >= 0 ; --i)
{ {
auto newPair = PairHelper(currAiNode->mChildren[i]); auto newPair = PairHelper(currAiNode->mChildren[i]);
currNode->children.push_back(newPair.first); currNode->children.push_back(newPair.first);
nodeStack.push(newPair); nodeStack.push(newPair);
rig.header.nodeCount++;
rig.header.charCounts.push_back(newPair.first->name.length());
} }
} }
} }

View File

@ -12,6 +12,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <stack> #include <stack>
#include <queue>
namespace SH_COMP namespace SH_COMP
{ {
@ -189,7 +190,6 @@ namespace SH_COMP
treeRoot->id = 0; treeRoot->id = 0;
treeRoot->children.clear(); treeRoot->children.clear();
nodeStack.emplace(std::make_pair(treeRoot, rig.root)); nodeStack.emplace(std::make_pair(treeRoot, rig.root));
dataToWrite.emplace_back(rig.root->name, rig.root->transform);
while(!nodeStack.empty()) while(!nodeStack.empty())
{ {
@ -198,15 +198,17 @@ namespace SH_COMP
auto currWriteNode = currPair.first; auto currWriteNode = currPair.first;
auto currDataNode = currPair.second; auto currDataNode = currPair.second;
for (int i {static_cast<int>(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 child = currDataNode->children[i];
auto newPair = std::make_pair(new RigWriteNode(), child); auto newPair = std::make_pair(new RigWriteNode(), child);
newPair.first->id = dataToWrite.size();
newPair.first->id = idCounter - i;
currWriteNode->children.push_back(newPair.first); currWriteNode->children.push_back(newPair.first);
nodeStack.push(newPair); nodeStack.push(newPair);
dataToWrite.emplace_back(child->name, child->transform);
} }
delete currDataNode; delete currDataNode;
@ -224,29 +226,33 @@ namespace SH_COMP
void MeshWriter::WriteRigTree(FileReference file, RigWriteNode const* root) void MeshWriter::WriteRigTree(FileReference file, RigWriteNode const* root)
{ {
std::stack<RigWriteNode const*> nodeStack; std::queue<RigWriteNode const*> nodeQueue;
nodeStack.push(root); nodeQueue.push(root);
while(!nodeStack.empty()) int ctr = 0;
while(!nodeQueue.empty())
{ {
auto node = nodeStack.top(); auto node = nodeQueue.front();
nodeStack.pop(); nodeQueue.pop();
file.write( file.write(
reinterpret_cast<char const*>(&node->id), reinterpret_cast<char const*>(&node->id),
sizeof(uint32_t) sizeof(uint32_t)
); );
uint32_t size = node->children.size(); uint32_t size = static_cast<uint32_t>(node->children.size());
file.write( file.write(
reinterpret_cast<char const*>(&size), reinterpret_cast<char const*>(&size),
sizeof(uint32_t) sizeof(uint32_t)
); );
std::cout << "Write Node: " << node->id << ", " << node->children.size() << std::endl;;
for (auto child : node->children) for (auto child : node->children)
{ {
nodeStack.push(child); nodeQueue.push(child);
} }
} }
} }