From 12755dbeabb3dc114d38c5338577011b45b6b948 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 20 Jun 2024 18:38:46 +0800 Subject: [PATCH] cosmetic fix & clean up & improve the logic of the oxrig family --- server_addon/maya/client/ayon_maya/api/lib.py | 2 +- .../plugins/load/load_ornatrix_cache.py | 26 +++++++---------- .../plugins/load/load_ornatrix_rig.py | 23 +-------------- .../ayon_maya/plugins/load/load_reference.py | 2 +- .../plugins/publish/collect_ornatrix_cache.py | 6 ++-- .../plugins/publish/collect_ornatrix_rig.py | 8 ++---- .../plugins/publish/collect_yeti_rig.py | 2 +- .../plugins/publish/extract_ornatrix_cache.py | 1 - .../plugins/publish/extract_ornatrix_rig.py | 28 +++++++++++-------- server_addon/maya/server/settings/creators.py | 4 +-- 10 files changed, 38 insertions(+), 64 deletions(-) diff --git a/server_addon/maya/client/ayon_maya/api/lib.py b/server_addon/maya/client/ayon_maya/api/lib.py index 7be7032f22..f6d201df19 100644 --- a/server_addon/maya/client/ayon_maya/api/lib.py +++ b/server_addon/maya/client/ayon_maya/api/lib.py @@ -4299,7 +4299,7 @@ def get_sequence(filepath, pattern="%04d"): pattern (str): The pattern to swap with the variable frame number. Returns: - list: file sequence. + list: clique.Collection. """ import clique diff --git a/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_cache.py b/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_cache.py index af32038c50..735ac23189 100644 --- a/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_cache.py +++ b/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_cache.py @@ -21,10 +21,10 @@ class OxCacheLoader(plugin.Loader): color = "orange" def load(self, context, name=None, namespace=None, data=None): - """Loads a .fursettings file defining how to load .abc into + """Loads a .cachesettings file defining how to load .abc into HairGuideFromMesh nodes - The .fursettings file defines what the node names should be and also + The .cachesettings file defines what the node names should be and also what "cbId" attribute they should receive to match the original source and allow published looks to also work for Ornatrix rigs and its caches. @@ -35,9 +35,8 @@ class OxCacheLoader(plugin.Loader): if namespace is None: namespace = self.create_namespace(folder_name) - # Ensure Onratrix is loaded - if not cmds.pluginInfo("Ornatrix.mll", query=True, loaded=True): - cmds.loadPlugin("Ornatrix.mll", quiet=True) + # Ensure Ornatrix is loaded + cmds.loadPlugin("Ornatrix.mll", quiet=True) path = self.filepath_from_context(context) settings = self.read_settings(path) @@ -134,21 +133,16 @@ class OxCacheLoader(plugin.Loader): orig_shape_name = node_settings["shape"]["name"] mesh_shape_name = "{}:{}".format(namespace, orig_shape_name) guide_name = "{}:{}".format(namespace, orig_guide_name) - mesh_shape_node = cmds.ls(guide_name, type="mesh") - if not mesh_shape_node: - mesh_shape_node = cmds.createNode("mesh", name=guide_name) - hair_guide_node = cmds.ls(guide_name, type="HairFromGuidesNode") - if not hair_guide_node: - hair_guide_node = cmds.createNode( - "HairFromGuidesNode", name=guide_name) + mesh_shape_node = cmds.createNode("mesh", name=guide_name) + hair_guide_node = cmds.createNode("HairFromGuidesNode", name=guide_name) - lib.set_id(hair_guide_node, node_settings["cbId"]) - mel.eval(f"OxAddStrandOperator {mesh_shape_name} {guide_name};") + lib.set_id(hair_guide_node, node_settings["cbId"]) + mel.eval(f"OxAddStrandOperator {mesh_shape_name} {guide_name};") cmds.setAttr(f"{guide_name}.cacheFilePath", filepath) - nodes.append(hair_guide_node) + nodes.extend([mesh_shape_node, hair_guide_node]) return nodes - def read_setting(self, path): + def read_settings(self, path): """Read the ornatrix-related parameters from the cachesettings. Args: path (str): filepath of cachesettings diff --git a/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_rig.py b/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_rig.py index 6797bde6bf..8d82933011 100644 --- a/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_rig.py +++ b/server_addon/maya/client/ayon_maya/plugins/load/load_ornatrix_rig.py @@ -61,7 +61,7 @@ class OxRigLoader(plugin.ReferenceLoader): cmds.setAttr( group_name + ".outlinerColor", red, green, blue ) - self.use_resources_textures(namespace, path) + self[:] = nodes if self.create_cache_instance_on_load: @@ -105,24 +105,3 @@ class OxRigLoader(plugin.ReferenceLoader): variant=variant, pre_create_data={"use_selection": True} ) - - def use_resources_textures(self, namespace, path): - """Use texture maps from resources directories - - Args: - namespace (str): namespace - path (str): published filepath - """ - path_no_ext, _ = os.path.splitext(path) - settings_path = f"{path_no_ext}.rigsettings" - with open(settings_path, "r") as fp: - image_attributes = json.load(fp) - - if not image_attributes: - return - for image_attribute in image_attributes: - texture_attribute = "{}:{}".format( - namespace, image_attribute["texture_attribute"]) - cmds.setAttr(texture_attribute, - image_attribute["destination_file"], - type="string") diff --git a/server_addon/maya/client/ayon_maya/plugins/load/load_reference.py b/server_addon/maya/client/ayon_maya/plugins/load/load_reference.py index c171268038..583fd251e6 100644 --- a/server_addon/maya/client/ayon_maya/plugins/load/load_reference.py +++ b/server_addon/maya/client/ayon_maya/plugins/load/load_reference.py @@ -124,7 +124,7 @@ class ReferenceLoader(plugin.ReferenceLoader): "skeletalMesh", "mvLook", "matchmove", - "OxCache", + "oxcache", } representations = {"ma", "abc", "fbx", "mb"} diff --git a/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_cache.py b/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_cache.py index 494b31a311..01b9c92bfa 100644 --- a/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_cache.py +++ b/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_cache.py @@ -21,14 +21,16 @@ class CollectOxCache(plugin.MayaInstancePlugin): mesh_shape_data = {"name": parent, "cbId": lib.get_id(parent)} ox_cache_nodes = cmds.listConnections( ox_shape, destination=True, type="HairFromGuidesNode") or [] + if not ox_cache_nodes: + continue # transfer cache file shape_data = { "shape": mesh_shape_data, "name": ox_shapes, "cbId": lib.get_id(ox_shape), "ox_nodes": ox_cache_nodes, - "cache_file_attribute": ["{}.cacheFilePath".format(ox_node) - for ox_node in ox_cache_nodes] + "cache_file_attributes": ["{}.cacheFilePath".format(ox_node) + for ox_node in ox_cache_nodes] } if shape_data["cbId"]: settings["nodes"].append(shape_data) diff --git a/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_rig.py b/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_rig.py index 5fa4f56686..4291819555 100644 --- a/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_rig.py +++ b/server_addon/maya/client/ayon_maya/plugins/publish/collect_ornatrix_rig.py @@ -1,5 +1,5 @@ import os - +from typing import List, Dict, Any import pyblish.api from ayon_core.pipeline.publish import KnownPublishError from ayon_maya.api import lib @@ -39,12 +39,8 @@ class CollectOxRig(plugin.MayaInstancePlugin): if i not in ornatrix_resources[n + 1:] ] self.log.debug("{}".format(instance.data["resources"])) - start = cmds.playbackOptions(query=True, animationStartTime=True) - for key in ["frameStart", "frameEnd", - "frameStartHandle", "frameEndHandle"]: - instance.data[key] = start - def get_texture_resources(self, node): + def get_texture_resources(self, node: str) -> List[Dict[str, Any]]: resources = [] node_shape = cmds.listRelatives(node, shapes=True) if not node_shape: diff --git a/server_addon/maya/client/ayon_maya/plugins/publish/collect_yeti_rig.py b/server_addon/maya/client/ayon_maya/plugins/publish/collect_yeti_rig.py index 0cca55b678..279dc4bb0a 100644 --- a/server_addon/maya/client/ayon_maya/plugins/publish/collect_yeti_rig.py +++ b/server_addon/maya/client/ayon_maya/plugins/publish/collect_yeti_rig.py @@ -33,7 +33,7 @@ class CollectYetiRig(plugin.MayaInstancePlugin): yeti_nodes = cmds.ls(instance[:], type="pgYetiMaya", long=True) for node in yeti_nodes: # Get Yeti resources (textures) - resources = self.get_texture_resources(node) + resources = self.get_yeti_resources(node) yeti_resources.extend(resources) instance.data["rigsettings"] = {"inputs": input_connections} diff --git a/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_cache.py b/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_cache.py index 320d0abb69..39f30ed720 100644 --- a/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_cache.py +++ b/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_cache.py @@ -21,7 +21,6 @@ class ExtractOxCache(plugin.MayaExtractorPlugin): dirname = self.staging_dir(instance) attr_values = instance.data["creator_attributes"] # Start writing the files for snap shot - # will be replace by the Yeti node name ox_abc_path = os.path.join(dirname, "{}ornatrix.abc".format( instance.name)) ox_export_option = self.ox_option(attr_values) diff --git a/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_rig.py b/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_rig.py index 2bdbfa3c89..f7024f955b 100644 --- a/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_rig.py +++ b/server_addon/maya/client/ayon_maya/plugins/publish/extract_ornatrix_rig.py @@ -9,7 +9,7 @@ from ayon_maya.api import plugin from maya import cmds -class ExtractxRig(plugin.MayaExtractorPlugin): +class ExtractOxRig(plugin.MayaExtractorPlugin): """Extract the Ornatrix rig to a Maya Scene and write the Ornatrix rig data.""" label = "Extract Ornatrix Rig" @@ -47,7 +47,7 @@ class ExtractxRig(plugin.MayaExtractorPlugin): instance.data['transfers'] = [] resources = instance.data.get("resources", []) - for resource in instance.data.get('resources', []): + for resource in resources: for file in resource['files']: src = file dst = os.path.join(image_search_path, os.path.basename(file)) @@ -69,19 +69,25 @@ class ExtractxRig(plugin.MayaExtractorPlugin): allDescendents=True, fullPath=True) or [] + texture_attributes = { + resource["texture_attribute"]: resource["destination_file"] + for resource in resources + } + # Ornatrix related staging dirs maya_path = os.path.join(dirname, "ornatrix_rig.{}".format(self.scene_type)) nodes = instance.data["setMembers"] with lib.maintained_selection(): - cmds.select(nodes, noExpand=True) - cmds.file(maya_path, - force=True, - exportSelected=True, - typ="mayaAscii" if self.scene_type == "ma" else "mayaBinary", # noqa: E501 - preserveReferences=False, - constructionHistory=True, - shader=False) + with lib.attribute_values(texture_attributes): + cmds.select(nodes, noExpand=True) + cmds.file(maya_path, + force=True, + exportSelected=True, + type="mayaAscii" if self.scene_type == "ma" else "mayaBinary", # noqa: E501 + preserveReferences=False, + constructionHistory=True, + shader=False) # Ensure files can be stored # build representations @@ -109,5 +115,3 @@ class ExtractxRig(plugin.MayaExtractorPlugin): ) self.log.debug("Extracted {} to {}".format(instance, dirname)) - - cmds.select(clear=True) diff --git a/server_addon/maya/server/settings/creators.py b/server_addon/maya/server/settings/creators.py index 9484a0881b..2931ed7aa2 100644 --- a/server_addon/maya/server/settings/creators.py +++ b/server_addon/maya/server/settings/creators.py @@ -382,13 +382,13 @@ DEFAULT_CREATORS_SETTINGS = { ] }, "CreateOxRig": { - "enabled": True, + "enabled": False, "default_variants": [ "Main" ] }, "CreateOxCache": { - "enabled": True, + "enabled": False, "default_variants": [ "Main" ]