Texture (pixel) coordinates to world coordinates

Hi All,

I have the following: A pixel image is mapped (any type of mapping) as a texture on a nurbs or mesh (could be either of them).

I would like to know where some pixel (x,y) from the image is located in Rhino world coordinates (x,y,z).

Is this at all possible? Any suggestions at which functions I have to look? Scripting or SDK (rhinocommon or .NET), would work for me.

Many thanks,

Hi @silvano,

i´ve done something related in vbscript. The process could work like this:

A nurbs surface or polysurface does not have texture coordinates, but its rendermesh does. So you will only work on mesh objects or the rendermesh in case of a nurbs object. This mesh is then triangulated and unwrapped virtually using your own routine or to make the explanation clear, with the command _ExtractUVMesh. With this 2D representation of your UV mesh, you can evaluate your pixel coordinate in 2D. Usually the UV range is between 0 and 1, if you set a different size for the unwrap, the 2D coordinate you search for is just scaled or divided using the dimensions of the unwrapped mesh.

After getting the 2d coordinate (world space) you find the triangle index which contains the pixel coordinate and work using barycentric coordinates. If you evaluate this barycentric coordinate in the 3d mesh using the triangle index, you get the 3d point.

There is one case where you will not find a proper 3D equvalent, if you evaluate a 2D pixel coordinate which is outside of a mesh island. In this case, you can find the closest 2D triangle and use it`s edge.


1 Like

Hi @clement
This is perfect for me. Many thanks for helping.

Sorry for refreshing this old topic but i need to get uvmesh via rhinocommon and i cant find proper way to do it i can access mapping vertices but remeshing from points won’t give me original uvmesh to work further with it. GetMeshes() doesn’t have uvmesh enum.

@nathanletwory maybe you know something about it?

You need to use the TextureCoordinates property on a mesh to retrieve the UV data.

1 Like

@nathanletwory i have already them but i can only get list of points from foreach (Point2f coord in mesh.TextureCoordinates) there’s no uvmesh here. Remeshing those points won’t give me original uvmesh and it is very easy to mess up things at this point.

Hi @D-W,

you need to build a new mesh using the mesh.TextureCoordinates as the new mesh vertices. The Z-value for each vertex is zero. Do You need an example ?


1 Like

I see i’ve done it now but i wonder what if uv islands are disconnected but i assume that referring to original mesh faces indexes will be good enough to recreate uvmesh properly - so far it works (i thought earlier it wouldn’t be possible this way) - i also thought there is somewhere hidden method :wink: If i’ll need an explanation i’ll post here - Thanks guys for quick response i hope i’ll be able to solve this on my own :slight_smile:

It will be one mesh, to get the islands seperated you could split into disjoint pieces with Mesh.SplitDisjointPieces after unwrapping or, explode the render mesh and unwrap each island individually.

Take care with overlaps when _UnpackTextures was used…

1 Like

@clement would you mind showing how to get islands for mesh ??

I get nice islands for any brep using instanceMesh = instance.GetMeshes(MeshType.Render); but when i have mesh my trouble start and i can’t even get proper uvmesh back - it is bit odd but it sometimes work and sometimes not - especially when i change uvs by hand but i think im just missing something here.

On left those from c# on right proper extracted uvmesh and mesh while uvediting.

Heres example of working mesh without any issues… I’m bit confused whats going on :confused:


i am not sure i understand 100% what you’re doing. Here is what i guess you’re doing:

  1. get the rendermesh, explode it into 3d pieces
  2. unwrap each piece individually into new 2d mesh islands
  3. make edits on the unwrapped 2d mesh islands
  4. re-wrap the islands from 2d to 3d

Is this correct ?


@clement i want to get uvs then generate points in uv domain and get it back on mesh via pointAt using barycentric coords and i got that already but im missing sometimes few triangles or remeshed uvs are messed up and sometimes everything works ok - i supose i have to explode mesh to individual triangles and then remesh eachone on uv.

Check inbox :inbox_tray: