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
def render(ents): """entities is dictionary built in obj_parser.parse() representing objects in scene""" #create scene and add objects to scene scene=Scene() for obj in ents['objects']: if isinstance(obj,list): for o in obj: scene.add(o) else: scene.add(obj) if ents['light'] is None: ents['light']=PointLight(Vec3(-1,-8,1)) scene.addLight(ents['light']) scene.setCamera(ents['camera']) engine=SimpleRT(shadow=True,iterations=3) image=engine.render(scene) return image
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 light to the scene scene.addLight(PointLight(Vec3(-1, -8, 1))) # 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)
from pyrt.renderer import SimpleRT from PIL import Image # Specify width/height width = 400 height = 300 # 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()
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 light to the scene scene.addLight(PointLight(Vec3(-1,-8,1))) # 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("11.png")
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, 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 #scene.addLight(PointLight(Vec3(0,5,15))) scene.addLight(SpotLight(Vec3(0, 0, 5), Vec3(-0.5, 0.5, -1), 7)) scene.addLight(SpotLight(Vec3(0, 0, 5), Vec3(0, -1, -1), 15)) #scene.addLight(SpotLight(Vec3(2.5, -2.5, 5), Vec3(0, 0, -1), 5)) # 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.), reflectivity=0.5) 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))
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, 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 scene.addLight(PointLight(Vec3(0,0,15))) # create some materials: floormaterial = PhongMaterial(color=Vec3(0.1,0.1,0.1)) sphere0material = PhongMaterial(color=Vec3(1.,0.,0.), reflectivity=0.5) sphere1material = PhongMaterial(color=Vec3(0.,1.,0.), reflectivity=0.5) sphere2material = PhongMaterial(color=Vec3(0.,0.,1.), reflectivity=0.5) sphere3material = PhongMaterial(color=Vec3(1.,1.,0.), reflectivity=0.5) # 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))
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