Editor
Class TerrainBuilder

source: e:\games\UnrealTournament\Editor\Classes\TerrainBuilder.uc
Core.Object
   |
   +--Editor.BrushBuilder
      |
      +--Editor.TerrainBuilder
Direct Known Subclasses:None

class TerrainBuilder
extends Editor.BrushBuilder

//============================================================================= // TerrainBuilder: Builds a 3D cube brush, with a tessellated bottom. //=============================================================================
Variables
 Width, Breadth
 WidthSegments, DepthSegments
           How many breaks to have in each direction
 name GroupName
           How many breaks to have in each direction


Function Summary
 void BuildTerrain(int Direction, float dx, float dy, float dz, int WidthSeg, int DepthSeg)



Source Code


00001	//=============================================================================
00002	// TerrainBuilder: Builds a 3D cube brush, with a tessellated bottom.
00003	//=============================================================================
00004	class TerrainBuilder
00005		extends BrushBuilder;
00006	
00007	var() float Height, Width, Breadth;
00008	var() int WidthSegments, DepthSegments;		// How many breaks to have in each direction
00009	var() name GroupName;
00010	
00011	function BuildTerrain( int Direction, float dx, float dy, float dz, int WidthSeg, int DepthSeg )
00012	{
00013		local int n,nbottom,i,j,k,x,y,idx;
00014		local float WidthStep, DepthStep;
00015	
00016		//
00017		// TOP
00018		//
00019	
00020		n = GetVertexCount();
00021	
00022		// Create vertices
00023		for( i=-1; i<2; i+=2 )
00024			for( j=-1; j<2; j+=2 )
00025				for( k=-1; k<2; k+=2 )
00026					Vertex3f( i*dx/2, j*dy/2, k*dz/2 );
00027	
00028		// Create the top and the first tri of each side.
00029		Poly3i(Direction,n+3,n+1,n+5, 'sky');
00030		Poly3i(Direction,n+3,n+5,n+7, 'sky');
00031	
00032		Poly3i(Direction,n+0,n+1,n+3, 'sky');
00033		Poly3i(Direction,n+2,n+3,n+7, 'sky');
00034		Poly3i(Direction,n+6,n+7,n+5, 'sky');
00035		Poly3i(Direction,n+4,n+5,n+1, 'sky');
00036	
00037		//
00038		// BOTTOM
00039		//
00040	
00041		nbottom = GetVertexCount();
00042	
00043		// Create vertices
00044		WidthStep = dx / WidthSeg;
00045		DepthStep = dy / DepthSeg;
00046	
00047		for( x = 0 ; x < WidthSeg + 1 ; x++ )
00048			for( y = 0 ; y < DepthSeg + 1 ; y++ )
00049				Vertex3f( (WidthStep * x) - dx/2, (DepthStep * y) - dy/2, -(dz/2) );
00050	
00051		// Create the bottom as a mesh of triangles
00052		for( x = 0 ; x < WidthSeg ; x++ )
00053			for( y = 0 ; y < DepthSeg ; y++ )
00054			{
00055				Poly3i(-Direction,
00056					(nbottom+y)		+ ((DepthSeg+1) * x),
00057					(nbottom+y)		+ ((DepthSeg+1) * (x+1)),
00058					((nbottom+1)+y)	+ ((DepthSeg+1) * (x+1)),
00059					'ground');
00060				Poly3i(-Direction,
00061					(nbottom+y)		+ ((DepthSeg+1) * x),
00062					((nbottom+1)+y) + ((DepthSeg+1) * (x+1)),
00063					((nbottom+1)+y) + ((DepthSeg+1) * x),
00064					'ground');
00065			}
00066	
00067		//
00068		// SIDES
00069		//
00070		// The bottom poly of each side is basically a triangle fan.
00071		//
00072		for( x = 0 ; x < WidthSeg ; x++ )
00073		{
00074			Poly3i(-Direction,
00075				n+7,
00076				nbottom + DepthSeg + ((DepthSeg+1) * x),
00077				nbottom + DepthSeg + ((DepthSeg+1) * (x + 1)), 'sky' );
00078			Poly3i(-Direction,
00079				n+1,
00080				nbottom + ((DepthSeg+1) * (x + 1)),
00081				nbottom + ((DepthSeg+1) * x), 'sky' );
00082		}
00083		for( y = 0 ; y < DepthSeg ; y++ )
00084		{
00085			Poly3i(-Direction,
00086				n+3,
00087				nbottom + y,
00088				nbottom + (y + 1), 'sky' );
00089			Poly3i(-Direction,
00090				n+5,
00091				nbottom + ((DepthSeg+1) * WidthSeg) + (y + 1),
00092				nbottom + ((DepthSeg+1) * WidthSeg) + y, 'sky' );
00093		}
00094	}
00095	
00096	event bool Build()
00097	{
00098		if( Height<=0 || Width<=0 || Breadth<=0 || WidthSegments<=0 || DepthSegments<=0 )
00099			return BadParameters();
00100	
00101		BeginBrush( false, GroupName );
00102		BuildTerrain( +1, Breadth, Width, Height, WidthSegments, DepthSegments );
00103		return EndBrush();
00104	}
00105	
00106	defaultproperties
00107	{
00108	     Height=256.000000
00109	     Width=256.000000
00110	     Breadth=512.000000
00111	     WidthSegments=4
00112	     DepthSegments=2
00113	     GroupName=Terrain
00114	     BitmapFilename="BBTerrain"
00115	     ToolTip="BSP Based Terrain"
00116	}

End Source Code