本文整理汇总了Python中maya.cmds.curve方法的典型用法代码示例。如果您正苦于以下问题:Python cmds.curve方法的具体用法?Python cmds.curve怎么用?Python cmds.curve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maya.cmds
的用法示例。
在下文中一共展示了cmds.curve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cvLocator
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def cvLocator(self, ctrlName, r=1, d=1, guide=False, *args):
"""Create and return a cvLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize.
"""
curveInstance = self.getControlInstance("Locator")
curve = curveInstance.cvMain(False, "Locator", ctrlName, r, d, '+Y', (0, 0, 0), 1, guide)
if guide:
# create an attribute to be used as guide by module:
cmds.addAttr(curve, longName="nJoint", attributeType='long')
cmds.setAttr(curve+".nJoint", 1)
# colorize curveShape:
self.colorShape([curve], 'blue')
# shapeSize setup:
shapeSizeCluster = self.shapeSizeSetup(curve)
return [curve, shapeSizeCluster]
return curve
#@utils.profiler
示例2: createCurveShape
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def createCurveShape(name, points):
"""
Create a curve and rename the shapes to be unique.
:param str name: Name of curve
:param list points: List of points.
"""
# create curve
curve = cmds.curve(p=points, d=1, n=name)
# rename shapes
shapes = []
for shape in cmds.listRelatives(curve, s=True, f=True) or []:
shape = cmds.rename(shape, "{0}Shape".format(name))
shapes.append(shape)
return curve, shapes
示例3: convertToBezierCurve
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def convertToBezierCurve(curve):
"""
Check if the parsed curve is a bezier curve, if this is not the case
convert the curve to a bezier curve.
:param str curve: Name of curve
"""
# get shape
curveShape = cmds.listRelatives(curve, s=True)[0]
# convert to bezier curve
if cmds.nodeType(curveShape) == "bezierCurve":
return
cmds.select(curve)
cmds.nurbsCurveToBezier()
# ----------------------------------------------------------------------------
示例4: splitCurveToParametersByParameter
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def splitCurveToParametersByParameter(curve, num):
"""
Get a list of parameters evenly spaced along a curve, based on the
division of its parameters. Ranges are normalizes to be between 0-1.
:param str curve:
:param int num:
:return: parameters
:rtype: list
"""
increment = 1.0 / (num - 1)
parameters = [i * increment for i in range(num)]
if cmds.getAttr("{0}.form".format(curve)) == 2:
parameters.insert(0, parameters[-1])
parameters.pop(-1)
return parameters
# ----------------------------------------------------------------------------
示例5: test_get_curve_object_with_history
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def test_get_curve_object_with_history(self):
curve = cmds.circle()[0]
obj = control.CurveShape(curve)
self.assertEqual(obj.degree, 3)
self.assertEqual(obj.form, 2)
self.assertListEqual(obj.knots, range(-2, 11))
expected_cvs = [
(0.7836116248912245, 0.7836116248912246, 0.0),
(6.785732323110912e-17, 1.1081941875543877, 0.0),
(-0.7836116248912245, 0.7836116248912244, 0.0),
(-1.1081941875543881, 5.74489823752483e-17, 0.0),
(-0.7836116248912245, -0.7836116248912245, 0.0),
(-1.1100856969603225e-16, -1.1081941875543884, 0.0),
(0.7836116248912245, -0.7836116248912244, 0.0),
(1.1081941875543881, -1.511240500779959e-16, 0.0),
]
self.cvs_are_equal(obj.cvs, expected_cvs)
self.assertIsNone(obj.color)
示例6: create_arrow
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def create_arrow(jointName):
curve = cmds.curve(
name="%s_ForwardDirection" % jointName,
degree=1,
point=[
(-1, 0, 0),
(-1, 2, 0),
(-2, 2, 0),
(0, 4, 0),
(2, 2, 0),
(1, 2, 0),
(1, 0, 0),
(-1, 0, 0),
],
)
group = cmds.group()
cmds.xform(objectSpace=True, pivots=(0, 0, 0))
jointScale = cmds.jointDisplayScale(query=True)
jointRadius = cmds.getAttr("%s.radius" % jointName)
jointScale *= jointRadius
cmds.xform(scale=(jointScale, jointScale, jointScale))
return group
示例7: import_curves_on_selected
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def import_curves_on_selected(file_path=None, tag_as_controller=False):
"""Imports a control shape from disk onto the selected transform.
:param file_path: Path to the control file.
:param tag_as_controller: True to tag the curve transform as a controller
:return: The new curve transform
"""
controls = load_curves(file_path)
selected_transforms = cmds.ls(sl=True)
if not selected_transforms:
return
for transform in selected_transforms:
for curve in controls:
curve.create(transform, tag_as_controller)
return selected_transforms
示例8: applyBrush
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def applyBrush(curve, parent):
'''
Simply applies the paint effects brush to the curve with the settings we want.
'''
mc.AttachBrushToCurves(curve)
stroke = mc.ls(sl=True)[0]
stroke = mc.parent(stroke,parent)[0]
mc.setAttr(stroke+'.displayPercent',92)
mc.setAttr(stroke+'.sampleDensity',0.5)
mc.setAttr(stroke+'.inheritsTransform',0)
mc.setAttr(stroke+'.translate',0,0,0)
mc.setAttr(stroke+'.rotate',0,0,0)
return stroke
示例9: addControlInfo
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def addControlInfo(self, cvNode, className=True, size=True, degree=True, direction=True, rot=True, dpGuide=False, *args):
""" Add some information in the curve transform node of the control.
"""
cmds.addAttr(cvNode, longName="dpControl", attributeType='bool')
cmds.setAttr(cvNode+".dpControl", 1)
if dpGuide:
cmds.addAttr(cvNode, longName="dpGuide", attributeType='bool')
cmds.setAttr(cvNode+".dpGuide", 1)
cmds.addAttr(cvNode, longName="version", dataType='string')
cmds.setAttr(cvNode+".version", self.dpUIinst.dpARVersion, type="string")
if self.cvID:
cmds.addAttr(cvNode, longName="controlID", dataType='string')
cmds.setAttr(cvNode+".controlID", self.cvID, type="string")
if className:
cmds.addAttr(cvNode, longName="className", dataType='string')
cmds.setAttr(cvNode+".className", self.guideModuleName, type="string")
if size:
cmds.addAttr(cvNode, longName="size", attributeType='float')
cmds.setAttr(cvNode+".size", self.cvSize)
if degree:
cmds.addAttr(cvNode, longName="degree", attributeType='short')
cmds.setAttr(cvNode+".degree", self.cvDegree)
if direction:
cmds.addAttr(cvNode, longName="direction", dataType='string')
cmds.setAttr(cvNode+".direction", self.cvDirection, type="string")
if rot:
cmds.addAttr(cvNode, longName="cvRotX", attributeType='double')
cmds.addAttr(cvNode, longName="cvRotY", attributeType='double')
cmds.addAttr(cvNode, longName="cvRotZ", attributeType='double')
cmds.setAttr(cvNode+".cvRotX", self.cvRot[0])
cmds.setAttr(cvNode+".cvRotY", self.cvRot[1])
cmds.setAttr(cvNode+".cvRotZ", self.cvRot[2])
示例10: createCurve
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def createCurve(self, cvName, cvDegree, cvPointList, cvKnot, cvPeriodic, dpGuide, *args):
""" Create and return a simple curve using given parameters.
"""
cvCurve = cmds.curve(name=cvName, point=cvPointList, degree=cvDegree, knot=cvKnot, periodic=cvPeriodic)
self.addControlInfo(cvCurve, dpGuide=dpGuide)
self.ctrls.renameShape([cvCurve])
return cvCurve
示例11: combineCurves
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def combineCurves(self, curveList, *args):
""" Combine all guiven curve to just one main curve and return it.
"""
mainCurve = curveList[0]
cmds.makeIdentity(mainCurve, translate=True, rotate=True, scale=True, apply=True)
for item in curveList[1:]:
cmds.makeIdentity(item, translate=True, rotate=True, scale=True, apply=True)
self.ctrls.transferShape(True, False, item, [mainCurve])
cmds.setAttr(mainCurve+".className", self.guideModuleName, type="string")
return mainCurve
示例12: cvCreate
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def cvCreate(self, useUI, cvID, cvName='Control_Ctrl', cvSize=1.0, cvDegree=1, cvDirection='+Y', cvRot=(0, 0, 0), cvAction=1, dpGuide=False, combine=False, *args):
""" Check if we need to get parameters from UI.
Create a respective curve shape.
Return the transform curve or a list of selected destination items.
"""
# getting current selection:
destinationList = cmds.ls(selection=True, type="transform")
# check if the given name is good or add a sequencial number on it:
self.cvName = utils.validateName(cvName, self.suffix)
self.cvID = cvID
self.cvSize = cvSize
self.cvDegree = cvDegree
self.cvDirection = cvDirection
self.cvRot = cvRot
self.cvAction = cvAction
# getting UI info:
if useUI:
self.getControlUIValues(self.cvName)
# combine or create curve using the parameters:
if combine:
self.cvCurve = self.generateCombineCurves(useUI, self.cvID, self.cvName, self.cvSize, self.cvDegree, self.cvDirection)
else:
# getting curve info to be created based on choose degree:
if self.cvDegree == 1: #linear
self.getLinearPoints()
else: #cubic
self.getCubicPoints()
self.cvCurve = self.createCurve(self.cvName, self.cvDegree, self.cvPointList, self.cvKnotList, self.cvPeriodic, dpGuide)
# set control direction for the control curve:
self.setControlDirection(self.cvCurve, self.cvDirection)
# working about action to do, like new control, add shape or replace shapes:
self.doControlAction(destinationList)
# select the result node and return it
if self.cvAction == 1: #new control
cmds.select(self.cvCurve)
return self.cvCurve
elif destinationList:
cmds.select(destinationList)
return destinationList
示例13: cvJointLoc
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def cvJointLoc(self, ctrlName, r=0.3, d=1, rot=(0, 0, 0), guide=True, *args):
"""Create and return a cvJointLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize.
"""
# create locator curve:
cvLoc = self.cvLocator(ctrlName+"_CvLoc", r, d)
# create arrow curves:
cvArrow1 = cmds.curve(n=ctrlName+"_CvArrow1", d=3, p=[(-0.1*r, 0.9*r, 0.2*r), (-0.1*r, 0.9*r, 0.23*r), (-0.1*r, 0.9*r, 0.27*r), (-0.1*r, 0.9*r, 0.29*r), (-0.1*r, 0.9*r, 0.3*r), (-0.372*r, 0.9*r, 0.24*r), (-0.45*r, 0.9*r, -0.13*r), (-0.18*r, 0.9*r, -0.345*r), (-0.17*r, 0.9*r, -0.31*r), (-0.26*r, 0.9*r, -0.41*r), (-0.21*r, 0.9*r, -0.41*r), (-0.05*r, 0.9*r, -0.4*r), (0, 0.9*r, -0.4*r), (-0.029*r, 0.9*r, -0.33*r), (-0.048*r, 0.9*r, -0.22*r), (-0.055*r, 0.9*r, -0.16*r), (-0.15*r, 0.9*r, -0.272*r), (-0.12*r, 0.9*r, -0.27*r), (-0.35*r, 0.9*r, -0.1*r), (-0.29*r, 0.9*r, 0.15*r), (-0.16*r, 0.9*r, 0.21*r), (-0.1*r, 0.9*r, 0.2*r)] )
cvArrow2 = cmds.curve(n=ctrlName+"_CvArrow2", d=3, p=[(0.1*r, 0.9*r, -0.2*r), (0.1*r, 0.9*r, -0.23*r), (0.1*r, 0.9*r, -0.27*r), (0.1*r, 0.9*r, -0.29*r), (0.1*r, 0.9*r, -0.3*r), (0.372*r, 0.9*r, -0.24*r), (0.45*r, 0.9*r, 0.13*r), (0.18*r, 0.9*r, 0.345*r), (0.17*r, 0.9*r, 0.31*r), (0.26*r, 0.9*r, 0.41*r), (0.21*r, 0.9*r, 0.41*r), (0.05*r, 0.9*r, 0.4*r), (0, 0.9*r, 0.4*r), (0.029*r, 0.9*r, 0.33*r), (0.048*r, 0.9*r, 0.22*r), (0.055*r, 0.9*r, 0.16*r), (0.15*r, 0.9*r, 0.272*r), (0.12*r, 0.9*r, 0.27*r), (0.35*r, 0.9*r, 0.1*r), (0.29*r, 0.9*r, -0.15*r), (0.16*r, 0.9*r, -0.21*r), (0.1*r, 0.9*r, -0.2*r)] )
cvArrow3 = cmds.curve(n=ctrlName+"_CvArrow3", d=3, p=[(-0.1*r, -0.9*r, 0.2*r), (-0.1*r, -0.9*r, 0.23*r), (-0.1*r, -0.9*r, 0.27*r), (-0.1*r, -0.9*r, 0.29*r), (-0.1*r, -0.9*r, 0.3*r), (-0.372*r, -0.9*r, 0.24*r), (-0.45*r, -0.9*r, -0.13*r), (-0.18*r, -0.9*r, -0.345*r), (-0.17*r, -0.9*r, -0.31*r), (-0.26*r, -0.9*r, -0.41*r), (-0.21*r, -0.9*r, -0.41*r), (-0.05*r, -0.9*r, -0.4*r), (0, -0.9*r, -0.4*r), (-0.029*r, -0.9*r, -0.33*r), (-0.048*r, -0.9*r, -0.22*r), (-0.055*r, -0.9*r, -0.16*r), (-0.15*r, -0.9*r, -0.272*r), (-0.12*r, -0.9*r, -0.27*r), (-0.35*r, -0.9*r, -0.1*r), (-0.29*r, -0.9*r, 0.15*r), (-0.16*r, -0.9*r, 0.21*r), (-0.1*r, -0.9*r, 0.2*r)] )
cvArrow4 = cmds.curve(n=ctrlName+"_CvArrow4", d=3, p=[(0.1*r, -0.9*r, -0.2*r), (0.1*r, -0.9*r, -0.23*r), (0.1*r, -0.9*r, -0.27*r), (0.1*r, -0.9*r, -0.29*r), (0.1*r, -0.9*r, -0.3*r), (0.372*r, -0.9*r, -0.24*r), (0.45*r, -0.9*r, 0.13*r), (0.18*r, -0.9*r, 0.345*r), (0.17*r, -0.9*r, 0.31*r), (0.26*r, -0.9*r, 0.41*r), (0.21*r, -0.9*r, 0.41*r), (0.05*r, -0.9*r, 0.4*r), (0, -0.9*r, 0.4*r), (0.029*r, -0.9*r, 0.33*r), (0.048*r, -0.9*r, 0.22*r), (0.055*r, -0.9*r, 0.16*r), (0.15*r, -0.9*r, 0.272*r), (0.12*r, -0.9*r, 0.27*r), (0.35*r, -0.9*r, 0.1*r), (0.29*r, -0.9*r, -0.15*r), (0.16*r, -0.9*r, -0.21*r), (0.1*r, -0.9*r, -0.2*r)] )
cvArrow5 = cmds.curve(n=ctrlName+"_CvArrow5", d=1, p=[(0, 0, 1.2*r), (0.09*r, 0, 1*r), (-0.09*r, 0, 1*r), (0, 0, 1.2*r)] )
cvArrow6 = cmds.curve(n=ctrlName+"_CvArrow6", d=1, p=[(0, 0, 1.2*r), (0, 0.09*r, 1*r), (0, -0.09*r, 1*r), (0, 0, 1.2*r)] )
# rename curveShape:
locArrowList = [cvLoc, cvArrow1, cvArrow2, cvArrow3, cvArrow4, cvArrow5, cvArrow6]
self.renameShape(locArrowList)
# create ball curve:
cvTemplateBall = self.cvControl("Ball", ctrlName+"_CvBall", r=0.7*r, d=3)
# parent shapes to transform:
locCtrl = cmds.group(name=ctrlName, empty=True)
ballChildrenList = cmds.listRelatives(cvTemplateBall, shapes=True, children=True)
for ballChildren in ballChildrenList:
cmds.setAttr(ballChildren+".template", 1)
self.transferShape(True, False, cvTemplateBall, [locCtrl])
for transform in locArrowList:
self.transferShape(True, False, transform, [locCtrl])
# set rotation direction:
cmds.setAttr(locCtrl+".rotateX", rot[0])
cmds.setAttr(locCtrl+".rotateY", rot[1])
cmds.setAttr(locCtrl+".rotateZ", rot[2])
cmds.makeIdentity(locCtrl, rotate=True, apply=True)
# create an attribute to be used as guide by module:
cmds.addAttr(locCtrl, longName="nJoint", attributeType='long')
cmds.setAttr(locCtrl+".nJoint", 1)
# colorize curveShapes:
self.colorShape([locCtrl], 'blue')
# shapeSize setup:
shapeSizeCluster = self.shapeSizeSetup(locCtrl)
cmds.select(clear=True)
return [locCtrl, shapeSizeCluster]
示例14: cvCharacter
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def cvCharacter(self, ctrlType, ctrlName, r=1, d=1, dir="+Y", rot=(0, 0, 0), *args):
""" Create and return a curve to be used as a control.
"""
# get radius by checking linear unit
r = self.dpCheckLinearUnit(r)
curve = self.cvControl(ctrlType, ctrlName, r, d, dir, rot)
# edit a minime curve:
cmds.addAttr(curve, longName="rigScale", attributeType='float', defaultValue=1, keyable=True)
cmds.addAttr(curve, longName="rigScaleMultiplier", attributeType='float', defaultValue=1, keyable=False)
# create Option_Ctrl Text:
try:
optCtrlTxt = cmds.group(name="Option_Ctrl_Txt", empty=True)
try:
cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Source Sans Pro", text="Option Ctrl", constructionHistory=False)[0]
except:
cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Arial", text="Option Ctrl", constructionHistory=False)[0]
txtShapeList = cmds.listRelatives(cvText, allDescendents=True, type='nurbsCurve')
if txtShapeList:
for s, shape in enumerate(txtShapeList):
# store CV world position
curveCVList = cmds.getAttr(shape+'.cp', multiIndices=True)
vtxWorldPosition = []
for i in curveCVList :
cvPointPosition = cmds.xform(shape+'.cp['+str(i)+']', query=True, translation=True, worldSpace=True)
vtxWorldPosition.append(cvPointPosition)
# parent the shapeNode :
cmds.parent(shape, optCtrlTxt, r=True, s=True)
# restore the shape world position
for i in curveCVList:
cmds.xform(shape+'.cp['+str(i)+']', a=True, worldSpace=True, t=vtxWorldPosition[i])
cmds.rename(shape, optCtrlTxt+"Shape"+str(s))
cmds.delete(cvText)
cmds.parent(optCtrlTxt, curve)
cmds.setAttr(optCtrlTxt+".template", 1)
cmds.setAttr(optCtrlTxt+".tx", -0.72*r)
cmds.setAttr(optCtrlTxt+".ty", 1.1*r)
except:
# it will pass if we don't able to find the font to create the text
pass
return curve
示例15: cvBaseGuide
# 需要导入模块: from maya import cmds [as 别名]
# 或者: from maya.cmds import curve [as 别名]
def cvBaseGuide(self, ctrlName, r=1, *args):
"""Create a control to be used as a Base Guide control.
Returns the main control (circle) and the radius control in a list.
"""
# get radius by checking linear unit
r = self.dpCheckLinearUnit(r)
# create a simple circle curve:
circle = cmds.circle(n=ctrlName, ch=True, o=True, nr=(0, 0, 1), d=3, s=8, radius=r)[0]
radiusCtrl = cmds.circle(n=ctrlName+"_RadiusCtrl", ch=True, o=True, nr=(0, 1, 0), d=3, s=8, radius=(r/4.0))[0]
# rename curveShape:
self.renameShape([circle, radiusCtrl])
# configure system of limits and radius:
cmds.setAttr(radiusCtrl+".translateX", r)
cmds.parent(radiusCtrl, circle, relative=True)
cmds.transformLimits(radiusCtrl, tx=(0.01, 1), etx=(True, False))
self.setLockHide([radiusCtrl], ['ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'])
# find makeNurbCircle history of the circles:
historyList = self.findHistory([circle, radiusCtrl], 'makeNurbCircle')
circleHistory = historyList[0]
radiusCtrlHistory = historyList[1]
# rename and make a connection for circle:
circleHistory = cmds.rename(circleHistory, circle+"_makeNurbCircle")
cmds.connectAttr(radiusCtrl+".tx", circleHistory+".radius", force=True)
radiusCtrlHistory = cmds.rename(radiusCtrlHistory, radiusCtrl+"_makeNurbCircle")
# create a mutiplyDivide in order to automatisation the radius of the radiusCtrl:
radiusCtrlMD = cmds.createNode('multiplyDivide', name=radiusCtrl+'_MD')
cmds.connectAttr(radiusCtrl+'.translateX', radiusCtrlMD+'.input1X', force=True)
cmds.setAttr(radiusCtrlMD+'.input2X', 0.15)
cmds.connectAttr(radiusCtrlMD+".outputX", radiusCtrlHistory+".radius", force=True)
# colorize curveShapes:
self.colorShape([circle], 'yellow')
self.colorShape([radiusCtrl], 'cyan')
if (int(cmds.about(version=True)[:4]) > 2016):
cmds.setAttr(circle+"Shape.lineWidth", 2)
cmds.select(clear=True)
return [circle, radiusCtrl]