mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Add option to replace only selected actors
This commit is contained in:
parent
2731925541
commit
6583525e42
2 changed files with 88 additions and 57 deletions
|
|
@ -654,13 +654,21 @@ def generate_sequence(h, h_dir):
|
||||||
|
|
||||||
|
|
||||||
def _get_comps_and_assets(
|
def _get_comps_and_assets(
|
||||||
component_class, asset_class, old_assets, new_assets
|
component_class, asset_class, old_assets, new_assets, selected
|
||||||
):
|
):
|
||||||
eas = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
|
eas = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
|
||||||
comps = eas.get_all_level_actors_components()
|
|
||||||
components = [
|
components = []
|
||||||
c for c in comps if isinstance(c, component_class)
|
if selected:
|
||||||
]
|
sel_actors = eas.get_selected_level_actors()
|
||||||
|
for actor in sel_actors:
|
||||||
|
comps = actor.get_components_by_class(component_class)
|
||||||
|
components.extend(comps)
|
||||||
|
else:
|
||||||
|
comps = eas.get_all_level_actors_components()
|
||||||
|
components = [
|
||||||
|
c for c in comps if isinstance(c, component_class)
|
||||||
|
]
|
||||||
|
|
||||||
# Get all the static meshes among the old assets in a dictionary with
|
# Get all the static meshes among the old assets in a dictionary with
|
||||||
# the name as key
|
# the name as key
|
||||||
|
|
@ -681,14 +689,15 @@ def _get_comps_and_assets(
|
||||||
return components, selected_old_assets, selected_new_assets
|
return components, selected_old_assets, selected_new_assets
|
||||||
|
|
||||||
|
|
||||||
def replace_static_mesh_actors(old_assets, new_assets):
|
def replace_static_mesh_actors(old_assets, new_assets, selected):
|
||||||
smes = unreal.get_editor_subsystem(unreal.StaticMeshEditorSubsystem)
|
smes = unreal.get_editor_subsystem(unreal.StaticMeshEditorSubsystem)
|
||||||
|
|
||||||
static_mesh_comps, old_meshes, new_meshes = _get_comps_and_assets(
|
static_mesh_comps, old_meshes, new_meshes = _get_comps_and_assets(
|
||||||
unreal.StaticMeshComponent,
|
unreal.StaticMeshComponent,
|
||||||
unreal.StaticMesh,
|
unreal.StaticMesh,
|
||||||
old_assets,
|
old_assets,
|
||||||
new_assets
|
new_assets,
|
||||||
|
selected
|
||||||
)
|
)
|
||||||
|
|
||||||
for old_name, old_mesh in old_meshes.items():
|
for old_name, old_mesh in old_meshes.items():
|
||||||
|
|
@ -701,12 +710,13 @@ def replace_static_mesh_actors(old_assets, new_assets):
|
||||||
static_mesh_comps, old_mesh, new_mesh)
|
static_mesh_comps, old_mesh, new_mesh)
|
||||||
|
|
||||||
|
|
||||||
def replace_skeletal_mesh_actors(old_assets, new_assets):
|
def replace_skeletal_mesh_actors(old_assets, new_assets, selected):
|
||||||
skeletal_mesh_comps, old_meshes, new_meshes = _get_comps_and_assets(
|
skeletal_mesh_comps, old_meshes, new_meshes = _get_comps_and_assets(
|
||||||
unreal.SkeletalMeshComponent,
|
unreal.SkeletalMeshComponent,
|
||||||
unreal.SkeletalMesh,
|
unreal.SkeletalMesh,
|
||||||
old_assets,
|
old_assets,
|
||||||
new_assets
|
new_assets,
|
||||||
|
selected
|
||||||
)
|
)
|
||||||
|
|
||||||
for old_name, old_mesh in old_meshes.items():
|
for old_name, old_mesh in old_meshes.items():
|
||||||
|
|
@ -720,12 +730,13 @@ def replace_skeletal_mesh_actors(old_assets, new_assets):
|
||||||
comp.set_skeletal_mesh_asset(new_mesh)
|
comp.set_skeletal_mesh_asset(new_mesh)
|
||||||
|
|
||||||
|
|
||||||
def replace_geometry_cache_actors(old_assets, new_assets):
|
def replace_geometry_cache_actors(old_assets, new_assets, selected):
|
||||||
geometry_cache_comps, old_caches, new_caches = _get_comps_and_assets(
|
geometry_cache_comps, old_caches, new_caches = _get_comps_and_assets(
|
||||||
unreal.GeometryCacheComponent,
|
unreal.GeometryCacheComponent,
|
||||||
unreal.GeometryCache,
|
unreal.GeometryCache,
|
||||||
old_assets,
|
old_assets,
|
||||||
new_assets
|
new_assets,
|
||||||
|
selected
|
||||||
)
|
)
|
||||||
|
|
||||||
for old_name, old_mesh in old_caches.items():
|
for old_name, old_mesh in old_caches.items():
|
||||||
|
|
|
||||||
|
|
@ -10,58 +10,78 @@ from openpype.hosts.unreal.api.pipeline import (
|
||||||
from openpype.pipeline import InventoryAction
|
from openpype.pipeline import InventoryAction
|
||||||
|
|
||||||
|
|
||||||
class UpdateActors(InventoryAction):
|
def update_assets(containers, selected):
|
||||||
"""Update Actors in level to this version.
|
allowed_families = ["model", "rig"]
|
||||||
|
|
||||||
|
# Get all the containers in the Unreal Project
|
||||||
|
all_containers = ls()
|
||||||
|
|
||||||
|
for container in containers:
|
||||||
|
container_dir = container.get("namespace")
|
||||||
|
if container.get("family") not in allowed_families:
|
||||||
|
unreal.log_warning(
|
||||||
|
f"Container {container_dir} is not supported.")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Get all containers with same asset_name but different objectName.
|
||||||
|
# These are the containers that need to be updated in the level.
|
||||||
|
sa_containers = [
|
||||||
|
i
|
||||||
|
for i in all_containers
|
||||||
|
if (
|
||||||
|
i.get("asset_name") == container.get("asset_name") and
|
||||||
|
i.get("objectName") != container.get("objectName")
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
asset_content = unreal.EditorAssetLibrary.list_assets(
|
||||||
|
container_dir, recursive=True, include_folder=False
|
||||||
|
)
|
||||||
|
|
||||||
|
# Update all actors in level
|
||||||
|
for sa_cont in sa_containers:
|
||||||
|
sa_dir = sa_cont.get("namespace")
|
||||||
|
old_content = unreal.EditorAssetLibrary.list_assets(
|
||||||
|
sa_dir, recursive=True, include_folder=False
|
||||||
|
)
|
||||||
|
|
||||||
|
if container.get("family") == "rig":
|
||||||
|
replace_skeletal_mesh_actors(
|
||||||
|
old_content, asset_content, selected)
|
||||||
|
replace_static_mesh_actors(
|
||||||
|
old_content, asset_content, selected)
|
||||||
|
elif container.get("family") == "model":
|
||||||
|
if container.get("loader") == "PointCacheAlembicLoader":
|
||||||
|
replace_geometry_cache_actors(
|
||||||
|
old_content, asset_content, selected)
|
||||||
|
else:
|
||||||
|
replace_static_mesh_actors(
|
||||||
|
old_content, asset_content, selected)
|
||||||
|
|
||||||
|
unreal.EditorLevelLibrary.save_current_level()
|
||||||
|
|
||||||
|
delete_previous_asset_if_unused(sa_cont, old_content)
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateAllActors(InventoryAction):
|
||||||
|
"""Update all the Actors in the current level to the version of the asset
|
||||||
|
selected in the scene manager.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
label = "Update Actors in level to this version"
|
label = "Replace all Actors in level to this version"
|
||||||
icon = "arrow-up"
|
icon = "arrow-up"
|
||||||
|
|
||||||
def process(self, containers):
|
def process(self, containers):
|
||||||
allowed_families = ["model", "rig"]
|
update_assets(containers, False)
|
||||||
|
|
||||||
# Get all the containers in the Unreal Project
|
|
||||||
all_containers = ls()
|
|
||||||
|
|
||||||
for container in containers:
|
class UpdateSelectedActors(InventoryAction):
|
||||||
container_dir = container.get("namespace")
|
"""Update only the selected Actors in the current level to the version
|
||||||
if container.get("family") not in allowed_families:
|
of the asset selected in the scene manager.
|
||||||
unreal.log_warning(
|
"""
|
||||||
f"Container {container_dir} is not supported.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Get all containers with same asset_name but different objectName.
|
label = "Replace selected Actors in level to this version"
|
||||||
# These are the containers that need to be updated in the level.
|
icon = "arrow-up"
|
||||||
sa_containers = [
|
|
||||||
i
|
|
||||||
for i in all_containers
|
|
||||||
if (
|
|
||||||
i.get("asset_name") == container.get("asset_name") and
|
|
||||||
i.get("objectName") != container.get("objectName")
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
asset_content = unreal.EditorAssetLibrary.list_assets(
|
def process(self, containers):
|
||||||
container_dir, recursive=True, include_folder=False
|
update_assets(containers, True)
|
||||||
)
|
|
||||||
|
|
||||||
# Update all actors in level
|
|
||||||
for sa_cont in sa_containers:
|
|
||||||
sa_dir = sa_cont.get("namespace")
|
|
||||||
old_content = unreal.EditorAssetLibrary.list_assets(
|
|
||||||
sa_dir, recursive=True, include_folder=False
|
|
||||||
)
|
|
||||||
|
|
||||||
if container.get("family") == "rig":
|
|
||||||
replace_skeletal_mesh_actors(old_content, asset_content)
|
|
||||||
replace_static_mesh_actors(old_content, asset_content)
|
|
||||||
elif container.get("family") == "model":
|
|
||||||
if container.get("loader") == "PointCacheAlembicLoader":
|
|
||||||
replace_geometry_cache_actors(
|
|
||||||
old_content, asset_content)
|
|
||||||
else:
|
|
||||||
replace_static_mesh_actors(old_content, asset_content)
|
|
||||||
|
|
||||||
unreal.EditorLevelLibrary.save_current_level()
|
|
||||||
|
|
||||||
delete_previous_asset_if_unused(sa_cont, old_content)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue