-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
brfSkeleton.h
115 lines (86 loc) · 3.36 KB
/
brfSkeleton.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* OpenBRF -- by marco tarini. Provided under GNU General Public License */
#ifndef BRFSKELETON_H
#define BRFSKELETON_H
#include "brfToken.h"
#include <vcg/space/box3.h>
#include <vector>
namespace vcg{
template<typename T> class Matrix44;
template<typename T> class Point4;
}
class BrfBone
{
public:
BrfBone();
BrfBone(FILE *f, int verbose=0){
Load(f,verbose);
}
char name[255];
vcg::Point3f x,y,z,t;
// 56 bytes of data.... 3x4 matrix, 12 floats + int + int?
int attach,b;
bool Load(FILE*f,int verbose=0);
void Save(FILE*f) const;
void Export(FILE*f);
static bool Skip(FILE*f);
//void Adjust(); // adjust to new axis ordering...
vcg::Matrix44<float> getRotationMatrix() const;
void setRotationMatrix(vcg::Matrix44<float>);
std::vector<int> next;
};
class BrfAnimationFrame;
class BrfMesh;
class BrfBody;
class BrfSkeleton
{
public:
BrfSkeleton();
static int tokenIndex(){return SKELETON;}
char name[255];
unsigned int flags;
bool Load(FILE*f,int verbose=0);
void Save(FILE*f) const;
bool Skip(FILE*f);
std::vector<BrfBone> bone;
int root;
void BuildTree();
bool IsAnimable() const{return false;}
vcg::Box3f bbox;
bool SaveSMD(FILE *f) const;
bool LoadSMD(FILE *f);
std::vector<vcg::Matrix44<float> > GetBoneMatrices(const BrfAnimationFrame &fr) const;
std::vector<vcg::Matrix44<float> > GetBoneMatrices() const;
std::vector<vcg::Matrix44<float> > GetBoneMatricesInverse() const;
void BuildDefaultMesh(BrfMesh & output) const; // builds a mesh with just an octa x bone...
vcg::Matrix44<float> getRotationMatrix(int i) const {return bone[i].getRotationMatrix();}
void setRotationMatrix(vcg::Matrix44<float> m,int i) {bone[i].setRotationMatrix(m);}
// for translations and points:
static vcg::Point3f adjustCoordSyst(vcg::Point3f);
// for rotations (full):
static vcg::Point4f adjustCoordSyst(vcg::Point4f); // for quaternions
static BrfBone adjustCoordSyst(BrfBone);
static vcg::Matrix44f adjustCoordSyst(vcg::Matrix44f);
// for rotations (half):
static vcg::Point4f adjustCoordSystHalf(vcg::Point4f);
static BrfBone adjustCoordSystHalf(BrfBone);
static vcg::Matrix44f adjustCoordSystHalf(vcg::Matrix44f);
static float BoneSizeX();
static float BoneSizeY();
static float BoneSizeZ();
int FindBoneByName(const char* name) const;
int FindSpecularBoneOf(int bonei) const; /* judges by the name */
std::vector<int> Bone2BoneMap(const BrfSkeleton & s) const;
std::vector<vcg::Point4<float> > BoneRotations() const;
// layout hitboxes according to bones position (or does the inverse)
bool LayoutHitboxes(const BrfBody &in, BrfBody &out, bool inverse) const;
void Scale( float f );
private:
void Export(const char* f); // for intrnal use
void SetBoneMatrices(const BrfAnimationFrame &fr, int boneIndex,
std::vector<vcg::Matrix44<float> > &boneMatrV, const vcg::Matrix44<float> &curr) const;
void SetBoneMatrices(int boneIndex,
std::vector<vcg::Matrix44<float> > &boneMatrV, const vcg::Matrix44<float> &curr) const;
void SetBoneMatricesInverse(int boneIndex,
std::vector<vcg::Matrix44<float> > &boneMatrV, const vcg::Matrix44<float> &curr) const;
};
#endif // BRFSKELETON_H