Skinning

Bind Skin

Functions for skin binding

Examples # bindskin hierarchy (closest distance) from zoo.libs.maya.cmds.skin import bindskin bindskin.bindSkinSelected(toSelectedBones=False, maximumInfluences=5, maxEditLimit=5, bindMethod=0, displayMessage=True)

# bindskin selected (closest distance) from zoo.libs.maya.cmds.skin import bindskin bindskin.bindSkinSelected(toSelectedBones=True, maximumInfluences=5, maxEditLimit=5, bindMethod=0, displayMessage=True)

# bindskin selected rigid bind (closest distance) from zoo.libs.maya.cmds.skin import bindskin bindskin.bindSkinSelected(toSelectedBones=True, maximumInfluences=0, maxEditLimit=5, bindMethod=0, displayMessage=True)

# bind skin heat map from zoo.libs.maya.cmds.skin import bindskin bindskin.bindSkinSelected(bindMethod=2)

#bind skin geodesic from zoo.libs.maya.cmds.skin import bindskin bindskin.bindSkinSelected(bindMethod=3)

# mirror x to -x from zoo.libs.maya.cmds.skin import bindskin bindskin.mirrorSkinSelection(mirrorMode=’YZ’, mirrorInverse=False)

# mirror -x to x from zoo.libs.maya.cmds.skin import bindskin bindskin.mirrorSkinSelection(mirrorMode=’YZ’, mirrorInverse=True)

# remove influence from zoo.libs.maya.cmds.skin import bindskin bindskin.removeInfluenceSelected()

# transfer skin weights zoo from zoo.libs.maya.cmds.skin import bindskin bindskin.transferSkinWeightsSelected()

# add joints to skin cluster from zoo.libs.maya.cmds.skin import bindskin bindskin.addJointsToSkinnedSelected()

# unbind skin from zoo.libs.maya.cmds.skin import bindskin bindskin.unbindSkinSelected()

# duplicate mesh before bind - orig shape duplicate from zoo.libs.maya.cmds.skin import bindskin bindskin.duplicateSelectedBeforeBind()

# change skin method to weight belnded (dual quat) from zoo.libs.maya.cmds.skin import bindskin bindskin.skinClusterMethodSwitch(skinningMethod=2, displayMessage=True)

# copy skin weights to the clipboard (mesh name is cpied and must be in scene for paste) from zoo.libs.maya.cmds.skin import bindskin bindskin.copySkinWeightsSel()

# paste skin weights from the copied mesh, see copySkinWeightsSel() from zoo.libs.maya.cmds.skin import bindskin bindskin.pasteSkinWeightsSel()

hammerWeights()
getAllSkinClusters(displayMessage=False)

Returns all valid skin clusters in a scene

Parameters:

displayMessage (bool) – Report the message inside of maya?

Return skinClusterList:

List of the skin cluster node names

Rtype skinClusterList:

list

checkValidOrigShape(mesh, deleteDeadShapes=False, displayMessage=False)

Checks for valid orig shape nodes, by checking if multiple orig shapes are present or that the object isn’t skinned or has no orig shape nodes returns the the orig shape node name or None on fail

Parameters:
  • mesh (str) – the object name to check

  • displayMessage (bool) – Report the message inside of maya?

Return originalShape:

The original shape node returned

Return type:

str

checkValidOrigShapeList(meshList, deleteDeadShapes=False, displayMessage=False)

List version of the function checkValidOrigShape

Parameters:
  • meshList – list of mesh objects

  • deleteDeadShapes (bool) – delete any dead original nodes while checking?

  • displayMessage (bool) – Report the message inside of maya?

Return origShapeList:

list of original shape nodes (intermediate objects)

Rtype origShapeList:

list

cleanDeadOrigShapesSelected(displayMessage=True)

Cleans the unused original shape nodes from selected mesh Nodes are likely intermediate objects with no output connections, usually left over and unused nodes

Parameters:

displayMessage (bool) – Report the message inside of maya?

duplicateMeshBeforeBind(mesh, fullPath=True, suffix='_duplicate', message=True, deleteDeadShapes=False, transferShader=True)

