pyvista_wasm.Camera#

class pyvista_wasm.Camera(position: tuple[float, float, float] = (0.0, 0.0, 1.0), focal_point: tuple[float, float, float] = (0.0, 0.0, 0.0), view_up: tuple[float, float, float] = (0.0, 1.0, 0.0), view_angle: float = 30.0, clipping_range: tuple[float, float] = (0.01, 1000.01), parallel_projection: bool = False, elevation: float = 0.0)#

Bases: object

Represents a virtual camera in a 3D scene.

Provides a PyVista-like API for controlling camera position, orientation, and projection settings in VTK.wasm scenes.

Parameters:
  • position (tuple of float, optional) – Camera position as (x, y, z). Default is (0, 0, 1).

  • focal_point (tuple of float, optional) – Point the camera looks at as (x, y, z). Default is (0, 0, 0).

  • view_up (tuple of float, optional) – View-up vector as (x, y, z). Default is (0, 1, 0).

  • view_angle (float, optional) – Camera view angle (field of view) in degrees. Default is 30.0.

  • clipping_range (tuple of float, optional) – Near and far clipping plane distances as (near, far). Default is (0.01, 1000.01).

  • parallel_projection (bool, optional) – Enable parallel (orthographic) projection instead of perspective projection. Default is False.

  • elevation (float, optional) – Camera elevation angle in degrees. Default is 0.0.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.position = (5, 5, 5)
>>> camera.focal_point = (0, 0, 0)
>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(pv.Sphere())
>>> plotter.camera = camera
>>> 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), view_up: tuple[float, float, float] = (0.0, 1.0, 0.0), view_angle: float = 30.0, clipping_range: tuple[float, float] = (0.01, 1000.01), parallel_projection: bool = False, elevation: float = 0.0) None#

Initialize a Camera instance.

Methods

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

Initialize a Camera instance.

azimuth(angle)

Rotate the camera position horizontally around the focal point.

disable_parallel_projection()

Disable parallel projection (use perspective projection).

enable_parallel_projection()

Enable parallel (orthographic) projection.

orbit_elevation(angle)

Rotate the camera position vertically around the focal point.

roll(angle)

Roll the camera around the view direction axis.

zoom(factor)

Move the camera closer to or farther from the focal point.

Attributes

clipping_range

Get or set the clipping range (near, far).

elevation

Get or set the camera elevation angle in degrees.

focal_point

Get or set the camera focal point.

parallel_projection

Get or set parallel projection mode.

position

Get or set the camera position.

view_angle

Get or set the camera view angle in degrees.

view_up

Get or set the view-up vector.

azimuth(angle: float) None#

Rotate the camera position horizontally around the focal point.

Parameters:

angle (float) – Rotation angle in degrees. Positive values rotate counter-clockwise when viewed from above the up vector.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera(position=(0, 0, 5), focal_point=(0, 0, 0))
>>> camera.azimuth(90)
>>> import numpy as np
>>> np.allclose(camera.position, (5, 0, 0), atol=1e-10)
True
property clipping_range: tuple[float, float]#

Get or set the clipping range (near, far).

Parameters:

value (tuple of float) – Near and far clipping plane distances as (near, far).

Returns:

Clipping range as (near, far).

Return type:

tuple of float

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.clipping_range = (0.1, 100.0)
>>> camera.clipping_range
(0.1, 100.0)
disable_parallel_projection() None#

Disable parallel projection (use perspective projection).

Switches the camera from parallel projection to perspective projection. This is equivalent to setting parallel_projection = False.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.enable_parallel_projection()
>>> camera.disable_parallel_projection()
>>> camera.parallel_projection
False
property elevation: float#

Get or set the camera elevation angle in degrees.

The elevation angle controls the vertical rotation of the camera. It rotates the camera about the cross product of the negative of the direction of projection and the view up vector, using the focal point as the center of rotation.

Parameters:

value (float) – Elevation angle in degrees.

Returns:

Elevation angle in degrees.

Return type:

float

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.elevation
0.0
>>> camera.elevation = 45.0
>>> camera.elevation
45.0
enable_parallel_projection() None#

Enable parallel (orthographic) projection.

Switches the camera from perspective projection to parallel projection. This is equivalent to setting parallel_projection = True.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.enable_parallel_projection()
>>> camera.parallel_projection
True
property focal_point: tuple[float, float, float]#

Get or set the camera focal point.

Parameters:

value (tuple of float) – Focal point as (x, y, z).

Returns:

Focal point as (x, y, z).

Return type:

tuple of float

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.focal_point = (1, 2, 3)
>>> camera.focal_point
(1.0, 2.0, 3.0)
orbit_elevation(angle: float) None#

Rotate the camera position vertically around the focal point.

This method is named orbit_elevation to avoid conflict with the elevation property, which stores a static angle value.

Parameters:

angle (float) – Rotation angle in degrees. Positive values tilt the camera upward.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera(position=(0, 0, 5), focal_point=(0, 0, 0))
>>> camera.orbit_elevation(90)
>>> import numpy as np
>>> np.allclose(camera.position, (0, -5, 0), atol=1e-10)
True
property parallel_projection: bool#

Get or set parallel projection mode.

When True, uses parallel (orthographic) projection instead of perspective projection. Parallel projection is useful for viewing 2D datasets, CAD-like orthographic views, and scientific visualization where perspective distortion is undesirable.

Parameters:

value (bool) – Enable (True) or disable (False) parallel projection.

Returns:

Whether parallel projection is enabled.

Return type:

bool

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.parallel_projection = True
>>> camera.parallel_projection
True
property position: tuple[float, float, float]#

Get or set the camera position.

Parameters:

value (tuple of float) – Camera position as (x, y, z).

Returns:

Camera position as (x, y, z).

Return type:

tuple of float

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.position = (5, 0, 0)
>>> camera.position
(5.0, 0.0, 0.0)
roll(angle: float) None#

Roll the camera around the view direction axis.

Parameters:

angle (float) – Roll angle in degrees.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera(position=(0, 0, 5), focal_point=(0, 0, 0))
>>> camera.roll(90)
>>> import numpy as np
>>> np.allclose(camera.view_up, (1, 0, 0), atol=1e-10)
True
property view_angle: float#

Get or set the camera view angle in degrees.

Parameters:

value (float) – View angle in degrees (field of view).

Returns:

View angle in degrees.

Return type:

float

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.view_angle = 45.0
>>> camera.view_angle
45.0
property view_up: tuple[float, float, float]#

Get or set the view-up vector.

Parameters:

value (tuple of float) – View-up vector as (x, y, z).

Returns:

View-up vector as (x, y, z).

Return type:

tuple of float

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera()
>>> camera.view_up = (0, 0, 1)
>>> camera.view_up
(0.0, 0.0, 1.0)
zoom(factor: float) None#

Move the camera closer to or farther from the focal point.

Parameters:

factor (float) – Zoom factor. Values greater than 1 move the camera closer (zoom in); values between 0 and 1 move it farther away (zoom out).

Raises:

ValueError – If factor is not positive.

Examples

>>> import pyvista_wasm as pv
>>> camera = pv.Camera(position=(0, 0, 10), focal_point=(0, 0, 0))
>>> camera.zoom(2.0)
>>> import numpy as np
>>> np.allclose(camera.position, (0, 0, 5), atol=1e-10)
True