0
\$\begingroup\$

I have written an obj parsing function and the result of his parsing can be drawn correctly. But if the uv is not generated by default by the modelling software, he will have problems with the uv. I looked at the obj file again and found something puzzling me. first,this is the obj file(the vn being deleted):

g default
v -2.211628 0.000000 2.211628
v 0.000000 0.000000 2.211628
v 2.211628 0.000000 2.211628
v -2.211628 0.000000 0.000000
v 0.000000 0.000000 0.000000
v 2.211628 0.000000 0.000000
v -2.211628 0.000000 -2.211628
v 0.000000 0.000000 -2.211628
v 2.211628 0.000000 -2.211628
vt 0.098901 0.197802
vt 0.401099 0.197802
vt 0.959707 0.080586
vt 0.098901 0.500000
vt 0.540293 0.500000
vt 0.959707 0.500000
vt 0.098901 0.802198
vt 0.540293 0.919414
vt 0.959707 0.919414
vt 0.401099 0.500000
vt 0.401099 0.802198
vt 0.540293 0.080586
s 1
g pPlane4
usemtl initialShadingGroup
f 1/1/1 2/2/2 5/10/3 4/4/4
f 2/12/2 3/3/5 6/6/6 5/5/3
f 4/4/4 5/10/3 8/11/7 7/7/8
f 5/5/3 6/6/6 9/9/9 8/8/7

I labeled these data on their corresponding images enter image description here

enter image description here

the face1 is 1/1/n 2/2/n 5/10/n,it's mean that the triangle is v1,v2,v5 and the uv is t1,t2,t10, so why the v125 map to the green part?Isn't it supposed to be the brown part? It doesn't look like this is simply flipping the uv over. This may have something to do with the left and right hand coordinate system. uv's are created in maya and rendered in the Unreal engine. below is the image in my rendering,The problem seems complicated enough, if I need the parse code I will upload it, thanks enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The Wavefront OBJ you are using has quads which presumably you need to convert to triangles. It's likely related to that code in your reader in terms of the exact winding you are using.

// Convert polygons to triangles
uint32_t i0 = faceIndex[0];
uint32_t i1 = faceIndex[1];

for (size_t j = 2; j < iFace; ++j)
{
    uint32_t index = faceIndex[j];
    indices.emplace_back(i0);
    if (ccw)
    {
        indices.emplace_back(i1);
        indices.emplace_back(index);
    }
    else
    {
        indices.emplace_back(index);
        indices.emplace_back(i1);
    }

    i1 = index;
}

In addition as you've hinted to yourself, the winding and view-orientation of the modeler does not necessarily match your rendering setup. This is why many exporters have options to flip the U (i.e. U = 1 - u), flip V (i.e. V = 1 - v), and/or flip the Z (i.e. Z = -z).

See WaveFrontReader.h for some working code you can compare against. It handles some behavior as well like negative index values you should be aware of for your own reader.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .