| 1 |
""" |
| 2 |
.. _light_types_example: |
| 3 |
|
| 4 |
Light Types |
| 5 |
~~~~~~~~~~~ |
| 6 |
|
| 7 |
Lights come in three types: |
| 8 |
|
| 9 |
* headlights, the axis of which always coincides with the view of the camera, |
| 10 |
* camera lights, which move together with the camera, but which can occupy |
| 11 |
any fixed relative position with respect to the camera, |
| 12 |
* scene lights, the position of which is fixed to the scene, and which is thus |
| 13 |
unaffected by moving the camera. This is the default type. |
| 14 |
|
| 15 |
Headlight |
| 16 |
========= |
| 17 |
|
| 18 |
For headlights the :py:attr:`pyvista.Camera.position` and |
| 19 |
:py:attr:`pyvista.Camera.focal_point` properties are meaningless. No matter |
| 20 |
where you move the camera, the light always emanates from the view point: |
| 21 |
|
| 22 |
""" |
| 23 |
|
| 24 |
# sphinx_gallery_thumbnail_number = 2 |
| 25 |
import pyvista as pv |
| 26 |
from pyvista import examples |
| 27 |
|
| 28 |
mesh = examples.download_bunny() |
| 29 |
mesh.rotate_x(90, inplace=True) |
| 30 |
mesh.rotate_z(180, inplace=True) |
| 31 |
|
| 32 |
pl = pv.Plotter(lighting='none') |
| 33 |
pl.add_mesh(mesh, color='lightblue', smooth_shading=True) |
| 34 |
light = pv.Light(light_type='headlight') |
| 35 |
# these don't do anything for a headlight: |
| 36 |
light.position = (1, 2, 3) |
| 37 |
light.focal_point = (4, 5, 6) |
| 38 |
pl.add_light(light) |
| 39 |
pl.show() |
| 40 |
|
| 41 |
|
| 42 |
# %% |
| 43 |
# Camera light |
| 44 |
# ============ |
| 45 |
# |
| 46 |
# Camera lights define their :py:attr:`pyvista.Camera.position` and |
| 47 |
# :py:attr:`pyvista.Camera.focal_point` properties in a coordinate system that |
| 48 |
# is local to the camera. The coordinates in the scene's coordinate system can |
| 49 |
# be accessed through the :py:attr:`pyvista.Light.world_position` and |
| 50 |
# :py:attr:`pyvista.Light.world_focal_point` read-only properties, |
| 51 |
# respectively. For specifics of the local coordinate system used for the |
| 52 |
# coordinates please see the documentation of |
| 53 |
# :func:`pyvista.Light.set_camera_light`. |
| 54 |
|
| 55 |
pl = pv.Plotter(lighting='none') |
| 56 |
pl.add_mesh(mesh, color='lightblue', smooth_shading=True) |
| 57 |
# a light that always shines from the right of the camera |
| 58 |
light = pv.Light(position=(1, 0, 0), light_type='camera light') |
| 59 |
pl.add_light(light) |
| 60 |
pl.show() |
| 61 |
|
| 62 |
|
| 63 |
# %% |
| 64 |
# Scene light |
| 65 |
# =========== |
| 66 |
# |
| 67 |
# Scene lights are attached to the scene, their position and focal point are |
| 68 |
# interpreted as global coordinates: |
| 69 |
|
| 70 |
pl = pv.Plotter(lighting='none') |
| 71 |
pl.add_mesh(mesh, color='lightblue', smooth_shading=True) |
| 72 |
# a light that always shines on the left side of the bunny |
| 73 |
light = pv.Light(position=(0, 1, 0), light_type='scene light') |
| 74 |
pl.add_light(light) |
| 75 |
pl.show() |
| 76 |
# %% |
| 77 |
# .. tags:: lights |