本文整理汇总了Python中maya.cmds.rotate函数的典型用法代码示例。如果您正苦于以下问题:Python rotate函数的具体用法?Python rotate怎么用?Python rotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rotate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addText
def addText(obj, t='A', f='Arial-Bold', c=12, rotOffset=[0, 0, 0], posOffset=[-1, 10, 0]):
'''\n
obj = transform to recieve text
t = text
f = font
c = color
'''
shapes = []
text = cmds.textCurves(ch=0, f=f, t=t)
# xform text
pos = cmds.xform(obj, q=True, rp=True, ws=True)
rot = cmds.xform(obj, q=True, ro=True, ws=True)
cmds.xform(text, t=pos, ro=rot)
# get selection
cmds.select(text, hi=True)
sel = cmds.ls(sl=True)
# find shapes
for item in sel:
if cmds.objectType(item) != 'transform':
# offset
cmds.rotate(rotOffset[0], rotOffset[1], rotOffset[2], item + '.cv[*]', r=True, eu=True, p=pos)
cmds.move(posOffset[0], posOffset[1], posOffset[2], item + '.cv[*]', r=True, ls=True, wd=True)
# assemble
cmds.setAttr(item + '.overrideEnabled', 1)
cmds.setAttr(item + '.overrideColor', c)
cmds.parent(item, obj, r=True, s=True)
cmds.rename(item, obj + 'Shape')
# delete left overs
cmds.delete(text)
示例2: create_pointer
def create_pointer(m):
if (BAXER_POINTER == True):
# import Baxter Pointer model and use it
try:
cmds.loadPlugin("objExport")
except:
pass
name = os.path.dirname(os.path.realpath(__file__)) + "/models/baxter_gripper.obj"
mel.eval('file -import -type "OBJ" -ignoreVersion -ra true -mergeNamespacesOnClash false -rpr "gripper" -options "mo=1" -pr "%s";' \
% name)
try:
mel.eval('rename "gripper_Mesh" "pointer' + str(m) + '";')
except:
pass
else:
# Create a pointer mesh that represents the robot claw
cmds.polyCone(name="pointer" + str(m), sx=3, r=0.5, h=2)
cmds.select("pointer" + str(m))
cmds.rotate("180deg", 0, 0, r=True)
cmds.move(0, -1, 0, "pointer" + str(m) + ".scalePivot", "pointer" + str(m) + ".rotatePivot")
cmds.move(0, 1, 0, absolute=True)
cmds.makeIdentity(apply=True, t=1, r=1, s=1)
bbx = cmds.xform("table", q=True, bb=True, ws=True)
cur_size = abs(bbx[3] - bbx[0])
cmds.scale(cur_size/TABLE_SIZE, cur_size/TABLE_SIZE, cur_size/TABLE_SIZE, "pointer" + str(m), centerPivot = True)
mel.eval('select -r pointer' + str(m) + '; sets -e -forceElement pointer_matSG;')
mel.eval("makeCollideNCloth")
示例3: bestFitPlane
def bestFitPlane(ptList,upVector=(0,1,0)):
'''
'''
# Initialize plane normal
norm = OpenMaya.MVector()
pt = OpenMaya.MVector()
# Calculate plane
for i in range(len(ptList)):
prev = OpenMaya.MVector(ptList[i-1][0],ptList[i-1][1],ptList[i-1][2])
curr = OpenMaya.MVector(ptList[i][0],ptList[i][1],ptList[i][2])
norm += OpenMaya.MVector((prev.z + curr.z) * (prev.y - curr.y), (prev.x + curr.x) * (prev.z - curr.z), (prev.y + curr.y) * (prev.x - curr.x))
pt += curr
# Normalize result
norm.normalize()
pt /= len(ptList)
# Build rotation matrix
mat = glTools.utils.matrix.buildRotation(norm,upVector,'y','x')
rot = glTools.utils.matrix.getRotation(mat,'xyz')
# Create Plane
plane = mc.polyPlane(w=1,h=1,sx=1,sy=1,ax=[0,1,0],cuv=2,ch=False)[0]
# Position Plane
mc.rotate(rot[0],rot[1],rot[2],plane,os=True,a=True)
mc.move(pt[0],pt[1],pt[2],plane,ws=True,a=True)
# Return result
return plane
示例4: apply
def apply( self, nodes=None, applySettings=None, worldSpace=False ):
if nodes is None:
nodes = self._nodeAttrDict.iterkeys()
for node in nodes:
if node in self._nodeAttrDict:
for attr, value in self._nodeAttrDict[ node ].iteritems():
attrpath = '%s.%s' % (node, attr)
if objExists( attrpath ):
setAttr( attrpath, value )
if worldSpace:
if node in self._nodeWorldDict:
if cmd.objectType( node, isAType='transform' ):
pos, rot, rotateOrder = self._nodeWorldDict[node]
move( pos[0], pos[1], pos[2], node, ws=True, a=True, rpr=True )
roAttrpath = '%s.ro' % node
initialRotateOrder = getAttr( roAttrpath )
rotateOrderMatches = initialRotateOrder == rotateOrder
if rotateOrderMatches:
rotate( rot[0], rot[1], rot[2], node, ws=True, a=True )
else:
setAttr( roAttrpath, rotateOrder )
rotate( rot[0], rot[1], rot[2], node, ws=True, a=True )
xform( node, ro=constants.ROTATE_ORDER_STRS[ initialRotateOrder ], p=True )
示例5: rotateJoint
def rotateJoint( self, rotateX, rotateY, rotateZ, rotateRelative=False ):
objs = cmds.ls( selection=True )
try:
pm.mel.eval( """
setToolTo $gRotate;
manipRotateValues Rotate;
toolPropertyShow;
changeToolIcon;
""" )
except:
print( "switching to rotate tool (with error correction via exception handling)" )
try:
pm.mel.eval( """
setToolTo $gRotate;
manipRotateValues Rotate;
toolPropertyShow;
changeToolIcon;
""" )
except:
print( "(...continuing error correction via exception handling)" )
for i in objs:
try:
cmds.rotate( rotateX, rotateY, rotateZ , i + ".rotateAxis", os=True, relative=rotateRelative )
except:
try:
cmds.rotate( rotateX, rotateY, rotateZ , i, os=True, relative=rotateRelative )
except:
print( "Couldn't rotate joint.")
print( traceback.format_exc( ) )
示例6: makeFlake
def makeFlake(branches,radius):
'''
Creates a single snowflake
branches : number of side branches
radius : radius of the snowflake
A cube is created and transformed to taper with a diamond cross-section.
It is passed to flakeIterate to generate 1/6 of the snowflake. This branch
is duplicated and rotated around the centre to create the full snowflake.
The parts are combined, the flake is scaled and transformations are frozen.
The snowflake name is returned.
'''
name=cmds.polyCube()[0]
cmds.rotate(45,0,0,name,r=1)
cmds.move(0.5,0,0,name+'.vtx[0:7]',r=1)
cmds.scale(0.7,0.2,0.1,p=[0,0,0],r=1)
cmds.scale(1,0.7,0.7,name+'.f[4]',r=1,p=[0,0,0])
cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0)
partList=flakeIterate(name,7,random.uniform(30,70),0.7)
branches=[combineParts(partList,'branch')]
for i in range(1,6):
branches[len(branches):]=[cmds.duplicate('branch')[0]]
cmds.rotate(0,i*60,0,branches[-1],r=1)
flake = combineParts(branches,'snowflake')
scale = radius/6
cmds.scale(scale,scale,scale,flake)
cmds.makeIdentity(flake,apply=True, s=1, n=0)
return flake
示例7: doPositionLocator
def doPositionLocator(locatorName,locInfo):
"""
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DESCRIPTION:
Position a locator with locator info generated from returnInfoForLoc
ARGUMENTS:
locatorName(string)
locInfo(dict)
RETURNS:
success(bool)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"""
if search.returnObjectType(locatorName) == 'locator':
objTrans = locInfo['position']
objRot = locInfo['rotation']
correctRo = locInfo['rotationOrder']
mc.move (objTrans[0],objTrans[1],objTrans[2], locatorName)
mc.setAttr ((locatorName+'.rotateOrder'), correctRo)
#Rotate
if locInfo['objectType'] == 'polyFace':
constBuffer = mc.normalConstraint((locInfo['createdFrom']),locatorName)
mc.delete(constBuffer[0])
else:
mc.rotate (objRot[0], objRot[1], objRot[2], locatorName, ws=True)
return True
else:
guiFactory.warning('Not a locator.')
return False
示例8: draw
def draw(self):
circle1 = cmds.circle( nr=(1, 0, 0), c=(0, 0, 0), sw=self.sweep, r=self.start_radius )
circle2 = cmds.circle( nr=(1, 0, 0), c=(0, 0, 0), sw=self.sweep, r=self.end_radius )
l1 = cmds.loft(circle1, circle2)
# curves
crv = cmds.curve(p=[(0, self.start_radius, 0), (0, self.end_radius, 0)], degree=1)
crv2 = cmds.duplicate(crv)
cmds.rotate(str(self.sweep) + 'deg', 0, 0, r=True)
extrusions = []
for e in [circle1, circle2, crv, crv2]:
extrusions.append(cmds.extrude(e, et=0, d=(1,0,0), l=self.height))
cmds.delete(e)
pieces = extrusions + [l1]
group = cmds.group(*[e[0] for e in pieces])
cmds.move(0,0,0, group+".scalePivot",group+".rotatePivot", absolute=True)
cmds.setKeyframe(group, attribute='rotateX', t='0sec', value=self.rotation)
return (pieces, group)
示例9: rotCtrlShapeX
def rotCtrlShapeX (_isPositive):
sel = cmds.ls(selection = True)
for controlName in sel:
#clear the selection
cmds.select(clear = True)
#error catching, in case something other than a
#curve or circle is selected
cmds.selectMode(component = True)
try:
#selects the cvs in a nurbs curve or circle
cmds.select(controlName+".cv[0:"+ str(getCVs(controlName)-1) + "]")
except:
#prints the reason for the failure
print "Button not Activated: Control to Scale Must be a Curve or Circle"
#does the rotation
if (_isPositive == True):
cmds.rotate(90,0,0, os = True, r = True)
else:
cmds.rotate(-90,0,0, os = True, r = True)
#select all of the controls that were originally selected
cmds.selectMode(object = True)
cmds.select(sel)
示例10: goToTarget
def goToTarget( first, second ):
tr = cmds.xform( second, q=1, ws=1, piv=1 )[:3]
ro = cmds.xform( second, q=1, ws=1, ro =1 )[:3]
cmds.move( tr[0], tr[1], tr[2], first, ws=1 )
cmds.rotate( ro[0], ro[1], ro[2], first, ws=1 )
示例11: bestFitPlaneCreate
def bestFitPlaneCreate(ptList,upVector=(0,1,0)):
'''
Create a best fit plane from a specified set of points.
@param ptList: List of points to calculate best fit plane from.
@type ptList: list
@param upVector: Up vector for orientation reference.
@type upVector: tuple or list
'''
# Calculate Plane Center and Normal
p = glTools.tools.center.centerPoint_average(ptList)
pt = OpenMaya.MVector(p[0],p[1],p[2])
n = bestFitPlaneNormal(ptList)
norm = OpenMaya.MVector(n[0],n[1],n[2])
# Build rotation matrix
mat = glTools.utils.matrix.buildRotation(norm,upVector,'y','x')
rot = glTools.utils.matrix.getRotation(mat,'xyz')
# Create Plane
plane = mc.polyPlane(w=1,h=1,sx=1,sy=1,ax=[0,1,0],cuv=2,ch=False)[0]
# Position Plane
mc.rotate(rot[0],rot[1],rot[2],plane,os=True,a=True)
mc.move(pt[0],pt[1],pt[2],plane,ws=True,a=True)
# Return result
return plane
示例12: a_ring
def a_ring():
ring_diameter = 22 # outer diameter
ring_thickness = 1.5
divit_diameter = 1.5
divit_depth = .75
ring_height = 4
#divit_spacing = .5
divits = []
cmds.polyPipe(radius=ring_diameter/2, height=ring_height*2, thickness=ring_thickness, name='ring0')
cmds.setAttr( 'polyPipe1.subdivisionsAxis', 20 )
for x in range(0,6):
for y in range(0,3):
letter = initials[x]
symbol = letter[y]
myName = "_c" + str(x) + str(y)
if symbol == 0 :
cmds.polyCylinder(axis=[0,0,1], radius=(divit_diameter/2), height=divit_depth, name=myName)
elif symbol == 2:
cmds.polyCylinder(axis=[0,0,1], radius=(divit_diameter/2), height=ring_thickness * 2.1, name=myName)
if symbol != 1:
divits.append(myName)
y_off = 0
cmds.move(0,y_off,(ring_diameter/2 - divit_depth/2 + .3),myName)
cmds.rotate(0,(x*3+y)*20,0,myName, pivot=[0,0,0])
rn = 0;
for d in divits[:]:
print 'ring' + str(rn) + " " + d
cmds.polyBoolOp('ring' + str(rn), d, op=2, n='ring' + str(rn+1), )
rn += 1
示例13: createArrow
def createArrow(name=None, thickness=0.1, length=2, vector=[1,0,0], point=[0,0,0]):
'''
Creates an arrow in the direction of the vector
Example:
arrow = createArrow(vector=[0,1,0], length=4)
'''
if not name:
name = 'arrow_CTRL'
#calc length for thickness
ratio = length/thickness
cyl = cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[length/2, 0, 0], ch=0)[0]
cone = cmds.cone(radius=thickness*2, sections=4, ch=0, pivot=(length*1.0005,0,0))[0]
xform = cmds.createNode('transform', ss=1, name=name)
shapes = []
transforms = []
for node in [cone,cyl]:
shapes.append(cmds.listRelatives(node, fullPath=1, shapes=1)[0])
transforms.append(node)
cmds.parent(shapes, xform, r=1, s=1)
rotateBy = cmds.angleBetween(euler=True, v1=(1,0,0), v2=vector)
cmds.rotate(rotateBy[0], rotateBy[1], rotateBy[2], xform)
cmds.xform(xform, t=point)
cmds.delete(transforms)
return xform
示例14: evenlyDivideCurve
def evenlyDivideCurve( curve, numDiv ):
""" Divides a curve into numDiv.
Assumes there are two CVs at the start and end of the curve """
# first, move the curve to the origin
translation = mc.xform(curve, q=True, ws=True, translation=True)
rotation = mc.xform(curve, q=True, ws=True, rotation=True)
mc.move(0, 0, 0, curve)
mc.rotate(0, 0, 0, curve)
# get the curve info node
infoNode = getCurveInfoNode(curve)
Knots = list( mc.getAttr( infoNode+".knots" )[0] )
CVs = mc.getAttr( curve+".cv[*]" )
numOrigCVs = len(CVs)
numOrigKnots = len(Knots)
if( not numOrigCVs == 4 ):
print("ERROR: original curve must have exactly 4 CVs")
return
else:
for p in range(0,(numDiv-numOrigCVs+4+1)):
percent = (p-1)/float(numDiv-2)
u = findParamAtArcPercent( curve, percent )
if p < 2 or p >= (numDiv-numOrigCVs+3):
CVs[p] = tuple(mc.pointOnCurve(curve, parameter=u))
else:
CVs.insert(p, tuple(mc.pointOnCurve(curve, parameter=u)) )
Knots.insert(p+1, u)
curve = mc.curve( curve,r=True, p=CVs, k=Knots)
mc.move(translation[0], translation[1], translation[2], curve)
mc.rotate(rotation[0], rotation[1], rotation[2], curve)
return curve
示例15: makeRowOfStreetTrees
def makeRowOfStreetTrees(num, coor, shaders, dir):
'''
Makes a row with the specified number of street trees.
num: Number of street trees in the row.
coor: A tuple with the x- and z- coordinates the center of the row of trees
will be located at.
shaders: A list of shaders for the tree crowns.
dir: String which specifies if the trees should be placed along the x-axis
(horisontal) or along the z-axis (vertical).
On exit: The specified number of trees has been created using makeStreetTree(...),
and placed in a row at the given coordinates. All of the trees are
combined and the resulting object is returned as a tuple with the
object name and node name.
'''
start = -(num - 1)/2.0 * 2.8
tree = makeStreetTree(shaders)
cmds.xform(tree[0], t = (start, 0, 0), ws = True)
for i in range(1,num):
tree1 = makeStreetTree(shaders)
cmds.xform(tree1[0], t = (start + i * 2.8, 0, 0), ws = True)
tree = cmds.polyUnite(tree[0], tree1[0])
cmds.xform(tree[0], centerPivots = True)
if dir == "vertical":
cmds.rotate(90, y = True)
cmds.xform(tree[0], translation = (coor[0], 0,coor[1]), ws = True)
return tree