Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Flame: support for comment with xml attribute overrides #2892

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
110 changes: 110 additions & 0 deletions openpype/hosts/flame/plugins/publish/collect_timeline_instances.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import pyblish
import openpype
import openpype.hosts.flame.api as opfapi
Expand All @@ -6,6 +7,10 @@
# # developer reload modules
from pprint import pformat

# constatns
NUM_PATERN = re.compile(r"([0-9\.]+)")
TXT_PATERN = re.compile(r"([a-zA-Z]+)")


class CollectTimelineInstances(pyblish.api.ContextPlugin):
"""Collect all Timeline segment selection."""
Expand All @@ -16,6 +21,16 @@ class CollectTimelineInstances(pyblish.api.ContextPlugin):

audio_track_items = []

# TODO: add to settings
# settings
xml_preset_attrs_from_comments = {
"width": "number",
"height": "number",
"pixelRatio": "float",
"resizeType": "string",
"resizeFilter": "string"
}

def process(self, context):
project = context.data["flameProject"]
sequence = context.data["flameSequence"]
Expand All @@ -26,6 +41,10 @@ def process(self, context):
# process all sellected
with opfapi.maintained_segment_selection(sequence) as segments:
for segment in segments:
comment_attributes = self._get_comment_attributes(segment)
self.log.debug("_ comment_attributes: {}".format(
pformat(comment_attributes)))

clip_data = opfapi.get_segment_attributes(segment)
clip_name = clip_data["segment_name"]
self.log.debug("clip_name: {}".format(clip_name))
Expand Down Expand Up @@ -101,6 +120,9 @@ def process(self, context):
# add resolution
self._get_resolution_to_data(inst_data, context)

# add comment attributes if any
inst_data.update(comment_attributes)

# create instance
instance = context.create_instance(**inst_data)

Expand All @@ -126,6 +148,94 @@ def process(self, context):
if marker_data.get("reviewTrack") is not None:
instance.data["reviewAudio"] = True

def _get_comment_attributes(self, segment):
comment = segment.comment.get_value()

# try to find attributes
attributes = {
"xml_overrides": {
"pixelRatio": 1.00}
}
# search for `:`
for split in self._split_comments(comment):
# make sure we ignore if not `:` in key
if ":" not in split:
continue

self._get_xml_preset_attrs(
attributes, split)

# add xml overides resolution to instance data
xml_overrides = attributes["xml_overrides"]
if xml_overrides.get("width"):
attributes.update({
"resolutionWidth": xml_overrides["width"],
"resolutionHeight": xml_overrides["height"],
"pixelAspect": xml_overrides["pixelRatio"]
})

return attributes

def _get_xml_preset_attrs(self, attributes, split):

# split to key and value
key, value = split.split(":")

for a_name, a_type in self.xml_preset_attrs_from_comments.items():
# exclude all not related attributes
if a_name.lower() not in key.lower():
continue

# get pattern defined by type
pattern = TXT_PATERN
if a_type in ("number" , "float"):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace before ','

pattern = NUM_PATERN

res_goup = pattern.findall(value)

# raise if nothing is found as it is not correctly defined
if not res_goup:
raise ValueError((
"Value for `{}` attribute is not "
"set correctly: `{}`").format(a_name, split))

if "string" in a_type:
_value = res_goup[0]
if "float" in a_type:
_value = float(res_goup[0])
if "number" in a_type:
_value = int(res_goup[0])

attributes["xml_overrides"][a_name] = _value

# condition for resolution in key
if "resolution" in key.lower():
res_goup = NUM_PATERN.findall(value)
# check if axpect was also defined
# 1920x1080x1.5
aspect = res_goup[2] if len(res_goup) > 2 else 1

width = int(res_goup[0])
height = int(res_goup[1])
pixel_ratio = float(aspect)
attributes["xml_overrides"].update({
"width": width,
"height": height,
"pixelRatio": pixel_ratio
})

def _split_comments(self, comment_string):
# first split comment by comma
split_comments = []
if "," in comment_string:
split_comments.extend(comment_string.split(","))
elif ";" in comment_string:
split_comments.extend(comment_string.split(";"))
else:
split_comments.append(comment_string)

return split_comments

def _get_head_tail(self, clip_data, first_frame):
# calculate head and tail with forward compatibility
head = clip_data.get("segment_head")
Expand Down
12 changes: 12 additions & 0 deletions openpype/hosts/flame/plugins/publish/extract_subset_resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pprint import pformat
from copy import deepcopy

import pyblish.api
import openpype.api
from openpype.hosts.flame import api as opfapi
Expand All @@ -23,6 +24,7 @@ class ExtractSubsetResources(openpype.api.Extractor):
"xml_preset_file": "Jpeg (8-bit).xml",
"xml_preset_dir": "",
"export_type": "File Sequence",
"ignore_comment_attrs": True,
"colorspace_out": "Output - sRGB",
"representation_add_range": False,
"representation_tags": ["thumbnail"]
Expand All @@ -32,6 +34,7 @@ class ExtractSubsetResources(openpype.api.Extractor):
"xml_preset_file": "Apple iPad (1920x1080).xml",
"xml_preset_dir": "",
"export_type": "Movie",
"ignore_comment_attrs": True,
"colorspace_out": "Output - Rec.709",
"representation_add_range": True,
"representation_tags": [
Expand Down Expand Up @@ -102,6 +105,7 @@ def process(self, instance):
preset_dir = preset_config["xml_preset_dir"]
export_type = preset_config["export_type"]
repre_tags = preset_config["representation_tags"]
ignore_comment_attrs = preset_config["ignore_comment_attrs"]
color_out = preset_config["colorspace_out"]

# get frame range with handles for representation range
Expand Down Expand Up @@ -131,6 +135,14 @@ def process(self, instance):
"startFrame": frame_start
})

if not ignore_comment_attrs:
# add any xml overrides collected form segment.comment
modify_xml_data.update(instance.data["xml_overrides"])

self.log.debug("__ modify_xml_data: {}".format(pformat(
modify_xml_data
)))

# with maintained duplication loop all presets
with opfapi.maintained_object_duplication(
exporting_clip) as duplclip:
Expand Down
1 change: 1 addition & 0 deletions openpype/settings/defaults/project_settings/flame.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"xml_preset_file": "OpenEXR (16-bit fp DWAA).xml",
"xml_preset_dir": "",
"export_type": "File Sequence",
"ignore_comment_attrs": false,
"colorspace_out": "ACES - ACEScg",
"representation_add_range": true,
"representation_tags": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
]

},
{
"type": "separator"
},
{
"type": "boolean",
"key": "ignore_comment_attrs",
"label": "Ignore attributes parsed from a segment comments"
},
{
"type": "separator"
},
{
"key": "colorspace_out",
"label": "Output color (imageio)",
Expand Down