Skip to content

Instantly share code, notes, and snippets.

@jhoolmans
Created February 24, 2014 19:49
Show Gist options
  • Select an option

  • Save jhoolmans/9195634 to your computer and use it in GitHub Desktop.

Select an option

Save jhoolmans/9195634 to your computer and use it in GitHub Desktop.

Revisions

  1. jhoolmans created this gist Feb 24, 2014.
    38 changes: 38 additions & 0 deletions softCluster.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    import maya.cmds as mc
    import maya.OpenMaya as om

    def softSelection():
    selection = om.MSelectionList()
    softSelection = om.MRichSelection()
    om.MGlobal.getRichSelection(softSelection)
    softSelection.getSelection(selection)

    dagPath = om.MDagPath()
    component = om.MObject()

    iter = om.MItSelectionList( selection,om.MFn.kMeshVertComponent )
    elements = []
    while not iter.isDone():
    iter.getDagPath( dagPath, component )
    dagPath.pop()
    node = dagPath.fullPathName()
    fnComp = om.MFnSingleIndexedComponent(component)

    for i in range(fnComp.elementCount()):
    elements.append([node, fnComp.element(i), fnComp.weight(i).influence()] )
    iter.next()
    return elements


    def createSoftCluster():
    softElementData = softSelection()
    selection = ["%s.vtx[%d]" % (el[0], el[1])for el in softElementData ]

    mc.select(selection, r=True)
    cluster = mc.cluster(relative=True)

    for i in range(len(softElementData)):
    mc.percent(cluster[0], selection[i], v=softElementData[i][2])
    mc.select(cluster[1], r=True)

    createSoftCluster()