Scene

The Scene object provides the central abstraction of the meshrender package. It manages objects, lights, and the camera, and it wraps the key functions that render images.

Scene

class meshrender.Scene(background_color=array([ 1., 1., 1.]), camera=None)

Bases: object

A scene containing objects and lights for 3D OpenGL rendering.

__init__(background_color=array([ 1., 1., 1.]), camera=None)

Initialize a Scene object.

Parameters:
  • background_color ((3,) float) – The background color for the scene.
  • camera (VirtualCamera) – Camera to use for rendering
background_color

(3,) float – The background color for the scene.

objects

dict – Dictionary mapping object names to their corresponding SceneObject.

lights

dict – Dictionary mapping light names to their corresponding PointLight or DirectionalLight.

Note that this doesn’t include the ambient light, since only one of those can exist at a time.

point_lights

list of PointLight – The set of point lights active in the scene.

directional_lights

list of DirectionalLight – The set of directional lights active in the scene.

ambient_light

AmbientLight – The ambient light active in the scene.

camera

VirualCamera – The scene’s camera (None if unassigned).

add_object(name, obj)

Adds an object to the scene.

Parameters:
  • name (str) – An identifier for the object.
  • obj (SceneObject) – A SceneObject representing the object, including its pose and material properties.
remove_object(name)

Removes an object from the scene.

Parameters:name (str) – An identifier for the object to be removed.
Raises:ValueError – If the given name was not assigned to an object in the scene.
add_light(name, light)

Adds a named light to the scene.

Parameters:
remove_light(name)

Removes a light from the scene.

Parameters:name (str) – An identifier for the light to be removed.
Raises:ValueError – If the given name was not assigned to a light in the scene.
close_renderer()

Close the renderer.

render(render_color=True, front_and_back=False)

Render raw images of the scene.

Parameters:
  • render_color (bool) – If True, both a color and a depth image are returned. If False, only a depth image is returned.
  • front_and_back (bool) – If True, all surface normals are treated as if they’re facing the camera.
Returns:

A raw RGB color image with pixel values in [0, 255] and a depth image with true depths expressed as floats. If render_color was False, only the depth image is returned.

Return type:

tuple of (h, w, 3) uint8, (h, w) float32

Raises:

ValueError – If the scene has no set camera.

Note

This function can be called repeatedly, regardless of changes to the scene (i.e. moving SceneObjects, adding and removing lights, moving the camera). However, adding or removing objects causes a new OpenGL context to be created, so put all the objects in the scene before calling it.

Note

Values listed as 0.0 in the depth image are actually at infinity (i.e. no object present at that pixel).

wrapped_render(render_modes, front_and_back=False)

Render images of the scene and wrap them with Image wrapper classes from the Berkeley AUTOLab’s perception module.

Parameters:
  • render_modes (list of perception.RenderMode) – A list of the desired image types to return, from the perception module’s RenderMode enum.
  • front_and_back (bool) – If True, all surface normals are treated as if they’re facing the camera.
Returns:

A list containing a corresponding Image sub-class for each type listed in render_modes.

Return type:

list of perception.Image