本文介绍了联合重量插值玛雅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何计算在玛雅的脸上点的连接权值。假设我们有一个平面上,我们要计算一下它的重量插值将在在脸上的任意点。我知道在Maya复制皮肤权重工具,这是否插了伟大的工作,但我不知道它背后的数学。

How can you calculate the joint weight values of a point on a face in maya. Say we have a plane and we want to calculate what it's interpolated weight would be at an arbitrary point on the face. I know the copy skin weights tool in maya does a great job of this interpolation, but am not sure of the math behind it.

import maya.cmds as cmds

if __name__ == '__main__':
    # Build two planes. One with no subdivs and one with 2.
    plane = cmds.polyPlane(name="plane_GEO",
                           subdivisionsX=1,
                           subdivisionsY=1,
                           width=10.0,
                           height=10.0)
    planeRef = cmds.polyPlane(name="plane_cn_GEO",
                              subdivisionsX=2,
                              subdivisionsY=2,
                              width=10.0,
                              height=10.0)

    #Move vertices.
    cmds.move(2, 0, 0, "%s.vtx[1]" % planeRef[0], relative=True)
    cmds.move(2, 0, 0, "%s.vtx[4]" % planeRef[0], relative=True)
    cmds.move(2, 0, 0, "%s.vtx[7]" % planeRef[0], relative=True)
    cmds.move(0, 0, 2, "%s.vtx[3:5]" % planeRef[0], relative=True)

    #Make joints.
    cmds.select(clear=True)
    jntA = cmds.joint(name="a_JNT", p=[5, 0, -5])
    cmds.select(clear=True)
    jntB = cmds.joint(name="b_JNT", p=[5, 0, 5])
    cmds.select(clear=True)
    jntC = cmds.joint(name="c_JNT", p=[-5, 0, 5])
    cmds.select(clear=True)
    jntD = cmds.joint(name="d_JNT", p=[-5, 0, -5])
    cmds.select(clear=True)

    #Bind joints.
    skinA = cmds.skinCluster([jntA, jntB, jntC, jntD],
                             plane[0],
                             name='%s_SKNCLUST' % plane[0],
                             toSelectedBones=True,
                             skinMethod=1,
                             normalizeWeights=1)

    skinB = cmds.skinCluster([jntA, jntB, jntC, jntD],
                             planeRef[0],
                             name='%s_SKNCLUST' % planeRef[0],
                             toSelectedBones=True,
                             skinMethod=1,
                             normalizeWeights=1)

    #Copy skin weight for reference of what joint weight is supposed to be.
    cmds.copySkinWeights(sourceSkin=skinA[0],
                         destinationSkin=skinB[0],
                         noMirror=True,
                         surfaceAssociation="closestPoint",
                         influenceAssociation="name")
    #Hide it.
    cmds.setAttr(planeRef[0] + ".visibility", 0)

    #Make a locator at a position.
    loc = cmds.spaceLocator(name="anno_LOC")
    cmds.move(2, 0, 2, loc[0])

    #Make an annotation.
    ano = cmds.annotate(loc[0],
                        tx="What is the joint weight values at this point?",
                        p=[2, 5, 2])
    anoTrans = cmds.listRelatives(ano, parent=True)
    cmds.rename(anoTrans, "weight_ANNOTATE")

这是一个简单的场景展示我的意思在Maya中。但愿它清除了这个念头。

This is a simple scene for showing of what I mean in maya. Hopefully it clears up the idea.

感谢您的帮助。

推荐答案

感谢您joojaa!

从这里得到的功能:http://gamedev.stackexchange.com/questions/23743/whats-the-most-efficient-way-to-find-barycentric-coordinates

转换Python函数:

converted python function:

import maya.OpenMaya as OpenMaya

def barycentricInterp(vecA, vecB, vecC, vecP):
    '''
    Calculates barycentricInterpolation of a point in a triangle.

    :param vecA - OpenMaya.MVector of a vertex point.
    :param vecB - OpenMaya.MVector of a vertex point.
    :param vecC - OpenMaya.MVector of a vertex point.
    :param vecP - OpenMaya.MVector of a point to be interpolated.

    Returns list of 3 floats representing weight values per each point.
    '''
    v0 = vecB - vecA
    v1 = vecC - vecA
    v2 = vecP - vecA

    d00 = v0 * v0
    d01 = v0 * v1
    d11 = v1 * v1
    d20 = v2 * v0
    d21 = v2 * v1
    denom = d00 * d11 - d01 * d01
    v = (d11 * d20 - d01 * d21) / denom
    w = (d00 * d21 - d01 * d20) / denom
    u = 1.0 - v - w

    return [u, v, w]

插值计算酷似copySkinWeights在Maya命令。

Interpolation is calculated exactly like the copySkinWeights command in maya.

这篇关于联合重量插值玛雅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:03