Blender (jusqu'à 2.49)
Python 
Tips and tricks
Description: 
to reorganize the table of the faces 
in a mesh to direct  the build effect
(updated: 2008/01/17)
(version française)
    Main   Index
previousScript Python: split by material
Script python: display a tga: Nextt

Updated script : 2008/01/17
Old script

Download 

Updated example of  blender file
The script 
Old example of blender file
The script 
Walk-through
the complex meshes, those which were subdivided or cut out, for example, require to be reorganized if one wishes to apply a Build effect to them.

This script makes it possible to carry out this sorting and, moreover, makes it possible to choose a starting point of the rebuilding by selecting a face.




Updated script : 2008/01/20

New options in a menu :
Hash : blend the faces as the hash method blender verticies in the mesh tool panel
Seed offers a new seew to the random numbre generator
#!BPY

""" Registration info for Blender menus: <- these words are ignored
Name: 'Reorganize mesh for build effect'
Blender: 245
Group: 'Mesh'
Tip: 'Select the startup face in edit mode, the script rebuilds the mesh from this one .'
"""
#----------------------------------------------
# jm soler  07/2005 :  'reorganize_buildeffectmesh'
#        updated for materials problems: 17/01/2008
#        updated for randomize option : 20/01/2008
#----------------------------------------------
# Page officielle :
#   http://jmsoler.free.fr/util/blenderfile/py/cpl_reorganize_buildeffectmesh_en.htm
# Communiquer les problemes et erreurs sur:
#   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#--------------------------------------------- 
#-------------------------------------------- 
#  Reorganize faces from the selected one
#  for a built effect
#  Jm Soler  july 2005

#  This script is under  GPL licence.
#--------------------------------------------
import Blender
from Blender import *
import sys
def reorganize_builtedeffectmesh(me,seed,hash=0):
    # copy the mesh data
    mesh=me.getData()

    # verify that at least one face is 
    # selected
    SF=[f for f in mesh.faces if f.sel==1]
    if len(SF)==0: 
       print "no face selected"
       return

    # if  there is more than one face selected
    # use the first one.
    SF=mesh.faces.pop(mesh.faces.index(SF[0]))

    # creat an empty list 
    LF=[]

    # copy all the faces in this list
    LF=mesh.faces[:]

    # don't forget to copy the removed (pop) SF 
    # in first position 
    LF.insert(0,SF) 

    # the mesh mays be in several parts
    fragment=[]
    List_fragment=[]

    # to range the face to do
    LFAT=[] #List_Face_A_Traiter

    # to range the face already saw
    LFDT=[] #List_Face_Deja_Traitees

    #take the first face from LF
    LFAT.append(LF[0])

    # To do on all the elements of LF...
    while len(LF)!=0:
     # control all the face in LFAT...
     for f1 in LFAT:
        # compare the vertices of this faces ...
        for v in f1.v:
            #... with all the faces that remain in LF ...
            for f2 in LF:
               #... if the face was not ralready saw
               # and if the face not already in LFAT 
               if (v in f2.v)  and (f2 not in LFDT) and  (f2 not in LFAT):
                  LFAT.append(f2)
        if f1 not in LFDT:
           LFDT.append(f1)

     List_fragment.append(LFAT[:])

     for f1 in LFAT:
         del LF[LF.index(f1)]

     LFAT=[]

     if len(LF)!=0:
        LFAT.append(LF[0])

    if hash and len(List_fragment)>0:
      Blender.Noise.setRandomSeed(seed)
      for nouveau in List_fragment:
        l=len(nouveau)
        n=0
        while n < l:
          f= nouveau[n]
          r=int(Blender.Noise.random()*l)
          nouveau[n]=nouveau[r]
          nouveau[r]=f
          n+=1
    if len(List_fragment)>0:
      fragment=Blender.NMesh.GetRaw() 
      fragment.materials=mesh.getMaterials()
      for nouveau in List_fragment:
           for f1 in nouveau:
              for f2 in f1.v:
                 if f2 not in fragment.verts:
                     fragment.verts.append(f2)
           for f in nouveau : fragment.faces.append(f)

      mesh.faces=fragment.faces
      mesh.verts=fragment.verts
      mesh.update()

    else: print "nothing to do" 
if Blender.Object.GetSelected():
   seed = Blender.Draw.Create(1)
   tog = Blender.Draw.Create(0)
   block = []
   block.append("Rebuild Mesh")
   block.append(("Hash", tog, "Randomize mesh ?"))
   block.append(("Seed: ", seed, 0, 100))
   retval = Blender.Draw.PupBlock("PupBlock test", block)
   if retval:
      EDITMODE=Blender.Window.EditMode()
      Blender.Window.EditMode(0)
      list=Blender.Object.GetSelected()[0] 
      if list.getType()=='Mesh':
         reorganize_builtedeffectmesh(list,seed.val,hash=tog.val) 
      else:
         pass
      Blender.Window.EditMode(EDITMODE) 
else:
   print 'perhaps not a mesh or no object selected' 
Blender.Redraw() 

Old script
 

#!BPY

""" Registration info for Blender menus: <- these words are ignored
Name: 'Reorganize mesh for build effect'
Blender: 232
Group: 'Mesh'
Tip: 'Select the startup face in edit mode, the script rebuilds the mesh from this one .'
"""
#----------------------------------------------
# jm soler  07/2005 :  'reorganize_buildeffectmesh'
#----------------------------------------------
# Page officielle :
#   http://jmsoler.free.fr/util/blenderfile/py/cpl_reorganize_buildeffectmesh_en.htm
# Communiquer les problemes et erreurs sur:
#   http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#--------------------------------------------- 
#-------------------------------------------- 
#  Reorganize faces from the selected one
#  for a built effect
#  Jm Soler  july 2005

#  This script is under  GPL licence.
#-------------------------------------------- 
import Blender
from Blender import *
import sys
def reorganize_builtedeffectmesh(selected):
    me=Blender.Object.Get(selected)
    mesh=me.getData()
    LF=[]
    SF=[f for f in mesh.faces if f.sel==1]
    if len(SF)==0: 
       print "no face selected"
       return
    SF=mesh.faces.pop(mesh.faces.index(SF[0]))
    LF=mesh.faces[:]
    LF.insert(0,SF) 
    print LF 
    fragment=[]
    List_fragment=[]
    LFAT=[] #List_Face_A_Traiter
    LFDT=[] #List_Face_Deja_Traitees
    LFAT.append(LF[0])
    while len(LF)!=0:
     for f1 in LFAT:
        for v in f1.v:
            for f2 in LF:
               if (v in f2.v)  and (f2 not in LFDT) and  (f2 not in LFAT):
                  LFAT.append(f2)
        if f1 not in LFDT:
           LFDT.append(f1)

     List_fragment.append(LFAT[:])

     for f1 in LFAT:
         del LF[LF.index(f1)]
     LFAT=[]
     if len(LF)!=0:
        LFAT.append(LF[0])
    if len(List_fragment)>0:
      fragment=Blender.NMesh.GetRaw() 
      fragment.materials=mesh.materials[:]
      for nouveau in List_fragment:
           for v1 in nouveau:
              for v2 in v1.v:
                 if v2 not in fragment.verts:
                     fragment.verts.append(v2)
           for f in nouveau : fragment.faces.append(f)
           NMesh.PutRaw(fragment,mesh.name)
    else: print "nothing to do" 
try:
   EDITMODE=Blender.Window.EditMode()
   Blender.Window.EditMode(0)
   list=Blender.Object.GetSelected()[0] 
   if list.getType()=='Mesh':
      reorganize_builtedeffectmesh(list.name ) 
   else:
      pass
   Blender.Window.EditMode(EDITMODE) 
except:
   print 'perhaps not a mesh or no object selected' 
Blender.Redraw()

 


 
previousScript Python: split by material
 Script python: display a tga: Next
To the  Top of this  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