def init_points(self): for vect in [OUT, RIGHT, UP, LEFT, DOWN, IN]: face = Square3D(resolution=self.square_resolution) face.shift(OUT) face.apply_matrix(z_to_vector(vect)) self.add(face) self.set_height(self.side_length)
def get_triangulation(self, normal_vector=None): # Figure out how to triangulate the interior to know # how to send the points as to the vertex shader. # First triangles come directly from the points if normal_vector is None: normal_vector = self.get_unit_normal() if not self.needs_new_triangulation: return self.triangulation points = self.get_points() if len(points) <= 1: self.triangulation = np.zeros(0, dtype="i4") self.needs_new_triangulation = False return self.triangulation if not np.isclose(normal_vector, OUT).all(): # Rotate points such that unit normal vector is OUT points = np.dot(points, z_to_vector(normal_vector)) indices = np.arange(len(points), dtype=int) b0s = points[0::3] b1s = points[1::3] b2s = points[2::3] v01s = b1s - b0s v12s = b2s - b1s crosses = cross2d(v01s, v12s) convexities = np.sign(crosses) atol = self.tolerance_for_point_equality end_of_loop = np.zeros(len(b0s), dtype=bool) end_of_loop[:-1] = (np.abs(b2s[:-1] - b0s[1:]) > atol).any(1) end_of_loop[-1] = True concave_parts = convexities < 0 # These are the vertices to which we'll apply a polygon triangulation inner_vert_indices = np.hstack( [ indices[0::3], indices[1::3][concave_parts], indices[2::3][end_of_loop], ] ) inner_vert_indices.sort() rings = np.arange(1, len(inner_vert_indices) + 1)[inner_vert_indices % 3 == 2] # Triangulate inner_verts = points[inner_vert_indices] inner_tri_indices = inner_vert_indices[ earclip_triangulation(inner_verts, rings) ] tri_indices = np.hstack([indices, inner_tri_indices]) self.triangulation = tri_indices self.needs_new_triangulation = False return tri_indices
def generate_points(self): for vect in IN, OUT, LEFT, RIGHT, UP, DOWN: face = Square( side_length=self.side_length, shade_in_3d=True, ) face.flip() face.shift(self.side_length * OUT / 2.0) face.apply_matrix(z_to_vector(vect)) self.add(face)
def new_sector(self, r, dr, lower_angle, upper_angle): alpha = self.max_opacity * self.opacity_function(r) annular_sector = AnnularSector(inner_radius=r, outer_radius=r + dr, color=self.color, fill_opacity=alpha, start_angle=lower_angle, angle=upper_angle - lower_angle) # rotate (not project) it into the viewing plane rotation_matrix = z_to_vector(self.projection_direction()) annular_sector.apply_matrix(rotation_matrix) # now rotate it inside that plane rotated_RIGHT = np.dot(RIGHT, rotation_matrix.T) projected_RIGHT = self.project(RIGHT) omega = angle_between_vectors(rotated_RIGHT, projected_RIGHT) annular_sector.rotate(omega, axis=self.projection_direction()) annular_sector.move_arc_center_to(self.get_source_point()) return annular_sector
def new_sector(self, r, dr, lower_angle, upper_angle): alpha = self.max_opacity * self.opacity_function(r) annular_sector = AnnularSector( inner_radius=r, outer_radius=r + dr, color=self.color, fill_opacity=alpha, start_angle=lower_angle, angle=upper_angle - lower_angle ) # rotate (not project) it into the viewing plane rotation_matrix = z_to_vector(self.projection_direction()) annular_sector.apply_matrix(rotation_matrix) # now rotate it inside that plane rotated_RIGHT = np.dot(RIGHT, rotation_matrix.T) projected_RIGHT = self.project(RIGHT) omega = angle_between_vectors(rotated_RIGHT, projected_RIGHT) annular_sector.rotate(omega, axis=self.projection_direction()) annular_sector.move_arc_center_to(self.get_source_point()) return annular_sector
def init_points(self): super().init_points() self.scale(self.radius) self.set_depth(self.height, stretch=True) self.apply_matrix(z_to_vector(self.axis)) return self