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 Class Reference

#include <mesh.h>

Inheritance diagram for Mesh:
Box RingMesh SphereMesh CityLights

Public Member Functions

void initTechnique (const string &technique)
 
TechniquePtr getTechnique () const
 
void setTechnique (TechniquePtr tech)
 
bool LoadExistant (Mesh *mesh)
 Loads a mesh that has been found in the hash table into this mesh (copying original data) More...
 
bool LoadExistant (const string filehash, const Vector &scale, int faction)
 
 Mesh ()
 
 Mesh (const Mesh &m)
 
GFXVertexListgetVertexList () const
 
void setVertexList (GFXVertexList *_vlist)
 
float getFramesPerSecond () const
 
float getCurrentFrame () const
 
void setCurrentFrame (float)
 
int getNumAnimationFrames (const string &which=string()) const
 
int getNumLOD () const
 
int getNumTextureFrames () const
 
float getTextureFramesPerSecond () const
 
double getTextureCumulativeTime () const
 
void setTextureCumulativeTime (double)
 
bool getConvex () const
 
void setConvex (bool b)
 
virtual int MeshType () const
 
BLENDFUNC getBlendSrc () const
 
BLENDFUNC getBlendDst () const
 
void Fork (Mesh *&one, Mesh *&two, float a, float b, float c, float d)
 Forks the mesh across the plane a,b,c,d into two separate meshes...upon which this may be deleted. More...
 
virtual ~Mesh ()
 Destructor... kills orig if refcount of orig becomes zero. More...
 
unsigned int numFX () const
 Gets number of specialFX. More...
 
void EnableSpecialFX ()
 Turns on SpecialFX. More...
 
unsigned int numTextures () const
 
Texturetexture (int i) const
 
void SetBlendMode (BLENDFUNC src, BLENDFUNC dst, bool lodcascade=false)
 
void GetPolys (vector< mesh_polygon > &)
 Gets all polygons in this mesh for collision computation. More...
 
void SetMaterial (const GFXMaterial &mat)
 Sets the material of this mesh to mat (affects original as well) More...
 
const GFXMaterialGetMaterial () const
 
GFXBOOL HasBeenDrawn () const
 If it has already been drawn this frame. More...
 
void UnDraw ()
 so one can query if it has or not been drawn More...
 
Vector const & Position () const
 Returns center of this mesh. More...
 
void Draw (float lod, const Matrix &m=identity_matrix, float toofar=1, int cloak=-1, float nebdist=0, unsigned char damage=0, bool renormalize_normals=false, const MeshFX *mfx=NULL)
 Draws lod pixel wide mesh at Transformation LATER. More...
 
void DrawNow (float lod, bool centered, const Matrix &m=identity_matrix, int cloak=-1, float nebdist=0)
 Draws lod pixels wide, mesh at Transformation NOW. If centered, then will center on camera and disable cull. More...
 
virtual void ProcessDrawQueue (size_t whichpass, int whichdrawqueue, bool zsort, const QVector &sortctr)
 Will draw all undrawn meshes of this type. More...
 
virtual void SelectCullFace (int whichdrawqueue)
 Will draw all undrawn far meshes beyond the range of zbuffer (better be convex). More...
 
virtual void RestoreCullFace (int whichdrawqueue)
 
void forceCullFace (GFXBOOL newValue)
 Sets whether or not this unit should be environment mapped. More...
 
GFXBOOL getCullFaceForcedOn () const
 
GFXBOOL getCullFaceForcedOff () const
 
void setEnvMap (GFXBOOL newValue, bool lodcascade=false)
 
GFXBOOL getEnvMap () const
 
void setLighting (GFXBOOL newValue, bool lodcascade=false)
 
GFXBOOL getLighting () const
 
Vector corner_min ()
 Returns bounding box values. More...
 
Vector corner_max ()
 
BoundingBox * getBoundingBox ()
 Returns a physical boudning box in 3space instead of in current unit space. More...
 
bool queryBoundingBox (const QVector &start, const float err) const
 queries this bounding box with a vector and radius More...
 
bool queryBoundingBox (const QVector &start, const QVector &end, const float err) const
 Queries bounding box with a ray. More...
 
float rSize () const
 returns the radial size of this More...
 
virtual float clipRadialSize () const
 
void UpdateFX (float ttime)
 based on TTL, etc, updates shield effects More...
 
void AddDamageFX (const Vector &LocalPos, const Vector &LocalNorm, const float percentage, const GFXColor &color=GFXColor(1, 1, 1, 1))
 Adds a new damage effect with age damage to the part of the unit. Color specifies the shield oclor. More...
 
void setVirtualBoundingBox (const Vector &mn, const Vector &mx, float rsize)
 

Static Public Member Functions

static MeshLoadMesh (const char *filename, const Vector &scalex, int faction, class Flightgroup *fg, const std::vector< std::string > &textureOverride=std::vector< std::string >())
 Loading a mesh from an XML file. faction specifies the logos. Orig is for internal (LOD) use only! More...
 
static vector< Mesh * > LoadMeshes (const char *filename, const Vector &scalex, int faction, class Flightgroup *fg, const std::vector< std::string > &textureOverride=std::vector< std::string >())
 
static vector< Mesh * > LoadMeshes (VSFileSystem::VSFile &f, const Vector &scalex, int faction, class Flightgroup *fg, std::string hash_name, const std::vector< std::string > &textureOverride=std::vector< std::string >())
 
static void ProcessZFarMeshes (bool nocamerasetup=false)
 
static void ProcessUndrawnMeshes (bool pushSpecialEffects=false, bool nocamerasetup=false)
 Will draw all undrawn meshes in total If pushSpclFX, the last series of meshes will be drawn with other lighting off. More...
 

Protected Member Functions

void PostProcessLoading (struct MeshXML *xml, const vector< string > &overrideTexture)
 
 Mesh (std::string filename, const Vector &scalex, int faction, class Flightgroup *fg, bool orig=false)
 
void InitUnit ()
 Setting all values to defaults (good for mesh copying and stuff) More...
 
MeshgetLOD (float lod, bool bBypassDamping=true)
 Returing the mesh relevant to "size" pixels LOD of this mesh. More...
 

Protected Attributes

Vector local_pos
 the position of the center of this mesh for collision detection More...
 
int refcount
 The refcount:: how many meshes are referencing the appropriate original. More...
 
Vector mx
 bounding box More...
 
Vector mn
 
float radialSize
 The radial size of this mesh. More...
 
int numlods
 num lods contained in the array of Mesh "orig" More...
 
float framespersecond
 
Meshorig
 
float lodsize
 The size that this LOD (if original) comes into effect. More...
 
Logoforcelogos
 The number of force logos on this mesh (original) More...
 
int numforcelogo
 
Logosquadlogos
 The number of squad logos on this mesh (original) More...
 
int numsquadlogo
 
GFXVertexListvlist
 tri,quad,line, strips, etc More...
 
unsigned int myMatNum
 The number of the appropriate material for this mesh (default 0) More...
 
TechniquePtr technique
 The technique used to render this mesh. More...
 
vector< Texture * > Decal
 The decal relevant to this mesh. More...
 
TexturedetailTexture
 
vector< VectordetailPlanes
 
float polygon_offset
 
char envMapAndLit
 whether this should be environment mapped 0x1 and 0x2 for if it should be lit (ored together) More...
 
GFXBOOL will_be_drawn
 Whether this original will be drawn this frame. More...
 
bool convex
 The blend functions. More...
 
unsigned char alphatest
 
enum BLENDFUNC blendSrc
 
enum BLENDFUNC blendDst
 
vector< MeshDrawContext > * draw_queue
 Support for reorganized rendering. More...
 
