Ejemplo n.º 1
0
Q3BSPLeaf *Q3BSPRep::createLeaf( int n ){
	q3_leaf *q3leaf=(q3_leaf*)header.dir[4].lump+n;

	Q3BSPLeaf *leaf=d_new Q3BSPLeaf;

	leaf->cluster=q3leaf->cluster;

	Vector mins( q3leaf->mins[0],q3leaf->mins[1],q3leaf->mins[2] );
	Vector maxs( q3leaf->maxs[0],q3leaf->maxs[1],q3leaf->maxs[2] );
	leaf->box=Box( tf(mins) );
	leaf->box.update( tf(maxs) );
	int *leaffaces=(int*)header.dir[5].lump+q3leaf->leafface;

	for( int k=0;k<q3leaf->n_leaffaces;++k ){

		int face_n=leaffaces[k];

		map<int,Q3BSPFace*>::const_iterator it=q3face_map.find(face_n);
		if( it!=q3face_map.end() ){
			if( it->second ) leaf->faces.push_back( it->second );
			continue;
		}

		q3_face *q3face=(q3_face*)header.dir[13].lump+leaffaces[k];

		if( q3face->type==1 || q3face->type==3 ){
			if( !q3face->n_meshverts || (q3face->n_meshverts%3) ) continue;
		}else if( q3face->type!=2 ) continue;

		bool draw=true,solid=true;

		if( q3face->texture>=0 ){
			q3_tex *q3tex=(q3_tex*)header.dir[1].lump+q3face->texture;
			if( !(q3tex->contents & 1) ) continue;
			if( q3tex->flags & 0x84 ) draw=false;
		}

		if( !draw && !solid ) continue;

		Q3BSPFace *face=0;
		if( draw ){
			Surf *surf=findSurf( q3face );
			face=d_new Q3BSPFace;
			face->t_surf=surf;
			face->vert=surf->verts.size();
			face->tri=surf->tris.size();
			face->n_verts=face->n_tris=0;
			leaf->faces.push_back( face );
			faces.push_back( face );
			q3face_map.insert( make_pair( face_n,face ) );
		}

		if( q3face->type==2 ){
			patchFace( face,q3face,draw,solid,1 );
		}else{
			meshFace( face,q3face,draw,solid );
		}
	}

	return leaf;
}
Ejemplo n.º 2
0
int getObjectSurfs( ObjectDB *odb, LWMeshInfo *mesh, GlobalFunc *global )
{
   LWSurfaceFuncs *surff;
   LWSurfaceID *surfid;
   const char *tag;
   double *dval;
   int i;

   /* get the surface ID array */

   surff = global( "Surface Functions" /*LWSURFACEFUNCS_GLOBAL*/, GFUSE_TRANSIENT );
   if ( !surff ) return 0;
   surfid = surff->byObject( odb->filename );
   if ( !surfid ) return 0;

   /* count the surface IDs and alloc the surface array */

   for ( odb->nsurfaces = 0; ; odb->nsurfaces++ )
      if ( !surfid[ odb->nsurfaces ] ) break;
   odb->surf = calloc( odb->nsurfaces, sizeof( DBSurface ));
   if ( !odb->surf ) {
      odb->nsurfaces = 0;
      return 0;
   }

   /* fill in the surface parameters */

   for ( i = 0; i < odb->nsurfaces; i++ ) {
      odb->surf[ i ].id = surfid[ i ];
      tag = surff->name( surfid[ i ] );
      odb->surf[ i ].name = malloc( strlen( tag ) + 1 );
      if ( !odb->surf[ i ].name ) {
         freeObjectSurfs( odb );
         return 0;
      }
      strcpy( odb->surf[ i ].name, tag );

      dval = surff->getFlt( surfid[ i ], SURF_COLR );
      odb->surf[ i ].colr[ 0 ] = ( float ) dval[ 0 ];
      odb->surf[ i ].colr[ 1 ] = ( float ) dval[ 1 ];
      odb->surf[ i ].colr[ 2 ] = ( float ) dval[ 2 ];

      dval = surff->getFlt( surfid[ i ], SURF_LUMI );
      odb->surf[ i ].lumi = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_DIFF );
      odb->surf[ i ].diff = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_SPEC );
      odb->surf[ i ].spec = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_REFL );
      odb->surf[ i ].refl = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_TRAN );
      odb->surf[ i ].tran = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_TRNL );
      odb->surf[ i ].trnl = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_RIND );
      odb->surf[ i ].rind = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_BUMP );
      odb->surf[ i ].bump = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_GLOS );
      odb->surf[ i ].glos = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_SHRP );
      odb->surf[ i ].shrp = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_SMAN );
      odb->surf[ i ].sman = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_RSAN );
      odb->surf[ i ].rsan = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_TSAN );
      odb->surf[ i ].tsan = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_CLRF );
      odb->surf[ i ].clrf = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_CLRH );
      odb->surf[ i ].clrh = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_ADTR );
      odb->surf[ i ].adtr = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_AVAL );
      odb->surf[ i ].aval = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_GVAL );
      odb->surf[ i ].gval = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_LSIZ );
      odb->surf[ i ].lsiz = ( float ) *dval;

      dval = surff->getFlt( surfid[ i ], SURF_LCOL );
      odb->surf[ i ].lcol[ 0 ] = ( float ) dval[ 0 ];
      odb->surf[ i ].lcol[ 1 ] = ( float ) dval[ 1 ];
      odb->surf[ i ].lcol[ 2 ] = ( float ) dval[ 2 ];

      odb->surf[ i ].alph = surff->getInt( surfid[ i ], SURF_ALPH );
      odb->surf[ i ].rfop = surff->getInt( surfid[ i ], SURF_RFOP );
      odb->surf[ i ].trop = surff->getInt( surfid[ i ], SURF_TROP );
      odb->surf[ i ].side = surff->getInt( surfid[ i ], SURF_SIDE );
      odb->surf[ i ].glow = surff->getInt( surfid[ i ], SURF_GLOW );
      odb->surf[ i ].line = surff->getInt( surfid[ i ], SURF_LINE );

      odb->surf[ i ].rimg = surff->getImg( surfid[ i ], SURF_RIMG );
      odb->surf[ i ].timg = surff->getImg( surfid[ i ], SURF_TIMG );
   }

   /* find surface index for each polygon */

   for ( i = 0; i < odb->npolygons; i++ ) {
      tag = mesh->polTag( mesh, odb->pol[ i ].id, LWPTAG_SURF );
      odb->pol[ i ].sindex = findSurf( odb, tag );
   }

   return 1;
}