Skin Tool UI

Finished a working version of a handy script and UI that allows you to quickly set joint influences on the selected components. This will really come in handy when blocking in weights.

Here’s the code for the UI:

import maya.cmds as cmds
from functools import partial
import bm_skinTools

reload(bm_skinTools)


def jointListCommand(*args):
    # updates our iconTextScrollList to show the joints that are currently affecting the selection
    jointList = bm_skinTools.listJoints(cmds.ls(sl=1, o=1))
    # if nothing is selected, don't update the list
    if not jointList:
        return
    cmds.iconTextScrollList("jointList", e=1, removeAll=1)
    for item in jointList:
        cmds.iconTextScrollList("jointList", e=1, append=item)
    cmds.iconTextScrollList("jointList", e=1, selectIndexedItem=1)


def getJointListSelection(*args):
    # returns the currently selected item in the joint list
    return cmds.iconTextScrollList('jointList', q=1, selectItem=1)


def floodButtonCommand(value=1, *args):
    # floods the selection to be influenced to the currently selected joint in the list by a value of 1
    if not cmds.ls(sl=1) or "." not in cmds.ls(sl=1)[0]:
        cmds.confirmDialog(message="Please Select Components")
        return
    bm_skinTools.setVertexWeight(cmds.ls(sl=1), getJointListSelection()[0], value)
    print str(cmds.ls(sl=1)) + " is now being influenced by " + getJointListSelection()[
        0] + " by a value of %.2f" % value


def launchUI():
    # launches a user interface that will show a list of the joints affecting the selection and some controls
    if cmds.window("skinToolsUI", exists=True):
        cmds.deleteUI("skinToolsUI")
    cmds.window("skinToolsUI", title="bm_SkinToolsUI", tlb=1)
    cmds.columnLayout()
    cmds.text("Joints Affecting Selection:")
    cmds.iconTextScrollList("jointList", w=(200), h=(100))
    jointListCommand()
    cmds.button(label="Update Joint List", command=jointListCommand)
    cmds.text("Flood Selection With Weight Value")
    cmds.gridLayout()
    cmds.button(label="1", backgroundColor=(.75, .1, .1), command=partial(floodButtonCommand, 1))
    cmds.button(label=".5", backgroundColor=(.75, .75, .1), command=partial(floodButtonCommand, .5))
    cmds.button(label="0", backgroundColor=(.2, .2, .75), command=partial(floodButtonCommand, 0))
    cmds.showWindow("skinToolsUI")
    cmds.window("skinToolsUI", e=1, wh=(225, 175), s=0)


And here’s the code for the script that does the leg work:

import maya.cmds as cmds


def setVertexWeight(verticies, joint, value=1, *args):
    """
        Takes the selected components and assigns them the desired weight value to the desired joint
    """
    # check to see if we have any vertices selected
    if not cmds.ls(sl=1) or "." not in cmds.ls(sl=1)[0]:
        return

    # first we'll convert our selection to vertices
    vertices = cmds.polyListComponentConversion(toVertex=1)

    # then get the mesh name from the vertex selection (cmds.ls(sl=1))
    # for instance, pCube1.vtx[0] will return pCube1
    obj = verticies[0][0:verticies[0].index(".")]
    # gives us a list of all the inputs on the object allowing us to find the skin clusters and joints affecting it.
    objHist = cmds.listHistory(obj)
    clusterList = cmds.ls(type="skinCluster")
    cluster = clusterList[0]
    # Checks to find which cluster in the cluster list is the one that is affecting the selected vertices
    for node in clusterList:
        if node in objHist:
            cluster = node

    # now for every vert in that list, apply the designated value
    for vert in verticies:
        cmds.skinPercent(cluster, vert, transformValue=[joint, value])


def listJoints(obj, *args):
    """
        Lists the joints that have an influence on the selected object.
    """
    if len(obj) == 0:
        return
    objHist = cmds.listHistory(obj)
    return cmds.ls(objHist, type="joint")



Advertisements
Image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s