Moved asynchronous image loading function to atom tools framework
Moved settings registry wrapper function to atom tools framework Created registry settings with default values for preview configurations based on asset type Changed lighting preset previews and thumbnails to use reflective material Created registry settings for preset selection dialog borders, padding, sizes Updated shared preview utility functions to compare against registered asset types instead of passing them in individually Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
@@ -42,6 +42,7 @@ ly_add_target(
|
||||
Gem::Atom_RHI.Reflect
|
||||
Gem::Atom_Feature_Common.Static
|
||||
Gem::Atom_Bootstrap.Headers
|
||||
Gem::ImageProcessingAtom.Headers
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
@@ -60,6 +61,8 @@ ly_add_target(
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
Gem::AtomToolsFramework.Static
|
||||
RUNTIME_DEPENDENCIES
|
||||
Gem::ImageProcessingAtom.Editor
|
||||
)
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/PlatformDef.h>
|
||||
#include <AzCore/Asset/AssetManager.h>
|
||||
#include <AzCore/PlatformDef.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
|
||||
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
|
||||
@@ -18,11 +19,24 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnin
|
||||
#include <QStringList>
|
||||
AZ_POP_DISABLE_WARNING
|
||||
|
||||
class QImage;
|
||||
|
||||
namespace AtomToolsFramework
|
||||
{
|
||||
template<typename T>
|
||||
T GetSettingOrDefault(AZStd::string_view path, const T& defaultValue)
|
||||
{
|
||||
T result;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
return (settingsRegistry && settingsRegistry->Get(result, path)) ? result : defaultValue;
|
||||
}
|
||||
|
||||
using LoadImageAsyncCallback = AZStd::function<void(const QImage&)>;
|
||||
void LoadImageAsync(const AZStd::string& path, LoadImageAsyncCallback callback);
|
||||
|
||||
QFileInfo GetSaveFileInfo(const QString& initialPath);
|
||||
QFileInfo GetOpenFileInfo(const AZStd::vector<AZ::Data::AssetType>& assetTypes);
|
||||
QFileInfo GetUniqueFileInfo(const QString& initialPath);
|
||||
QFileInfo GetDuplicationFileInfo(const QString& initialPath);
|
||||
bool LaunchTool(const QString& baseName, const QString& extension, const QStringList& arguments);
|
||||
}
|
||||
} // namespace AtomToolsFramework
|
||||
|
||||
@@ -6,15 +6,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Atom/ImageProcessing/ImageObject.h>
|
||||
#include <Atom/ImageProcessing/ImageProcessingBus.h>
|
||||
#include <AtomToolsFramework/Util/Util.h>
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include <AzCore/Jobs/JobFunction.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzFramework/API/ApplicationAPI.h>
|
||||
#include <AzQtComponents/Components/Widgets/FileDialog.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
|
||||
|
||||
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
|
||||
#include <QApplication>
|
||||
@@ -24,6 +27,36 @@ AZ_POP_DISABLE_WARNING
|
||||
|
||||
namespace AtomToolsFramework
|
||||
{
|
||||
void LoadImageAsync(const AZStd::string& path, LoadImageAsyncCallback callback)
|
||||
{
|
||||
AZ::Job* job = AZ::CreateJobFunction(
|
||||
[path, callback]()
|
||||
{
|
||||
ImageProcessingAtom::IImageObjectPtr imageObject;
|
||||
ImageProcessingAtom::ImageProcessingRequestBus::BroadcastResult(
|
||||
imageObject, &ImageProcessingAtom::ImageProcessingRequests::LoadImagePreview, path);
|
||||
|
||||
if (imageObject)
|
||||
{
|
||||
AZ::u8* imageBuf = nullptr;
|
||||
AZ::u32 pitch = 0;
|
||||
AZ::u32 mip = 0;
|
||||
imageObject->GetImagePointer(mip, imageBuf, pitch);
|
||||
const AZ::u32 width = imageObject->GetWidth(mip);
|
||||
const AZ::u32 height = imageObject->GetHeight(mip);
|
||||
|
||||
QImage image(imageBuf, width, height, pitch, QImage::Format_RGBA8888);
|
||||
|
||||
if (callback)
|
||||
{
|
||||
callback(image);
|
||||
}
|
||||
}
|
||||
},
|
||||
true);
|
||||
job->Start();
|
||||
}
|
||||
|
||||
QFileInfo GetSaveFileInfo(const QString& initialPath)
|
||||
{
|
||||
const QFileInfo initialFileInfo(initialPath);
|
||||
|
||||
@@ -60,7 +60,6 @@ ly_add_target(
|
||||
Gem::AtomToolsFramework.Editor
|
||||
Gem::Atom_RPI.Public
|
||||
Gem::Atom_Feature_Common.Public
|
||||
Gem::ImageProcessingAtom.Headers
|
||||
)
|
||||
|
||||
ly_add_target(
|
||||
@@ -113,7 +112,6 @@ ly_add_target(
|
||||
RUNTIME_DEPENDENCIES
|
||||
Gem::AtomToolsFramework.Editor
|
||||
Gem::EditorPythonBindings.Editor
|
||||
Gem::ImageProcessingAtom.Editor
|
||||
)
|
||||
|
||||
ly_set_gem_variant_to_load(TARGETS MaterialEditor VARIANTS Tools)
|
||||
|
||||
@@ -6,61 +6,26 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/Jobs/JobFunction.h>
|
||||
|
||||
#include <AzFramework/Asset/AssetSystemBus.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <AzFramework/IO/LocalFileIO.h>
|
||||
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
|
||||
|
||||
#include <Viewport/MaterialViewportComponent.h>
|
||||
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
|
||||
#include <Atom/Viewport/MaterialViewportSettings.h>
|
||||
|
||||
#include <Atom/ImageProcessing/ImageObject.h>
|
||||
#include <Atom/ImageProcessing/ImageProcessingBus.h>
|
||||
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
|
||||
#include <Atom/RPI.Reflect/Asset/AssetUtils.h>
|
||||
#include <Atom/RPI.Reflect/System/AnyAsset.h>
|
||||
#include <Atom/RPI.Edit/Common/AssetUtils.h>
|
||||
#include <Atom/RPI.Edit/Common/JsonUtils.h>
|
||||
#include <Atom/RPI.Reflect/Asset/AssetUtils.h>
|
||||
#include <Atom/RPI.Reflect/System/AnyAsset.h>
|
||||
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
|
||||
#include <Atom/Viewport/MaterialViewportSettings.h>
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzFramework/Asset/AssetSystemBus.h>
|
||||
#include <AzFramework/IO/LocalFileIO.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
|
||||
#include <Viewport/MaterialViewportComponent.h>
|
||||
|
||||
namespace MaterialEditor
|
||||
{
|
||||
using LoadImageAsyncCallback = AZStd::function<void(const QImage&)>;
|
||||
void LoadImageAsync(const AZStd::string& path, LoadImageAsyncCallback callback)
|
||||
{
|
||||
AZ::Job* job = AZ::CreateJobFunction([path, callback]() {
|
||||
ImageProcessingAtom::IImageObjectPtr imageObject;
|
||||
ImageProcessingAtom::ImageProcessingRequestBus::BroadcastResult(imageObject, &ImageProcessingAtom::ImageProcessingRequests::LoadImagePreview, path);
|
||||
|
||||
if (imageObject)
|
||||
{
|
||||
AZ::u8* imageBuf = nullptr;
|
||||
AZ::u32 pitch = 0;
|
||||
AZ::u32 mip = 0;
|
||||
imageObject->GetImagePointer(mip, imageBuf, pitch);
|
||||
const AZ::u32 width = imageObject->GetWidth(mip);
|
||||
const AZ::u32 height = imageObject->GetHeight(mip);
|
||||
|
||||
QImage image(imageBuf, width, height, pitch, QImage::Format_RGBA8888);
|
||||
|
||||
if (callback)
|
||||
{
|
||||
callback(image);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
job->Start();
|
||||
}
|
||||
|
||||
MaterialViewportComponent::MaterialViewportComponent()
|
||||
{
|
||||
}
|
||||
|
||||
+5
-2
@@ -28,13 +28,16 @@ namespace MaterialEditor
|
||||
MaterialViewportRequestBus::BroadcastResult(presets, &MaterialViewportRequestBus::Events::GetLightingPresets);
|
||||
AZStd::sort(presets.begin(), presets.end(), [](const auto& a, const auto& b) { return a->m_displayName < b->m_displayName; });
|
||||
|
||||
const int itemSize = aznumeric_cast<int>(
|
||||
AtomToolsFramework::GetSettingOrDefault<AZ::u64>("/O3DE/Atom/MaterialEditor/PresetBrowserDialog/LightingItemSize", 180));
|
||||
|
||||
QListWidgetItem* selectedItem = nullptr;
|
||||
for (const auto& preset : presets)
|
||||
{
|
||||
AZStd::string path;
|
||||
MaterialViewportRequestBus::BroadcastResult(path, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset);
|
||||
QListWidgetItem* item =
|
||||
CreateListItem(preset->m_displayName.c_str(), AZ::RPI::AssetUtils::MakeAssetId(path, 0).GetValue(), QSize(180, 180));
|
||||
QListWidgetItem* item = CreateListItem(
|
||||
preset->m_displayName.c_str(), AZ::RPI::AssetUtils::MakeAssetId(path, 0).GetValue(), QSize(itemSize, itemSize));
|
||||
|
||||
m_listItemToPresetMap[item] = preset;
|
||||
|
||||
|
||||
+4
-1
@@ -27,10 +27,13 @@ namespace MaterialEditor
|
||||
MaterialViewportRequestBus::BroadcastResult(presets, &MaterialViewportRequestBus::Events::GetModelPresets);
|
||||
AZStd::sort(presets.begin(), presets.end(), [](const auto& a, const auto& b) { return a->m_displayName < b->m_displayName; });
|
||||
|
||||
const int itemSize = aznumeric_cast<int>(
|
||||
AtomToolsFramework::GetSettingOrDefault<AZ::u64>("/O3DE/Atom/MaterialEditor/PresetBrowserDialog/ModelItemSize", 90));
|
||||
|
||||
QListWidgetItem* selectedItem = nullptr;
|
||||
for (const auto& preset : presets)
|
||||
{
|
||||
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), preset->m_modelAsset.GetId(), QSize(90, 90));
|
||||
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), preset->m_modelAsset.GetId(), QSize(itemSize, itemSize));
|
||||
|
||||
m_listItemToPresetMap[item] = preset;
|
||||
|
||||
|
||||
+12
-4
@@ -51,13 +51,21 @@ namespace MaterialEditor
|
||||
|
||||
QListWidgetItem* PresetBrowserDialog::CreateListItem(const QString& title, const AZ::Data::AssetId& assetId, const QSize& size)
|
||||
{
|
||||
const int itemBorder = aznumeric_cast<int>(
|
||||
AtomToolsFramework::GetSettingOrDefault<AZ::u64>("/O3DE/Atom/MaterialEditor/PresetBrowserDialog/ItemBorder", 4));
|
||||
const int itemSpacing = aznumeric_cast<int>(
|
||||
AtomToolsFramework::GetSettingOrDefault<AZ::u64>("/O3DE/Atom/MaterialEditor/PresetBrowserDialog/ItemSpacing", 10));
|
||||
const int headerHeight = aznumeric_cast<int>(
|
||||
AtomToolsFramework::GetSettingOrDefault<AZ::u64>("/O3DE/Atom/MaterialEditor/PresetBrowserDialog/HeaderHeight", 15));
|
||||
|
||||
const QSize gridSize = m_ui->m_presetList->gridSize();
|
||||
m_ui->m_presetList->setGridSize(
|
||||
QSize(AZStd::max(gridSize.width(), size.width() + 10), AZStd::max(gridSize.height(), size.height() + 10 + 15)));
|
||||
m_ui->m_presetList->setGridSize(QSize(
|
||||
AZStd::max(gridSize.width(), size.width() + itemSpacing),
|
||||
AZStd::max(gridSize.height(), size.height() + itemSpacing + headerHeight)));
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(m_ui->m_presetList);
|
||||
item->setData(Qt::UserRole, title);
|
||||
item->setSizeHint(size + QSize(4, 19));
|
||||
item->setSizeHint(size + QSize(itemBorder, itemBorder + headerHeight));
|
||||
m_ui->m_presetList->addItem(item);
|
||||
|
||||
QWidget* itemWidget = new QWidget(m_ui->m_presetList);
|
||||
@@ -67,7 +75,7 @@ namespace MaterialEditor
|
||||
|
||||
AzQtComponents::ElidingLabel* header = new AzQtComponents::ElidingLabel(itemWidget);
|
||||
header->setText(title);
|
||||
header->setFixedSize(QSize(size.width(), 15));
|
||||
header->setFixedSize(QSize(size.width(), headerHeight));
|
||||
header->setMargin(0);
|
||||
header->setStyleSheet("background-color: rgb(35, 35, 35)");
|
||||
AzQtComponents::Text::addPrimaryStyle(header);
|
||||
|
||||
Reference in New Issue
Block a user