| 1 |
""" |
| 2 |
.. _lighting_mesh_example: |
| 3 |
|
| 4 |
Lighting Properties |
| 5 |
~~~~~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
Control aspects of the rendered mesh's lighting such as Ambient, Diffuse, |
| 8 |
and Specular. These options only work if the ``lighting`` argument to |
| 9 |
``add_mesh`` is ``True`` (it's ``True`` by default). |
| 10 |
|
| 11 |
You can turn off all lighting for the given mesh by passing ``lighting=False`` |
| 12 |
to ``add_mesh``. |
| 13 |
""" |
| 14 |
|
| 15 |
# sphinx_gallery_thumbnail_number = 4 |
| 16 |
import pyvista as pv |
| 17 |
from pyvista import examples |
| 18 |
|
| 19 |
mesh = examples.download_st_helens().warp_by_scalar() |
| 20 |
|
| 21 |
cpos = pv.CameraPosition( |
| 22 |
position=(575848.0, 5128459.0, 22289.0), |
| 23 |
focal_point=(562835.0, 5114981.5, 2294.5), |
| 24 |
viewup=(-0.5, -0.5, 0.7), |
| 25 |
) |
| 26 |
|
| 27 |
# %% |
| 28 |
# First, lets take a look at the mesh with default lighting conditions |
| 29 |
mesh.plot(cpos=cpos, show_scalar_bar=False) |
| 30 |
|
| 31 |
# %% |
| 32 |
# What about with no lighting |
| 33 |
mesh.plot(lighting=False, cpos=cpos, show_scalar_bar=False) |
| 34 |
|
| 35 |
# %% |
| 36 |
# Demonstration of the specular property |
| 37 |
|
| 38 |
# sphinx_gallery_start_ignore |
| 39 |
# specular does not seem to work correctly |
| 40 |
PYVISTA_GALLERY_FORCE_STATIC = True |
| 41 |
# sphinx_gallery_end_ignore |
| 42 |
|
| 43 |
pl = pv.Plotter(shape=(1, 2), window_size=[1500, 500]) |
| 44 |
|
| 45 |
pl.subplot(0, 0) |
| 46 |
pl.add_mesh(mesh, show_scalar_bar=False) |
| 47 |
pl.add_text('No Specular') |
| 48 |
|
| 49 |
pl.subplot(0, 1) |
| 50 |
s = 1.0 |
| 51 |
pl.add_mesh(mesh, specular=s, show_scalar_bar=False) |
| 52 |
pl.add_text(f'Specular of {s}') |
| 53 |
|
| 54 |
pl.link_views() |
| 55 |
pl.view_isometric() |
| 56 |
pl.show(cpos=cpos) |
| 57 |
|
| 58 |
# %% |
| 59 |
# Just specular |
| 60 |
|
| 61 |
# sphinx_gallery_start_ignore |
| 62 |
# specular does not seem to work correctly |
| 63 |
PYVISTA_GALLERY_FORCE_STATIC = True |
| 64 |
# sphinx_gallery_end_ignore |
| 65 |
|
| 66 |
mesh.plot(specular=0.5, cpos=cpos, show_scalar_bar=False) |
| 67 |
|
| 68 |
# %% |
| 69 |
# Specular power |
| 70 |
|
| 71 |
# sphinx_gallery_start_ignore |
| 72 |
# specular does not seem to work correctly |
| 73 |
PYVISTA_GALLERY_FORCE_STATIC = True |
| 74 |
# sphinx_gallery_end_ignore |
| 75 |
|
| 76 |
mesh.plot(specular=0.5, specular_power=15, cpos=cpos, show_scalar_bar=False) |
| 77 |
|
| 78 |
# %% |
| 79 |
# Demonstration of all three in use |
| 80 |
|
| 81 |
# sphinx_gallery_start_ignore |
| 82 |
# specular does not seem to work correctly |
| 83 |
PYVISTA_GALLERY_FORCE_STATIC = True |
| 84 |
# sphinx_gallery_end_ignore |
| 85 |
|
| 86 |
mesh.plot(diffuse=0.5, specular=0.5, ambient=0.5, cpos=cpos, show_scalar_bar=False) |
| 87 |
|
| 88 |
# %% |
| 89 |
# For detailed control over lighting conditions in general see the |
| 90 |
# :ref:`light_examples` examples. |
| 91 |
# |
| 92 |
# .. tags:: plot |