Blender (jusqu'à 2.49)
Python 
Build a staircase 
1/ straight 
2/ Spiral
(french version)
    Début   Index
previoustScript Python: image tga
Script python: Displacement painting Nextt

1/ Build a  straight staircase 

Squeeze step
#-------------------------------------------- 
#  Straight staircase with squeezed step
#   jmsoler  2006
#  this script is offered 
#  under  GPL licence.
#-------------------------------------------- 
import Blender
from Blender import NMesh

# Steps' number
n = 10

# distance from the object's center
xc = 0.0
yc = 10.0
zc = 0.0

# dimensions
len_x = 5.0 # step 's  width
len_y = 6.0 # step 's  height 
len_z = 2.0 # step 's  high 
 

ME=NMesh.GetRaw()
verts=ME.verts

for s in range(n):
 x = xc+len_x*s
 y = yc 
 z = zc+len_z*s
 verts.append(NMesh.Vert(x,y,z))

 x = xc+len_x*s
 y = yc+len_y
 z = zc+len_z*s
 verts.append(NMesh.Vert(x,y,z))

 x = xc+len_x*s
 y = yc+len_y
 z = zc+len_z*(s+1)
 verts.append(NMesh.Vert(x,y,z)) 

 x = xc+len_x*s
 y = yc
 z = zc+len_z*(s+1)
 verts.append(NMesh.Vert(x,y,z))
 

for i in range(0,len(verts)-4,2)[:-1]:
 f=NMesh.Face()
 f.v=ME.verts[i:i+4]
 ME.faces.append(f) 
NMesh.PutRaw(ME,'test') 

Disjoint step 
import Blender
from Blender import NMesh

#Number of steps
n = 10

#Distance entre les marches
d = 0.5

# distance du centre de l'objet
xc = 0.0
yc = 10.0
zc = 0.0

# dimensions des cotes de la marche
lar_x = 5.0
lar_y = 6.0
lar_z = 0.5

ME=NMesh.GetRaw()
verts=ME.verts

for s in range(n):
 x=xc+s*lar_x
 y=yc
 z=zc+s*(lar_z+d) 
 verts.append(NMesh.Vert(x,y,z))
 z+=lar_z 
 verts.append(NMesh.Vert(x,y,z))

 x=xc+(s+1)*lar_x
 y=yc
 z=zc+s*(lar_z+d) 
 verts.append(NMesh.Vert(x,y,z))
 z+=lar_z 
 verts.append(NMesh.Vert(x,y,z))

 x=xc+(s+1)*lar_x
 y=yc+lar_y
 z=zc+s*(lar_z+d) 
 verts.append(NMesh.Vert(x,y,z))
 z+=lar_z 
 verts.append(NMesh.Vert(x,y,z))

 x=xc+s*lar_x
 y=yc+lar_y
 z=zc+s*(lar_z+d) 
 verts.append(NMesh.Vert(x,y,z))
 z+=lar_z 
 verts.append(NMesh.Vert(x,y,z))

FL=[(0,1,3,2),
    (4,5,7,6),
    (0,2,4,6),
    (1,3,5,7),
    (0,1,7,6),
    (2,3,5,4)]

for i in range(0,len(verts)+1,8)[:-1]:
 for a,b,c,d in FL :
   f=NMesh.Face()
   f.v=[ME.verts[v] for v in i+a,i+b,i+c,i+d] 
   ME.faces.append(f)
NMesh.PutRaw(ME,'test') 


 

2/ Build a spiral staircase

The main purpose of this script is to illustrate formulas which offer to  rotate a point around Z axis  :

Newx=Oldx*cos(angle)-Oldy*sin(angle)
Newy=Oldx*sin(angle)+Oldy*cos(angle)
Download the script

#-------------------------------------------- 
#  Spiral staircase
#  jmsoler  2002 
#  this script is offered 
#  under GPL licence
#-------------------------------------------- 
import Blender
from Blender import *
import math
from math import *

DEBUG=0

nbsteps=6
htsteps=0.6

internalwidth=0.01
externalwidth=1.5
heightstep=4.0

# rad=30*2*pi/360
# but cleaner if l'angle is computed wit the external
# width of the step

rad=2*asin(externalwidth/(2*heightstep))

p=[[0.0,0.0,htsteps],
 [cos(rad)*externalwidth-sin(rad)*heightstep,sin(rad)*externalwidth+cos(rad)*heightstep,htsteps],
 [externalwidth,heightstep,htsteps],
 [internalwidth,0.0,htsteps]]

if DEBUG : print  p[2][0],p[2][1],

m=NMesh.GetRaw()

for nm in range(nbsteps):
    # the formulas to do the rodation around Z axis is :
    #  Nx=Ax*cos(r)-Ay*sin(r)
    #  Ny=Ax*sin(r)+Ay*cos(r)

    v=NMesh.Vert(cos(nm*rad)*p[0][0]-sin(nm*rad)*p[0][1],
                 sin(nm*rad)*p[0][0]+cos(nm*rad)*p[0][1],
                 nm*p[0][2])
    m.verts.append(v)

    v=NMesh.Vert(cos(nm*rad)*p[1][0]-sin(nm*rad)*p[1][1],
                 sin(nm*rad)*p[1][0]+cos(nm*rad)*p[1][1],
                 nm*p[1][2])
    m.verts.append(v)

    v=NMesh.Vert(cos(nm*rad)*p[2][0]-sin(nm*rad)*p[2][1],
                 sin(nm*rad)*p[2][0]+cos(nm*rad)*p[2][1],
                 nm*p[2][2])
    m.verts.append(v)

    v=NMesh.Vert(cos(nm*rad)*p[3][0]-sin(nm*rad)*p[3][1],
                 sin(nm*rad)*p[3][0]+cos(nm*rad)*p[3][1],
                 nm*p[3][2])
    m.verts.append(v)

    f=NMesh.Face()
    for n in range(4):
       f.v.append(m.verts[n+len(m.verts)-4])
    m.faces.append(f)

l=len(m.faces)
for n0 in range(l-1):
    f=NMesh.Face()
    f.v.append(m.verts[n0*4+7])
    f.v.append(m.verts[n0*4+6])
    f.v.append(m.verts[n0*4+1])
    f.v.append(m.verts[n0*4])
    m.faces.append(f)

NMesh.PutRaw(m,'test')
Redraw() 


 
previoustScript Python: image tga
 Script python: Displacement painting Next
Vers le  Haut de page

Les questions concernant cette page  peuvent être posées sur  :
 news://news.zoo-logique.org/3D.Blender


 

 

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube