Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the OTIO reader annotation #646

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})"
)
Loading