Skip to content

Commit 7f4056e

Browse files
authored
Merge pull request #32 from BigRoy/bugfix/collect_render_resolution_from_tool
Collect render instance resolution from the tool in comp instead of from comp frame format prefs
2 parents f744302 + f226268 commit 7f4056e

File tree

3 files changed

+96
-62
lines changed

3 files changed

+96
-62
lines changed

client/ayon_fusion/api/lib.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,72 @@ def prompt_reset_context():
405405
update_content_on_context_change()
406406

407407
dialog.deleteLater()
408+
409+
410+
@contextlib.contextmanager
411+
def temp_expression(attribute, frame, expression):
412+
"""Temporarily set an expression on an attribute during context"""
413+
# Save old comment
414+
old_comment = ""
415+
has_expression = False
416+
417+
if attribute[frame] not in ["", None]:
418+
if attribute.GetExpression() is not None:
419+
has_expression = True
420+
old_comment = attribute.GetExpression()
421+
attribute.SetExpression(None)
422+
else:
423+
old_comment = attribute[frame]
424+
attribute[frame] = ""
425+
426+
try:
427+
attribute.SetExpression(expression)
428+
yield
429+
finally:
430+
# Reset old comment
431+
attribute.SetExpression(None)
432+
if has_expression:
433+
attribute.SetExpression(old_comment)
434+
else:
435+
attribute[frame] = old_comment
436+
437+
438+
def get_tool_resolution(tool, frame):
439+
"""Return the 2D input resolution to a Fusion tool
440+
441+
If the current tool hasn't been rendered its input resolution
442+
hasn't been saved. To combat this, add an expression in
443+
the comments field to read the resolution
444+
445+
Args
446+
tool (Fusion Tool): The tool to query input resolution
447+
frame (int): The frame to query the resolution on.
448+
449+
Returns:
450+
tuple: width, height as 2-tuple of integers
451+
452+
Raises:
453+
ValueError: Unable to retrieve comp resolution.
454+
455+
"""
456+
comp = tool.Composition
457+
attribute = tool["Comments"]
458+
459+
# False undo removes the undo-stack from the undo list
460+
with comp_lock_and_undo_chunk(comp, "Read resolution", False):
461+
462+
# Get width
463+
with temp_expression(attribute, frame, "self.Input.OriginalWidth"):
464+
value = attribute[frame]
465+
if value is None:
466+
raise ValueError("Failed to read input width")
467+
width = int(value)
468+
469+
# Get height
470+
with temp_expression(attribute, frame, "self.Input.OriginalHeight"):
471+
value = attribute[frame]
472+
if value is None:
473+
raise ValueError("Failed to read input height")
474+
height = int(value)
475+
476+
return width, height

client/ayon_fusion/plugins/publish/collect_render.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from ayon_core.pipeline import publish
66
from ayon_core.pipeline.publish import RenderInstance
7-
from ayon_fusion.api.lib import get_frame_path
7+
from ayon_fusion.api.lib import get_frame_path, get_tool_resolution
88

99

1010
@attr.s
@@ -50,6 +50,19 @@ def get_instances(self, context):
5050
if product_type not in ["render", "image"]:
5151
continue
5252

53+
# Get resolution from tool if we can
54+
tool = inst.data["transientData"]["tool"]
55+
try:
56+
width, height = get_tool_resolution(
57+
tool, frame=inst.data["frameStart"])
58+
except ValueError:
59+
self.log.debug(
60+
f"Unable to get resolution from tool: {tool}. "
61+
"Falling back to comp frame format resolution "
62+
"preferences.")
63+
width = comp_frame_format_prefs.get("Width")
64+
height = comp_frame_format_prefs.get("Height")
65+
5366
instance_families = inst.data.get("families", [])
5467
product_name = inst.data["productName"]
5568
instance = FusionRenderInstance(
@@ -69,8 +82,8 @@ def get_instances(self, context):
6982
setMembers='',
7083
publish=True,
7184
name=product_name,
72-
resolutionWidth=comp_frame_format_prefs.get("Width"),
73-
resolutionHeight=comp_frame_format_prefs.get("Height"),
85+
resolutionWidth=width,
86+
resolutionHeight=height,
7487
pixelAspect=aspect_x / aspect_y,
7588
tileRendering=False,
7689
tilesX=0,

client/ayon_fusion/plugins/publish/validate_saver_resolution.py

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
)
66

77
from ayon_fusion.api.action import SelectInvalidAction
8-
from ayon_fusion.api import comp_lock_and_undo_chunk
8+
from ayon_fusion.api.lib import get_tool_resolution
99

1010

1111
class ValidateSaverResolution(
@@ -51,7 +51,16 @@ def get_invalid(cls, instance):
5151
def get_resolution(cls, instance):
5252
saver = instance.data["tool"]
5353
first_frame = instance.data["frameStartHandle"]
54-
return cls.get_tool_resolution(saver, frame=first_frame)
54+
55+
try:
56+
return get_tool_resolution(saver, frame=first_frame)
57+
except ValueError:
58+
raise PublishValidationError(
59+
"Cannot get resolution info for frame '{}'.\n\n "
60+
"Please check that saver has connected input.".format(
61+
first_frame
62+
)
63+
)
5564

5665
@classmethod
5766
def get_expected_resolution(cls, instance):
@@ -65,60 +74,3 @@ def get_expected_resolution(cls, instance):
6574

6675
attributes = entity["attrib"]
6776
return attributes["resolutionWidth"], attributes["resolutionHeight"]
68-
69-
@classmethod
70-
def get_tool_resolution(cls, tool, frame):
71-
"""Return the 2D input resolution to a Fusion tool
72-
73-
If the current tool hasn't been rendered its input resolution
74-
hasn't been saved. To combat this, add an expression in
75-
the comments field to read the resolution
76-
77-
Args
78-
tool (Fusion Tool): The tool to query input resolution
79-
frame (int): The frame to query the resolution on.
80-
81-
Returns:
82-
tuple: width, height as 2-tuple of integers
83-
84-
"""
85-
comp = tool.Composition
86-
87-
# False undo removes the undo-stack from the undo list
88-
with comp_lock_and_undo_chunk(comp, "Read resolution", False):
89-
# Save old comment
90-
old_comment = ""
91-
has_expression = False
92-
93-
if tool["Comments"][frame] not in ["", None]:
94-
if tool["Comments"].GetExpression() is not None:
95-
has_expression = True
96-
old_comment = tool["Comments"].GetExpression()
97-
tool["Comments"].SetExpression(None)
98-
else:
99-
old_comment = tool["Comments"][frame]
100-
tool["Comments"][frame] = ""
101-
# Get input width
102-
tool["Comments"].SetExpression("self.Input.OriginalWidth")
103-
if tool["Comments"][frame] is None:
104-
raise PublishValidationError(
105-
"Cannot get resolution info for frame '{}'.\n\n "
106-
"Please check that saver has connected input.".format(
107-
frame
108-
)
109-
)
110-
111-
width = int(tool["Comments"][frame])
112-
113-
# Get input height
114-
tool["Comments"].SetExpression("self.Input.OriginalHeight")
115-
height = int(tool["Comments"][frame])
116-
117-
# Reset old comment
118-
tool["Comments"].SetExpression(None)
119-
if has_expression:
120-
tool["Comments"].SetExpression(old_comment)
121-
else:
122-
tool["Comments"][frame] = old_comment
123-
124-
return width, height

0 commit comments

Comments
 (0)