def parseSphere(entity): """process a dictionary (entity) containing info about a sphere and return a pyrt.geometry.Sphere() object entity= { "type":"sphere", "radius":"string representing a float number", "center":"x,y,z",#string of float numbers seperated by commas "color":"r,g,b" #int 0-255 seperated by commas, "reflectivity":"string representing a float number 0-1" } """ if entity['type'] != "sphere": raise ValueError("entity passed to parseSphere() is not a sphere") s_center = Vec3(entity['center'].split(',')) s_color = entity['color'].split(',') s_color = Vec3(s_color) s_color.normalize() if "reflectivity" in entity: s_reflect = float(entity['reflectivity']) s_material = PhongMaterial(color=s_color, reflectivity=s_reflect) else: s_material = PhongMaterial(color=s_color) s_radius = float(entity['radius']) return Sphere(center=s_center, radius=s_radius, material=s_material)
vp = camera.projection * camera.view # Create a scene scene = Scene() # Add a light to the scene scene.addLight(PointLight(Vec3(0, -5, 0))) # Create a triangle t = Triangle(Vertex(position=(-5, 1, 0), texcoord=(0, 0)), Vertex(position=(0, 1, 5), texcoord=(1, 0)), Vertex(position=(5, 1, 0), texcoord=(1, 1)), material=TextureMaterial(texturepath=['tex16.png'])) s = Sphere(center=Vec3(0, -3, 0), radius=1, material=TextureMaterial(texturepath=['tex16.png'])) # Add triangle and sphere to the scene: scene.add(t) scene.add(s) # Now tell the scene which camera we use scene.setCamera(camera) # Create a raytracer using "SimpleRT" engine = SimpleRT() # Render the scene: image = engine.render(scene)
from pyrt.renderer import SimpleRT from PIL import Image # Specify width/height as in example 5 width = 320 height = 240 # now create a camera and a view like in example 5: camera = PerspectiveCamera(width, height, 60) camera.setView(Vec3(0,-10,0), Vec3(0,0,0), Vec3(0,0,1)) # Create a scene scene = Scene() # Add a sphere to the scene: scene.add(Sphere(center=Vec3(0.,0.,0.), radius=3., material=PhongMaterial(color=Vec3(1.,0.,0.)))) # Now tell the scene which camera we use scene.setCamera(camera) # Create a raytracer using "SimpleRT" engine = SimpleRT() # Render the scene: image = engine.render(scene) # Save the resulting image using pillow image.save("10.png")
# now create a camera and a view like in example 5: camera = PerspectiveCamera(width, height, 60) camera.setView(Vec3(0, -10, 0), Vec3(0, 0, 0), Vec3(0, 0, 1)) # Create a scene scene = Scene() # Add a light to the scene scene.addLight(PointLight(Vec3(0, 0, 0))) # Create material with normal mappings material0 = NormalMappedMaterial(texturepath='tex16.png', normalmappath='normalmap.png') material1 = TextureMaterial(texturepath='tex16.png') # Add spheres to the scene: scene.add(Sphere(center=Vec3(-3.5, 0., 0.), radius=2.8, material=material0)) scene.add(Sphere(center=Vec3(3.5, 0., 0.), radius=2.8, material=material1)) # Now tell the scene which camera we use scene.setCamera(camera) # Create a raytracer using "SimpleRT" engine = SimpleRT() # Render the scene: image = engine.render(scene) # Save the resulting image using pillow image.save("18.png")
# Add "floor" A = Vertex(position=(-5.0, -5.0, 0.0)) B = Vertex(position=(5.0, -5.0, 0.0)) C = Vertex(position=(5.0, 5.0, 0.0)) D = Vertex(position=(-5.0, 5.0, 0.0)) scene.add(Triangle(A, B, C, material=floormaterial)) scene.add(Triangle(A, C, D, material=floormaterial)) # Add some spheres #scene.add(Sphere(center=Vec3(-2.5,-2.5,1.75), radius=1.75, material=sphere0material)) scene.add( Sphere(center=Vec3(2.5, -2.5, 1.75), radius=1.75, material=sphere1material)) scene.add( Sphere(center=Vec3(2.5, 2.5, 1.75), radius=1.75, material=sphere2material)) scene.add( Sphere(center=Vec3(-2.5, 2.5, 1.75), radius=1.75, material=sphere3material)) # Now tell the scene which camera we use scene.setCamera(camera) # Create a raytracer using "SimpleRT" engine = SimpleRT(shadow=True, iterations=3) # Render the scene: image = engine.render(scene)
sphere2material = PhongMaterial(color=Vec3(0.,0.,1.)) sphere3material = PhongMaterial(color=Vec3(1.,1.,0.)) # Add "floor" A = Vertex(position=(-20.0, -70.0, 0.0)) B = Vertex(position=( 20.0, -70.0, 0.0)) C = Vertex(position=( 20.0, 10.0, 0.0)) D = Vertex(position=(-20.0, 10.0, 0.0)) scene.add(Triangle(A,B,C, material=floormaterial)) scene.add(Triangle(A,C,D, material=floormaterial)) # Add some spheres scene.add(Sphere(center=Vec3(-2.5,-8.0,1.75), radius=1.75, material=sphere0material)) scene.add(Sphere(center=Vec3( 2.5,-8.0,1.75), radius=1.75, material=sphere1material)) scene.add(Sphere(center=Vec3( 2.5, 5.0,1.75), radius=1.75, material=sphere2material)) scene.add(Sphere(center=Vec3(-2.5,-3.5,1.75), radius=1.75, material=sphere3material)) scene.add(Sphere(center=Vec3(10.0,10.0,5.0), radius=1.75, material=PhongMaterial(color=Vec3(1.,0.,0.)))) scene.add(Sphere(center=Vec3(-10.0,5.0,5.0), radius=3., material=PhongMaterial(color=Vec3(1.,.5,0.)))) # Now tell the scene which camera we use scene.setCamera(camera) # Create a raytracer using "SimpleRT" engine = SimpleRT(shadow=True) # Render the scene: image = engine.render(scene)
def make_frame(t): # Specify width/height as in example 5 width = 320 height = 240 # now create a camera and a view like in example 5: camera = PerspectiveCamera(width, height, 45) camera.setView(Vec3(0., -10., 10.), Vec3(0., 0., 0.), Vec3(0., 0., 1.)) # Create a scene scene = Scene() # Add a light to the scene radius = 3.0 p = 2 * pi / 4 x = radius * cos(t * p) y = radius * sin(t * p) scene.addLight(PointLight(Vec3(x, y, 10))) # create some materials: floormaterial = PhongMaterial(color=Vec3(0.5, 0.5, 0.5)) sphere0material = PhongMaterial(color=Vec3(1., 0., 0.)) sphere1material = PhongMaterial(color=Vec3(0., 1., 0.)) sphere2material = PhongMaterial(color=Vec3(0., 0., 1.)) sphere3material = PhongMaterial(color=Vec3(1., 1., 0.)) # Add "floor" A = Vertex(position=(-5.0, -5.0, 0.0)) B = Vertex(position=(5.0, -5.0, 0.0)) C = Vertex(position=(5.0, 5.0, 0.0)) D = Vertex(position=(-5.0, 5.0, 0.0)) scene.add(Triangle(A, B, C, material=floormaterial)) scene.add(Triangle(A, C, D, material=floormaterial)) # Add some spheres scene.add( Sphere(center=Vec3(-2.5, -2.5, 1.75), radius=1.75, material=sphere0material)) scene.add( Sphere(center=Vec3(2.5, -2.5, 1.75), radius=1.75, material=sphere1material)) scene.add( Sphere(center=Vec3(2.5, 2.5, 1.75), radius=1.75, material=sphere2material)) scene.add( Sphere(center=Vec3(-2.5, 2.5, 1.75), radius=1.75, material=sphere3material)) # Now tell the scene which camera we use scene.setCamera(camera) # Create a raytracer using "SimpleRT" engine = SimpleRT(shadow=True) # Render the scene: image = engine.render(scene) return image.data