Merge pull request #5929 from ynput/bugfix/maya-crashing-model-renderset-collector

This commit is contained in:
Ondřej Samohel 2023-11-28 14:22:20 +01:00 committed by GitHub
commit d0a94da2ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 30 deletions

View file

@ -33,7 +33,7 @@ class ImportModelRender(InventoryAction):
) )
def process(self, containers): def process(self, containers):
from maya import cmds from maya import cmds # noqa: F401
project_name = get_current_project_name() project_name = get_current_project_name()
for container in containers: for container in containers:
@ -66,7 +66,7 @@ class ImportModelRender(InventoryAction):
None None
""" """
from maya import cmds from maya import cmds # noqa: F401
project_name = get_current_project_name() project_name = get_current_project_name()
repre_docs = get_representations( repre_docs = get_representations(
@ -85,12 +85,7 @@ class ImportModelRender(InventoryAction):
if scene_type_regex.fullmatch(repre_name): if scene_type_regex.fullmatch(repre_name):
look_repres.append(repre_doc) look_repres.append(repre_doc)
# QUESTION should we care if there is more then one look look_repre = look_repres[0] if look_repres else None
# representation? (since it's based on regex match)
look_repre = None
if look_repres:
look_repre = look_repres[0]
# QUESTION shouldn't be json representation validated too? # QUESTION shouldn't be json representation validated too?
if not look_repre: if not look_repre:
print("No model render sets for this model version..") print("No model render sets for this model version..")

View file

@ -45,11 +45,23 @@ FILE_NODES = {
"PxrTexture": "filename" "PxrTexture": "filename"
} }
RENDER_SET_TYPES = [
"VRayDisplacement",
"VRayLightMesh",
"VRayObjectProperties",
"RedshiftObjectId",
"RedshiftMeshParameters",
]
# Keep only node types that actually exist # Keep only node types that actually exist
all_node_types = set(cmds.allNodeTypes()) all_node_types = set(cmds.allNodeTypes())
for node_type in list(FILE_NODES.keys()): 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:
if node_type not 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
@ -69,9 +81,7 @@ def get_attributes(dictionary, attr, node=None):
else: else:
val = dictionary.get(attr, []) val = dictionary.get(attr, [])
if not isinstance(val, list): return val if isinstance(val, list) else [val]
return [val]
return val
def get_look_attrs(node): def get_look_attrs(node):
@ -106,7 +116,7 @@ def get_look_attrs(node):
def node_uses_image_sequence(node, node_path): def node_uses_image_sequence(node, node_path):
# type: (str) -> bool # type: (str, str) -> bool
"""Return whether file node uses an image sequence or single image. """Return whether file node uses an image sequence or single image.
Determine if a node uses an image sequence or just a single image, Determine if a node uses an image sequence or just a single image,
@ -114,6 +124,7 @@ def node_uses_image_sequence(node, node_path):
Args: Args:
node (str): Name of the Maya node node (str): Name of the Maya node
node_path (str): The file path of the node
Returns: Returns:
bool: True if node uses an image sequence bool: True if node uses an image sequence
@ -247,7 +258,7 @@ def get_file_node_files(node):
# For sequences get all files and filter to only existing files # For sequences get all files and filter to only existing files
result = [] result = []
for index, path in enumerate(paths): for path in paths:
if node_uses_image_sequence(node, path): if node_uses_image_sequence(node, path):
glob_pattern = seq_to_glob(path) glob_pattern = seq_to_glob(path)
result.extend(glob.glob(glob_pattern)) result.extend(glob.glob(glob_pattern))
@ -358,6 +369,7 @@ class CollectLook(pyblish.api.InstancePlugin):
for attr in shader_attrs: for attr in shader_attrs:
if cmds.attributeQuery(attr, node=look, exists=True): if cmds.attributeQuery(attr, node=look, exists=True):
existing_attrs.append("{}.{}".format(look, attr)) existing_attrs.append("{}.{}".format(look, attr))
materials = cmds.listConnections(existing_attrs, materials = cmds.listConnections(existing_attrs,
source=True, source=True,
destination=False) or [] destination=False) or []
@ -367,30 +379,32 @@ class CollectLook(pyblish.api.InstancePlugin):
self.log.debug("Found the following sets:\n{}".format(look_sets)) self.log.debug("Found the following sets:\n{}".format(look_sets))
# Get the entire node chain of the look sets # Get the entire node chain of the look sets
# history = cmds.listHistory(look_sets, allConnections=True) # history = cmds.listHistory(look_sets, allConnections=True)
history = cmds.listHistory(materials, 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 # Since we retrieved history only of the connected materials
# connected to the look sets above we now add direct history # connected to the look sets above we now add direct history
# for some of the look sets directly # for some of the look sets directly
# handling render attribute sets # handling render attribute sets
render_set_types = [
"VRayDisplacement", # Maya (at least 2024) crashes with Warning when render set type
"VRayLightMesh", # isn't available. cmds.ls() will return empty list
"VRayObjectProperties", if RENDER_SET_TYPES:
"RedshiftObjectId", render_sets = cmds.ls(look_sets, type=RENDER_SET_TYPES)
"RedshiftMeshParameters", if render_sets:
] history.update(
render_sets = cmds.ls(look_sets, type=render_set_types) cmds.listHistory(render_sets,
if render_sets: future=False,
history.extend( pruneDagObjects=True)
cmds.listHistory(render_sets, or []
future=False, )
pruneDagObjects=True)
or []
)
# Ensure unique entries only # Ensure unique entries only
history = list(set(history)) history = list(history)
files = cmds.ls(history, files = cmds.ls(history,
# It's important only node types are passed that # It's important only node types are passed that

View file

@ -7,6 +7,8 @@ from openpype.pipeline.plugin_discover import (
deregister_plugin_path deregister_plugin_path
) )
from .load.utils import get_representation_path_from_context
class LauncherAction(object): class LauncherAction(object):
"""A custom action available""" """A custom action available"""
@ -100,6 +102,10 @@ class InventoryAction(object):
""" """
return True return True
@classmethod
def filepath_from_context(cls, context):
return get_representation_path_from_context(context)
# Launcher action # Launcher action
def discover_launcher_actions(): def discover_launcher_actions():