简体   繁体   English

Android Mesh渲染问题

[英]Android Mesh Render issue

This time i'm having an issue with the actual rendering of my model. 这次我遇到了模型实际渲染的问题。 I can load it all through the Libgdx loadObj() function, and render it using GL10_Triangles, however i keep getting missing triangles in my model (it seems like only half the models are being rendered). 我可以通过Libgdx loadObj()函数加载它,并使用GL10_Triangles渲染它,但是我在模型中不断丢失三角形(似乎只有一半的模型被渲染)。 I've tried the old ObjLoad function (commented out) and also the different render styles but nothing seems to work. 我已经尝试了旧的ObjLoad功能(注释掉)以及不同的渲染样式,但似乎没有任何效果。

And yes I have checked the model in Blender and the model is complete without missing faces. 是的,我已经在Blender中检查了模型,模型完整而没有丢失面孔。

See the print screen below, and the code below that. 请参阅下面的打印屏幕,以及下面的代码。 Any help would be fantastic, it's very frustrating as i'm so close to getting this to work. 任何帮助都会非常棒,因为我非常接近这一点,所以非常令人沮丧。

打印屏幕 And here's the code. 这是代码。

public class LifeCycle implements ApplicationListener {

Mesh model;
private PerspectiveCamera camera;

public void create() {

    InputStream stream = null;
    camera = new PerspectiveCamera(45, 4, 4);
    try 
    {
        stream = Gdx.files.internal("Hammer/test_hammer.obj").read();
        //model = ModelLoaderOld.loadObj(stream);
        model = ObjLoader.loadObj(stream,true);
        stream.close();
    } 
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
    Gdx.gl10.glTranslatef(0.0f, 0.0f, -3.0f);
}

protected float rotateZ = 0.1f;
protected float increment = 0.1f;

public void render()
{
    Gdx.app.log("LifeCycle", "render()");
    Gdx.gl.glClearColor(0.0f, 0.0f, 0.5f, 1.0f);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    camera.update();
    camera.apply(Gdx.gl10);
    Gdx.gl10.glTranslatef(0.0f, 0.0f, -3.0f);
    Gdx.gl10.glRotatef(rotateZ, rotateZ, 5.0f, rotateZ);
    model.render(GL10.GL_TRIANGLES);

    rotateZ += increment;
    System.out.println(""+rotateZ);
}
}

This actually looks like the OBJ file stores quads instead of triangles, but your loading routine just reads them as triangles (just reads the first 3 index groups of a face). 这实际上看起来像OBJ文件存储四边形而不是三角形,但是你的加载例程只是将它们读作三角形(只读取一个面的前3个索引组)。 Whereas Blender might (and should) be smart enough to handle quads, your loader routine isn't. 虽然Blender可能(并且应该)足够智能来处理四边形,但是你的装载程序却不是。 So either write a better OBJ loader (but I guess this isn't your class), configure your OBJ loader to treat quads correctly (if possible), or export the model as triangles instead of quads (if possible). 所以要么写一个更好的OBJ加载器(但我想这不是你的类),配置你的OBJ加载器来正确处理四边形(如果可能的话),或者将模型导出为三角形而不是四边形(如果可能的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM