From: Mikko Rasa Date: Thu, 9 Aug 2012 20:21:45 +0000 (+0300) Subject: Refactor strip generation code and add comments X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ea6445c234d1db93e7c62cce228e94b2b652c1c5;p=libs%2Fgl.git Refactor strip generation code and add comments --- diff --git a/blender/io_mesh_mspgl/export_mspgl.py b/blender/io_mesh_mspgl/export_mspgl.py index 0e96c424..124114e5 100644 --- a/blender/io_mesh_mspgl/export_mspgl.py +++ b/blender/io_mesh_mspgl/export_mspgl.py @@ -94,6 +94,7 @@ class Exporter: island_strips = [] while 1: if not island: + # No current island; find any unused face to start from queue = [] for f in mesh.faces: if not f.flag: @@ -104,38 +105,46 @@ class Exporter: if not queue: break + # Find all faces connected to the first one while queue: - f = queue[0] - del queue[0] - island.append(f) + face = queue.pop(0) + island.append(face) - for e in f.edges: - other = e.other_face(f) - if other and not other.flag: - other.flag = True - queue.append(other) + for n in f.get_neighbors(): + n.flag = True + queue.append(n) + # Unflag the island for the next phase for f in island: f.flag = False + # Find an unused face with as few unused neighbors as possible, but + # at least one. This heuristic gives a preference to faces in corners + # or along borders of a non-closed island. best = 5 face = None for f in island: if f.flag: continue - score = 0 - for e in f.edges: - other = e.other_face(f) - if other and not other.flag: - score += 1 + + score = sum(n.flag for n in f.get_neighbors()) if score>0 and score=max_len: break + # Hop over the last edge edge = face.get_edge(*result[-2:]) - - next = edge.other_face(face) - if not next or next.flag: + face = edge.other_face(face) + if not face or face.flag: break - face = next return result