Hi, is there any package that does (or can help in doing) UV mapping? More specifically: I have a 3D mesh made of triangles, and I want to “unwrap it” mapping each of its 3D points to a 2D plane.
All parametric geometries in Meshes.jl support a local coordinate system with unitless coordinates in [0, 1]:
t = Triangle((0, 0), (1, 0), (0, 1))
t(u, v) # uv coordinates are barycentric in triangles
This is one of the ingredients to unwrap a mesh of triangles into a plane (when that is possible).
Makie.jl provides a UV texture mechanism as well to map colors to meshes, which we use internally in our viz
recipes. Perhaps you can look into their codebase for related functionality.
Can you describe your problem more?
UV mapping for arbitrary meshes is really hard and doesn’t actually exist outside Julia as well, as far as I can tell.
If it’s some easy mesh, you may get away with doing something simple, but if it’s a more complex mesh, your best bet may be to use blender or some other 3D software to semi-automatically do it.
You can just import the OBJ or any other format, and save it back out as an OBJ with uv information.
That process is more complex than it has any right to be though, so prepare for some frustration
In theory you could also just get all triangles, project them to 2d, and then use GitHub - JuliaGeometry/Packing.jl: Algorithms for packing problems to place them on a texture.
That will result in very wasteful texture mapping though, with bad seems. But I guess you could just pad a bit when writing to the image/texture.
I guess one could also play around with converting the mesh to a graph and then use something like this:
https://juliagraphs.org/NetworkLayout.jl/stable/#Example-4
But, I wouldn’t expect this to do any good uv-maps.
This is the context where I’m working:
I have a 3D object in a triangular mesh (obj) and also its texture map (png). I want to do some analysis of the image contained in particular, relatively small regions of that texture. But in some cases, the region that I want to analyze is near the seams of the original texture map, and I would like to have different, continuous maps of such regions to perform the analysis.
I think I could do it like this:
- Identify the vertices contained in the region of interest (split as more than one region in the original texture map).
- Create a smaller mesh with only the triangles that contain those points in 3D. That “submesh” is expected to be rather flat, containing only tens of vertices in a patch of the original object.
- Unwrap those 3D triangles into a new 2D map without seams (its countour should coincide with the 3D contour of the patch).
- Having the UV coordinates of the original texture map (A) and the new map (B), calculate the affine transformation between each triangle of A that is present in the region of interest into the corresponding triangle of B. Apply those transformations to the color pixels of A to create the new continuous texture map.
I was asking for help on step #3, because I think I can manage with the rest by myself. An alternative would be to count with tools for texture analysis in 3D (do they exist?), but so far I am working with Images.jl, which is only for 2D images.
I assume small distortions of the original texture map due to the affine transformations, although I don’t think they should be great, since I am dealing only with small regions without very marked curvatures.
It almost seems like you want to render a section of a mesh to some nonlinear extension of a best-fit plane, and then analyze the image?