mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Hide animation instance in creator + add inventory action to recreate animation publish instance for loaded rigs
This commit is contained in:
parent
59220366e2
commit
1a10e0fc74
5 changed files with 101 additions and 40 deletions
|
|
@ -32,6 +32,10 @@ from openpype.pipeline import (
|
||||||
load_container,
|
load_container,
|
||||||
registered_host,
|
registered_host,
|
||||||
)
|
)
|
||||||
|
from openpype.pipeline.create import (
|
||||||
|
legacy_create,
|
||||||
|
get_legacy_creator_by_name,
|
||||||
|
)
|
||||||
from openpype.pipeline.context_tools import (
|
from openpype.pipeline.context_tools import (
|
||||||
get_current_asset_name,
|
get_current_asset_name,
|
||||||
get_current_project_asset,
|
get_current_project_asset,
|
||||||
|
|
@ -3913,3 +3917,51 @@ def get_capture_preset(task_name, task_type, subset, project_settings, log):
|
||||||
capture_preset = plugin_settings["capture_preset"]
|
capture_preset = plugin_settings["capture_preset"]
|
||||||
|
|
||||||
return capture_preset or {}
|
return capture_preset or {}
|
||||||
|
|
||||||
|
|
||||||
|
def create_rig_animation_instance(nodes, context, namespace, log=None):
|
||||||
|
"""Create an animation publish instance for loaded rigs.
|
||||||
|
|
||||||
|
See the RecreateRigAnimationInstance inventory action on how to use this
|
||||||
|
for loaded rig containers.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
nodes (list): Member nodes of the rig instance.
|
||||||
|
context (dict): Representation context of the rig container
|
||||||
|
namespace (str): Namespace of the rig container
|
||||||
|
log (logging.Logger, optional): Logger to log to if provided
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
|
||||||
|
"""
|
||||||
|
output = next((node for node in nodes if
|
||||||
|
node.endswith("out_SET")), None)
|
||||||
|
controls = next((node for node in nodes if
|
||||||
|
node.endswith("controls_SET")), None)
|
||||||
|
|
||||||
|
assert output, "No out_SET in rig, this is a bug."
|
||||||
|
assert controls, "No controls_SET in rig, this is a bug."
|
||||||
|
|
||||||
|
# Find the roots amongst the loaded nodes
|
||||||
|
roots = cmds.ls(nodes, assemblies=True, long=True) or \
|
||||||
|
get_highest_in_hierarchy(nodes)
|
||||||
|
assert roots, "No root nodes in rig, this is a bug."
|
||||||
|
|
||||||
|
asset = legacy_io.Session["AVALON_ASSET"]
|
||||||
|
dependency = str(context["representation"]["_id"])
|
||||||
|
|
||||||
|
if log:
|
||||||
|
log.info("Creating subset: {}".format(namespace))
|
||||||
|
|
||||||
|
# Create the animation instance
|
||||||
|
creator_plugin = get_legacy_creator_by_name("CreateAnimation")
|
||||||
|
with maintained_selection():
|
||||||
|
cmds.select([output, controls] + roots, noExpand=True)
|
||||||
|
legacy_create(
|
||||||
|
creator_plugin,
|
||||||
|
name=namespace,
|
||||||
|
asset=asset,
|
||||||
|
options={"useSelection": True},
|
||||||
|
data={"dependencies": dependency}
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,12 @@ from openpype.hosts.maya.api import (
|
||||||
class CreateAnimation(plugin.Creator):
|
class CreateAnimation(plugin.Creator):
|
||||||
"""Animation output for character rigs"""
|
"""Animation output for character rigs"""
|
||||||
|
|
||||||
|
# We hide the animation creator from the UI since the creation of it
|
||||||
|
# is automated upon loading a rig. There's an inventory action to recreate
|
||||||
|
# it for loaded rigs if by chance someone deleted the animation instance.
|
||||||
|
# Note: This setting is actually applied from project settings
|
||||||
|
enabled = False
|
||||||
|
|
||||||
name = "animationDefault"
|
name = "animationDefault"
|
||||||
label = "Animation"
|
label = "Animation"
|
||||||
family = "animation"
|
family = "animation"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
from openpype.pipeline import (
|
||||||
|
InventoryAction,
|
||||||
|
get_representation_context
|
||||||
|
)
|
||||||
|
from openpype.hosts.maya.api.lib import (
|
||||||
|
create_rig_animation_instance,
|
||||||
|
get_container_members,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RecreateRigAnimationInstance(InventoryAction):
|
||||||
|
"""Recreate animation publish instance for loaded rigs"""
|
||||||
|
|
||||||
|
label = "Recreate rig animation instance"
|
||||||
|
icon = "industry"
|
||||||
|
color = "#55DDAA"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_compatible(container):
|
||||||
|
return (
|
||||||
|
container.get("loader") == "ReferenceLoader"
|
||||||
|
and container.get("name", "").startswith("rig")
|
||||||
|
)
|
||||||
|
|
||||||
|
def process(self, containers):
|
||||||
|
|
||||||
|
for container in containers:
|
||||||
|
# todo: delete an existing entry if it exist or skip creation
|
||||||
|
|
||||||
|
namespace = container["namespace"]
|
||||||
|
representation_id = container["representation"]
|
||||||
|
context = get_representation_context(representation_id)
|
||||||
|
nodes = get_container_members(container)
|
||||||
|
|
||||||
|
create_rig_animation_instance(nodes, context, namespace)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,16 +4,12 @@ import contextlib
|
||||||
from maya import cmds
|
from maya import cmds
|
||||||
|
|
||||||
from openpype.settings import get_project_settings
|
from openpype.settings import get_project_settings
|
||||||
from openpype.pipeline import legacy_io
|
|
||||||
from openpype.pipeline.create import (
|
|
||||||
legacy_create,
|
|
||||||
get_legacy_creator_by_name,
|
|
||||||
)
|
|
||||||
import openpype.hosts.maya.api.plugin
|
import openpype.hosts.maya.api.plugin
|
||||||
from openpype.hosts.maya.api.lib import (
|
from openpype.hosts.maya.api.lib import (
|
||||||
maintained_selection,
|
maintained_selection,
|
||||||
get_container_members,
|
get_container_members,
|
||||||
parent_nodes
|
parent_nodes,
|
||||||
|
create_rig_animation_instance
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -114,9 +110,6 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
||||||
icon = "code-fork"
|
icon = "code-fork"
|
||||||
color = "orange"
|
color = "orange"
|
||||||
|
|
||||||
# Name of creator class that will be used to create animation instance
|
|
||||||
animation_creator_name = "CreateAnimation"
|
|
||||||
|
|
||||||
def process_reference(self, context, name, namespace, options):
|
def process_reference(self, context, name, namespace, options):
|
||||||
import maya.cmds as cmds
|
import maya.cmds as cmds
|
||||||
|
|
||||||
|
|
@ -220,37 +213,10 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
||||||
self._lock_camera_transforms(members)
|
self._lock_camera_transforms(members)
|
||||||
|
|
||||||
def _post_process_rig(self, name, namespace, context, options):
|
def _post_process_rig(self, name, namespace, context, options):
|
||||||
|
nodes = self[:]
|
||||||
output = next((node for node in self if
|
create_rig_animation_instance(
|
||||||
node.endswith("out_SET")), None)
|
nodes, context, namespace, log=self.log
|
||||||
controls = next((node for node in self if
|
|
||||||
node.endswith("controls_SET")), None)
|
|
||||||
|
|
||||||
assert output, "No out_SET in rig, this is a bug."
|
|
||||||
assert controls, "No controls_SET in rig, this is a bug."
|
|
||||||
|
|
||||||
# Find the roots amongst the loaded nodes
|
|
||||||
roots = cmds.ls(self[:], assemblies=True, long=True)
|
|
||||||
assert roots, "No root nodes in rig, this is a bug."
|
|
||||||
|
|
||||||
asset = legacy_io.Session["AVALON_ASSET"]
|
|
||||||
dependency = str(context["representation"]["_id"])
|
|
||||||
|
|
||||||
self.log.info("Creating subset: {}".format(namespace))
|
|
||||||
|
|
||||||
# Create the animation instance
|
|
||||||
creator_plugin = get_legacy_creator_by_name(
|
|
||||||
self.animation_creator_name
|
|
||||||
)
|
)
|
||||||
with maintained_selection():
|
|
||||||
cmds.select([output, controls] + roots, noExpand=True)
|
|
||||||
legacy_create(
|
|
||||||
creator_plugin,
|
|
||||||
name=namespace,
|
|
||||||
asset=asset,
|
|
||||||
options={"useSelection": True},
|
|
||||||
data={"dependencies": dependency}
|
|
||||||
)
|
|
||||||
|
|
||||||
def _lock_camera_transforms(self, nodes):
|
def _lock_camera_transforms(self, nodes):
|
||||||
cameras = cmds.ls(nodes, type="camera")
|
cameras = cmds.ls(nodes, type="camera")
|
||||||
|
|
|
||||||
|
|
@ -554,7 +554,7 @@
|
||||||
"publish_mip_map": true
|
"publish_mip_map": true
|
||||||
},
|
},
|
||||||
"CreateAnimation": {
|
"CreateAnimation": {
|
||||||
"enabled": true,
|
"enabled": false,
|
||||||
"write_color_sets": false,
|
"write_color_sets": false,
|
||||||
"write_face_sets": false,
|
"write_face_sets": false,
|
||||||
"include_parent_hierarchy": false,
|
"include_parent_hierarchy": false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue