Winding Order of Triangles from BRepTool::Triangulation

I'm dabbling with OCCT and wanted to test it with the Unity Game Engine.

I was able to get Box Mesh to appear, however it looks like the winding order of the triangles is the same no matter which way the normal vector of the face is.

The simple workaround is to render the mesh with a shader/material that renders on both sides.

Is this the expected behavior?  Or did I not correctly extract the triangulation?

If I did do it correctly, does Express Mesh take into account winding order?

Kirill Gavrilov's picture

The winding order of triangles is well-defined within OCCT - so that you may see that Solid objects are displayed with back face culling in OCCT 3D Viewer, and it allows defining different material for the front and back faces.
What confuses you is probably the fact that Poly_Triangulation is defined within TopoDS_TFace - so that it is shared between the Faces having different Orientation and Location. Therefore, displaying triangulation in 3D Viewer requires applying Face Orientation to triangle indexes (as well as Face Location to triangulation nodes).

Express Mesh is no different in this respect (triangle winding rule), but it gives interesting features for tuning triangulation - like triangle size limits and generation of quad-dominant mesh and others.
You may be also interested in CAD Processor in your research for advanced processing of complex CAD models for game engines:
https://www.opencascade.com/content/cad-processor

trevor.gronseth_156578's picture

Ok.  Bear with me.  The OCCT Library is vast!

If I use BRepPrimAPI_MakeBox class, I can get its Faces (via the TopExp_Explorer) in the form of TopoDS_Face object.  However, TopoDS_Face doesn't have an orientation.  Yet,  each Face of the Box has an orientation somewhere, I'm just not clear on how to access it from TopoDS_Face.

Thanks for the help.

Forum supervisor's picture

Hello Trevor,

If you wish to learn OCCT API faster, please, consider our remote and on-site training courses.

Please, do not hesitate to contact us for more information.

Best regards,

Forum supervisor

trevor.gronseth_156578's picture

I will.  Thank you.

Bhupendra Singh Nagra's picture

Hi Trevor. Can you let me know how did you integrate it in unity? Did you write a PInvoke based wrapper?