Build new mesh from clipping plane intersection vertices

I’m looking to add a new mesh built from points of intersection to achieve a “cross-section” like effect, similar to what can be found in the example here:

However given the sort of materials I am wanting to render, using a stencil does not seem compatible. I’m using a similar code base to the following example for fetching intersection points as seen here:

I have modified versions of the code for this functionality to try and generate a plane based on the points returned as can be seen in this example I put together:

The issue I am facing is using those vertices to create a new mesh to act as the “cap” on top of the clipped mesh. Everytime I try to plug these vertices into a mesh geometry all that is generated is a random array of triangles.

MAIN QUESTION: Is this sort of mesh building from intersection points possible? If so am I missing some form or processing or ordering on the received values?

Any help or pointing in the right direction would be greatly appreciated!

Many thanks.

There are two cases:

  • if the vertices are ordered along the perimeter of the cross section mesh, than you can build the mesh via shape or ear cut triangulation
  • if the vertices are not ordered, then you need additional info to build the mesh (e.g. about the object being cut, about the algorithm that produces the vertices, etc). Without such additional knowledge, it is impossible. Consider this example – the left image shows 5 points, how would you connect them in a mesh if you know nothing else about these points besides their coordinates? The next 4 images show some possible meshes.