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()
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()
|