Given a mesh will duplicate it ignoring the skinning, does this via the original shape node. Will fail if mesh isn’t skinned or no orig node

Parameters:
  • mesh (str) – The mesh name to be duplicated

  • fullPath (bool) – return full path names not short

  • suffix (str) – The suffix to add to the duplicated mesh

  • message (bool) – Report the message inside of maya?

  • transferShader (bool) – Transfer the shader from the skinned mesh so that the new duplicate matches?

Return duplicateMesh:

the name of the duplicated mesh

Return type:

str

duplicateSelectedBeforeBind(fullPath=True, suffix='_duplicate', message=True, selectDuplicate=True, transferShader=True)

Duplicates selected mesh/es before a skin cluster has been added, pre bind. Will fail if no skinning is present. Works by finding the original shape node and duplicating it

Parameters:
  • fullPath (bool) – return full path names not short

  • suffix (str) – The suffix to add to the duplicated mesh

  • message (bool) – Report the message inside of maya?

  • transferShader (bool) – Transfer the shader from the skinned mesh so that the new duplicate matches?

Return duplicatedMeshes:

a list of the duplicated mesh names

Return type:

list

combineSkinnedMeshes(objList, constructionHistory=False, centerPivot=True, mergeUVSets=True)

Combines meshes that have been skinned, joins them into one skinned object.

Parameters:
  • objList (list(str)) – A list of mesh objects

  • constructionHistory (bool) – Delete the construction history?

  • centerPivot (bool) – Center the pivot after combine

  • mergeUVSets (bool) – Merge the UV sets?

Return mesh:

The combined mesh name

Rtype mesh:

str

Return skinCluster:

The combined skin cluster name

Rtype skinCluster:

str

combineSkinnedMeshesSelected(constructionHistory=False, centerPivot=True, mergeUVSets=True, message=True)

Combines selected meshes that have been skinned, joins them into one skinned object.

Parameters:
  • constructionHistory (bool) – Delete the construction history?

  • centerPivot (bool) – Center the pivot after combine

  • mergeUVSets (bool) – Merge the UV sets?

  • message (True) – Report a message to the user?

Returns:

Return type:

getSkinCluster(obj)

Checks if the given object has a skin cluster using mel, (doesn’t have a python equivalent). Long or short names must be converted to unique names, see namehandling.getUniqueShortName() documentation Returns empty string if no skin cluster found on object

Parameters:

obj (str) – Maya obj name, usually a transform node, best if a long or unique name

Return skinCluster:

The name of the skin cluster, or if not found/skinned will be an empty string “”

Rtype skinned:

str

getSkinClusterList(objList)

Returns a list of skin clusters from an objList

Parameters:

objList (list) – Maya obj name list

Return skinClusterList:

list of skin clusters

Rtype skinClusterList:

list

getSkinClustersSelected()

Find all the skin clusters related to selected objects (transforms) Works off the first shape node and selected must be the transform/s

getJnts(objList)

returns only joints from an object list

Parameters:

objList (list) – list of object names

Return jntList:

List of joint names

Rtype jntList:

list

getSkinClusterFromJoint(joint)

Returns all skin clusters connected to a single joint

Parameters:

joint (str) – A single joint name

Return skinClusterList:

A list of skin clusters, will be empty if none found

Rtype skinClusterList:

list(str)

getSkinClustersFromJoints(jointList)

Returns all skin clusters connected to a joint list

Parameters:

jointList (list(str)) – A list of Maya joint names

Return skinClusterList:

A list of skin clusters, will be empty if none found

Rtype skinClusterList:

list(str)

filterSkinnedJoints(jointList)

Returns all skinned joints from a joint list. Found by seeing connected skin clusters to joint.worldMatrix

Parameters:

jointList (list(str)) – A list of joints

Return skinnedJointList:

A list of skinned joints

Rtype skinnedJointList:

list(str)

filterSkinnedMeshes(objList)

Returns meshes that are skinned from a list

Parameters:

objList (list) – list of Maya object names

Return skinnedMeshes:

list of skinned meshes

Rtype skinnedMeshes:

