diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-05-24 16:18:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-05-24 16:18:12 +0400 |
commit | 8c767ce0e88d611c95a21e97ee08c512cdd9392e (patch) | |
tree | 088fe7fb941ead685c06c765282280b819f3093f /release | |
parent | 4178b44b353e51139954d4b954e9234cdc172507 (diff) |
utility function for mesh data types
mesh.edge_loops_from_edges(edges=None)
Lets you get edge loops from python either from the entire mesh or from by passing an edge list.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpy_types.py | 69 | ||||
-rw-r--r-- | release/scripts/op/uvcalc_follow_active.py | 2 |
2 files changed, 68 insertions, 3 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index edead35dafe..cf8e0c8c328 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -303,7 +303,7 @@ class Mesh(bpy_types.ID): edge_face_count_dict = self.edge_face_count_dict return [edge_face_count_dict.get(ed.key, 0) for ed in self.edges] - def edge_loops(self, faces=None, seams=()): + def edge_loops_from_faces(self, faces=None, seams=()): """ Edge loops defined by faces @@ -314,7 +314,7 @@ class Mesh(bpy_types.ID): return a list of edge key lists [ [(0,1), (4, 8), (3,8)], ...] - optionaly, seams are edge keys that will be removed + return a list of edge vertex index lists """ OTHER_INDEX = 2, 3, 0, 1 # opposite face index @@ -379,6 +379,71 @@ class Mesh(bpy_types.ID): return edge_loops + def edge_loops_from_edges(self, edges=None): + """ + Edge loops defined by edges + + Takes me.edges or a list of edges and returns the edge loops + + return a list of vertex indices. + [ [1, 6, 7, 2], ...] + + closed loops have matching start and end values. + """ + line_polys = [] + + # Get edges not used by a face + if edges is None: + edges = self.edges + + if not hasattr(edges, "pop"): + edges = edges[:] + + edge_dict= dict((ed.key, ed) for ed in self.edges if ed.selected) + + while edges: + current_edge= edges.pop() + vert_end, vert_start = current_edge.verts[:] + line_poly = [vert_start, vert_end] + + ok = True + while ok: + ok = False + #for i, ed in enumerate(edges): + i = len(edges) + while i: + i -= 1 + ed = edges[i] + v1, v2 = ed.verts + if v1 == vert_end: + line_poly.append(v2) + vert_end = line_poly[-1] + ok = 1 + del edges[i] + #break + elif v2 == vert_end: + line_poly.append(v1) + vert_end = line_poly[-1] + ok = 1 + del edges[i] + #break + elif v1 == vert_start: + line_poly.insert(0, v2) + vert_start = line_poly[0] + ok = 1 + del edges[i] + #break + elif v2 == vert_start: + line_poly.insert(0, v1) + vert_start = line_poly[0] + ok = 1 + del edges[i] + #break + line_polys.append(line_poly) + + return line_polys + + class MeshEdge(StructRNA): __slots__ = () diff --git a/release/scripts/op/uvcalc_follow_active.py b/release/scripts/op/uvcalc_follow_active.py index c8a13441048..81229f73461 100644 --- a/release/scripts/op/uvcalc_follow_active.py +++ b/release/scripts/op/uvcalc_follow_active.py @@ -180,7 +180,7 @@ def extend(obj, operator, EXTEND_MODE): #SEAM = me.edges.seam if EXTEND_MODE == 'LENGTH': - edge_loops = me.edge_loops(face_sel, [ed.key for ed in me.edges if ed.seam]) + edge_loops = me.edge_loops_from_faces(face_sel, [ed.key for ed in me.edges if ed.seam]) me_verts = me.verts for loop in edge_loops: looplen = [0.0] |