/
polyhedronobject.py
53 lines (40 loc) · 1.67 KB
/
polyhedronobject.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
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
import scriptcontext as sc # type: ignore
from compas.scene import GeometryObject
from compas.colors import Color
from compas_rhino.conversions import vertices_and_faces_to_rhino
from compas_rhino.conversions import transformation_to_rhino
from .sceneobject import RhinoSceneObject
from ._helpers import attributes
class PolyhedronObject(RhinoSceneObject, GeometryObject):
"""Scene object for drawing polyhedron shapes.
Parameters
----------
polyhedron : :class:`compas.geometry.Polyhedron`
A COMPAS polyhedron.
**kwargs : dict, optional
Additional keyword arguments.
"""
def __init__(self, polyhedron, **kwargs):
super(PolyhedronObject, self).__init__(geometry=polyhedron, **kwargs)
def draw(self, color=None):
"""Draw the polyhedron associated with the scene object.
Parameters
----------
color : rgb1 | rgb255 | :class:`compas.colors.Color`, optional
The RGB color of the polyhedron.
Returns
-------
list[System.Guid]
The GUIDs of the objects created in Rhino.
"""
color = Color.coerce(color) or self.color
attr = attributes(name=self.geometry.name, color=color, layer=self.layer)
vertices = [list(vertex) for vertex in self.geometry.vertices]
faces = self.geometry.faces
geometry = vertices_and_faces_to_rhino(vertices, faces)
geometry.Transform(transformation_to_rhino(self.worldtransformation))
self._guids = [sc.doc.Objects.AddMesh(geometry, attr)]
return self.guids