Hello i have my script almost working now. except the very last part where i set the points on my mesh.
Basically i have a script in python API which gets the points from 3 different shaped sphere meshes, finds the difference between meshes 2 and 3, adds the difference to the points of mesh 1, and finally sets mesh 1 to this new shape
I have tried to track the result of things at each step throughout the script and it seems the result of the difference added to the original mesh values are fine. But then when i use setPoints(), my mesh explodes!
i dont know why because the set points works fine when i simply copy one set of verts straight onto a mesh, but when i add together points and then setPoints i think i have created a problem
I have in included the code, im sorry its a bit long, but i think pretty straightforward, if anyone can help my make this work then you would really be helping me out.
thanks alot,
Sam
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()
counter=0
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(geo, finalPos):
geo.setPoints(finalPos, om.MSpace.kObject)
#store the vert positions for each mesh
mFnMeshTarget, target_mesh_verts = getPoints("target")
mFnMesh, scan1_verts = getPoints("neutral")
mFnMesh2, scan2_verts = getPoints("expression")
#find the difference between the verts from the expression scan and neutral scan
diffList = findDiff(scan1_verts,scan2_verts)
finalPos = addDiff(diffList, target_mesh_verts)
#set the mesh difference to the target mesh
setPoints(mFnMeshTarget,finalPos)