trimesh.scene.cameras#

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

Bases: object

property K#

Get the intrinsic matrix for the Camera object.

Returns:

K – Intrinsic matrix for camera

Return type:

(3, 3) float

__init__(name=None, resolution=None, focal=None, fov=None, z_near=0.01, z_far=1000.0)#

Create a new Camera object that stores camera intrinsic and extrinsic parameters.

TODO: skew is not supported TODO: cx and cy that are not half of width and height

Parameters:
  • name (str or None) – Name for camera to be used as node name

  • resolution ((2,) int) – Pixel size in (height, width)

  • focal ((2,) float) – Focal length in pixels. Either pass this OR FOV but not both. focal = (K[0][0], K[1][1])

  • fov ((2,) float) – Field of view (fovx, fovy) in degrees

  • z_near (float) – What is the closest

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: 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.

Examples

`python points = np.array([0, 0, 0], [1, 1, 1]) scene.camera_transform = scene.camera.look_at(points) `

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