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
|
"""
.. _light_types_example:
Light Types
~~~~~~~~~~~
Lights come in three types:
* headlights, the axis of which always coincides with the view of the camera,
* camera lights, which move together with the camera, but which can occupy
any fixed relative position with respect to the camera,
* scene lights, the position of which is fixed to the scene, and which is thus
unaffected by moving the camera. This is the default type.
Headlight
=========
For headlights the :py:attr:`pyvista.Camera.position` and
:py:attr:`pyvista.Camera.focal_point` properties are meaningless. No matter
where you move the camera, the light always emanates from the view point:
"""
# sphinx_gallery_thumbnail_number = 2
from __future__ import annotations
import pyvista as pv
from pyvista import examples
mesh = examples.download_bunny()
mesh.rotate_x(90, inplace=True)
mesh.rotate_z(180, inplace=True)
plotter = pv.Plotter(lighting='none')
plotter.add_mesh(mesh, color='lightblue', smooth_shading=True)
light = pv.Light(light_type='headlight')
# these don't do anything for a headlight:
light.position = (1, 2, 3)
light.focal_point = (4, 5, 6)
plotter.add_light(light)
plotter.show()
# %%
# Camera light
# ============
#
# Camera lights define their :py:attr:`pyvista.Camera.position` and
# :py:attr:`pyvista.Camera.focal_point` properties in a coordinate system that
# is local to the camera. The coordinates in the scene's coordinate system can
# be accessed through the :py:attr:`pyvista.Light.world_position` and
# :py:attr:`pyvista.Light.world_focal_point` read-only properties,
# respectively. For specifics of the local coordinate system used for the
# coordinates please see the documentation of
# :func:`pyvista.Light.set_camera_light`.
plotter = pv.Plotter(lighting='none')
plotter.add_mesh(mesh, color='lightblue', smooth_shading=True)
# a light that always shines from the right of the camera
light = pv.Light(position=(1, 0, 0), light_type='camera light')
plotter.add_light(light)
plotter.show()
# %%
# Scene light
# ===========
#
# Scene lights are attached to the scene, their position and focal point are
# interpreted as global coordinates:
plotter = pv.Plotter(lighting='none')
plotter.add_mesh(mesh, color='lightblue', smooth_shading=True)
# a light that always shines on the left side of the bunny
light = pv.Light(position=(0, 1, 0), light_type='scene light')
plotter.add_light(light)
plotter.show()
|