def fountainTop(fountain): ''' Creates a top decoration for a fountain. fountain: A object the top decoration will be placed on. On exit: A top decoration has been created by adding a deformer to a basic polygonal object. The top is returned as a tuple with the object name and node name. ''' height = random.uniform(0.1,0.6) # Decide which type of object will form the top. type = random.choice(["cube", "cylinder", "prism", "cone", "sphere"]) if type == "cube": top = cmds.polyCube(name = "top", h = height, w = 0.2, d = 0.2, sy = 10) if type == "cylinder": top = cmds.polyCylinder(name = "top",h = height, r = 0.1, sy = 10) if type == "prism": top = cmds.polyPrism(name = "top", l = height, w = 0.1, sh = 10) if type == "cone": top = cmds.polyCone(name = "top", h = height, r = 0.1, sy = 10) if type == "sphere": top = cmds.polySphere(name = "top",r = height/2.0) bbox = cmds.exactWorldBoundingBox(fountain) cmds.xform(top, translation = (0,bbox[4]+ height/2.0,0)) flare = random.choice([0,1]) if flare == 1: cmds.select(top[0]) flare = cmds.nonLinear(type = "flare") cmds.setAttr(flare[0] + ".curve", random.uniform(-3,3)) twist = random.choice([0,1]) if type == "cube" or type == "prism": if twist == 1: cmds.select(top[0]) twist = cmds.nonLinear(type = "twist") cmds.setAttr(twist[0] + ".endAngle", random.randint(-500, 500)) return top
def _polyPrism(self): cmds.polyPrism()
def polyPrism(*args, **kwargs): res = cmds.polyPrism(*args, **kwargs) if not kwargs.get('query', kwargs.get('q', False)): res = _factories.maybeConvert(res, _general.PyNode) return res
def testAnimPropDeleteReload(self): # create some animated properties on a transform node ( could be any type ) nodeName = MayaCmds.polyPrism(ch=False, name='prism') MayaCmds.addAttr(longName='SPT_int8', defaultValue=0, attributeType='byte', keyable=True) MayaCmds.addAttr(longName='SPT_int16', defaultValue=100, attributeType='short', keyable=True) MayaCmds.addAttr(longName='SPT_int32', defaultValue=1000, attributeType='long', keyable=True) MayaCmds.addAttr(longName='SPT_float', defaultValue=0.57777777, attributeType='float', keyable=True) MayaCmds.addAttr(longName='SPT_double', defaultValue=5.0456435, attributeType='double', keyable=True) MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(nodeName, attribute='SPT_int8') MayaCmds.setKeyframe(nodeName, attribute='SPT_int16') MayaCmds.setKeyframe(nodeName, attribute='SPT_int32') MayaCmds.setKeyframe(nodeName, attribute='SPT_float') MayaCmds.setKeyframe(nodeName, attribute='SPT_double') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe(nodeName, attribute='SPT_int8', value=8) MayaCmds.setKeyframe(nodeName, attribute='SPT_int16', value=16) MayaCmds.setKeyframe(nodeName, attribute='SPT_int32', value=32) MayaCmds.setKeyframe(nodeName, attribute='SPT_float', value=5.24847) MayaCmds.setKeyframe(nodeName, attribute='SPT_double', value=3.14154) # create SPT_HWColor on the shape node MayaCmds.select('prismShape') MayaCmds.addAttr(longName='SPT_HwColorR', defaultValue=1.0, minValue=0.0, maxValue=1.0) MayaCmds.addAttr(longName='SPT_HwColorG', defaultValue=1.0, minValue=0.0, maxValue=1.0) MayaCmds.addAttr(longName='SPT_HwColorB', defaultValue=1.0, minValue=0.0, maxValue=1.0) MayaCmds.addAttr(longName='SPT_HwColor', usedAsColor=True, attributeType='float3') MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(at='SPT_HwColorR') MayaCmds.setKeyframe(at='SPT_HwColorG') MayaCmds.setKeyframe(at='SPT_HwColorB') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe(at='SPT_HwColorR', value=0.5) MayaCmds.setKeyframe(at='SPT_HwColorG', value=0.15) MayaCmds.setKeyframe(at='SPT_HwColorB', value=0.75) # write them out to an Abc file and load back in self.__files.append(util.expandFileName('testPropReload.abc')) MayaCmds.AbcExport(j='-atp SPT_ -fr 1 24 -root prism -file ' + self.__files[-1]) # load back the Abc file, delete the 2nd letter and save to a maya file abcNode = MayaCmds.AbcImport( self.__files[-1], mode='open') # delete connections to animated props prop = MayaCmds.listConnections('|prism.SPT_float', p=True)[0] MayaCmds.disconnectAttr(prop, '|prism.SPT_float') attr = '|prism|prismShape.SPT_HwColorG' prop = MayaCmds.listConnections(attr, p=True)[0] MayaCmds.disconnectAttr(prop, attr) self.__files.append(util.expandFileName('test.mb')) MayaCmds.file(rename=self.__files[-1]) MayaCmds.file(save=True) # import the saved maya file to compare with the original scene MayaCmds.file(self.__files[-1], open=True) MayaCmds.select('prism', replace=True) MayaCmds.group(name='ReloadGrp') MayaCmds.AbcImport(self.__files[-2], mode='import') # test the equality of props for t in range(1, 25): MayaCmds.currentTime(t, update=True) self.failUnlessEqual(MayaCmds.getAttr('|prism.SPT_int8'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_int8'), 'prism.SPT_int8 not equal') self.failUnlessEqual(MayaCmds.getAttr('|prism.SPT_int16'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_int16'), 'prism.SPT_int16 not equal') self.failUnlessEqual(MayaCmds.getAttr('|prism.SPT_int32'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_int32'), 'prism.SPT_int32 not equal') self.failUnlessAlmostEqual(MayaCmds.getAttr('|prism.SPT_double'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_double'), 4, 'prism.SPT_double not equal') self.failUnlessAlmostEqual( MayaCmds.getAttr('|prism|prismShape.SPT_HwColorR'), MayaCmds.getAttr('|ReloadGrp|prism|prismShape.SPT_HwColorR'), 4, 'prismShape.SPT_HwColorR not equal') self.failUnlessAlmostEqual( MayaCmds.getAttr('|prism|prismShape.SPT_HwColorB'), MayaCmds.getAttr('|ReloadGrp|prism|prismShape.SPT_HwColorB'), 4, 'prismShape.SPT_HwColorB not equal')
def testAnimPropDeleteReload(self): # create some animated properties on a transform node ( could be any type ) nodeName = MayaCmds.polyPrism(ch=False, name = 'prism') MayaCmds.addAttr(longName='SPT_int8', defaultValue=0, attributeType='byte', keyable=True) MayaCmds.addAttr(longName='SPT_int16', defaultValue=100, attributeType='short', keyable=True) MayaCmds.addAttr(longName='SPT_int32', defaultValue=1000, attributeType='long', keyable=True) MayaCmds.addAttr(longName='SPT_float', defaultValue=0.57777777, attributeType='float', keyable=True) MayaCmds.addAttr(longName='SPT_double', defaultValue=5.0456435, attributeType='double', keyable=True) MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(nodeName, attribute='SPT_int8') MayaCmds.setKeyframe(nodeName, attribute='SPT_int16') MayaCmds.setKeyframe(nodeName, attribute='SPT_int32') MayaCmds.setKeyframe(nodeName, attribute='SPT_float') MayaCmds.setKeyframe(nodeName, attribute='SPT_double') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe(nodeName, attribute='SPT_int8', value=8) MayaCmds.setKeyframe(nodeName, attribute='SPT_int16', value=16) MayaCmds.setKeyframe(nodeName, attribute='SPT_int32', value=32) MayaCmds.setKeyframe(nodeName, attribute='SPT_float', value=5.24847) MayaCmds.setKeyframe(nodeName, attribute='SPT_double', value=3.14154) # create SPT_HWColor on the shape node MayaCmds.select('prismShape') MayaCmds.addAttr(longName='SPT_HwColorR', defaultValue=1.0, minValue=0.0, maxValue=1.0) MayaCmds.addAttr(longName='SPT_HwColorG', defaultValue=1.0, minValue=0.0, maxValue=1.0) MayaCmds.addAttr(longName='SPT_HwColorB', defaultValue=1.0, minValue=0.0, maxValue=1.0) MayaCmds.addAttr( longName='SPT_HwColor', usedAsColor=True, attributeType='float3') MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(at='SPT_HwColorR') MayaCmds.setKeyframe(at='SPT_HwColorG') MayaCmds.setKeyframe(at='SPT_HwColorB') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe(at='SPT_HwColorR', value=0.5) MayaCmds.setKeyframe(at='SPT_HwColorG', value=0.15) MayaCmds.setKeyframe(at='SPT_HwColorB', value=0.75) # write them out to an Abc file and load back in self.__files.append(util.expandFileName('testPropReload.abc')) MayaCmds.AbcExport(j='-atp SPT_ -fr 1 24 -root prism -file ' + self.__files[-1]) # load back the Abc file, delete the 2nd letter and save to a maya file abcNode = MayaCmds.AbcImport( self.__files[-1], mode='open' ) # delete connections to animated props prop = MayaCmds.listConnections('|prism.SPT_float', p=True)[0] MayaCmds.disconnectAttr(prop, '|prism.SPT_float') attr = '|prism|prismShape.SPT_HwColorG' prop = MayaCmds.listConnections(attr, p=True)[0] MayaCmds.disconnectAttr(prop, attr) self.__files.append(util.expandFileName('test.mb')) MayaCmds.file(rename=self.__files[-1]) MayaCmds.file(save=True) # import the saved maya file to compare with the original scene MayaCmds.file(self.__files[-1], open=True) MayaCmds.select('prism', replace=True) MayaCmds.group(name='ReloadGrp') MayaCmds.AbcImport(self.__files[-2], mode='import') # test the equality of props for t in range(1, 25): MayaCmds.currentTime(t, update=True) self.failUnlessEqual(MayaCmds.getAttr('|prism.SPT_int8'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_int8'), 'prism.SPT_int8 not equal' ) self.failUnlessEqual(MayaCmds.getAttr('|prism.SPT_int16'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_int16'), 'prism.SPT_int16 not equal') self.failUnlessEqual(MayaCmds.getAttr('|prism.SPT_int32'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_int32'), 'prism.SPT_int32 not equal') self.failUnlessAlmostEqual(MayaCmds.getAttr('|prism.SPT_double'), MayaCmds.getAttr('|ReloadGrp|prism.SPT_double'), 4, 'prism.SPT_double not equal') self.failUnlessAlmostEqual( MayaCmds.getAttr('|prism|prismShape.SPT_HwColorR'), MayaCmds.getAttr('|ReloadGrp|prism|prismShape.SPT_HwColorR'), 4, 'prismShape.SPT_HwColorR not equal') self.failUnlessAlmostEqual( MayaCmds.getAttr('|prism|prismShape.SPT_HwColorB'), MayaCmds.getAttr('|ReloadGrp|prism|prismShape.SPT_HwColorB'), 4, 'prismShape.SPT_HwColorB not equal')
def polyPrism(): cmds.polyPrism()
def polyPrismRange(xx): for x in range(xx): mc.polyPrism()
cmds.select(all=True) cmds.delete() cmds.polySphere(n='Sphere') cmds.polyCube(n='Cube') cmds.move(0, 0, 5) cmds.polyCylinder(n='Cylinder') cmds.move(0, 0, 10) cmds.polyCone(n='Cone') cmds.move(0, 0, 15) cmds.polyTorus(n='Torus') cmds.move(0, 0, 20) cmds.polyPlane(n='Plane') cmds.move(0, 0, 25) #cmds.polyDisc(n='Disc') #cmds.move( 0, 0, 30 ) cmds.polyPyramid(n='Pyramid') cmds.move(0, 0, 30) cmds.polyPlatonicSolid(n='Platonic') cmds.move(0, 0, 35) cmds.polyPrism(n='Prism') cmds.move(0, 0, 40) cmds.polyPipe(n='Pipe') cmds.move(0, 0, 45) cmds.polyHelix(n='Helix') cmds.move(0, 0, 50) #cmds.polyGear(n='Gear') #cmds.move( 0, 0, 60 ) cmds.polyPrimitive(r=1, l=0.4036, pt=0, n='SoccerBall') cmds.move(0, 0, 55)
cylinder = mc.polyCylinder(r=1, h=2, sx=20, sy=1, sz=1, ax=(0, 1, 0), rcp=0, cuv=3, ch=1) mc.scale(2, 1, 2, cylinder, r=True) mc.move(0, 0, -6, r=True) mc.rotate(3, 5, 6, cylinder, r=True, os=True) cone = mc.polyCone(r=1, h=2, sx=20, sy=1, sz=0, ax=(0, 1, 0), rcp=0, cuv=3, ch=1) mc.scale(2, 3, 2, cone, r=True) mc.move(6, 0, 6, cone, r=True) mc.rotate(12, 11, 5, cone, r=True, os=True) torus = mc.polyTorus(r=1, sr=0.5, tx=0, sx=20, sy=0, ax=(0, 1, 0), cuv=3, ch=1) mc.scale(2, 2, 2, torus, r=True) mc.move(-6, 0, 6, torus, r=True) mc.rotate(1, 23, 5, torus, r=True, os=True) prism = mc.polyPrism(w=1, ns=3, sh=1, sc=0, ax=(0, 1, 0), cuv=3, ch=1) mc.scale(2, 2, 2, prism, r=True) mc.move(0, 0, 6, prism, r=True) mc.rotate(1, 4, 30, prism, r=True, os=True) pyramid = mc.polyPyramid(w=1, ns=4, sh=0, sc=0, ax=(0, 1, 0), cuv=3, ch=1) mc.scale(4, 5, 4, pyramid, r=True) mc.move(6, 0, -6, pyramid, r=True) pipe = mc.polyPipe(r=1, h=3, t=0.5, sa=20, sh=1, sc=0, ax=(0, 1, 0), cuv=3, rcp=0, ch=1) mc.scale(2, 2, 2, pipe, r=True) mc.move(-6, 0, -6, pipe, r=True) mc.rotate(14, 32, 30, pipe, r=True, os=True) helix = mc.polyHelix(c=3, h=2, w=2, r=0.4, sa=8, sco=50, sc=0, d=1, ax=(0, 1, 0), cuv=3, rcp=0, ch=1) mc.scale(2, 2, 2, helix, r=True)
def makeRobot(self): """ Function to model a robot. This function creates a robot out of primitive geometry,then stores all of the geometry in a master group. """ # TORSO torso = mc.polyPrism(ch=False, name="torso") mc.setAttr(torso[0] + ".translateY", 2.5) mc.setAttr(torso[0] + ".rotateY", -90) mc.setAttr(torso[0] + ".scale", 3, .92, 3) # HIPS hips = mc.polyCylinder(ch=False, name="hips") mc.setAttr(hips[0] + ".translateY", 1.53) mc.setAttr(hips[0] + ".scale", .85, .05, .85) # LEFT LEG leftLeg = mc.polyCylinder(ch=False, name="leftLeg") mc.setAttr(leftLeg[0] + ".translate", .5, 1, 0) mc.setAttr(leftLeg[0] + ".rotateZ", 20) mc.setAttr(leftLeg[0] + ".scale", .12, .6, .12) # LEFT ANKLE leftAnkle = mc.polyCylinder(ch=False, name="leftAnkle") mc.setAttr(leftAnkle[0] + ".translate", .67, .58, 0) mc.setAttr(leftAnkle[0] + ".rotateZ", 20) mc.setAttr(leftAnkle[0] + ".scale", .23, .23, .23) # LEFT FOOT leftFoot = mc.polySphere(ch=False, name="leftFoot") mc.setAttr(leftFoot[0] + ".translate", .80, .24, 0) mc.setAttr(leftFoot[0] + ".rotateZ", 20) mc.setAttr(leftFoot[0] + ".scale", .49, .49, .4) # RIGHT LEG rightLeg = mc.polyCylinder(ch=False, name="rightLeg") mc.setAttr(rightLeg[0] + ".translate", .5, 1, 0) mc.setAttr(rightLeg[0] + ".rotateZ", 20) mc.setAttr(rightLeg[0] + ".scale", .12, .6, .12) # RIGHT ANKLE rightAnkle = mc.polyCylinder(ch=False, name="rightAnkle") mc.setAttr(rightAnkle[0] + ".translate", .67, .58, 0) mc.setAttr(rightAnkle[0] + ".rotateZ", 20) mc.setAttr(rightAnkle[0] + ".scale", .23, .23, .23) # RIGHT FOOT rightFoot = mc.polySphere(ch=False, name="rightFoot") mc.setAttr(rightFoot[0] + ".translate", .80, .24, 0) mc.setAttr(rightFoot[0] + ".rotateZ", 20) mc.setAttr(rightFoot[0] + ".scale", .49, .49, .4) # CREATES A RIGHT LEG GROUP FOR ROTATION mc.select(d=True) rtLegGroup = mc.group(em=True, name="rtLegGroup") rightLeg = mc.parent(rightLeg[0], rtLegGroup) rightAnkle = mc.parent(rightAnkle[0], rtLegGroup) rightFoot = mc.parent(rightFoot[0], rtLegGroup) mc.setAttr(rtLegGroup + ".scaleX", -1.0) # DELETES RIGHT LEG GROUP rightLeg = mc.parent(rightLeg[0], world=True) rightAnkle = mc.parent(rightAnkle[0], world=True) rightFoot = mc.parent(rightFoot[0], world=True) mc.delete(rtLegGroup) # GEAR BOX gearBox = mc.polyCube(ch=False, name="gearBox") mc.setAttr(gearBox[0] + ".translate", .2, 2.8, 1.4) mc.setAttr(gearBox[0] + ".rotateY", 58) mc.setAttr(gearBox[0] + ".scale", .4, .4, .04) # LEFT ARM leftArm = mc.polyCylinder(ch=False, name="leftArm") mc.setAttr(leftArm[0] + ".translate", 1.89, 3, 0) mc.setAttr(leftArm[0] + ".rotateZ", 90) mc.setAttr(leftArm[0] + ".scale", .21, 1.2, .21) # RIGHT ARM rightArm = mc.polyCylinder(ch=False, name="rightArm") mc.setAttr(rightArm[0] + ".translate", -1.89, 3, 0) mc.setAttr(rightArm[0] + ".rotateZ", 90) mc.setAttr(rightArm[0] + ".scale", .21, 1.2, .21) #Left Shoulder leftShoulder = mc.polyTorus(ch=False, name="leftShoulder") mc.setAttr(leftShoulder[0] + ".translate", 1.2, 2.95, -0.08) mc.setAttr(leftShoulder[0] + ".rotate", -32, 0, 90) mc.setAttr(leftShoulder[0] + ".scale", .35, .35, .35) #Right Shoulder rightShoulder = mc.polyTorus(ch=False, name="rightShoulder") mc.setAttr(rightShoulder[0] + ".translate", -1.2, 2.95, -0.08) mc.setAttr(rightShoulder[0] + ".rotate", -32, 0, -90) mc.setAttr(rightShoulder[0] + ".scale", .35, .35, .35) # LEFT HAND leftHand = mc.polySphere(ch=False, name="leftHand") mc.setAttr(leftHand[0] + ".translate", 3, 2.95, 0) mc.setAttr(leftHand[0] + ".scale", .4, .4, .4) # RIGHT HAND rightHand = mc.polySphere(ch=False, name="rightHand") mc.setAttr(rightHand[0] + ".translate", -3, 2.95, 0) mc.setAttr(rightHand[0] + ".scale", .4, .4, .4) # NECK neck = mc.polyCube(ch=False, name="neck") mc.setAttr(neck[0] + ".translateY", 3.4) mc.setAttr(neck[0] + ".scale", .6, .5, .6) # HEAD head = mc.polyCube(ch=False, name="head") mc.setAttr(head[0] + ".translate", 0, 4.5, 0.2) mc.setAttr(head[0] + ".scale", 2.9, 1.8, 2.8) # HEAD WIRE headWire = mc.polyCylinder(ch=False, name="headWire") mc.setAttr(headWire[0] + ".translateY", 5.7) mc.setAttr(headWire[0] + ".scale", .12, .5, .12) # HEAD TOP headTop = mc.polySphere(ch=False, name="headTop") mc.setAttr(headTop[0] + ".translateY", 6.35) mc.setAttr(headTop[0] + ".scale", .55, .55, .55) # LEFT EYE leftEye = mc.polyCylinder(ch=False, name="leftEye") mc.setAttr(leftEye[0] + ".translate", .8, 4.9, 1.57) mc.setAttr(leftEye[0] + ".rotateX", 90) mc.setAttr(leftEye[0] + ".scale", .4, .2, .4) # RIGHT EYE rightEye = mc.polyCylinder(ch=False, name="rightEye") mc.setAttr(rightEye[0] + ".translate", -0.8, 4.9, 1.57) mc.setAttr(rightEye[0] + ".rotateX", 90) mc.setAttr(rightEye[0] + ".scale", .4, .2, .4) # MOUTH mouth = mc.polyCube(ch=False, name="mouth") mc.setAttr(mouth[0] + ".translate", 0, 4.35, 1.57) mc.setAttr(mouth[0] + ".scale", 1, .3, .3) # PUTS ALL PARTS INTO A LIST bodyParts = [ torso, hips, leftLeg, leftAnkle, leftFoot, rightLeg, rightAnkle, rightFoot, gearBox, leftArm, leftShoulder, leftHand, rightArm, rightShoulder, rightHand, neck, head, headWire, headTop, leftEye, rightEye, mouth ] # CREATES THE EMPTY MASTER GROUP mc.select(d=True) robotGroup = mc.group(em=True, name="robotGroup{0}".format(1)) # PARENTS EACH BODY PART TO THE MASTER GROUP for obj in bodyParts: parts = mc.parent(obj, robotGroup) return robotGroup
mx.polyPlane(n='plane5',w=5,h=5,ax=(0,0,1)) mx.move(0,2.5,2.5) mx.polyPlane(n='plane6',w=5,h=5,ax=(0,0,-1)) mx.move(0,2.5,-2.5) Polyprism w = sideLenght ns= number of sides sh= subdivisionsHeight sc= subdivisionsCap EX. import maya.cmds as mx mx.file(f=1,new=1) mx.polyPrism(n='pp1',w=5) mx.polyPrism(n='pp2',w=5,l=10,ax=(1,0,0)) mx.rotate(0,90,0) mx.polyPrism(n='pp3',w=5,l=10,ax=(1,0,0)) Make polyprism to roof of house EX. import maya.cmds as mx mx.file(f=1,new=1) mx.polyPrism(n='pp2',w=5,l=10,ax=(-1,0,0)) mx.rotate(0,90,0) mx.polyPrism(n='pp3',w=5,l=10,ax=(-1,0,0))