Quick Peek at libgdx’ new 3D Stuff

Here’s a code snippet how working with the new libgdx 3D classes will look like. In this case i have a model loaded from an Ogre mesh and skeleton file, which is composed of two sub-meshes. I use the same Material for each sub-mesh, hence the call to model.setMaterial(). There’s another method that allows you to set the material of each sub-mesh separately. You can of course also directly manipulate all members of a model (everything is public, all hail…).

First i load a texture and create a new Material (according to the specs of the last blog post, that’s implemented already…). Then i call the Ogre loader, telling it where to find the files. Once loaded i have to set the material of each part of the model (in this case two, sharing the same material). Finally i can set the animation by specifying the animation name as well as the animation time in seconds. This will “skin” the model, meaning that the vertices will be positioned such that they represent the pose of the animation at the given time. The final call will setup all materials and render the currently set pose.

If you want to use a single model for multiple objects in your scene you’d just keep track of which animation and animation time the objects are in, call model.setAnimation() and then model.render().

Caveat: you’d set the same material multiple times if multiple objects share the same model. I decided against implementing state/material sorting. 90% of the time your scenario will be trivial and it will be easy to set the material once, render all objects sharing the model, then move on to the next object group.

Everythings already working so far. I gotta clean up a couple of things, then write the binary format (de-)serialization. Next i’m gonna implement key framed models, with an MD2 loader as the base and a way to convert bone models (Ogre models) to key-framed models. I’ll also add another model class for static (multi-mesh) models, using the Obj loader ESpitz is currently working on. That should cover all bases: skeletal animation models, key-framed models (faster) and static models.

I then have to convert all the Java stuff to native code so it runs acceptably on Android. Not a huge deal, but might need some adjustment of the datastructures i have so far.

The final thing i have to do is come up with a good system to integrate mount points in animated models. We’ll see how that will work out. For skeletal animation models its easy, you basically get a quaternion/matrix you can use to position your attached model (e.g. a weapon). For key-framed models loaded from an MD2 file it’s not so easy. We’ll see.


  • Implement MD2 loader (again) and key-framed models
  • Implement OBJ loader (provided by ESpitz i hope) and static models
  • (De-)serialization of models to custom binary format
  • Native methods for skining/frame interpolation
  • Mount points/axes

A Material System for Libgdx

I threw together a quick pseudo design for the material system i want to have in libgdx. Here we go (that’s actually a few weeks old already…):

That’s just an early design, not entirely cast in stone (Vevusio would like the MaterialAttribute class to be an interface actually, i kind of agree. kind of). Of course this system is very basic, in the spirit of the VertexAttribute class. It should suite both OpenGL ES 1.x and 2.0 (hence the need for naming material attributes so that they can be bound to a shader). Each MaterialAttribute implementation is responsible for setting the appropriate GL state/uniforms where possible. What’s still open is a system that can help reduce state changes. Not sure how to approach that yet, we’ll see.

Feedback welcome.

Workshop Sources & Slides

I figured it would be a nice thing to open source the sources and slides of the workshop on Android Game Development i held at this year’s Droidcon in Berlin last week. For this i created a new Google Code project over here, and also created a new sub-forum on our forums. The slides are rather comprehensive (201 slides in total) and are meant as a kind of script for people that want to “replay” what happened at the workshop. We talked about how to create a game development framework for Android (based on SurfaceView and Canvas) and how to implement a game:

The code is licensed under the Apache 2 license, so feel free to do with it whatever you want (in accordance to the license of coures). The assets are partially created by myself, some are from 3rd parties that either made them public domain or for which i rely on the fair use clause for teaching purposes. The slides are CC licensed, you are allowed to redistribute them, print them etc. but you are under no circumstances allowed to modify or commercialize them (read: make money off of them). If i find out you do i’m gonna hunt you down and twist your nipples.