MD5 model loading

I used the md5reader2 to load up a MD5 model, but nothing is showing up on the JME screen.



the FPS printout show that there is TriMesh(1), Vert(513)



Would that means the model is loaded and it's just not in the viewing area? may be scale is set too small, or camera viewing angel is incorrect?



http://www.oniva.com/upload/1356/md5.jpg

http://www.oniva.com/upload/1356/3ds.jpg

http://www.oniva.com/upload/1356/3ds2.jpg



both MD5 model files:

http://www.oniva.com/upload/1356/aaa.md5mesh

http://www.oniva.com/upload/1356/aaa.md5anim



Code to run load the model

http://www.oniva.com/upload/1356/FishTest.java



import com.jme.app.SimpleGame;

import com.jme.input.Mouse;

import com.jme.math.Vector3f;

import com.jme.renderer.ColorRGBA;



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 java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import java.util.logging.Level;


public class FishTest extends SimpleGame {
    private static final String BODYMODEL = "models/aaa.md5mesh";
    private static final String BODYANIM = "models/aaa.md5anim";
  
    private Model bodyModel;
    private Animation bodyAnimation;
    private AnimationController bodyAnimator;
    private SkeletalModelInstance bodyInstance;

    public FishTest() throws IOException {
        bodyModel = loadModel(BODYMODEL);

        bodyAnimation = loadAnimation(BODYANIM);
    }

    public static void main(String[] args) throws IOException {
        final FishTest app = new FishTest();

        app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);

        // Turn the logger off so we can see the XML later on

        app.start();
    }

    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.updateModelBound();

        bodyInstance.setLocalScale(1.00f);
        cam.setLocation(bodyInstance.getLocalTranslation().add(2.0f, 0.0f, 0.0f));

        cam.lookAt(bodyInstance.getLocalTranslation(), 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;
    }
}



JME log as following in elcipse


Dec 21, 2007 2:27:11 PM com.jme.app.BaseGame start
INFO: Application started.
Dec 21, 2007 2:27:11 PM com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
Dec 21, 2007 2:27:11 PM com.jme.system.PropertiesIO load
INFO: Read properties
Dec 21, 2007 2:27:14 PM com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
Dec 21, 2007 2:27:14 PM com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
Dec 21, 2007 2:27:15 PM com.jme.system.PropertiesIO save
INFO: Saved properties
Dec 21, 2007 2:27:15 PM com.jme.app.BaseSimpleGame initSystem
INFO: jME version 1.0
Dec 21, 2007 2:27:15 PM com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  640H: 480
Dec 21, 2007 2:27:15 PM com.jme.app.BaseSimpleGame initSystem
INFO: Running on: ialmrnt5
Driver version: 6.14.10.4396
Intel - Intel 945G - 1.4.0 - Build 4.14.10.4396
Dec 21, 2007 2:27:15 PM com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
Dec 21, 2007 2:27:15 PM com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
Dec 21, 2007 2:27:15 PM com.jme.scene.Node <init>
INFO: Node created.
Dec 21, 2007 2:27:15 PM com.jme.scene.Node <init>
INFO: Node created.
Dec 21, 2007 2:27:15 PM com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
Dec 21, 2007 2:27:15 PM com.jme.scene.Node <init>
INFO: Node created.
Dec 21, 2007 2:27:15 PM com.jme.scene.Node attachChild
INFO: Child (Skin) attached to this node (MD5Model)
Dec 21, 2007 2:27:15 PM com.jme.scene.Node attachChild
INFO: Child (MD5Model) attached to this node (rootNode)
Dec 21, 2007 2:27:19 PM com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
Dec 21, 2007 2:27:19 PM com.jme.app.BaseGame start




I tried it too with different scaling, materials and stuff, but i failed :slight_smile:

If i had a dummy box to bodyInstance, it shows the box.



Just something minor: in your code you have new ColorRGBA(1.5f, 1.5f, 1.5f, 1.0f), but the values only range from 0 to 1. But thats not a problem as it gets clamped at 1 anyway.



