마야 2015 년,이 명령을 사용하여 곡선의 arclen를 얻을 수 있습니다. 이걸 얻기 위해 어쨌든 있습니까?Maya에서 두 커브 점 사이에 arclen을 얻는 방법은 무엇입니까?</p> <pre><code>cmds.arclen('bezier1') </code></pre> <p>을하지만 지금은 내 곡선에서 두 점의 arclen을 얻으려면 :
0
A
답변
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
1
Maya API를 사용하면 MFnNurbsCurve::findLengthFromParam (Maya 2016 이상)을 사용할 수 있습니다. 두 점 사이에 필요하면 각 매개 변수로이 함수를 호출하고 빼십시오.
api를 사용하지 않으려면 다른 옵션은 원래 곡선의 복제본을 만들고 필요한 점에서이를 "분리"한 다음이 새로운 곡선에 arclen 명령을 사용하여 길이. 그래서 그것은 다른 방법입니다.
커브를 분리 할 때 곡률을 가능한 한 원본에 가깝게 유지하려고 시도하지만 정확한 길이가 아니므로 길이가 원래 커브와 같지 않을 수 있습니다. 커브를 다시 작성하여 포인트가 더 많아지면 이것이 중요한 요소 인 경우 정확도를 높일 수 있습니다.
응답 해 주셔서 감사합니다. 그렇다면 Maya2015에는 이러한 api가 없습니까? –
문서를 보면 그렇게 보이지 않습니다. 직접 작성할 수도 있지만 b- 스플라인 길이를 대략적으로 연구하면 좀 더 복잡해집니다. – scottiedoo