## Editor
Class TerrainBuilder

source: C:\XIII\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,ntop,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
    00029		Poly4i(Direction,n+3,n+1,n+5,n+7, 'sky');
    00030
    00031		//
    00032		// BOTTOM
    00033		//
    00034
    00035		nbottom = GetVertexCount();
    00036
    00037		// Create vertices
    00038		WidthStep = dx / WidthSeg;
    00039		DepthStep = dy / DepthSeg;
    00040
    00041		for( x = 0 ; x < WidthSeg + 1 ; x++ )
    00042			for( y = 0 ; y < DepthSeg + 1 ; y++ )
    00043				Vertex3f( (WidthStep * x) - dx/2, (DepthStep * y) - dy/2, -(dz/2) );
    00044
    00045		ntop = GetVertexCount();
    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			Poly4i(-Direction,
    00075				nbottom + DepthSeg + ((DepthSeg+1) * x),
    00076				nbottom + DepthSeg + ((DepthSeg+1) * (x + 1)),
    00077				ntop + DepthSeg + ((DepthSeg+1) * (x + 1)),
    00078				ntop + DepthSeg + ((DepthSeg+1) * x),
    00079				'sky' );
    00080			Poly4i(-Direction,
    00081				nbottom + ((DepthSeg+1) * (x + 1)),
    00082				nbottom + ((DepthSeg+1) * x),
    00083				ntop + ((DepthSeg+1) * x),
    00084				ntop + ((DepthSeg+1) * (x + 1)),
    00085				'sky' );
    00086		}
    00087		for( y = 0 ; y < DepthSeg ; y++ )
    00088		{
    00089			Poly4i(-Direction,
    00090				nbottom + y,
    00091				nbottom + (y + 1),
    00092				ntop + (y + 1),
    00093				ntop + y,
    00094				'sky' );
    00095			Poly4i(-Direction,
    00096				nbottom + ((DepthSeg+1) * WidthSeg) + (y + 1),
    00097				nbottom + ((DepthSeg+1) * WidthSeg) + y,
    00098				ntop + ((DepthSeg+1) * WidthSeg) + y,
    00099				ntop + ((DepthSeg+1) * WidthSeg) + (y + 1),
    00100				'sky' );
    00101		}
    00102	}
    00103
    00104	event bool Build()
    00105	{
    00106		if( Height<=0 || Width<=0 || Breadth<=0 || WidthSegments<=0 || DepthSegments<=0 )
    00107			return BadParameters();
    00108
    00109		BeginBrush( false, GroupName );
    00110		BuildTerrain( +1, Breadth, Width, Height, WidthSegments, DepthSegments );
    00111		return EndBrush();
    00112	}
    00113
    00114	defaultproperties
    00115	{
    00116	     Height=256.000000
    00117	     width=256.000000
    00118	     Breadth=512.000000
    00119	     WidthSegments=4
    00120	     DepthSegments=2
    00121	     GroupName="Terrain"
    00122	     BitmapFilename="BBTerrain"
    00123	     ToolTip="BSP Based Terrain"
    00124	}

End Source Code