Skip to content

Commit

Permalink
Clean up the OTIO reader annotation (#646)
Browse files Browse the repository at this point in the history
### Clean up the OTIO reader annotation

This PR aims to clean up a bit the code related to the OTIO reader for
annotations in Live Review.

### Question
I see that some files for other hooks and schemas are in camel case
instead of snake case. Does anyone knows if there is a reason? Is
everyone ok with me renaming the files inside `otio_reader` to use snake
case instead?

---------

Signed-off-by: Éloïse Brosseau <[email protected]>
  • Loading branch information
eloisebrosseau authored Dec 16, 2024
1 parent 109dd45 commit bc93220
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 46 deletions.
41 changes: 18 additions & 23 deletions src/plugins/rv-packages/otio_reader/annotation_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
from rv import commands, extra_commands


def hook_function(in_timeline, argument_map=None) -> None:
def hook_function(
in_timeline: otio.schemadef.Annotation.Annotation, argument_map: dict | None = None
) -> None:
"""A hook for the annotation schema"""
for layer in in_timeline.layers:
if layer.name == "Paint":
if type(layer.layer_range) is otio._opentime.TimeRange:
range = layer.layer_range
if isinstance(layer.layer_range, otio._opentime.TimeRange):
time_range = layer.layer_range
else:
range = otio.opentime.TimeRange(
time_range = otio.opentime.TimeRange(
layer.layer_range["start_time"], layer.layer_range["duration"]
)

relative_time = range.end_time_inclusive()
relative_time = time_range.end_time_inclusive()
frame = relative_time.to_frames()

source_node = argument_map.get("source_group")
Expand All @@ -41,12 +44,12 @@ def hook_function(in_timeline, argument_map=None) -> None:
effectHook.add_rv_effect_props(
pen_component,
{
"color": [float(x) for x in layer.rgba],
"color": list(map(float, layer.rgba)),
"brush": layer.brush,
"debug": 1,
"join": 3,
"cap": 2,
"splat": 1,
"cap": 1,
"splat": 0,
"mode": 0 if layer.type == "COLOR" else 1,
},
)
Expand Down Expand Up @@ -88,18 +91,10 @@ def hook_function(in_timeline, argument_map=None) -> None:
global_width = 2 / 15 # 0.133333...

for point in layer.points:
points = commands.getFloatProperty(points_property)
if (
len(points) > 1
and points[-1] == point.y * global_scale.y
and points[-2] == point.x * global_scale.x
):
pass
else:
commands.insertFloatProperty(
points_property,
[point.x * global_scale.x, point.y * global_scale.y],
)
commands.insertFloatProperty(
width_property, [point.width * global_width]
)
commands.insertFloatProperty(
points_property,
[point.x * global_scale.x, point.y * global_scale.y],
)
commands.insertFloatProperty(
width_property, [point.width * global_width]
)
15 changes: 11 additions & 4 deletions src/plugins/rv-packages/otio_reader/annotation_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def __init__(
self.layers = layers

_visible = otio.core.serializable_field(
"visible", required_type=bool, doc=("Visible: expects either true or false")
"visible", required_type=bool, doc=("visible: expects either true or false")
)

_layers = otio.core.serializable_field(
"layers", required_type=list, doc=("Layers: expects a list of annotation types")
"layers", required_type=list, doc=("layers: expects a list of annotation types")
)

@property
Expand All @@ -53,7 +53,14 @@ def layers(self, val: list):
self._layers = val

def __str__(self) -> str:
return f"Annotation({self.name}, {self.effect_name}, {self.visible}, {self.layers})"
return (
f"Annotation({self.name}, {self.effect_name}, {self.visible}, "
f"{self.layers})"
)

def __repr__(self) -> str:
return f"otio.schema.Annotation(name={self.name!r}, effect_name={self.effect_name!r}, visible={self.visible!r}, layers={self.layers!r})"
return (
f"otio.schema.Annotation(name={self.name!r}, "
f"effect_name={self.effect_name!r}, "
f"visible={self.visible!r}, layers={self.layers!r})"
)
22 changes: 11 additions & 11 deletions src/plugins/rv-packages/otio_reader/paint_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,61 @@ def __init__(
self.ghost = ghost

name = otio.core.serializable_field(
"name", required_type=str, doc=("Name: expects a string")
"name", required_type=str, doc=("name: expects a string")
)

_points = otio.core.serializable_field(
"points", required_type=list, doc=("Points: expects a list of point objects")
"points", required_type=list, doc=("points: expects a list of point objects")
)

@property
def points(self) -> list:
return self._points

@points.setter
def points(self, val: list) -> None:
def points(self, val: list):
self._points = val

_rgba = otio.core.serializable_field(
"rgba", required_type=list, doc=("RGBA: expects a list of four floats")
"rgba", required_type=list, doc=("rgba: expects a list of four floats")
)

@property
def rgba(self) -> list:
return self._rgba

@rgba.setter
def rgba(self, val: list) -> list:
def rgba(self, val: list) -> None:
self._rgba = val

type = otio.core.serializable_field(
"type", required_type=str, doc=("Type: expects a string")
"type", required_type=str, doc=("type: expects a string")
)

brush = otio.core.serializable_field(
"brush", required_type=str, doc=("Brush: expects a string")
"brush", required_type=str, doc=("brush: expects a string")
)

_layer_range = otio.core.serializable_field(
"layer_range",
required_type=otio.opentime.TimeRange,
doc=("Layer_range: expects a TimeRange object"),
doc=("layer_range: expects a TimeRange object"),
)

@property
def layer_range(self) -> otio.opentime.TimeRange:
return self._layer_range

@layer_range.setter
def layer_range(self, val) -> otio.opentime.TimeRange:
def layer_range(self, val):
self._layer_range = val

_hold = otio.core.serializable_field(
"hold", required_type=bool, doc=("Hold: expects either true or false")
"hold", required_type=bool, doc=("hold: expects either true or false")
)

_ghost = otio.core.serializable_field(
"ghost", required_type=bool, doc=("Ghost: expects either true or false")
"ghost", required_type=bool, doc=("ghost: expects either true or false")
)

def __str__(self) -> str:
Expand Down
12 changes: 4 additions & 8 deletions src/plugins/rv-packages/otio_reader/point_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ class Point(otio.core.SerializableObject):
_name = "Point"

def __init__(
self,
width: float | None = None,
x: float | None = None,
y: float | None = None
self, width: float | None = None, x: float | None = None, y: float | None = None
) -> None:
super().__init__()
self.width = width
self.x = x
self.y = y

width = otio.core.serializable_field(
"width", required_type=float, doc=("Width: expect a float")
"width", required_type=float, doc=("width: expects a float")
)

x = otio.core.serializable_field(
Expand All @@ -55,10 +52,9 @@ def __init__(
)

def __str__(self) -> str:
return f"Point{self.width}, {self.x}, {self.y}"
return f"Point({self.width}, {self.x}, {self.y})"

def __repr__(self) -> str:
return (
f"otio.schema.Point(width={self.width!r}, x={self.x!r}, "
f"y={self.y!r})"
f"otio.schema.Point(width={self.width!r}, x={self.x!r}, " f"y={self.y!r})"
)

0 comments on commit bc93220

Please sign in to comment.