adding together MFloatPoints python api


#1

Hello, ok i just need to figure out why this code isn’t working properly.
I use the ‘getPoints()’ method and store all the verts of a certain piece of geo as ‘MPoints’
i then find the difference between two meshes (in the findDiff function) and store them in an MFloatPointArray()
then finally take this result and add it to the original mesh (in the addDiff function) - here is where the problem comes. Its obviously one of the items is the wrong type or something and it returns this error:

in method ‘MFloatPoint___add__’, argument 2 of type ‘MFloatVector const &’ #

here is the 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.MPointArray()
    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(p1-(p1-p2)))
	return diff_list	

def addDiff(diff_list, target_mesh_verts):
    final_list=om.MFloatPointArray()
    for i in xrange(target_mesh_verts.length()):
        p1 = diff_list[i]
        p2 = target_mesh_verts[i]
        final_list.append(om.MFloatPoint(p1+p2))
    return final_list


#store the vert positions for each mesh
mFnMeshTarget, target_mesh_verts = getPoints("target")
mFnMesh, scan1_verts = getPoints("neutralShape")
mFnMesh, scan2_verts = getPoints("expressionShape")

#find the difference between the verts from the expression scan and neutral scan 
diff_list = findDiff(scan1_verts,scan2_verts)

finalPos = addDiff(diff_list, target_mesh_verts)

Can anyone show me how to make the p1 and p2 elements in the ‘addDiff’ function addable.

thanks,
Sam


#2

My first guess would be that you are adding an MFloatPoint and an MPoint (float vs double), and there’s no overload function for these two, i.e. you need to convert one of them to the other. Otherwise, please write a minimal example that produces the problem. For example:

MPoint p1;
MFloatPoint p2;
p1 = p1 + p2;

#3

thanks,
i converted them both to the same type at one point and it still comes back with the same error. so they are both MPointFloats, but this doesnt add either

Sam


#4

They are nitpicking about this, and you can’t actually add two points. You need to convert one of them to a vector:

import maya.OpenMaya as om

p1 = om.MPoint()
p2 = om.MPoint()

#p = p1 + p2 # error
p = p1 + om.MVector(p2)

How you could have known:

http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__cpp_ref_class_m_point_html


#5

thanks alot for the help mate. Even with that guide i find it very hard to navigate and find the solution. I think i fundamentally need to understand how the api works first.

cheers,
Sam


#6

Sure, I wasn’t criticizing or anything; it was just a tip of how to know these things, and unless you mess with this a lot in C++, it isn’t trivial. Until then, keep asking these questions on the forum :slight_smile:
(Also, perhaps you should look at the python doc about open maya instead of the c++'s.)