1
votes

Just a heads up, I'm really new to this so sorry if my question is unclear:

I've made a 3D model using Blender and as the material for my model I just used a mix shader with glossy and diffuse textures. I'm trying to get it to show up correctly in LibGDX. When I render the model in Blender, here's what it looks like: enter image description here

I then export the file to fbx, then use fbx-conv to convert it to a .g3db file, but when I try to load the model in my code(taken from http://blog.xoppa.com/loading-models-using-libgdx/):

public class Basic3DTest implements ApplicationListener {
PerspectiveCamera cam;
public CameraInputController camController;
public Environment environment;
public ModelInstance instance;
public ModelBatch modelBatch;
public AssetManager assets;
public Array<ModelInstance> instances = new Array<ModelInstance>();
public boolean loading;

@Override
public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f,
            0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -.5f,
            -0.6f, -1f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);
    assets = new AssetManager();
    assets.load("data/Space Game/ModelData/blinky.g3db", Model.class);
    loading = true;
}

  private void doneLoading() {
        Model ship = assets.get("data/Space Game/ModelData/blinky.g3db", Model.class);
        ModelInstance shipInstance = new ModelInstance(ship); 
        instances.add(shipInstance);
        loading = false;
    }

@Override
public void dispose() {
    modelBatch.dispose();
    instances.clear();
    assets.dispose();
}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
   public void render () {
    if (loading && assets.update())
        doneLoading();
    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
}

@Override
public void resize(int arg0, int arg1) {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

}

Here's what shows up: enter image description here

Any idea what could be wrong? Thanks a bunch in advance.

2

2 Answers

0
votes

You should explicitly set shader while rendering. For information about using a shader in libgdx, please refer to https://github.com/libgdx/libgdx/wiki/Shaders

0
votes
'AssetManager assets = new AssetManager();'
'assets.load("myFile.g3db", Model.class);'
'assets.finishLoading();'
'Model myModel = assets.get("myFile.g3db", Model.class);'

'ModelInstance myInstance = new ModelInstance(myModel);'
'Texture myTexture = new Texture(Gdx.files.internal("badlogic.png"));'
'Material myMaterial = new Material(TextureAttribute.createDiffuse(myTexture));'
'NodePart nodePart = myModel.nodes.get(0).parts.get(0);'
'nodePart.material.set(myMaterial);

/* All of this must be in create method */