From 37e88288b4f667d8151664a1b7f28e64ad944482 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Mon, 7 Sep 2020 14:01:34 +0200 Subject: [PATCH] tag instance for scanline conversion using oiio tools --- .../global/publish/extract_scanline_exr.py | 85 +++++++++++++++++++ .../global/publish/submit_publish_job.py | 7 +- pype/plugins/maya/create/create_render.py | 1 + 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 pype/plugins/global/publish/extract_scanline_exr.py diff --git a/pype/plugins/global/publish/extract_scanline_exr.py b/pype/plugins/global/publish/extract_scanline_exr.py new file mode 100644 index 0000000000..e1ca0e7c1c --- /dev/null +++ b/pype/plugins/global/publish/extract_scanline_exr.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +"""Convert tiled exrs to scanline if needed.""" +import os +import copy + +import pyblish.api +import pype.api +import pype.lib + + +class ExtractScanlineExr(pyblish.api.InstancePlugin): + """Convert tiled EXRs to scanline using OIIO tool.""" + + label = "Extract Scanline EXR" + hosts = ["shell"] + order = pyblish.api.ExtractorOrder + families = ["imagesequence", "render", "render2d", "source"] + + def process(self, instance): + """Plugin entry point.""" + anatomy = instance.context.data['anatomy'] + + # get representation and loop them + representations = instance.data["representations"] + representations_new = [] + + for repre in representations: + tags = repre.get("tags", []) + if "toScanline" not in tags: + continue + + # run only on exrs + if repre.get("ext") != "exr": + continue + + if not isinstance(repre['files'], (list, tuple)): + input_files = [repre['files']] + self.log.info("We have a sequence.") + else: + input_files = repre['files'] + self.log.info("We have a single frame") + + stagingdir = os.path.normpath(repre.get("stagingDir")) + stagingdir = anatomy.fill_root(stagingdir) + + oiio_tool_path = os.getenv("PYPE_OIIO_PATH", "") + + new_files = [] + for file in input_files: + + oiio_cmd = [] + oiio_cmd.append(oiio_tool_path) + oiio_cmd.append( + os.path.join(stagingdir, file) + ) + oiio_cmd.append("--scanline") + oiio_cmd.append("-o") + new_file = f"_scanline_{file}" + new_files.append(new_file) + oiio_cmd.append(stagingdir, new_file) + + subprocess_exr = " ".join(oiio_cmd) + self.log.info(f"running: {subprocess_exr}") + pype.api.subprocess(subprocess_exr) + + # raise error if there is no ouptput + if not os.path.exists(os.path.join(stagingdir, new_file)): + self.log.error( + f"File {new_file} was not produced by oiio tool!") + raise AssertionError("OIIO tool conversion failed") + + if "representations" not in instance.data: + instance.data["representations"] = [] + + representation = copy.deepcopy(repre) + + representation['name'] = 'scanline exr' + representation['files'] = new_files if len(new_files) > 1 else new_files[0] # noqa: E501 + representation['tags'].remove("toScanline") + + # add representation + self.log.debug("Adding: {}".format(representation)) + representations_new.append(representation) + + instance.data["representations"] = representations_new diff --git a/pype/plugins/global/publish/submit_publish_job.py b/pype/plugins/global/publish/submit_publish_job.py index ab5d6cf9b2..2d6d1efff8 100644 --- a/pype/plugins/global/publish/submit_publish_job.py +++ b/pype/plugins/global/publish/submit_publish_job.py @@ -193,7 +193,8 @@ class ProcessSubmittedJobOnFarm(pyblish.api.InstancePlugin): "slate": ["slateFrame"], "review": ["lutPath"], "render2d": ["bakeScriptPath", "bakeRenderPath", - "bakeWriteNodeName", "version"] + "bakeWriteNodeName", "version"], + "renderlayer": ["convertToScanline"] } # list of family names to transfer to new family if present @@ -491,6 +492,10 @@ class ProcessSubmittedJobOnFarm(pyblish.api.InstancePlugin): "tags": ["review"] if preview else [] } + # support conversion from tiled to scanline + if instance_data.get("convertToScanline"): + rep["tags"].append("toScanline") + # poor man exclusion if ext in self.skip_integration_repre_list: rep["tags"].append("delete") diff --git a/pype/plugins/maya/create/create_render.py b/pype/plugins/maya/create/create_render.py index 6826d33c58..fa0e269126 100644 --- a/pype/plugins/maya/create/create_render.py +++ b/pype/plugins/maya/create/create_render.py @@ -188,6 +188,7 @@ class CreateRender(avalon.maya.Creator): self.data["tileRendering"] = False self.data["tilesX"] = 2 self.data["tilesY"] = 2 + self.data["convertToScanline"] = False # Disable for now as this feature is not working yet # self.data["assScene"] = False