def add_point_light(self, light): sphere = Instance(Sphere(Point3(0, 0, 0), 0.1, material=Emissive())) sphere.translate(light.location.x, light.location.y, light.location.z) sphere.casts_shadows = False self.geometry.append(sphere) self.lights.append(light)
def __init__(self, config): self.tracer = Tracer(self) self.sampler = Sampler(config.samples) self.view_plane = ViewPlane() self.background_color = RGBColor(0.1, 0.1, 0.1) self.camera = Camera() self.geometry = [] self.lights = [] self.data = numpy.zeros((self.view_plane.vres, self.view_plane.hres, 3), dtype=numpy.uint8) mesh = load_obj("teapot.obj") triangles = [] if config.debug: for face in mesh.faces: triangle = SmoothMeshTriangle(mesh, face, material=Phong(RGBColor.Red())) self.add_geometry(triangle) else: for face in mesh.faces: triangle = Instance(SmoothMeshTriangle(mesh, face, material=Normal())) triangle.scale(0.02, 0.02, 0.02) triangle.rotate_y(math.pi/10.0) triangle.translate(-1, -1.2, -5) triangles.append(triangle) disk = Instance(Disk(Point3(0, 0, 0), Vector3(0, 0, 1), 5, material=Matte(RGBColor(0.9, 0.9, 0.9)))) disk.translate(0, 0, -8) self.add_geometry(disk) # sphere = Instance(Sphere(Point3(0, 0, 0), 1, material=Matte(RGBColor.Red()))) # sphere.translate(-1, 0, -5) grid = Grid() grid.setup(triangles) self.add_geometry(grid) self.ambient_light = AmbientLight() self.add_point_light(PointLight(Point3(-2.5, -1.5, -1.0)))