trimesh.viewer package

Submodules

trimesh.viewer.notebook module

notebook.py

Render trimesh.Scene objects in HTML and jupyter notebooks using three.js

trimesh.viewer.notebook.in_notebook()

Check to see if we are in an IPython or Jypyter notebook.

Returns

in_notebook – Returns True if we are in a notebook

Return type

bool

trimesh.viewer.notebook.scene_to_html(scene)

Return HTML that will render the scene using GLTF/GLB encoded to base64 loaded by three.js

Parameters

scene (trimesh.Scene) – Source geometry

Returns

html – HTML containing embedded geometry

Return type

str

trimesh.viewer.notebook.scene_to_notebook(scene, height=500, **kwargs)

Convert a scene to HTML containing embedded geometry and a three.js viewer that will display nicely in an IPython/Jupyter notebook.

Parameters

scene (trimesh.Scene) – Source geometry

Returns

html – Object containing rendered scene

Return type

IPython.display.HTML

trimesh.viewer.trackball module

Trackball class for 3D manipulation of viewpoints.

class trimesh.viewer.trackball.Trackball(pose, size, scale, target=array([0., 0., 0.]))

Bases: object

A trackball class for creating camera transforms from mouse movements.

STATE_PAN = 1
STATE_ROLL = 2
STATE_ROTATE = 0
STATE_ZOOM = 3
down(point)

Record an initial mouse press at a given point.

Parameters

point ((2,) int) – The x and y pixel coordinates of the mouse press.

drag(point)

Update the tracball during a drag.

Parameters

point ((2,) int) – The current x and y pixel coordinates of the mouse during a drag. This will compute a movement for the trackball with the relative motion between this point and the one marked by down().

property pose

autolab_core.RigidTransform : The current camera-to-world pose.

resize(size)

Resize the window.

Parameters

size ((float, float)) – The new width and height of the camera image in pixels.

rotate(azimuth, axis=None)

Rotate the trackball about the “Up” axis by azimuth radians.

Parameters

azimuth (float) – The number of radians to rotate.

scroll(clicks)

Zoom using a mouse scroll wheel motion.

Parameters

clicks (int) – The number of clicks. Positive numbers indicate forward wheel movement.

set_state(state)

Set the state of the trackball in order to change the effect of dragging motions.

Parameters

state (int) – One of Trackball.STATE_ROTATE, Trackball.STATE_PAN, Trackball.STATE_ROLL, and Trackball.STATE_ZOOM.

trimesh.viewer.widget module

trimesh.viewer.windowed module

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.

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, **kwargs)

Bases: pyglet.window.Window

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

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_wireframe()

Toggle wireframe mode

Good for looking inside meshes, off by default.

update_flags()

Check the view flags, and call required GL functions.

trimesh.viewer.windowed.geometry_hash(geometry)

Get an MD5 for a geometry object

Parameters

geometry (object) –

Returns

MD5

Return type

str

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

Render a preview of a scene to a PNG.

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

  • resolution ((2,) int) – Resolution in pixels

  • kwargs – Passed to SceneViewer

Returns

render – Image in PNG format

Return type

bytes

Module contents

viewer

View meshes and scenes via pyglet or inline HTML.

trimesh.viewer.SceneWidget(*args, **kwargs)
class trimesh.viewer.SceneViewer(scene, smooth=True, flags=None, visible=True, resolution=None, start_loop=True, callback=None, callback_period=None, caption=None, fixed=None, **kwargs)

Bases: pyglet.window.Window

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

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_wireframe()

Toggle wireframe mode

Good for looking inside meshes, off by default.

update_flags()

Check the view flags, and call required GL functions.

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

Render a preview of a scene to a PNG.

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

  • resolution ((2,) int) – Resolution in pixels

  • kwargs – Passed to SceneViewer

Returns

render – Image in PNG format

Return type

bytes

trimesh.viewer.in_notebook()

Check to see if we are in an IPython or Jypyter notebook.

Returns

in_notebook – Returns True if we are in a notebook

Return type

bool

trimesh.viewer.scene_to_notebook(scene, height=500, **kwargs)

Convert a scene to HTML containing embedded geometry and a three.js viewer that will display nicely in an IPython/Jupyter notebook.

Parameters

scene (trimesh.Scene) – Source geometry

Returns

html – Object containing rendered scene

Return type

IPython.display.HTML

trimesh.viewer.scene_to_html(scene)

Return HTML that will render the scene using GLTF/GLB encoded to base64 loaded by three.js

Parameters

scene (trimesh.Scene) – Source geometry

Returns

html – HTML containing embedded geometry

Return type

str