I am a teacher, and some students of mine are trying to build a computer game (at least some part of it).
I can program Java, and has studied jME a bit, some months already.
This is my first try using jME to load a model.
The students has build the animation in blender.
I exported it to md5 following Ender directions and software.
I used the marine example, adapting it to the students model.
After a lot of forum readings, and a lot of failures, finally I managed to have my model showing.
this is my code:
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
//import java.util.logging.Level;
import md5reader.MD5AnimReader;
import md5reader.MD5MeshReader;
import model.Model;
import model.SkeletalModelInstance;
import model.animation.Animation;
import model.animation.AnimationAnimator;
import model.animation.AnimationController;
import com.jme.app.SimpleGame;
import com.jme.input.Mouse;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.math.Quaternion;
import com.jme.math.FastMath;
import com.jme.scene.SceneElement;
//import com.jme.util.LoggingSystem;
/*
* BopeTest.java
* Created on 08-agu-2007
*
* Copyright md5reader.sourceforge.net, 2007
*
* MarineTest.java is a derivate of JmeDDSTest.java, created by Gareth Jenkins-Jones.
*
* JmeDDSTest.java
* Created on 06-Feb-2005
*
* Copyright Chaosdeathfish.com, 2005
*/
/**
* TODO Document me
*
* @author Marco Frisan
*/
public class BopeTest extends SimpleGame {
private static final String BODYMODEL = "models/characters/bope/bope.md5mesh";
private static final String BODYANIM = "models/characters/bope/bope.md5anim";
private Model bodyModel;
private Animation bodyAnimation;
private AnimationController bodyAnimator;
private SkeletalModelInstance bodyInstance;
public static void main(String[] args) throws IOException {
final BopeTest app = new BopeTest();
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
// Turn the logger off so we can see the XML later on
//LoggingSystem.getLogger().setLevel(Level.OFF);
app.start();
}
public BopeTest() throws IOException {
bodyModel = loadModel(BODYMODEL);
bodyAnimation = loadAnimation(BODYANIM);
}
protected void simpleInitGame() {
lightState.get(0).setAmbient(new ColorRGBA(1.5f, 1.5f, 1.5f, 1.0f));
bodyInstance = new SkeletalModelInstance(bodyModel);
bodyAnimator = bodyInstance.addAnimationController();
AnimationAnimator anim = bodyAnimator.addAnimation(bodyAnimation);
anim.setInterpolationThreshold(0f);
bodyAnimator.update(0f);
bodyInstance.getMeshes()[0].setNormalsMode(
SceneElement.NM_GL_NORMALIZE_IF_SCALED);
bodyInstance.updateModelBound();
bodyInstance.setLocalScale(1.00f);
Quaternion q = new Quaternion();
q.fromAngleAxis(FastMath.PI/2, new Vector3f(-1,0,0));
bodyInstance.setLocalRotation(q);
// cam.setLocation(bodyInstance.getLocalTranslation().add(2.0f, 0.0f, 0.0f));
// cam.lookAt(bodyInstance.getLocalTranslation(), new Vector3f(0.0f, 1.0f, 0.0f));
cam.setLocation(bodyInstance.getLocalTranslation().add(0.0f, 75.0f, 300.0f));
// cam.lookAt(bodyInstance.getLocalTranslation().add(0.0f, 50.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f));
rootNode.detachAllChildren();
rootNode.attachChild(bodyInstance);
}
private Model loadModel(String path) throws IOException {
InputStream in = getClass().getResourceAsStream("/" + path);
if (in == null)
throw new FileNotFoundException("Cannot find " + path);
MD5MeshReader reader = new MD5MeshReader();
reader.setProperty(MD5MeshReader.CLASSLOADER, getClass()
.getClassLoader());
return reader.readModel(in);
}
private Animation loadAnimation(String path) throws IOException {
InputStream in = getClass().getResourceAsStream("/" + path);
if (in == null)
throw new FileNotFoundException("Cannot find " + path);
MD5AnimReader animReader = new MD5AnimReader();
Animation animation = animReader.readAnimation(in);
return animation;
}
}
The problem is that the head of the model (and another part, maybe the ak47) is streaching away from the rest of the body. I don't know if its a blender problem, md5 exporter problem, jME code problem, or a bit of all this problem.
This is what hapenning: http://s5.photobucket.com/albums/y161/Adranbach/?action=view¤t=bopeProblem3.png
and more: http://s5.photobucket.com/albums/y161/Adranbach/?action=view¤t=bopeProblem2.png
I would appreciate any help I can receive. I am not able to operate blender, my students made the model, but if some checking is necessary, I will ask to them.
Thanks :)