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

Properly containerize image plane loads. #434

Merged
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
66 changes: 59 additions & 7 deletions pype/plugins/maya/load/load_image_plane.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import pymel.core as pc
import maya.cmds as cmds

from avalon import api
from avalon.maya.pipeline import containerise
from avalon.maya import lib
from Qt import QtWidgets


Expand All @@ -12,10 +17,14 @@ class ImagePlaneLoader(api.Loader):
color = "orange"

def load(self, context, name, namespace, data):
import pymel.core as pc

new_nodes = []
image_plane_depth = 1000
asset = context['asset']['name']
namespace = namespace or lib.unique_namespace(
asset + "_",
prefix="_" if asset[0].isdigit() else "",
suffix="_",
)

# Getting camera from selection.
selection = pc.ls(selection=True)
Expand Down Expand Up @@ -80,6 +89,9 @@ def load(self, context, name, namespace, data):

# Ask user whether to use sequence or still image.
if context["representation"]["name"] == "exr":
# Ensure OpenEXRLoader plugin is loaded.
pc.loadPlugin("OpenEXRLoader.mll", quiet=True)

reply = QtWidgets.QMessageBox.information(
None,
"Frame Hold.",
Expand All @@ -93,11 +105,51 @@ def load(self, context, name, namespace, data):
)
image_plane_shape.frameExtension.set(start_frame)

# Ensure OpenEXRLoader plugin is loaded.
pc.loadPlugin("OpenEXRLoader.mll", quiet=True)

new_nodes.extend(
[image_plane_transform.name(), image_plane_shape.name()]
[
image_plane_transform.longName().split("|")[-1],
image_plane_shape.longName().split("|")[-1]
]
)

return new_nodes
for node in new_nodes:
pc.rename(node, "{}:{}".format(namespace, node))

return containerise(
name=name,
namespace=namespace,
nodes=new_nodes,
context=context,
loader=self.__class__.__name__
)

def update(self, container, representation):
image_plane_shape = None
for node in pc.PyNode(container["objectName"]).members():
if node.nodeType() == "imagePlane":
image_plane_shape = node

assert image_plane_shape is not None, "Image plane not found."

path = api.get_representation_path(representation)
image_plane_shape.imageName.set(path)
cmds.setAttr(
container["objectName"] + ".representation",
str(representation["_id"]),
type="string"
)

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

def remove(self, container):
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