如何在Maya中获得两个曲线点之间的圆弧



在Maya 2015中,我可以使用以下命令获得曲线的圆弧:

cmds.arclen('bezier1')

但是现在我想要得到曲线上两点的圆弧。有办法拿到这个吗?

使用Maya API,您可以使用MFnNurbsCurve::findLengthFromParam (Maya 2016+ only)。如果在两点之间需要,则使用每个参数调用此函数并相减。

如果你不想使用api,那么另一个选择是创建原始曲线的副本,并在需要的点上使用"detach",然后在新曲线上使用arclen命令来获得你的长度。这是另一种方法

请注意,当分离曲线时,它似乎试图保持曲率尽可能接近原始曲线,但这并不准确,因此长度可能与原始曲线不同。也许重建曲线以获得更多的点可能会提高准确性,如果这对你来说是一个重要的因素。

使用Maya的API肯定是最好的方法,正如@scottiedoo所说,但这里是我不知道API时所做的函数,它会给你相同的结果。

from maya import cmds
def computeCrvLength(crv, startParam = None, endParam = None):
    '''
    Compute the length of a curve between the two given UParameters. If the both
    UParameters arguments are set to None (default), will compute the length of
    the whole curve.
    Arguments:
    - crv = string; an existing nurbCurve
    - startParam = 0 <= float <= 1 or None; default = None; point parameter
      value, if not None, will compute the points only between the startPt and
      EndPt values.
    - endParam = 0 <= float <= 1 or None; default = None; point parameter
      value, if not None, will compute the points only between the startPt and
      EndPt values.
    Returns:
    - The length of the curve between the given UParameters
    - The length of the curve from its start to the startParam
    - The length of the curve from its start to the endParam
    '''
    ###### Exceptions
    if cmds.objExists(crv) == False:
        cmds.error ('The curve "%s" does'nt exists.' % crv)
    if cmds.filterExpand (crv, sm = 9) == None:
        cmds.error ('The object "%s" is not a nurbCurve.' % crv)
    if startParam != None:
        if (0 <= startParam <= 1) == False:
            cmds.error ('The start point parameter value must be between 0 and 1.')
    if endParam != None:
        if (0 <= endParam <= 1) == False:
            cmds.error ('The end point parameter value must be between 0 and 1.')
    if (startParam == None and endParam != None) or (startParam != None and endParam == None):
        cmds.error ('The start and end points parameters must be both None or ' + 
                    'both have values.')
    if startParam != None and endParam != None:
        if endParam < startParam:
            cmds.error ('The end point parameter value cannot be less or ' + 
                        'equal to start point parameter value.')
    ###### Function
    if startParam == None and endParam == None:
        crvLength = cmds.arclen (crv, ch = False)
        distCrvToStartParam = 0
        distCrvToEndParam = crvLength
    else:
        tmpArclenDim = cmds.arcLengthDimension (cmds.listRelatives(crv, s = True)[0]
                                                + '.u[0]')
        cmds.setAttr (cmds.listRelatives(tmpArclenDim, p = True)[0] +
                      '.uParamValue', startParam)
        distCrvToStartParam = cmds.getAttr (tmpArclenDim + '.al')
        cmds.setAttr (cmds.listRelatives(tmpArclenDim, p = True)[0] +
                      '.uParamValue', endParam)
        distCrvToEndParam = cmds.getAttr (tmpArclenDim + '.al')
        cmds.delete (tmpArclenDim)
        crvLength = (distCrvToEndParam - distCrvToStartParam)
    return crvLength, distCrvToStartParam, distCrvToEndParam

相关内容

  • 没有找到相关文章

最新更新