Merge pull request #660 from aws-lumberyard-dev/Atom/guthadam/ATOM-15486

ATOM-15486 Material Editor: Implement layout and user settings
This commit is contained in:
Guthrie Adams
2021-05-11 13:09:39 -05:00
committed by GitHub
41 changed files with 1019 additions and 517 deletions
@@ -29,11 +29,13 @@ namespace AtomToolsFramework
AZ_CLASS_ALLOCATOR(InspectorGroupHeaderWidget, AZ::SystemAllocator, 0);
explicit InspectorGroupHeaderWidget(QWidget* parent = nullptr);
void SetExpanded(bool expanded);
void SetExpanded(bool expand);
bool IsExpanded() const;
Q_SIGNALS:
void clicked(QMouseEvent* event);
void expanded();
void collapsed();
protected:
void mousePressEvent(QMouseEvent* event) override;
@@ -44,6 +44,7 @@ namespace AtomToolsFramework
const AZ::Uuid& instanceClassId,
AzToolsFramework::IPropertyEditorNotify* instanceNotificationHandler = {},
QWidget* parent = {},
const AZ::u32 saveStateKey = {},
const AzToolsFramework::InstanceDataHierarchy::ValueComparisonFunction& valueComparisonFunction = {});
void Refresh() override;
@@ -56,6 +56,15 @@ namespace AtomToolsFramework
//! Calls Rebuild for all InspectorGroupWidget, allowing for destructive UI changes
virtual void RebuildAll() = 0;
//! Expands a specific group
virtual void ExpandGroup(const AZStd::string& groupNameId) = 0;
//! Collapses a specific group
virtual void CollapseGroup(const AZStd::string& groupNameId) = 0;
//! Checks the expansion state of a specific group
virtual bool IsGroupExpanded(const AZStd::string& groupNameId) const = 0;
//! Expands all groups and headers
virtual void ExpandAll() = 0;
@@ -63,15 +63,22 @@ namespace AtomToolsFramework
void RefreshAll() override;
void RebuildAll() override;
void ExpandGroup(const AZStd::string& groupNameId) override;
void CollapseGroup(const AZStd::string& groupNameId) override;
bool IsGroupExpanded(const AZStd::string& groupNameId) const override;
void ExpandAll() override;
void CollapseAll() override;
private:
void OnHeaderClicked(QMouseEvent* event, InspectorGroupHeaderWidget* groupHeader, QWidget* groupWidget);
protected:
virtual bool ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const;
virtual void OnGroupExpanded(const AZStd::string& groupNameId);
virtual void OnGroupCollapsed(const AZStd::string& groupNameId);
virtual void OnHeaderClicked(const AZStd::string& groupNameId, QMouseEvent* event);
private:
QVBoxLayout* m_layout = nullptr;
QScopedPointer<Ui::InspectorWidget> m_ui;
AZStd::vector<InspectorGroupHeaderWidget*> m_headers;
AZStd::vector<QWidget*> m_groups;
AZStd::unordered_map<AZStd::string, AZStd::pair<InspectorGroupHeaderWidget*, QWidget*>> m_groups;
};
} // namespace AtomToolsFramework
@@ -33,10 +33,21 @@ namespace AtomToolsFramework
setMargin(0);
}
void InspectorGroupHeaderWidget::SetExpanded(bool expanded)
void InspectorGroupHeaderWidget::SetExpanded(bool expand)
{
m_expanded = expanded;
update();
if (m_expanded != expand)
{
m_expanded = expand;
if (m_expanded)
{
emit expanded();
}
else
{
emit collapsed();
}
update();
}
}
bool InspectorGroupHeaderWidget::IsExpanded() const
@@ -22,6 +22,7 @@ namespace AtomToolsFramework
const AZ::Uuid& instanceClassId,
AzToolsFramework::IPropertyEditorNotify* instanceNotificationHandler,
QWidget* parent,
const AZ::u32 saveStateKey,
const AzToolsFramework::InstanceDataHierarchy::ValueComparisonFunction& valueComparisonFunction)
: InspectorGroupWidget(parent)
{
@@ -37,6 +38,7 @@ namespace AtomToolsFramework
m_propertyEditor->SetHideRootProperties(true);
m_propertyEditor->SetAutoResizeLabels(true);
m_propertyEditor->SetValueComparisonFunction(valueComparisonFunction);
m_propertyEditor->SetSavedStateKey(saveStateKey);
m_propertyEditor->Setup(context, instanceNotificationHandler, false);
m_propertyEditor->AddInstance(instance, instanceClassId, nullptr, instanceToCompare);
m_propertyEditor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
@@ -39,7 +39,6 @@ namespace AtomToolsFramework
m_layout = new QVBoxLayout(m_ui->m_propertyContent);
m_layout->setContentsMargins(0, 0, 0, 0);
m_layout->setSpacing(0);
m_headers.clear();
m_groups.clear();
}
@@ -70,16 +69,27 @@ namespace AtomToolsFramework
groupHeader->setText(groupDisplayName.c_str());
groupHeader->setToolTip(groupDescription.c_str());
m_layout->addWidget(groupHeader);
m_headers.push_back(groupHeader);
groupWidget->setObjectName(groupNameId.c_str());
groupWidget->setParent(m_ui->m_propertyContent);
m_layout->addWidget(groupWidget);
m_groups.push_back(groupWidget);
connect(groupHeader, &InspectorGroupHeaderWidget::clicked, this, [this, groupHeader, groupWidget](QMouseEvent* event) {
OnHeaderClicked(event, groupHeader, groupWidget);
m_groups[groupNameId] = AZStd::make_pair(groupHeader, groupWidget);
connect(groupHeader, &InspectorGroupHeaderWidget::clicked, this, [this, groupNameId](QMouseEvent* event) {
OnHeaderClicked(groupNameId, event);
});
connect(groupHeader, &InspectorGroupHeaderWidget::expanded, this, [this, groupNameId]() { OnGroupExpanded(groupNameId); });
connect(groupHeader, &InspectorGroupHeaderWidget::collapsed, this, [this, groupNameId]() { OnGroupCollapsed(groupNameId); });
if (ShouldGroupAutoExpanded(groupNameId))
{
ExpandGroup(groupNameId);
}
else
{
CollapseGroup(groupNameId);
}
}
void InspectorWidget::RefreshGroup(const AZStd::string& groupNameId)
@@ -114,50 +124,86 @@ namespace AtomToolsFramework
}
}
void InspectorWidget::ExpandGroup(const AZStd::string& groupNameId)
{
auto groupItr = m_groups.find(groupNameId);
if (groupItr != m_groups.end())
{
groupItr->second.first->SetExpanded(true);
groupItr->second.second->setVisible(true);
}
}
void InspectorWidget::CollapseGroup(const AZStd::string& groupNameId)
{
auto groupItr = m_groups.find(groupNameId);
if (groupItr != m_groups.end())
{
groupItr->second.first->SetExpanded(false);
groupItr->second.second->setVisible(false);
}
}
bool InspectorWidget::IsGroupExpanded(const AZStd::string& groupNameId) const
{
auto groupItr = m_groups.find(groupNameId);
return groupItr != m_groups.end() ? groupItr->second.first->IsExpanded() : false;
}
void InspectorWidget::ExpandAll()
{
for (auto headerWidget : m_headers)
for (auto& groupPair : m_groups)
{
headerWidget->SetExpanded(true);
}
for (auto groupWidget : m_groups)
{
groupWidget->setVisible(true);
groupPair.second.first->SetExpanded(true);
groupPair.second.second->setVisible(true);
}
}
void InspectorWidget::CollapseAll()
{
for (auto headerWidget : m_headers)
for (auto& groupPair : m_groups)
{
headerWidget->SetExpanded(false);
}
for (auto groupWidget : m_groups)
{
groupWidget->setVisible(false);
groupPair.second.first->SetExpanded(false);
groupPair.second.second->setVisible(false);
}
}
void InspectorWidget::OnHeaderClicked(QMouseEvent* event, InspectorGroupHeaderWidget* groupHeader, QWidget* groupWidget)
bool InspectorWidget::ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const
{
AZ_UNUSED(groupNameId);
return true;
}
void InspectorWidget::OnGroupExpanded(const AZStd::string& groupNameId)
{
AZ_UNUSED(groupNameId);
}
void InspectorWidget::OnGroupCollapsed(const AZStd::string& groupNameId)
{
AZ_UNUSED(groupNameId);
}
void InspectorWidget::OnHeaderClicked(const AZStd::string& groupNameId, QMouseEvent* event)
{
if (event->button() == Qt::MouseButton::LeftButton)
{
groupHeader->SetExpanded(!groupHeader->IsExpanded());
groupWidget->setVisible(groupHeader->IsExpanded());
if (!IsGroupExpanded(groupNameId))
{
ExpandGroup(groupNameId);
}
else
{
CollapseGroup(groupNameId);
}
return;
}
if (event->button() == Qt::MouseButton::RightButton)
{
QMenu menu;
menu.addAction("Expand", [groupHeader, groupWidget]() {
groupHeader->SetExpanded(true);
groupWidget->setVisible(true);
})->setEnabled(!groupHeader->IsExpanded());
menu.addAction("Collapse", [groupHeader, groupWidget]() {
groupHeader->SetExpanded(false);
groupWidget->setVisible(false);
})->setEnabled(groupHeader->IsExpanded());
menu.addAction("Expand", [this, groupNameId]() { ExpandGroup(groupNameId); })->setEnabled(!IsGroupExpanded(groupNameId));
menu.addAction("Collapse", [this, groupNameId]() { CollapseGroup(groupNameId); })->setEnabled(IsGroupExpanded(groupNameId));
menu.addAction("Expand All", [this]() { ExpandAll(); });
menu.addAction("Collapse All", [this]() { CollapseAll(); });
menu.exec(event->globalPos());
@@ -0,0 +1,35 @@
/*
* 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 <AzCore/Memory/Memory.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/UserSettings/UserSettings.h>
#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;
AZStd::string m_defaultMaterialTypeName = "StandardPBR";
};
} // namespace MaterialEditor
@@ -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 <AzCore/EBus/EBus.h>
#include <AzCore/std/any.h>
#include <AzCore/Outcome/Outcome.h>
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<AZStd::any> GetProperty(AZStd::string_view name) const = 0;
virtual AZ::Outcome<AZStd::string> GetStringProperty(AZStd::string_view name) const = 0;
virtual AZ::Outcome<bool> 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<MaterialEditorSettingsRequests>;
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<MaterialEditorSettingsNotifications>;
} // namespace MaterialEditor
@@ -13,7 +13,6 @@
#include <ACES/Aces.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/smart_ptr/shared_ptr.h>
#include <Atom/Feature/Utils/LightingPreset.h>
#include <Atom/Feature/Utils/ModelPreset.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 <ACES/Aces.h>
#include <AzCore/Memory/Memory.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/UserSettings/UserSettings.h>
#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
@@ -0,0 +1,35 @@
/*
* 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 <AzCore/Memory/Memory.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/RTTI/ReflectContext.h>
#include <AzCore/UserSettings/UserSettings.h>
#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);
AZStd::vector<char> m_mainWindowState;
AZStd::unordered_set<AZ::u32> m_inspectorCollapsedGroups;
};
} // namespace MaterialEditor
@@ -0,0 +1,54 @@
/*
* 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 <Atom/Document/MaterialDocumentSettings.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace MaterialEditor
{
void MaterialDocumentSettings::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<MaterialDocumentSettings, AZ::UserSettings>()
->Version(1)
->Field("showReloadDocumentPrompt", &MaterialDocumentSettings::m_showReloadDocumentPrompt)
->Field("defaultMaterialTypeName", &MaterialDocumentSettings::m_defaultMaterialTypeName)
;
if (auto editContext = serializeContext->GetEditContext())
{
editContext->Class<MaterialDocumentSettings>(
"MaterialDocumentSettings", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_showReloadDocumentPrompt, "Show Reload Document Prompt", "")
->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_defaultMaterialTypeName, "Default Material Type Name", "")
;
}
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<MaterialDocumentSettings>("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<const MaterialDocumentSettings&>()
->Property("showReloadDocumentPrompt", BehaviorValueProperty(&MaterialDocumentSettings::m_showReloadDocumentPrompt))
->Property("defaultMaterialTypeName", BehaviorValueProperty(&MaterialDocumentSettings::m_defaultMaterialTypeName))
;
}
}
} // namespace MaterialEditor
@@ -14,6 +14,7 @@
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentSettings.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/RPI.Edit/Material/MaterialSourceData.h>
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
@@ -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<AZ::SerializeContext*>(context))
{
serialize->Class<MaterialDocumentSystemComponent, AZ::Component>()
@@ -132,6 +134,7 @@ namespace MaterialEditor
void MaterialDocumentSystemComponent::Activate()
{
m_documentMap.clear();
m_settings = AZ::UserSettings::CreateFind<MaterialDocumentSettings>(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);
}
}
@@ -18,10 +18,10 @@
#include <AzCore/Asset/AssetCommon.h>
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <Atom/Document/MaterialDocumentSettings.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/RPI.Public/WindowContext.h>
#include <Document/MaterialDocument.h>
#include <Document/MaterialEditorSettings.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QFileInfo>
@@ -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<MaterialDocumentSettings> m_settings;
AZStd::unordered_map<AZ::Uuid, AZStd::shared_ptr<MaterialDocument>> m_documentMap;
AZStd::unordered_set<AZ::Uuid> m_documentIdsToRebuild;
AZStd::unordered_set<AZ::Uuid> m_documentIdsToReopen;
AZStd::unique_ptr<MaterialEditorSettings> m_settings;
const size_t m_maxMessageBoxLineCount = 15;
};
}
} // namespace MaterialEditor
@@ -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 <Document/MaterialEditorSettings.h>
namespace MaterialEditor
{
MaterialEditorSettings::MaterialEditorSettings()
{
MaterialEditorSettingsRequestBus::Handler::BusConnect();
}
MaterialEditorSettings::~MaterialEditorSettings()
{
MaterialEditorSettingsRequestBus::Handler::BusDisconnect();
}
AZ::Outcome<AZStd::any> 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<AZStd::string> MaterialEditorSettings::GetStringProperty(AZStd::string_view name) const
{
AZ::Outcome<AZStd::any> outcome = GetProperty(name);
if (!outcome || !outcome.GetValue().is<AZStd::string>())
{
return AZ::Failure();
}
return AZ::Success(AZStd::any_cast<AZStd::string>(outcome.GetValue()));
}
AZ::Outcome<bool> MaterialEditorSettings::GetBoolProperty(AZStd::string_view name) const
{
AZ::Outcome<AZStd::any> outcome = GetProperty(name);
if (!outcome || !outcome.GetValue().is<bool>())
{
return AZ::Failure();
}
return AZ::Success(AZStd::any_cast<bool>(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));
}
}
@@ -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 <AzCore/RTTI/RTTI.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/any.h>
#include <Atom/Document/MaterialEditorSettingsBus.h>
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<AZStd::any> GetProperty(AZStd::string_view name) const override;
AZ::Outcome<AZStd::string> GetStringProperty(AZStd::string_view name) const override;
AZ::Outcome<bool> 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<AZStd::string, AZStd::any> m_propertyMap;
};
} // namespace MaterialEditor
@@ -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();
}
@@ -24,6 +24,7 @@
#include <Viewport/MaterialViewportComponent.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
#include <Atom/Viewport/MaterialViewportSettings.h>
#include <Atom/ImageProcessing/ImageObject.h>
#include <Atom/ImageProcessing/ImageProcessingBus.h>
@@ -70,6 +71,8 @@ namespace MaterialEditor
void MaterialViewportComponent::Reflect(AZ::ReflectContext* context)
{
MaterialViewportSettings::Reflect(context);
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<MaterialViewportComponent, AZ::Component>()
@@ -160,6 +163,9 @@ namespace MaterialEditor
void MaterialViewportComponent::Activate()
{
m_viewportSettings =
AZ::UserSettings::CreateFind<MaterialViewportSettings>(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");
});
}
}
@@ -13,13 +13,12 @@
#pragma once
#include <ACES/Aces.h>
#include <AzCore/Component/Component.h>
#include <AzFramework/Asset/AssetCatalogBus.h>
#include <Atom/Feature/Utils/LightingPreset.h>
#include <Atom/Feature/Utils/ModelPreset.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <Atom/Viewport/MaterialViewportSettings.h>
#include <AzCore/Component/Component.h>
#include <AzFramework/Asset/AssetCatalogBus.h>
namespace MaterialEditor
{
@@ -111,10 +110,6 @@ namespace MaterialEditor
mutable AZStd::map<AZ::Render::LightingPresetPtr, AZStd::string> m_lightingPresetLastSavePathMap;
mutable AZStd::map<AZ::Render::ModelPresetPtr, AZStd::string> 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<MaterialViewportSettings> m_viewportSettings;
};
}
@@ -41,6 +41,7 @@
#include <Atom/Feature/Utils/ModelPreset.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <Atom/Viewport/PerformanceMonitorRequestBus.h>
#include <Atom/Viewport/MaterialViewportSettings.h>
#include <AtomLyIntegration/CommonFeatures/Grid/GridComponentConstants.h>
#include <AtomLyIntegration/CommonFeatures/Grid/GridComponentConfig.h>
@@ -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<AzFramework::Scene> 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<Render::DisplayMapperFeatureProcessorInterface>();
// Init Skybox
m_skyboxFeatureProcessor = m_scene->GetFeatureProcessor<AZ::Render::SkyBoxFeatureProcessorInterface>();
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<AzFramework::TransformComponent>());
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,13 +233,23 @@ namespace MaterialEditor
MaterialViewportRequestBus::BroadcastResult(modelPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection);
OnModelPresetSelected(modelPreset);
m_viewportController->Init(m_cameraEntity->GetId(), m_modelEntity->GetId(), m_iblEntity->GetId());
// Apply user settinngs restored since last run
AZStd::intrusive_ptr<MaterialViewportSettings> viewportSettings =
AZ::UserSettings::CreateFind<MaterialViewportSettings>(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();
AZ::TransformNotificationBus::MultiHandler::BusConnect(m_cameraEntity->GetId());
AzFramework::WindowSystemRequestBus::Handler::BusConnect();
m_viewportController->Init(m_cameraEntity->GetId(), m_modelEntity->GetId(), m_iblEntity->GetId());
}
MaterialViewportRenderer::~MaterialViewportRenderer()
@@ -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 <Atom/Viewport/MaterialViewportSettings.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace MaterialEditor
{
void MaterialViewportSettings::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<MaterialViewportSettings, AZ::UserSettings>()
->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>(
"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<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<MaterialViewportSettings>("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<const MaterialViewportSettings&>()
->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
@@ -21,6 +21,8 @@
#include <Atom/RPI.Edit/Material/MaterialSourceData.h>
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
#include <Atom/Document/MaterialDocumentSettings.h>
#include <QFileDialog>
namespace MaterialEditor
@@ -69,8 +71,11 @@ namespace MaterialEditor
QObject::connect(m_ui->m_materialTypeComboBox, static_cast<void (QComboBox::*)(const int)>(&QComboBox::currentIndexChanged), this, [this]() { UpdateMaterialTypeSelection(); });
QObject::connect(m_ui->m_materialTypeComboBox, &QComboBox::currentTextChanged, this, [this]() { UpdateMaterialTypeSelection(); });
// Select StandardPBR by default but we will later data drive this with editor settings
const int index = m_ui->m_materialTypeComboBox->findText("StandardPBR");
// Select the default material type from settings
auto settings =
AZ::UserSettings::CreateFind<MaterialDocumentSettings>(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL);
const int index = m_ui->m_materialTypeComboBox->findText(settings->m_defaultMaterialTypeName.c_str());
if (index >= 0)
{
m_ui->m_materialTypeComboBox->setCurrentIndex(index);
@@ -10,45 +10,51 @@
*
*/
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzFramework/Application/Application.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/PythonTerminal/ScriptTermDialog.h>
#include <AzQtComponents/Components/StyleManager.h>
#include <AzQtComponents/Utilities/QtPluginPaths.h>
#include <AtomToolsFramework/Util/Util.h>
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/Window/MaterialEditorWindowNotificationBus.h>
#include <Atom/RHI/Factory.h>
#include <Atom/RPI.Edit/Common/AssetUtils.h>
#include <Atom/RPI.Edit/Common/JsonUtils.h>
#include <Atom/RPI.Edit/Material/MaterialSourceData.h>
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
#include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/Window/MaterialEditorWindowNotificationBus.h>
#include <Atom/Window/MaterialEditorWindowSettings.h>
#include <AtomToolsFramework/Util/Util.h>
#include <AzFramework/Application/Application.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzQtComponents/Components/StyleManager.h>
#include <AzQtComponents/Components/WindowDecorationWrapper.h>
#include <AzQtComponents/Utilities/QtPluginPaths.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/PythonTerminal/ScriptTermDialog.h>
#include <Viewport/MaterialViewportWidget.h>
#include <Viewport/MaterialViewportWidget.h>
#include <Window/MaterialEditorWindow.h>
#include <Window/PerformanceMonitor/PerformanceMonitorWidget.h>
#include <Window/HelpDialog/HelpDialog.h>
#include <Window/MaterialBrowserWidget.h>
#include <Window/MaterialInspector/MaterialInspector.h>
#include <Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
#include <Window/CreateMaterialDialog/CreateMaterialDialog.h>
#include <Window/HelpDialog/HelpDialog.h>
#include <Window/SettingsDialog/SettingsDialog.h>
#include <Window/MaterialBrowserWidget.h>
#include <Window/MaterialEditorWindow.h>
#include <Window/MaterialInspector/MaterialInspector.h>
#include <Window/PerformanceMonitor/PerformanceMonitorWidget.h>
#include <Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QApplication>
#include <QByteArray>
#include <QCloseEvent>
#include <QVariant>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QWindow>
#include <QVBoxLayout>
#include <QVariant>
#include <QWindow>
AZ_POP_DISABLE_WARNING
namespace MaterialEditor
@@ -56,6 +62,15 @@ namespace MaterialEditor
MaterialEditorWindow::MaterialEditorWindow(QWidget* parent /* = 0 */)
: AzQtComponents::DockMainWindow(parent)
{
resize(1280, 1024);
// Among other things, we need the window wrapper to save the main window size, position, and state
auto mainWindowWrapper =
new AzQtComponents::WindowDecorationWrapper(AzQtComponents::WindowDecorationWrapper::OptionAutoTitleBarButtons);
mainWindowWrapper->setGuest(this);
mainWindowWrapper->enableSaveRestoreGeometry("amazon", "MaterialEditor", "mainWindowGeometry");
// set the style sheet for RPE highlighting and other styling
AzQtComponents::StyleManager::setStyleSheet(this, QStringLiteral(":/MaterialEditor.qss"));
QApplication::setWindowIcon(QIcon(":/Icons/materialtype.svg"));
@@ -74,6 +89,7 @@ namespace MaterialEditor
m_advancedDockManager = new AzQtComponents::FancyDocking(this);
setObjectName("MaterialEditorWindow");
setDockNestingEnabled(true);
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
@@ -81,17 +97,21 @@ namespace MaterialEditor
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
m_menuBar = new QMenuBar(this);
m_menuBar->setObjectName("MenuBar");
setMenuBar(m_menuBar);
m_toolBar = new MaterialEditorToolBar(this);
m_toolBar->setObjectName("ToolBar");
addToolBar(m_toolBar);
m_centralWidget = new QWidget(this);
m_tabWidget = new AzQtComponents::TabWidget(m_centralWidget);
m_tabWidget->setObjectName("TabWidget");
m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
m_tabWidget->setContentsMargins(0, 0, 0, 0);
m_materialViewport = new MaterialViewportWidget(m_centralWidget);
m_materialViewport->setObjectName("Viewport");
m_materialViewport->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
QVBoxLayout* vl = new QVBoxLayout(m_centralWidget);
@@ -103,7 +123,8 @@ namespace MaterialEditor
setCentralWidget(m_centralWidget);
m_statusBar = new StatusBarWidget(this);
this->statusBar()->addPermanentWidget(m_statusBar, 1);
m_statusBar->setObjectName("StatusBar");
statusBar()->addPermanentWidget(m_statusBar, 1);
SetupMenu();
SetupTabs();
@@ -118,6 +139,19 @@ namespace MaterialEditor
SetDockWidgetVisible("Performance Monitor", false);
SetDockWidgetVisible("Python Terminal", false);
// Restore geometry and show the window
mainWindowWrapper->showFromSettings();
// Restore additional state for docked windows
auto windowSettings = AZ::UserSettings::CreateFind<MaterialEditorWindowSettings>(
AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL);
if (!windowSettings->m_mainWindowState.empty())
{
QByteArray windowState(windowSettings->m_mainWindowState.data(), windowSettings->m_mainWindowState.size());
m_advancedDockManager->restoreState(windowState);
}
MaterialEditorWindowRequestBus::Handler::BusConnect();
MaterialDocumentNotificationBus::Handler::BusConnect();
OnDocumentOpened(AZ::Uuid::CreateNull());
@@ -144,8 +178,9 @@ namespace MaterialEditor
}
auto dockWidget = new AzQtComponents::StyledDockWidget(name.c_str());
dockWidget->setObjectName(name.c_str());
dockWidget->setObjectName(QString("%1_DockWidget").arg(name.c_str()));
dockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
widget->setObjectName(name.c_str());
widget->setParent(dockWidget);
widget->setMinimumSize(QSize(300, 300));
dockWidget->setWidget(widget);
@@ -203,15 +238,16 @@ namespace MaterialEditor
QSize requestedWindowSize = size() + offset;
resize(requestedWindowSize);
AZ_Assert(m_materialViewport->size() == requestedViewportSize,
AZ_Assert(
m_materialViewport->size() == requestedViewportSize,
"Resizing the window did not give the expected viewport size. Requested %d x %d but got %d x %d.",
requestedViewportSize.width(), requestedViewportSize.height(),
m_materialViewport->size().width(), m_materialViewport->size().height());
requestedViewportSize.width(), requestedViewportSize.height(), m_materialViewport->size().width(),
m_materialViewport->size().height());
QSize newDeviceSize = m_materialViewport->size();
AZ_Warning("Material Editor", newDeviceSize.width() == width && newDeviceSize.height() == height,
"Resizing the window did not give the expected frame size. Requested %d x %d but got %d x %d.",
width, height,
AZ_Warning(
"Material Editor", newDeviceSize.width() == width && newDeviceSize.height() == height,
"Resizing the window did not give the expected frame size. Requested %d x %d but got %d x %d.", width, height,
newDeviceSize.width(), newDeviceSize.height());
}
@@ -235,6 +271,13 @@ namespace MaterialEditor
return;
}
// Capture docking state before shutdown
auto windowSettings = AZ::UserSettings::CreateFind<MaterialEditorWindowSettings>(
AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL);
QByteArray windowState = m_advancedDockManager->saveState();
windowSettings->m_mainWindowState.assign(windowState.begin(), windowState.end());
MaterialEditorWindowNotificationBus::Broadcast(&MaterialEditorWindowNotifications::OnMaterialEditorWindowClosing);
}
@@ -272,7 +315,7 @@ namespace MaterialEditor
m_actionUndo->setEnabled(canUndo);
m_actionRedo->setEnabled(canRedo);
m_actionPreferences->setEnabled(false);
m_actionSettings->setEnabled(true);
m_actionAssetBrowser->setEnabled(true);
m_actionInspector->setEnabled(true);
@@ -465,9 +508,11 @@ namespace MaterialEditor
m_menuEdit->addSeparator();
m_actionPreferences = m_menuEdit->addAction("&Preferences...", [this]() {
m_actionSettings = m_menuEdit->addAction("&Settings...", [this]() {
SettingsDialog dialog(this);
dialog.exec();
}, QKeySequence::Preferences);
m_actionPreferences->setEnabled(false);
m_actionSettings->setEnabled(true);
m_menuView = m_menuBar->addMenu("&View");
@@ -512,8 +557,8 @@ namespace MaterialEditor
m_menuHelp = m_menuBar->addMenu("&Help");
m_actionHelp = m_menuHelp->addAction("&Help...", [this]() {
HelpDialog dlg(this);
dlg.exec();
HelpDialog dialog(this);
dialog.exec();
});
m_actionAbout = m_menuHelp->addAction("&About...", [this]() {
@@ -119,7 +119,7 @@ namespace MaterialEditor
QMenu* m_menuEdit = {};
QAction* m_actionUndo = {};
QAction* m_actionRedo = {};
QAction* m_actionPreferences = {};
QAction* m_actionSettings = {};
QMenu* m_menuView = {};
QAction* m_actionAssetBrowser = {};
@@ -10,25 +10,24 @@
*
*/
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <Atom/Window/MaterialEditorWindowFactoryRequestBus.h>
#include <Atom/Window/MaterialEditorWindowSettings.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzToolsFramework/API/ViewPaneOptions.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/API/ViewPaneOptions.h>
#include <AzToolsFramework/UI/UICore/QWidgetSavedState.h>
#include <Atom/Window/MaterialEditorWindowFactoryRequestBus.h>
#include <Source/Window/MaterialEditorWindowComponent.h>
#include <Source/Window/MaterialEditorWindow.h>
#include <Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
#include <Window/MaterialEditorWindow.h>
#include <Window/MaterialEditorWindowComponent.h>
#include <Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
namespace MaterialEditor
{
void MaterialEditorWindowComponent::Reflect(AZ::ReflectContext* context)
{
GeneralViewportSettings::Reflect(context);
MaterialEditorWindowSettings::Reflect(context);
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
@@ -102,7 +101,6 @@ namespace MaterialEditor
m_materialEditorBrowserInteractions.reset(aznew MaterialEditorBrowserInteractions);
m_window.reset(aznew MaterialEditorWindow);
m_window->show();
}
void MaterialEditorWindowComponent::DestroyMaterialEditorWindow()
@@ -0,0 +1,50 @@
/*
* 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 <Atom/Window/MaterialEditorWindowSettings.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
namespace MaterialEditor
{
void MaterialEditorWindowSettings::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<MaterialEditorWindowSettings, AZ::UserSettings>()
->Version(1)
->Field("mainWindowState", &MaterialEditorWindowSettings::m_mainWindowState)
->Field("inspectorCollapsedGroups", &MaterialEditorWindowSettings::m_inspectorCollapsedGroups)
;
if (auto editContext = serializeContext->GetEditContext())
{
editContext->Class<MaterialEditorWindowSettings>(
"MaterialEditorWindowSettings", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
;
}
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<MaterialEditorWindowSettings>("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<const MaterialEditorWindowSettings&>()
;
}
}
} // namespace MaterialEditor
@@ -1,14 +1,14 @@
/*
* 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.
*
*/
* 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 <Atom/RPI.Edit/Common/AssetUtils.h>
#include <Atom/RPI.Edit/Material/MaterialPropertyId.h>
@@ -21,13 +21,16 @@
#include <AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h>
#include <AtomToolsFramework/Util/MaterialPropertyUtil.h>
#include <Source/Window/MaterialInspector/MaterialInspector.h>
#include <Window/MaterialInspector/MaterialInspector.h>
namespace MaterialEditor
{
MaterialInspector::MaterialInspector(QWidget* parent)
: AtomToolsFramework::InspectorWidget(parent)
{
m_windowSettings = AZ::UserSettings::CreateFind<MaterialEditorWindowSettings>(
AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL);
MaterialDocumentNotificationBus::Handler::BusConnect();
}
@@ -39,6 +42,7 @@ namespace MaterialEditor
void MaterialInspector::Reset()
{
m_documentPath.clear();
m_documentId = AZ::Uuid::CreateNull();
m_groups = {};
@@ -46,6 +50,22 @@ namespace MaterialEditor
AtomToolsFramework::InspectorWidget::Reset();
}
bool MaterialInspector::ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const
{
auto stateItr = m_windowSettings->m_inspectorCollapsedGroups.find(GetGroupSaveStateKey(groupNameId));
return stateItr == m_windowSettings->m_inspectorCollapsedGroups.end();
}
void MaterialInspector::OnGroupExpanded(const AZStd::string& groupNameId)
{
m_windowSettings->m_inspectorCollapsedGroups.erase(GetGroupSaveStateKey(groupNameId));
}
void MaterialInspector::OnGroupCollapsed(const AZStd::string& groupNameId)
{
m_windowSettings->m_inspectorCollapsedGroups.insert(GetGroupSaveStateKey(groupNameId));
}
void MaterialInspector::OnDocumentOpened(const AZ::Uuid& documentId)
{
AddGroupsBegin();
@@ -55,6 +75,8 @@ namespace MaterialEditor
bool isOpen = false;
MaterialDocumentRequestBus::EventResult(isOpen, m_documentId, &MaterialDocumentRequestBus::Events::IsOpen);
MaterialDocumentRequestBus::EventResult(m_documentPath, m_documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath);
if (!m_documentId.IsNull() && isOpen)
{
// Create the top group for displaying details about the material
@@ -70,10 +92,24 @@ namespace MaterialEditor
AddGroupsEnd();
}
AZ::Crc32 MaterialInspector::GetGroupSaveStateKey(const AZStd::string& groupNameId) const
{
return AZ::Crc32(AZStd::string::format("MaterialInspector::PropertyGroup::%s::%s", m_documentPath.c_str(), groupNameId.c_str()));
}
bool MaterialInspector::CompareInstanceNodeProperties(
const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) const
{
AZ_UNUSED(source);
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target);
return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue);
}
void MaterialInspector::AddDetailsGroup()
{
const AZ::RPI::MaterialTypeSourceData* materialTypeSourceData = nullptr;
MaterialDocumentRequestBus::EventResult(materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData);
MaterialDocumentRequestBus::EventResult(
materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData);
const AZStd::string groupNameId = "details";
const AZStd::string groupDisplayName = "Details";
@@ -81,20 +117,19 @@ namespace MaterialEditor
auto& group = m_groups[groupNameId];
AtomToolsFramework::DynamicProperty property;
MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.materialType"));
MaterialDocumentRequestBus::EventResult(
property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.materialType"));
group.m_properties.push_back(property);
property = {};
MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.parentMaterial"));
MaterialDocumentRequestBus::EventResult(
property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::Name("details.parentMaterial"));
group.m_properties.push_back(property);
// Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this,
[this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) {
AZ_UNUSED(source);
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target);
return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue);
});
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
&group, &group, group.TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId),
[this](const auto source, const auto target) { return CompareInstanceNodeProperties(source, target); });
AddGroup(groupNameId, groupDisplayName, groupDescription, propertyGroupWidget);
}
@@ -114,32 +149,33 @@ namespace MaterialEditor
for (const auto& uvNamePair : uvNameMap)
{
AtomToolsFramework::DynamicProperty property;
MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::RPI::MaterialPropertyId(groupNameId, uvNamePair.m_shaderInput.ToString()).GetFullName());
MaterialDocumentRequestBus::EventResult(
property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty,
AZ::RPI::MaterialPropertyId(groupNameId, uvNamePair.m_shaderInput.ToString()).GetFullName());
group.m_properties.push_back(property);
property.SetValue(property.GetConfig().m_parentValue);
}
// Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this,
[this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) {
AZ_UNUSED(source);
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target);
return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue);
});
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
&group, &group, group.TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId),
[this](const auto source, const auto target) { return CompareInstanceNodeProperties(source, target); });
AddGroup(groupNameId, groupDisplayName, groupDescription, propertyGroupWidget);
}
void MaterialInspector::AddPropertiesGroup()
{
const AZ::RPI::MaterialTypeSourceData* materialTypeSourceData = nullptr;
MaterialDocumentRequestBus::EventResult(materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData);
MaterialDocumentRequestBus::EventResult(
materialTypeSourceData, m_documentId, &MaterialDocumentRequestBus::Events::GetMaterialTypeSourceData);
for (const auto& groupDefinition : materialTypeSourceData->GetGroupDefinitionsInDisplayOrder())
{
const AZStd::string& groupNameId = groupDefinition.m_nameId;
const AZStd::string& groupDisplayName = !groupDefinition.m_displayName.empty() ? groupDefinition.m_displayName : groupNameId;
const AZStd::string& groupDescription = !groupDefinition.m_description.empty() ? groupDefinition.m_description : groupDisplayName;
const AZStd::string& groupDescription =
!groupDefinition.m_description.empty() ? groupDefinition.m_description : groupDisplayName;
auto& group = m_groups[groupNameId];
const auto& propertyLayout = materialTypeSourceData->m_propertyLayout;
@@ -150,18 +186,17 @@ namespace MaterialEditor
for (const auto& propertyDefinition : propertyListItr->second)
{
AtomToolsFramework::DynamicProperty property;
MaterialDocumentRequestBus::EventResult(property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty, AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName());
MaterialDocumentRequestBus::EventResult(
property, m_documentId, &MaterialDocumentRequestBus::Events::GetProperty,
AZ::RPI::MaterialPropertyId(groupNameId, propertyDefinition.m_nameId).GetFullName());
group.m_properties.push_back(property);
}
}
// Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this,
[this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) {
AZ_UNUSED(source);
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target);
return property && AtomToolsFramework::ArePropertyValuesEqual(property->GetValue(), property->GetConfig().m_parentValue);
});
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
&group, &group, group.TYPEINFO_Uuid(), this, this, GetGroupSaveStateKey(groupNameId),
[this](const auto source, const auto target) { return CompareInstanceNodeProperties(source, target); });
AddGroup(groupNameId, groupDisplayName, groupDescription, propertyGroupWidget);
}
}
@@ -177,7 +212,8 @@ namespace MaterialEditor
if (!AtomToolsFramework::ArePropertyValuesEqual(reflectedProperty.GetValue(), property.GetValue()))
{
reflectedProperty.SetValue(property.GetValue());
AtomToolsFramework::InspectorRequestBus::Event(documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first);
AtomToolsFramework::InspectorRequestBus::Event(
documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first);
}
return;
}
@@ -185,7 +221,8 @@ namespace MaterialEditor
}
}
void MaterialInspector::OnDocumentPropertyConfigModified(const AZ::Uuid& documentId, const AtomToolsFramework::DynamicProperty& property)
void MaterialInspector::OnDocumentPropertyConfigModified(
const AZ::Uuid& documentId, const AtomToolsFramework::DynamicProperty& property)
{
for (auto& groupPair : m_groups)
{
@@ -197,12 +234,14 @@ namespace MaterialEditor
if (reflectedProperty.GetVisibility() != property.GetVisibility())
{
reflectedProperty.SetConfig(property.GetConfig());
AtomToolsFramework::InspectorRequestBus::Event(documentId, &AtomToolsFramework::InspectorRequestBus::Events::RebuildGroup, groupPair.first);
AtomToolsFramework::InspectorRequestBus::Event(
documentId, &AtomToolsFramework::InspectorRequestBus::Events::RebuildGroup, groupPair.first);
}
else
{
reflectedProperty.SetConfig(property.GetConfig());
AtomToolsFramework::InspectorRequestBus::Event(documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first);
AtomToolsFramework::InspectorRequestBus::Event(
documentId, &AtomToolsFramework::InspectorRequestBus::Events::RefreshGroup, groupPair.first);
}
return;
}
@@ -214,7 +253,8 @@ namespace MaterialEditor
{
// For some reason the reflected property editor notifications are not symmetrical
// This function is called continuously anytime a property changes until the edit has completed
// Because of that, we have to track whether or not we are continuing to edit the same property to know when editing has started and ended
// Because of that, we have to track whether or not we are continuing to edit the same property to know when editing has started and
// ended
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(pNode);
if (property)
{
@@ -233,23 +273,24 @@ namespace MaterialEditor
{
if (m_activeProperty == property)
{
MaterialDocumentRequestBus::Event(m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue,
property->GetId(), property->GetValue());
MaterialDocumentRequestBus::Event(
m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue, property->GetId(), property->GetValue());
}
}
}
void MaterialInspector::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode)
{
// As above, there are symmetrical functions on the notification interface for when editing begins and ends and has been completed but they are not being called following that pattern.
// when this function executes the changes to the property are ready to be committed or reverted
// As above, there are symmetrical functions on the notification interface for when editing begins and ends and has been completed
// but they are not being called following that pattern. when this function executes the changes to the property are ready to be
// committed or reverted
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(pNode);
if (property)
{
if (m_activeProperty == property)
{
MaterialDocumentRequestBus::Event(m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue,
property->GetId(), property->GetValue());
MaterialDocumentRequestBus::Event(
m_documentId, &MaterialDocumentRequestBus::Events::SetPropertyValue, property->GetId(), property->GetValue());
MaterialDocumentRequestBus::Event(m_documentId, &MaterialDocumentRequestBus::Events::EndEdit);
m_activeProperty = nullptr;
@@ -258,4 +299,4 @@ namespace MaterialEditor
}
} // namespace MaterialEditor
#include <Source/Window/MaterialInspector/moc_MaterialInspector.cpp>
#include <Window/MaterialInspector/moc_MaterialInspector.cpp>
@@ -20,6 +20,7 @@
#include <AtomToolsFramework/Inspector/InspectorWidget.h>
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <Atom/Window/MaterialEditorWindowSettings.h>
#endif
namespace MaterialEditor
@@ -41,7 +42,16 @@ namespace MaterialEditor
// AtomToolsFramework::InspectorRequestBus::Handler overrides...
void Reset() override;
protected:
bool ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const override;
void OnGroupExpanded(const AZStd::string& groupNameId) override;
void OnGroupCollapsed(const AZStd::string& groupNameId) override;
private:
AZ::Crc32 GetGroupSaveStateKey(const AZStd::string& groupNameId) const;
bool CompareInstanceNodeProperties(
const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) const;
void AddDetailsGroup();
void AddUvNamesGroup();
void AddPropertiesGroup();
@@ -64,6 +74,8 @@ namespace MaterialEditor
const AtomToolsFramework::DynamicProperty* m_activeProperty = nullptr;
AZ::Uuid m_documentId = AZ::Uuid::CreateNull();
AZStd::string m_documentPath;
AZStd::unordered_map<AZStd::string, AtomToolsFramework::DynamicPropertyGroup> m_groups;
AZStd::intrusive_ptr<MaterialEditorWindowSettings> m_windowSettings;
};
} // namespace MaterialEditor
@@ -0,0 +1,43 @@
/*
* 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 <Window/SettingsDialog/SettingsDialog.h>
#include <Window/SettingsDialog/SettingsWidget.h>
#include <QDialogButtonBox>
#include <QVBoxLayout>
namespace MaterialEditor
{
SettingsDialog::SettingsDialog(QWidget* parent)
: QDialog(parent)
{
setWindowTitle("Material Editor Settings");
setFixedSize(600, 300);
setLayout(new QVBoxLayout(this));
auto settingsWidget = new SettingsWidget(this);
settingsWidget->Populate();
layout()->addWidget(settingsWidget);
// Create the bottom row of the dialog with action buttons
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, this);
layout()->addWidget(buttonBox);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
setModal(true);
}
} // namespace MaterialEditor
//#include <Window/SettingsDialog/moc_SettingsDialog.cpp>
@@ -0,0 +1,27 @@
/*
* 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 <QDialog>
namespace MaterialEditor
{
class SettingsDialog
: public QDialog
{
Q_OBJECT
public:
SettingsDialog(QWidget* parent = nullptr);
~SettingsDialog() = default;
};
} // namespace MaterialEditor
@@ -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 <Window/SettingsDialog/SettingsWidget.h>
#include <AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h>
namespace MaterialEditor
{
SettingsWidget::SettingsWidget(QWidget* parent)
: AtomToolsFramework::InspectorWidget(parent)
{
m_documentSettings =
AZ::UserSettings::CreateFind<MaterialDocumentSettings>(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL);
}
SettingsWidget::~SettingsWidget()
{
AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect();
}
void SettingsWidget::Populate()
{
AddGroupsBegin();
AddDocumentGroup();
AddGroupsEnd();
}
void SettingsWidget::AddDocumentGroup()
{
const AZStd::string groupNameId = "documentSettings";
const AZStd::string groupDisplayName = "Document Settings";
const AZStd::string groupDescription = "Document Settings";
const AZ::Crc32 saveStateKey(AZStd::string::format("SettingsWidget::DocumentGroup"));
AddGroup(
groupNameId, groupDisplayName, groupDescription,
new AtomToolsFramework::InspectorPropertyGroupWidget(
m_documentSettings.get(), nullptr, m_documentSettings->TYPEINFO_Uuid(), this, this, saveStateKey));
}
void SettingsWidget::Reset()
{
AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect();
AtomToolsFramework::InspectorWidget::Reset();
}
void SettingsWidget::BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode)
{
AZ_UNUSED(pNode);
}
void SettingsWidget::AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode)
{
AZ_UNUSED(pNode);
}
void SettingsWidget::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode)
{
AZ_UNUSED(pNode);
}
} // namespace MaterialEditor
//#include <Window/SettingsWidget/moc_SettingsWidget.cpp>
@@ -0,0 +1,54 @@
/*
* 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 <Atom/Document/MaterialDocumentSettings.h>
#include <AtomToolsFramework/Inspector/InspectorWidget.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI_Internals.h>
#endif
namespace MaterialEditor
{
//! Provides controls for viewing and editing settings.
class SettingsWidget
: public AtomToolsFramework::InspectorWidget
, private AzToolsFramework::IPropertyEditorNotify
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(SettingsWidget, AZ::SystemAllocator, 0);
explicit SettingsWidget(QWidget* parent = nullptr);
~SettingsWidget() override;
void Populate();
private:
void AddDocumentGroup();
// AtomToolsFramework::InspectorRequestBus::Handler overrides...
void Reset() override;
// AzToolsFramework::IPropertyEditorNotify overrides...
void BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) override;
void AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode) override;
void SetPropertyEditingActive([[maybe_unused]] AzToolsFramework::InstanceDataNode* pNode) override {}
void SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) override;
void SealUndoStack() override {}
void RequestPropertyContextMenu(AzToolsFramework::InstanceDataNode*, const QPoint&) override {}
void PropertySelectionChanged(AzToolsFramework::InstanceDataNode*, bool) override {}
AZStd::intrusive_ptr<MaterialDocumentSettings> m_documentSettings;
};
} // namespace MaterialEditor
@@ -10,13 +10,13 @@
*
*/
#include <Atom/Document/MaterialEditorSettingsBus.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <Atom/Viewport/MaterialViewportSettings.h>
#include <AzCore/std/containers/vector.h>
#include <Source/Window/ToolBar/LightingPresetComboBox.h>
#include <Source/Window/ToolBar/MaterialEditorToolBar.h>
#include <Source/Window/ToolBar/ModelPresetComboBox.h>
#include <Window/ToolBar/LightingPresetComboBox.h>
#include <Window/ToolBar/MaterialEditorToolBar.h>
#include <Window/ToolBar/ModelPresetComboBox.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <AzQtComponents/Components/Widgets/ToolBar.h>
@@ -33,15 +33,16 @@ namespace MaterialEditor
{
AzQtComponents::ToolBar::addMainToolBarStyle(this);
AZStd::intrusive_ptr<MaterialViewportSettings> viewportSettings =
AZ::UserSettings::CreateFind<MaterialViewportSettings>(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 <Source/Window/ToolBar/moc_MaterialEditorToolBar.cpp>
#include <Window/ToolBar/moc_MaterialEditorToolBar.cpp>
@@ -1,86 +1,40 @@
/*
* 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.
*
*/
* 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 <Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <AtomToolsFramework/Inspector/InspectorPropertyGroupWidget.h>
#include <AtomToolsFramework/Util/Util.h>
#include <Window/PresetBrowserDialogs/LightingPresetBrowserDialog.h>
#include <Window/PresetBrowserDialogs/ModelPresetBrowserDialog.h>
#include <Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
#include <QAction>
#include <QApplication>
#include <QHBoxLayout>
#include <QPushButton>
#include <QToolButton>
#include <QAction>
#include <QHBoxLayout>
#include <QVBoxLayout>
namespace MaterialEditor
{
void GeneralViewportSettings::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<GeneralViewportSettings>()
->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>(
"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<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<GeneralViewportSettings>("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<const GeneralViewportSettings&>()
->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<MaterialViewportSettings>(AZ::Crc32("MaterialViewportSettings"), AZ::UserSettings::CT_GLOBAL);
m_windowSettings = AZ::UserSettings::CreateFind<MaterialEditorWindowSettings>(
AZ::Crc32("MaterialEditorWindowSettings"), AZ::UserSettings::CT_GLOBAL);
MaterialViewportNotificationBus::Handler::BusConnect();
}
@@ -92,7 +46,7 @@ namespace MaterialEditor
AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect();
}
void ViewportSettingsInspector::Popuate()
void ViewportSettingsInspector::Populate()
{
AddGroupsBegin();
AddGeneralGroup();
@@ -103,20 +57,21 @@ namespace MaterialEditor
void ViewportSettingsInspector::AddGeneralGroup()
{
const AZStd::string groupNameId = "general";
const AZStd::string groupDisplayName = "General";
const AZStd::string groupDescription = "General";
const AZStd::string groupNameId = "generalSettings";
const AZStd::string groupDisplayName = "General Settings";
const AZStd::string groupDescription = "General Settings";
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, this, GetGroupSaveStateKey(groupNameId)));
}
void ViewportSettingsInspector::AddModelGroup()
{
const AZStd::string groupNameId = "model";
const AZStd::string groupDisplayName = "Model";
const AZStd::string groupDescription = "Model";
const AZStd::string groupNameId = "modelSettings";
const AZStd::string groupDisplayName = "Model Settings";
const AZStd::string groupDescription = "Model Settings";
auto groupWidget = new QWidget(this);
auto buttonGroupWidget = new QWidget(groupWidget);
@@ -142,7 +97,7 @@ namespace MaterialEditor
if (m_modelPreset)
{
auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this, groupWidget);
m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this, groupWidget, GetGroupSaveStateKey(groupNameId));
groupWidget->layout()->addWidget(inspectorWidget);
}
@@ -201,9 +156,9 @@ namespace MaterialEditor
void ViewportSettingsInspector::AddLightingGroup()
{
const AZStd::string groupNameId = "lighting";
const AZStd::string groupDisplayName = "Lighting";
const AZStd::string groupDescription = "Lighting";
const AZStd::string groupNameId = "lightingSettings";
const AZStd::string groupDisplayName = "Lighting Settings";
const AZStd::string groupDescription = "Lighting Settings";
auto groupWidget = new QWidget(this);
auto buttonGroupWidget = new QWidget(groupWidget);
@@ -229,7 +184,8 @@ namespace MaterialEditor
if (m_lightingPreset)
{
auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this, groupWidget);
m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this, groupWidget,
GetGroupSaveStateKey(groupNameId));
groupWidget->layout()->addWidget(inspectorWidget);
}
@@ -247,8 +203,7 @@ namespace MaterialEditor
AZ::Render::LightingPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(
preset, &MaterialViewportRequestBus::Events::AddLightingPreset, AZ::Render::LightingPreset());
MaterialViewportRequestBus::Broadcast(
&MaterialViewportRequestBus::Events::SaveLightingPreset, preset, savePath);
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveLightingPreset, preset, savePath);
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectLightingPreset, preset);
}
}
@@ -272,7 +227,8 @@ namespace MaterialEditor
MaterialViewportRequestBus::BroadcastResult(preset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection);
AZStd::string defaultPath;
MaterialViewportRequestBus::BroadcastResult(defaultPath, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset);
MaterialViewportRequestBus::BroadcastResult(
defaultPath, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset);
if (defaultPath.empty())
{
@@ -300,13 +256,15 @@ 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();
@@ -316,7 +274,7 @@ namespace MaterialEditor
{
if (m_lightingPreset != preset)
{
Popuate();
Populate();
}
}
@@ -324,37 +282,37 @@ namespace MaterialEditor
{
if (m_modelPreset != preset)
{
Popuate();
Populate();
}
}
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 +337,14 @@ 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
@@ -398,6 +357,28 @@ namespace MaterialEditor
savePath = AtomToolsFramework::GetUniqueFileInfo(savePath.c_str()).absoluteFilePath().toUtf8().constData();
return savePath;
}
AZ::Crc32 ViewportSettingsInspector::GetGroupSaveStateKey(const AZStd::string& groupNameId) const
{
return AZ::Crc32(AZStd::string::format("ViewportSettingsInspector::PropertyGroup::%s", groupNameId.c_str()));
}
bool ViewportSettingsInspector::ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const
{
auto stateItr = m_windowSettings->m_inspectorCollapsedGroups.find(GetGroupSaveStateKey(groupNameId));
return stateItr == m_windowSettings->m_inspectorCollapsedGroups.end();
}
void ViewportSettingsInspector::OnGroupExpanded(const AZStd::string& groupNameId)
{
m_windowSettings->m_inspectorCollapsedGroups.erase(GetGroupSaveStateKey(groupNameId));
}
void ViewportSettingsInspector::OnGroupCollapsed(const AZStd::string& groupNameId)
{
m_windowSettings->m_inspectorCollapsedGroups.insert(GetGroupSaveStateKey(groupNameId));
}
} // namespace MaterialEditor
#include <Source/Window/ViewportSettingsInspector/moc_ViewportSettingsInspector.cpp>
@@ -14,28 +14,17 @@
#if !defined(Q_MOC_RUN)
#include <ACES/Aces.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
#include <Atom/Feature/Utils/LightingPreset.h>
#include <Atom/Feature/Utils/ModelPreset.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI_Internals.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
#include <Atom/Viewport/MaterialViewportSettings.h>
#include <Atom/Window/MaterialEditorWindowSettings.h>
#include <AtomToolsFramework/Inspector/InspectorWidget.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI_Internals.h>
#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
@@ -51,7 +40,7 @@ namespace MaterialEditor
~ViewportSettingsInspector() override;
private:
void Popuate();
void Populate();
void AddGeneralGroup();
void AddModelGroup();
@@ -90,8 +79,14 @@ namespace MaterialEditor
AZStd::string GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const;
GeneralViewportSettings m_generalSettings;
AZ::Crc32 GetGroupSaveStateKey(const AZStd::string& groupNameId) const;
bool ShouldGroupAutoExpanded(const AZStd::string& groupNameId) const override;
void OnGroupExpanded(const AZStd::string& groupNameId) override;
void OnGroupCollapsed(const AZStd::string& groupNameId) override;
AZ::Render::ModelPresetPtr m_modelPreset;
AZ::Render::LightingPresetPtr m_lightingPreset;
AZStd::intrusive_ptr<MaterialViewportSettings> m_viewportSettings;
AZStd::intrusive_ptr<MaterialEditorWindowSettings> m_windowSettings;
};
} // namespace MaterialEditor
@@ -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
)
@@ -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
)
@@ -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
@@ -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
@@ -26,6 +28,10 @@ set(FILES
Source/Window/MaterialEditor.qss
Source/Window/MaterialEditorWindowComponent.h
Source/Window/MaterialEditorWindowComponent.cpp
Source/Window/SettingsDialog/SettingsDialog.cpp
Source/Window/SettingsDialog/SettingsDialog.h
Source/Window/SettingsDialog/SettingsWidget.cpp
Source/Window/SettingsDialog/SettingsWidget.h
Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp
Source/Window/CreateMaterialDialog/CreateMaterialDialog.h
Source/Window/CreateMaterialDialog/CreateMaterialDialog.ui
@@ -213,7 +213,11 @@ namespace AZ
}
// Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this,
const AZ::Crc32 saveStateKey(AZStd::string::format(
"MaterialPropertyInspector::PropertyGroup::%s::%s", m_materialAssetId.ToString<AZStd::string>().c_str(),
groupNameId.c_str()));
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
&group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey,
[this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) {
AZ_UNUSED(source);
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target);
@@ -262,7 +266,11 @@ namespace AZ
}
// Passing in same group as main and comparison instance to enable custom value comparison for highlighting modified properties
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(&group, &group, group.TYPEINFO_Uuid(), this, this,
const AZ::Crc32 saveStateKey(AZStd::string::format(
"MaterialPropertyInspector::PropertyGroup::%s::%s", m_materialAssetId.ToString<AZStd::string>().c_str(),
groupNameId.c_str()));
auto propertyGroupWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
&group, &group, group.TYPEINFO_Uuid(), this, this, saveStateKey,
[this](const AzToolsFramework::InstanceDataNode* source, const AzToolsFramework::InstanceDataNode* target) {
AZ_UNUSED(source);
const AtomToolsFramework::DynamicProperty* property = AtomToolsFramework::FindDynamicPropertyForInstanceDataNode(target);