Ok. So, we know what we want our game to look like. And we want it to be 3D. So…er…how do we actually make a 3D game for iPhone?
Obviously there’s quite a few bits to this, but today we’re gonna look at making a 3D mesh and getting it to show up on your device. Now, this here certainly isn’t the only way to do it, and it’s probably not the best way either, but it’s quick and it works, and it’s what we’re using for Drive Forever.

This is quite an “asset-heavy” game – as in there’s tons of different cars, buildings, bonuses and so on, all of which need modelling and texturing. And because they’re all using fancy custom shaders, we need to see them on the iPhone as we’re making them, so we know how they’re going to come out (the other option was to write a custom viewport shader for our modelling software, which would have been pretty rad, except then we would have to make TWO versions of every shader that looked identical – nightmare).

So. We’re making our meshes in Autodesk Maya, although you could use whatever you want really, there ain’t gonna be millions of vertices or fancy NURBS surfaces or anything. We wanna see them on the iPhone. So we made a button in Maya that does it.

It’s the green one that says ‘build’.

Just press the button! Almost TOO easy!

Simple! Well, it is now, it was a bit fiddly making the button. So, the build button pops up the export window, which is just a standard maya window written in Python (could have used MEL but whatever). When you hit the Export button, another Python script runs, doing the following:

1. The Maya scene has already been set up in a neat, ordered hierarchy (you can see it in the Outliner window). When you hit export, it builds a directory structure on the hard drive that matches the maya structure. Super handy – we do NOT want to be manually moving files around, that’s how things get messed up!

2. Each object for export is actually a group consisting of: one ‘metadata’ node (actually just a NURBS curve with some custom attributes) and one or more geometry nodes. The script exports each object to a separate file using Maya’s DAE_FBX exporter (more on that later).

3. Then it creates a simple TXT file in the same folder, containing the object’s metadata. At the minute, that’s just an OBB and stuff like that, there’ll be more eventually.

4. Now it starts to get a little more involved. The Python script in Maya executes a second program, a C++ executable Tak wrote, called Meshbuilder, which does all sorts of fancy stuff.

5. First, MeshBuilder loads each DAE & TXT file pair and combines them to create an MSH suitable for use on the iPhone. It’s using the comically-named open asset import library, AssImp.

6. It replaces the Phong or Lambert materials that have been assigned in Maya with the crazy custom shaders. Interesting side note – this is super hacky! We just put a suffix on the NAME of the maya material to tell Meshbuilder what shader to use. So, for example, if a material name ends with “_matteEmissiveShaderRG”, MeshBuilder replaces the lambert material with a custom shader which uses the red channel of the texture map for the albedo, the green for the emissive, and then tints the material with a runtime-generated colour. There’s definitely a better way of doing that, but hey, this works and it was quick to code, so we can just get on with the game.

7. Then Meshbuilder looks through the DAE at all the textures on the meshes, and looks at which ones have changed since last time. Just for fun, MeshBuilder then calls another executable for all the modified textures, this time a free image convertor called PVRTexTool, which turns the uncompressed Targa textures into creates highly compressed textures that’ll run much faster on the iPhone, and generates mip-maps as well.

8. This is the cool bit. Now, there’s another program running on the iPhone, called MeshViewer. The phone needs to be on the same wireless network, and use something like Network Ping Lite to find out the IP address. Meshbuilder then sends the mesh to the phone over wifi, and it just pops up on the screen, which feels pretty frickin’ 2011. There’s some basic debug controls on MeshViewer, letting you pan, zoom and change lighting, that’s about it. It’s cool though. As well as practical applications, it could also potentially be used for comedy, wirelessly sending detailed 3D meshes of penises to people’s iPhones. Just a thought.

Where the magic happens, part 2

That’s about it. The texture compression step takes a while, often 20-30 seconds, but that isn’t necessary if you’re just editing the mesh. If you just tweaked the mesh and didn’t change the texture, it pops up on the phone about two seconds after pressing the button. Since there’s going to be around 200 assets, and each one will probably take 20 or so tweaks to get right, this little button is probably the only thing standing between the art team and total insanity….

:-)

3 Responses to “Making Drive Forever, Part 2: Fun with Pipelines”
  1. CrazyEoin says:

    I really cant wait to play this! Its looks awesome as a game and its super cool that your giving us the behind the scenes as it happening. I take it that “MeshViewer” is a custom app that you guys made your selves?

  2. Forum Admin says:

    Hey, thanks CrazyEoin! We’re lookin forward to playing it as well! Yes, both MeshBuilder and MeshViewer are custom apps that Tak wrote, they’re designed specifically for this game, so they’re not much use to anyone else yet, although you may be able to talk Tak into releasing something eventually….

    :-)

  3. CrazyEoin says:

    Cool! Although I use Unity3D for most of my dev work so although I won’t get as slick looking visuals as your selves ( not without learning a load more about writing my own custom shader’s ) I can get sort of the same rapid visual feedback for how it will look.

    Another quick question while I’ve got your attention, building roads is very cool, and the concept has me completely stoked but what about the cars? What kind of handling can we expect? Ridge Racer? Grand Turismo? GTA? This is a very important factor in how the game will feel. Also any chance for customizable cars, as in not just the paint work but the shape of the car and its accessories?

    Loving what I’m current seeing, keep up the awesome work!

Leave a Reply