forked from gramaziokohler/workshop_swinburne_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path023_mesh_rhino.py
38 lines (30 loc) · 1.03 KB
/
023_mesh_rhino.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
import random
import compas
from compas.geometry import Cylinder
from compas.datastructures import Mesh
from compas.utilities import flatten
from compas_rhino.artists import MeshArtist
from compas_rhino.artists import CylinderArtist
mesh = Mesh.from_off(compas.get('tubemesh.off'))
start = random.choice(list(mesh.edges()))
loop = mesh.edge_loop(start)
strip = [mesh.edge_faces(*edge) for edge in mesh.edge_strip(start)]
strip[:] = list(set(flatten(strip)))
edgecolor = {}
for edge in loop:
edgecolor[edge] = (0, 255, 0)
edgecolor[start] = (255, 0, 0)
facecolor = {}
for face in strip:
facecolor[face] = (255, 200, 200)
artist = MeshArtist(mesh, layer='Tubemesh')
artist.clear_layer()
artist.draw_faces(color=facecolor)
# artist.draw_edges(color=edgecolor)
for edge in edgecolor:
o = mesh.edge_midpoint(*edge)
n = mesh.edge_direction(*edge)
h = mesh.edge_length(*edge)
cylinder = Cylinder([(o, n), 0.02], h)
artist = CylinderArtist(cylinder, color=(0, 255, 0), layer='Tubemesh')
artist.draw(show_vertices=False)