list

filterMeshes(objList, skinned=False)

Returns meshes/surfaces and joints that are ready for skinning from the list of objects

Tests for issues and reports errors

Parameters:

objList (list(str)) – list of maya objects/nodes

Return meshList:

list of mesh names, empty list if none

Rtype meshList:

list(str)

filterObjsForSkin(objList)

Returns meshes/surfaces/curves and joints that are ready for skinning from the list of objects

Tests for issues and reports errors

Parameters:

skinningMethod (int) – 0 = classic linear, 1 = dual quaternion, 2 = weight blended

Returns:

List of joint names and a list of mesh/surface or nurbs curve names

Return type:

tuple(list(str), list(str))

skinClusterMethodSwitch(skinningMethod=2, displayMessage=True)

Switches the attribute .skinningMethod for all skinClusters on selected objects

Parameters:
  • skinningMethod (int) – 0 = classic linear, 1 = dual quaternion, 2 = weight blended

  • displayMessage (bool) – Report the message inside of maya?

unbindSkinObjs(objList)

Python version of Maya’s unbind skin, this function is for an object list

unbindSkinSelected()

python version of unbind skin on selected

bindSkin(joints, meshes, toSelectedBones=True, maximumInfluences=5, maxEditLimit=5, bindMethod=0, displayMessage=True)

Skins meshes to joints based with skin variables

Parameters:
  • toSelectedBones (bool) – on binds to selected off binds to hierarchy

  • maxInfluences (int) – 5 is default, 1 is a rigid bind, limits the amount of joint influences

  • maxEditLimit (int) – is after the weights have been assigned so influences can be set differently for skin editing

  • bindMethod (int) – closest distance = 0, hierarchy = 1, heat = 2 and geodesic = 3

  • displayMessage (bool) – Report the message inside of maya?

bindSkinSelected(toSelectedBones=True, maximumInfluences=5, maxEditLimit=5, bindMethod=0, displayMessage=True)

Binds skin to mesh or meshes based off selection similar to the regular Maya behaviour. No in built cmds version

Parameters:
  • toSelectedBones (bool) – on binds to selected off binds to hierarchy

  • maxInfluences (int) – 5 is default, 1 is a rigid bind, limits the amount of joint influences

  • maxEditLimit (int) – is after the weights have been assigned so influences can be set differently for skin editing

  • displayMessage (bool) – Report the message inside of maya?

Param:

bindMethod: 0 = distance = 1 = hierarchy, 2 = heat, 3 = geodesic

setMaxInfluencesOnSkinCluster(skinCluster, maxInfluences=4)

for a skin cluster set the max influences and turn maintain on

Parameters:
  • skinCluster (str) – skin cluster name

  • maxInfluences (bool) – the max influences

setMaxInfluencesOnSkinClusterList(skinClusterList, maxInfluences=4)
setMaxInfluencesOnSkinSelected(maxInfluences=4)
checkInfluenceObj(obj, skinCluster)

Checks if an object is an influece of a skin cluster

Parameters:
  • obj (str) – Maya obj name

  • skinCluster (str) – skin cluster name

Return influence:

True if the object is an influence

Rtype influence:

bool

renameSelSkinClusters(suffix='skin')

Renames the skin clusters based off the selected object

Parameters:

suffix (str) – skin cluster of pCube1 will be named pCube1_skin

removeInfluence(objList, skinCluster)

Removes Influence Objects from a Skin Cluster Checks if influences are valid Returns object list of influences removed

Parameters:
  • objList – the list of influence objects to be removed

  • skinCluster (str) – The skin luster name

Return removedInfluenceList:

list of influence objects removed

Return type:

list

removeInfluenceSelected()

Removes influence objects from a skinned mesh. Last selected object should be the skinned mesh, other objects are the influences Will check for user error

addJointsToSkinned(jointList, skinClusterList)

Adds joints as new influences to a skin cluster Select the mesh/es with skin cluster and the joints to assign jnts are assigned with zero weighting and do not affect existing weights

should check this no need for try

addJointsToSkinnedSelected(displayMessage=True)

