Get point position using Uv map

242 views
Skip to first unread message

illunara

unread,
Oct 31, 2014, 11:40:16 AM10/31/14
to python_in...@googlegroups.com
Hi everybody
Is there anyway that i can get position(x,y,z) of a Random Uv point(u,v) on Uv map?
also, if possible, find the symmetry line of UV map too.
thank a lots :3

Jan

unread,
Oct 31, 2014, 4:21:47 PM10/31/14
to python_in...@googlegroups.com
The following script gets you the world position from a random uv-coordinate of the selected object.
I affraid I don't know what you mean with symmetry line.


import maya.OpenMaya as om
import maya.cmds as cmds
import random

def GetDagPath(nodeName):
sel = om.MSelectionList()
om.MGlobal.getSelectionListByName(nodeName, sel)

dp = om.MDagPath()

sel.getDagPath(0,dp)
return dp


def UvCoordToWorld(U, V, mesh):

mfnMesh = om.MFnMesh(GetDagPath(mesh))
numFaces = mfnMesh.numPolygons()

WSpoint = om.MPoint(0.0,0.0,0.0)

util2 = om.MScriptUtil()
util2.createFromList ((U, V),2)
float2ParamUV = util2.asFloat2Ptr()

for i in range(numFaces):
try:
mfnMesh.getPointAtUV(i,WSpoint, float2ParamUV, om.MSpace.kWorld)
break; #point is in poly
except:
continue #point not found!

return WSpoint

f = UvCoordToWorld (random.random(), random.random(), cmds.ls(sl=True,type='shape'))
print [f[0], f[1], f[2]]

illunara

unread,
Oct 31, 2014, 5:04:59 PM10/31/14
to python_in...@googlegroups.com
oh wow, amazing. Thank a lots, Jan :D

and btw, if the given UV point is out of UV map, can i somehow get the closest uv's value?

Jan

unread,
Nov 1, 2014, 6:20:09 AM11/1/14
to python_in...@googlegroups.com
I don't think there is an API function for that. You could write your own function to find the closest UV based on the mesh's UV list.
However it might be a lot easier to just skip the results that are not within the coverage (ie. sorting out each result that is 0.0,0.0)

illunara

unread,
Nov 2, 2014, 12:58:37 AM11/2/14
to python_in...@googlegroups.com
Ah, okay. I will try to work it out somehow, anyway, thank for helping me, Jan :D
Reply all
Reply to author
Forward
0 new messages