trimesh.scene.cameras

Classes:

Camera([name, resolution, focal, fov, …])

Functions:

camera_to_rays(camera)

Calculate the trimesh.scene.Camera object to direction vectors.

look_at(points, fov[, rotation, distance, …])

Generate transform for a camera to keep a list of points in the camera’s field of view.

ray_pixel_coords(camera)

Get the x-y coordinates of rays in camera coordinates at z == -1.

class trimesh.scene.cameras.Camera(name=None, resolution=None, focal=None, fov=None, z_near=0.01, z_far=1000.0)

Bases: object

Attributes:

K

Get the intrinsic matrix for the Camera object.

focal

Get the focal length in pixels for the camera.

fov

Get the field of view in degrees.

resolution

Get the camera resolution in pixels.

Methods:

angles()

Get ray spherical coordinates in radians.

copy()

Safely get a copy of the current camera.

look_at(points, **kwargs)

Generate transform for a camera to keep a list of points in the camera’s field of view.

to_rays()

Calculate ray direction vectors.

property K

Get the intrinsic matrix for the Camera object.

Returns

K – Intrinsic matrix for camera

Return type

(3, 3) float

angles()

Get ray spherical coordinates in radians.

Returns

angles – Ray spherical coordinate angles in radians.

Return type

(n, 2) float

copy()

Safely get a copy of the current camera.

property focal

Get the focal length in pixels for the camera.

Returns

focal – Focal length in pixels

Return type

(2,) float

property fov

Get the field of view in degrees.

Returns

fov – XY field of view in degrees

Return type

(2,) float

look_at(points, **kwargs)

Generate transform for a camera to keep a list of points in the camera’s field of view.

Parameters
  • points ((n, 3) float) – Points in space

  • rotation (None, or (4, 4) float) – Rotation matrix for initial rotation

  • distance (None or float) – Distance from camera to center

  • center (None, or (3,) float) – Center of field of view.

Returns

transform – Transformation matrix from world to camera

Return type

(4, 4) float

property resolution

Get the camera resolution in pixels.

Returns

Camera resolution in pixels

Return type

resolution (2,) float

to_rays()

Calculate ray direction vectors.

Will return one ray per pixel, as set in self.resolution.

Returns

vectors – Ray direction vectors in camera frame with z == -1

Return type

(n, 3) float

trimesh.scene.cameras.camera_to_rays(camera)

Calculate the trimesh.scene.Camera object to direction vectors.

Will return one ray per pixel, as set in camera.resolution.

Parameters

camera (trimesh.scene.Camera) –

Returns

vectors – Ray direction vectors in camera frame with z == -1

Return type

(n, 3) float

trimesh.scene.cameras.look_at(points, fov, rotation=None, distance=None, center=None, pad=None)

Generate transform for a camera to keep a list of points in the camera’s field of view.

Parameters
  • points ((n, 3) float) – Points in space

  • fov ((2,) float) – Field of view, in DEGREES

  • rotation (None, or (4, 4) float) – Rotation matrix for initial rotation

  • distance (None or float) – Distance from camera to center

  • center (None, or (3,) float) – Center of field of view.

Returns

transform – Transformation matrix from world to camera

Return type

(4, 4) float

trimesh.scene.cameras.ray_pixel_coords(camera)

Get the x-y coordinates of rays in camera coordinates at z == -1.

One coordinate pair will be given for each pixel as defined in camera.resolution. If reshaped, the returned array corresponds to pixels of the rendered image.

Examples

```python xy = ray_pixel_coords(camera).reshape(

tuple(camera.coordinates) + (2,))

top_left == xy[0, 0] bottom_right == xy[-1, -1] ```

Parameters

camera (trimesh.scene.Camera) – Camera object to generate rays from

Returns

xy – x-y coordinates of intersection of each camera ray with the z == -1 frame

Return type

(n, 2) float