Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mesh_bxm.cpp
Go to the documentation of this file.
1 #include "mesh_io.h"
2 #include "mesh_bxm.h"
3 #include "mesh.h"
4 #include "mesh_xml.h"
5 
6 #ifndef STANDALONE
7 #include "aux_texture.h"
8 #include "animation.h"
9 #include "faction_generic.h"
10 #endif
11 #include <assert.h>
12 
13 #include "vegastrike.h"
14 
15 string inverseblend[16] = {
16  "ZERO", "ZERO", "ONE", "SRCCOLOR", "INVSRCCOLOR", "SRCALPHA", "INVSRCALPHA",
17  "DESTALPHA", "INVDESTALPHA", "DESTCOLOR", "INVDESTCOLOR", "SRCALPHASAT", "CONSTALPHA", "INVCONSTALPHA",
18  "CONSTCOLOR", "INVCONSTCOLOR"
19 };
20 
21 void fcloseInput( FILE *fp )
22 {
23  fclose( fp );
24 }
25 
26 int aprintf( ... )
27 {
28  return 0;
29 }
30 
31 FILE * aopen( ... )
32 {
33  return NULL;
34 }
35 
36 #ifndef STANDALONE
37 
38 #define fprintf aprintf
39 #define fopen aopen
40 #define fclose aopen
41 
42 #else
43 
44 Texture * LoadTexture( string nam )
45 {
46  return new Texture( nam );
47 }
48 
49 Texture * LoadAnimation( string Name )
50 {
51  return new Animation( Name );
52 }
53 
54 #endif
55 
57 {
58  Mesh *m;
59  vector< float >sizes;
60  unsigned int num;
62  {
63  m = 0;
64  num = 0;
65  }
66 };
67 
68 //#define DLIST
69 
70 #ifdef DLIST
71 
72 #define GL_TRIANGLE (0)
73 #define GL_QUAD (0)
74 #define DLISTBEGINSTATE( stat ) \
75  do { \
76  if ( stat && (laststate != stat) ) { \
77  if (laststate != GL_COMPILE) glEnd(); \
78  glBegin( stat ); \
79  laststate = stat; \
80  } \
81  } \
82  while (0)
83 
84 #define DLISTENDSTATE( stat ) \
85  do { \
86  if ( stat && (laststate != GL_COMPILE) ) { \
87  glEnd(); \
88  laststate = GL_COMPILE; \
89  } \
90  } \
91  while (0)
92 
93 #define DLISTDOVERTEX( num ) \
94  do { \
95  glTexCoord2f( vtx.s, vtx.t ); \
96  glNormal3f( vtx.i, vtx.j, vtx.k ); \
97  glVertex3f( vtx.x*xml.scale.i, \
98  vtx.y*xml.scale.j, \
99  vtx.z*xml.scale.k \
100  ); \
101  } \
102  while (0)
103 
104 #else
105 
106 #define DLISTBEGINSTATE( stat )
107 #define DLISTDOVERTEX( num )
108 #define DLISTENDSTATE( stat )
109 
110 #endif
111 
112 //sets up the appropriate lists for the below functions to utilize
113 #define BEGIN_GL_LINES( expectitems ) \
114  do { \
115  xml.active_list = &xml.lines; xml.active_ind = &xml.lineind; xml.num_vertices = \
116  2; xml.active_list->reserve( 2*expectitems ); xml.active_ind->reserve( 2*expectitems ); \
117  } \
118  while (0)
119 
120 #define BEGIN_GL_TRIANGLES( expectitems ) \
121  do { \
122  xml.active_list = &xml.tris; xml.active_ind = &xml.triind; xml.num_vertices = 3; \
123  xml.active_list->reserve( 3*expectitems ); xml.active_ind->reserve( 3*expectitems ); \
124  } \
125  while (0)
126 
127 #define BEGIN_GL_TRIANGLE( expectitems ) \
128  do {xml.trishade.push_back( flatshade ); } \
129  while (0)
130 
131 #define BEGIN_GL_QUADS( expectitems ) \
132  do { \
133  xml.active_list = &xml.quads; xml.active_ind = &xml.quadind; xml.num_vertices = \
134  4; xml.active_list->reserve( 4*expectitems ); xml.active_ind->reserve( 4*expectitems ); \
135  } \
136  while (0)
137 
138 #define BEGIN_GL_QUAD( expectitems ) \
139  do {xml.quadshade.push_back( flatshade ); } \
140  while (0)
141 
142 #define BEGIN_GL_TRIANGLE_FAN( expectitems ) \
143  do { \
144  xml.trifans.push_back( std::vector< GFXVertex > () ); xml.active_list = \
145  &xml.trifans.back(); xml.tfancnt = xml.trifanind.size(); xml.active_ind = &xml.trifanind; xml.active_list->reserve( \
146  expectitems ); xml.active_ind->reserve( expectitems ); \
147  } \
148  while (0)
149 
150 #define BEGIN_GL_QUAD_STRIP( expectitems ) \
151  do { \
152  xml.num_vertices = 4; xml.quadstrips.push_back( vector< GFXVertex > () ); \
153  xml.active_list = &xml.quadstrips.back(); xml.qstrcnt = xml.quadstripind.size(); xml.active_ind = &xml.quadstripind; \
154  xml.active_list->reserve( expectitems ); xml.active_ind->reserve( expectitems ); \
155  } \
156  while (0)
157 
158 #define BEGIN_GL_TRIANGLE_STRIP( expectitems ) \
159  do { \
160  xml.num_vertices = 3; xml.tristrips.push_back( vector< GFXVertex > () ); \
161  xml.tstrcnt = xml.tristripind.size(); xml.active_ind = &xml.tristripind; xml.active_list->reserve( expectitems ); \
162  xml.active_ind->reserve( expectitems ); \
163  } \
164  while (0)
165 
166 #define BEGIN_GL_LINE_STRIP( expectitems ) \
167  do { \
168  xml.num_vertices = 2; xml.linestrips.push_back( vector< GFXVertex > () ); \
169  xml.active_list = &xml.linestrips.back(); xml.lstrcnt = xml.linestripind.size(); xml.active_ind = &xml.linestripind; \
170  xml.active_list->reserve( expectitems ); xml.active_ind->reserve( expectitems ); \
171  } \
172  while (0)
173 
174 #define END_GL_LINES
175 #define END_GL_TRIANGLES
176 #define END_GL_TRIANGLE
177 #define END_GL_QUADS
178 #define END_GL_QUAD
179 
180 #define END_GL_TRIANGLE_FAN \
181  do {xml.nrmltrifan.reserve( xml.trifanind.size()*3 ); \
182  for (unsigned int i = xml.tfancnt+2; i < xml.trifanind.size(); i++) { \
183  xml.nrmltrifan.push_back( xml.trifanind[xml.tfancnt] ); \
184  xml.nrmltrifan.push_back( xml.trifanind[i-1] ); \
185  xml.nrmltrifan.push_back( xml.trifanind[i] ); \
186  } \
187  } \
188  while (0)
189 
190 #define END_GL_QUAD_STRIP \
191  do {xml.nrmlquadstrip.reserve( xml.quadstripind.size()*(4/2) ); \
192  for (unsigned int i = xml.qstrcnt+3; i < xml.quadstripind.size(); i += 2) { \
193  xml.nrmlquadstrip.push_back( xml.quadstripind[i-3] ); \
194  xml.nrmlquadstrip.push_back( xml.quadstripind[i-2] ); \
195  xml.nrmlquadstrip.push_back( xml.quadstripind[i] ); \
196  xml.nrmlquadstrip.push_back( xml.quadstripind[i-1] ); \
197  } \
198  } \
199  while (0)
200 
201 #define END_GL_TRIANGLE_STRIP \
202  do {xml.nrmltristrip.reserve( xml.tristripind.size()*3 ); \
203  for (unsigned int i = xml.tstrcnt+2; i < xml.tristripind.size(); i++) { \
204  if ( (i-xml.tstrcnt)%2 ) { \
205  xml.nrmltristrip.push_back( xml.tristripind[i-2] ); \
206  xml.nrmltristrip.push_back( xml.tristripind[i-1] ); \
207  xml.nrmltristrip.push_back( xml.tristripind[i] ); \
208  } \
209  else { \
210  xml.nrmltristrip.push_back( xml.tristripind[i-1] ); \
211  xml.nrmltristrip.push_back( xml.tristripind[i-2] ); \
212  xml.nrmltristrip.push_back( xml.tristripind[i] ); \
213  } \
214  } \
215  } \
216  while (0)
217 
218 #define END_GL_LINE_STRIP \
219  do { \
220  xml.nrmllinstrip.reserve( xml.linestripind.size()*2 ); \
221  for (unsigned int i = xml.lstrcnt+1; i < xml.linestripind.size(); i++) { \
222  xml.nrmllinstrip.push_back( xml.linestripind[i-1] ); \
223  xml.nrmllinstrip.push_back( xml.linestripind[i] ); \
224  } \
225  } \
226  while (0)
227 
228 #define END_GL_COMPILE
229 
230 #define READSTRING( inmemfile, word32index, stringlen, stringvar ) \
231  do { /* By Klauss - Much more efficient than the preceding code, and yet still portable */ \
232  char8bit *inmemstring = (char8bit*) (inmemfile+word32index); \
233  char8bit oc = inmemstring[stringlen]; inmemstring[stringlen] = 0; \
234  stringvar = (const char*) inmemstring; \
235  inmemstring[stringlen] = oc; \
236  word32index += (stringlen+3)/4; \
237  } \
238  while (0)
239 
240 #define BEGINSTATE( stat, expectitems ) \
241  do {BEGIN_##stat( expectitems ); DLISTBEGINSTATE( stat ); } \
242  while (0)
243 
244 #define ENDSTATE( stat ) \
245  do {END_##stat; DLISTENDSTATE( stat ); } \
246  while (0)
247 
248 #define DOVERTEX( num ) \
249  do { \
250  vtx = xml.vertices[ind##num]; \
251  if (!xml.sharevert) { \
252  vtx.s = s##num; \
253  vtx.t = t##num; \
254  } \
255  xml.vertex = vtx; \
256  xml.vertexcount[ind##num] += 1; \
257  if ( (!vtx.i) && (!vtx.j) && (!vtx.k) && !xml.recalc_norm ) \
258  xml.recalc_norm = true; \
259  xml.active_list->push_back( xml.vertex ); \
260  xml.active_ind->push_back( ind##num ); \
261  xml.num_vertices--; \
262  DLISTDOVERTEX( stat ); \
263  } \
264  while (0)
265 
266 template < typename T >
267 void reverse_vector( vector< T > &vec )
268 {
269  vector< T >newvec;
270  for ( ; ( !vec.empty() ); vec.pop_back() )
271  newvec.push_back( vec.back() );
272  vec.swap( newvec );
273 }
274 
275 #ifdef STANDALONE
276 
277  #define bxmfprintf fprintf
278  #define bxmfopen fopen
279 
280 void Mesh::BFXMToXmesh( FILE *Inputfile, FILE *Outputfile, vector< Mesh* > &output, Vector overallscale, int fac )
281 {
282  Flightgroup *fg = 0;
283 
284 #else
285 
286 static inline void fignoref( FILE *f, ... ) {}
287 
288 static inline FILE * fignorefopen( const char*, const char* )
289 {
290  return 0;
291 }
292 
293  #define bxmfprintf fignoref
294  #define bxmfopen fignorefopen
295 
296 vector< Mesh* >Mesh::LoadMeshes( VSFileSystem::VSFile &Inputfile,
297  const Vector &scalex,
298  int faction,
299  class Flightgroup *fg,
300  std::string hash_name,
301  const std::vector< std::string > &overrideTextures )
302 {
303  Vector overallscale = scalex;
304  int fac = faction;
305  FILE *Outputfile = 0;
306  vector< Mesh* >output;
307 
308 #endif
309 
310  vector< OrigMeshLoader >meshes;
311  int32bit word32index = 0;
312  union chunk32
313  {
314  int32bit i32val;
315  float32bit f32val;
316  char8bit c8val[4];
317  }
318  *inmemfile;
319 #ifdef STANDALONE
320  printf( "Loading Mesh File: %s\n", Inputfile.GetFilename().c_str() );
321  fseek( Inputfile, 4+sizeof (int32bit), SEEK_SET );
322  fread( &intbuf, sizeof (int32bit), 1, Inputfile ); //Length of Inputfile
323  int32bit Inputlength = VSSwapHostIntToLittle( intbuf );
324  inmemfile = (chunk32*) malloc( Inputlength+1 );
325  if (!inmemfile) {
326  fprintf( stderr, "Buffer allocation failed, Aborting" );
327  exit( -1 );
328  }
329  rewind( Inputfile );
330  fread( inmemfile, 1, Inputlength, Inputfile );
331  fcloseInput( Inputfile );
332 #else
333  int32bit Inputlength = Inputfile.Size();
334  inmemfile = (chunk32*) malloc( Inputlength );
335  if (!inmemfile) {
336  fprintf( stderr, "Buffer allocation failed, Aborting" );
337  exit( -1 );
338  }
339  Inputfile.Read( inmemfile, Inputlength );
340  Inputfile.Close();
341 #endif
342  //Extract superheader fields
343  word32index += 3;
344  int32bit Superheaderlength = VSSwapHostIntToLittle( inmemfile[word32index].i32val );
345  int32bit NUMFIELDSPERVERTEX = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //Number of fields per vertex:integer (8)
346  int32bit NUMFIELDSPERPOLYGONSTRUCTURE = VSSwapHostIntToLittle( inmemfile[word32index+2].i32val ); //Number of fields per polygon structure: integer (1)
347  int32bit NUMFIELDSPERREFERENCEDVERTEX = VSSwapHostIntToLittle( inmemfile[word32index+3].i32val ); //Number of fields per referenced vertex: integer (3)
348  int32bit NUMFIELDSPERREFERENCEDANIMATION = VSSwapHostIntToLittle( inmemfile[word32index+4].i32val ); //Number of fields per referenced animation: integer (1)
349  int32bit numrecords = VSSwapHostIntToLittle( inmemfile[word32index+5].i32val ); //Number of records: integer
350  int32bit NUMFIELDSPERANIMATIONDEF = VSSwapHostIntToLittle( inmemfile[word32index+6].i32val ); //Number of fields per animationdef: integer (1)
351  word32index = (Superheaderlength/4); //Go to first record
352  //For each record
353  for (int32bit recordindex = 0; recordindex < numrecords; recordindex++) {
354  int32bit recordbeginword = word32index;
355  //Extract Record Header
356  int32bit recordheaderlength = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //length of record header in bytes
357  word32index += 1;
358  int32bit recordlength = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //length of record in bytes
359  word32index += 1;
360  int32bit nummeshes = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //Number of meshes in the current record
361  word32index = recordbeginword+(recordheaderlength/4);
362  meshes.push_back( OrigMeshLoader() );
363  meshes.back().num = nummeshes;
364  meshes.back().m = new Mesh[nummeshes];
365  meshes.back().sizes.insert( meshes.back().sizes.begin(), nummeshes, 0 );
366  //For each mesh
367  for (int32bit meshindex = 0; meshindex < nummeshes; meshindex++) {
368  Mesh *mesh = &meshes.back().m[meshindex];
369  mesh->draw_queue = new vector< MeshDrawContext >[NUM_ZBUF_SEQ+1];
370  MeshXML xml;
371  xml.fg = fg;
372  xml.faction = fac;
373  if (recordindex > 0 || meshindex > 0) {
374  char filenamebuf[56]; //Is more than enough characters - int can't be this big in decimal
375  int32bit error = sprintf( filenamebuf, "%d_%d.xmesh", recordindex, meshindex );
376  if (error == -1) //if wasn't enough characters - something is horribly wrong.
377  exit( error );
378  string filename = string( filenamebuf );
379  Outputfile = bxmfopen( filename.c_str(), "w+" );
380  }
381  //Extract Mesh Header
382  int32bit meshbeginword = word32index;
383  int32bit meshheaderlength = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //length of record header in bytes
384  word32index += 1;
385  int32bit meshlength = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //length of record in bytes
386  float32bit scale = VSSwapHostFloatToLittle( inmemfile[meshbeginword+2].f32val ); //scale
387  int32bit reverse = VSSwapHostIntToLittle( inmemfile[meshbeginword+3].i32val ); //reverse flag if
388  int32bit forcetexture = VSSwapHostIntToLittle( inmemfile[meshbeginword+4].i32val ); //force texture flag
389  int32bit sharevert = VSSwapHostIntToLittle( inmemfile[meshbeginword+5].i32val ); //share vertex flag
390  float32bit polygonoffset = VSSwapHostFloatToLittle( inmemfile[meshbeginword+6].f32val ); //polygonoffset
391  int32bit bsrc = VSSwapHostIntToLittle( inmemfile[meshbeginword+7].i32val ); //Blendmode source
392  int32bit bdst = VSSwapHostIntToLittle( inmemfile[meshbeginword+8].i32val ); //Blendmode destination
393  float32bit power = VSSwapHostFloatToLittle( inmemfile[meshbeginword+9].f32val ); //Specular: power
394  float32bit ar = VSSwapHostFloatToLittle( inmemfile[meshbeginword+10].f32val ); //Ambient: red
395  float32bit ag = VSSwapHostFloatToLittle( inmemfile[meshbeginword+11].f32val ); //Ambient: green
396  float32bit ab = VSSwapHostFloatToLittle( inmemfile[meshbeginword+12].f32val ); //Ambient: blue
397  float32bit aa = VSSwapHostFloatToLittle( inmemfile[meshbeginword+13].f32val ); //Ambient: Alpha
398  float32bit dr = VSSwapHostFloatToLittle( inmemfile[meshbeginword+14].f32val ); //Diffuse: red
399  float32bit dg = VSSwapHostFloatToLittle( inmemfile[meshbeginword+15].f32val ); //Diffuse: green
400  float32bit db = VSSwapHostFloatToLittle( inmemfile[meshbeginword+16].f32val ); //Diffuse: blue
401  float32bit da = VSSwapHostFloatToLittle( inmemfile[meshbeginword+17].f32val ); //Diffuse: Alpha
402  float32bit er = VSSwapHostFloatToLittle( inmemfile[meshbeginword+18].f32val ); //Emmissive: red
403  float32bit eg = VSSwapHostFloatToLittle( inmemfile[meshbeginword+19].f32val ); //Emmissive: green
404  float32bit eb = VSSwapHostFloatToLittle( inmemfile[meshbeginword+20].f32val ); //Emmissive: blue
405  float32bit ea = VSSwapHostFloatToLittle( inmemfile[meshbeginword+21].f32val ); //Emmissive: Alpha
406  float32bit sr = VSSwapHostFloatToLittle( inmemfile[meshbeginword+22].f32val ); //Specular: red
407  float32bit sg = VSSwapHostFloatToLittle( inmemfile[meshbeginword+23].f32val ); //Specular: green
408  float32bit sb = VSSwapHostFloatToLittle( inmemfile[meshbeginword+24].f32val ); //Specular: blue
409  float32bit sa = VSSwapHostFloatToLittle( inmemfile[meshbeginword+25].f32val ); //Specular: Alpha
410  int32bit cullface = VSSwapHostIntToLittle( inmemfile[meshbeginword+26].i32val ); //CullFace
411  int32bit lighting = VSSwapHostIntToLittle( inmemfile[meshbeginword+27].i32val ); //lighting
412  int32bit reflect = VSSwapHostIntToLittle( inmemfile[meshbeginword+28].i32val ); //reflect
413  int32bit usenormals = VSSwapHostIntToLittle( inmemfile[meshbeginword+29].i32val ); //usenormals
414  float32bit alphatest = 0;
415  if (meshheaderlength > 30*4)
416  alphatest = VSSwapHostFloatToLittle( inmemfile[meshbeginword+30].f32val ); //Alpha Testing Values
417  //End Header
418  //Go to Arbitrary Length Attributes section
419  word32index = meshbeginword+(meshheaderlength/4);
420  int32bit VSAbeginword = word32index;
421  int32bit LengthOfArbitraryLengthAttributes = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //Length of Arbitrary length attributes section in bytes
422  word32index += 1;
423  bxmfprintf(
424  Outputfile,
425  "<Mesh scale=\"%f\" reverse=\"%d\" forcetexture=\"%d\" sharevert=\"%d\" polygonoffset=\"%f\" blendmode=\"%s %s\" alphatest=\"%f\" ",
426  scale,
427  reverse,
428  forcetexture,
429  sharevert,
430  polygonoffset,
431  inverseblend[bsrc%16].c_str(),
432  inverseblend[bdst%16].c_str(),
433  alphatest );
434  xml.scale = scale*overallscale;
435  xml.lodscale = overallscale;
436  xml.reverse = reverse;
437  xml.force_texture = forcetexture;
438  xml.sharevert = sharevert;
439  if (alphatest <= 1 && alphatest >= 0)
440  mesh->alphatest = (unsigned char) (alphatest*255.0);
441  else if (alphatest > 1)
442  mesh->alphatest = 255;
443  else mesh->alphatest = 0;
444  mesh->polygon_offset = polygonoffset;
445  mesh->SetBlendMode( (BLENDFUNC) bsrc, (BLENDFUNC) bdst );
446 
447  string detailtexturename = "";
448  int32bit detailtexturenamelen = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //detailtexture name length
449  word32index += 1;
450  READSTRING( inmemfile, word32index, detailtexturenamelen, detailtexturename );
451  if (detailtexturename.size() != 0) {
452  bxmfprintf( Outputfile, " detailtexture=\"%s\" ", detailtexturename.c_str() );
453  mesh->detailTexture = mesh->TempGetTexture( &xml, detailtexturename, FactionUtil::GetFaction(
454  xml.faction ), GFXTRUE ); //LoadTexture(detailtexturename);
455  } else {
456  mesh->detailTexture = 0;
457  }
458  vector< Mesh_vec3f >Detailplanes; //store detail planes until finish printing mesh attributes
459  int32bit numdetailplanes = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of detailplanes
460  word32index += 1;
461  for (int32bit detailplane = 0; detailplane < numdetailplanes; detailplane++) {
462  float32bit x = VSSwapHostFloatToLittle( inmemfile[word32index].f32val ); //x-coord
463  float32bit y = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //y-coord
464  float32bit z = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //z-coord
465  word32index += 3;
466  Mesh_vec3f temp;
467  temp.x = x;
468  temp.y = y;
469  temp.z = z;
470  Detailplanes.push_back( temp );
471  } //End detail planes
472  //Textures
473  int32bit numtextures = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of textures
474  word32index += 1;
475  for (int32bit tex = 0; tex < numtextures; tex++) {
476  int32bit textype = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //texture type
477  int32bit texindex = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //texture index
478  int32bit texnamelen = VSSwapHostIntToLittle( inmemfile[word32index+2].i32val ); //texture name length
479  word32index += 3;
480  string texname = "";
481  /*int32bit namebound=(texnamelen+3)/4;
482  * for(stringindex=0;stringindex<namebound;stringindex++){
483  * for(int32bit bytenum=0;bytenum<4;bytenum++){ // Extract chars
484  * if(inmemfile[word32index].c8val[bytenum]){ //If not padding
485  * texname+=inmemfile[word32index].c8val[bytenum]; //Append char to end of string
486  * }
487  * }
488  * word32index+=1;
489  * }*/
490  READSTRING( inmemfile, word32index, texnamelen, texname );
491  switch (textype)
492  {
493  case ALPHAMAP:
494  bxmfprintf( Outputfile, " alphamap" );
495  break;
496  case ANIMATION:
497  bxmfprintf( Outputfile, " animation" );
498  break;
499  case TEXTURE:
500  bxmfprintf( Outputfile, " texture" );
501  break;
502  case TECHNIQUE:
503  bxmfprintf( Outputfile, " technique" );
504  break;
505  }
506  if (texindex)
507  bxmfprintf( Outputfile, "%d", texindex );
508  bxmfprintf( Outputfile, "=\"%s\" ", texname.c_str() );
509  if (textype == TECHNIQUE) {
510  xml.technique = texname;
511  } else {
512  while (mesh->Decal.size() <= (unsigned int) texindex)
513  mesh->Decal.push_back( 0 );
514  while (xml.decals.size() <= (unsigned int) texindex) {
516  xml.decals.push_back( z );
517  }
518  switch (textype)
519  {
520  case ALPHAMAP:
521  xml.decals[texindex].alpha_name = texname;
522  break;
523  case TEXTURE:
524  //mesh->Decal[texindex]=LoadTexture (texname);
525  xml.decals[texindex].decal_name = texname;
526  break;
527  case ANIMATION:
528  //mesh->Decal[texindex]=LoadAnimation(texname);
529  xml.decals[texindex].animated_name = texname;
530  break;
531  }
532  }
533  }
534  /*
535  * for (int LC=0;LC<overrideTextures.size();++LC) {
536  * if (overrideTextures[LC]!="") {
537  * while (xml.decals.size()<=LC) {
538  * MeshXML::ZeTexture z;
539  * xml.decals.push_back(z);
540  * }
541  * if (overrideTextures[LC].find(".ani")!=string::npos) {
542  * xml.decals[LC].decal_name="";
543  * xml.decals[LC].animated_name=overrideTextures[LC];
544  * xml.decals[LC].alpha_name="";
545  * }else {
546  * xml.decals[LC].animated_name="";
547  * xml.decals[LC].alpha_name="";
548  * xml.decals[LC].decal_name=overrideTextures[LC];
549  * }
550  * }
551  * }*/
552  bxmfprintf( Outputfile, ">\n" );
553  //End Textures
554  bxmfprintf( Outputfile,
555  "<Material power=\"%f\" cullface=\"%d\" reflect=\"%d\" lighting=\"%d\" usenormals=\"%d\">\n",
556  power,
557  cullface,
558  lighting,
559  reflect,
560  usenormals );
561  bxmfprintf( Outputfile, "\t<Ambient Red=\"%f\" Green=\"%f\" Blue=\"%f\" Alpha=\"%f\"/>\n", ar, ag, ab, aa );
562  bxmfprintf( Outputfile, "\t<Diffuse Red=\"%f\" Green=\"%f\" Blue=\"%f\" Alpha=\"%f\"/>\n", dr, dg, db, da );
563  bxmfprintf( Outputfile, "\t<Emissive Red=\"%f\" Green=\"%f\" Blue=\"%f\" Alpha=\"%f\"/>\n", er, eg, eb, ea );
564  bxmfprintf( Outputfile, "\t<Specular Red=\"%f\" Green=\"%f\" Blue=\"%f\" Alpha=\"%f\"/>\n", sr, sg, sb, sa );
565  bxmfprintf( Outputfile, "</Material>\n" );
566  mesh->setEnvMap( reflect );
567  mesh->forceCullFace( cullface );
568  static bool forcelight = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "ForceLighting", "true" ) );
569  mesh->setLighting( forcelight || lighting );
570  xml.usenormals = usenormals;
571  xml.material.ar = ar;
572  xml.material.ag = ag;
573  xml.material.ab = ab;
574  xml.material.aa = aa;
575  xml.material.dr = dr;
576  xml.material.dg = dg;
577  xml.material.db = db;
578  xml.material.da = da;
579  xml.material.er = er;
580  xml.material.eg = eg;
581  xml.material.eb = eb;
582  xml.material.ea = ea;
583  xml.material.sr = sr;
584  xml.material.sg = sg;
585  xml.material.sb = sb;
586  xml.material.sa = sa;
587  xml.material.power = power;
588 #ifdef STANDALONE
589  mesh->myMatNum = xml.material;
590 #endif
591  for (int32bit detplane = 0; (unsigned int) detplane < Detailplanes.size(); detplane++) {
592  bxmfprintf( Outputfile, "<DetailPlane x=\"%f\" y=\"%f\" z=\"%f\" />\n", Detailplanes[detplane].x,
593  Detailplanes[detplane].y, Detailplanes[detplane].z );
594  mesh->detailPlanes.push_back( Vector( Detailplanes[detplane].x,
595  Detailplanes[detplane].y,
596  Detailplanes[detplane].z ) );
597  }
598  //Logos
599  int32bit numlogos = VSSwapHostIntToLittle( inmemfile[word32index++].i32val ); //number of logos
600  for (int32bit logo = 0; logo < numlogos; logo++) {
601  float32bit size = VSSwapHostFloatToLittle( inmemfile[word32index].f32val ); //size
602  float32bit offset = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //offset
603  float32bit rotation = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //rotation
604  int32bit type = VSSwapHostIntToLittle( inmemfile[word32index+3].i32val ); //type
605  int32bit numrefs = VSSwapHostIntToLittle( inmemfile[word32index+4].i32val ); //number of reference points
606  bxmfprintf( Outputfile,
607  "<Logo type=\"%d\" rotate=\"%f\" size=\"%f\" offset=\"%f\">\n",
608  type,
609  rotation,
610  size,
611  offset );
612  struct MeshXML::ZeLogo l;
613  l.type = type;
614  l.rotate = rotation;
615  l.size = size;
616  l.offset = offset;
617  xml.logos.push_back( l );
618  xml.logos.back().type = type; //and again!
619  xml.logos.back().rotate = rotation;
620  xml.logos.back().size = size;
621  xml.logos.back().offset = offset;
622 
623  word32index += 5;
624  for (int32bit ref = 0; ref < numrefs; ref++) {
625  int32bit refnum = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //Logo ref
626  float32bit weight = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //reference weight
627  bxmfprintf( Outputfile, "\t<Ref point=\"%d\" weight=\"%f\"/>\n", refnum, weight );
628  xml.logos.back().refpnt.push_back( refnum );
629  xml.logos.back().refweight.push_back( weight );
630  word32index += 2;
631  }
632  bxmfprintf( Outputfile, "</Logo>\n" );
633  }
634  //End logos
635  //LODs
636  int32bit numLODs = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of LODs
637  word32index += 1;
638  for (int32bit LOD = 0; LOD < numLODs; LOD++) {
639  float32bit size = VSSwapHostFloatToLittle( inmemfile[word32index].f32val ); //Size
640  int32bit index = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //Mesh index
641  bxmfprintf( Outputfile, "<LOD size=\"%f\" meshfile=\"%d_%d.xmesh\"/>\n", size, recordindex, index );
642  meshes.back().sizes[LOD] = size;
643  word32index += 2;
644  }
645  //End LODs
646  //AnimationDefinitions
647  int32bit numanimdefs = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of animation definitions
648  word32index += 1;
649 #ifndef STANDALONE
650  if (meshindex == 0)
651  for (int framecount = numLODs+1; framecount < nummeshes; framecount++)
652  bxmfprintf( Outputfile, "<Frame FrameMeshName=\"%d_%d.xmesh\"/>\n", recordindex, framecount );
653 #endif
654  for (int32bit anim = 0; anim < numanimdefs; anim++) {
655  int32bit animnamelen = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //length of name
656  word32index += 1;
657  string animname;
658  READSTRING( inmemfile, word32index, animnamelen, animname );
659  float32bit FPS = VSSwapHostFloatToLittle( inmemfile[word32index].f32val ); //FPS
660  bxmfprintf( Outputfile, "<AnimationDefinition AnimationName=\"%s\" FPS=\"%f\">\n", animname.c_str(), FPS );
661 
662  vector< int > *framerefs = new vector< int >;
663  mesh->framespersecond = FPS;
664  word32index += NUMFIELDSPERANIMATIONDEF;
665  int32bit numframerefs = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of animation frame references
666  word32index += 1;
667  for (int32bit fref = 0; fref < numframerefs; fref++) {
668  int32bit ref = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of animation frame references
669  word32index += NUMFIELDSPERREFERENCEDANIMATION;
670  bxmfprintf( Outputfile, "<AnimationFrameIndex AnimationMeshIndex=\"%d\"/>\n", ref-1-numLODs );
671  framerefs->push_back( ref );
672  }
673  animationSequences.Put( hash_name+animname, framerefs );
674  bxmfprintf( Outputfile, "</AnimationDefinition>\n" );
675  }
676  //End AnimationDefinitions
677  //End VSA
678  //go to geometry
679  word32index = VSAbeginword+(LengthOfArbitraryLengthAttributes/4);
680  //Vertices
681  bxmfprintf( Outputfile, "<Points>\n" );
682  int32bit numvertices = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
683  word32index += 1;
684  xml.vertices.reserve( xml.vertices.size()+numvertices );
685  xml.vertexcount.reserve( xml.vertexcount.size()+numvertices );
686  for (int32bit vert = 0; vert < numvertices; vert++) {
687  float32bit x = VSSwapHostFloatToLittle( inmemfile[word32index].f32val ); //x
688  float32bit y = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //y
689  float32bit z = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //z
690  float32bit i = VSSwapHostFloatToLittle( inmemfile[word32index+3].f32val ); //i
691  float32bit j = VSSwapHostFloatToLittle( inmemfile[word32index+4].f32val ); //j
692  float32bit k = VSSwapHostFloatToLittle( inmemfile[word32index+5].f32val ); //k
693  if (i == 0 && j == 0 && k == 0) {
694  i = x;
695  j = y;
696  k = z;
697  float ms = i*i+j*j+k*k;
698  if (ms > .000001) {
699  float m = 1.0f/sqrt( ms );
700  i *= m;
701  j *= m;
702  k *= m;
703  } else {
704  i = 0;
705  j = 0;
706  k = 1;
707  }
708  }
709  float32bit s = VSSwapHostFloatToLittle( inmemfile[word32index+6].f32val ); //s
710  float32bit t = VSSwapHostFloatToLittle( inmemfile[word32index+7].f32val ); //t
711  word32index += NUMFIELDSPERVERTEX;
712  bxmfprintf(
713  Outputfile,
714  "<Point>\n\t<Location x=\"%f\" y=\"%f\" z=\"%f\" s=\"%f\" t=\"%f\"/>\n\t<Normal i=\"%f\" j=\"%f\" k=\"%f\"/>\n</Point>\n",
715  x,
716  y,
717  z,
718  s,
719  t,
720  i,
721  j,
722  k );
723  xml.vertices.push_back( GFXVertex( Vector( x, y, z ), Vector( i, j, k ), s, t ) );
724  //NOTE: postprocessing takes care of scale |-
725  xml.vertexcount.push_back( 0 );
726  }
727  bxmfprintf( Outputfile, "</Points>\n" );
728  //End Vertices
729  //Lines
730  GFXVertex vtx;
731 #ifdef DLIST
732  static GLenum laststate = GL_COMPILE;
733  mesh->vlist = glGenLists( 1 );
734  glNewList( mesh->vlist, GL_COMPILE );
735 #endif
736  bxmfprintf( Outputfile, "<Polygons>\n" );
737  int32bit numlines = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
738  word32index += 1;
739  BEGINSTATE( GL_LINES, numlines );
740  for (int32bit rvert = 0; rvert < numlines; rvert++) {
741  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //flatshade
742  word32index += NUMFIELDSPERPOLYGONSTRUCTURE;
743  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
744  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
745  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
746  word32index += NUMFIELDSPERREFERENCEDVERTEX;
747  int32bit ind2 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 2
748  float32bit s2 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
749  float32bit t2 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
750  word32index += NUMFIELDSPERREFERENCEDVERTEX;
751  bxmfprintf(
752  Outputfile,
753  "\t<Line flatshade=\"%d\">\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t</Line>\n",
754  flatshade,
755  ind1,
756  s1,
757  t1,
758  ind2,
759  s2,
760  t2 );
761 
762  DOVERTEX( 1 );
763  DOVERTEX( 2 );
764  }
765  ENDSTATE( GL_LINES );
766  //End Lines
767  //Triangles
768  int32bit numtris = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
769  word32index += 1;
770  BEGINSTATE( GL_TRIANGLES, numtris );
771  for (int32bit rtvert = 0; rtvert < numtris; rtvert++) {
772  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //flatshade
773  word32index += NUMFIELDSPERPOLYGONSTRUCTURE;
774  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
775  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
776  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
777  word32index += NUMFIELDSPERREFERENCEDVERTEX;
778  int32bit ind2 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 2
779  float32bit s2 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
780  float32bit t2 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
781  word32index += NUMFIELDSPERREFERENCEDVERTEX;
782  int32bit ind3 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 3
783  float32bit s3 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
784  float32bit t3 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
785  word32index += NUMFIELDSPERREFERENCEDVERTEX;
786  bxmfprintf(
787  Outputfile,
788  "\t<Tri flatshade=\"%d\">\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t</Tri>\n",
789  flatshade,
790  ind1,
791  s1,
792  t1,
793  ind2,
794  s2,
795  t2,
796  ind3,
797  s3,
798  t3 );
799 
800  BEGINSTATE( GL_TRIANGLE, 3 );
801  DOVERTEX( 1 );
802  DOVERTEX( 2 );
803  DOVERTEX( 3 );
804  ENDSTATE( GL_TRIANGLE );
805  }
806  ENDSTATE( GL_TRIANGLES );
807  //End Triangles
808  //Quads
809  int32bit numquads = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
810  word32index += 1;
811  BEGINSTATE( GL_QUADS, numquads );
812  for (int32bit rqvert = 0; rqvert < numquads; rqvert++) {
813  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //flatshade
814  word32index += NUMFIELDSPERPOLYGONSTRUCTURE;
815  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
816  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
817  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
818  word32index += NUMFIELDSPERREFERENCEDVERTEX;
819  int32bit ind2 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 2
820  float32bit s2 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
821  float32bit t2 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
822  word32index += NUMFIELDSPERREFERENCEDVERTEX;
823  int32bit ind3 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 3
824  float32bit s3 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
825  float32bit t3 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
826  word32index += NUMFIELDSPERREFERENCEDVERTEX;
827  int32bit ind4 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 3
828  float32bit s4 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
829  float32bit t4 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
830  word32index += NUMFIELDSPERREFERENCEDVERTEX;
831  bxmfprintf(
832  Outputfile,
833  "\t<Quad flatshade=\"%d\">\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n\t</Quad>\n",
834  flatshade,
835  ind1,
836  s1,
837  t1,
838  ind2,
839  s2,
840  t2,
841  ind3,
842  s3,
843  t3,
844  ind4,
845  s4,
846  t4 );
847 
848  BEGINSTATE( GL_QUAD, 4 );
849  DOVERTEX( 1 );
850  DOVERTEX( 2 );
851  DOVERTEX( 3 );
852  DOVERTEX( 4 );
853  ENDSTATE( GL_QUAD );
854  }
855  ENDSTATE( GL_QUADS );
856  //End Quads
857  //Linestrips
858  int32bit numlinestrips = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
859  word32index += 1;
860  for (int32bit lstrip = 0; lstrip < numlinestrips; lstrip++) {
861  int32bit numstripelements = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
862  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //flatshade
863  bxmfprintf( Outputfile, "\t<Linestrip flatshade=\"%d\">\n", flatshade );
864 
865  BEGINSTATE( GL_LINE_STRIP, numstripelements );
866  word32index += 1+NUMFIELDSPERPOLYGONSTRUCTURE;
867  for (int32bit elem = 0; elem < numstripelements; elem++) {
868  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
869  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
870  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
871  word32index += NUMFIELDSPERREFERENCEDVERTEX;
872  bxmfprintf( Outputfile, "\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n", ind1, s1, t1 );
873  DOVERTEX( 1 );
874  }
875  bxmfprintf( Outputfile, "\t</Linestrip>" );
876  ENDSTATE( GL_LINE_STRIP );
877  }
878  //End Linestrips
879  //Tristrips
880  int32bit numtristrips = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
881  word32index += 1;
882  for (int32bit tstrip = 0; tstrip < numtristrips; tstrip++) {
883  int32bit numstripelements = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
884  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //flatshade
885  bxmfprintf( Outputfile, "\t<Tristrip flatshade=\"%d\">\n", flatshade );
886  BEGINSTATE( GL_TRIANGLE_STRIP, numstripelements );
887  word32index += 1+NUMFIELDSPERPOLYGONSTRUCTURE;
888  for (int32bit elem = 0; elem < numstripelements; elem++) {
889  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
890  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
891  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
892  word32index += NUMFIELDSPERREFERENCEDVERTEX;
893  bxmfprintf( Outputfile, "\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n", ind1, s1, t1 );
894  DOVERTEX( 1 );
895  }
896  bxmfprintf( Outputfile, "\t</Tristrip>" );
897  ENDSTATE( GL_TRIANGLE_STRIP );
898  }
899  //End Tristrips
900  //Trifans
901  int32bit numtrifans = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
902  word32index += 1;
903  for (int32bit tfan = 0; tfan < numtrifans; tfan++) {
904  int32bit numstripelements = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
905  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //flatshade
906  bxmfprintf( Outputfile, "\t<Trifan flatshade=\"%d\">\n", flatshade );
907  BEGINSTATE( GL_TRIANGLE_FAN, numstripelements );
908  word32index += 1+NUMFIELDSPERPOLYGONSTRUCTURE;
909  for (int32bit elem = 0; elem < numstripelements; elem++) {
910  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
911  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
912  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
913  word32index += NUMFIELDSPERREFERENCEDVERTEX;
914  bxmfprintf( Outputfile, "\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n", ind1, s1, t1 );
915  DOVERTEX( 1 );
916  }
917  bxmfprintf( Outputfile, "\t</Trifan>" );
918  ENDSTATE( GL_TRIANGLE_FAN );
919  }
920  //End Trifans
921  //Quadstrips
922  int32bit numquadstrips = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
923  word32index += 1;
924  for (int32bit qstrip = 0; qstrip < numquadstrips; qstrip++) {
925  int32bit numstripelements = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //number of vertices
926  int32bit flatshade = VSSwapHostIntToLittle( inmemfile[word32index+1].i32val ); //flatshade
927  bxmfprintf( Outputfile, "\t<Quadstrip flatshade=\"%d\">\n", flatshade );
928  BEGINSTATE( GL_QUAD_STRIP, numstripelements );
929  word32index += 1+NUMFIELDSPERPOLYGONSTRUCTURE;
930  for (int32bit elem = 0; elem < numstripelements; elem++) {
931  int32bit ind1 = VSSwapHostIntToLittle( inmemfile[word32index].i32val ); //index 1
932  float32bit s1 = VSSwapHostFloatToLittle( inmemfile[word32index+1].f32val ); //s
933  float32bit t1 = VSSwapHostFloatToLittle( inmemfile[word32index+2].f32val ); //t
934  word32index += NUMFIELDSPERREFERENCEDVERTEX;
935  bxmfprintf( Outputfile, "\t\t<Vertex point=\"%d\" s=\"%f\" t=\"%f\"/>\n", ind1, s1, t1 );
936  DOVERTEX( 1 );
937  }
938  bxmfprintf( Outputfile, "\t</Quadstrip>" );
939  ENDSTATE( GL_QUAD_STRIP );
940  }
941  //End Quadstrips
942  ENDSTATE( GL_COMPILE );
943 #ifdef DLIST
944  glEndList();
945 #endif
946  if (reverse) {
947  //Reverse all vectors
948  vector< vector< GFXVertex > >::iterator iter;
949  reverse_vector( xml.lines );
950  reverse_vector( xml.lineind );
951  reverse_vector( xml.tris );
952  reverse_vector( xml.triind );
953  reverse_vector( xml.quads );
954  reverse_vector( xml.quadind );
955  for (iter = xml.trifans.begin(); iter != xml.trifans.end(); iter++)
956  reverse_vector( *iter );
957  for (iter = xml.quadstrips.begin(); iter != xml.quadstrips.end(); iter++)
958  reverse_vector( *iter );
959  for (iter = xml.tristrips.begin(); iter != xml.tristrips.end(); iter++)
960  reverse_vector( *iter );
961  for (iter = xml.linestrips.begin(); iter != xml.linestrips.end(); iter++)
962  reverse_vector( *iter );
966  }
967  bxmfprintf( Outputfile, "</Polygons>\n" );
968  //End Geometry
969  //go to next mesh
970  bxmfprintf( Outputfile, "</Mesh>\n" );
971  mesh->PostProcessLoading( &xml, overrideTextures );
972  word32index = meshbeginword+(meshlength/4);
973  }
974  //go to next record
975  word32index = recordbeginword+(recordlength/4);
976  output.push_back( new Mesh() );
977  *output.back() = *meshes.back().m; //use builtin
978  output.back()->orig = meshes.back().m;
979  for (int i = 0; i < (int) meshes.back().sizes.size()-1; ++i)
980  output.back()->orig[i+1].lodsize = meshes.back().sizes[i];
981  output.back()->numlods = output.back()->orig->numlods = meshes.back().num;
982  }
983  free( inmemfile );
984  inmemfile = NULL;
985 #ifndef STANDALONE
986  return output;
987 #endif
988 }
989