hi…
i’m new to the site & using the maya python api…
i’m trying to deform a mesh using the api for speed, my goal is to unwrap a mesh to match the uv layout of the current uv set.
i’ve been searching online and have gotten so far… the code below works ok on a mesh which only has a single uv shell.
but i’ll have multiple shells, which i split the verts on the uv borders.
my problem is with the setPoints… take a cube for example, i get a vert in every position to match the default uv layout (when the verts have been split)
but the polys are twisted… i’m guessing the issue is with vert indices aren’t the same as when i iterated over the point array ?
any help and advice would be much appreciated.
thanks
def deformMeshToUVSetLayout():
# get the active selection
selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selection )
iterSel = OpenMaya.MItSelectionList(selection, OpenMaya.MFn.kMesh)
# go through selection
while not iterSel.isDone():
# get dagPath
dagPath = OpenMaya.MDagPath()
iterSel.getDagPath( dagPath )
# create empty point array & float arrays
mesh_MPointArray = OpenMaya.MPointArray()
U_MFloatArray = OpenMaya.MFloatArray()
V_MFloatArray = OpenMaya.MFloatArray()
# create function set, get points in world space & UVs
meshFn = OpenMaya.MFnMesh(dagPath)
meshFn.getPoints(mesh_MPointArray, OpenMaya.MSpace.kWorld)
meshFn.getUVs(U_MFloatArray, V_MFloatArray)
# write UV postions to mesh_MPointArray
for i in range( mesh_MPointArray.length() ):
mesh_MPointArray[i].x = U_MFloatArray[i]
mesh_MPointArray[i].y = V_MFloatArray[i]
mesh_MPointArray[i].z = 0
# apply new point positions to mesh
meshFn.setPoints(mesh_MPointArray, OpenMaya.MSpace.kWorld)
return