Beispiel #1
0
def set_weights(skin, data, prune=False):
    """Set an skin cluster with weight data.

    Args:
        skin: Skin cluster node or mobject
        data: Weight data specifically in the format `get_weights` returns
        prune: Remove unused influences from the skin cluster

    Returns:
        None
    """
    influences = get_skin_influences(skin)
    influences_remapped = {v: k for k, v in influences.items()}
    mfn_skin = oma2.MFnSkinCluster(skin)
    for vert, weights in data:
        weight_list_index_attr = '{skincluster}.weightList[{vertId}]'.format(
            skincluster=mfn_skin.name(), vertId=vert)
        for influence, weight_value in weights:
            influence_logical_index = influences_remapped[influence]
            weights_attr = '.weights[{influenceId}]'.format(
                influenceId=influence_logical_index)
            cmds.setAttr(weight_list_index_attr + weights_attr, weight_value)
    if prune:
        skin_name = om2.MFnDependencyNode(skin).name()
        skin_geo = om2.MFnDependencyNode(
            oma2.MFnGeometryFilter(skin).getOutputGeometry()[0]).name()
        cmds.skinPercent(skin_name, skin_geo, nrm=False, prw=0)
Beispiel #2
0
def getBaseGeometryIndexFromDeformer(deformer, base):
    """

    :param deformer:
    :param base:
    :return:
    """
    mDeformObj = transformUtils.getmObject(deformer)
    if cmds.objectType(base) == "transform":
        base = cmds.listRelatives(base, s=True, ni=True, pa=True)[0]
    baseObj = transformUtils.getmObject(base)

    deformFn = OpenMayaAnim2.MFnGeometryFilter(mDeformObj)
    geoIndex = deformFn.indexForOutputShape(baseObj)
    return geoIndex