Exporting edges of ofMesh while in OF_PRIMITIVE_LINE_LOOP mode

Hi guys,

I need to export the edges of an ofMesh in order to do some processing on them.
The problem is that the ofMesh::save function just saves a bunch of points when the mesh is set to OF_PRIMITIVE_LINE_LOOP.
In processing there is wonderful library https://github.com/nervoussystem/OBJExport which also exports the edges of a mesh, you can use it in this way:

obj.beginDraw();
obj.beginShape();
obj.vertex(p1.x, p1.y);
obj.vertex(p2.x, p3.y);
// and so on..
obj.dispose();
obj.endDraw();

For example, this is a mesh exported using the nervous system library opened inside Houdini (3d software):

Then I can simply remove the geo and get what I want, the edges:

How could I achieve something like that in OF?
I’m open to addons, suggestion, sharing my code, etc…

Namasté

Hi! Might this help?

1 Like

Thanks @hamoid !
I’m going to check it, I don’t know if it could work since my mesh is built of just lines and not triangles.

Yeah maybe you need first a method to triangulate the shape.

Try searching for tesselate in the OF source code. No time to
check myself right now, but I think ofPath uses tesselate
to make a mesh out of the contours.

@hamoid Yep I’m gonna try the triangulation approach.
There is an ofTessellator object that is responsible for the tessellation of the ofPath but in the past it gave me some issues. Plus I don’t know how well it performs on 3d outlines but it’s definitely a start.
Thanks for reminding me!

I will also give a try to this repo https://github.com/mattdesl/extrude-polyline and see if I can do the same stuff in OF.

@zach Does this one https://github.com/ofZach/ofxTriangleMesh still work in 0.9.3?

I did a quick test using ofTessellator and it correctly triangulates the 2d mesh and exports it (still need to test against a 3d mesh).
This is the code:

ofPolyline line;

for (int i = 0; i < differential_line.lines_mesh.getNumVertices(); i++){
    ofPoint p = differential_line.lines_mesh.getVertex(i);
    line.addVertex(p);
}

line.close();

ofTessellator tessellator;
ofMesh exported_mesh;
tessellator.tessellateToMesh(line, OF_POLY_WINDING_ODD, exported_mesh, true);
exported_mesh.save("test_tessellator.ply");

However, the nervous obj exporter seems to just export one huge non triangulated face, which is waaaay better for what I need to do.
In this screenshot the left image was generated from OF using ofTessellator, the right one was created in processing using the nervous library. The numbers that you see are the id of each primitive (face).

This seems magic to me, how could something like that be achieved inside OF?

Could you study the syntax of the obj file created by the nervous library and imitate that with your own exporter? Does it have any triangles? Or just one shape with a ton of vertices?

1 Like

@hamoid That’s exactly what I plan to do next!
For now, I was just able to clean up the mesh inside Houdini, by removing the inside edges and just keep the border ones.