pyvista_wasm.Light#

class pyvista_wasm.Light(position: tuple[float, float, float] = (0.0, 0.0, 1.0), focal_point: tuple[float, float, float] = (0.0, 0.0, 0.0), color: tuple[float, float, float] | str = (1.0, 1.0, 1.0), intensity: float = 1.0, light_type: str = 'SceneLight', positional: bool = False, cone_angle: float = 30.0, cone_falloff: float = 5.0, attenuation_values: tuple[float, float, float] = (1.0, 0.0, 0.0))#

Bases: object

Light class.

Parameters:
  • position (sequence[float], optional) – The position of the light. The interpretation of the position depends on the type of the light and whether the light has a transformation matrix.

  • focal_point (sequence[float], optional) – The focal point of the light. The interpretation of the focal point depends on the type of the light and whether the light has a transformation matrix.

  • color (sequence[float] | str, optional) – The color of the light. The ambient, diffuse and specular colors will all be set to this color on creation.

  • light_type (str, default: 'SceneLight') –

    The type of the light. One of 'Headlight', 'CameraLight' or 'SceneLight'.

    • A headlight is attached to the camera, looking at its focal point along the axis of the camera.

    • A camera light also moves with the camera, but it can occupy a general position with respect to it.

    • A scene light is stationary with respect to the scene, as it does not follow the camera. This is the default.

  • intensity (float, optional) – The brightness of the light (between 0 and 1).

  • positional (bool, optional) –

    Set if the light is positional.

    The default is a directional light, i.e. an infinitely distant point source. A positional light with a cone angle of at least 90 degrees acts like a spherical point source. A positional light with a cone angle that is less than 90 degrees is known as a spotlight.

  • cone_angle (float, optional) – Cone angle of a positional light in degrees.

  • cone_falloff (float, optional) – The exponent of the cosine used for spotlights.

  • attenuation_values (sequence[float], optional) –

    Quadratic attenuation constants.

    The values are a 3-length sequence which specifies the constant, linear and quadratic constants in this order. These parameters only have an effect for positional lights.

Examples

Headlight. For headlights the position and focal point properties are meaningless. No matter where you move the camera, the light always emanates from the view point:

>>> import pyvista_wasm as pv
>>> from pyvista_wasm import examples
>>> mesh = examples.download_bunny()
>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(mesh, color='lightblue')
>>> 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 move together with the camera, but can occupy any fixed relative position with respect to the camera:

>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(mesh, color='lightblue')
>>> # a light that always shines from the right of the camera
>>> light = pv.Light(position=(1, 0, 0), light_type='CameraLight')
>>> 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()
>>> _ = plotter.add_mesh(mesh, color='lightblue')
>>> # a light that always shines on the left side of the bunny
>>> light = pv.Light(position=(0, 1, 0), light_type='SceneLight')
>>> plotter.add_light(light)
>>> plotter.show()
__init__(position: tuple[float, float, float] = (0.0, 0.0, 1.0), focal_point: tuple[float, float, float] = (0.0, 0.0, 0.0), color: tuple[float, float, float] | str = (1.0, 1.0, 1.0), intensity: float = 1.0, light_type: str = 'SceneLight', positional: bool = False, cone_angle: float = 30.0, cone_falloff: float = 5.0, attenuation_values: tuple[float, float, float] = (1.0, 0.0, 0.0)) None#

Initialize a Light instance.

Methods

__init__([position, focal_point, color, ...])

Initialize a Light instance.

generate_vtk_js_code(idx)

Generate VTK.wasm JavaScript code for this light.

set_light_type_to_camera_light()

Set light type to CameraLight (moves with the camera).

set_light_type_to_headlight()

Set light type to Headlight (at camera position).

set_light_type_to_scene_light()

Set light type to SceneLight (fixed in world space).

generate_vtk_js_code(idx: int) str#

Generate VTK.wasm JavaScript code for this light.

Parameters:

idx (int) – Unique index used to avoid variable name collisions in JavaScript.

Returns:

JavaScript code that creates and configures the light.

Return type:

str

set_light_type_to_camera_light() None#

Set light type to CameraLight (moves with the camera).

set_light_type_to_headlight() None#

Set light type to Headlight (at camera position).

set_light_type_to_scene_light() None#

Set light type to SceneLight (fixed in world space).