PasteAll.org
http://pasteall.org/2/python 15 Mar 2008 14:15
Loading
import Blender

def facecollect(startface, partition, visited, fan):
if not visited[startface]:
visited[startface] = True
partition.append(startface)
for vert in startface.verts:
for face in fan[vert]:
facecollect(face, partition, visited, fan)

def getfaceOrig(mesh,index):
for face in mesh.faces:
if face.getProperty("ORIGINDEX") == index:
return face


def partition():
scene = Blender.Scene.GetCurrent()
actob = scene.objects.active
mat = actob.getMatrix('worldspace')
if actob and actob.type == 'Mesh':
#partition first
mesh = actob.getData(mesh=True)
partitions = list()
vertfan = dict()
facevisit = dict()


if "ORIGINDEX" not in mesh.faces.properties:
mesh.faces.addPropertyLayer("ORIGINDEX", Blender.Mesh.PropertyTypes["INT"])

for face in mesh.faces:
face.setProperty("ORIGINDEX", face.index)
for vert in mesh.verts:
vertfan[vert] = list()

for face in mesh.faces:
facevisit[face] = False
for vert in face.verts:
vertfan[vert].append(face)

#now go through and visit everything
for face in mesh.faces:
if not facevisit[face]:
partition = list()
facecollect(face, partition,facevisit, vertfan)
partitions.append(partition)


bboxs = list() #list of bound boxes for the islands
for island in partitions:
vmin = Blender.Mathutils.Vector(island[0].verts[0].co)
vmax = Blender.Mathutils.Vector(island[0].verts[0].co)
for face in island:
for vert in face.verts:
vmin = min(vmin, vert.co)
vmax = max(vmax, vert.co)

bboxs.append((vmin,vmax))


hooks = list()

islands = list()
for partition in partitions:
island = list()
for face in partition:
island.append(face.getProperty("ORIGINDEX"))
islands.append(island)




for island in islands:
for vert in mesh.verts:
vert.sel = 0

for index in island:
face = getfaceOrig(mesh,index)
for vert in face.verts:
vert.sel = 1

Blender.Window.EditMode(1)
mods = actob.modifiers

mods.ZanQdoHack()

Blender.Window.EditMode(0)



partition()
  1. import Blender
  2.  
  3. def facecollect(startface, partition, visited, fan):
  4.         if not visited[startface]:
  5.                 visited[startface] = True
  6.                 partition.append(startface)
  7.                 for vert in startface.verts:
  8.                         for face in fan[vert]:
  9.                                 facecollect(face, partition, visited, fan)
  10.  
  11. def getfaceOrig(mesh,index):
  12.         for face in mesh.faces:
  13.                 if face.getProperty("ORIGINDEX") == index:
  14.                         return face            
  15.  
  16.  
  17. def partition():
  18.         scene = Blender.Scene.GetCurrent()
  19.         actob = scene.objects.active
  20.         mat = actob.getMatrix('worldspace')
  21.         if actob and actob.type == 'Mesh':
  22.                 #partition first
  23.                 mesh = actob.getData(mesh=True)
  24.                 partitions = list()
  25.                 vertfan = dict()
  26.                 facevisit = dict()
  27.                
  28.                
  29.                 if "ORIGINDEX" not in mesh.faces.properties:
  30.                         mesh.faces.addPropertyLayer("ORIGINDEX", Blender.Mesh.PropertyTypes["INT"])
  31.                
  32.                 for face in mesh.faces:
  33.                         face.setProperty("ORIGINDEX", face.index)
  34.                 for vert in mesh.verts:
  35.                         vertfan[vert] = list()
  36.                        
  37.                 for face in mesh.faces:
  38.                         facevisit[face] = False
  39.                         for vert in face.verts:
  40.                                 vertfan[vert].append(face)
  41.                        
  42.                 #now go through and visit everything
  43.                 for face in mesh.faces:
  44.                         if not facevisit[face]:
  45.                                 partition = list()
  46.                                 facecollect(face, partition,facevisit, vertfan)
  47.                                 partitions.append(partition)
  48.                
  49.                
  50.                 bboxs = list() #list of bound boxes for the islands
  51.                 for island in partitions:
  52.                         vmin = Blender.Mathutils.Vector(island[0].verts[0].co)
  53.                         vmax = Blender.Mathutils.Vector(island[0].verts[0].co)
  54.                         for face in island:
  55.                                 for vert in face.verts:
  56.                                         vmin = min(vmin, vert.co)
  57.                                         vmax = max(vmax, vert.co)
  58.                                        
  59.                         bboxs.append((vmin,vmax))
  60.                                
  61.                
  62.                 hooks = list()
  63.                
  64.                 islands = list()
  65.                 for partition in partitions:
  66.                         island = list()
  67.                         for face in partition:
  68.                                 island.append(face.getProperty("ORIGINDEX"))
  69.                         islands.append(island)         
  70.                
  71.                
  72.  
  73.                
  74.                 for island in islands:
  75.                         for vert in mesh.verts:
  76.                                 vert.sel = 0
  77.                        
  78.                         for index in island:
  79.                                 face = getfaceOrig(mesh,index)
  80.                                 for vert in face.verts:
  81.                                         vert.sel = 1
  82.                        
  83.                         Blender.Window.EditMode(1)
  84.                         mods = actob.modifiers
  85.                        
  86.                         mods.ZanQdoHack()
  87.                        
  88.                         Blender.Window.EditMode(0)
  89.                        
  90.                                
  91.        
  92. partition()
PasteAll.org brought to you by the monkeys of GraphicAll.org