WIP Ingestion of rig nodes from model file
This commit is contained in:
parent
457094dc50
commit
7777e5642b
Binary file not shown.
|
@ -16,12 +16,14 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
namespace SH_COMP
|
namespace SH_COMP
|
||||||
{
|
{
|
||||||
|
|
||||||
Assimp::Importer MeshCompiler::aiImporter;
|
Assimp::Importer MeshCompiler::aiImporter;
|
||||||
|
|
||||||
void MeshCompiler::ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes) noexcept
|
void MeshCompiler::ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes, RigNode*& root) noexcept
|
||||||
{
|
{
|
||||||
for (size_t i{ 0 }; i < node.mNumMeshes; ++i)
|
for (size_t i{ 0 }; i < node.mNumMeshes; ++i)
|
||||||
{
|
{
|
||||||
|
@ -31,9 +33,16 @@ namespace SH_COMP
|
||||||
meshes.back().name = node.mName.C_Str();
|
meshes.back().name = node.mName.C_Str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std::strcmp(node.mName.C_Str(), "Armature") == 0)
|
||||||
|
{
|
||||||
|
BuildArmature(&node, root);
|
||||||
|
}
|
||||||
|
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);
|
ProcessNode(*node.mChildren[i], scene, meshes, root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +74,12 @@ namespace SH_COMP
|
||||||
meshData.vertexTangent.reserve(mesh.mNumVertices);
|
meshData.vertexTangent.reserve(mesh.mNumVertices);
|
||||||
meshData.texCoords.reserve(mesh.mNumVertices);
|
meshData.texCoords.reserve(mesh.mNumVertices);
|
||||||
|
|
||||||
|
for (auto i {0}; i < mesh.mNumBones; ++i)
|
||||||
|
{
|
||||||
|
auto& bone = *mesh.mBones[i];
|
||||||
|
std::cout << "bone" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i{ 0 }; i < mesh.mNumVertices; ++i)
|
for (size_t i{ 0 }; i < mesh.mNumVertices; ++i)
|
||||||
{
|
{
|
||||||
// Vertex position
|
// Vertex position
|
||||||
|
@ -175,16 +190,16 @@ namespace SH_COMP
|
||||||
|
|
||||||
void MeshCompiler::LoadFromFile(AssetPath path, MeshAsset& asset) noexcept
|
void MeshCompiler::LoadFromFile(AssetPath path, MeshAsset& asset) noexcept
|
||||||
{
|
{
|
||||||
const aiScene* scene = aiImporter.ReadFile(path.string().c_str(),
|
const aiScene* scene = aiImporter.ReadFile(path.string().c_str(),0
|
||||||
aiProcess_Triangulate // Make sure we get triangles rather than nvert polygons
|
//aiProcess_Triangulate // Make sure we get triangles rather than nvert polygons
|
||||||
| aiProcess_GenUVCoords // Convert any type of mapping to uv mapping
|
//| aiProcess_GenUVCoords // Convert any type of mapping to uv mapping
|
||||||
| aiProcess_TransformUVCoords // preprocess UV transformations (scaling, translation ...)
|
//| aiProcess_TransformUVCoords // preprocess UV transformations (scaling, translation ...)
|
||||||
| aiProcess_FindInstances // search for instanced meshes and remove them by references to one master
|
//| aiProcess_FindInstances // search for instanced meshes and remove them by references to one master
|
||||||
| aiProcess_CalcTangentSpace // calculate tangents and bitangents if possible
|
//| aiProcess_CalcTangentSpace // calculate tangents and bitangents if possible
|
||||||
| aiProcess_JoinIdenticalVertices // join identical vertices/ optimize indexing
|
//| aiProcess_JoinIdenticalVertices // join identical vertices/ optimize indexing
|
||||||
| aiProcess_FindInvalidData // detect invalid model data, such as invalid normal vectors
|
//| aiProcess_FindInvalidData // detect invalid model data, such as invalid normal vectors
|
||||||
| aiProcess_FlipUVs // flip the V to match the Vulkans way of doing UVs
|
//| aiProcess_FlipUVs // flip the V to match the Vulkans way of doing UVs
|
||||||
| aiProcess_ValidateDataStructure
|
//| aiProcess_ValidateDataStructure
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!scene || !scene->HasMeshes())
|
if (!scene || !scene->HasMeshes())
|
||||||
|
@ -195,7 +210,7 @@ namespace SH_COMP
|
||||||
|
|
||||||
//ExtractAnimations(*scene, anims);
|
//ExtractAnimations(*scene, anims);
|
||||||
|
|
||||||
ProcessNode(*scene->mRootNode, *scene, asset.meshes);
|
ProcessNode(*scene->mRootNode, *scene, asset.meshes, asset.rig.root);
|
||||||
|
|
||||||
aiImporter.FreeScene();
|
aiImporter.FreeScene();
|
||||||
}
|
}
|
||||||
|
@ -226,10 +241,28 @@ namespace SH_COMP
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshCompiler::BuildArmature(aiNode const* node, RigNode*& root) noexcept
|
||||||
|
{
|
||||||
|
std::queue<aiNode const*> nodes;
|
||||||
|
nodes.push(node);
|
||||||
|
root = new RigNode();
|
||||||
|
auto current = root;
|
||||||
|
|
||||||
|
while(!nodes.empty())
|
||||||
|
{
|
||||||
|
auto node = nodes.front();
|
||||||
|
nodes.pop();
|
||||||
|
|
||||||
|
current->name = node->mName.C_Str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MeshCompiler::LoadAndCompile(AssetPath path) noexcept
|
void MeshCompiler::LoadAndCompile(AssetPath path) noexcept
|
||||||
{
|
{
|
||||||
auto const asset = new MeshAsset();
|
auto const asset = new MeshAsset();
|
||||||
|
|
||||||
|
asset->rig.root = nullptr;
|
||||||
|
|
||||||
LoadFromFile(path, *asset);
|
LoadFromFile(path, *asset);
|
||||||
BuildHeaders(*asset);
|
BuildHeaders(*asset);
|
||||||
CompileMeshBinary(path, *asset);
|
CompileMeshBinary(path, *asset);
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace SH_COMP
|
||||||
|
|
||||||
static Assimp::Importer aiImporter;
|
static Assimp::Importer aiImporter;
|
||||||
|
|
||||||
static void ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes) noexcept;
|
static void ProcessNode(aiNode const& node, aiScene const& scene, MeshVectorRef meshes, RigNode*& root) noexcept;
|
||||||
static void ExtractAnimations(aiScene const& scene, AnimVectorRef anims) 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(MeshAsset& asset) noexcept;
|
static void BuildHeaders(MeshAsset& asset) noexcept;
|
||||||
|
@ -41,6 +41,7 @@ namespace SH_COMP
|
||||||
static void LoadFromFile(AssetPath path, MeshAsset& asset) noexcept;
|
static void LoadFromFile(AssetPath path, MeshAsset& asset) noexcept;
|
||||||
static void CompileMeshBinary(AssetPath path, MeshAsset const& asset) noexcept;
|
static void CompileMeshBinary(AssetPath path, MeshAsset const& asset) noexcept;
|
||||||
|
|
||||||
|
static void BuildArmature(aiNode const* node, RigNode*& root) noexcept;
|
||||||
public:
|
public:
|
||||||
static void LoadAndCompile(AssetPath path) noexcept;
|
static void LoadAndCompile(AssetPath path) noexcept;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,11 @@ namespace SH_COMP
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SHMat4
|
||||||
|
{
|
||||||
|
float data[16];
|
||||||
|
};
|
||||||
|
|
||||||
struct MeshDataHeader
|
struct MeshDataHeader
|
||||||
{
|
{
|
||||||
uint32_t vertexCount;
|
uint32_t vertexCount;
|
||||||
|
@ -45,6 +50,18 @@ namespace SH_COMP
|
||||||
std::vector<uint32_t> indices;
|
std::vector<uint32_t> indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RigNode
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
SHMat4 transform;
|
||||||
|
std::vector<RigNode*> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RigData
|
||||||
|
{
|
||||||
|
RigNode* root;
|
||||||
|
};
|
||||||
|
|
||||||
struct MeshAssetHeader
|
struct MeshAssetHeader
|
||||||
{
|
{
|
||||||
size_t meshCount;
|
size_t meshCount;
|
||||||
|
@ -53,6 +70,7 @@ namespace SH_COMP
|
||||||
struct MeshAsset
|
struct MeshAsset
|
||||||
{
|
{
|
||||||
MeshAssetHeader header;
|
MeshAssetHeader header;
|
||||||
|
RigData rig;
|
||||||
std::vector<MeshDataHeader> headers;
|
std::vector<MeshDataHeader> headers;
|
||||||
std::vector<MeshData> meshes;
|
std::vector<MeshData> meshes;
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,7 +53,7 @@ int main(int argc, char* argv[])
|
||||||
// SH_COMP::MeshCompiler::LoadAndCompile(path);
|
// SH_COMP::MeshCompiler::LoadAndCompile(path);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
SH_COMP::MeshCompiler::LoadAndCompile("Racoon.gltf");
|
SH_COMP::MeshCompiler::LoadAndCompile("Racoon.fbx");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue