Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add loaded asset extensions settings for layout loaders in unreal host #44

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions client/ayon_unreal/plugins/load/load_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
imprint,
ls,
)
from ayon_core.lib import EnumDef


class LayoutLoader(plugin.Loader):
Expand All @@ -47,6 +48,32 @@ class LayoutLoader(plugin.Loader):
icon = "code-fork"
color = "orange"
ASSET_ROOT = "/Game/Ayon"
loaded_assets_extension = "fbx"

@classmethod
def apply_settings(cls, project_settings):
super(LayoutLoader, cls).apply_settings(project_settings)

# Apply import settings
loaded_assets_extension = (
project_settings.get("unreal", {}).get("loaded_assets_extension", {})
)
if loaded_assets_extension:
cls.loaded_assets_extension = loaded_assets_extension

@classmethod
def get_options(cls, contexts):
return [
EnumDef(
"loaded_assets_extension",
label="Loaded Assets Extension",
items={
"fbx": "fbx",
"abc": "abc"
},
default=cls.loaded_assets_extension
)
]

def _get_asset_containers(self, path):
ar = unreal.AssetRegistryHelpers.get_asset_registry()
Expand Down Expand Up @@ -296,7 +323,7 @@ def _import_animation(
sec_params = section.get_editor_property('params')
sec_params.set_editor_property('animation', animation)

def _get_repre_entities_by_version_id(self, data):
def _get_repre_entities_by_version_id(self, data, repre_extension):
version_ids = {
element.get("version")
for element in data
Expand All @@ -311,7 +338,7 @@ def _get_repre_entities_by_version_id(self, data):
project_name = get_current_project_name()
repre_entities = ayon_api.get_representations(
project_name,
representation_names={"fbx", "abc"},
representation_names={repre_extension},
version_ids=version_ids,
fields={"id", "versionId", "name"}
)
Expand All @@ -320,7 +347,8 @@ def _get_repre_entities_by_version_id(self, data):
output[version_id].append(repre_entity)
return output

def _process(self, lib_path, asset_dir, sequence, repr_loaded=None):
def _process(self, lib_path, asset_dir, sequence,
repr_loaded=None, loaded_extension=None):
ar = unreal.AssetRegistryHelpers.get_asset_registry()

with open(lib_path, "r") as fp:
Expand All @@ -340,7 +368,7 @@ def _process(self, lib_path, asset_dir, sequence, repr_loaded=None):
loaded_assets = []

repre_entities_by_version_id = self._get_repre_entities_by_version_id(
data
data, loaded_extension
)
for element in data:
repre_id = None
Expand Down Expand Up @@ -644,9 +672,11 @@ def load(self, context, name, namespace, options):
[level])

EditorLevelLibrary.load_level(level)

extension = options.get(
"loaded_assets_extension", self.loaded_assets_extension)
path = self.filepath_from_context(context)
loaded_assets = self._process(path, asset_dir, shot)
loaded_assets = self._process(
path, asset_dir, shot, loaded_extension=extension)

for s in sequences:
EditorAssetLibrary.save_asset(s.get_path_name())
Expand Down Expand Up @@ -759,7 +789,9 @@ def update(self, container, context):

source_path = get_representation_path(repre_entity)

loaded_assets = self._process(source_path, asset_dir, sequence)
loaded_assets = self._process(
source_path, asset_dir, sequence,
loaded_extension=self.loaded_assets_extension)

data = {
"representation": repre_entity["id"],
Expand Down
15 changes: 14 additions & 1 deletion server/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ayon_server.settings import BaseSettingsModel, SettingsField

from .imageio import UnrealImageIOModel


Expand All @@ -19,6 +18,13 @@ def _render_format_enum():
]


def _loaded_asset_enum():
return [
{"value": "fbx", "label": "fbx"},
{"value": "abc", "label": "abc"}
]


class UnrealSettings(BaseSettingsModel):
imageio: UnrealImageIOModel = SettingsField(
default_factory=UnrealImageIOModel,
Expand All @@ -32,6 +38,12 @@ class UnrealSettings(BaseSettingsModel):
False,
title="Delete assets that are not matched"
)
loaded_assets_extension: str = SettingsField(
"fbx",
title="Loaded Assets Extension",
enum_resolver=_loaded_asset_enum,
description="Extension for the loaded assets"
)
render_queue_path: str = SettingsField(
"",
title="Render Queue Path",
Expand Down Expand Up @@ -60,6 +72,7 @@ class UnrealSettings(BaseSettingsModel):
DEFAULT_VALUES = {
"level_sequences_for_layouts": True,
"delete_unmatched_assets": False,
"loaded_assets_extension": "fbx",
"render_queue_path": "/Game/Ayon/renderQueue",
"render_config_path": "/Game/Ayon/DefaultMovieRenderQueueConfig.DefaultMovieRenderQueueConfig",
"preroll_frames": 0,
Expand Down