Adds joints to a skinned mesh, keeps the joints with a zero influence value

Parameters:

displayMessage (bool) – Report the message inside of maya?

disableSkinCluster(skinCluster)

Disables a single skin cluster

Parameters:

skinCluster (str) – A single skin cluster name

disableSkinClusterList(skinClusterList, displayMessage=True)

Disables a skin cluster list turning the node state to hasNoEffect (1)

Parameters:
  • skinClusterList (list) – List of the skin cluster node names

  • displayMessage (bool) – Report the message inside of maya?

renableSkinCluster(skinCluster)

Renables a disabled skin cluster by rebinding it, only works in mel, Maya trick.

Might be able to use resetInfluenceMatrices(skinCluster) instead

Parameters:

skinCluster (str) – A single skin cluster name

resetInfluenceMatrices(skinCluster)

Set bindPreMatrix the same as current worldInverseMatrix for each influence of given skinCluster

Credit http://syntetik.blogspot.com/2010/10/bindprematrix-in-skincluster.html

Parameters:

skinCluster (str) – A single skin cluster name

renableSkinClusterList(skinClusterList, displayMessage=True, keepSelection=True)

Re enables a skin cluster list that have previously had their nodestate set to hasNoEffect (1)

Parameters:
  • skinClusterList (list) – List of the skin cluster node names

  • displayMessage (bool) – Report the message inside of maya?

  • keepSelection (bool) – Keep the selection? Needed as te .mel eval requires selection

toggleSkinCluster(skinCluster)

Toggles a single skin cluster node

Parameters:

skinCluster (str) – A single skin cluster name

toggleSkinClusterList(skinClusterList, displayMessage=True)

Toggles on/off a skin cluster list. Toggles off the state of the first skin cluster.

Parameters:
  • skinClusterList (list(str)) – A list of skinCluster names

  • displayMessage (bool) – Report the message to the user?

toggleSkinClusterListSelected(displayMessage=True)

Toggles on/off the selected skin clusters from a mesh selection.

Toggles off the state of the first skin cluster.

Parameters:

displayMessage (bool) – Report the message to the user?

toggleAllSkinClusters(displayMessage=True)

Toggles all skin clusters in a scene Handy for quick move pivots on joints Uses the nodeState attribute on the cluster

  1. Switching the nodestate to 1 (hasNoEffect) disables the skin cluster like a temp skin unbind without data loss

  2. Maya trick by selecting any joint and the mesh of the existing skin cluster and > bind skin

  3. Will return the cluster on skinning essentially skinning it at the current mesh/joint position

copySkinWeightsSel(message=True)

Copies a skinned mesh and tracks it with a class singleton so it can be pasted later.

Parameters:

message (bool) – Report a message to the user?

Returns:

The skinned mesh as a transform node. If None found returns “”

Return type:

str

pasteSkinWeightsSel(message=True)

Pastes the skinning from the copied mesh (in singleton skinInstance.copiedSkinMesh) to selected geo.

The new selection can be meshes or faces/verts/edges.

Parameters:

message (bool) – Report messages to the user?

Returns:

The pasted skin cluster names, or empty list if failed.

Return type:

list(str)

transferSkinning(sourceMesh, targetMesh)

Transfers skin weights from the source mesh to the target, if the target already has a skin cluster will use the current

Parameters:
  • sourceMesh (str) – the mesh that already has the skin weights

  • targetMesh (str) – the mesh that will have the skin weights copied onto it

Return targetSkinCluster:

the skinCluster created or transferred onto

Rtype targetSkinCluster:

str

transferSkinWeightsSelected()

Transfers skin weights from the first selected object to other objects iterates through a list so the transfer is from the first object selected to all other objects

mirrorSkinClusterList(skinClusterList, surfaceAssociation='closestPoint', influenceAssociation='closestJoint', mirrorMode='YZ', mirrorInverse=False)

Mirrors Skin Clusters

Parameters:
  • surfaceAssociation (str) – which surface style to mirror, “closestPoint”, “rayCast”, or “closestComponent”

  • influenceAssociation (str) – choose joint style to mirror “closestJoint”, “closestBone”, “label”, “name”, “oneToOne”

  • mirrorMode (str) – which plane to mirror over, XY, YZ, or XZ

  • mirrorInverse (bool) – Reverse the direction of the mirror. if true - to +

