movis.layer.composition.LayerItem#
- class movis.layer.composition.LayerItem(layer: Layer, name: str = 'layer', transform: Transform | None = None, offset: float = 0.0, start_time: float = 0.0, end_time: float | None = None, audio_level: float = 0.0, visible: bool = True, audio: bool = True)[source]#
A wrapper layer for managing additional info. (e.g., the name and position) of each layer in a composition.
Usually, there is no need for the user to create this layer directly. However, editing additional information like the layer’s position or opacity, or when adding animations or effects, requires editing this layer.
LayerItemcan be accessed as the return value ofcomposition.add_layer()or by specifying it likecomposition['layer_name']. If you want to directly access the layer, refer to thelayer_item.layerproperty.- Args:
- layer:
The layer to be wrapped.
- name:
The name of the layer. The layer name must be unique within the composition.
- transform:
An instance of
Transformthat includes multiple properties used to transform the layer within the composition.- offset:
The starting time of the layer. For example, if
start_time=0.0andoffset=1.0, the layer will appear after 1 second in the composition.- start_time:
The start time of the layer. This variable is used to clip the layer in the time axis direction. For example, if
start_time=1.0andoffset=0.0, this layer will appear immediately with one second skipped.- end_time:
The end time of the layer. This variable is used to clip the layer in the time axis direction. For example, if
start_time=0.0,end_time=1.0, andoffset=0.0, this layer will disappear after one second. If not specified, the layer’s duration is used forend_time.- audio_level:
The relative audio level of the layer (dB). If the layer has no audio, this value is ignored.
- visible:
A flag specifying whether the layer is visible or not; if
visible=False, the layer in the composition is not rendered.- audio:
A flag specifying whether the audio is enabled or not; if
audio=False, the audio of the given layer is not used.
Methods
- add_effect(effect: Effect) Effect[source]#
Adds an effect to the layer.
- Args:
- effect:
The effect to be added to the layer.
- Returns:
The effect that was added.
- get_composition_coords(layer_coords: ndarray, time: float = 0.0, layer_size: tuple[int, int] | None = None) ndarray[source]#
Returns the coordinates of the composition from the coordinates of the layer.
- Examples:
>>> import movis as mv >>> import numpy as np >>> composition = mv.layer.Composition(size=(640, 480), duration=5.0) >>> layer = mv.layer.Image.from_color(size=scene.size, color='white') >>> scene.add_layer(layer, scale=0.5, name='item') >>> scene['item'].get_composition_coords( ... layer_coords=np.array([[0, 0], [640, 480]], dtype=float)) array([[160., 120.], [480., 360.]])
- Args:
- layer_coords:
The coordinates of the layer. The shape of the array must be
(N, 2)or(2,).- time:
The time at which the layer is rendered. Defaults to
0.0.- layer_size:
The size of the layer. If not specified, the size of the layer is determined from the layer’s current frame.
- Returns:
The coordinates of the composition from the coordinates of the layer. The shape of the array is
(N, 2).
- get_key(time: float) tuple[Hashable, Hashable, Hashable][source]#
Returns the state of the layer item at the given time.
- Args:
- time:
The time at which the layer is rendered.
- Returns:
A tuple of hashable keys representing the state of the layer at the given time.
- remove_effect(effect: Effect) None[source]#
Removes an effect from the layer.
- Args:
- effect:
The effect to be removed from the layer.
Attributes
anchor_pointThe anchor point of the layer.
blending_modeThe blending mode of the layer.
durationThe duration of the layer item.
effectsA list of effects applied to the layer.
opacityThe opacity of the layer.
origin_pointThe origin point of the layer.
positionThe position of the layer.
rotationThe rotation of the layer.
scaleThe scale of the layer.