int draw_sequence
 How transparent this mesh is (in what order should it be rendered in. More...
 
string hash_name
 The name of this unit. More...
 
vector< MeshFXLocalFX
 The enabled light effects on this mesh. More...
 

Static Protected Attributes

static Hashtable< std::string,
Mesh, MESH_HASTHABLE_SIZE
meshHashTable
 The hash table of all meshes. More...
 
static Hashtable< std::string,
std::vector< int >
, MESH_HASTHABLE_SIZE
animationSequences
 

Friends

class OrigMeshContainer
 Needs to have access to our class. More...
 

Detailed Description

Mesh is the basic textured drawable Mesh has 1 texture and 1 vertex list (with possibly multiple primitives inside Meshes have a center-location but do not need to be translated to be drawn Meshes store various LOD's and originals in the orig pointer. These may be accessed in order to draw quickly a whole series of meshes. Unless DrawNow is invoked, Drawing only stores the mesh on teh appropriate draw queue so they may be drawn at a later date Also meshe contain Logos, flags based on squadron and faction that may be user-edited and appear in pleasing places on the hull.

Definition at line 125 of file mesh.h.

Constructor & Destructor Documentation

Mesh::Mesh ( std::string  filename,
const Vector scalex,
int  faction,
class Flightgroup fg,
bool  orig = false 
)
protected

Definition at line 173 of file mesh.cpp.

References convex, Hashtable< KEY, VALUE, SIZ >::Delete(), StarSystemGent::faction, fprintf, Hashtable< KEY, VALUE, SIZ >::Get(), LoadExistant(), LoadMesh(), meshHashTable, orig, and refcount.

173  : hash_name( filename )
174 {
175  this->convex = false;
176  Mesh *cpy = LoadMesh( filename.c_str(), scale, faction, fg, vector< std::string > () );
177  if (cpy->orig) {
178  LoadExistant( cpy->orig );
179  delete cpy; //wasteful, but hey
180  if (orig != false) {
181  orig = false;
182  std::vector< Mesh* > *tmp = bfxmHashTable.Get( this->orig->hash_name );
183  if (tmp && tmp->size() && (*tmp)[0] == this->orig) {
184  if (this->orig->refcount == 1) {
185  bfxmHashTable.Delete( this->orig->hash_name );
186  delete tmp;
187  orig = true;
188  }
189  }
190  if (meshHashTable.Get( this->orig->hash_name ) == this->orig) {
191  if (this->orig->refcount == 1) {
193  orig = true;
194  }
195  }
196  if (orig) {
197  Mesh *tmp = this->orig;
198  tmp->orig = this;
199  this->orig = NULL;
200  refcount = 2;
201  delete[] tmp;
202  }
203  }
204  } else {
205  delete cpy;
206  fprintf( stderr, "fallback, %s unable to be loaded as bfxm\n", filename.c_str() );
207  }
208 }
Mesh::Mesh ( )

Definition at line 109 of file mesh.cpp.

References InitUnit().

Referenced by Fork(), and LoadMeshes().

110 {
111  InitUnit();
112 }
Mesh::Mesh ( const Mesh m)

Definition at line 139 of file mesh.cpp.

References fprintf, Hashtable< KEY, VALUE, SIZ >::Get(), hash_name, i, InitUnit(), LoadExistant(), meshHashTable, and orig.

140 {
141  fprintf( stderr, "UNTESTED MESH COPY CONSTRUCTOR" );
142  this->orig = NULL;
143  this->hash_name = m.hash_name;
144  InitUnit();
145  Mesh *oldmesh = meshHashTable.Get( hash_name );
146  if (0 == oldmesh) {
147  vector< Mesh* > *vec = bfxmHashTable.Get( hash_name );
148  for (unsigned int i = 0; i < vec->size(); ++i) {
149  Mesh *mush = (*vec)[i]->orig ? (*vec)[i]->orig : (*vec)[i];
150  if (mush == m.orig || mush == &m)
151  oldmesh = (*vec)[i];
152  }
153  if (0 == oldmesh) {
154  if (vec->size() > 1) fprintf( stderr, "Copy constructor %s used in ambiguous Situation", hash_name.c_str() );
155  if ( vec->size() )
156  oldmesh = (*vec)[0];
157  }
158  }
159  if ( LoadExistant( oldmesh->orig != NULL ? oldmesh->orig : oldmesh ) )
160  return;
161 }
Mesh::~Mesh ( )
virtual

Destructor... kills orig if refcount of orig becomes zero.

Definition at line 359 of file mesh_gfx.cpp.

References Decal, Hashtable< KEY, VALUE, SIZ >::Delete(), draw_queue, forcelogos, Hashtable< KEY, VALUE, SIZ >::Get(), hash_name, i, j, meshHashTable, NUM_MESH_SEQUENCE, orig, refcount, squadlogos, undrawn_meshes, vlist, and VSFileSystem::vs_fprintf().

360 {
361  if (!orig || orig == this) {
362  for (int j = 0; j < NUM_MESH_SEQUENCE; j++)
363  for (OrigMeshVector::iterator it = undrawn_meshes[j].begin(); it != undrawn_meshes[j].end(); ++it)
364  if (it->orig == this) {
365  undrawn_meshes[j].erase( it-- );
366  VSFileSystem::vs_fprintf( stderr, "stale mesh found in draw queue--removed!\n" );
367  }
368  delete vlist;
369  for (unsigned int i = 0; i < Decal.size(); i++)
370  if (Decal[i] != NULL) {
371  delete Decal[i];
372  Decal[i] = NULL;
373  }
374  if (squadlogos != NULL) {
375  delete squadlogos;
376  squadlogos = NULL;
377  }
378  if (forcelogos != NULL) {
379  delete forcelogos;
380  forcelogos = NULL;
381  }
382  if (meshHashTable.Get( hash_name ) == this)
384  vector< Mesh* > *hashers = bfxmHashTable.Get( hash_name );
385  vector< Mesh* >::iterator finder;
386  if (hashers) {
387  for (int i = hashers->size()-1; i >= 0; --i)
388  if ( (*hashers)[i] == this ) {
389  hashers->erase( hashers->begin()+i );
390  if ( hashers->empty() ) {
391  bfxmHashTable.Delete( hash_name );
392  delete hashers;
393  }
394  }
395  }
396  if (draw_queue != NULL)
397  delete[] draw_queue;
398  } else {
399  orig->refcount--;
400  //printf ("orig refcount: %d",refcount);
401  if (orig->refcount == 0)
402  delete[] orig;
403  }
404 }

Member Function Documentation

void Mesh::AddDamageFX ( const Vector LocalPos,
const Vector LocalNorm,
const float  percentage,
const GFXColor color = GFXColor(                         1,                         1,                         1,                         1 ) 
)

Adds a new damage effect with age damage to the part of the unit. Color specifies the shield oclor.

Definition at line 85 of file mesh_fx.cpp.

References GFXColor::a, GFXColor::b, endpotency, flickertime, GFXColor::g, LocalFX, MAXLOCALFX, mindamage, GFXColor::r, rSize(), startpotency, and Vector.

86 {
87  Vector loc( pnt+norm );
88  /*if (!(norm.i||norm.j||norm.k)) */ {
89  loc = pnt;
90  loc.Normalize();
91  loc *= ( 1+rSize() );
92  }
93 
94  GFXColor tmp( col.r, col.g, col.b, col.a );
95  float numsec = flickertime*(damage < mindamage) ? mindamage : damage;
96  MeshFX newFX( numsec, (startpotency-endpotency)/( numsec*rSize()*rSize() ), true,
97  GFXColor( loc.i, loc.j, loc.k, 1 ),
98  tmp,
99  GFXColor( 0, 0, 0, 1 ),
100  tmp,
101  GFXColor( 1, 0, startpotency/( rSize()*rSize() ) ) );
102  newFX.setSize(rSize());
103  if (LocalFX.size() >= MAXLOCALFX)
104  LocalFX[( rand()%( LocalFX.size() ) )].MergeLights( newFX );
105  else
106  LocalFX.push_back( newFX );
107 }
virtual float Mesh::clipRadialSize ( ) const
inlinevirtual

Reimplemented in RingMesh.

Definition at line 405 of file mesh.h.

References radialSize.

406  {
407  return radialSize;
408  }
Vector Mesh::corner_max ( )
inline
Vector Mesh::corner_min ( )
inline

Returns bounding box values.

Definition at line 386 of file mesh.h.

References mn.

Referenced by Planet::AddSpaceElevator(), ContinuousTerrain::AdjustTerrain(), Box::Box(), ContinuousTerrain::Collide(), ContinuousTerrain::ContinuousTerrain(), and Box::ProcessDrawQueue().

387  {
388  return mn;
389  }
void Mesh::Draw ( float  lod,
const Matrix m = identity_matrix,
float  toofar = 1,
int  cloak = -1,
float  nebdist = 0,
unsigned char  damage = 0,
bool  renormalize_normals = false,
const MeshFX mfx = NULL 
)

Draws lod pixel wide mesh at Transformation LATER.

all else == defaults, only ambient

Definition at line 406 of file mesh_gfx.cpp.

References GFXColor::a, GFXColor::b, c, MeshDrawContext::CLOAK, MeshDrawContext::cloaked, MeshDrawContext::CloakFX, MeshDrawContext::damage, draw_queue, draw_sequence, float, MeshDrawContext::FOG, GFXColor::g, g_game, GetElapsedTime(), getLOD(), MeshDrawContext::GLASSCLOAK, LocalFX, MeshDrawContext::mesh_seq, MESH_SPECIAL_FX_ONLY, MeshDrawContext::NEARINVIS, MeshDrawContext::NONE, NUM_ZBUF_SEQ, OrigMeshContainer, GFXColor::r, MeshDrawContext::RENORMALIZE, rSize(), MeshDrawContext::SpecialFX, technique, undrawn_meshes, UpdateFX(), MeshDrawContext::useXtraFX, will_be_drawn, MeshDrawContext::xtraFX, and game_data_t::zfar.

Referenced by ContinuousTerrain::Draw(), WarpTrail::Draw(), HaloSystem::Draw(), SphereMesh::Draw(), GameUnit< UnitType >::Draw(), NavigationSystem::Draw(), and GameUnit< UnitType >::DrawNow().

407 {
408  Mesh *origmesh = getLOD( lod );
409  if (origmesh->rSize() > 0) {
410  //Vector pos (local_pos.Transform(m));
411  MeshDrawContext c( m );
412  if (mfx) {
413  c.xtraFX=*mfx;
414  c.useXtraFX=true;
415  }
417  c.SpecialFX = &LocalFX;
418  c.damage = hulldamage;
419 
420  c.mesh_seq = ( ( toofar+rSize() ) > g_game.zfar ) ? NUM_ZBUF_SEQ : draw_sequence;
421  c.cloaked = MeshDrawContext::NONE;
422  if (nebdist < 0)
423  c.cloaked |= MeshDrawContext::FOG;
424  if (renormalize)
425  c.cloaked |= MeshDrawContext::RENORMALIZE;
426  if (cloak >= 0) {
427  c.cloaked |= MeshDrawContext::CLOAK;
428  if ( (cloak&0x1) ) {
429  c.cloaked |= MeshDrawContext::GLASSCLOAK;
430  c.mesh_seq = MESH_SPECIAL_FX_ONLY; //draw near the end with lights
431  } else {
432  c.mesh_seq = 2;
433  }
434  if (cloak <= 2147483647/2)
435  c.cloaked |= MeshDrawContext::NEARINVIS;
436  float tmp = ( (float) cloak )/2147483647;
437  c.CloakFX.r = (c.cloaked&MeshDrawContext::GLASSCLOAK) ? tmp : 1;
438  c.CloakFX.g = (c.cloaked&MeshDrawContext::GLASSCLOAK) ? tmp : 1;
439  c.CloakFX.b = (c.cloaked&MeshDrawContext::GLASSCLOAK) ? tmp : 1;
440  c.CloakFX.a = tmp;
441  /*
442  * c.CloakNebFX.ambient[0]=((float)cloak)/2147483647;
443  * c.CloakNebFX.ag=((float)cloak)/2147483647;
444  * c.CloakNebFX.ab=((float)cloak)/2147483647;
445  * c.CloakNebFX.aa=((float)cloak)/2147483647;
446  */
448  }
449  //c.mat[12]=pos.i;
450  //c.mat[13]=pos.j;
451  //c.mat[14]=pos.k;//to translate to local_pos which is now obsolete!
452 
453  origmesh->draw_queue[static_cast<size_t>(c.mesh_seq)].push_back( c );
454  if ( !( origmesh->will_be_drawn&(1<<c.mesh_seq) ) ) {
455  origmesh->will_be_drawn |= (1<<c.mesh_seq);
456  for (int passno = 0, npasses = origmesh->technique->getNumPasses(); passno < npasses; ++passno)
457  undrawn_meshes[static_cast<size_t>(c.mesh_seq)].push_back( OrigMeshContainer( origmesh, toofar-rSize(), passno ) );
458  }
459  will_be_drawn |= (1<<c.mesh_seq);
460  }
461 }
void Mesh::DrawNow ( float  lod,
bool  centered,
const Matrix m = identity_matrix,
int  cloak = -1,
float  nebdist = 0 
)

Draws lod pixels wide, mesh at Transformation NOW. If centered, then will center on camera and disable cull.

Definition at line 463 of file mesh_gfx.cpp.

References _Universe, Universe::AccessCamera(), blendDst, blendSrc, Decal, DEPTHWRITE, draw_sequence, GFXVertexList::DrawOnce(), FOG_OFF, getLOD(), Camera::GetNebula(), GFXADDTEXTURE, GFXBlendMode(), GFXCenterCamera(), GFXCreateLight(), GFXDeleteLight(), GFXDisable(), GFXEnable(), GFXFogMode(), GFXLoadIdentity(), GFXLoadMatrixModel(), GFXMODULATETEXTURE, GFXPickLights(), GFXSelectMaterial(), GFXTextureEnv(), GFXToggleTexture(), i, LocalFX, MESH_SPECIAL_FX_ONLY, MODEL, myMatNum, Matrix::p, rSize(), Nebula::SetFogState(), SRCALPHA, TEXTURE1, Vector, vlist, and ZERO.

Referenced by Background::Draw(), and Atmosphere::Draw().

464 {
465  //short fix
466  Mesh *o = getLOD( lod );
467  //fixme: cloaking not delt with.... not needed for backgroudn anyway
468  if (nebdist < 0) {
470  if (t)
471  t->SetFogState();
472  } else {
473  GFXFogMode( FOG_OFF );
474  }
475  if (centered) {
476  //Matrix m1 (m);
477  //Vector pos(_Universe->AccessCamera()->GetPosition().Transform(m1));
478  //m1[12]=pos.i;
479  //m1[13]=pos.j;
480  //m1[14]=pos.k;
481  GFXCenterCamera( true );
482  GFXLoadMatrixModel( m );
483  } else {
486  GFXPickLights( Vector( m.p.i, m.p.j, m.p.k ), rSize() );
487  }
488  GFXLoadMatrixModel( m );
489  }
490  //Making it static avoids frequent reallocations - although may be troublesome for thread safety
491  //but... WTH... nothing is thread safe in VS.
492  //Also: Be careful with reentrancy... right now, this section is not reentrant.
493  static vector< int >specialfxlight;
494 
495  unsigned int i;
496  for (i = 0; i < LocalFX.size(); i++) {
497  int ligh;
498  GFXCreateLight( ligh, (LocalFX)[i], true );
499  specialfxlight.push_back( ligh );
500  }
502  if (blendSrc != SRCALPHA && blendDst != ZERO)
505  if (o->Decal.size() && o->Decal[0])
506  o->Decal[0]->MakeActive();
507  GFXTextureEnv( 0, GFXMODULATETEXTURE ); //Default diffuse mode
508  GFXTextureEnv( 1, GFXADDTEXTURE ); //Default envmap mode
509  GFXToggleTexture( bool(o->Decal.size() && o->Decal[0]), 0 );
510  o->vlist->DrawOnce();
511  if (centered)
512  GFXCenterCamera( false );
513  for (i = 0; i < specialfxlight.size(); i++)
514  GFXDeleteLight( specialfxlight[i] );
515  if (cloak >= 0 && cloak < 2147483647)
516  GFXEnable( TEXTURE1 );
517 }
void Mesh::EnableSpecialFX ( )

Turns on SpecialFX.

Definition at line 118 of file mesh_fx.cpp.

References blendDst, blendSrc, draw_sequence, GFXFALSE, GFXTRUE, MESH_SPECIAL_FX_ONLY, ONE, orig, setEnvMap(), and setLighting().

119 {
121  setEnvMap( GFXFALSE );
122  setLighting( GFXTRUE );
123  if (orig) {
125  orig->blendSrc = orig->blendDst = ONE;
126  orig->setEnvMap( GFXFALSE );
128  }
129  blendSrc = ONE;
130  blendDst = ONE;
131 }
void Mesh::forceCullFace ( GFXBOOL  newValue)
inline

Sets whether or not this unit should be environment mapped.

Definition at line 350 of file mesh.h.

References envMapAndLit.

Referenced by Fork(), and LoadMeshes().

351  {
352  if (newValue) envMapAndLit = ( envMapAndLit&~(0x8|0x4) );
353  if (!newValue) envMapAndLit = ( envMapAndLit&~(0x4|0x8) );
354  }
void Mesh::Fork ( Mesh *&  one,
Mesh *&  two,
float  a,
float  b,
float  c,
float  d 
)

Forks the mesh across the plane a,b,c,d into two separate meshes...upon which this may be deleted.

Definition at line 25 of file mesh_poly.cpp.

References blendDst, blendSrc, Decal, draw_queue, forceCullFace(), forcelogos, Fork(), getEnvMap(), getLighting(), GFXVertexList::GetPolys(), GFXFALSE, GFXQUAD, GFXTRI, i, j, local_pos, Magnitude(), VsnetOSS::memcpy(), Mesh(), mn, mx, NUM_ZBUF_SEQ, numforcelogo, numsquadlogo, orig, PFRONT, radialSize, refcount, setEnvMap(), setLighting(), squadlogos, updateMax(), Vector, vlist, whichside(), x, AiXml::X, y, and AiXml::Y.

Referenced by Fork().

26 {
27  if (orig && orig != this) {
28  orig->Fork( x, y, a, b, c, d );
29  return;
30  }
31  int numtris, numquads;
32  GFXVertex *Orig;
33  vlist->GetPolys( &Orig, &numquads, &numtris );
34  numquads -= numtris;
35  int numtqx[2] = {0, 0};
36  int numtqy[2] = {0, 0};
37 
38  GFXVertex *X = new GFXVertex[numquads*4+numtris*3];
39  GFXVertex *xnow = X;
40  GFXVertex *Y = new GFXVertex[numquads*4+numtris*3];
41  GFXVertex *ynow = Y;
42  Vector xmax, xmin, ymax, ymin;
43  xmax = ymax = Vector( -FLT_MAX, -FLT_MAX, -FLT_MAX );
44  xmin = ymin = Vector( FLT_MAX, FLT_MAX, FLT_MAX );
45 
46  int i, j;
47  int inc = 3;
48  int offset = 0;
49  int last = numtris;
50  mesh_polygon tmppolygon;
51  for (int l = 0; l < 2; l++) {
52  for (i = 0; i < last; i++) {
53  if ( ( !(numtqy[l] < last/3
54  && numtqx[l] > 2*last/3) )
55  && ( (numtqx[l] < last/3
56  && numtqy[l] > 2*last/3) || whichside( &Orig[offset+i*inc], inc, a, b, c, d ) == PFRONT ) ) {
57  numtqx[l]++;
58  for (j = 0; j < inc; j++) {
59  memcpy( xnow, &Orig[offset+i*inc+j], sizeof (GFXVertex) );
60  updateMax( xmin, xmax, *xnow );
61  xnow++;
62  }
63  } else {
64  numtqy[l]++;
65  for (j = 0; j < inc; j++) {
66  memcpy( ynow, &Orig[offset+i*inc+j], sizeof (GFXVertex) );
67  updateMax( ymin, ymax, *ynow );
68  ynow++;
69  }
70  }
71  }
72  numtqx[l] *= inc;
73  numtqy[l] *= inc;
74  inc = 4;
75  offset = numtris*3;
76  last = numquads;
77  }
78  free( Orig );
79  enum POLYTYPE polytypes[2] = {GFXTRI, GFXQUAD};
80  if ( ( !(numtqx[0] || numtqx[1]) ) || ( !(numtqy[0] || numtqy[1]) ) ) {
81  x = y = NULL;
82  delete[] X;
83  delete[] Y;
84  return;
85  }
86  x = new Mesh;
87  x->setLighting( getLighting() );
88  x->setEnvMap( getEnvMap() );
89  x->forceCullFace( GFXFALSE );
90 
91  y = new Mesh;
92  y->setLighting( getLighting() );
93  y->setEnvMap( getEnvMap() );
94 
95  y->forceCullFace( GFXFALSE );
96  x->forcelogos = x->squadlogos = NULL;
97  x->numforcelogo = x->numsquadlogo = 0;
98  x->setLighting( getLighting() );
99  x->setEnvMap( getEnvMap() );
100  x->blendSrc = y->blendSrc = blendSrc;
101  x->blendDst = y->blendDst = blendDst;
102  while ( x->Decal.size() < Decal.size() )
103  x->Decal.push_back( NULL );
104  {
105  for (unsigned int i = 0; i < Decal.size(); i++)
106  if (Decal[i])
107  x->Decal[i] = Decal[i]->Clone();
108  }
109 
110  y->squadlogos = y->forcelogos = NULL;
111  y->numforcelogo = y->numsquadlogo = 0;
112  y->setLighting( getLighting() );
113  y->setEnvMap( getEnvMap() );
114  while ( y->Decal.size() < Decal.size() )
115  y->Decal.push_back( NULL );
116  {
117  for (unsigned int i = 0; i < Decal.size(); i++)
118  if (Decal[i])
119  y->Decal[i] = Decal[i]->Clone();
120  }
121  if (numtqx[0] && numtqx[1]) {
122  x->vlist = new GFXVertexList( polytypes, numtqx[0]+numtqx[1], X, 2, numtqx, true );
123  } else {
124  int exist = 0;
125  if (numtqx[1])
126  exist = 1;
127  assert( numtqx[0] || numtqx[1] );
128  x->vlist = new GFXVertexList( &polytypes[exist], numtqx[exist], X, 1, &numtqx[exist], true, 0 );
129  }
130  if (numtqy[0] || numtqy[1]) {
131  y->vlist = new GFXVertexList( polytypes, numtqy[0]+numtqy[1], Y, 2, numtqy, true );
132  } else {
133  int exis = 0;
134  if (numtqy[1])
135  exis = 1;
136  assert( numtqx[0] || numtqx[1] );
137  y->vlist = new GFXVertexList( &polytypes[exis], numtqy[exis], Y, 1, &numtqy[exis], true, 0 );
138  }
139  x->local_pos = Vector( .5*(xmin+xmax) );
140  y->local_pos = Vector( .5*(ymin+ymax) );
141  x->radialSize = .5*(xmax-xmin).Magnitude();
142  y->radialSize = .5*(ymax-ymin).Magnitude();
143  x->mn = xmin;
144  x->mx = xmax;
145  y->mn = ymin;
146  y->mx = ymax;
147  x->orig = new Mesh[1];
148  x->forceCullFace( GFXFALSE );
149 
150  y->orig = new Mesh[1];
151  y->forceCullFace( GFXFALSE );
152  x->draw_queue = new vector< MeshDrawContext >[NUM_ZBUF_SEQ+1];
153  y->draw_queue = new vector< MeshDrawContext >[NUM_ZBUF_SEQ+1];
154  *y->orig = *y;
155  *x->orig = *x;
156  x->orig->refcount = 1;
157  y->orig->refcount = 1;
158  x->numforcelogo = 0;
159  x->forcelogos = NULL;
160  x->numsquadlogo = 0;
161  x->squadlogos = NULL;
162  x->numforcelogo = 0;
163  x->forcelogos = NULL;
164  x->numsquadlogo = 0;
165  x->squadlogos = NULL;
166 
167  delete[] X;
168  delete[] Y;
169 }
BLENDFUNC Mesh::getBlendDst ( ) const
inline

Definition at line 274 of file mesh.h.

References blendDst.

275  {
276  return blendDst;
277  }
BLENDFUNC Mesh::getBlendSrc ( ) const
inline

Definition at line 270 of file mesh.h.

References blendSrc.

271  {
272  return blendSrc;
273  }
BoundingBox* Mesh::getBoundingBox ( )

Returns a physical boudning box in 3space instead of in current unit space.

bool Mesh::getConvex ( ) const
inline

Definition at line 261 of file mesh.h.

References convex.

262  {
263  return this->convex;
264  }
GFXBOOL Mesh::getCullFaceForcedOff ( ) const
inline

Definition at line 359 of file mesh.h.

References envMapAndLit.

Referenced by RestoreCullFace(), and SelectCullFace().

360  {
361  return (envMapAndLit&0x8) != 0;
362  }
GFXBOOL Mesh::getCullFaceForcedOn ( ) const
inline

Definition at line 355 of file mesh.h.

References envMapAndLit.

Referenced by SelectCullFace().

356  {
357  return (envMapAndLit&0x4) != 0;
358  }
float Mesh::getCurrentFrame ( ) const

Definition at line 283 of file mesh.cpp.

References framespersecond.

Referenced by getLOD().

284 {
285  return framespersecond;
286 }
GFXBOOL Mesh::getEnvMap ( ) const
inline

Definition at line 370 of file mesh.h.

References envMapAndLit.

Referenced by Fork(), and initTechnique().

371  {
372  return (envMapAndLit&0x1) != 0;
373  }
float Mesh::getFramesPerSecond ( ) const

Definition at line 298 of file mesh.cpp.

References framespersecond.

Referenced by Mount::ComputeAnimatedFrame(), and getLOD().

299 {
301 }
GFXBOOL Mesh::getLighting ( ) const
inline

Definition at line 381 of file mesh.h.

References envMapAndLit.

Referenced by Fork().

382  {
383  return (envMapAndLit&0x2) != 0;
384  }
Mesh * Mesh::getLOD ( float  lod,
bool  bBypassDamping = true 
)
protected

Returing the mesh relevant to "size" pixels LOD of this mesh.

Definition at line 303 of file mesh.cpp.

References animationSequences, float_to_int(), Hashtable< KEY, VALUE, SIZ >::Get(), getCurrentFrame(), GetElapsedTime(), getFramesPerSecond(), getNumLOD(), VegaConfig::getVariable(), hash_name, i, int, LOD_HYSTHERESIS_DIVIDER, LOD_HYSTHERESIS_MAXENLARGEMENT_FACTOR, lodsize, numlods, XMLSupport::parse_float(), setCurrentFrame(), and vs_config.

Referenced by Draw(), and DrawNow().

304 {
305  if (!orig)
306  return this;
307  Mesh *retval = &orig[0];
308  vector< int > *animFrames = 0;
309  if ( getFramesPerSecond() > .0000001 && ( animFrames = animationSequences.Get( hash_name ) ) ) {
310  //return &orig[(int)floor(fmod (getNewTime()*getFramesPerSecond(),numlods))];
311  unsigned int which = (int) float_to_int( floor( fmod( getCurrentFrame(),
312  animFrames->size() ) ) );
313  float adv = GetElapsedTime()*getFramesPerSecond();
314  static float max_frames_skipped =
315  XMLSupport::parse_float( vs_config->getVariable( "graphics", "mesh_animation_max_frames_skipped", "3" ) );
316  if (adv > max_frames_skipped)
317  adv = max_frames_skipped;
319  return &orig[(*animFrames)[which%animFrames->size()]%getNumLOD()];
320  } else {
321  float maxlodsize = retval ? retval->lodsize : 0.0f;
322  for (int i = 1; i < numlods; i++) {
323  float lodoffs = 0;
324  if (!bBypassDamping) {
325  if (lod < orig[i].lodsize)
326  lodoffs = ( (i < numlods-1) ? (orig[i+1].lodsize-orig[i].lodsize)/LOD_HYSTHERESIS_DIVIDER : 0.0f );
327  else
328  lodoffs = ( (i > 0) ? (orig[i-1].lodsize-orig[i].lodsize)/LOD_HYSTHERESIS_DIVIDER : 0.0f );
329  float maxenlargement = ( (orig[i].lodsize*LOD_HYSTHERESIS_MAXENLARGEMENT_FACTOR)-orig[i].lodsize );
330  if ( (lodoffs > 0) && (lodoffs > maxenlargement) ) lodoffs = maxenlargement; //Avoid excessive enlargement of low-detail LOD levels, when LOD levels are far apart.
331  }
332  if ( ( lod < (orig[i].lodsize+lodoffs) ) && (lod < maxlodsize) ) {
333  maxlodsize = orig[i].lodsize;
334  retval = &orig[i];
335  }
336  }
337  }
338  return retval;
339 }
const GFXMaterial & Mesh::GetMaterial ( ) const

Definition at line 548 of file mesh_gfx.cpp.

References GFXGetMaterial(), and myMatNum.

549 {
550  return GFXGetMaterial( myMatNum );
551 }
int Mesh::getNumAnimationFrames ( const string &  which = string()) const

Definition at line 57 of file mesh.cpp.

References animationSequences, Hashtable< KEY, VALUE, SIZ >::Get(), and hash_name.

58 {
59  if ( which.empty() ) {
60  vector< int > *animSeq = animationSequences.Get( hash_name );
61  if (animSeq) return animSeq->size();
62  } else {
63  vector< int > *animSeq = animationSequences.Get( hash_name+"*"+which );
64  if (animSeq) return animSeq->size();
65  }
66  return 0;
67 }
int Mesh::getNumLOD ( ) const

Definition at line 273 of file mesh.cpp.

References numlods.

Referenced by getLOD().

274 {
275  return numlods;
276 }
int Mesh::getNumTextureFrames ( ) const

Definition at line 237 of file mesh_gfx.cpp.

References Decal.

238 {
239  if ( Decal.size() )
240  if (Decal[0])
241  return Decal[0]->numFrames();
242  return 1;
243 }
void Mesh::GetPolys ( vector< mesh_polygon > &  polys)

Gets all polygons in this mesh for collision computation.

Definition at line 171 of file mesh_poly.cpp.

References GetPolys(), GFXVertexList::GetPolys(), i, j, orig, Vector, vlist, GFXVertex::x, GFXVertex::y, and GFXVertex::z.

Referenced by ContinuousTerrain::ContinuousTerrain(), GetPolys(), and Unit::LoadRow().

172 {
173  int numtris;
174  int numquads;
175  if (orig && orig != this) {
176  orig->GetPolys( polys );
177  return;
178  }
179  GFXVertex *tmpres;
180  Vector vv;
181  vlist->GetPolys( &tmpres, &numquads, &numtris );
182  numquads -= numtris;
183  int i;
184  int inc = 3;
185  int offset = 0;
186  int last = numtris;
187  mesh_polygon tmppolygon;
188  for (int l = 0; l < 2; l++) {
189  for (i = 0; i < last; i++) {
190  polys.push_back( tmppolygon );
191  for (int j = 0; j < 3; j++) {
192  vv.i = tmpres[offset+i*inc+j].x; //+local_pos.i;
193  vv.j = tmpres[offset+i*inc+j].y; //+local_pos.j;
194  vv.k = tmpres[offset+i*inc+j].z; //+local_pos.k;
195  polys[polys.size()-1].v.push_back( vv );
196  }
197  if (inc == 4) {
198  for (int j = 1; j < 4; j++) {
199  vv.i = tmpres[offset+i*inc+j].x; //+local_pos.i;
200  vv.j = tmpres[offset+i*inc+j].y; //+local_pos.j;
201  vv.k = tmpres[offset+i*inc+j].z; //+local_pos.k;
202  polys[polys.size()-1].v.push_back( vv );
203  }
204  }
205  }
206  inc = 4;
207  offset = numtris*3;
208  last = numquads;
209  }
210  free( tmpres );
211 }
TechniquePtr Mesh::getTechnique ( ) const
inline

Definition at line 162 of file mesh.h.

References technique.

162 { return technique; }
double Mesh::getTextureCumulativeTime ( ) const

Definition at line 245 of file mesh_gfx.cpp.

References Decal.

246 {
247  if ( Decal.size() )
248  if (Decal[0])
249  return Decal[0]->curTime();
250  return 0;
251 }
float Mesh::getTextureFramesPerSecond ( ) const

Definition at line 253 of file mesh_gfx.cpp.

References Decal.

254 {
255  if ( Decal.size() )
256  if (Decal[0])
257  return Decal[0]->framesPerSecond();
258  return 0;
259 }
GFXVertexList * Mesh::getVertexList ( ) const

Definition at line 288 of file mesh.cpp.

References vlist.

Referenced by MeshAnimation::Init().

289 {
290  return vlist;
291 }
GFXBOOL Mesh::HasBeenDrawn ( ) const
inline

If it has already been drawn this frame.

Definition at line 316 of file mesh.h.

References will_be_drawn.

317  {
318  return will_be_drawn;
319  }
void Mesh::initTechnique ( const string &  technique)

Definition at line 1867 of file mesh_gfx.cpp.

References Decal, getEnvMap(), Technique::getTechnique(), VegaConfig::getVariable(), technique, and vs_config.

Referenced by SphereMesh::InitSphere(), and InitUnit().

1868 {
1869  if ( xmltechnique.empty() ) {
1870  //Load default technique, which depends:
1871  string effective;
1872  if ( Decal.size() > 1 || getEnvMap() ) {
1873  //Use shader-ified technique for multitexture or environment-mapped meshes
1874 #ifdef __APPLE__
1875  static string shader_technique = vs_config->getVariable( "graphics", "default_full_technique", "mac" );
1876 #else
1877  static string shader_technique = vs_config->getVariable( "graphics", "default_full_technique", "default" );
1878 #endif
1879  effective = shader_technique;
1880  } else {
1881  static string fixed_technique = vs_config->getVariable( "graphics", "default_simple_technique", "fixed_simple" );
1882  effective = fixed_technique;
1883  }
1884  technique = Technique::getTechnique( effective );
1885  } else {
1886  technique = Technique::getTechnique( xmltechnique );
1887  }
1888 }
void Mesh::InitUnit ( )
protected

Setting all values to defaults (good for mesh copying and stuff)

Definition at line 69 of file mesh.cpp.

References alphatest, blendDst, blendSrc, convex, Decal, detailTexture, draw_queue, draw_sequence, envMapAndLit, forcelogos, framespersecond, GFXFALSE, GFXTRUE, initTechnique(), local_pos, lodsize, mn, mx, myMatNum, numforcelogo, numlods, numsquadlogo, ONE, orig, polygon_offset, radialSize, refcount, setEnvMap(), setLighting(), squadlogos, Vector, vlist, will_be_drawn, and ZERO.

Referenced by Box::Box(), and Mesh().

70 {
71  convex = false;
72  polygon_offset = 0;
73  framespersecond = 0;
74  numlods = 1;
75  alphatest = 0;
76  lodsize = FLT_MAX;
77  forcelogos = NULL;
78  squadlogos = NULL;
79  local_pos = Vector( 0, 0, 0 );
80  blendSrc = ONE;
81  blendDst = ZERO;
82  vlist = NULL;
83  mn = Vector( 0, 0, 0 );
84  mx = Vector( 0, 0, 0 );
85  radialSize = 0;
86  GFXVertex *alphalist;
87  if ( Decal.empty() )
88  Decal.push_back( NULL );
89  alphalist = NULL;
90 
91  //texturename[0] = -1;
93  myMatNum = 0; //default material!
94  //scale = Vector(1.0,1.0,1.0);
95  refcount = 1; //FIXME VEGASTRIKE THIS _WAS_ zero...NOW ONE
96  orig = NULL;
97 
98  envMapAndLit = 0x3;
99  setEnvMap( GFXTRUE );
100  setLighting( GFXTRUE );
101  detailTexture = NULL;
102  draw_queue = NULL;
104  draw_sequence = 0;
105 
106  initTechnique( "fixed" );
107 }
bool Mesh::LoadExistant ( Mesh mesh)

Loads a mesh that has been found in the hash table into this mesh (copying original data)

Definition at line 114 of file mesh.cpp.

References orig, and refcount.

Referenced by SphereMesh::InitSphere(), LoadExistant(), LoadMeshes(), and Mesh().

115 {
116  *this = *oldmesh;
117  oldmesh->refcount++;
118  orig = oldmesh;
119  return true;
120 }
bool Mesh::LoadExistant ( const string  filehash,
const Vector scale,
int  faction 
)

Definition at line 122 of file mesh.cpp.

References Hashtable< KEY, VALUE, SIZ >::Get(), VSFileSystem::GetHashName(), VSFileSystem::GetSharedMeshHashName(), hash_name, LoadExistant(), and meshHashTable.

123 {
124  Mesh *oldmesh;
125 
126  hash_name = VSFileSystem::GetHashName( filehash, scale, faction );
127  oldmesh = meshHashTable.Get( hash_name );
128  if (oldmesh == 0) {
130  oldmesh = meshHashTable.Get( hash_name );
131  }
132  if (0 != oldmesh)
133  return LoadExistant( oldmesh );
134  //VSFileSystem::Fprintf (stderr,"cannot cache %s",GetSharedMeshHashName(filehash,scale,faction).c_str());
135  return false;
136 }
Mesh * Mesh::LoadMesh ( const char *  filename,
const Vector scalex,
int  faction,
class Flightgroup fg,
const std::vector< std::string > &  textureOverride = std::vector< std::string > () 
)
static

Loading a mesh from an XML file. faction specifies the logos. Orig is for internal (LOD) use only!

Definition at line 1239 of file mesh_xml.cpp.

References fprintf.

Referenced by HaloSystem::AddHalo(), addRapidMesh(), addShieldMesh(), Planet::AddSpaceElevator(), ContinuousTerrain::ContinuousTerrain(), getTemplate(), GetWarpMesh(), MeshAnimation::Init(), MakeFogMesh(), Mesh(), and NavigationSystem::ParseFile().

1244 {
1245  vector< Mesh* >m = LoadMeshes( filename, scale, faction, fg, overridetextures );
1246  if ( m.empty() )
1247  return 0;
1248  if (m.size() > 1) {
1249  fprintf( stderr, "Mesh %s has %u subcomponents. Only first used!\n", filename, (unsigned int) m.size() );
1250  for (unsigned int i = 1; i < m.size(); ++i)
1251  delete m[i];
1252  }
1253  return m[0];
1254 }
vector< Mesh * > Mesh::LoadMeshes ( const char *  filename,
const Vector scalex,
int  faction,
class Flightgroup fg,
const std::vector< std::string > &  textureOverride = std::vector< std::string > () 
)
static

Definition at line 1257 of file mesh_xml.cpp.

References bfxmHashTable, VSFileSystem::VSFile::Close(), f, VSFileSystem::GetHashName(), VSFileSystem::GetSharedMeshHashName(), VSFileSystem::VSFile::GoTo(), LoadExistant(), VSFileSystem::MeshFile, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), orig, VSFileSystem::VSFile::Read(), VSFileSystem::Shared, and VSFileSystem::vs_fprintf().

