CGen - Object Oriented City Generator

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
theevilgeek
Gnoblar
Posts: 9
Joined: Fri May 04, 2007 5:05 am

CGen - Object Oriented City Generator

Post by theevilgeek » Fri May 04, 2007 5:31 am

Hey all!

I'm afraid I'm a bit of a n00b when it comes to Ogre; a group of students and myself recently set out to produce a video game using the Wiimote and Nunchuk for input, and Ogre as our graphics engine. This represented my first opportunity to give Ogre a whirl-- and to learn from the immensely helpful community that has formed around it.

As part of this project, I have written a 5000+ line procedural city generation library that I'm interested in "giving back" to the community; I'd really love to see it turn into something much bigger than a one-time use sort of thing.

To this end, I have attempted to use sound design principles in its implementation, though I'm sure there are a few glitches here and there (passing by reference, constant reference, value, pointer, and so forth became a wee bit inconsistent here and there, though I think I've put forth a "good effort" in this regard). I'm sure there were some good design patterns I might have employed here and there so as to look as clever as possible but I'm sure I happened to overlook more than a few :).

At any rate, this library ("CGen") utilizes the abstract factory pattern to allow various generator configurations to be [statically] plugged in so as to fully customize the city generation process. The entire system is accessed using a facad interface class not altogether unlike Ogre root; one need only invoke "generate()" after providing a sequence, a factory, and a map of configuration values to an instance of CRoot, and a city structure is (eventually) returned; provided the same sequence, the same city will be generated.

The following pipeline is executed, modifying a shared data structure representing the as-yet-unfinished city, to yield the final CCity instance: center gen -> population gen -> road gen -> lot gen -> terrain gen -> building gen -> city gen. Each generator is associated with a fixed interface, and one or more sample generators have been implemented at each level.

The city consists of a map of Vector2s to entity lists, where an entity is anything that inherits from CEntity; each entity can then be drawn, though the entity interface hasn't been unified very tightly just yet (entities that have been implemented are roads, buildings, parks, and decorations [mailboxes, lights, etc.]). Entities in a single cell appear in a coordinate frame relative to the particular cell (Vector2) from which they're mapped. It's up to the client to draw everything however the client sees fit; it wasn't really clear to me as to how one might produce a more typical scene graph structure without losing the separation between city data and how that data is illustrated graphically.

At any rate, I'd love to share my library with any developers that might find it fun to play with. Further, I think a commercial-grade procedural city generation framework would be a really fun project to launch and contribute to-- I'd really like to see this project grow into something truly (dare I sound this geeky?) beautiful. However, before I dedicate the time it'll take to make the code clean enough for a public "release," (so as to not be humiliated and mocked by my peers :P) I wanted to find out if anyone in the Ogre community would be interested in helping out on this project as either a contributor or a regular team member.

Needless to say, the library would be released under the GPL with absolutely no proprietary nonsense appended; I have no motive here aside from releasing a piece of code I'm quite proud of and that I'd like to see evolve into something greater than I alone could make.

Thanks for your opinions! :)

- Brandon
0 x

User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender » Fri May 04, 2007 6:17 am

Did explicity consider and reject the LGPL? If you wish to gain support you will get more if people are allowed to use you library in their commercial game while supporting it.
0 x

theevilgeek
Gnoblar
Posts: 9
Joined: Fri May 04, 2007 5:05 am

Post by theevilgeek » Fri May 04, 2007 7:15 am

Absolutely; LGPL would be fine. These details don't really matter to me-- my main goal is to provide credit to those who contribute to it and little more.

- Brandon
0 x

Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

I would be interested ...

Post by Shadow007 » Fri May 04, 2007 7:34 am

I would Really be interested, but don't have ANY time to give :(

Good luck for your project !
0 x

User avatar
ScurvyKnave
Gremlin
Posts: 150
Joined: Mon Oct 10, 2005 5:57 pm
Contact:

Post by ScurvyKnave » Fri May 04, 2007 8:09 am

Sounds very interesting. Would be nice to see a screenshot of something you've generated.

Your use of the term 'entity' may be confusing in the Ogre context, since Ogre uses the term to refer to an instance of a mesh-based object.
0 x

User avatar
steven
Gnoll
Posts: 657
Joined: Mon Feb 28, 2005 1:53 pm
Location: Australia - Canberra (ex - Switzerland - Geneva)
Contact:

Post by steven » Fri May 04, 2007 9:03 am

Can you provide some screenshots of generated cities?

IMO you could create a sourceforge project with such a library.
Or if it is too integrated to Ogre make it an ogre add-on (see the Addons Forum).
0 x

theevilgeek
Gnoblar
Posts: 9
Joined: Fri May 04, 2007 5:05 am

Post by theevilgeek » Fri May 04, 2007 10:14 am

I'm not in the lab right now, and I don't expect X forwarding to play very nicely at the moment, so I can't get the screen captures just yet. I'll submit some images taken from my OpenGL test code, a few (very basic) generated buildings, and some preliminary images from within Ogre tomorrow morning.

