Scenegraph Classes

The end-user facing classes of Wasabi Scenegraph allow users to create simple scenes by combining custom meshes created with tools such as Blender and procedural meshes created with Python code.

The Scene object represents a scene that can be rendered, including a selection of models and lights:

from wasabisg.scenegraph import Scene

scene = Scene(
    ambient=(0.05, 0.05, 0.05, 1.0)
)

We might load a model from an .obj file and add an instance of it to the scene:

from wasabisg.loaders.objloader import ObjFileLoader
from wasabisg.scenegraph import ModelNode

loader = ObjFileLoader()
tree_model = loader.load_obj('tree.obj')

tree = ModelNode(tree_model, pos=(10, 0, 10))
scene.add(tree)

We typically need a light:

from wasabisg.lighting import Light

# Distant light to approximate the sun
sunlight = Light(
    pos=(100, 100, 100),
    colour=(1.0, 1.0, 1.0, 1.0),
    intensity=10,
    falloff=0
)

scene.add(sunlight)

Then the scene can be rendered:

from euclid import Point3
from wasabi.scenegraph import Camera

c = Camera(
    pos=Point3(0, 1, -20),
    look_at=(0, 1, 0),
    width=800,  # or whatever size your viewport is
    height=600
)
scene.render(c)

Of course, you will need code to set up a window with an OpenGL context, and then ensure that the scene is rendered every frame. The camera object can persist between frames; assign to its pos and look_at attributes to move and reorient the camera.

High Level Classes Reference

These high-level classes provide the main API for Wasabi Scenegraph.

class wasabisg.scenegraph.Scene(ambient=(0, 0, 0, 1.0), renderer=<class 'wasabisg.renderer.LightingAccumulationRenderer'>)[source]

A collection of scenegraph objects.

At present this class does little more than render a list of objects; in future however it may support more sophisticated behaviour.

add(obj)[source]

Add obj to the scene.

obj should be a scenegraph node, but currently adding a Mesh or Model directly is supported as a convenience.

clear()[source]

Remove all objects from the scene.

remove(obj)[source]

Remove obj from the scene.

render(camera)[source]

Render the scene with the given camera.

update(dt)[source]

Update all objects in the scene with the given time step.

The camera classes define how the scene is viewed. The width and height parameters should match the viewport into which you are rendering; these are used both to calculate the correct aspect ratio and allocate appropriately sized offscreen buffers when rendering.

class wasabisg.scenegraph.Camera(width=800, height=600, pos=Point3(0.00, 15.00, 15.00), look_at=Point3(0.00, 0.00, 0.00), fov=67.5, near=1.0, far=10000.0)[source]

The camera class is a view onto a scene.

This class offers the ability to set up the projection and modelview matrixes.

Parameters:fov – The field of view in the y direction.
eye_vector()[source]

Get the direction in which the camera is looking.

get_view_matrix()[source]

Get the view matrix as a euclid.Matrix4.

The standard camera applies a perspective. You can alternatively use an orthographic camera so that your scene appears 2D or isometric.

class wasabisg.scenegraph.OrthographicCamera(width=800, height=600, pos=Point3(0.00, 15.00, 15.00), look_at=Point3(0.00, 0.00, 0.00), scale=20.0, near=1.0, far=10000.0)[source]

An orthographic camera.

Parameters:scale – the width of the viewport in world space.
class wasabisg.scenegraph.ModelNode(model, pos=(0, 0, 0), rotation=(0, 0, 1, 0), group=None, transparent=False)[source]

Draw a model at a point in space, with a rotation.

Lights

class wasabisg.lighting.Light(pos=Point3(0.00, 0.00, 0.00), colour=(1, 1, 1, 1), intensity=5, falloff=2)[source]

A point light.

Parameters:
  • pos (euclid.Point3) – The position of the light in the scene.
  • colour – The colour of the light as an RGBA tuple. Typically the A component should be 1.0.
  • intensity – The intensity of the light. This can be arbitrarily high.
  • falloff – The rate of falloff of the light. Bigger numbers mean faster attenuation.
class wasabisg.lighting.Sunlight(direction=Vector3(0.00, 0.00, 0.00), colour=(1, 1, 1, 1), intensity=5)[source]

A sun light (ie. at infinite distance).

Parameters:
  • direction (euclid.Vector3) – The direction TO the sun FROM the scene.
  • colour – The colour of the light as an RGBA tuple. Typically the A component should be 1.0.
  • intensity – The intensity of the light. This can be arbitrarily high.

Table Of Contents

Previous topic

Wasabi Scenegraph

Next topic

Models and Meshes

This Page