def clip_project_lines(camera, lines, color): if len(lines) < 1: return [] lines_rel = [line_map(camera.transform, line) for line in lines] projected_lines = [line_map(project, line) for line in lines_rel] #clip to viewing region if this.view_boundary == 'sphere': view_clipped_lines = remove_None([ Clipping.clip_line_sphere(line, r=this.view_radius) for line in projected_lines ]) if this.view_boundary == 'cylinder': view_clipped_lines = remove_None([ Clipping.clip_line_cylinder(line, r=this.view_radius, h=this.view_height, axis=1) for line in projected_lines ]) if this.view_boundary == 'none': view_clipped_lines = projected_lines if len(view_clipped_lines) < 1: return [] return view_clipped_lines
def clip_and_draw_lines(lines, camera, color, shape, shapes): lines = Clipping.camera_clip_lines(lines, camera) if len(lines) > 1: #clipping = False doubles the framerate if this.clipping: clipped_lines = Clipping.clip_lines(lines, shape, shapes) #draw clipped line draw_lines(camera, clipped_lines, color) else: #noclip draw_lines(camera, lines, color)
def draw(camera, shapes): #initialize frame this.graphics.init_draw() for shape in shapes: shape.update_visibility(camera) #calculate boundaries for clipping if this.clipping: shape.boundaries = Clipping.calc_boundaries( shape.faces, shape.subfaces, camera.pos) #draw shapes for shape in shapes: for face in shape.faces: if face.visible: if this.show_fuzz: draw_face_fuzz(face, camera, shape, shapes) draw_face_lines(face, camera, shape, shapes) #draw boundary of (d-1) screen if this.view_boundary == 'sphere': draw_spherical_boundary() if this.view_boundary == 'cylinder': draw_cylindrical_boundary()
def draw_wireframe(camera, shape, color): #init? lines = [shape.get_edge_line(edge) for edge in shape.edges] lines = Clipping.camera_clip_lines(lines, camera) if len(lines) < 1: return draw_lines(camera, lines, color)
def draw_normals(camera, shape, color): lines = [ Line(face.center, face.center + face.normal) for face in shape.faces ] lines = Clipping.camera_clip_lines(lines, camera) if len(lines) < 1: return draw_lines(camera, lines, color)
def draw_face_fuzz_old(face, camera, shape, shapes): #weights = np.random.uniform(size=[n_points,len(verts)]) #weights = weights/np.sum(weights,axis=1,keepdims=True) #points = np.dot(weights,verts) verts = [shape.verts[i] for i in face.get_verts(shape)] #points = [vec.linterp(verts[0], verts[1], t[0]) + vec.linterp(verts[0], verts[2], t[1]) for t in t_vals] if this.d == 3: points = [ vec.linterp(vec.linterp(verts[0], verts[1], t[0]), vec.linterp(verts[2], verts[3], t[0]), t[1]) for t in this.random_fuzz ] if this.d == 4: points = [ vec.linterp( vec.linterp(vec.linterp(verts[0], verts[1], t[0]), vec.linterp(verts[2], verts[3], t[0]), t[1]), vec.linterp(vec.linterp(verts[4], verts[5], t[0]), vec.linterp(verts[6], verts[7], t[0]), t[1]), t[2]) for t in this.random_fuzz ] #print(points.shape) if this.clipping: clipped = [False for i in range(len(points))] for clipping_shape in shapes: if (clipping_shape is not shape) and (not clipping_shape.transparent): new_clipped = [ Clipping.point_clipped(point, clipping_shape.boundaries) for point in points ] clipped = [ clip1 or clip2 for clip1, clip2 in zip(clipped, new_clipped) ] clipped_points = [ point for point, clip in zip(points, clipped) if (not clip) ] if len(clipped_points) < 1: return draw_points(camera, clipped_points, face.color) else: draw_points(camera, points, face.color)
def draw_points(camera, points, color): clipped_points = [ point for point in points if (not Clipping.point_clipped(point, [camera.plane], small_z)) ] #clipped_points = points #DEBUG if len(clipped_points) < 1: return points_rel = camera.transform(clipped_points) projected_points = [project(point) for point in points_rel] #need to implement clipping into cylinder #clip into sphere if this.view_boundary == 'sphere': projected_points = [ point for point in projected_points if np.dot(point, point) < this.view_radius**2 ] try: if this.d == 3: this.graphics.draw_points_2d(projected_points, color) if this.d == 4: if this.stereo: for dorigin, angles in zip([this.stereo_sep, -this.stereo_sep], this.stereo_view_angles): this.graphics.draw_points_3d(projected_points, color, this.draw_origin + dorigin, angles) else: this.graphics.draw_points_3d(projected_points, color, this.draw_origin, this.view_angles) except: print('problem drawing', points) raise
def draw_face_fuzz(face, camera, shape, shapes): points = face.fuzz_points if this.clipping: clipped = [False for i in range(len(points))] for clipping_shape in shapes: if (clipping_shape is not shape) and (not clipping_shape.transparent): new_clipped = [ Clipping.point_clipped(point, clipping_shape.boundaries) for point in points ] clipped = [ clip1 or clip2 for clip1, clip2 in zip(clipped, new_clipped) ] clipped_points = [ point for point, clip in zip(points, clipped) if (not clip) ] if len(clipped_points) < 1: return draw_points(camera, clipped_points, face.color) else: draw_points(camera, points, face.color)