mirrorSkinMeshList(objList, surfaceAssociation='closestPoint', influenceAssociation='closestJoint', mirrorMode='YZ', mirrorInverse=False)

Mirrors Skin Weights from skin clusters connected to the objects in the objList

Parameters:
  • objList (list) – List of Maya Object Names

  • surfaceAssociation (str) – which surface style to mirror, “closestPoint”, “rayCast”, or “closestComponent”

  • influenceAssociation (str) – choose joint style to mirror “closestJoint”, “closestBone”, “label”, “name”, “oneToOne”

  • mirrorMode (str) – which plane to mirror over, XY, YZ, or XZ

  • mirrorInverse (bool) – Reverse the direction of the mirror. if true - to +

Return skinClusterList:

list of the skin clusters mirrored

Rtype skinClusterList:

list

mirrorSkinSelection(surfaceAssociation='closestPoint', influenceAssociation='closestJoint', mirrorMode='YZ', mirrorInverse=False)

Mirrors Skin Weights from skin clusters assigned to the current meshes or joints Selections as object transforms

Parameters:
  • surfaceAssociation (str) – which surface style to mirror, “closestPoint”, “rayCast”, or “closestComponent”

  • influenceAssociation (str) – choose joint style to mirror “closestJoint”, “closestBone”, “label”, “name”, “oneToOne”

  • mirrorMode (str) – which plane to mirror over, XY, YZ, or XZ

  • mirrorInverse (bool) – Reverse the direction of the mirror. if true - to +

class ZooSkinTrackerSingleton(*args, **kwargs)

Bases: object

Keeps track of copied skin data.

Skin Replace Joints

from zoo.libs.maya.cmds.skin import skinreplacejoints skinreplacejoints.replaceJointsMatrixSuffix(boundText=”oldJnt”, replaceText=”newJnt”, prefix=False, message=True)

replaceSkinMatrixJoint(boundJoint, replaceJoint, message=True)

Swaps the binding of a joint and replaces the bind to another joint.

Useful while swapping the skinning from one skeleton to another.

The skinning is swapped based on the matrix positions, so if the joint is in new locations the mesh may move.

Parameters:
  • boundJoint (str) – The joint with the skinning, to be replaced

  • replaceJoint (str) – The new joint that will receive the skinning

replaceSkinJointMatrixList(boundJoints, replaceJoints, filterSkinnedJoints=True, message=False)

Swaps the binding of a list of joints and replaces the bind to another list of joints.

Useful while swapping the skinning from one skeleton to another.

The skinning is swapped based on the matrix positions, so if joints are in new locations the mesh may move.

Parameters:
  • boundJoints (list(str)) – A list of joints bound to a skin cluster

  • replaceJoints (list(str)) – A list of joints to be switched to connect to the skin cluster

  • message (bool) – Report the message to the user

replaceSkinJoints(obj, old_jnts, new_jnts)

Swaps the binding of a list of joints and replaces the bind to another list of joints. (untested)

Uses maya’s cmds.skinPercent(“skinCluster1”, tmw=[old, new]) to do the transfer

from https://stackoverflow.com/questions/53635659/how-to-transfer-skin-weights-from-one-bone-to-another-via-python

replaceJointsMatrixSuffix(boundText='oldJnt', replaceText='newJnt', prefix=False, message=True)

Swaps the binding of a list of joints and replaces the bind to another list of joints from scene suffix/prefix.

Parameters:
  • boundText (str) – The suffix/prefix of the existing joints

  • replaceText (str) – The suffix/prefix of the new joints

  • prefix (bool) – If True will be the prefix otherwise suffix

  • message (bool) – Report a message to the user?

Return success:

True if the transfer was successful

Rtype success:

bool

replaceJointsMatrixSel(message=True)

Swaps the binding of the first half of selected joints and replaces them with the binding of the second half.

Parameters:

message (bool) – Report a message to the user?