How to divide a non-planar polygon into triangles?

Im working on a importer for model-files where you have not only triangles but non-planar polygons defined by the vertices which obviously cant be loaded as tris directly.

So how do I make tris of them?

Are you importing to .egg? Because I believe .egg supports triangulating polygons.

If not, you’ll have to triangulate yourself. The easiest way is to start at the first vertex and fan triangles to all of the other vertices. A better-looking way is to use a tristrip representing the polygon.
There are plenty of results online for “triangulation”.

Blender has triangulate option.

You can either look at blenders function and rewrite it in panda, or you can make importer for blender.

there even is panda3d.org/reference/python … iangulator but it only works on planar polys.
i propably just need a way to project the vertices to 2d so that the poly wouldnt overlap…

It is very easy to triangulate a non-planar polygon though, using the methods I described above, for example.

If you’re using the egg library to create your structures, you can use EggPolygon::triangulate_info() or triangulate_in_place().

Of course, triangulating a non-planar polygon is ambiguous. The results differ depending on how you decide to do it. Usually, it’s best to ask the artist not to create these in the first place, but some modeling tools don’t do a good job of detecting and avoiding them.

David