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
Beispiel #2
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
	def executeDNA(self, string, baseGroups, baseWeight):
		
		'''
		if string['number'] >= 1:
			#if string['number'] in [0,1,3]:
			return
		
		elif string['number'] == 5 or string['number'] == 6:
			return	
		'''
		# Redraw hack to see what is happening
		# bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
		
		newGroups, formmatrix, growmatrices = self.makeAffectedGroups(string, baseGroups)
		groupLen = len(newGroups)\
		
		pad = str(' ').rjust(string['level'], ' ')
		
		idText = 'limb '+misc.nr4(string['number'])+' '+string['name'].ljust(10, ' ')
		print(pad,idText)
		
		# only if we made a group with something in it do we continue
		if not groupLen:
			print('  - No group!')
		else:
				
			# Loop through all the groups
			for i, group in enumerate(newGroups):
			
				# The step number to print out
				stepText = misc.nr4(i+1)+' of '+misc.nr4(groupLen)
			
				# We need a check matrix only if we're not on the head or body
				if string['name'] == 'head' or string['name'] == 'body' or True:
					try:
						del(self.ob['formmatrix'])
					except:
						pass
				# If not... then just try to get rid of it
				else:
					self.ob['formmatrix'] = formmatrix
			
				# Body gets a set matrix (so it grows nice and straight)
				if string['name'] == 'head':
					growmatrix = mathutils.Matrix(((1.0,0.0,0.0),(0.0,0.0,1.0),(0.0,-1.0,0.0))).transposed()
					
				# Head gets a set matrix (so it grows nice and straight)
				elif string['name'] == 'body':
					growmatrix = mathutils.Matrix(((-1.0,0.0,0.0),(0.0,0.0,1.0),(0.0,1.0,0.0))).transposed()
					
				# In all other cases the matrix can be dealt with by the grow addon
				else:
					growmatrix = growmatrices[i]
					
				self.ob['growmatrix'] = growmatrix
			
				# Select a group
				select_faces.none()
				select_faces.in_group(group)
				
				# No need to continue if we have no selected faces
				if not mesh_extras.contains_selected_item(self.me.faces):
					print(pad,'skip ',stepText,'no selection',string['action']['name'])
					
				else:
					
					a = string['action']
					
					if a['type'] == 'grow':
							
						# Check for mirroring
						right = mathutils.Vector((1.0,0.0,0.0))
						check = mathutils.Vector(growmatrix[2])
						
						# If we're aiming left we "invert" the rotation
						if right.dot(check) < 0.0:
							rot = mathutils.Vector((-a['rotation'][0],a['rotation'][1],-a['rotation'][2]))
						else:
							rot = a['rotation']
					
						# Add relative intensity here (half the original + half the weight)
						weight = baseWeight * self.getWeight(groupLen, a['scalin'])
						
						trans = a['translation']
						#trans = self.applyIntensity(a['translation'], weight, 'float')
						#rot = self.applyIntensity(rot, weight, 'inc')
					
					if a['type'] == 'grow' and trans == 0.0:
					
						print(pad,'skip ',stepText,'too short',trans,'from',a['translation'])
					
					else:
					
						print(pad,'step ',stepText,a['name'])
						#print(self.applyIntensity(a['push'], weight, 'float'))
						
						bpy.ops.object.mode_set(mode='EDIT')
						
						if a['type'] == 'bump':
						
							bpy.ops.mesh.bump(
								type=a['bumptype'],
								scale=a['bumpscale'],
								steps=True,
								)
								
						else:
						
							bpy.ops.mesh.grow(
								translation=trans,
								rotation=rot,
								rotation_falloff=a['rotation_falloff'],
								scale=a['scale'],
								scale_falloff=a['scale_falloff'],
								retain=True,
								steps=True,
								debug=False,
								)
							
						bpy.ops.object.mode_set(mode='OBJECT')
							
						
						select_faces.none()
						select_faces.in_group(group)
						
						self.applyGrowthColor(a)
						if a['type'] == 'grow':
							self.applyGrowthCrease(a)
						
						# Remove new stuff from all but the current group
						self.cleanGroup(group)
						
						# Keep track of how much steps we've taken
						self.dnaStep += 1
						
						# If there's a sub
						if len(string['strings']):
							for s in string['strings']:
								#print('going sub', string['name'], s['name'])
								self.executeDNA(s, [group], weight)
