Duplicate Geo and Transfer Weights - Help needed

121 views
Skip to first unread message

David Martinez

unread,
Feb 24, 2014, 5:20:08 PM2/24/14
to python_in...@googlegroups.com
Hi,

I'm working on a really simple script and yet I'm having trouble getting the script to do what I want.
Here is a description of what I'm trying to do:

Get selection
Duplicate the object
For any skin Clusters that the object may have
    | Get joints skinned to the skin cluster
    | Replace the selection with the duplicated object
    | Adds the joints connected to the skin Cluster to the selection
    | Skin the new object
    | Copy weights from one object to the other

Here is the code that I have so far: https://gist.github.com/davidmartinezanim/9198402

I've tried to get the code to have the same settings as I have in Maya:


And yet, when I do it in Maya, it works, but when I run the code, the original and duplicate objects are different. (When I move one of the joints, the skinning is not quite the same)

Any ideas about what could be causing the issue?

--
David Martinez - Technical Animator
 

Eduardo Grana

unread,
Feb 25, 2014, 7:38:54 AM2/25/14
to python_in...@googlegroups.com
Hello David,

Maybe you can try adding the  noMirror=True flag on the copySkinWeights command in line 20...
Something like
            cmds.copySkinWeights(sourceSkin=currentSkinCluster,
                destinationSkin=newSkinCluster,
                surfaceAssociation="closestPoint",
                influenceAssociation=("name", "label", "oneToOne"),
                normalize = True, noMirror=True)
I would also change the influenceAssociation to "closestJoint", but it seems to work with out it too...
Cheers!
Eduardo


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpyWbqvJkp7bFyh7jNZg3zJFV_iV902CjKd7xpoOL5dpbw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

David Martinez

unread,
Feb 25, 2014, 7:55:49 AM2/25/14
to python_in...@googlegroups.com
Hi Eduardo,

I tried what you suggested but there are still a few vertices that decide to get skinned to other joints and do not respect the old skinning information. I'm not sure what's causing the issue though. Or why it happens when I do it using code but not when using the interface...


--
David Martinez - Technical Animator
 


Eduardo Grana

unread,
Feb 25, 2014, 8:09:22 AM2/25/14
to python_in...@googlegroups.com
Hi David,
I've tried with a sphere and 3 joints, maybe not the best test case,
i'm wondering if you could send me a test case to figure it out better.
Have you tried with influenceAssociation="closestJoint"?
Cheers,
Eduardo



For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

David Martinez

unread,
Feb 25, 2014, 8:11:32 AM2/25/14
to python_in...@googlegroups.com
Hi Eduardo,

Yes, I did try with that and I get results that are closer but still not quite what I was looking for.

I will try to repro the issue in a free rig or something as the scenes that I'm dealing with at the moment are not in the public domain.
Thanks,




--
David Martinez - Technical Animator
 


Eduardo Grana

unread,
Feb 25, 2014, 8:24:56 AM2/25/14
to python_in...@googlegroups.com
Ok.
Remeber that you not only should match the skin weights, but the settings in the skin cluster.
Also be aware that there may be weighting between the different skinning methods (if weight blended is used)
Cheers!
Eduardo



For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

David Martinez

unread,
Feb 25, 2014, 8:31:35 AM2/25/14
to python_in...@googlegroups.com
Hi again,

Would it be possible to retrieve the information from a skin cluster so I can mimic the same settings when creating the new one?


--
David Martinez - Technical Animator
 


Eduardo Grana

unread,
Feb 25, 2014, 10:17:57 AM2/25/14
to python_in...@googlegroups.com
Hi David,