Of course, the generators I've implemented have been built within the constraints of a semester-- they don't necessarily represent the upper limit of what is possible to write using the facilities provided by the library, though I think they look okay for now :).

The most useful aspect of the library is that it can (hopefully) be extended from this point onward very, very quickly to implement procedural environment (city / rural / etc ) generation for real-time applications in need of pretty, 'instant' content. For instance, the road generator I've implemented does not use L-systems; in fact, roads are currently constrained to a grid. With the work that's already been done, it would prove fairly straightforward (or will, after minor tweaking!) to add a new road generator that uses L-systems to produce more realistic road networks that can wander around, off the city grid. The cgen library is very much a framework, in this respect.

With regard to coupling between the library and Ogre-- there really isn't any. The library exists as an entirely seperate code base that doesn't depend on Ogre at all. However, it -is- being used within Ogre, and with some more work, I'd expect that the two can yield some very attractive results. An add-on at this point, or at the very least-- a wrapper-- would be a very viable option to allow Ogre programmers to add complex, dynamic content to their applications very quickly.

Lastly, in response to steven, yup-- I'd ultimately expect this library to live in the form of a sourceforge project. Before jumping into this process, I had wanted to find out if you guys would actually be interested in this library; it'd take a little bit of work in order to get the library to a state that I'd feel comfortable putting it out in the open to fend for itself :)-- I wanted to make sure the commitment on my part was worth it. Essentially, I was worried that without a community, it'd become yet another untouched pile of beta code on sf.net.

(phew! hope that answers everything)

Thanks for all your feedback!

- Brandon
0 x

User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 1
Contact:

Post by Kencho » Fri May 04, 2007 12:27 pm

Looks interesting and useful. Looking forward for those screenies!
0 x
Image

User avatar
Aladrin
Orc
Posts: 465
Joined: Fri Mar 10, 2006 10:22 pm

Post by Aladrin » Fri May 04, 2007 12:50 pm

YES! :D

This is definitely something I'd be interested in. I love procedurally generated content. I was just wishing the other day that there was something for cities. I'm definitely looking forward to the release of this library.
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Fri May 04, 2007 5:44 pm

Sounds really interesting. Would be worth getting set up on Sourceforge or Google Code so it can be examined more widely :)

And yeah, you'll need to pick a more integration-friendly license really, LGPL would be good, or more lenient like BSD if you're not expecting to extend it much further or run it as a long-term thing.
0 x

User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
Contact:

Post by Praetor » Fri May 04, 2007 6:28 pm

I find the MIT license gets the job done. As far as I understand it, no string attached at all, except source code must always keep the original license text in it, and modifications and additions need to be marked as such. Accomplishes the "giving credit where credit is due" task, without much more.
0 x

Captain Nemo
Greenskin
Posts: 134
Joined: Sun May 02, 2004 5:06 pm
Location: Kassel, Germany
Contact:

Post by Captain Nemo » Fri May 04, 2007 6:39 pm

I am interested as well! Looking forward to it.
0 x
http://www.aridocean.com
The Marine Life Simulation

Kerion
Goblin
Posts: 235
Joined: Wed Feb 05, 2003 5:49 am
Contact:

Post by Kerion » Fri May 04, 2007 6:44 pm

I am a huge fan of the BSD license personally, but any of the three; BSD, MIT or LGPL, will work for what you want.
0 x

theevilgeek
Gnoblar
Posts: 9
Joined: Fri May 04, 2007 5:05 am

Post by theevilgeek » Fri May 04, 2007 11:54 pm

Okay-- sorry for the delay. Here are a few screen captures of the OpenGL city visualizer that I wrote for debugging purposes. I have been unable to get access to the machine with our Ogre project on it to take some captures of that city, though I expect to do so either later today or tomorrow.

A few things-- for some reason, ksnapshot seems to have skewed the images slightly; the pictures are a bit more curvy than they ought to be :). Furthermore, note that the texturing on the buildings is totally wrong- this is because the visualizer utilized rather hacked-up texturing code, not the final texturing mechanism provided by the library :p. The city lots and parks are not drawn properly by the visualizer, either; the city it displays is mostly just for seeing how population density affects the building shape, height, and distribution.

procedural buildings:
Image
Image
Image
Image

city centers:
Image

city extrema:
Image

lots:
Image

population density:
Image

road network:
Image

procedural cities:
Image
Image

first person city:
Image


I'm currently applying for a Sourceforge project so that I can get the code up ASAP. As for the project license, I'm not certain which option (LGPL, MIT, or BSD) would be best for everyone, and want to carefully review each before making a final choice.

Thanks!

- Brandon
0 x

jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Post by jjp » Sat May 05, 2007 12:30 am

Great! This might very likely be useful for our next project :)
0 x
Enough is never enough.

theevilgeek
Gnoblar
Posts: 9
Joined: Fri May 04, 2007 5:05 am

Post by theevilgeek » Sun May 06, 2007 10:52 pm