Heres what SceneGraphDump says:



Node: rootNode

RenderStates: LWZ

Children: SkeletalModelInstance/MD5Model 


SkeletalModelInstance: MD5Model
Controllers: [model.animation.SkeletalAnimationController@2a5330]
Children: ModelTriMesh/Skin 
ModelTriMesh: Skin
.......................
TriangleBatch: null
Batches set: VINT0
Vertex: 513
Triangles: 1016

Is that means the model has some problem



-OR-



it's the angel of camera is not correct and model not shown in the viewing area of JME?



-OR-



the scale is too small to see the model?

It's possible that one of the renderstates (Lighting, Wireframe, or ZBuffer) is disabling drawing of the model, if depth check is set to always fail, wireframe line width too small, or lighting enabled but without lights, model won't be visible.

What i saw while debugging is that the worldBound extents are all 0 (from ModelTriMesh), even after scaling and updating worldbound.

But i don't know what causes that or how to fix it :slight_smile:

Core-Dump said:
Just something minor: in your code you have new ColorRGBA(1.5f, 1.5f, 1.5f, 1.0f), but the values only range from 0 to 1. But thats not a problem as it gets clamped at 1 anyway.


That is my error.

For the model I don't know I read the source code of your test and everything seems good. Now I will investigate the model.

I am using the MD5reader2 to read the model.



I read the model using MD5reader2's FishTest.java



But i am highly suspect it's the MD5exporter is not exporting model correctly

http://www.oniva.com/upload/1356/3ds.jpg

http://www.oniva.com/upload/1356/3ds2.jpg



in MD5viewer, the "arm model" is showing up fine though

http://www.oniva.com/upload/1356/view.jpg

I used the md5reader2 to load up a MD5 model, but nothing is showing up on the JME screen.

the FPS printout show that there is TriMesh(1), Vert(513)


Usually this is because your texture isnt found, check the troubleshooting section http://www.jmonkeyengine.com/wiki/doku.php?id=exporting_animated_.md5_models_from_blender

Is your texture named Skin.tga and located in same folder as your model?

edit: also is your model and tex in another folder? I have models folder so shader string in model.md5mesh is 

shader "models/Skin"

otherwise try moving the cam around I didnt look at your code for cam position or direction or model position. oh yeah and make sure your texture isnt saved with RLE compression, change the background to gray so you can tell if model isnt there or is textured black.
mud2005 said:

Usually this is because your texture isnt found, check the troubleshooting section
Is your texture named Skin.tga and located in same folder as your model?

heh awsome, thats the problem.
I didn't have a texture in the folder...

But the Reader should print out a Warning that the Texture couldn't be loaded.
But the Reader should print out a Warning that the Texture couldn't be loaded.
sounds like your volunteering to work on the md5 reader code  :D :D

You can load my model without problem into JME?



How can you do it?



How can I load texture in the MD5reader2 code?



In the TestFish.java sample code, the fish needs texture file, but in the code never load the texture. does the model has a reference to some texture already? 



How to figure out what texture file name the model is referencing to?   

I just followd mud2005's advice and put a Skin.tga file into the folder where i have the model.

And checked the wiki for more infos :slight_smile:


In the TestFish.java sample code, the fish needs texture file, but in the code never load the texture. does the model has a reference to some texture already?
the texute is loaded in MD5DefaultSkin

How to figure out what texture file name the model is referencing to?
Its named in blender when skinning model.

If there's a missing texture then why doesn't MD5Model has a TextureState set on it?

Textures in MD5 format should be a link the *.md5mesh file.


mesh {
   // meshes: sargeheadmesh1
   shader "models/characters/sarge2/hsarge"



At least this is what I guess. If texture is null I am agree with you that it should be sobstituted automatically with a default material.
I remeber I already played around with this problem. I will resolve it, I hope.

Meanwhile, if you have any suggestion or if you want to help you are wellcome. You can submit patches on sourceforge traker or you can suggest me code directly here, or you can ask to become a MD5 Reader developer and update new code using CVS.

Meanwhile I will try to do it by myself.