trimesh.viewer¶
- trimesh.viewer.notebook
- trimesh.viewer.trackball
- trimesh.viewer.widget
- trimesh.viewer.windowed
- windowed.py
SceneViewerSceneViewer.__init__()SceneViewer.add_geometry()SceneViewer.cleanup_geometries()SceneViewer.flip()SceneViewer.hide_geometry()SceneViewer.init_gl()SceneViewer.on_draw()SceneViewer.on_key_press()SceneViewer.on_mouse_drag()SceneViewer.on_mouse_press()SceneViewer.on_mouse_scroll()SceneViewer.on_resize()SceneViewer.reset_view()SceneViewer.save_image()SceneViewer.toggle_axis()SceneViewer.toggle_culling()SceneViewer.toggle_fullscreen()SceneViewer.toggle_grid()SceneViewer.toggle_wireframe()SceneViewer.unhide_geometry()SceneViewer.update_flags()
render_scene()
viewer¶
View meshes and scenes via pyglet or inline HTML.
- class trimesh.viewer.SceneViewer(scene, smooth: bool = True, flags: dict | None = None, visible: bool = True, resolution: ArrayLike | None = None, fullscreen: bool = False, resizable: bool = True, start_loop: bool = True, callback: Callable | None = None, callback_period: float | floating | int | integer | unsignedinteger | None = None, caption: str | None = None, fixed: Iterable | None = None, offset_lines: bool = True, line_settings: dict | None = None, background=None, window_conf=None, profile: bool = False, record: bool = False, **kwargs)¶
Bases:
BaseWindow- __init__(scene, smooth: bool = True, flags: dict | None = None, visible: bool = True, resolution: ArrayLike | None = None, fullscreen: bool = False, resizable: bool = True, start_loop: bool = True, callback: Callable | None = None, callback_period: float | floating | int | integer | unsignedinteger | None = None, caption: str | None = None, fixed: Iterable | None = None, offset_lines: bool = True, line_settings: dict | None = None, background=None, window_conf=None, profile: bool = False, record: bool = False, **kwargs)¶
Create a window that will display a trimesh.Scene object in an OpenGL context via pyglet.
- Parameters:
scene (trimesh.scene.Scene) – Scene with geometry and transforms
smooth – If True try to smooth shade things
flags – If passed apply keys to self.view: [‘cull’, ‘wireframe’, etc]
visible – Display window or not
resolution – Initial resolution of window
fullscreen – Determines whether the window is rendered in fullscreen mode.
resizable – Determines whether the rendered window can be resized by the user.
start_loop – Call pyglet.app.run() at the end of init
callback – A function which can be called periodically to update things in the scene
callback_period – How often to call the callback, in seconds
caption – Caption for the window title
fixed – List of keys in scene.geometry to skip view transform on to keep fixed relative to camera
offset_lines – If True, will offset lines slightly so if drawn coplanar with mesh geometry they will be visible
line_settings – Override default line width and point size with keys ‘line_width’ and ‘point_size’ in pixels
background – Color for background
window_conf – Passed to window init
profile – If set will run a pyinstrument profile for every call to on_draw and print the output.
record – If True, will save a list of png bytes to a list located in scene.metadata[‘recording’]
kwargs – Additional arguments to pass, including ‘background’ for to set background color
- 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.
- flip()¶
Swap the OpenGL front and back buffers.
Call this method on a double-buffered window to update the visible display with the back buffer. The contents of the back buffer is undefined after this operation.
Windows are double-buffered by default. This method is called automatically by EventLoop after the
on_draw()event.
- 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.in_notebook() Literal['jupyter', 'marimo', False]¶
Check to see if we are in a Jypyter or Marimo notebook.
- Returns:
Returns the type of notebook we’re in or False if it is running as terminal application.
- Return type:
in_notebook
- trimesh.viewer.render_scene(scene, resolution=None, visible=True, fullscreen=False, resizable=True, **kwargs)¶
Render a preview of a scene to a PNG. Note that whether this works or not highly variable based on platform and graphics driver.
- Parameters:
scene (trimesh.Scene) – Geometry to be rendered
resolution ((2,) int or None) – Resolution in pixels or set from scene.camera
visible (bool) – Show a window during rendering. Note that MANY platforms refuse to render with hidden windows and will likely return a blank image; this is a platform issue and cannot be fixed in Python.
fullscreen (bool) – Determines whether the window is rendered in fullscreen mode. Defaults to False (windowed).
resizable (bool) – Determines whether the rendered window can be resized by the user. Defaults to True (resizable).
kwargs – Passed to SceneViewer
- Returns:
render – Image in PNG format
- Return type:
bytes
- trimesh.viewer.scene_to_html(scene, escape_quotes: bool = False) str¶
Return HTML that will render the scene using GLTF/GLB encoded to base64 loaded by three.js
- Parameters:
scene (trimesh.Scene) – Source geometry
escape_quotes – If true, replaces quotes ‘”’ with ‘"’ so that the HTML is valid inside a srcdoc property.
- Returns:
html – HTML containing embedded geometry
- Return type:
str
- trimesh.viewer.scene_to_mo_notebook(scene, height=500, **kwargs)¶
Convert a scene to HTML containing embedded geometry and a three.js viewer that will display nicely in an Marimo notebook.
- Parameters:
scene (trimesh.Scene) – Source geometry
- Returns:
html – Object containing rendered scene
- Return type:
mo.Html
- 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