-
Notifications
You must be signed in to change notification settings - Fork 0
/
savePoly.py
95 lines (80 loc) · 2.61 KB
/
savePoly.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import openmesh as om
import numpy as np
from math import sin, cos, pi
import sys
def salvaPoligono(raioBase, raioTopo, nLados, altura, GC = [0,0,0], debug_vertices_insertion=False, debug_face_insertion=False):
angleSpacing = 2*pi/nLados
currRad = 0
mesh = om.TriMesh()
vHandle = []
#add all vertices to vHandle
for i in range(nLados):
vHandle.append(mesh.add_vertex(np.array([
GC[0] + (cos(currRad) * raioTopo),
GC[1] + altura/2,
GC[2] + (sin(currRad) * raioTopo)
])))
vHandle.append(mesh.add_vertex(np.array([
GC[0] + (cos(currRad) * raioBase),
GC[1] - altura/2,
GC[2] + (sin(currRad) * raioBase)
])))
currRad += angleSpacing
if debug_vertices_insertion:
for j in vHandle:
i = mesh.point(j)
print(f"({i[0]:.3f}, {i[1]:.3f}, {i[2]:.3f})")
print()
faceHandler = []
lenVHandle = len(vHandle)
#calculation geometric centre of base and top to construct base and top w/ triangular faces
CG_topo = mesh.add_vertex(np.array([
GC[0] + 0,
GC[1] + altura/2,
GC[2] + 0
]))
CG_base = mesh.add_vertex(np.array([
GC[0] + 0,
GC[1] - altura/2,
GC[2] + 0
]))
#create lateral faces
for i in range(0, lenVHandle, 2):
if debug_face_insertion:
print(f"Adding face with vertices:")
po = mesh.point(vHandle[(i)%lenVHandle])
print(f"({po[0]:.3f}, {po[1]:.3f}, {po[2]:.3f})")
po = mesh.point(vHandle[(i+2)%lenVHandle])
print(f"({po[0]:.3f}, {po[1]:.3f}, {po[2]:.3f})")
po = mesh.point(vHandle[(i+1)%lenVHandle])
print(f"({po[0]:.3f}, {po[1]:.3f}, {po[2]:.3f})")
print()
face_vhandles = []
face_vhandles.append(vHandle[(i)%lenVHandle])
face_vhandles.append(vHandle[(i+2)%lenVHandle])
face_vhandles.append(vHandle[(i+1)%lenVHandle])
mesh.add_face(face_vhandles)
if debug_face_insertion:
print(f"Adding face with vertices:")
po = mesh.point(vHandle[(i+1)%lenVHandle])
print(f"({po[0]:.3f}, {po[1]:.3f}, {po[2]:.3f})")
po = mesh.point(vHandle[(i+2)%lenVHandle])
print(f"({po[0]:.3f}, {po[1]:.3f}, {po[2]:.3f})")
po = mesh.point(vHandle[(i+3)%lenVHandle])
print(f"({po[0]:.3f}, {po[1]:.3f}, {po[2]:.3f})")
print()
face_vhandles = []
face_vhandles.append(vHandle[(i+1)%lenVHandle])
face_vhandles.append(vHandle[(i+2)%lenVHandle])
face_vhandles.append(vHandle[(i+3)%lenVHandle])
mesh.add_face(face_vhandles)
#create base and top faces
face_vhandles = [CG_topo]
face_vhandles.append(vHandle[(i+2)%lenVHandle])
face_vhandles.append(vHandle[i])
mesh.add_face(face_vhandles)
face_vhandles = [CG_base]
face_vhandles.append(vHandle[i+1])
face_vhandles.append(vHandle[(i+3)%lenVHandle])
mesh.add_face(face_vhandles)
return mesh