Export as Obj, flipping normals?

I wrote a little obj exporter. Works fine. Problem is that the export is mirrored because of the left handed vs right handed coordinate issue.

Okay, making the x direction of the mesh inverted by *-1 mirrors it back.

obj.WriteLine("v {0} {1} {2}",-t.x,t.y,t.z);

But then the normals are flipped. So i need to flip the normals too.

I had then a look at the available Obj exporter in the Unify wiki. There the normals gets inverted by minus 1 too. So i wrote: obj.WriteLine("vn {0} {1} {2}",-wv.x,wv.y,wv.z);

Didn’t help. The normals are still flipped.

And that’s where i am stuck at the moment. My code looks basically equal to the code in the wiki as far as i can tell. Only difference is that my code is JS while the code in the Wiki is C#. But this shouldn’t be the problem. And my version arrives with flipped normals. So i obviously miss something important. I do something wrong.

Could somebody please give me a hint where i am wrong here? How do i flip my normals so that my faces points upwards again?

Attached is a very reduced example file. Just the export code at an object. The created obj file can be found at C

1724915–108769–exportobjproblem.rar (107 KB)

Haha, this was again one of those glorious moments where the solution jumped into my face a few seconds after creating the thread. I need to change the order of the index too to alter the triangle winding. Then it works like charm. Gets even mentioned in the exporter script in the Wiki.

Means i need to turn this:

obj.WriteLine(“f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n”, triangles*+1, triangles[i+1]+1, triangles[i+2]+1);*
into this:
obj.WriteLine(“f {1}/{1}/{1} {0}/{0}/{0} {2}/{2}/{2}\n”, triangles*+1, triangles[i+1]+1, triangles[i+2]+1);*
Thanks for help and listening :slight_smile:

1 Like

You save my day, magic!

many thanks from 2021)