def limit(limit=1, key=''): from macouno import liberty lib = liberty.liberty('string', key) nupolygons = lib.makeDict(mesh_extras.get_selected_polygons()) nuLen = len(nupolygons) while nuLen > limit: deFace = lib.Choose('select',nupolygons) deFace.select = False nupolygons = lib.makeDict(mesh_extras.get_selected_polygons()) nuLen = len(nupolygons) return
def __init__(self, context, translation, rotation, rotation_falloff, scale, scale_falloff, retain, steps, debug, animate): self.startTime = time.time() self.markTime = self.startTime self.debug = debug self.animate = animate self.context = context self.ob = context.active_object self.selectNr = len(mesh_extras.get_selected_polygons()) if not self.selectNr: print('Grow error no polygons selected') return if steps: self.ob['growsteps'] = 0 self.factor = 0.0 self.iteration = 0 self.reachedGoal = False self.translated = 0.0 self.currentX = 0.0 self.averagelength = 0.0 # Go into object mode for the initial stages bpy.ops.object.mode_set(mode='OBJECT') self.averageLength = mesh_extras.get_average_outer_edge_length() if self.averageLength == 0.0: print('ERROR NO OUTER EDGES FOUND') return # Now this is an added bit only for use with entoform.py # This matrix may already be set by a previous grow function running making this shape (just being consistent) try: self.transformMatrix = mathutils.Matrix((self.ob['growmatrix'][0],self.ob['growmatrix'][1],self.ob['growmatrix'][2])) except: self.transformMatrix = mesh_extras.get_selection_matrix() # This matrix is just there to check whether the "directions" are correct try: self.checkMatrix = mathutils.Matrix((self.ob['formmatrix'][0],self.ob['formmatrix'][1],self.ob['formmatrix'][2])) print('GOT checkmatrix') except: self.checkMatrix = False # Make the actions actions = [] actions.append({'type': 'extrude'}) actions.append({'type': 'scale', 'vector': scale, 'falloff': scale_falloff}) actions.append({'type': 'rotate', 'vector': mathutils.Vector(rotation), 'falloff': rotation_falloff}) actions.append({'type': 'translate', 'vector': translation}) # Add the extrude at the start (doing it this way in case we'd like to invert the list) #actions.insert(0, {'type': 'extrude'}) # Loop through all the actions bpy.ops.object.mode_set(mode='EDIT') self.mark('startloop') while not self.reachedGoal: self.mark('step '+str(self.iteration)) # Window redraw nice as a hack! #bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1) #time.sleep(0.5) # Figure out how much to translate and where we are on the curves self.currentX = self.translated / translation self.translated += self.averageLength self.newX = self.translated / translation self.mark('transcal') self.mark(self.translated) self.mark(translation) # Lets check.. if we move beyond the wanted result in this step... we quit! if self.translated == translation: self.reachedGoal = True elif self.translated > translation: self.reachedGoal = True self.newX = 1.0 break self.mark('actions') for action in actions: self.mark(action['type']+' start') self.spurt(action) self.mark(action['type']+' end') self.iteration += 1 if steps: self.ob['growsteps'] = self.iteration scene_update.go(False, self.animate) # Save this matrix, in case we grow again... if retain: self.ob['growmatrix'] = self.transformMatrix else: try: del(self.ob['growmatrix']) except: pass self.mark('end')
def __init__(self, context, translation, rotation, rotation_falloff, scale, scale_falloff, retain, steps, debug): self.startTime = time.time() self.markTime = self.startTime self.debug = debug self.context = context self.ob = context.active_object self.selectNr = len(mesh_extras.get_selected_polygons()) if not self.selectNr: print('Grow error no polygons selected') return if steps: self.ob['growsteps'] = 0 self.factor = 0.0 self.iteration = 0 self.reachedGoal = False self.translated = 0.0 self.currentX = 0.0 self.averagelength = 0.0 # Go into object mode for the initial stages bpy.ops.object.mode_set(mode='OBJECT') self.averageLength = mesh_extras.get_average_outer_edge_length() # Now this is an added bit only for use with entoform.py # This matrix may already be set by a previous grow function running making this shape (just being consistent) try: self.transformMatrix = mathutils.Matrix((self.ob['growmatrix'][0],self.ob['growmatrix'][1],self.ob['growmatrix'][2])) except: self.transformMatrix = mesh_extras.get_selection_matrix() # This matrix is just there to check whether the "directions" are correct try: self.checkMatrix = mathutils.Matrix((self.ob['formmatrix'][0],self.ob['formmatrix'][1],self.ob['formmatrix'][2])) print('GOT checkmatrix') except: self.checkMatrix = False # Make the actions actions = [] actions.append({'type': 'extrude'}) actions.append({'type': 'scale', 'vector': scale, 'falloff': scale_falloff}) actions.append({'type': 'rotate', 'vector': mathutils.Vector(rotation), 'falloff': rotation_falloff}) actions.append({'type': 'translate', 'vector': translation}) # Add the extrude at the start (doing it this way in case we'd like to invert the list) #actions.insert(0, {'type': 'extrude'}) # Loop through all the actions bpy.ops.object.mode_set(mode='EDIT') self.mark('startloop') while not self.reachedGoal: self.mark('step '+str(self.iteration)) # Window redraw nice as a hack! #bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1) #time.sleep(0.5) # Figure out how much to translate and where we are on the curves self.currentX = self.translated / translation self.translated += self.averageLength self.newX = self.translated / translation self.mark('transcal') # Lets check.. if we move beyond the wanted result in this step... we quit! if self.translated == translation: self.reachedGoal = True elif self.translated > translation: self.reachedGoal = True self.newX = 1.0 break self.mark('actions') for action in actions: self.mark(action['type']+' start') self.spurt(action) self.mark(action['type']+' end') self.iteration += 1 if steps: self.ob['growsteps'] = self.iteration # Save this matrix, in case we grow again... if retain: self.ob['growmatrix'] = self.transformMatrix else: try: del(self.ob['growmatrix']) except: pass self.mark('end')
def makeAffectedGroups(self, string, baseGroups): selection = string['selection'] newGroups = [] formmatrix = mathutils.Matrix() growmatrices = [] # Select everything in the base groups for i, g in enumerate(baseGroups): # Deselect on the first go if not i: e = False else: e = True #print('base',g.name) select_bmesh_faces.go(mode='GROUPED', extend=e, group=g.index) #print('in_group',len(mesh_extras.get_selected_polygons())) # If nothing is selected there's nothing to do if mesh_extras.contains_selected_item(self.me.polygons): # Select the polygons at the tip in a certain direction if selection['type'] == 'joint': select_bmesh_faces.go(mode='INNER') #print('1, selected',len(mesh_extras.get_selected_polygons()),mesh_extras.contains_selected_item(self.me.polygons)) if mesh_extras.contains_selected_item(self.me.polygons): #return newGroups, formmatrix, growmatrices # Select connected twice to make sure we have enough now that selection is doubled select_bmesh_faces.go(mode='CONNECTED', extend=True) select_bmesh_faces.go(mode='CONNECTED', extend=True) #print('2, selected',len(mesh_extras.get_selected_polygons())) selCnt = len(mesh_extras.get_selected_polygons()) nuCnt = selCnt div = selection['divergence'] # If the nr of polygons selected isn't diminished... we select less! while selCnt and selCnt == nuCnt and div > 0.1: select_bmesh_faces.go(mode='DIRECTIONAL', direction=selection['vector'], limit=div) nuCnt = len(mesh_extras.get_selected_polygons()) #print('join selection at',math.degrees(div), nuCnt) div = div * 0.5 if nuCnt == selCnt: select_bmesh_faces.go(mode='NONE') # If we have selected polygons... we can add em to a new group newGroups, formmatrix, growmatrices = self.addToNewGroups(string, newGroups, growmatrices) # Select by direction elif selection['type'] == 'direction': select_bmesh_faces.go(mode='DIRECTIONAL', direction=selection['vector'],limit=selection['divergence']) #print('done selecting', len(mesh_extras.get_selected_polygons()),'polys in',selection['vector'],math.degrees(selection['divergence'])) newGroups, formmatrix, growmatrices = self.addToNewGroups(string, newGroups, growmatrices) # All! else: newGroups, formmatrix, growmatrices = self.addToNewGroups(string, newGroups, growmatrices) return newGroups, formmatrix, growmatrices