Merge pull request #4877 from quadproduction/347-fix-studio-openpype-animation-instance-doesn-t-have-the-right-subset-name-when-created-with

This commit is contained in:
Ondřej Samohel 2023-05-18 12:30:59 +02:00 committed by GitHub
commit a8bce5a28e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 46 deletions

View file

@ -190,6 +190,44 @@ def maintained_selection():
cmds.select(clear=True)
def get_custom_namespace(custom_namespace):
"""Return unique namespace.
The input namespace can contain a single group
of '#' number tokens to indicate where the namespace's
unique index should go. The amount of tokens defines
the zero padding of the number, e.g ### turns into 001.
Warning: Note that a namespace will always be
prefixed with a _ if it starts with a digit
Example:
>>> get_custom_namespace("myspace_##_")
# myspace_01_
>>> get_custom_namespace("##_myspace")
# _01_myspace
>>> get_custom_namespace("myspace##")
# myspace01
"""
split = re.split("([#]+)", custom_namespace, 1)
if len(split) == 3:
base, padding, suffix = split
padding = "%0{}d".format(len(padding))
else:
base = split[0]
padding = "%02d" # default padding
suffix = ""
return unique_namespace(
base,
format=padding,
prefix="_" if not base or base[0].isdigit() else "",
suffix=suffix
)
def unique_namespace(namespace, format="%02d", prefix="", suffix=""):
"""Return unique namespace
@ -3939,7 +3977,9 @@ def get_capture_preset(task_name, task_type, subset, project_settings, log):
return capture_preset or {}
def create_rig_animation_instance(nodes, context, namespace, log=None):
def create_rig_animation_instance(
nodes, context, namespace, options=None, log=None
):
"""Create an animation publish instance for loaded rigs.
See the RecreateRigAnimationInstance inventory action on how to use this
@ -3949,12 +3989,16 @@ def create_rig_animation_instance(nodes, context, namespace, log=None):
nodes (list): Member nodes of the rig instance.
context (dict): Representation context of the rig container
namespace (str): Namespace of the rig container
options (dict, optional): Additional loader data
log (logging.Logger, optional): Logger to log to if provided
Returns:
None
"""
if options is None:
options = {}
output = next((node for node in nodes if
node.endswith("out_SET")), None)
controls = next((node for node in nodes if
@ -3973,6 +4017,23 @@ def create_rig_animation_instance(nodes, context, namespace, log=None):
asset = legacy_io.Session["AVALON_ASSET"]
dependency = str(context["representation"]["_id"])
custom_subset = options.get("animationSubsetName")
if custom_subset:
formatting_data = {
"asset_name": context['asset']['name'],
"asset_type": context['asset']['type'],
"subset": context['subset']['name'],
"family": (
context['subset']['data'].get('family') or
context['subset']['data']['families'][0]
)
}
namespace = get_custom_namespace(
custom_subset.format(
**formatting_data
)
)
if log:
log.info("Creating subset: {}".format(namespace))

View file

@ -84,44 +84,6 @@ def get_reference_node_parents(ref):
return parents
def get_custom_namespace(custom_namespace):
"""Return unique namespace.
The input namespace can contain a single group
of '#' number tokens to indicate where the namespace's
unique index should go. The amount of tokens defines
the zero padding of the number, e.g ### turns into 001.
Warning: Note that a namespace will always be
prefixed with a _ if it starts with a digit
Example:
>>> get_custom_namespace("myspace_##_")
# myspace_01_
>>> get_custom_namespace("##_myspace")
# _01_myspace
>>> get_custom_namespace("myspace##")
# myspace01
"""
split = re.split("([#]+)", custom_namespace, 1)
if len(split) == 3:
base, padding, suffix = split
padding = "%0{}d".format(len(padding))
else:
base = split[0]
padding = "%02d" # default padding
suffix = ""
return lib.unique_namespace(
base,
format=padding,
prefix="_" if not base or base[0].isdigit() else "",
suffix=suffix
)
class Creator(LegacyCreator):
defaults = ['Main']
@ -216,7 +178,7 @@ class ReferenceLoader(Loader):
count = options.get("count") or 1
for c in range(0, count):
namespace = get_custom_namespace(custom_namespace)
namespace = lib.get_custom_namespace(custom_namespace)
group_name = "{}:{}".format(
namespace,
custom_group_name