md5reader problem: Can anyone help me? (SOLVED)

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&current=bopeProblem3.png
and more: http://s5.photobucket.com/albums/y161/Adranbach/?action=view&current=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 :)

looks like a rigging issue i.e some verts not attached to bones

Thanks for the answer :slight_smile:

I have asked the group of students to check the model, it really seems there are problems in the model animation, related to bones. I will post the results if we succeed.

Take a look in the wiki at the page Update functions in the scene graph.



There are some general rules about calls to update methods. The first one says:


If a node was translated, scaled or rotated call updateGeometricState().


So, I think you could try to add a updateGeometricState() call after you rotate the bodyInstance.


      bodyInstance.setLocalScale(1.00f);
                Quaternion q = new Quaternion();
                q.fromAngleAxis(FastMath.PI/2, new Vector3f(-1,0,0));
                bodyInstance.setLocalRotation(q);

      bodyInstance.updateGeometricState(0f, false); // add this



I don't know what values should be used for the timer and initiator parameters of the method.

Thx for the reply, Ender.

I asked the author of the model to check it, and he did found some errors on blender about the union of skeleton and vertex. I am waiting for him to correct those, so we can continue our studies.

As soon as I run it with the new model, I will post here.

Thanks very much for the answers, I finally succeed in run the animation of the char properly.

First of all it was necessary to check and connect all the bones, there were some bones indeed that was not connected properly, and maybe this caused some flaws on the hierarchy.

After that, the model was shaking a lot, to correct this I had to recompile and regenerate a md5r2.jar file.

I must confess that as I downloaded the md5reader2 recently (mid December) I tough that all should be already fixed, but it is not, as Ender have kindly warned some where in this forum.

I have added all the stuff that was recommended here, I'm not sure if all is necessary, but now it will be easy to check what is missing or not.

There is a long way ahead until my group of students will be able to build a game, but certainly produce a animated model from scratch in blender and then put it in a scene graph running is a great motivator! jME and all the guys around here Rocks!

I will check how I can be useful, maybe providing a ready to use md5r2.jar to put in cvs, I compiled it trough a build.xml file I coded to use with ant.

If someone needs some inputs on what I have done here, I will try to help, just post here.

the shaking is stopped by adding an origin bone, did u find a way to have it work as u expect without that bone :?

duodecimo said:
After that, the model was shaking a lot, to correct this I had to recompile and regenerate a md5r2.jar file.


Really interesting! We never guess that a recompile could be a solution to this problem.

duodecimo said:
I will check how I can be useful, maybe providing a ready to use md5r2.jar to put in cvs, I compiled it trough a build.xml file I coded to use with ant.
If someone needs some inputs on what I have done here, I will try to help, just post here.


It would be really helpfull to add your ant script and your recompiled package somewhere in the space on SourceForge. It should be possible to post that files as patches in the Tracker; if not, please, contact me and we can manage to find a way to upload the files.

I would also be happy to host informations and images of your project in the MD5 Reader 2 SourceForge web space, if possible.

mcbeth said:
the shaking is stopped by adding an origin bone, did u find a way to have it work as u expect without that bone :?


I am not sure about that, because I should re-read the MD5 spec., but if I remember well an Origin bone should be a requirement of MD5 format. Though, even if I am wrong and the Origin bone is not a requirement, it is always a good idea to put it in a bone hierarchy: Introduction to Rigging (i am not sure if the argument of the Origin bone is explained in this page because the Blender site seems to be unreachable at the moment, but the argument is surely somewhere in this tutorial).

I have read about the original bone, and edited the md5mesh file intending to add it, then, I figured out that the first bone there already had a very similar value as the one proposed here on forum, exported as it is from Blender, as you can see in the transcription:

joints {
   "TORAX"   -1 ( -0.007770 0.214233 10.997836 ) ( -0.500000 -0.500000 -0.500000 )      //


In fact, it worked without modification. I think that Ender last correction did the work, as I only had to recompile the md5reader2 code downloaded from CVS and use it.

As I was writing this answer, Ender posted:
I will gladly provide the code, the xml script and the model, Ender. I advance that it is not a clean code, as I was trying and modifying it successively, but, what the heck, we can always make it nicer later :)

I can e-mail them for you, just contact me at duodecimo, at gmail, dot, com, if its ok for you.
duodecimo said:
In fact, it worked without modification. I think that Ender last correction did the work, as I only had to recompile the md5reader2 code downloaded from CVS and use it.


Maybe, when I made that change, I forgot to export also the jar package. So the jar currently in the CVS does not contain the updated classes. I am sorry. :roll:

I will contact you soon for the script and the jar, thank you a lot for help and feedback.