Skip to content

Note

Click here to download the full example code

Mesh headlight (library)

An example controlling the mesh headlight, using napari-threedee as a library.

mesh headlight library

Out:

Downloading data from https://raw.githubusercontent.com/vispy/demo-data/main/orig/triceratops.obj.gz (141 kB)

[..................                      ] 45.52059 | downloading   
[....................................    ] 91.04119 / downloading   
[........................................] 100.00000 - downloading   
File saved as /home/runner/.vispy/data/orig/triceratops.obj.gz.


import napari
import numpy as np
from vispy.io import load_data_file, read_mesh

from napari_threedee.visualization._qt.qt_lighting_control import QtLightingControlWidget


# Fetch datasets - this will download dataset if datasets are not found
vertices, faces, _, _ = read_mesh(load_data_file('orig/triceratops.obj.gz'))

# put the mesh right side up, scale it up (napari#3477) and fix faces handedness
vertices *= -100
faces = faces[:, ::-1]
vertex_values = np.ones((len(vertices),))

# create an empty viewer
viewer = napari.Viewer(ndisplay=3)

# add the mesh
viewer.add_surface((vertices, faces, vertex_values), name='triceratops')

lighting_control_widget = QtLightingControlWidget(viewer=viewer)
viewer.window.add_dock_widget(widget=lighting_control_widget)

napari.run()

Total running time of the script: ( 0 minutes 1.329 seconds)

Download Python source code: mesh_headlight_library.py

Download Jupyter notebook: mesh_headlight_library.ipynb

Gallery generated by mkdocs-gallery