1

Let me preface this by saying I’m fairly new at OpenGL ES and OpenGL in general.

I’ve got a model object that our 3D guy exported from zBrush. It doesn’t have any normals in the .obj file, and I think that’s what’s causing this behavior. I’m using obj2opengl to create a .h file containing the vertices and texture coordinates, then importing those and rendering. Here’s what the import looks like:

glGenBuffers(1, &mushroomVertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, mushroomVertexBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(mushroom01b_LowVerts), mushroom01b_LowVerts, GL_STATIC_DRAW);

glGenBuffers(1, &mushroomTextureBufferID);
glBindBuffer(GL_ARRAY_BUFFER, mushroomTextureBufferID);
glBufferData(GL_ARRAY_BUFFER, sizeof(mushroom01b_LowTexCoords), mushroom01b_LowTexCoords, GL_STATIC_DRAW);

When it’s time to draw the object, here’s the code I’m using:

glBindBuffer(GL_ARRAY_BUFFER, mushroomVertexBufferID);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, NULL);

glBindBuffer(GL_ARRAY_BUFFER, mushroomTextureBufferID);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, NULL);

self.effect.texture2d0.name = _mushroomTextureInfo.name;
self.effect.texture2d0.target = _mushroomTextureInfo.target;

[self.effect prepareToDraw];

glDrawArrays(GL_TRIANGLES, 0, mushroom01b_LowNumVerts);

This works, and for models where I’ve opened them in Blender, fixed the normals, and re-exported as OBJ with normals (adding code above for a third array buffer), it looks pretty good. But if I don’t modify the exported-from-zBrush OBJ at all, here’s what I get:

Messed up normals

Now, this is with face culling enabled with glEnable(GL_CULL_FACE);. If I don’t enable it, the model seems to be rendering inside-out.

Clearly the zBrush export is messed up somehow. My question is how to fix it.

4

2 回答 2

4

该模型未进行三角剖分。让您的艺术家在输出中选中该框。

我去为你查看了脚本文件。

假设四边形是

a -- c
|    |
|    |
b -- d

在 .pl 你会发现

矩形 => 第二个三角形

    if($5 != "")
    {
        @d = split('/', $5);
        $va_idx[$numFaces] = $a[0]-1;
        $ta_idx[$numFaces] = $a[1]-1;
        $na_idx[$numFaces] = $a[2]-1;

        $vb_idx[$numFaces] = $d[0]-1;
        $tb_idx[$numFaces] = $d[1]-1;
        $nb_idx[$numFaces] = $d[2]-1;

        $vc_idx[$numFaces] = $c[0]-1;
        $tc_idx[$numFaces] = $c[1]-1;
        $nc_idx[$numFaces] = $c[2]-1;

        $face_line[$numFaces] = $line;

        $numFaces++;
    }

尝试重新排序以查看是否需要反转第二个三角形的缠绕顺序

矩形 => 第二个三角形

    if($5 != "")
    {
        @d = split('/', $5);
        $va_idx[$numFaces] = $a[0]-1;
        $ta_idx[$numFaces] = $a[1]-1;
        $na_idx[$numFaces] = $a[2]-1;

                    $vb_idx[$numFaces] = $c[0]-1;
        $tb_idx[$numFaces] = $c[1]-1;
        $nb_idx[$numFaces] = $c[2]-1;

        $vc_idx[$numFaces] = $d[0]-1;
        $tc_idx[$numFaces] = $d[1]-1;
        $nc_idx[$numFaces] = $d[2]-1;



        $face_line[$numFaces] = $line;

        $numFaces++;
    }
于 2013-07-03T22:45:02.867 回答
1

尝试将剔除从顺时针更改为逆时针,如果您的工具尊重 obj 中的方向并且 zBrush 导出尊重它,这可能会有所帮助。

于 2013-07-03T20:59:07.063 回答