From 6701cd7c7c83df0b2e895ebc351d424a4719073c Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 13 Sep 2024 16:43:27 +0200 Subject: [PATCH] Refactor staging directory data passing in publishing instance plugins - Refactored code to pass staging directory data uniformly across multiple instance plugins for consistency and maintainability. Updated the method to handle this data transfer efficiently. --- .../plugins/publish/collect_gizmo.py | 15 ++++++++++- .../plugins/publish/collect_model.py | 15 ++++++++++- .../plugins/publish/collect_reads.py | 13 ++++++++++ .../plugins/publish/collect_writes.py | 26 ++++++++++++++----- .../plugins/publish/extract_camera.py | 22 +++++++++++++--- 5 files changed, 79 insertions(+), 12 deletions(-) diff --git a/client/ayon_nuke/plugins/publish/collect_gizmo.py b/client/ayon_nuke/plugins/publish/collect_gizmo.py index ece9823..2e31dba 100644 --- a/client/ayon_nuke/plugins/publish/collect_gizmo.py +++ b/client/ayon_nuke/plugins/publish/collect_gizmo.py @@ -15,9 +15,12 @@ class CollectGizmo(pyblish.api.InstancePlugin): def process(self, instance): + # pass staging dir data + self._pass_staging_dir_data(instance) + gizmo_node = instance.data["transientData"]["node"] - # add product type to familiess + # add product type to families instance.data["families"].insert(0, instance.data["productType"]) # make label nicer instance.data["label"] = gizmo_node.name() @@ -47,3 +50,13 @@ def process(self, instance): "frameEnd": last_frame }) self.log.debug("Gizmo instance collected: `{}`".format(instance)) + + def _pass_staging_dir_data(self, instance): + staging_dir = instance.data["transientData"]["stagingDir"] + staging_dir_persistent = instance.data["transientData"].get( + "stagingDir_persistent", False + ) + instance.data.update({ + "stagingDir": staging_dir, + "stagingDir_persistent": staging_dir_persistent + }) diff --git a/client/ayon_nuke/plugins/publish/collect_model.py b/client/ayon_nuke/plugins/publish/collect_model.py index f4266bb..a257a7c 100644 --- a/client/ayon_nuke/plugins/publish/collect_model.py +++ b/client/ayon_nuke/plugins/publish/collect_model.py @@ -15,9 +15,12 @@ class CollectModel(pyblish.api.InstancePlugin): def process(self, instance): + # pass staging dir data + self._pass_staging_dir_data(instance) + geo_node = instance.data["transientData"]["node"] - # add product type to familiess + # add product type to families instance.data["families"].insert(0, instance.data["productType"]) # make label nicer instance.data["label"] = geo_node.name() @@ -46,3 +49,13 @@ def process(self, instance): "frameEnd": last_frame }) self.log.debug("Model instance collected: `{}`".format(instance)) + + def _pass_staging_dir_data(self, instance): + staging_dir = instance.data["transientData"]["stagingDir"] + staging_dir_persistent = instance.data["transientData"].get( + "stagingDir_persistent", False + ) + instance.data.update({ + "stagingDir": staging_dir, + "stagingDir_persistent": staging_dir_persistent + }) \ No newline at end of file diff --git a/client/ayon_nuke/plugins/publish/collect_reads.py b/client/ayon_nuke/plugins/publish/collect_reads.py index 439374e..e75d7ba 100644 --- a/client/ayon_nuke/plugins/publish/collect_reads.py +++ b/client/ayon_nuke/plugins/publish/collect_reads.py @@ -17,6 +17,9 @@ class CollectNukeReads(pyblish.api.InstancePlugin): def process(self, instance): self.log.debug("checking instance: {}".format(instance)) + # pass staging dir data + self._pass_staging_dir_data(instance) + node = instance.data["transientData"]["node"] if node.Class() != "Read": return @@ -122,3 +125,13 @@ def process(self, instance): }) self.log.debug("instance.data: {}".format(instance.data)) + + def _pass_staging_dir_data(self, instance): + staging_dir = instance.data["transientData"]["stagingDir"] + staging_dir_persistent = instance.data["transientData"].get( + "stagingDir_persistent", False + ) + instance.data.update({ + "stagingDir": staging_dir, + "stagingDir_persistent": staging_dir_persistent + }) diff --git a/client/ayon_nuke/plugins/publish/collect_writes.py b/client/ayon_nuke/plugins/publish/collect_writes.py index 816f493..7376827 100644 --- a/client/ayon_nuke/plugins/publish/collect_writes.py +++ b/client/ayon_nuke/plugins/publish/collect_writes.py @@ -20,9 +20,29 @@ class CollectNukeWrites(pyblish.api.InstancePlugin, _write_nodes = {} _frame_ranges = {} + def _pass_staging_dir_data(self, instance): + staging_dir = instance.data["transientData"]["stagingDir"] + instance.data["stagingDir"] = staging_dir + + staging_dir_persistent = instance.data["transientData"].get( + "stagingDir_persistent", False + ) + + if staging_dir_persistent is not None: + instance.data["stagingDir_persistent"] = staging_dir_persistent + else: + # compatibility. This is mainly focused on `renders`folders which + # were previously not cleaned up (and could be used in read notes) + # this logic should be removed and replaced with custom staging dir + instance.data["stagingDir_persistent"] = True + def process(self, instance): + # pass staging dir data + self._pass_staging_dir_data(instance) + group_node = instance.data["transientData"]["node"] + render_target = instance.data["render_target"] write_node = self._write_node_helper(instance) @@ -200,12 +220,6 @@ def _set_additional_instance_data( "frameEndHandle": last_frame, }) - # TODO temporarily set stagingDir as persistent for backward - # compatibility. This is mainly focused on `renders`folders which - # were previously not cleaned up (and could be used in read notes) - # this logic should be removed and replaced with custom staging dir - instance.data["stagingDir_persistent"] = True - def _write_node_helper(self, instance): """Helper function to get write node from instance. diff --git a/client/ayon_nuke/plugins/publish/extract_camera.py b/client/ayon_nuke/plugins/publish/extract_camera.py index 01c1ddf..0745bee 100644 --- a/client/ayon_nuke/plugins/publish/extract_camera.py +++ b/client/ayon_nuke/plugins/publish/extract_camera.py @@ -43,8 +43,8 @@ def _get_camera_export_presets(self, instance): write_geo_knobs.append((("storageFormat", "Ogawa"))) elif export_camera_settings == "fbx": - write_geo_knobs.insert(0, ("file_type", "fbx")) - write_geo_knobs.append(("writeLights", False)) + write_geo_knobs.insert(0, ("file_type", "fbx")) + write_geo_knobs.append(("writeLights", False)) else: raise ValueError( @@ -53,8 +53,11 @@ def _get_camera_export_presets(self, instance): return write_geo_knobs - def process(self, instance): + + # pass staging dir data + staging_dir = self._pass_staging_dir_data(instance) + camera_node = instance.data["transientData"]["node"] handle_start = instance.context.data["handleStart"] handle_end = instance.context.data["handleEnd"] @@ -66,7 +69,6 @@ def process(self, instance): rm_nodes = [] self.log.debug("Creating additional nodes for 3D Camera Extractor") product_name = instance.data["productName"] - staging_dir = self.staging_dir(instance) # get extension form preset export_presets = self._get_camera_export_presets(instance) @@ -138,6 +140,18 @@ def process(self, instance): self.log.debug("Extracted instance '{0}' to: {1}".format( instance.name, file_path)) + def _pass_staging_dir_data(self, instance): + staging_dir = instance.data["transientData"]["stagingDir"] + staging_dir_persistent = instance.data["transientData"].get( + "stagingDir_persistent", False + ) + instance.data.update({ + "stagingDir": staging_dir, + "stagingDir_persistent": staging_dir_persistent + }) + + return staging_dir + def bakeCameraWithAxeses(camera_node, output_range): """ Baking all perent hierarchy of axeses into camera