trimesh.viewer.windowed

windowed.py

Provides a pyglet- based windowed viewer to preview Trimesh, Scene, PointCloud, and Path objects.

Works on all major platforms: Windows, Linux, and OSX.

Classes:

SceneViewer(scene[, smooth, flags, visible, …])

Trackball(pose, size, scale[, target])

A trackball class for creating camera transforms from mouse movements.

Functions:

geometry_hash(geometry)

Get a hash for a geometry object

render_scene(scene[, resolution, visible])

Render a preview of a scene to a PNG.

to_rgba(colors[, dtype])

Convert a single or multiple RGB colors to RGBA colors.

translation_matrix(direction)

Return matrix to translate by direction vector.

class trimesh.viewer.windowed.SceneViewer(scene, smooth=True, flags=None, visible=True, resolution=None, start_loop=True, callback=None, callback_period=None, caption=None, fixed=None, offset_lines=True, line_settings=None, background=None, window_conf=None, profile=False, **kwargs)

Bases: pyglet.window.BaseWindow

Methods:

add_geometry(name, geometry, **kwargs)

Add a geometry to the viewer.

cleanup_geometries()

Remove any stored vertex lists that no longer exist in the scene.

hide_geometry(node)

Don’t display the geometry contained at a node on the next draw.

init_gl()

Perform the magic incantations to create an OpenGL scene using pyglet.

on_draw()

Run the actual draw calls.

on_key_press(symbol, modifiers)

Call appropriate functions given key presses.

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

Pan or rotate the view.

on_mouse_press(x, y, buttons, modifiers)

Set the start point of the drag.

on_mouse_scroll(x, y, dx, dy)

Zoom the view.

on_resize(width, height)

Handle resized windows.

reset_view([flags])

Set view to the default view.

save_image(file_obj)

Save the current color buffer to a file object in PNG format.

toggle_axis()

Toggle a rendered XYZ/RGB axis marker: off, world frame, every frame

toggle_culling()

Toggle back face culling.

toggle_fullscreen()

Toggle between fullscreen and windowed mode.

toggle_grid()

Toggle a rendered grid.

toggle_wireframe()

Toggle wireframe mode

unhide_geometry(node)

If a node is hidden remove the flag and show the geometry on the next draw.

update_flags()

Check the view flags, and call required GL functions.

add_geometry(name, geometry, **kwargs)

Add a geometry to the viewer.

Parameters
  • name (hashable) – Name that references geometry

  • geometry (Trimesh, Path2D, Path3D, PointCloud) – Geometry to display in the viewer window

  • ** (kwargs) – Passed to rendering.convert_to_vertexlist

cleanup_geometries()

Remove any stored vertex lists that no longer exist in the scene.

hide_geometry(node)

Don’t display the geometry contained at a node on the next draw.

Parameters

node (str) – Node to not display

init_gl()

Perform the magic incantations to create an OpenGL scene using pyglet.

on_draw()

Run the actual draw calls.

on_key_press(symbol, modifiers)

Call appropriate functions given key presses.

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

Pan or rotate the view.

on_mouse_press(x, y, buttons, modifiers)

Set the start point of the drag.

on_mouse_scroll(x, y, dx, dy)

Zoom the view.

on_resize(width, height)

Handle resized windows.

reset_view(flags=None)

Set view to the default view.

Parameters

flags (None or dict) – If any view key passed override the default e.g. {‘cull’: False}

save_image(file_obj)

Save the current color buffer to a file object in PNG format.

Parameters

file_obj (file name, or file- like object) –

toggle_axis()

Toggle a rendered XYZ/RGB axis marker: off, world frame, every frame

toggle_culling()

Toggle back face culling.

It is on by default but if you are dealing with non- watertight meshes you probably want to be able to see the back sides.

toggle_fullscreen()

Toggle between fullscreen and windowed mode.

toggle_grid()

Toggle a rendered grid.

toggle_wireframe()

Toggle wireframe mode

Good for looking inside meshes, off by default.

unhide_geometry(node)

If a node is hidden remove the flag and show the geometry on the next draw.

Parameters

node (str) – Node to display

update_flags()

Check the view flags, and call required GL functions.

trimesh.viewer.windowed.geometry_hash(geometry)

Get a hash for a geometry object

Parameters

geometry (object) –

Returns

hash

Return type

str

trimesh.viewer.windowed.render_scene(scene, resolution=None, visible=True, **kwargs)

Render a preview of a scene to a PNG.

Parameters
  • scene (trimesh.Scene) – Geometry to be rendered

  • resolution ((2,) int or None) – Resolution in pixels, or set from scene.camera

  • kwargs – Passed to SceneViewer

Returns

render – Image in PNG format

Return type

bytes