Import Export Vertex Groups rewritten
[blender-addons-contrib.git] / geodesic_domes / forms_271.py
1 import math
2 #PKHG>TOOMUCH?? from math import pi, sin, cos, atan, tan, fabs
3 from math import sin, cos
4 from geodesic_domes.vefm_271 import *
5 class form(mesh):
6     def __init__(self, uresolution, vresolution, uscale, vscale, upart,\
7                  vpart, uphase, vphase, utwist, vtwist, xscale, yscale, sform):
8         mesh.__init__(self)
9         #PKHG already in vefm271 mesh: self.a360 = pi * 2.0
10         self.PKHG_parameters = [uresolution, vresolution, uscale, vscale, upart,
11                                 vpart, uphase, vphase, utwist, vtwist, xscale, yscale, sform]
12         self.ures = uresolution
13         self.vres = vresolution
14         
15         self.uscale = uscale
16         self.vscale = vscale
17         self.upart = upart
18         self.vpart = vpart
19         self.uphase = uphase * self.a360
20         self.vphase = vphase * self.a360
21         self.utwist = utwist
22         self.vtwist = vtwist
23         
24         self.xscale = xscale
25         self.yscale = yscale
26         self.sform = sform
27                 
28         if self.upart != 1.0:    ## there is a gap in the major radius
29             self.uflag = 1
30         else:
31             self.uflag = 0
32         if self.vpart != 1.0:    ## there is a gap in the minor radius
33             self.vflag = 1
34         else:
35             self.vflag = 0
36         if self.uflag:
37             self.ufinish = self.ures + 1
38         else:
39             self.ufinish = self.ures
40         if self.vflag:
41             self.vfinish = self.vres + 1
42         else:
43             self.vfinish = self.vres
44         self.ustep = (self.a360 / self.ures) * self.upart
45         self.vstep = (self.a360 / self.vres) * self.vpart
46         if self.xscale != 1.0:
47             self.xscaleflag = 1
48         else:            
49             self.xscaleflag = 0        
50         if self.yscale != 1.0:            
51             self.yscaleflag = 1            
52         else:            
53             self.yscaleflag = 0                            
54         self.rowlist=[]
55
56     def generatepoints(self):
57         for i in range(self.ufinish):
58             row=[]
59             for j in range(self.vfinish):
60                 u = self.ustep * i + self.uphase
61                 v = self.vstep * j + self.vphase
62             #    if self.xscaleflag:
63             #        u = self.ellipsecomp(self.xscale, u) 
64             #    if self.yscaleflag:
65             #        v = self.ellipsecomp(self.yscale, v)            
66                 if self.sform[12]:
67                     r1 = self.superform(self.sform[0], self.sform[1], self.sform[2],\
68                                         self.sform[3], self.sform[14] + u, self.sform[4],\
69                     self.sform[5], self.sform[16] * v)
70                 else:
71                     r1 = 1.0
72                 if self.sform[13]:
73                     r2 = self.superform(self.sform[6], self.sform[7], self.sform[8],\
74                                         self.sform[9], self.sform[15] + v, self.sform[10],\
75                     self.sform[11], self.sform[17] * v)
76                 else:
77                     r2 = 1.0
78                 x, y, z = self.formula(u, v, r1, r2)
79                 point = vertex((x, y, z))
80                 row.append(point)
81                 self.verts.append(point)
82             self.rowlist.append(row)
83         if self.vflag:
84             pass
85         else:
86             for i in range(len(self.rowlist)):
87                 self.rowlist[i].append(self.rowlist[i][0])
88         if  self.uflag:
89             pass
90         else:
91             self.rowlist.append(self.rowlist[0])
92
93 #    def formula(self, u, v, r1, r2):
94 #        pass
95
96     def generatefaces(self):
97         ufin = len(self.rowlist) - 1
98         vfin = len(self.rowlist[0]) - 1
99         for i in range(ufin):
100             for j in range(vfin):
101                 top = i
102                 bottom = i + 1
103                 left = j
104                 right = j + 1
105                 a = self.rowlist[top][left]
106                 b = self.rowlist[top][right]
107                 c = self.rowlist[bottom][right]
108                 d = self.rowlist[bottom][left]
109                 face1 = face([a, b, c, d])
110                 self.faces.append(face1)
111                 edge1 = edge(a, b)
112                 edge2 = edge(a, d)
113                 self.edges.append(edge1)
114                 self.edges.append(edge2)
115                 if i + 1 == ufin:
116                     edge3 = edge(d, c)
117                     self.edges.append(edge3)
118                 if j + 1 == vfin:
119                     edge4 = edge(b, c)
120                     self.edges.append(edge4)
121     
122 class grid(form):
123     def __init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
124                  uphase, vphase, utwist, vtwist, xscale, yscale, sform):
125         form.__init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
126                         uphase, vphase, utwist, vtwist, xscale, yscale, sform)
127         unit = 1.0 / self.a360
128         if self.ures == 1 :            
129             print("\n***ERRORin forms_271.grid L121***, ures is  1, changed into 2\n\n")
130             self.ures = 2
131         if self.vres == 1 :            
132             print("\n***ERROR in grid forms_271.grid L124***, vres is 1, changed into 2\n\n")
133             self.vres = 2            
134         self.ustep = self.a360 / (self.ures - 1)
135         self.vstep = self.a360 / (self.vres - 1)
136         
137         self.uflag = 1
138         self.vflag = 1
139             
140         self.xscaleflag = 0        
141         self.yscaleflag = 0
142         self.uexpand = unit * self.uscale
143         self.vexpand = unit * self.vscale
144         self.ushift = self.uscale * 0.5
145         self.vshift = self.vscale * 0.5
146         
147         self.generatepoints()
148         self.generatefaces()
149         for i in range(len(self.verts)):
150             self.verts[i].index = i
151         self.connectivity()
152                 
153     def formula(self, u, v, r1, r2):     
154         x = u * self.uexpand - self.ushift
155         y = v * self.vexpand - self.vshift
156         z = r1 * r2 - 1.0         
157         return x, y, z
158     
159     
160 class cylinder(form):
161     def __init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
162                  uphase, vphase, utwist, vtwist, xscale, yscale, sform):
163         form.__init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
164                       uphase, vphase, utwist, vtwist, xscale, yscale, sform)
165         unit = 1.0 / self.a360
166         self.vshift = self.vscale * 0.5
167         self.vexpand = unit * self.vscale
168         self.vflag = 1    
169         self.generatepoints()
170         self.generatefaces()
171         for i in range(len(self.verts)):
172             self.verts[i].index = i
173         self.connectivity()    
174
175     def formula(self, u, v, r1, r2):
176         x = sin(u) * self.uscale * r1 * r2 * self.xscale
177         y = cos(u) * self.uscale * r1 * r2
178         z = v * self.vexpand - self.vshift
179         return x, y, z
180
181 class parabola(form):
182     def __init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
183                  uphase, vphase, utwist, vtwist, xscale, yscale, sform):
184         form.__init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
185                       uphase, vphase, utwist, vtwist, xscale, yscale, sform)
186         unit = 1.0 / self.a360
187         self.vshift = self.vscale * 0.5
188         self.vexpand = unit * self.vscale
189         self.vflag = 1
190         self.generatepoints()
191         self.generatefaces()
192         for i in range(len(self.verts)):
193             self.verts[i].index = i
194         self.connectivity()        
195     
196     def formula(self, u, v, r1, r2):
197         factor = sqrt(v) + 0.001
198         x = sin(u) * factor * self.uscale * r1 * r2 * self.xscale
199         y = cos(u) * factor * self.uscale * r1 * r2
200         z = - v * self.vexpand + self.vshift
201         return x, y, z
202         
203 class torus(form):    
204     def __init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
205                  uphase, vphase, utwist, vtwist, xscale, yscale, sform):
206         form.__init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
207                       uphase, vphase, utwist, vtwist, xscale, yscale, sform)
208         self.generatepoints()
209         self.generatefaces()
210         for i in range(len(self.verts)):
211             self.verts[i].index = i
212         self.connectivity()        
213                     
214     def formula(self, u, v, r1, r2):
215         z = sin(v) * self.uscale * r2 * self.yscale
216         y = (self.vscale + self.uscale * cos(v)) * cos(u) * r1 * r2
217         x = (self.vscale + self.uscale * cos(v)) * sin(u) * r1 * r2 * self.xscale
218         return x, y, z
219
220 class sphere(form):
221     def __init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
222                  uphase, vphase, utwist, vtwist, xscale, yscale, sform):
223         form.__init__(self, uresolution, vresolution, uscale, vscale, upart, vpart,\
224                       uphase,vphase,utwist,vtwist,xscale,yscale,sform)
225         self.vstep = (self.a360 / (self.vres - 1)) * self.vpart
226         self.vflag = 1
227         self.generatepoints()
228         self.generatefaces()
229         for i in range(len(self.verts)):
230             self.verts[i].index = i
231         self.connectivity()        
232         
233     def formula(self, u, v, r1, r2):
234         v = (v * 0.5) - (self.a360 * 0.25)
235         x = r1 * cos(u) * r2 * cos(v) * self.uscale * self.xscale
236         y = r1 * sin(u) * r2 * cos(v) * self.uscale
237         z = r2 * sin(v) * self.uscale * self.yscale
238         return x, y, z