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 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5bf4a57
supports to check on the existing uasset when loading data during up-…
moonyuet Dec 16, 2024
f78de09
up-versioning work across different projects
moonyuet Dec 18, 2024
e7e98be
ensure the asset is being imported/hooked back to version folder
moonyuet Dec 18, 2024
ff86be4
remove unused variable
moonyuet Dec 18, 2024
97859c4
include the changes on the Plugins Folders
moonyuet Dec 19, 2024
f9d67b2
restore some codes for pipeline.py
moonyuet Dec 20, 2024
3ee6558
add functions for adding the asset to the content plugin
moonyuet Dec 20, 2024
7ec3e76
remove unused import
moonyuet Dec 20, 2024
fa6b030
add the migration of content plugin functionn into the asset loaders
moonyuet Dec 20, 2024
46180aa
use content plugin path as loading asset directories if there is one
moonyuet Dec 23, 2024
0f941dc
make sure the content loaded in the correct content plugin
moonyuet Dec 30, 2024
6a1abac
make sure the uasset and yeti loading into the correct directory of t…
moonyuet Dec 30, 2024
8a58a0b
Merge branch 'develop' into enhancement/enhancement/AY-6498_Check-for…
antirotor Jan 8, 2025
97e964e
Merge branch 'develop' into enhancement/enhancement/AY-6498_Check-for…
moonyuet Jan 9, 2025
a97f742
add debug message to inform users no content plugin found
moonyuet Jan 9, 2025
8275798
supports the settings of adding content plugin paths for loading the …
moonyuet Jan 10, 2025
4e36812
add check on the existence of the content plugin
moonyuet Jan 10, 2025
b022d0b
make sure the asset can be loaded into the content plugins correctly
moonyuet Jan 10, 2025
8d6316c
supports to removing assets from manual migration
moonyuet Jan 13, 2025
e22afba
fix the wrong variable for applying setting for image loader
moonyuet Jan 13, 2025
2aac9a0
ondrej's suggestion on how the asset loading works in content plugins…
moonyuet Jan 14, 2025
798a1b9
make sure the settings are correctly synced
moonyuet Jan 14, 2025
69c0ade
supports to import asset to either project-based or content-plugin-ba…
moonyuet Jan 15, 2025
587eb2a
remove unused import
moonyuet Jan 15, 2025
042f1f4
do not use the hard-coded name
moonyuet Jan 16, 2025
03d2322
include the content plugin name as imprinted data when the content pl…
moonyuet Jan 16, 2025
9b63764
refactoring the check on existing uasset data across game content and…
moonyuet Jan 17, 2025
52ce81e
add missing comma on the function
moonyuet Jan 17, 2025
2ca97a2
Merge branch 'develop' into enhancement/enhancement/AY-6498_Check-for…
antirotor Jan 17, 2025
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
80 changes: 64 additions & 16 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 @@ -846,13 +837,14 @@ def select_camera(sequence):
actor_subsys.set_actor_selection_state(actor, False)


def format_asset_directory(context, directory_template):
def format_asset_directory(context, directory_template,
use_content_plugin=False, content_plugin_name=""):
"""Setting up the asset directory path and name.
Args:
name (str): Instance name
context (dict): context
directory_template (str): directory template path
extension (str, optional): file extension. Defaults to "abc".
use_content_plugin (bool): whether content plugin is used for the asset directory
content_plugin_name (str, optional): content plugin name.
Returns:
tuple[str, str]: asset directory, asset name
"""
Expand Down Expand Up @@ -889,7 +881,11 @@ def format_asset_directory(context, directory_template):
data["version"]["version"] = f"v{version:03d}"
asset_name_with_version = set_asset_name(data)
asset_dir = StringTemplate(directory_template).format_strict(data)
return f"{AYON_ROOT_DIR}/{asset_dir}", asset_name_with_version
root_dir = AYON_ROOT_DIR
if use_content_plugin and content_plugin_name:
root_dir = root_dir.replace("Game", content_plugin_name)

return f"{root_dir}/{asset_dir}", asset_name_with_version


def set_asset_name(data):
Expand Down Expand Up @@ -1034,16 +1030,25 @@ def get_frame_range_from_folder_attributes(folder_entity=None):
return frame_start, frame_end


def has_asset_existing_directory(asset_name, asset_dir):
def has_asset_existing_directory(asset_name, asset_dir,
use_content_plugin, content_plugin_name):
"""Check if the asset already existed
Args:
asset_name (str): asset name
asset_dir (str): asset directory
use_content_plugin (bool): whether content plugin is used
content_plugin_name (str): name of the content plugin

Returns:
str: package path
"""
asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
all_assets = asset_registry.get_assets_by_path('/Game', recursive=True)
if use_content_plugin and content_plugin_name:
content_plugin_asset = asset_registry.get_assets_by_path(
f'/{content_plugin_name}', recursive=True)
all_assets.extend(content_plugin_asset)

