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 _removeMeshPointNode(self): if self._meshPointNode is None: return try: cmds.delete(self._meshPointNode) except Exception: pass self._meshPointNode = None
def deleteAllPaths(self): """ Deletes all curves that have been placed in the PATH_LAYER. """ curves = cmds.editDisplayLayerMembers( self.PATH_LAYER, query=True, noRecurse=True) for curve in curves: cmds.delete(curve) cmds.delete(self.PATH_LAYER)
def deleteToken(self, uid): """ This looks up the token or proxy corresponding to the uid, then deletes it. """ node = self.getTokenNodeName(uid) if node: cmds.delete(node) number = node.split('_')[1] if number: annotation = 'TokenAnnotation_' + number cmds.delete(annotation)
def _handleDeleteAllButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ allObj = cmds.ls("molecule*", assemblies=True) for i in allObj: cmds.delete(i) cmds.delete("redBlinnSG") cmds.delete("whiteBlinnSG") cmds.delete("redBlinn") cmds.delete("whiteBlinn") self.spawnButton.setText("Spawn Molecules")
def _handleDeleteAllButton(self): """ This callback creates a polygonal cylinder in the Maya scene. """ allObj = cmds.ls('molecule*', assemblies=True) for i in allObj: cmds.delete(i) cmds.delete("redBlinnSG") cmds.delete("whiteBlinnSG") cmds.delete("redBlinn") cmds.delete("whiteBlinn") self.spawnButton.setText("Spawn Molecules")
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 initializeLayers(self): """ Creates a new layer for each trackway in this site and level based on the first UID found (returned by getUidList). It is important to load into the Maya scene only trackways from a common combination of site, level, and sector, since a given trackway may be redundantly defined in different sectors for a given site and level. The list of trackway names is returned for the TrackwayManagerWidget to populate a combo box. """ # first delete any current display layers layers = cmds.ls( type='displayLayer') for layer in layers: if (layer.endswith(self.LAYER_SUFFIX)): cmds.delete(layer) # get the current UID list so we can extract the site, year, sector, and # level information uidList = self.getUidList() if not uidList: return # we'll use the first track as representative of the site and level, # presumed to be in common with all tracks in this scene. track = self.getTrackByUid(uidList[0]) trackwayNames = self.getTrackwayNames(track.site, track.level) # then for each trackway name (such as 'S1') create a corresponding # layer with the LAYER_SUFFIX, then populate it with the track nodes of # the tracks comprising that trackway for trackwayName in trackwayNames: layer = '%s%s' % (trackwayName, self.LAYER_SUFFIX) # then make the layer self.createLayer(layer) # get a list of tracks for this trackway (filtering on site, level, # sector and name) trackway = self.getTrackway(trackwayName, uidList) if trackway and len(trackway) > 0: self.addTrackwayToLayer(layer, trackway) return trackwayNames
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 run(self, *args, **kwargs): """ Fetches the nodes in the current trackSetNode, then for each such node, those that start with 'Token' are deleted. """ setNode = TrackSceneUtils.getTrackSetNode() nodes = cmds.sets(setNode, q=True) if len(nodes) == 0: self.puts(success=False, uidList=[]) return for node in nodes: if node.startswith('Token'): cmds.delete(node) # and remove the annotations (objects with name starting with 'Token' objects = cmds.ls(transforms=True) for object in objects: if object.startswith('Token'): cmds.delete(object) return
def clearScene(): cmds.select(all=True) cmds.delete()
def _deleteHistory(self): mc.select(self.j_wrist) mc.delete(ch=True)
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 _deleteHistory(self): mc.select(self.j_shoulder) mc.delete(ch=True)
def deleteLayer(self, layer): """ Deletes a display layer. """ if not cmds.objExists(layer): cmds.delete(layer)
def _deleteHistory(self): mc.select(self.j_root) mc.delete(ch=True) #Torso('torso')
def _deleteHistory(self): mc.select(self.j_ankle) mc.delete(ch=True)
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')
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')