Frage

I need to convert text (string+font) into mesh (vertices, indices, triangles etc), but I don't need to draw anything. I'll just get a string from one API and push it as vertices & indices to another. What's the simplest/easiest/best way of doing this? Font metrics and text placing are of course available and no other transforms are needed.

I'm currently working with VC++. However, any kind of OpenSource (C/C++, C#, VB,...) and "non-open but free" COM/.NET -libraries would be great.

I've heard of FreeType. Does it answer my prayers or is there something even better?

EDIT: As Nico Schertler commented, there seems to be Mesh.TextFromFont -function in DirectX -libs that probably does the trick. Thank you Nico! I'll update when I have time to test this in practise.

War es hilfreich?

Lösung

Mesh.TextFromFont sounded good but it didn't save the day since I couldn't figure out how to get the actual point/triangle data from the mesh -object.

But then I found this. In this project, GraphicsPath is used to create a point-path from a glyph. Then the points are coverted into Polygons and the polygons are then tesselated into triangles using Poly2Tri.

A quick browse through the source code and with some small modifications and code stripping I ended up with a nice .NET -dll with one simple static function that does everything I need.

Andere Tipps

To convert a text into a mesh you can use the ttf2mesh library. This library consists of just one C-file and allows to open truetype font (.ttf) and convert it glyphs to a mesh objects in 2d or 3d space. There is an examples in the repository. An interesting feature is the lack of dependency on any third party library (like libfreetype). Also in the examples there is a ttf2obj program that allows you to convert a font file to an OBJ file.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top