def get_intersection_dictionary(bm, edge_indices): if hasattr(bm.verts, "ensure_lookup_table"): bm.verts.ensure_lookup_table() bm.edges.ensure_lookup_table() permutations = get_valid_permutations(bm, edge_indices) k = defaultdict(list) d = defaultdict(list) for edges in permutations: raw_vert_indices = cm.vertex_indices_from_edges_tuple(bm, edges) vert_vectors = cm.vectors_from_indices(bm, raw_vert_indices) points = LineIntersect(*vert_vectors) # some can be skipped. (NaN, None, not on both edges) if can_skip(points, vert_vectors): continue # reaches this point only when an intersection happens on both edges. [k[edge].append(points[0]) for edge in edges] # k will contain a dict of edge indices and points found on those edges. for edge_idx, unordered_points in k.items(): tv1, tv2 = bm.edges[edge_idx].verts v1 = bm.verts[tv1.index].co v2 = bm.verts[tv2.index].co ordered_points = order_points((v1, v2), unordered_points) d[edge_idx].extend(ordered_points) return d
def checkVTX(self, context): ''' - decides VTX automatically. - remembers edges attached to current selection, for later. ''' # [x] if either of these edges share a vertex, return early. indices = cm.vertex_indices_from_edges_tuple(self.bm, self.selected_edges) if cm.duplicates(indices): msg = "edges share a vertex, degenerate case, returning early" self.report({"WARNING"}, msg) return False # [x] find which edges intersect getVTX(self) # [x] check coplanar, or parallel. if [] == self.edges: coplanar = cm.test_coplanar(self.edge1, self.edge2) if not coplanar: msg = "parallel or not coplanar! returning early" self.report({"WARNING"}, msg) return False return True
def checkVTX(self, context): ''' - decides VTX automatically. - remembers edges attached to current selection, for later. ''' # [x] if either of these edges share a vertex, return early. indices = cm.vertex_indices_from_edges_tuple(self.bm, self.selected_edges) if cm.duplicates(indices): msg = "edges share a vertex, degenerate case, returning early" self.report({"WARNING"}, msg) return False # [x] find which edges intersect getVTX(self) # [x] check coplanar, or parallel. if [] == self.edges: coplanar = cm.test_coplanar(self.edge1, self.edge2) if not coplanar: msg = "parallel or not coplanar! returning early" self.report({"WARNING"}, msg) return False return True
def get_intersection_dictionary(bm, edge_indices): if hasattr(bm.verts, "ensure_lookup_table"): bm.verts.ensure_lookup_table() bm.edges.ensure_lookup_table() permutations = get_valid_permutations(bm, edge_indices) k = defaultdict(list) d = defaultdict(list) for edges in permutations: raw_vert_indices = cm.vertex_indices_from_edges_tuple(bm, edges) vert_vectors = cm.vectors_from_indices(bm, raw_vert_indices) points = LineIntersect(*vert_vectors) # some can be skipped. (NaN, None, not on both edges) if can_skip(points, vert_vectors): continue # reaches this point only when an intersection happens on both edges. [k[edge].append(points[0]) for edge in edges] # k will contain a dict of edge indices and points found on those edges. for edge_idx, unordered_points in k.items(): tv1, tv2 = bm.edges[edge_idx].verts v1 = bm.verts[tv1.index].co v2 = bm.verts[tv2.index].co ordered_points = order_points((v1, v2), unordered_points) d[edge_idx].extend(ordered_points) return d
def remove_permutations_that_share_a_vertex(bm, permutations): ''' Get useful Permutations ''' final_permutations = [] for edges in permutations: raw_vert_indices = cm.vertex_indices_from_edges_tuple(bm, edges) if cm.duplicates(raw_vert_indices): continue # reaches this point if they do not share. final_permutations.append(edges) return final_permutations
def remove_permutations_that_share_a_vertex(bm, permutations): ''' Get useful Permutations ''' final_permutations = [] for edges in permutations: raw_vert_indices = cm.vertex_indices_from_edges_tuple(bm, edges) if cm.duplicates(raw_vert_indices): continue # reaches this point if they do not share. final_permutations.append(edges) return final_permutations
def doVTX(self): ''' At this point we know that there is an intersection, and if it is V, T or X. - If both are None, then both edges are projected towards point. (V) - If only one is None, then it's a projection onto a real edge (T) - Else, then the intersection lies on both edges (X) ''' print('point:', self.point) print('edges selected:', self.idx1, self.idx2) print('edges to use:', self.edges) self.bm.verts.new((self.point)) earmarked = self.edges pt = self.point # V (projection of both edges) if [] == earmarked: cl_vert1 = cm.closest_idx(pt, self.bm.edges[self.idx1]) cl_vert2 = cm.closest_idx(pt, self.bm.edges[self.idx2]) add_edges(self, [cl_vert1, cl_vert2]) # X (weld intersection) elif len(earmarked) == 2: vector_indices = cm.vertex_indices_from_edges_tuple(self.bm, earmarked) add_edges(self, vector_indices) # T (extend towards) else: to_edge_idx = self.edges[0] from_edge_idx = self.idx1 if to_edge_idx == self.idx2 else self.idx2 # make 3 new edges: 2 on the towards, 1 as extender cl_vert = cm.closest_idx(pt, self.bm.edges[from_edge_idx]) to_vert1, to_vert2 = cm.vert_idxs_from_edge_idx(self.bm, to_edge_idx) roto_indices = [cl_vert, to_vert1, to_vert2] add_edges(self, roto_indices) # final refresh before returning to user. if earmarked: remove_earmarked_edges(self, earmarked) bmesh.update_edit_mesh(self.me, True)
def doVTX(self): ''' At this point we know that there is an intersection, and if it is V, T or X. - If both are None, then both edges are projected towards point. (V) - If only one is None, then it's a projection onto a real edge (T) - Else, then the intersection lies on both edges (X) ''' print('point:', self.point) print('edges selected:', self.idx1, self.idx2) print('edges to use:', self.edges) self.bm.verts.new((self.point)) earmarked = self.edges pt = self.point # V (projection of both edges) if [] == earmarked: cl_vert1 = cm.closest_idx(pt, self.bm.edges[self.idx1]) cl_vert2 = cm.closest_idx(pt, self.bm.edges[self.idx2]) add_edges(self, [cl_vert1, cl_vert2]) # X (weld intersection) elif len(earmarked) == 2: vector_indices = cm.vertex_indices_from_edges_tuple(self.bm, earmarked) add_edges(self, vector_indices) # T (extend towards) else: to_edge_idx = self.edges[0] from_edge_idx = self.idx1 if to_edge_idx == self.idx2 else self.idx2 # make 3 new edges: 2 on the towards, 1 as extender cl_vert = cm.closest_idx(pt, self.bm.edges[from_edge_idx]) to_vert1, to_vert2 = cm.vert_idxs_from_edge_idx(self.bm, to_edge_idx) roto_indices = [cl_vert, to_vert1, to_vert2] add_edges(self, roto_indices) # final refresh before returning to user. if earmarked: remove_earmarked_edges(self, earmarked) bmesh.update_edit_mesh(self.me, True)