Zephyris' Procedural Buildings Tool

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Zephyris' Procedural Buildings Tool

Post by Zephyris »

So here's something a bit different:

I have decided I was bored of drawing buildings and wanted a tool that could draw them for me, so I am working on a procedural building generator! This, at the moment, is made up of two halves; one half generates the building structure (including construction stages and the four orientations) based on a simple numerical description of the building's storeys and roofs. The second half procedurally colours the building with the TTD palette. It is all still under heavy development but it's (IMO) quite impressive so I wanted to show off how powerful it could be!

Here is an example building definition:

Code: Select all

storeyheight=6;
windowwidth=3;
windowheight=3;
windowbaseheight=2;
windowspacing=2;
buildingdefinition=newArray(
	0, 1, 8, 12, 22, 8,
	1, 2, 16, 8, 2, 20,
	0, 1, 16, 24, 2, 4,
	1, 3, 8, 12, 22, 8,
	1, 1, 16, 16, 2, 4,
	2, 2, 2, 16, 2, 4,
	2, 1, 14, 16, 4, 4,
	3, 3, 14, 16, 4, 4
);
auxdefinition=newArray(
	1, 0, 1, 1,
	0, 0, 0, 0,
	0, 1, 1, 1,
	0.7, 1, 0, 0,
	1, 0, 1, 0,
	0, 0, 0, 0,
	1, 1, 1, 0,
	0.7, 0, 0, 0
);
The two big arrays contain most of the info about the building structure. The building definition array has 6 entries per line which define the following:

Code: Select all

s, t, w, d, x, y
s=storey (i.e. 0 (ground), 1 (first), 2 (second), etc.)
t=type (1=walls, 2=flat roof, 3=sloped roof)
w=width (in 3D)
d=depth (in 3D)
x=x location (in 3D)
y=y location (in 3D)
The aux definition array has 4 entries per line which define which walls have windows in for walls, the height and orientation of a sloped roof, and will be where any other future variables will sit.

This set of instructions gives the following building:
Building1.png
Building1.png (3.37 KiB) Viewed 5421 times
This can be fully "proceduralised" with some random numbers...

Code: Select all

gwa=randomRangeEven(12, 20);
gwb=tilew-gwa-2;
bya=randomRangeEven(0, 8);
byb=randomRangeEven(0, 8);
gda=randomRangeEven(16, 32-bya);
gdb=randomRangeEven(16, 32-byb);
uda=randomRangeEven(8, 14);
udb=randomRangeEven(8, 14);
bxa=0;
bxb=gwa+2;
buildingdefinition=newArray(
	0, 1, gwa, gda, bxa, bya,
	1, 2, gwa, gda-uda, bxa, bya+uda,
	1, 1, gwa, uda, bxa, bya,
	2, 1, gwa, uda, bxa, bya,
	3, 3, gwa, uda, bxa, bya,
	0, 1, gwb, gdb, bxb, byb,
	1, 2, gwb, gdb-udb, bxb, byb+udb,
	1, 1, gwb, udb, bxb, byb,
	2, 3, gwb, udb, bxb, byb
);
auxdefinition=newArray(
	1, 1, randomBinary(), 1,
	0, 0, 0, 0,
	1, randomBinary(), 1, randomBinary(),
	1, randomBinary(), randomBinary(), 1,
	0.7, randomBinary(), 0, 0,
	1, 1, randomBinary(), 1,
	0, 0, 0, 0,
	1, randomBinary(), randomBinary(), 1,
	0.7, randomBinary(), 0, 0
);
These procedural instructions give, for example, the following buildings:
ProcBuilding2.png
ProcBuilding2.png (3.94 KiB) Viewed 5421 times
ProcBuilding3.png
ProcBuilding3.png (3.89 KiB) Viewed 5421 times
A few sets of procedural instructions should be able to generate a very wide range of buildings, from terraced houses to skyscrapers, extremely quickly and consistently... It would also make generating regional variations of architecture style (e.g. typical roof slopes, building size, window shape/size, etc.) for a building set really simple!
Last edited by Zephyris on 09 Nov 2010 01:29, edited 1 time in total.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Zephyris' Procedural Buildings Tool

