mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
Fix rounding
This commit is contained in:
parent
3eff2fe3cb
commit
b00aab1eed
2 changed files with 115 additions and 45 deletions
|
|
@ -1969,8 +1969,6 @@ def get_id_from_sibling(node, history_only=True):
|
||||||
return first_id
|
return first_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Project settings
|
|
||||||
def set_scene_fps(fps, update=True):
|
def set_scene_fps(fps, update=True):
|
||||||
"""Set FPS from project configuration
|
"""Set FPS from project configuration
|
||||||
|
|
||||||
|
|
@ -1983,28 +1981,21 @@ def set_scene_fps(fps, update=True):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fps_mapping = {'15': 'game',
|
fps_mapping = {
|
||||||
'24': 'film',
|
'15': 'game',
|
||||||
'25': 'pal',
|
'24': 'film',
|
||||||
'30': 'ntsc',
|
'25': 'pal',
|
||||||
'48': 'show',
|
'30': 'ntsc',
|
||||||
'50': 'palf',
|
'48': 'show',
|
||||||
'60': 'ntscf',
|
'50': 'palf',
|
||||||
'23.98': '23.976fps',
|
'60': 'ntscf',
|
||||||
'23.976': '23.976fps',
|
'23.976023976023978': '23.976fps',
|
||||||
'29.97': '29.97fps',
|
'29.97002997002997': '29.97fps',
|
||||||
'47.952': '47.952fps',
|
'47.952047952047955': '47.952fps',
|
||||||
'47.95': '47.952fps',
|
'59.94005994005994': '59.94fps',
|
||||||
'59.94': '59.94fps',
|
'44100': '44100fps',
|
||||||
'44100': '44100fps',
|
'48000': '48000fps'
|
||||||
'48000': '48000fps'}
|
}
|
||||||
|
|
||||||
# pull from mapping
|
|
||||||
# this should convert float string to float and int to int
|
|
||||||
# so 25.0 is converted to 25, but 23.98 will be still float.
|
|
||||||
dec, ipart = math.modf(fps)
|
|
||||||
if dec == 0.0:
|
|
||||||
fps = int(ipart)
|
|
||||||
|
|
||||||
unit = fps_mapping.get(str(fps), None)
|
unit = fps_mapping.get(str(fps), None)
|
||||||
if unit is None:
|
if unit is None:
|
||||||
|
|
@ -2124,7 +2115,9 @@ def set_context_settings():
|
||||||
asset_data = asset_doc.get("data", {})
|
asset_data = asset_doc.get("data", {})
|
||||||
|
|
||||||
# Set project fps
|
# Set project fps
|
||||||
fps = asset_data.get("fps", project_data.get("fps", 25))
|
fps = convert_to_maya_fps(
|
||||||
|
asset_data.get("fps", project_data.get("fps", 25))
|
||||||
|
)
|
||||||
legacy_io.Session["AVALON_FPS"] = str(fps)
|
legacy_io.Session["AVALON_FPS"] = str(fps)
|
||||||
set_scene_fps(fps)
|
set_scene_fps(fps)
|
||||||
|
|
||||||
|
|
@ -2146,15 +2139,12 @@ def validate_fps():
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fps = get_current_project_asset(fields=["data.fps"])["data"]["fps"]
|
expected_fps = convert_to_maya_fps(
|
||||||
# TODO(antirotor): This is hack as for framerates having multiple
|
get_current_project_asset(fields=["data.fps"])["data"]["fps"]
|
||||||
# decimal places. FTrack is ceiling decimal values on
|
)
|
||||||
# fps to two decimal places but Maya 2019+ is reporting those fps
|
current_fps = mel.eval('currentTimeUnitToFPS()')
|
||||||
# with much higher resolution. As we currently cannot fix Ftrack
|
|
||||||
# rounding, we have to round those numbers coming from Maya.
|
|
||||||
current_fps = float_round(mel.eval('currentTimeUnitToFPS()'), 2)
|
|
||||||
|
|
||||||
fps_match = current_fps == fps
|
fps_match = current_fps == expected_fps
|
||||||
if not fps_match and not IS_HEADLESS:
|
if not fps_match and not IS_HEADLESS:
|
||||||
from openpype.widgets import popup
|
from openpype.widgets import popup
|
||||||
|
|
||||||
|
|
@ -2163,14 +2153,19 @@ def validate_fps():
|
||||||
dialog = popup.PopupUpdateKeys(parent=parent)
|
dialog = popup.PopupUpdateKeys(parent=parent)
|
||||||
dialog.setModal(True)
|
dialog.setModal(True)
|
||||||
dialog.setWindowTitle("Maya scene does not match project FPS")
|
dialog.setWindowTitle("Maya scene does not match project FPS")
|
||||||
dialog.setMessage("Scene %i FPS does not match project %i FPS" %
|
dialog.setMessage(
|
||||||
(current_fps, fps))
|
"Scene {} FPS does not match project {} FPS".format(
|
||||||
|
current_fps, expected_fps
|
||||||
|
)
|
||||||
|
)
|
||||||
dialog.setButtonText("Fix")
|
dialog.setButtonText("Fix")
|
||||||
|
|
||||||
# Set new text for button (add optional argument for the popup?)
|
# Set new text for button (add optional argument for the popup?)
|
||||||
toggle = dialog.widgets["toggle"]
|
toggle = dialog.widgets["toggle"]
|
||||||
update = toggle.isChecked()
|
update = toggle.isChecked()
|
||||||
dialog.on_clicked_state.connect(lambda: set_scene_fps(fps, update))
|
dialog.on_clicked_state.connect(
|
||||||
|
lambda: set_scene_fps(expected_fps, update)
|
||||||
|
)
|
||||||
|
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
||||||
|
|
@ -3353,3 +3348,85 @@ def iter_visible_nodes_in_range(nodes, start, end):
|
||||||
def get_attribute_input(attr):
|
def get_attribute_input(attr):
|
||||||
connections = cmds.listConnections(attr, plugs=True, destination=False)
|
connections = cmds.listConnections(attr, plugs=True, destination=False)
|
||||||
return connections[0] if connections else None
|
return connections[0] if connections else None
|
||||||
|
|
||||||
|
|
||||||
|
def convert_to_maya_fps(fps):
|
||||||
|
"""Convert any fps to supported Maya framerates."""
|
||||||
|
float_framerates = [
|
||||||
|
23.976023976023978,
|
||||||
|
# WTF is 29.97 df vs fps?
|
||||||
|
29.97002997002997,
|
||||||
|
47.952047952047955,
|
||||||
|
59.94005994005994
|
||||||
|
]
|
||||||
|
# 44100 fps evaluates as 41000.0. Why? Omitting for now.
|
||||||
|
int_framerates = [
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10,
|
||||||
|
12,
|
||||||
|
15,
|
||||||
|
16,
|
||||||
|
20,
|
||||||
|
24,
|
||||||
|
25,
|
||||||
|
30,
|
||||||
|
40,
|
||||||
|
48,
|
||||||
|
50,
|
||||||
|
60,
|
||||||
|
75,
|
||||||
|
80,
|
||||||
|
90,
|
||||||
|
100,
|
||||||
|
120,
|
||||||
|
125,
|
||||||
|
150,
|
||||||
|
200,
|
||||||
|
240,
|
||||||
|
250,
|
||||||
|
300,
|
||||||
|
375,
|
||||||
|
400,
|
||||||
|
500,
|
||||||
|
600,
|
||||||
|
750,
|
||||||
|
1200,
|
||||||
|
1500,
|
||||||
|
2000,
|
||||||
|
3000,
|
||||||
|
6000,
|
||||||
|
48000
|
||||||
|
]
|
||||||
|
|
||||||
|
# If input fps is a whole number we'll return.
|
||||||
|
if float(fps).is_integer():
|
||||||
|
# Validate fps is part of Maya's fps selection.
|
||||||
|
if fps not in int_framerates:
|
||||||
|
raise ValueError(
|
||||||
|
"Framerate \"{}\" is not supported in Maya".format(fps)
|
||||||
|
)
|
||||||
|
return fps
|
||||||
|
else:
|
||||||
|
# Differences to supported float frame rates.
|
||||||
|
differences = []
|
||||||
|
for i in float_framerates:
|
||||||
|
differences.append(abs(i - fps))
|
||||||
|
|
||||||
|
# Validate difference does not stray too far from supported framerates.
|
||||||
|
min_difference = min(differences)
|
||||||
|
min_index = differences.index(min_difference)
|
||||||
|
supported_framerate = float_framerates[min_index]
|
||||||
|
if round(min_difference) != 0:
|
||||||
|
raise ValueError(
|
||||||
|
"Framerate \"{}\" strays too far from any supported framerate"
|
||||||
|
" in Maya. Closest supported framerate is \"{}\"".format(
|
||||||
|
fps, supported_framerate
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return supported_framerate
|
||||||
|
|
|
||||||
|
|
@ -33,18 +33,11 @@ class ValidateMayaUnits(pyblish.api.ContextPlugin):
|
||||||
linearunits = context.data.get('linearUnits')
|
linearunits = context.data.get('linearUnits')
|
||||||
angularunits = context.data.get('angularUnits')
|
angularunits = context.data.get('angularUnits')
|
||||||
|
|
||||||
# TODO(antirotor): This is hack as for framerates having multiple
|
fps = context.data.get('fps')
|
||||||
# decimal places. FTrack is ceiling decimal values on
|
|
||||||
# fps to two decimal places but Maya 2019+ is reporting those fps
|
|
||||||
# with much higher resolution. As we currently cannot fix Ftrack
|
|
||||||
# rounding, we have to round those numbers coming from Maya.
|
|
||||||
# NOTE: this must be revisited yet again as it seems that Ftrack is
|
|
||||||
# now flooring the value?
|
|
||||||
fps = mayalib.float_round(context.data.get('fps'), 2, ceil)
|
|
||||||
|
|
||||||
# TODO repace query with using 'context.data["assetEntity"]'
|
# TODO repace query with using 'context.data["assetEntity"]'
|
||||||
asset_doc = get_current_project_asset()
|
asset_doc = get_current_project_asset()
|
||||||
asset_fps = asset_doc["data"]["fps"]
|
asset_fps = mayalib.convert_to_maya_fps(asset_doc["data"]["fps"])
|
||||||
|
|
||||||
self.log.info('Units (linear): {0}'.format(linearunits))
|
self.log.info('Units (linear): {0}'.format(linearunits))
|
||||||
self.log.info('Units (angular): {0}'.format(angularunits))
|
self.log.info('Units (angular): {0}'.format(angularunits))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue