Blender (jusqu'à 2.49)
Python : 
Multiplier les cubes 1/n 
Mise en forme avec le Module NMesh
(voir aussi : formes élémentaires)
 
    Début   Index
précédent Python : modèle cube
Script Python : multiplier cube 2Suivant

Multiplier les cubes
 

# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) J-M Soler 07/25/02008
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****

import Blender
from Blender import NMesh

Taille=1.75 #talle de l'arete
deplacement_lateral=3.0
nx=ny=nz=-deplacement_lateral
maxx=maxy=maxz=5*deplacement_lateral

vertices_list=[ 
    [0.0,0.0,0.0],
    [0.0,Taille,0.0],
    [Taille,Taille,0.0],
    [Taille,0.0,0.0],
    [0.0,0.0,Taille],
    [0.0,Taille,Taille],
    [Taille,Taille,Taille],
    [Taille,0.0,Taille]
]

faces_list=[[0,1,2,3],
    [7,6,5,4],
    [3,7,4,0],
    [5,6,2,1],
    [4,5,1,0],
    [2,6,7,3]]
 

#-------------------------
# ouverture de l'objet mesh dans la mémoire ram
#-------------------------
A_CUBE_MESH=NMesh.GetRaw()
#-------------------------
# on active les vertex color dans ce mesh
#------------------------- 
A_CUBE_MESH.hasVertexColours(1)

#-------------------------
# fonction de creation des cubes
#-------------------------
def CUBE(i,j,k):
 lastvertex=len(A_CUBE_MESH.verts)
 for coordinate in vertices_list:
     A_VERTEX=NMesh.Vert(coordinate[0]+i, 
                         coordinate[1]+j, 
                         coordinate[2]+k)

     A_CUBE_MESH.verts.append(A_VERTEX)
 #-------------------------
 # on calcule les valeurs rvb
 #------------------------- 
 r=int(255.0*(i/float(maxx)))
 v=int(255.0*(j/float(maxy)))
 b=int(255.0*(k/float(maxy)))

 #-------------------------
 # on cree l'objet couleur
 #------------------------- 
 COL=NMesh.Col(r, 
               v, 
               b, 0)
 print COL
 for thisface in faces_list:
     A_FACE=NMesh.Face()
     for vertexpos in thisface:
         A_FACE.append(A_CUBE_MESH.verts[vertexpos+lastvertex])
     A_CUBE_MESH.faces.append(A_FACE)
     #-------------------------
     # on ajoute la couleur a chaque sommet
     #------------------------- 
     A_FACE.col=[COL,COL,COL,COL]

#-------------------------
# fonction de multiplication
#-------------------------
#-------------------------
# while pour éviter de gaspiller de la mémoire 
# avec range qui cree la liste complete...
#-------------------------
while nx<maxx-1:
 nx+=deplacement_lateral
 ny=nz=-deplacement_lateral
 while ny<maxy-1:
  ny+=deplacement_lateral
  nz=-deplacement_lateral 
  while nz<maxz-1:
   nz+=deplacement_lateral
   CUBE(nx,ny,nz)

#-------------------------
# on cree un materiau
#-------------------------
if not A_CUBE_MESH.materials:
   mat = Blender.Material.New()
   #-------------------------
   # on l'attache au mesh
   #-------------------------
   A_CUBE_MESH.materials.append(mat)
   #-------------------------
   # on fait en sorte que les vertex 
   # color soient visibles
   #-------------------------
   mat.mode=54591623

#-------------------------
# accrochage du mesh a la base de donne 
# de la scene courante 
#-------------------------
NMesh.PutRaw(A_CUBE_MESH,'Cube') 

print maxx**3
Blender.Redraw() 


 
précédentpython : modèle cube
Python : multiplier cube 2 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