<p>The fastest and easiest way to do this is using <a href="https://blender.org" rel="nofollow noreferrer">blender</a>. 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.</p>

<p>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.</p>

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

<pre><code>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))
</code></pre>

CC BY-SA 4.0
2019-07-03T08:02:02.763Z
2019-07-03T08:02:02.763Z
squarespiral
<p>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.</p>

<p>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.</p>

<p>I found a number of possible solutions to this (gmsh, netgen, ... <a href="https://stackoverflow.com/questions/4882993/mesh-generation-from-points-with-x-y-and-z-coordinates">and more</a>) but many of those seem too much (would require high time investment to learn) for my relatively simple problem.</p>

<p>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: <strong>What is the easiest workflow to generate a trimesh from a svg or png?</strong></p>

<p>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).</p>

CC BY-SA 4.0
2019-07-02T23:19:09.030Z
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.
joojaa
CC BY-SA 4.0
2019-07-03T08:09:17.757Z
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.
squarespiral
<triangulation>
How to triangulate a simple 2d surface to generate a constrained surface trimesh
squarespiral
# How to triangulate a simple 2d surface to generate a constrained surface trimesh

(Asked by: username_0 on 2019-06-29)

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](https://stackoverflow.com/questions/4882993/mesh-generation-from-points-with-x-y-and-z-coordinates)) 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).

**Tags:** triangulation

> **Comments:**
> **username_1**: 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.  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_0 on 2019-07-03. Score: 0 | Accepted answer

The fastest and easiest way to do this is using [blender](https://blender.org). 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))

```


---

