Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

General: Move loader logic from avalon to openpype #2886

Merged
13 changes: 9 additions & 4 deletions openpype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def install():
"""Install Pype to Avalon."""
from pyblish.lib import MessageHandler
from openpype.modules import load_modules
from openpype.pipeline import LegacyCreator
from openpype.pipeline import (
LegacyCreator,
register_loader_plugins_path,
)
from avalon import pipeline

# Make sure modules are loaded
Expand All @@ -91,7 +94,7 @@ def modified_emit(obj, record):
log.info("Registering global plug-ins..")
pyblish.register_plugin_path(PUBLISH_PATH)
pyblish.register_discovery_filter(filter_pyblish_plugins)
avalon.register_plugin_path(avalon.Loader, LOAD_PATH)
register_loader_plugins_path(LOAD_PATH)

project_name = os.environ.get("AVALON_PROJECT")

Expand Down Expand Up @@ -119,7 +122,7 @@ def modified_emit(obj, record):
continue

pyblish.register_plugin_path(path)
avalon.register_plugin_path(avalon.Loader, path)
register_loader_plugins_path(path)
avalon.register_plugin_path(LegacyCreator, path)
avalon.register_plugin_path(avalon.InventoryAction, path)

Expand All @@ -139,10 +142,12 @@ def _on_task_change():
@import_wrapper
def uninstall():
"""Uninstall Pype from Avalon."""
from openpype.pipeline import deregister_loader_plugins_path

log.info("Deregistering global plug-ins..")
pyblish.deregister_plugin_path(PUBLISH_PATH)
pyblish.deregister_discovery_filter(filter_pyblish_plugins)
avalon.deregister_plugin_path(avalon.Loader, LOAD_PATH)
deregister_loader_plugins_path(LOAD_PATH)
log.info("Global plug-ins unregistred")

# restore original discover
Expand Down
10 changes: 7 additions & 3 deletions openpype/hosts/aftereffects/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

from openpype import lib
from openpype.api import Logger
from openpype.pipeline import LegacyCreator
from openpype.pipeline import (
LegacyCreator,
register_loader_plugins_path,
deregister_loader_plugins_path,
)
import openpype.hosts.aftereffects
from openpype.lib import register_event_callback

Expand Down Expand Up @@ -67,7 +71,7 @@ def install():
pyblish.api.register_host("aftereffects")
pyblish.api.register_plugin_path(PUBLISH_PATH)

avalon.api.register_plugin_path(avalon.api.Loader, LOAD_PATH)
register_loader_plugins_path(LOAD_PATH)
avalon.api.register_plugin_path(LegacyCreator, CREATE_PATH)
log.info(PUBLISH_PATH)

Expand All @@ -80,7 +84,7 @@ def install():

def uninstall():
pyblish.api.deregister_plugin_path(PUBLISH_PATH)
avalon.api.deregister_plugin_path(avalon.api.Loader, LOAD_PATH)
deregister_loader_plugins_path(LOAD_PATH)
avalon.api.deregister_plugin_path(LegacyCreator, CREATE_PATH)


Expand Down
5 changes: 2 additions & 3 deletions openpype/hosts/aftereffects/api/plugin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import avalon.api
from openpype.pipeline import LoaderPlugin
from .launch_logic import get_stub


class AfterEffectsLoader(avalon.api.Loader):
class AfterEffectsLoader(LoaderPlugin):
@staticmethod
def get_stub():
return get_stub()

5 changes: 2 additions & 3 deletions openpype/hosts/aftereffects/plugins/load/load_background.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import re

import avalon.api

