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();
}
}