# Modifying Fence Code

Question asked by stonesfcr on Apr 10, 2016

Some time ago I found on another thread a fence code, I studied it and now I tried to made it into a fence that includes doors (entrances), but I can't make it work when there's sloped terrain:

attr poleHeight = 2

attr barHeight1 = 0.15

attr barHeight2 = 1.7

attr barHeightDoor1 = 0.25

attr barHeightDoor2 = 1.6

attr barDimension = 0.08

attr poleWidth = 0.08

attr poleDist = 3

attr poleThickness = 0.08

attr boardWidth = 0.03

attr boardDist = .08

attr boardHeight = 1.9

attr boardThickness = 0.03

Lot -->

extrude(world.y, poleHeight)

comp(f){side: FrontFence}

FrontFence -->

split(x){~.5:Reja("fence") | 2.5: Reja("door") | ~.5:Reja("fence") | .75: Reja("door") | ~.5:Reja("fence")}

##########################################################################

# Fence

##########################################################################

Reja(Tipo) -->

case Tipo =="fence" :

MakeBar1("fence")

MakeBar2("fence")

PutPoles

else:

MakeBar1("door")

MakeBar2("door")

PutPoles

##########################################################################

# Fence

##########################################################################

MakeBar1(Tipo) -->

case Tipo == "fence" :

split(y) {barHeight1 : NIL | barDimension : extrude(barDimension / 5) t(0,'-1.2,0) Bar | ~1 : NIL}

else:

split(y) {barHeightDoor1 : NIL | barDimension : extrude(barDimension / 2) t(0,'-1.2,0) Bar | ~1 : NIL}

MakeBar2(Tipo) -->

case Tipo == "fence" :

split(y) {barHeight2 : NIL | barDimension : extrude(barDimension / 5) t(0,'-1.2,0) Bar | ~1 : NIL}

else:

split(y) {barHeightDoor2 : NIL | barDimension : extrude(barDimension / 2) t(0,'-1.2,0) Bar | ~1 : NIL}

Bar -->

color(.1,.1,.15)

alignScopeToAxes(y)

comp(f) {front : BarBevel | back : BarBevel | all : Bar.}

BarBevel -->

roofGable(45)

split(y) {'.1 :comp(f) {bottom : NIL | all : Bar.} | ~1 : NIL}

##########################################################################

# Poles

##########################################################################

PutPoles -->

alignScopeToAxes(y)

split(x) {{ poleWidth: MakePole | ~poleDist : PutBoards}* | poleWidth: MakePole }

MakePole -->

color("#706050")

alignScopeToAxes(y)

innerRect

s('1,'1,poleThickness)

i("assets/fencePole.obj")

t(0,0,'-1)

Pole.

##########################################################################

# Boards

##########################################################################

PutBoards -->

alignScopeToAxes(y)

split(x) {{ ~boardDist : NIL | boardWidth: MakeBoard}* | boardDist : NIL }

MakeBoard -->

alignScopeToGeometry(zUp, 0, world.lowest)

s('1,boardHeight,'1)

Board

Board -->

color("#706050")

alignScopeToAxes(y)

innerRect

s('1,'1,boardThickness)

i("assets/fenceBoard.obj")

Board.

When I raise a point on the polygon it starts to distort, how can I fix it?

Thanks