Daniel
Daniel

Reputation: 41

LibGDX 3D low fps on android

I just started to learn to render 3D with libgdx (with Xoppa tutorials), and got a problem with the framerate when using a .G3DB object as model on android.

I am importing an object from blender (that I previously converted to .g3db with fbx converter) which is working fine on desktop (60fps) but on android I get 5fps (I am using a Nexus 5 device). So I tried to render a cube instead with the same code, and then I had no performance problem and it runned smoothly again (the model contains 289 vertices).

I searched over the forum but found nothing that helped me to fix the problem. Is it a problem with the G3dModelLoader in my code?

Can anybody help me?
Thank you

N.B. : Sorry for my english

<!-- language-all: lang-java -->

private PerspectiveCamera camera;
private ModelBatch modelBatch;
private Model model;
private Model box;
private ModelInstance modelInstance;
private Environment environment;
private CameraInputController camController;
private ModelInstance boxInstance;

@Override
public void create() {
    camera = new PerspectiveCamera(40,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());

    camera.position.set(0f,-30f,0f);
    camera.lookAt(0f,0f,0f);
    camera.near = 0.1f;
    camera.far = 60.0f;
    camera.update();

    modelBatch = new ModelBatch();

    // Blender object
    UBJsonReader jsonReader = new UBJsonReader();
    G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
    model = modelLoader.loadModel(Gdx.files.getFileHandle("data/hill.g3db", FileType.Internal));
    modelInstance = new ModelInstance(model,0,0,0);

    // Cube object
    ModelBuilder modelBuilder = new ModelBuilder();
    box = modelBuilder.createBox(2f, 2f, 2f, new Material(ColorAttribute.createDiffuse(Color.BLUE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    boxInstance = new ModelInstance(box,0,0,0);

    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, -1f, -0.8f, -0.2f));

    camController = new CameraInputController(camera);
    camController.scrollFactor=-0.05f;
    camController.pinchZoomFactor=2f;
    Gdx.input.setInputProcessor(camController);
    camController.update();
}

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

@Override
public void render() {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(camera);
    modelBatch.render(modelInstance, environment);
    System.out.println(Gdx.graphics.getFramesPerSecond());
    modelBatch.end();
}

Upvotes: 3

Views: 786

Answers (1)

Daniel
Daniel

Reputation: 41

Well after converting to .g3dj I saw that the file was way to big, I had somehow exported several objects in one .fbx... so that was my mistake (the file took 15x more space and caused the slow down of the device)

Upvotes: 1

Related Questions