This is duplicate post of a discussion I started on ESRI’s CityEngine support forum

The next part of this thread is to start a simple road CGA rule file that can take into account the road classification field. This code is based in part on the tutorial examples given by CityEngine but I’ve modified them for the purpose of this discussion (with myself). The principles here can be applied for many rule sets not just road networks.

This CGA rule will create different looking roads depending on the road classification and place a lamp post at regular intervals on designated streets. I’ve also added a rule for a covered market street but this is to be added manually in CityEngine.

Road classes are taken from the Streetnetwork’s “layer attribbutes” with code code like this : attr roadClass = getObjectAttr(“ROADCLASS_FIELDNAME_FROM_GIS”)

 

const lamp_asset = "lamppost.obj" // this is under your assets directory you can get a quick model from places like Google 3D Warehouse just be sure you have permission to use them!
attr sidewalkHeight =0.25
attr lampDistance =25 // you could change this or add different attributes for each road class
attr roadClass = "None" // attribute name declared in layer attribute 

Street--> // I've coloured these in simple primary colours so you can see what's happening
	case roadClass == "Primary" : color ("#ff0000")
	case roadClass == "Secondary" : color ("#00ff00")
	case roadClass == "Tertiary" : color ("#0000ff") // you can add more classes here
	else : color("#535353")

Sidewalk-->
	set(trim.vertical,false) set(trim.horizontal,false)
	comp(f){ all: SidewalkPart }

SidewalkPart -->
	case scope.sx > 5:
		SidewalkWithCurbs
		alignScopeToAxes(y) t(0,sidewalkHeight,0)
		SidewalkLampTest
	else:
		SidewalkWithCurbs

SidewalkWithCurbs -->
	extrude(world.y,sidewalkHeight)
	comp(f)
		{ top   : split(y){ sidewalkHeight : Curbs | ~1 : Pavement }
		| front : Curbs }

SidewalkLampTest--> // in this example only my primary and secondary classes of street get lampposts!
	case roadClass == "Primary" : SidewalkLamps
	case roadClass == "Secondary" : SidewalkLamps
	else : nil 

SidewalkLamps -->
	split(x){ ~lampDistance :  NIL
		| { 0.1: Lamp | ~lampDistance : NIL }* }

Pavement -->
	color("#C0C0C0")

Lamp -->
	t(0,0,scope.sz-sidewalkHeight*2)
	s(0,5,0)
	r(0,90,0)
	i(lamp_asset)

Curbs -->
	color("#C0C0C0")

Crossing-->
	color("#535353")

Junction-->
	color("#535353")

JunctionEntry-->
	color("#535353")

Island-->
	extrude(0.5) color("#008000")

StreetMarketRoof--> // you need to select the shapes start rule manually to enable this but you could do it via road class as well
	   extrude(10) comp(f) {  bottom : marketstreet | top : marketroof  } 

marketroof--> roofGable(22.5)
marketstreet -->  reverseNormals color("#008000") // I seem to need to do this so I can have a coloured street under my marketroof

Has anyone got anything else to add or correct? Can someone provide code for a nice simple bridge?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.