Support switching between proxy and non-proxy

This commit is contained in:
Toke Stuart Jepsen 2023-02-10 10:00:49 +00:00
parent 22046ad5d3
commit ff63a91864
3 changed files with 31 additions and 14 deletions

View file

@ -53,10 +53,8 @@ class ArnoldStandinLoader(load.LoaderPlugin):
root = cmds.group(name=label, empty=True) root = cmds.group(name=label, empty=True)
# Set color. # Set color.
project_name = context["project"]["name"] settings = get_project_settings(context["project"]["name"])
settings = get_project_settings(project_name) color = settings['maya']['load']['colors'].get('ass')
colors = settings['maya']['load']['colors']
color = colors.get('ass')
if color is not None: if color is not None:
cmds.setAttr(root + ".useOutlinerColor", True) cmds.setAttr(root + ".useOutlinerColor", True)
cmds.setAttr( cmds.setAttr(
@ -121,10 +119,6 @@ class ArnoldStandinLoader(load.LoaderPlugin):
def _setup_proxy(self, shape, path, namespace): def _setup_proxy(self, shape, path, namespace):
proxy_basename, proxy_path = self._get_proxy_path(path) proxy_basename, proxy_path = self._get_proxy_path(path)
if not os.path.exists(proxy_path):
self.log.error("Proxy files do not exist. Skipping proxy setup.")
return path, None
options_node = "defaultArnoldRenderOptions" options_node = "defaultArnoldRenderOptions"
merge_operator = get_attribute_input(options_node + ".operator") merge_operator = get_attribute_input(options_node + ".operator")
if merge_operator is None: if merge_operator is None:
@ -163,6 +157,12 @@ class ArnoldStandinLoader(load.LoaderPlugin):
) )
) )
# We setup the string operator no matter whether there is a proxy or
# not. This makes it easier to update since the string operator will
# always be created. Return original path to use for standin.
if not os.path.exists(proxy_path):
return path, string_replace_operator
return proxy_path, string_replace_operator return proxy_path, string_replace_operator
def update(self, container, representation): def update(self, container, representation):
@ -180,6 +180,9 @@ class ArnoldStandinLoader(load.LoaderPlugin):
path = get_representation_path(representation) path = get_representation_path(representation)
proxy_basename, proxy_path = self._get_proxy_path(path) proxy_basename, proxy_path = self._get_proxy_path(path)
# Whether there is proxy or so, we still update the string operator.
# If no proxy exists, the string operator wont replace anything.
cmds.setAttr( cmds.setAttr(
string_replace_operator + ".match", string_replace_operator + ".match",
"resources/" + proxy_basename, "resources/" + proxy_basename,
@ -190,7 +193,11 @@ class ArnoldStandinLoader(load.LoaderPlugin):
os.path.basename(path), os.path.basename(path),
type="string" type="string"
) )
cmds.setAttr(standin + ".dso", proxy_path, type="string")
dso_path = path
if os.path.exists(proxy_path):
dso_path = proxy_path
cmds.setAttr(standin + ".dso", dso_path, type="string")
sequence = is_sequence(os.listdir(os.path.dirname(path))) sequence = is_sequence(os.listdir(os.path.dirname(path)))
cmds.setAttr(standin + ".useFrameExtension", sequence) cmds.setAttr(standin + ".useFrameExtension", sequence)

View file

@ -95,6 +95,9 @@ class ExtractArnoldSceneSource(publish.Extractor):
) )
# Extract proxy. # Extract proxy.
if not instance.data.get("proxy", []):
return
kwargs["filename"] = file_path.replace(".ass", "_proxy.ass") kwargs["filename"] = file_path.replace(".ass", "_proxy.ass")
filenames = self._extract( filenames = self._extract(
instance.data["proxy"], attribute_data, kwargs instance.data["proxy"], attribute_data, kwargs
@ -132,7 +135,6 @@ class ExtractArnoldSceneSource(publish.Extractor):
duplicate_nodes = [] duplicate_nodes = []
for node in nodes: for node in nodes:
duplicate_transform = cmds.duplicate(node)[0] duplicate_transform = cmds.duplicate(node)[0]
delete_bin.append(duplicate_transform)
# Discard the children. # Discard the children.
shapes = cmds.listRelatives(duplicate_transform, shapes=True) shapes = cmds.listRelatives(duplicate_transform, shapes=True)
@ -145,7 +147,11 @@ class ExtractArnoldSceneSource(publish.Extractor):
duplicate_transform, world=True duplicate_transform, world=True
)[0] )[0]
cmds.rename(duplicate_transform, node.split("|")[-1])
duplicate_transform = "|" + node.split("|")[-1]
duplicate_nodes.append(duplicate_transform) duplicate_nodes.append(duplicate_transform)
delete_bin.append(duplicate_transform)
with attribute_values(attribute_data): with attribute_values(attribute_data):
with maintained_selection(): with maintained_selection():

View file

@ -9,6 +9,9 @@ from openpype.pipeline.publish import (
class ValidateArnoldSceneSource(pyblish.api.InstancePlugin): class ValidateArnoldSceneSource(pyblish.api.InstancePlugin):
"""Validate Arnold Scene Source. """Validate Arnold Scene Source.
We require at least 1 root node/parent for the meshes. This is to ensure we
can duplicate the nodes and preserve the names.
If using proxies we need the nodes to share the same names and not be If using proxies we need the nodes to share the same names and not be
parent to the world. This ends up needing at least two groups with content parent to the world. This ends up needing at least two groups with content
nodes and proxy nodes in another. nodes and proxy nodes in another.
@ -39,9 +42,6 @@ class ValidateArnoldSceneSource(pyblish.api.InstancePlugin):
return ungrouped_nodes, nodes_by_name, parents return ungrouped_nodes, nodes_by_name, parents
def process(self, instance): def process(self, instance):
if not instance.data["proxy"]:
return
ungrouped_nodes = [] ungrouped_nodes = []
nodes, content_nodes_by_name, content_parents = self._get_nodes_data( nodes, content_nodes_by_name, content_parents = self._get_nodes_data(
@ -50,7 +50,7 @@ class ValidateArnoldSceneSource(pyblish.api.InstancePlugin):
ungrouped_nodes.extend(nodes) ungrouped_nodes.extend(nodes)
nodes, proxy_nodes_by_name, proxy_parents = self._get_nodes_data( nodes, proxy_nodes_by_name, proxy_parents = self._get_nodes_data(
instance.data["proxy"] instance.data.get("proxy", [])
) )
ungrouped_nodes.extend(nodes) ungrouped_nodes.extend(nodes)
@ -61,6 +61,10 @@ class ValidateArnoldSceneSource(pyblish.api.InstancePlugin):
"All nodes need to be grouped.".format(ungrouped_nodes) "All nodes need to be grouped.".format(ungrouped_nodes)
) )
# Proxy validation.
if not instance.data.get("proxy", []):
return
# Validate for content and proxy nodes amount being the same. # Validate for content and proxy nodes amount being the same.
if len(instance.data["setMembers"]) != len(instance.data["proxy"]): if len(instance.data["setMembers"]) != len(instance.data["proxy"]):
raise PublishValidationError( raise PublishValidationError(