本文整理匯總了Python中maya.OpenMaya.MFnNurbsCurve方法的典型用法代碼示例。如果您正苦於以下問題:Python OpenMaya.MFnNurbsCurve方法的具體用法?Python OpenMaya.MFnNurbsCurve怎麽用?Python OpenMaya.MFnNurbsCurve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.OpenMaya
的用法示例。
在下文中一共展示了OpenMaya.MFnNurbsCurve方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getCurveFn
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def getCurveFn(self):
inputCurvePlug = OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputCurveAttr)
curve = getSingleSourceObjectFromPlug(inputCurvePlug)
# Get Fn from a DAG path to get the world transformations correctly
if curve is not None:
path = OpenMaya.MDagPath()
trFn = OpenMaya.MFnDagNode(curve)
trFn.getPath(path)
path.extendToShape()
if path.node().hasFn(OpenMaya.MFn.kNurbsCurve):
return OpenMaya.MFnNurbsCurve(path)
return None
# Calculate expected instances by the instancing mode
示例2: asMFnNurbsCurve
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def asMFnNurbsCurve(curve):
"""
Convert a node into a OpenMaya.MFnNurbsCurve.
:param str node:
:return: MFnNurbsCurve of parsed curve
:rtype: OpenMaya.MFnNurbsCurve
"""
dag = toMDagPath(curve)
nurbsCurveFn = OpenMaya.MFnNurbsCurve(dag)
return nurbsCurveFn
示例3: getCurveParamAtPosition
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def getCurveParamAtPosition(crv, position):
"""Get curve parameter from a position
Arguments:
position (list of float): Represents the position in worldSpace
exp: [1.4, 3.55, 42.6]
crv (curve): The source curve to get the parameter.
Returns:
list: paramenter and curve length
"""
point = om.MPoint(position[0], position[1], position[2])
dag = om.MDagPath()
obj = om.MObject()
oList = om.MSelectionList()
oList.add(crv.name())
oList.getDagPath(0, dag, obj)
curveFn = om.MFnNurbsCurve(dag)
length = curveFn.length()
crv.findParamFromLength(length)
paramUtill = om.MScriptUtil()
paramPtr = paramUtill.asDoublePtr()
point = curveFn.closestPoint(point, paramPtr, 0.001, om.MSpace.kObject)
curveFn.getParamAtPoint(point, paramPtr, 0.001, om.MSpace.kObject)
param = paramUtill.getDouble(paramPtr)
return param, length
示例4: editCurve
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def editCurve(parent, points, degree=1, form=kOpen):
assert isinstance(parent, DagNode), (
"parent must be of type cmdx.DagNode"
)
degree = min(3, max(1, degree))
cvs = om1.MPointArray()
curveFn = om1.MFnNurbsCurve()
for point in points:
cvs.append(om1.MPoint(*point))
mobj = curveFn.createWithEditPoints(cvs,
degree,
form,
False,
False,
True,
_encode1(parent.path()))
mod = om1.MDagModifier()
mod.renameNode(mobj, parent.name(namespace=True) + "Shape")
mod.doIt()
def undo():
mod.deleteNode(mobj)
mod.doIt()
def redo():
mod.undoIt()
commit(undo, redo)
shapeFn = om1.MFnDagNode(mobj)
return encode(shapeFn.fullPathName())
示例5: NurbsCurveData
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def NurbsCurveData(points, degree=1, form=om1.MFnNurbsCurve.kOpen):
"""Tuple of points to MObject suitable for nurbsCurve-typed data
Arguments:
points (tuple): (x, y, z) tuples per point
degree (int, optional): Defaults to 1 for linear
form (int, optional): Defaults to MFnNurbsCurve.kOpen,
also available kClosed
Example:
Create a new nurbs curve like this.
>>> data = NurbsCurveData(
... points=(
... (0, 0, 0),
... (0, 1, 0),
... (0, 2, 0),
... ))
...
>>> parent = createNode("transform")
>>> shape = createNode("nurbsCurve", parent=parent)
>>> shape["cached"] = data
"""
degree = min(3, max(1, degree))
cvs = om1.MPointArray()
curveFn = om1.MFnNurbsCurve()
data = om1.MFnNurbsCurveData()
mobj = data.create()
for point in points:
cvs.append(om1.MPoint(*point))
curveFn.createWithEditPoints(cvs,
degree,
form,
False,
False,
True,
mobj)
return mobj
示例6: compute
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def compute(self, plug, dataBlock):
if plug == closestPointOnCurve.aOutPosition or plug == closestPointOnCurve.aOutParam:
dataHandle = dataBlock.inputValue(closestPointOnCurve.aInCurve)
inputAsCurve = dataHandle.asNurbsCurve()
#if not inputAsCurve.hasFn(OpenMaya.MFn.kNurbsCurve):
# return OpenMaya.kUnknownParameter
dataHandle = dataBlock.inputValue(closestPointOnCurve.aInPosition)
inPositionAsFloat3 = dataHandle.asFloat3()
inPosition = OpenMaya.MPoint(
inPositionAsFloat3[0],
inPositionAsFloat3[1],
inPositionAsFloat3[2]
)
# connect the MFnNurbsCurve
# and ask the closest point
nurbsCurveFn = OpenMaya.MFnNurbsCurve(inputAsCurve)
# get and set outPosition
outParam = OpenMaya.MScriptUtil()
outParam.createFromDouble(0)
outParamPtr = outParam.asDoublePtr()
# get position and paramater
outPosition = nurbsCurveFn.closestPoint(
inPosition, True, outParamPtr, 0.001, OpenMaya.MSpace.kWorld
)
outputHandle = dataBlock.outputValue(
closestPointOnCurve.aOutPosition
)
outputHandle.set3Float(outPosition.x, outPosition.y, outPosition.z)
# get and set outNormal
#outNormal = nurbsCurveFn.normal(parameter, OpenMaya.MSpace.kWorld)
#outputHandle = dataBlock.outputValue(closestPointOnCurve.aOutNormal)
#outputHandle.set3Float(outNormal.x, outNormal.y, outNormal.z)
#outputHandle.set3Float(0, 1, 0 )
# get and set the uvs
outputHandle = dataBlock.outputValue(closestPointOnCurve.aOutParam)
#outputHandle.setFloat(OpenMaya.MScriptUtil(outParamPtr).asDouble())
outputHandle.setFloat(OpenMaya.MScriptUtil.getDouble(outParamPtr))
dataBlock.setClean(plug)
else:
return OpenMaya.kUnknownParameter
# creator
示例7: getRotationForParam
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def getRotationForParam(self, param, axisHandlesSorted, curveForm, curveMaxParam):
indexRange = (-1, -1)
wrapAround = not (curveForm is OpenMaya.MFnNurbsCurve.kOpen)
# Find the range of indices that make up this curve segment
for i in xrange(len(axisHandlesSorted)):
# TODO: could use a binary search
if param < axisHandlesSorted[i][1]:
if i > 0:
indexRange = (i - 1, i)
break
elif wrapAround:
indexRange = (len(axisHandlesSorted) - 1, 0)
break
else:
indexRange = (0, 0)
break
# Edge case
if indexRange[0] == -1 and indexRange[1] == -1 and len(axisHandlesSorted) > 0:
if wrapAround:
indexRange = (len(axisHandlesSorted) - 1, 0)
else:
indexRange = (len(axisHandlesSorted) - 1, len(axisHandlesSorted) - 1)
# Now find the lerp value based on the range
if indexRange[0] > -1 and indexRange[1] > -1:
minParam = axisHandlesSorted[indexRange[0]][1]
maxParam = axisHandlesSorted[indexRange[1]][1]
minAxis = axisHandlesSorted[indexRange[0]][2]
maxAxis = axisHandlesSorted[indexRange[1]][2]
if(math.fabs(minParam - maxParam) > 0.001):
if minParam > maxParam and wrapAround:
if param < maxParam:
param = param + curveMaxParam
maxParam = maxParam + curveMaxParam
t = min(max((param - minParam) / (maxParam - minParam), 0.0), 1.0)
return minAxis + (maxAxis - minAxis) * t
return minAxis
return 0.0
示例8: compute
# 需要導入模塊: from maya import OpenMaya [as 別名]
# 或者: from maya.OpenMaya import MFnNurbsCurve [as 別名]
def compute(self, plug, dataBlock):
try:
curveDataHandle = dataBlock.inputValue(instanceAlongCurveLocator.inputCurveAttr)
curve = curveDataHandle.asNurbsCurveTransformed()
updateTranslation = (plug == instanceAlongCurveLocator.outputTranslationAttr.compound)
updateRotation = (plug == instanceAlongCurveLocator.outputRotationAttr.compound)
updateScale = (plug == instanceAlongCurveLocator.outputScaleAttr.compound)
if not curve.isNull():
if updateTranslation or updateRotation or updateScale:
curveFn = OpenMaya.MFnNurbsCurve(curve)
instanceCount = self.getInstanceCountByMode()
distOffset = dataBlock.inputValue(instanceAlongCurveLocator.distOffsetAttr).asFloat()
curveLength = curveFn.length()
# Curve thresholds
curveStart = dataBlock.inputValue(instanceAlongCurveLocator.curveStartAttr).asFloat() * curveLength
curveEnd = dataBlock.inputValue(instanceAlongCurveLocator.curveEndAttr).asFloat() * curveLength
effectiveCurveLength = min(max(curveEnd - curveStart, 0.001), curveLength)
lengthIncrement = self.getIncrementByMode(instanceCount, effectiveCurveLength)
# Common data
inputTransformPlug = self.getInputTransformPlug()
inputTransformFn = self.getInputTransformFn()
# Force update of transformation
if OpenMaya.MPlug(self.thisMObject(), instanceAlongCurveLocator.inputTransformAttr).isConnected():
dataBlock.inputValue(inputTransformPlug).asMatrix()
# Manipulator data
curveAxisHandleArray = dataBlock.inputArrayValue(instanceAlongCurveLocator.curveAxisHandleAttr.compound)
axisHandlesSorted = getSortedCurveAxisArray(self.thisMObject(), curveAxisHandleArray, instanceCount)
if updateTranslation:
self.updateInstancePositions(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement, inputTransformPlug, inputTransformFn, axisHandlesSorted)
if updateRotation:
self.updateInstanceRotations(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement, inputTransformPlug, inputTransformFn, axisHandlesSorted)
if updateScale:
self.updateInstanceScale(curveFn, dataBlock, instanceCount, distOffset, curveStart, curveEnd, effectiveCurveLength, lengthIncrement)
except:
sys.stderr.write('Failed trying to compute locator. stack trace: \n')
sys.stderr.write(traceback.format_exc())
return OpenMaya.kUnknownParameter