def spawnAliens(num_aliens): #----------------------Generate X-amount of aliens------------------- #---make gravity field if it doesn't already exist gravName = cmds.ls( 'alienGrav*' ) print gravName if gravName == []: print "make grav" cmds.gravity(n="alienGrav", pos = (0, 0, 0), m=980, att=0, dx=0, dy=-1, dz=0, mxd=-1, vsh="none", vex=0, vof=(0, 0, 0), vsw=360, tsr=0.5) for i in range(0, num_aliens): #Give each a unique name curName = "alien" curName = curName+str(i) cmds.duplicate('alien', n=curName) #---Place in random location cmds.setAttr(curName+".translateX", random.randrange(-MAX_DIST, MAX_DIST)) cmds.setAttr(curName+".translateY", 200) cmds.setAttr(curName+".translateZ", random.randrange(-MAX_DIST, MAX_DIST)) #Random orientation cmds.setAttr(curName+".rotateX", random.randrange(360)) cmds.setAttr(curName+".rotateY", random.randrange(360)) cmds.setAttr(curName+".rotateZ", random.randrange(360)) #Connect up to gravity cmds.connectDynamic(curName, f="alienGrav") #Connect up to gravity cmds.connectDynamic("alien", f="alienGrav")
def spawnMolecules(num_molecules): #----------------------Generate X-amount of molecules------------------- setUpMolecule() for i in range(0, num_molecules): #Give each a unique name curName = "molecule" curName = curName+str(i) cmds.duplicate('molecule', n=curName) #---Place in random location cmds.setAttr(curName+".translateX", random.randrange(MAX_DIST)) cmds.setAttr(curName+".translateY", random.randrange(MAX_DIST)) cmds.setAttr(curName+".translateZ", random.randrange(MAX_DIST)) #Random orientation cmds.setAttr(curName+".rotateX", random.randrange(360)) cmds.setAttr(curName+".rotateY", random.randrange(360)) cmds.setAttr(curName+".rotateZ", random.randrange(360)) #Set rotation of legs #These set numbers are arbitrary, but these locations looked good. cmds.setAttr(curName+"|realignGroup1.rotateZ", -39.4)#random.randrange(360)) cmds.setAttr(curName+"|realignGroup2.rotateZ", 217.6)#cmds.getAttr(curName+"|hydroAssembly1.rotateZ")+104) #Get number from 0 to 1. 0=symmetrical 1= asymmetrical stretchType = random.randrange(0,2) #Set up stretching anims based on our assigned type if stretchType == 0: symStretch(curName) else: asymStretch(curName) #Set up bending motion (oscillating animation) bend(curName) #Set some random movement for i in range(1, ANIM_LENGTH): #--------Assign a random animation state---------- #---Move molecule to new location every five frames if i % 5 == 0: curPosX = cmds.getAttr(curName+".translateX") curPosY = cmds.getAttr(curName+".translateY") curPosZ = cmds.getAttr(curName+".translateZ") #Move to random position and keyframe cmds.setKeyframe(curName, at="translateX", t=i, v=curPosX + random.randrange(BROWNIAN_OFFSET)) cmds.setKeyframe(curName, at="translateY", t=i, v=curPosY + random.randrange(BROWNIAN_OFFSET)) cmds.setKeyframe(curName, at="translateZ", t=i, v=curPosZ + random.randrange(BROWNIAN_OFFSET)) #Every five frames, randomly rotate if i % 5 == 0 and i != 0: #Random rotation randNum = random.randrange(3,6) animations[randNum](curName, i, random.randrange(MAX_ROT)) #--_Delete first molecule that we used to duplicate the rest cmds.delete('molecule')
def _CreateSphereButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ sphere = cmds.polySphere(r=20, name="sphere1") cmds.duplicate('sphere1') response = nimble.createRemoteResponse(globals()) response.put('name', sphere) global created created = 'sphere'
def _CreateCubeButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ cube = cmds.polyCube(w=20, h=20, d=20, name="cube1") cmds.duplicate('cube1') response = nimble.createRemoteResponse(globals()) response.put('name', cube) global created created = 'cube'
def _CreateCubeButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ cube = cmds.polyCube(w=20,h=20,d=20,name="cube1") cmds.duplicate('cube1') response = nimble.createRemoteResponse(globals()) response.put('name', cube) global created created = 'cube'
def _duplicate(self): #set the random seed random.seed(1024) for i in range (0, 100): cmds.duplicate('H2O') #let the instances rotate objName='H2O' + str(i+1) #random place x = random.uniform(-30,30) y = random.uniform(0, 40) z = random.uniform(-30, 30) cmds.move(x, y, z, objName) #random rotate xRot=random.uniform(0, 360) yRot=random.uniform(0, 360) zRot=random.uniform(0, 360) cmds.rotate(xRot, yRot, zRot, objName)
def spawnAliens(num_aliens): #----------------------Generate X-amount of aliens------------------- #---make gravity field if it doesn't already exist gravName = cmds.ls('alienGrav*') print gravName if gravName == []: print "make grav" cmds.gravity(n="alienGrav", pos=(0, 0, 0), m=980, att=0, dx=0, dy=-1, dz=0, mxd=-1, vsh="none", vex=0, vof=(0, 0, 0), vsw=360, tsr=0.5) for i in range(0, num_aliens): #Give each a unique name curName = "alien" curName = curName + str(i) cmds.duplicate('alien', n=curName) #---Place in random location cmds.setAttr(curName + ".translateX", random.randrange(-MAX_DIST, MAX_DIST)) cmds.setAttr(curName + ".translateY", 200) cmds.setAttr(curName + ".translateZ", random.randrange(-MAX_DIST, MAX_DIST)) #Random orientation cmds.setAttr(curName + ".rotateX", random.randrange(360)) cmds.setAttr(curName + ".rotateY", random.randrange(360)) cmds.setAttr(curName + ".rotateZ", random.randrange(360)) #Connect up to gravity cmds.connectDynamic(curName, f="alienGrav") #Connect up to gravity cmds.connectDynamic("alien", f="alienGrav")
def _handleExampleButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ random.seed(1234) #check sphereList = cmds.ls('hydrogen1', 'hydrogen2', 'oxygen', 'H2O') if len(sphereList) > 0: cmds.delete(sphereList) #create 2 hydrogen and oxygen h1 = cmds.polySphere(r=12.0, name='hydrogen1') h2 = cmds.polySphere(r=12.0, name='hydrogen2') oxygen = cmds.polySphere(r=15.0, name='oxygen') #move cmds.move(-15, 0, 0, h1) cmds.move(15, 0, 0, h2) cmds.xform(h1, piv=[0, 0, 0], ws=True) cmds.xform(h2, piv=[0, 0, 0], ws=True) cmds.rotate(0, '75', 0, h1) #group hydrogen and oxygen together H2O = cmds.group(empty=True, name='H2O#') cmds.parent('hydrogen1', 'hydrogen2', 'oxygen', 'H2O1') #add color def createMaterial(name, color, type): cmds.sets(renderable=True, noSurfaceShader=True, empty=True, name=name + 'SG') cmds.shadingNode(type, asShader=True, name=name) cmds.setAttr(name + '.color', color[0], color[1], color[2], type='double3') cmds.connectAttr(name + '.outColor', name + 'SG.surfaceShader') def assignMaterial(name, object): cmds.sets(object, edit=True, forceElement=name + 'SG') def assignNewMaterial(name, color, type, object): createMaterial(name, color, type) assignMaterial(name, object) #H is white and O is red assignNewMaterial('Red', (1, 0, 0), 'lambert', 'oxygen') assignNewMaterial('White', (1, 1, 1), 'lambert', 'hydrogen1') assignMaterial('White', 'hydrogen2') #key frame def keyFullRotation(pObjectName, pStartTime, pEndTime, pTargetAttribute, pValueStart, pvalueEnd): keyt = (pStartTime[0], pStartTime[0]) cmds.cutKey(pObjectName, time=(keyt, keyt), attribute=pTargetAttribute) cmds.setKeyframe(pObjectName, time=pStartTime, attribute=pTargetAttribute, value=pValueStart) cmds.setKeyframe(pObjectName, time=pEndTime, attribute=pTargetAttribute, value=pvalueEnd) #cmds.selectKey( pObjectName, time=(pStartTime, [pEndTime]), attribute=pTargetAttribute, keyframe=True ) #duplicate H2O for i in range(1, 52): cmds.duplicate(H2O) #get random coord x = random.uniform(-200, 200) y = random.uniform(0, 300) z = random.uniform(-200, 200) cmds.move(x, y, z, H2O) xRot = random.uniform(0, 360) yRot = random.uniform(0, 360) zRot = random.uniform(0, 360) cmds.rotate(xRot, yRot, zRot, H2O) startTime = cmds.playbackOptions(minTime=1) endTime = cmds.playbackOptions(maxTime=30) h2o = "H2O" + str(i) for y in range(3): coordsX = cmds.getAttr(h2o + '.translateX') coordsY = cmds.getAttr(h2o + '.translateY') coordsZ = cmds.getAttr(h2o + '.translateZ') ranStartX = int(random.uniform(0, 15)) ranStartY = int(random.uniform(0, 15)) ranStartZ = int(random.uniform(0, 15)) ranEndX = int(random.uniform(15, 30)) ranEndY = int(random.uniform(15, 30)) ranEndZ = int(random.uniform(15, 30)) x = random.uniform(coordsX - 50, coordsX + 50) y = random.uniform(coordsY, coordsY + 50) z = random.uniform(coordsZ - 50, coordsZ + 50) #print x,y,z keyFullRotation(h2o, ranStartZ, 15, 'translateZ', coordsZ, z) keyFullRotation(h2o, ranStartX, 15, 'translateX', coordsX, x) keyFullRotation(h2o, ranStartY, 15, 'translateY', coordsY, y) keyFullRotation(h2o, 15, ranEndZ, 'translateZ', z, coordsZ) keyFullRotation(h2o, 15, ranEndX, 'translateX', x, coordsX) keyFullRotation(h2o, 15, ranEndY, 'translateY', y, coordsY) RcoordsX = cmds.getAttr(h2o + '.rotateX') RcoordsY = cmds.getAttr(h2o + '.rotateY') RcoordsZ = cmds.getAttr(h2o + '.rotateZ') xRot = random.uniform(0, 360) yRot = random.uniform(0, 360) zRot = random.uniform(0, 360) keyFullRotation(h2o, ranStartZ, 15, 'rotateZ', RcoordsZ, zRot) keyFullRotation(h2o, ranStartX, 15, 'rotateX', RcoordsX, xRot) keyFullRotation(h2o, ranStartY, 15, 'rotateY', RcoordsY, zRot) keyFullRotation(h2o, 15, ranEndZ, 'rotateZ', zRot, RcoordsZ) keyFullRotation(h2o, 15, ranEndX, 'rotateX', xRot, RcoordsX) keyFullRotation(h2o, 15, ranEndY, 'rotateY', zRot, RcoordsY) print 'done' cmds.delete('H2O52')
def _handleExampleButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ random.seed(1234) #check sphereList = cmds.ls('hydrogen1','hydrogen2', 'oxygen','H2O') if len(sphereList)>0: cmds.delete(sphereList) #create 2 hydrogen and oxygen h1 = cmds.polySphere(r=12.0, name='hydrogen1') h2 = cmds.polySphere(r=12.0, name='hydrogen2') oxygen = cmds.polySphere(r=15.0, name='oxygen') #move cmds.move(-15,0,0,h1) cmds.move(15,0,0,h2) cmds.xform(h1, piv=[0,0,0],ws=True) cmds.xform(h2, piv=[0,0,0],ws=True) cmds.rotate(0,'75',0,h1) #group hydrogen and oxygen together H2O = cmds.group(empty=True, name='H2O#') cmds.parent('hydrogen1','hydrogen2','oxygen','H2O1') #add color def createMaterial( name, color, type ): cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name=name + 'SG' ) cmds.shadingNode( type, asShader=True, name=name ) cmds.setAttr( name+'.color', color[0], color[1], color[2], type='double3') cmds.connectAttr(name+'.outColor', name+'SG.surfaceShader') def assignMaterial (name, object): cmds.sets(object, edit=True, forceElement=name+'SG') def assignNewMaterial( name, color, type, object): createMaterial (name, color, type) assignMaterial (name, object) #H is white and O is red assignNewMaterial('Red', (1,0,0), 'lambert', 'oxygen'); assignNewMaterial('White',(1,1,1),'lambert', 'hydrogen1'); assignMaterial('White', 'hydrogen2'); #key frame def keyFullRotation( pObjectName, pStartTime, pEndTime, pTargetAttribute,pValueStart, pvalueEnd ): keyt = (pStartTime[0], pStartTime[0]) cmds.cutKey( pObjectName, time=(keyt, keyt), attribute=pTargetAttribute ) cmds.setKeyframe( pObjectName, time=pStartTime, attribute=pTargetAttribute, value=pValueStart ) cmds.setKeyframe( pObjectName, time=pEndTime, attribute=pTargetAttribute, value=pvalueEnd ) #cmds.selectKey( pObjectName, time=(pStartTime, [pEndTime]), attribute=pTargetAttribute, keyframe=True ) #duplicate H2O for i in range(1,52): cmds.duplicate(H2O) #get random coord x = random.uniform(-200,200) y = random.uniform(0,300) z = random.uniform(-200,200) cmds.move(x,y,z, H2O) xRot = random.uniform(0,360) yRot = random.uniform(0,360) zRot = random.uniform(0,360) cmds.rotate(xRot,yRot,zRot,H2O) startTime = cmds.playbackOptions(minTime=1 ) endTime = cmds.playbackOptions( maxTime=30 ) h2o = "H2O"+str(i) for y in range(3): coordsX = cmds.getAttr( h2o+'.translateX' ) coordsY = cmds.getAttr( h2o+'.translateY' ) coordsZ = cmds.getAttr( h2o+'.translateZ' ) ranStartX = int(random.uniform(0,15)) ranStartY = int(random.uniform(0,15)) ranStartZ = int(random.uniform(0,15)) ranEndX = int(random.uniform(15,30)) ranEndY = int(random.uniform(15,30)) ranEndZ = int(random.uniform(15,30)) x = random.uniform(coordsX-50,coordsX+50) y = random.uniform(coordsY,coordsY+50) z = random.uniform(coordsZ-50,coordsZ+50) #print x,y,z keyFullRotation( h2o, ranStartZ, 15, 'translateZ',coordsZ,z) keyFullRotation( h2o, ranStartX, 15, 'translateX', coordsX,x) keyFullRotation( h2o, ranStartY, 15, 'translateY', coordsY,y) keyFullRotation( h2o, 15, ranEndZ, 'translateZ',z,coordsZ) keyFullRotation( h2o, 15, ranEndX, 'translateX', x,coordsX) keyFullRotation( h2o, 15, ranEndY, 'translateY', y,coordsY) RcoordsX = cmds.getAttr( h2o+'.rotateX' ) RcoordsY = cmds.getAttr( h2o+'.rotateY' ) RcoordsZ = cmds.getAttr( h2o+'.rotateZ' ) xRot = random.uniform(0,360) yRot = random.uniform(0,360) zRot = random.uniform(0,360) keyFullRotation( h2o, ranStartZ, 15, 'rotateZ',RcoordsZ,zRot) keyFullRotation( h2o, ranStartX, 15, 'rotateX', RcoordsX,xRot) keyFullRotation( h2o, ranStartY, 15, 'rotateY', RcoordsY,zRot) keyFullRotation( h2o, 15, ranEndZ, 'rotateZ',zRot,RcoordsZ) keyFullRotation( h2o, 15, ranEndX, 'rotateX', xRot,RcoordsX) keyFullRotation( h2o, 15, ranEndY, 'rotateY', zRot,RcoordsY) print 'done' cmds.delete('H2O52')
def _handleCreateH2o(self): """ """ #Sets the animation end time cmds.playbackOptions(max=240, aet=240) #this number sets the number of molecules to create molecules = 10 #Creates each atom in the h2o molecule, aligns them properly, then groups them together . cmds.polySphere(name="oxygen", r=1.2) cmds.polySphere(name="hydrogenA", r=1.06) cmds.select("hydrogenA") cmds.move(0, -1.3, 0) cmds.group('oxygen', 'hydrogenA', n='oxygenHydrogenA') cmds.select('hydrogenA') cmds.rotate(0, 0, '-52.5', p=(0, 0, 0)) cmds.polySphere(name="hydrogenB", r=1.06) cmds.select("hydrogenB") cmds.move(0, -1.3, 0) cmds.group('oxygen', 'hydrogenB', n='oxygenHydrogenB') cmds.select('hydrogenB') cmds.rotate(0, 0, '52.5', p=(0, 0, 0)) cmds.select('hydrogenA', 'hydrogenB') cmds.polyColorPerVertex(rgb=(1, 1, 1), cdo=True) cmds.select('oxygen') cmds.polyColorPerVertex(rgb=(1, 0, 0), cdo=True) cmds.group('oxygenHydrogenB', 'oxygenHydrogenA', n='h2o') #duplicates the original molecule for i in range(1, molecules): cmds.duplicate('h2o') #list of planes for movement xyz = ['X', 'Y'] #Sets movement for the original h2o molecule cmds.select("h2o") plane = random.choice(xyz) cmds.setKeyframe('h2o', at='translate' + plane, v=float(cmds.getAttr('h2o.translate' + plane)), t=1) cmds.setKeyframe('h2o', at='translate' + plane, v=5, t=240) #Iterates through each h2o group and assigns a random position and orientation for each molecule. #It also randomly choose a direction for the molecule to move in. for i in range(1, molecules): #random plane plane = random.choice(xyz) cmds.select("h2o" + str(i)) #random position cmds.move(random.randrange(-9, 9), random.randrange(-9, 9), random.randrange(-9, 9)) #random orientation cmds.rotate(random.randrange(0, 350), random.randrange(0, 350), random.randrange(0, 350)) #sets the start and end position for movement cmds.setKeyframe( 'h2o' + str(i), at='translate' + plane, v=float(cmds.getAttr('h2o' + str(i) + '.translate' + plane)), t=1) cmds.setKeyframe('h2o' + str(i), at='translate' + plane, v=5, t=240) plane = random.choice(xyz) #Selects all the h2o molecules cmds.select("h2o", add=True) for i in range(1, molecules): cmds.select("h2o" + str(i)) #Creates a new animation layer called vibrate and adds all the h2o molecules to it. cmds.animLayer('vibrate', aso=True) #Sets oscillation for original molecule cmds.setKeyframe('h2o', at='translateZ', v=float(cmds.getAttr('h2o.translateZ')), t=1) cmds.setKeyframe('h2o', at='translateZ', v=float(cmds.getAttr('h2o.translateZ')) + .2, t=2) #cmds.selectKey('h2o', t=(1,2), at="translateZ") cmds.selectKey('h2o', at='translateZ') cmds.setInfinity(pri='oscillate', poi='oscillate') #Sets oscillation for all other molecules for i in range(1, molecules): cmds.setKeyframe('h2o' + str(i), at='translateZ', v=float( cmds.getAttr('h2o' + str(i) + '.translateZ')), t=1) cmds.setKeyframe( 'h2o' + str(i), at='translateZ', v=float(cmds.getAttr('h2o' + str(i) + '.translateZ')) + .2, t=2) #cmds.selectKey('h2o'+str(i), t=(1,2), at="translateZ") cmds.selectKey('h2o' + str(i), at="translateZ") cmds.setInfinity(pri='oscillate', poi='oscillate')
def _handleExample2Button(self): """ This callback creates a polygonal cylinder in the Maya scene. r = 50 a = 2.0*r y = (0, 1, 0) c = cmds.polyCylinder( r=r, h=5, sx=40, sy=1, sz=1, ax=y, rcp=0, cuv=2, ch=1, n='exampleCylinder')[0] cmds.select(c) response = nimble.createRemoteResponse(globals()) response.put('name', c) """ # creat the transparent container cmds.polyCylinder(name='container', r=1.6, axis=(0, 1, 0), height=3.2) cmds.select('container') cmds.polyColorPerVertex(r=0.4, g=1, b=1, a=0.05, colorDisplayOption=True) cmds.move(0.0, 1.6, 0, relative=True) # create a bubble cmds.polySphere(name='bubble', radius=0.01) pos_x = 0 pos_y = 0 pos_z = 0 total_bubbles = 50 for nth_num in xrange(0, total_bubbles): bubble = 'bubble' + str(nth_num) cmds.duplicate('bubble', n=bubble) cmds.select(bubble) cmds.polyColorPerVertex(r=1, g=1, b=0.75, a=1, colorDisplayOption=True) x_vib = random.uniform(-1.0, 1.0) z_vib = random.uniform(-1.0, 1.0) cmds.move(x_vib, 0.0, z_vib, bubble) start_frame = int(random.uniform(0, 124 - 30)) print start_frame xRot = random.uniform(0, 360) yRot = random.uniform(0, 360) zRot = random.uniform(0, 360) for frame in xrange(0, 124): if ( frame - start_frame >= 0 and frame - start_frame < 30 ): # the first 40 frames, the bubble remains at the bottom while growing bigger cmds.setKeyframe(bubble, attribute='scaleX', value=0.5 * ((frame - start_frame) / 30.0), t=frame) cmds.setKeyframe(bubble, attribute='scaleY', value=0.3 * ((frame - start_frame) / 30.0), t=frame) cmds.setKeyframe(bubble, attribute='scaleZ', value=0.5 * ((frame - start_frame) / 30.0), t=frame) elif (frame - start_frame >= 30): pos_y = 3.0 * ( (frame - start_frame - 30) / 84.0 ) # from frame 40, the bubble getting bigger and ascend to the top pos_x = x_vib + random.uniform(-0.03, 0.03) pos_z = z_vib + random.uniform(-0.03, 0.03) xRot = xRot + 0.3 yRot = yRot + 0.03 zRot = zRot + 0.3 factor = 1.1 * math.tan(3.14 / 4 * frame / 124.0) #cmds.blendShape(edit=True,en=0.8) cmds.setKeyframe(bubble, attribute='translateX', value=pos_x, t=frame) cmds.setKeyframe(bubble, attribute='translateY', value=pos_y, t=frame) cmds.setKeyframe(bubble, attribute='translateZ', value=pos_z, t=frame) cmds.setKeyframe(bubble, attribute='scaleX', value=0.5 + 3.0 * factor * ((frame - start_frame) / 84.0), t=frame) cmds.setKeyframe(bubble, attribute='scaleY', value=0.3 + 1.8 * factor * ((frame - start_frame) / 84.0), t=frame) cmds.setKeyframe(bubble, attribute='scaleZ', value=0.5 + 2.4 * factor * ((frame - start_frame) / 84.0), t=frame) cmds.setKeyframe(bubble, attribute='rotateX', value=xRot, t=frame) cmds.setKeyframe(bubble, attribute='rotateY', value=yRot, t=frame) cmds.setKeyframe(bubble, attribute='rotateZ', value=zRot, t=frame) cmds.delete('bubble')
def setUpMolecule(): #Adjust time slider cmds.playbackOptions( minTime='1', maxTime='300', mps=1) # Create the oxygen part of the larger bond (cylinder) cmds.polyCylinder(n='oxyCylinder', r=1, h=2, sx=20, sy=1, sz=1, ax=(1, 0, 0), rcp=0, cuv=3, ch=1) #Set scale for oxyCylinder cmds.setAttr("oxyCylinder.translateX", 6) cmds.setAttr("oxyCylinder.scaleZ", 2) cmds.setAttr("oxyCylinder.scaleX", 2) cmds.setAttr("oxyCylinder.scaleY", 2) #-------Set up shader and shade cylinder---------- redShader = cmds.shadingNode('blinn', asShader=True, n='redBlinn') cmds.setAttr("redBlinn.color", 0.772, 0, 0, type="double3") cmds.select('oxyCylinder') cmds.hyperShade(assign=redShader) #--------------White Cylinder------------- # Create the oxygen part of the larger bond (cylinder) cmds.polyCylinder(n='hydroCylinder', r=1, h=2, sx=20, sy=1, sz=1, ax=(1, 0, 0), rcp=0, cuv=3, ch=1) #Set scale for oxyCylinder cmds.setAttr("hydroCylinder.translateX", 10) cmds.setAttr("hydroCylinder.scaleZ", 2) cmds.setAttr("hydroCylinder.scaleX", 2) cmds.setAttr("hydroCylinder.scaleY", 2) #-------Set up shader and shade cylinder---------- whiteShader = cmds.shadingNode('blinn', asShader=True, n='whiteBlinn') cmds.setAttr("whiteBlinn.color", 1, 1, 1, type="double3") #Select the cylinder to color cmds.select('hydroCylinder') # Assign shader cmds.hyperShade(assign=whiteShader) #---------------------------------------------------------- #-----------Group two cylinders together as "cylinder"----- #---------------------------------------------------------- cmds.group(em=True, n='cylinder') cmds.parent('oxyCylinder', 'cylinder') cmds.parent('hydroCylinder', 'cylinder') #------------Oxygen------------- # Create the Oxygen sphere cmds.polySphere(n='oxygen', r=1, sx=20, sy=20, ax=(0, 1, 0), cuv=2, ch=1) #Set scale for oxygen cmds.setAttr("oxygen.scaleZ", 5) cmds.setAttr("oxygen.scaleX", 5) cmds.setAttr("oxygen.scaleY", 5) #-------Assign shader-------- cmds.select('oxygen') cmds.hyperShade(assign=redShader) #------------Hydrogen------------- # Create the Hydrogen sphere cmds.polySphere(n='hydrogen', r=1, sx=20, sy=20, ax=(0, 1, 0), cuv=2, ch=1) #Set scale for oxygen cmds.setAttr("hydrogen.translateX", 14) cmds.setAttr("hydrogen.scaleZ", 4) cmds.setAttr("hydrogen.scaleX", 4) cmds.setAttr("hydrogen.scaleY", 4) #-------Assign shader-------- cmds.select('hydrogen') cmds.hyperShade(assign=whiteShader) #---------------------------------------------------------- #-----------Group 'cylinder' and hydrogen together as "hydroAssembly"----- #---------------------------------------------------------- cmds.group(em=True, n='hydroAssembly1') cmds.parent('cylinder', 'hydroAssembly1') cmds.parent('hydrogen', 'hydroAssembly1') #---------------------------------------------------------- #-----------Group into realign group #---------------------------------------------------------- cmds.group(em=True, n='realignGroup1') cmds.parent('hydroAssembly1', 'realignGroup1') #------------------------------------------------------------- #------------Duplicate the assembly-------------------------- #------------------------------------------------------------- cmds.duplicate('realignGroup1', n='realignGroup2') cmds.setAttr('realignGroup2.rotateZ', 180) cmds.rename('realignGroup2|hydroAssembly1','hydroAssembly2') #---------------------------------------------------------- #-----------Make entire thing a group "molecule"----- #---------------------------------------------------------- cmds.group(em=True, n='molecule') cmds.parent('oxygen', 'molecule') cmds.parent('realignGroup1', 'molecule') cmds.parent('realignGroup2', 'molecule') #-------Move entire molecule up------- cmds.setAttr("molecule.translateY", 10)
def _createGeometry(self, name): #self.spine = mc.polyCylinder(h=75,r=2,n=name+'_spine')[0] #mc.move(0,30,0) self.pelvic = mc.polyCylinder(h=40, r=2, n=name + '_pelvic')[0] mc.rotate(0, 0, '90deg') self.clavical = mc.polyCylinder(h=56, r=2, n=name + '_clavical')[0] mc.rotate(0, 0, '90deg') mc.move(0, 67, 0) #self.hip = mc.polySphere(r=5,n=name+'_hip') self.hipPlate = mc.polyCube(w=50, d=10, h=5) mc.move(0, 15, 0) self.hipPlate2 = mc.polyCube(w=8, d=5, h=35)[0] mc.move(12, 0, 15) mc.select(self.hipPlate2 + '.e[10]') mc.move(0, 3, 0, r=True) mc.select(self.hipPlate2 + '.e[0]') mc.move(0, 3, 0, r=True) mc.select(self.hipPlate2 + '.e[6]') mc.move(0, -3, 0, r=True) mc.select(self.hipPlate2 + '.e[1]') mc.move(0, -3, 0, r=True) mc.select(self.hipPlate2 + '.e[4]') mc.move(3, 0, 0, r=True) mc.select(self.hipPlate2) mc.rotate(-10, 0, 0) self.hipPlate3 = mc.polyCube(w=15, d=5, h=35)[0] mc.move(23.5, 0, 15) mc.select(self.hipPlate3 + '.e[11]') mc.move(0, 10, 0, r=True) mc.select(self.hipPlate3 + '.e[0]') mc.move(0, 3, 0, r=True) mc.select(self.hipPlate3 + '.e[7]') mc.move(-6, -3, 0, r=True) mc.select(self.hipPlate3 + '.e[1]') mc.move(0, -3, 0, r=True) mc.select(self.hipPlate3 + '.e[5]') mc.move(-3, 0, 0, r=True) mc.select(self.hipPlate3) mc.rotate(-10, 0, 0) self.hipPlate4 = mc.polyCube(w=8, d=5, h=35)[0] mc.move(-12, 0, 15) mc.select(self.hipPlate4 + '.e[11]') mc.move(0, 3, 0, r=True) mc.select(self.hipPlate4 + '.e[0]') mc.move(0, 3, 0, r=True) mc.select(self.hipPlate4 + '.e[7]') mc.move(0, -3, 0, r=True) mc.select(self.hipPlate4 + '.e[1]') mc.move(0, -3, 0, r=True) mc.select(self.hipPlate4 + '.e[5]') mc.move(-3, 0, 0, r=True) mc.select(self.hipPlate4) mc.rotate(-10, 0, 0) self.hipPlate5 = mc.polyCube(w=15, d=5, h=35)[0] mc.move(-23.5, 0, 15) mc.select(self.hipPlate5 + '.e[10]') mc.move(0, 10, 0, r=True) mc.select(self.hipPlate5 + '.e[0]') mc.move(0, 3, 0, r=True) mc.select(self.hipPlate5 + '.e[6]') mc.move(6, -3, 0, r=True) mc.select(self.hipPlate5 + '.e[1]') mc.move(0, -3, 0, r=True) mc.select(self.hipPlate5 + '.e[4]') mc.move(3, 0, 0, r=True) mc.select(self.hipPlate5) mc.rotate(-10, 0, 0) self.hipPlate = mc.polyUnite(self.hipPlate, self.hipPlate2, self.hipPlate3, self.hipPlate4, self.hipPlate5) self.crotchPlate1 = mc.polyCube(w=10, d=20, h=20)[0] mc.select(self.crotchPlate1 + '.e[3]') mc.move(0, 2, 0, r=True) mc.scale(.75, 1, 1) self.crotchPlate2 = mc.polyCube(w=10, d=10, h=20)[0] mc.move(0, 0, 15) mc.select(self.crotchPlate2 + '.e[0]') mc.move(0, 2, -5, r=True) mc.scale(.75, 1, 1) mc.select(self.crotchPlate2) self.crotchPlate1_1 = mc.duplicate(rr=True) mc.sets(e=True, forceElement=self.color1) mc.move(0, 2, -3, r=True) mc.scale(1.5, 1, 1) self.crotchPlate3 = mc.polyCube(w=10, d=20, h=10)[0] mc.move(0, 15, 10) mc.select(self.crotchPlate3 + '.e[1]') mc.move(0, 0, -6, r=True) mc.scale(.75, 1, 1) mc.select(self.crotchPlate3) self.crotchPlate3_1 = mc.duplicate(rr=True) mc.sets(e=True, forceElement=self.color1) mc.move(0, 2, -3, r=True) mc.scale(1.5, 1, 1) mc.select(self.crotchPlate3) self.crotchPlate3_2 = mc.duplicate(rr=True) mc.sets(e=True, forceElement=self.color3) mc.move(0, 0, 1, r=True) mc.scale(.75, .75, 1) #self.crotchPlate4 = mc.polyCube(w=10,d=20,h=10)[0] #mc.move(0,-15,0) self.pelvic = mc.polyUnite(self.pelvic, self.crotchPlate2, self.crotchPlate3, self.crotchPlate1_1, self.crotchPlate3_1, self.crotchPlate3_2) self.pelvic = mc.polyUnite(self.pelvic, self.crotchPlate1) self.pelvic = mc.polyUnite(self.pelvic, self.hipPlate)[0] #self.torso = mc.polyUnite(self.spine,self.pelvic,n=name)[0] self.torso = self.pelvic ######### Cockpit ############## self.cockpit = mc.polyCube(w=10, d=2, h=10)[0] mc.sets(e=True, forceElement=self.color2) mc.move(0, 25, 8, r=True) mc.select(self.cockpit + '.e[1]') mc.move(0, 5, 5, r=True) self.cockpit2 = mc.polyCube(w=10, d=2, h=10)[0] mc.sets(e=True, forceElement=self.color2) mc.move(0, 35, 10, r=True) mc.select(self.cockpit2 + '.e[1]') mc.move(0, 0, 10, r=True) mc.select(self.cockpit2 + '.e[2]') mc.move(0, 2, 10, r=True) self.cockpit = mc.polyUnite(self.cockpit, self.cockpit2) self.cockpitWall1 = mc.polyCube(w=2, h=30, d=10)[0] mc.move(0, 25, 0, r=True) mc.select(self.cockpitWall1 + '.e[1]') mc.move(0, 0, 15, r=True) self.cockpitWall2 = mc.polyCube(w=2, h=20, d=20)[0] mc.move(6.5, 32, 0, r=True) mc.select(self.cockpitWall2 + '.e[1]') mc.move(0, 0, 15, r=True) self.cockpitWall3 = mc.polyCube(w=2, h=20, d=20)[0] mc.move(-6.5, 32, 0, r=True) mc.select(self.cockpitWall3 + '.e[1]') mc.move(0, 0, 15, r=True) self.cockpitWall4 = mc.polyCube(w=2, h=20, d=20)[0] mc.move(6.5, 52, 0, r=True) mc.select(self.cockpitWall4 + '.e[0]') mc.move(0, 0, 15, r=True) self.cockpitWall5 = mc.polyCube(w=2, h=20, d=20)[0] mc.move(-6.5, 52, 0, r=True) mc.select(self.cockpitWall5 + '.e[0]') mc.move(0, 0, 15, r=True) self.cockpitWall6 = mc.polyCube(w=15, h=20, d=2) mc.move(0, 32, -10, r=True) self.cockpitWall7 = mc.polyCube(w=15, h=20, d=2) mc.move(0, 52, -10, r=True) self.cockpit = mc.polyUnite(self.cockpit, self.cockpitWall1, self.cockpitWall2, self.cockpitWall3, self.cockpitWall4, self.cockpitWall5, self.cockpitWall6, self.cockpitWall7) self.lRibs1 = mc.polyCube(w=10, d=20, h=5)[0] mc.sets(e=True, forceElement=self.color1) mc.move(12, 25, 0, r=True) mc.select(self.lRibs1 + '.e[1]') mc.move(0, 0, -2, r=True) mc.select(self.lRibs1 + '.e[2]') mc.move(0, 0, 2, r=True) mc.select(self.lRibs1 + '.e[7]') mc.move(-2, 1, 0, r=True) mc.polyBevel() self.lRibs2 = mc.polyCube(w=5, d=15, h=5)[0] mc.sets(e=True, forceElement=self.color1) mc.move(12, 30, 0, r=True) mc.select(self.lRibs2 + '.e[1]') mc.move(0, 0, -2, r=True) mc.select(self.lRibs2 + '.e[2]') mc.move(0, 0, 2, r=True) mc.select(self.lRibs2 + '.e[7]') mc.move(-2, 1, 0, r=True) mc.polyBevel() self.lRibs3 = mc.polyCube(w=2, d=20, h=10)[0] mc.sets(e=True, forceElement=self.color2) mc.move(8, 30, 0, r=True) mc.select(self.lRibs3 + '.e[1]') mc.move(0, 0, 2, r=True) mc.select(self.lRibs3 + '.e[2]') mc.move(0, 0, -2, r=True) mc.select(self.lRibs3 + '.e[7]') mc.move(2, 1, 0, r=True) mc.polyBevel() self.lRibs4 = mc.polyCube(w=8, d=30, h=10)[0] mc.sets(e=True, forceElement=self.color2) mc.move(8, 40, 0, r=True) mc.select(self.lRibs4 + '.e[1]') mc.move(0, 0, 5, r=True) mc.select(self.lRibs4 + '.e[2]') mc.move(0, 0, -2, r=True) mc.select(self.lRibs4 + '.e[7]') mc.move(5, 1, 0, r=True) mc.polyBevel() self.lRibs = mc.polyUnite(self.lRibs1, self.lRibs2, self.lRibs3, self.lRibs4) self.rRibs1 = mc.polyCube(w=10, d=20, h=5)[0] mc.sets(e=True, forceElement=self.color1) mc.move(-12, 25, 0, r=True) mc.select(self.rRibs1 + '.e[1]') mc.move(0, 0, -2, r=True) mc.select(self.rRibs1 + '.e[2]') mc.move(0, 0, 2, r=True) mc.select(self.rRibs1 + '.e[6]') mc.move(2, 1, 0, r=True) mc.polyBevel() self.rRibs2 = mc.polyCube(w=5, d=15, h=5)[0] mc.sets(e=True, forceElement=self.color1) mc.move(-12, 30, 0, r=True) mc.select(self.rRibs2 + '.e[1]') mc.move(0, 0, -2, r=True) mc.select(self.rRibs2 + '.e[2]') mc.move(0, 0, 2, r=True) mc.select(self.rRibs2 + '.e[6]') mc.move(2, 1, 0, r=True) mc.polyBevel() self.rRibs3 = mc.polyCube(w=2, d=20, h=10)[0] mc.sets(e=True, forceElement=self.color2) mc.move(-8, 30, 0, r=True) mc.select(self.rRibs3 + '.e[1]') mc.move(0, 0, 2, r=True) mc.select(self.rRibs3 + '.e[2]') mc.move(0, 0, -2, r=True) mc.select(self.rRibs3 + '.e[6]') mc.move(-2, 1, 0, r=True) mc.polyBevel() self.rRibs4 = mc.polyCube(w=8, d=30, h=10)[0] mc.sets(e=True, forceElement=self.color2) mc.move(-8, 40, 0, r=True) mc.select(self.rRibs4 + '.e[1]') mc.move(0, 0, 5, r=True) mc.select(self.rRibs4 + '.e[2]') mc.move(0, 0, -2, r=True) mc.select(self.rRibs4 + '.e[6]') mc.move(-5, 1, 0, r=True) mc.polyBevel() self.rRibs = mc.polyUnite(self.rRibs1, self.rRibs2, self.rRibs3, self.rRibs4) self.cockpit = mc.polyUnite(self.cockpit, self.lRibs, self.rRibs) ########## CHEST ############# self.chest1 = mc.polyCube(w=10, d=2, h=10)[0] mc.sets(e=True, forceElement=self.color3) mc.move(0, 47, 23, r=True) mc.select(self.chest1 + '.e[1]') mc.move(0, 0, 10, r=True) mc.select(self.chest1 + '.e[3]') mc.move(0, 2, 0, r=True) mc.select(self.chest1 + '.e[2]') mc.move(0, 0, -20, r=True) self.chest2 = mc.polyCube(w=10, d=2, h=10)[0] mc.sets(e=True, forceElement=self.color3) mc.move(0, 57, 23, r=True) mc.select(self.chest2 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest2 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest2 + '.e[2]') mc.move(0, 0, -20, r=True) self.chest3 = mc.polyCube(w=20, d=2, h=10)[0] mc.sets(e=True, forceElement=self.color3) mc.move(15, 57, 23, r=True) mc.select(self.chest3 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest3 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest3 + '.e[2]') mc.move(0, 0, -20, r=True) mc.select(self.chest3 + '.e[5]') mc.move(0, 0, -5, r=True) self.chest4 = mc.polyCube(w=20, d=2, h=10)[0] mc.sets(e=True, forceElement=self.color3) mc.move(-15, 57, 23, r=True) mc.select(self.chest4 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest4 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest4 + '.e[2]') mc.move(0, 0, -20, r=True) mc.select(self.chest4 + '.e[4]') mc.move(0, 0, -5, r=True) self.chest5 = mc.polyCube(w=10, d=2, h=5)[0] mc.sets(e=True, forceElement=self.color3) mc.move(0, 67, 13, r=True) mc.select(self.chest5 + '.e[0]') mc.move(0, -2.5, 10, r=True) mc.select(self.chest5 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest5 + '.e[2]') mc.move(0, 0, -20, r=True) mc.select(self.chest5 + '.f[1]') #mc.move(0,0,-20,r=True) mc.scale(.5, 1, .5) self.chest6 = mc.polyCube(w=20, d=2, h=5)[0] mc.sets(e=True, forceElement=self.color3) mc.move(15, 64.5, 13, r=True) mc.select(self.chest6 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest6 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest6 + '.e[2]') mc.move(0, 0, -20, r=True) mc.select(self.chest6 + '.e[5]') mc.move(0, 0, -5, r=True) mc.select(self.chest6 + '.e[1]') mc.move(0, 0, -10, r=True) self.chest7 = mc.polyCube(w=20, d=2, h=5)[0] mc.sets(e=True, forceElement=self.color3) mc.move(-15, 64.5, 13, r=True) mc.select(self.chest7 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest7 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest7 + '.e[2]') mc.move(0, 0, -20, r=True) mc.select(self.chest7 + '.e[4]') mc.move(0, 0, -5, r=True) mc.select(self.chest7 + '.e[1]') mc.move(0, 0, -10, r=True) self.chest8 = mc.polyCube(w=10, d=2, h=5)[0] mc.sets(e=True, forceElement=self.color3) mc.move(10, 67.5, 3, r=True) mc.select(self.chest8 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest8 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest8 + '.e[2]') mc.move(0, 0, -10, r=True) mc.select(self.chest8 + '.e[5]') mc.move(0, 0, -5, r=True) mc.select(self.chest8 + '.e[1]') mc.move(0, 0, -1, r=True) self.chest9 = mc.polyCube(w=10, d=2, h=5)[0] mc.sets(e=True, forceElement=self.color3) mc.move(-10, 67.5, 3, r=True) mc.select(self.chest9 + '.e[0]') mc.move(0, 0, 10, r=True) mc.select(self.chest9 + '.e[3]') mc.move(0, 0, -10, r=True) mc.select(self.chest9 + '.e[2]') mc.move(0, 0, -10, r=True) mc.select(self.chest9 + '.e[4]') mc.move(0, 0, -5, r=True) mc.select(self.chest9 + '.e[1]') mc.move(0, 0, -1, r=True) self.chest = mc.polyUnite(self.chest1, self.chest2, self.chest3, self.chest4, self.chest5, self.chest6, self.chest7, self.chest8, self.chest9) ######### shoulders ############ t1 = mc.polyCube(sx=3, sy=3, sz=3, w=15, h=15, d=15, n='l_shoulder')[0] mc.sets(e=True, forceElement=self.color4) t1r = mc.polyBevel(ws=1, oaf=1, o=.5, sa=30)[0] #mc.scale(1,5,1) mc.move(25, 67, 0, r=True) t2 = mc.polyCube(sx=3, sy=3, sz=3, w=15, h=15, d=15, n='r_shoulder')[0] mc.sets(e=True, forceElement=self.color4) t2r = mc.polyBevel(ws=1, oaf=1, o=.5, sa=30)[0] #mc.scale(1,5,1) mc.move(-25, 67, 0, r=True) self.clavical = mc.polyUnite(self.clavical, t1, t2)