AngryDude
 All Classes Namespaces Files Functions Variables Macros
Skinning.hpp
Go to the documentation of this file.
1 #ifndef __Skinning_hpp__
2 #define __Skinning_hpp__
3 
4 #include "NV/NvMath.h"
5 
6 #include <vector>
7 #include <string>
8 
9 struct Vertex
10 {
11  nv::vec3f position;
12  nv::vec3f normal;
13  nv::vec4f bones;
14  nv::vec2f uv;
15 };
16 
17 struct Mesh
18 {
19  std::vector<Vertex> vertices;
20  std::vector<unsigned short> indices;
21  std::string albedoTextureFilename;
22 };
23 
25 {
26  nv::vec4f value;
27  float time;
28 };
29 
31 {
32  std::vector<AnimationKey> translationKeys;
33  std::vector<AnimationKey> rotationKeys;
34 };
35 
36 struct ModelNode
37 {
38  std::string name;
39  std::vector<int> childrenIndices;
40  nv::matrix4f defaultTransform;
42  int boneIdx;
43 };
44 
45 struct Bone
46 {
47  nv::matrix4f offset;
48 };
49 
51 {
52  std::vector<Mesh> meshes;
53  std::vector<NodeAnimation> nodeAnimations;
54  std::vector<ModelNode> modelNodes;
55  std::vector<Bone> bones;
56 };
57 
58 
62 namespace cereal {
63 
64 template<class Archive> void serialize(Archive& archive, nv::vec2f& v)
65 {
66  archive(v.x, v.y);
67 }
68 
69 template<class Archive> void serialize(Archive& archive, nv::vec3f& v)
70 {
71  archive(v.x, v.y, v.z);
72 }
73 
74 template<class Archive> void serialize(Archive& archive, nv::vec4f& v)
75 {
76  archive(v.x, v.y, v.z, v.w);
77 }
78 
79 template<class Archive> void serialize(Archive& archive, nv::matrix4f& v)
80 {
81  archive(v._11, v._12, v._13, v._14,
82  v._21, v._22, v._23, v._24,
83  v._31, v._32, v._33, v._34,
84  v._41, v._42, v._43, v._44);
85 }
86 
87 template<class Archive> void serialize(Archive& archive, Vertex& v)
88 {
89  archive(v.position, v.normal, v.bones, v.uv);
90 }
91 
92 template<class Archive> void serialize(Archive& archive, Mesh& mesh)
93 {
94  archive(mesh.vertices, mesh.indices, mesh.albedoTextureFilename);
95 }
96 
97 template<class Archive> void serialize(Archive& archive, AnimationKey& key)
98 {
99  archive(key.value, key.time);
100 }
101 
102 template<class Archive> void serialize(Archive& archive, NodeAnimation& animation)
103 {
104  archive(animation.translationKeys, animation.rotationKeys);
105 }
106 
107 template<class Archive> void serialize(Archive& archive, ModelNode& node)
108 {
109  archive(node.name, node.childrenIndices, node.defaultTransform, node.nodeAnimationIdx, node.boneIdx);
110 }
111 
112 template<class Archive> void serialize(Archive& archive, Bone& bone)
113 {
114  archive(bone.offset);
115 }
116 
117 template<class Archive> void serialize(Archive& archive, SkinnedModel& model)
118 {
119  archive(model.meshes, model.nodeAnimations, model.modelNodes, model.bones);
120 }
121 
122 } // namespace cereal
123 
124 #endif
nv::matrix4f offset
Definition: Skinning.hpp:47
nv::vec2f uv
Definition: Skinning.hpp:14
nv::vec4f bones
Definition: Skinning.hpp:13
std::vector< Vertex > vertices
Definition: Skinning.hpp:19
std::vector< AnimationKey > translationKeys
Definition: Skinning.hpp:32
float time
Definition: Skinning.hpp:27
Definition: Skinning.hpp:45
std::vector< NodeAnimation > nodeAnimations
Definition: Skinning.hpp:53
nv::vec4f value
Definition: Skinning.hpp:26
Definition: Skinning.hpp:17
std::vector< ModelNode > modelNodes
Definition: Skinning.hpp:54
nv::matrix4f defaultTransform
Definition: Skinning.hpp:40
int boneIdx
Definition: Skinning.hpp:42
std::vector< Mesh > meshes
Definition: Skinning.hpp:52
Definition: Skinning.hpp:30
std::string albedoTextureFilename
Definition: Skinning.hpp:21
Definition: Skinning.hpp:9
nv::vec3f position
Definition: Skinning.hpp:11
std::vector< int > childrenIndices
Definition: Skinning.hpp:39
nv::vec3f normal
Definition: Skinning.hpp:12
std::vector< AnimationKey > rotationKeys
Definition: Skinning.hpp:33
std::vector< Bone > bones
Definition: Skinning.hpp:55
std::vector< unsigned short > indices
Definition: Skinning.hpp:20
int nodeAnimationIdx
Definition: Skinning.hpp:41
Definition: Skinning.hpp:50
void serialize(Archive &archive, nv::vec2f &v)
Definition: Skinning.hpp:64
Definition: Skinning.hpp:36
Definition: Skinning.hpp:24
std::string name
Definition: Skinning.hpp:38