libGdx - 试图加载使用libgdx.g3d OBJ模型时黑屏 [英] libGdx--Blank black screen when trying to load obj models using libgdx.g3d

查看:457
本文介绍了libGdx - 试图加载使用libgdx.g3d OBJ模型时黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图加载并使用libgdx渲染.OBJ模型时,我什么也没有,一个黑色的屏幕。
我曾尝试不同的模式我已经试过装.g3db文件,而不是OBJ文件,并拿出了同样的结果(.OBJ格式使用搅拌机出口)。没有呈现在屏幕上,但我的glClearColor(和黑色以外是我试过的东西,看看我的模型渲染纯黑色)我拥有所有正确加载一个obj文件(skeleton.mtl,skeleton.obj,质感的资产。 PNG),我敢肯定,我的code做他们的东西,因为如果我删除说了,texture.png,我得到一个错误说,它不能找到资产。所以,在渲染时,为什么我得到什么?我想知道为什么发生这种情况。这里是我的code:

 公共无效显示(){
    modelBatch =新ModelBatch();
    环境=新环境();
    environment.set(新ColorAttribute(ColorAttribute.AmbientLight,0.4f,0.4f,0.4f,1F));
    environment.add(新的平行光()集(0.8f,0.8f,0.8f,-1f,-0.8​​f,-0.2f));    凸轮=新PerspectiveCamera(67,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
    cam.position.set(1F,1F,1F);
    cam.lookAt(0,0,0);
    cam.near = 0.1F;
    cam.far = 300F;
    cam.update();
    ModelLoader装载机=新ObjLoader();
    模型= loader.loadModel(Gdx.files.internal(模型/ skeleton.obj));
    例如=新ModelInstance(模型);    camController =新CameraInputController(凸轮);
    Gdx.input.setInputProcessor(camController);    ModelLoader装载机=新ObjLoader();
    模型= loader.loadModel(Gdx.files.internal(模型/ skeleton.obj));
    例如=新ModelInstance(模型);    camController =新CameraInputController(凸轮);
    Gdx.input.setInputProcessor(camController);

然后我的渲染循环:

  @覆盖
    公共无效渲染(浮动三角洲){
    Gdx.gl.glClearColor(0,0,0,1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glViewport(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());    camController.update();    modelBatch.begin(凸轮);
    modelBatch.render(例如,环境);
    modelBatch.end();
}


解决方案

  cam.position.set(1F,1F,1F);
cam.lookAt(0,0,0);
cam.near = 0.1F;

您相机的方式在原点附近,所以你的对象可能太大,相机可能是内,所以它不会被渲染。

另外,你可能导出你的对象以零不透明度:
<一href=\"https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX#wiki-troubleshooting-missing-textures\" rel=\"nofollow\">https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX#wiki-troubleshooting-missing-textures


  

另外,这是很常见的,从搅拌机的材料与不透明度设置为零出口。如果你发现你的模式不被渲染。转到搅拌机材质,低于透明度设置其阿尔法所需的一种(通常为1,对于完全不透明)。


I get nothing but a black screen when trying to load and render an .obj model using libgdx. I have tried different models (exporting using blender in .obj format) I've tried loading .g3db files instead of obj files and come up with the same result. Nothing renders onscreen but my glClearColor (and yes I've tried something other than black to see if my model was rendering pure black) I have all the assets loading correctly for an .obj file (skeleton.mtl, skeleton.obj, texture.png) and I'm sure my code is doing something with them because if I remove say, the texture.png, I get an error saying it cannot find the asset. So why do I get NOTHING when rendering? I would like to understand why this is happening. Here is my code:

    public void show() {
    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.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(1f, 1f, 1f);
    cam.lookAt(0,0,0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    ModelLoader loader = new ObjLoader();
    model = loader.loadModel(Gdx.files.internal("models/skeleton.obj"));
    instance = new ModelInstance(model);

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

    ModelLoader loader = new ObjLoader();
    model = loader.loadModel(Gdx.files.internal("models/skeleton.obj"));
    instance = new ModelInstance(model);

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

Then my Render loop:

@Override
    public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    camController.update();

    modelBatch.begin(cam);
    modelBatch.render(instance, environment);
    modelBatch.end();
}

解决方案

cam.position.set(1f, 1f, 1f);
cam.lookAt(0,0,0);
cam.near = 0.1f;

Your camera is way to near the origin, so your object may be too big and the camera may be "inside" it, so it wont be rendered.

Also, you probably exported your object with zero opacity: https://github.com/libgdx/libgdx/wiki/Importing-Blender-models-in-LibGDX#wiki-troubleshooting-missing-textures

Also, it is quite common that the materials from Blender export with opacity set to Zero. If you notice your model is not being rendered. Go to the Material in Blender, and below "Transparency" set its Alpha to the desired one (usually 1, for full opacity).

这篇关于libGdx - 试图加载使用libgdx.g3d OBJ模型时黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