diff --git a/src/Libraries/MeshCompiler.cpp b/src/Libraries/MeshCompiler.cpp index d61c434..a047362 100644 --- a/src/Libraries/MeshCompiler.cpp +++ b/src/Libraries/MeshCompiler.cpp @@ -35,7 +35,7 @@ namespace SH_COMP if (std::strcmp(node.mName.C_Str(), "Armature") == 0) { - BuildArmature(&node, root); + BuildArmature(node, root); } else { @@ -243,14 +243,28 @@ namespace SH_COMP void MeshCompiler::BuildArmature(aiNode const& baseNode, RigNode*& root) noexcept { - std::queue nodes; - nodes.push(&baseNode); + RigNode* start = new RigNode(); - root = new RigNode(); - RigNode* parent = nullptr; - auto current = root; + CopyNode(baseNode, start); - //TODO Use CopyNode de recursive copy + root = start->children[0]; + } + + void MeshCompiler::CopyNode(aiNode const& source, RigNode* parent) noexcept + { + RigNode* current = new RigNode(); + current->name = source.mName.C_Str(); + std::memcpy(¤t->transform, &source.mTransformation, sizeof(float) * 16); + + for (auto i {0}; i < source.mNumChildren; ++i) + { + CopyNode(*source.mChildren[i], current); + } + + if (parent) + { + parent->children.push_back(current); + } } void MeshCompiler::LoadAndCompile(AssetPath path) noexcept diff --git a/src/Libraries/MeshCompiler.h b/src/Libraries/MeshCompiler.h index cf72b5f..8fa9c9a 100644 --- a/src/Libraries/MeshCompiler.h +++ b/src/Libraries/MeshCompiler.h @@ -42,7 +42,7 @@ namespace SH_COMP static void CompileMeshBinary(AssetPath path, MeshAsset const& asset) noexcept; static void BuildArmature(aiNode const& node, RigNode*& root) noexcept; - static void CopyNode(aiNode const& source, RigNode*& parent) noexcept; + static void CopyNode(aiNode const& source, RigNode* parent) noexcept; public: static void LoadAndCompile(AssetPath path) noexcept; };