unreal load plugins are expecting representation context

This commit is contained in:
Jakub Trllo 2024-02-26 17:52:45 +01:00
parent 4ddfc7e00c
commit 54a71203ef
12 changed files with 142 additions and 102 deletions

View file

@ -126,12 +126,15 @@ class AnimationAlembicLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
name = container["asset_name"]
source_path = get_representation_path(representation)
def update(self, container, context):
folder_name = container["asset_name"]
repre_doc = context["representation"]
source_path = get_representation_path(repre_doc)
destination_path = container["namespace"]
task = self.get_task(source_path, destination_path, name, True)
task = self.get_task(
source_path, destination_path, folder_name, True
)
# do import fbx and replace existing data
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
@ -143,8 +146,8 @@ class AnimationAlembicLoader(plugin.Loader):
unreal_pipeline.imprint(
container_path,
{
"representation": str(representation["_id"]),
"parent": str(representation["parent"])
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"])
})
asset_content = unreal.EditorAssetLibrary.list_assets(

View file

@ -246,9 +246,10 @@ class AnimationFBXLoader(plugin.Loader):
unreal.EditorLevelLibrary.save_current_level()
unreal.EditorLevelLibrary.load_level(master_level)
def update(self, container, representation):
name = container["asset_name"]
source_path = get_representation_path(representation)
def update(self, container, context):
repre_doc = context["representation"]
folder_name = container["asset_name"]
source_path = get_representation_path(repre_doc)
asset_doc = get_current_project_asset(fields=["data.fps"])
destination_path = container["namespace"]
@ -258,7 +259,7 @@ class AnimationFBXLoader(plugin.Loader):
task.set_editor_property('filename', source_path)
task.set_editor_property('destination_path', destination_path)
# strip suffix
task.set_editor_property('destination_name', name)
task.set_editor_property('destination_name', folder_name)
task.set_editor_property('replace_existing', True)
task.set_editor_property('automated', True)
task.set_editor_property('save', True)
@ -305,8 +306,8 @@ class AnimationFBXLoader(plugin.Loader):
unreal_pipeline.imprint(
container_path,
{
"representation": str(representation["_id"]),
"parent": str(representation["parent"])
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"])
})
asset_content = EditorAssetLibrary.list_assets(

View file

@ -260,7 +260,7 @@ class CameraLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
def update(self, container, context):
ar = unreal.AssetRegistryHelpers.get_asset_registry()
curr_level_sequence = LevelSequenceLib.get_current_level_sequence()
@ -379,12 +379,13 @@ class CameraLoader(plugin.Loader):
sub_scene.set_sequence(new_sequence)
repre_doc = context["representation"]
self._import_camera(
EditorLevelLibrary.get_editor_world(),
new_sequence,
new_sequence.get_bindings(),
settings,
str(representation["data"]["path"])
str(repre_doc["data"]["path"])
)
# Set range of all sections
@ -412,8 +413,8 @@ class CameraLoader(plugin.Loader):
key.set_time(unreal.FrameNumber(value=new_time))
data = {
"representation": str(representation["_id"]),
"parent": str(representation["parent"])
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"])
}
imprint(f"{asset_dir}/{container.get('container_name')}", data)

View file

@ -108,7 +108,7 @@ class PointCacheAlembicLoader(plugin.Loader):
Args:
context (dict): application context
name (str): subset name
name (str): Product name
namespace (str): in Unreal this is basically path to container.
This is not passed here, so namespace is set
by `containerise()` because only then we know
@ -163,25 +163,30 @@ class PointCacheAlembicLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
context = representation.get("context", {})
unreal.log_warning(context)
if not context:
raise RuntimeError("No context found in representation")
def update(self, container, context):
asset_doc = context["asset"]
subset_doc = context["subset"]
version_doc = context["version"]
repre_doc = context["representation"]
# Create directory for asset and Ayon container
asset = context.get('asset')
name = context.get('subset')
folder_name = asset_doc["name"]
product_name = subset_doc["name"]
suffix = "_CON"
asset_name = f"{asset}_{name}" if asset else f"{name}"
version = context.get('version')
asset_name = product_name
if folder_name:
asset_name = f"{folder_name}_{product_name}"
# Check if version is hero version and use different name
name_version = f"{name}_v{version:03d}" if version else f"{name}_hero"
version = version_doc.get("name", -1)
if version < 0:
name_version = f"{product_name}_hero"
else:
name_version = f"{product_name}_v{version:03d}"
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
f"{self.root}/{asset}/{name_version}", suffix="")
f"{self.root}/{folder_name}/{name_version}", suffix="")
container_name += suffix
@ -189,14 +194,14 @@ class PointCacheAlembicLoader(plugin.Loader):
frame_end = int(container.get("frame_end"))
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
self.import_and_containerize(
path, asset_dir, asset_name, container_name,
frame_start, frame_end)
self.imprint(
asset, asset_dir, container_name, asset_name, representation,
folder_name, asset_dir, container_name, asset_name, repre_doc,
frame_start, frame_end)
asset_content = unreal.EditorAssetLibrary.list_assets(

View file

@ -659,7 +659,7 @@ class LayoutLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
def update(self, container, context):
data = get_current_project_settings()
create_sequences = data["unreal"]["level_sequences_for_layouts"]
@ -675,9 +675,11 @@ class LayoutLoader(plugin.Loader):
root = "/Game/Ayon"
asset_dir = container.get('namespace')
context = representation.get("context")
hierarchy = context.get('hierarchy').split("/")
asset_doc = context["asset"]
repre_doc = context["representation"]
hierarchy = list(asset_doc["data"]["parents"])
sequence = None
master_level = None
@ -726,13 +728,13 @@ class LayoutLoader(plugin.Loader):
EditorAssetLibrary.delete_directory(f"{asset_dir}/animations/")
source_path = get_representation_path(representation)
source_path = get_representation_path(repre_doc)
loaded_assets = self._process(source_path, asset_dir, sequence)
data = {
"representation": str(representation["_id"]),
"parent": str(representation["parent"]),
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"]),
"loaded_assets": loaded_assets
}
imprint(

View file

@ -407,16 +407,18 @@ class ExistingLayoutLoader(plugin.Loader):
}
upipeline.imprint(f"{curr_level_path}/{container_name}", data)
def update(self, container, representation):
def update(self, container, context):
asset_dir = container.get('namespace')
source_path = get_representation_path(representation)
project_name = get_current_project_name()
project_name = context["project"]["name"]
repre_doc = context["representation"]
source_path = get_representation_path(repre_doc)
containers = self._process(source_path, project_name)
data = {
"representation": str(representation["_id"]),
"parent": str(representation["parent"]),
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"]),
"loaded_assets": containers
}
upipeline.imprint(

View file

@ -144,34 +144,40 @@ class SkeletalMeshAlembicLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
context = representation.get("context", {})
def update(self, container, context):
asset_doc = context["asset"]
subset_doc = context["subset"]
version_doc = context["version"]
repre_doc = context["representation"]
if not context:
raise RuntimeError("No context found in representation")
folder_name = asset_doc["name"]
product_name = subset_doc["name"]
# Create directory for asset and Ayon container
asset = context.get('asset')
name = context.get('subset')
# Create directory for folder and Ayon container
suffix = "_CON"
asset_name = f"{asset}_{name}" if asset else f"{name}"
version = context.get('version')
asset_name = product_name
if folder_name:
asset_name = f"{folder_name}_{product_name}"
# Check if version is hero version and use different name
name_version = f"{name}_v{version:03d}" if version else f"{name}_hero"
version = version_doc.get("name", -1)
if version < 0:
name_version = f"{product_name}_hero"
else:
name_version = f"{product_name}_v{version:03d}"
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
f"{self.root}/{asset}/{name_version}", suffix="")
f"{self.root}/{folder_name}/{name_version}", suffix="")
container_name += suffix
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
self.import_and_containerize(path, asset_dir, asset_name,
container_name)
self.imprint(
asset, asset_dir, container_name, asset_name, representation)
folder_name, asset_dir, container_name, asset_name, repre_doc)
asset_content = unreal.EditorAssetLibrary.list_assets(
asset_dir, recursive=True, include_folder=False

View file

@ -146,34 +146,40 @@ class SkeletalMeshFBXLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
context = representation.get("context", {})
def update(self, container, context):
asset_doc = context["asse"]
subset_doc = context["subset"]
version_doc = context["version"]
repre_doc = context["representation"]
if not context:
raise RuntimeError("No context found in representation")
folder_name = asset_doc["name"]
product_name = subset_doc["name"]
# Create directory for asset and Ayon container
asset = context.get('asset')
name = context.get('subset')
suffix = "_CON"
asset_name = f"{asset}_{name}" if asset else f"{name}"
version = context.get('version')
asset_name = product_name
if folder_name:
asset_name = f"{folder_name}_{product_name}"
# Check if version is hero version and use different name
name_version = f"{name}_v{version:03d}" if version else f"{name}_hero"
version = version_doc.get("name", -1)
if version < 0:
name_version = f"{product_name}_hero"
else:
name_version = f"{product_name}_v{version:03d}"
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
f"{self.root}/{asset}/{name_version}", suffix="")
f"{self.root}/{folder_name}/{name_version}", suffix="")
container_name += suffix
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
self.import_and_containerize(
path, asset_dir, asset_name, container_name)
self.imprint(
asset, asset_dir, container_name, asset_name, representation)
folder_name, asset_dir, container_name, asset_name, repre_doc)
asset_content = unreal.EditorAssetLibrary.list_assets(
asset_dir, recursive=True, include_folder=False

View file

@ -145,34 +145,36 @@ class StaticMeshAlembicLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
context = representation.get("context", {})
def update(self, container, context):
asset_doc = context["asset"]
subset_doc = context["subset"]
repre_doc = context["representation"]
if not context:
raise RuntimeError("No context found in representation")
folder_name = asset_doc["name"]
product_name = subset_doc["name"]
# Create directory for asset and Ayon container
asset = context.get('asset')
name = context.get('subset')
suffix = "_CON"
asset_name = f"{asset}_{name}" if asset else f"{name}"
asset_name = product_name
if folder_name:
asset_name = f"{folder_name}_{product_name}"
version = context.get('version')
# Check if version is hero version and use different name
name_version = f"{name}_v{version:03d}" if version else f"{name}_hero"
name_version = f"{product_name}_v{version:03d}" if version else f"{product_name}_hero"
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
f"{self.root}/{asset}/{name_version}", suffix="")
f"{self.root}/{folder_name}/{name_version}", suffix="")
container_name += suffix
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
self.import_and_containerize(path, asset_dir, asset_name,
container_name)
self.imprint(
asset, asset_dir, container_name, asset_name, representation)
folder_name, asset_dir, container_name, asset_name, repre_doc)
asset_content = unreal.EditorAssetLibrary.list_assets(
asset_dir, recursive=True, include_folder=False

View file

@ -134,34 +134,40 @@ class StaticMeshFBXLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
context = representation.get("context", {})
def update(self, container, context):
asset_doc = context["asset"]
subset_doc = context["subset"]
version_doc = context["version"]
repre_doc = context["representation"]
if not context:
raise RuntimeError("No context found in representation")
folder_name = asset_doc["name"]
product_name = subset_doc["name"]
# Create directory for asset and Ayon container
asset = context.get('asset')
name = context.get('subset')
suffix = "_CON"
asset_name = f"{asset}_{name}" if asset else f"{name}"
version = context.get('version')
asset_name = product_name
if folder_name:
asset_name = f"{folder_name}_{product_name}"
# Check if version is hero version and use different name
name_version = f"{name}_v{version:03d}" if version else f"{name}_hero"
version = version_doc.get("name", -1)
if version < 0:
name_version = f"{product_name}_hero"
else:
name_version = f"{product_name}_v{version:03d}"
tools = unreal.AssetToolsHelpers().get_asset_tools()
asset_dir, container_name = tools.create_unique_asset_name(
f"{self.root}/{asset}/{name_version}", suffix="")
f"{self.root}/{folder_name}/{name_version}", suffix="")
container_name += suffix
if not unreal.EditorAssetLibrary.does_directory_exist(asset_dir):
path = get_representation_path(representation)
path = get_representation_path(repre_doc)
self.import_and_containerize(
path, asset_dir, asset_name, container_name)
self.imprint(
asset, asset_dir, container_name, asset_name, representation)
folder_name, asset_dir, container_name, asset_name, repre_doc)
asset_content = unreal.EditorAssetLibrary.list_assets(
asset_dir, recursive=True, include_folder=False

View file

@ -96,11 +96,15 @@ class UAssetLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
def update(self, container, context):
ar = unreal.AssetRegistryHelpers.get_asset_registry()
asset_dir = container["namespace"]
name = representation["context"]["subset"]
subset_doc = context["subset"]
repre_doc = context["representation"]
product_name = subset_doc["name"]
unique_number = container["container_name"].split("_")[-2]
@ -116,19 +120,20 @@ class UAssetLoader(plugin.Loader):
if obj.get_class().get_name() != "AyonAssetContainer":
unreal.EditorAssetLibrary.delete_asset(asset)
update_filepath = get_representation_path(representation)
update_filepath = get_representation_path(repre_doc)
shutil.copy(
update_filepath,
f"{destination_path}/{name}_{unique_number}.{self.extension}")
f"{destination_path}/{product_name}_{unique_number}.{self.extension}"
)
container_path = f'{container["namespace"]}/{container["objectName"]}'
# update metadata
unreal_pipeline.imprint(
container_path,
{
"representation": str(representation["_id"]),
"parent": str(representation["parent"]),
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"]),
}
)

View file

@ -69,7 +69,7 @@ class YetiLoader(plugin.Loader):
Args:
context (dict): application context
name (str): subset name
name (str): Product name
namespace (str): in Unreal this is basically path to container.
This is not passed here, so namespace is set
by `containerise()` because only then we know
@ -139,9 +139,10 @@ class YetiLoader(plugin.Loader):
return asset_content
def update(self, container, representation):
def update(self, container, context):
repre_doc = context["representation"]
name = container["asset_name"]
source_path = get_representation_path(representation)
source_path = get_representation_path(repre_doc)
destination_path = container["namespace"]
task = self.get_task(source_path, destination_path, name, True)
@ -154,8 +155,8 @@ class YetiLoader(plugin.Loader):
unreal_pipeline.imprint(
container_path,
{
"representation": str(representation["_id"]),
"parent": str(representation["parent"])
"representation": str(repre_doc["_id"]),
"parent": str(repre_doc["parent"])
})
asset_content = unreal.EditorAssetLibrary.list_assets(