added inner-face edges and all new faces

This commit is contained in:
Stephen M. McQuay 2012-06-23 10:50:17 -07:00
parent 719bc94e8c
commit 889cdf201c

View File

@ -43,11 +43,8 @@ def _make_edge_point(mesh, eid):
def refine(mesh):
new_verts = list(mesh.vertices)
nv_offset = len(new_verts)
# TODO:
new_faces = []
# TODO:
new_edges = []
new_faces = []
for eid, verts_for_edge in enumerate(mesh.edges):
new_vert = _make_edge_point(mesh, eid)
@ -61,8 +58,23 @@ def refine(mesh):
for fid in range(len(mesh.faces)):
# join all new edge points on a face:
new_edges.extend(
[[i[0] + nv_offset, i[1] + nv_offset]
for i in combinations(mesh.edges_for_face[fid], 2)])
new_center_face = [i + nv_offset for i in mesh.edges_for_face[fid]]
inner_edges = list(combinations(new_center_face, 2))
new_edges.extend(inner_edges)
# make new faces: center face
new_faces.append(new_center_face)
# three new faces, one per old vertex:
for fvid in mesh.faces[fid]:
possible_edges = mesh.edges_for_vert[fvid]
face_edges = mesh.edges_for_face[fid]
edges_for_fvid = list(set(possible_edges) & set(face_edges))
assert len(edges_for_fvid) == 2
new_faces.append([
edges_for_fvid[0] + nv_offset,
fvid,
edges_for_fvid[1] + nv_offset
])
return PolygonMesh(new_verts, new_faces, new_edges)