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