I want to split a couple of simple 2d forms into tri meshes. The meshes should conserve the original geometry and ideally I'd like a possibility to influence refinement vs. tris count.

I have the 2d forms available as images (svg, png) and am happy to convert to something else if necessary (STL, ...?). Output should ideally be an IBO (index buffer containing points and triangle index numbers), but I will settle for something I can convert into that. I don't need a library, a manual process is fine, but I'm not above using one, if it gets the job done.

I found a number of possible solutions to this (gmsh, netgen, ... and more) but many of those seem too much (would require high time investment to learn) for my relatively simple problem.

I am moderately proficient in python, blender and common linux software and am happy to come up with a small script to solve this, but don't want to dive deep into e.g. GL in order to solve this - hence my question: What is the easiest workflow to generate a trimesh from a svg or png?

This feels like a "common" issue, but I'm having a bit of hard time to find a solution with good effort/result ratio (maybe my google-fu is broken).

  • $\begingroup$ Triangle is easy to use (if you're comfortable with calling command-line programs) and generates high-quality triangulations in 2D. $\endgroup$
    – user106
    Commented Jun 29, 2019 at 16:58
  • $\begingroup$ If you need something quick and dirty to bolt in look up ear clipping. Though dicretisizing a random svg is not so easy so find a tool that does this. $\endgroup$
    – joojaa
    Commented Jul 2, 2019 at 23:19
  • $\begingroup$ Triangle looks exactly like it provides the needed control, but there is no fast and easy way to use it with svg files - need to convert it to a special triangle file format first - probably with a separate script. $\endgroup$ Commented Jul 3, 2019 at 8:09

1 Answer 1


The fastest and easiest way to do this is using blender. Simply import the svg (supported out of the box) into blender. The svg will be imported as a "curve"-type geometry. Optionally do some clean up/refinement. The curves can then be converted to a mesh. The mesh defaults to a trimesh. Voila - svg to trimesh in a couple of seconds.

Mesh refinement is not very fine-grained, but there is some measure of control via the "beauty-fill", "subdivide" and "triangulate" as well as "merge vertices by distance" tools from within blender.

The IBO (vertices + triangle vertex indices) can then be extracted using a short python script:

import bpy
obdata = bpy.context.object.data # selected object
for v in obdata.vertices:
    fh.write('({}, {}),\n'.format(v.co.x, v.co.y))
for f in obdata.polygons:
    for v in f.vertices:
        print('{} '.format(v))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.