LibGDX 3D with low fps on Android

I just started learning how to render 3D with libgdx (with Xoppa tutorials) and got a frame rate issue when using a .G3DB object as a model on Android.

I import an object from blender (which I previously converted to .g3db with fbx converter), which works fine on desktop (60fps), but on Android I get 5fps (I am using Nexus 5 device). So I tried to display the cube with the same code, and then I had no performance issues and it ran again (the model contains 289 vertices).

I searched through the forum but couldn't find anything that helped me solve the problem. Is this a problem with the G3dModelLoader in my code?

Can anyone help me?
Thanks you

NB: 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();
}

      

+3


source to share


1 answer


After converting to .g3dj I saw that the file was big, I somehow exported multiple objects into one .fbx ... so it was my fault (the file took 15 times more space and caused the device to slow down)



+1


source







All Articles