cc: update old verts
This commit is contained in:
parent
198a7d7ca8
commit
a00f1cb59a
@ -33,11 +33,11 @@ def refine(mesh):
|
||||
e_vert_offset = len(new_vertices)
|
||||
|
||||
# For each edge, add an edge point.
|
||||
for cur_edge_id, cur_edge in enumerate(mesh.edges):
|
||||
for old_edge_id, old_edge in enumerate(mesh.edges):
|
||||
# make mapping from edge -> new_face_vert for later
|
||||
face_ids_for_edge = mesh.faces_for_edge[cur_edge_id]
|
||||
face_ids_for_edge = mesh.faces_for_edge[old_edge_id]
|
||||
for fid in face_ids_for_edge:
|
||||
edge_vids_for[fid].append(cur_edge_id)
|
||||
edge_vids_for[fid].append(old_edge_id)
|
||||
|
||||
tmp_verts = []
|
||||
|
||||
@ -46,7 +46,7 @@ def refine(mesh):
|
||||
tmp_verts.extend([new_vertices[f + f_vert_offset] for f in face_ids_for_edge])
|
||||
|
||||
# ... and its two original endpoints.
|
||||
tmp_verts.extend([mesh.vertices[vid] for vid in cur_edge])
|
||||
tmp_verts.extend([mesh.vertices[vid] for vid in old_edge])
|
||||
|
||||
# centroid == average
|
||||
new_vertices.append(centroid(tmp_verts))
|
||||
@ -80,9 +80,9 @@ def refine(mesh):
|
||||
|
||||
R = centroid(e_verts)
|
||||
# where each edge midpoint is the average of its two endpoint vertices.
|
||||
# Move each original point to the point (or add it to new_verts)
|
||||
# **Move** each original point to the point (or add it to new_verts)
|
||||
new_vertex_point = (F + 2 * R + (len(edges) - 3) * new_vertices[new_vid]) / len(edges)
|
||||
new_vertices.append(new_vertex_point)
|
||||
new_vertices[new_vid] = new_vertex_point
|
||||
|
||||
return PolygonMesh(vertices=new_vertices, edges=new_edges, faces=new_faces)
|
||||
|
||||
@ -94,4 +94,4 @@ if __name__ == '__main__':
|
||||
cube = json.load(open('blender/samples/cube.json', 'r'))
|
||||
p = PolygonMesh(**cube)
|
||||
q = refine(p)
|
||||
print q
|
||||
print json.dumps({'vertices': [list(v) for v in q.vertices]})
|
||||
|
Loading…
Reference in New Issue
Block a user