Skip to content

Commit

Permalink
Allow frame range defaults for instances to be based on current task …
Browse files Browse the repository at this point in the history
…entity attributes
  • Loading branch information
BigRoy committed Sep 10, 2024
1 parent f9b7674 commit 7a5430d
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 31 deletions.
50 changes: 36 additions & 14 deletions client/ayon_maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,24 +570,47 @@ def pairwise(iterable):
return zip(a, a)


def collect_animation_defs(fps=False):
def collect_animation_defs(fps=False, create_context=None):
"""Get the basic animation attribute definitions for the publisher.
Arguments:
fps (bool): Whether to include `fps` attribute definition.
create_context (CreateContext | None): When provided the context of
publisher will be used to define the defaults for the attributes.
Depending on project settings this may then use the entity's frame
range and FPS instead of the current scene values.
Returns:
OrderedDict
List[NumberDef]: List of number attribute definitions.
"""

# get scene values as defaults
frame_start = cmds.playbackOptions(query=True, minTime=True)
frame_end = cmds.playbackOptions(query=True, maxTime=True)
frame_start_handle = cmds.playbackOptions(
query=True, animationStartTime=True
)
frame_end_handle = cmds.playbackOptions(query=True, animationEndTime=True)

handle_start = frame_start - frame_start_handle
handle_end = frame_end_handle - frame_end
use_entity_frame_range = False
if create_context is not None:
project_settings = create_context.get_current_project_settings()
print(project_settings["maya"]["create"])
use_entity_frame_range: bool = project_settings["maya"]["create"].get(
"use_entity_attributes_as_defaults", False)

if create_context is not None and use_entity_frame_range:
task_entity = create_context.get_current_task_entity()
frame_start = task_entity["attrib"]["frameStart"]
frame_end = task_entity["attrib"]["frameEnd"]
handle_start = task_entity["attrib"]["handleStart"]
handle_end = task_entity["attrib"]["handleEnd"]
default_fps = task_entity["attrib"]["fps"]
else:
# get scene values as defaults
frame_start = cmds.playbackOptions(query=True, minTime=True)
frame_end = cmds.playbackOptions(query=True, maxTime=True)
frame_start_handle = cmds.playbackOptions(
query=True, animationStartTime=True)
frame_end_handle = cmds.playbackOptions(
query=True, animationEndTime=True)

handle_start = frame_start - frame_start_handle
handle_end = frame_end_handle - frame_end
default_fps = mel.eval('currentTimeUnitToFPS()')

# build attributes
defs = [
Expand Down Expand Up @@ -619,9 +642,8 @@ def collect_animation_defs(fps=False):
]

if fps:
current_fps = mel.eval('currentTimeUnitToFPS()')
fps_def = NumberDef(
"fps", label="FPS", default=current_fps, decimals=5
"fps", label="FPS", default=default_fps, decimals=5
)
defs.append(fps_def)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
)