Just wanted to ping the thread; haven't heard too many responses yet and wanted to make sure there is interest :)
0 x

grizzley90
Gnome
Posts: 318
Joined: Wed Jan 18, 2006 7:22 pm
Location: Montreal, Canada

Post by grizzley90 » Sun May 06, 2007 11:17 pm

Your SF project will very likely experience a massive attack. :P Can't Wait!
0 x

User avatar
joshcryer
Gnome
Posts: 351
Joined: Wed Oct 13, 2004 8:22 am

Post by joshcryer » Mon May 07, 2007 7:45 am

You stole my idea! Not really. :) But I did have a long discussion on #ogre3d about this particular type of thing a few years ago. Your project is looking VERY promising to do what I need to be done. I cannot believe it, to be honest. :)

Now if only you could make the buildings have floors, and rooms, and stuff.
0 x

Mikko
Gnoblar
Posts: 2
Joined: Fri Apr 27, 2007 10:05 am
Location: Helsinki, Finland

Post by Mikko » Mon May 07, 2007 8:14 am

Hi,

while attending some course on computer graphics at my university I came across this paper.

Do you happen to be based on that? Just wanted you know that there's research about the subject and it could be useful for you.
0 x

Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
Contact:

Post by Vectrex » Mon May 07, 2007 8:28 am

Great news, looks very cool.

These might give you some extra inspiration :)
http://forums.introversion.co.uk/introv ... .php?t=586
http://forums.introversion.co.uk/introv ... subversion
0 x

theevilgeek
Gnoblar
Posts: 9
Joined: Fri May 04, 2007 5:05 am

Post by theevilgeek » Mon May 07, 2007 10:46 am

Thanks for all the kind words!

With regard to introversion's citygen stuff: :shock:. I actually stumbled upon that a little before posting here. And it serves as an excellent example as to what exactly should be more or less a trivial task with something like cgen. The "beta" city shown above uses a simple grid and a psuedorandom sequence to come up with somewhat interesting streets. But to get something REALLY nice-- that actually resembles a city in the real world-- something like an L-system grammar is needed, which appears to be what Introversion has done here.

Also, quite frequently, many projects using L-systems for road generation will seed the system using an actual road map of a real city. While I decided that a more pure approach would be best for our game, a real-map based generator is another viable idea for a cgen plugin-- it's quite easy to imagine how such a plugin would be useful for a multitude of different projects. And I'd love to explore this myself, if and when I get some time to work on a new road generator :).

The buildings seen above come from a somewhat simpler paper:

http://aim.adc.rmit.edu.au/phd/sgreuter ... te2003.pdf

This approach is MUCH simpler than Mueller's model; additionally, the paper is actually somewhat useful in figuring out how to actually implement the darn thing :P. We decided to favor the easier approach as we didn't expect to have enough time to get anything half as good as the Mueller paper implemented. However, something as attractive as Mueller's buildings would be much more straightforward to implement now that I've got a framework to work within.

As soon as I finish patching code (and my endless finals are... finally... completed), I'll post the source to cgen. I'm not sure if I should post it now, bugs and all, or wait until I can add the missing pieces in-- but I'll definately get it up there as soon as humanly possible. Any opinions? Oh-- and I'm still waiting on sourceforge approval.

Also-- before this thread vanishes into the abyss-- I just wanted to take a moment to compliment Sinbad (and the rest of the Ogre team!) on the fantastic amount of care and detail that went into Ogre's incredible design. In building cgen, I had hoped to use some of the same ideas and patterns that fit so naturally into Ogre's implementation. And my goodness, is it hard to design a library!

Thanks for all your feedback!
- Brandon
0 x

User avatar
Aladrin
Orc
Posts: 465
Joined: Fri Mar 10, 2006 10:22 pm

Post by Aladrin » Mon May 07, 2007 12:20 pm

Oh wow. Another neat game from Introversion. I'm all tingly.

The first 2 were awesome, the third... Just not my style. Just about anything with procedurally generated cities is probably my style, though. Heh. Thanks for the links!
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Thu Jul 19, 2007 9:33 pm

Er .. Any updates? :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
joshcryer
Gnome
Posts: 351
Joined: Wed Oct 13, 2004 8:22 am

Post by joshcryer » Sun Nov 25, 2007 10:15 pm

jacmoe wrote:Er .. Any updates? :)
Yeah? :)
0 x

Kirkof
Gnoblar
Posts: 8
Joined: Sun Nov 18, 2007 11:26 pm

Post by Kirkof » Mon Nov 26, 2007 7:48 pm

In fact, it is my idea. But anyway, those kind of ideas are common, as long as you know the term 'city' and too lazy to do modelling.

In fact I've got plans like you. Buildings are easy to do, but puting one hundred boxes in one place cannot be considered enough :)

Your idea is good, hovewer I've got some doubts about building it as a tree. You see, nature and buildings are quite different stuff ; buildings dont grow. I dont see how one extremely formalized system can solve this problem ; In short, L-system is not an answer to everything.

good luck
0 x

Post Reply