I've made some rough code about copying the usual attributes you can tweak about a skin cluster
(hope i didn't forget something!)
you can try that function in your code, and let me know how it goes!
Cheers!
Eduardo




For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

David Martinez

unread,
Feb 25, 2014, 10:57:54 AM2/25/14
to python_in...@googlegroups.com
Hi,

I've tried adding a call to 'copySkinClusterSettings' after creating the skin cluster but I'm still getting small inconsistencies when I move the joints (Although is pretty close)
Here is the latest code that I'm using:

- https://gist.github.com/davidmartinezanim/9211736

I will try to repro that with a custom example and send you a link tonight.
Cheers



--
David Martinez - Technical Animator
 


Marcus Ottosson

unread,
Feb 25, 2014, 1:16:05 PM2/25/14
to python_in...@googlegroups.com
Sorry, I haven't looked through your code fully, but just had a quick thought.

If the behaviour is different between scripted and manual, what happens if you were to play with cmds.refresh() and cmds.dgdirty()?

I'm thinking the differences may be because the viewport has time to update when performing manually, but not when run via script. Try putting in a few calls to refresh and/or dgdirty inbetween the lines of your core to force evaluation.



For more options, visit https://groups.google.com/groups/opt_out.



--
Marcus Ottosson
konstr...@gmail.com

David Martinez

unread,
Feb 25, 2014, 1:18:53 PM2/25/14
to python_in...@googlegroups.com
I will give it a go and let you guys know how it goes

David Martinez

David Martinez

unread,
Feb 26, 2014, 9:51:56 AM2/26/14
to python_in...@googlegroups.com
I tried adding those commands here and there but I'm still getting the issue.

Just for the record, most of the skinning is in the right place but there are a few vertices that drift a little bit compared to the original geo. It's not much but I was expecting it to be a perfect match. Ironically, I tried with a few skinned objects of freely available characters and I did not encounter the issue. Quite annoying that keeps happening at work.   :-S



--
David Martinez - Technical Animator
 


Eduardo Grana

unread,
Feb 26, 2014, 11:55:18 AM2/26/14
to python_in...@googlegroups.com
Hello David,
It happens often, don't worry. Maybe you can chat with a rigger friend at your studio and ask him is they are doing some
something that is obvious. Another thing that pops into my head is that maybe if you have a huge or a tiny character, and
there maybe some precision issues. Maybe you also have some very small weights on your joints that get lost in the copying.
You can test the last option by pruning your weights before copying de skin cluster.
Hope it works out!
Cheers!
Eduardo



For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

Marcus Ottosson

unread,
Feb 26, 2014, 12:09:10 PM2/26/14
to python_in...@googlegroups.com
Isn't the issue that performing a certain set of actions via script differs from when you run them manually? Not sure scaling could (or should) have any effect on that.



For more options, visit https://groups.google.com/groups/opt_out.



--
Marcus Ottosson
konstr...@gmail.com

Eduardo Grana

unread,
Feb 26, 2014, 12:25:32 PM2/26/14
to python_in...@googlegroups.com
Hello Marcus,
You are right, it's just i'm running out of ideas... =)
Cheers!
Eduardo



For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

David Martinez

unread,
Feb 26, 2014, 1:00:11 PM2/26/14
to python_in...@googlegroups.com
You guys are probably going to kill me...

I've just done the same thing once again using the interface, tweaked the joint rotations and compared the original and final meshes and I DO get that same inconsistency. So it's not something that only happens when running the code but also using the interface. I'm so sorry about that, I guess I missed it because in my first version, the result that I was getting was not as close. Right now, it's almost unnoticeable.

On the bright side, your suggestions allowed me to get the results that I was looking for. Thanks!

One of the current projects is in milimiters and the objects are quite small so that might be causing the issue.I will try pruning the weights to see if that makes any difference. Is there anything else that I should keep in mind?


--
David Martinez - Technical Animator
 


Eduardo Grana

unread,
Feb 26, 2014, 1:14:38 PM2/26/14
to python_in...@googlegroups.com
Hey David,
No worries, no harm done.
regarding skin clusters, i remember that they behave in weird ways when they are translating a mesh far far far far away,
i also kind of remember something about  the dual quaternion mode and not scaling well... but that was back in version 2011 or 2012,
maybe they fixed it already...
Cheers!
Eduardo




For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar

Marcus Ottosson

unread,
Feb 26, 2014, 1:26:05 PM2/26/14
to python_in...@googlegroups.com
As a prelude to transferring the weights, perhaps you could 

1. clone/copy the mesh, lets call it C
2. scale it by a pre-determined bounding-box size
3. transfer the weights from B to C via methods that use rays or anything that is scale-dependent.
4. and finally transfer those weights back to the original A using an absolute per-point method.

Happening behind the scenes, without the user having to worry about it.



For more options, visit https://groups.google.com/groups/opt_out.



--
Marcus Ottosson
konstr...@gmail.com

David Martinez

unread,
Feb 26, 2014, 6:03:46 PM2/26/14
to python_in...@googlegroups.com
Hi Marcus,

Could you elaborate on points 2 and 3? I don't quite understand what you mean.

Thanks in advance,


--
David Martinez - Technical Animator
 


David Martinez

unread,
Feb 26, 2014, 6:04:21 PM2/26/14
to python_in...@googlegroups.com
And thanks again Eduardo for your advice. I appreciate it!   :-)


--
David Martinez - Technical Animator
 


Marcus Ottosson

unread,
Feb 27, 2014, 2:49:55 AM2/27/14
to python_in...@googlegroups.com
Have a look at this, transferring weights from a sphere (source) to a head (target), when they are both too small

Inline images 1



For more options, visit https://groups.google.com/groups/opt_out.



--
Marcus Ottosson
konstr...@gmail.com

Eduardo Grana

unread,
Feb 27, 2014, 6:10:32 PM2/27/14
to python_in...@googlegroups.com
Hey David,
I just realized, maybe you should copy the skin cluster setting before copying the weights,
since there are some attributes that may affect the weights.
Cheers!
Eduardo



For more options, visit https://groups.google.com/groups/opt_out.



--
Eduardo Graña
www.eduardograna.com.ar
Reply all
Reply to author
Forward
0 new messages