Skip to content

Commit

Permalink
supports to check on the existing uasset when loading data during up-…
Browse files Browse the repository at this point in the history
…versioning or setting version
  • Loading branch information
moonyuet committed Dec 16, 2024
1 parent 210f984 commit 5bf4a57
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 16 deletions.
12 changes: 11 additions & 1 deletion client/ayon_unreal/plugins/load/load_alembic_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ 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"]

Expand All @@ -256,6 +258,8 @@ 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)
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
Expand All @@ -266,8 +270,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 Down
12 changes: 11 additions & 1 deletion client/ayon_unreal/plugins/load/load_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,29 @@ 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, context["product"]["name"])
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
11 changes: 10 additions & 1 deletion client/ayon_unreal/plugins/load/load_geometrycache_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ 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)
Expand All @@ -265,6 +266,8 @@ def update(self, container, context):
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"))
Expand All @@ -276,8 +279,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
14 changes: 13 additions & 1 deletion client/ayon_unreal/plugins/load/load_image_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def update(self, container, context):
folder_path = context["folder"]["path"]
product_type = context["product"]["productType"]
repre_entity = context["representation"]
name = context["product"]["name"]
path = get_representation_path(repre_entity)
ext = os.path.splitext(path)[-1].lstrip(".")

Expand All @@ -228,10 +229,21 @@ def update(self, container, context):
asset_root, suffix=f"_{ext}")

container_name += suffix
asset_path = (
has_asset_directory_pattern_matched(asset_name, asset_dir, name, extension=ext)
if not self.use_interchange else None
)
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)

self.import_and_containerize(path, asset_dir, asset_name, container_name)
self.import_and_containerize(
path, asset_dir, asset_name, container_name, 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
12 changes: 11 additions & 1 deletion client/ayon_unreal/plugins/load/load_skeletalmesh_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def update(self, container, context):
folder_path = context["folder"]["path"]
product_type = context["product"]["productType"]
repre_entity = context["representation"]
name = context["product"]["name"]

# Create directory for folder and Ayon container
suffix = "_CON"
Expand All @@ -270,6 +271,9 @@ def update(self, container, context):
asset_root, suffix=f"_{ext}")

container_name += suffix

asset_path = has_asset_directory_pattern_matched(
asset_name, asset_dir, name, extension=ext)
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
Expand All @@ -279,7 +283,13 @@ def update(self, container, context):
"frameEnd": container.get("frameEnd", 1)
}
self.import_and_containerize(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}"
)

self.imprint(
folder_path,
Expand Down
11 changes: 10 additions & 1 deletion client/ayon_unreal/plugins/load/load_skeletalmesh_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def update(self, container, context):
folder_path = context["folder"]["path"]
product_type = context["product"]["productType"]
repre_entity = context["representation"]
name = context["product"]["name"]

# Create directory for asset and Ayon container
suffix = "_CON"
Expand All @@ -199,9 +200,17 @@ def update(self, container, context):
asset_root, suffix=f"_{ext}")

container_name += suffix
asset_path = has_asset_directory_pattern_matched(
asset_name, asset_dir, name, extension=ext)
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
self.import_and_containerize(path, asset_dir, asset_name, container_name)
self.import_and_containerize(
path, asset_dir, asset_name, container_name, 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
12 changes: 10 additions & 2 deletions client/ayon_unreal/plugins/load/load_staticmesh_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def update(self, container, context):
folder_path = context["folder"]["path"]
product_type = context["product"]["productType"]
repre_entity = context["representation"]
name = context["product"]["name"]

# Create directory for asset and Ayon container
suffix = "_CON"
Expand All @@ -267,15 +268,22 @@ def update(self, container, context):
asset_root, suffix=f"_{ext}")

