Sorry, is there anybody can help me to solve the problem with the texture of MD5

I add a MD5 node to my project use this code:



try{

     MD5Importer importer = new MD5Importer();

     URL MD5Url = fristTest.class.getClassLoader().getResource("pic/2/11.md5mesh");

     importer.loadMesh(MD5Url, "box");

     mesh = importer.getMD5Node();

     importer.cleanup();

   }

   catch(IOException e){

     System.out.println("MD5 loading error");

   }

  Spatial model = (Spatial)mesh;

  rootNode.attachChild(model);



I can see the model in my game window, but I still dont know how to add the texture to the MD5 node. I read some topic in the forum, but there is a few information about it.

Sorry, I am a new guy.

You will have to tell the exporter where to find the textures.

Replace resources/ with your directory:


try {
   ResourceLocatorTool.addResourceLocator(
      ResourceLocatorTool.TYPE_TEXTURE,
      new SimpleResourceLocator(ResourceManager.class.getClassLoader().getResource("resources/")));
} catch (URISyntaxException e1) {
   System.out.println("Error");
}

oh, can you give me a example, I still cant handle that.

Thank you!

Actually this is already an example. Place it before you try to load your model and replace "resource/" with the package your texture is in.

So I assume the texture is in the same package as the model then it should be:


try {
   ResourceLocatorTool.addResourceLocator(
      ResourceLocatorTool.TYPE_TEXTURE,
      new SimpleResourceLocator(ResourceManager.class.getClassLoader().getResource("pic/2/")));
} catch (URISyntaxException e1) {
   System.out.println("Error");
}



Nevertheless there is quite often the problem that the texture is stored as absolute-path. That might be a problem. You could have a look in the md5-file, search for the texture-file and change the directory to the right one (e.g. to ./texture.jpg ) But don't forget to keep a copy of the orginial one.

Thanks a lot!



I am new to JME, please forgive my inexperience.

So you got it work? Did you had to change the file or was setting the ResourceLocator enough?

No, but I still try to figure it out.

So plz post the code you got so far…maybe we will see something!?

Oh, I would appreciate your help.


public class fristTest extends BaseSimpleGame {
   
     ......

     public static void main(String[] args) {
fristTest app = new fristTest();
app.setDialogBehaviour(ConfigShowMode.AlwaysShow);
app.start();
}

     protected void simpleInitGame() {
buildRocketMD5();
}

     public void buildRocketMD5(){
     IMD5Node mesh = null;
IMD5Animation Anim=null;
IMD5Controller animController;

try{
                                               //I want use the way your tell me to locate the texture
            ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(fristTest.class.getClassLoader().getResource("pic/2/")));

MD5Importer importer = new MD5Importer();
URL MD5Url = fristTest.class.getClassLoader().getResource("pic/2/11.md5mesh");
URL MD5UrlAnim= fristTest.class.getClassLoader().getResource("pic/2/11.md5anim");
importer.loadMesh(MD5Url, "box");
importer.loadAnim(MD5UrlAnim, "simpleAnim");
mesh = importer.getMD5Node();
Anim=importer.getAnimation();
importer.cleanup();
}
catch(IOException e){
System.out.println("MD5 loading error");
}
                               catch (URISyntaxException e1) {
System.out.println("Error");
}


//this method to add animation to controller
animController = new MD5Controller(mesh);
animController.addAnimation(Anim);
animController.setActive(true);
animController.setRepeatType(2);
animController.setSpeed((float) 0.1);

Spatial model = (Spatial)mesh;

model.setLocalScale(0.025f);
model.setLocalTranslation(new Vector3f(20,0,20));
model.getLocalTranslation().y = (float) (tb.getHeight(model
.getLocalTranslation())+3);

rootNode.attachChild(model);
rootNode.updateGeometricState(0, true);
}

        ......

}

but still cant get to work. MD5Node is not extend from Node or Spatail, so I cant use this code to add texture to MD5Node as simple Node.

TextureState ts = display.getRenderer().createTextureState();
 ts.setEnabled(true);
 ts.setTexture(
           TextureManager.loadTexture(
               Lesson1.class.getClassLoader().getResource(
               "pic/2/RL_D256.dds"),
               Texture.MinificationFilter.Trilinear,
               Texture.MagnificationFilter.Bilinear));

 model.setRenderState(ts);
 model.updateRenderState();