Post by Zephyris »

The second half of the program colours the building, and does so in a very similar drawing style to my existing OpenGFX and UK town set buildings... Using the example building from above here are some typical results that pop out:
Building1a.png
Building1a.png (14.36 KiB) Viewed 5419 times
Building1b.png
Building1b.png (12.23 KiB) Viewed 5419 times
Building1c.png
Building1c.png (15.55 KiB) Viewed 5419 times
The colouring is all based on random or customised base palette entries for the walls, roof, floor and windows, then is shaded and textured in 8bpp by some custom tools I have written. Other neat tricks it can do are vertically and horizontally (taking into account perspective) striped wall textures.
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Zephyris' Procedural Buildings Tool

Post by supermop »

This is great! I've been wanting to do a metabolist building set once i get my shed grf tidied up, and this is perfect (from a metabolist architecture perspective - i kind of like drawing the buildings).

I'll be watching this space!
User avatar
Purno
Tycoon
Tycoon
Posts: 16659
Joined: 30 Mar 2004 12:30
Location: Almere, The Netherlands

Re: Zephyris' Procedural Buildings Tool

Post by Purno »

This is cheating. How can a coder possibly keep up with the speed you're creating sprites? :mrgreen:
Just kidding

Interesting tool. Very interesting.
Contributor to the The 2cc Set and Dutch Trainset. Inventor of the Metro concept. Retired Graphics Artist.
Image Image
Download TT | Latest TTDPatch | OpenTTD | OpenTTDCoop | BaNaNaS: OpenTTD content system | 2048² OTTD scenario of the Netherlands
GRF Codec | GRF Crawler | GRF Maker | Usefull graphics & tools sites | NML Documentation Wiki | NFO Documentation Wiki
All my graphics are licensed under GPL. "Always remember you're unique, just like everyone else."
User avatar
Ammler
President
President
Posts: 953
Joined: 18 Jun 2006 18:18
Location: Switzerland
Contact:

Re: Zephyris' Procedural Buildings Tool

Post by Ammler »

Purno wrote:How can a coder possibly keep up with the speed you're creating sprites?
I would assume, it does create the code too :-)

(looks almost like nml code already anyway)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Zephyris' Procedural Buildings Tool

Post by planetmaker »

This looks very impresive and awesome, Zeyphris! I'm looking forward seeing it in action :-)
Purno wrote:This is cheating. How can a coder possibly keep up with the speed you're creating sprites? :mrgreen:
Not a problem. The sprites are all aligned in the same pattern, thus coding can be just as fast :-)
User avatar
cmoiromain
Chief Executive
Chief Executive
Posts: 655
Joined: 15 Jan 2007 21:45
Location: FRANCE
Contact:

Re: Zephyris' Procedural Buildings Tool

Post by cmoiromain »

Sir, you are a pure genius. This is mindblowing!
I am little, ugly, and nasty. How do you do?
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Zephyris' Procedural Buildings Tool

Post by Zephyris »

Thanks for all the positive comments! Heres a little update on the colouring aspect - multiple colour schemes per tile (defined on a per storey/roof basis, max 8 colour schemes). The colour schemes are encoded in the building structure by grey shade, e.g. the outer rear wall is 128 for colour scheme 1, 129 for colour scheme 2, 130 for colour scheme 3, etc, then coloured appropriately by the colouring program.
Building.png
Building.png (4 KiB) Viewed 5142 times
BuildingCol.png
BuildingCol.png (19.66 KiB) Viewed 5142 times
I think the next fight is going to be accurate z sorting of the various building objects. It is working at the moment, but is quite hacky and I'm sure it will fail with some cases; it's really hard to get your head round! I'm also not exactly sure what to do for generation of the ground tiles for house-like buildings. And chimneys.
Purno wrote:How can a coder possibly keep up with the speed you're creating sprites?
I do plan to automatically generate some useful code to speed up coding of sprites. I was planning to just dump the sprite location and x/y offsets and image file name in the form of the real sprites for the building... Would any other code be useful? (bounding box? whatever those are :) ). TBH I have never coded buildings and I'm not quite sure what is needed.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Zephyris' Procedural Buildings Tool

Post by Zephyris »

