import math
import bmesh
def deselect():
for x in bpy.data.objects:
x.select = False
def genVert(n, m, q, r, s):
d = 1.0
for i in range(n):
yield(0.0, 0.0, q*float(i)/float(n))
for j in range(m+1):
if d>0:
t = float(j)*math.pi/float(m)
else:
t = math.pi-float(j)*math.pi/float(m)
yield(r*math.cos(t), s*r*math.sin(t), q*float(i)/float(n))
d *= -1.0
i = n
yield(0.0, 0.0, q*float(i)/float(n))
for j in range(m+1):
t = float(j)*math.pi/float(m)
yield(r*math.cos(t), s*r*math.sin(t), q*float(i)/float(n))
def genEdge(n):
for i in range(n-1):
yield(i, i+1)
def genFace(n, m):
for i in range(n+1):
o = (m+2)*i
for j in range(m):
f = o + j + 1
yield(o, f, f+1)
def main(n=10, m=12, q=1.0, r=1.0, s=1.0):
deselect()
verts = list(genVert(n, m, q, r, s))
faces = list(genFace(n, m))
m = bpy.data.meshes.new('saruNoKoshikakeMesh')
o = bpy.data.objects.new('saruNoKoshikake', m)
bpy.context.scene.objects.link(o)
bpy.context.scene.objects.active = o
bpy.context.scene.objects.active.select = True
m.from_pydata(verts, [], faces)
m.update()
return {'FINISHED'}