def create_geometry(self, geometry, name=None, color=None): # Imported colors take priority over a the parameter color if 'mesh_color.diffuse' in geometry.attributes: color = geometry.attributes['mesh_color.diffuse'] # If we have a color, we'll discard alpha because draw_mesh is hard coded for a=1 if color: r, g, b, _a = color color = (r, g, b) else: color = (1., 1., 1.) if self.collection and self.collection not in bpy.data.collections.keys( ): compas_blender.utilities.create_collection(self.collection) v, f = geometry.to_vertices_and_faces() native_mesh = compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection) native_mesh.hide_set(True) return native_mesh
def draw(self, color: Optional[RGBColor] = None, u: Optional[int] = None, v: Optional[int] = None) -> List[bpy.types.Object]: """Draw the torus associated with the artist. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the torus. The default color is :attr:`compas.artists.ShapeArtist.color`. u : int, optional Number of faces in the "u" direction. Default is :attr:`TorusArtist.u`. v : int, optional Number of faces in the "v" direction. Default is :attr:`TorusArtist.v`. Returns ------- list The objects created in Blender. """ u = u or self.u v = v or self.v color = color or self.color vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v) obj = compas_blender.draw_mesh(vertices, faces, name=self.shape.name, color=color, collection=self.collection) return [obj]
def create_geometry( self, geometry: Union[Mesh, Shape], name: str = None, color: Union[RGBColor, Tuple[int, int, int, int], Tuple[float, float, float, float]] = None ) -> bpy.types.Object: # Imported colors take priority over a the parameter color if 'mesh_color.diffuse' in geometry.attributes: color = geometry.attributes['mesh_color.diffuse'] # If we have a color, we'll discard alpha because draw_mesh is hard coded for a=1 if color: color = color[:3] else: color = (1., 1., 1.) v, f = geometry.to_vertices_and_faces() native_mesh = compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection) native_mesh.hide_set(True) return native_mesh
def draw(self, color: Optional[RGBColor] = None, u: int = None, v: int = None) -> List[bpy.types.Object]: """Draw the sphere associated with the artist. Parameters ---------- color : tuple of float or tuple of int, optional The RGB color of the sphere. u : int, optional Number of faces in the "u" direction. Default is ``~SphereArtist.u``. v : int, optional Number of faces in the "v" direction. Default is ``~SphereArtist.v``. Returns ------- list The objects created in Blender. """ u = u or self.u v = v or self.v color = color or self.color vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v) obj = compas_blender.draw_mesh(vertices, faces, name=self.shape.name, color=color, collection=self.collection) return [obj]
def draw(self, color: Optional[RGBColor] = None, u: int = None) -> List[bpy.types.Object]: """Draw the cylinder associated with the artist. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the cylinder. u : int, optional Number of faces in the "u" direction. Default is :attr:`~CylinderArtist.u`. Returns ------- list[:blender:`bpy.types.Object`] The objects created in Blender. """ u = u or self.u color = color or self.color vertices, faces = self.shape.to_vertices_and_faces(u=u) obj = compas_blender.draw_mesh(vertices, faces, name=self.shape.name, color=color, collection=self.collection) return [obj]
def draw_mesh(self): """Draw the mesh.""" vertices, faces = self.mesh.to_vertices_and_faces() obj = compas_blender.draw_mesh(vertices, faces, name=self.mesh.name, collection=self.collection) return [obj]
def draw_blocks(self, nodes=None): """Draw the blocks of the assembly. """ nodes = nodes or list(self.assembly.nodes()) objects = [] for node in nodes: block = self.assembly.node_attribute(node, 'block') vertices, faces = block.to_vertices_and_faces() obj = compas_blender.draw_mesh(vertices, faces, name=block.name, collection=self.blockcollection) objects.append(obj) self.object_block = zip(objects, nodes) return objects
def draw_interfaces(self, edges=None): """Draw the interfaces between the blocks. """ edges = edges or list(self.assembly.edges()) objects = [] for edge in edges: name = f"Interface.{edge[0]}-{edge[1]}" interface = self.assembly.edge_attribute(edge, 'interface') vertices = interface.points faces = [list(range(len(vertices)))] obj = compas_blender.draw_mesh(vertices, faces, name=name, collection=self.interfacecollection) objects.append(obj) self.object_interface = zip(objects, edges) return objects
def draw_mesh(self) -> List[bpy.types.Object]: """Draw the mesh. Returns ------- list[:blender:`bpy.types.Object`] """ vertices, faces = self.mesh.to_vertices_and_faces() obj = compas_blender.draw_mesh(vertices, faces, name=self.mesh.name, collection=self.collection) return [obj]
def draw(self, color: Optional[RGBColor] = None) -> List[bpy.types.Object]: """Draw the box associated with the artist. Parameters ---------- color : tuple of float, optional The RGB color of the box. Returns ------- list The objects created in Blender. """ color = color or self.color vertices, faces = self.shape.to_vertices_and_faces() obj = compas_blender.draw_mesh(vertices, faces, name=self.shape.name, color=color, collection=self.collection) return [obj]
def draw(self, color: Optional[RGBColor] = None) -> List[bpy.types.Object]: """Draw the box associated with the artist. Parameters ---------- color : rgb-tuple, optional The RGB color of the box. The default color is :attr:`compas.artists.ShapeArtist.color`. Returns ------- list[:blender:`bpy.types.Object`] The object(s) created in Blender to represent the box. """ color = color or self.color vertices, faces = self.shape.to_vertices_and_faces() obj = compas_blender.draw_mesh(vertices, faces, name=self.shape.name, color=color, collection=self.collection) return [obj]
def draw_geometry(self, geometry, name=None, color=None): # Imported colors take priority over a the parameter color if 'mesh_color.diffuse' in geometry.attributes: color = geometry.attributes['mesh_color.diffuse'] # If we have a color, we'll discard alpha because draw_mesh is hard coded for a=1 if color: r, g, b, _a = color color = [r, g, b] else: color = [1., 1., 1.] if self.layer: collection = bpy.data.collections.new(self.layer) bpy.context.scene.collection.children.link(collection) v, f = geometry.to_vertices_and_faces() return draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, layer=self.layer)
def draw(self, color: Optional[RGBColor] = None) -> List[bpy.types.Object]: """Draw the polyhedron associated with the artist. Parameters ---------- color : tuple[float, float, float] or tuple[int, int, int], optional The RGB color of the polyhedron. The default color is :attr:`compas.artists.ShapeArtist.color`. Returns ------- list[:blender:`bpy.types.Object`] The objects created in Blender. """ color = color or self.color vertices, faces = self.shape.to_vertices_and_faces() obj = compas_blender.draw_mesh(vertices, faces, name=self.shape.name, color=color, collection=self.collection) return [obj]
def create_geometry(self, geometry: Mesh, name: str = None, color: Union[RGBColor, Tuple[int, int, int, int], Tuple[float, float, float, float]] = None ) -> bpy.types.Object: """Create the scene objecy representing the robot geometry. Parameters ---------- geometry : :class:`compas.datastructures.Mesh` The geometry representing the robot. name : str, optional A name for the scene object. color : tuple[int, int, int] or tuple[float, float, float], optional The color of the object. Returns ------- bpy.types.Object """ # Imported colors take priority over a the parameter color if 'mesh_color.diffuse' in geometry.attributes: color = geometry.attributes['mesh_color.diffuse'] # If we have a color, we'll discard alpha because draw_mesh is hard coded for a=1 if color: color = color[:3] else: color = (1., 1., 1.) v, f = geometry.to_vertices_and_faces() native_mesh = compas_blender.draw_mesh( vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection ) native_mesh.hide_set(True) return native_mesh
def draw_mesh(self, compas_mesh, color=None): v, f = compas_mesh.to_vertices_and_faces() return draw_mesh(v, f, color=color)