def MergeVertices(self): #select all objects in the scene pmc.select(all=True) #change selection mode to component pmc.selectMode(component=True) pmc.selectType(v=True)
def PerlinNoiseFiller( NObject, FMin, FMax ): # Set Local Variables NObjName = '%s' % NObject.name() Divisions = 15 Vmin = FMin Vmax = FMax # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to a random value weighted by the sum of its location for v in range(len(ObjectVerts)): loc = pm.xform( ObjectVerts[v], query=True, translation=True, worldSpace=True ) RawValue = PerlinNoise((loc[0]*200),(loc[1]*300),(loc[2]*250), Divisions) ModValue = math.fabs(math.cos(RawValue/10.0)) FValue = max(min(ModValue, Vmax), Vmin) pm.polyColorPerVertex( ObjectVerts[v], colorRGB=( FValue, FValue, FValue ), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def f3DNoise( NObject, FMin, FMax ): # Set Local Variables NObjName = '%s' % NObject.name() min = FMin max = FMax # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) RandomVerts = list(ObjectVerts) random.shuffle(RandomVerts) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to a random value weighted by the sum of its location for v in range(len(ObjectVerts)): loc = pm.xform( RandomVerts[v], query=True, translation=True, worldSpace=True ) locValue = math.sqrt(abs(random.choice(loc))) RValue = random.uniform( min, max ) FValue = (locValue * RValue)/2 pm.polyColorPerVertex( ObjectVerts[v], colorRGB=( FValue, FValue, FValue ), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def editJointPivotTool(self): objs = pm.selected() pm.selectMode(co=True) pm.selectType(ra=True) pm.select(objs[0].rotateAxis, r=True) rotateCtx = pm.manipRotateContext(psc=pm.Callback(self.editJointPivotExit, objs)) pm.setToolTo(rotateCtx)
def get_select_type(): if pymel.selectType(vertex=True, query=True): return 'vertex' elif pymel.selectType(facet=True, query=True): return 'face' elif pymel.selectType(edge=True, query=True): return 'edge'
def setComponentSelectType(self, enabled=True, keys={}): pm.selectMode(component=True) kwargs = {} for k in keys: kwargs[k] = enabled for k in self.allkeys: if not kwargs.has_key(k): kwargs[k] = not enabled pm.selectType(**kwargs)
def create(self): index_list = self.vertexFromMaps('polyHide', threshold=self.threshold) mesh_vertex = ['{}.vtx[{}]'.format(self.mesh, i) for i in index_list] pm.select(mesh_vertex, r=1) mel.eval("ConvertSelectionToFaces;") pm.selectType(objectComponent=1, allComponents=False) pm.selectType(objectComponent=1, polymeshFace=True) pm.mel.PolySelectConvert(1) all_faces = pm.selected() if pm.selected(): self.add_material() pm.select(None)
def import_component(file_path, selected_object): """ This function opens the selected file and reads the information from the file :param file_path: :param selected_object: :return: """ try: f = open(file_path, 'r') except: pm.confirmDialog( t='Error', b=['OK'], m='Unable to read file: %s' % file_path ) raise component = cPickle.load(f) f.close() # this list is for storing the unmatched component ID's err_comps = [] # selected objects name if selected_object is None: selected_object = get_selected_object() else: None # this list is for storing the component ID's with the name of the object selection = [] # clearing any selection on the mesh pm.select(clear=True) # this for loop is for merging and the storing the component ID's with the object ID unmatched ID's is gonna be # stored in errComps list. for compValue in component: try: selection.append(selected_object+"."+compValue) except: try: err_comps.append(compValue[0]) except: err_comps.append(compValue) # changing the select mode into component mode pm.selectMode(component=True) # changing the hilite visibility to true pm.hilite(selected_object, r=True) # this is for checking the component types and changing the selection type to the chosen component if component[0].startswith("vtx["): pm.selectType(pv=True) elif component[0].startswith("vtxFace["): pm.selectType(pvf=True) elif component[0].startswith("e["): pm.selectType(pe=True) elif component[0].startswith("f["): pm.selectType(pf=True) else: None # applying the selection by using the list pm.select(selection, r=True) # checks the component errors if any if len(err_comps) > 0: import_error_window(err_comps) sys.stderr.write('Not all components could be loaded.') return selected_object
def create(self): dupMesh = self.duplicateMesh() index_list = self.vertexFromMaps('PolyDelete', threshold=self.threshold) mesh_vertex = ['{}.vtx[{}]'.format(dupMesh, i) for i in index_list] pm.select(mesh_vertex, r=1) mel.eval("ConvertSelectionToFaces;") pm.selectType(objectComponent=1, allComponents=False) pm.selectType(objectComponent=1, polymeshFace=True) pm.mel.PolySelectConvert(1) all_faces = pm.selected() pm.delete(all_faces) pm.select(None)
def SetMiddleGrey( NObject ): NObjName = '%s' % NObject.name() # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to 0.5 Grey for v in range(len(ObjectVerts)): pm.polyColorPerVertex( ObjectVerts[v], colorRGB=(0.5,0.5,0.5), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def combineClean(instanceGroup, meshName, duplicateFaces=False): print("Combining mesh") mesh = pm.polyUnite(instanceGroup, name=meshName, constructionHistory=False) #print( "Merging %i" % len( mesh[ 0 ].vtx ) + " verticies" ) pm.polyMergeVertex(mesh[0].vtx, distance=0.1) #print( "Reduced to %i" % mesh[ 0 ].numVertices() + " verticies" ) if duplicateFaces: print("Cleaning up faces") pm.select(mesh[0]) pm.selectType(polymeshFace=True) pm.polySelectConstraint(mode=3, type=0x0008, topology=2) # Don't ask me how I did this mel.eval( 'polyCleanupArgList 3 { "0","2","0","0","0","0","0","0","0","1e-005","0","1e-005","1","0.3","0","-1","1" };' ) pm.delete() pm.polySelectConstraint(mode=0, topology=0) pm.selectType(polymeshFace=False) pm.selectMode(object=True) print("Faces reduced") if pm.PyNode(instanceGroup).exists(): pm.delete(instanceGroup) pm.delete(constructionHistory=True) pm.select(clear=True) print("Cleaning up complete") return mesh
def spawnEnemy( minSpawn, maxSpawn): colorRGBV = [1,1,0] rMax = maxSpawn rMin = minSpawn spawnMin = rMin + .01 spawnMax = rMax - .01 locX = random.uniform(spawnMin, spawnMax) locY = random.uniform(spawnMin, spawnMax) moveVectorX = random.uniform(-1.0,1.0) moveVectorY = random.uniform(-1.0,1.0) mayaObj = pm.polyCube( name="Enemy", w=1, h=1, d=1, cuv=0, ax=(0,1,0), sx=1, sy=1, sz=1 ) moveObj(mayaObj[0], locX, 0, locY) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() pVs = pm.ls( selection=True, fl=True ) pm.select( cl=True ) for v in range(len(pVs)): pm.polyColorPerVertex( pVs[v], colorRGB=colorRGBV, alpha=1.0, cdo=True, notUndoable=True ) return [mayaObj, moveVectorX, moveVectorY]
def combineClean( instanceGroup, meshName, duplicateFaces = False ): print( "Combining mesh" ) mesh = pm.polyUnite( instanceGroup, name = meshName, constructionHistory = False ) #print( "Merging %i" % len( mesh[ 0 ].vtx ) + " verticies" ) pm.polyMergeVertex( mesh[ 0 ].vtx, distance = 0.1 ) #print( "Reduced to %i" % mesh[ 0 ].numVertices() + " verticies" ) if duplicateFaces: print( "Cleaning up faces" ) pm.select( mesh[ 0 ] ) pm.selectType( polymeshFace = True ) pm.polySelectConstraint( mode = 3, type = 0x0008, topology = 2 ) # Don't ask me how I did this mel.eval('polyCleanupArgList 3 { "0","2","0","0","0","0","0","0","0","1e-005","0","1e-005","1","0.3","0","-1","1" };') pm.delete() pm.polySelectConstraint( mode = 0, topology = 0 ) pm.selectType( polymeshFace = False ) pm.selectMode( object = True ) print( "Faces reduced" ) if pm.PyNode( instanceGroup ).exists(): pm.delete( instanceGroup ) pm.delete( constructionHistory = True ) pm.select( clear = True ) print( "Cleaning up complete" ) return mesh
def switchSelectionModeToEdge(item): ''' :Reference: doMenuComponentSelection in C:/Program Files/Autodesk/Maya2017/scripts/others/dagMenuProc.mel ''' pm.mel.eval('HideManipulators') if pm.selectMode(q=True, object=True): pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, edge=True) pm.selectType(edge=True) pm.hilite(item) else: pm.selectType(alc=False) pm.selectType(edge=True) not pm.selectMode(q=True, preset=True) or pm.hilite(item) try: not pm.mel.eval('exists dR_selTypeChanged') or pm.mel.eval( 'dR_selTypeChanged("edge")') except pm.MelError: pass
def SimpleNoise( NObject, FMin, FMax ): # Set Local Variables NObjName = '%s' % NObject.name() min = FMin max = FMax # Select the Objects Vertices pm.selectMode( co=True ) pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() # List the Objects Vertices ObjectVerts = pm.ls( selection=True, fl=True ) pm.select( cl=True ) # For Every Vertex on the Object, Set its Vertex Color to 0.5 Grey for v in range(len(ObjectVerts)): FValue = random.uniform( min, max ) pm.polyColorPerVertex( ObjectVerts[v], colorRGB=( FValue, FValue, FValue ), alpha=1.0) # Release the Selection Constraints pm.polySelectConstraint( mode=0 ) pm.selectMode( o=True ) # Select the Object Again pm.select( NObjName )
def buildMenuItems(self): pm.menuItem(rp='NW', l='Reset', ecr=False, ann='Reset all selection masks', c=pm.Callback(self.resetSelectionMasking)) pm.menuItem(rp='NE', l='All Off', ecr=False, c=pm.Callback(self.setObjectSelectType, enabled=False, keys=self.allkeys)) pm.menuItem(rp='SE', l='Clear Selection', ecr=True, c=pm.Callback(pm.select, cl=True)) pm.menuItem(rp='S', l='Use Selected', c=pm.Callback(self.setMaskingToSelection)) selType = lambda x: pm.selectType(q=True, **{x: True}) # common masking pm.menuItem(rp='N', l='Polys', ecr=False, cb=selType('p'), c=pm.CallbackWithArgs(self.setObjectSelectType, keys=['polymesh'])) pm.menuItem(rp='E', l='Curves', ecr=False, cb=selType('nurbsCurve'), c=pm.CallbackWithArgs(self.setObjectSelectType, keys=['nurbsCurve', 'cos', 'stroke'])) pm.menuItem(rp='SW', l='Joints', ecr=False, cb=selType('joint'), c=pm.CallbackWithArgs(self.setObjectSelectType, keys=['joint'])) pm.menuItem(rp='W', l='Surfaces', ecr=False, cb=selType('nurbsSurface'), c=pm.CallbackWithArgs( self.setObjectSelectType, keys=['nurbsSurface', 'subdiv', 'plane'])) # extended menu pm.menuItem(l='Selection Masking', en=False) pm.menuItem(d=True) pm.menuItem(l='Render', ecr=False, cb=selType('light'), c=pm.CallbackWithArgs(self.setObjectSelectType, keys=['light', 'camera', 'texture'])) pm.menuItem(l='Deformers', ecr=False, cb=selType('lattice'), c=pm.CallbackWithArgs( self.setObjectSelectType, keys=['lattice', 'cluster', 'sculpt', 'nonlinear'])) pm.menuItem(l='Dynamics', ecr=False, cb=selType('particleShape'), c=pm.CallbackWithArgs(self.setObjectSelectType, keys=[ 'particleShape', 'emitter', 'field', 'spring', 'rigidBody', 'fluid', 'hairSystem', 'follicle', 'rigidConstraint' ])) pm.menuItem(l='Misc', ecr=False, cb=selType('ikEndEffector'), c=pm.CallbackWithArgs( self.setObjectSelectType, keys=['ikEndEffector', 'locator', 'dimension']))
def run(): RawMovementVector = IntVector2( 0, 0 ) numEnemies = 15 playSpaceMinMaxX = 50 playSpaceMinMaxY = 50 enemyList = [] # Init SDL if sdl2.SDL_Init(sdl2.SDL_INIT_TIMER|sdl2.SDL_INIT_GAMECONTROLLER|sdl2.SDL_INIT_EVENTS) != 0: print(sdl2.SDL_GetError()) return -1 # Init Controller controller = sdl2.SDL_GameController() for i in range(sdl2.SDL_NumJoysticks()): if sdl2.SDL_IsGameController(i): controller = sdl2.SDL_GameControllerOpen(i) # Create SDL Window ctrlWindow = sdl2.SDL_CreateWindow( b"Control", sdl2.SDL_WINDOWPOS_UNDEFINED, sdl2.SDL_WINDOWPOS_UNDEFINED, 200, 150, sdl2.SDL_WINDOW_INPUT_FOCUS|sdl2.SDL_WINDOW_HIDDEN ) if not ctrlWindow: print(sdl2.GetError()) return -1 # Init Player player = pm.polyCube( name="Player", w=1, h=1, d=1, cuv=0, ax=(0,1,0), sx=1, sy=1, sz=1 ) if player is None: print "ERROR! Player not created!" return -1 else: pm.selectType( pv=True ) pm.polySelectConstraint( type=0x0001, mode=3 ) pm.select() pVs = pm.ls( selection=True, fl=True ) pm.select( cl=True ) for v in range(len(pVs)): pm.polyColorPerVertex( pVs[v], colorRGB=(1.0,0.0,0.0), alpha=1.0, cdo=True, notUndoable=True ) pSpeed = 40.0 for i in range(numEnemies): thisE = spawnEnemy(-(playSpaceMinMaxX), playSpaceMinMaxX) enemyList.append(thisE) print enemyList # Start Ticks lastTime = 0 cTime = sdl2.SDL_GetTicks() activeEnemies = numEnemies playerScale = 1.0 # Start Game Loop running = True while running: # See if Yout Won achieved #print activeEnemies if activeEnemies < 1: sdl2.SDL_DestroyWindow(ctrlWindow) sdl2.SDL_Quit() pm.select( all=True ) pm.delete() return "You Won!" #Calculate Delta Time lastTime = cTime cTime = sdl2.SDL_GetTicks() dTime = cTime - lastTime if dTime > 16: dTime = 16 deltaM = float(dTime)/float(1000) ButtonPressed = False # Process Input evnt = sdl2.SDL_Event() while sdl2.SDL_PollEvent(ctypes.byref(evnt)) != 0: if evnt.type == sdl2.SDL_QUIT: running = False break elif evnt.type == sdl2.SDL_CONTROLLERAXISMOTION: if evnt.caxis.axis == sdl2.SDL_CONTROLLER_AXIS_LEFTX: RawMovementVector.x = evnt.caxis.value break elif evnt.caxis.axis == sdl2.SDL_CONTROLLER_AXIS_LEFTY: RawMovementVector.y = evnt.caxis.value break elif evnt.type == sdl2.SDL_CONTROLLERBUTTONDOWN: if evnt.cbutton.button == sdl2.SDL_CONTROLLER_BUTTON_A: ButtonPressed = True break elif evnt.type == sdl2.SDL_CONTROLLERBUTTONUP: if evnt.cbutton.button == sdl2.SDL_CONTROLLER_BUTTON_A: ButtonPressed = False break elif evnt.type == sdl2.SDL_KEYDOWN: if evnt.key.keysym.sym == sdl2.SDLK_ESCAPE: sdl2.SDL_DestroyWindow(ctrlWindow) sdl2.SDL_Quit() break #print RawMovementVector.x, RawMovementVector.y, ButtonPressed # Remap Raw Movement to -1 to 1 in float Movement = RemapMovement( RawMovementVector.x, RawMovementVector.y ) #print Movement.x, Movement.y pMoveX = Movement.x * (deltaM*pSpeed) pMoveY = Movement.y * (deltaM*pSpeed) moveObj( player[0], pMoveX, 0.0, pMoveY) for i in range(len(enemyList)): testList = enemyList testList[i] = updateEnemy( testList[i], playSpaceMinMaxX, playSpaceMinMaxY, deltaM ) if detectCollision( player[0], testList[i][0][0] ) == True: vis = pm.getAttr( testList[i][0][0]+'.visibility' ) if vis == True: pm.hide( enemyList[i][0][0] ) activeEnemies = activeEnemies - 1 playerScale = playerScale + 0.5 pm.xform( player[0], scale=[playerScale, playerScale, playerScale] ) # redraw viewport pm.refresh( cv=True ) sdl2.SDL_DestroyWindow(ctrlWindow) sdl2.SDL_Quit() return 0
def setObjectSelectType(self, enabled, keys): pm.selectMode(object=True) kwargs = {} for k in keys: kwargs[k] = enabled pm.selectType(**kwargs)
def switch_joint_picker(): state = pm.selectType(q=1, j=1) pm.selectType(j=not state)
def switch_geo_picker(): state = pm.selectType(q=1, p=1) pm.selectType(p=not state)
def switch_curve_Picker(): state = pm.selectType(q=1, nc=1) pm.selectType(nc=not state)
# DelRandIntEdges.py # # Leif Peterson 2016 # # This code deletes random interior edges and cleans up winged vertices, while maintaing corners import pymel.core as pm import random # create a list of all selected objects SelectedObjects = pm.ls( selection=True, o=True ) # for each object delete its interior edges randomly for Object in range(len(SelectedObjects)): # select only border edges pm.selectType( pe=True ) pm.hilite( SelectedObjects[Object] ) pm.polySelectConstraint( mode=3, type=0x8000, where=1 ) pm.select() borderEdges = pm.ls( selection=True, fl=True ) # select all edges pm.polySelectConstraint( where=0 ) pm.select() allEdges = pm.ls( selection=True, fl=True ) # initilize the inside edges list insideEdges = [] # remove border edges for edge in range(len(borderEdges)):
def switchSelectType(cls, type, *args, **kwargs): ''' ''' if type == 'mesh': pm.selectMode(object=True) if type == 'vtx': pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, polymeshVertex=True) if type == 'e': pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, polymeshEdge=True) if type == 'f': pm.selectType(ocm=True, alc=False) pm.selectType(ocm=True, polymeshFace=True)