[1]:
import fresnel
import math

Interactive scene view#

fresnel provides a Qt widget to interactively display scenes rendered with the path tracer. This is implemented with the PySide2 library. Using jupyter support for this library, you can open an interactive window outside if the browser and interact with it from the jupyter notebook.

First, initialize jupyter’s pyside2 integration.

[2]:
from PySide2 import QtCore
%gui qt

Then, import fresnel.interact. This must be done after %gui qt.

[ ]:
import fresnel.interact

Build a scene

[ ]:
position = []
for k in range(5):
    for i in range(5):
        for j in range(5):
            position.append([2*i, 2*j, 2*k])
scene = fresnel.Scene()
scene.lights[1].theta = math.pi

geometry = fresnel.geometry.Sphere(scene, position = position, radius=1.0)
geometry.material = fresnel.material.Material(color=fresnel.color.linear([0.1,0.1,0.8]),
                                              roughness=0.1,
                                              specular=1.0)
scene.camera = fresnel.camera.Orthographic.fit(scene)

SceneView widget#

Create a interact.SceneView widget to visualize the scene.

[ ]:
view = fresnel.interact.SceneView(scene)

When the SceneView is the result of a cell, the windows shows and gets focus. In JupyterLab environments, you may need to use view.show()

[ ]:
view

# use view.show() if in JupyterLab

In the new window, you can click and drag to rotate the camera. Jupyter is still running so you can query changes to the window here. For example, after rotating the camera, inspect the new camera configuration:

[ ]:
repr(scene.camera)

After you change scene properties, call setScene to re-render the scene with the changes. For example: change the material color.

[ ]:
geometry.material.color = fresnel.color.linear([0.8,0.1,0.1])
view.setScene(scene)

This page was generated from a jupyter notebook. You can download and run the notebook locally from the fresnel-examples repository.