Add meshes/joints to skinCluster

622 views
Skip to first unread message

Aren Voorhees

unread,
Nov 4, 2015, 11:13:16 AM11/4/15
to Python Programming for Autodesk Maya
Hey everyone, 

I'm working on a tool that loops through a bunch of meshes, creates a joint for each and bakes the mesh's keyframes to the respective joint.  I have it working, but they way I'm doing it now is kind of slow because I am merging all the meshes at the end in order to collapse all the skinClusters down to one (so I don't have like, a million skinClusters in my export).  Does anyone have any ideas on how I can avoid that last merge step that is taking so long?  This tool will be used on files with 1000+ meshes which is why I am concerned about speed.

def skin_frags(self):

        cmds.cutKey(self.frags)
       
        count = 0
        for i in self.frags:
            cmds.makeIdentity(i, apply=True)
            skinCluster = cmds.skinCluster(i, self.fragJnts[count])
            cmds.parent(self.fragJnts[count], self.scaleJnt)
            count += 1
       
        cmb = cmds.polyUniteSkinned(self.frags) #This is what makes it so slow!
        cmds.rename(cmb[0], "Frags_Merged")

I was trying out a separate idea too, where I create one skinCluster node, then add each joint and mesh to that skinCluster, something like this:

frags = cmds.ls(sl=True)

fragJnts = []
count = 0
for i in frags:
   fragPos = cmds.xform(i, query=True, t=True)
   cmds.select(clear=True)
   jnt = cmds.joint(position=fragPos, name='Frag_' + str(count) + '_JNT')
   cmds.parent(i, jnt)
   fragJnts.append(jnt)
   count += 1
   
sc = cmds.skinCluster(frags[0], fragJnts[0])

count = 1
for i in range(1, len(frags)):
    cmds.skinCluster(sc, edit=True, addInfluence=fragJnts[count], geometry=frags[count], useGeometry=True) #Here I am trying to one-by-one add the joint and respective mesh, but haven't got that                                                                                                            working yet either
    count += 1


If anyone has any tips with either method I'm trying to use, I'd really appreciate it!

Thanks,
Aren

Nicolas Combecave

unread,
Nov 4, 2015, 11:50:59 AM11/4/15
to python_in...@googlegroups.com
I'm not in front of maya right now but a couple thoughts:

Did you try the polyUnite without retaining history?
``` python
cmds.polyUniteSkinned(self.frags, ch=False)
```

If you go the route of rebuilding a skinCluster from scratch on the final merged geometry, keep in mind that skinClusters can only deform one geometry, unlike many other deformers.

--
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/a89820b9-764a-4738-8246-9f099ec5712d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Combecave

unread,
Nov 4, 2015, 11:51:56 AM11/4/15
to python_in...@googlegroups.com
Sorry about the formating, here a cleaner version:

I’m not in front of maya right now but a couple thoughts:

Did you try the polyUnite without retaining history?

cmds.polyUniteSkinned(self.frags, ch=False)

If you go the route of rebuilding a skinCluster from scratch on the final merged geometry, keep in mind that skinClusters can only deform one geometry, unlike many other deformers.

Marcus Ottosson

unread,
Nov 4, 2015, 12:05:04 PM11/4/15
to python_in...@googlegroups.com

keep in mind that skinClusters can only deform one geometry

How do you mean? I think skinClusters can take on any number of meshes, like any other deformer.

@Aren Voorhees What is this for? Are you looking to transfer the animation of a transform onto the mesh, and zero out the transform?



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



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

Nicolas Combecave

unread,
Nov 4, 2015, 12:21:31 PM11/4/15
to python_in...@googlegroups.com

You can of course use the skinCluster -e -g “anotherGeom”, and it will “deform” this geometry, but it is not supported by the node.
Documentation is unclear about it:

http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/skinCluster.html

The skinCluster binds only a single geometry at a time. Thus, to bind multiple geometries, multiple skinCluster commands must be issued.

http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_fn_skin_cluster_html

Note that unlike most deformers, a skinCluster node can deform only a single geometry. Therefore, if additional geometries are added to the skinCluster set, they will be ignored.

This last documentation excerpt is somehow misleading because if you add another geometry to the skinCluster via the deformer or the skinCluster command with the -e -geometry flags combination, the object will be deformed, but the skinCluster internal weights structure does not allow multiple geometries to be accessed by the node.

Anyway if anyone found a way to allow one skinCluster to deform multiple geometries, with the ability to paint weights on them, I’d be interested…


Marcus Ottosson

unread,
Nov 4, 2015, 12:45:14 PM11/4/15
to python_in...@googlegroups.com

You can of course use the skinCluster -e -g “anotherGeom”, and it will “deform” this geometry, but it is not supported by the node.

Ah, yes you’re right. I was confusing this with skinning a combined mesh. Sorry to have made you dig up all of those links. :)

I’ve experimented in the past with a “fan-in-fan-out” sort of approach to that, where meshes were combined and then separated before and after a skinCluster node, but can’t remember whether it actually worked. There was issues with point numbers changing I think, though that seems fixable. But I suppose that’s quite off topic!

Aren Voorhees

unread,
Nov 4, 2015, 3:05:06 PM11/4/15
to Python Programming for Autodesk Maya
combi, thanks for the help - I tried setting the constructionHistory flag to false but that didn't seem to make any significant difference.  Currently it takes about 1:20 to do 1000 meshes which is a lot slower than I'd like.  It is the combine at the end that is taking so long - without that it's only about 15 seconds.

Marcus, your're close, but what I need to do is bake a dynamics simulation on a bunch of meshes to joints.  So for each mesh in the sim, I need one joint, and I need to essentially copy whatever keyframes are on the mesh to it's corresponding joint.  I have it working, but without the combine, I'm left with individual skinCluster nodes for each mesh, meaning I might have 1000+ skinCluster nodes in my file which I'd like to avoid.

Aren Voorhees

unread,
Nov 5, 2015, 9:35:02 AM11/5/15
to Python Programming for Autodesk Maya
I didn't have much time to try this out yesterday, but I can see what you guys were saying now - 1 mesh = 1 skinCluster node.  So if I want to collapse all those skinClusters into one, I need to merge all the meshes as well.  It's pretty cool that they added the polyUniteSkinned command, as it does what I need, I just wish it was faster.  I wonder if there is a faster way to do it with the python api or C++?  More learning is needed!

The only other idea I had was to create the joints based off the mesh position, then combine the mesh, then create a single skinCluster and one-by-one add the joints...the only trick there would be making sure each "chunk" of the mesh would be skinned 100% to the correct joint.  I'll give a try and report back whatever I figure out!

Nicolas Combecave

unread,
Nov 5, 2015, 9:55:38 AM11/5/15
to python_in...@googlegroups.com
Is there a chance that it's a memory issue?
I wonder if doing polyUniteSkinned 30-50 pieces chunks, and then polyUniteSkinned those intermediates chunks would speed up things. 

--
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.

Aren Voorhees

unread,
Nov 5, 2015, 2:01:54 PM11/5/15
to Python Programming for Autodesk Maya
I will definitely try that out, thanks.
Reply all
Reply to author
Forward
0 new messages