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

4 thoughts on “Quick Peek at libgdx’ new 3D Stuff

  1. Hi!

    We’re working on a game based on libgdx. How far is the custom binary format for the models (especially for bones + animation)? ’cause I couldnt get the animation get work on android(cause: 04-16 22:13:31.095: WARN/dalvikvm(13391): VFY: unable to resolve static method 5645: Ljavax/xml/bind/JAXBContext;.newInstance ([Ljava/lang/Class;)Ljavax/xml/bind/JAXBContext;
    ), just local. Good job so far.

Leave a Reply

Your email address will not be published.