adding the difference between two meshes onto a third with api

86 views
Skip to first unread message

s...@weacceptyou.com

unread,
Dec 14, 2016, 3:57:36 PM12/14/16
to Python Programming for Autodesk Maya
hello,

i got this concept working fine with python cmds. I am trying to see if i can get it working with api. So far with the thanks to Justin Israel, i got my code to this stage:

http://pastebin.ubuntu.com/23630582/

basically imagine there are 3 meshes:

1) a female neutral mesh named "target"
2) a male neutral mesh named "neutral"
3) the same male mesh but in a muscle man pose named "expression"

all meshes have identical topology

all i want to achieve is to first find the relative difference between the male neutral mesh verts and the male muscle man mesh verts. And then to apply this difference on top of the female neutral mesh.

I got this working fine with cmds. So the i would find the difference values for each vert and store in a list. I would then apply this difference on top of each corresponding female mesh vert with the move commmand. It produced the same pose but a female version.

However in my api code i am using the setPoints() method which i think is taking the difference but making the transforms absolute. So the female neutral mesh becomes identical to the male muscle man mesh, rather than it generating a female version of the muscle man pose.

can anyone show me where im going wrong here. I know it can be done with a small tweak im sure.

sorry for long post,
Sam

Nicolas Chaverou

unread,
Dec 14, 2016, 4:49:57 PM12/14/16
to python_in...@googlegroups.com
Hey

On Wed, Dec 14, 2016 at 9:57 PM, <s...@weacceptyou.com> wrote:
hello,

i got this concept working fine with python cmds. I am trying to see if i can get it working with api. So far with the thanks to Justin Israel, i got my code to this stage:

http://pastebin.ubuntu.com/23630582/

basically imagine there are 3 meshes:

1) a female neutral mesh named "target"
2) a male neutral mesh named "neutral"
3) the same male mesh but in a muscle man pose named "expression"

all meshes have identical topology

all i want to achieve is to first find the relative difference between the male neutral mesh verts and the male muscle man mesh verts. And then to apply this difference on top of the female neutral mesh.

I got this working fine with cmds. So the i would find the difference values for each vert and store in a list. I would then apply this difference on top of each corresponding female mesh vert with the move commmand. It produced the same pose but a female version.

However in my api code i am using the setPoints() method which i think is taking the difference but making the transforms absolute.

I haven't looked at the code but setPoints doesn't apply differences, it just replaces the mesh vertices from another list of vertices
It's your task to fetch the points from your target mesh, apply the difference and use setPoints to dump the new vertices in

Hope this makes sense :)
 
So the female neutral mesh becomes identical to the male muscle man mesh, rather than it generating a female version of the muscle man pose.

can anyone show me where im going wrong here. I know it can be done with a small tweak im sure.

sorry for long post,
Sam

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/804aba19-1965-4377-bf99-05c4856ef54c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

33th...@gmail.com

unread,
Dec 24, 2016, 3:51:16 AM12/24/16
to Python Programming for Autodesk Maya, s...@weacceptyou.com
I think this is more of what you want:

def getPoints(geo):
sel = om.MSelectionList()
dagNode = om.MDagPath()

sel.add(geo)
sel.getDagPath(0,dagNode)

dagNode.extendToShape()
fnMesh = om.MFnMesh(dagNode.node())

vts=om.MPointArray()
fnMesh.getPoints(vts, om.MSpace.kObject)

return dagNode, vts

def findDiff(vtsA, vtsB):
numVerts = vtsB.length()
diff = om.MVectorArray(numVerts)
for i in xrange(numVerts):
diff[i] = vtsB[i] - vtsA[i]
return diff

def setPoints(dagNode, deltas):
dagNode.extendToShape()
fnMesh = om.MFnMesh(dagNode.node())
pts = om.MPointArray()
fnMesh.getPoints(pts, om.MSpace.kObject)

for i in xrange(pts.length()):
pts[i] += deltas[i]

fnMesh.setPoints(pts, om.MSpace.kObject)

but it's not going to give you a great result, since those deltas are being applied as world space, and not surface relative.

however, you could very easily just use the muscular male as a blendshape target for the neutral male. delete the connection. Then just plug the outMesh of the female neutral into the inMesh of the male neutral. delete the connection. Then turn on the blendshape to 1. You will have the muscular female shape you're looking for.

goodluck!

samwilli...@gmail.com

unread,
Dec 25, 2016, 3:01:15 PM12/25/16
to Python Programming for Autodesk Maya, s...@weacceptyou.com, 33th...@gmail.com
sorry just saw this,

thanks alot for the help!
Reply all
Reply to author
Forward
0 new messages