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

Set resolution using the virtual resolution and set pixel aspect ratio from entity #22

Merged
merged 3 commits into from
Jan 22, 2025
Merged
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
23 changes: 21 additions & 2 deletions client/ayon_cinema4d/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,29 @@ def set_resolution_from_entity(task_entity, doc=None):
attrib = task_entity["attrib"]
width: int = int(attrib["resolutionWidth"])
height: int = int(attrib["resolutionHeight"])
pixel_aspect: float = attrib["pixelAspect"]

@contextlib.contextmanager
def _unlocked_ratio(render_data):
"""Temporarily unlock the ratio of the render resolution."""
original = render_data[c4d.RDATA_LOCKRATIO]
render_data[c4d.RDATA_LOCKRATIO] = False
try:
yield
finally:
render_data[c4d.RDATA_LOCKRATIO] = original

rd = doc.GetFirstRenderData()
while rd:
rd[c4d.RDATA_XRES] = width
rd[c4d.RDATA_YRES] = height
# Fix #20: Set the virtual resolution with user interaction so Redshift
# still triggers some additional checks on the attribute change.
with _unlocked_ratio(rd):
flag = c4d.DESCFLAGS_SET_USERINTERACTION
rd.SetParameter(c4d.RDATA_XRES_VIRTUAL, width, flag)
rd.SetParameter(c4d.RDATA_YRES_VIRTUAL, height, flag)

# Set pixel aspect ratio
rd[c4d.RDATA_PIXELASPECT] = pixel_aspect

rd = rd.GetNext()
c4d.EventAdd()
Loading