#--------------------------------------------
# fractionnement d'un mesh en differents objets
# Jm Soler 2002 (blender 1.80-->2.23, except 2.10/2.12)
# ce script est proposé sous licence GPL.
#--------------------------------------------
import Blender
from Blender import *
import sys
def split_fragmented_mesh(selected):
List=Blender.Object.Get()
Ln2=[]
for n in List:
Ln2.append(n.name)
me=Blender.Object.Get(selected)
nom=me.data.name
mesh=NMesh.GetRaw(nom)
List_Faces=mesh.faces[:]
LF=List_Faces
fragment=[]
List_fragment=[]
List_Face_A_Traiter=[]
List_Face_Deja_Traitees=[]
LFAT=List_Face_A_Traiter
LFDT=List_Face_Deja_Traitees
LFAT.append(LF[0])
n=1
while len(LF)!=0:
print len(LFAT)
for v1 in LFAT:
for v in v1.v:
for v2 in LF:
if (v in v2.v) and (v2 not in LFDT) and (v2 not in LFAT):
LFAT.append(v2)
n= n+1; print n
if v1 not in LFDT:
LFDT.append(v1)
List_fragment.append(LFAT[:])
for v1 in LFAT:
del LF[LF.index(v1)]
LFAT=[]
if len(LF)!=0:
LFAT.append(LF[0])
for nouveau in List_fragment:
fragment=Blender.NMesh.GetRaw()
for v1 in nouveau:
for v2
in v1.v:
print v1.mat, len(fragment.verts),len(v1.v), v1.v.index(v2),
if v2 not in fragment.verts:
fragment.verts.append(v2)
fragment.faces=nouveau
fragment.mats=mesh.mats[:]
nom_prov=mesh.name+'%s'
% List_fragment.index(nouveau)
mprov=NMesh.GetRaw(nom_prov)
while mprov!=None:
nom_prov=nom_prov+'%s' % List_fragment.index(nouveau)
mprov=NMesh.GetRaw(nom_prov)
NMesh.PutRaw(fragment,nom_prov,1)
List=Blender.Object.Get()
Ln=[]
N_obname=''
for n in List:
Ln.append(n.name)
for L in Ln:
if L not in Ln2:
N_obname=L;
break
Ln2=Ln
ob=Blender.Object.Get(N_obname)
ob.loc[0],ob.loc[1],ob.loc[2]=me.loc[0],me.loc[1],me.loc[2]
ob.rot[0],ob.rot[1],ob.rot[2]=me.rot[0],me.rot[1],me.rot[2]
ob.size[0],ob.size[1],ob.size[2]=me.size[0],me.size[1],me.size[2]
list=Blender.Object.GetSelected()
if len(list)>0:
selected=list[0].name
split_fragmented_mesh(selected)
Blender.Redraw()
sys.stdout.flush() |