Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Editor.TerrainBuilder


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
//=============================================================================
// TerrainBuilder: Builds a 3D cube brush, with a tessellated bottom.
//=============================================================================
class TerrainBuilder
    extends BrushBuilder;

var() float Height, Width, Breadth;
var() int WidthSegments, DepthSegments;     // How many breaks to have in each direction
var() name GroupName;

function BuildTerrain( int Direction, float dx, float dy, float dz, int WidthSeg, int DepthSeg )
{
    local int n,nbottom,ntop,i,j,k,x,y;
    local float WidthStep, DepthStep;

    //
    // TOP
    //

    n = GetVertexCount();

    // Create vertices
    for( i=-1; i<2; i+=2 )
        for( j=-1; j<2; j+=2 )
            for( k=-1; k<2; k+=2 )
                Vertex3f( i*dx/2, j*dy/2, k*dz/2 );

    // Create the top
    Poly4i(Direction,n+3,n+1,n+5,n+7, 'sky');

    //
    // BOTTOM
    //

    nbottom = GetVertexCount();

    // Create vertices
    WidthStep = dx / WidthSeg;
    DepthStep = dy / DepthSeg;

    for( x = 0 ; x < WidthSeg + 1 ; x++ )
        for( y = 0 ; y < DepthSeg + 1 ; y++ )
            Vertex3f( (WidthStep * x) - dx/2, (DepthStep * y) - dy/2, -(dz/2) );

    ntop = GetVertexCount();

    for( x = 0 ; x < WidthSeg + 1 ; x++ )
        for( y = 0 ; y < DepthSeg + 1 ; y++ )
            Vertex3f( (WidthStep * x) - dx/2, (DepthStep * y) - dy/2, dz/2 );

    // Create the bottom as a mesh of triangles
    for( x = 0 ; x < WidthSeg ; x++ )
        for( y = 0 ; y < DepthSeg ; y++ )
        {
            Poly3i(-Direction,
                (nbottom+y)     + ((DepthSeg+1) * x),
                (nbottom+y)     + ((DepthSeg+1) * (x+1)),
                ((nbottom+1)+y) + ((DepthSeg+1) * (x+1)),
                'ground');
            Poly3i(-Direction,
                (nbottom+y)     + ((DepthSeg+1) * x),
                ((nbottom+1)+y) + ((DepthSeg+1) * (x+1)),
                ((nbottom+1)+y) + ((DepthSeg+1) * x),
                'ground');
        }

    //
    // SIDES
    //
    // The bottom poly of each side is basically a triangle fan.
    //
    for( x = 0 ; x < WidthSeg ; x++ )
    {
        Poly4i(-Direction,
            nbottom + DepthSeg + ((DepthSeg+1) * x),
            nbottom + DepthSeg + ((DepthSeg+1) * (x + 1)),
            ntop + DepthSeg + ((DepthSeg+1) * (x + 1)),
            ntop + DepthSeg + ((DepthSeg+1) * x),
            'sky' );
        Poly4i(-Direction,
            nbottom + ((DepthSeg+1) * (x + 1)),
            nbottom + ((DepthSeg+1) * x),
            ntop + ((DepthSeg+1) * x),
            ntop + ((DepthSeg+1) * (x + 1)),
            'sky' );
    }
    for( y = 0 ; y < DepthSeg ; y++ )
    {
        Poly4i(-Direction,
            nbottom + y,
            nbottom + (y + 1),
            ntop + (y + 1),
            ntop + y,
            'sky' );
        Poly4i(-Direction,
            nbottom + ((DepthSeg+1) * WidthSeg) + (y + 1),
            nbottom + ((DepthSeg+1) * WidthSeg) + y,
            ntop + ((DepthSeg+1) * WidthSeg) + y,
            ntop + ((DepthSeg+1) * WidthSeg) + (y + 1),
            'sky' );
    }
}

event bool Build()
{
    if( Height<=0 || Width<=0 || Breadth<=0 || WidthSegments<=0 || DepthSegments<=0 )
        return BadParameters();

    BeginBrush( false, GroupName );
    BuildTerrain( +1, Breadth, Width, Height, WidthSegments, DepthSegments );
    return EndBrush();
}

defaultproperties
{
     Height=256.000000
     Width=256.000000
     Breadth=512.000000
     WidthSegments=4
     DepthSegments=2
     GroupName="Terrain"
     BitmapFilename="BBTerrain"
     ToolTip="BSP Based Terrain"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fr 30.3.2007 08:43:38.000 - Creation time: Mo 16.4.2007 11:20:54.890 - Created with UnCodeX