Referenced by pushMesh().

1262 {
1263  /*
1264  * if (strstr(filename,".xmesh")) {
1265  * Mesh * m = new Mesh (filename,scale,faction,fg);
1266  * vector <Mesh*> ret;
1267  * ret.push_back(m);
1268  * return ret;
1269  * }*/
1270  string hash_name = VSFileSystem::GetHashName( filename, scale, faction );
1271  vector< Mesh* > *oldmesh = bfxmHashTable.Get( hash_name );
1272  if (oldmesh == 0) {
1273  hash_name = VSFileSystem::GetSharedMeshHashName( filename, scale, faction );
1274  oldmesh = bfxmHashTable.Get( hash_name );
1275  }
1276  if (0 != oldmesh) {
1277  vector< Mesh* >ret;
1278  for (unsigned int i = 0; i < oldmesh->size(); ++i) {
1279  ret.push_back( new Mesh() );
1280  Mesh *m = (*oldmesh)[i];
1281  ret.back()->LoadExistant( m->orig ? m->orig : m );
1282  }
1283  return ret;
1284  }
1285  VSFile f;
1286  VSError err = f.OpenReadOnly( filename, MeshFile );
1287  if (err > Ok) {
1288  VSFileSystem::vs_fprintf( stderr, "Cannot Open Mesh File %s\n", filename );
1289  return vector< Mesh* > ();
1290  }
1291  char bfxm[4];
1292  f.Read( &bfxm[0], sizeof(bfxm[0])*4 );
1293  bool isbfxm = (bfxm[0] == 'B' && bfxm[1] == 'F' && bfxm[2] == 'X' && bfxm[3] == 'M');
1294  if ( isbfxm || strstr( filename, ".obj" ) ) {
1295  if (!isbfxm) {
1296  // NOTE : Commented out following block, probably not needed anymore
1297 /* if ( !loadObj( f, filename ) ) {
1298  VSFileSystem::vs_fprintf( stderr, "Cannot Open Mesh File %s\n", filename );
1299 */
1300 //cleanexit=1;
1301 //winsys_exit(1);
1302  // return vector< Mesh* > ();
1303  // }
1304  }
1305  f.GoTo( 0 );
1306  hash_name =
1307  (err == VSFileSystem::Shared) ? VSFileSystem::GetSharedMeshHashName( filename, scale,
1309  filename,
1310  scale,
1311  faction );
1312  vector< Mesh* > retval( LoadMeshes( f, scale, faction, fg, hash_name, overrideTextures ) );
1313  vector< Mesh* > *newvec = new vector< Mesh* > ( retval );
1314  for (unsigned int i = 0; i < retval.size(); ++i) {
1315  retval[i]->hash_name = hash_name;
1316  if (retval[i]->orig)
1317  retval[i]->orig->hash_name = hash_name;
1318  (*newvec)[i] = retval[i]->orig ? retval[i]->orig : retval[i];
1319  }
1320  bfxmHashTable.Put( hash_name, newvec );
1321  return retval;
1322  } else {
1323  f.Close();
1324  bool original = false;
1325  Mesh *m = new Mesh( filename, scale, faction, fg, original );
1326  vector< Mesh* >ret;
1327  ret.push_back( m );
1328  return ret;
1329  }
1330 }
vector< Mesh * > Mesh::LoadMeshes ( VSFileSystem::VSFile f,
const Vector scalex,
int  faction,
class Flightgroup fg,
std::string  hash_name,
const std::vector< std::string > &  textureOverride = std::vector< std::string > () 
)
static

