Fitting a polyline to a 3d mesh (contour)

Continuing the discussion from Smoothing polyline over several frames:

Dear all, dear @zach,

I am attempting to get the contour / outline of a 3d mesh and came across the very interesting discussion in the linked thread. I think the example code @Zach provided is very relevant, but I am not able to apply these techniques to a mesh and get a 2d outline.

My initial idea was to take a frontal projection of a mesh and then somehow take a (2d) outline of that.

Does anyone have any clues on how / whether this can be done somehow?

Many thanks!

Ok, thinking out loud here. How about using worldToScreen to get the screen position of each vertex in the mesh. Then use a 2D convex hull algorithm on the list of points to get the outline.

Thanks! that seems like an interesting approach.

A different idea I had is working in openGL directly and use front / back face culling in some way to achieve the same effect. Something like what they attempt here:

However, when I try to use functions like the following, nothing happens at all. Any mesh I draw just shows up as normal… I am not used to programming directly in OpenGL so maybe I am missing something simple?

glEnable(GL_CULL_FACE); glCullFace(GL_FRONT)

//go into wire mode
glPolygonMode(GL_BACK, GL_LINE); //wireframe mode
glEnable(GL_LINE_SMOOTH);
glLineWidth(5); //fat lines

The technique described there only gets you a ‘visual outline’ where the solution I decribed above gets you the actual vertices of the outline. In the thread title you spoke of a polyline, so I assumed you wanted the actual vertices. Or do you just want the visual effect?

Yes, you are right. Your method gives you the actual vertices - this offers much more flexibility.

At this point I am just experimenting with different approaches, also to test for real time performence etc. The OpenGL method I described above so far is not too impressive, I’ll give your method a try as well :smile: