cozmo.opengl

This module provides a 3D visualizer for Cozmo’s world state.

It uses PyOpenGL, a Python OpenGL 3D graphics library which is available on most platforms. It also depends on the Pillow library for image processing.

The easiest way to make use of this viewer is to call cozmo.run_program() with use_3d_viewer=True or cozmo.run.connect_with_3dviewer().

Warning

This package requires Python to have the PyOpenGL package installed, along with an implementation of GLUT (OpenGL Utility Toolkit).

To install the Python packages do pip3 install --user "cozmo[3dviewer]"

On Windows and Linux you must also install freeglut (macOS / OSX has one preinstalled).

On Linux: sudo apt-get install freeglut3

On Windows: Go to http://freeglut.sourceforge.net/ to get a freeglut.dll file. It’s included in any of the Windows binaries downloads. Place the DLL next to your Python script, or install it somewhere in your PATH to allow any script to use it.”

Functions

LoadMtlFile(filename) Load a .mtl material file, and return the contents as a dictionary.

Classes

CubeRenderFrame(cube) Minimal copy of a Cube’s state for 1 frame of rendering.
CustomObjectRenderFrame(obj, is_fixed) Minimal copy of a CustomObject’s state for 1 frame of rendering.
DynamicTexture() Wrapper around An OpenGL Texture that can be dynamically updated.
FaceRenderFrame(face) Minimal copy of a Face’s state for 1 frame of rendering.
LoadedObjFile(filename) The loaded / parsed contents of a 3D Wavefront OBJ file.
ObservableElementRenderFrame(element) Minimal copy of a Cube’s state for 1 frame of rendering.
OpenGLViewer(enable_camera_view[, …]) OpenGL based 3D Viewer.
OpenGLWindow(x, y, width, height, …) A Window displaying an OpenGL viewport.
RenderableObject(object_data[, override_mtl]) Container for an object that can be rendered via OpenGL.
RobotControlIntents([left_wheel_speed, …]) Input intents for controlling the robot.
RobotRenderFrame(robot) Minimal copy of a Robot’s state for 1 frame of rendering.
WorldRenderFrame(robot) Minimal copy of the World’s state for 1 frame of rendering.
class cozmo.opengl.DynamicTexture

Wrapper around An OpenGL Texture that can be dynamically updated.

bind()

Bind the texture for rendering.

update(pil_image: PIL.Image.Image)

Update the texture to contain the provided image.

Parameters:pil_image (PIL.Image.Image) – The image to write into the texture.
class cozmo.opengl.LoadedObjFile(filename)

The loaded / parsed contents of a 3D Wavefront OBJ file.

This is the intermediary step between the file on the disk, and a renderable 3D object. It supports the subset of the OBJ file that was used in the Cozmo and Cube assets, and does not attempt to exhaustively support every possible setting.

Parameters:filename (str) – The filename of the OBJ file to load.
class cozmo.opengl.OpenGLViewer(enable_camera_view, show_viewer_controls=True)

OpenGL based 3D Viewer.

Handles rendering of both a 3D world view and a 2D camera window.

Parameters:
  • enable_camera_view (bool) – True to also open a 2nd window to display the live camera view.
  • show_viewer_controls (bool) – Specifies whether to draw controls on the view.
disconnect()

Called from the SDK when the program is complete and it’s time to exit.

class cozmo.opengl.OpenGLWindow(x, y, width, height, window_name, is_3d)

A Window displaying an OpenGL viewport.

Parameters:
  • x (int) – The initial x coordinate of the window in pixels.
  • y (int) – The initial y coordinate of the window in pixels.
  • width (int) – The initial height of the window in pixels.
  • height (int) – The initial height of the window in pixels.
  • window_name (str) – The name / title for the window.
  • is_3d (bool) – True to create a Window for 3D rendering.
height = None

The height of the window

Type:int
init_display()

Initialze the OpenGL display parts of the Window.

Warning

Must be called on the same thread as OpenGL (usually the main thread), and after glutInit().

width = None

The width of the window

Type:int
class cozmo.opengl.RenderableObject(object_data: cozmo.opengl.LoadedObjFile, override_mtl=None)

Container for an object that can be rendered via OpenGL.

Can contain multiple meshes, for e.g. articulated objects.

Parameters:
  • object_data (LoadedObjFile) – The object data (vertices, faces, etc.) to generate the renderable object from.
  • override_mtl (dict) – An optional material to use as an override instead of the material specified in the data. This allows one OBJ file to be used to create multiple objects with different materials and textures. Use LoadMtlFile() to generate a dict from a MTL file.
draw_all()

Draw all of the meshes.

meshes = None

The individual meshes, indexed by name, for this object.

Type:dict
cozmo.opengl.LoadMtlFile(filename)

Load a .mtl material file, and return the contents as a dictionary.

Supports the subset of MTL required for the Cozmo 3D viewer assets.

Parameters:filename (str) – The filename of the file to load.
Returns:A dictionary mapping named MTL attributes to values.
Return type:dict