Skip to content

Camera class

Camera related objects and classes.

Camera(clip: Clip, data: george.TVPCamera | None = None)

Bases: pytvpaint.utils.Refreshable

The Camera class represents the camera in a TVPaint clip.

There's only one camera in the clip so instantiating multiple objects of this class won't create cameras.

Source code in pytvpaint/camera.py
26
27
28
29
30
def __init__(self, clip: Clip, data: george.TVPCamera | None = None) -> None:
    super().__init__()
    self._clip = clip
    self._data: george.TVPCamera = data or george.tv_camera_info_get()
    self._points: list[CameraPoint] = []

clip: Clip property

The camera's clip.

points: Iterator[CameraPoint] property

Iterator for the CameraPoint objects of the camera.

refresh() -> None

Refreshed the camera data.

Source code in pytvpaint/camera.py
32
33
34
35
36
def refresh(self) -> None:
    """Refreshed the camera data."""
    if not self.refresh_on_call and self._data:
        return
    self._data = george.tv_camera_info_get()

make_current() -> None

Makes the parent clip the current one, thereby making sure the correct camera will be set.

Source code in pytvpaint/camera.py
47
48
49
def make_current(self) -> None:
    """Makes the parent clip the current one, thereby making sure the correct camera will be set."""
    self._clip.make_current()

anti_aliasing() -> int

The antialiasing value of the camera.

Source code in pytvpaint/camera.py
106
107
108
109
110
@refreshed_property
@set_as_current
def anti_aliasing(self) -> int:
    """The antialiasing value of the camera."""
    return self._data.anti_aliasing

insert_point(index: int, x: int, y: int, angle: int, scale: float) -> CameraPoint

Insert a new point in the camera path.

Source code in pytvpaint/camera.py
123
124
125
126
127
128
129
130
131
132
133
@set_as_current
def insert_point(
    self,
    index: int,
    x: int,
    y: int,
    angle: int,
    scale: float,
) -> CameraPoint:
    """Insert a new point in the camera path."""
    return CameraPoint.new(self, index, x, y, angle, scale)

get_point_data_at(position: float) -> george.TVPCameraPoint

Get the points data interpolated at that position (between 0 and 1).

Source code in pytvpaint/camera.py
145
146
147
148
149
@set_as_current
def get_point_data_at(self, position: float) -> george.TVPCameraPoint:
    """Get the points data interpolated at that position (between 0 and 1)."""
    position = max(0.0, min(position, 1.0))
    return george.tv_camera_interpolation(position)

remove_point(index: int) -> None

Remove a point at that index.

Source code in pytvpaint/camera.py
151
152
153
154
155
156
157
158
@set_as_current
def remove_point(self, index: int) -> None:
    """Remove a point at that index."""
    try:
        point = next(p for i, p in enumerate(self.points) if i == index)
        point.remove()
    except StopIteration:
        pass

CameraPoint(index: int, camera: Camera, data: george.TVPCameraPoint | None = None)

Bases: pytvpaint.utils.Removable

A CameraPoint is a point on the camera path.

You can use them to animate the camera movement.

Source code in pytvpaint/camera.py
167
168
169
170
171
172
173
174
175
176
def __init__(
    self,
    index: int,
    camera: Camera,
    data: george.TVPCameraPoint | None = None,
) -> None:
    super().__init__()
    self._index: int = index
    self._camera: Camera = camera
    self._data = data or george.tv_camera_enum_points(self._index)

data: george.TVPCameraPoint property

Returns the raw data of the point.

index: int property

The index of the point in the path.

camera: Camera property

The camera instance it belongs to.

refresh() -> None

Refreshed the camera point data.

Source code in pytvpaint/camera.py
178
179
180
181
182
183
def refresh(self) -> None:
    """Refreshed the camera point data."""
    super().refresh()
    if not self.refresh_on_call and self._data:
        return
    self._data = george.tv_camera_enum_points(self._index)

new(camera: Camera, index: int, x: int, y: int, angle: int, scale: float) -> CameraPoint classmethod

Create a new point and add it to the camera path at that index.

Source code in pytvpaint/camera.py
276
277
278
279
280
281
282
283
284
285
286
287
288
@classmethod
def new(
    cls,
    camera: Camera,
    index: int,
    x: int,
    y: int,
    angle: int,
    scale: float,
) -> CameraPoint:
    """Create a new point and add it to the camera path at that index."""
    george.tv_camera_insert_point(index, x, y, angle, scale)
    return cls(index, camera)

remove() -> None

Remove the camera point.

Warning

the point instance won't be usable after that call

Source code in pytvpaint/camera.py
290
291
292
293
294
295
296
297
def remove(self) -> None:
    """Remove the camera point.

    Warning:
        the point instance won't be usable after that call
    """
    george.tv_camera_remove_point(self.index)
    self.mark_removed()