Template for 3D village you can walk through (UPDATED)

I’ve been developing code to draw a 3D village that you can walk through, allowing buildings to be defined very simply.

UPDATE:
Code is here - https://gist.github.com/dermotbalson/5538596

Images are here - https://www.dropbox.com/sh/6sfspcbmje3hngh/mz7wCaRhO4

(zipfile included as well, for convenience)

If you get it running, the pink building on the right has interior settings, just walk right inside and have a look around

Some screen shots are below. I can’t do a video because the picture breaks up if I try.

http://instagram.com/p/ZABWgYBHck/

http://instagram.com/p/ZACYzCBHdF/

http://instagram.com/p/ZACilEhHdJ/

http://instagram.com/p/ZACnSmhHdP/

http://instagram.com/p/ZACrW8hHdS/

http://instagram.com/p/ZACwmZBHdV/

For those who are interested, each building has walls with the same texture, a wall colour tint (if you want one), a roof, and whatever door, windows, or graffiti you want to add. The buildings have insides as well, of course.

This is the code for the most elaborate building, most of the settings are x,y,w,h and image

    b:BuildingWalls(20,140,100,70,30,"Dropbox:map-whitewall2",.05,15)
    b:AddTint(color(255,255,0,50))
    b:AddFeature(3,30,0,10,20,"Dropbox:map-door1-030")
    b:AddFeature(3,5,5,15,10,"Dropbox:map-poster1-030")
    b:AddFeature(4,1,0.5,8,10,"Dropbox:map-Ignatz1-999")
    b:AddFeature(4,80,0,8,10,"Dropbox:map-door10-130")
    b:AddFeature(4,30,5,25,10,"Dropbox:map-window3-300")
    b:Roof(2,"Dropbox:map-roof1-100",.5)

The whole village so far can be defined in 50 lines of code, with about 300 lines of “engine” code to do all the meshes. The image textures come from all over the internet - any image will do.

I wanted to be able to add things like trees and animals, but of course, the problem is they are 2D images and will look flat from the side. So I cheated, and provided for these images to rotate themselves so they are always facing you. The dog is in two pictures above, taken from different angles, but he has turned himself to face me.

Simple touch navigation lets you walk around the whole map.

I haven’t decided where all this is going yet, but I decided to share at this point in case anyone is interested and wants to get involved. This code could be used to build 3D sets for games, if it is efficient enough.

This is sweet. I’m looking forward to seeing it.

This looks nice. Did you share the code anywhere? I like to play with it. I was already looking how to do this -:slight_smile:

Nice work @Ignatz.

More info, including code is available on his web page

https://coolcodea.wordpress.com/2013/04/29/45-3d-town-walkthrough/#more-8347

That code has improved a lot since I did that post, but i’m still working on it, and need to clean it up. Also I need to share the images I used.

I’ll do that in the next day or so, and then post links in my original message above and mark the title as updated. This will enable you to try it out if you wish, and create your own stuff.

Note that at present, there is nothing to stop you walking through walls (but that is quite exciting). I still need to code that.

PS I found this really hard to do, so if we can create a library to make it relatively easy, I think that would be really useful, because I haven’t seen many genuine 3D projects except simple demos. The map can in theory be extended indefinitely, too, subject to processing limits and Codea constraints.

Code and images posted in original message above, have fun!

Error map hedge-2 does not exist?

if you don’t have a hedge-2.png image, then just take a picture of some hedge or grass from the internet and save it with the name hedge-2. I think it’s only used round the edge of the map anyway. Or just comment out the line that uses it.

Is it possible to leave it blank but still start the world?

Like @Ignatz said, you could just comment out the following lines in the SetupMap function in the Map tab:

    local i="map-hedge2"
    b:BuildingWalls(0,0,WIDTH,1,15,i,.15)
    b:BuildingWalls(0,0,1,HEIGHT,15,i,.15)
    b:BuildingWalls(WIDTH,0,1,HEIGHT,15,i,.15)
    b:BuildingWalls(0,HEIGHT,WIDTH,1,15,i,.15)  

Sorry not to be more helpful right now, but I’m extremely busy!

Oh and also make sure your images are in your Dropbox, or change imageFolder=“Dropbox” in Setup to imageFolder=“Documents” or whatever the folder location is where you stored the images.