在libgdx中导入扩展名为md2的对象

时间:2013-12-03 19:12:07

标签: java eclipse libgdx

我是java游戏编程的新手我想导入一个md2对象我用这个tuto http://code.google.com/p/libgdx-users/wiki/MD2_Keyframe_Animation 但问题是我无法从类KeyframedModelViewer实例化一个实例这是我的代码

package com.ELISA.ELISAgame.Screens;
import com.ELISA.ELISAgame.ELISA;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.ModelLoader;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.Material;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
/*import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;*/
import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;


public class Game implements ApplicationListener, Screen {


ELISA game;
PerspectiveCamera cam;
CameraInputController camController;
ModelBatch modelBatch;
ModelLoader loader;
AssetManager assets;
Model model;
Material material;
ModelInstance instance;

public Game(ELISA game) {
    this.game = game;


}

public void create() {


}

@Override
public void render(float delta) {
    camController.update();
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    modelBatch.begin(cam);
    modelBatch.render(instance);

    modelBatch.end();

}

@Override
public void resize(int width, int height) {


}

@Override
public void show() {

    //new JoglApplication(new KeyframedModelViewer("data/antigene.md2", "data/antigene.png"), "KeframedModel Viewer", 800, 480, false);
    modelBatch = new ModelBatch();
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
    cam.position.set(0f, 6f, 11.5f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.8f;
    cam.far = 300f;
    cam.update();

    loader = new ObjLoader();
     //model = loader.loadModel(Gdx.files.internal("data/labo.obj"));
     instance = new ModelInstance(model);
     Material material = new Material("material", new TextureAttribute(texture, 0, "s_tex"));
     model.setMaterial(material);
    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

}

@Override
public void hide() {


}

@Override
public void pause() {


}

@Override
public void resume() {


}

@Override
public void dispose() {
    modelBatch.dispose();
    model.dispose();


}

}

1 个答案:

答案 0 :(得分:0)

那个维基,“libgdx-users”非常过时。目前不支持MD2,这就是现在处理3d动画的方式:

https://github.com/libgdx/libgdx/wiki/3D-animations-and-skinning

“当使用fbx-conv https://github.com/libgdx/fbx-conv将模型从FBX转换为G3DB / G3DJ时,动画会自动转换。就像FBX一样,G3DB / G3DJ文件可以在一个文件中包含多个动画应用于源FBX文件中不存在的节点的动画将不会被转换。因此,请确保在导出到FBX时选择所有节点和动画。“