diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h new file mode 100644 index 0000000000..37d6a8c2d8 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialDocumentSettings.h @@ -0,0 +1,34 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include +#endif + +namespace MaterialEditor +{ + struct MaterialDocumentSettings + : public AZ::UserSettings + { + AZ_RTTI(MaterialDocumentSettings, "{FA4F4BF3-BF39-4753-AAF7-AF383B868881}", AZ::UserSettings); + AZ_CLASS_ALLOCATOR(MaterialDocumentSettings, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + bool m_showReloadDocumentPrompt = true; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h deleted file mode 100644 index 3ddfdf44d4..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Document/MaterialEditorSettingsBus.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -namespace MaterialEditor -{ - class MaterialEditorSettingsRequests - : public AZ::EBusTraits - { - public: - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - - virtual AZ::Outcome GetProperty(AZStd::string_view name) const = 0; - virtual AZ::Outcome GetStringProperty(AZStd::string_view name) const = 0; - virtual AZ::Outcome GetBoolProperty(AZStd::string_view name) const = 0; - - virtual void SetProperty(AZStd::string_view name, const AZStd::any& value) = 0; - virtual void SetStringProperty(AZStd::string_view name, AZStd::string_view stringValue) = 0; - virtual void SetBoolProperty(AZStd::string_view name, bool boolValue) = 0; - }; - using MaterialEditorSettingsRequestBus = AZ::EBus; - - class MaterialEditorSettingsNotifications - : public AZ::EBusTraits - { - public: - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - - virtual void OnPropertyChanged(AZStd::string_view name, const AZStd::any& value) = 0; - }; - using MaterialEditorSettingsNotificationBus = AZ::EBus; - -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h index 0727547b13..af85dcc1db 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportNotificationBus.h @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h new file mode 100644 index 0000000000..7af6b307df --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Viewport/MaterialViewportSettings.h @@ -0,0 +1,41 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include +#include +#endif + +namespace MaterialEditor +{ + struct MaterialViewportSettings + : public AZ::UserSettings + { + AZ_RTTI(MaterialViewportSettings, "{16150503-A314-4765-82A3-172670C9EA90}", AZ::UserSettings); + AZ_CLASS_ALLOCATOR(MaterialViewportSettings, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + bool m_enableGrid = true; + bool m_enableShadowCatcher = true; + bool m_enableAlternateSkybox = false; + float m_fieldOfView = 90.0f; + AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; + AZStd::string m_selectedModelPresetName = "Shader Ball"; + AZStd::string m_selectedLightingPresetName = "Neutral Urban"; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h new file mode 100644 index 0000000000..bf572b070a --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowSettings.h @@ -0,0 +1,37 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#include +#include +#include +#endif + +namespace MaterialEditor +{ + struct MaterialEditorWindowSettings + : public AZ::UserSettings + { + AZ_RTTI(MaterialEditorWindowSettings, "{BB9DEB77-B7BE-4DF5-9FDD-6D9F3136C4EA}", AZ::UserSettings); + AZ_CLASS_ALLOCATOR(MaterialEditorWindowSettings, AZ::SystemAllocator, 0); + + static void Reflect(AZ::ReflectContext* context); + + bool m_enableGrid = true; + bool m_enableShadowCatcher = true; + bool m_enableAlternateSkybox = false; + float m_fieldOfView = 90.0f; + }; +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp new file mode 100644 index 0000000000..a64b6584c1 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp @@ -0,0 +1,51 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include + +namespace MaterialEditor +{ + void MaterialDocumentSettings::Reflect(AZ::ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("showReloadDocumentPrompt", &MaterialDocumentSettings::m_showReloadDocumentPrompt) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "MaterialDocumentSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_showReloadDocumentPrompt, "Show Reload Document Prompt", "") + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class("MaterialDocumentSettings") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Constructor() + ->Constructor() + ->Property("showReloadDocumentPrompt", BehaviorValueProperty(&MaterialDocumentSettings::m_showReloadDocumentPrompt)) + ; + } + } +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp index dbb1d18e49..d0a904d522 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -40,12 +41,13 @@ AZ_POP_DISABLE_WARNING namespace MaterialEditor { MaterialDocumentSystemComponent::MaterialDocumentSystemComponent() - : m_settings(aznew MaterialEditorSettings) { } void MaterialDocumentSystemComponent::Reflect(AZ::ReflectContext* context) { + MaterialDocumentSettings::Reflect(context); + if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() @@ -132,6 +134,7 @@ namespace MaterialEditor void MaterialDocumentSystemComponent::Activate() { m_documentMap.clear(); + m_settings = AZ::UserSettings::CreateFind(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL); MaterialDocumentSystemRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); } @@ -188,22 +191,25 @@ namespace MaterialEditor AZStd::string documentPath; MaterialDocumentRequestBus::EventResult(documentPath, documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath); - if (QMessageBox::question(QApplication::activeWindow(), + if (m_settings->m_showReloadDocumentPrompt && + (QMessageBox::question(QApplication::activeWindow(), QString("Material document was externally modified"), QString("Would you like to reopen the document:\n%1?").arg(documentPath.c_str()), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)) { - AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + continue; + } - bool openResult = false; - MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, documentPath); - if (!openResult) - { - QMessageBox::critical( - QApplication::activeWindow(), QString("Material document could not be opened"), - QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); - MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); - } + AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + + bool openResult = false; + MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, documentPath); + if (!openResult) + { + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); + MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); } } @@ -212,22 +218,25 @@ namespace MaterialEditor AZStd::string documentPath; MaterialDocumentRequestBus::EventResult(documentPath, documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath); - if (QMessageBox::question(QApplication::activeWindow(), + if (m_settings->m_showReloadDocumentPrompt && + (QMessageBox::question(QApplication::activeWindow(), QString("Material document dependencies have changed"), QString("Would you like to update the document with these changes:\n%1?").arg(documentPath.c_str()), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)) { - AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + continue; + } - bool openResult = false; - MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Rebuild); - if (!openResult) - { - QMessageBox::critical( - QApplication::activeWindow(), QString("Material document could not be opened"), - QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); - MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); - } + AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount); + + bool openResult = false; + MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Rebuild); + if (!openResult) + { + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str())); + MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h index 4b0ee424a7..617937ad1a 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.h @@ -18,10 +18,10 @@ #include #include +#include #include #include #include -#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include @@ -43,7 +43,7 @@ namespace MaterialEditor MaterialDocumentSystemComponent(); ~MaterialDocumentSystemComponent() = default; MaterialDocumentSystemComponent(const MaterialDocumentSystemComponent&) = delete; - MaterialDocumentSystemComponent& operator =(const MaterialDocumentSystemComponent&) = delete; + MaterialDocumentSystemComponent& operator=(const MaterialDocumentSystemComponent&) = delete; static void Reflect(AZ::ReflectContext* context); @@ -87,10 +87,10 @@ namespace MaterialEditor AZ::Uuid OpenDocumentImpl(AZStd::string_view sourcePath, bool checkIfAlreadyOpen); + AZStd::intrusive_ptr m_settings; AZStd::unordered_map> m_documentMap; AZStd::unordered_set m_documentIdsToRebuild; AZStd::unordered_set m_documentIdsToReopen; - AZStd::unique_ptr m_settings; const size_t m_maxMessageBoxLineCount = 15; }; -} +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp deleted file mode 100644 index fc0ed84bfa..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#include - -namespace MaterialEditor -{ - MaterialEditorSettings::MaterialEditorSettings() - { - MaterialEditorSettingsRequestBus::Handler::BusConnect(); - } - - MaterialEditorSettings::~MaterialEditorSettings() - { - MaterialEditorSettingsRequestBus::Handler::BusDisconnect(); - } - - AZ::Outcome MaterialEditorSettings::GetProperty(AZStd::string_view name) const - { - const auto it = m_propertyMap.find(name); - if (it != m_propertyMap.end()) - { - return AZ::Success(it->second); - } - AZ_Warning("MaterialEditorSettings", false, "Failed to find property [%s].", name.data()); - return AZ::Failure(); - } - - AZ::Outcome MaterialEditorSettings::GetStringProperty(AZStd::string_view name) const - { - AZ::Outcome outcome = GetProperty(name); - if (!outcome || !outcome.GetValue().is()) - { - return AZ::Failure(); - } - return AZ::Success(AZStd::any_cast(outcome.GetValue())); - } - - AZ::Outcome MaterialEditorSettings::GetBoolProperty(AZStd::string_view name) const - { - AZ::Outcome outcome = GetProperty(name); - if (!outcome || !outcome.GetValue().is()) - { - return AZ::Failure(); - } - return AZ::Success(AZStd::any_cast(outcome.GetValue())); - } - - void MaterialEditorSettings::SetProperty(AZStd::string_view name, const AZStd::any& value) - { - m_propertyMap[name] = value; - MaterialEditorSettingsNotificationBus::Broadcast(&MaterialEditorSettingsNotifications::OnPropertyChanged, name, value); - } - - void MaterialEditorSettings::SetStringProperty(AZStd::string_view name, AZStd::string_view stringValue) - { - SetProperty(name, AZStd::any(AZStd::string(stringValue))); - } - - void MaterialEditorSettings::SetBoolProperty(AZStd::string_view name, bool boolValue) - { - SetProperty(name, AZStd::any(boolValue)); - } -} diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h deleted file mode 100644 index f3a948ed80..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialEditorSettings.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -#include - -namespace MaterialEditor -{ - class MaterialEditorSettings - : public MaterialEditorSettingsRequestBus::Handler - { - public: - AZ_RTTI(MaterialEditorSettings, "{9C6B6E20-A28E-45DD-85BE-68CA35E9305E}"); - AZ_CLASS_ALLOCATOR(MaterialEditorSettings, AZ::SystemAllocator, 0); - - MaterialEditorSettings(); - ~MaterialEditorSettings(); - - AZ::Outcome GetProperty(AZStd::string_view name) const override; - AZ::Outcome GetStringProperty(AZStd::string_view name) const override; - AZ::Outcome GetBoolProperty(AZStd::string_view name) const override; - - void SetProperty(AZStd::string_view name, const AZStd::any& value) override; - void SetStringProperty(AZStd::string_view name, AZStd::string_view stringValue) override; - void SetBoolProperty(AZStd::string_view name, bool boolValue) override; - - private: - AZStd::unordered_map m_propertyMap; - }; - -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 1f32c2a66b..55710efb66 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -284,7 +284,7 @@ namespace MaterialEditor AZ_Assert(context, "No serialize context"); char resolvedPath[AZ_MAX_PATH_LEN] = ""; - AZ::IO::FileIOBase::GetInstance()->ResolvePath("@user@/EditorUserSettings.xml", resolvedPath, AZ_ARRAY_SIZE(resolvedPath)); + AZ::IO::FileIOBase::GetInstance()->ResolvePath("@user@/MaterialEditorUserSettings.xml", resolvedPath, AZ_ARRAY_SIZE(resolvedPath)); m_localUserSettings.Save(resolvedPath, context); } } @@ -546,6 +546,9 @@ namespace MaterialEditor void MaterialEditorApplication::Stop() { + MaterialEditor::MaterialEditorWindowFactoryRequestBus::Broadcast( + &MaterialEditor::MaterialEditorWindowFactoryRequestBus::Handler::DestroyMaterialEditorWindow); + UnloadSettings(); AzFramework::Application::Stop(); } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp index abaf50804f..948a23d509 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -70,6 +71,8 @@ namespace MaterialEditor void MaterialViewportComponent::Reflect(AZ::ReflectContext* context) { + MaterialViewportSettings::Reflect(context); + if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() @@ -160,6 +163,9 @@ namespace MaterialEditor void MaterialViewportComponent::Activate() { + m_viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + m_lightingPresetPreviewImageDefault = QImage(180, 90, QImage::Format::Format_RGBA8888); m_lightingPresetPreviewImageDefault.fill(Qt::GlobalColor::black); @@ -192,13 +198,14 @@ namespace MaterialEditor MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnBeginReloadContent); - const AZStd::string prevLightingPresetSelectionName = m_lightingPresetSelection ? m_lightingPresetSelection->m_displayName : ""; - const AZStd::string prevModelPresetSelectionName = m_modelPresetSelection ? m_modelPresetSelection->m_displayName : ""; + const AZStd::string selectedLightingPresetNameOld = m_viewportSettings->m_selectedLightingPresetName; m_lightingPresetVector.clear(); m_lightingPresetLastSavePathMap.clear(); m_lightingPresetSelection.reset(); + const AZStd::string selectedModelPresetNameOld = m_viewportSettings->m_selectedModelPresetName; + m_modelPresetVector.clear(); m_modelPresetLastSavePathMap.clear(); m_modelPresetSelection.reset(); @@ -263,8 +270,8 @@ namespace MaterialEditor // If there was a prior selection, this will keep the same configuration selected. // Otherwise, these strings are empty and the operation will be ignored. - SelectLightingPresetByName(prevLightingPresetSelectionName); - SelectModelPresetByName(prevModelPresetSelectionName); + SelectLightingPresetByName(selectedLightingPresetNameOld); + SelectModelPresetByName(selectedModelPresetNameOld); MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnEndReloadContent); @@ -327,6 +334,7 @@ namespace MaterialEditor if (preset) { m_lightingPresetSelection = preset; + m_viewportSettings->m_selectedLightingPresetName = preset->m_displayName; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnLightingPresetSelected, m_lightingPresetSelection); } } @@ -422,6 +430,7 @@ namespace MaterialEditor if (preset) { m_modelPresetSelection = preset; + m_viewportSettings->m_selectedModelPresetName = preset->m_displayName; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnModelPresetSelected, m_modelPresetSelection); } } @@ -463,71 +472,66 @@ namespace MaterialEditor void MaterialViewportComponent::SetShadowCatcherEnabled(bool enable) { - m_shadowCatcherEnabled = enable; + m_viewportSettings->m_enableShadowCatcher = enable; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnShadowCatcherEnabledChanged, enable); } bool MaterialViewportComponent::GetShadowCatcherEnabled() const { - return m_shadowCatcherEnabled; + return m_viewportSettings->m_enableShadowCatcher; } void MaterialViewportComponent::SetGridEnabled(bool enable) { - m_gridEnabled = enable; + m_viewportSettings->m_enableGrid = enable; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnGridEnabledChanged, enable); } bool MaterialViewportComponent::GetGridEnabled() const { - return m_gridEnabled; + return m_viewportSettings->m_enableGrid; } void MaterialViewportComponent::SetAlternateSkyboxEnabled(bool enable) { - m_alternateSkyboxEnabled = enable; + m_viewportSettings->m_enableAlternateSkybox = enable; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnAlternateSkyboxEnabledChanged, enable); } bool MaterialViewportComponent::GetAlternateSkyboxEnabled() const { - return m_alternateSkyboxEnabled; + return m_viewportSettings->m_enableAlternateSkybox; } void MaterialViewportComponent::SetFieldOfView(float fieldOfView) { - m_fieldOfView = fieldOfView; + m_viewportSettings->m_fieldOfView = fieldOfView; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnFieldOfViewChanged, fieldOfView); } float MaterialViewportComponent::GetFieldOfView() const { - return m_fieldOfView; + return m_viewportSettings->m_fieldOfView; } void MaterialViewportComponent::SetDisplayMapperOperationType(AZ::Render::DisplayMapperOperationType operationType) { - m_displayMapperOperationType = operationType; + m_viewportSettings->m_displayMapperOperationType = operationType; MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnDisplayMapperOperationTypeChanged, operationType); } AZ::Render::DisplayMapperOperationType MaterialViewportComponent::GetDisplayMapperOperationType() const { - return m_displayMapperOperationType; + return m_viewportSettings->m_displayMapperOperationType; } void MaterialViewportComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile) { AZ::TickBus::QueueFunction([this]() { ReloadContent(); - - // Automatically select preferred default presets if they exist - // We will later data drive this with editor settings - SelectLightingPresetByName("Neutral Urban"); - SelectModelPresetByName("Shader Ball"); }); } } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h index 8332cb862c..ad35a86cf2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportComponent.h @@ -13,13 +13,12 @@ #pragma once #include - -#include -#include - #include #include #include +#include +#include +#include namespace MaterialEditor { @@ -111,10 +110,6 @@ namespace MaterialEditor mutable AZStd::map m_lightingPresetLastSavePathMap; mutable AZStd::map m_modelPresetLastSavePathMap; - bool m_shadowCatcherEnabled = true; - bool m_gridEnabled = true; - bool m_alternateSkyboxEnabled = false; - float m_fieldOfView = 90.0f; - AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; + AZStd::intrusive_ptr m_viewportSettings; }; } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp index 5939a40db6..f009cc1f9b 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportRenderer.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -92,6 +93,7 @@ namespace MaterialEditor auto sceneSystem = AzFramework::SceneSystemInterface::Get(); AZ_Assert(sceneSystem, "MaterialViewportRenderer was unable to get the scene system during construction."); AZStd::shared_ptr mainScene = sceneSystem->GetScene(AzFramework::Scene::MainSceneName); + // This should never happen unless scene creation has changed. AZ_Assert(mainScene, "Main scenes missing during system component initialization"); mainScene->SetSubsystem(m_scene); @@ -138,7 +140,6 @@ namespace MaterialEditor m_renderPipeline->SetDefaultViewFromEntity(m_cameraEntity->GetId()); // Configure tone mapper - AzFramework::EntityContextRequestBus::EventResult(m_postProcessEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "postProcessEntity"); AZ_Assert(m_postProcessEntity != nullptr, "Failed to create post process entity."); @@ -154,13 +155,11 @@ namespace MaterialEditor m_displayMapperFeatureProcessor = m_scene->GetFeatureProcessor(); // Init Skybox - m_skyboxFeatureProcessor = m_scene->GetFeatureProcessor(); m_skyboxFeatureProcessor->Enable(true); m_skyboxFeatureProcessor->SetSkyboxMode(AZ::Render::SkyBoxMode::Cubemap); // Create IBL - AzFramework::EntityContextRequestBus::EventResult(m_iblEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "IblEntity"); AZ_Assert(m_iblEntity != nullptr, "Failed to create ibl entity."); @@ -176,8 +175,8 @@ namespace MaterialEditor m_modelEntity->CreateComponent(AZ::Render::MaterialComponentTypeId); m_modelEntity->CreateComponent(azrtti_typeid()); m_modelEntity->Activate(); - // Create shadow catcher + // Create shadow catcher AzFramework::EntityContextRequestBus::EventResult(m_shadowCatcherEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "ViewportShadowCatcher"); AZ_Assert(m_shadowCatcherEntity != nullptr, "Failed to create shadow catcher entity."); m_shadowCatcherEntity->CreateComponent(AZ::Render::MeshComponentTypeId); @@ -208,7 +207,6 @@ namespace MaterialEditor } // Create grid - AzFramework::EntityContextRequestBus::EventResult(m_gridEntity, entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "ViewportGrid"); AZ_Assert(m_gridEntity != nullptr, "Failed to create grid entity."); @@ -235,6 +233,16 @@ namespace MaterialEditor MaterialViewportRequestBus::BroadcastResult(modelPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection); OnModelPresetSelected(modelPreset); + // Apply user settinngs restored since last run + AZStd::intrusive_ptr viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + + OnGridEnabledChanged(viewportSettings->m_enableGrid); + OnShadowCatcherEnabledChanged(viewportSettings->m_enableShadowCatcher); + OnAlternateSkyboxEnabledChanged(viewportSettings->m_enableAlternateSkybox); + OnFieldOfViewChanged(viewportSettings->m_fieldOfView); + OnDisplayMapperOperationTypeChanged(viewportSettings->m_displayMapperOperationType); + MaterialDocumentNotificationBus::Handler::BusConnect(); MaterialViewportNotificationBus::Handler::BusConnect(); AZ::TickBus::Handler::BusConnect(); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.cpp new file mode 100644 index 0000000000..fd64f3073d --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Viewport/MaterialViewportSettings.cpp @@ -0,0 +1,72 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include + +namespace MaterialEditor +{ + void MaterialViewportSettings::Reflect(AZ::ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("enableGrid", &MaterialViewportSettings::m_enableGrid) + ->Field("enableShadowCatcher", &MaterialViewportSettings::m_enableShadowCatcher) + ->Field("enableAlternateSkybox", &MaterialViewportSettings::m_enableAlternateSkybox) + ->Field("fieldOfView", &MaterialViewportSettings::m_fieldOfView) + ->Field("displayMapperOperationType", &MaterialViewportSettings::m_displayMapperOperationType) + ->Field("selectedModelPresetName", &MaterialViewportSettings::m_selectedModelPresetName) + ->Field("selectedLightingPresetName", &MaterialViewportSettings::m_selectedLightingPresetName) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "MaterialViewportSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialViewportSettings::m_enableGrid, "Enable Grid", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialViewportSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialViewportSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") + ->DataElement(AZ::Edit::UIHandlers::Slider, &MaterialViewportSettings::m_fieldOfView, "Field Of View", "") + ->Attribute(AZ::Edit::Attributes::Min, 60.0f) + ->Attribute(AZ::Edit::Attributes::Max, 120.0f) + ->DataElement(AZ::Edit::UIHandlers::ComboBox, &MaterialViewportSettings::m_displayMapperOperationType, "Display Mapper Type", "") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Aces, "Aces") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB") + ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard") + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class("MaterialViewportSettings") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Constructor() + ->Constructor() + ->Property("enableGrid", BehaviorValueProperty(&MaterialViewportSettings::m_enableGrid)) + ->Property("enableShadowCatcher", BehaviorValueProperty(&MaterialViewportSettings::m_enableShadowCatcher)) + ->Property("enableAlternateSkybox", BehaviorValueProperty(&MaterialViewportSettings::m_enableAlternateSkybox)) + ->Property("fieldOfView", BehaviorValueProperty(&MaterialViewportSettings::m_fieldOfView)) + ->Property("displayMapperOperationType", BehaviorValueProperty(&MaterialViewportSettings::m_displayMapperOperationType)) + ; + } + } +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 6e47de189c..12e75f8fcf 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -10,14 +10,15 @@ * */ -#include #include -#include -#include -#include -#include +#include #include #include +#include +#include +#include +#include +#include #include @@ -121,10 +122,24 @@ namespace MaterialEditor MaterialEditorWindowRequestBus::Handler::BusConnect(); MaterialDocumentNotificationBus::Handler::BusConnect(); OnDocumentOpened(AZ::Uuid::CreateNull()); + + auto windowState = AZ::UserSettings::Find( + AZ::Crc32("MaterialEditorWindowState"), AZ::UserSettings::CT_GLOBAL); + if (windowState) + { + windowState->RestoreGeometry(this); + } } MaterialEditorWindow::~MaterialEditorWindow() { + auto windowState = AZ::UserSettings::CreateFind( + AZ::Crc32("MaterialEditorWindowState"), AZ::UserSettings::CT_GLOBAL); + if (windowState) + { + windowState->CaptureGeometry(this); + } + MaterialDocumentNotificationBus::Handler::BusDisconnect(); MaterialEditorWindowRequestBus::Handler::BusDisconnect(); } diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp index 820cee30f9..3d796a21ad 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp @@ -10,25 +10,24 @@ * */ -#include -#include +#include +#include #include - -#include +#include +#include #include #include +#include #include - -#include -#include -#include -#include +#include +#include +#include namespace MaterialEditor { void MaterialEditorWindowComponent::Reflect(AZ::ReflectContext* context) { - GeneralViewportSettings::Reflect(context); + MaterialEditorWindowSettings::Reflect(context); if (AZ::SerializeContext* serialize = azrtti_cast(context)) { diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp new file mode 100644 index 0000000000..a9c928df10 --- /dev/null +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowSettings.cpp @@ -0,0 +1,62 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include + +namespace MaterialEditor +{ + void MaterialEditorWindowSettings::Reflect(AZ::ReflectContext* context) + { + if (auto serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Version(1) + ->Field("enableGrid", &MaterialEditorWindowSettings::m_enableGrid) + ->Field("enableShadowCatcher", &MaterialEditorWindowSettings::m_enableShadowCatcher) + ->Field("enableAlternateSkybox", &MaterialEditorWindowSettings::m_enableAlternateSkybox) + ->Field("fieldOfView", &MaterialEditorWindowSettings::m_fieldOfView) + ; + + if (auto editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "MaterialEditorWindowSettings", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableGrid, "Enable Grid", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialEditorWindowSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") + ->DataElement(AZ::Edit::UIHandlers::Slider, &MaterialEditorWindowSettings::m_fieldOfView, "Field Of View", "") + ->Attribute(AZ::Edit::Attributes::Min, 60.0f) + ->Attribute(AZ::Edit::Attributes::Max, 120.0f) + ; + } + } + + if (auto behaviorContext = azrtti_cast(context)) + { + behaviorContext->Class("MaterialEditorWindowSettings") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "render") + ->Constructor() + ->Constructor() + ->Property("enableGrid", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableGrid)) + ->Property("enableShadowCatcher", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableShadowCatcher)) + ->Property("enableAlternateSkybox", BehaviorValueProperty(&MaterialEditorWindowSettings::m_enableAlternateSkybox)) + ->Property("fieldOfView", BehaviorValueProperty(&MaterialEditorWindowSettings::m_fieldOfView)) + ; + } + } +} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp index 2af73bf436..8da7c903a2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ToolBar/MaterialEditorToolBar.cpp @@ -10,13 +10,13 @@ * */ -#include #include #include +#include #include -#include -#include -#include +#include +#include +#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include @@ -33,15 +33,16 @@ namespace MaterialEditor { AzQtComponents::ToolBar::addMainToolBarStyle(this); + AZStd::intrusive_ptr viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + // Add toggle grid button m_toggleGrid = addAction(QIcon(":/Icons/grid.svg"), "Toggle Grid"); m_toggleGrid->setCheckable(true); connect(m_toggleGrid, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_toggleGrid->isChecked()); - }); - bool enableGrid = false; - MaterialViewportRequestBus::BroadcastResult(enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); - m_toggleGrid->setChecked(enableGrid); + }); + m_toggleGrid->setChecked(viewportSettings->m_enableGrid); // Add toggle shadow catcher button m_toggleShadowCatcher = addAction(QIcon(":/Icons/shadow.svg"), "Toggle Shadow Catcher"); @@ -49,34 +50,32 @@ namespace MaterialEditor connect(m_toggleShadowCatcher, &QAction::triggered, [this]() { MaterialViewportRequestBus::Broadcast( &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_toggleShadowCatcher->isChecked()); - }); - bool enableShadowCatcher = false; - MaterialViewportRequestBus::BroadcastResult(enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); - m_toggleShadowCatcher->setChecked(enableShadowCatcher); + }); + m_toggleShadowCatcher->setChecked(viewportSettings->m_enableShadowCatcher); // Add mapping selection button - + QToolButton* toneMappingButton = new QToolButton(this); QMenu* toneMappingMenu = new QMenu(toneMappingButton); - m_operationNames = - { - { AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard" }, - { AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB" }, - { AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough" }, - { AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut" }, - { AZ::Render::DisplayMapperOperationType::Aces, "Aces" } - }; + m_operationNames = { + {AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard"}, + {AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB"}, + {AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough"}, + {AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut"}, + {AZ::Render::DisplayMapperOperationType::Aces, "Aces"}}; + for (auto operationNamePair : m_operationNames) { m_operationActions[operationNamePair.first] = toneMappingMenu->addAction(operationNamePair.second, [operationNamePair]() { MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, - operationNamePair.first); - }); + &MaterialViewportRequestBus::Events::SetDisplayMapperOperationType, operationNamePair.first); + }); m_operationActions[operationNamePair.first]->setCheckable(true); + m_operationActions[operationNamePair.first]->setChecked( + operationNamePair.first == viewportSettings->m_displayMapperOperationType); } - m_operationActions[AZ::Render::DisplayMapperOperationType::Aces]->setChecked(true); + toneMappingButton->setMenu(toneMappingMenu); toneMappingButton->setText("Tone Mapping"); toneMappingButton->setIcon(QIcon(":/Icons/toneMapping.svg")); @@ -122,4 +121,4 @@ namespace MaterialEditor } // namespace MaterialEditor -#include +#include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp index fd50ace918..22e752dddd 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.cpp @@ -26,61 +26,12 @@ namespace MaterialEditor { - void GeneralViewportSettings::Reflect(AZ::ReflectContext* context) - { - if (auto serializeContext = azrtti_cast(context)) - { - serializeContext->Class() - ->Version(1) - ->Field("enableGrid", &GeneralViewportSettings::m_enableGrid) - ->Field("enableShadowCatcher", &GeneralViewportSettings::m_enableShadowCatcher) - ->Field("enableAlternateSkybox", &GeneralViewportSettings::m_enableAlternateSkybox) - ->Field("fieldOfView", &GeneralViewportSettings::m_fieldOfView) - ->Field("displayMapperOperationType", &GeneralViewportSettings::m_displayMapperOperationType) - ; - - if (auto editContext = serializeContext->GetEditContext()) - { - editContext->Class( - "GeneralViewportSettings", "") - ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->DataElement(AZ::Edit::UIHandlers::Default, &GeneralViewportSettings::m_enableGrid, "Enable Grid", "") - ->DataElement(AZ::Edit::UIHandlers::Default, &GeneralViewportSettings::m_enableShadowCatcher, "Enable Shadow Catcher", "") - ->DataElement(AZ::Edit::UIHandlers::Default, &GeneralViewportSettings::m_enableAlternateSkybox, "Enable Alternate Skybox", "") - ->DataElement(AZ::Edit::UIHandlers::Slider, &GeneralViewportSettings::m_fieldOfView, "Field Of View", "") - ->Attribute(AZ::Edit::Attributes::Min, 60.0f) - ->Attribute(AZ::Edit::Attributes::Max, 120.0f) - ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralViewportSettings::m_displayMapperOperationType, "Display Mapper Type", "") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Aces, "Aces") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::AcesLut, "AcesLut") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Passthrough, "Passthrough") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::GammaSRGB, "GammaSRGB") - ->EnumAttribute(AZ::Render::DisplayMapperOperationType::Reinhard, "Reinhard") - ; - } - } - - if (auto behaviorContext = azrtti_cast(context)) - { - behaviorContext->Class("GeneralViewportSettings") - ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) - ->Attribute(AZ::Script::Attributes::Category, "Editor") - ->Attribute(AZ::Script::Attributes::Module, "render") - ->Constructor() - ->Constructor() - ->Property("enableGrid", BehaviorValueProperty(&GeneralViewportSettings::m_enableGrid)) - ->Property("enableShadowCatcher", BehaviorValueProperty(&GeneralViewportSettings::m_enableShadowCatcher)) - ->Property("enableAlternateSkybox", BehaviorValueProperty(&GeneralViewportSettings::m_enableAlternateSkybox)) - ->Property("fieldOfView", BehaviorValueProperty(&GeneralViewportSettings::m_fieldOfView)) - ->Property("displayMapperOperationType", BehaviorValueProperty(&GeneralViewportSettings::m_displayMapperOperationType)) - ; - } - } - ViewportSettingsInspector::ViewportSettingsInspector(QWidget* parent) : AtomToolsFramework::InspectorWidget(parent) { + m_viewportSettings = + AZ::UserSettings::CreateFind(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL); + MaterialViewportNotificationBus::Handler::BusConnect(); } @@ -109,7 +60,7 @@ namespace MaterialEditor AddGroup( groupNameId, groupDisplayName, groupDescription, - new AtomToolsFramework::InspectorPropertyGroupWidget(&m_generalSettings, nullptr, m_generalSettings.TYPEINFO_Uuid(), this)); + new AtomToolsFramework::InspectorPropertyGroupWidget(m_viewportSettings.get(), nullptr, m_viewportSettings->TYPEINFO_Uuid(), this)); } void ViewportSettingsInspector::AddModelGroup() @@ -300,13 +251,13 @@ namespace MaterialEditor m_lightingPreset.reset(); MaterialViewportRequestBus::BroadcastResult(m_lightingPreset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection); - MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); + MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled); MaterialViewportRequestBus::BroadcastResult( - m_generalSettings.m_enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); + m_viewportSettings->m_enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled); MaterialViewportRequestBus::BroadcastResult( - m_generalSettings.m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); - MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); - MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); + m_viewportSettings->m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled); + MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView); + MaterialViewportRequestBus::BroadcastResult(m_viewportSettings->m_displayMapperOperationType, &MaterialViewportRequestBus::Handler::GetDisplayMapperOperationType); AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); AtomToolsFramework::InspectorWidget::Reset(); @@ -330,31 +281,31 @@ namespace MaterialEditor void ViewportSettingsInspector::OnShadowCatcherEnabledChanged(bool enable) { - m_generalSettings.m_enableShadowCatcher = enable; + m_viewportSettings->m_enableShadowCatcher = enable; RefreshGroup("general"); } void ViewportSettingsInspector::OnGridEnabledChanged(bool enable) { - m_generalSettings.m_enableGrid = enable; + m_viewportSettings->m_enableGrid = enable; RefreshGroup("general"); } void ViewportSettingsInspector::OnAlternateSkyboxEnabledChanged(bool enable) { - m_generalSettings.m_enableAlternateSkybox = enable; + m_viewportSettings->m_enableAlternateSkybox = enable; RefreshGroup("general"); } void ViewportSettingsInspector::OnFieldOfViewChanged(float fieldOfView) { - m_generalSettings.m_fieldOfView = fieldOfView; + m_viewportSettings->m_fieldOfView = fieldOfView; RefreshGroup("general"); } void ViewportSettingsInspector::OnDisplayMapperOperationTypeChanged(AZ::Render::DisplayMapperOperationType operationType) { - m_generalSettings.m_displayMapperOperationType = operationType; + m_viewportSettings->m_displayMapperOperationType = operationType; RefreshGroup("general"); } @@ -379,13 +330,13 @@ namespace MaterialEditor { MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnLightingPresetChanged, m_lightingPreset); MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnModelPresetChanged, m_modelPreset); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_generalSettings.m_enableGrid); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, m_viewportSettings->m_enableGrid); MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_generalSettings.m_enableShadowCatcher); + &MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, m_viewportSettings->m_enableShadowCatcher); MaterialViewportRequestBus::Broadcast( - &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_generalSettings.m_enableAlternateSkybox); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_generalSettings.m_fieldOfView); - MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_generalSettings.m_displayMapperOperationType); + &MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_viewportSettings->m_enableAlternateSkybox); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_viewportSettings->m_fieldOfView); + MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetDisplayMapperOperationType, m_viewportSettings->m_displayMapperOperationType); } AZStd::string ViewportSettingsInspector::GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h index c61acb2e4c..fdfdec1458 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h @@ -14,28 +14,16 @@ #if !defined(Q_MOC_RUN) #include -#include #include #include -#include +#include +#include #include +#include #endif namespace MaterialEditor { - struct GeneralViewportSettings - { - AZ_TYPE_INFO(GeneralViewportSettings, "{16150503-A314-4765-82A3-172670C9EA90}"); - AZ_CLASS_ALLOCATOR(GeneralViewportSettings, AZ::SystemAllocator, 0); - static void Reflect(AZ::ReflectContext* context); - - bool m_enableGrid = true; - bool m_enableShadowCatcher = true; - bool m_enableAlternateSkybox = false; - float m_fieldOfView = 90.0f; - AZ::Render::DisplayMapperOperationType m_displayMapperOperationType = AZ::Render::DisplayMapperOperationType::Aces; - }; - //! Provides controls for viewing and editing a material document settings. //! The settings can be divided into cards, with each one showing a subset of properties. class ViewportSettingsInspector @@ -90,7 +78,7 @@ namespace MaterialEditor AZStd::string GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const; - GeneralViewportSettings m_generalSettings; + AZStd::intrusive_ptr m_viewportSettings; AZ::Render::ModelPresetPtr m_modelPreset; AZ::Render::LightingPresetPtr m_lightingPreset; }; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake index 845ff70cd1..e85a028005 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake @@ -13,7 +13,5 @@ set(FILES Source/main.cpp Source/MaterialEditorApplication.cpp Source/MaterialEditorApplication.h - Include/Atom/Document/MaterialDocumentModule.h - Source/Document/MaterialDocumentModule.cpp tool_dependencies.cmake ) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake index ff781e6664..cf951cf0b2 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditordocument_files.cmake @@ -14,11 +14,11 @@ set(FILES Include/Atom/Document/MaterialDocumentSystemRequestBus.h Include/Atom/Document/MaterialDocumentNotificationBus.h Include/Atom/Document/MaterialDocumentRequestBus.h - Include/Atom/Document/MaterialEditorSettingsBus.h + Include/Atom/Document/MaterialDocumentSettings.h + Source/Document/MaterialDocumentModule.cpp Source/Document/MaterialDocumentSystemComponent.cpp Source/Document/MaterialDocumentSystemComponent.h Source/Document/MaterialDocument.cpp Source/Document/MaterialDocument.h - Source/Document/MaterialEditorSettings.cpp - Source/Document/MaterialEditorSettings.h + Source/Document/MaterialDocumentSettings.cpp ) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake index e8a65c8084..6ad602e167 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorviewport_files.cmake @@ -12,6 +12,7 @@ set(FILES Include/Atom/Viewport/InputController/MaterialEditorViewportInputControllerBus.h Include/Atom/Viewport/MaterialViewportModule.h + Include/Atom/Viewport/MaterialViewportSettings.h Include/Atom/Viewport/MaterialViewportRequestBus.h Include/Atom/Viewport/MaterialViewportNotificationBus.h Include/Atom/Viewport/PerformanceMetrics.h @@ -35,6 +36,7 @@ set(FILES Source/Viewport/InputController/RotateModelBehavior.cpp Source/Viewport/InputController/RotateModelBehavior.h Source/Viewport/MaterialViewportModule.cpp + Source/Viewport/MaterialViewportSettings.cpp Source/Viewport/MaterialViewportComponent.cpp Source/Viewport/MaterialViewportComponent.h Source/Viewport/MaterialViewportWidget.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake index 1547dbf48f..52022e6e87 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditorwindow_files.cmake @@ -11,6 +11,7 @@ set(FILES Include/Atom/Window/MaterialEditorWindowModule.h + Include/Atom/Window/MaterialEditorWindowSettings.h Include/Atom/Window/MaterialEditorWindowNotificationBus.h Include/Atom/Window/MaterialEditorWindowRequestBus.h Include/Atom/Window/MaterialEditorWindowFactoryRequestBus.h @@ -19,6 +20,7 @@ set(FILES Source/Window/MaterialEditorWindow.h Source/Window/MaterialEditorWindow.cpp Source/Window/MaterialEditorWindowModule.cpp + Source/Window/MaterialEditorWindowSettings.cpp Source/Window/MaterialBrowserWidget.h Source/Window/MaterialBrowserWidget.cpp Source/Window/MaterialBrowserWidget.ui