Exemplo n.º 1
0
	def addToNewGroups(self, string, newGroups, growmatrices=[]):
	
		selection = string['selection']
		
		formmatrix = mesh_extras.get_selection_matrix()
		
		if selection['area'] == 'area':
			
			# make sure we have one continuous island selected
			select_bmesh_faces.go(mode='ISLAND')
			
			addedGroup = bmesh_extras.add_to_group(newGroup=True, groupName=string['name'])
			addedGroups = [addedGroup]
		
		else:
			addedGroups = bmesh_extras.cluster_selection(limit=self.clusterSize, groupName=string['name'])
			#print('made',len(addedGroups),'groups')
		
		#addGroups, addMatrices = mesh_extras.group_selection(area = selection['area'], name=string['name'],chunkProduct=4, chunkLimit=selection['limit'])
		
		if len(addedGroups):
			addedMatrices = []
			for g in addedGroups:
				group = bpy.context.active_object.vertex_groups[g]
				newGroups.append(group)
				self.newGroups.append(group)
				
				# Get a matrix for every group
				select_bmesh_faces.go(mode='GROUPED', group=g)
				addedMatrices.append(mesh_extras.get_selection_matrix())
				
			for m in addedMatrices:
				growmatrices.append(m)
			
		return newGroups, formmatrix, growmatrices
Exemplo n.º 2
0
	def addToNewGroups(self, string, newGroups, growmatrices=[]):
	
		selection = string['selection']
		
		formmatrix = mesh_extras.get_selection_matrix()
		
		if selection['area'] == 'area':
			
			# make sure we have one continuous island selected
			select_bmesh_faces.go(mode='ISLAND')
			
			addedGroup = bmesh_extras.add_to_group(newGroup=True, groupName=string['name'])
			addedGroups = [addedGroup]
		
		else:
			addedGroups = bmesh_extras.cluster_selection(limit=self.clusterSize, groupName=string['name'])
			#print('made',len(addedGroups),'groups')
		
		#addGroups, addMatrices = mesh_extras.group_selection(area = selection['area'], name=string['name'],chunkProduct=4, chunkLimit=selection['limit'])
		
		if len(addedGroups):
			addedMatrices = []
			for g in addedGroups:
				group = bpy.context.active_object.vertex_groups[g]
				newGroups.append(group)
				self.newGroups.append(group)
				
				# Get a matrix for every group
				select_bmesh_faces.go(mode='GROUPED', group=g)
				addedMatrices.append(mesh_extras.get_selection_matrix())
				
			for m in addedMatrices:
				growmatrices.append(m)
			
		return newGroups, formmatrix, growmatrices
Exemplo n.º 3
0
	def addToNewGroups(self, string, newGroups, growmatrices=[]):
	
		selection = string['selection']
		self.doubleCheckSelection(selection)
	
		faces = mesh_extras.get_selected_faces()
		
		formmatrix = mathutils.Matrix()
		growmatrices = []
		
		if len(faces):
		
			verts = []
			inds = []
			for f in faces:
				for v in f.vertices:
					if not v in inds:
						inds.append(v)
						verts.append(self.me.vertices[v])

			# NOW WE GO MAKE THE GROUPS
			if len(verts):

				weights = self.makeWeights(verts)
				
				formmatrix = mesh_extras.get_selection_matrix(faces)
				
				# If we do this per area, we want the entire area to be part of one group
				if selection['area'] == 'area':
					growmatrices.append(formmatrix)
					newGroup = self.ob.vertex_groups.new(string['name']+'.'+selection['type'])
					newGroups.append(newGroup)
					self.newGroups.append(newGroup)
					
					for v in verts:
							newGroup.add([v.index], 1.0, 'REPLACE')
					
				# If we have it per face, we need sepparate weights and groups
				elif selection['area'] == 'faces':
				
					if len(faces):
					
						for i, f in enumerate(faces):
							growmatrices.append(mesh_extras.get_selection_matrix([f]))
							newGroup = self.ob.vertex_groups.new(string['name']+'.'+selection['type']+'.'+misc.nr4(i))
							newGroups.append(newGroup)
							self.newGroups.append(newGroup)
							
							vertList = f.vertices
							
							for i,v in enumerate(verts):
								ind = v.index
								if ind in vertList:
									newGroup.add([v.index], weights[i], 'REPLACE')

								
		return newGroups, formmatrix, growmatrices
Exemplo n.º 4
0
	def addToNewGroups(self, string, newGroups, growmatrices=[]):
	
		selection = string['selection']
		self.doubleCheckSelection(selection)
	
		faces = mesh_extras.get_selected_faces()
		
		formmatrix = mathutils.Matrix()
		growmatrices = []
		
		if len(faces):
		
			verts = []
			inds = []
			for f in faces:
				for v in f.vertices:
					if not v in inds:
						inds.append(v)
						verts.append(self.me.vertices[v])

			# NOW WE GO MAKE THE GROUPS
			if len(verts):

				weights = self.makeWeights(verts)
				
				formmatrix = mesh_extras.get_selection_matrix(faces)
				
				# If we do this per area, we want the entire area to be part of one group
				if selection['area'] == 'area':
					growmatrices.append(formmatrix)
					newGroup = self.ob.vertex_groups.new(string['name']+'.'+selection['type'])
					newGroups.append(newGroup)
					self.newGroups.append(newGroup)
					
					for v in verts:
							newGroup.add([v.index], 1.0, 'REPLACE')
					
				# If we have it per face, we need sepparate weights and groups
				elif selection['area'] == 'faces':
				
					if len(faces):
					
						for i, f in enumerate(faces):
							growmatrices.append(mesh_extras.get_selection_matrix([f]))
							newGroup = self.ob.vertex_groups.new(string['name']+'.'+selection['type']+'.'+misc.nr4(i))
							newGroups.append(newGroup)
							self.newGroups.append(newGroup)
							
							vertList = f.vertices
							
							for i,v in enumerate(verts):
								ind = v.index
								if ind in vertList:
									newGroup.add([v.index], weights[i], 'REPLACE')

								
		return newGroups, formmatrix, growmatrices
Exemplo n.º 5
0
	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')
Exemplo n.º 6
0
	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')