コード例 #1
0
from pyrt.geometry import Sphere
from pyrt.material import PhongMaterial
from pyrt.camera import PerspectiveCamera
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)
コード例 #2
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
コード例 #3
0
from pyrt.geometry import Triangle, Sphere, Vertex
from pyrt.material import PhongMaterial
from pyrt.camera import PerspectiveCamera
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,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"
コード例 #4
0
from pyrt.geometry import Triangle, Sphere, Vertex
from pyrt.material import PhongMaterial
from pyrt.camera import PerspectiveCamera
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))
コード例 #5
0
from pyrt.renderer import SimpleRT
from PIL import Image

# Specify width/height 
# width = 320
# height = 240

width = 1280
height = 720

# now create a camera and a view :
camera = PerspectiveCamera(width, height, 90)
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.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=(-20.0, -70.0, 0.0))
B = Vertex(position=( 20.0, -70.0, 0.0))
コード例 #6
0
from pyrt.math import Vec3
from pyrt.scene import Scene
from pyrt.light import PointLight
from pyrt.geometry import Triangle, Sphere, Vertex, TriangleMesh
from pyrt.material import PhongMaterial
from pyrt.camera import PerspectiveCamera
from pyrt.renderer import SimpleRT

# 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()

trimesh = TriangleMesh()
trimesh.load("../data/teapot_simple/teapot.obj")

print(trimesh.stats())

center = trimesh.getCentroid()
print(center)

bbox = trimesh.getBBox()
print(bbox)
コード例 #7
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