How do you convert a linear data (shapefile) into a tunnel in CityEngine?

1402
4
08-17-2016 06:13 PM
AKINOLAEKUNDAYO
New Contributor II

Can someone help me with the cga code to convert a line into a tunnel in CityEngine?

0 Kudos
4 Replies
LR
by
Occasional Contributor III

Here's a simple one I made. You could use some recursion to make smooth arcs, but I try to keep the poly count low. Only works on straight lines, unfortunately. Change the nodes to crossings.

version "2016.0"

attr shapeType =""
attr streetWidth = 0
attr sidewalkWidthLeft = 0
attr sidewalkWidthRight = 0

import EsriStreets: "/ESRI.lib/rules/Streets/Street_Modern_Standard.cga"

@StartRule 
 Lot --> 
 case shapeType == "Street": MakeTunnel EsriStreets.Street
 case shapeType == "Sidewalk": EsriStreets.Sidewalk
 else:NIL

MakeTunnel --> 
 extrude(streetWidth/1.2)
 alignScopeToGeometry(zUp, any, world.lowest)
 s('1,streetWidth+sidewalkWidthLeft+sidewalkWidthRight+2,'1)
 t(0,-1*(sidewalkWidthLeft/2+sidewalkWidthRight/2+1),0)
 color(1,0,0)
 rotateScope(45,0,0)
 split(y){1: NIL | ~1: OuterSplit1 }

OuterSplit1 -->
 rotateScope(90,0,0)
 split(y){1: NIL | ~1: InnerSplit1}

InnerSplit1 -->
 color(0,1,0)
 rotateScope(-45,0,0)
 split(y){1: Wall | ~1: InnerSplit2}

InnerSplit2 -->
 color(0,1,0)
 rotateScope(90,0,0)
 split(y){1: Wall | ~1: InnerSplit3 | 1: Wall}
 
InnerSplit3 -->
 rotateScope(225,0,0)
 split(y){1: Wall | ~1: InnerSplit4 } 
 
InnerSplit4 -->
 rotateScope(90,0,0)
 split(y){1: Wall | ~1: NIL } 
 
Wall -->
 color("#BBBBBB")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

AKINOLAEKUNDAYO
New Contributor II

LR, much appreciated. Apologies! Did not make myself clear enough. I was looking for a railway tunnel - cylindrical in nature.

0 Kudos
LR
by
Occasional Contributor III

Here's a basic approach for a hollow cylinder - I insert a disc, move/extrude it and then delete the center. Again, straight lines only.

version "2016.0"
attr shapeType =""
attr TunnelLength = 0
@StartRule 
 Lot --> 
 case shapeType == "Street": MakeTunnel
 else:NIL
 
MakeTunnel -->
 set(TunnelLength, scope.sx)
 alignScopeToGeometry(zUp, any, world.lowest)
 primitiveDisk(20, 5)
 center(xyz)
 r(0,90,0)
 t(-scope.sx/2,0,-TunnelLength/2)
 extrude(TunnelLength)
 setback(1){all: TunnelColor | remainder: NIL}

TunnelColor --> 
 color(1,1,0)
0 Kudos
AKINOLAEKUNDAYO
New Contributor II

Thanks Ivan,

Where have you been?

0 Kudos