Beispiel #4
0
	def executeDNA(self, string, baseGroups, baseWeight, subCount):
		
		''''
		if string['number'] >= 1:
			#if string['number'] in [0,1,3]:
			return
	
		elif string['number'] == 5 or string['number'] == 6:
			return	
		'''
		# Redraw hack
		#bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
		
		newGroups, formmatrix, growmatrices = self.makeAffectedGroups(string, baseGroups, subCount)
		groupLen = len(newGroups)
		
		pad = str(' ').rjust(string['level'], ' ')
		
		idText = 'limb '+misc.nr4(string['number'])+' '+string['name'].ljust(10, ' ')
		print(pad,idText)
		
		# only if we made a group with something in it do we continue
		if not groupLen:
			print('  - No group!')
		else:
	
			# Loop through all the groups
			for i, group in enumerate(newGroups):
			
				# The step number to print out
				stepText = misc.nr4(i+1)+' of '+misc.nr4(groupLen)
			
				# We need a check matrix only if we're not on the trunk or body
				if string['name'] == 'trunk' or string['name'] == 'body' or True:
					try:
						del(self.ob['formmatrix'])
					except:
						pass
				# If not... then just try to get rid of it
				else:
					self.ob['formmatrix'] = formmatrix
			
				# Body gets a set matrix (so it grows nice and straight)
				if string['name'] == 'trunk':
					growmatrix = mathutils.Matrix(((1.0,0.0,0.0),(0.0,-1.0,0.0),(0.0,0.0,1.0))).transposed()
					
				# In all other cases the matrix can be dealt with by the grow addon
				else:
					growmatrix = growmatrices[i]
					
				self.ob['growmatrix'] = growmatrix
			
				# Select a group
				select_faces.none()
				select_faces.in_group(group)
				
				# No need to continue if we have no selected faces
				if not mesh_extras.contains_selected_item(self.me.faces):
					print(pad,'skip ',stepText,'no selection',string['action']['name'])
					
				else:
					
					a = string['action']
					
					if a['type'] == 'grow':
							
						# Check for mirroring
						right = mathutils.Vector((1.0,0.0,0.0))
						check = mathutils.Vector(growmatrix[2])
						
						# If we're aiming left we "invert" the rotation
						if right.dot(check) < 0.0:
							rot = mathutils.Vector((-a['rotation'][0],a['rotation'][1],-a['rotation'][2]))
						else:
							rot = a['rotation']
					
						# Add relative intensity here (half the original + half the weight)
						weight = baseWeight * self.getWeight(groupLen, a['scalin'])
						
						trans = a['translation']
					
					if a['type'] == 'grow' and trans == 0.0:
					
						print(pad,'skip ',stepText,'too short',trans,'from',a['translation'])
					
					else:
					
						print(pad,'step ',stepText,a['name'])
						
						bpy.ops.object.mode_set(mode='EDIT')
						
						if a['type'] == 'bump':
						
							bpy.ops.mesh.bump(
								type=a['bumptype'],
								scale=a['bumpscale'],
								steps=True,
								)
								
						else:
						
							bpy.ops.mesh.grow(
								translation=trans,
								rotation=rot,
								rotation_falloff=a['rotation_falloff'],
								scale=a['scale'],
								scale_falloff=a['scale_falloff'],
								retain=True,
								steps=True,
								debug=False,
								)
							
						bpy.ops.object.mode_set(mode='OBJECT')
							
						
						select_faces.none()
						select_faces.in_group(group)
						
						self.applyGrowthColor(a)
						if a['type'] == 'grow':
							self.applyGrowthCrease(a)
						
						# Remove new stuff from all but the current group
						self.cleanGroup(group)
						
						# Keep track of how much steps we've taken
						self.dnaStep += 1
						
						# If there's a sub
						if len(string['strings']):
							for sc, s in enumerate(string['strings']):
								#print('going sub', string['name'], s['name'])
								self.executeDNA(s, [group], weight, sc)
