def draw_edges(self, width=0.05, keys=None, colors=None): self.clear_edges() self.clear_edgelabels() keys = keys or list(self.datastructure.edges()) lines = [0] * len(keys) if colors is None: colors = {key: self.defaults['color.line'] for key in keys} for index, (u, v) in enumerate(keys): lines[index] = { 'start': self.datastructure.vertex_coordinates(u), 'end': self.datastructure.vertex_coordinates(v), 'layer': self.layer, 'color': colors[(u, v)], 'width': width, 'name': '{}.edge.{}-{}'.format(self.datastructure, u, v) } objects = draw_lines(lines) layer_collection = create_collection(self.layer) edge_collection_name = "{}.edges".format(self.datastructure.name) edge_collection = create_collection(edge_collection_name, parent=layer_collection) for obj in objects: for collection in obj.users_collection: collection.objects.unlink(obj) edge_collection.objects.link(obj) self.edge_objects = objects self.edge_collection = edge_collection
def draw_faces(self, keys=None, colors=None): self.clear_faces() self.clear_facelabels() keys = keys or list(self.datastructure.faces()) faces = [0] * len(keys) if colors is None: colors = {key: self.defaults['color.face'] for key in keys} for index, key in enumerate(keys): faces[index] = { "points": self.datastructure.face_coordinates(key), "name": "{}.face.{}".format(self.datastructure.name, key), "color": colors[key], "layer": self.layer } objects = draw_faces(faces) layer_collection = create_collection(self.layer) face_collection_name = "{}.faces".format(self.datastructure.name) face_collection = create_collection(face_collection_name, parent=layer_collection) for obj in objects: for collection in obj.users_collection: collection.objects.unlink(obj) face_collection.objects.link(obj) self.face_objects = objects self.face_collection = face_collection
def _link_object(obj, collection=None, layer=None): if not collection: collection = bpy.context.collection if not isinstance(collection, bpy.types.Collection): collection = create_collection(collection) # if not layer: # layer = bpy.context.view_layer # layer_collection = layer.active_layer_collection.collection for c in obj.users_collection: c.objects.unlink(obj) collection.objects.link(obj)
def draw_vertices(self, keys=None, radius=0.05): self.clear_vertices() self.clear_vertexlabels() keys = keys or list(self.datastructure.vertices()) points = [0] * len(keys) for index, key in enumerate(keys): points[index] = { 'pos': self.datastructure.vertex_coordinates(key), 'radius': radius, 'name': '{}.vertex.{}'.format(self.datastructure.name, key) } objects = draw_spheres(points) layer_collection = create_collection(self.layer) vertex_collection_name = "{}.vertices".format(self.datastructure.name) vertex_collection = create_collection(vertex_collection_name, parent=layer_collection) for obj in objects: for collection in obj.users_collection: collection.objects.unlink(obj) vertex_collection.objects.link(obj) self.vertex_objects = objects self.vertex_collection = vertex_collection