Author Topic: Loading animation from a md2 file  (Read 4984 times)

Offline David Restrepo

  • byte
  • *
  • Posts: 1
    • View Profile
Loading animation from a md2 file
« on: March 22, 2005, 11:49:52 pm »
Hello there, How are you?

Í'm beginning to work with JPCT and I'm having some problems to use animations from md2 files. I'm working with the tutorials for learning.

This is the code for loading the md2 file:
.
.
.
Object3D hombre=Loader.loadMD2("3d"+File.separator+"hombre.md2", 1f);
hombre.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
TextureManager.getInstance().addTexture("hombretex", new Texture("3d"+File.separator+"hombre.jpg"));
hombre.setTexture("hombretex");
hombre.setCenter(SimpleVector.ORIGIN);
hombre.translate(50, 0, 0);
hombre.build();
theWorld.addObject(hombre);

Animation anima=new Animation(61);
anima.createSubSequence("stand");
anima.addKeyFrame(hombre.getMesh().cloneMesh(true));
hombre.setAnimationSequence(anima);

theWorld.addObject(hombre);
.
.
.
private void gameloop() {
.
.
   while (!exit) {
            hombre.animate(0, 0);
            if (anim>1) {
               anim=0;
               } else {
               anim+=0.1f;
               }
.
.
.
But when I'm running the .class I get this error:

Loading file 3d\hombre.md2
File 3d\hombre.md2 loaded...67052 bytes
Magic number: 844121161
Version: 8
Skin width: 384
Skin height: 192
Frame size: 852
Number of skins: 1
Number of Vertices: 203
Number of Texture coordinates: 311
Number of triangles: 400
Number of GL-commands: 2013
Number of Frames: 62
Reading Texture coordinates...
Done!
Reading polygonal data...
Done!
Reading keyframes...
Done!
Coverting MD2-format into jPCT-format...
Processing: base...
Processing: stand...
Processing: run...
Processing: leap...
Processing: kick...
Processing: punch...
Processing: shoot...
Processing: pain...
Processing: death...
Done!
Java version is: 1.4.2_03
-> support for BufferedImage
-> using BufferedImage
Software renderer (legacy mode) initialized
Software renderer disposed
Software renderer (OpenGL mode) initialized
6-12 -> using splitted buffer access!
Exception in thread "main" java.lang.NullPointerException
        at JPCTTutorial3.gameloop(JPCTTutorial3.java:137)
        at JPCTTutorial3.<init>(JPCTTutorial3.java:109)
        at JPCTTutorial3.main(JPCTTutorial3.java:243)

Can you help me to understand how to use the animations contained into a md2 file?
 :wink:
Thanks in advance.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Loading animation from a md2 file
« Reply #1 on: March 23, 2005, 09:49:55 am »
If you are loading a MD2, there's no need to create an Animation by yourself. The loader already does this for you. So reduce your code to something like this:

Code: [Select]
Object3D hombre=Loader.loadMD2("3d"+File.separator+"hombre.md2", 1f);
hombre.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
TextureManager.getInstance().addTexture("hombretex", new Texture("3d"+File.separator+"hombre.jpg"));
hombre.setTexture("hombretex");
hombre.translate(50, 0, 0);
hombre.build();
theWorld.addObject(hombre);

private void gameloop() {

while (!exit) {
hombre.animate(anim, 0);
if (anim>1) {
anim=0;
} else {
anim+=0.1f;
      }
                ....
}
}