dm2skin.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:dm2skin 作者: duncanskertchly 项目源码 文件源码
def dm2skin_getNeighbouringJoints(joint, vertexString=None, cluster=None, influences=3):
    """This gets a list of nearby joints in the skin cluster to joint up to
    the number of influences. These will be the ones we use in our minimization
    later"""

    if not cmds.objExists(joint):
        return False
    if influences < 3:
        return False
    if not cluster:
        return False

    clusterJoints = cmds.skinCluster(cluster, q=True, inf=True)

    pos1 = cmds.xform(vertexString, q=True, ws=True, t=True)

    parentJoint = cmds.listRelatives(joint, parent=True)

    subtract = 1
    # add the main joint
    resultList = [joint]
    # i've found it works best to always include the parent
    if parentJoint and parentJoint in clusterJoints:
        resultList.insert(0, parentJoint[0])
        subtract = 2

    # for the rest of the available influences get a list of nearby joints in space
    measureList = []
    for measureJnt in clusterJoints:
        if measureJnt not in resultList:
            jntPos2 = cmds.xform(measureJnt, q=True, ws=True, t=True)
            #this just gets the length of the vector between the two joints
            dist = math.sqrt(reduce(lambda x, y: x + y, [math.pow(jntPos2[i] - pos1[i], 2) for i in range(len(pos1))]))
            measureList.append((measureJnt, dist))

    # sort the list in ascending order so we get the closest joints first
    measureList.sort(key=lambda dist: dist[1])
    ascendingList = [entry[0] for entry in measureList[0:influences - subtract]]
    return resultList + ascendingList
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号