Prototype Procedural City Generator. |
I was looking at ESRI CityEngine the other day. Someone mentioned about it at the Sverchok thread on Blender Artist Forum. CityEngine is quite impressive. I like how simple it looks to work with such a complex thing like city and building generations. It also has its own programming language, set of RULES they called it to generate city. READ: "CGA shape grammar"
ESRI CityEngine is quite impressive. |
There are many tools out there that can procedurally generate city these days, which is quite amazing. I have not had chance to try on any of them. I am sure they are all good and we can study them and try to apply the concept in Sverchok.
In the past I remember using few scripts for Maya does procedural city (buildings) creations. The one I like the most is "QTown for Maya" from Brave Rabbit.
https://vimeo.com/28773741
QTown by Brave Rabbit. Simple and easy to use! |
It is a WIP and Research in progress. It is one of my dream to be able to create inside Blender. I also want to make "Procedural Creature" that is next in plan. Sverchok makes some things easier, especially in procedurally editing mesh.
My principle is always not so much on just giving tool, I always want to understand HOW TO create the tool and hopefully I can share the knowledge.
None of these are new, I just want to explore it in Blender using Sverchok Add-On. Sometimes I like to re-invent the wheel to understand how it is made.
Worth to look is this Suicidator City Generator, probably the most solid Add-On for Blender for building city. I have mentioned it few times in the past:
http://cgchan.com/suicidator/
PROCEDURAL CITY: Random vs Real
So the task is to create a CITY, random/specifically made skycrappers tall buildings by the means of NODING or CODING.- NODING = using nodes and noodles
- CODING = using code and programming
I like NODING because the result can be more interactive, that's because NODING always has interface and parameters. Or at least it feels simpler because we care about INPUT and OUTPUT and we know that the node will hopefully do.
NODING is "visual" and actually can be recreated more easily even if you don't have programming knowledge. However, that is also often the MISLEADING PART.
Many software like Maya and Houdini claimed that PROCEDURAL and NODE BASED is "easy" and can allow advance effects without programming. It is not fully true.
Procedural or parametric is a hidden complexity. It will take some LOGIC and it is not necessarily easy. But it can be learned and explained, just like cooking. You may not get it at first. You will be stucked a lot. You will get error a lot and Blender may crash a lot (in case of Sverchok). However you are ALLOWED to make mistake and experiment and see the result. Find a problem and fix it.
Stick with this stuff and actually give effort to understand it and you will be rewarded.
(enough preaching, let's continue....)
When it comes to "iteration", CODING could be simpler to implement. A once off code that can run multiple time on many objects. CODING can also be faster and efficient, compared to connecting noodle and nodes. Nodes always need to calculate and bake and update the result. This can be slow after sometimes. Which means we are no longer can see realtime update via parameter. In such case, CODING is totally way to go.
Either way, I respect both way. We probably need both means to tackle task like "Procedural City".
If we need to generate city that actually existed in our world, then we can look at something like OpenStreetMap. Add-On like OSM importer below for Blender is useful.
http://blenderartists.org/forum/showthread.php?334508-Addon-Import-OpenStreetMap-(-osm)
My wishlist for that above is to also import the building height for extrusion. Then each building can be detailed according to one's needs. It will be an interesting task to think about.
When it comes to "random" or "generative", we basically need to think about RULES that we need to apply for each task, such as:
1. Road and Street Map, including their intersection
2. How buildings will be laid out within the space created by Road and Street
3. How buildings got stacked and detailed: how tall, roof part, bottom part, windows part, etc.
THE PLAN
I first draw a plan and see how this can be implemented using tools and functions inside Blender. Obviously this is a big task and I have to allocate time and allow improvements.I am not attempting to do everything in one writing. I will do try to solve by breaking parts. I don't have architecture background, I actually need to go and read some architecture books, which I think important to understand elements of buildings.
ELEMENTS Street and Road Map
We will have some kind of AREA of TERRAIN. It is not flat, but to build building we probably need to FLATTEN those area.However, we could explore the idea or PROCEDURAL STREET/ROAD a little bit.
What is the first thing came up in your mind to draw street? Grease Pencil? You bet! That's also the first thing in my mind.
We could draw some street and road from TOP VIEW and PROJECT it down.
There will be some INTERSECTING Lines that we need to deal with. Maybe using Sverchok.
There is some convenient of using Grease Pencil. It can be converted into Polygon and Curve object in Blender and both can be quite convenient or inconvenient, however we look at it.
Grease Pencil => Curve => Street
Remember that converting Grease to Curve is always resulting in very dense curve, and we need to always Simplify Curve first. Clean curve is better.Turn off "Link Stroke" option when converting.
Use "Simplify Curve" add on. --- hopefully when Blender NURBS got improved after Google Summer of Code 2014, we can have CURVE RESAMPLE.
AFTER SIMPLIFY CURVE:
Curve in Blender is SPECIAL. Just like Text Object and Armature Object. It has A LOT hidden feature in it. Curve has many build in "procedurality", such as EXTRUDE and BEVEL.
For what we are doing, we keep it simple, I just show you that we can switch between 2D and 3D. With 3D Curve, we can TILT the curve and that will affect the extrusions.
We just need to PROJECT it down the ground. Would be nice if the TILT was also affected by the angle of how it got projected down into the ground. And it sort of does! We just apply Shrinkwrap modifier to the curve and adjust the parameter.
That is the basic idea. One day we cover how to create RAILWAY or ways to detail streets and roads with lamps and so on.
Grease Pencil => Curve => Polygon Edges
What if we actually use Polygon for this task? With polygon, the advantage is to be able to have Intersecting Points in between lines. That can be taken care using Sverchok "Intersect Edges" node. Not always the fastest but it will do the job.Watch out with dense Mesh. When you are converting Grease to Curve to Poly, make sure that your Curve is Poly and it has decent numbers of Points.
Dense Edge Mesh will calculate too long time and will definitely crash Blender. See below how many points and curve I have, not many.
PYTHON METHOD:
http://blenderscripting.blogspot.com.au/2013/05/developing-script-from-start-to-finish.html
Bake the resulting EDGES that now have Intersecting Points. By doing that you can Skin Modifier it and you can have a nice connecting intersecting lines! This should be useful to create Pipes or Tubes too.
You can further clean up the Edges using REMOVE DOUBLES in Blender or inside Sverchok.
NODE: Intersect Edges
CORRECTION: This quirkiness is intentional, to allow us to do more things, such as exploding the intersection lines. We can use Remove Doubles if we do not want the edge or point doubles.
I advice you try to create a setup like below with 6 x EMPTIES and all the criss-crossing lines and see how Intersecing Lines really work.
You can use Blender REMOVE DOUBLES or Sverchok REMOVE DOUBLES node.
Basically it is possible to have a CLEAN INTERSECTING LINES.
If you use FILL HOLE, it is possible to have nicely filled PLATE.
And you can use Wireframe Deformer (because it needs faces).
All those above are useful techniques to consider when creating Street and Road.
ELEMENT: Buildings around Shape
Next, we have tasked to FILL the area created by those INTERSECTING STREET and ROAD.After some experiments, I think the simplest area to fill is when we have CONVEX Profile. It's area that does not have curve profile that goes in.
Actually Convex or Concave will not matter so much, depends how we like to create the building around the area. I was thinking something like below:
1. We basically draw an INSET from the SHAPE.
2. Then from inset, we already have QUAD FACES, and the rest is easy and straight forward.
There are of course many other ways we could approach. There is this "dividing square randomly" algorithm that I quite like that I have seen before.
Something like below:
Above the CITY ENGINE also does this Square Cutting of any area. It is cutting with lines but with slight offset. I have to research on this next.
Those SQUARE LIKE City arrangement is another example CITY ALGORITHM we could use. City of Adelaide is a bit squarish. New York City is also a good study.
I actually quite like these "SQUARE PACKING" algorithm. |
For now, let's just do it by creating PUBLIC HOUSING type of building blocks. Simple one first.
START WITH A CONVEX SHAPE
I will be using one of the Shape Plate we have created above by cutting lines. Flat plane.Now, let's jump into Sverchok and start creating and dealing with GHOST MESH.
First of all, what we need to do is to create INSET type of MESH. We don't have Sverchok Inset Node (yet), so we need to recreate it ourselves.
Blender has Inset function, but we will not use it. We want this as procedural as possible.
Let's create INSET operation. We are basically pushing or pulling the original Vertices using the Vector of each points. So I will do exactly that.
There is probably limitation of this method, but should be ok for now. Concept wise. If we are using Blender 2D Curve, it has OFFSET option that might be handy.
However, we are dealing with Polygon only in Sverchok. Let's live with that for now.
Now to fill the AREA between original SHAPE and offset SHAPE, we can use Cylinder Topology. Here is the preview:
And this is the actual thing.
We just need to specify the right number of Vertices for the Cylinder generator node to give the right topology. There is only 1 correct value => which is the total number of Vertices that the SHAPE have. Sometimes if you go OVER, Sverchok might crash Blender. Use LIST LENGTH node to ensure we got the correct total points.
Now, we have QUADS to work with. We can create our Building Blocks using the uber useful ADAPTIVE POLYGONS node.
ADAPTIVE POLYGONS node is a type of COMPOUND node. We could actually build it ourselves and may have a bit more control. However for now, this is fine.
Prepare DONOR object, we just use CUBE for now. Sverchok BOX node can do this. But you also need to "place the box on the floor".
What we get now:
You may notice that I made changes on the LIST JOIN node. The correct setting is as below:
Below is the cleaned up version. I also placed the BOX ON THE GROUND.
We have our PUBLIC HOUSING building blocks. However, they are a little bit too boring, we can probably randomize the height a bit.
This is how far I actually have gone with this Procedural City.
We could definitely use the VECTORIZED INPUT, so that we can bring in MULTIPLE AREA PLATES to generate building.
Our building is just an ugly simple block at the moment. Detailing and modifying building, probably best done using CODING. Script Node of some sort, that way we can give variations according to our need.
There are often interesting issues you need to deal with:
- Vertice Sorting (yes, some of those vertices might be out of order!)
- Flipping Face Normal (building grow into the ground).
All normal and part of procedurality! No Rules cannot be broken by Numbers!
It's a prototype.
Soon enough, I realized that we need to deal with:
- UV and Procedural Textures (OSL maybe?)
- DETAILS: Trees, Street
I guess I need to do some research, probably next gen Games is a good start. Spiderman game and all sort of games that have procedural city.
Above is not the only solution, but just pieces of ideas that you may or may not use. Basically I think with CITY, we need some kind of ways to generate the TOPOLOGY Map first. Kind of way to automate and separate AREAS and still have control. What I did above is very basic, it is just random extrusion from original maps. However, I think it can be further developed and refined.
Next thing I should study is actually the QTown script for Maya. It can be ported to Blender, actually.
Remember the Spiderman "I LOVE YOU" writing on The Amazing Spiderman 2, which can easily be created using Voronoi. We can use it to draw random Map.
OK, now I realized that in order to populate MANY AREA PLATES such above, I really need to tweak my setup above so that it works for Multiple Objects (remember the VECTORIZED INPUTS).
Either, we need to "separate every mesh" part or allows for multiple mesh. I think it needs to work with both scenarios.
Once that's taken care off, it's just a matter of bringing in ANY MESH and it will populate it with simple buildings. Simple building for now, the reason being = remember Sverchok is dealing with Mesh, not actually Instances, unlike Particles, every Mesh is REAL.
http://www.cg.tuwien.ac.at/research/publications/2010/dusberger-2010-msm/dusberger-2010-msm-report.pdf
http://www.ia.arch.ethz.ch/wp-content/uploads/2011/09/HS11_CityEngine_overview.pdf
http://homes.esat.kuleuven.be/~mmathias/publications/3dimpvt2011.pdf
Above is not the only solution, but just pieces of ideas that you may or may not use. Basically I think with CITY, we need some kind of ways to generate the TOPOLOGY Map first. Kind of way to automate and separate AREAS and still have control. What I did above is very basic, it is just random extrusion from original maps. However, I think it can be further developed and refined.
Next thing I should study is actually the QTown script for Maya. It can be ported to Blender, actually.
FURTHER ON: Voronoi
Voronoi 2D can be used to create random yet natural mapping.Remember the Spiderman "I LOVE YOU" writing on The Amazing Spiderman 2, which can easily be created using Voronoi. We can use it to draw random Map.
OK, now I realized that in order to populate MANY AREA PLATES such above, I really need to tweak my setup above so that it works for Multiple Objects (remember the VECTORIZED INPUTS).
Either, we need to "separate every mesh" part or allows for multiple mesh. I think it needs to work with both scenarios.
Once that's taken care off, it's just a matter of bringing in ANY MESH and it will populate it with simple buildings. Simple building for now, the reason being = remember Sverchok is dealing with Mesh, not actually Instances, unlike Particles, every Mesh is REAL.
SCATTER RANDOM SHAPES x INTERSECTION
LINKS AND READINGS
http://cs.brown.edu/research/pubs/theses/ugrad/2013/zweig.pdfhttp://www.cg.tuwien.ac.at/research/publications/2010/dusberger-2010-msm/dusberger-2010-msm-report.pdf
http://www.ia.arch.ethz.ch/wp-content/uploads/2011/09/HS11_CityEngine_overview.pdf
http://homes.esat.kuleuven.be/~mmathias/publications/3dimpvt2011.pdf
Post a Comment