for game_asset in all_assets:
if game_asset.asset_name == asset_name:
asset_path = game_asset.get_asset().get_path_name()
Expand All @@ -1054,10 +1059,13 @@ def has_asset_existing_directory(asset_name, asset_dir):
return asset_path
return None

def has_asset_directory_pattern_matched(asset_name, asset_dir, name, extension=None):
def has_asset_directory_pattern_matched(asset_name, asset_dir, name, extension=None,
use_content_plugin=False, content_plugin_name=""):
version_folder = asset_dir.split("/")[-1]
target_asset_dir = asset_dir.replace(version_folder, "")
asset_path = has_asset_existing_directory(asset_name, target_asset_dir)
asset_path = has_asset_existing_directory(
asset_name, target_asset_dir, use_content_plugin, content_plugin_name
)
if not asset_path:
return None
existing_asset_dir = unreal.Paths.split(asset_path)[0]
Expand All @@ -1074,6 +1082,25 @@ def has_asset_directory_pattern_matched(asset_name, asset_dir, name, extension=N
return None


def has_content_plugin_path(content_plugin_name):
"""Search if the content plugin from the ayon settings exist in
the Unreal project

Args:
content_plugin_name (str): Content plugin name

Returns:
str: content plugin name
"""
asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()

# Get all assets
asset_list = asset_registry.get_all_assets()
for package in asset_list:
if unreal.Paths.split(package.package_path)[0].startswith(f"/{content_plugin_name}"):
return content_plugin_name


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

Expand Down Expand Up @@ -1250,3 +1277,24 @@ def add_track(sequence, track):
return sequence.add_track(track)
else:
return sequence.add_master_track(track)


def remove_asset_from_content_plugin(container):
"""Remove the AYON-loaded asset from content plugin
(Only valid when users manually migrates the asset)

Args:
container (dict): container data
"""
path = container["namespace"]
content_plugin_path = container.get("content_plugin_path", "")
if content_plugin_path:
path = path.replace(AYON_ROOT_DIR, f"/{content_plugin_path}/Ayon")
if unreal.EditorAssetLibrary.does_directory_exist(path):
container_name = container["container_name"]
container_path = f"{path}/{container_name}"
if unreal.EditorAssetLibrary.does_asset_exist(container_path):
container = unreal.EditorAssetLibrary.load_asset(container_path)
data = unreal.EditorAssetLibrary.get_metadata_tag_values(container)
if data["namespace"] == container["namespace"]:
unreal.EditorAssetLibrary.delete_directory(path)
37 changes: 31 additions & 6 deletions client/ayon_unreal/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from .lib import remove_loaded_asset
from ayon_core.lib import (
BoolDef,
UILabelDef
UILabelDef,
EnumDef
)
from ayon_core.pipeline import (
AutoCreator,
Expand Down Expand Up @@ -300,6 +301,26 @@ class LayoutLoader(Loader):
color = "orange"
loaded_layout_dir = "{folder[path]}/{product[name]}"
remove_loaded_assets = False
content_plugin_enabled = False
content_plugin_path = []

@classmethod
def get_options(cls, contexts):
default_content_plugin = next(
(path for path in cls.content_plugin_path), "")
return [
BoolDef(
"content_plugin_enabled",
label="Content Plugin",
default=cls.content_plugin_enabled
),
EnumDef(
"content_plugin_name",
label="Content Plugin Name",
items=[path for path in cls.content_plugin_path],
default=default_content_plugin
)
]

@staticmethod
def _get_fbx_loader(loaders, family):
Expand Down Expand Up @@ -413,7 +434,8 @@ def imprint(
asset_name,
container_name,
project_name,
hierarchy_dir=None
hierarchy_dir=None,
content_plugin_name=None
):
data = {
"schema": "ayon:container-2.0",
Expand All @@ -432,10 +454,12 @@ def imprint(
}
if hierarchy_dir is not None:
data["master_directory"] = hierarchy_dir
if content_plugin_name:
data["content_plugin_name"] = content_plugin_name
imprint(
"{}/{}".format(asset_dir, container_name), data)

def _load_assets(self, instance_name, repre_id, product_type, repr_format):
def _load_assets(self, instance_name, repre_id, product_type, repr_format, options):
all_loaders = discover_loader_plugins()
loaders = loaders_from_representation(
all_loaders, repre_id)
Expand All @@ -461,15 +485,16 @@ def _load_assets(self, instance_name, repre_id, product_type, repr_format):
f"{product_type}")
return

options = {
# "asset_dir": asset_dir
import_options = {
"content_plugin_enabled": options["content_plugin_enabled"],
"content_plugin_name": options.get("content_plugin_name", "")
}

assets = load_container(
loader,
repre_id,
namespace=instance_name,
options=options
options=import_options
)
return assets

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
Loading
Loading