Definition at line 296 of file mesh_bxm.cpp.

References GFXMaterial::aa, GFXMaterial::ab, GFXMaterial::ag, ALPHAMAP, alphatest, ANIMATION, animationSequences, GFXMaterial::ar, BEGINSTATE, bxmfopen, bxmfprintf, char8bit, VSFileSystem::VSFile::Close(), GFXMaterial::da, GFXMaterial::db, Decal, MeshXML::decals, detailPlanes, detailTexture, GFXMaterial::dg, DOVERTEX, GFXMaterial::dr, draw_queue, GFXMaterial::ea, GFXMaterial::eb, GFXMaterial::eg, ENDSTATE, GFXMaterial::er, error, MeshXML::faction, StarSystemGent::faction, fcloseInput(), MeshXML::fg, float32bit, MeshXML::force_texture, forceCullFace(), fprintf, framespersecond, FactionUtil::GetFaction(), VSFileSystem::VSFile::GetFilename(), VegaConfig::getVariable(), GFXTRUE, i, index, int, int32bit, inverseblend, j, k, MeshXML::lineind, MeshXML::lines, MeshXML::linestripind, MeshXML::linestrips, MeshXML::LOD, MeshXML::lodscale, MeshXML::logos, MeshXML::material, Mesh(), myMatNum, NUM_ZBUF_SEQ, MeshXML::ZeLogo::offset, XMLSupport::parse_bool(), polygon_offset, PostProcessLoading(), power, GFXMaterial::power, Hashtable< KEY, VALUE, SIZ >::Put(), MeshXML::quadind, MeshXML::quads, MeshXML::quadstripind, MeshXML::quadstrips, VSFileSystem::VSFile::Read(), READSTRING, MeshXML::reverse, reverse_vector(), MeshXML::ZeLogo::rotate, GFXMaterial::sa, GFXMaterial::sb, MeshXML::scale, SetBlendMode(), setEnvMap(), setLighting(), GFXMaterial::sg, MeshXML::sharevert, size, MeshXML::ZeLogo::size, VSFileSystem::VSFile::Size(), UniverseUtil::sqrt(), GFXMaterial::sr, t1(), TECHNIQUE, MeshXML::technique, TEXTURE, MeshXML::trifans, MeshXML::triind, MeshXML::tris, MeshXML::tristripind, MeshXML::tristrips, MeshXML::ZeLogo::type, MeshXML::usenormals, Vector, vert, MeshXML::vertexcount, MeshXML::vertices, vlist, vs_config, VSSwapHostFloatToLittle(), VSSwapHostIntToLittle(), Mesh_vec3f::x, x, Mesh_vec3f::y, y, Mesh_vec3f::z, and z.

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 }
virtual int Mesh::MeshType ( ) const
inlinevirtual

