Viewer

This package comes with a 3D viewer which allows one to navigate around a scene using a camera controlled by a virtual trackball.

SceneViewer

class meshrender.SceneViewer(scene, size=(640, 480), **flags)

Bases: pyglet.window.Window

An interactive viewer for a 3D scene.

This doesn’t use the scene’s camera - instead, it uses one based on a trackball.

The basic commands for moving about the scene are given as follows:

  • To rotate the camera about the center of the scene, hold the left mouse button and drag the cursor.

  • To rotate the camera about its viewing axis, hold CTRL and then hold the left mouse button and drag the cursor.

  • To pan the camera, do one of the following:

    • Hold SHIFT, then hold the left mouse button and drag the cursor.
    • Hold the middle mouse button and drag the cursor.
  • To zoom the camera in or our, do one of the following:

    • Scroll the mouse wheel.
    • Hold the right mouse button and drag the cursor.

Other keyboard commands are as follows:

  • z – resets the view to the original view.
  • w – toggles wireframe mode for each mesh in the scene.
  • l – toggles between raymond lighting and the scene’s default lights.
  • a – toggles rotational animation.
  • n – toggles ‘bad normals’ mode.
  • q – quits the viewer
  • s – saves the current image
  • r – starts a recording session, pressing again stops (saves animation as .gif)
__init__(scene, size=(640, 480), **flags)

Initialize a scene viewer and open the viewer window.

Parameters:
  • scene (Scene) – A scene to view. The scene’s camera is not used.
  • size ((int, int)) – The width and height of the target window in pixels.
  • flags (other kwargs) – Other optional keyword arguments.

Note

The possible set of flags are given in the Other Parameters section.

Other Parameters:
 
  • line_width (float) – Sets the line width for wireframe meshes (default is 1).
  • flip_wireframe (bool) – If True, inverts the ‘wireframe’ material property for all meshes.
  • raymond_lighting (bool) – If True, the scene’s point and directional lights are discarded in favor of a set of three directional lights that move with the camera.
  • front_and_back (bool) – If True, the shader will treat all normals as facing the camera.
  • animate (bool) – If True, the camera will rotate by default about the scene.
  • animate_az (float) – The number of radians to rotate per timestep.
  • animate_rate (float) – The framerate for animation in fps.
  • animate_axis ((3,) float or None) – If present, the animation will rotate about the given axis in world coordinates. Otherwise, the animation will rotate in azimuth.
on_close()

Exit the event loop when the window is closed.

on_draw()

Redraw the scene into the viewing window.

on_resize(width, height)

Resize the camera and trackball when the window is resized.

on_mouse_press(x, y, buttons, modifiers)

Record an initial mouse press.

on_mouse_drag(x, y, dx, dy, buttons, modifiers)

Record a mouse drag.

on_mouse_release(x, y, button, modifiers)

Record a mouse release.

on_mouse_scroll(x, y, dx, dy)

Record a mouse scroll.

on_key_press(symbol, modifiers)

Record a key press.

static record(dt, self)

Save another frame for the GIF.

static animate(dt, self)

Animate the scene by rotating the camera.