From 1c27e661091845a74d7cc50b0963f599390eaae3 Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Thu, 13 Aug 2020 15:19:23 +0100 Subject: [PATCH] Updated the loading of the layout to support nested containers --- pype/hosts/blender/plugin.py | 34 +++++++++++++----------- pype/plugins/blender/load/load_layout.py | 18 ++++++++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/pype/hosts/blender/plugin.py b/pype/hosts/blender/plugin.py index 4df23cf7bb..ddc453dd34 100644 --- a/pype/hosts/blender/plugin.py +++ b/pype/hosts/blender/plugin.py @@ -29,15 +29,19 @@ def get_unique_number( c for c in bpy.data.collections if c.name == 'AVALON_CONTAINERS' ] - loaded_assets = [] + containers = [] + # First, add the children of avalon containers for c in avalon_containers: - loaded_assets.extend(c.children) - collections_names = [ - c.name for c in loaded_assets + containers.extend(c.children) + # then keep looping to include all the children + for c in containers: + containers.extend(c.children) + container_names = [ + c.name for c in containers ] count = 1 name = f"{asset}_{count:0>2}_{subset}_CON" - while name in collections_names: + while name in container_names: count += 1 name = f"{asset}_{count:0>2}_{subset}_CON" return f"{count:0>2}" @@ -197,16 +201,16 @@ class AssetLoader(api.Loader): return None # Only containerise if it's not already a collection from a .blend file. - representation = context["representation"]["name"] - if representation != "blend": - from avalon.blender.pipeline import containerise - return containerise( - name=name, - namespace=namespace, - nodes=nodes, - context=context, - loader=self.__class__.__name__, - ) + # representation = context["representation"]["name"] + # if representation != "blend": + # from avalon.blender.pipeline import containerise + # return containerise( + # name=name, + # namespace=namespace, + # nodes=nodes, + # context=context, + # loader=self.__class__.__name__, + # ) asset = context["asset"]["name"] subset = context["subset"]["name"] diff --git a/pype/plugins/blender/load/load_layout.py b/pype/plugins/blender/load/load_layout.py index 166e862f8d..260112988c 100644 --- a/pype/plugins/blender/load/load_layout.py +++ b/pype/plugins/blender/load/load_layout.py @@ -196,7 +196,7 @@ class BlendLayoutLoader(plugin.AssetLoader): assert libpath.is_file(), ( f"The file doesn't exist: {libpath}" ) - assert extension in pype.hosts.blender.plugin.VALID_EXTENSIONS, ( + assert extension in plugin.VALID_EXTENSIONS, ( f"Unsupported file: {libpath}" ) @@ -350,17 +350,17 @@ class UnrealLayoutLoader(plugin.AssetLoader): asset, subset, unique_number ) - container = bpy.data.collections.new(lib_container) - container.name = container_name + layout_container = bpy.data.collections.new(lib_container) + layout_container.name = container_name blender.pipeline.containerise_existing( - container, + layout_container, name, namespace, context, self.__class__.__name__, ) - container_metadata = container.get( + container_metadata = layout_container.get( blender.pipeline.AVALON_PROPERTY) container_metadata["libpath"] = libpath @@ -375,6 +375,9 @@ class UnrealLayoutLoader(plugin.AssetLoader): all_loaders = api.discover(api.Loader) + avalon_container = bpy.data.collections.get( + blender.pipeline.AVALON_CONTAINERS) + for element in data: reference = element.get('reference') family = element.get('family') @@ -396,6 +399,9 @@ class UnrealLayoutLoader(plugin.AssetLoader): if not element_container: continue + avalon_container.children.unlink(element_container) + layout_container.children.link(element_container) + element_metadata = element_container.get( blender.pipeline.AVALON_PROPERTY) @@ -426,7 +432,7 @@ class UnrealLayoutLoader(plugin.AssetLoader): # Save the list of objects in the metadata container container_metadata["objects"] = layout_collection.all_objects - nodes = [container] + nodes = [layout_container] self[:] = nodes return nodes