Reimplemented in SphereMesh.

Definition at line 266 of file mesh.h.

267  {
268  return 0;
269  }
unsigned int Mesh::numFX ( ) const
inline

Gets number of specialFX.

Definition at line 294 of file mesh.h.

References LocalFX.

295  {
296  return LocalFX.size();
297  }
unsigned int Mesh::numTextures ( ) const
inline

Definition at line 300 of file mesh.h.

References Decal.

Referenced by Background::Cache().

301  {
302  return Decal.size();
303  }
Vector const& Mesh::Position ( ) const
inline

Returns center of this mesh.

Definition at line 326 of file mesh.h.

References local_pos.

327  {
328  return local_pos;
329  }
void Mesh::PostProcessLoading ( struct MeshXML xml,
const vector< string > &  overrideTexture 
)
protected

Definition at line 1696 of file mesh_xml.cpp.

References a, ClearTangents(), MeshXML::decals, MeshXML::faction, MeshXML::fg, FLAT_SHADE, FactionUtil::GetFaction(), VegaConfig::getVariable(), GFXLINE, GFXLINESTRIP, GFXOptimizeList(), GFXQUAD, GFXQUADSTRIP, GFXSetMaterial(), GFXTRI, GFXTRIFAN, GFXTRISTRIP, GFXVertex::i, index, GFXVertex::j, j, GFXVertex::k, k, MeshXML::lineind, MeshXML::lines, MeshXML::linestripind, MeshXML::linestrips, Magnitude(), MeshXML::material, NormalizeNormals(), NormalizeTangents(), XMLSupport::parse_bool(), XMLSupport::parse_float(), MeshXML::quadind, MeshXML::quads, MeshXML::quadshade, MeshXML::quadstripind, MeshXML::quadstrips, MeshXML::scale, MeshXML::sharevert, SumNormals(), SumTangents(), MeshXML::technique, MeshXML::trifanind, MeshXML::trifans, MeshXML::triind, MeshXML::tris, MeshXML::trishade, MeshXML::tristripind, MeshXML::tristrips, updateMax(), MeshXML::usenormals, MeshXML::usetangents, v, Vector, MeshXML::vertices, vs_config, and z.

Referenced by LoadMeshes().

