2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // trilib.c: library for loading triangles from an Alias triangle file
35 #include "qd_skeletons.h"
38 // on disk representation of a face
39 #define FLOAT_START 99999.0
40 #define FLOAT_END -FLOAT_START
43 #define M_PI 3.14159265
46 float FixHTRRotateX = 0.0;
47 float FixHTRRotateY = 0.0;
48 float FixHTRRotateZ = 0.0;
49 float FixHTRTranslateX = 0.0;
50 float FixHTRTranslateY = 0.0;
51 float FixHTRTranslateZ = 0.0;
61 vector n; /* normal */
73 void ByteSwapTri (tf_triangle *tri)
77 for (i=0 ; i<sizeof(tf_triangle)/4 ; i++)
79 ((int *)tri)[i] = BigLong (((int *)tri)[i]);
83 void LoadTRI (char *filename, triangle_t **pptri, int *numtriangles, mesh_node_t **nodesList, int *num_mesh_nodes)
87 char name[256], tex[256];
98 *nodesList = (mesh_node_t *) SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
102 *((unsigned char *)&exitpattern + 0) = *((unsigned char *)&t + 3);
103 *((unsigned char *)&exitpattern + 1) = *((unsigned char *)&t + 2);
104 *((unsigned char *)&exitpattern + 2) = *((unsigned char *)&t + 1);
105 *((unsigned char *)&exitpattern + 3) = *((unsigned char *)&t + 0);
107 if ((input = fopen(filename, "rb")) == 0)
108 Error ("reader: could not open file '%s'", filename);
112 fread(&magic, sizeof(int), 1, input);
113 if (BigLong(magic) != MAGIC)
114 Error ("%s is not a Alias object separated triangle file, magic number is wrong.", filename);
116 ptri = malloc (MAXTRIANGLES * sizeof(triangle_t));
120 while (feof(input) == 0) {
121 if (fread(&start, sizeof(float), 1, input) < 1)
123 *(int *)&start = BigLong(*(int *)&start);
124 if (*(int *)&start != exitpattern)
126 if (start == FLOAT_START) {
127 /* Start of an object or group of objects. */
130 /* There are probably better ways to read a string from */
131 /* a file, but this does allow you to do error checking */
132 /* (which I'm not doing) on a per character basis. */
134 fread( &(name[i]), sizeof( char ), 1, input);
135 } while( name[i] != '\0' );
138 // fprintf(stdout,"OBJECT START: %s\n",name);
139 fread( &count, sizeof(int), 1, input);
140 count = BigLong(count);
144 // fprintf(stdout,"NUMBER OF TRIANGLES: %d\n",count);
149 fread( &(tex[i]), sizeof( char ), 1, input);
150 } while( tex[i] != '\0' );
153 // fprintf(stdout," Object texture name: '%s'\n",tex);
156 /* Else (count == 0) this is the start of a group, and */
157 /* no texture name is present. */
159 else if (start == FLOAT_END) {
160 /* End of an object or group. Yes, the name should be */
161 /* obvious from context, but it is in here just to be */
162 /* safe and to provide a little extra information for */
163 /* those who do not wish to write a recursive reader. */
169 fread( &(name[i]), sizeof( char ), 1, input);
170 } while( name[i] != '\0' );
173 // fprintf(stdout,"OBJECT END: %s\n",name);
179 // read the triangles
181 for (i = 0; i < count; ++i) {
184 fread( &tri, sizeof(tf_triangle), 1, input );
186 for (j=0 ; j<3 ; j++)
190 for (k=0 ; k<3 ; k++)
192 ptri->verts[j][k] = tri.pt[j].p.v[k];
198 if ((ptri - *pptri) >= MAXTRIANGLES)
199 Error ("Error: too many triangles; increase MAXTRIANGLES\n");
203 *numtriangles = ptri - *pptri;
207 DefaultNodesList(nodesList,num_mesh_nodes,numtriangles);
211 //==========================================================================
215 //==========================================================================
219 float translation[3];
220 static char *hrc_name;
227 void HandleHRCModel(triangle_t **triList, int *triangleCount, mesh_node_t **nodesList, int *num_mesh_nodes,
228 int ActiveNode, int Depth, int numVerts)
230 void ReadHRCClusterList(mesh_node_t *meshNode, int baseIndex);
236 mesh_node_t *meshNode;
240 tokenType_t nextToken;
241 float orig_scaling[3];
242 float orig_rotation[3];
243 float orig_translation[3];
251 TK_BeyondRequire(TK_NAME, TK_STRING);
253 if (Depth == 0 || tk_String[0] == '_')
255 ActiveNode = *num_mesh_nodes;
257 if ((*num_mesh_nodes) > MAX_FM_MESH_NODES)
259 Error("Too many mesh nodes in file %s\n", hrc_name);
261 meshNode = &(*nodesList)[ActiveNode];
263 // memset(meshNode, 0, sizeof(mesh_node_t));
264 strcpy(meshNode->name, tk_String);
266 memset(meshNode->tris, 0, sizeof(meshNode->tris));
267 memset(meshNode->verts, 0, sizeof(meshNode->verts));
269 meshNode->start_glcmds = 0;
270 meshNode->num_glcmds = 0;
274 { // Childs under the children
275 meshNode = &(*nodesList)[ActiveNode];
276 vertIndexBase = numVerts;
285 // Get the scaling, rotation, and translation values
286 TK_Beyond(TK_SCALING);
287 for(i = 0; i < 3; i++)
289 orig_scaling[i] = scaling[i];
291 TK_Require(TK_FLOATNUMBER);
292 scaling[i] *= tk_FloatNumber;
296 TK_Beyond(TK_ROTATION);
297 for(i = 0; i < 3; i++)
299 orig_rotation[i] = rotation[i];
301 TK_Require(TK_FLOATNUMBER);
302 rotation[i] = tk_FloatNumber;
306 TK_Beyond(TK_TRANSLATION);
307 for(i = 0; i < 3; i++)
309 orig_translation[i] = translation[i];
311 TK_Require(TK_FLOATNUMBER);
312 translation[i] += tk_FloatNumber;
317 rx = ((rotation[0]-90.0)/360.0)*2.0*M_PI;
318 ry = (rotation[2]/360.0)*2.0*M_PI;
319 rz = (rotation[1]/360.0)*2.0*M_PI;
321 // rjr - might not work if there an item doesn't have a mesh
322 nextToken = tk_Token;
323 if (nextToken == TK_ACTOR_DATA)
325 while (nextToken != TK_MODEL && nextToken != TK_RBRACE)
327 nextToken = TK_Fetch();
331 while (nextToken == TK_SPLINE)
332 { // spline node has two right braces
333 nextToken = TK_Beyond(TK_RBRACE);
334 nextToken = TK_Beyond(TK_RBRACE);
337 while (nextToken == TK_MATERIAL)
339 nextToken = TK_Beyond(TK_RBRACE);
342 while(nextToken == TK_MODEL)
344 HandleHRCModel(triList,triangleCount,nodesList,num_mesh_nodes,ActiveNode, Depth+1, 0);
346 nextToken = TK_Fetch();
349 if (nextToken == TK_MESH)
351 // Get all the tri and vertex info
352 TK_BeyondRequire(TK_VERTICES, TK_INTNUMBER);
353 vertexCount = tk_IntNumber;
354 for(i = 0; i < vertexCount; i++)
356 TK_BeyondRequire(TK_LBRACKET, TK_INTNUMBER);
357 if(tk_IntNumber != i)
359 Error("File '%s', line %d:\nVertex index mismatch.\n",
360 tk_SourceName, tk_Line);
362 TK_Beyond(TK_POSITION);
363 // Apply the scaling, rotation, and translation in the order
364 // specified in the HRC file. This could be wrong.
365 TK_Require(TK_FLOATNUMBER);
366 x = tk_FloatNumber*scaling[0];
367 TK_FetchRequire(TK_FLOATNUMBER);
368 y = tk_FloatNumber*scaling[1];
369 TK_FetchRequire(TK_FLOATNUMBER);
370 z = tk_FloatNumber*scaling[2];
372 y2 = y*cos(rx)+z*sin(rx);
373 z2 = -y*sin(rx)+z*cos(rx);
377 x2 = x*cos(ry)-z*sin(ry);
378 z2 = x*sin(ry)+z*cos(ry);
382 x2 = x*cos(rz)+y*sin(rz);
383 y2 = -x*sin(rz)+y*cos(rz);
387 vList[i].v[0] = x+translation[0];
388 vList[i].v[1] = y-translation[2];
389 vList[i].v[2] = z+translation[1];
391 TK_BeyondRequire(TK_POLYGONS, TK_INTNUMBER);
392 triCount = tk_IntNumber;
393 if(triCount >= MAXTRIANGLES)
395 Error("Too many triangles in file %s\n", hrc_name);
398 start_tri = *triangleCount;
399 *triangleCount += triCount;
403 for(i = 0; i < triCount; i++)
407 pos = (i + start_tri) >> 3;
408 bit = 1 << ((i + start_tri) & 7 );
409 meshNode->tris[pos] |= bit;
412 TK_BeyondRequire(TK_LBRACKET, TK_INTNUMBER);
413 if(tk_IntNumber != i)
415 Error("File '%s', line %d:\nTriangle index mismatch.\n",
416 tk_SourceName, tk_Line);
418 TK_BeyondRequire(TK_NODES, TK_INTNUMBER);
419 if(tk_IntNumber != 3)
421 Error("File '%s', line %d:\nBad polygon vertex count: %d.",
422 tk_SourceName, tk_Line, tk_IntNumber);
424 tList[i+start_tri].HasUV = true;
425 for(j = 0; j < 3; j++)
427 TK_BeyondRequire(TK_LBRACKET, TK_INTNUMBER);
428 if(tk_IntNumber != j)
430 Error("File '%s', line %d:\nTriangle vertex index"
431 " mismatch. %d should be %d\n", tk_SourceName, tk_Line,
434 TK_BeyondRequire(TK_VERTEX, TK_INTNUMBER);
436 tList[i+start_tri].verts[2-j][0] = vList[tk_IntNumber].v[0];
437 tList[i+start_tri].verts[2-j][1] = vList[tk_IntNumber].v[1];
438 tList[i+start_tri].verts[2-j][2] = vList[tk_IntNumber].v[2];
440 tList[i+start_tri].indicies[2-j] = tk_IntNumber+vertIndexBase;
442 TK_BeyondRequire(TK_UVTEXTURE, TK_FLOATNUMBER);
443 tList[i+start_tri].uv[2-j][0] = tk_FloatNumber;
445 TK_Require(TK_FLOATNUMBER);
446 tList[i+start_tri].uv[2-j][1] = tk_FloatNumber;
449 /* printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n"
450 " v2: %f, %f, %f\n", i,
451 tList[i].verts[0][0],
452 tList[i].verts[0][1],
453 tList[i].verts[0][2],
454 tList[i].verts[1][0],
455 tList[i].verts[1][1],
456 tList[i].verts[1][2],
457 tList[i].verts[2][0],
458 tList[i].verts[2][1],
459 tList[i].verts[2][2]);
463 TK_Beyond(TK_RBRACE);
464 TK_Beyond(TK_RBRACE);
466 if (tk_Token == TK_EDGES)
468 // TK_Beyond(TK_EDGES);
469 TK_Beyond(TK_RBRACE);
472 scaling[0] = scaling[1] = scaling[2] = 1.0;
473 // rotation[0] = rotation[1] = rotation[2] = 0.0;
474 // translation[0] = translation[1] = translation[2] = 0.0;
476 // See if there are any other models belonging to this node
481 nextToken = tk_Token;
482 if(nextToken == TK_CLUSTERS)
484 if(g_skelModel.clustered == -1)
486 ReadHRCClusterList(meshNode, vertIndexBase);
490 nextToken = TK_Get(TK_CLUSTER_NAME);
492 while (nextToken == TK_CLUSTER_NAME)
494 TK_BeyondRequire(TK_CLUSTER_STATE, TK_INTNUMBER);
495 nextToken = TK_Fetch();
499 // one right brace follow the list of clusters
500 nextToken = TK_Beyond(TK_RBRACE);
504 if(g_skelModel.clustered == -1 && !vertIndexBase)
506 meshNode->clustered = false;
511 nextToken = tk_Token;
512 if(nextToken == TK_SPLINE)
514 while (nextToken == TK_SPLINE)
515 { // spline node has two right braces
516 nextToken = TK_Beyond(TK_RBRACE);
517 nextToken = TK_Beyond(TK_RBRACE);
520 nextToken = TK_Beyond(TK_RBRACE);
523 while (nextToken == TK_MATERIAL)
525 nextToken = TK_Beyond(TK_RBRACE);
528 while(nextToken == TK_MODEL)
530 HandleHRCModel(triList,triangleCount,nodesList, num_mesh_nodes, ActiveNode, Depth+1, vertexCount+vertIndexBase);
532 nextToken = TK_Fetch();
538 scaling[i] = orig_scaling[i];
539 rotation[i] = orig_rotation[i];
540 translation[i] = orig_translation[i];
544 static void LoadHRC(char *fileName, triangle_t **triList, int *triangleCount, mesh_node_t **nodesList, int *num_mesh_nodes)
552 *nodesList = (mesh_node_t *) SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
558 scaling[0] = scaling[1] = scaling[2] = 1.0;
559 rotation[0] = rotation[1] = rotation[2] = 0.0;
560 translation[0] = translation[1] = translation[2] = 0.0;
563 *triList = (triangle_t *) SafeMalloc(MAXTRIANGLES*sizeof(triangle_t), "Triangle list");
564 memset(*triList,0,MAXTRIANGLES*sizeof(triangle_t));
566 TK_OpenSource(fileName);
567 TK_FetchRequire(TK_HRCH);
568 TK_FetchRequire(TK_COLON);
569 TK_FetchRequire(TK_SOFTIMAGE);
574 HandleHRCModel(triList, triangleCount, nodesList, num_mesh_nodes, 0, 0, 0);
578 //==========================================================================
582 //==========================================================================
586 void HandleHTRModel(triangle_t **triList, int *triangleCount, mesh_node_t **nodesList, int *num_mesh_nodes,
587 int ActiveNode, int Depth, int numVerts)
598 mesh_node_t *meshNode;
605 TK_BeyondRequire(TK_NAME, TK_STRING);
607 if (Depth == 0 || tk_String[0] == '_')
609 ActiveNode = *num_mesh_nodes;
611 if ((*num_mesh_nodes) > MAX_FM_MESH_NODES)
613 Error("Too many mesh nodes in file %s\n", hrc_name);
615 meshNode = &(*nodesList)[ActiveNode];
617 // memset(meshNode, 0, sizeof(mesh_node_t));
618 strcpy(meshNode->name, tk_String);
620 memset(meshNode->tris, 0, sizeof(meshNode->tris));
621 memset(meshNode->verts, 0, sizeof(meshNode->verts));
623 meshNode->start_glcmds = 0;
624 meshNode->num_glcmds = 0;
628 { // Childs under the children
629 meshNode = &(*nodesList)[ActiveNode];
630 vertIndexBase = numVerts;
639 TK_BeyondRequire(TK_VERTICES, TK_INTNUMBER);
640 vertexCount = tk_IntNumber;
642 // Get triangle count
643 TK_BeyondRequire(TK_FACES, TK_INTNUMBER);
644 triCount = tk_IntNumber;
645 if(triCount >= MAXTRIANGLES)
647 Error("Too many triangles in file %s\n", hrc_name);
651 TK_Beyond(TK_ORIGIN);
652 TK_Require(TK_FLOATNUMBER);
653 origin[0] = tk_FloatNumber;
654 TK_FetchRequire(TK_FLOATNUMBER);
655 origin[1] = tk_FloatNumber;
656 TK_FetchRequire(TK_FLOATNUMBER);
657 origin[2] = tk_FloatNumber;
659 //rx = 90.0/360.0*2.0*M_PI;
660 rx = FixHTRRotateX/360.0*2.0*M_PI;
661 ry = FixHTRRotateY/360.0*2.0*M_PI;
662 rz = FixHTRRotateZ/360.0*2.0*M_PI;
665 for(i = 0; i < vertexCount; i++)
667 TK_FetchRequire(TK_VERTEX);
668 TK_FetchRequire(TK_FLOATNUMBER);
669 x = tk_FloatNumber-origin[0];
670 TK_FetchRequire(TK_FLOATNUMBER);
671 y = tk_FloatNumber-origin[1];
672 TK_FetchRequire(TK_FLOATNUMBER);
673 z = tk_FloatNumber-origin[2];
675 x += FixHTRTranslateX;
676 y += FixHTRTranslateY;
677 z += FixHTRTranslateZ;
679 y2 = y*cos(rx)-z*sin(rx);
680 z2 = y*sin(rx)+z*cos(rx);
683 x2 = x*cos(ry)+z*sin(ry);
684 z2 = -x*sin(ry)+z*cos(ry);
687 x2 = x*cos(rz)-y*sin(rz);
688 y2 = x*sin(rz)+y*cos(rz);
697 start_tri = *triangleCount;
698 *triangleCount += triCount;
703 for(i = 0; i < triCount; i++)
707 pos = (i + start_tri) >> 3;
708 bit = 1 << ((i + start_tri) & 7 );
709 meshNode->tris[pos] |= bit;
712 TK_FetchRequire(TK_FACE);
713 TK_FetchRequire(TK_LPAREN);
714 for(j = 0; j < 3; j++)
716 TK_FetchRequire(TK_INTNUMBER);
717 vertexNum = tk_IntNumber-1;
718 if(vertexNum >= vertexCount)
720 Error("File '%s', line %d:\nVertex number"
721 " >= vertexCount: %d\n", tk_SourceName, tk_Line,
724 tList[i+start_tri].verts[2-j][0] = vList[vertexNum].v[0];
725 tList[i+start_tri].verts[2-j][1] = vList[vertexNum].v[1];
726 tList[i+start_tri].verts[2-j][2] = vList[vertexNum].v[2];
728 TK_FetchRequire(TK_RPAREN);
732 TK_FetchRequire(TK_FLOATNUMBER);
733 tList[i+start_tri].uv[0][0]=tk_FloatNumber;
734 TK_FetchRequire(TK_FLOATNUMBER);
735 tList[i+start_tri].uv[0][1]=tk_FloatNumber;
736 TK_FetchRequire(TK_FLOATNUMBER);
737 tList[i+start_tri].uv[1][0]=tk_FloatNumber;
738 TK_FetchRequire(TK_FLOATNUMBER);
739 tList[i+start_tri].uv[1][1]=tk_FloatNumber;
740 TK_FetchRequire(TK_FLOATNUMBER);
741 tList[i+start_tri].uv[2][0]=tk_FloatNumber;
742 TK_FetchRequire(TK_FLOATNUMBER);
743 tList[i+start_tri].uv[2][1]=tk_FloatNumber;
744 tList[i+start_tri].HasUV=1;
747 tList[i+start_tri].HasUV=0;
749 // printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n"
750 // " v2: %f, %f, %f\n", i,
751 // tList[i].verts[0][0],
752 // tList[i].verts[0][1],
753 // tList[i].verts[0][2],
754 // tList[i].verts[1][0],
755 // tList[i].verts[1][1],
756 // tList[i].verts[1][2],
757 // tList[i].verts[2][0],
758 // tList[i].verts[2][1],
759 // tList[i].verts[2][2]);
765 if (tk_Token == TK_VERTICES)
767 HandleHTRModel(triList,triangleCount,nodesList, num_mesh_nodes, ActiveNode, Depth+1, vertexCount+vertIndexBase);
771 static void LoadHTR(char *fileName, triangle_t **triList, int *triangleCount, mesh_node_t **nodesList, int *num_mesh_nodes)
779 *nodesList = SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
785 scaling[0] = scaling[1] = scaling[2] = 1.0;
786 rotation[0] = rotation[1] = rotation[2] = 0.0;
787 translation[0] = translation[1] = translation[2] = 0.0;
790 *triList = SafeMalloc(MAXTRIANGLES*sizeof(triangle_t), "Triangle list");
791 memset(*triList,0,MAXTRIANGLES*sizeof(triangle_t));
793 TK_OpenSource(fileName);
795 TK_Beyond(TK_C_HEXEN);
796 TK_Beyond(TK_C_TRIANGLES);
797 TK_BeyondRequire(TK_C_VERSION, TK_INTNUMBER);
798 if(tk_IntNumber != 1&&tk_IntNumber != 2)
800 Error("Unsupported version (%d) in file %s\n", tk_IntNumber,
803 Version2=(tk_IntNumber==2);
806 HandleHTRModel(triList, triangleCount, nodesList, num_mesh_nodes, 0, 0, 0);
811 static void LoadHTR(char *fileName, triangle_t **triList, int *triangleCount, mesh_node_t **nodesList, int *num_mesh_nodes)
831 *nodesList = (mesh_node_t *) SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
834 TK_OpenSource(fileName);
836 TK_Beyond(TK_C_HEXEN);
837 TK_Beyond(TK_C_TRIANGLES);
838 TK_BeyondRequire(TK_C_VERSION, TK_INTNUMBER);
839 if(tk_IntNumber != 1&&tk_IntNumber != 2)
841 Error("Unsupported version (%d) in file %s\n", tk_IntNumber,
844 Version2=(tk_IntNumber==2);
848 TK_BeyondRequire(TK_VERTICES, TK_INTNUMBER);
849 vertexCount = tk_IntNumber;
850 vList = (void *) SafeMalloc(vertexCount*sizeof vList[0], "Vertex list");
852 // Get triangle count
853 TK_BeyondRequire(TK_FACES, TK_INTNUMBER);
854 triCount = tk_IntNumber;
855 if(triCount >= MAXTRIANGLES)
857 Error("Too many triangles in file %s\n", fileName);
859 *triangleCount = triCount;
860 tList = (triangle_t *) SafeMalloc(MAXTRIANGLES*sizeof(triangle_t), "Triangle list");
862 memset(*triList,0,MAXTRIANGLES*sizeof(triangle_t));
865 TK_Beyond(TK_ORIGIN);
866 TK_Require(TK_FLOATNUMBER);
867 origin[0] = tk_FloatNumber;
868 TK_FetchRequire(TK_FLOATNUMBER);
869 origin[1] = tk_FloatNumber;
870 TK_FetchRequire(TK_FLOATNUMBER);
871 origin[2] = tk_FloatNumber;
873 //rx = 90.0/360.0*2.0*M_PI;
874 rx = FixHTRRotateX/360.0*2.0*M_PI;
875 ry = FixHTRRotateY/360.0*2.0*M_PI;
876 rz = FixHTRRotateZ/360.0*2.0*M_PI;
879 for(i = 0; i < vertexCount; i++)
881 TK_FetchRequire(TK_VERTEX);
882 TK_FetchRequire(TK_FLOATNUMBER);
883 x = tk_FloatNumber-origin[0];
884 TK_FetchRequire(TK_FLOATNUMBER);
885 y = tk_FloatNumber-origin[1];
886 TK_FetchRequire(TK_FLOATNUMBER);
887 z = tk_FloatNumber-origin[2];
889 x += FixHTRTranslateX;
890 y += FixHTRTranslateY;
891 z += FixHTRTranslateZ;
893 y2 = y*cos(rx)-z*sin(rx);
894 z2 = y*sin(rx)+z*cos(rx);
897 x2 = x*cos(ry)+z*sin(ry);
898 z2 = -x*sin(ry)+z*cos(ry);
901 x2 = x*cos(rz)-y*sin(rz);
902 y2 = x*sin(rz)+y*cos(rz);
912 for(i = 0; i < triCount; i++)
914 TK_FetchRequire(TK_FACE);
915 TK_FetchRequire(TK_LPAREN);
916 for(j = 0; j < 3; j++)
918 TK_FetchRequire(TK_INTNUMBER);
919 vertexNum = tk_IntNumber-1;
920 if(vertexNum >= vertexCount)
922 Error("File '%s', line %d:\nVertex number"
923 " >= vertexCount: %d\n", tk_SourceName, tk_Line,
926 tList[i].verts[2-j][0] = vList[vertexNum].v[0];
927 tList[i].verts[2-j][1] = vList[vertexNum].v[1];
928 tList[i].verts[2-j][2] = vList[vertexNum].v[2];
930 TK_FetchRequire(TK_RPAREN);
934 TK_FetchRequire(TK_FLOATNUMBER);
935 tList[i].uv[2][0]= fmod(1000+tk_FloatNumber,1);
936 TK_FetchRequire(TK_FLOATNUMBER);
937 tList[i].uv[2][1]=fmod(1000+tk_FloatNumber,1);
938 TK_FetchRequire(TK_FLOATNUMBER);
939 tList[i].uv[1][0]=fmod(1000+tk_FloatNumber,1);
940 TK_FetchRequire(TK_FLOATNUMBER);
941 tList[i].uv[1][1]=fmod(1000+tk_FloatNumber,1);
942 TK_FetchRequire(TK_FLOATNUMBER);
943 tList[i].uv[0][0]=fmod(1000+tk_FloatNumber,1);
944 TK_FetchRequire(TK_FLOATNUMBER);
945 tList[i].uv[0][1]=fmod(1000+tk_FloatNumber,1);
951 /* printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n"
952 " v2: %f, %f, %f\n", i,
953 tList[i].verts[0][0],
954 tList[i].verts[0][1],
955 tList[i].verts[0][2],
956 tList[i].verts[1][0],
957 tList[i].verts[1][1],
958 tList[i].verts[1][2],
959 tList[i].verts[2][0],
960 tList[i].verts[2][1],
961 tList[i].verts[2][2]);
967 DefaultNodesList(nodesList,num_mesh_nodes,triangleCount);
970 //==========================================================================
974 //==========================================================================
976 void LoadTriangleList(char *fileName, triangle_t **triList, int *triangleCount, mesh_node_t **ppmnodes, int *num_mesh_nodes)
981 char InputFileName[256];
983 dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
987 strcpy(InputFileName, fileName);
988 strcat(InputFileName, ".hrc");
989 if((file1 = fopen(InputFileName, "rb")) != NULL)
992 LoadHRC(InputFileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
993 printf(" - assuming .HRC\n");
997 strcpy(InputFileName, fileName);
998 strcat(InputFileName, ".asc");
999 if((file1 = fopen(InputFileName, "rb")) != NULL)
1002 LoadASC(InputFileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1003 printf(" - assuming .ASC\n");
1007 strcpy(InputFileName, fileName);
1008 strcat(InputFileName, ".tri");
1009 if((file1 = fopen(InputFileName, "rb")) != NULL)
1012 LoadTRI(InputFileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1013 printf(" - assuming .TRI\n");
1017 strcpy(InputFileName, fileName);
1018 strcat(InputFileName, ".3ds");
1019 if((file1 = fopen(InputFileName, "rb")) != NULL)
1022 Load3DSTriangleList (InputFileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1023 printf(" - assuming .3DS\n");
1027 strcpy(InputFileName, fileName);
1028 strcat(InputFileName, ".htr");
1029 if((file1 = fopen(InputFileName, "rb")) != NULL)
1032 LoadHTR (InputFileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1033 printf(" - assuming .HTR\n");
1036 Error("\n Could not open file '%s':\n"
1037 "No HRC, ASC, 3DS, HTR, or TRI match.\n", fileName);
1041 if((file1 = fopen(fileName, "rb")) != NULL)
1045 if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
1047 LoadHRC(fileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1049 else if (strcmp(dotstart,".asc") == 0 || strcmp(dotstart,".ASC") == 0)
1051 LoadASC(fileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1053 else if (strcmp(dotstart,".tri") == 0 || strcmp(dotstart,".TRI") == 0)
1055 LoadTRI(fileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1057 else if (strcmp(dotstart,".3ds") == 0 || strcmp(dotstart,".3DS") == 0)
1059 Load3DSTriangleList (fileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1061 else if (strcmp(dotstart,".htr") == 0 || strcmp(dotstart,".HTR") == 0)
1063 LoadHTR (fileName, triList, triangleCount, ppmnodes, num_mesh_nodes);
1067 Error("Could not open file '%s':\n",fileName);
1071 else //failed to load file
1073 Error("Could not open file '%s':\n",fileName);