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

Maya: Use resolution and frame range from task entity #39

Closed
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
18 changes: 13 additions & 5 deletions client/ayon_core/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from maya import cmds, mel
from maya.api import OpenMaya

from ayon_api import get_task_by_name
from ayon_core.client import (
get_project,
get_asset_by_name,
Expand Down Expand Up @@ -2614,17 +2615,24 @@ def reset_scene_resolution():
project_name = get_current_project_name()
project_doc = get_project(project_name)
project_data = project_doc["data"]
asset_data = get_current_project_asset()["data"]
asset_data_root = get_current_project_asset()
asset_data = asset_data_root["data"]

task_name = get_current_task_name()
task_entity = get_task_by_name(
project_name, asset_data_root["_id"], task_name)

# Set project resolution
width_key = "resolutionWidth"
height_key = "resolutionHeight"
pixelAspect_key = "pixelAspect"

width = asset_data.get(width_key, project_data.get(width_key, 1920))
height = asset_data.get(height_key, project_data.get(height_key, 1080))
pixelAspect = asset_data.get(pixelAspect_key,
project_data.get(pixelAspect_key, 1))
# Get frame information from task entity
# NOTE: If there is no task override then the asset
# value is automatically returned instead
width = task_entity["attrib"][width_key]
height = task_entity["attrib"][height_key]
pixelAspect = task_entity["attrib"][pixelAspect_key]

set_scene_resolution(width, height, pixelAspect)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pyblish.api
from ayon_core.hosts.maya.api.lib import get_all_children

from ayon_api import get_task_by_name


class CollectNewInstances(pyblish.api.InstancePlugin):
"""Gather members for instances and pre-defined attribute
Expand Down Expand Up @@ -91,6 +93,13 @@ def process(self, instance):
instance.data["frameEnd"] + instance.data["handleEnd"]
)

project_name = instance.context.data["projectName"]
asset_entity = instance.context.data["assetEntity"]
task_name = instance.data["task"]
task_entity = get_task_by_name(
project_name, asset_entity["_id"], task_name)
instance.data["taskEntity"] = task_entity

def get_all_parents(self, nodes):
"""Get all parents by using string operations (optimization)

Expand Down
86 changes: 74 additions & 12 deletions client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

import dataclasses

import pyblish.api

from maya import cmds
Expand Down Expand Up @@ -53,12 +56,24 @@ def process(self, instance):
)
return

frame_start_handle = int(context.data.get("frameStartHandle"))
frame_end_handle = int(context.data.get("frameEndHandle"))
handle_start = int(context.data.get("handleStart"))
handle_end = int(context.data.get("handleEnd"))
frame_start = int(context.data.get("frameStart"))
frame_end = int(context.data.get("frameEnd"))
# Get frame information from task entity
# NOTE: If there is no task override then the asset
# value is automatically returned instead
frames = get_instance_task_frame_range(instance)
frame_start_handle = frames.frame_start_handle
frame_end_handle = frames.frame_end_handle
handle_start = frames.handle_start
handle_end = frames.handle_end
frame_start = frames.frame_start
frame_end = frames.frame_end

# Get frame information from asset context
# frame_start_handle = int(context.data.get("frameStartHandle"))
# frame_end_handle = int(context.data.get("frameEndHandle"))
# handle_start = int(context.data.get("handleStart"))
# handle_end = int(context.data.get("handleEnd"))
# frame_start = int(context.data.get("frameStart"))
# frame_end = int(context.data.get("frameEnd"))

inst_start = int(instance.data.get("frameStartHandle"))
inst_end = int(instance.data.get("frameEndHandle"))
Expand Down Expand Up @@ -130,12 +145,24 @@ def repair(cls, instance):
node = instance.data["name"]
context = instance.context

frame_start_handle = int(context.data.get("frameStartHandle"))
frame_end_handle = int(context.data.get("frameEndHandle"))
handle_start = int(context.data.get("handleStart"))
handle_end = int(context.data.get("handleEnd"))
frame_start = int(context.data.get("frameStart"))
frame_end = int(context.data.get("frameEnd"))
# Get frame information from task entity
# NOTE: If there is no task override then the asset
# value is automatically returned instead
frames = get_instance_task_frame_range(instance)
frame_start_handle = frames.frame_start_handle
frame_end_handle = frames.frame_end_handle
handle_start = frames.handle_start
handle_end = frames.handle_end
frame_start = frames.frame_start
frame_end = frames.frame_end

# Get frame information from asset context
# frame_start_handle = int(context.data.get("frameStartHandle"))
# frame_end_handle = int(context.data.get("frameEndHandle"))
# handle_start = int(context.data.get("handleStart"))
# handle_end = int(context.data.get("handleEnd"))
# frame_start = int(context.data.get("frameStart"))
# frame_end = int(context.data.get("frameEnd"))

# Start
if cmds.attributeQuery("handleStart", node=node, exists=True):
Expand Down Expand Up @@ -204,3 +231,38 @@ def _set_attr_in_layer(cls, node_attr, layer, value):
value=value
))
cmds.setAttr(node_attr, value)


def get_instance_task_frame_range(instance):
# Get frame information from task entity
# NOTE: If there is no task override then the asset
# value is automatically returned instead
attrib = instance.data["taskEntity"]["attrib"]
return FrameRange(
frame_start=attrib["frameStart"],
frame_end=attrib["frameEnd"],
handle_start=attrib["handleStart"],
handle_end=attrib["handleEnd"])


@dataclasses.dataclass
class FrameRange:
"""Frame range with handles.

The frame range excludes the handles - and thus the handles are outside
of the frame range. To get the inclusive start and end frame use
`frame_start_handle` and `frame_end_handle`.

"""
frame_start: int
frame_end: int
handle_start: int
handle_end: int

@property
def frame_start_handle(self) -> int:
return self.frame_start - self.handle_start

@property
def frame_end_handle(self) -> int:
return self.frame_end + self.handle_end
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ def get_invalid_resolution(cls, instance):

@classmethod
def get_db_resolution(cls, instance):
task_doc = instance.data["taskEntity"]
asset_doc = instance.data["assetEntity"]
project_doc = instance.context.data["projectEntity"]
for data in [asset_doc["data"], project_doc["data"]]:
for data in [
task_doc["attrib"],
asset_doc["data"],
project_doc["data"]]:
if (
"resolutionWidth" in data and
"resolutionHeight" in data and
Expand Down
Loading