3
3
4
4
#include " Bone.hpp"
5
5
6
- #define BONE_VERSION 0x0002
6
+ #define BONE_VERSION 0x0002
7
7
// ------------------------------------------------------------------------------
8
- #define BONE_CHUNK_VERSION 0x0001
9
- #define BONE_CHUNK_DEF 0x0002
10
- #define BONE_CHUNK_BIND_POSE 0x0003
11
- #define BONE_CHUNK_MATERIAL 0x0004
12
- #define BONE_CHUNK_SHAPE 0x0005
13
- #define BONE_CHUNK_IK_JOINT 0x0006
14
- #define BONE_CHUNK_MASS 0x0007
15
- #define BONE_CHUNK_FLAGS 0x0008
16
- #define BONE_CHUNK_IK_JOINT_BREAK 0x0009
17
- #define BONE_CHUNK_IK_JOINT_FRICTION 0x0010
18
-
8
+ #define BONE_CHUNK_VERSION 0x0001
9
+ #define BONE_CHUNK_DEF 0x0002
10
+ #define BONE_CHUNK_BIND_POSE 0x0003
11
+ #define BONE_CHUNK_MATERIAL 0x0004
12
+ #define BONE_CHUNK_SHAPE 0x0005
13
+ #define BONE_CHUNK_IK_JOINT 0x0006
14
+ #define BONE_CHUNK_MASS 0x0007
15
+ #define BONE_CHUNK_FLAGS 0x0008
16
+ #define BONE_CHUNK_IK_JOINT_BREAK 0x0009
17
+ #define BONE_CHUNK_IK_JOINT_FRICTION 0x0010
19
18
20
19
static const Fobb dummy = Fobb().identity();
21
20
@@ -27,12 +26,12 @@ const Fobb& CBone::get_obb() const
27
26
CBone::CBone ()
28
27
{
29
28
construct ();
30
- flags.zero ();
31
- rest_length = 0 ;
32
- SelfID = -1 ;
33
- parent = 0 ;
29
+ flags.zero ();
30
+ rest_length = 0 ;
31
+ SelfID = -1 ;
32
+ parent = 0 ;
34
33
35
- ResetData ();
34
+ ResetData ();
36
35
}
37
36
38
37
CBone::~CBone ()
@@ -41,153 +40,156 @@ CBone::~CBone()
41
40
42
41
void CBone::ResetData ()
43
42
{
44
- IK_data.Reset ();
45
- game_mtl = " default_object" ;
46
- shape.Reset ();
43
+ IK_data.Reset ();
44
+ game_mtl = " default_object" ;
45
+ shape.Reset ();
47
46
48
- mass = 10 .f ;;
49
- center_of_mass.set (0 .f ,0 .f ,0 .f );
47
+ mass = 10 .f ;
48
+ ;
49
+ center_of_mass.set (0 .f , 0 .f , 0 .f );
50
50
}
51
51
52
52
void CBone::Save (IWriter& F)
53
53
{
54
- F.open_chunk (BONE_CHUNK_VERSION);
55
- F.w_u16 (BONE_VERSION);
56
- F.close_chunk ();
57
-
58
- F.open_chunk (BONE_CHUNK_DEF);
59
- F.w_stringZ (name);
60
- F.w_stringZ (parent_name);
61
- F.w_stringZ (wmap);
62
- F.close_chunk ();
63
-
64
- F.open_chunk (BONE_CHUNK_BIND_POSE);
65
- F.w_fvector3 (rest_offset);
66
- F.w_fvector3 (rest_rotate);
67
- F.w_float (rest_length);
68
- F.close_chunk ();
69
-
70
- SaveData (F);
54
+ F.open_chunk (BONE_CHUNK_VERSION);
55
+ F.w_u16 (BONE_VERSION);
56
+ F.close_chunk ();
57
+
58
+ F.open_chunk (BONE_CHUNK_DEF);
59
+ F.w_stringZ (name);
60
+ F.w_stringZ (parent_name);
61
+ F.w_stringZ (wmap);
62
+ F.close_chunk ();
63
+
64
+ F.open_chunk (BONE_CHUNK_BIND_POSE);
65
+ F.w_fvector3 (rest_offset);
66
+ F.w_fvector3 (rest_rotate);
67
+ F.w_float (rest_length);
68
+ F.close_chunk ();
69
+
70
+ SaveData (F);
71
71
}
72
72
73
73
void CBone::Load_0 (IReader& F)
74
74
{
75
- F.r_stringZ (name); xr_strlwr (name);
76
- F.r_stringZ (parent_name); xr_strlwr (parent_name);
77
- F.r_stringZ (wmap);
78
- F.r_fvector3 (rest_offset);
79
- F.r_fvector3 (rest_rotate);
80
- rest_length = F.r_float ();
81
- std::swap (rest_rotate.x ,rest_rotate.y );
82
- Reset ();
75
+ F.r_stringZ (name);
76
+ xr_strlwr (name);
77
+ F.r_stringZ (parent_name);
78
+ xr_strlwr (parent_name);
79
+ F.r_stringZ (wmap);
80
+ F.r_fvector3 (rest_offset);
81
+ F.r_fvector3 (rest_rotate);
82
+ rest_length = F.r_float ();
83
+ std::swap (rest_rotate.x , rest_rotate.y );
84
+ Reset ();
83
85
}
84
86
85
87
void CBone::Load_1 (IReader& F)
86
88
{
87
89
R_ASSERT (F.find_chunk (BONE_CHUNK_VERSION));
88
- u16 ver = F.r_u16 ();
90
+ u16 ver = F.r_u16 ();
91
+
92
+ if ((ver != 0x0001 ) && (ver != BONE_VERSION)) return ;
89
93
90
- if ((ver!=0x0001 )&&(ver!=BONE_VERSION))
91
- return ;
92
-
93
94
R_ASSERT (F.find_chunk (BONE_CHUNK_DEF));
94
- F.r_stringZ (name); xr_strlwr (name);
95
- F.r_stringZ (parent_name); xr_strlwr (parent_name);
96
- F.r_stringZ (wmap);
95
+ F.r_stringZ (name);
96
+ xr_strlwr (name);
97
+ F.r_stringZ (parent_name);
98
+ xr_strlwr (parent_name);
99
+ F.r_stringZ (wmap);
97
100
98
101
R_ASSERT (F.find_chunk (BONE_CHUNK_BIND_POSE));
99
- F.r_fvector3 (rest_offset);
100
- F.r_fvector3 (rest_rotate);
101
- rest_length = F.r_float ();
102
-
103
- if (ver==0x0001 )
104
- std::swap (rest_rotate.x ,rest_rotate.y );
105
-
106
- LoadData (F);
102
+ F.r_fvector3 (rest_offset);
103
+ F.r_fvector3 (rest_rotate);
104
+ rest_length = F.r_float ();
105
+
106
+ if (ver == 0x0001 ) std::swap (rest_rotate.x , rest_rotate.y );
107
+
108
+ LoadData (F);
107
109
}
108
110
109
111
void CBone::SaveData (IWriter& F)
110
112
{
111
- F.open_chunk (BONE_CHUNK_DEF);
112
- F.w_stringZ (name);
113
- F.close_chunk ();
114
-
115
- F.open_chunk (BONE_CHUNK_MATERIAL);
116
- F.w_stringZ (game_mtl);
117
- F.close_chunk ();
118
-
119
- F.open_chunk (BONE_CHUNK_SHAPE);
120
- F.w (&shape,sizeof (SBoneShape));
121
- F.close_chunk ();
122
-
123
- F.open_chunk (BONE_CHUNK_FLAGS);
124
- F.w_u32 (IK_data.ik_flags .get ());
125
- F.close_chunk ();
126
-
127
- F.open_chunk (BONE_CHUNK_IK_JOINT);
128
- F.w_u32 (IK_data.type );
129
- F.w (IK_data.limits ,sizeof (SJointLimit)* 3 );
130
- F.w_float (IK_data.spring_factor );
131
- F.w_float (IK_data.damping_factor );
132
- F.close_chunk ();
133
-
134
- F.open_chunk (BONE_CHUNK_IK_JOINT_BREAK);
135
- F.w_float (IK_data.break_force );
136
- F.w_float (IK_data.break_torque );
137
- F.close_chunk ();
138
-
139
- F.open_chunk (BONE_CHUNK_IK_JOINT_FRICTION);
140
- F.w_float (IK_data.friction );
141
- F.close_chunk ();
142
-
143
- F.open_chunk (BONE_CHUNK_MASS);
144
- F.w_float (mass);
145
- F.w_fvector3 (center_of_mass);
146
- F.close_chunk ();
113
+ F.open_chunk (BONE_CHUNK_DEF);
114
+ F.w_stringZ (name);
115
+ F.close_chunk ();
116
+
117
+ F.open_chunk (BONE_CHUNK_MATERIAL);
118
+ F.w_stringZ (game_mtl);
119
+ F.close_chunk ();
120
+
121
+ F.open_chunk (BONE_CHUNK_SHAPE);
122
+ F.w (&shape, sizeof (SBoneShape));
123
+ F.close_chunk ();
124
+
125
+ F.open_chunk (BONE_CHUNK_FLAGS);
126
+ F.w_u32 (IK_data.ik_flags .get ());
127
+ F.close_chunk ();
128
+
129
+ F.open_chunk (BONE_CHUNK_IK_JOINT);
130
+ F.w_u32 (IK_data.type );
131
+ F.w (IK_data.limits , sizeof (SJointLimit) * 3 );
132
+ F.w_float (IK_data.spring_factor );
133
+ F.w_float (IK_data.damping_factor );
134
+ F.close_chunk ();
135
+
136
+ F.open_chunk (BONE_CHUNK_IK_JOINT_BREAK);
137
+ F.w_float (IK_data.break_force );
138
+ F.w_float (IK_data.break_torque );
139
+ F.close_chunk ();
140
+
141
+ F.open_chunk (BONE_CHUNK_IK_JOINT_FRICTION);
142
+ F.w_float (IK_data.friction );
143
+ F.close_chunk ();
144
+
145
+ F.open_chunk (BONE_CHUNK_MASS);
146
+ F.w_float (mass);
147
+ F.w_fvector3 (center_of_mass);
148
+ F.close_chunk ();
147
149
}
148
150
149
151
void CBone::LoadData (IReader& F)
150
152
{
151
153
R_ASSERT (F.find_chunk (BONE_CHUNK_DEF));
152
- F.r_stringZ (name); xr_strlwr (name);
154
+ F.r_stringZ (name);
155
+ xr_strlwr (name);
153
156
154
157
R_ASSERT (F.find_chunk (BONE_CHUNK_MATERIAL));
155
- F.r_stringZ (game_mtl);
158
+ F.r_stringZ (game_mtl);
156
159
157
160
R_ASSERT (F.find_chunk (BONE_CHUNK_SHAPE));
158
- F.r (&shape,sizeof (SBoneShape));
159
-
160
- if (F.find_chunk (BONE_CHUNK_FLAGS))
161
- IK_data.ik_flags .assign (F.r_u32 ());
161
+ F.r (&shape, sizeof (SBoneShape));
162
+
163
+ if (F.find_chunk (BONE_CHUNK_FLAGS)) IK_data.ik_flags .assign (F.r_u32 ());
162
164
163
165
R_ASSERT (F.find_chunk (BONE_CHUNK_IK_JOINT));
164
- IK_data.type = (EJointType)F.r_u32 ();
165
- F.r (IK_data.limits ,sizeof (SJointLimit)* 3 );
166
- IK_data.spring_factor = F.r_float ();
167
- IK_data.damping_factor = F.r_float ();
166
+ IK_data.type = (EJointType)F.r_u32 ();
167
+ F.r (IK_data.limits , sizeof (SJointLimit) * 3 );
168
+ IK_data.spring_factor = F.r_float ();
169
+ IK_data.damping_factor = F.r_float ();
168
170
169
- if (F.find_chunk (BONE_CHUNK_IK_JOINT_BREAK)){
171
+ if (F.find_chunk (BONE_CHUNK_IK_JOINT_BREAK)) {
170
172
IK_data.break_force = F.r_float ();
171
- IK_data.break_torque = F.r_float ();
173
+ IK_data.break_torque = F.r_float ();
172
174
}
173
175
174
- if (F.find_chunk (BONE_CHUNK_IK_JOINT_FRICTION)){
175
- IK_data.friction = F.r_float ();
176
+ if (F.find_chunk (BONE_CHUNK_IK_JOINT_FRICTION)) {
177
+ IK_data.friction = F.r_float ();
176
178
}
177
179
178
- if (F.find_chunk (BONE_CHUNK_MASS)){
179
- mass = F.r_float ();
180
+ if (F.find_chunk (BONE_CHUNK_MASS)) {
181
+ mass = F.r_float ();
180
182
F.r_fvector3 (center_of_mass);
181
183
}
182
184
}
183
185
184
186
void CBone::CopyData (CBone* bone)
185
187
{
186
- game_mtl = bone->game_mtl ;
187
- shape = bone->shape ;
188
- IK_data = bone->IK_data ;
189
- mass = bone->mass ;
190
- center_of_mass = bone->center_of_mass ;
188
+ game_mtl = bone->game_mtl ;
189
+ shape = bone->shape ;
190
+ IK_data = bone->IK_data ;
191
+ mass = bone->mass ;
192
+ center_of_mass = bone->center_of_mass ;
191
193
}
192
194
193
195
void CBoneInstance::set_param (u32 idx, float data)
0 commit comments