Author Topic: Help regarding loading a MD2 model  (Read 1828 times)

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Help regarding loading a MD2 model
« on: June 16, 2009, 02:37:58 pm »
Hello people,

I have never played around with 3D before, I know java pretty well, but just never used it for graphics though.
I tried following the example from http://www.jpct.net/wiki/index.php/Loading_3ds_Models_from_Blender, to load a model.

All went ok, but then i changed the model to a MD2 model. I seems like it loads the model, and applying textures, and I can't seem to either size it correctly i think. The model looks very FLAT.

if its any help then I downloaded a Quake 2 model from http://www.polycount.com/models/quake2/, that i tried with.

Here is the my source code.


Code: [Select]

import com.threed.jpct.*;

import javax.swing.*;

public class HelloWorldSoftware {
    private String[] textures = {"sydney"};
    private String thingName = "sydney";
    private int thingScale = 1;//end
    private World world;
    private FrameBuffer buffer;
    private Object3D thing;
    private TextureManager tm = TextureManager.getInstance();

    public static void main(String[] args) throws Exception {
        new HelloWorldSoftware().loop();
    }

    public HelloWorldSoftware() throws Exception {
        world = new World();
        world.setAmbientLight(150, 150, 150);
        for (int i = 0; i < textures.length; ++i) {
            tm.addTexture(textures[i] + ".jpg", new Texture("res/" + thingName + "/"  + textures[i] + ".jpg"));
        }
        TextureInfo ti=new TextureInfo(tm.getTextureID(textures[0] + ".jpg"));
        thing = loadModel("res/"+ thingName + "/" + thingName + ".md2", thingScale);
        thing.setTexture(ti);
       
        world.addObject(thing);
        world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT,100);
        world.getCamera().lookAt(thing.getTransformedCenter());
    }

    private void loop() throws Exception {
        buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
        buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
        buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
        while (!org.lwjgl.opengl.Display.isCloseRequested()) {
            SimpleVector place = new SimpleVector();
            buffer.clear(java.awt.Color.BLUE);
            world.renderScene(buffer);
            world.draw(buffer);
            buffer.update();
            buffer.displayGLOnly();
            thing.rotateY(0.02f);
            thing.rotateX(0.01f);
           
            Thread.sleep(10);
        }
        buffer.dispose();
        System.exit(0);
    }

    private Object3D loadModel(String filename, float scale) {
        Object3D temp = Loader.loadMD2(filename, scale);
        temp.build();
        return temp;
    }
}

I hope one of you have some time to give me a bit of help.

//Michael
« Last Edit: June 16, 2009, 02:58:38 pm by cintix »
Faith is for the weak...

Offline cintix

  • byte
  • *
  • Posts: 28
    • View Profile
Re: Help regarding loading a MD2 model
« Reply #1 on: June 16, 2009, 06:28:36 pm »
Never mind... I just saw there was more then one model in the file i downloaded. :-(
I just had too load the right model. :-)
Faith is for the weak...