From be652995e8d4778f4c4997a6792e4510511a3c89 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 24 Mar 2022 11:21:41 +0100 Subject: [PATCH 1/5] added extractor converting pngs to exr from tvpaint --- .../plugins/publish/extract_convert_to_exr.py | 96 +++++++++++++++++++ .../plugins/publish/extract_sequence.py | 1 - 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py diff --git a/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py b/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py new file mode 100644 index 0000000000..5fc9be9f42 --- /dev/null +++ b/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py @@ -0,0 +1,96 @@ +"""Plugin converting png files from ExtractSequence into exrs. + +Requires: + ExtractSequence - source of PNG + ExtractReview - review was already created so we can convert to any exr +""" +import os +import json + +import pyblish.api +from openpype.lib import ( + get_oiio_tools_path, + run_subprocess, +) +from openpype.pipeline import KnownPublishError + + +class ExtractConvertToEXR(pyblish.api.InstancePlugin): + # Offset to get after ExtractSequence plugin. + order = pyblish.api.ExtractorOrder + 0.1 + label = "Extract Sequence EXR" + hosts = ["tvpaint"] + families = ["render"] + + active = False + + replace_pngs = True + exr_compression = "DWAA" + + def process(self, instance): + repres = instance.data.get("representations") + if not repres: + return + + oiio_path = get_oiio_tools_path() + # Raise an exception when oiiotool is not available + # - this can currently happen on MacOS machines + if not os.path.exists(oiio_path): + KnownPublishError( + "OpenImageIO tool is not available on this machine." + ) + + new_repres = [] + for repre in repres: + if repre["name"] != "png": + continue + + self.log.info( + "Processing representation: {}".format( + json.dumps(repre, sort_keys=True, indent=4) + ) + ) + + src_filepaths = set() + new_filenames = [] + for src_filename in repre["files"]: + dst_filename = os.path.splitext(src_filename)[0] + ".exr" + new_filenames.append(dst_filename) + + src_filepath = os.path.join(repre["stagingDir"], src_filename) + dst_filepath = os.path.join(repre["stagingDir"], dst_filename) + + src_filepaths.add(src_filepath) + + args = [ + oiio_path, src_filepath, + "--compression", self.exr_compression, + # TODO how to define color conversion? + "--colorconvert", "sRGB", "linear", + "-o", dst_filepath + ] + run_subprocess(args) + + new_repres.append( + { + "name": "exr", + "ext": "exr", + "files": new_filenames, + "stagingDir": repre["stagingDir"], + "tags": list(repre["tags"]) + } + ) + + if self.replace_pngs: + instance.data["representations"].remove(repre) + for filepath in src_filepaths: + os.remove(filepath) + + instance.data["representations"].extend(new_repres) + self.log.info( + "Representations: {}".format( + json.dumps( + instance.data["representations"], sort_keys=True, indent=4 + ) + ) + ) diff --git a/openpype/hosts/tvpaint/plugins/publish/extract_sequence.py b/openpype/hosts/tvpaint/plugins/publish/extract_sequence.py index 729c545545..139dabadee 100644 --- a/openpype/hosts/tvpaint/plugins/publish/extract_sequence.py +++ b/openpype/hosts/tvpaint/plugins/publish/extract_sequence.py @@ -12,7 +12,6 @@ from openpype.hosts.tvpaint.lib import ( fill_reference_frames, composite_rendered_layers, rename_filepaths_by_frame_start, - composite_images ) From 41a66e86775637a9215e6887a24627755d508a4a Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 24 Mar 2022 11:22:14 +0100 Subject: [PATCH 2/5] added settings for new plugin --- .../defaults/project_settings/tvpaint.json | 5 +++ .../schema_project_tvpaint.json | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/openpype/settings/defaults/project_settings/tvpaint.json b/openpype/settings/defaults/project_settings/tvpaint.json index 528bf6de8e..46beeb85b9 100644 --- a/openpype/settings/defaults/project_settings/tvpaint.json +++ b/openpype/settings/defaults/project_settings/tvpaint.json @@ -28,6 +28,11 @@ "enabled": true, "optional": true, "active": true + }, + "ExtractConvertToEXR": { + "enabled": false, + "replace_pngs": true, + "exr_compression": "ZIP" } }, "load": { diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_tvpaint.json b/openpype/settings/entities/schemas/projects_schema/schema_project_tvpaint.json index 8286ed1193..97462a8b62 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_tvpaint.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_tvpaint.json @@ -78,6 +78,47 @@ "docstring": "Validate if shot on instances metadata is same as workfiles shot" } ] + }, + { + "type": "dict", + "key": "ExtractConvertToEXR", + "label": "Extract Convert To EXR", + "is_group": true, + "checkbox_key": "enabled", + "children": [ + { + "type": "boolean", + "key": "enabled", + "label": "Enabled" + }, + { + "type": "label", + "label": "WARNING: This plugin does not work on MacOS (using OIIO tool)." + }, + { + "type": "boolean", + "key": "replace_pngs", + "label": "Replace source PNG" + }, + { + "type": "enum", + "key": "exr_compression", + "label": "EXR Compression", + "multiselection": false, + "enum_items": [ + {"ZIP": "ZIP"}, + {"ZIPS": "ZIPS"}, + {"DWAA": "DWAA"}, + {"DWAB": "DWAB"}, + {"PIZ": "PIZ"}, + {"RLE": "RLE"}, + {"PXR24": "PXR24"}, + {"B44": "B44"}, + {"B44A": "B44A"}, + {"none": "None"} + ] + } + ] } ] }, From c68a93b467135fa02f48e41db10b3464ed9379bc Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 24 Mar 2022 12:10:43 +0100 Subject: [PATCH 3/5] added plugin which prepare keys for ExplicitCleanUp plugin --- .../plugins/publish/collect_cleanup_keys.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 openpype/plugins/publish/collect_cleanup_keys.py diff --git a/openpype/plugins/publish/collect_cleanup_keys.py b/openpype/plugins/publish/collect_cleanup_keys.py new file mode 100644 index 0000000000..635b038387 --- /dev/null +++ b/openpype/plugins/publish/collect_cleanup_keys.py @@ -0,0 +1,21 @@ +""" +Requires: + None +Provides: + context + - cleanupFullPaths (list) + - cleanupEmptyDirs (list) +""" + +import pyblish.api + + +class CollectCleanupKeys(pyblish.api.ContextPlugin): + """Prepare keys for 'ExplicitCleanUp' plugin.""" + + label = "Collect Cleanup Keys" + order = pyblish.api.CollectorOrder + + def process(self, context): + context.data["cleanupFullPaths"] = [] + context.data["cleanupEmptyDirs"] = [] From 62d7bcc0d027f26fc62620a0f670ec32f5fbd399 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 24 Mar 2022 12:11:01 +0100 Subject: [PATCH 4/5] changed default attributes --- .../hosts/tvpaint/plugins/publish/extract_convert_to_exr.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py b/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py index 5fc9be9f42..522173803b 100644 --- a/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py +++ b/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py @@ -22,10 +22,12 @@ class ExtractConvertToEXR(pyblish.api.InstancePlugin): hosts = ["tvpaint"] families = ["render"] - active = False + enabled = False + # Replace source PNG files or just add replace_pngs = True - exr_compression = "DWAA" + # EXR compression + exr_compression = "ZIP" def process(self, instance): repres = instance.data.get("representations") From 54b0e2ec9cf0e37228c1ece66f4728e2cb53ac79 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 24 Mar 2022 12:11:19 +0100 Subject: [PATCH 5/5] don't remove the files but add to cleanup data --- .../hosts/tvpaint/plugins/publish/extract_convert_to_exr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py b/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py index 522173803b..ab5bbc5e2c 100644 --- a/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py +++ b/openpype/hosts/tvpaint/plugins/publish/extract_convert_to_exr.py @@ -85,8 +85,9 @@ class ExtractConvertToEXR(pyblish.api.InstancePlugin): if self.replace_pngs: instance.data["representations"].remove(repre) + for filepath in src_filepaths: - os.remove(filepath) + instance.context.data["cleanupFullPaths"].append(filepath) instance.data["representations"].extend(new_repres) self.log.info(