171. 3D Dungeon – finding 3D models
I usually stop after creating a basic 3D scene, because I am not really a designer, and because the speed is too low in Codea to allow adding any more complexity.
However, in this case, the speed is still very high, and dungeons are fairly straightforward to design (provide bad guys, kill them, and repeat).
So what I’ve been doing is finding 3D models for the dungeon, and I’ll talk about that in this post.
What I mean by 3D models
Codea images are 2D rectangles containing a picture surrounded by transparent pixels. Behind the scenes, they are drawn as two triangles.
3D models are completely different. They are meshes consisting of hundreds, thousands, or tens of thousands, of triangles, making up a realistic 3D shape that you can rotate in all 3 dimensions. There are usually no transparent pixels around them, because the mesh fits the intended shape exactly. The more triangles you use, the better the fit – but it takes longer to draw.
So you can think of a 3D model as a wireframe model of something.
This model needs to be clothed either with colours (each triangle corner can be given a specific colour if you want) or with a texture image, which you can think of as a canvas that is stretched over the wireframe. Most 3D models have textures.
How to create 3D models
You can create 3D models in a variety of packages like Maya, AutoCad and many others. I believe the best known free program is Blender, which I am using – but not to draw with. This is for two reasons.
One is that I am not particularly creative and can’t draw.
The other is that I find Blender to be a nightmare to use, because the UI design is the most terrible I’ve ever seen. Every time you press something, all the menus change. It’s like being in a maze of mirrors. I have to look online for absolutely everything I want to do, and even then, it’s usually confusing.
So I use Blender just for converting file types.
Where to find 3D models
Fortunately, many graphic artists are willing to share their 3D models freely, and you can use Google to find them. As with anything on the net, there are lots of “gotchas”, like models in the wrong file formats, missing elements, scam sites, broken models, models that are way too big, and so on, so you need to be patient and prepared to sort through a lot of stuff. I probably use one in ten models that I download.
In my situation of trying to keep performance good, I also look for “low poly” models (meaning smaller models with fewer polygons, ie shapes). Any file below a megabyte is worth a look, but a 10mb file is likely to kill performance (it might be ok on its own, but not in a dungeon full of other models).
Of all the things above, the right file format is the most important.
How to import 3D models
I’ve covered this quite fully in an earlier post here. I’ll repeat the most important paragraphs.
There are plenty of free models donated by generous people. Unfortunately, the datafiles produced by most modelling software are in binary form, and impossible to read without a modelling program.
However, there is one exception. The OBJ file format is in plain text and is machine readable (meaning Codea can read it). And using Blender (free!), we can convert models from most other formats to OBJ. So, subject to any licensing restrictions on the models, we are in business.
So I look for models in any format that Blender can convert to OBJ format. I now usually also make sure that the models only use triangles, and not shapes with more than 3 sides (as most models allow). Blender has an option to convert everything to triangles, so I do this before exporting to OBJ format. (My Codea import code was written to deal with shapes with more than three sides, but it doesn’t always work, so I usually stick to triangles).
Then I doctor the OBJ file (as discussed in my post), save any texture images to PhotoBucket, and create a gist with the resulting text.
Finally, I try loading the file into a test program in Codea, and see if anything appears on the screen. If it appears, it will often be
- huge
- tiny
- way up/down there
- over on the left/right
Why people don’t centre all models on (0,0,0) is beyond me…
So when I use 3D models in Codea, I need adjustments both for size (so I multiply all the vertex positions by a scaling factor (anything from 0.02 to 10, depending on the model) and add an offset to centre them correctly.
Some of the models I found so far
In this picture, you can see (roughly from left to right)
- wooden crate
- metal cage with open door
- creepy zombie monster thing
- spider
- a bug thing (from Halo I think)
- a revolver
- a mouldy cupboard
You can walk round all of these things and they look good from any angle.
Animating 3D models
This is actually my biggest problem. People do make animated 3D objects, but I don’t understand their datafiles, which are not explained. I presume it requires alternative sets of meshes – eg for arms and legs – in different positions, and you draw them in sequence to create the illusion of walking, fighting etc.
So I’m doing without any of that, which is somewhat restrictive. Basically, I need characters that don’t require obvious arm or leg movements. I can make bugs and spiders scuttle, but a person or zombie can hardly hop or slide along with frozen legs. Fortunately I found a zombie with kind of tentacle legs (see picture) that I can wobble into a reasonable kind of movement. Anything that flies or floats (like ghosts) is also an option.
The next step
My next step is, after finishing collecting all the models I can find, is to lay out the dungeon and set up some gameplay rules.
For the bad guys, I will also need to program some behaviour, such as attacking, following, and dying.
The range of skills you need to build a 3D game is really quite astonishing. I am cheating and cutting corners (like borrowing other people’s models), but it still amazes me just how much is involved.
First of all, thanks for these invaluable tutorials on how to import models into Codea. Absolutely incredible work. Just a quick note that if you’re using Blender to triangulate the faces or reduce the poly count, you might as well also use it to centre the geometry around the origin. With the mouse over the model, Shift + Ctrl + Alt + C –> Move Geometry to Origin
Thank you for that, good tip, much appreciated!