def by_outside(self, vertices, edges, faces): vertex_normals, face_normals = calc_mesh_normals( vertices, edges, faces) percent = self.inputs['Percent'].sv_get(default=[1.0])[0][0] center = self.inputs['Center'].sv_get()[0][0] center = Vector(center) def get_center(face): verts = [Vector(vertices[i]) for i in face] result = Vector((0, 0, 0)) for v in verts: result += v return (1.0 / float(len(verts))) * result values = [] for face, normal in zip(faces, face_normals): face_center = get_center(face) direction = face_center - center dirlength = direction.length if dirlength > 0: value = math.pi - direction.angle(normal) else: value = math.pi values.append(value) threshold = self.map_percent(values, percent) out_face_mask = [(value >= threshold) for value in values] out_faces = [ face for (face, mask) in zip(faces, out_face_mask) if mask ] out_verts_mask = self.select_verts_by_faces(out_faces, vertices) out_edges_mask = self.select_edges_by_verts(out_verts_mask, edges) return out_verts_mask, out_edges_mask, out_face_mask
def by_outside(vertices, edges, faces, percent, center): face_normals, _ = calc_mesh_normals(vertices, edges, faces) center = Vector(center[0]) def get_center(face): verts = [Vector(vertices[i]) for i in face] result = Vector((0, 0, 0)) for v in verts: result += v return (1.0 / float(len(verts))) * result values = [] for face, normal in zip(faces, face_normals): face_center = get_center(face) direction = face_center - center dirlength = direction.length if dirlength > 0: value = math.pi - direction.angle(normal) else: value = math.pi values.append(value) threshold = map_percent(values, percent[0]) out_face_mask = [(value >= threshold) for value in values] return out_face_mask
def by_outside(self, vertices, edges, faces): vertex_normals, face_normals = calc_mesh_normals(vertices, edges, faces) percent = self.inputs['Percent'].sv_get(default=[1.0])[0][0] center = self.inputs['Center'].sv_get()[0][0] center = Vector(center) def get_center(face): verts = [Vector(vertices[i]) for i in face] result = Vector((0,0,0)) for v in verts: result += v return (1.0/float(len(verts))) * result values = [] for face, normal in zip(faces, face_normals): face_center = get_center(face) direction = face_center - center dirlength = direction.length if dirlength > 0: value = math.pi - direction.angle(normal) else: value = math.pi values.append(value) threshold = self.map_percent(values, percent) out_face_mask = [(value >= threshold) for value in values] out_faces = [face for (face, mask) in zip(faces, out_face_mask) if mask] out_verts_mask = self.select_verts_by_faces(out_faces, vertices) out_edges_mask = self.select_edges_by_verts(out_verts_mask, edges) return out_verts_mask, out_edges_mask, out_face_mask
def by_normal(vertices, edges, faces, percent, direction): face_normals, _ = calc_mesh_normals(vertices, edges, faces) np_verts = np.array(face_normals) np_dir = np.array(direction) np_dir, np_percent = numpy_match_long_repeat([np_dir, np.array(percent)]) values = np_dot(np_verts[:, np.newaxis], np_dir[np.newaxis, :], axis=2) threshold = map_percent(values, np_percent) out_face_mask = np.any(values >= threshold, axis=1) return out_face_mask
def by_normal(self, vertices, edges, faces): vertex_normals, face_normals = calc_mesh_normals(vertices, edges, faces) percent = self.inputs['Percent'].sv_get(default=[1.0])[0][0] direction = self.inputs['Direction'].sv_get()[0][0] values = [Vector(n).dot(direction) for n in face_normals] threshold = self.map_percent(values, percent) out_face_mask = [(value >= threshold) for value in values] out_faces = [face for (face, mask) in zip(faces, out_face_mask) if mask] out_verts_mask = self.select_verts_by_faces(out_faces, vertices) out_edges_mask = self.select_edges_by_verts(out_verts_mask, edges) return out_verts_mask, out_edges_mask, out_face_mask