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 execute(self, context):
	
		paths = [os.path.join(self.directory, name.name)
				 for name in self.files]

		if not paths:
			paths.append(self.filepath)

		if bpy.ops.object.mode_set.poll():
			bpy.ops.object.mode_set(mode='OBJECT')

		if bpy.ops.object.select_all.poll():
			bpy.ops.object.select_all(action='DESELECT')

		for path in paths:
			objName = bpy.path.display_name(os.path.basename(path))
			print("FOUND FILE",objName)
			
			with open(path,'r') as f:
			
				slice = False
				bm = False
				me = False
				ob = False
				preI =False
				x = 0.0
				y = 0.0
				z = 0.0
				e = 0.0
				aPrev = False
				t = False
				
				
				for li, line in enumerate(f.readlines()):
				
					# Keep track of what slice we're on
					if line.startswith('; Slice'):
						
						slice = line.replace('; Slice ', '')
						slice = int(slice)
					
					# Only slices are added! The stuff before we don't need
					if not slice is False:
					
						if line.startswith('G1 '):
						
							# Create a fresh new bmesh and an object for it to go into
							# We need the object here so we can make vertex groups later on (in bmesh_extras)
							if bm is False:
								bm = bmesh.new()
								me = bpy.data.meshes.new(objName)
								ob = bpy.data.objects.new(objName, me)
								scn =bpy.context.scene
								scn.objects.link(ob)
								ob.select = True
								scn.objects.active = ob
								
								try:
									ex = bm.verts.layers.float['extrusions']
								except KeyError:
									ex = bm.verts.layers.float.new('extrusions')
								
								# Don't forget that the string type needs encoded bytes!!! Shees...
								try:
									et = bm.edges.layers.string['types']
								except KeyError:
									et = bm.edges.layers.string.new('types')

							# Lets get coordinates
							words = line.split(' ')
							t = None
							for word in words:
								if len(word) > 1:
									if word.startswith('X'):
										x = gVal(word)		
									elif word.startswith('Y'):
										y = gVal(word)
									elif word.startswith('Z'):
										z = gVal(word)
										
									elif word.endswith('\n'):
										t = word.replace('\n','')
										if t == 'move':
											t = 'Travel move'
										elif t == 'position':
											t = 'Move to start position'
										elif t == 'print':
											t = 'End of print'
										
									elif word.startswith('A'):
										aCur = gVal(word.replace(';',''))
										if aPrev:
											e = aCur - aPrev
										else:
											e = 0.0
										aPrev = aCur
											

									
							#	Only add a point for actual defined positions
							if t:
								
								# Add a vert at the correct coords
								curV = bm.verts.new((x,y,z))
								curV[ex] = e
								curI = len(bm.verts)-1
								
								# Add the vert to the correct vertex group
								bm, group_index = bmesh_extras.add_to_group(bme=bm, verts = [curV], newGroup=False, groupName=t)
								
								# Add an edge if we can!
								if not preI is False:
									curE = bm.edges.new([bm.verts[curI], bm.verts[preI]])
									curE[et] = t.encode('utf-8')
									
								# Set the previous vert index to the current index
								preI = curI
							
					# Do not go beyond the end of the print
					if t == 'End of print':
						break
						
							
			if not bm is False:
				bm.to_mesh(me)
				bm.free()
				

		return {'FINISHED'}
Exemplo n.º 4
0
    def execute(self, context):

        paths = [
            os.path.join(self.directory, name.name) for name in self.files
        ]

        if not paths:
            paths.append(self.filepath)

        if bpy.ops.object.mode_set.poll():
            bpy.ops.object.mode_set(mode='OBJECT')

        if bpy.ops.object.select_all.poll():
            bpy.ops.object.select_all(action='DESELECT')

        for path in paths:
            objName = bpy.path.display_name(os.path.basename(path))
            print("FOUND FILE", objName)

            with open(path, 'r') as f:

                slice = False
                bm = False
                me = False
                ob = False
                preI = False
                x = 0.0
                y = 0.0
                z = 0.0
                e = 0.0
                aPrev = False
                t = False

                for li, line in enumerate(f.readlines()):

                    # Keep track of what slice we're on
                    if line.startswith('; Slice'):

                        slice = line.replace('; Slice ', '')
                        slice = int(slice)

                    # Only slices are added! The stuff before we don't need
                    if not slice is False:

                        if line.startswith('G1 '):

                            # Create a fresh new bmesh and an object for it to go into
                            # We need the object here so we can make vertex groups later on (in bmesh_extras)
                            if bm is False:
                                bm = bmesh.new()
                                me = bpy.data.meshes.new(objName)
                                ob = bpy.data.objects.new(objName, me)
                                scn = bpy.context.scene
                                scn.objects.link(ob)
                                ob.select = True
                                scn.objects.active = ob

                                try:
                                    ex = bm.verts.layers.float['extrusions']
                                except KeyError:
                                    ex = bm.verts.layers.float.new(
                                        'extrusions')

                                # Don't forget that the string type needs encoded bytes!!! Shees...
                                try:
                                    et = bm.edges.layers.string['types']
                                except KeyError:
                                    et = bm.edges.layers.string.new('types')

                            # Lets get coordinates
                            words = line.split(' ')
                            t = None
                            for word in words:
                                if len(word) > 1:
                                    if word.startswith('X'):
                                        x = gVal(word)
                                    elif word.startswith('Y'):
                                        y = gVal(word)
                                    elif word.startswith('Z'):
                                        z = gVal(word)

                                    elif word.endswith('\n'):
                                        t = word.replace('\n', '')
                                        if t == 'move':
                                            t = 'Travel move'
                                        elif t == 'position':
                                            t = 'Move to start position'
                                        elif t == 'print':
                                            t = 'End of print'

                                    elif word.startswith('A'):
                                        aCur = gVal(word.replace(';', ''))
                                        if aPrev:
                                            e = aCur - aPrev
                                        else:
                                            e = 0.0
                                        aPrev = aCur

                            #	Only add a point for actual defined positions
                            if t:

                                # Add a vert at the correct coords
                                curV = bm.verts.new((x, y, z))
                                curV[ex] = e
                                curI = len(bm.verts) - 1

                                # Add the vert to the correct vertex group
                                bm, group_index = bmesh_extras.add_to_group(
                                    bme=bm,
                                    verts=[curV],
                                    newGroup=False,
                                    groupName=t)

                                # Add an edge if we can!
                                if not preI is False:
                                    curE = bm.edges.new(
                                        [bm.verts[curI], bm.verts[preI]])
                                    curE[et] = t.encode('utf-8')

                                # Set the previous vert index to the current index
                                preI = curI

                    # Do not go beyond the end of the print
                    if t == 'End of print':
                        break

            if not bm is False:
                bm.to_mesh(me)
                bm.free()

        return {'FINISHED'}