This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5670 from ynput/enhancement/OP-6890_unreal-improv…
…ed_update Unreal: Changed behaviour for updating assets
- Loading branch information
Showing
11 changed files
with
723 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
openpype/hosts/unreal/plugins/inventory/delete_unused_assets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import unreal | ||
|
||
from openpype.hosts.unreal.api.tools_ui import qt_app_context | ||
from openpype.hosts.unreal.api.pipeline import delete_asset_if_unused | ||
from openpype.pipeline import InventoryAction | ||
|
||
|
||
class DeleteUnusedAssets(InventoryAction): | ||
"""Delete all the assets that are not used in any level. | ||
""" | ||
|
||
label = "Delete Unused Assets" | ||
icon = "trash" | ||
color = "red" | ||
order = 1 | ||
|
||
dialog = None | ||
|
||
def _delete_unused_assets(self, containers): | ||
allowed_families = ["model", "rig"] | ||
|
||
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 | ||
|
||
asset_content = unreal.EditorAssetLibrary.list_assets( | ||
container_dir, recursive=True, include_folder=False | ||
) | ||
|
||
delete_asset_if_unused(container, asset_content) | ||
|
||
def _show_confirmation_dialog(self, containers): | ||
from qtpy import QtCore | ||
from openpype.widgets import popup | ||
from openpype.style import load_stylesheet | ||
|
||
dialog = popup.Popup() | ||
dialog.setWindowFlags( | ||
QtCore.Qt.Window | ||
| QtCore.Qt.WindowStaysOnTopHint | ||
) | ||
dialog.setFocusPolicy(QtCore.Qt.StrongFocus) | ||
dialog.setWindowTitle("Delete all unused assets") | ||
dialog.setMessage( | ||
"You are about to delete all the assets in the project that \n" | ||
"are not used in any level. Are you sure you want to continue?" | ||
) | ||
dialog.setButtonText("Delete") | ||
|
||
dialog.on_clicked.connect( | ||
lambda: self._delete_unused_assets(containers) | ||
) | ||
|
||
dialog.show() | ||
dialog.raise_() | ||
dialog.activateWindow() | ||
dialog.setStyleSheet(load_stylesheet()) | ||
|
||
self.dialog = dialog | ||
|
||
def process(self, containers): | ||
with qt_app_context(): | ||
self._show_confirmation_dialog(containers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import unreal | ||
|
||
from openpype.hosts.unreal.api.pipeline import ( | ||
ls, | ||
replace_static_mesh_actors, | ||
replace_skeletal_mesh_actors, | ||
replace_geometry_cache_actors, | ||
) | ||
from openpype.pipeline import InventoryAction | ||
|
||
|
||
def update_assets(containers, selected): | ||
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() | ||
|
||
|
||
class UpdateAllActors(InventoryAction): | ||
"""Update all the Actors in the current level to the version of the asset | ||
selected in the scene manager. | ||
""" | ||
|
||
label = "Replace all Actors in level to this version" | ||
icon = "arrow-up" | ||
|
||
def process(self, containers): | ||
update_assets(containers, False) | ||
|
||
|
||
class UpdateSelectedActors(InventoryAction): | ||
"""Update only the selected Actors in the current level to the version | ||
of the asset selected in the scene manager. | ||
""" | ||
|
||
label = "Replace selected Actors in level to this version" | ||
icon = "arrow-up" | ||
|
||
def process(self, containers): | ||
update_assets(containers, True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.