Blog

Blog

Abusing Clutter

Posted at 22:57 on 06 Jun 2008

I thought it might be fun to see how easy it is to use Clutter with full 3D actors instead of just flat rectangles. I started off by thinking I could make something like a table tennis game with a proper model for a table and the bats. I made a model for the table with a bit of wrestling with Blender so I needed a way to display the model in Clutter.

I decided to write a library to display MD2 models as a Clutter actor. MD2 is the model format from Quake 2 for players and weapons. It seemed like a good format because it's quite simple and it already represents the model as a set of triangle fans and triangle strips so it fits nicely with OpenGL.

The result of that is available in a git repo here:

git clone git://github.com/bpeel/clutter-md2.git

You can create an actor from an MD2 file by passing it the filename. When painting the model it scales the coordinates to fit in the width and height of the actor while preserving the aspect ratio (so you can position it easily with other pixel-based actors). You can rotate and move the actor with the regular actor API. There is also a new behaviour to animate the model using the frames in the file. The frames are interpolated as key frames to make the animation a bit smoother.

image

I didn't have much luck with the MD2 exporter of Blender because it kept complaining that I'd scaled the model and it made a mess when it tried to convert it to triangles. So for now I've given up on the table tennis game and started making a simpler game to demonstrate the library using the ready-made MD2 models from here.

The game creates a scrolling road (made entirely out of ClutterRectangles) and animates driving past some tractors in a car (which are MD2 models). You can move the car with the arrow keys, but other than that it needs a lot of work.

image

The git repo for the game is at:

git clone git://github.com/bpeel/tractordodge.git