Write tree into binary with BFS style traversing
This commit is contained in:
parent
c5f7b22515
commit
d03c12d1e2
|
@ -11,10 +11,10 @@
|
||||||
#include "MeshWriter.h"
|
#include "MeshWriter.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
namespace SH_COMP
|
namespace SH_COMP
|
||||||
{
|
{
|
||||||
|
|
||||||
void MeshWriter::WriteMeshHeader(std::ofstream& file, MeshDataHeader const& header)
|
void MeshWriter::WriteMeshHeader(std::ofstream& file, MeshDataHeader const& header)
|
||||||
{
|
{
|
||||||
file.write(
|
file.write(
|
||||||
|
@ -135,6 +135,64 @@ namespace SH_COMP
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshWriter::WriteRigHeader(FileReference file, RigDataHeader const& header)
|
||||||
|
{
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(header.nodeCount),
|
||||||
|
sizeof(uint32_t)
|
||||||
|
);
|
||||||
|
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(header.charCounts.data()),
|
||||||
|
sizeof(uint32_t) * header.nodeCount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshWriter::WriteRigData(FileReference file, RigDataHeader const& header,
|
||||||
|
std::map<uint32_t, RigNodeData> const& data)
|
||||||
|
{
|
||||||
|
for (auto i {0}; i < header.nodeCount; ++i)
|
||||||
|
{
|
||||||
|
file.write(
|
||||||
|
data.at(i).name.data(),
|
||||||
|
header.charCounts[i]
|
||||||
|
);
|
||||||
|
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(&data.at(i).transform),
|
||||||
|
sizeof(SHMat4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeshWriter::WriteRigNodes(FileReference file, RigDataHeader const& header, RigNode const* root)
|
||||||
|
{
|
||||||
|
std::queue<RigNode const*> nodeQueue;
|
||||||
|
nodeQueue.push(root);
|
||||||
|
|
||||||
|
while(!nodeQueue.empty())
|
||||||
|
{
|
||||||
|
auto const node = nodeQueue.front();
|
||||||
|
nodeQueue.pop();
|
||||||
|
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(&node->idRef),
|
||||||
|
sizeof(uint32_t)
|
||||||
|
);
|
||||||
|
|
||||||
|
uint32_t const size { static_cast<uint32_t>(node->children.size()) };
|
||||||
|
|
||||||
|
file.write(
|
||||||
|
reinterpret_cast<char const*>(&size),
|
||||||
|
sizeof(uint32_t)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (auto const& child : node->children)
|
||||||
|
{
|
||||||
|
nodeQueue.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MeshWriter::WriteHeaders(FileReference file, ModelConstRef asset)
|
void MeshWriter::WriteHeaders(FileReference file, ModelConstRef asset)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +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 WriteRigHeader(FileReference file, RigDataHeader const& header);
|
||||||
|
static void WriteRigData(FileReference file, RigDataHeader const& header, std::map<uint32_t, RigNodeData> const& data);
|
||||||
|
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);
|
||||||
static void WriteData(FileReference file, ModelConstRef asset);
|
static void WriteData(FileReference file, ModelConstRef asset);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue