diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index 803ecdd7cc..82fde3538e 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -59,6 +59,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): "review", "nukescript", "render", + "rendersetup", "write", "rig", "plate" diff --git a/pype/plugins/maya/create/create_rendersetup.py b/pype/plugins/maya/create/create_rendersetup.py new file mode 100644 index 0000000000..a2890b3e01 --- /dev/null +++ b/pype/plugins/maya/create/create_rendersetup.py @@ -0,0 +1,53 @@ +import avalon.maya +import pype.maya.lib as lib +from maya import cmds + + +class CreateRenderSetup(avalon.maya.Creator): + """Create rendersetup template json data""" + + name = "rendersetup" + label = "Render Setup Preset" + family = "rendersetup" + icon = "tablet" + + def __init__(self, *args, **kwargs): + super(CreateRenderSetup, self).__init__(*args, **kwargs) + + # here we can pre-create renderSetup layers, possibly utlizing + # presets for it. + + # _____ + # / __\__ + # | / __\__ + # | | / \ + # | | | | + # \__| | | + # \__| | + # \_____/ + + # from pypeapp import config + # import maya.app.renderSetup.model.renderSetup as renderSetup + # presets = config.get_presets(project=os.environ['AVALON_PROJECT']) + # layer = presets['plugins']['maya']['create']['renderSetup']["layer"] + + # rs = renderSetup.instance() + # rs.createRenderLayer(layer) + + self.options = {"useSelection": False} # Force no content + + def process(self): + exists = cmds.ls(self.name) + assert len(exists) <= 1, ( + "More than one renderglobal exists, this is a bug" + ) + + if exists: + return cmds.warning("%s already exists." % exists[0]) + + with lib.undo_chunk(): + instance = super(CreateRenderSetup, self).process() + + self.data["renderSetup"] = "42" + null = cmds.sets(name="null_SET", empty=True) + cmds.sets([null], forceElement=instance) diff --git a/pype/plugins/maya/load/load_rendersetup.py b/pype/plugins/maya/load/load_rendersetup.py new file mode 100644 index 0000000000..91f78f5c35 --- /dev/null +++ b/pype/plugins/maya/load/load_rendersetup.py @@ -0,0 +1,50 @@ +from avalon import api +import maya.app.renderSetup.model.renderSetup as renderSetup +from avalon.maya import lib +from maya import cmds +import json + + +class RenderSetupLoader(api.Loader): + """ + This will load json preset for RenderSetup, overwriting current one. + """ + + families = ["rendersetup"] + representations = ["json"] + defaults = ['Main'] + + label = "Load RenderSetup template" + icon = "tablet" + color = "orange" + + def load(self, context, name, namespace, data): + + from avalon.maya.pipeline import containerise + # from pype.maya.lib import namespaced + + asset = context['asset']['name'] + namespace = namespace or lib.unique_namespace( + asset + "_", + prefix="_" if asset[0].isdigit() else "", + suffix="_", + ) + + with open(self.fname, "r") as file: + renderSetup.instance().decode( + json.load(file), renderSetup.DECODE_AND_OVERWRITE, None) + + nodes = [] + null = cmds.sets(name="null_SET", empty=True) + nodes.append(null) + + self[:] = nodes + if not nodes: + return + + return containerise( + name=name, + namespace=namespace, + nodes=nodes, + context=context, + loader=self.__class__.__name__) diff --git a/pype/plugins/maya/publish/extract_rendersetup.py b/pype/plugins/maya/publish/extract_rendersetup.py new file mode 100644 index 0000000000..b8dbfc178e --- /dev/null +++ b/pype/plugins/maya/publish/extract_rendersetup.py @@ -0,0 +1,40 @@ +import json +import os +import pype.api +import maya.app.renderSetup.model.renderSetup as renderSetup + + +class ExtractRenderSetup(pype.api.Extractor): + """ + Produce renderSetup template file + + This will save whole renderSetup to json file for later use. + """ + + label = "Extract RenderSetup" + hosts = ["maya"] + families = ["rendersetup"] + + def process(self, instance): + parent_dir = self.staging_dir(instance) + json_filename = "{}.json".format(instance.name) + json_path = os.path.join(parent_dir, json_filename) + + with open(json_path, "w+") as file: + json.dump( + renderSetup.instance().encode(None), + fp=file, indent=2, sort_keys=True) + + if "representations" not in instance.data: + instance.data["representations"] = [] + + representation = { + 'name': 'json', + 'ext': '.json', + 'files': json_filename, + "stagingDir": parent_dir, + } + instance.data["representations"].append(representation) + + self.log.info( + "Extracted instance '%s' to: %s" % (instance.name, json_path))