From ea6445c234d1db93e7c62cce228e94b2b652c1c5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 9 Aug 2012 23:21:45 +0300 Subject: [PATCH] Refactor strip generation code and add comments --- blender/io_mesh_mspgl/export_mspgl.py | 54 +++++++++++++++------------ blender/io_mesh_mspgl/mesh.py | 19 +++++++--- 2 files changed, 45 insertions(+), 28 deletions(-) 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 -- 2.43.0