2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
29 char *SKEL_ROOT_NAMES[] =
\r
34 char *SKEL_NAMES[] =
\r
41 int NAME_OFFSETS[] =
\r
46 int numJointsForSkeleton[] =
\r
53 float g_rotation[3];
\r
54 float g_translation[3];
\r
56 //==========================================================================
\r
60 //==========================================================================
\r
62 static void LoadHRCClustered(char *fileName, int **clusterList, int *num_verts, int skelType)
\r
66 TK_OpenSource(fileName);
\r
67 TK_FetchRequire(TK_HRCH);
\r
68 TK_FetchRequire(TK_COLON);
\r
69 TK_FetchRequire(TK_SOFTIMAGE);
\r
71 TK_Beyond(TK_CLUSTERS);
\r
73 while(TK_Search(TK_CLUSTER_NAME) != TK_EOF)
\r
75 TK_Require(TK_STRING);
\r
77 for( i = 0; i < numJointsForSkeleton[skelType]; ++i)
\r
79 if(stricmp(tk_String, SKEL_NAMES[NAME_OFFSETS[skelType]+i]) == 0)
\r
81 i = -i + numJointsForSkeleton[skelType] - 1;
\r
83 TK_BeyondRequire(TK_NUM_CLUSTER_VERTICES, TK_INTNUMBER);
\r
85 num_verts[i+1] = tk_IntNumber;
\r
87 clusterList[i] = (int *) SafeMalloc(num_verts[i+1]*sizeof(int), "LoadHRCClustered");
\r
88 assert(clusterList[i]);
\r
89 // currently this function is only called by LoadTriangleListClustered, which in turn is only
\r
90 // called by Cmd_Base in qdata. This is where the only call to free for this memory is being made.
\r
92 TK_Beyond(TK_LBRACE);
\r
94 for(j = 0; j < num_verts[i+1]; ++j)
\r
96 TK_Require(TK_INTNUMBER);
\r
97 clusterList[i][j] = tk_IntNumber;
\r
106 num_verts[0] = numJointsForSkeleton[skelType];
\r
109 static void LoadHRCGlobals(char *fileName)
\r
113 TK_OpenSource(fileName);
\r
114 TK_FetchRequire(TK_HRCH);
\r
115 TK_FetchRequire(TK_COLON);
\r
116 TK_FetchRequire(TK_SOFTIMAGE);
\r
117 TK_Beyond(TK_MODEL);
\r
119 TK_Beyond(TK_SCALING);
\r
120 for(i = 0; i < 3; i++)
\r
122 TK_Require(TK_FLOATNUMBER);
\r
123 g_scaling[i] = tk_FloatNumber;
\r
127 TK_Beyond(TK_ROTATION);
\r
128 for(i = 0; i < 3; i++)
\r
130 TK_Require(TK_FLOATNUMBER);
\r
131 g_rotation[i] = tk_FloatNumber;
\r
135 TK_Beyond(TK_TRANSLATION);
\r
136 for(i = 0; i < 3; i++)
\r
138 TK_Require(TK_FLOATNUMBER);
\r
139 g_translation[i] = tk_FloatNumber;
\r
144 static void ParseVec3(vec3_t in)
\r
146 TK_Require(TK_FLOATNUMBER);
\r
147 in[1] = tk_FloatNumber;
\r
148 TK_FetchRequire(TK_FLOATNUMBER);
\r
149 in[2] = tk_FloatNumber;
\r
150 TK_FetchRequire(TK_FLOATNUMBER);
\r
151 in[0] = tk_FloatNumber;
\r
154 static void ParseRotation3(vec3_t in)
\r
156 TK_Require(TK_FLOATNUMBER);
\r
157 in[1] = -tk_FloatNumber;
\r
158 TK_FetchRequire(TK_FLOATNUMBER);
\r
159 in[2] = tk_FloatNumber;
\r
160 TK_FetchRequire(TK_FLOATNUMBER);
\r
161 in[0] = tk_FloatNumber;
\r
164 static void ParseTranslation3(vec3_t in)
\r
166 TK_Require(TK_FLOATNUMBER);
\r
167 in[1] = tk_FloatNumber;
\r
168 TK_FetchRequire(TK_FLOATNUMBER);
\r
169 in[2] = tk_FloatNumber;
\r
170 TK_FetchRequire(TK_FLOATNUMBER);
\r
171 in[0] = tk_FloatNumber;
\r
174 static void LoadHRCJointList(char *fileName, QDataJoint_t *jointList, int skelType)
\r
176 #define MAX_STACK 64
\r
178 vec3_t curTranslation[MAX_STACK], curRotation[MAX_STACK], curScale[MAX_STACK];
\r
179 int curCorrespondingJoint[MAX_STACK];
\r
180 int currentStack = 0, stackSize;
\r
182 float cx, sx, cy, sy, cz, sz;
\r
187 TK_OpenSource(fileName);
\r
188 TK_FetchRequire(TK_HRCH);
\r
189 TK_FetchRequire(TK_COLON);
\r
190 TK_FetchRequire(TK_SOFTIMAGE);
\r
192 TK_Beyond(TK_MODEL);
\r
193 TK_Beyond(TK_MODEL);
\r
197 TK_Beyond(TK_MODEL);
\r
198 TK_BeyondRequire(TK_NAME, TK_STRING);
\r
200 if(_stricmp(tk_String, SKEL_ROOT_NAMES[skelType]) == 0)
\r
204 TK_Beyond(TK_SCALING);
\r
206 ParseVec3(curScale[currentStack]);
\r
208 TK_Beyond(TK_ROTATION);
\r
210 ParseRotation3(curRotation[currentStack]);
\r
212 TK_Beyond(TK_TRANSLATION);
\r
214 ParseVec3(curTranslation[currentStack]);
\r
216 // account for global model translation
\r
217 curTranslation[currentStack][1] += g_translation[0];
\r
218 curTranslation[currentStack][2] += g_translation[1];
\r
219 curTranslation[currentStack][0] += g_translation[2];
\r
223 for(i = 0; i < NUM_JOINTS_RAVEN; ++i)
\r
227 TK_Beyond(TK_MODEL);
\r
229 // TK_BeyondRequire(TK_NAME, TK_STRING);
\r
231 // if(_stricmp(tk_String, SKEL_NAMES[NAME_OFFSETS[skelType]+i]) == 0)
\r
234 TK_Beyond(TK_SCALING);
\r
236 ParseVec3(curScale[currentStack]);
\r
238 TK_Beyond(TK_ROTATION);
\r
240 ParseRotation3(curRotation[currentStack]);
\r
242 TK_Beyond(TK_TRANSLATION);
\r
244 ParseVec3(curTranslation[currentStack]);
\r
246 curCorrespondingJoint[currentStack] = -1;
\r
251 TK_Beyond(TK_SCALING);
\r
253 ParseVec3(curScale[currentStack]);
\r
255 TK_Beyond(TK_ROTATION);
\r
257 ParseRotation3(curRotation[currentStack]);
\r
259 jointList[i].rotation[1] = curRotation[currentStack][1];
\r
260 jointList[i].rotation[2] = curRotation[currentStack][2];
\r
261 jointList[i].rotation[0] = curRotation[currentStack][0];
\r
263 TK_Beyond(TK_TRANSLATION);
\r
265 ParseVec3(curTranslation[currentStack]);
\r
267 jointList[i].placement.origin[1] = curTranslation[currentStack][1];
\r
268 jointList[i].placement.origin[2] = curTranslation[currentStack][2];
\r
269 jointList[i].placement.origin[0] = curTranslation[currentStack][0];
\r
271 jointList[i].placement.direction[1] = 7.5;
\r
272 jointList[i].placement.direction[2] = 0.0;
\r
273 jointList[i].placement.direction[0] = 0.0;
\r
275 jointList[i].placement.up[1] = 0.0;
\r
276 jointList[i].placement.up[2] = 7.5;
\r
277 jointList[i].placement.up[0] = 0.0;
\r
279 curCorrespondingJoint[currentStack] = i;
\r
284 stackSize = currentStack;
\r
286 for(i = 0; i < NUM_JOINTS_RAVEN; ++i)
\r
288 rx = jointList[i].rotation[0]*ANGLE_TO_RAD;
\r
289 ry = jointList[i].rotation[1]*ANGLE_TO_RAD;
\r
290 rz = jointList[i].rotation[2]*ANGLE_TO_RAD;
\r
301 // y-axis rotation for direction
\r
302 x2 = jointList[i].placement.direction[0]*cy+jointList[i].placement.direction[2]*sy;
\r
303 z2 = -jointList[i].placement.direction[0]*sy+jointList[i].placement.direction[2]*cy;
\r
304 jointList[i].placement.direction[0] = x2;
\r
305 jointList[i].placement.direction[2] = z2;
\r
307 // y-axis rotation for up
\r
308 x2 = jointList[i].placement.up[0]*cy+jointList[i].placement.up[2]*sy;
\r
309 z2 = -jointList[i].placement.up[0]*sy+jointList[i].placement.up[2]*cy;
\r
310 jointList[i].placement.up[0] = x2;
\r
311 jointList[i].placement.up[2] = z2;
\r
313 // z-axis rotation for direction
\r
314 x2 = jointList[i].placement.direction[0]*cz-jointList[i].placement.direction[1]*sz;
\r
315 y2 = jointList[i].placement.direction[0]*sz+jointList[i].placement.direction[1]*cz;
\r
316 jointList[i].placement.direction[0] = x2;
\r
317 jointList[i].placement.direction[1] = y2;
\r
319 // z-axis rotation for up
\r
320 x2 = jointList[i].placement.up[0]*cz-jointList[i].placement.up[1]*sz;
\r
321 y2 = jointList[i].placement.up[0]*sz+jointList[i].placement.up[1]*cz;
\r
322 jointList[i].placement.up[0] = x2;
\r
323 jointList[i].placement.up[1] = y2;
\r
325 // x-axis rotation for direction vector
\r
326 y2 = jointList[i].placement.direction[1]*cx-jointList[i].placement.direction[2]*sx;
\r
327 z2 = jointList[i].placement.direction[1]*sx+jointList[i].placement.direction[2]*cx;
\r
328 jointList[i].placement.direction[1] = y2;
\r
329 jointList[i].placement.direction[2] = z2;
\r
331 // x-axis rotation for up vector
\r
332 y2 = jointList[i].placement.up[1]*cx-jointList[i].placement.up[2]*sx;
\r
333 z2 = jointList[i].placement.up[1]*sx+jointList[i].placement.up[2]*cx;
\r
334 jointList[i].placement.up[1] = y2;
\r
335 jointList[i].placement.up[2] = z2;
\r
337 // translate to position in model
\r
338 jointList[i].placement.direction[0] += jointList[i].placement.origin[0];
\r
339 jointList[i].placement.direction[1] += jointList[i].placement.origin[1];
\r
340 jointList[i].placement.direction[2] += jointList[i].placement.origin[2];
\r
342 // translate to position in model
\r
343 jointList[i].placement.up[0] += jointList[i].placement.origin[0];
\r
344 jointList[i].placement.up[1] += jointList[i].placement.origin[1];
\r
345 jointList[i].placement.up[2] += jointList[i].placement.origin[2];
\r
348 baseJoint = NUM_JOINTS_RAVEN;
\r
350 for(i = stackSize/*NUM_JOINTS_RAVEN*/ - 1; i > 0; --i)
\r
353 rx = curRotation[i-1][0]*ANGLE_TO_RAD;
\r
354 ry = curRotation[i-1][1]*ANGLE_TO_RAD;
\r
355 rz = curRotation[i-1][2]*ANGLE_TO_RAD;
\r
366 for(j = i-1; j < stackSize-1; ++j)
\r
368 // y-axis rotation for origin
\r
369 x2 = jointList[j].placement.origin[0]*cy+jointList[j].placement.origin[2]*sy;
\r
370 z2 = -jointList[j].placement.origin[0]*sy+jointList[j].placement.origin[2]*cy;
\r
371 jointList[j].placement.origin[0] = x2;
\r
372 jointList[j].placement.origin[2] = z2;
\r
374 // y-axis rotation for direction
\r
375 x2 = jointList[j].placement.direction[0]*cy+jointList[j].placement.direction[2]*sy;
\r
376 z2 = -jointList[j].placement.direction[0]*sy+jointList[j].placement.direction[2]*cy;
\r
377 jointList[j].placement.direction[0] = x2;
\r
378 jointList[j].placement.direction[2] = z2;
\r
380 // y-axis rotation for up
\r
381 x2 = jointList[j].placement.up[0]*cy+jointList[j].placement.up[2]*sy;
\r
382 z2 = -jointList[j].placement.up[0]*sy+jointList[j].placement.up[2]*cy;
\r
383 jointList[j].placement.up[0] = x2;
\r
384 jointList[j].placement.up[2] = z2;
\r
386 // z-axis rotation for origin
\r
387 x2 = jointList[j].placement.origin[0]*cz-jointList[j].placement.origin[1]*sz;
\r
388 y2 = jointList[j].placement.origin[0]*sz+jointList[j].placement.origin[1]*cz;
\r
389 jointList[j].placement.origin[0] = x2;
\r
390 jointList[j].placement.origin[1] = y2;
\r
392 // z-axis rotation for direction
\r
393 x2 = jointList[j].placement.direction[0]*cz-jointList[j].placement.direction[1]*sz;
\r
394 y2 = jointList[j].placement.direction[0]*sz+jointList[j].placement.direction[1]*cz;
\r
395 jointList[j].placement.direction[0] = x2;
\r
396 jointList[j].placement.direction[1] = y2;
\r
398 // z-axis rotation for up
\r
399 x2 = jointList[j].placement.up[0]*cz-jointList[j].placement.up[1]*sz;
\r
400 y2 = jointList[j].placement.up[0]*sz+jointList[j].placement.up[1]*cz;
\r
401 jointList[j].placement.up[0] = x2;
\r
402 jointList[j].placement.up[1] = y2;
\r
404 // x-axis rotation for origin
\r
405 y2 = jointList[j].placement.origin[1]*cx-jointList[j].placement.origin[2]*sx;
\r
406 z2 = jointList[j].placement.origin[1]*sx+jointList[j].placement.origin[2]*cx;
\r
407 jointList[j].placement.origin[1] = y2;
\r
408 jointList[j].placement.origin[2] = z2;
\r
410 // x-axis rotation for direction vector
\r
411 y2 = jointList[j].placement.direction[1]*cx-jointList[j].placement.direction[2]*sx;
\r
412 z2 = jointList[j].placement.direction[1]*sx+jointList[j].placement.direction[2]*cx;
\r
413 jointList[j].placement.direction[1] = y2;
\r
414 jointList[j].placement.direction[2] = z2;
\r
416 // x-axis rotation for up vector
\r
417 y2 = jointList[j].placement.up[1]*cx-jointList[j].placement.up[2]*sx;
\r
418 z2 = jointList[j].placement.up[1]*sx+jointList[j].placement.up[2]*cx;
\r
419 jointList[j].placement.up[1] = y2;
\r
420 jointList[j].placement.up[2] = z2;
\r
422 if(curCorrespondingJoint[j+1] != -1)
\r
424 // translate origin
\r
425 jointList[j].placement.origin[0] += curTranslation[i-1][0];
\r
426 jointList[j].placement.origin[1] += curTranslation[i-1][1];
\r
427 jointList[j].placement.origin[2] += curTranslation[i-1][2];
\r
429 // translate back to local coord
\r
430 jointList[j].placement.direction[0] += curTranslation[i-1][0];
\r
431 jointList[j].placement.direction[1] += curTranslation[i-1][1];
\r
432 jointList[j].placement.direction[2] += curTranslation[i-1][2];
\r
434 // translate back to local coord
\r
435 jointList[j].placement.up[0] += curTranslation[i-1][0];
\r
436 jointList[j].placement.up[1] += curTranslation[i-1][1];
\r
437 jointList[j].placement.up[2] += curTranslation[i-1][2];
\r
443 void LoadGlobals(char *fileName)
\r
448 char InputFileName[256];
\r
450 dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
\r
454 strcpy(InputFileName, fileName);
\r
455 strcat(InputFileName, ".hrc");
\r
456 if((file1 = fopen(InputFileName, "rb")) != NULL)
\r
460 LoadHRCGlobals(InputFileName);
\r
462 printf(" - assuming .HRC\n");
\r
466 Error("\n Could not open file '%s':\n"
\r
467 "No HRC match.\n", fileName);
\r
471 if((file1 = fopen(fileName, "rb")) != NULL)
\r
475 if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
\r
477 LoadHRCGlobals(fileName);
\r
482 Error("Could not open file '%s':\n",fileName);
\r
486 void LoadClusters(char *fileName, int **clusterList, int *num_verts, int skelType)
\r
491 char InputFileName[256];
\r
493 dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
\r
497 strcpy(InputFileName, fileName);
\r
498 strcat(InputFileName, ".hrc");
\r
499 if((file1 = fopen(InputFileName, "rb")) != NULL)
\r
503 LoadHRCClustered(InputFileName, clusterList, num_verts, skelType);
\r
505 printf(" - assuming .HRC\n");
\r
509 Error("\n Could not open file '%s':\n"
\r
510 "No HRC match.\n", fileName);
\r
514 if((file1 = fopen(fileName, "rb")) != NULL)
\r
518 if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
\r
520 LoadHRCClustered(fileName, clusterList, num_verts, skelType);
\r
525 Error("Could not open file '%s':\n",fileName);
\r
529 void LoadJointList(char *fileName, QDataJoint_t *jointList, int skelType)
\r
534 char InputFileName[256];
\r
536 dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
\r
540 strcpy(InputFileName, fileName);
\r
541 strcat(InputFileName, ".hrc");
\r
542 if((file1 = fopen(InputFileName, "rb")) != NULL)
\r
546 LoadHRCJointList(InputFileName, jointList, skelType);
\r
548 printf(" - assuming .HRC\n");
\r
552 Error("\n Could not open file '%s':\n"
\r
553 "No HRC.\n", fileName);
\r
557 if((file1 = fopen(fileName, "rb")) != NULL)
\r
561 if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
\r
563 LoadHRCJointList(fileName, jointList, skelType);
\r
569 Error("Could not open file '%s':\n",fileName);
\r