Róbert Nagy
Róbert Nagy

Reputation: 7632

Model loading error in libGDX

I downloaded a table model from : archive3d, converted the .3ds model using blender to .fbx and using fbx-converter, provided by libGDX, to a .g3db format model. I included all the textures with the model in the assets folder.

Here is my code:

`@Override
    public void create() {
        camera = new PerspectiveCamera(75, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        camera.position.set(0f, 0f, 2f);
        camera.lookAt(0f, 0f, 0f);
        camera.near = 0.1f;
        camera.far = 300f;`

batch = new ModelBatch();

UBJsonReader jsonReader = new UBJsonReader();
G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
model = modelLoader.loadModel(Gdx.files.internal("table.g3db"));
modelInstance = new ModelInstance(model);

environment = new com.badlogic.gdx.graphics.g3d.Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1f));

@Override
    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        camera.update();

        batch.begin(camera);
        batch.render(modelInstance, environment);
        batch.end();
    }

I get only a black blank screen, without no errors.

Upvotes: 2

Views: 1136

Answers (3)

zrathaen
zrathaen

Reputation: 1

Too many vertices. I believe that signed short int is used what implies 32k limit. The models you provided link to are pretty big so if you just converted the model without first optimizing it is going to be way too big.

Upvotes: 0

11mad11
11mad11

Reputation: 53

check if when you use fbx-conv check if you have a warning about having too many vertices. Check if all material file and image that your model use are compatible with libgx.

Upvotes: 0

Xoppa
Xoppa

Reputation: 8113

First change your clear color to something different than black. So you can verify whether your model is not being rendered (e.g. because it is not visible) or whether your model has a black material (e.g. missing textures or incorrect normals).

Gdx.gl.glClearColor(0.5, 0.2, 0.6, 1);

Next remove the environment variable. No need to apply lights when it doesn't even render without them.

If the problem still exists then follow this tutorial. Make sure to understand it, including the CameraInputController part at the bottom. Then add the CameraInputController to your application so you can move the camera around, zoom in and out, etc. Also fix your camera's near and far plane. 0.1f for the near plane is too close to zero which might cause issues, instead set it to at least 1f. Your far plane is set to 300f units, so if your model is bigger than that you won't see it (entirely). For testing set it to 10000f or something (don't forget to reduce it afterwards).

In most cases the problem is caused by a too big or misplaced model. You should be able to see and fix that in Blender as well. For testing you can also scale down the model in code:

modelInstance.transform.scale(0.05f, 0.05f, 0.05f);

Check this wiki page for more tips on exporting your model correctly. E.g. your textures might not be correctly applied in Blender or your vertex winding might be incorrect causing the wrong face culling.

If all that doesn't help then verify that your code does work with some other model (e.g. the ones used in the libgdx tests or in this tutorial). Then convert your model to a g3dj file open it with a text editor and inspect it for issues.

Upvotes: 1

Related Questions