Browsed by
Month: March 2012

To Unity and Beyond? QGIS, ArcGIS, SketchUp Pro/Free, CityEngine and Unity

To Unity and Beyond? QGIS, ArcGIS, SketchUp Pro/Free, CityEngine and Unity

I’m always looking for new ways to combine data and visualisation techniques.  Partly I’m inspired by the likes of the DigitalUrban blog but mostly I’ve always liked mucking about with 3D software and real world data (3D Construction kit for the C64 anyone?).

So here is what you need for what I’m about to do, there’s a lot of different ways of achieving the same thing and at different costs.  Inevitably if you have lots of money the steps are more streamlined.

Okay this will be a very quick run down as I’m not going to go into the details.  I suggest you familiarise yourself with each piece of software paying attention to the import export functionalities of each.

This guide, as the blog is in general, primarily a notebook of workflows for myself so I don’t have to remember them all!

Recommended reading? Digital Urban and this “Google SketchUp for Game Design: Beginner’s Guide”

  1. Create City Streets or download from OpenStreetMap
  2. Edit data in ArcGIS or QGIS (and save as shapefile) or even use SketchUp pro and export as dxf
  3. Import data (edited in ArcGIS/QGIS or otherwise…) into CityEngine shapefiles/DXF/GDB/OSM/DAE/OBJ *or you can import OSM data directly*
  4. Generate your city using various ‘assets’, for example, city streets and plots from a GIS or straight from Open Street Map data.   Using rules you can create your own building models as well.
  5. Once complete export your city model to a FBX format, in CityEngine FBX export dialog box I change the Misc Options Global Offset and click the ‘Center‘ button
  6. You can also create more more models (signs, trees etc) that can be placed in Unity separately.   In SketchUp Pro its just a case of exporting as an FBX file, but if you have SketchUp Free use the OBJ exporter  and AutoDesks free FBX converter.
  7. Either you have exported the city model to the correct Asset folder for your Unity project or you can click on the Assets menu in Unity and select Import New Asset
     
  8. In Unity select your newly imported model and using the Inspector window change the scale factor to 1 select Generate Colliders and Import Materials choosing the right Material Naming and Material Search options. The click apply and wait while your model is prepared.
  9. Once complete drag your model from the Project window into the Scene window and position. Now drag from the Standard Assets–>Character Controllers folder drag and drop the ‘First Person Controller’ onto your model.
  10. Add a light by selecting the menu GameObject–>Create Other –> Directional Light and then position it in over your model in the Scene window. If you can’t find it double click on the Directional Light heading in the Hierarchy window.
  11. Add a SkyBox (yes with nice fluffy clouds) by selecting the Edit–>Render Settings menu heading and clickin the little circle to the right of the SkyBox Material heading in the Inspector. In the Select Material dialog box type ‘sky’ and a list of the skyboxes will appear. Select one of these.
  12. To create a standalone playable demo of your model first make sure it all works click the play button, if you fall off your model press the play button again to stop and make sure the First Person Controller is placed above your model and that you selected the create colliders on your imported model in the Inspector window.
  13. Select File Build Settings, click “Add Current” to build the scene you are working on. Now click on Web Player (or PC and Mac Standalone) and click Build and Run
  14. Navigate to the folder where the HTML file has been created an double click on it, if you have installed the Unity Web Player your model walkthrough should load up just as if you had pressed play within Unity itself..
Landuses – Area Test

Landuses – Area Test

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

I’ve already outlined a way to allocate landuses based on a static shape layer, as we get nearer placing buildings on our plots we need to ensure that the “lots” are the correct size and shape.

This following rule can be adapted to test a Lot’s area (in sqm) and then onto the next rule depending on its area. I’ve used this to place different building types on a lot depending on it’s area but you could just as easily tie this into the woodland rule set above…

//the descriptive names can be changed and are more of a guide really change or add more areas for your needs
attr areatest =
	case geometry.area < 100 : "100orLess"
	case geometry.area < 200 && geometry.area > 100 : "100to200"
	case geometry.area < 300 && geometry.area > 200 : "200to300"
	case geometry.area < 400 && geometry.area > 300 : "300to400"
	case geometry.area < 500 && geometry.area > 400 : "400to500"
	case geometry.area < 600 && geometry.area > 500 : "500to600"
	case geometry.area < 700 && geometry.area > 600 : "600to700"
	case geometry.area < 800 && geometry.area > 700 : "700to800"
	case geometry.area < 900 && geometry.area > 800 : "800to900"
	case geometry.area < 1000 && geometry.area > 900 : "900to1000"
	case geometry.area > 1000 : "1000orMore"
	else : "0"

