Android上的LibGDX 3D低fps

时间:2014-11-17 10:55:35

标签: java android performance libgdx

我刚开始学习使用libgdx渲染3D(使用Xoppa教程),并且在使用.G3DB对象作为android上的模型时遇到帧速率问题。

我从blender导入一个对象(我以前用fbx转换器转换为.g3db),这在桌面上工作正常(60fps)但在android上我得到5fps(我使用的是Nexus 5设备)。所以我尝试用相同的代码渲染一个立方体,然后我没有性能问题,它再次平滑运行(模型包含289个顶点)。

我在论坛上搜索但发现没有任何帮助我解决问题的方法。我的代码中的G3dModelLoader是一个问题吗?

有人可以帮帮我吗? 谢谢

N.B。 :对不起我的英文

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

1 个答案:

答案 0 :(得分:1)

转换为.g3dj后,我看到该文件很大,我以某种方式在一个.fbx中导出了几个对象......所以这是我的错误(该文件占用了15倍的空间并导致文件速度变慢)设备)