mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
Merge pull request #365 from BigRoy/enhancement/maya_collect_look
Maya: Collect Look code cleanup + minor bugfix
This commit is contained in:
commit
cff14e7930
1 changed files with 88 additions and 82 deletions
|
|
@ -8,7 +8,7 @@ from maya import cmds # noqa
|
||||||
import pyblish.api
|
import pyblish.api
|
||||||
from ayon_core.hosts.maya.api import lib
|
from ayon_core.hosts.maya.api import lib
|
||||||
|
|
||||||
SHAPE_ATTRS = ["castsShadows",
|
SHAPE_ATTRS = {"castsShadows",
|
||||||
"receiveShadows",
|
"receiveShadows",
|
||||||
"motionBlur",
|
"motionBlur",
|
||||||
"primaryVisibility",
|
"primaryVisibility",
|
||||||
|
|
@ -16,8 +16,7 @@ SHAPE_ATTRS = ["castsShadows",
|
||||||
"visibleInReflections",
|
"visibleInReflections",
|
||||||
"visibleInRefractions",
|
"visibleInRefractions",
|
||||||
"doubleSided",
|
"doubleSided",
|
||||||
"opposite"]
|
"opposite"}
|
||||||
SHAPE_ATTRS = set(SHAPE_ATTRS)
|
|
||||||
|
|
||||||
|
|
||||||
def get_pxr_multitexture_file_attrs(node):
|
def get_pxr_multitexture_file_attrs(node):
|
||||||
|
|
@ -59,9 +58,8 @@ for node_type in list(FILE_NODES.keys()):
|
||||||
if node_type not in all_node_types:
|
if node_type not in all_node_types:
|
||||||
FILE_NODES.pop(node_type)
|
FILE_NODES.pop(node_type)
|
||||||
|
|
||||||
for node_type in RENDER_SET_TYPES:
|
RENDER_SET_TYPES = [node_type for node_type in RENDER_SET_TYPES
|
||||||
if node_type not in all_node_types:
|
if node_type in all_node_types]
|
||||||
RENDER_SET_TYPES.remove(node_type)
|
|
||||||
del all_node_types
|
del all_node_types
|
||||||
|
|
||||||
# Cache pixar dependency node types so we can perform a type lookup against it
|
# Cache pixar dependency node types so we can perform a type lookup against it
|
||||||
|
|
@ -109,8 +107,7 @@ def get_look_attrs(node):
|
||||||
if cmds.objectType(node, isAType="shape"):
|
if cmds.objectType(node, isAType="shape"):
|
||||||
attrs = cmds.listAttr(node, changedSinceFileOpen=True) or []
|
attrs = cmds.listAttr(node, changedSinceFileOpen=True) or []
|
||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
if attr in SHAPE_ATTRS or \
|
if attr in SHAPE_ATTRS or attr.startswith('ai'):
|
||||||
attr not in SHAPE_ATTRS and attr.startswith('ai'):
|
|
||||||
result.append(attr)
|
result.append(attr)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
@ -290,7 +287,6 @@ class CollectLook(pyblish.api.InstancePlugin):
|
||||||
families = ["look"]
|
families = ["look"]
|
||||||
label = "Collect Look"
|
label = "Collect Look"
|
||||||
hosts = ["maya"]
|
hosts = ["maya"]
|
||||||
maketx = True
|
|
||||||
|
|
||||||
def process(self, instance):
|
def process(self, instance):
|
||||||
"""Collect the Look in the instance with the correct layer settings"""
|
"""Collect the Look in the instance with the correct layer settings"""
|
||||||
|
|
@ -302,15 +298,12 @@ class CollectLook(pyblish.api.InstancePlugin):
|
||||||
"""Collect looks.
|
"""Collect looks.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
instance: Instance to collect.
|
instance (pyblish.api.Instance): Instance to collect.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.log.debug("Looking for look associations "
|
self.log.debug("Looking for look associations "
|
||||||
"for %s" % instance.data['name'])
|
"for %s" % instance.data['name'])
|
||||||
|
|
||||||
# Lookup set (optimization)
|
|
||||||
instance_lookup = set(cmds.ls(instance, long=True))
|
|
||||||
|
|
||||||
# Discover related object sets
|
# Discover related object sets
|
||||||
self.log.debug("Gathering sets ...")
|
self.log.debug("Gathering sets ...")
|
||||||
sets = self.collect_sets(instance)
|
sets = self.collect_sets(instance)
|
||||||
|
|
@ -351,75 +344,15 @@ class CollectLook(pyblish.api.InstancePlugin):
|
||||||
# Collect file nodes used by shading engines (if we have any)
|
# Collect file nodes used by shading engines (if we have any)
|
||||||
files = []
|
files = []
|
||||||
look_sets = list(sets.keys())
|
look_sets = list(sets.keys())
|
||||||
shader_attrs = [
|
|
||||||
"surfaceShader",
|
|
||||||
"volumeShader",
|
|
||||||
"displacementShader",
|
|
||||||
"aiSurfaceShader",
|
|
||||||
"aiVolumeShader",
|
|
||||||
"rman__surface",
|
|
||||||
"rman__displacement"
|
|
||||||
]
|
|
||||||
if look_sets:
|
if look_sets:
|
||||||
self.log.debug("Found look sets: {}".format(look_sets))
|
self.log.debug("Found look sets: {}".format(look_sets))
|
||||||
|
files = self.collect_file_nodes(look_sets)
|
||||||
# Get all material attrs for all look sets to retrieve their inputs
|
|
||||||
existing_attrs = []
|
|
||||||
for look in look_sets:
|
|
||||||
for attr in shader_attrs:
|
|
||||||
if cmds.attributeQuery(attr, node=look, exists=True):
|
|
||||||
existing_attrs.append("{}.{}".format(look, attr))
|
|
||||||
|
|
||||||
materials = cmds.listConnections(existing_attrs,
|
|
||||||
source=True,
|
|
||||||
destination=False) or []
|
|
||||||
|
|
||||||
self.log.debug("Found materials:\n{}".format(materials))
|
|
||||||
|
|
||||||
self.log.debug("Found the following sets:\n{}".format(look_sets))
|
|
||||||
# Get the entire node chain of the look sets
|
|
||||||
# history = cmds.listHistory(look_sets, allConnections=True)
|
|
||||||
# if materials list is empty, listHistory() will crash with
|
|
||||||
# RuntimeError
|
|
||||||
history = set()
|
|
||||||
if materials:
|
|
||||||
history = set(
|
|
||||||
cmds.listHistory(materials, allConnections=True))
|
|
||||||
|
|
||||||
# Since we retrieved history only of the connected materials
|
|
||||||
# connected to the look sets above we now add direct history
|
|
||||||
# for some of the look sets directly
|
|
||||||
# handling render attribute sets
|
|
||||||
|
|
||||||
# Maya (at least 2024) crashes with Warning when render set type
|
|
||||||
# isn't available. cmds.ls() will return empty list
|
|
||||||
if RENDER_SET_TYPES:
|
|
||||||
render_sets = cmds.ls(look_sets, type=RENDER_SET_TYPES)
|
|
||||||
if render_sets:
|
|
||||||
history.update(
|
|
||||||
cmds.listHistory(render_sets,
|
|
||||||
future=False,
|
|
||||||
pruneDagObjects=True)
|
|
||||||
or []
|
|
||||||
)
|
|
||||||
|
|
||||||
# Ensure unique entries only
|
|
||||||
history = list(history)
|
|
||||||
|
|
||||||
files = cmds.ls(history,
|
|
||||||
# It's important only node types are passed that
|
|
||||||
# exist (e.g. for loaded plugins) because otherwise
|
|
||||||
# the result will turn back empty
|
|
||||||
type=list(FILE_NODES.keys()),
|
|
||||||
long=True)
|
|
||||||
|
|
||||||
# Sort for log readability
|
|
||||||
files.sort()
|
|
||||||
|
|
||||||
self.log.debug("Collected file nodes:\n{}".format(files))
|
self.log.debug("Collected file nodes:\n{}".format(files))
|
||||||
# Collect textures if any file nodes are found
|
|
||||||
|
# Collect texture resources if any file nodes are found
|
||||||
resources = []
|
resources = []
|
||||||
for node in files: # sort for log readability
|
for node in files:
|
||||||
resources.extend(self.collect_resources(node))
|
resources.extend(self.collect_resources(node))
|
||||||
instance.data["resources"] = resources
|
instance.data["resources"] = resources
|
||||||
self.log.debug("Collected resources: {}".format(resources))
|
self.log.debug("Collected resources: {}".format(resources))
|
||||||
|
|
@ -439,6 +372,78 @@ class CollectLook(pyblish.api.InstancePlugin):
|
||||||
|
|
||||||
self.log.debug("Collected look for %s" % instance)
|
self.log.debug("Collected look for %s" % instance)
|
||||||
|
|
||||||
|
def collect_file_nodes(self, look_sets):
|
||||||
|
"""Get the entire node chain of the look sets and return file nodes
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
look_sets (List[str]): List of sets and shading engines relevant
|
||||||
|
to the look.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List[str]: List of file node names.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
shader_attrs = [
|
||||||
|
"surfaceShader",
|
||||||
|
"volumeShader",
|
||||||
|
"displacementShader",
|
||||||
|
"aiSurfaceShader",
|
||||||
|
"aiVolumeShader",
|
||||||
|
"rman__surface",
|
||||||
|
"rman__displacement"
|
||||||
|
]
|
||||||
|
|
||||||
|
# Get all material attrs for all look sets to retrieve their inputs
|
||||||
|
existing_attrs = []
|
||||||
|
for look_set in look_sets:
|
||||||
|
for attr in shader_attrs:
|
||||||
|
if cmds.attributeQuery(attr, node=look_set, exists=True):
|
||||||
|
existing_attrs.append("{}.{}".format(look_set, attr))
|
||||||
|
|
||||||
|
materials = cmds.listConnections(existing_attrs,
|
||||||
|
source=True,
|
||||||
|
destination=False) or []
|
||||||
|
|
||||||
|
self.log.debug("Found materials:\n{}".format(materials))
|
||||||
|
|
||||||
|
# Get the entire node chain of the look sets
|
||||||
|
# history = cmds.listHistory(look_sets, allConnections=True)
|
||||||
|
# if materials list is empty, listHistory() will crash with
|
||||||
|
# RuntimeError
|
||||||
|
history = set()
|
||||||
|
if materials:
|
||||||
|
history.update(cmds.listHistory(materials, allConnections=True))
|
||||||
|
|
||||||
|
# Since we retrieved history only of the connected materials connected
|
||||||
|
# to the look sets above we now add direct history for some of the
|
||||||
|
# look sets directly handling render attribute sets
|
||||||
|
|
||||||
|
# Maya (at least 2024) crashes with Warning when render set type
|
||||||
|
# isn't available. cmds.ls() will return empty list
|
||||||
|
if RENDER_SET_TYPES:
|
||||||
|
render_sets = cmds.ls(look_sets, type=RENDER_SET_TYPES)
|
||||||
|
if render_sets:
|
||||||
|
history.update(
|
||||||
|
cmds.listHistory(render_sets,
|
||||||
|
future=False,
|
||||||
|
pruneDagObjects=True)
|
||||||
|
or []
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get file nodes in the material history
|
||||||
|
files = cmds.ls(list(history),
|
||||||
|
# It's important only node types are passed that
|
||||||
|
# exist (e.g. for loaded plugins) because otherwise
|
||||||
|
# the result will turn back empty
|
||||||
|
type=list(FILE_NODES.keys()),
|
||||||
|
long=True)
|
||||||
|
|
||||||
|
# Sort for log readability
|
||||||
|
files.sort()
|
||||||
|
|
||||||
|
return files
|
||||||
|
|
||||||
def collect_sets(self, instance):
|
def collect_sets(self, instance):
|
||||||
"""Collect all objectSets which are of importance for publishing
|
"""Collect all objectSets which are of importance for publishing
|
||||||
|
|
||||||
|
|
@ -446,7 +451,8 @@ class CollectLook(pyblish.api.InstancePlugin):
|
||||||
which need to be
|
which need to be
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
instance (list): all nodes to be published
|
instance (pyblish.api.Instance): publish instance containing all
|
||||||
|
nodes to be published.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict
|
dict
|
||||||
|
|
@ -624,7 +630,7 @@ class CollectLook(pyblish.api.InstancePlugin):
|
||||||
"source": source, # required for resources
|
"source": source, # required for resources
|
||||||
"files": files,
|
"files": files,
|
||||||
"color_space": color_space
|
"color_space": color_space
|
||||||
} # required for resources
|
}
|
||||||
|
|
||||||
|
|
||||||
class CollectModelRenderSets(CollectLook):
|
class CollectModelRenderSets(CollectLook):
|
||||||
|
|
@ -639,13 +645,13 @@ class CollectModelRenderSets(CollectLook):
|
||||||
families = ["model"]
|
families = ["model"]
|
||||||
label = "Collect Model Render Sets"
|
label = "Collect Model Render Sets"
|
||||||
hosts = ["maya"]
|
hosts = ["maya"]
|
||||||
maketx = True
|
|
||||||
|
|
||||||
def collect_sets(self, instance):
|
def collect_sets(self, instance):
|
||||||
"""Collect all related objectSets except shadingEngines
|
"""Collect all related objectSets except shadingEngines
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
instance (list): all nodes to be published
|
instance (pyblish.api.Instance): publish instance containing all
|
||||||
|
nodes to be published.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict
|
dict
|
||||||
|
|
@ -661,7 +667,7 @@ class CollectModelRenderSets(CollectLook):
|
||||||
if objset in sets:
|
if objset in sets:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if "shadingEngine" in cmds.nodeType(objset, inherited=True):
|
if cmds.objectType(objset, isAType="shadingEngine"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
sets[objset] = {"uuid": lib.get_id(objset), "members": list()}
|
sets[objset] = {"uuid": lib.get_id(objset), "members": list()}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue