Skip to content

Note

Click here to download the full example code

Ambient occlusion (plugin)

An example adding ambient occlusion to a mesh, using napari-threedee as a napari plugin.

ambient occlusion plugin

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


# 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', shading="smooth")

# open the plugin
viewer.window.add_plugin_dock_widget(
    plugin_name="napari-threedee", widget_name="ambient occlusion controls"
)

napari.run()

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

Download Python source code: ambient_occlusion_plugin.py

Download Jupyter notebook: ambient_occlusion_plugin.ipynb

Gallery generated by mkdocs-gallery