Blender (jusqu'à 2.49)
Python 
Tips and  Tricks 
Description: spread  a mesh in different  pieces 
by material 
(Updated : 2005/07/12)
(version française)
Table of content   Index
previous  Script : spead mesh2obj by pieces
Script Rvk 2 rvk : Next

 

#-------------------------------------------- 
#  spread  a mesh in different  pieces by material 
#   Jm Soler 2005
#  ce script est proposé sous licence GPL.
#-------------------------------------------- 
import Blender
from Blender import *
import sys

def split_materials_mesh(selected):
    me=Blender.Object.Get(selected)
    mesh=me.getData()
    List_fragment=[]
    Materials=mesh.getMaterials(0)
    for mat in Materials:
       List_fragment.append([])
    for f1 in mesh.faces:
       List_fragment[f1.materialIndex].append(f1) 
    if len(List_fragment)>1:
      for nouveau in List_fragment:
        fragment=Blender.NMesh.GetRaw()
        for f1 in nouveau:
           for v2 in f1.v:
              if v2 not in fragment.verts:
                   fragment.verts.append(v2)
        fragment.faces=nouveau
        fragment.materials=[Materials[List_fragment.index(nouveau)]]
        names = NMesh.GetNames()
        n=0
        nom_prov=mesh.name+'%s' % List_fragment.index(nouveau)
        while nom_prov in names:
              nom_prov=nom_prov+'%s' % (List_fragment.index(nouveau)+n)
              n+=1 
        ob=NMesh.PutRaw(fragment,nom_prov,1)
        ob.setMatrix(me.getMatrix()) 
    print "nothing to do" 

try:
  list=Blender.Object.GetSelected()[0] 
  if list.getType()=='Mesh':
      split_materials_mesh(list.name ) 
  else:
      pass
except:
   print 'perhaps not a mesh or no object selected'

Blender.Redraw()

 


 
previous  Script : spead mesh2obj by pieces
 Script Rvk 2 rvk : Next
To the top  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