Min3D for Android: Loading Multiple MD2 files

NOTE: This OpenGL ES 1.1 framework isn’t maintained anymore. Check out the OpenGL ES 2.0 Rajawali framework which also supports live wallpapers.

This was a request from a Min3D user. It’s a short tutorial about how to load multiple animated MD2 files with Min3D. If you don’t know what MD2 files are, then read this.

The .md2 file has to placed in the “res/raw” folder of your Android project. The texture should be in the res/drawable folder. The parser picks up the textures automatically.

The most important bit of code is this:


IParser parser = Parser.createParser(Parser.Type.MD2,
	getResources(), "com.rozengain.min3d:raw/revenant", true);
parser.parse();
AnimationObject3D revenant = parser.getParsedAnimationObject();
scene.addChild(revenant);

First specify the type (Parser.Type.MD2) and the path to the resource (the package name, “raw”, and the resource id (the file name without the extension).
Adding a second MD2 model is done in the exact same way. Here’s the full code:


package com.rozengain.min3d;

import min3d.animation.AnimationObject3d;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import min3d.vos.Light;
import min3d.vos.Number3d;

public class MultiMD2Activity extends RendererActivity {
	private AnimationObject3d revenant;
	private AnimationObject3d fatso;

	@Override
	public void initScene() {
		IParser parser = Parser.createParser(Parser.Type.MD2,
				getResources(), "com.rozengain.min3d:raw/revenant", true);
		parser.parse();

		revenant = parser.getParsedAnimationObject();
		revenant.position().x = -1;
		revenant.scale().x = revenant.scale().y = revenant.scale().z = .03f;
		revenant.rotation().z = -90;
		revenant.rotation().x = -90;
		scene.addChild(revenant);

		parser = Parser.createParser(Parser.Type.MD2,
				getResources(), "com.rozengain.min3d:raw/fatso", true);
		parser.parse();

		fatso = parser.getParsedAnimationObject();
		fatso.scale().x = fatso.scale().y = fatso.scale().z = .03f;
		fatso.position().x = 1;
		fatso.rotation().z = -90;
		fatso.rotation().x = -90;
		scene.addChild(fatso);

		Light light = new Light();
    	scene.lights().add(light);

    	scene.camera().position.y = 1;
    	scene.camera().target = new Number3d(0, 1, 0);

    	revenant.setFps(20);
    	revenant.play();
    	fatso.setFps(30);
    	fatso.play();
	}
}

Download the Eclipse project here.

Loading an animated MD2 file (min3D framework for Android)

NOTE: This OpenGL ES 1.1 framework isn’t maintained anymore. Check out the OpenGL ES 2.0 Rajawali framework which also supports live wallpapers.

I just updated min3D for Android with an MD2 file importer.  MD2 is a format that was developed by ID Software and originally used for Quake II and other games. MD2 can be used for static models but the main reason for using it is animation.

Min3D is now able to import 3 different filetypes:

This is what the code looks like. Check out the min3D sample application to see it running:


package min3d.sampleProject1;

import min3d.animation.AnimationObject3d;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;

public class ExampleLoadMD2File extends RendererActivity {
	private AnimationObject3d ogre;
	@Override
	public void initScene() {
		IParser parser = Parser.createParser(Parser.Type.MD2,
				getResources(), "min3d.sampleProject1:raw/ogro");
		parser.parse();

		ogre = parser.getParsedAnimationObject();
		ogre.scale().x = ogre.scale().y = ogre.scale().z = .07f;
		ogre.rotation().z = -90;
		ogre.rotation().x = -90;
		scene.addChild(ogre);
		ogre.setFps(70);
		ogre.play();
	}

	@Override
	public void updateScene() {

	}

}

Here’s the result (click the image to see the youtube video):

Please note that it looks MUCH better on the phone.

Please note that it looks MUCH better on a handset.