Android Mesh Render issue

江枫思渺然 提交于 2019-12-12 02:29:05

问题


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). I've tried the old ObjLoad function (commented out) and also the different render styles but nothing seems to work.

And yes I have checked the model in Blender and the model is complete without missing faces.

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

回答1:


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). Whereas Blender might (and should) be smart enough to handle quads, your loader routine isn't. 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).



来源:https://stackoverflow.com/questions/9019669/android-mesh-render-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!