Finished Writing rig to file
This commit is contained in:
parent
abd3f2dd53
commit
d54222e2cf
|
@ -289,6 +289,8 @@ namespace SH_COMP
|
||||||
|
|
||||||
nodeQueue.emplace(PairHelper(baseNode));
|
nodeQueue.emplace(PairHelper(baseNode));
|
||||||
rig.root = nodeQueue.front().first;
|
rig.root = nodeQueue.front().first;
|
||||||
|
rig.header.nodeCount++;
|
||||||
|
rig.header.charCounts.push_back(rig.root->name.length());
|
||||||
|
|
||||||
while(!nodeQueue.empty())
|
while(!nodeQueue.empty())
|
||||||
{
|
{
|
||||||
|
@ -302,6 +304,9 @@ namespace SH_COMP
|
||||||
auto newPair = PairHelper(currAiNode->mChildren[i]);
|
auto newPair = PairHelper(currAiNode->mChildren[i]);
|
||||||
currNode->children.push_back(newPair.first);
|
currNode->children.push_back(newPair.first);
|
||||||
nodeQueue.push(newPair);
|
nodeQueue.push(newPair);
|
||||||
|
|
||||||
|
rig.header.nodeCount++;
|
||||||
|
rig.header.charCounts.push_back(newPair.first->name.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,10 +135,18 @@ namespace SH_COMP
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshWriter::WriteRig(FileReference file, RigData const& data)
|
||||||
|
{
|
||||||
|
WriteRigHeader(file, data.header);
|
||||||
|
RigWriteNode* root {nullptr};
|
||||||
|
WriteRigNodeData(file, data,root);
|
||||||
|
WriteRigTree(file, root);
|
||||||
|
}
|
||||||
|
|
||||||
void MeshWriter::WriteRigHeader(FileReference file, RigDataHeader const& header)
|
void MeshWriter::WriteRigHeader(FileReference file, RigDataHeader const& header)
|
||||||
{
|
{
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(header.nodeCount),
|
reinterpret_cast<char const*>(&header.nodeCount),
|
||||||
sizeof(uint32_t)
|
sizeof(uint32_t)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -148,46 +156,74 @@ namespace SH_COMP
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshWriter::WriteRigData(FileReference file, RigDataHeader const& header,
|
void MeshWriter::WriteRigNodeData(FileReference file, RigData const& rig, RigWriteNode*& treeRoot)
|
||||||
RigData const& data)
|
|
||||||
{
|
{
|
||||||
for (auto i {0}; i < header.nodeCount; ++i)
|
// Build node collection and assign ID to each node BFS STYLE
|
||||||
{
|
// Build tree of nodes using ID
|
||||||
file.write(
|
|
||||||
data.at(i).name.data(),
|
|
||||||
header.charCounts[i]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
std::vector<RigNodeDataWrite> dataToWrite;
|
||||||
|
dataToWrite.reserve(rig.header.nodeCount);
|
||||||
|
|
||||||
|
std::queue<std::pair<RigWriteNode*, RigNodeData*>> nodeQueue;
|
||||||
|
treeRoot = new RigWriteNode;
|
||||||
|
treeRoot->id = 0;
|
||||||
|
treeRoot->children.clear();
|
||||||
|
nodeQueue.emplace(std::make_pair(treeRoot, rig.root));
|
||||||
|
dataToWrite.emplace_back(rig.root->name, rig.root->transform);
|
||||||
|
|
||||||
|
while(!nodeQueue.empty())
|
||||||
|
{
|
||||||
|
auto currPair = nodeQueue.front();
|
||||||
|
nodeQueue.pop();
|
||||||
|
auto currWriteNode = currPair.first;
|
||||||
|
auto currDataNode = currPair.second;
|
||||||
|
|
||||||
|
for (auto child : currDataNode->children)
|
||||||
|
{
|
||||||
|
auto newPair = std::make_pair(new RigWriteNode(), child);
|
||||||
|
newPair.first->id = dataToWrite.size();
|
||||||
|
currWriteNode->children.push_back(newPair.first);
|
||||||
|
nodeQueue.push(newPair);
|
||||||
|
|
||||||
|
dataToWrite.emplace_back(child->name, child->transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete currDataNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto const& data : dataToWrite)
|
||||||
|
{
|
||||||
|
file.write(data.name.c_str(), data.name.size());
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(&data.at(i).transform),
|
reinterpret_cast<char const*>(&data.transform),
|
||||||
sizeof(SHMat4)
|
sizeof(SHMat4)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshWriter::WriteRigNodes(FileReference file, RigDataHeader const& header, RigNode const* root)
|
void MeshWriter::WriteRigTree(FileReference file, RigWriteNode const* root)
|
||||||
{
|
{
|
||||||
std::queue<RigNode const*> nodeQueue;
|
std::queue<RigWriteNode const*> nodeQueue;
|
||||||
nodeQueue.push(root);
|
nodeQueue.push(root);
|
||||||
|
|
||||||
while(!nodeQueue.empty())
|
while(!nodeQueue.empty())
|
||||||
{
|
{
|
||||||
auto const node = nodeQueue.front();
|
auto node = nodeQueue.front();
|
||||||
nodeQueue.pop();
|
nodeQueue.pop();
|
||||||
|
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(&node->idRef),
|
reinterpret_cast<char const*>(&node->id),
|
||||||
sizeof(uint32_t)
|
sizeof(uint32_t)
|
||||||
);
|
);
|
||||||
|
|
||||||
uint32_t const size { static_cast<uint32_t>(node->children.size()) };
|
uint32_t size = node->children.size();
|
||||||
|
|
||||||
file.write(
|
file.write(
|
||||||
reinterpret_cast<char const*>(&size),
|
reinterpret_cast<char const*>(&size),
|
||||||
sizeof(uint32_t)
|
sizeof(uint32_t)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (auto const& child : node->children)
|
for (auto child : node->children)
|
||||||
{
|
{
|
||||||
nodeQueue.push(child);
|
nodeQueue.push(child);
|
||||||
}
|
}
|
||||||
|
@ -239,6 +275,7 @@ namespace SH_COMP
|
||||||
|
|
||||||
WriteHeaders(file, asset);
|
WriteHeaders(file, asset);
|
||||||
WriteData(file, asset);
|
WriteData(file, asset);
|
||||||
|
WriteRig(file, asset.rig);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,10 @@ namespace SH_COMP
|
||||||
static void WriteAnimData(FileReference file, AnimDataHeader const& header, AnimData const& data);
|
static void WriteAnimData(FileReference file, AnimDataHeader const& header, AnimData const& data);
|
||||||
static void WriteAnimNode(FileReference file, AnimNodeInfo const& info, AnimNode const& node);
|
static void WriteAnimNode(FileReference file, AnimNodeInfo const& info, AnimNode const& node);
|
||||||
|
|
||||||
|
static void WriteRig(FileReference file, RigData const& data);
|
||||||
static void WriteRigHeader(FileReference file, RigDataHeader const& header);
|
static void WriteRigHeader(FileReference file, RigDataHeader const& header);
|
||||||
static void WriteRigData(FileReference file, RigDataHeader const& header, RigData const& data);
|
static void WriteRigNodeData(FileReference file, RigData const& rig, RigWriteNode*& treeRoot);
|
||||||
|
static void WriteRigTree(FileReference file, RigWriteNode const* root);
|
||||||
//static void WriteRigNodes(FileReference file, RigDataHeader const& header, RigNode const* root);
|
//static void WriteRigNodes(FileReference file, RigDataHeader const& header, RigNode const* root);
|
||||||
|
|
||||||
static void WriteHeaders(FileReference file, ModelConstRef asset);
|
static void WriteHeaders(FileReference file, ModelConstRef asset);
|
||||||
|
|
|
@ -24,6 +24,18 @@ namespace SH_COMP
|
||||||
std::vector<RigNodeData*> children;
|
std::vector<RigNodeData*> children;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RigNodeDataWrite
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
SHMat4 transform;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RigWriteNode
|
||||||
|
{
|
||||||
|
uint32_t id;
|
||||||
|
std::vector<RigWriteNode*> children;
|
||||||
|
};
|
||||||
|
|
||||||
struct RigData
|
struct RigData
|
||||||
{
|
{
|
||||||
RigDataHeader header;
|
RigDataHeader header;
|
||||||
|
|
Loading…
Reference in New Issue