def _makeMolecule(self): #H2O O = cmds.polySphere(r=1, n='O', ax = [0,0,0]); H1 = cmds.polySphere(r=0.8, n='H1', ax=[0,0,0]); H2 = cmds.polySphere(r=0.8, n='H2', ax=[0,0,0]); cmds.move(0.0,0.0,1,H1, r=True) cmds.move(0.0,0.0,-1,H2, r=True) cmds.xform(H1, piv=[0,0,0], ws=True) cmds.xform(H2, piv=[0,0,0], ws=True) cmds.rotate(0,'60',0, H1); #group O, H1, H2 as a water molecule H2O = cmds.group( empty=True, name='H2O' ) cmds.parent(H1,H2,O,H2O) #paint on colors for the water molecule #create red lambert cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name='O_WhiteSG' ) cmds.shadingNode( 'lambert', asShader=True, name='O_White' ) cmds.setAttr( 'O_White.color', 1, 1, 1, type='double3') cmds.connectAttr('O_White.outColor', 'O_WhiteSG.surfaceShader') #create red lambert cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name='H_RedSG' ) cmds.shadingNode( 'lambert', asShader=True, name='H_Red' ) cmds.setAttr( 'H_Red.color', 1, 0, 0, type='double3') cmds.connectAttr('H_Red.outColor', 'H_RedSG.surfaceShader') #assign the material cmds.sets('H1', edit=True, forceElement='H_RedSG') cmds.sets('H2', edit=True, forceElement='H_RedSG') cmds.sets('O', edit=True, forceElement='O_WhiteSG') return H2O
def _handleCreateBall(self): cmds.polySphere(name='ball', r=2, sx=20, sy=20, ax=[0, 1, 0]) cmds.polyColorPerVertex(rgb=(1, 1, 1), cdo=True) cmds.select('ball.f[380:399]', 'ball.f[320:339]', 'ball.f[280:299]', 'ball.f[240:259]', 'ball.f[200:219]', 'ball.f[160:179]', 'ball.f[120:139]', 'ball.f[80:99]', 'ball.f[40:59]', 'ball.f[0:19]') cmds.polyColorPerVertex(rgb=(1, 0, 0), cdo=True) cmds.select('ball') cmds.nonLinear( type='squash')
def createBubble(tx, tz, name): """ :param tx: translate x value :param tz: translate z value :param name: string name of bubble :return: nothing """ cmds.polySphere(sx=15, sy=15, r=.1, n=name) cmds.move(tx,0,tz, name, absolute=True)
def _handleBubblesButton(self): """ This callback creates a polygonal sphere in the Maya scene. it then translates it. """ decRange = np.arange(-1,1,.1) decRange2 = np.arange(0,1,.1) r = 2 a = 2.0*r y = (0, 1, 0) # y up #polyPlane -w 1 -h 1 -sx 10 -sy 10 -ax 0 1 0 -cuv 2 -ch 1; p = cmd.polyPlane( w=100, h=100, sx=10, sy=10, ax=y, cuv=3, ch=1,n='HotPlate')[0] cmd.select(p) cmd.move(0,2,0,r=True) cmd.setKeyframe() c = cmds.polySphere( r=r, sx=10, sy=10, ax=y, cuv=2, ch=1, n='Bubble')[0] cmds.select(c) cmd.setKeyframe() ''' cmd.setKeyframe() for i in range(1,300,5): x = rand.choice(decRange) y = 5*rand.choice(decRange2) z = rand.choice(decRange) cmd.currentTime(i) cmd.move(x, y, z, r=True) cmd.setKeyframe() ''' randBubbleCount = rand.choice(range(10,300)) #this should be set in the interface for i in range(0,100,1): randX = rand.choice(range(-50,50,1)) randZ = rand.choice(range(-50,50,1)) r = 2 a = 2.0*r yUp = (0, 1, 0) # y up b = cmds.polySphere( r=r, sx=10, sy=10, ax=yUp, cuv=2, ch=1, n='Bubble')[0] cmds.select(b) startTime = rand.choice(range(1, 600, 1)) cmd.currentTime(1) cmd.move(randX, 0, randZ, a=True) cmd.setKeyframe() for j in range(startTime, 600, 2): x = rand.choice(decRange) y = 5*rand.choice(decRange2) z = rand.choice(decRange) cmd.currentTime(j) cmd.move(x, y, z, r=True) cmd.setKeyframe() response = nimble.createRemoteResponse(globals()) response.put('name', c)
def _createGeometry(self, side): mc.select(cl=True) self.r_hand_palm = mc.polyCube(sx=4, sy=4, sz=4, w=10, h=10, d=3, n='R_palm')[0] mc.move(0, 5, -1.5) self.r_hand_heal = mc.polyCube(w=10, h=2, d=2, n='R_heal')[0] mc.move(0, 1, 1, r=True) if side == Side.right: mc.select(self.r_hand_heal + '.e[7]') elif side == Side.left: mc.select(self.r_hand_heal + '.e[6]') mc.move(0, 2, 0, r=True) self.r_hand = mc.polyUnite(self.r_hand_heal, self.r_hand_palm, n='r_hand')[0] self.r_hand_n_1 = mc.polySphere(r=1.2, n="r_hand_n_1")[0] mc.move(-3.75, 9.25, -.5) self.r_hand_n_2 = mc.polySphere(r=1.2, n="r_hand_n_2")[0] mc.move(-1.25, 9.25, -.5) self.r_hand_n_3 = mc.polySphere(r=1.2, n="r_hand_n_3")[0] mc.move(1.25, 9.25, -.5) self.r_hand_n_4 = mc.polySphere(r=1.2, n="r_hand_n_4")[0] mc.move(3.75, 9.25, -.5) self.r_hand_n_t = mc.polySphere(r=1.2, n="r_hand_n_t")[0] if side == Side.right: mc.move(4.5, 2, 1.5) elif side == Side.left: mc.move(-4.5, 2, 1.5) #self.hand = mc.polyCBoolOp(self.r_hand, self.r_hand_n_1, self.r_hand_n_2, self.r_hand_n_3, self.r_hand_n_4, self.r_hand_n_t, # op=2, n='r_hand') ### we did this becuase maya is stupid, and 2014 does not have polyCBoolOp() self.hand = mc.polyBoolOp(self.r_hand, self.r_hand_n_1, op=2, n='r_hand')[0] self.hand = mc.polyBoolOp(self.hand, self.r_hand_n_2, op=2, n='r_hand')[0] self.hand = mc.polyBoolOp(self.hand, self.r_hand_n_3, op=2, n='r_hand')[0] self.hand = mc.polyBoolOp(self.hand, self.r_hand_n_4, op=2, n='r_hand')[0] self.hand = mc.polyBoolOp(self.hand, self.r_hand_n_t, op=2, n='r_hand')[0]
def _createCalfArmor(self, name, side): p1 = mc.polySphere(r=10)[0] mc.scale(.35, 1.5, .75) mc.move(5, 0, 0) p2 = mc.polySphere(r=10)[0] mc.scale(.35, 1.5, .75) mc.move(-5, 0, 0) p3 = mc.polyCylinder(r=10, sx=40)[0] mc.rotate(0, 0, '90deg') mc.scale(1.5, 5, .75) #claf1 = mc.polyUnite(p1,p2,p3) #print calf1 #calf1 = mc.polyBoolOp(p1, p3, op=1, n='calf')[0] #calf2 = mc.polyBoolOp(calf1, p2, op=1, n='calf')[0] p4 = mc.polyCube(w=10, h=10, d=10)[0] mc.move(0, 10, -5) p5 = mc.polyCube(w=10, h=10, d=10)[0] mc.move(0, 10, -5) p6 = mc.polyCube(w=10, h=10, d=10)[0] mc.move(0, 10, -5) c1 = mc.polyBoolOp(p1, p4, op=2)[0] c2 = mc.polyBoolOp(p2, p5, op=2)[0] c3 = mc.polyBoolOp(p3, p6, op=2)[0] claf1 = mc.polyUnite(c1, c2, c3) mc.sets(e=True, forceElement=self.color1) mc.move(0, 45, -10) self.tibia = mc.polyUnite(self.tibia, claf1) t1 = mc.polyCube(sx=3, sy=3, sz=3, w=10, h=10, d=10, n='thigh')[0] t1r = mc.polyBevel(ws=1, oaf=1, o=.5, sa=30)[0] mc.scale(1, 5, 1) mc.move(0, 75, -12, r=True) t3 = mc.polyCube(sx=3, sy=3, sz=3, w=10, h=15, d=10, n='thight_armor')[0] mc.sets(e=True, forceElement=self.color1) t3r = mc.polyBevel(ws=1, oaf=1, o=.5, sa=30)[0] mc.scale(1.75, 3, 1.4) mc.move(0, 90, -9, r=True) self.femur = mc.polyUnite(self.femur, t1, t3) pass
def create_bubble(): cmds.playbackOptions(minTime='0', maxTime='71') # set playback range size = 0.2 bubble = cmds.polySphere(name='bubble', radius=0.2) # create a sphere #for f in range(72): # for the first 84 frames (starting from 0 and ending with 83) for time in [1, 15, 30, 45, 60, 72]: # for each frame calculate sub-steps #mc.setKeyframe( bubble, attribute='translateX', value=px, t=f ) # set keyframes cmds.setKeyframe(bubble, attribute='translateY', value=size + 0.1 * time, t=time) cmds.setKeyframe(bubble, attribute='scaleX', value=size + 0.02 * time, t=time) cmds.setKeyframe(bubble, attribute='scaleY', value=size + 0.02 * time, t=time) cmds.setKeyframe(bubble, attribute='scaleZ', value=size + 0.02 * time, t=time)
def _handleBubbleButton(self): """ This callback creates a polygonal sphere in the Maya scene. it then translates it. """ decRange = np.arange(-1,1,.1) decRange2 = np.arange(0,1,.1) r = 2 a = 2.0*r y = (0, 1, 0) # y up c = cmds.polySphere( r=r, sx=10, sy=10, ax=y, cuv=2, ch=1, n='Bubble')[0] cmds.select(c) cmd.setKeyframe() cmd.setKeyframe() for i in range(1,300,5): x = rand.choice(decRange) y = 5*rand.choice(decRange2) z = rand.choice(decRange) cmd.currentTime(i) cmd.move(x,y,z,r=True) cmd.setKeyframe() response = nimble.createRemoteResponse(globals()) response.put('name', c)
def _createGeometry(self, name, side): #build toe self.side = side self.name = name self.toe = mc.polyCube(sx=2, sy=2, sz=2, w=5, h=2, d=3, n=name + '_toe')[0] self.ball = mc.polyCylinder(h=5, n=name + '_ball')[0] mc.move(0, 0, -2, r=True) mc.rotate(0, 0, '90deg') self.toe = mc.polyUnite(self.toe, self.ball, n=name + '_toe')[0] mc.move(0, 0, -2, self.toe + ".scalePivot", self.toe + ".rotatePivot") #build arch self.arch = mc.polyCube(w=5, d=10, n=name + '_arch')[0] mc.move(0, 0, -7, r=True) #mc.select(f[8]-f[11]) mc.select(self.arch + '.f[2]') mc.move(0, 3, 0, r=True) self.ankle = mc.polySphere(r=2.5)[0] mc.move(0, 3, -12, r=True) self.arch = mc.polyUnite(self.arch, self.ankle, n=name + '_arch')[0] mc.move(0, 3, -12, self.arch + ".scalePivot", self.arch + ".rotatePivot") #self.heal = mc.polyCube(sx=2, sy=2, sz=2,w=5, h=3, n=name+'_heal') pass
def _createGeometry(self, name, side): #create tibia self.tibia = mc.polyCube(sx=1, sy=1, sz=1, w=2, h=50, d=2, n=name + '_tibia')[0] mc.move(0, 28, -12) self.knee = mc.polyCylinder(h=5, r=2, n=name + '_knee')[0] mc.move(0, 54, -12, r=True) mc.rotate(0, 0, '90deg') self.tibia = mc.polyUnite(self.tibia, self.knee, n=name + '_tibia')[0] mc.move(0, 54, -12, self.tibia + ".scalePivot", self.tibia + ".rotatePivot") #create feamer self.femur = mc.polyCube(sx=1, sy=1, sz=1, w=3, h=50, d=3, n=name + '_feamer')[0] mc.move(0, 80, -12) self.hip = mc.polySphere(r=5, n=name + '_hip') mc.move(0, 107, -12) self.femur = mc.polyUnite(self.femur, self.hip, n=name + '_femur')[0] mc.move(0, 107, -12, self.femur + ".scalePivot", self.femur + ".rotatePivot") pass
def _handlePlasticBlue(self): if materials.blueCPlasticSG == None: materials.blueClearPlastic() Sphere = mc.polySphere(r=5, n='bluePlasticSphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.blueCPlasticSG)
def _handleChromeTex(self): if materials.npchromeSG == None: materials.npchrome() Sphere = mc.polySphere(r=5, n='texChromephere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.npchromeSG)
def _handleSilver(self): if materials.silverSG == None: materials.silver() Sphere = mc.polySphere(r=5, n='sliverSphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.silverSG)
def _handleShinyGold(self): if materials.shinyGoldSG == None: materials.shinyGold() Sphere = mc.polySphere(r=5, n='shinyGoldSphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.shinyGoldSG)
def doMulti(time): for i in range(0, time / 2): #makes time/2 bubbles and sets up a bunch of random stats for them initTime = randint(0, time - 30) initX = randint(-10, 10) initZ = randint(-10, 10) xRand = randint(-5, 5) zRand = randint(-5, 5) #keyframes all the bubbles based on time that user sets in Qt slider r = .1 c = cmds.polySphere(r=r) cmds.setAttr(c[0] + ".visibility", 0) cmds.setKeyframe(time=initTime + 60) cmds.scale(11, 10, 11) cmds.move(initX, 20, initZ) cmds.setKeyframe(time=initTime + 50) cmds.setAttr(c[0] + ".visibility", 1) cmds.rotate(100, 0, 0) cmds.scale(10, 9, 9.5) cmds.setKeyframe(time=initTime + 40) cmds.move(initX + xRand, 10, initZ + zRand) cmds.rotate(60, 0, 0) cmds.setKeyframe(time=initTime + 30) cmds.move(initX, 6, initZ) cmds.rotate(0, 0, 0) cmds.setKeyframe(time=initTime + 20) cmds.move(initX, 3, initZ) cmds.scale(3, 3, 3) cmds.setKeyframe(time=initTime + 10) cmds.move(initX, 0, initZ) cmds.scale(1, .8, 1) cmds.setKeyframe(time=initTime)
def _handleBlueFM(self): if materials.blueFMSG == None: materials.blueFineMetallic() Sphere = mc.polySphere(r=5, n='blueFMSphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.blueFMSG)
def _handleBlueAA(self): if materials.blueAASG == None: materials.blueAnodizedAluminum() Sphere = mc.polySphere(r=5, n='blueAASphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.blueAASG)
def doSingle(): #keyframes a bubble, does NOT use slider r = .1 c = cmds.polySphere(r=r) cmds.setAttr(c[0] + ".visibility", 0) cmds.setKeyframe(time=60) cmds.scale(11, 10, 11) cmds.move(0, 20, 0) cmds.setKeyframe(time=50) cmds.setAttr(c[0] + ".visibility", 1) cmds.rotate(100, 0, 0) cmds.scale(10, 9, 9.5) cmds.setKeyframe(time=40) cmds.move(4, 10, 0) cmds.rotate(60, 0, 0) cmds.setKeyframe(time=30) cmds.move(0, 6, 0) cmds.rotate(0, 0, 0) cmds.setKeyframe(time=20) cmds.move(0, 3, 0) cmds.scale(3, 3, 3) cmds.setKeyframe(time=10) cmds.move(0, 0, 0) cmds.scale(1, .8, 1) cmds.setKeyframe(time=1)
def _handleRedAA(self): if materials.redAASG == None: materials.redAnodizedAluminum() print materials.redAASG Sphere = mc.polySphere(r=5, n='redAASphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=materials.redAASG)
def _CreateSphereButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ sphere = cmds.polySphere(r=50.0, name='sphere1') cmds.select(sphere) response = nimble.createRemoteResponse(globals()) response.put('name', sphere)
def _handlePlasticCustom(self): r = self.redSpin.value() g = self.greenSpin.value() b = self.blueSpin.value() custPlast = materials.clearPlasticRGB('cust', r, g, b) Sphere = mc.polySphere(r=5, n='custAASphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=custPlast.PlasticSG)
def _handleCustomFM(self): r = self.redSpin.value() g = self.greenSpin.value() b = self.blueSpin.value() custFM = materials.fineMetallic('cust', r, g, b) Sphere = mc.polySphere(r=5, n='custFMSphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=custFM.FMSG)
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 bouncingBubble(amp, sampFreq, scaleFactor): startRadius = 1.0 #2.865 spf = sampFreq / 24 # approximate samples per frame sphere = cmds.polySphere( n='bubble', r=startRadius)[0] # bakes in radius, scale of 1.0 makes radius 2.865 shader = str( cmds.listConnections(cmds.listHistory(sphere, f=1), type='lambert')[0]) print('Created ' + sphere + ' with shader ' + shader) # cmds.xform('column', t = [0,.5,0], sp=[0,-.5,0]) # move scale pivot to bottom of shape frameWin = BoxOnSphere.SPHERE_STEP print('Calculating average amplitude for every ' + str(frameWin) + '-frame (' + str(frameWin / 24.) + ' second) ' + 'window') avgs = averageAmplitude(amp, spf * frameWin) curProg = 1 tenPercent = len(avgs) / 10 # scaleFactor = 10.0 print('Keyframing size translations') for i in range(1, len(avgs)): h = normalize( avgs, i ) * scaleFactor # take away or add + 1 to allow or disallow the sphere to decay infinitely small cmds.setKeyframe(sphere, v=h, at='scaleX', t=(i - 1) * frameWin) cmds.setKeyframe(sphere, v=h, at='scaleY', t=(i - 1) * frameWin) cmds.setKeyframe(sphere, v=h, at='scaleZ', t=(i - 1) * frameWin) if i % tenPercent == 0: if not (curProg == 0 or curProg == 10): sys.stdout.write(str(curProg) + '0%...') curProg += 1 print('100%') frameWin = 10 print('Calculating average amplitude for every ' + str(frameWin) + '-frame (' + str(frameWin / 24.) + ' second) ' + 'window') avgs = averageAmplitude(amp, spf * frameWin) curProg = 1 tenPercent = len(avgs) / 10 print('Keyframing color translations') for i in range(1, len(avgs)): norm = normalize(avgs, i) rgb = colorsys.hsv_to_rgb(norm, 1, min( norm + .2, 1)) # hue and value both vary with amplitude # listConnections returns a list with unicode strings cmds.setAttr(shader + '.color', rgb[0], rgb[1], rgb[2], type='double3') cmds.setKeyframe(shader + '.color', at='color', t=i * frameWin) if i % tenPercent == 0: if not (curProg == 0 or curProg == 10): sys.stdout.write(str(curProg) + '0%...') curProg += 1 print('100%') return sphere
def _handleCustomAA(self): name = self.customName.text() r = self.redSpin.value() g = self.greenSpin.value() b = self.blueSpin.value() custAA = materials.anodizedAluminum(name + '_cust', r, g, b) Sphere = mc.polySphere(r=5, n=name + '_custAASphere')[0] mc.select(cl=True) mc.select(Sphere) mc.sets(e=True, forceElement=custAA.AASG) listOfMaterialShader.append(custAA.AASG)
def _createGeometry(self, name, side): #create tibia self.tibia = mc.polyCube(sx=1, sy=1, sz=1, w=2, h=50, d=2, n=name + '_tibia')[0] mc.move(0, 28, -12) self.knee = mc.polyCylinder(h=5, r=2, n=name + '_knee')[0] mc.move(0, 54, -12, r=True) mc.rotate(0, 0, '90deg') self.tibia = mc.polyUnite(self.tibia, self.knee, n=name + '_tibia')[0] self.llegArmor = mc.polyCube(w=8, h=30, d=8)[0] mc.move(0, 22, -12) mc.select(self.llegArmor + '.f[3]') mc.scale(1.5, 1, 1.5) mc.select(self.llegArmor + '.e[0]') mc.polySubdivideEdge(dv=2) mc.select(self.llegArmor + '.e[12]') mc.move(0, 2, 0, r=True) self.tibia = mc.polyUnite(self.tibia, self.llegArmor, n=name + '_tibia')[0] mc.move(0, 54, -12, self.tibia + ".scalePivot", self.tibia + ".rotatePivot") #create feamer self.femur = mc.polyCube(sx=1, sy=1, sz=1, w=3, h=50, d=3, n=name + '_feamer')[0] mc.move(0, 80, -12) self.hip = mc.polySphere(r=5, n=name + '_hip') mc.move(0, 107, -12) self.femur = mc.polyUnite(self.femur, self.hip, n=name + '_femur')[0] mc.move(0, 107, -12, self.femur + ".scalePivot", self.femur + ".rotatePivot") self._createCalfArmor(name, side) pass
def _handleSphereButton(self): """ This callback creates a polygonal sphere in the Maya scene. it then translates it. """ r = 2 a = 2.0*r y = (0, 1, 0) # y up c = cmds.polySphere( r=r, sx=10, sy=10, ax=y, cuv=2, ch=1, n='Bubble')[0] cmds.select(c) cmd.move(0, 5, 0, r = True) response = nimble.createRemoteResponse(globals()) response.put('name', c)
def _createGeometry(self, segmentLength, offset): mc.select(cl=True) #section 1 cunstruction self.r_hand_p_n_1 = mc.polySphere(r=.6,n="r_hand_p_n_1") mc.move(offset,2,.25) self.r_hand_p_b_1 = mc.polyCylinder(r=.25,h=.5,n="r_hand_p_b_1") mc.move(offset,2.6,.25) self.r_hand_p_p_1 = mc.polyCube(sx=2, sy=2, sz=2, h=segmentLength) mc.move(offset,3.25+self.segOffset,.25) self.r_hand_p_n_2_a = mc.polyCylinder(ax=[1,0,0], sx=2, sy=2, sz=2, h=.3, r=.5,n='r_hand_p_n_2_a') mc.move(offset+.35,4.25+(2*self.segOffset),.25) #1.875 + .35 self.r_hand_p_n_2_b = mc.polyCylinder(ax=[1,0,0], sx=2, sy=2, sz=2, h=.3, r=.5,n='r_hand_p_n_2_b') mc.move(offset-.35,4.25+(2*self.segOffset),.25) #1.875 -.35 #section 1 unite self.r_hand_p_s_1 = mc.polyUnite(self.r_hand_p_n_1, self.r_hand_p_b_1, self.r_hand_p_p_1, self.r_hand_p_n_2_a, self.r_hand_p_n_2_b, n='r_hand_p_s_1')[0] mc.move(offset,2,.25, self.r_hand_p_s_1+".scalePivot", self.r_hand_p_s_1+".rotatePivot") #section 2 construction self.r_hand_p_n_2_c = mc.polyCylinder(ax=[1,0,0], sx=2, sy=2, sz=2, h=.3, r=.5,n='r_hand_p_n_2_c') mc.move(offset,4.25+(2*self.segOffset),.25) self.r_hand_p_p_2 = mc.polyCube(sx=2, sy=2, sz=2, h=segmentLength) mc.move(offset,5.25+(3*self.segOffset),.25) self.r_hand_p_n_3_a = mc.polyCylinder(ax=[1,0,0], sx=2, sy=2, sz=2, h=.3, r=.5,n='r_hand_p_n_3_a') mc.move(offset+.35,6.25+(4*self.segOffset),.25) #1.875 + .35 self.r_hand_p_n_3_b = mc.polyCylinder(ax=[1,0,0], sx=2, sy=2, sz=2, h=.3, r=.5,n='r_hand_p_n_3_b') mc.move(offset-.35,6.25+(4*self.segOffset),.25) #1.875 -.35 #section 2 unite self.r_hand_p_s_2 = mc.polyUnite(self.r_hand_p_n_2_c, self.r_hand_p_p_2, self.r_hand_p_n_3_a, self.r_hand_p_n_3_b, n='r_hand_p_s_2')[0] mc.move(offset,4.25+(2*self.segOffset),.25, self.r_hand_p_s_2+".scalePivot", self.r_hand_p_s_2+".rotatePivot") #section 3 construction self.r_hand_p_n_3_c = mc.polyCylinder(ax=[1,0,0], sx=2, sy=2, sz=2, h=.3, r=.5,n='r_hand_p_n_3_c') mc.move(offset,6.25+(4*self.segOffset),.25) self.r_hand_p_p_3 = mc.polyCube(sx=2, sy=2, sz=2, h=segmentLength) mc.move(offset,7.25+(5*self.segOffset),.25) #section 3 unite self.r_hand_p_s_3 = mc.polyUnite(self.r_hand_p_n_3_c, self.r_hand_p_p_3, n='r_hand_p_s_3')[0] mc.move(offset,6.25+(4*self.segOffset),.25, self.r_hand_p_s_3+".scalePivot", self.r_hand_p_s_3+".rotatePivot")
def _createGeometry(self, name, side): #create radius self.radius = mc.polyCube(sx=1, sy=1, sz=1, w=2,h=40, d=2, n=name+'_radius')[0] mc.move(0,20,0) self.elbow = mc.polyCylinder(h=5,r=2,n=name+'_elbow')[0] mc.move(0,41,0,r=True) mc.rotate(0,0,'90deg') self.radius = mc.polyUnite(self.radius,self.elbow, n=name+'_radius')[0] mc.move(0,41,0, self.radius+".scalePivot", self.radius+".rotatePivot") #create humerus self.humerus = mc.polyCube(sx=1, sy=1, sz=1, w=3,h=40, d=3, n=name+'_humerus')[0] mc.move(0,62,0) self.shoulder = mc.polySphere(r=5,n=name+'_shoulder') mc.move(0,84,0) self.humerus = mc.polyUnite(self.humerus,self.shoulder, n=name+'_humerus')[0] mc.move(0,84,0, self.humerus+".scalePivot", self.humerus+".rotatePivot") pass
def drawBubble(radius, xpoint, ypoint, zpoint, name, time): """ Arguments: radius is the size of the overall shape Return: None """ y = (0, 1, 0) d = cmds.polyCylinder(r=10, h=20, sx=40, sy=10, sz=1, ax=(0, 0, 0), rcp=0, cuv=2, ch=1, n='CylinderContainer')[0] cmds.move(0, 10, 0) cmds.select(d) response = nimble.createRemoteResponse(globals()) response.put('name', d) c = cmds.polySphere(r=radius, ax=y, cuv=2, ch=1, n=name)[0] xpoint = 0 for i in range(1, time + 1, 3): # figure out best time step cmds.setKeyframe(name, t=i) cmds.move(xpoint, ypoint, zpoint, relative=False) cmds.select(name) response = nimble.createRemoteResponse(globals()) response.put('name', name) xpoint = xpoint + .1 # need to do some physics for theses print(ypoint, i) if ypoint >= 19.5: ypoint = 20 print("pop") break else: ypoint = (.55 + float(ypoint)) zpoint = zpoint + .001 #cmds.setKeyframe( name , at="translateY", t=time, v=xpoint + 3) return None
from __future__ import print_function, absolute_import, unicode_literals, division import nimble import random from nimble import cmds from nimble import MayaCommandException count = 0 while count < 100: result = cmds.polySphere() name = result[0] bcmds = nimble.createCommandsBatch() index = 0 while index < 100: bcmds.move( 2.0*(random.random() - 0.5), 2.0*(random.random() - 0.5), 2.0*(random.random() - 0.5), name, relative=True) bcmds.rotate( random.random() - 0.5, random.random() - 0.5, random.random() - 0.5, name, relative=True) bcmds.scale( 1.0 + 0.01*(random.random() - 0.5), 1.0 + 0.01*(random.random() - 0.5), 1.0 + 0.01*(random.random() - 0.5),
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 buildScene(self): """Doc...""" groupItems = [] hinds = [] fores = [] for c in self._data.getChannelsByKind(ChannelsEnum.POSITION): isHind = c.target in [TargetsEnum.LEFT_HIND, TargetsEnum.RIGHT_HIND] radius = 20 if isHind else 15 res = cmds.polySphere(radius=radius, name=c.target) groupItems.append(res[0]) if isHind: hinds.append(res[0]) else: fores.append(res[0]) if c.target == TargetsEnum.LEFT_HIND: self._leftHind = res[0] elif c.target == TargetsEnum.RIGHT_HIND: self._rightHind = res[0] elif c.target == TargetsEnum.RIGHT_FORE: self._rightFore = res[0] elif c.target == TargetsEnum.LEFT_FORE: self._leftFore = res[0] for k in c.keys: frames = [ ['translateX', k.value.x, k.inTangentMaya[0], k.outTangentMaya[0]], ['translateY', k.value.y, k.inTangentMaya[1], k.outTangentMaya[1]], ['translateZ', k.value.z, k.inTangentMaya[2], k.outTangentMaya[2]] ] for f in frames: cmds.setKeyframe( res[0], attribute=f[0], time=k.time, value=f[1], inTangentType=f[2], outTangentType=f[3] ) if k.event == 'land': printResult = cmds.polyCylinder( name=c.target + '_print1', radius=radius, height=(1.0 if isHind else 5.0) ) cmds.move(k.value.x, k.value.y, k.value.z, printResult[0]) groupItems.append(printResult[0]) cfg = self._data.configs name = 'cyc' + str(int(cfg.get(GaitConfigEnum.CYCLES))) + \ '_ph' + str(int(cfg.get(GaitConfigEnum.PHASE))) + \ '_gad' + str(int(cfg.get(SkeletonConfigEnum.FORE_OFFSET).z)) + \ '_step' + str(int(cfg.get(SkeletonConfigEnum.STRIDE_LENGTH))) cube = cmds.polyCube(name='pelvic_reference', width=20, height=20, depth=20) self._hips = cube[0] groupItems.append(cube[0]) cmds.move(0, 100, 0, cube[0]) backLength = self._data.configs.get(SkeletonConfigEnum.FORE_OFFSET).z - \ self._data.configs.get(SkeletonConfigEnum.HIND_OFFSET).z cube2 = cmds.polyCube(name='pectoral_comparator', width=15, height=15, depth=15) cmds.move(0, 115, backLength, cube2[0]) cmds.parent(cube2[0], cube[0], absolute=True) cmds.expression( string="%s.translateZ = 0.5*abs(%s.translateZ - %s.translateZ) + min(%s.translateZ, %s.translateZ)" % (cube[0], hinds[0], hinds[1], hinds[0], hinds[1]) ) cube = cmds.polyCube(name='pectoral_reference', width=15, height=15, depth=15) self._pecs = cube[0] groupItems.append(cube[0]) cmds.move(0, 100, 0, cube[0]) cmds.expression( string="%s.translateZ = 0.5*abs(%s.translateZ - %s.translateZ) + min(%s.translateZ, %s.translateZ)" % (cube[0], fores[0], fores[1], fores[0], fores[1]) ) self._group = cmds.group(*groupItems, world=True, name=name) cfg = self._data.configs info = 'Gait Phase: ' + \ str(cfg.get(GaitConfigEnum.PHASE)) + \ '\nGleno-Acetabular Distance (GAD): ' + \ str(cfg.get(SkeletonConfigEnum.FORE_OFFSET).z) + \ '\nStep Length: ' + \ str(cfg.get(SkeletonConfigEnum.STRIDE_LENGTH)) + \ '\nHind Duty Factor: ' + \ str(cfg.get(GaitConfigEnum.DUTY_FACTOR_HIND)) + \ '\nFore Duty Factor: ' + \ str(cfg.get(GaitConfigEnum.DUTY_FACTOR_FORE)) + \ '\nCycles: ' + \ str(cfg.get(GaitConfigEnum.CYCLES)) cmds.select(self._group) if not cmds.attributeQuery('notes', node=self._group, exists=True): cmds.addAttr(longName='notes', dataType='string') cmds.setAttr(self._group + '.notes', info, type='string') self.createShaders() self.createRenderEnvironment() minTime = min(0, int(cmds.playbackOptions(query=True, minTime=True))) deltaTime = cfg.get(GeneralConfigEnum.STOP_TIME) - cfg.get(GeneralConfigEnum.START_TIME) maxTime = max( int(float(cfg.get(GaitConfigEnum.CYCLES))*float(deltaTime)), int(cmds.playbackOptions(query=True, maxTime=True)) ) cmds.playbackOptions( minTime=minTime, animationStartTime=minTime, maxTime= maxTime, animationEndTime=maxTime ) cmds.currentTime(0, update=True) cmds.select(self._group)
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 _handleRestoreButton(self): ball = cmds.ls('ball')[0] if(ball != None): cmds.delete(ball) cmds.polySphere(r=0.658, n='ball', ax = [0,0,0]) cmds.move(29.108,2,-0.2, 'ball')