Added abstraction for rig data and representation
WIP Building rig node collection to prepare for write
This commit is contained in:
parent
37a2edef14
commit
456167e9f0
|
@ -22,8 +22,9 @@ namespace SH_COMP
|
||||||
{
|
{
|
||||||
|
|
||||||
Assimp::Importer MeshCompiler::aiImporter;
|
Assimp::Importer MeshCompiler::aiImporter;
|
||||||
|
uint32_t MeshCompiler::rigNodeIDCounter { 0 };
|
||||||
|
|
||||||
void MeshCompiler::ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes, RigNode*& root) noexcept
|
void MeshCompiler::ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes, RigData& rig) noexcept
|
||||||
{
|
{
|
||||||
for (size_t i{ 0 }; i < node.mNumMeshes; ++i)
|
for (size_t i{ 0 }; i < node.mNumMeshes; ++i)
|
||||||
{
|
{
|
||||||
|
@ -35,38 +36,17 @@ namespace SH_COMP
|
||||||
|
|
||||||
if (std::strcmp(node.mName.C_Str(), "Armature") == 0)
|
if (std::strcmp(node.mName.C_Str(), "Armature") == 0)
|
||||||
{
|
{
|
||||||
BuildArmature(node, root);
|
BuildArmature(node, rig.root);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (size_t i{ 0 }; i < node.mNumChildren; ++i)
|
for (size_t i{ 0 }; i < node.mNumChildren; ++i)
|
||||||
{
|
{
|
||||||
ProcessNode(*node.mChildren[i], scene, meshes, root);
|
ProcessNode(*node.mChildren[i], scene, meshes, rig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void MeshCompiler::ExtractAnimations(aiScene const& scene, AnimVectorRef anims) noexcept
|
|
||||||
//{
|
|
||||||
// if (scene.HasAnimations())
|
|
||||||
// {
|
|
||||||
// std::vector<AnimationAsset> anims(scene.mNumAnimations);
|
|
||||||
// for (auto i{ 0 }; i < scene.mNumAnimations; ++i)
|
|
||||||
// {
|
|
||||||
// auto const& anim{ *scene.mAnimations[i] };
|
|
||||||
|
|
||||||
// anims[i].name = anim.mName.C_Str();
|
|
||||||
|
|
||||||
// anims[i].duration = anim.mDuration;
|
|
||||||
// anims[i].ticksPerSecond = anim.mTicksPerSecond;
|
|
||||||
|
|
||||||
// std::copy_n(anim.mChannels, anim.mNumChannels, anims[i].nodeChannels.data());
|
|
||||||
// std::copy_n(anim.mMeshChannels, anim.mNumMeshChannels, anims[i].meshChannels.data());
|
|
||||||
// std::copy_n(anim.mMorphMeshChannels, anim.mNumMorphMeshChannels, anims[i].morphMeshChannels.data());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void MeshCompiler::GetMesh(aiMesh const& mesh, MeshData& meshData) noexcept
|
void MeshCompiler::GetMesh(aiMesh const& mesh, MeshData& meshData) noexcept
|
||||||
{
|
{
|
||||||
meshData.vertexPosition.reserve(mesh.mNumVertices);
|
meshData.vertexPosition.reserve(mesh.mNumVertices);
|
||||||
|
@ -335,7 +315,6 @@ namespace SH_COMP
|
||||||
|
|
||||||
void MeshCompiler::ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept
|
void MeshCompiler::ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
// Size and read for number of animation clips
|
// Size and read for number of animation clips
|
||||||
anims.resize(scene.mNumAnimations);
|
anims.resize(scene.mNumAnimations);
|
||||||
for (auto i {0}; i < scene.mNumAnimations; ++i)
|
for (auto i {0}; i < scene.mNumAnimations; ++i)
|
||||||
|
@ -421,7 +400,7 @@ namespace SH_COMP
|
||||||
|
|
||||||
ParseAnimations(*scene, asset.anims);
|
ParseAnimations(*scene, asset.anims);
|
||||||
|
|
||||||
ProcessNode(*scene->mRootNode, *scene, asset.meshes, asset.rig.root);
|
ProcessNode(*scene->mRootNode, *scene, asset.meshes, asset.rig);
|
||||||
|
|
||||||
aiImporter.FreeScene();
|
aiImporter.FreeScene();
|
||||||
}
|
}
|
||||||
|
@ -449,29 +428,16 @@ namespace SH_COMP
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshCompiler::BuildArmature(aiNode const& baseNode, RigNode*& root) noexcept
|
void MeshCompiler::BuildArmature(aiNode const& baseNode, RigData& rig) noexcept
|
||||||
{
|
{
|
||||||
RigNode* start = new RigNode();
|
std::queue<aiNode const*> nodesQueue;
|
||||||
|
nodesQueue.push(&baseNode);
|
||||||
|
|
||||||
CopyNode(baseNode, start);
|
RigNode* parent = nullptr;
|
||||||
|
|
||||||
root = start->children[0];
|
while(!nodesQueue.empty())
|
||||||
}
|
|
||||||
|
|
||||||
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(SHMat4));
|
|
||||||
|
|
||||||
for (auto i {0}; i < source.mNumChildren; ++i)
|
|
||||||
{
|
|
||||||
CopyNode(*source.mChildren[i], current);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent)
|
|
||||||
{
|
|
||||||
parent->children.push_back(current);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,8 +445,6 @@ namespace SH_COMP
|
||||||
{
|
{
|
||||||
auto const asset = new ModelAsset();
|
auto const asset = new ModelAsset();
|
||||||
|
|
||||||
asset->rig.root = nullptr;
|
|
||||||
|
|
||||||
LoadFromFile(path, *asset);
|
LoadFromFile(path, *asset);
|
||||||
BuildHeaders(*asset);
|
BuildHeaders(*asset);
|
||||||
CompileMeshBinary(path, *asset);
|
CompileMeshBinary(path, *asset);
|
||||||
|
|
|
@ -33,9 +33,9 @@ namespace SH_COMP
|
||||||
using ModelRef = ModelAsset&;
|
using ModelRef = ModelAsset&;
|
||||||
|
|
||||||
static Assimp::Importer aiImporter;
|
static Assimp::Importer aiImporter;
|
||||||
|
static uint32_t rigNodeIDCounter;
|
||||||
|
|
||||||
static void ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes, RigNode*& root) noexcept;
|
static void ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes, RigData& rig) noexcept;
|
||||||
//static void ExtractAnimations(aiScene const& scene, AnimVectorRef anims) noexcept;
|
|
||||||
static void GetMesh(aiMesh const& mesh, MeshData& meshData) noexcept;
|
static void GetMesh(aiMesh const& mesh, MeshData& meshData) noexcept;
|
||||||
static void BuildHeaders(ModelRef asset) noexcept;
|
static void BuildHeaders(ModelRef asset) noexcept;
|
||||||
|
|
||||||
|
@ -52,8 +52,7 @@ namespace SH_COMP
|
||||||
static void LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
static void LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
||||||
static void CompileMeshBinary(AssetPath path, ModelConstRef asset) noexcept;
|
static void CompileMeshBinary(AssetPath path, ModelConstRef asset) noexcept;
|
||||||
|
|
||||||
static void BuildArmature(aiNode const& node, RigNode*& root) noexcept;
|
static void BuildArmature(aiNode const& node, RigData& rig) noexcept;
|
||||||
static void CopyNode(aiNode const& source, RigNode* parent) noexcept;
|
|
||||||
|
|
||||||
static void ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept;
|
static void ParseAnimations(aiScene const& scene, std::vector<AnimData>& anims) noexcept;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -13,25 +13,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "MeshAsset.h"
|
#include "MeshAsset.h"
|
||||||
#include "AnimationAsset.h"
|
#include "AnimationAsset.h"
|
||||||
|
#include "RigAsset.h"
|
||||||
|
|
||||||
namespace SH_COMP
|
namespace SH_COMP
|
||||||
{
|
{
|
||||||
struct RigNode
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
uint32_t id;
|
|
||||||
SHMat4 transform;
|
|
||||||
std::vector<RigNode*> children;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RigData
|
|
||||||
{
|
|
||||||
RigNode* root;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ModelAssetHeader
|
struct ModelAssetHeader
|
||||||
{
|
{
|
||||||
|
|
|
@ -1 +1,34 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "PseudoMath.h"
|
||||||
|
|
||||||
|
namespace SH_COMP
|
||||||
|
{
|
||||||
|
struct RigDataHeader
|
||||||
|
{
|
||||||
|
uint32_t nodeCount;
|
||||||
|
std::vector<uint32_t> charCounts;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RigNodeData
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
SHMat4 transform;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RigNode
|
||||||
|
{
|
||||||
|
uint32_t idRef;
|
||||||
|
std::vector<uint32_t> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RigData
|
||||||
|
{
|
||||||
|
std::map<uint32_t, RigNodeData> nodeDataCollection;
|
||||||
|
RigNode root;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue