1
votes

I'm using libGdx 1.9.6 and I've got an issue. I've searched multiple forums, read various tutorials but nothing fits. I've created a simple cube in blender, textured it and export it to FBX (using fbx-conv). I've also downloaded the BDX-Blender-Exporter. I've tested Blender 2.69 and 2.76b without any changes to the result.

The model is loaded and shown :

blended cube

If I change the background color to (0,0,0,0) or (0,0,0,1) then only a black screen appears.

Here's the code (libGDX 1.9.6, Android-Studio 2.3.3)

public class modelloader implements ApplicationListener {
private PerspectiveCamera camera;
private ModelBatch modelBatch;
private Model model;
private ModelInstance modelInstance;
private Environment environment;
private CameraInputController camController;

private AssetManager as;

@Override
public void create() {

    camera = new PerspectiveCamera(
            75,
            Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());

    camera.position.set(0f,0f,7f);
    camera.lookAt(0f,0f,0f);

    camera.near = 0.1f;
    camera.far = 300.0f;

    modelBatch = new ModelBatch();

    as = new AssetManager();
    as.load("moon.g3db",Model.class);
    as.finishLoading();
    model = as.get("moon.g3db",Model.class);


    model.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

    modelInstance = new ModelInstance(model);

    modelInstance.transform.rotate(1, 0, 0, 0);
    modelInstance.transform.translate(0, 0, -2);
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.8f, 0.3f, 1f));
    camController = new CameraInputController(camera);
    camController.forwardTarget = true;
    Gdx.input.setInputProcessor(camController);
}

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

@Override
public void render() {
    camController.update();
    Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl20.glClearColor(1,1,1,0);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    camera.update(true);

    modelBatch.begin(camera);
    modelBatch.render(modelInstance, environment);
    modelBatch.end();

}

The model is also only shown when the line

model.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

exists.

Here's the blender file :

cube.blend

Where could be the problem?

1
edit : wrong link to picture fixedCptnRoughnight
Without model.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));] it looks like this : i.imgur.com/drNer46.pngCptnRoughnight
Assuming your model is UV unwrapped and the texture is present, have you tried this: stackoverflow.com/questions/19112349/… Also look at the OP in this link and Gdx.gl20 functions that he enableskacpr
Yes, I've also read this thread. Doesn't matter with or without these Gdx.gl20 - functions. The texture blends with the background color. I've already tried to modify my model in blender, but without success.CptnRoughnight
Sounds like this: github.com/libgdx/libgdx/wiki/… : Also, it is quite common that the materials from Blender export with opacity set to Zero. If you notice your model is not being rendered. Go to the Material in Blender, and below "Transparency" set its Alpha to the desired one (usually 1, for full opacity).Xoppa

1 Answers

1
votes

Holy mackerel, it was the texture file... it was 1024x1024 png... but somehow corruptet... once opened and resaved and all works.... countless hours and this is the only thing I've not checked... Thanks for the help guys! –