More Real-Time Editable SVG in Python

More Real-Time Editable SVG in Python

RSVG Building Generator in Python

I decided that I would get the most done tonight by working on my old project that I pretty much discarded after the last blog on it. But PyGTK is so easy to use, it was no trouble adding an interface to change the variables of the building. And you can see the obvious problem inherent in a simple python script generating something interesting: it looks pretty much the same no matter what your variables are. Add a story, it's the same building with another story. Add some height and reduce the width of the windows, same building. But the cool part about a Python script is that you can just add as much junk as you want. If you think about width, there's more than I let on to architecture. Not only does each window have width and height, but there are structures holding the window to the building and they have width. There's another equation to write. In fact, I wrote a bunch of them down. The most important equation that I found, though is the width of a pixel in the real world.

pixel width = building width / Texture width Example: The building is 10 meters (33 ft) wide. pixel width = 10m / 512 px = 125/64 cm per pixel = 1.95 cm per pix (.77 in/px)

That means that I can recreate a strip of metal 2cm wide by making a line 1px wide. I can make a piece of wood 10cm wide by making a box 5px wide. But the calculations have to be exact. In fact, I need them more exact than rsvg is willing to render them. I say that I want something 1px wide and it gives me 2px wide. Why? Because it's trying to make it look really nice by anti-aliasing it. In fact, it does look nice and anti-aliased, but it screws up my calculations.

Is there anything smaller than 2cm that I would want to put on a building? No. So that means I can simply create a shaded 512px square texture for each piece of land 10m x 10m. I'm planning on 20 buildings. So that translates into 1MB per side of the building. 20*4*1MB = 80 MB for the outsides of buildings. Yowch. Thankfully, there are a bunch of options. First of all, you can compress your textures with s3tc. It's part of OpenGL ARB if you know how to use it (I don't yet). Secondly, you can texture your buildings with looping textures and smaller textures. But if we want anything as small as 2cm, we have to do it in the mesh instead of the texture. That's okay because meshes do better at detail than textures anyway. Level of detail becomes a problem for large cities, but I think Cell will do fine. The secondary reason I'm writing this building generator in Python is so I can generate meshes automatically in Blender.

But I've gotta make my buildings more diverse. It's really looking ugly right now. I have a function to add rows to that table in the upper right. That will allow me to adjust the width and height of each window. I can also adjust the position of the door.

Until next time, automation like a fire in the rain.
Javantea

Permalink

Comments: 0

Leave a reply »

 
  • Leave a Reply
    Your gravatar
    Your Name