1697 {
1698  unsigned int i;
1699  unsigned int a = 0;
1700  unsigned int j;
1701  //begin vertex normal calculations if necessary
1702  if (!xml->usenormals) {
1703  ClearTangents( xml->vertices );
1704 
1705  vector< float >weights;
1706  weights.resize( xml->vertices.size(), 0.f );
1707 
1708  size_t i, j, n;
1709 
1710  SumNormals( xml->vertices, xml->triind, 0, xml->triind.size(), GFXTRI, weights );
1711  SumNormals( xml->vertices, xml->quadind, 0, xml->quadind.size(), GFXQUAD, weights );
1712  SumNormals( xml->vertices, xml->lineind, 0, xml->lineind.size(), GFXLINE, weights );
1713  for ( i = j = 0, n = xml->tristrips.size(); i < n; j += xml->tristrips[i++].size() )
1714  SumNormals( xml->vertices, xml->tristripind, j, j+xml->tristrips[i].size(), GFXTRISTRIP, weights );
1715  for ( i = j = 0, n = xml->quadstrips.size(); i < n; j += xml->quadstrips[i++].size() )
1716  SumNormals( xml->vertices, xml->quadstripind, j, j+xml->quadstrips[i].size(), GFXQUADSTRIP, weights );
1717  for ( i = j = 0, n = xml->trifans.size(); i < n; j += xml->trifans[i++].size() )
1718  SumNormals( xml->vertices, xml->trifanind, j, j+xml->trifans[i].size(), GFXTRIFAN, weights );
1719  for ( i = j = 0, n = xml->linestrips.size(); i < n; j += xml->linestrips[i++].size() )
1720  SumNormals( xml->vertices, xml->linestripind, j, j+xml->linestrips[i].size(), GFXLINESTRIP, weights );
1721  NormalizeNormals( xml->vertices, weights );
1722  } else {
1723  //Flip normals - someone thought VS should flips normals, ask him why.
1724  for (i = 0; i < xml->vertices.size(); ++i) {
1725  GFXVertex &v = xml->vertices[i];
1726  v.i *= -1;
1727  v.j *= -1;
1728  v.k *= -1;
1729  }
1730  }
1731  a = 0;
1732  std::vector< unsigned int > ind;
1733  for (a = 0; a < xml->tris.size(); a += 3)
1734  for (j = 0; j < 3; j++) {
1735  int ix = xml->triind[a+j];
1736  ind.push_back( ix );
1737  xml->tris[a+j].SetNormal( xml->vertices[ix].GetNormal() );
1738  xml->tris[a+j].SetTangent( xml->vertices[ix].GetTangent(),
1739  xml->vertices[ix].GetTangentParity() );
1740  }
1741  a = 0;
1742  for (a = 0; a < xml->quads.size(); a += 4)
1743  for (j = 0; j < 4; j++) {
1744  int ix = xml->quadind[a+j];
1745  ind.push_back( ix );
1746  xml->quads[a+j].SetNormal( xml->vertices[ix].GetNormal() );
1747  xml->quads[a+j].SetTangent( xml->vertices[ix].GetTangent(),
1748  xml->vertices[ix].GetTangentParity() );
1749  }
1750  a = 0;
1751  for (a = 0; a < xml->lines.size(); a += 2)
1752  for (j = 0; j < 2; j++) {
1753  int ix = xml->lineind[a+j];
1754  ind.push_back( ix );
1755  xml->lines[a+j].SetNormal( xml->vertices[ix].GetNormal() );
1756  }
1757  a = 0;
1758  unsigned int k = 0;
1759  unsigned int l = 0;
1760  for (l = a = 0; a < xml->tristrips.size(); a++)
1761  for (k = 0; k < xml->tristrips[a].size(); k++, l++) {
1762  int ix = xml->tristripind[l];
1763  ind.push_back( ix );
1764  xml->tristrips[a][k].SetNormal( xml->vertices[ix].GetNormal() );
1765  xml->tristrips[a][k].SetTangent( xml->vertices[ix].GetTangent(),
1766  xml->vertices[ix].GetTangentParity() );
1767  }
1768  for (l = a = 0; a < xml->trifans.size(); a++)
1769  for (k = 0; k < xml->trifans[a].size(); k++, l++) {
1770  int ix = xml->trifanind[l];
1771  ind.push_back( ix );
1772  xml->trifans[a][k].SetNormal( xml->vertices[ix].GetNormal() );
1773  xml->trifans[a][k].SetTangent( xml->vertices[ix].GetTangent(),
1774  xml->vertices[ix].GetTangentParity() );
1775  }
1776  for (l = a = 0; a < xml->quadstrips.size(); a++)
1777  for (k = 0; k < xml->quadstrips[a].size(); k++, l++) {
1778  int ix = xml->quadstripind[l];
1779  ind.push_back( ix );
1780  xml->quadstrips[a][k].SetNormal( xml->vertices[ix].GetNormal() );
1781  xml->quadstrips[a][k].SetTangent( xml->vertices[ix].GetTangent(),
1782  xml->vertices[ix].GetTangentParity() );
1783  }
1784  for (l = a = 0; a < xml->linestrips.size(); a++)
1785  for (k = 0; k < xml->linestrips[a].size(); k++, l++) {
1786  int ix = xml->linestripind[l];
1787  ind.push_back( ix );
1788  xml->linestrips[a][k].SetNormal( xml->vertices[ix].GetNormal() );
1789  }
1790  //TODO: add alpha handling
1791 
1792  //check for per-polygon flat shading
1793  unsigned int trimax = xml->tris.size()/3;
1794  a = 0;
1795  i = 0;
1796  j = 0;
1797  if (!xml->usenormals) {
1798  for (i = 0; i < trimax; i++, a += 3)
1799  if (FLAT_SHADE || xml->trishade[i] == 1) {
1800  for (j = 0; j < 3; j++) {
1801  Vector Cur = xml->vertices[xml->triind[a+j]].GetPosition();
1802  Cur = (xml->vertices[xml->triind[a+( (j+1)%3 )]].GetPosition()-Cur)
1803  .Cross( xml->vertices[xml->triind[a+( (j+2)%3 )]].GetPosition()-Cur );
1804  Normalize( Cur );
1805  xml->tris[a+j].SetNormal( Cur );
1806  }
1807  }
1808  a = 0;
1809  trimax = xml->quads.size()/4;
1810  for (i = 0; i < trimax; i++, a += 4)
1811  if ( xml->quadshade[i] == 1 || (FLAT_SHADE) ) {
1812  for (j = 0; j < 4; j++) {
1813  Vector Cur = xml->vertices[xml->quadind[a+j]].GetPosition();
1814  Cur = (xml->vertices[xml->quadind[a+( (j+1)%4 )]].GetPosition()-Cur)
1815  .Cross( xml->vertices[xml->quadind[a+( (j+2)%4 )]].GetPosition()-Cur );
1816  Normalize( Cur );
1817  xml->quads[a+j].SetNormal( Cur );
1818  }
1819  }
1820  }
1821  string factionname = FactionUtil::GetFaction( xml->faction );
1822  for (unsigned int LC = 0; LC < textureOverride.size(); ++LC)
1823  if (textureOverride[LC] != "") {
1824  while (xml->decals.size() <= LC) {
1826  xml->decals.push_back( z );
1827  }
1828  if (textureOverride[LC].find( ".ani" ) != string::npos) {
1829  xml->decals[LC].decal_name = "";
1830  xml->decals[LC].animated_name = textureOverride[LC];
1831  xml->decals[LC].alpha_name = "";
1832  } else {
1833  xml->decals[LC].animated_name = "";
1834  xml->decals[LC].alpha_name = "";
1835  xml->decals[LC].decal_name = textureOverride[LC];
1836  }
1837  }
1838  while ( Decal.size() < xml->decals.size() )
1839  Decal.push_back( NULL );
1840  {
1841  for (unsigned int i = 0; i < xml->decals.size(); i++)
1842  Decal[i] = ( TempGetTexture( xml, i, factionname ) );
1843  }
1844  while (Decal.back() == NULL && Decal.size() > 1)
1845  Decal.pop_back();
1846  initTechnique( xml->technique );
1847 
1848  unsigned int index = 0;
1849 
1850  unsigned int totalvertexsize = xml->tris.size()+xml->quads.size()+xml->lines.size();
1851  for (index = 0; index < xml->tristrips.size(); index++)
1852  totalvertexsize += xml->tristrips[index].size();
1853  for (index = 0; index < xml->trifans.size(); index++)
1854  totalvertexsize += xml->trifans[index].size();
1855  for (index = 0; index < xml->quadstrips.size(); index++)
1856  totalvertexsize += xml->quadstrips[index].size();
1857  for (index = 0; index < xml->linestrips.size(); index++)
1858  totalvertexsize += xml->linestrips[index].size();
1859  index = 0;
1860  vector< GFXVertex > vertexlist( totalvertexsize );
1861 
1862  mn = Vector( FLT_MAX, FLT_MAX, FLT_MAX );
1863  mx = Vector( -FLT_MAX, -FLT_MAX, -FLT_MAX );
1864  radialSize = 0;
1865  vector< enum POLYTYPE >polytypes;
1866  polytypes.insert( polytypes.begin(), totalvertexsize, GFXTRI );
1867  //enum POLYTYPE * polytypes= new enum POLYTYPE[totalvertexsize];//overkill but what the hell
1868  vector< int >poly_offsets;
1869  poly_offsets.insert( poly_offsets.begin(), totalvertexsize, 0 );
1870  int o_index = 0;
1871  if ( xml->tris.size() ) {
1872  polytypes[o_index] = GFXTRI;
1873  poly_offsets[o_index] = xml->tris.size();
1874  o_index++;
1875  }
1876  if ( xml->quads.size() ) {
1877  polytypes[o_index] = GFXQUAD;
1878  poly_offsets[o_index] = xml->quads.size();
1879  o_index++;
1880  }
1881  if ( xml->lines.size() ) {
1882  polytypes[o_index] = GFXLINE;
1883  poly_offsets[o_index] = xml->lines.size();
1884  o_index++;
1885  }
1886  for (a = 0; a < xml->tris.size(); a++, index++)
1887  vertexlist[index] = xml->tris[a];
1888  for (a = 0; a < xml->quads.size(); a++, index++)
1889  vertexlist[index] = xml->quads[a];
1890  for (a = 0; a < xml->lines.size(); a++, index++)
1891  vertexlist[index] = xml->lines[a];
1892  for (a = 0; a < xml->tristrips.size(); a++) {
1893  for (unsigned int m = 0; m < xml->tristrips[a].size(); m++, index++)
1894  vertexlist[index] = xml->tristrips[a][m];
1895  polytypes[o_index] = GFXTRISTRIP;
1896  poly_offsets[o_index] = xml->tristrips[a].size();
1897  o_index++;
1898  }
1899  for (a = 0; a < xml->trifans.size(); a++) {
1900  for (unsigned int m = 0; m < xml->trifans[a].size(); m++, index++)
1901  vertexlist[index] = xml->trifans[a][m];
1902  polytypes[o_index] = GFXTRIFAN;
1903  poly_offsets[o_index] = xml->trifans[a].size();
1904  o_index++;
1905  }
1906  for (a = 0; a < xml->quadstrips.size(); a++) {
1907  for (unsigned int m = 0; m < xml->quadstrips[a].size(); m++, index++)
1908  vertexlist[index] = xml->quadstrips[a][m];
1909  polytypes[o_index] = GFXQUADSTRIP;
1910  poly_offsets[o_index] = xml->quadstrips[a].size();
1911  o_index++;
1912  }
1913  for (a = 0; a < xml->linestrips.size(); a++) {
1914  for (unsigned int m = 0; m < xml->linestrips[a].size(); m++, index++)
1915  vertexlist[index] = xml->linestrips[a][m];
1916  polytypes[o_index] = GFXLINESTRIP;
1917  poly_offsets[o_index] = xml->linestrips[a].size();
1918  o_index++;
1919  }
1920  for (i = 0; i < index; ++i)
1921  updateMax( mn, mx, vertexlist[i] );
1922  //begin tangent calculations if necessary
1923  if (!xml->usetangents) {
1924  ClearTangents( vertexlist );
1925 
1926  vector< float >weights;
1927  vector< int > indices( vertexlist.size() ); //Oops, someday we'll use real indices
1928  weights.resize( vertexlist.size(), 0.f );
1929 
1930  size_t i, j, n;
1931  for (i = 0, n = vertexlist.size(); i < n; ++i)
1932  indices[i] = i;
1933  for (i = j = 0, n = polytypes.size(); i < n; j += poly_offsets[i++])
1934  SumTangents( vertexlist, indices, j, j+poly_offsets[i], polytypes[i], weights );
1935  NormalizeTangents( vertexlist, weights );
1936  }
1937  if (mn.i == FLT_MAX && mn.j == FLT_MAX && mn.k == FLT_MAX)
1938  mx.i = mx.j = mx.k = mn.i = mn.j = mn.k = 0;
1939  mn.i *= xml->scale.i;
1940  mn.j *= xml->scale.j;
1941  mn.k *= xml->scale.k;
1942  mx.i *= xml->scale.i;
1943  mx.j *= xml->scale.j;
1944  mx.k *= xml->scale.k;
1945  float x_center = (mn.i+mx.i)/2.0,
1946  y_center = (mn.j+mx.j)/2.0,
1947  z_center = (mn.k+mx.k)/2.0;
1948  local_pos = Vector( x_center, y_center, z_center );
1949  for (a = 0; a < totalvertexsize; a++) {
1950  vertexlist[a].x *= xml->scale.i; //FIXME
1951  vertexlist[a].y *= xml->scale.j;
1952  vertexlist[a].z *= xml->scale.k;
1953  }
1954  for (a = 0; a < xml->vertices.size(); a++) {
1955  xml->vertices[a].x *= xml->scale.i; //FIXME
1956  xml->vertices[a].y *= xml->scale.j;
1957  xml->vertices[a].z *= xml->scale.k;
1958  xml->vertices[a].i *= -1;
1959  xml->vertices[a].k *= -1;
1960  xml->vertices[a].j *= -1;
1961  }
1962  if (o_index || index)
1963  radialSize = .5*(mx-mn).Magnitude();
1964  if (xml->sharevert) {
1965  vlist = new GFXVertexList(
1966  (polytypes.size() ? &polytypes[0] : 0),
1967  xml->vertices.size(),
1968  (xml->vertices.size() ? &xml->vertices[0] : 0), o_index,
1969  (poly_offsets.size() ? &poly_offsets[0] : 0), false,
1970  (ind.size() ? &ind[0] : 0) );
1971  } else {
1972  static bool usopttmp = ( XMLSupport::parse_bool( vs_config->getVariable( "graphics", "OptimizeVertexArrays", "false" ) ) );
1973  static float optvertexlimit =
1974  ( XMLSupport::parse_float( vs_config->getVariable( "graphics", "OptimizeVertexCondition", "1.0" ) ) );
1975  bool cachunk = false;
1976  if ( usopttmp && (vertexlist.size() > 0) ) {
1977  int numopt = totalvertexsize;
1978  GFXVertex *newv;
1979  unsigned int *ind;
1980  GFXOptimizeList( &vertexlist[0], totalvertexsize, &newv, &numopt, &ind );
1981  if (numopt < totalvertexsize*optvertexlimit) {
1982  vlist = new GFXVertexList(
1983  (polytypes.size() ? &polytypes[0] : 0),
1984  numopt, newv, o_index,
1985  (poly_offsets.size() ? &poly_offsets[0] : 0), false,
1986  ind );
1987  cachunk = true;
1988  }
1989  free( ind );
1990  free( newv );
1991  }
1992  if (!cachunk) {
1993  if (vertexlist.size() == 0)
1994  vertexlist.resize( 1 );
1995  vlist = new GFXVertexList(
1996  (polytypes.size() ? &polytypes[0] : 0),
1997  totalvertexsize, &vertexlist[0], o_index,
1998  (poly_offsets.size() ? &poly_offsets[0] : 0) );
1999  }
2000  }
2001  CreateLogos( xml, xml->faction, xml->fg );
2002  //Calculate bounding sphere
2003  if (mn.i == FLT_MAX) {
2004  mn = Vector( 0, 0, 0 );
2005  mx = Vector( 0, 0, 0 );
2006  }
2007  GFXSetMaterial( myMatNum, xml->material );
2008 }
void Mesh::ProcessDrawQueue ( size_t  whichpass,
int  whichdrawqueue,
bool  zsort,
const QVector sortctr 
)
virtual