container_name += suffix
asset_path = has_asset_directory_pattern_matched(
asset_name, asset_dir, name, extension=ext)
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
loaded_options = {
"default_conversion": False,
"abc_conversion_preset": self.abc_conversion_preset
}
self.import_and_containerize(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}"
)
self.imprint(
folder_path,
asset_dir,
Expand Down
12 changes: 11 additions & 1 deletion client/ayon_unreal/plugins/load/load_staticmesh_fbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def update(self, container, context):
folder_path = context["folder"]["path"]
product_type = context["product"]["productType"]
repre_entity = context["representation"]
name = context["product"]["name"]

# Create directory for asset and Ayon container
suffix = "_CON"
Expand All @@ -230,10 +231,19 @@ def update(self, container, context):


container_name += suffix
asset_path = (
has_asset_directory_pattern_matched(asset_name, asset_dir, name, extension=ext)
if not self.use_interchange else None
)
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
unreal.EditorAssetLibrary.make_directory(asset_dir)
self.import_and_containerize(path, asset_dir, asset_name,
container_name)
container_name, 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
12 changes: 11 additions & 1 deletion client/ayon_unreal/plugins/load/load_uasset.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def update(self, container, context):

asset_dir = container["namespace"]
repre_entity = context["representation"]
name = context["product"]["name"]

destination_path = asset_dir.replace(
"/Game", Path(unreal.Paths.project_content_dir()).as_posix(), 1)
Expand All @@ -137,19 +138,28 @@ def update(self, container, context):

update_filepath = get_representation_path(repre_entity)
new_asset_name = os.path.basename(update_filepath)
asset_path = unreal_pipeline.has_asset_directory_pattern_matched(
new_asset_name, asset_dir, name)
if asset_path:
destination_path = unreal.Paths.split(asset_path)[0]
shutil.copy(update_filepath, f"{destination_path}/{new_asset_name}")

container_path = f'{container["namespace"]}/{container["objectName"]}'
# update metadata
unreal_pipeline.imprint(
container_path,
{
"asset_name": new_asset_name,
"representation": repre_entity["id"],
"parent": repre_entity["versionId"],
"project_name": context["project"]["name"]
}
)

if asset_path:
unreal.EditorAssetLibrary.rename_asset(
f"{asset_path}",
f"{asset_dir}/{new_asset_name}.{new_asset_name}"
)
asset_content = unreal.EditorAssetLibrary.list_assets(
asset_dir, recursive=True, include_folder=True
)
Expand Down
21 changes: 15 additions & 6 deletions client/ayon_unreal/plugins/load/load_yeticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def load(self, context, name, namespace, options):
loaded_asset_dir = unreal.Paths.split(asset_path)[0]
task = self.get_task(path, loaded_asset_dir, asset_name, True)
else:
if not unreal.EditorAssetLibrary.does_asset_exist(
f"{asset_dir}/{asset_name}"):
task = self.get_task(path, asset_dir, asset_name, False)
task = self.get_task(path, asset_dir, asset_name, False)

unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task]) # noqa: E501

Expand Down Expand Up @@ -163,11 +161,18 @@ def load(self, context, name, namespace, options):

def update(self, container, context):
repre_entity = context["representation"]
name = container["asset_name"]
asset_name = container["asset_name"]
source_path = get_representation_path(repre_entity)
destination_path = container["namespace"]
asset_path = unreal_pipeline.has_asset_directory_pattern_matched(
asset_name, destination_path, context["product"]["name"])
task = None
if asset_path:
loaded_asset_dir = unreal.Paths.split(asset_path)[0]
task = self.get_task(source_path, loaded_asset_dir, asset_name, True)
else:
task = self.get_task(source_path, destination_path, asset_name, False)

task = self.get_task(source_path, destination_path, name, False)

# do import fbx and replace existing data
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
Expand All @@ -182,7 +187,11 @@ def update(self, container, context):
"project_name": context["project"]["name"]
}
)

if asset_path:
unreal.EditorAssetLibrary.rename_asset(
f"{asset_path}",
f"{destination_path}/{asset_name}.{asset_name}"
)
asset_content = unreal.EditorAssetLibrary.list_assets(
destination_path, recursive=True, include_folder=True
)
Expand Down

0 comments on commit 5bf4a57

Please sign in to comment.