home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Editor / Classes / TerrainBuilder.uc < prev    next >
Text File  |  2003-10-22  |  3KB  |  125 lines

  1. //=============================================================================
  2. // TerrainBuilder: Builds a 3D cube brush, with a tessellated bottom.
  3. //=============================================================================
  4. class TerrainBuilder
  5.     extends BrushBuilder;
  6.  
  7. var() float Height, Width, Breadth;
  8. var() int WidthSegments, DepthSegments;        // How many breaks to have in each direction
  9. var() name GroupName;
  10.  
  11. function BuildTerrain( int Direction, float dx, float dy, float dz, int WidthSeg, int DepthSeg )
  12. {
  13.     local int n,nbottom,ntop,i,j,k,x,y;
  14.     local float WidthStep, DepthStep;
  15.  
  16.     //
  17.     // TOP
  18.     //
  19.  
  20.     n = GetVertexCount();
  21.  
  22.     // Create vertices
  23.     for( i=-1; i<2; i+=2 )
  24.         for( j=-1; j<2; j+=2 )
  25.             for( k=-1; k<2; k+=2 )
  26.                 Vertex3f( i*dx/2, j*dy/2, k*dz/2 );
  27.  
  28.     // Create the top
  29.     Poly4i(Direction,n+3,n+1,n+5,n+7, 'sky');
  30.  
  31.     //
  32.     // BOTTOM
  33.     //
  34.  
  35.     nbottom = GetVertexCount();
  36.  
  37.     // Create vertices
  38.     WidthStep = dx / WidthSeg;
  39.     DepthStep = dy / DepthSeg;
  40.  
  41.     for( x = 0 ; x < WidthSeg + 1 ; x++ )
  42.         for( y = 0 ; y < DepthSeg + 1 ; y++ )
  43.             Vertex3f( (WidthStep * x) - dx/2, (DepthStep * y) - dy/2, -(dz/2) );
  44.  
  45.     ntop = GetVertexCount();
  46.  
  47.     for( x = 0 ; x < WidthSeg + 1 ; x++ )
  48.         for( y = 0 ; y < DepthSeg + 1 ; y++ )
  49.             Vertex3f( (WidthStep * x) - dx/2, (DepthStep * y) - dy/2, dz/2 );
  50.  
  51.     // Create the bottom as a mesh of triangles
  52.     for( x = 0 ; x < WidthSeg ; x++ )
  53.         for( y = 0 ; y < DepthSeg ; y++ )
  54.         {
  55.             Poly3i(-Direction,
  56.                 (nbottom+y)        + ((DepthSeg+1) * x),
  57.                 (nbottom+y)        + ((DepthSeg+1) * (x+1)),
  58.                 ((nbottom+1)+y)    + ((DepthSeg+1) * (x+1)),
  59.                 'ground');
  60.             Poly3i(-Direction,
  61.                 (nbottom+y)        + ((DepthSeg+1) * x),
  62.                 ((nbottom+1)+y) + ((DepthSeg+1) * (x+1)),
  63.                 ((nbottom+1)+y) + ((DepthSeg+1) * x),
  64.                 'ground');
  65.         }
  66.  
  67.     //
  68.     // SIDES
  69.     //
  70.     // The bottom poly of each side is basically a triangle fan.
  71.     //
  72.     for( x = 0 ; x < WidthSeg ; x++ )
  73.     {
  74.         Poly4i(-Direction,
  75.             nbottom + DepthSeg + ((DepthSeg+1) * x),
  76.             nbottom + DepthSeg + ((DepthSeg+1) * (x + 1)),
  77.             ntop + DepthSeg + ((DepthSeg+1) * (x + 1)),
  78.             ntop + DepthSeg + ((DepthSeg+1) * x),
  79.             'sky' );
  80.         Poly4i(-Direction,
  81.             nbottom + ((DepthSeg+1) * (x + 1)),
  82.             nbottom + ((DepthSeg+1) * x),
  83.             ntop + ((DepthSeg+1) * x),
  84.             ntop + ((DepthSeg+1) * (x + 1)),
  85.             'sky' );
  86.     }
  87.     for( y = 0 ; y < DepthSeg ; y++ )
  88.     {
  89.         Poly4i(-Direction,
  90.             nbottom + y,
  91.             nbottom + (y + 1),
  92.             ntop + (y + 1),
  93.             ntop + y,
  94.             'sky' );
  95.         Poly4i(-Direction,
  96.             nbottom + ((DepthSeg+1) * WidthSeg) + (y + 1),
  97.             nbottom + ((DepthSeg+1) * WidthSeg) + y,
  98.             ntop + ((DepthSeg+1) * WidthSeg) + y,
  99.             ntop + ((DepthSeg+1) * WidthSeg) + (y + 1),
  100.             'sky' );
  101.     }
  102. }
  103.  
  104. event bool Build()
  105. {
  106.     if( Height<=0 || Width<=0 || Breadth<=0 || WidthSegments<=0 || DepthSegments<=0 )
  107.         return BadParameters();
  108.  
  109.     BeginBrush( false, GroupName );
  110.     BuildTerrain( +1, Breadth, Width, Height, WidthSegments, DepthSegments );
  111.     return EndBrush();
  112. }
  113.  
  114. defaultproperties
  115. {
  116.     Height=256
  117.     Width=256
  118.     Breadth=512
  119.     WidthSegments=4
  120.     DepthSegments=2
  121.     GroupName=Terrain
  122.     BitmapFilename="BBTerrain"
  123.     ToolTip="BSP Based Terrain"
  124. }
  125.