root/trunk/libx42/include/x42data.h

Revision 471, 8.8 kB (checked in by phill, 1 year ago)

o Fixed retarded buffer overflow.

Line 
1 /******************************************************************************
2         libx42 - skinned vertex animation library
3         Copyright (C) 2007 HermitWorks Entertainment Corporation
4
5         This program is free software; you can redistribute it and/or modify it
6         under the terms of the GNU General Public License as published by the Free
7         Software Foundation; either version 2 of the License, or (at your option)
8         any later version.
9
10         This program is distributed in the hope that it will be useful, but
11         WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12         or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13         for more details.
14
15         You should have received a copy of the GNU General Public License along
16         with this program; if not, write to the
17        
18                 Free Software Foundation, Inc.
19                 51 Franklin Street, Fifth Floor
20                 Boston, MA  02110-1301, USA.
21 ******************************************************************************/
22
23 #ifndef INC_LIBX42_X42DATA_H
24 #define INC_LIBX42_X42DATA_H
25
26 /*
27         x42 file format
28 */
29
30 typedef signed char                             s8;
31 typedef unsigned char                   u8;             //sized types, adjust on other systems!
32 typedef signed short int                s16;
33 typedef unsigned short int              u16;
34 typedef unsigned int                    u32;
35
36 typedef u16 x42NameIndex_t;     //index of the first char of a null-terminated string in the strings blob
37 typedef u16 x42Index_t;
38
39 typedef float                                   f32;
40
41 typedef f32 vec2_t[2];
42 typedef f32 vec3_t[3];
43 typedef f32 vec4_t[4];
44 typedef f32 quat_t[4]; //i, j, k, real
45
46 /*
47         affine_t: an affine 3x4 matrix.
48         Values are stored in column-major order.
49 */
50 typedef struct affine_t
51 {
52         f32 c[4][3];
53 } affine_t;
54
55 typedef u8 rgba_t[4];
56
57 typedef struct shpere_t
58 {
59         vec3_t          center;
60         f32                     radius;
61 } sphere_t;
62
63 typedef struct aabb_t
64 {
65         vec3_t          mins;
66         vec3_t          maxs;
67 } aabb_t;
68
69 #define X42_FLOAT_S16N_PACK( x ) ((s16)((float)(x) * 32767.0F))
70 #define X42_FLOAT_S16N_UNPACK( x ) ((float)(int)(x) * (1.0F / 32767.0F))
71
72 #define X42_FLOAT_S8N_PACK( x ) ((s8)((float)(x) * 127.0F))
73 #define X42_FLOAT_S8N_UNPACK( x ) ((float)(int)(x) * (1.0F / 127.0F))
74 #define X42_FLOAT_U8N_PACK( x ) ((u8)((float)(x) * 255.0F))
75 #define X42_FLOAT_U8N_UNPACK( x ) ((float)(int)(x) * (1.0F / 255.0F))
76
77 #define X42_IDENT                                               (('2' << 24) | ('4' << 16) | ('W' << 8) | 'H')
78
79 //supported versions
80 #define X42_VER_V5                                              101             //big increment in case anyone ever has to do a 4* for some unknown reason
81
82 #define X42_CURRENT_VERSION                             X42_VER_V5
83
84 #define X42_WEIGHTS_PER_VERT                    4
85
86 #define X42_MF_HAS_NORMALS                              0x0001
87 #define X42_MF_HAS_TANGENT_BASIS                0x0002
88 #define X42_MF_HAS_TEXTURE_COORDINATES  0x0004
89 #define X42_MF_HAS_COLORS                               0x0008
90 #define X42_MF_HAS_ALL_DATA                             0x000F          //shorthand for all of the above
91 #define X42_MF_UNIFORM_SCALE                    0x0100
92
93 typedef struct x42Header_ident_t
94 {
95         u32                     ident;                          //must be X42_IDENT
96         u32                     version;                        //must be X42_VER_Vx (see above for valid values)
97 } x42Header_ident_t;
98
99 typedef struct x42Header_v5_t
100 {
101         u16                     modelFlags;                     //one or more X42_MF_* values
102        
103         s16                     baseFrame;                      //zero if numFrames is zero
104         u16                     numFrames;                      //may be zero
105
106         u16                     nameBlobLen;            //may be zero
107
108         u16                     numBones;                       //may be zero
109         u16                     numAnimGroups;          //zero if numBones is zero, else must be at least 1
110
111         u16                     numPosValues;           //may be zero
112         u16                     numRotValues;           //may be zero
113         u16                     numScaleValues;         //may be zero
114
115         u16                     keyStreamLength;        //may be zero
116         u16                     numAnims;                       //may be zero
117
118         u16                     numTags;                        //may be zero
119         u16                     numInfluences;          //may be zero
120
121         u16                     numLods;                        //may be zero iff numGroups is zero
122         u16                     numGroups;                      //may be zero
123
124         u32                     numVerts;                       //may be zero iff numGroups is zero
125         u32                     numIndices;                     //may be zero
126
127         aabb_t          boundingBox;
128         sphere_t        boundingSphere;
129 } x42Header_v5_t;
130
131 typedef struct x42PackHeader_v5_t
132 {
133         vec2_t          animPosPack[3];
134         vec2_t          animScalePack;
135         vec2_t          vertPosPack[3];
136         vec2_t          vertTcPack[2];
137 } x42PackHeader_v5_t;
138
139 #define X42_MAX_FRAMES                  0xFFFF
140 #define X42_MAX_ANIMGROUPS              32
141
142 #define X42_KT_POSITION                 0       //index is the bone index, value (follows) is the position value index
143 #define X42_KT_SCALE                    1       //index is the bone index, value (follows) is the scale value index
144 #define X42_KT_ROTATION                 2       //index is the bone index, value (follows) is the rotation value index
145
146 typedef struct x42KeyStreamEntry_v5_t
147 {
148         u16                     type;                   //one of X42_KT_*
149         u16                     bone;                   //a valid bone index (cannot be X42_MODEL_BONE)
150         u16                     frame;                  //the frame number, in the range [0, numFrames)
151         u16                     value;
152 } x42KeyStreamEntry_v5_t;
153
154 #define X42_NO_LOOP                     ((u16)0xFFFF)
155
156 typedef struct x42Animation_v5_t
157 {
158         x42NameIndex_t  name;
159        
160         /*
161                 If lastFrame < firstFrame then the anim plays the frames
162                 in reverse order.
163                
164                 If loopStart is X42_NO_LOOP then it and loopEnd are ignored.
165
166                 If lastFrame < firstFrame and loopStart is not X42_NO_LOOP
167                 then loopEnd must be <= to loopStart, else loopEnd must
168                 be >= loopStart.
169         */
170         u16                             firstFrame;
171         u16                             lastFrame;                      //inclusive
172         u16                             loopStart;
173         u16                             loopEnd;                        //inclusive
174        
175         u16                             frameRate;                      //in frames per *millisecond*
176 } x42Animation_v5_t;
177
178 typedef struct x42AnimGroup_v5_t
179 {
180         x42NameIndex_t  name;
181         u16                             beginBone;
182         u16                             endBone;
183 } x42AnimGroup_v5_t;
184
185 #define X42_MODEL_BONE ((u16)0xFFFF)
186
187 #define X42_BF_NONE                                     0x0000
188 #define X42_BF_USE_INV_PARENT_SCALE     0x0001
189
190 typedef struct x42Bone_v5_t
191 {
192         x42NameIndex_t  name;
193
194         u16                             flags;                          //one or more X42_BF_* values
195         u16                             parentIdx;                      //index of the parent bone, must be less than this bone's index
196                                                                                 //X42_MODEL_BONE denotes a top-level bone
197
198         f32                             extent;                         //the furthest reaches of this bone's influence
199 } x42Bone_v5_t;
200
201 typedef struct x42Influence_v5_t
202 {
203         u16                             bone;                           //indexes into the bones array
204         affine_t                meshToBone;                     //transforms points from bind pose into bone space
205 } x42Influence_v5_t;
206
207 typedef struct x42Tag_v5_t
208 {
209         x42NameIndex_t  name;
210         u16                             bone;
211         affine_t                tagMatrix;
212 } x42Tag_v5_t;
213
214 #define X42_PT_POINT_LIST               0x0000  //GL_POINTS
215
216 #define X42_PT_LINE_LIST                0x0001  //GL_LINES
217 #define X42_PT_LINE_STRIP               0x0003  //GL_LINE_STRIP
218
219 #define X42_PT_TRIANGLE_LIST    0x0004  //GL_TRIANGLES
220 #define X42_PT_TRIANGLE_STRIP   0x0005  //GL_TRIANGLE_STRIP
221 #define X42_PT_TRIANGLE_FAN             0x0006  //GL_TRIANGLE_FAN
222
223 #define X42_MAX_INFLUENCES_PER_BATCH_V5 60
224
225 #define X42_NO_INDICES ((u32)0xFFFFFFFF)
226
227 typedef struct x42Group_v5_t
228 {
229         x42NameIndex_t  material;
230         x42NameIndex_t  surfaceName;
231
232         /*
233                 This is an optimization hint for the renderer.
234                 It is set to 0, 1, 2, 3, or 4.
235
236                 If the value is one, then each vertex in this
237                 group will have one influence index in the first
238                 element of its indices array and the first element
239                 of its weights array will be set to 1.0F. The last
240                 three elements of its weights and indices arrays
241                 will be zero.
242
243                 If the value is two, then each vertex in this
244                 group will have two influence indices in the first
245                 two elements of its indices array and the first
246                 two elements of its weights array will add up
247                 to 1.0F. The last two elements of the its weights
248                 and indices arrays will be zero.
249
250                 And so on.
251
252                 If the value is zero then the group will have at most
253                 one influence which will be bound to the root bone by
254                 an identity matrix.
255         */
256         u16                             maxVertInfluences;
257
258         /*
259                 Indices into the global influences array.
260        
261                 Note that vertices in this group index
262                 into *this* influence array, not the global
263                 one, that is to say that given:
264        
265                         a vertex weighted against influence 0
266                         and an influences array starting with 4, 3, 9, 0, 2...
267        
268                 the vertex will be written with an influence
269                 index of 3 since influence 0 is loaded as the
270                 fourth (zero-indexed) influence of this group.
271         */
272         u16                             numInfluences;
273         u16                             influences[X42_MAX_INFLUENCES_PER_BATCH_V5];
274        
275         u16                             primType;                       //the type of primitive for this group
276                
277         /*
278                 These values define the part or the vertex
279                 and index array that belongs to this group.
280
281                 Note that in the case of primType_t::Points
282                 there is *no* index data: firstIndex gets
283                 ignored and the renderer draws numPrims verts
284                 starting at firstVert and going in sequence.
285                 This is a DX compatibility thing - get over it.
286
287                 If firstIndex is X42_NO_INDICES then the group is
288                 simply drawn unindexed (pretend indices are 0, 1, 2, ... ).
289         */
290         u32                             firstVert;                      //index of the first vertex for this group
291         u32                             numVerts;                       //number of vertices referenced in this group
292         u32                             firstIndex;                     //index of the first index for this group,
293                                                                                 //if this is X42_NO_INDICES then the group's vertices aren't indexed
294         u32                             numElems;                       //number of indices (or vertices if non-indexed) to draw
295 } x42Group_v5_t;
296
297 typedef struct x42LodRange_v5_t
298 {
299         u16                             lodName;
300         u16                             firstGroup;
301         u16                             numGroups;
302 } x42LodRange_v5_t;
303
304 #endif
Note: See TracBrowser for help on using the browser.