Beispiel #5
0
	def executeDNA(self, string, baseGroups, baseWeight):
		
		pad = str(' ').rjust(string['level'], ' ')
		
		# Stop if the limit is reached! (mostly for debugging)
		if self.steplimit and string['number'] >= self.steplimit:
			print(pad,' # Reached steplimit',self.steplimit,'>> RETURNING')
			return
		'''		
		if string['number'] == 5 or string['number'] == 6:
			return	
		'''
		#print(pad,'1 makegroups')
		newGroups, formmatrix, growmatrices = self.makeAffectedGroups(string, baseGroups)
		groupLen = len(newGroups)
		
		# Temporary halt!
		#return
		
		#if string['number'] == (self.steplimit-1):
		#	print(pad,' # Reached steplimit',self.steplimit,'>> RETURNING')
		#	return
		
		idText = 'limb '+misc.nr4(string['number'])+' '+string['name'].ljust(10, ' ')
		#print(pad,idText)
		
		# only if we made a group with something in it do we continue
		if not groupLen:
			print(pad,' ### No group!')
		else:
				
			# Loop through all the groups
			for i, group in enumerate(newGroups):
					
				# The step number to print out
				stepText = misc.nr4(i+1)+' of '+misc.nr4(groupLen)
			
				# We need a check matrix only if we're not on the head or body
				if string['name'] == 'head' or string['name'] == 'body' or True:
					try:
						del(self.ob['formmatrix'])
					except:
						pass
				# If not... then just try to get rid of it
				else:
					self.ob['formmatrix'] = formmatrix
			
				# Body gets a set matrix (so it grows nice and straight)
				if string['name'] == 'head':
					growmatrix = mathutils.Matrix(((1.0,0.0,0.0),(0.0,0.0,1.0),(0.0,-1.0,0.0))).transposed()
					
				# Head gets a set matrix (so it grows nice and straight)
				elif string['name'] == 'body':
					growmatrix = mathutils.Matrix(((-1.0,0.0,0.0),(0.0,0.0,1.0),(0.0,1.0,0.0))).transposed()
					
				# In all other cases the matrix can be dealt with by the grow addon
				else:
					growmatrix = growmatrices[i]
					
				self.ob['growmatrix'] = growmatrix
			
				# Select a group
				#print(pad,'2 select groups')
				select_bmesh_faces.go(mode='GROUPED', group=group.index)
				
				#print('sel-',len(mesh_extras.get_selected_polygons()),group.name)
				

				
				mesh_extras.smooth_selection()

				# No need to continue if we have no selected polygons
				if not mesh_extras.contains_selected_item(self.me.polygons):
					print(pad,'skip ',stepText,'no selection',string['action']['name'])
					
				else:
					
					action = string['action']
						
					if action['type'] == 'grow':
							
						# Check for mirroring
						right = mathutils.Vector((1.0,0.0,0.0))
						check = mathutils.Vector(growmatrix[2])
						
						# If we're aiming left we "invert" the rotation
						if right.dot(check) < 0.0:
							rot = mathutils.Vector((-action['rotation'][0],action['rotation'][1],-action['rotation'][2]))
						else:
							rot = action['rotation']
					
						# Add relative intensity here (half the original + half the weight)
						weight = baseWeight * self.getWeight(groupLen, action['scalin'])
					
					print(pad,'step ',stepText,action['name'], string['number'])

						
					# Cast the selection to the correct shape please
					bmesh_extras.cast_loop(corners=action['loop_corners'], falloff_scale=action['loop_scale'], falloff_shape=action['loop_shape'],corner_group='corner')
					
					bpy.ops.object.mode_set(mode='EDIT')
					
					
					if action['type'] == 'bump':
					
						bpy.ops.mesh.bump(
							type=action['bumptype'],
							scale=action['bumpscale'],
							steps=True,
							)
							
					else:
					
						bpy.ops.mesh.grow(
							translation=action['translation'],
							rotation=rot,
							rotation_falloff=action['rotation_falloff'],
							scale=action['scale'],
							scale_falloff=action['scale_falloff'],
							retain=True,
							steps=True,
							debug=False,
							)
					
					bpy.ops.object.mode_set(mode='OBJECT')
					
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					
					bmesh_extras.color_limb(col=action['vertexcolor'], jon=action['jointcolor'], hard=action['colorstyle'])
					
					# RESELECT GROUPED...
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					
					bmesh_extras.crease_edges(sharpness=action['crease'], group='corner')						
					
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					
					# Remove new stuff from all but the current group
					self.cleanGroup(group)
					
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					# Keep track of how much steps we've taken
					self.dnaStep += 1
					
					# Redraw hack to see what is happening
					#bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
					
					# If there's a sub string and we're allowed deeper... lets do that
					if len(string['strings']):
						for s in string['strings']:
							if s['number'] < self.steplimit or not self.steplimit:
								#print('going sub', string['name'], s['name'])
								self.executeDNA(s, [group], weight)