Lot-->
   res_areatest

//this directs the rule to the appropriate model depending on the area size
res_areatest-->
	case areatest == "100orless" : res_100orless
	case areatest == "100to200" : res_100to200
	case areatest == "200to300" : res_200to300
	case areatest == "400to500" : res_400to500
	case areatest == "500to600" : res_500to600
	case areatest == "600to700" : res_600to700
	case areatest == "700to800" : res_700to800
	case areatest == "800to900" : res_800to900
	case areatest == "900to1000" : res_900to1000
	case areatest == "1000orMore" : res_1000orMore
	else : stop.	

res_100orless-->
	extrude(5) report("1000", geometry.area())
//etc....

As usual does anyone have any thoughts/suggestions/corrections?

Landuses – Create a woodland – Random Tree Scatter

Landuses – Create a woodland – Random Tree Scatter

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

I know roads don't really look like that...

A quick CGA rule share here! This one allows you to place randomly a selection of tree models on a lot (with start rule “woodland”). In my city model I wanted to place some trees in open areas by a river so this was a quick solution. This places a number of random trees (100) of different sizes and ranges, I’ve also allowed for a setback so when the lot fronts a road the trees are not right up against it.

Obviously you can change the names of the rules to what you use and you could combine this with the landuses code I posted first in this discussion thread.

If you need a tree you could use SketchUp and if you have the free version you might want this OBJ exporter plugin

tree_asset = fileRandom("trees/tree*.obj") // you could just have *.obj and it would randomly pick any obj file in this directory, you can use sketchup to create an obj
attr treenumber = 100 //change this depending on your lot size, or maybe run an area test on the lot to determine the density of your woodland!
attr treeminheight = 5 // know your tree to get that realistic height, perhaps wiki it?
attr treemaxheight = 15
attr woodlandsetback = 5

woodland-->
	setback(woodlandsetback) { streetSide : woodlandborder | remainder : trees} 

trees-->
	scatter(surface, treenumber, uniform) { palmtree }
	woodlandground

singletree-->
	t(0,0,0) // you can change these numbers as well if you didn't want to place the tree at the scatter point centre
	s(0,rand(treeminheight ,treemaxheight ),0)
	r(0,rand(0,360),0) // rotates tree at a random rotation
	i(tree_asset)	

woodlandborder-->
	 extrude(1) woodlandbordercolor

woodlandground-->color("#005B00")

woodlandbordercolor-->color("#AAAA55")

As usual if anyone has any suggestions/thoughts/modifications please reply!

Creating a City from GIS data – Landuses – Part 1

Creating a City from GIS data – Landuses – Part 1

mmm LBCS Codes

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

Since my first post has produced such an amazing response  I shall continue and start a thread on using GIS data on landuses.

What I have been doing is using my road network in ArcGIS and importing it into CityEngine where I make a suitable road network, this I use to create blocks that are not sub-divided.   I then export these block shapes as a shapefile back into ArcGIS where I add new fields (like an LBCS or landuse Code).   I can then make an outline landuse plan from these in ArcGIS and symbolise them.

So we start back again in CityEngine with some static shapes with an object attribute for the landuse (in my case I’ve called it LBCSCode).

The layer attributes code would look like this :

attr landuse = getObjectAttr("LBCS_Code")

Then to colour the static shapes I could use the following code (don’t forget to apply the rule file!):

attr landuse = "0" // this just initialises the attribute that we have in our layer attributes
Lot-->  //I didn't use LotInner as this example doesn't create a subdivision
case landuse == "1000" : color("#FFFF00") report("1000", geometry.area())
case landuse == "2000" : color("#FF0000") report("2000", geometry.area())
case landuse == "3000" : color("#A020F0") report("3000", geometry.area())
case landuse == "4000" : color("#0000FF") report("4000", geometry.area())
case landuse == "5000" : color("#BEBEBE") report("5000", geometry.area())
case landuse == "6000" : color("#2F4F4F") report("6000", geometry.area())
case landuse == "7000" : color("#90EE90") report("7000", geometry.area())
case landuse == "8000" : color("#228B22") report("8000", geometry.area())
case landuse == "9000" : color("#FFFFFF") report("9000", geometry.area())
else : color("#000000")

