Hi there,
Ok i got my little script working with the python API. It takes a mesh1 (a neutral body mesh), mesh2 (a different character neutral mesh) and mesh3 (the mesh2 character mesh posed differently).
the script should simply store the vert points from mesh1,mesh2,mesh3. then find the difference between mesh2 and mesh3. then finally add the difference to mesh1.
However i thought with python API things were supposed to be really fast with big meshes. My mesh has around 20,000 verts. and although that is alot, i am currently waiting about a minute for the script to finish.
Can anyone please tell me what im doing wrong, or maybe that is just how long things take with a big mesh. i appreciate a fairly big code sample
thanks alot guys,
here is my code:
import maya.OpenMaya as om
def getPoints(geo):
sel = om.MSelectionList()
dag = om.MDagPath()
sel.add(geo)
sel.getDagPath(0,dag)
mesh = om.MFnMesh(dag)
vts=om.MFloatPointArray()
mesh.getPoints(vts, om.MSpace.kObject)
return mesh,vts
def findDiff(scan1_verts, scan2_verts):
diff_list=om.MFloatPointArray()
for i in xrange(scan1_verts.length()):
p1 = scan1_verts[i]
p2 = scan2_verts[i]
diff_list.append(om.MFloatPoint(p2)-om.MFloatVector(p1))
return diff_list
def addDiff(diff_list, target_mesh_verts):
final_list=om.MFloatPointArray()
for i in xrange(target_mesh_verts.length()):
p1 = target_mesh_verts[i]
p2 = diff_list[i]
final_list.append(om.MFloatPoint(p1)+om.MFloatVector(p2))
return final_list
def setPoints(girlMesh, finalPos):
for i in xrange(girlMesh.numVertices()):
girlMesh.setPoints(finalPos,om.MSpace.kObject)
#store the vert positions for each mesh
mFnMeshTarget, target_mesh_verts = getPoints("mesh1")
mFnMesh, scan1_verts = getPoints("mesh2")
mFnMesh2, scan2_verts = getPoints("mesh3")
#find the difference between the verts from the expression scan and neutral scan
diffList = findDiff(scan1_verts,scan2_verts)
#add the difference to the target mesh
finalPos = addDiff(diffList, target_mesh_verts)
#set the mesh difference to the target mesh
setPoints(mFnMeshTarget,finalPos)