Beispiel #6
0
	def executeDNA(self, string, baseGroups, baseWeight):
		
		pad = str(' ').rjust(string['level'], ' ')
		
		# Stop if the limit is reached! (mostly for debugging)
		if self.steplimit and string['number'] >= self.steplimit:
			print(pad,' # Reached steplimit',self.steplimit,'>> RETURNING')
			return
		'''		
		if string['number'] == 5 or string['number'] == 6:
			return	
		'''
		#print(pad,'1 makegroups')
		newGroups, formmatrix, growmatrices = self.makeAffectedGroups(string, baseGroups)
		groupLen = len(newGroups)
		
		# Temporary halt!
		#return
		
		#if string['number'] == (self.steplimit-1):
		#	print(pad,' # Reached steplimit',self.steplimit,'>> RETURNING')
		#	return
		
		idText = 'limb '+misc.nr4(string['number'])+' '+string['name'].ljust(10, ' ')
		#print(pad,idText)
		
		# only if we made a group with something in it do we continue
		if not groupLen:
			print(pad,' ### No group!')
		else:
				
			# Loop through all the groups
			for i, group in enumerate(newGroups):
					
				# The step number to print out
				stepText = misc.nr4(i+1)+' of '+misc.nr4(groupLen)
			
				# We need a check matrix only if we're not on the head or body
				if string['name'] == 'head' or string['name'] == 'body' or True:
					try:
						del(self.ob['formmatrix'])
					except:
						pass
				# If not... then just try to get rid of it
				else:
					self.ob['formmatrix'] = formmatrix
			
				# Body gets a set matrix (so it grows nice and straight)
				if string['name'] == 'head':
					growmatrix = mathutils.Matrix(((1.0,0.0,0.0),(0.0,0.0,1.0),(0.0,-1.0,0.0))).transposed()
					
				# Head gets a set matrix (so it grows nice and straight)
				elif string['name'] == 'body':
					growmatrix = mathutils.Matrix(((-1.0,0.0,0.0),(0.0,0.0,1.0),(0.0,1.0,0.0))).transposed()
					
				# In all other cases the matrix can be dealt with by the grow addon
				else:
					growmatrix = growmatrices[i]
					
				self.ob['growmatrix'] = growmatrix
			
				# Select a group
				#print(pad,'2 select groups')
				select_bmesh_faces.go(mode='GROUPED', group=group.index)
				
				#print('sel-',len(mesh_extras.get_selected_polygons()),group.name)
				

				
				mesh_extras.smooth_selection()

				# No need to continue if we have no selected polygons
				if not mesh_extras.contains_selected_item(self.me.polygons):
					print(pad,'skip ',stepText,'no selection',string['action']['name'])
					
				else:
					
					action = string['action']
						
					if action['type'] == 'grow':
							
						# Check for mirroring
						right = mathutils.Vector((1.0,0.0,0.0))
						check = mathutils.Vector(growmatrix[2])
						
						# If we're aiming left we "invert" the rotation
						if right.dot(check) < 0.0:
							rot = mathutils.Vector((-action['rotation'][0],action['rotation'][1],-action['rotation'][2]))
						else:
							rot = action['rotation']
					
						# Add relative intensity here (half the original + half the weight)
						weight = baseWeight * self.getWeight(groupLen, action['scalin'])
					
					print(pad,'step ',stepText,action['name'], string['number'])

						
					# Cast the selection to the correct shape please
					bmesh_extras.cast_loop(corners=action['loop_corners'], falloff_scale=action['loop_scale'], falloff_shape=action['loop_shape'],corner_group='corner')
					
					bpy.ops.object.mode_set(mode='EDIT')
					
					
					if action['type'] == 'bump':
					
						bpy.ops.mesh.bump(
							type=action['bumptype'],
							scale=action['bumpscale'],
							steps=True,
							)
							
					else:
					
						bpy.ops.mesh.grow(
							translation=action['translation'],
							rotation=rot,
							rotation_falloff=action['rotation_falloff'],
							scale=action['scale'],
							scale_falloff=action['scale_falloff'],
							retain=True,
							steps=True,
							debug=False,
							)
					
					bpy.ops.object.mode_set(mode='OBJECT')
					
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					
					bmesh_extras.color_limb(col=action['vertexcolor'], jon=action['jointcolor'], hard=action['colorstyle'])
					
					# RESELECT GROUPED...
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					
					bmesh_extras.crease_edges(sharpness=action['crease'], group='corner')						
					
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					
					# Remove new stuff from all but the current group
					self.cleanGroup(group)
					
					select_bmesh_faces.go(mode='GROUPED', group=group.index)
					# Keep track of how much steps we've taken
					self.dnaStep += 1
					
					# Redraw hack to see what is happening
					#bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
					
					# If there's a sub string and we're allowed deeper... lets do that
					if len(string['strings']):
						for s in string['strings']:
							if s['number'] < self.steplimit or not self.steplimit:
								#print('going sub', string['name'], s['name'])
								self.executeDNA(s, [group], weight)