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 _createJoints(self, side): mc.select(cl=True) self.j_thumb_1 = mc.joint(p=(self.sideModifyer*2.25,-1.5,1.25)) mc.select(cl=True) mc.parent(self.r_hand_n_t, self.j_thumb_1) pass
def _createJoints(self, name): #bone mc.select(cl=True) #make some joints? self.j_head = mc.joint(p=(0, 0, 0), n=name + '_j_head') #parent some joints mc.parent(self.head, self.j_head) pass
def _createJoints(self, name, side): #bone mc.select(cl=True) self.j_shoulder = mc.joint(p=(0, 84, 0), n=name + '_shoulder') self.j_elbow = mc.joint(p=(0, 41, 0), n=name + '_elbow') #self.j_toe = mc.joint(p=(0,0,2), n=name+'_toe') mc.parent(self.humerus, self.j_shoulder) mc.parent(self.radius, self.j_elbow) pass
def _createJoints(self, name, side): #bone mc.select(cl=True) self.j_ankle = mc.joint(p=(0, 3, -12), n=name + '_ankle') self.j_ball = mc.joint(p=(0, 0, -2), n=name + '_ball') self.j_toe = mc.joint(p=(0, 0, 2), n=name + '_toe') mc.parent(self.arch, self.j_ankle) mc.parent(self.toe, self.j_toe) pass
def _createJoints(self, side): mc.select(cl=True) self.j_thumb_1 = mc.joint(p=(self.sideModifyer * 4.5, 2, 1.5)) self.j_thumb_2 = mc.joint(p=(self.sideModifyer * 8.5, 6.5, 1.5), dof='z') self.j_thumb_2 = mc.joint(p=(self.sideModifyer * 8.5, 11, 1.5)) mc.select(cl=True) mc.parent(self.s_1, self.j_thumb_1) mc.parent(self.s_2, self.j_thumb_2) pass
def _createJoints(self, name): #bone mc.select(cl=True) self.j_root = mc.joint(p=(0,0,0), n=name+'_j_root') self.j_neck = mc.joint(p=(0,67,0), n=name+'_j_neck') mc.parent(self.torso,self.j_root) mc.parent(self.clavical,self.j_neck) pass
def _handleRoadButton(self): exist = cmds.ls('road') if(len(exist) != 0): cmds.delete('road') road=cmds.group(empty=True, name='road') transformName = cmds.ls('brick', typ='transform')[0] num = int(self.bricksNum.text()) for i in range(0, num): instanceResult = cmds.instance(transformName, name=transformName + '_instance#') #print 'instanceResult: ' + str(instanceResult) x = random.uniform(-3, 34) z = random.uniform(-3,3) cmds.move(x, 0, z, instanceResult) yRot = random.uniform(0,360) cmds.rotate(0, yRot, 0, instanceResult) cmds.parent(instanceResult, road)
def _handleDuplicatedButton(self): random.seed(1234) exist = cmds.ls('dust') if(len(exist) != 0): cmds.delete('dust') dust=cmds.group(empty=True, name='dust') transformName = cmds.ls('pie', typ='transform')[0] num = int(self.dustNum.text()) for i in range(0, num): instanceResult = cmds.instance(transformName, name=transformName + '_instance#') #print 'instanceResult: ' + str(instanceResult) x = random.uniform(-3, 34) y = random.uniform(0,4) z = random.uniform(-3,3) cmds.move(x, y, z, instanceResult) xRot = random.uniform(0,360) yRot = random.uniform(0,360) zRot = random.uniform(0,360) cmds.rotate(xRot, yRot, zRot, instanceResult) cmds.parent(instanceResult, dust)
def _createJoints(self, name): #bone mc.select(cl=True) self.j_root = mc.joint(p=(0, 0, 0), n=name + '_j_root') self.j_s1 = mc.joint(p=(0, 11, 1), n=name + '_j_s1') self.j_s2 = mc.joint(p=(0, 22, 1), n=name + '_j_s2') self.j_s3 = mc.joint(p=(0, 33, 1), n=name + '_j_s3') self.j_s4 = mc.joint(p=(0, 44, 1), n=name + '_j_s4') self.j_s5 = mc.joint(p=(0, 55, 1), n=name + '_j_s5') self.j_neck = mc.joint(p=(0, 67, 0), n=name + '_j_neck') mc.select(cl=True) self.j_bind_root = mc.joint(p=(0, 0, 0), n=name + '_j_bind_root') mc.select(cl=True) self.j_bind_neck = mc.joint(p=(0, 67, 0), n=name + '_j_bind_neck') #mc.parent(self.j_bind_root, self.j_root) #mc.parent(self.j_bind_neck, self.j_neck) self.h_hips = mc.circle(nr=(0, 1, 0), c=(0, 0, 0), r=50, n=name + "_hips_IK_handle")[0] self.h_shoulders = mc.circle(nr=(0, 1, 0), c=(0, 67, 0), r=70, n=name + "_shoulders_IK_handle")[0] mc.move(0, 67, 0, self.h_shoulders + ".scalePivot", self.h_shoulders + ".rotatePivot") mc.parentConstraint(self.h_hips, self.j_bind_root, mo=True) mc.parentConstraint(self.h_shoulders, self.j_bind_neck, mo=True) #mc.parent(self.h_hips, self.torso) #mc.parent(self.h_shoulders, self.torso) mc.parent(self.torso, self.j_root) mc.parent(self.clavical, self.j_neck) pass
def _createIK(self, name, side): self.ik_wrist = mc.ikHandle(sj=self.j_shoulder, ee=self.hand.j_wrist, n=name + "_wrist_ik") #self.ik_ball = mc.ikHandle(sj = self.foot.j_ankle, ee=self.foot.j_ball, n=name+"_ball_ik") #self.ik_toe = mc.ikHandle(sj = self.foot.j_ball, ee=self.foot.j_toe, n=name+"_toe_ik") self.h_hand = mc.circle(nr=(0, 1, 0), c=(0, 0, 0), r=20, n=name + "_hand_IK_handle")[0] #mc.move(0,3,-12, self.h_hand+".scalePivot", self.h_hand+".rotatePivot") mc.parentConstraint(self.h_hand, self.ik_wrist[0], mo=True) ''' mc.parentConstraint( self.h_foot, self.ik_ball[0], mo=True) mc.parentConstraint( self.h_foot, self.ik_toe[0], mo=True) #self.ik = mc.group(ankle_ik, ball_ik, toe_ik, n=name+"_leg_IK") ''' mc.parent(self.h_hand, self.radius) pass
def _createJoints(self, name, side): #bone mc.select(cl=True) self.j_hip = mc.joint(p=(0, 107, -12), n=name + '_hip') self.j_knee = mc.joint(p=(0, 54, -11), n=name + '_knee') #self.j_toe = mc.joint(p=(0,0,2), n=name+'_toe') mc.parent(self.femur, self.j_hip) mc.parent(self.tibia, self.j_knee) mc.parent(self.foot.j_ankle, self.j_knee) pass
def _createJoints(self, segmentLength, offset): #bone mc.select(cl=True) self.j_r_p_n_1 = mc.joint( p=(offset,2,.25)) self.j_r_p_n_2 = mc.joint( p=(offset,4.25+(2*self.segOffset),.25),dof='x') self.j_r_p_n_3 = mc.joint( p=(offset,6.25+(4*self.segOffset),.25),dof='x') self.j_r_p_n_4 = mc.joint( p=(offset,8.25+(6*self.segOffset),.25)) mc.select(cl=True) mc.parent(self.r_hand_p_s_1, self.j_r_p_n_1) mc.parent(self.r_hand_p_s_2, self.j_r_p_n_2) mc.parent(self.r_hand_p_s_3, self.j_r_p_n_3)
def _createJoints(self, segmentLength, offset): #bone voff = 9.25 mc.select(cl=True) self.j_n_1 = mc.joint(p=(offset, voff, -.5), dof='xz') self.j_n_2 = mc.joint(p=(offset, voff + 3.75 + (2 * self.segOffset), -.5), dof='x') self.j_n_3 = mc.joint(p=(offset, voff + 6.75 + (4 * self.segOffset), -.5), dof='x') self.j_n_4 = mc.joint(p=(offset, voff + 9.25 + (6 * self.segOffset), -.5)) mc.select(cl=True) mc.parent(self.r_hand_p_s_1, self.j_n_1) mc.parent(self.r_hand_p_s_2, self.j_n_2) mc.parent(self.r_hand_p_s_3, self.j_n_3)
def parentIKToRoot(self): mc.parent(self.rightLeg.ik_ankle[0], self.j_root) mc.parent(self.rightLeg.ik_ball[0], self.j_root) mc.parent(self.rightLeg.ik_toe[0], self.j_root) mc.parent(self.leftLeg.ik_ankle[0], self.j_root) mc.parent(self.leftLeg.ik_ball[0], self.j_root) mc.parent(self.leftLeg.ik_toe[0], self.j_root) pass
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 __init__(self, name): self.name = name self.currentFeet = "parallel" self.currentArms = "straight" ''' mc.select(cl=True) self.rightHand = hand.Hand(name+'_right', Side.right) mc.select(cl=True) self.leftHand = hand.Hand(name+'_left', Side.left) ''' self.leftLeg = leg.Leg(name+'_left', Side.left) mc.select(cl=True) self.rightLeg = leg.Leg(name+'_right', Side.right) mc.select(cl=True) self.leftArm = arms.Arm(name+'_left', Side.left) mc.select(cl=True) self.rightArm = arms.Arm(name+'_right', Side.right) mc.select(cl=True) mc.select(self.rightArm.hand.j_wrist) #mc.move(-112, 173, 0, r=True) mc.rotate('180deg', '-90deg',0, r=True) mc.select(self.leftArm.hand.j_wrist) #mc.move(112, 173, 0, r=True) mc.rotate('180deg', '90deg',0, r=True) mc.select(self.rightLeg.j_hip) mc.move(-20,0,12, r=True) mc.select(self.leftLeg.j_hip) mc.move(20,0,12, r=True) mc.select(self.rightLeg.h_foot) mc.move(-20,0,12, r=True) mc.select(self.leftLeg.h_foot) mc.move(20,0,12, r =True) mc.select(self.rightArm.j_shoulder) mc.move(-28,90,0, r=True) mc.rotate(0,0,-90) mc.select(self.leftArm.j_shoulder) mc.move(28,90,0, r=True) mc.rotate(0,0,90) self.torso = torso.Torso(name+'_torso') mc.select(self.torso.j_root) mc.select(self.torso.j_bind_root, add=True) mc.move(0,107,0) mc.select(self.torso.j_bind_neck) mc.select(self.torso.h_hips, add=True) mc.select(self.torso.h_shoulders, add=True) mc.move(0,107,0, r=True) mc.parent(self.rightLeg.j_hip, self.torso.j_root) mc.parent(self.leftLeg.j_hip, self.torso.j_root) mc.parent(self.rightArm.j_shoulder, self.torso.j_neck) mc.parent(self.leftArm.j_shoulder, self.torso.j_neck) #mc.parent(self.leftArm.hand.j_wrist, self.leftArm.j_elbow) #mc.parent(self.rightArm.hand.j_wrist, self.rightArm.j_elbow) mc.select(cl=True) self.j_root = mc.joint(p=(0,107,0), n=name+'_root') mc.parent(self.torso.j_root, self.j_root) mc.setAttr(self.j_root+ " | " + self.torso.j_root+".segmentScaleCompensate", 0) mc.select(cl=True) self.parentIKToRoot() print self.leftArm.h_hand
def detachLegsIKFromRoot(self): mc.parent(self.j_root + "|" + self.leftLeg.h_foot, world=True) mc.parent(self.j_root + "|" + self.rightLeg.h_foot, world=True) pass
def attachLegsIKToRoot(self): mc.parent(self.leftLeg.h_foot, self.j_root) mc.parent(self.rightLeg.h_foot, self.j_root) pass
def parentIKToRoot(self): mc.parent(self.rightLeg.ik_ankle[0], self.j_root) mc.parent(self.rightLeg.ik_ball[0], self.j_root) mc.parent(self.rightLeg.ik_toe[0], self.j_root) mc.parent(self.leftLeg.ik_ankle[0], self.j_root) mc.parent(self.leftLeg.ik_ball[0], self.j_root) mc.parent(self.leftLeg.ik_toe[0], self.j_root) mc.parent(self.leftArm.ik_wrist[0], self.j_root) mc.parent(self.rightArm.ik_wrist[0], self.j_root) mc.parent(self.torso.ik_spine[0], self.j_root) mc.parent(self.torso.j_bind_root, self.j_root) mc.parent(self.torso.j_bind_neck, self.j_root) #mc.parent(self.rightArm.ik_wrist[0], self.j_root) pass
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 __init__(self, name): self.name = name mc.select(cl=True) self.rightHand = hand.Hand(name + '_right', Side.right) mc.select(cl=True) self.leftHand = hand.Hand(name + '_left', Side.left) self.leftLeg = leg.Leg(name + '_left', Side.left) mc.select(cl=True) self.rightLeg = leg.Leg(name + '_right', Side.right) mc.select(cl=True) self.leftArm = arms.Arm(name + '_left', Side.left) mc.select(cl=True) self.rightArm = arms.Arm(name + '_right', Side.right) mc.select(cl=True) mc.select(self.rightHand.j_wrist) mc.move(-112, 173, 0, r=True) mc.rotate('90deg', '-90deg', 0, r=True) mc.select(self.leftHand.j_wrist) mc.move(112, 173, 0, r=True) mc.rotate('90deg', '90deg', 0, r=True) mc.select(self.rightLeg.j_hip) mc.move(-20, 0, 12, r=True) mc.select(self.leftLeg.j_hip) mc.move(20, 0, 12, r=True) mc.select(self.rightLeg.h_foot) mc.move(-20, 0, 12, r=True) mc.select(self.leftLeg.h_foot) mc.move(20, 0, 12, r=True) mc.select(self.rightArm.j_shoulder) mc.move(-28, 90, 0, r=True) mc.rotate(0, 0, -90) mc.select(self.leftArm.j_shoulder) mc.move(28, 90, 0, r=True) mc.rotate(0, 0, 90) self.torso = torso.Torso('torso') mc.select(self.torso.j_root) mc.move(0, 107, 0) mc.parent(self.rightLeg.j_hip, self.torso.j_root) mc.parent(self.leftLeg.j_hip, self.torso.j_root) mc.parent(self.rightArm.j_shoulder, self.torso.j_neck) mc.parent(self.leftArm.j_shoulder, self.torso.j_neck) mc.parent(self.leftHand.j_wrist, self.leftArm.j_elbow) mc.parent(self.rightHand.j_wrist, self.rightArm.j_elbow) mc.select(cl=True) self.j_root = mc.joint(p=(0, 107, 0), n=name + '_root') mc.parent(self.torso.j_root, self.j_root) mc.setAttr( self.j_root + " | " + self.torso.j_root + ".segmentScaleCompensate", 0) mc.select(cl=True) self.parentIKToRoot()
def createTrackNode(cls, uid, trackSetNode =None, props =None): """ A track node consists of a triangular pointer (left = red, right = green) which is selectable but only allows rotateY, translateX, and translateZ. The node has a child, a transform called inverter, which serves to counteract the scaling in x and z that is applied to the triangular node. There are two orthogonal rulers (width and length). Width and length uncertainty is represented by rectangular bars at the ends of the rulers. In Maya one can directly adjust track position (translateX and translateZ) and orientation (rotationY); other attributes are adjusted only through the UI. """ if not trackSetNode: trackSetNode = TrackSceneUtils.getTrackSetNode() if not trackSetNode: return None node = cls.getTrackNode(uid, trackSetNode=trackSetNode) if node: return node # Set up dimensional constants for the track node nodeThickness = 1.0 thetaBreadth = 0.1 thetaThickness = 0.5 barBreadth = 2.0 barThickness = 0.5 rulerBreadth = 1.0 rulerThickness = 0.25 epsilon = 1.0 # Create an isoceles triangle pointer, with base aligned with X, and # scaled by node.width. The midpoint of the base is centered on the # 'track center' and the altitude extends from that center of the track # 'anteriorly' to the perimeter of the track's profile (if present, else # estimated). The node is scaled longitudinally (in z) based on the # distance zN (the 'anterior' length of the track, in cm). The triangle # is initially 1 cm on a side. sideLength = 1.0 node = cmds.polyPrism( length=nodeThickness, sideLength=sideLength, numberOfSides=3, subdivisionsHeight=1, subdivisionsCaps=0, axis=(0, 1, 0), createUVs=0, constructionHistory=0, name='Track0')[0] # Point the triangle down the +Z axis cmds.rotate(0.0, -90.0, 0.0) # push it down below ground level so that the two rulers are just # submerged, and scale the triangle in Z to match its width (1 cm) so it # is ready to be scaled cmds.move(0, -(nodeThickness/2.0 + rulerThickness), math.sqrt(3.0)/6.0) # move the node's pivot to the 'base' of the triangle so it scales # outward from that point cmds.move( 0, 0, 0, node + ".scalePivot", node + ".rotatePivot", absolute=True) cmds.scale(2.0/math.sqrt(3.0), 1.0, 100.0) cmds.makeIdentity( apply=True, translate=True, rotate=True, scale=True, normal=False) # Set up the cadence attributes cmds.addAttr( longName='cadence_width', shortName=TrackPropEnum.WIDTH.maya, niceName='Width') cmds.addAttr( longName='cadence_widthUncertainty', shortName=TrackPropEnum.WIDTH_UNCERTAINTY.maya, niceName='Width Uncertainty') cmds.addAttr( longName='cadence_length', shortName=TrackPropEnum.LENGTH.maya, niceName='Length') cmds.addAttr( longName='cadence_lengthUncertainty', shortName=TrackPropEnum.LENGTH_UNCERTAINTY.maya, niceName='Length Uncertainty') cmds.addAttr( longName='cadence_lengthRatio', shortName=TrackPropEnum.LENGTH_RATIO.maya, niceName='Length Ratio') cmds.addAttr( longName='cadence_rotationUncertainty', shortName=TrackPropEnum.ROTATION_UNCERTAINTY.maya, niceName='Rotation Uncertainty') cmds.addAttr( longName='cadence_uniqueId', shortName=TrackPropEnum.UID.maya, dataType='string', niceName='Unique ID') # Construct a ruler representing track width, then push it down just # below ground level, and ake it non-selectable. Drive its scale by the # node's width attribute. widthRuler = cmds.polyCube( axis=(0, 1, 0), width=100.0, height=rulerThickness, depth=rulerBreadth, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='WidthRuler')[0] # Push it down to just rest on the triangular node (which is already # submerged by the thickness of the ruler and half the node thickness. cmds.move(0.0, -rulerThickness/2.0, 0.0) cmds.setAttr(widthRuler + '.overrideEnabled', 1) cmds.setAttr(widthRuler + '.overrideDisplayType', 2) # Construct a ruler representing track length and push it down the same # as the width ruler, and make it non-selectable. Its length will be # driven by the node's length attribute. lengthRuler = cmds.polyCube( axis=(0, 1, 0), width=rulerBreadth, height=rulerThickness, depth=100.0, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='LengthRuler')[0] cmds.move(0.0, -rulerThickness/2.0, 0.0) cmds.setAttr(lengthRuler + '.overrideEnabled', 1) cmds.setAttr(lengthRuler + '.overrideDisplayType', 2) # Now construct 'error bars' to the North, South, West, and East of the # node, to visualize uncertainty in width (West and East bars) and # length (North and South bars), and push them just below ground level, # and make them non-selectable. barN = cmds.polyCube( axis=(0,1,0), width=barBreadth, height=barThickness, depth=100.0, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='BarN')[0] cmds.move(0, -(barThickness/2 + rulerThickness), 0) cmds.setAttr(barN + '.overrideEnabled', 1) cmds.setAttr(barN + '.overrideDisplayType', 2) barS = cmds.polyCube( axis=(0, 1, 0), width=barBreadth, height=barThickness, depth=100.0, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='BarS')[0] cmds.move(0, -(barThickness/2 + rulerThickness), 0) cmds.setAttr(barS + '.overrideEnabled', 1) cmds.setAttr(barS + '.overrideDisplayType', 2) barW = cmds.polyCube( axis=(0, 1, 0), width=100.0, height=barThickness, depth=barBreadth, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='BarW')[0] cmds.move(0, -(barThickness/2 + rulerThickness), 0) cmds.setAttr(barW + '.overrideEnabled', 1) cmds.setAttr(barW + '.overrideDisplayType', 2) barE = cmds.polyCube( axis=(0, 1, 0), width=100.0, height=barThickness, depth=barBreadth, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='BarE')[0] cmds.move(0, -(barThickness/2 + rulerThickness), 0) cmds.setAttr(barE + '.overrideEnabled', 1) cmds.setAttr(barE + '.overrideDisplayType', 2) # Create two diverging lines that indicate rotation uncertainty (plus # and minus), with their pivots placed so they extend from the node # center, and each is made non-selectable. First make the indicator of # maximum (counterclockwise) estimated track rotation thetaPlus = cmds.polyCube( axis=(0, 1, 0), width=thetaBreadth, height=thetaThickness, depth=1.0, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='ThetaPlus')[0] cmds.setAttr(thetaPlus + '.overrideEnabled', 1) cmds.setAttr(thetaPlus + '.overrideDisplayType', 2) # Next, construct the indicator of the minimum (clockwise) estimate of # track rotation thetaMinus = cmds.polyCube( axis=(0, 1, 0), width=thetaBreadth, height=thetaThickness, depth=1.0, subdivisionsX=1, subdivisionsY=1, createUVs=0, constructionHistory=0, name='ThetaMinus')[0] cmds.setAttr(thetaMinus + '.overrideEnabled', 1) cmds.setAttr(thetaMinus + '.overrideDisplayType', 2) # The two width 'error bars' will be translated outward from the node # center. First, the width attribute is converted from meters (as it # comes from the database) to centimeters; the computation is available # in the output of the node 'width'. width = cmds.createNode('multiplyDivide', name='width') cmds.setAttr(width + '.operation', 1) cmds.setAttr(width + '.input1X', 100.0) cmds.connectAttr( node + '.' + TrackPropEnum.WIDTH.maya, width + '.input2X') # Translate barW in x by width/2.0; output is in xW.outputX xW = cmds.createNode('multiplyDivide', name = 'xW') cmds.setAttr(xW + '.operation', 2) cmds.connectAttr(width + '.outputX', xW + '.input1X') cmds.setAttr(xW + '.input2X', 2.0) cmds.connectAttr(xW + '.outputX', barW + '.translateX') # Translate barE in x by -width/2.0; output is in xE.outputX xE = cmds.createNode('multiplyDivide', name = 'xE') cmds.setAttr(xE + '.operation', 2) # division operation cmds.connectAttr(width + '.outputX', xE + '.input1X') cmds.setAttr(xE + '.input2X', -2.0) cmds.connectAttr(xE + '.outputX', barE + '.translateX') # Now regarding length, first convert the node.length attribute from # meters to centimeters. This computation is available in the output of # the node 'length' length = cmds.createNode('multiplyDivide', name='length') cmds.setAttr(length + '.operation', 1) cmds.setAttr(length + '.input1X', 100.0) cmds.connectAttr( node + '.' + TrackPropEnum.LENGTH.maya, length + '.input2X') # scale thetaPlus and thetaMinus by length (since they are 1 cm, # multiply by length in cm) cmds.connectAttr(length + '.outputX', thetaPlus + '.scaleZ') cmds.connectAttr(length + '.outputX', thetaMinus + '.scaleZ') # Then barN is translated forward in z by zN = lengthRatio*length # (centimeters) zN = cmds.createNode('multiplyDivide', name='zN') cmds.setAttr(zN + '.operation', 1) cmds.connectAttr( node + '.' + TrackPropEnum.LENGTH_RATIO.maya, zN + '.input1X') cmds.connectAttr(length + '.outputX', zN + '.input2X') cmds.connectAttr(zN + '.outputX', barN + '.translateZ') # Next, translate barS backward in z by (zN - length); output is in # zS.output1D zS = cmds.createNode('plusMinusAverage', name='sZ') cmds.setAttr(zS + '.operation', 2) cmds.connectAttr(zN + '.outputX', zS + '.input1D[0]') cmds.connectAttr(length + '.outputX', zS + '.input1D[1]') cmds.connectAttr(zS + '.output1D', barS + '.translateZ') # Next, compute the half length, hl = length/2.0 (centimeters) hl = cmds.createNode('multiplyDivide', name='hl') cmds.setAttr(hl + '.operation', 2) cmds.connectAttr(length + '.outputX', hl + '.input1X') cmds.setAttr(hl + '.input2X', 2.0) # Translate lengthRuler along z by zL = (zN - hl) (centimeters) zL = cmds.createNode('plusMinusAverage', name='zL') cmds.setAttr(zL + '.operation', 2) cmds.connectAttr(zN + '.outputX', zL + '.input1D[0]') cmds.connectAttr(hl + '.outputX', zL + '.input1D[1]') cmds.connectAttr(zL + '.output1D', lengthRuler + '.translateZ') # Scale the four 'error bars' to represent the width and length # uncertainties (centimeters) cmds.connectAttr( node + "." + TrackPropEnum.WIDTH_UNCERTAINTY.maya, barW + '.scaleX') cmds.connectAttr( node + "." + TrackPropEnum.WIDTH_UNCERTAINTY.maya, barE + '.scaleX') cmds.connectAttr( node + "." + TrackPropEnum.LENGTH_UNCERTAINTY.maya, barN + '.scaleZ') cmds.connectAttr( node + "." + TrackPropEnum.LENGTH_UNCERTAINTY.maya, barS + '.scaleZ') # Create an 'inverter' transform under which all the other parts are # hung as children, which counteracts scaling applied to its parent # triangular node. inverter = cmds.createNode('transform', name='inverter') # drive the inverter's .scaleX and .scaleZ as the inverse of the parent # node's scale values sx = cmds.createNode('multiplyDivide', name='sx') cmds.setAttr(sx + '.operation', 2) cmds.setAttr(sx + '.input1X', 1.0) cmds.connectAttr(node + '.scaleX', sx + '.input2X') cmds.connectAttr(sx + '.outputX', inverter + '.scaleX') sz = cmds.createNode('multiplyDivide', name='sz') cmds.setAttr(sz + '.operation', 2) cmds.setAttr(sz + '.input1X', 1.0) cmds.connectAttr(node + '.scaleZ', sz + '.input2X') cmds.connectAttr(sz + '.outputX', inverter + '.scaleZ') # Assemble the parts as children under the scale inverter node cmds.parent(lengthRuler, inverter) cmds.parent(widthRuler, inverter) cmds.parent(barN, inverter) cmds.parent(barS, inverter) cmds.parent(barW, inverter) cmds.parent(barE, inverter) cmds.parent(thetaPlus, inverter) cmds.parent(thetaMinus, inverter) cmds.parent(inverter, node) # Rotate thetaPlus and thetaMinus about the Y axis to indicate # rotational uncertainty cmds.connectAttr( node + '.' + TrackPropEnum.ROTATION_UNCERTAINTY.maya, node + '|' + inverter + '|' + thetaPlus + '.rotateY') neg = cmds.createNode('multiplyDivide', name='negative') cmds.setAttr(neg + '.operation', 1) cmds.setAttr(neg + '.input1X', -1.0) cmds.connectAttr( node + '.' + TrackPropEnum.ROTATION_UNCERTAINTY.maya, neg + '.input2X') cmds.connectAttr( neg + '.outputX', node + '|' + inverter + '|' + thetaMinus + '.rotateY') # Disable some transforms of the node cmds.setAttr(node + '.rotateX', lock=True) cmds.setAttr(node + '.rotateZ', lock=True) cmds.setAttr(node + '.scaleY', lock=True) cmds.setAttr(node + '.translateY', lock=True) # Now, the width of the triangle will be driven by its width attribute # (driving .scaleX) cmds.connectAttr(node + '.width', node + '.scaleX') # The quantity zN is used to scale length of the triangle cmds.connectAttr(zN + '.outputX', node + '.scaleZ') # Scale the 'length' (in x) of the width ruler cmds.connectAttr( node + '.width', node + '|' + inverter + '|WidthRuler.scaleX') # Scale the length of the length ruler cmds.connectAttr( node + '.length', node + '|' + inverter + '|LengthRuler.scaleZ') # Translate the track node epsilon below ground level (to reveal the # overlaid track siteMap) cmds.move(0, -epsilon, 0, node) # Initialize all the properties from the dictionary if props: cls.setTrackProps(node, props) else: print('in createTrackNode: properties not provided') return node # Add the new nodeName to the Cadence track scene set, color it, and # we're done cmds.sets(node, add=trackSetNode) cls.colorTrackNode(node, props) return node
def __init__(self, name, c1=None, c2=None, c3=None): self.name = name self.currentFeet = "parallel" self.currentArms = "straight" self.color1 = c1 self.color2 = c2 self.color3 = c3 if self.color1 is None: self.color1 = 'initialShadingGroup' if self.color2 is None: self.color2 = 'initialShadingGroup' if self.color3 is None: self.color3 = 'initialShadingGroup' #self.sword = sword.Sword(name) ''' mc.select(cl=True) self.rightHand = hand.Hand(name+'_right', Side.right) mc.select(cl=True) self.leftHand = hand.Hand(name+'_left', Side.left) ''' self.leftLeg = leg.Leg(name + '_left', Side.left, self.color1, self.color2, self.color3) mc.select(cl=True) self.rightLeg = leg.Leg(name + '_right', Side.right, self.color1, self.color2, self.color3) mc.select(cl=True) self.leftArm = arms.Arm(name + '_left', Side.left, self.color1, self.color2, self.color3) mc.select(cl=True) self.rightArm = arms.Arm(name + '_right', Side.right, self.color1, self.color2, self.color3) mc.select(cl=True) mc.select(self.rightArm.hand.j_wrist) #mc.move(-112, 173, 0, r=True) mc.rotate('180deg', '-90deg', 0, r=True) mc.select(self.leftArm.hand.j_wrist) #mc.move(112, 173, 0, r=True) mc.rotate('180deg', '90deg', 0, r=True) mc.select(self.rightLeg.j_hip) mc.move(-20, 0, 12, r=True) mc.select(self.leftLeg.j_hip) mc.move(20, 0, 12, r=True) mc.select(self.rightLeg.h_foot) mc.move(-20, 0, 12, r=True) mc.select(self.leftLeg.h_foot) mc.move(20, 0, 12, r=True) mc.select(self.rightArm.j_shoulder) mc.move(-35, 90, 0, r=True) mc.rotate(0, 0, -90) mc.select(self.leftArm.j_shoulder) mc.move(35, 90, 0, r=True) mc.rotate(0, 0, 90) self.torso = torso.Torso(name + '_torso', self.color1, self.color2, self.color3) mc.select(self.torso.j_root) mc.select(self.torso.j_bind_root, add=True) mc.move(0, 107, 0) mc.select(self.torso.j_bind_neck) mc.select(self.torso.h_hips, add=True) mc.select(self.torso.h_shoulders, add=True) mc.move(0, 107, 0, r=True) self.head = head.Head(name) #mc.select(self.head.head) mc.select(self.head.j_head) mc.move(0, 189, 0) mc.parent(self.rightLeg.j_hip, self.torso.j_root) mc.parent(self.leftLeg.j_hip, self.torso.j_root) mc.parent(self.rightArm.j_shoulder, self.torso.j_s5) mc.parent(self.leftArm.j_shoulder, self.torso.j_s5) mc.parent(self.head.j_head, self.torso.j_neck) #mc.parent(self.leftArm.hand.j_wrist, self.leftArm.j_elbow) #mc.parent(self.rightArm.hand.j_wrist, self.rightArm.j_elbow) mc.select(cl=True) self.j_root = mc.joint(p=(0, 107, 0), n=name + '_root') mc.parent(self.torso.j_root, self.j_root) mc.setAttr( self.j_root + " | " + self.torso.j_root + ".segmentScaleCompensate", 0) mc.select(cl=True) self.parentIKToRoot() #print self.leftArm.h_hand self.leftArm.hand.setBallet() self.rightArm.hand.setBallet()
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 _handlePair(self): cmds.parent('hand_L', 'arm_L') cmds.parent('hand_R', 'arm_R')
def _createJoints(self, side): #bone mc.select(cl=True) self.j_wrist = mc.joint(p=(0, 0, 0), n='wrist') '''self.j_r_p_n_2 = mc.joint( p=(offset,4.25+(2*self.segOffset),.25),dof='x') self.j_r_p_n_3 = mc.joint( p=(offset,6.25+(4*self.segOffset),.25),dof='x') self.j_r_p_n_4 = mc.joint( p=(offset,8.25+(6*self.segOffset),.25)) ''' mc.select(cl=True) mc.parent(self.index.j_n_1, self.j_wrist) mc.parent(self.middle.j_n_1, self.j_wrist) mc.parent(self.ring.j_n_1, self.j_wrist) mc.parent(self.pinky.j_n_1, self.j_wrist) mc.parent(self.thumb.j_thumb_1, self.j_wrist) mc.select(cl=True) mc.parent(self.hand, self.j_wrist)
def attachIKToRoot(self): mc.parent(self.leftLeg.h_foot, self.j_root) mc.parent(self.rightLeg.h_foot, self.j_root) mc.parent(self.leftArm.h_hand, self.j_root) mc.parent(self.rightArm.h_hand, self.j_root) mc.parent(self.torso.h_shoulders, self.j_root) mc.parent(self.torso.h_hips, self.j_root) pass
def detachArmsIKFromRoot(self): mc.parent(self.j_root + "|" + self.leftArm.h_hand, world=True) mc.parent(self.j_root + "|" + self.rightArm.h_hand, world=True) pass