diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CAnimatedMeshHalfLife.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CAnimatedMeshHalfLife.h | 1260 |
1 files changed, 630 insertions, 630 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CAnimatedMeshHalfLife.h b/libraries/irrlicht-1.8/source/Irrlicht/CAnimatedMeshHalfLife.h index 32a4ef8..693cd8d 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CAnimatedMeshHalfLife.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/CAnimatedMeshHalfLife.h | |||
@@ -1,630 +1,630 @@ | |||
1 | // Copyright (C) 2002-2012 Thomas Alten | 1 | // Copyright (C) 2002-2012 Thomas Alten |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #ifndef __C_ANIMATED_MESH_HALFLIFE_H_INCLUDED__ | 5 | #ifndef __C_ANIMATED_MESH_HALFLIFE_H_INCLUDED__ |
6 | #define __C_ANIMATED_MESH_HALFLIFE_H_INCLUDED__ | 6 | #define __C_ANIMATED_MESH_HALFLIFE_H_INCLUDED__ |
7 | 7 | ||
8 | #include "IAnimatedMesh.h" | 8 | #include "IAnimatedMesh.h" |
9 | #include "ISceneManager.h" | 9 | #include "ISceneManager.h" |
10 | #include "irrArray.h" | 10 | #include "irrArray.h" |
11 | #include "irrString.h" | 11 | #include "irrString.h" |
12 | #include "IMeshLoader.h" | 12 | #include "IMeshLoader.h" |
13 | #include "SMesh.h" | 13 | #include "SMesh.h" |
14 | #include "IReadFile.h" | 14 | #include "IReadFile.h" |
15 | 15 | ||
16 | namespace irr | 16 | namespace irr |
17 | { | 17 | { |
18 | namespace scene | 18 | namespace scene |
19 | { | 19 | { |
20 | 20 | ||
21 | 21 | ||
22 | // STUDIO MODELS, Copyright (c) 1998, Valve LLC. All rights reserved. | 22 | // STUDIO MODELS, Copyright (c) 1998, Valve LLC. All rights reserved. |
23 | #define MAXSTUDIOTRIANGLES 20000 // TODO: tune this | 23 | #define MAXSTUDIOTRIANGLES 20000 // TODO: tune this |
24 | #define MAXSTUDIOVERTS 2048 // TODO: tune this | 24 | #define MAXSTUDIOVERTS 2048 // TODO: tune this |
25 | #define MAXSTUDIOSEQUENCES 256 // total animation sequences | 25 | #define MAXSTUDIOSEQUENCES 256 // total animation sequences |
26 | #define MAXSTUDIOSKINS 100 // total textures | 26 | #define MAXSTUDIOSKINS 100 // total textures |
27 | #define MAXSTUDIOSRCBONES 512 // bones allowed at source movement | 27 | #define MAXSTUDIOSRCBONES 512 // bones allowed at source movement |
28 | #define MAXSTUDIOBONES 128 // total bones actually used | 28 | #define MAXSTUDIOBONES 128 // total bones actually used |
29 | #define MAXSTUDIOMODELS 32 // sub-models per model | 29 | #define MAXSTUDIOMODELS 32 // sub-models per model |
30 | #define MAXSTUDIOBODYPARTS 32 | 30 | #define MAXSTUDIOBODYPARTS 32 |
31 | #define MAXSTUDIOGROUPS 4 | 31 | #define MAXSTUDIOGROUPS 4 |
32 | #define MAXSTUDIOANIMATIONS 512 // per sequence | 32 | #define MAXSTUDIOANIMATIONS 512 // per sequence |
33 | #define MAXSTUDIOMESHES 256 | 33 | #define MAXSTUDIOMESHES 256 |
34 | #define MAXSTUDIOEVENTS 1024 | 34 | #define MAXSTUDIOEVENTS 1024 |
35 | #define MAXSTUDIOPIVOTS 256 | 35 | #define MAXSTUDIOPIVOTS 256 |
36 | #define MAXSTUDIOCONTROLLERS 8 | 36 | #define MAXSTUDIOCONTROLLERS 8 |
37 | 37 | ||
38 | typedef f32 vec3_hl[3]; // x,y,z | 38 | typedef f32 vec3_hl[3]; // x,y,z |
39 | typedef f32 vec4_hl[4]; // x,y,z,w | 39 | typedef f32 vec4_hl[4]; // x,y,z,w |
40 | 40 | ||
41 | // byte-align structures | 41 | // byte-align structures |
42 | #include "irrpack.h" | 42 | #include "irrpack.h" |
43 | 43 | ||
44 | struct SHalflifeHeader | 44 | struct SHalflifeHeader |
45 | { | 45 | { |
46 | c8 id[4]; | 46 | c8 id[4]; |
47 | s32 version; | 47 | s32 version; |
48 | 48 | ||
49 | c8 name[64]; | 49 | c8 name[64]; |
50 | s32 length; | 50 | s32 length; |
51 | 51 | ||
52 | vec3_hl eyeposition; // ideal eye position | 52 | vec3_hl eyeposition; // ideal eye position |
53 | vec3_hl min; // ideal movement hull size | 53 | vec3_hl min; // ideal movement hull size |
54 | vec3_hl max; | 54 | vec3_hl max; |
55 | 55 | ||
56 | vec3_hl bbmin; // clipping bounding box | 56 | vec3_hl bbmin; // clipping bounding box |
57 | vec3_hl bbmax; | 57 | vec3_hl bbmax; |
58 | 58 | ||
59 | s32 flags; | 59 | s32 flags; |
60 | 60 | ||
61 | u32 numbones; // bones | 61 | u32 numbones; // bones |
62 | u32 boneindex; | 62 | u32 boneindex; |
63 | 63 | ||
64 | u32 numbonecontrollers; // bone controllers | 64 | u32 numbonecontrollers; // bone controllers |
65 | u32 bonecontrollerindex; | 65 | u32 bonecontrollerindex; |
66 | 66 | ||
67 | u32 numhitboxes; // complex bounding boxes | 67 | u32 numhitboxes; // complex bounding boxes |
68 | u32 hitboxindex; | 68 | u32 hitboxindex; |
69 | 69 | ||
70 | u32 numseq; // animation sequences | 70 | u32 numseq; // animation sequences |
71 | u32 seqindex; | 71 | u32 seqindex; |
72 | 72 | ||
73 | u32 numseqgroups; // demand loaded sequences | 73 | u32 numseqgroups; // demand loaded sequences |
74 | u32 seqgroupindex; | 74 | u32 seqgroupindex; |
75 | 75 | ||
76 | u32 numtextures; // raw textures | 76 | u32 numtextures; // raw textures |
77 | u32 textureindex; | 77 | u32 textureindex; |
78 | u32 texturedataindex; | 78 | u32 texturedataindex; |
79 | 79 | ||
80 | u32 numskinref; // replaceable textures | 80 | u32 numskinref; // replaceable textures |
81 | u32 numskinfamilies; | 81 | u32 numskinfamilies; |
82 | u32 skinindex; | 82 | u32 skinindex; |
83 | 83 | ||
84 | u32 numbodyparts; | 84 | u32 numbodyparts; |
85 | u32 bodypartindex; | 85 | u32 bodypartindex; |
86 | 86 | ||
87 | u32 numattachments; // queryable attachable points | 87 | u32 numattachments; // queryable attachable points |
88 | u32 attachmentindex; | 88 | u32 attachmentindex; |
89 | 89 | ||
90 | s32 soundtable; | 90 | s32 soundtable; |
91 | s32 soundindex; | 91 | s32 soundindex; |
92 | s32 soundgroups; | 92 | s32 soundgroups; |
93 | s32 soundgroupindex; | 93 | s32 soundgroupindex; |
94 | 94 | ||
95 | s32 numtransitions; // animation node to animation node transition graph | 95 | s32 numtransitions; // animation node to animation node transition graph |
96 | s32 transitionindex; | 96 | s32 transitionindex; |
97 | } PACK_STRUCT; | 97 | } PACK_STRUCT; |
98 | 98 | ||
99 | // header for demand loaded sequence group data | 99 | // header for demand loaded sequence group data |
100 | struct studioseqhdr_t | 100 | struct studioseqhdr_t |
101 | { | 101 | { |
102 | s32 id; | 102 | s32 id; |
103 | s32 version; | 103 | s32 version; |
104 | 104 | ||
105 | c8 name[64]; | 105 | c8 name[64]; |
106 | s32 length; | 106 | s32 length; |
107 | } PACK_STRUCT; | 107 | } PACK_STRUCT; |
108 | 108 | ||
109 | // bones | 109 | // bones |
110 | struct SHalflifeBone | 110 | struct SHalflifeBone |
111 | { | 111 | { |
112 | c8 name[32]; // bone name for symbolic links | 112 | c8 name[32]; // bone name for symbolic links |
113 | s32 parent; // parent bone | 113 | s32 parent; // parent bone |
114 | s32 flags; // ?? | 114 | s32 flags; // ?? |
115 | s32 bonecontroller[6]; // bone controller index, -1 == none | 115 | s32 bonecontroller[6]; // bone controller index, -1 == none |
116 | f32 value[6]; // default DoF values | 116 | f32 value[6]; // default DoF values |
117 | f32 scale[6]; // scale for delta DoF values | 117 | f32 scale[6]; // scale for delta DoF values |
118 | } PACK_STRUCT; | 118 | } PACK_STRUCT; |
119 | 119 | ||
120 | 120 | ||
121 | // bone controllers | 121 | // bone controllers |
122 | struct SHalflifeBoneController | 122 | struct SHalflifeBoneController |
123 | { | 123 | { |
124 | s32 bone; // -1 == 0 | 124 | s32 bone; // -1 == 0 |
125 | s32 type; // X, Y, Z, XR, YR, ZR, M | 125 | s32 type; // X, Y, Z, XR, YR, ZR, M |
126 | f32 start; | 126 | f32 start; |
127 | f32 end; | 127 | f32 end; |
128 | s32 rest; // byte index value at rest | 128 | s32 rest; // byte index value at rest |
129 | s32 index; // 0-3 user set controller, 4 mouth | 129 | s32 index; // 0-3 user set controller, 4 mouth |
130 | } PACK_STRUCT; | 130 | } PACK_STRUCT; |
131 | 131 | ||
132 | // intersection boxes | 132 | // intersection boxes |
133 | struct SHalflifeBBox | 133 | struct SHalflifeBBox |
134 | { | 134 | { |
135 | s32 bone; | 135 | s32 bone; |
136 | s32 group; // intersection group | 136 | s32 group; // intersection group |
137 | vec3_hl bbmin; // bounding box | 137 | vec3_hl bbmin; // bounding box |
138 | vec3_hl bbmax; | 138 | vec3_hl bbmax; |
139 | } PACK_STRUCT; | 139 | } PACK_STRUCT; |
140 | 140 | ||
141 | #ifndef ZONE_H | 141 | #ifndef ZONE_H |
142 | // NOTE: this was a void*, but that crashes on 64bit. | 142 | // NOTE: this was a void*, but that crashes on 64bit. |
143 | // I have found no mdl format desc, so not sure what it's meant to be, but s32 at least works. | 143 | // I have found no mdl format desc, so not sure what it's meant to be, but s32 at least works. |
144 | typedef s32 cache_user_t; | 144 | typedef s32 cache_user_t; |
145 | #endif | 145 | #endif |
146 | 146 | ||
147 | // demand loaded sequence groups | 147 | // demand loaded sequence groups |
148 | struct SHalflifeSequenceGroup | 148 | struct SHalflifeSequenceGroup |
149 | { | 149 | { |
150 | c8 label[32]; // textual name | 150 | c8 label[32]; // textual name |
151 | c8 name[64]; // file name | 151 | c8 name[64]; // file name |
152 | cache_user_t cache; // cache index pointer | 152 | cache_user_t cache; // cache index pointer |
153 | s32 data; // hack for group 0 | 153 | s32 data; // hack for group 0 |
154 | } PACK_STRUCT; | 154 | } PACK_STRUCT; |
155 | 155 | ||
156 | // sequence descriptions | 156 | // sequence descriptions |
157 | struct SHalflifeSequence | 157 | struct SHalflifeSequence |
158 | { | 158 | { |
159 | c8 label[32]; // sequence label | 159 | c8 label[32]; // sequence label |
160 | 160 | ||
161 | f32 fps; // frames per second | 161 | f32 fps; // frames per second |
162 | s32 flags; // looping/non-looping flags | 162 | s32 flags; // looping/non-looping flags |
163 | 163 | ||
164 | s32 activity; | 164 | s32 activity; |
165 | s32 actweight; | 165 | s32 actweight; |
166 | 166 | ||
167 | s32 numevents; | 167 | s32 numevents; |
168 | s32 eventindex; | 168 | s32 eventindex; |
169 | 169 | ||
170 | s32 numframes; // number of frames per sequence | 170 | s32 numframes; // number of frames per sequence |
171 | 171 | ||
172 | u32 numpivots; // number of foot pivots | 172 | u32 numpivots; // number of foot pivots |
173 | u32 pivotindex; | 173 | u32 pivotindex; |
174 | 174 | ||
175 | s32 motiontype; | 175 | s32 motiontype; |
176 | s32 motionbone; | 176 | s32 motionbone; |
177 | vec3_hl linearmovement; | 177 | vec3_hl linearmovement; |
178 | s32 automoveposindex; | 178 | s32 automoveposindex; |
179 | s32 automoveangleindex; | 179 | s32 automoveangleindex; |
180 | 180 | ||
181 | vec3_hl bbmin; // per sequence bounding box | 181 | vec3_hl bbmin; // per sequence bounding box |
182 | vec3_hl bbmax; | 182 | vec3_hl bbmax; |
183 | 183 | ||
184 | s32 numblends; | 184 | s32 numblends; |
185 | s32 animindex; // SHalflifeAnimOffset pointer relative to start of sequence group data | 185 | s32 animindex; // SHalflifeAnimOffset pointer relative to start of sequence group data |
186 | // [blend][bone][X, Y, Z, XR, YR, ZR] | 186 | // [blend][bone][X, Y, Z, XR, YR, ZR] |
187 | 187 | ||
188 | s32 blendtype[2]; // X, Y, Z, XR, YR, ZR | 188 | s32 blendtype[2]; // X, Y, Z, XR, YR, ZR |
189 | f32 blendstart[2]; // starting value | 189 | f32 blendstart[2]; // starting value |
190 | f32 blendend[2]; // ending value | 190 | f32 blendend[2]; // ending value |
191 | s32 blendparent; | 191 | s32 blendparent; |
192 | 192 | ||
193 | s32 seqgroup; // sequence group for demand loading | 193 | s32 seqgroup; // sequence group for demand loading |
194 | 194 | ||
195 | s32 entrynode; // transition node at entry | 195 | s32 entrynode; // transition node at entry |
196 | s32 exitnode; // transition node at exit | 196 | s32 exitnode; // transition node at exit |
197 | s32 nodeflags; // transition rules | 197 | s32 nodeflags; // transition rules |
198 | 198 | ||
199 | s32 nextseq; // auto advancing sequences | 199 | s32 nextseq; // auto advancing sequences |
200 | } PACK_STRUCT; | 200 | } PACK_STRUCT; |
201 | 201 | ||
202 | // events | 202 | // events |
203 | struct mstudioevent_t | 203 | struct mstudioevent_t |
204 | { | 204 | { |
205 | s32 frame; | 205 | s32 frame; |
206 | s32 event; | 206 | s32 event; |
207 | s32 type; | 207 | s32 type; |
208 | c8 options[64]; | 208 | c8 options[64]; |
209 | } PACK_STRUCT; | 209 | } PACK_STRUCT; |
210 | 210 | ||
211 | 211 | ||
212 | // pivots | 212 | // pivots |
213 | struct mstudiopivot_t | 213 | struct mstudiopivot_t |
214 | { | 214 | { |
215 | vec3_hl org; // pivot point | 215 | vec3_hl org; // pivot point |
216 | s32 start; | 216 | s32 start; |
217 | s32 end; | 217 | s32 end; |
218 | } PACK_STRUCT; | 218 | } PACK_STRUCT; |
219 | 219 | ||
220 | // attachment | 220 | // attachment |
221 | struct SHalflifeAttachment | 221 | struct SHalflifeAttachment |
222 | { | 222 | { |
223 | c8 name[32]; | 223 | c8 name[32]; |
224 | s32 type; | 224 | s32 type; |
225 | s32 bone; | 225 | s32 bone; |
226 | vec3_hl org; // attachment point | 226 | vec3_hl org; // attachment point |
227 | vec3_hl vectors[3]; | 227 | vec3_hl vectors[3]; |
228 | } PACK_STRUCT; | 228 | } PACK_STRUCT; |
229 | 229 | ||
230 | struct SHalflifeAnimOffset | 230 | struct SHalflifeAnimOffset |
231 | { | 231 | { |
232 | u16 offset[6]; | 232 | u16 offset[6]; |
233 | } PACK_STRUCT; | 233 | } PACK_STRUCT; |
234 | 234 | ||
235 | // animation frames | 235 | // animation frames |
236 | union SHalflifeAnimationFrame | 236 | union SHalflifeAnimationFrame |
237 | { | 237 | { |
238 | struct { | 238 | struct { |
239 | u8 valid; | 239 | u8 valid; |
240 | u8 total; | 240 | u8 total; |
241 | } PACK_STRUCT num; | 241 | } PACK_STRUCT num; |
242 | s16 value; | 242 | s16 value; |
243 | } PACK_STRUCT; | 243 | } PACK_STRUCT; |
244 | 244 | ||
245 | 245 | ||
246 | // body part index | 246 | // body part index |
247 | struct SHalflifeBody | 247 | struct SHalflifeBody |
248 | { | 248 | { |
249 | c8 name[64]; | 249 | c8 name[64]; |
250 | u32 nummodels; | 250 | u32 nummodels; |
251 | u32 base; | 251 | u32 base; |
252 | u32 modelindex; // index into models array | 252 | u32 modelindex; // index into models array |
253 | } PACK_STRUCT; | 253 | } PACK_STRUCT; |
254 | 254 | ||
255 | 255 | ||
256 | // skin info | 256 | // skin info |
257 | struct SHalflifeTexture | 257 | struct SHalflifeTexture |
258 | { | 258 | { |
259 | c8 name[64]; | 259 | c8 name[64]; |
260 | s32 flags; | 260 | s32 flags; |
261 | s32 width; | 261 | s32 width; |
262 | s32 height; | 262 | s32 height; |
263 | s32 index; | 263 | s32 index; |
264 | } PACK_STRUCT; | 264 | } PACK_STRUCT; |
265 | 265 | ||
266 | 266 | ||
267 | // skin families | 267 | // skin families |
268 | // short index[skinfamilies][skinref] | 268 | // short index[skinfamilies][skinref] |
269 | 269 | ||
270 | // studio models | 270 | // studio models |
271 | struct SHalflifeModel | 271 | struct SHalflifeModel |
272 | { | 272 | { |
273 | c8 name[64]; | 273 | c8 name[64]; |
274 | s32 type; | 274 | s32 type; |
275 | 275 | ||
276 | f32 boundingradius; | 276 | f32 boundingradius; |
277 | 277 | ||
278 | u32 nummesh; | 278 | u32 nummesh; |
279 | u32 meshindex; | 279 | u32 meshindex; |
280 | 280 | ||
281 | u32 numverts; // number of unique vertices | 281 | u32 numverts; // number of unique vertices |
282 | u32 vertinfoindex; // vertex bone info | 282 | u32 vertinfoindex; // vertex bone info |
283 | u32 vertindex; // vertex vec3_hl | 283 | u32 vertindex; // vertex vec3_hl |
284 | u32 numnorms; // number of unique surface normals | 284 | u32 numnorms; // number of unique surface normals |
285 | u32 norminfoindex; // normal bone info | 285 | u32 norminfoindex; // normal bone info |
286 | u32 normindex; // normal vec3_hl | 286 | u32 normindex; // normal vec3_hl |
287 | 287 | ||
288 | u32 numgroups; // deformation groups | 288 | u32 numgroups; // deformation groups |
289 | u32 groupindex; | 289 | u32 groupindex; |
290 | } PACK_STRUCT; | 290 | } PACK_STRUCT; |
291 | 291 | ||
292 | 292 | ||
293 | // meshes | 293 | // meshes |
294 | struct SHalflifeMesh | 294 | struct SHalflifeMesh |
295 | { | 295 | { |
296 | u32 numtris; | 296 | u32 numtris; |
297 | u32 triindex; | 297 | u32 triindex; |
298 | u32 skinref; | 298 | u32 skinref; |
299 | u32 numnorms; // per mesh normals | 299 | u32 numnorms; // per mesh normals |
300 | u32 normindex; // normal vec3_hl | 300 | u32 normindex; // normal vec3_hl |
301 | } PACK_STRUCT; | 301 | } PACK_STRUCT; |
302 | 302 | ||
303 | // Default alignment | 303 | // Default alignment |
304 | #include "irrunpack.h" | 304 | #include "irrunpack.h" |
305 | 305 | ||
306 | // lighting options | 306 | // lighting options |
307 | #define STUDIO_NF_FLATSHADE 0x0001 | 307 | #define STUDIO_NF_FLATSHADE 0x0001 |
308 | #define STUDIO_NF_CHROME 0x0002 | 308 | #define STUDIO_NF_CHROME 0x0002 |
309 | #define STUDIO_NF_FULLBRIGHT 0x0004 | 309 | #define STUDIO_NF_FULLBRIGHT 0x0004 |
310 | 310 | ||
311 | // motion flags | 311 | // motion flags |
312 | #define STUDIO_X 0x0001 | 312 | #define STUDIO_X 0x0001 |
313 | #define STUDIO_Y 0x0002 | 313 | #define STUDIO_Y 0x0002 |
314 | #define STUDIO_Z 0x0004 | 314 | #define STUDIO_Z 0x0004 |
315 | #define STUDIO_XR 0x0008 | 315 | #define STUDIO_XR 0x0008 |
316 | #define STUDIO_YR 0x0010 | 316 | #define STUDIO_YR 0x0010 |
317 | #define STUDIO_ZR 0x0020 | 317 | #define STUDIO_ZR 0x0020 |
318 | #define STUDIO_LX 0x0040 | 318 | #define STUDIO_LX 0x0040 |
319 | #define STUDIO_LY 0x0080 | 319 | #define STUDIO_LY 0x0080 |
320 | #define STUDIO_LZ 0x0100 | 320 | #define STUDIO_LZ 0x0100 |
321 | #define STUDIO_AX 0x0200 | 321 | #define STUDIO_AX 0x0200 |
322 | #define STUDIO_AY 0x0400 | 322 | #define STUDIO_AY 0x0400 |
323 | #define STUDIO_AZ 0x0800 | 323 | #define STUDIO_AZ 0x0800 |
324 | #define STUDIO_AXR 0x1000 | 324 | #define STUDIO_AXR 0x1000 |
325 | #define STUDIO_AYR 0x2000 | 325 | #define STUDIO_AYR 0x2000 |
326 | #define STUDIO_AZR 0x4000 | 326 | #define STUDIO_AZR 0x4000 |
327 | #define STUDIO_TYPES 0x7FFF | 327 | #define STUDIO_TYPES 0x7FFF |
328 | #define STUDIO_RLOOP 0x8000 // controller that wraps shortest distance | 328 | #define STUDIO_RLOOP 0x8000 // controller that wraps shortest distance |
329 | 329 | ||
330 | // sequence flags | 330 | // sequence flags |
331 | #define STUDIO_LOOPING 0x0001 | 331 | #define STUDIO_LOOPING 0x0001 |
332 | 332 | ||
333 | // bone flags | 333 | // bone flags |
334 | #define STUDIO_HAS_NORMALS 0x0001 | 334 | #define STUDIO_HAS_NORMALS 0x0001 |
335 | #define STUDIO_HAS_VERTICES 0x0002 | 335 | #define STUDIO_HAS_VERTICES 0x0002 |
336 | #define STUDIO_HAS_BBOX 0x0004 | 336 | #define STUDIO_HAS_BBOX 0x0004 |
337 | #define STUDIO_HAS_CHROME 0x0008 // if any of the textures have chrome on them | 337 | #define STUDIO_HAS_CHROME 0x0008 // if any of the textures have chrome on them |
338 | 338 | ||
339 | #define RAD_TO_STUDIO (32768.0/M_PI) | 339 | #define RAD_TO_STUDIO (32768.0/M_PI) |
340 | #define STUDIO_TO_RAD (M_PI/32768.0) | 340 | #define STUDIO_TO_RAD (M_PI/32768.0) |
341 | 341 | ||
342 | /*! | 342 | /*! |
343 | Textureatlas | 343 | Textureatlas |
344 | Combine Source Images with arbitrary size and bithdepth to an Image with 2^n size | 344 | Combine Source Images with arbitrary size and bithdepth to an Image with 2^n size |
345 | borders from the source images are copied around for allowing filtering ( bilinear, mipmap ) | 345 | borders from the source images are copied around for allowing filtering ( bilinear, mipmap ) |
346 | */ | 346 | */ |
347 | struct STextureAtlas | 347 | struct STextureAtlas |
348 | { | 348 | { |
349 | STextureAtlas () | 349 | STextureAtlas () |
350 | { | 350 | { |
351 | release(); | 351 | release(); |
352 | } | 352 | } |
353 | 353 | ||
354 | virtual ~STextureAtlas () | 354 | virtual ~STextureAtlas () |
355 | { | 355 | { |
356 | release (); | 356 | release (); |
357 | } | 357 | } |
358 | 358 | ||
359 | void release (); | 359 | void release (); |
360 | void addSource ( const c8 * name, video::IImage * image ); | 360 | void addSource ( const c8 * name, video::IImage * image ); |
361 | void create ( u32 pixelborder, video::E_TEXTURE_CLAMP texmode ); | 361 | void create ( u32 pixelborder, video::E_TEXTURE_CLAMP texmode ); |
362 | void getScale ( core::vector2df &scale ); | 362 | void getScale ( core::vector2df &scale ); |
363 | void getTranslation ( const c8 * name, core::vector2di &pos ); | 363 | void getTranslation ( const c8 * name, core::vector2di &pos ); |
364 | 364 | ||
365 | struct TextureAtlasEntry | 365 | struct TextureAtlasEntry |
366 | { | 366 | { |
367 | io::path name; | 367 | io::path name; |
368 | u32 width; | 368 | u32 width; |
369 | u32 height; | 369 | u32 height; |
370 | 370 | ||
371 | core::vector2di pos; | 371 | core::vector2di pos; |
372 | 372 | ||
373 | video::IImage * image; | 373 | video::IImage * image; |
374 | 374 | ||
375 | bool operator < ( const TextureAtlasEntry & other ) | 375 | bool operator < ( const TextureAtlasEntry & other ) |
376 | { | 376 | { |
377 | return height > other.height; | 377 | return height > other.height; |
378 | } | 378 | } |
379 | }; | 379 | }; |
380 | 380 | ||
381 | 381 | ||
382 | core::array < TextureAtlasEntry > atlas; | 382 | core::array < TextureAtlasEntry > atlas; |
383 | video::IImage * Master; | 383 | video::IImage * Master; |
384 | }; | 384 | }; |
385 | 385 | ||
386 | 386 | ||
387 | //! Possible types of Animation Type | 387 | //! Possible types of Animation Type |
388 | enum E_ANIMATION_TYPE | 388 | enum E_ANIMATION_TYPE |
389 | { | 389 | { |
390 | //! No Animation | 390 | //! No Animation |
391 | EAMT_STILL, | 391 | EAMT_STILL, |
392 | //! From Start to End, then Stop ( Limited Line ) | 392 | //! From Start to End, then Stop ( Limited Line ) |
393 | EAMT_WAYPOINT, | 393 | EAMT_WAYPOINT, |
394 | //! Linear Cycling Animation ( Sawtooth ) | 394 | //! Linear Cycling Animation ( Sawtooth ) |
395 | EAMT_LOOPING, | 395 | EAMT_LOOPING, |
396 | //! Linear bobbing ( Triangle ) | 396 | //! Linear bobbing ( Triangle ) |
397 | EAMT_PINGPONG | 397 | EAMT_PINGPONG |
398 | }; | 398 | }; |
399 | 399 | ||
400 | //! Names for Animation Type | 400 | //! Names for Animation Type |
401 | const c8* const MeshAnimationTypeNames[] = | 401 | const c8* const MeshAnimationTypeNames[] = |
402 | { | 402 | { |
403 | "still", | 403 | "still", |
404 | "waypoint", | 404 | "waypoint", |
405 | "looping", | 405 | "looping", |
406 | "pingpong", | 406 | "pingpong", |
407 | 0 | 407 | 0 |
408 | }; | 408 | }; |
409 | 409 | ||
410 | 410 | ||
411 | //! Data for holding named Animation Info | 411 | //! Data for holding named Animation Info |
412 | struct KeyFrameInterpolation | 412 | struct KeyFrameInterpolation |
413 | { | 413 | { |
414 | core::stringc Name; // Name of the current Animation/Bone | 414 | core::stringc Name; // Name of the current Animation/Bone |
415 | E_ANIMATION_TYPE AnimationType; // Type of Animation ( looping, usw..) | 415 | E_ANIMATION_TYPE AnimationType; // Type of Animation ( looping, usw..) |
416 | 416 | ||
417 | f32 CurrentFrame; // Current Frame | 417 | f32 CurrentFrame; // Current Frame |
418 | s32 NextFrame; // Frame which will be used next. For blending | 418 | s32 NextFrame; // Frame which will be used next. For blending |
419 | 419 | ||
420 | s32 StartFrame; // Absolute Frame where the current animation start | 420 | s32 StartFrame; // Absolute Frame where the current animation start |
421 | s32 Frames; // Relative Frames how much Frames this animation have | 421 | s32 Frames; // Relative Frames how much Frames this animation have |
422 | s32 LoopingFrames; // How much of Frames sould be looped | 422 | s32 LoopingFrames; // How much of Frames sould be looped |
423 | s32 EndFrame; // Absolute Frame where the current animation ends End = start + frames - 1 | 423 | s32 EndFrame; // Absolute Frame where the current animation ends End = start + frames - 1 |
424 | 424 | ||
425 | f32 FramesPerSecond; // Speed in Frames/Seconds the animation is played | 425 | f32 FramesPerSecond; // Speed in Frames/Seconds the animation is played |
426 | f32 RelativeSpeed; // Factor Original fps is modified | 426 | f32 RelativeSpeed; // Factor Original fps is modified |
427 | 427 | ||
428 | u32 BeginTime; // Animation started at this thime | 428 | u32 BeginTime; // Animation started at this thime |
429 | u32 EndTime; // Animation end at this time | 429 | u32 EndTime; // Animation end at this time |
430 | u32 LastTime; // Last Keyframe was done at this time | 430 | u32 LastTime; // Last Keyframe was done at this time |
431 | 431 | ||
432 | KeyFrameInterpolation ( const c8 * name = "", s32 start = 0, s32 frames = 0, s32 loopingframes = 0, | 432 | KeyFrameInterpolation ( const c8 * name = "", s32 start = 0, s32 frames = 0, s32 loopingframes = 0, |
433 | f32 fps = 0.f, f32 relativefps = 1.f ) | 433 | f32 fps = 0.f, f32 relativefps = 1.f ) |
434 | : Name ( name ), AnimationType ( loopingframes ? EAMT_LOOPING : EAMT_WAYPOINT), | 434 | : Name ( name ), AnimationType ( loopingframes ? EAMT_LOOPING : EAMT_WAYPOINT), |
435 | CurrentFrame ( (f32) start ), NextFrame ( start ), StartFrame ( start ), | 435 | CurrentFrame ( (f32) start ), NextFrame ( start ), StartFrame ( start ), |
436 | Frames ( frames ), LoopingFrames ( loopingframes ), EndFrame ( start + frames - 1 ), | 436 | Frames ( frames ), LoopingFrames ( loopingframes ), EndFrame ( start + frames - 1 ), |
437 | FramesPerSecond ( fps ), RelativeSpeed ( relativefps ), | 437 | FramesPerSecond ( fps ), RelativeSpeed ( relativefps ), |
438 | BeginTime ( 0 ), EndTime ( 0 ), LastTime ( 0 ) | 438 | BeginTime ( 0 ), EndTime ( 0 ), LastTime ( 0 ) |
439 | { | 439 | { |
440 | } | 440 | } |
441 | 441 | ||
442 | // linear search | 442 | // linear search |
443 | bool operator == ( const KeyFrameInterpolation & other ) const | 443 | bool operator == ( const KeyFrameInterpolation & other ) const |
444 | { | 444 | { |
445 | return Name.equals_ignore_case ( other.Name ); | 445 | return Name.equals_ignore_case ( other.Name ); |
446 | } | 446 | } |
447 | 447 | ||
448 | }; | 448 | }; |
449 | 449 | ||
450 | 450 | ||
451 | //! a List holding named Animations | 451 | //! a List holding named Animations |
452 | typedef core::array < KeyFrameInterpolation > IAnimationList; | 452 | typedef core::array < KeyFrameInterpolation > IAnimationList; |
453 | 453 | ||
454 | //! a List holding named Skins | 454 | //! a List holding named Skins |
455 | typedef core::array < core::stringc > ISkinList; | 455 | typedef core::array < core::stringc > ISkinList; |
456 | 456 | ||
457 | 457 | ||
458 | // Current Model per Body | 458 | // Current Model per Body |
459 | struct SubModel | 459 | struct SubModel |
460 | { | 460 | { |
461 | core::stringc name; | 461 | core::stringc name; |
462 | u32 startBuffer; | 462 | u32 startBuffer; |
463 | u32 endBuffer; | 463 | u32 endBuffer; |
464 | u32 state; | 464 | u32 state; |
465 | }; | 465 | }; |
466 | 466 | ||
467 | struct BodyPart | 467 | struct BodyPart |
468 | { | 468 | { |
469 | core::stringc name; | 469 | core::stringc name; |
470 | u32 defaultModel; | 470 | u32 defaultModel; |
471 | core::array < SubModel > model; | 471 | core::array < SubModel > model; |
472 | }; | 472 | }; |
473 | //! a List holding named Models and SubModels | 473 | //! a List holding named Models and SubModels |
474 | typedef core::array < BodyPart > IBodyList; | 474 | typedef core::array < BodyPart > IBodyList; |
475 | 475 | ||
476 | 476 | ||
477 | class CAnimatedMeshHalfLife : public IAnimatedMesh | 477 | class CAnimatedMeshHalfLife : public IAnimatedMesh |
478 | { | 478 | { |
479 | public: | 479 | public: |
480 | 480 | ||
481 | //! constructor | 481 | //! constructor |
482 | CAnimatedMeshHalfLife(); | 482 | CAnimatedMeshHalfLife(); |
483 | 483 | ||
484 | //! destructor | 484 | //! destructor |
485 | virtual ~CAnimatedMeshHalfLife(); | 485 | virtual ~CAnimatedMeshHalfLife(); |
486 | 486 | ||
487 | //! loads a Halflife mdl file | 487 | //! loads a Halflife mdl file |
488 | virtual bool loadModelFile( io::IReadFile* file, ISceneManager * smgr ); | 488 | virtual bool loadModelFile( io::IReadFile* file, ISceneManager * smgr ); |
489 | 489 | ||
490 | //IAnimatedMesh | 490 | //IAnimatedMesh |
491 | virtual u32 getFrameCount() const; | 491 | virtual u32 getFrameCount() const; |
492 | virtual IMesh* getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop); | 492 | virtual IMesh* getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop, s32 endFrameLoop); |
493 | virtual const core::aabbox3d<f32>& getBoundingBox() const; | 493 | virtual const core::aabbox3d<f32>& getBoundingBox() const; |
494 | virtual E_ANIMATED_MESH_TYPE getMeshType() const; | 494 | virtual E_ANIMATED_MESH_TYPE getMeshType() const; |
495 | virtual void renderModel ( u32 param, video::IVideoDriver * driver, const core::matrix4 &absoluteTransformation); | 495 | virtual void renderModel ( u32 param, video::IVideoDriver * driver, const core::matrix4 &absoluteTransformation); |
496 | 496 | ||
497 | //! returns amount of mesh buffers. | 497 | //! returns amount of mesh buffers. |
498 | virtual u32 getMeshBufferCount() const; | 498 | virtual u32 getMeshBufferCount() const; |
499 | //! returns pointer to a mesh buffer | 499 | //! returns pointer to a mesh buffer |
500 | virtual IMeshBuffer* getMeshBuffer(u32 nr) const; | 500 | virtual IMeshBuffer* getMeshBuffer(u32 nr) const; |
501 | //! Returns pointer to a mesh buffer which fits a material | 501 | //! Returns pointer to a mesh buffer which fits a material |
502 | virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const; | 502 | virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const; |
503 | 503 | ||
504 | virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue); | 504 | virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue); |
505 | 505 | ||
506 | //! set the hardware mapping hint, for driver | 506 | //! set the hardware mapping hint, for driver |
507 | virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX); | 507 | virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX); |
508 | 508 | ||
509 | //! flags the meshbuffer as changed, reloads hardware buffers | 509 | //! flags the meshbuffer as changed, reloads hardware buffers |
510 | virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX); | 510 | virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX); |
511 | 511 | ||
512 | //! set user axis aligned bounding box | 512 | //! set user axis aligned bounding box |
513 | virtual void setBoundingBox(const core::aabbox3df& box); | 513 | virtual void setBoundingBox(const core::aabbox3df& box); |
514 | 514 | ||
515 | //! Gets the default animation speed of the animated mesh. | 515 | //! Gets the default animation speed of the animated mesh. |
516 | /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */ | 516 | /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */ |
517 | virtual f32 getAnimationSpeed() const | 517 | virtual f32 getAnimationSpeed() const |
518 | { | 518 | { |
519 | return FramesPerSecond; | 519 | return FramesPerSecond; |
520 | } | 520 | } |
521 | 521 | ||
522 | //! Gets the frame count of the animated mesh. | 522 | //! Gets the frame count of the animated mesh. |
523 | /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated. | 523 | /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated. |
524 | The actual speed is set in the scene node the mesh is instantiated in.*/ | 524 | The actual speed is set in the scene node the mesh is instantiated in.*/ |
525 | virtual void setAnimationSpeed(f32 fps) | 525 | virtual void setAnimationSpeed(f32 fps) |
526 | { | 526 | { |
527 | FramesPerSecond=fps; | 527 | FramesPerSecond=fps; |
528 | } | 528 | } |
529 | 529 | ||
530 | //! Get the Animation List | 530 | //! Get the Animation List |
531 | virtual IAnimationList* getAnimList () { return &AnimList; } | 531 | virtual IAnimationList* getAnimList () { return &AnimList; } |
532 | 532 | ||
533 | //! Return the named Body List of this Animated Mesh | 533 | //! Return the named Body List of this Animated Mesh |
534 | virtual IBodyList *getBodyList() { return &BodyList; } | 534 | virtual IBodyList *getBodyList() { return &BodyList; } |
535 | 535 | ||
536 | private: | 536 | private: |
537 | 537 | ||
538 | // KeyFrame Animation List | 538 | // KeyFrame Animation List |
539 | IAnimationList AnimList; | 539 | IAnimationList AnimList; |
540 | // Sum of all sequences | 540 | // Sum of all sequences |
541 | u32 FrameCount; | 541 | u32 FrameCount; |
542 | 542 | ||
543 | // Named meshes of the Body | 543 | // Named meshes of the Body |
544 | IBodyList BodyList; | 544 | IBodyList BodyList; |
545 | 545 | ||
546 | //! return a Mesh per frame | 546 | //! return a Mesh per frame |
547 | SMesh* MeshIPol; | 547 | SMesh* MeshIPol; |
548 | 548 | ||
549 | ISceneManager *SceneManager; | 549 | ISceneManager *SceneManager; |
550 | 550 | ||
551 | SHalflifeHeader *Header; | 551 | SHalflifeHeader *Header; |
552 | SHalflifeHeader *TextureHeader; | 552 | SHalflifeHeader *TextureHeader; |
553 | bool OwnTexModel; // do we have a modelT.mdl ? | 553 | bool OwnTexModel; // do we have a modelT.mdl ? |
554 | SHalflifeHeader *AnimationHeader[32]; // sequences named model01.mdl, model02.mdl | 554 | SHalflifeHeader *AnimationHeader[32]; // sequences named model01.mdl, model02.mdl |
555 | 555 | ||
556 | void initData (); | 556 | void initData (); |
557 | SHalflifeHeader * loadModel( io::IReadFile* file, const io::path &filename ); | 557 | SHalflifeHeader * loadModel( io::IReadFile* file, const io::path &filename ); |
558 | bool postLoadModel( const io::path &filename ); | 558 | bool postLoadModel( const io::path &filename ); |
559 | 559 | ||
560 | u32 SequenceIndex; // sequence index | 560 | u32 SequenceIndex; // sequence index |
561 | f32 CurrentFrame; // Current Frame | 561 | f32 CurrentFrame; // Current Frame |
562 | f32 FramesPerSecond; | 562 | f32 FramesPerSecond; |
563 | 563 | ||
564 | #define MOUTH_CONTROLLER 4 | 564 | #define MOUTH_CONTROLLER 4 |
565 | u8 BoneController[4 + 1 ]; // bone controllers + mouth position | 565 | u8 BoneController[4 + 1 ]; // bone controllers + mouth position |
566 | u8 Blending[2]; // animation blending | 566 | u8 Blending[2]; // animation blending |
567 | 567 | ||
568 | vec4_hl BoneAdj; | 568 | vec4_hl BoneAdj; |
569 | f32 SetController( s32 controllerIndex, f32 value ); | 569 | f32 SetController( s32 controllerIndex, f32 value ); |
570 | 570 | ||
571 | u32 SkinGroupSelection; // skin group selection | 571 | u32 SkinGroupSelection; // skin group selection |
572 | u32 SetSkin( u32 value ); | 572 | u32 SetSkin( u32 value ); |
573 | 573 | ||
574 | void initModel(); | 574 | void initModel(); |
575 | void dumpModelInfo(u32 level) const; | 575 | void dumpModelInfo(u32 level) const; |
576 | 576 | ||
577 | void ExtractBbox(s32 sequence, core::aabbox3df &box) const; | 577 | void ExtractBbox(s32 sequence, core::aabbox3df &box) const; |
578 | 578 | ||
579 | void setUpBones (); | 579 | void setUpBones (); |
580 | SHalflifeAnimOffset * getAnim( SHalflifeSequence *seq ); | 580 | SHalflifeAnimOffset * getAnim( SHalflifeSequence *seq ); |
581 | void slerpBones( vec4_hl q1[], vec3_hl pos1[], vec4_hl q2[], vec3_hl pos2[], f32 s ); | 581 | void slerpBones( vec4_hl q1[], vec3_hl pos1[], vec4_hl q2[], vec3_hl pos2[], f32 s ); |
582 | void calcRotations ( vec3_hl *pos, vec4_hl *q, SHalflifeSequence *seq, SHalflifeAnimOffset *anim, f32 f ); | 582 | void calcRotations ( vec3_hl *pos, vec4_hl *q, SHalflifeSequence *seq, SHalflifeAnimOffset *anim, f32 f ); |
583 | 583 | ||
584 | void calcBoneAdj(); | 584 | void calcBoneAdj(); |
585 | void calcBoneQuaternion(const s32 frame, const SHalflifeBone *bone, SHalflifeAnimOffset *anim, const u32 j, f32& angle1, f32& angle2) const; | 585 | void calcBoneQuaternion(const s32 frame, const SHalflifeBone *bone, SHalflifeAnimOffset *anim, const u32 j, f32& angle1, f32& angle2) const; |
586 | void calcBonePosition(const s32 frame, f32 s, const SHalflifeBone *bone, SHalflifeAnimOffset *anim, f32 *pos ) const; | 586 | void calcBonePosition(const s32 frame, f32 s, const SHalflifeBone *bone, SHalflifeAnimOffset *anim, f32 *pos ) const; |
587 | 587 | ||
588 | void buildVertices (); | 588 | void buildVertices (); |
589 | 589 | ||
590 | io::path TextureBaseName; | 590 | io::path TextureBaseName; |
591 | 591 | ||
592 | #define HL_TEXTURE_ATLAS | 592 | #define HL_TEXTURE_ATLAS |
593 | 593 | ||
594 | #ifdef HL_TEXTURE_ATLAS | 594 | #ifdef HL_TEXTURE_ATLAS |
595 | STextureAtlas TextureAtlas; | 595 | STextureAtlas TextureAtlas; |
596 | video::ITexture *TextureMaster; | 596 | video::ITexture *TextureMaster; |
597 | #endif | 597 | #endif |
598 | 598 | ||
599 | }; | 599 | }; |
600 | 600 | ||
601 | 601 | ||
602 | //! Meshloader capable of loading HalfLife Model files | 602 | //! Meshloader capable of loading HalfLife Model files |
603 | class CHalflifeMDLMeshFileLoader : public IMeshLoader | 603 | class CHalflifeMDLMeshFileLoader : public IMeshLoader |
604 | { | 604 | { |
605 | public: | 605 | public: |
606 | 606 | ||
607 | //! Constructor | 607 | //! Constructor |
608 | CHalflifeMDLMeshFileLoader( scene::ISceneManager* smgr ); | 608 | CHalflifeMDLMeshFileLoader( scene::ISceneManager* smgr ); |
609 | 609 | ||
610 | //! returns true if the file maybe is able to be loaded by this class | 610 | //! returns true if the file maybe is able to be loaded by this class |
611 | /** based on the file extension (e.g. ".bsp") */ | 611 | /** based on the file extension (e.g. ".bsp") */ |
612 | virtual bool isALoadableFileExtension(const io::path& filename) const; | 612 | virtual bool isALoadableFileExtension(const io::path& filename) const; |
613 | 613 | ||
614 | //! creates/loads an animated mesh from the file. | 614 | //! creates/loads an animated mesh from the file. |
615 | /** \return Pointer to the created mesh. Returns 0 if loading failed. | 615 | /** \return Pointer to the created mesh. Returns 0 if loading failed. |
616 | If you no longer need the mesh, you should call IAnimatedMesh::drop(). | 616 | If you no longer need the mesh, you should call IAnimatedMesh::drop(). |
617 | See IReferenceCounted::drop() for more information. | 617 | See IReferenceCounted::drop() for more information. |
618 | */ | 618 | */ |
619 | virtual IAnimatedMesh* createMesh(io::IReadFile* file); | 619 | virtual IAnimatedMesh* createMesh(io::IReadFile* file); |
620 | 620 | ||
621 | private: | 621 | private: |
622 | scene::ISceneManager* SceneManager; | 622 | scene::ISceneManager* SceneManager; |
623 | }; | 623 | }; |
624 | 624 | ||
625 | 625 | ||
626 | } // end namespace scene | 626 | } // end namespace scene |
627 | } // end namespace irr | 627 | } // end namespace irr |
628 | 628 | ||
629 | #endif | 629 | #endif |
630 | 630 | ||