-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex.h
50 lines (44 loc) · 1.42 KB
/
vertex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <fstream>
namespace graphics
{
struct vertex
{
glm::vec3 pos;
glm::vec3 normal;
glm::vec2 uv;
// limit to 4 bones per vertex
int bone_ids[4] = {};
float bone_weights[4] = {};
void serialise(std::ofstream& out)
{
out.write((char*)glm::value_ptr(pos), sizeof(glm::vec3));
out.write((char*)glm::value_ptr(normal), sizeof(glm::vec3));
out.write((char*)glm::value_ptr(uv), sizeof(glm::vec2));
out.write((char*)bone_ids, sizeof(bone_ids));
out.write((char*)bone_weights, sizeof(bone_weights));
}
void deserialise(std::ifstream& in)
{
in.read((char*)glm::value_ptr(pos),sizeof(glm::vec3));
in.read((char*)glm::value_ptr(normal),sizeof(glm::vec3));
in.read((char*)glm::value_ptr(uv),sizeof(glm::vec2));
in.read((char*)bone_ids, sizeof(bone_ids));
in.read((char*)bone_weights, sizeof(bone_weights));
}
};
struct bone
{
glm::mat4 offset_matrix;
void serialise(std::ofstream& out)
{
out.write((char*)glm::value_ptr(offset_matrix), sizeof(glm::mat4));
}
void deserialise(std::ifstream& in)
{
in.read((char*)glm::value_ptr(offset_matrix), sizeof(glm::mat4));
}
};
}