Will draw all undrawn meshes of this type.

Definition at line 957 of file mesh_gfx.cpp.

References GFXToggleTexture(), gl_options, i, gl_options_t::Multitexture, Technique::Pass::ShaderPass, technique, and Technique::Pass::type.

Referenced by SphereMesh::ProcessDrawQueue(), CityLights::ProcessDrawQueue(), ProcessUndrawnMeshes(), and ProcessZFarMeshes().

958 {
959  //Process the pass for all queued instances
960  const Technique::Pass &pass = technique->getPass( whichpass );
961  if (pass.type == Technique::Pass::ShaderPass)
962  ProcessShaderDrawQueue( whichpass, whichdrawqueue, zsort, sortctr );
963  else
964  ProcessFixedDrawQueue( whichpass, whichdrawqueue, zsort, sortctr );
965  //Restore texture units
966  for (unsigned int i = 0; i < gl_options.Multitexture; ++i)
967  GFXToggleTexture( i < 2, i );
968 }
void Mesh::ProcessUndrawnMeshes ( bool  pushSpecialEffects = false,
bool  nocamerasetup = false 
)
static

Will draw all undrawn meshes in total If pushSpclFX, the last series of meshes will be drawn with other lighting off.

Definition at line 561 of file mesh_gfx.cpp.

References _Universe, a, Universe::AccessCamera(), DEPTHWRITE, draw_queue, gl_options_t::ext_srgb_framebuffer, g_game, Camera::GetPosition(), GFXClear(), GFXDeactivateShader(), GFXDisable(), GFXEnable(), GFXFALSE, GFXPopGlobalEffects(), GFXPushGlobalEffects(), GFXTRUE, GL_FRAMEBUFFER_SRGB_EXT, gl_options, MESH_SPECIAL_FX_ONLY, NUM_ZBUF_SEQ, orig, Logo::ProcessDrawQueue(), ProcessDrawQueue(), undrawn_logos, undrawn_meshes, Camera::UpdateGFXFrustum(), Logo::will_be_drawn, will_be_drawn, game_data_t::zfar, and game_data_t::znear.

Referenced by GameStarSystem::Draw(), GameCockpit::Draw(), NavigationSystem::Draw(), GameUnit< UnitType >::DrawNow(), and Briefing::Render().

562 {
563  //clear Z buffer
565 
566  for (int a = 0; a < NUM_ZBUF_SEQ; a++) {
567  if (a == MESH_SPECIAL_FX_ONLY) {
570  } else {
572  }
573  std::sort( undrawn_meshes[a].begin(), undrawn_meshes[a].end() );
574  for (OrigMeshVector::iterator it = undrawn_meshes[a].begin(); it < undrawn_meshes[a].end(); ++it) {
575  Mesh *m = it->orig;
576  m->ProcessDrawQueue( it->passno, a, it->zsort, _Universe->AccessCamera()->GetPosition() );
577  m->will_be_drawn &= ( ~(1<<a) ); //not accurate any more
578  }
579  for (OrigMeshVector::iterator it = undrawn_meshes[a].begin(); it < undrawn_meshes[a].end(); ++it) {
580  Mesh *m = it->orig;
581  m->draw_queue[a].clear();
582  }
583  undrawn_meshes[a].clear();
584  if (a == MESH_SPECIAL_FX_ONLY) {
585  if (!pushSpecialEffects)
588  }
589  for (vector< Logo* >::iterator it = undrawn_logos.begin(); it < undrawn_logos.end(); it++) {
590  Logo *l = *it;
591  l->ProcessDrawQueue();
592  l->will_be_drawn = false;
593  }
594  undrawn_logos.clear();
595  }
596 
597  // Restore state
600  glDisable( GL_FRAMEBUFFER_SRGB_EXT );
601 }
void Mesh::ProcessZFarMeshes ( bool  nocamerasetup = false)
static

Definition at line 519 of file mesh_gfx.cpp.

References _Universe, a, Universe::AccessCamera(), draw_queue, gl_options_t::ext_srgb_framebuffer, g_game, Camera::GetPosition(), VegaConfig::getVariable(), GFXClear(), GFXDeactivateShader(), GFXFALSE, GFXTRUE, GL_FRAMEBUFFER_SRGB_EXT, gl_options, NUM_ZBUF_SEQ, orig, XMLSupport::parse_float(), ProcessDrawQueue(), Animation::ProcessFarDrawQueue(), undrawn_meshes, Camera::UpdateGFXFrustum(), vs_config, will_be_drawn, and game_data_t::zfar.

Referenced by GameStarSystem::Draw(), GameCockpit::Draw(), NavigationSystem::Draw(), and GameUnit< UnitType >::DrawNow().

520 {
521  int a = NUM_ZBUF_SEQ;
522 
523  //clear Z buffer
525 
526  static float far_margin = XMLSupport::parse_float( vs_config->getVariable( "graphics", "mesh_far_percent", ".8" ) );
528 
529  std::sort( undrawn_meshes[a].begin(), undrawn_meshes[a].end() );
530  for (OrigMeshVector::iterator it = undrawn_meshes[a].begin(); it < undrawn_meshes[a].end(); ++it) {
531  Mesh *m = it->orig;
532  m->ProcessDrawQueue( it->passno, a, it->zsort, _Universe->AccessCamera()->GetPosition() );
533  m->will_be_drawn &= ( ~(1<<a) ); //not accurate any more
534  }
535  for (OrigMeshVector::iterator it = undrawn_meshes[a].begin(); it < undrawn_meshes[a].end(); ++it) {
536  Mesh *m = it->orig;
537  m->draw_queue[a].clear();
538  }
539  undrawn_meshes[a].clear();
540 
543  glDisable( GL_FRAMEBUFFER_SRGB_EXT );
544 
545  Animation::ProcessFarDrawQueue( -FLT_MAX );
546 }
bool Mesh::queryBoundingBox ( const QVector start,
const float  err 
) const

queries this bounding box with a vector and radius

bool Mesh::queryBoundingBox ( const QVector start,
const QVector end,
const float  err 
) const

Queries bounding box with a ray.

void Mesh::RestoreCullFace ( int  whichdrawqueue)
virtual

Reimplemented in SphereMesh.

Definition at line 603 of file mesh_gfx.cpp.

References blendDst, blendSrc, CULLFACE, getCullFaceForcedOff(), GFXEnable(), SRCALPHA, and ZERO.

604 {
605  if ( blendDst != ZERO || getCullFaceForcedOff() )
606  if (blendSrc != SRCALPHA)
607  GFXEnable( CULLFACE );
608 }
float Mesh::rSize ( ) const
inline

returns the radial size of this

Definition at line 401 of file mesh.h.

References radialSize.

Referenced by AddDamageFX(), RingMesh::clipRadialSize(), HaloSystem::Draw(), GameUnit< UnitType >::Draw(), Draw(), GameUnit< UnitType >::DrawNow(), and DrawNow().

402  {
403  return radialSize;
404  }
void Mesh::SelectCullFace ( int  whichdrawqueue)
virtual

Will draw all undrawn far meshes beyond the range of zbuffer (better be convex).

Reimplemented in SphereMesh.

Definition at line 610 of file mesh_gfx.cpp.

References blendDst, blendSrc, CULLFACE, getCullFaceForcedOff(), getCullFaceForcedOn(), GFXDisable(), GFXEnable(), SRCALPHA, and ZERO.

611 {
612  if ( getCullFaceForcedOn() )
613  GFXEnable( CULLFACE );
614  else if ( getCullFaceForcedOff() )
615  GFXDisable( CULLFACE );
616  if (blendDst != ZERO)
617  if ( blendSrc != SRCALPHA || getCullFaceForcedOff() )
618  GFXDisable( CULLFACE );
619 }
void Mesh::SetBlendMode ( BLENDFUNC  src,
BLENDFUNC  dst,
bool  lodcascade = false 
)

Definition at line 341 of file mesh.cpp.

References blendDst, blendSrc, draw_sequence, i, numlods, ONE, and ZERO.

