Metal MaterialsΒΆ

In this example we load some example metal materials from the raysect library.

from matplotlib.pyplot import *

from raysect.primitive import Sphere, Box, Cylinder, Subtract
from raysect.optical import World, translate, rotate, Point3D, d65_white, ConstantSF, Vector3D, Node
from raysect.optical.observer import PinholeCamera
from raysect.optical.library import Gold, Silver, Copper, Titanium, Aluminium
from raysect.optical.material import Lambert, UniformSurfaceEmitter, LinearPolariser


def polariser(parent=None, transform=None):

    assembly = Node(parent=parent, transform=transform)

    polariser = Cylinder(
        radius=0.101, height=0.002, parent=assembly, transform=translate(0, 0, -0.001),
        material=LinearPolariser(Vector3D(0, 1, 0))
    )

    body = Subtract(
        Cylinder(radius=0.11, height=0.010),
        Cylinder(radius=0.1, height=0.011, transform=translate(0, 0, -0.0005)),
        parent=assembly,
        transform=translate(0, 0, -0.005),
        material=Lambert(ConstantSF(0.05))
    )

    handle = Cylinder(
        radius=0.004, height=0.021, parent=assembly,
        transform=translate(0, 0.109, 0)*rotate(0, 90, 0),
        material=Lambert(ConstantSF(0.05))
    )

    return assembly


world = World()

Sphere(0.5, world, transform=translate(1.2, 0.5001, 0.6), material=Gold())
Sphere(0.5, world, transform=translate(0.6, 0.5001, -0.6), material=Silver())
Sphere(0.5, world, transform=translate(0, 0.5001, 0.6), material=Copper())
Sphere(0.5, world, transform=translate(-0.6, 0.5001, -0.6), material=Titanium())
Sphere(0.5, world, transform=translate(-1.2, 0.5001, 0.6), material=Aluminium())

Box(Point3D(-100, -0.1, -100), Point3D(100, 0, 100), world, material=Lambert(ConstantSF(1.0)))
Cylinder(3.0, 8.0, world, transform=translate(4, 8, 0) * rotate(90, 0, 0), material=UniformSurfaceEmitter(d65_white, 1.0))

camera = PinholeCamera((512, 512), parent=world, transform=translate(0, 4, -3.5) * rotate(0, -48, 0))
camera.spectral_bins = 15
camera.pixel_samples = 100

# p1 = polariser(parent=camera, transform=translate(0, 0, 0.2)*rotate(0, 0, 90))

# start ray tracing
ion()
timestamp = time.strftime("%Y-%m-%d_%H-%M-%S")
for p in range(1, 1000):
    print("Rendering pass {}...".format(p))
    camera.observe()
    camera.pipelines[0].save(f'demo_metal_{timestamp}_{p}_samples.png')
    print()

# display final result
ioff()
camera.display()
show()
../../_images/metal_balls.png