Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

C# Accessing UV information in MNMesh

C# Accessing UV information in MNMesh

Anonymous
Not applicable
732 Views
2 Replies
Message 1 of 3

C# Accessing UV information in MNMesh

Anonymous
Not applicable

Hi,

 

  I am having some difficulty figuring out how to access UV information in an MNMesh.  I have the following code:

 

IMNMapFace fmap = f_map.F(faceIdx);

 

When I try to get the Vertex array in the fmap I am running into trouble.  According to the SDK, the following returns an IntPtr to the array

 

IPoint3 uvert = f_map.V(the_fmap.Tv[0]);

 

My problem is the_fmap.Tv portion.  I can't figure out how to get the array of UVs used in the Mapface.

 

I have tried other routes to access the data including MNMesh.Mv but this can sometimes return the wrong data is the UV is shared among several faces in different locations in the UV map.  Basically my C# skills are not good enough to figure out how to access this data.

 

Does anyone have any tips or a code snippet that shows how to do this?

 

Thanks

 

Todd

0 Likes
Accepted solutions (1)
733 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

If anyone is curious, a co-worker helped me figure out how to do this.  The below code will retrieve the proper UV Verts.  In our case we only need the first, second, and last if you are curious as to why I'm grabbing only three.

 

                                        IMNMapFace the_fmap = themesh.Mf(tmap.MapChannel,faceIdx);
					// Find the pointer to the List of map vertices for this face.
					IntPtr tt = the_fmap.Tv;
					// find the number of map verts and make an integer array.
					int[] mapverts = new int[the_fmap.Deg];
					// populate the array with the true map verts
					for (int i = 0; i <= the_fmap.Deg - 1; i++)
					{
						IntPtr newptr = IntPtr.Add(tt, i * sizeof(Int32));
						mapverts[i] = System.Runtime.InteropServices.Marshal.ReadInt32(newptr);
					}
					// create a piont for each map vert using the array.
					IPoint3 uvert1 = f_map.V(mapverts[0]);
					IPoint3 uvert2 = f_map.V(mapverts[1]);
					IPoint3 uvert3 = f_map.V(mapverts[mapverts.Length - 1])
0 Likes
Message 3 of 3

Anonymous
Not applicable

In case anyone was curious, a co-worker helped me solve this issue.  The below code will retrieve the UV indices I was looking for.

 

                                        IMNMapFace the_fmap = themesh.Mf(tmap.MapChannel,faceIdx);
					// Find the pointer to the List of map vertices for this face.
					IntPtr tt = the_fmap.Tv;
					// find the number of map verts and make an integer array.
					int[] mapverts = new int[the_fmap.Deg];
					// populate the array with the true map verts
					for (int i = 0; i <= the_fmap.Deg - 1; i++)
					{
						IntPtr newptr = IntPtr.Add(tt, i * sizeof(Int32));
						mapverts[i] = System.Runtime.InteropServices.Marshal.ReadInt32(newptr);
					}
					// create a piont for each map vert using the array.
					IPoint3 uvert1 = f_map.V(mapverts[0]);
					IPoint3 uvert2 = f_map.V(mapverts[1]);
					IPoint3 uvert3 = f_map.V(mapverts[mapverts.Length - 1]);

 

0 Likes