0

Maya 2015 では、次のコマンドを使用してカーブのアークレンを取得できます。

cmds.arclen('bezier1')

しかし今、私は自分の曲線の 2 点の arclen を取得したいと考えています。とにかくこれを取得することはありますか?

4

2 に答える 2

1

Maya API を使用すると、MFnNurbsCurve::findLengthFromParamを使用できます(Maya 2016+ のみ)。2 点間で必要な場合は、各パラメーターでこの関数を呼び出して減算します。

API を使用したくない場合は、元の曲線の複製を作成し、必要なポイントでそれを「デタッチ」してから、その新しい曲線で arclen コマンドを使用して長さを取得します。それは別の方法です。

曲線をデタッチすると、曲率をできるだけ元に近づけようとするように見えますが、これは正確ではないため、元の曲線と比較して長さが同じではない可能性があることに注意してください。より多くのポイントを持つように曲線を再構築すると、それが重要な要素である場合、精度が向上する可能性があります。

于 2016-11-09T06:15:59.940 に答える
0

@scottiedooが言ったように、MayaのAPIを使用することは確かにそれを行うための最良の方法ですが、これは私が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
于 2016-11-17T11:31:38.540 に答える