Correctly export all triangles in CW (or CCW)

The forums here are for Blender development. Questions and discussion about *using* Blender belong on blenderartists.org If your thread was moved here, you are probably in the wrong place.

Moderators: jesterKing, stiv

Post Reply
titovmaxim
Posts: 0
Joined: Sat Jul 20, 2013 11:06 am

Correctly export all triangles in CW (or CCW)

Post by titovmaxim »

Hi all. Got a trouble with exporting models from blender to .OBJ. After importing and using in the game engine some parts of the model are culled because of wrong vertices order.

The easy test to reproduce. Take some simple shape. Make a mirror. The material is one-sided, culling is switched on (for testing), the normals looks out of the model and freshly recalculated. Both things looks ok in blender. On export, one of two parts will have different windings (CW and CCW), so one of them will be broken in the game engine.

One method to fix it is to flip normals manually on the broken part. Then it will work in the engine, but will be broken in blender. And there is no easy test to know which part will be broken prior to import to the engine.

So the question is. Is there any script or exporter setting to arrange all triangles properly on export (according to their correctly set normals)? So we would have a correct model in blender and correct model for OpenGL with consistent winding? Seems to be 100% technically possible.

Have searched through web. Have not found any good robust solutions yet...

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

in blender, all normals should point outwards. If some normals are inwards after export, but other's are not, then i'm clueless. The only problem i experienced was with a custom file format that needed inverted normals. Reversing all face verts worked.
I'm sitting, waiting, wishing, building Blender in superstition...

afree10
Posts: 0
Joined: Sat Aug 24, 2013 3:14 pm

Post by afree10 »

I am getting the same problem with my OpenGL "engine".

Here is a blender file when exported has the issue.
https://docs.google.com/file/d/0Bxis5FP ... sp=sharing

I know my modelling skills need improving :)

Edit: also its to do with the actual face data, nothing to do with normals (since I didn't even export or import them).

Edit 2: It may be a problem with blenders triangle generation modifier (which from my very very quick glance of the obj exporter python code seems to be what blenders obj exporter uses).

I also turned off triangle generation from the obj exporter and used the blender triangulate modifier to triangulate my mesh, it still caused issues with my OpenGL culling.

The Beauty Subdivide option disabled and enabled dosen't change the situation.

afree10
Posts: 0
Joined: Sat Aug 24, 2013 3:14 pm

Post by afree10 »

Fixed: When I opened the blender properties window (key: n) I noticed that under display if I enabled blenders culling it generated the same issue I was having, so I replaced the offending faces and everything was fine.

Although this is still a tad annoying and could be considered an issue with blender (unless I did something like placed faces in the wrong order, it could be my fault).

Post Reply