I have a triangular mesh of a surface curved in two directions, e.g. a sphere. It is therefore not possible to roll this surface flat (essentially specifying a mapping to U,V texture coordinates) without distorting some of the triangles. Does anyone know of a C++ library that can take the mesh as input and produce as output suitable U,V texture coordinates for each mesh vertex, such that the resulting implied texture map distorts the triangles as little as possible?

EDIT: An example of this process is described in this paper - "Least Squares Conformal Maps for Automatic Texture Atlas Generation". I'm basically after an implementation of that, or something which does the same thing.

  • 2
    "Texture atlases" typically refer to a system where multiple textures (often non-square) are tightly packed inside a larger, (often square) square texture. It sounds like you're just trying to generate a UV unmapping, which is related but not the same thing. – Josh Sep 27 '11 at 14:46
  • I see. The process will generate one or more non-square textures, which then need to be packed into one large square texture, i.e. texture atlas generation. However, two other important steps are splitting the mesh into suitable regions, and, as you rightly say, generating a UV unmapping for each mesh region. – user664303 Sep 28 '11 at 9:13
  • This is something I've been interested in for about a year and will need to implement sometime. Did you get a good solution? If so, please share what you did. I've been hoping I could learn the mathematical theory and then write it myself in C++ using OpenNL for tips. This could take me a VERY long time though as I've still a bit green on complex numbers which are the foundation for conformal maps (AIUI). – PeteUK Sep 7 '13 at 22:06
up vote 4 down vote accepted

So, it sounds like you don't actually want a texture atlas per se, but instead just a generalized technique for performing a UV unmapping of an arbitrary mesh. Unwrapping can be used to create texture atlases, but not all texture atlases are UV unwrappings, which I why I bring up the distinction.

Unwrapping is a mesh parameterization problem. Specialized solutions exist for simple cases, such as spheres, but arbitrary polygonal meshes are non-trivial. That said, it is a solvable problem because most modelling tools have the capability to do this kind of unwrapping. For example, you can check out Blender's documentation on unwrapping for example (in fact, were you particularly adventurous you could even poke around in Blender's source code to check out their implementations -- but that's probably crazy talk). There's also this tool.

Blender uses the Least-Squares Conformal unwrapping technique, which you can find several academic papers on. This paper is one of the better ones. There is also the Angle-Based Flattening technique, which is related (though older, I believe).

This page may also be of some utility. In particular, on that page you can find the OpenNL library which provides a C++ implementation of an iterative LSCM solver (it's the only one I know of outside of perhaps a few papers that might include a pseudocode implementation).

  • I'm not actually clear on your distinction, but unless some UV unwrappings are not texture atlases then the output I'm after will be a texture atlas. However, it seems you are suggesting a more specific name for it is UV unwrapping. It's worth noting that my triangulated mesh may need to be split into several distinct regions which are then unwrapped, in order to avoid too much distortion. – user664303 Sep 28 '11 at 8:39
  • Thanks for the link to the paper. I had seen it. It explains a process for doing exactly what I'm trying to achieve. I'm looking for a straight forward implmentation of it. I had downloaded Graphite, from the same group, but the OpenNL example implementation of LSCM may be a simpler approach. I'll see if it does everything they describe in the paper and let you know. – user664303 Sep 28 '11 at 8:52

If you are using OpenGL, gluSphere does it for i.e. a sphere. Make sure to read the part with gluQuadricTexture at the bottom of the page.

  • Thanks. However, I need something that can take an arbitrary mesh as input. – user664303 Sep 27 '11 at 13:17
  • @user664303 I'm afraid there is no general solution. What kind of mesh is it? – Maik Semder Sep 27 '11 at 14:10
  • It is a triangulated mesh computed using the marching cubes algorithm. – user664303 Sep 28 '11 at 8:32

My suggestion is to have an artist make the mesh and have them play around with UV mapping it. Tools like Max and Maya have advanced projection capabilities, as well as the ability for an artist to eyeball it until it looks right.

  • I'm not in a position to hire or ask anyone to help, unfortunately. – user664303 Sep 28 '11 at 8:33

I use UNITY although you'll have to get used to the LUA scripting in it. But manipulating geometric objects is pretty smooth with it. Hope that helps.

  • Looking at the Unity documentation I found the function Texture2D::PackTextures, which packs several textures into a single, larger texture. However, I'm looking for something that generates texture coordinates into a texture (yet to be generated), given a 3d mesh. Is there a function to do this in Unity? – user664303 Sep 27 '11 at 13:14
  • This doesn't really address the question; -1. – Josh Sep 27 '11 at 14:49

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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