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

Maya: Redshift Volume Loader Implement update, remove, switch + fix vdb sequence support #3197

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Changes from all 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
75 changes: 69 additions & 6 deletions openpype/hosts/maya/plugins/load/load_vdb_to_redshift.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import os

from openpype.api import get_project_settings
from openpype.pipeline import load
from openpype.pipeline import (
load,
get_representation_path
)


class LoadVDBtoRedShift(load.LoaderPlugin):
"""Load OpenVDB in a Redshift Volume Shape"""
"""Load OpenVDB in a Redshift Volume Shape

Note that the RedshiftVolumeShape is created without a RedshiftVolume
shader assigned. To get the Redshift volume to render correctly assign
a RedshiftVolume shader (in the Hypershade) and set the density, scatter
and emission channels to the channel names of the volumes in the VDB file.

"""

families = ["vdbcache"]
representations = ["vdb"]
Expand Down Expand Up @@ -55,7 +65,7 @@ def load(self, context, name=None, namespace=None, data=None):

# Root group
label = "{}:{}".format(namespace, name)
root = cmds.group(name=label, empty=True)
root = cmds.createNode("transform", name=label)

settings = get_project_settings(os.environ['AVALON_PROJECT'])
colors = settings['maya']['load']['colors']
Expand All @@ -74,9 +84,9 @@ def load(self, context, name=None, namespace=None, data=None):
name="{}RVSShape".format(label),
parent=root)

cmds.setAttr("{}.fileName".format(volume_node),
self.fname,
type="string")
self._set_path(volume_node,
path=self.fname,
representation=context["representation"])

nodes = [root, volume_node]
self[:] = nodes
Expand All @@ -87,3 +97,56 @@ def load(self, context, name=None, namespace=None, data=None):
nodes=nodes,
context=context,
loader=self.__class__.__name__)

def update(self, container, representation):
from maya import cmds

path = get_representation_path(representation)

# Find VRayVolumeGrid
members = cmds.sets(container['objectName'], query=True)
grid_nodes = cmds.ls(members, type="RedshiftVolumeShape", long=True)
assert len(grid_nodes) == 1, "This is a bug"

# Update the VRayVolumeGrid
self._set_path(grid_nodes[0], path=path, representation=representation)

# Update container representation
cmds.setAttr(container["objectName"] + ".representation",
str(representation["_id"]),
type="string")

def remove(self, container):
from maya import cmds

# Get all members of the avalon container, ensure they are unlocked
# and delete everything
members = cmds.sets(container['objectName'], query=True)
cmds.lockNode(members, lock=False)
cmds.delete([container['objectName']] + members)

# Clean up the namespace
try:
cmds.namespace(removeNamespace=container['namespace'],
deleteNamespaceContent=True)
except RuntimeError:
pass

def switch(self, container, representation):
self.update(container, representation)

@staticmethod
def _set_path(grid_node,
path,
representation):
"""Apply the settings for the VDB path to the RedshiftVolumeShape"""
from maya import cmds

if not os.path.exists(path):
raise RuntimeError("Path does not exist: %s" % path)

is_sequence = bool(representation["context"].get("frame"))
cmds.setAttr(grid_node + ".useFrameExtension", is_sequence)

# Set file path
cmds.setAttr(grid_node + ".fileName", path, type="string")