MAPA fixes

This commit is contained in:
Jack Andersen 2017-11-17 17:34:11 -10:00
parent e1d952dd88
commit b25db30c2a
2 changed files with 92 additions and 51 deletions

View File

@ -4,6 +4,22 @@ from mathutils import Vector
VertPool = hmdl.HMDLMesh.VertPool VertPool = hmdl.HMDLMesh.VertPool
strip_next_loop = hmdl.HMDLMesh.strip_next_loop strip_next_loop = hmdl.HMDLMesh.strip_next_loop
def recursive_faces_islands(list_out, rem_list, face):
if face not in rem_list:
return []
list_out.append(face)
rem_list.remove(face)
next_faces = []
for e in face.edges:
if not e.is_contiguous or e.seam:
continue
for f in e.link_faces:
if f == face:
continue
next_faces.append(f)
return next_faces
def cook(writebuf, mesh_obj): def cook(writebuf, mesh_obj):
if mesh_obj.type != 'MESH': if mesh_obj.type != 'MESH':
raise RuntimeError("%s is not a mesh" % mesh_obj.name) raise RuntimeError("%s is not a mesh" % mesh_obj.name)
@ -43,61 +59,86 @@ def cook(writebuf, mesh_obj):
vert_pool.write_out_map(writebuf) vert_pool.write_out_map(writebuf)
# Create map surfaces and borders # Create map surfaces and borders
island_faces = list(bm_master.faces) faces_rem = list(bm_master.faces)
#prev_loop_emit = None
loop_ranges = []
loop_iter = 0 loop_iter = 0
while len(island_faces): loop_ranges = []
out_count = 0 while len(faces_rem):
sel_lists_local = [] island_faces = []
restore_out_count = out_count faces = [faces_rem[0]]
for start_face in island_faces: while len(faces):
for l in start_face.loops: next_faces = []
out_count = restore_out_count ret_faces = None
island_local = list(island_faces) for f in faces:
if out_count & 1: ret_faces = recursive_faces_islands(island_faces, faces_rem, f)
prev_loop = l.link_loop_prev if ret_faces == False:
loop = prev_loop.link_loop_prev break
sel_list = [l, prev_loop, loop] next_faces.extend(ret_faces)
prev_loop = loop if ret_faces == False:
else: break
prev_loop = l.link_loop_next faces = next_faces
loop = prev_loop.link_loop_next
sel_list = [l, prev_loop, loop]
out_count += 3
island_local.remove(start_face)
while True:
if not prev_loop.edge.is_contiguous or prev_loop.edge.seam:
break
loop, prev_loop = strip_next_loop(prev_loop, out_count)
face = loop.face
if face not in island_local:
break
sel_list.append(loop)
island_local.remove(face)
out_count += 1
sel_lists_local.append((sel_list, island_local, out_count))
max_count = 0
max_sl = None
max_island_faces = None
for sl in sel_lists_local:
if len(sl[0]) > max_count:
max_count = len(sl[0])
max_sl = sl[0]
max_island_faces = sl[1]
out_count = sl[2]
island_faces = max_island_faces
# island_faces now holds one island (map edge delimited)
prev_loop_emit = None
loop_set = set() loop_set = set()
edge_set = set() edge_set = set()
loop_count = len(max_sl) out_count = 0
for loop in max_sl: loop_count = 0
vert_pool.loop_out_map(writebuf, loop) while len(island_faces):
loop_set.add(loop) sel_lists_local = []
for edge in loop.face.edges: restore_out_count = out_count
if edge.seam: for start_face in island_faces:
edge_set.add(edge) for l in start_face.loops:
out_count = restore_out_count
island_local = list(island_faces)
if out_count & 1:
prev_loop = l.link_loop_prev
loop = prev_loop.link_loop_prev
sel_list = [l, prev_loop, loop]
prev_loop = loop
else:
prev_loop = l.link_loop_next
loop = prev_loop.link_loop_next
sel_list = [l, prev_loop, loop]
out_count += 3
island_local.remove(start_face)
while True:
if not prev_loop.edge.is_contiguous or prev_loop.edge.seam:
break
loop, prev_loop = strip_next_loop(prev_loop, out_count)
face = loop.face
if face not in island_local:
break
sel_list.append(loop)
island_local.remove(face)
out_count += 1
sel_lists_local.append((sel_list, island_local, out_count))
max_count = 0
max_sl = None
max_island_faces = None
for sl in sel_lists_local:
if len(sl[0]) > max_count:
max_count = len(sl[0])
max_sl = sl[0]
max_island_faces = sl[1]
out_count = sl[2]
island_faces = max_island_faces
if prev_loop_emit:
vert_pool.loop_out_map(writebuf, prev_loop_emit)
vert_pool.loop_out_map(writebuf, max_sl[0])
loop_count += 2
loop_set.add(prev_loop_emit)
loop_set.add(max_sl[0])
loop_count += len(max_sl)
for loop in max_sl:
vert_pool.loop_out_map(writebuf, loop)
prev_loop_emit = loop
loop_set.add(loop)
for edge in loop.face.edges:
if edge.seam:
edge_set.add(edge)
# Create island surface with edges
if len(edge_set): if len(edge_set):
trace_edge = edge_set.pop() trace_edge = edge_set.pop()
else: else:

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit a99bddc90524b9ca532b0cf8865b493b3002fd67 Subproject commit 98bf80a9b9f5afd38bf9491954ea359d7ad4b122