Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Looks: add basic support for Renderman #3190

Merged
merged 6 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 additions & 14 deletions openpype/hosts/maya/plugins/publish/collect_look.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@

SHAPE_ATTRS = set(SHAPE_ATTRS)

DEFAULT_FILE_NODES = frozenset(
["file"]
)

ARNOLD_FILE_NODES = frozenset(
["aiImage"]
)

REDSHIFT_FILE_NODES = frozenset(
["RedshiftNormalMap"]
)

RENDERMAN_FILE_NODES = frozenset(
[
"PxrBump",
"PxrNormalMap",
# PxrMultiTexture (need to handle multiple filename0 attrs)
"PxrPtexture",
"PxrTexture",
]
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to store it like this:

file_nodes = {
    # Maya
    "file": "filename",

    # Arnold
    "aiImage": "filename",

    # Redshift
    "RedshiftNormalMap": "tex0",

    # Renderman
    "PxrBump": "filename",
    "PxrNormalMap": "filename",
    "PxrPtexture": "filename",
    "PxrTexture": "filename",
    # PrxMultiTexture is a special case with multiple filename attributes
    # So this could maybe be a special function?
    "PxrMultiTexture": get_pixar_multi_texture
}

# Example usages
node_type = cmds.nodeType(node)
attr = file_nodes[node_type]
path = cmds.getAttr('{}.{}'.format(node, attr))

Special edge case:

def get_pixar_multi_texture(node):
    filepaths = []
    for path in path_attributes:
        filepaths.append(path)
    return filepaths

Somehow feels more manageable overall instead of having the logic spread out as much as it is now?


NODES_WITH_FILENAME = frozenset().union(
DEFAULT_FILE_NODES, ARNOLD_FILE_NODES, RENDERMAN_FILE_NODES
)


def get_look_attrs(node):
"""Returns attributes of a node that are important for the look.
Expand Down Expand Up @@ -60,6 +86,7 @@ def get_look_attrs(node):


def node_uses_image_sequence(node):
# type: (str) -> bool
"""Return whether file node uses an image sequence or single image.

Determine if a node uses an image sequence or just a single image,
Expand All @@ -77,9 +104,14 @@ def node_uses_image_sequence(node):
node_path = get_file_node_path(node).lower()

# The following tokens imply a sequence
patterns = ["<udim>", "<tile>", "<uvtile>", "u<u>_v<v>", "<frame0"]

return (cmds.getAttr('%s.useFrameExtension' % node) or
patterns = ["<udim>", "<tile>", "<uvtile>",
"u<u>_v<v>", "<frame0", "<f4>"]
try:
use_frame_extension = cmds.getAttr('%s.useFrameExtension' % node)
except ValueError:
use_frame_extension = False

return (use_frame_extension or
any(pattern in node_path for pattern in patterns))


Expand Down Expand Up @@ -165,7 +197,7 @@ def get_file_node_path(node):
if any(pattern in lower for pattern in patterns):
return texture_pattern

if cmds.nodeType(node) == 'aiImage':
if cmds.nodeType(node) in NODES_WITH_FILENAME:
return cmds.getAttr('{0}.filename'.format(node))
if cmds.nodeType(node) == 'RedshiftNormalMap':
return cmds.getAttr('{}.tex0'.format(node))
Expand Down Expand Up @@ -326,7 +358,10 @@ def collect(self, instance):
"volumeShader",
"displacementShader",
"aiSurfaceShader",
"aiVolumeShader"]
"aiVolumeShader",
"rman__surface",
"rman__displacement"
]
if look_sets:
materials = []

Expand Down Expand Up @@ -374,9 +409,13 @@ def collect(self, instance):
or []
)

files = cmds.ls(history, type="file", long=True)
files.extend(cmds.ls(history, type="aiImage", long=True))
files.extend(cmds.ls(history, type="RedshiftNormalMap", long=True))
all_supported_nodes = set().union(
DEFAULT_FILE_NODES, ARNOLD_FILE_NODES, REDSHIFT_FILE_NODES,
RENDERMAN_FILE_NODES
)
files = []
for node_type in all_supported_nodes:
files.extend(cmds.ls(history, type=node_type, long=True))

self.log.info("Collected file nodes:\n{}".format(files))
# Collect textures if any file nodes are found
Expand Down Expand Up @@ -510,23 +549,21 @@ def collect_resource(self, node):
Returns:
dict
"""

self.log.debug("processing: {}".format(node))
if cmds.nodeType(node) not in ["file", "aiImage", "RedshiftNormalMap"]:
if cmds.nodeType(node) not in {
"file", "aiImage", "RedshiftNormalMap", "PxrTexture"}:
self.log.error(
"Unsupported file node: {}".format(cmds.nodeType(node)))
raise AssertionError("Unsupported file node")

self.log.debug(" - got {}".format(cmds.nodeType(node)))
if cmds.nodeType(node) == 'file':
self.log.debug(" - file node")
attribute = "{}.fileTextureName".format(node)
computed_attribute = "{}.computedFileTextureNamePattern".format(node)
elif cmds.nodeType(node) == 'aiImage':
self.log.debug("aiImage node")
elif cmds.nodeType(node) in ['aiImage', 'PxrTexture']:
attribute = "{}.filename".format(node)
computed_attribute = attribute
elif cmds.nodeType(node) == 'RedshiftNormalMap':
self.log.debug("RedshiftNormalMap node")
attribute = "{}.tex0".format(node)
computed_attribute = attribute

Expand Down
6 changes: 4 additions & 2 deletions openpype/hosts/maya/plugins/publish/extract_look.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ def process_resources(self, instance, staging_dir):

if mode == COPY:
transfers.append((source, destination))
self.log.info('copying')
self.log.info('file will be copied {} -> {}'.format(
source, destination))
elif mode == HARDLINK:
hardlinks.append((source, destination))
self.log.info('hardlinking')
self.log.info('file will be hardlinked {} -> {}'.format(
source, destination))

# Store the hashes from hash to destination to include in the
# database
Expand Down