Manually construct mesh quad faces?

Hi everybody!

I hope you’re all doing fine! :mask:

I have an std::vector<glm::vec3> that contains the 8 three-dimensional corner points of a distorted box.
I now want to construct an ofMesh from the corner points, which would be composed by 6 planar quad faces.

I’m familiar with meshes and their underlying data structures, but in oF I’m kinda lost on how to manually construct quad faces?

Vertices are usually a flat array of three-dimensional points, and faces a collection of vertex indices per face. However, here in oF the faces also seem to be a flat collection of indices? How, can there be a distinction between tri and quad faces then?

Any ideas? Thanks. :slightly_smiling_face:

As a test, I’ve exported a simple three-dimensional cube with quad faces from Blender, and it seems to get triangulated when importing the OBJ with ofxAssimpModelLoader. At least, it’s drawn with a tri wireframe.



To make sure that the mesh cube wasn’t triangulated during the export to OBJ from Blender, I’ve also imported it into Rhino, which is a CAD tool for architects and designers, and it displays the cube correctly with quad face:

Does openFrameworks simply not understand quad meshes? Or is there a workaround?
Can somebody please shine some light on what is going on here?

Why doesn’t for instance GL_QUADS - even mentioned in the Graphics chapter on meshes in ofBook - seem to be available?

It’s kind of impracticable for me to construct triangulated meshes, since I want to be able to export and edit them in poly-modelling software. Tri meshes are harder to read topology-wise and impractical to edit manually. I would have to run each mesh through some sort of third-party quad-remesher first, which kinda defeats the process of using procedural scripts in the first place.

Any suggestion is well come!

Hi @diff-arch,
OF doesn’t support Quads anymore because it has been deprecated in newer versions of OpenGL.
Do you want to manipulate the vertices in OF? It should be the same vertices, just different indices (6 for two triangles and 4 for quads). If you want to import into OF, manipulate the vertices and then export to Blender, OF will output a triangle mesh, but seems like it should be pretty straightforward to convert back to faces in Blender (


Not really! What I have is a collection of objects which define distorted boxes with planar faces, defined by 8 corner vertices or points. It’s all custom code and data for now. I basically use openFrameworks only for windowing and previewing geometry.
Currently I visualize the twisted boxes with lines, kinda like a skeletal, wireframe display.
I guess I kinda generate the vertices from scratch, if that makes sense. 8 points defining a box.

Yes, the export was what I was about to test. I was fine with the display showing tris, but was hoping that the export would be quads. That’s really unfortunate, it exporting tri meshes, I mean.
I guess I need to come up with my own OBJ exporter and skip the oF meshing step.

Yes, but the results are oftentimes unpredictable and for hundreds of OBJ files, it seems kinda overkill, even with a Python routine inside Blender. My goal is not really to export to Blender, but rather to export clean, quad meshes, without the need to do any post-processing.

Thanks for your reply. Much appreciated!!

Ah ok, now I understand better. If it’s imported as triangles, for export, can you try building the quads?

for( int i = 0; i < mesh.getNumIndices(); i+= 6 ) {
   // first triangle 
   int triIndex0 = i+0;
   int triIndex1 = i+1;
   int triIndex2 = i+2;
   // second triangle 
   int tri2Index0 = i+3;
   int tri2Index1 = i+4;
   int tri2Index2 = i+5;
   // depending on winding order, may take a few attempts to find the correct quad indices
   int quadIndex0 = triIndex0;
   int quadIndex1 = triIndex1;
   int quadIndex2 = tri2Index1;
   int quadIndex3 = tri2Index2;

You could also use this to build a wireframe mesh for drawing if you didn’t want it to draw triangles.

1 Like

Thanks you.