from openpype.lib import (
get_background_layers,
get_unique_layer_name
)
from openpype.pipeline import get_representation_path
from openpype.hosts.aftereffects.api import (
AfterEffectsLoader,
containerise
Expand Down Expand Up @@ -78,7 +77,7 @@ def update(self, container, representation):
else: # switching version - keep same name
comp_name = container["namespace"]

path = avalon.api.get_representation_path(representation)
path = get_representation_path(representation)

layers = get_background_layers(path)
comp = stub.reload_background(container["members"][1],
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/aftereffects/plugins/load/load_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re

import avalon.api
from openpype import lib

from openpype.pipeline import get_representation_path
from openpype.hosts.aftereffects.api import (
AfterEffectsLoader,
containerise
Expand Down Expand Up @@ -92,7 +92,7 @@ def update(self, container, representation):
"{}_{}".format(context["asset"], context["subset"]))
else: # switching version - keep same name
layer_name = container["namespace"]
path = avalon.api.get_representation_path(representation)
path = get_representation_path(representation)
# with aftereffects.maintained_selection(): # TODO
stub.replace_item(layer.id, path, stub.LOADED_ICON + layer_name)
stub.imprint(
Expand Down
10 changes: 7 additions & 3 deletions openpype/hosts/blender/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
from avalon import io, schema
from avalon.pipeline import AVALON_CONTAINER_ID

from openpype.pipeline import LegacyCreator
from openpype.pipeline import (
LegacyCreator,
register_loader_plugins_path,
deregister_loader_plugins_path,
)
from openpype.api import Logger
from openpype.lib import (
register_event_callback,
Expand Down Expand Up @@ -50,7 +54,7 @@ def install():
pyblish.api.register_host("blender")
pyblish.api.register_plugin_path(str(PUBLISH_PATH))

avalon.api.register_plugin_path(avalon.api.Loader, str(LOAD_PATH))
register_loader_plugins_path(str(LOAD_PATH))
avalon.api.register_plugin_path(LegacyCreator, str(CREATE_PATH))

lib.append_user_scripts()
Expand All @@ -72,7 +76,7 @@ def uninstall():
pyblish.api.deregister_host("blender")
pyblish.api.deregister_plugin_path(str(PUBLISH_PATH))

avalon.api.deregister_plugin_path(avalon.api.Loader, str(LOAD_PATH))
deregister_loader_plugins_path(str(LOAD_PATH))
avalon.api.deregister_plugin_path(LegacyCreator, str(CREATE_PATH))

if not IS_HEADLESS:
Expand Down
10 changes: 6 additions & 4 deletions openpype/hosts/blender/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import bpy

import avalon.api
from openpype.pipeline import LegacyCreator
from openpype.pipeline import (
LegacyCreator,
LoaderPlugin,
)
from .pipeline import AVALON_CONTAINERS
from .ops import (
MainThreadItem,
Expand Down Expand Up @@ -145,13 +147,13 @@ def process(self):
return collection


class Loader(avalon.api.Loader):
class Loader(LoaderPlugin):
"""Base class for Loader plug-ins."""

hosts = ["blender"]


class AssetLoader(avalon.api.Loader):
class AssetLoader(LoaderPlugin):
"""A basic AssetLoader for Blender

This will implement the basic logic for linking/appending assets
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import bpy

from avalon import api
from openpype.pipeline import get_representation_path
from openpype.hosts.blender.api.pipeline import (
AVALON_CONTAINERS,
AVALON_PROPERTY,
Expand Down Expand Up @@ -178,7 +178,7 @@ def exec_update(self, container: Dict, representation: Dict):
"""
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(api.get_representation_path(representation))
libpath = Path(get_representation_path(representation))
extension = libpath.suffix.lower()

self.log.info(
Expand Down
35 changes: 18 additions & 17 deletions openpype/hosts/blender/plugins/load/load_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
from pprint import pformat
from typing import Dict, List, Optional

from avalon import api, blender
import bpy
from openpype.pipeline import get_representation_path
import openpype.hosts.blender.api.plugin
from openpype.hosts.blender.api.pipeline import (
containerise_existing,
AVALON_PROPERTY,
)

logger = logging.getLogger("openpype").getChild("blender").getChild("load_action")

Expand Down Expand Up @@ -49,16 +53,15 @@ def process_asset(

container = bpy.data.collections.new(lib_container)
container.name = container_name
blender.pipeline.containerise_existing(
containerise_existing(
container,
name,
namespace,
context,
self.__class__.__name__,
)

container_metadata = container.get(
blender.pipeline.AVALON_PROPERTY)
container_metadata = container.get(AVALON_PROPERTY)

container_metadata["libpath"] = libpath
container_metadata["lib_container"] = lib_container
Expand Down Expand Up @@ -90,16 +93,16 @@ def process_asset(

anim_data.action.make_local()

if not obj.get(blender.pipeline.AVALON_PROPERTY):
if not obj.get(AVALON_PROPERTY):

obj[blender.pipeline.AVALON_PROPERTY] = dict()
obj[AVALON_PROPERTY] = dict()

avalon_info = obj[blender.pipeline.AVALON_PROPERTY]
avalon_info = obj[AVALON_PROPERTY]
avalon_info.update({"container_name": container_name})

objects_list.append(obj)

animation_container.pop(blender.pipeline.AVALON_PROPERTY)
animation_container.pop(AVALON_PROPERTY)

# Save the list of objects in the metadata container
container_metadata["objects"] = objects_list
Expand Down Expand Up @@ -128,7 +131,7 @@ def update(self, container: Dict, representation: Dict):
container["objectName"]
)

libpath = Path(api.get_representation_path(representation))
libpath = Path(get_representation_path(representation))
extension = libpath.suffix.lower()

logger.info(
Expand All @@ -153,8 +156,7 @@ def update(self, container: Dict, representation: Dict):
f"Unsupported file: {libpath}"
)

collection_metadata = collection.get(
blender.pipeline.AVALON_PROPERTY)
collection_metadata = collection.get(AVALON_PROPERTY)

collection_libpath = collection_metadata["libpath"]
normalized_collection_libpath = (
Expand Down Expand Up @@ -225,16 +227,16 @@ def update(self, container: Dict, representation: Dict):
strip.action = anim_data.action
strip.action_frame_end = anim_data.action.frame_range[1]

if not obj.get(blender.pipeline.AVALON_PROPERTY):
if not obj.get(AVALON_PROPERTY):

obj[blender.pipeline.AVALON_PROPERTY] = dict()
obj[AVALON_PROPERTY] = dict()

avalon_info = obj[blender.pipeline.AVALON_PROPERTY]
avalon_info = obj[AVALON_PROPERTY]
avalon_info.update({"container_name": collection.name})

objects_list.append(obj)

anim_container.pop(blender.pipeline.AVALON_PROPERTY)
anim_container.pop(AVALON_PROPERTY)

# Save the list of objects in the metadata container
collection_metadata["objects"] = objects_list
Expand Down Expand Up @@ -266,8 +268,7 @@ def remove(self, container: Dict) -> bool:
"Nested collections are not supported."
)

collection_metadata = collection.get(
blender.pipeline.AVALON_PROPERTY)
collection_metadata = collection.get(AVALON_PROPERTY)
objects = collection_metadata["objects"]
lib_container = collection_metadata["lib_container"]

Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import bpy

from avalon import api
from openpype.pipeline import get_representation_path
from openpype.hosts.blender.api import plugin
from openpype.hosts.blender.api.pipeline import (
AVALON_CONTAINERS,
Expand Down Expand Up @@ -102,7 +102,7 @@ def exec_update(self, container: Dict, representation: Dict):
"""
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(api.get_representation_path(representation))
libpath = Path(get_representation_path(representation))

self.log.info(
"Container: %s\nRepresentation: %s",
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_camera_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import bpy

from avalon import api
from openpype.pipeline import get_representation_path
from openpype.hosts.blender.api import plugin
from openpype.hosts.blender.api.pipeline import (
AVALON_CONTAINERS,
Expand Down Expand Up @@ -155,7 +155,7 @@ def exec_update(self, container: Dict, representation: Dict):
"""
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(api.get_representation_path(representation))
libpath = Path(get_representation_path(representation))
extension = libpath.suffix.lower()

self.log.info(
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_camera_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import bpy

from avalon import api
from openpype.pipeline import get_representation_path
from openpype.hosts.blender.api import plugin, lib
from openpype.hosts.blender.api.pipeline import (
AVALON_CONTAINERS,
Expand Down Expand Up @@ -143,7 +143,7 @@ def exec_update(self, container: Dict, representation: Dict):
"""
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(api.get_representation_path(representation))
libpath = Path(get_representation_path(representation))
extension = libpath.suffix.lower()

self.log.info(
Expand Down
4 changes: 2 additions & 2 deletions openpype/hosts/blender/plugins/load/load_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import bpy

from avalon import api
from openpype.pipeline import get_representation_path
from openpype.hosts.blender.api import plugin, lib
from openpype.hosts.blender.api.pipeline import (
AVALON_CONTAINERS,
Expand Down Expand Up @@ -187,7 +187,7 @@ def exec_update(self, container: Dict, representation: Dict):
"""
object_name = container["objectName"]
asset_group = bpy.data.objects.get(object_name)
libpath = Path(api.get_representation_path(representation))
libpath = Path(get_representation_path(representation))
extension = libpath.suffix.lower()

self.log.info(
Expand Down
Loading