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

Checking existing uasset data during setting version after the load #180

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
43 changes: 34 additions & 9 deletions client/ayon_unreal/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,15 +713,6 @@ def replace_static_mesh_actors(old_assets, new_assets, selected):
new_assets,
selected
)
unreal.log("static_mesh_comps")
unreal.log(static_mesh_comps)

unreal.log("old_meshes")
unreal.log(old_meshes)

unreal.log("new_meshes")
unreal.log(old_meshes)


for old_name, old_mesh in old_meshes.items():
new_mesh = new_meshes.get(old_name)
Expand Down Expand Up @@ -1074,6 +1065,40 @@ def has_asset_directory_pattern_matched(asset_name, asset_dir, name, extension=N
return None


def get_target_content_plugin_path(name, extension):
"""Get target content plugin path

Args:
name (str): Product Name
extension (str): extension

Returns:
unreal.Path: the directory of the related asset
in the content plugin
"""
# Get the Asset Registry
asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()

# Get all assets
asset_list = asset_registry.get_all_assets()
game_assets = [
asset.package_path for asset
in asset_registry.get_assets_by_path('/Game', recursive=True)
]
pattern = rf"{name}_\d{{3}}"
if extension:
pattern = rf"{name}_v\d{{3}}_{extension}"
for package in asset_list:
asset_name = str(package.asset_name)
is_content_version_folder_matched = re.match(pattern, asset_name)
if is_content_version_folder_matched and (
package.package_path not in game_assets
):
unreal.log(f"asset_name: {asset_name}")
return unreal.Paths.split(package.package_path)[0]
return None


def get_top_hierarchy_folder(path):
"""Get top hierarchy of the path

Expand Down
5 changes: 1 addition & 4 deletions client/ayon_unreal/plugins/inventory/update_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ls,
replace_static_mesh_actors,
replace_skeletal_mesh_actors,
replace_geometry_cache_actors,
replace_geometry_cache_actors
)
from ayon_core.pipeline import InventoryAction

Expand Down Expand Up @@ -68,9 +68,6 @@ def update_assets(containers, selected):
sa_dir, recursive=True, include_folder=False
)

unreal.log("old_content")
unreal.log(old_content)

if container.get("family") == "rig":
replace_skeletal_mesh_actors(
old_content, asset_content, selected)
Expand Down
31 changes: 25 additions & 6 deletions client/ayon_unreal/plugins/load/load_alembic_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import os

from ayon_core.lib import EnumDef
from ayon_core.pipeline import (
get_representation_path,
AYON_CONTAINER_ID
)
from ayon_core.pipeline import AYON_CONTAINER_ID
from ayon_unreal.api import plugin
from ayon_unreal.api import pipeline as unreal_pipeline
import unreal # noqa
Expand Down Expand Up @@ -194,6 +191,10 @@ def load(self, context, name, namespace, options):
asset_path = unreal_pipeline.has_asset_directory_pattern_matched(
asset_name, asset_dir, folder_name, extension=ext)

content_plugin_path = unreal_pipeline.get_target_content_plugin_path(name, ext)
if content_plugin_path:
asset_dir = content_plugin_path

if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)

Expand Down Expand Up @@ -241,12 +242,14 @@ def load(self, context, name, namespace, options):

def update(self, container, context):
folder_path = context["folder"]["path"]
hierarchy = folder_path.lstrip("/").split("/")
folder_name = hierarchy.pop(-1)
product_type = context["product"]["productType"]
repre_entity = context["representation"]

# Create directory for folder and Ayon container
suffix = "_CON"
source_path = get_representation_path(repre_entity)
source_path = self.filepath_from_context(context)

ext = os.path.splitext(source_path)[-1].lstrip(".")
asset_root, asset_name = unreal_pipeline.format_asset_directory(context, self.loaded_asset_dir)
Expand All @@ -256,6 +259,13 @@ def update(self, container, context):
asset_root, suffix=f"_{ext}")

container_name += suffix
asset_path = unreal_pipeline.has_asset_directory_pattern_matched(
asset_name, asset_dir, folder_name, extension=ext)

content_plugin_path = unreal_pipeline.get_target_content_plugin_path(folder_name, ext)
if content_plugin_path:
asset_dir = content_plugin_path

if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
Expand All @@ -266,8 +276,14 @@ def update(self, container, context):

self.import_and_containerize(
source_path, asset_dir, asset_name,
container_name, loaded_options
container_name, loaded_options,
asset_path=asset_path
)
if asset_path:
unreal.EditorAssetLibrary.rename_asset(
f"{asset_path}",
f"{asset_dir}/{asset_name}.{asset_name}"
)

# update metadata
self.imprint(
Expand All @@ -288,6 +304,9 @@ def update(self, container, context):
for a in asset_content:
unreal.EditorAssetLibrary.save_asset(a)

unreal_pipeline.add_assets_to_content_plugin(
asset_name, ext, asset_content)

def remove(self, container):
path = container["namespace"]
if unreal.EditorAssetLibrary.does_directory_exist(path):
Expand Down
31 changes: 27 additions & 4 deletions client/ayon_unreal/plugins/load/load_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import os
import ayon_api
import unreal
from ayon_core.pipeline import (AYON_CONTAINER_ID, get_current_project_name,
get_representation_path, load_container,
from ayon_core.pipeline import (AYON_CONTAINER_ID,
get_current_project_name,
load_container,
discover_loader_plugins,
loaders_from_representation)
from ayon_core.pipeline.context_tools import get_current_folder_entity
Expand Down Expand Up @@ -415,6 +416,11 @@ def load(self, context, name, namespace, options):

container_name += suffix
asset_path = unreal_pipeline.has_asset_directory_pattern_matched(asset_name, asset_dir, name)

content_plugin_path = unreal_pipeline.get_target_content_plugin_path(name, ext)
if content_plugin_path:
asset_dir = content_plugin_path

if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
Expand Down Expand Up @@ -475,27 +481,44 @@ def update(self, container, context):
folder_entity = context["folder"]

suffix = "_CON"
source_path = get_representation_path(repre_entity)
source_path = self.filepath_from_context(context)
ext = os.path.splitext(source_path)[-1].lstrip(".")
asset_root, asset_name = unreal_pipeline.format_asset_directory(context, self.loaded_asset_dir)
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
asset_root, suffix=f"_{ext}")

container_name += suffix
asset_path = unreal_pipeline.has_asset_directory_pattern_matched(
asset_name, asset_dir, context["product"]["name"])

content_plugin_path = unreal_pipeline.get_target_content_plugin_path(
context["product"]["name"], ext
)
if content_plugin_path:
asset_dir = content_plugin_path

if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
EditorAssetLibrary.make_directory(asset_dir)

master_level = self._import_animation_with_json(
source_path, context, hierarchy,
asset_dir, folder_name, asset_name
asset_dir, folder_name, asset_name,
asset_path=asset_path
)
if not unreal.EditorAssetLibrary.does_asset_exist(
f"{asset_dir}/{container_name}"):
# Create Asset Container
unreal_pipeline.create_container(
container=container_name, path=asset_dir
)

if asset_path:
unreal.EditorAssetLibrary.rename_asset(
f"{asset_path}",
f"{asset_dir}/{asset_name}.{asset_name}"
)

# update metadata
self.imprint(
folder_path,
Expand Down
16 changes: 6 additions & 10 deletions client/ayon_unreal/plugins/load/load_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
EditorAssetLibrary,
EditorLevelLibrary
)
from ayon_core.pipeline import (
AYON_CONTAINER_ID,
get_representation_path,
)
from ayon_core.pipeline import AYON_CONTAINER_ID
from ayon_unreal.api import plugin
from ayon_unreal.api.pipeline import (
generate_master_level_sequence,
Expand Down Expand Up @@ -237,7 +234,6 @@ def load(self, context, name, namespace, options):

def update(self, container, context):
# Create directory for asset and Ayon container
repre_entity = context["representation"]
folder_entity = context["folder"]
folder_path = folder_entity["path"]
asset_root, asset_name = format_asset_directory(
Expand All @@ -253,11 +249,11 @@ def update(self, container, context):
master_level = None
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
EditorAssetLibrary.make_directory(asset_dir)
path = get_representation_path(repre_entity)
master_level = self._create_map_camera(
context, path, tools, hierarchy_dir,
master_dir_name, asset_dir, asset_name
)
path = self.filepath_from_context(context)
master_level = self._create_map_camera(
context, path, tools, hierarchy_dir,
master_dir_name, asset_dir, asset_name
)

# Create Asset Container
if not unreal.EditorAssetLibrary.does_asset_exist(
Expand Down
29 changes: 23 additions & 6 deletions client/ayon_unreal/plugins/load/load_geometrycache_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"""Loader for published alembics."""
import os

from ayon_core.pipeline import (
get_representation_path,
AYON_CONTAINER_ID
)
from ayon_core.pipeline import AYON_CONTAINER_ID
from ayon_core.lib import EnumDef
from ayon_unreal.api import plugin
from ayon_unreal.api.pipeline import (
create_container,
imprint,
has_asset_directory_pattern_matched,
format_asset_directory,
get_target_content_plugin_path,
UNREAL_VERSION
)

Expand Down Expand Up @@ -211,6 +209,11 @@ def load(self, context, name, namespace, options):
frame_end += 1
asset_path = has_asset_directory_pattern_matched(
asset_name, asset_dir, name, extension=ext)

content_plugin_path = get_target_content_plugin_path(name, ext)
if content_plugin_path:
asset_dir = content_plugin_path

if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
Expand Down Expand Up @@ -255,19 +258,27 @@ def update(self, container, context):
folder_path = context["folder"]["path"]
product_type = context["product"]["productType"]
repre_entity = context["representation"]
name = context["product"]["name"]
asset_dir = container["namespace"]
suffix = "_CON"
path = get_representation_path(repre_entity)
path = self.filepath_from_context(context)
ext = os.path.splitext(path)[-1].lstrip(".")
asset_root, asset_name = format_asset_directory(context, self.loaded_asset_dir)
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
asset_root, suffix=f"_{ext}")

container_name += suffix
asset_path = has_asset_directory_pattern_matched(
asset_name, asset_dir, name, extension=ext)

frame_start = int(container.get("frame_start"))
frame_end = int(container.get("frame_end"))

content_plugin_path = get_target_content_plugin_path(name, ext)
if content_plugin_path:
asset_dir = content_plugin_path

if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
Expand All @@ -276,8 +287,14 @@ def update(self, container, context):
}
self.import_and_containerize(
path, asset_dir, asset_name, container_name,
frame_start, frame_end, loaded_options)
frame_start, frame_end, loaded_options,
asset_path=asset_path)

if asset_path:
unreal.EditorAssetLibrary.rename_asset(
f"{asset_path}",
f"{asset_dir}/{asset_name}.{asset_name}"
)

self.imprint(
folder_path,
Expand Down
Loading
Loading