渲染3d .g3db模型时的空白屏幕[libgdx]

时间:2016-10-25 16:40:10

标签: libgdx blender 3d-model

我一直在尝试在屏幕上显示模型(来自Blender的简单UVSphere)。我首先将其导出为.fbx格式,然后使用gdx-conv-win32.exe转换为.g3db格式。到目前为止我有这个代码,但是它显示的是一个空白的黑屏...它只适用于本教程中的模型(.obj模型)https://xoppa.github.io/blog/loading-models-using-libgdx/

package com.mygdx.game.screens;

/.../ imports

public class GameScreen extends MenuScreens {

public Environment environment;
public PerspectiveCamera cam;
public CameraInputController camController;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;

AssetManager manager = new AssetManager();
public boolean loading;
public Array<ModelInstance> instances;

public GameScreen(ProjectSurvival game){
    super();
    this.game = game;

    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 20f, 20f, 20f));
    environment.add(new PointLight().set(1, 1, 1, 20, 20, 20, 500));
    instances = new Array<ModelInstance>();

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(1f, 1f, 1f);
    cam.lookAt(0,0,0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    manager = new AssetManager();
    manager.load("ship.g3db", Model.class);
    loading = true;
}

private void doneLoading() {
    Model test = manager.get("ship.g3db", Model.class);
    ModelInstance shipInstance = new ModelInstance(test);
    instances.add(shipInstance);
    loading = false;
}

@Override
public void show() {
}

@Override
public void render(float delta) {
    //super.render(delta);

    if (loading && manager.update()) {
        doneLoading();
        System.out.println("loaded");
    }
    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
}
@Override
public void resize(int width, int height) {
    super.resize(width, height);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
    super.dispose();
    modelBatch.dispose();
    model.dispose();
    instances.clear();
    manager.dispose();
}

}

还有其他几个类似的主题,但没有一个能解决我的问题...请帮助我!

编辑:

这是我的g3dj文件(我剪掉了部分内容因为它非常长):

{
"version": [  0,   1], 
"id": "", 
"meshes": [
    {
        "attributes": ["POSITION", "NORMAL", "TEXCOORD0"], 
        "vertices": [
            -0.724124,  0.035572, -0.598984, -0.742302, -0.159337, -0.650807,  0.028780,  0.420519, 
            -0.691568,  0.068115, -0.634070, -0.791498, -0.084201, -0.605335,  0.021021,  0.407816, 
            -0.694079,  0.034096, -0.634070, -0.878414,  0.254219, -0.404614,  0.026918,  0.405321, 
            // deleted (...)
            -0.846887, -0.041603, -0.403719, -0.887509, -0.132389, -0.441267,  0.051316,  0.489956, 
            -0.826199, -0.040587, -0.445113, -0.867977, -0.072359, -0.491256,  0.049283,  0.474874, 
            -0.803523, -0.039472, -0.485435, -0.859127, -0.022919, -0.511185,  0.047232,  0.459797
        ], 
        "parts": [
            {
                "id": "Mesh_part1", 
                "type": "TRIANGLES", 
                "indices": [
                      0,   1,   2,   1,   0,   3,   4,   2,   5,   2,   4,   0, 
                      2,   6,   7,   6,   2,   1,   5,   7,   8,   7,   5,   2, 
                      0,   9,   3,   3,   9,  10,   9,  11,  10,  11,   9,  12, 
                      9,   4,  13,   4,   9,   0,  12,  13,  14,  13,  12,   9, 
                     // deleted (...)
                     3610,  3613,  3614,  137,  3614,  3613,  3614,  137,  133,  3606,  3612,  3596, 
                     3612,  3606,  3613,  112,  3613,  3606,  3613,  112,  137,  3614,  3608,  3610, 
                     3608,  3614,  3615,  3615,  3539,  3608,  3539,  3615,  3543,  133,  3615,  3614, 
                     3615,  133,  134,  134,  3543,  3615,  3543,  134,  14
                ]
            }
        ]
    }
], 
"materials": [
    {
        "id": "Material.001", 
        "ambient": [ 0.200000,  0.200000,  0.200000], 
        "diffuse": [ 0.800000,  0.800000,  0.800000], 
        "emissive": [ 0.000000,  0.000000,  0.000000], 
        "opacity":  0.000000, 
        "specular": [ 0.200000,  0.200000,  0.200000], 
        "shininess":  20.000000
    }
], 
"nodes": [
    {
        "id": "Sphere", 
        "rotation": [-0.707107,  0.000000,  0.000000,  0.707107], 
        "scale": [ 100.000000,  100.000000,  100.000000], 
        "translation": [ 0.000000,  101.334976,  0.000000], 
        "parts": [
            {
                "meshpartid": "Mesh_part1", 
                "materialid": "Material.001", 
                "uvMapping": [[]]
            }
        ]
    }
], 
"animations": []

}

2 个答案:

答案 0 :(得分:0)

由于没有可接受的答案:

如@Xoppa所述,在您的文件中,将不透明度设置为零,在gd3j文件中将其设置为1.0000

"opacity":  0.000000

// TODO 1:在搅拌机中找到材料的特性

// TODO 2:添加到故障排除指南

答案 1 :(得分:0)

有同样的问题,但将 LWO(光波)对象转换为 g3db / g3dj。问题是当 LightWave 导出为 FBX 格式时,它不会添加有关纹理的信息(我实际上不确定 FBX 格式是否完全支持纹理?)。然后我切换到 .OBJ 导出,但我再次遇到了不支持 png 格式的纹理的问题。只有在使用 .jpg 纹理后它才开始工作。在将不透明度正确设置为 1 之后。对于纹理,它无法处理转换器将不透明度设置为 0。

相关问题