Referenced by addShieldMesh(), SphereMesh::InitSphere(), and LoadMeshes().

342 {
343  blendSrc = src;
344  blendDst = dst;
345  draw_sequence = 0;
346  if (blendDst != ZERO) {
347  draw_sequence++;
348  if (blendDst != ONE)
349  draw_sequence++;
350  }
351  if (orig) {
353  orig->blendSrc = src;
354  orig->blendDst = dst;
355  if (lodcascade) {
356  for (int i = 1; i < numlods; i++) {
358  orig[i].blendSrc = src;
359  orig[i].blendDst = dst;
360  }
361  }
362  }
363 }
void Mesh::setConvex ( bool  b)

Definition at line 163 of file mesh.cpp.

References b, convex, orig, and setConvex().

Referenced by CityLights::CityLights(), SphereMesh::InitSphere(), MakeFogMesh(), setConvex(), and SphereMesh::SphereMesh().

164 {
165  this->convex = b;
166  if (orig && orig != this)
167  orig->setConvex( b );
168 }
void Mesh::setCurrentFrame ( float  which)

Definition at line 278 of file mesh.cpp.

References framespersecond.

Referenced by GameUnit< UnitType >::Draw(), GameUnit< UnitType >::DrawNow(), and getLOD().

279 {
280  framespersecond = which;
281 }
void Mesh::setEnvMap ( GFXBOOL  newValue,
bool  lodcascade = false 
)
inline

Definition at line 363 of file mesh.h.

References envMapAndLit, i, and numlods.

Referenced by addShieldMesh(), Box::Box(), EnableSpecialFX(), Fork(), SphereMesh::InitSphere(), InitUnit(), and LoadMeshes().

364  {
365  envMapAndLit = ( newValue ? (envMapAndLit|0x1) : ( envMapAndLit&(~0x1) ) );
366  if (lodcascade && orig)
367  for (int i = 0; i < numlods; i++)
368  orig[i].setEnvMap( newValue );
369  }
void Mesh::setLighting ( GFXBOOL  newValue,
bool  lodcascade = false 
)
inline

Definition at line 374 of file mesh.h.

References envMapAndLit, i, and numlods.

Referenced by addShieldMesh(), EnableSpecialFX(), Fork(), InitUnit(), and LoadMeshes().

375  {
376  envMapAndLit = ( newValue ? (envMapAndLit|0x2) : ( envMapAndLit&(~0x2) ) );
377  if (lodcascade && orig)
378  for (int i = 0; i < numlods; i++)
379  orig[i].setLighting( newValue );
380  }
void Mesh::SetMaterial ( const GFXMaterial mat)

Sets the material of this mesh to mat (affects original as well)

Definition at line 265 of file mesh.cpp.

References GFXSetMaterial(), i, myMatNum, and numlods.

Referenced by Atmosphere::Draw(), and SetFogMaterialColor().

266 {
267  GFXSetMaterial( myMatNum, mat );
268  if (orig)
269  for (int i = 0; i < numlods; i++)
270  orig[i].myMatNum = myMatNum;
271 }
void Mesh::setTechnique ( TechniquePtr  tech)
inline

Definition at line 163 of file mesh.h.

163 { technique = tech; }
void Mesh::setTextureCumulativeTime ( double  d)

Definition at line 261 of file mesh_gfx.cpp.

References Decal, and i.

262 {
263  for (unsigned int i = 0; i < Decal.size(); ++i)
264  if (Decal[i])
265  Decal[i]->setTime( d );
266 }
void Mesh::setVertexList ( GFXVertexList _vlist)

Definition at line 293 of file mesh.cpp.

References vlist.

294 {
295  vlist = _vlist;
296 }
void Mesh::setVirtualBoundingBox ( const Vector mn,
const Vector mx,
float  rsize 
)
inline

Definition at line 417 of file mesh.h.

References mn, mx, and radialSize.

418  {
419  radialSize = rsize;
420  this->mn = mn;
421  this->mx = mx;
422  }
Texture* Mesh::texture ( int  i) const
inline

Definition at line 304 of file mesh.h.

References Decal.

Referenced by Background::Cache(), and SphereMesh::InitSphere().

305  {
306  return Decal[i];
307  }
void Mesh::UnDraw ( )
inline

so one can query if it has or not been drawn

Definition at line 321 of file mesh.h.

References GFXFALSE, and will_be_drawn.

322  {
324  }
void Mesh::UpdateFX ( float  ttime)

based on TTL, etc, updates shield effects

Definition at line 108 of file mesh_fx.cpp.

References i, and LocalFX.

Referenced by Draw().

109 {
110  //adjusts lights by TTL, eventually removing them
111  for (unsigned int i = 0; i < LocalFX.size(); i++)
112  if ( !LocalFX[i].Update( howmuchtime ) ) {
113  LocalFX.erase( LocalFX.begin()+i );
114  i--;
115  }
116 }

Friends And Related Function Documentation

friend class OrigMeshContainer
friend

Needs to have access to our class.

Definition at line 231 of file mesh.h.

Referenced by Draw().

Member Data Documentation

unsigned char Mesh::alphatest
protected

Definition at line 218 of file mesh.h.

Referenced by InitUnit(), and LoadMeshes().

Hashtable< std::string, std::vector< int >, 503 > Mesh::animationSequences
staticprotected

Definition at line 181 of file mesh.h.

Referenced by getLOD(), getNumAnimationFrames(), and LoadMeshes().

bool Mesh::convex
protected

The blend functions.

Definition at line 217 of file mesh.h.

Referenced by getConvex(), InitUnit(), Mesh(), and setConvex().

vector< Vector > Mesh::detailPlanes
protected

Definition at line 210 of file mesh.h.

Referenced by LoadMeshes().

Texture* Mesh::detailTexture
protected

Definition at line 209 of file mesh.h.

Referenced by InitUnit(), and LoadMeshes().

vector< MeshDrawContext >* Mesh::draw_queue
protected

Support for reorganized rendering.

Definition at line 223 of file mesh.h.

Referenced by Box::Box(), Draw(), Fork(), SphereMesh::InitSphere(), InitUnit(), LoadMeshes(), Box::ProcessDrawQueue(), ProcessUndrawnMeshes(), ProcessZFarMeshes(), and ~Mesh().

int Mesh::draw_sequence
protected

How transparent this mesh is (in what order should it be rendered in.

Definition at line 225 of file mesh.h.

Referenced by Box::Box(), Draw(), DrawNow(), EnableSpecialFX(), SphereMesh::InitSphere(), InitUnit(), and SetBlendMode().

char Mesh::envMapAndLit
protected

whether this should be environment mapped 0x1 and 0x2 for if it should be lit (ored together)

Definition at line 213 of file mesh.h.

Referenced by forceCullFace(), getCullFaceForcedOff(), getCullFaceForcedOn(), getEnvMap(), getLighting(), InitUnit(), setEnvMap(), and setLighting().

Logo* Mesh::forcelogos
protected

The number of force logos on this mesh (original)

Definition at line 196 of file mesh.h.

Referenced by Fork(), InitUnit(), and ~Mesh().

float Mesh::framespersecond
protected

Definition at line 191 of file mesh.h.

Referenced by getCurrentFrame(), getFramesPerSecond(), InitUnit(), LoadMeshes(), and setCurrentFrame().

string Mesh::hash_name
protected

The name of this unit.

Definition at line 227 of file mesh.h.

Referenced by getLOD(), getNumAnimationFrames(), SphereMesh::InitSphere(), LoadExistant(), Mesh(), and ~Mesh().

Vector Mesh::local_pos
protected

the position of the center of this mesh for collision detection

Definition at line 178 of file mesh.h.

Referenced by Fork(), InitUnit(), and Position().

vector< MeshFX > Mesh::LocalFX
protected

The enabled light effects on this mesh.

Definition at line 233 of file mesh.h.

Referenced by AddDamageFX(), Draw(), DrawNow(), numFX(), and UpdateFX().

float Mesh::lodsize
protected

The size that this LOD (if original) comes into effect.

Definition at line 194 of file mesh.h.

Referenced by getLOD(), SphereMesh::InitSphere(), and InitUnit().

Hashtable< std::string, Mesh, 503 > Mesh::meshHashTable
staticprotected

The hash table of all meshes.

Definition at line 180 of file mesh.h.

Referenced by Box::Box(), SphereMesh::InitSphere(), LoadExistant(), Mesh(), and ~Mesh().

Vector Mesh::mn
protected

Definition at line 186 of file mesh.h.

Referenced by corner_min(), Fork(), SphereMesh::InitSphere(), InitUnit(), and setVirtualBoundingBox().

Vector Mesh::mx
protected

bounding box

Definition at line 185 of file mesh.h.

Referenced by corner_max(), Fork(), SphereMesh::InitSphere(), InitUnit(), and setVirtualBoundingBox().

unsigned int Mesh::myMatNum
protected

The number of the appropriate material for this mesh (default 0)

Definition at line 204 of file mesh.h.

Referenced by DrawNow(), GetMaterial(), InitUnit(), LoadMeshes(), and SetMaterial().

int Mesh::numforcelogo
protected

Definition at line 197 of file mesh.h.

Referenced by Fork(), and InitUnit().

int Mesh::numlods
protected

num lods contained in the array of Mesh "orig"

Definition at line 190 of file mesh.h.

Referenced by getLOD(), getNumLOD(), SphereMesh::InitSphere(), InitUnit(), SetBlendMode(), setEnvMap(), setLighting(), and SetMaterial().

int Mesh::numsquadlogo
protected

Definition at line 200 of file mesh.h.

Referenced by Fork(), and InitUnit().

float Mesh::polygon_offset
protected

Definition at line 211 of file mesh.h.

Referenced by InitUnit(), and LoadMeshes().

float Mesh::radialSize
protected

The radial size of this mesh.

Definition at line 188 of file mesh.h.

Referenced by clipRadialSize(), Fork(), SphereMesh::InitSphere(), InitUnit(), rSize(), and setVirtualBoundingBox().

int Mesh::refcount
protected

The refcount:: how many meshes are referencing the appropriate original.

Definition at line 183 of file mesh.h.

Referenced by Box::Box(), Fork(), SphereMesh::InitSphere(), Texture::InitTexture(), InitUnit(), LoadExistant(), Mesh(), and ~Mesh().

Logo* Mesh::squadlogos
protected

The number of squad logos on this mesh (original)

Definition at line 199 of file mesh.h.

Referenced by Fork(), InitUnit(), and ~Mesh().

TechniquePtr Mesh::technique
protected

The technique used to render this mesh.

Definition at line 206 of file mesh.h.

Referenced by Draw(), getTechnique(), initTechnique(), OrigMeshContainer::operator<(), OrigMeshContainer::OrigMeshContainer(), and ProcessDrawQueue().

GFXVertexList* Mesh::vlist
protected

tri,quad,line, strips, etc

Definition at line 202 of file mesh.h.

Referenced by Box::Box(), DrawNow(), Fork(), GetPolys(), getVertexList(), SphereMesh::InitSphere(), InitUnit(), LoadMeshes(), setVertexList(), and ~Mesh().

GFXBOOL Mesh::will_be_drawn
protected

Whether this original will be drawn this frame.

Definition at line 215 of file mesh.h.

Referenced by Draw(), HasBeenDrawn(), InitUnit(), ProcessUndrawnMeshes(), ProcessZFarMeshes(), and UnDraw().


The documentation for this class was generated from the following files: