-
Notifications
You must be signed in to change notification settings - Fork 103
/
polygonobject.py
57 lines (43 loc) · 1.63 KB
/
polygonobject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from typing import Any
from typing import Optional
import bpy # type: ignore
from compas.colors import Color
from compas.geometry import Polygon
from compas.scene import GeometryObject
from compas_blender import conversions
from .sceneobject import BlenderSceneObject
class PolygonObject(BlenderSceneObject, GeometryObject):
"""Scene object for drawing polygons in Blender.
Parameters
----------
polygon : :class:`compas.geometry.Polygon`
A COMPAS polygon.
**kwargs : dict, optional
Additional keyword arguments.
"""
def __init__(self, polygon: Polygon, **kwargs: Any):
super().__init__(geometry=polygon, **kwargs)
def draw(
self,
color: Optional[Color] = None,
collection: Optional[str] = None,
) -> list[bpy.types.Object]:
"""Draw the polygon.
Parameters
----------
color : tuple[float, float, float] | tuple[int, int, int] | :class:`compas.colors.Color`, optional
The RGB color of the polygon.
collection : str, optional
The name of the Blender scene collection containing the created object(s).
Returns
-------
list[:blender:`bpy.types.Object`]
"""
name = self.geometry.name
color = Color.coerce(color) or self.color
vertices, faces = self.geometry.to_vertices_and_faces()
mesh = conversions.vertices_and_faces_to_blender_mesh(vertices, faces, name=self.geometry.name)
obj = self.create_object(mesh, name=name)
self.update_object(obj, color=color, collection=collection)
self._guids = [obj]
return self.guids