From 82748d33071d726a76841d733a7c957a51ab36ae Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 5 Feb 2018 16:18:30 +0100 Subject: [PATCH] Implement FusionLoadSequence, including update and remove - also remove fusionless dependency --- .../plugins/fusion/load/load_sequence.py | 72 ++++++++++++++++--- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/colorbleed/plugins/fusion/load/load_sequence.py b/colorbleed/plugins/fusion/load/load_sequence.py index 2a675eee4c..52b869e540 100644 --- a/colorbleed/plugins/fusion/load/load_sequence.py +++ b/colorbleed/plugins/fusion/load/load_sequence.py @@ -1,6 +1,4 @@ from avalon import api -import fusionless -import fusionless.context as fuCtx import os @@ -17,25 +15,79 @@ class FusionLoadSequence(api.Loader): def load(self, context, name, namespace, data): - from avalon.fusion.pipeline import imprint_container + from avalon.fusion import ( + imprint_container, + get_current_comp, + comp_lock_and_undo_chunk + ) # Fallback to asset name when namespace is None if namespace is None: namespace = context['asset']['name'] # Use the first file for now - root = self.fname - files = os.listdir(root) - path = os.path.join(root, files[0]) + path = self._get_first_image(self.fname) # Create the Loader with the filename path set - comp = fusionless.Comp() - with fuCtx.lock_and_undo_chunk(comp, "Create Loader"): - tool = comp.create_tool("Loader") - tool.input("Clip").set_value(path) + comp = get_current_comp() + with comp_lock_and_undo_chunk(comp, "Create Loader"): + + args = (-32768, -32768) + tool = comp.AddTool("Loader", *args) + tool["Clip"] = path imprint_container(tool, name=name, namespace=namespace, context=context, loader=self.__class__.__name__) + + def _get_first_image(self, root): + """Get first file in representation root""" + files = sorted(os.listdir(root)) + return os.path.join(root, files[0]) + + def update(self, container, representation): + """Update the Loader's path + + Fusion automatically tries to reset some variables when changing + the loader's path to a new file. These automatic changes are to its + inputs: + - ClipTimeStart (if duration changes) + - ClipTimeEnd (if duration changes) + - GlobalIn (if duration changes) + - GlobalEnd (if duration changes) + - Reverse (sometimes?) + - Loop (sometimes?) + - Depth (always resets to "Format") + - KeyCode (always resets to "") + - TimeCodeOffset (always resets to 0) + + """ + + from avalon.fusion import comp_lock_and_undo_chunk + + root = api.get_representation_path(representation) + path = self._get_first_image(root) + print representation + print path + + tool = container["_tool"] + assert tool.ID == "Loader", "Must be Loader" + comp = tool.Comp() + + with comp_lock_and_undo_chunk(comp, "Update Loader"): + tool["Clip"] = path + + # Update the imprinted representation + tool.SetData("avalon.representation", str(representation["_id"])) + + def remove(self, container): + + from avalon.fusion import comp_lock_and_undo_chunk + + tool = container["_tool"] + assert tool.ID == "Loader", "Must be Loader" + comp = tool.Comp() + with comp_lock_and_undo_chunk(comp, "Remove Loader"): + tool.Delete()