else:
return self.faces[0]
+ def other_vertex(self, v):
+ if v.index==self.vertices[0].index:
+ return self.vertices[1]
+ else:
+ return self.vertices[0]
+
class Vertex:
def __init__(self, mv):
v.index = len(self.vertices)
self.vertices.append(v)
+ v_edges = []
+ v_edge_keys = set()
for f in g:
- for j in range(len(f.edges)):
- e = f.edges[j]
-
- if self.vertices[i] not in e.vertices:
+ for e in f.edges:
+ if e.key in v_edge_keys or self.vertices[i] not in e.vertices:
continue
- if e.other_face(f) not in g and len(e.faces)>=2:
- e.faces.remove(f)
- e = Edge(e)
- f.edges[j] = e
- e.faces.append(f)
- else:
- del self.edges[e.key]
+ e_faces_in_g = [c for c in e.faces if c in g]
+ boundary = len(e_faces_in_g)<len(e.faces)
+ v_edges.append((e, boundary, e_faces_in_g))
+ v_edge_keys.add(e.key)
- e.vertices[e.vertices.index(self.vertices[i])] = v
+ for e, boundary, e_faces_in_g in v_edges:
+ if boundary:
+ ne = Edge(e)
+ for c in e_faces_in_g:
+ e.faces.remove(c)
+ c.edges[c.edges.index(e)] = ne
+ ne.faces.append(c)
+ e = ne
+ else:
+ del self.edges[e.key]
- e.key = make_edge_key(e.vertices[0].index, e.vertices[1].index)
- self.edges[e.key] = e
+ e.vertices[e.vertices.index(self.vertices[i])] = v
+ e.key = make_edge_key(e.vertices[0].index, e.vertices[1].index)
+ self.edges[e.key] = e
+
+ for f in g:
self.vertices[i].faces.remove(f)
f.vertices[f.vertices.index(self.vertices[i])] = v
v.faces.append(f)
fv = f.pivot_vertices(v)
edge1 = fv[1].co-fv[0].co
edge2 = fv[-1].co-fv[0].co
- weight = 1
- if len(f.get_edge(fv[0], fv[1]).faces)==1:
- weight += 1
- if len(f.get_edge(fv[0], fv[-1]).faces)==1:
- weight += 1
- v.normal += f.normal*edge1.angle(edge2)*weight
- v.normal.normalize()
+ if edge1.length and edge2.length:
+ weight = 1
+ if len(f.get_edge(fv[0], fv[1]).faces)==1:
+ weight += 1
+ if len(f.get_edge(fv[0], fv[-1]).faces)==1:
+ weight += 1
+ v.normal += f.normal*edge1.angle(edge2)*weight
+ if v.normal.length:
+ v.normal.normalize()
+ else:
+ v.normal = mathutils.Vector((0, 0, 1))
else:
# XXX Should use edges to compute normal
- v.normal = mathutils.Vector(0, 0, 1)
+ v.normal = mathutils.Vector((0, 0, 1))
def compute_uv(self):
for v in self.vertices:
f = v.faces[0]
i = f.vertices.index(v)
v.uvs = [u[i] for u in f.uvs]
+ else:
+ v.uvs = [(0.0, 0.0)]*len(self.uv_layers)
def compute_tbn(self, index):
if not self.uv_layers: