Blender (jusqu'à 2.49)
Python 
Construire un escalier 


1/ Droit 2/ en colimaçon

 

(Version anglaise)

    Début   Index
précédentScript Python: image tga
Script python: Displacement painting Suivant

1/ Construire un escalier Droit 

Marches en accordeon

#-------------------------------------------- 
#  Escalier droit  avec marches en accordeon 
#   jmsoler  2006
#  ce script est proposé 
#  sous licence GPL.
#-------------------------------------------- 
import Blender
from Blender import NMesh

#Nombre de marches
n = 10

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

#dimensions
len_x = 5.0 # largeur de la marche
len_y = 6.0 #longueur de la marche
len_z = 2.0 #hauteur de lamarche
 

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') 

Marches séparées 

# (mise a jour le 24/11/2007)
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/ Construire un escalier en colimaçon

L'intérêt principal de ce script est d'illustrer les formules  qui permettent de faire tourner un point autour d'un axe:

Nouveaux=Ancienx*cos(angle)-Ay*sin(angle)
Nouveauy=Ancienx*sin(angle)+Ay*cos(angle)

Téléchargerle script 
 
 
#-------------------------------------------- 
#  Escalier en colimacon
#   jmsoler  2002 
#  ce script est proposé 
#  sous licence GPL.
#-------------------------------------------- 
import Blender
from Blender import *
import math
from math import *

nbmarches=12
htmarche=0.6

largeurinterne=0.1
largeurexterne=1.5
longueurmarche=4.0

# rad=30*2*pi/360
# mais c'est plus propre si l'angle
# est calcule' a' partie de la largeur externe 
# de la marche 

rad=2*asin(largeurexterne/(2*longueurmarche))

p=[[0.0,0.0,htmarche],
 [cos(rad)*largeurexterne-sin(rad)*longueurmarche,
    sin(rad)*largeurexterne+cos(rad)*longueurmarche,
    htmarche],
 [largeurexterne,longueurmarche,htmarche],
 [largeurinterne,0.0,htmarche]]

print  p[2][0],p[2][1],

m=NMesh.GetRaw()

for nm in range(nbmarches):
    # comme la formule pour faire pivoter un point autour
    # d'un axe est: Nx=Ax*cos(r)-Ay*sin(r)
    #               Ny=Ax*sin(r)+Ay*cos(r)
    #j'applique...

    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() 


 
 
précédentScript Python: image tga
 Script python: Displacement painting Suivant
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