File: lighting_mesh.py

package info (click to toggle)
python-pyvista 0.44.1-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 159,804 kB
  • sloc: python: 72,164; sh: 118; makefile: 68
file content (88 lines) | stat: -rw-r--r-- 2,179 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
.. _lighting_properties_example:

Lighting Properties
~~~~~~~~~~~~~~~~~~~

Control aspects of the rendered mesh's lighting such as Ambient, Diffuse,
and Specular. These options only work if the ``lighting`` argument to
``add_mesh`` is ``True`` (it's ``True`` by default).

You can turn off all lighting for the given mesh by passing ``lighting=False``
to ``add_mesh``.
"""

# sphinx_gallery_thumbnail_number = 4
from __future__ import annotations

import pyvista as pv
from pyvista import examples

mesh = examples.download_st_helens().warp_by_scalar()

cpos = [(575848.0, 5128459.0, 22289.0), (562835.0, 5114981.5, 2294.5), (-0.5, -0.5, 0.7)]

# %%
# First, lets take a look at the mesh with default lighting conditions
mesh.plot(cpos=cpos, show_scalar_bar=False)

# %%
# What about with no lighting
mesh.plot(lighting=False, cpos=cpos, show_scalar_bar=False)

# %%
# Demonstration of the specular property

# sphinx_gallery_start_ignore
# specular does not seem to work correctly
PYVISTA_GALLERY_FORCE_STATIC = True
# sphinx_gallery_end_ignore

p = pv.Plotter(shape=(1, 2), window_size=[1500, 500])

p.subplot(0, 0)
p.add_mesh(mesh, show_scalar_bar=False)
p.add_text('No Specular')

p.subplot(0, 1)
s = 1.0
p.add_mesh(mesh, specular=s, show_scalar_bar=False)
p.add_text(f'Specular of {s}')

p.link_views()
p.view_isometric()
p.show(cpos=cpos)

# %%
# Just specular

# sphinx_gallery_start_ignore
# specular does not seem to work correctly
PYVISTA_GALLERY_FORCE_STATIC = True
# sphinx_gallery_end_ignore

mesh.plot(specular=0.5, cpos=cpos, show_scalar_bar=False)

# %%
# Specular power

# sphinx_gallery_start_ignore
# specular does not seem to work correctly
PYVISTA_GALLERY_FORCE_STATIC = True
# sphinx_gallery_end_ignore

mesh.plot(specular=0.5, specular_power=15, cpos=cpos, show_scalar_bar=False)

# %%
# Demonstration of all three in use

# sphinx_gallery_start_ignore
# specular does not seem to work correctly
PYVISTA_GALLERY_FORCE_STATIC = True
# sphinx_gallery_end_ignore

mesh.plot(diffuse=0.5, specular=0.5, ambient=0.5, cpos=cpos, show_scalar_bar=False)

# %%
# For detailed control over lighting conditions in general see the
# :ref:`light_examples` examples.