You can also see that I’ve used the report operation to produce a summary of the land areas (helpful when doing landuse plans!)

Lovely reporting!

So would anyone do this differently?  Thoughts/suggestions/corrections?

The next post will cover using this static shape layer to inform a dynamic model so change landuses in the object attributes here will change what happens in the dynamic model.

Creating a City from GIS data – Transport Infrastructure – Part 2

Creating a City from GIS data – Transport Infrastructure – Part 2

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?

Creating a City from GIS data – Transport Infrastructure – Part 1

Creating a City from GIS data – Transport Infrastructure – Part 1

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

I thought I’d start a thread for people wishing to make simple City Models based in part, on real world data in ArcGIS. Hopefully it will help in the creation of quite a complex city model that people can modify for their own purposes. It’s intended to be a simple discussion that anyone can join in with so feel free to add to it! This will assume a basic working knowledge of CityEngine, for example import/export of data as well as tools like ‘CleanUp’ graph.

NB : I am not a programmer and my knowledge is limited in many areas of CityEngine so if you spot mistakes or can suggest betters ways of doing something, please tell me!

As you can link CGA rules together and add to the complexity I thought it would be helpful to break the various components down. Firstly I’m a planner mainly working on Master Planning projects so this is from my perspective, I would welcome other people’s perspectives though!

The city model I want to create already has a few distinct data sets, they can be simply characterised as:

  • Existing data, shapefiles/GDBs (polylines, and polygons) of the existing city which are quite detailed
  • New data, GDBS (again polylines, and polygons) of the proposals/planned expansion which as a master plan are more general (No internal local streets yet) which I have created

Now to break it down further, I want to control and model in CityEngine the general headings below:

  1. Transport Infrastructure (mainly roads, but some rail and other types, such as covered market street)
  2. LandUse (I put it at the top because,it’s what I do)
  3. Plotsizes (Blocks on or off, Lot sizes, lot minimum width etc..)
  4. Models, initially simple block models that we can add detail to based on Landuse, plotsizes etc..

So I’m proposing that we aim to create a set of CGA rules that are easy to understand and create a basic city model from which we can add more complexity to. I really want to build code that can be flexible, often there are a couple of ways to do rules in CityEngine but I propose we don’t always do the simple route, that way people can build in complexity. I’m also assuming that we start with all the base data we need.

I suggest we start with a discussion of Transport Infrastructure since these allow blocks to be created. I’ve looked at the rule files in the tutorials in particular the Modern streets CGA. However as we’re building on existing data I think we need to start with what fields in the polyline data from the GIS we might want to use:

  1. Right of Way (ROW) width
  2. Number of Lanes
  3. Direction (one way, two way and actual direction)
  4. Pavement (sidewalk in the USA!) Left
  5. Pavement (sidewalk in the USA!) Right
  6. Surface (asphalt, unmade etc..)
  7. Class (Motorway/Highway/Main/Secondary/Distributor/Access/Track)
  8. Central reservation
  9. Bridge?

Any other fields we might want to use in CityEngine, any suggestions?

So the best way of controlling how CityEngine draws the correct width of your streetnetwork is via the “layer attributes” window once you’ve selected the imported Streetnetwork data in the Scene window. CityEngine helpfully already does some of this automatically but it doesn’t hurt to repeat it!

I’ve modified the code to show you can change the road width based on a text field not just a number :

 

streetscale = 1  // street width scale factorstreetWidthDefault = 5
width            = getObjectAttr("rdClass")// Instead of reading a number this reads the type of road eg motorway or local street I use prefix rd to indicate where it is located
attr streetWidth = // street width dependeding on "width" attributes
    case width == "Primary" : 55 * streetscale
    case width == "Secondary" : 30 * streetscale
    case width == "Tertiary" : 20 * streetscale
    case width == "Footpath" : 2.5 * streetscale
    case width == "" :0 *streetscale // if there is no class attribute then the width is zero
    else           : streetWidthDefault

So can anyone add anything more to this, thoughts about the process or additional ways to set road widths?

Next post will be creating a CGA rule file that models a road based on the object attributes such as surface and class…