cosmetic fix & clean up & improve the logic of the oxrig family

This commit is contained in:
Kayla Man 2024-06-20 18:38:46 +08:00
parent dc3247c1f2
commit 12755dbeab
10 changed files with 38 additions and 64 deletions

View file

@ -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

View file

@ -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

View file

@ -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")

View file

@ -124,7 +124,7 @@ class ReferenceLoader(plugin.ReferenceLoader):
"skeletalMesh",
"mvLook",
"matchmove",
"OxCache",
"oxcache",
}
representations = {"ma", "abc", "fbx", "mb"}

View file

@ -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)

View file

@ -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:

View file

@ -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}

View file

@ -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
# <NAME> 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)

View file

@ -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)

View file

@ -382,13 +382,13 @@ DEFAULT_CREATORS_SETTINGS = {
]
},
"CreateOxRig": {
"enabled": True,
"enabled": False,
"default_variants": [
"Main"
]
},
"CreateOxCache": {
"enabled": True,
"enabled": False,
"default_variants": [
"Main"
]