Covellite++  Version: 2.3.0 Revision: ??? Platform: x64 Build: 23:13 04.01.2025
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
Assimp.hpp
1
2#pragma once
3#include <glm/glm.force.hpp>
4#include <alicorn/std/string.hpp>
5#include <alicorn/std.fast/unordered-map.hpp>
6#include <alicorn/boost/filesystem.hpp>
7#include <assimp/importer.hpp>
8
9struct aiNode;
10struct aiMesh;
11struct aiVectorKey;
12struct aiQuatKey;
13
14namespace basement
15{
16
17namespace model
18{
19
20class Assimp final
21{
22 using Path_t = ::boost::filesystem::path;
23 using String_t = ::alicorn::extension::std::String;
24 using BoneLocals_t = ::alicorn::extension::std::fast::unordered_map<::std::string, aiMatrix4x4>;
25 using VertexWeight_t = ::std::pair<::std::string, float>;
26 using BoneWeights_t = ::std::map<unsigned int, ::std::vector<VertexWeight_t>>;
27
28public:
29 class Bone final
30 {
31 public:
32 ::std::string Name;
33 ::std::string ParentName;
34 ::glm::mat4 GlobalTransform;
35 ::glm::mat4 LocalTransform;
36 };
37
38 class Frames final
39 {
40 public:
41 using Keys_t = ::std::vector<::std::pair<float, ::glm::mat4>>;
42 ::std::string BoneName;
43 Keys_t Keys;
44 };
45
46 class Face final
47 {
48 class Vertex final
49 {
50 public:
51 uint64_t Hash = static_cast<uint64_t>(-1);
52 aiVector3D Position;
53 aiVector3D Normal;
54 aiVector3D TexCoords;
55 ::std::vector<VertexWeight_t> WeightBones;
56 };
57
58 public:
59 Vertex Vertexes[3];
60 String_t MaterialName;
61 };
62
63private:
64 using BoneListener_t = ::std::function<void(const Bone &)>;
65 using FrameListener_t = ::std::function<void(const Frames &)>;
66 using FaceListener_t = ::std::function<void(const Face &)>;
67
68public:
69 void LoadSkeleton(const BoneListener_t &);
70 void LoadGeometry(const FaceListener_t &);
71 float LoadAnimation(const FrameListener_t &);
72
73private:
74 static ::glm::mat4 aiMatrix4x4ToGlm(const aiMatrix4x4 &);
75 static const ::aiScene * LoadFile(const Path_t &, ::Assimp::Importer &);
76 static BoneLocals_t LoadBoneLocals(const aiScene * const);
77 static void LoadSkeleton(const BoneListener_t &, const BoneLocals_t &,
78 const aiNode * const, const ::glm::mat4 & = ::glm::mat4{ 1.0f });
79 static BoneWeights_t LoadBoneWeights(const aiMesh * const);
80 void LoadSkin(const FaceListener_t &, const aiScene *, const aiNode *);
81 static Frames::Keys_t BuildFrames(const ::std::vector<aiVectorKey> &,
82 const ::std::vector<aiQuatKey> &, const ::std::vector<aiVectorKey> &);
83
84private:
85 ::Assimp::Importer m_Importer;
86 const ::aiScene * m_pScene;
87
88public:
89 explicit Assimp(const Path_t &);
90};
91
92} // namespace model
93
94} // namespace basement
Definition Common.hpp:10