def _get_animation_attr_defs():
def _get_animation_attr_defs(create_context):
"""Get Animation generic definitions."""
defs = lib.collect_animation_defs()
defs = lib.collect_animation_defs(create_context=create_context)
defs.extend(
[
BoolDef("farm", label="Submit to Farm"),
Expand Down Expand Up @@ -99,7 +99,7 @@ def read_instance_node(self, node):
return node_data

def get_instance_attr_defs(self):
return _get_animation_attr_defs()
return _get_animation_attr_defs(self.create_context)


class CreatePointCache(plugin.MayaCreator):
Expand All @@ -121,7 +121,7 @@ def read_instance_node(self, node):
return node_data

def get_instance_attr_defs(self):
return _get_animation_attr_defs()
return _get_animation_attr_defs(self.create_context)

def create(self, product_name, instance_data, pre_create_data):
instance = super(CreatePointCache, self).create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CreateArnoldSceneSource(plugin.MayaCreator):

def get_instance_attr_defs(self):

defs = lib.collect_animation_defs()
defs = lib.collect_animation_defs(create_context=self.create_context)

defs.extend([
BoolDef("motionBlur",
Expand Down
2 changes: 1 addition & 1 deletion client/ayon_maya/plugins/create/create_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CreateCamera(plugin.MayaCreator):

def get_instance_attr_defs(self):

defs = lib.collect_animation_defs()
defs = lib.collect_animation_defs(create_context=self.create_context)

defs.extend([
BoolDef("bakeToWorldSpace",
Expand Down
3 changes: 2 additions & 1 deletion client/ayon_maya/plugins/create/create_maya_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def get_instance_attr_defs(self):
"static export frame.",
default=True)
]
defs.extend(lib.collect_animation_defs())
defs.extend(lib.collect_animation_defs(
create_context=self.create_context))
defs.extend([
EnumDef("defaultUSDFormat",
label="File format",
Expand Down
3 changes: 2 additions & 1 deletion client/ayon_maya/plugins/create/create_multiverse_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def get_publish_families(self):

def get_instance_attr_defs(self):

defs = lib.collect_animation_defs(fps=True)
defs = lib.collect_animation_defs(
fps=True, create_context=self.create_context)
defs.extend([
EnumDef("fileFormat",
label="File format",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class CreateMultiverseUsdComp(plugin.MayaCreator):

def get_instance_attr_defs(self):

defs = lib.collect_animation_defs(fps=True)
defs = lib.collect_animation_defs(
fps=True, create_context=self.create_context)
defs.extend([
EnumDef("fileFormat",
label="File format",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class CreateMultiverseUsdOver(plugin.MayaCreator):
icon = "cubes"

def get_instance_attr_defs(self):
defs = lib.collect_animation_defs(fps=True)
defs = lib.collect_animation_defs(
fps=True, create_context=self.create_context)
defs.extend([
EnumDef("fileFormat",
label="File format",
Expand Down
7 changes: 5 additions & 2 deletions client/ayon_maya/plugins/create/create_ornatrix_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def get_instance_attr_defs(self):

# Add animation data without step and handles
remove = {"handleStart", "handleEnd"}
defs = [attr_def for attr_def in lib.collect_animation_defs()
if attr_def.key not in remove]
defs = [
attr_def for attr_def in lib.collect_animation_defs(
create_context=self.create_context)
if attr_def.key not in remove
]
defs.extend(
[
EnumDef("format",
Expand Down
3 changes: 2 additions & 1 deletion client/ayon_maya/plugins/create/create_redshift_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ def get_instance_attr_defs(self):
default=False)
]

defs.extend(lib.collect_animation_defs())
defs.extend(lib.collect_animation_defs(
create_context=self.create_context))
return defs
2 changes: 1 addition & 1 deletion client/ayon_maya/plugins/create/create_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def create(self, product_name, instance_data, pre_create_data):

def get_instance_attr_defs(self):

defs = lib.collect_animation_defs()
defs = lib.collect_animation_defs(create_context=self.create_context)

# Option for using Maya or folder frame range in settings.
if not self.useMayaTimeline:
Expand Down
3 changes: 2 additions & 1 deletion client/ayon_maya/plugins/create/create_unreal_yeticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def get_instance_attr_defs(self):
]

# Add animation data without step and handles
defs.extend(lib.collect_animation_defs())
defs.extend(lib.collect_animation_defs(
create_context=self.create_context))
remove = {"step", "handleStart", "handleEnd"}
defs = [attr_def for attr_def in defs if attr_def.key not in remove]

Expand Down
3 changes: 2 additions & 1 deletion client/ayon_maya/plugins/create/create_vrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def get_instance_attr_defs(self):

# Add time range attributes but remove some attributes
# which this instance actually doesn't use
defs.extend(lib.collect_animation_defs())
defs.extend(lib.collect_animation_defs(
create_context=self.create_context))
remove = {"handleStart", "handleEnd", "step"}
defs = [attr_def for attr_def in defs if attr_def.key not in remove]

Expand Down
3 changes: 2 additions & 1 deletion client/ayon_maya/plugins/create/create_yeti_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def get_instance_attr_defs(self):
]

# Add animation data without step and handles
defs.extend(lib.collect_animation_defs())
defs.extend(lib.collect_animation_defs(
create_context=self.create_context))
remove = {"step", "handleStart", "handleEnd"}
defs = [attr_def for attr_def in defs if attr_def.key not in remove]

Expand Down
11 changes: 11 additions & 0 deletions server/settings/creators.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ class CreateMultishotLayout(BasicCreatorModel):


class CreatorsModel(BaseSettingsModel):
use_entity_attributes_as_defaults: bool = SettingsField(
False,
title="Use current context entity attributes as frame range defaults",
description=(
"For frame range attributes on the created instances, use the "
"current context's task entity as the default value. When "
"disabled it will default to Maya's current timeline."
)
)

CreateLook: CreateLookModel = SettingsField(
default_factory=CreateLookModel,
title="Create Look"
Expand Down Expand Up @@ -256,6 +266,7 @@ class CreatorsModel(BaseSettingsModel):


DEFAULT_CREATORS_SETTINGS = {
"use_entity_attributes_as_defaults": False,
"CreateLook": {
"enabled": True,
"make_tx": True,
Expand Down

0 comments on commit 7a5430d

Please sign in to comment.