import bpy
import math
def staircase(name, nSteps, r1, r2, dTheta,dz):
verts=[]
faces = []
for i in range(nSteps):
v3=i*4
v1 = v3-2
v2 = v3-1
v4 = v3+1
v5 = v3+2
v6 = v3+3
theta = i*dTheta
z= i*dz
c = math.cos(theta)
s = math.sin(theta)
verts.append( [r1*c, r1*s, z] )
verts.append( [r2*c, r2*s, z] )
verts.append( [r1*c, r1*s, z+dz] )
verts.append( [r2*c, r2*s, z+dz] )
if (0!=i):
faces.append( [v1, v2, v4, v3] )
faces.append( [v3, v4, v6, v5] )
mesh = bpy.data.meshes.new(name);
mesh.from_pydata(verts, [], faces)
mesh.validate(True)
mesh.show_normal_face = True
obj = bpy.data.objects.new(name, mesh)
scn = bpy.context.scene
scn.objects.link(obj)
staircase("stairs", 40, 0.2, 2, math.pi/10, 0.2)
|
Blender python API quick-start
Syntax highlighting by Pygments.