One more treat for tonight... Procedural step-back skyscrapers building structures.

You definately want to view the attachments :)
Building1.png
(32.79 KiB) Downloaded 2 times
Building2.png
(20.47 KiB) Downloaded 2 times
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Zephyris' Procedural Buildings Tool

Post by Yexo »

Very impressive work Zephyris. With regards to coding: a filename, x/y offset for every sprite (unless it's always the same), width/height of every sprite (again: unless it's always the same). The bounding box could be the same for every house except for the height, which could be computed from the height of the sprite. If you can provide this information in a machine-readable format I'll write the code / write a generator for the code. This work is too good not to be used because it's not coded.
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: Zephyris' Procedural Buildings Tool

Post by supermop »

I know its a stretch, but could some of the workings of this be manifested in a newgrf? perhaps to create random buildings/vehicles in in game?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Zephyris' Procedural Buildings Tool

Post by Kogut »

supermop wrote:I know its a stretch, but could some of the workings of this be manifested in a newgrf? perhaps to create random buildings/vehicles in in game?
Rather no ingame, but it may be possible to integrate it with code generator and NML compiler to gen program that will generate new newgrf every time.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Zephyris' Procedural Buildings Tool

Post by planetmaker »

Yexo wrote:Very impressive work Zephyris. With regards to coding: a filename, x/y offset for every sprite (unless it's always the same), width/height of every sprite (again: unless it's always the same). The bounding box could be the same for every house except for the height, which could be computed from the height of the sprite. If you can provide this information in a machine-readable format I'll write the code / write a generator for the code. This work is too good not to be used because it's not coded.
I'd like to co-sign this pledge, too
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Zephyris' Procedural Buildings Tool

Post by Zephyris »

Kogut wrote:
supermop wrote:I know its a stretch, but could some of the workings of this be manifested in a newgrf? perhaps to create random buildings/vehicles in in game?
Rather no ingame, but it may be possible to integrate it with code generator and NML compiler to gen program that will generate new newgrf every time.
Maybe I should have written the scripts in something more portable :) At the moment it is in the ImageJ (my favourite open source scientific imaging program) macro language. I'm sure it could be ported to something more sensible with relative ease, it is a very conventional syntax.
Yexo wrote:Very impressive work Zephyris. With regards to coding: a filename, x/y offset for every sprite (unless it's always the same), width/height of every sprite (again: unless it's always the same). The bounding box could be the same for every house except for the height, which could be computed from the height of the sprite. If you can provide this information in a machine-readable format I'll write the code / write a generator for the code. This work is too good not to be used because it's not coded.
Sounds like a good offer :) I'll keep these variables in mind when coding the generator, I should be able to generate some example numbers in the near future...
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Zephyris' Procedural Buildings Tool

Post by planetmaker »

Zephyris wrote:Maybe I should have written the scripts in something more portable :) At the moment it is in the ImageJ (my favourite open source scientific imaging program) macro language. I'm sure it could be ported to something more sensible with relative ease, it is a very conventional syntax.
ImageJ is definitely portable ;-) and it's not like its syntax looks like totally incomprehensible, even though I haven't yet written any scripts for it. A pro would also be that ImageJ is quite well documented.
So unless you find a good reason to move away from it... keep it simple and stick to it. :-)
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Zephyris' Procedural Buildings Tool

Post by Zephyris »

Just so you call know I am still fiddling with the generator trying to get the results as good as possible... It is, unfortunately, a classic 80%/20% thing; 20% effort to get 80% finished, 80% effort to get the last 20% sorted! Hopefully I can get it finished at some point though :)

I've also done some stuff on a procedural tree generator... Any thoughts? It makes growth stages dead easy to generate, it would also make creating season variations (if OpenTTD ever supports that, hint hint) of the trees very simple.
Attachments
ProcTrees1.png
ProcTrees1.png (9.74 KiB) Viewed 4756 times
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Zephyris' Procedural Buildings Tool

Post by Kogut »

Can you generate next pack of trees?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Zephyris' Procedural Buildings Tool

Post by Zephyris »

Kogut wrote:Can you generate next pack of trees?
What do you mean? A new tree set? That is the plan!
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: No registered users and 23 guests