Integrating latest from github/staging

Integrating up through commit 5e1bdae
This commit is contained in:
alexpete
2021-03-26 14:31:50 -07:00
parent 9c54341af8
commit 36c4e827bd
764 changed files with 11453 additions and 20251 deletions
@@ -24,7 +24,6 @@
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/Window/MaterialEditorWindowNotificationBus.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <Atom/RHI/Factory.h>
@@ -420,50 +419,6 @@ namespace MaterialEditor
m_menuFile->addSeparator();
auto presetMenu = m_menuFile->addMenu("Presets");
presetMenu->addAction("New Model Preset", [this]() {
AZ::Render::ModelPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(preset, &MaterialViewportRequestBus::Events::AddModelPreset, AZ::Render::ModelPreset());
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectModelPreset, preset);
});
presetMenu->addAction("Save Model Preset", [this]() {
const QString defaultPath = AtomToolsFramework::GetUniqueFileInfo(
QString(AZ::IO::FileIOBase::GetInstance()->GetAlias("@devassets@")) +
AZ_CORRECT_FILESYSTEM_SEPARATOR + "Materials" +
AZ_CORRECT_FILESYSTEM_SEPARATOR + "untitled.modelpreset.azasset").absoluteFilePath();
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveModelPresetSelection,
AtomToolsFramework::GetSaveFileInfo(defaultPath).absoluteFilePath().toUtf8().constData());
});
presetMenu->addSeparator();
presetMenu->addAction("New Lighting Preset", [this]() {
AZ::Render::LightingPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(preset, &MaterialViewportRequestBus::Events::AddLightingPreset, AZ::Render::LightingPreset());
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectLightingPreset, preset);
});
presetMenu->addAction("Save Lighting Preset", [this]() {
const QString defaultPath = AtomToolsFramework::GetUniqueFileInfo(
QString(AZ::IO::FileIOBase::GetInstance()->GetAlias("@devassets@")) +
AZ_CORRECT_FILESYSTEM_SEPARATOR + "Materials" +
AZ_CORRECT_FILESYSTEM_SEPARATOR + "untitled.lightingpreset.azasset").absoluteFilePath();
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveLightingPresetSelection,
AtomToolsFramework::GetSaveFileInfo(defaultPath).absoluteFilePath().toUtf8().constData());
});
presetMenu->addSeparator();
presetMenu->addAction("Reload Presets", [this]() {
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::ReloadContent);
}, QKeySequence::Refresh);
m_menuFile->addSeparator();
m_menuFile->addAction("Run &Python...", [this]() {
const QString script = QFileDialog::getOpenFileName(this, "Run Script", QString(), QString("*.py"));
if (!script.isEmpty())
@@ -22,11 +22,14 @@
#include <Atom/Window/MaterialEditorWindowFactoryRequestBus.h>
#include <Source/Window/MaterialEditorWindowComponent.h>
#include <Source/Window/MaterialEditorWindow.h>
#include <Source/Window/ViewportSettingsInspector/ViewportSettingsInspector.h>
namespace MaterialEditor
{
void MaterialEditorWindowComponent::Reflect(AZ::ReflectContext* context)
{
GeneralViewportSettings::Reflect(context);
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<MaterialEditorWindowComponent, AZ::Component>()
@@ -0,0 +1,73 @@
/*
* 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/Feature/Utils/LightingPreset.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <AtomToolsFramework/Util/Util.h>
#include <AzFramework/Application/Application.h>
#include <Window/PresetBrowserDialogs/LightingPresetBrowserDialog.h>
namespace MaterialEditor
{
LightingPresetBrowserDialog::LightingPresetBrowserDialog(QWidget* parent)
: PresetBrowserDialog(parent)
{
QSignalBlocker signalBlocker(this);
setWindowTitle("Lighting Preset Browser");
MaterialViewportRequestBus::BroadcastResult(m_initialPreset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection);
AZ::Render::LightingPresetPtrVector presets;
MaterialViewportRequestBus::BroadcastResult(presets, &MaterialViewportRequestBus::Events::GetLightingPresets);
AZStd::sort(presets.begin(), presets.end(), [](const auto& a, const auto& b) { return a->m_displayName < b->m_displayName; });
QListWidgetItem* selectedItem = nullptr;
for (const auto& preset : presets)
{
QImage image;
MaterialViewportRequestBus::BroadcastResult(image, &MaterialViewportRequestBus::Events::GetLightingPresetPreview, preset);
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), image);
m_listItemToPresetMap[item] = preset;
if (m_initialPreset == preset)
{
selectedItem = item;
}
}
if (selectedItem)
{
m_ui->m_presetList->setCurrentItem(selectedItem);
m_ui->m_presetList->scrollToItem(selectedItem);
}
}
void LightingPresetBrowserDialog::SelectCurrentPreset()
{
auto presetItr = m_listItemToPresetMap.find(m_ui->m_presetList->currentItem());
if (presetItr != m_listItemToPresetMap.end())
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectLightingPreset, presetItr->second);
}
}
void LightingPresetBrowserDialog::SelectInitialPreset()
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectLightingPreset, m_initialPreset);
}
} // namespace MaterialEditor
#include <Window/PresetBrowserDialogs/moc_LightingPresetBrowserDialog.cpp>
@@ -0,0 +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.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <Atom/Feature/Utils/LightingPreset.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
#include <AzCore/std/containers/vector.h>
#endif
#include <Window/PresetBrowserDialogs/PresetBrowserDialog.h>
namespace MaterialEditor
{
//! Widget for managing and selecting from a library of preset assets
class LightingPresetBrowserDialog : public PresetBrowserDialog
{
Q_OBJECT
public:
LightingPresetBrowserDialog(QWidget* parent = nullptr);
~LightingPresetBrowserDialog() = default;
private:
void SelectCurrentPreset() override;
void SelectInitialPreset() override;
AZ::Render::LightingPresetPtr m_initialPreset;
AZStd::unordered_map<QListWidgetItem*, AZ::Render::LightingPresetPtr> m_listItemToPresetMap;
};
} // namespace MaterialEditor
@@ -0,0 +1,73 @@
/*
* 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/Feature/Utils/ModelPreset.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <AtomToolsFramework/Util/Util.h>
#include <AzFramework/Application/Application.h>
#include <Window/PresetBrowserDialogs/ModelPresetBrowserDialog.h>
namespace MaterialEditor
{
ModelPresetBrowserDialog::ModelPresetBrowserDialog(QWidget* parent)
: PresetBrowserDialog(parent)
{
QSignalBlocker signalBlocker(this);
setWindowTitle("Model Preset Browser");
MaterialViewportRequestBus::BroadcastResult(m_initialPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection);
AZ::Render::ModelPresetPtrVector presets;
MaterialViewportRequestBus::BroadcastResult(presets, &MaterialViewportRequestBus::Events::GetModelPresets);
AZStd::sort(presets.begin(), presets.end(), [](const auto& a, const auto& b) { return a->m_displayName < b->m_displayName; });
QListWidgetItem* selectedItem = nullptr;
for (const auto& preset : presets)
{
QImage image;
MaterialViewportRequestBus::BroadcastResult(image, &MaterialViewportRequestBus::Events::GetModelPresetPreview, preset);
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), image);
m_listItemToPresetMap[item] = preset;
if (m_initialPreset == preset)
{
selectedItem = item;
}
}
if (selectedItem)
{
m_ui->m_presetList->setCurrentItem(selectedItem);
m_ui->m_presetList->scrollToItem(selectedItem);
}
}
void ModelPresetBrowserDialog::SelectCurrentPreset()
{
auto presetItr = m_listItemToPresetMap.find(m_ui->m_presetList->currentItem());
if (presetItr != m_listItemToPresetMap.end())
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectModelPreset, presetItr->second);
}
}
void ModelPresetBrowserDialog::SelectInitialPreset()
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectModelPreset, m_initialPreset);
}
} // namespace MaterialEditor
#include <Window/PresetBrowserDialogs/moc_ModelPresetBrowserDialog.cpp>
@@ -0,0 +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.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <Atom/Feature/Utils/ModelPreset.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
#include <AzCore/std/containers/vector.h>
#endif
#include <Window/PresetBrowserDialogs/PresetBrowserDialog.h>
namespace MaterialEditor
{
//! Widget for managing and selecting from a library of preset assets
class ModelPresetBrowserDialog : public PresetBrowserDialog
{
Q_OBJECT
public:
ModelPresetBrowserDialog(QWidget* parent = nullptr);
~ModelPresetBrowserDialog() = default;
private:
void SelectCurrentPreset() override;
void SelectInitialPreset() override;
AZ::Render::ModelPresetPtr m_initialPreset;
AZStd::unordered_map<QListWidgetItem*, AZ::Render::ModelPresetPtr> m_listItemToPresetMap;
};
} // namespace MaterialEditor
@@ -0,0 +1,115 @@
/*
* 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 <AtomToolsFramework/Util/Util.h>
#include <AzFramework/Application/Application.h>
#include <AzQtComponents/Components/StyleManager.h>
#include <AzQtComponents/Components/Widgets/ElidingLabel.h>
#include <AzQtComponents/Components/Widgets/LineEdit.h>
#include <AzQtComponents/Components/Widgets/Text.h>
#include <Window/PresetBrowserDialogs/PresetBrowserDialog.h>
#include <QLabel>
#include <QLineEdit>
#include <QMenu>
namespace MaterialEditor
{
PresetBrowserDialog::PresetBrowserDialog(QWidget* parent)
: QDialog(parent)
, m_ui(new Ui::PresetBrowserDialog)
{
m_ui->setupUi(this);
QSignalBlocker signalBlocker(this);
SetupPresetList();
SetupSearchWidget();
SetupDialogButtons();
}
void PresetBrowserDialog::SetupPresetList()
{
m_ui->m_presetList->setFlow(QListView::LeftToRight);
m_ui->m_presetList->setResizeMode(QListView::Adjust);
m_ui->m_presetList->setGridSize(QSize(0, 0));
m_ui->m_presetList->setWrapping(true);
QObject::connect(m_ui->m_presetList, &QListWidget::currentItemChanged, [this]() { SelectCurrentPreset(); });
}
QListWidgetItem* PresetBrowserDialog::CreateListItem(const QString& title, const QImage& image)
{
const QSize gridSize = m_ui->m_presetList->gridSize();
m_ui->m_presetList->setGridSize(
QSize(AZStd::max(gridSize.width(), image.width() + 10), AZStd::max(gridSize.height(), image.height() + 10)));
QListWidgetItem* item = new QListWidgetItem(m_ui->m_presetList);
item->setData(Qt::UserRole, title);
item->setSizeHint(image.size() + QSize(4, 4));
m_ui->m_presetList->addItem(item);
QLabel* previewImage = new QLabel(m_ui->m_presetList);
previewImage->setFixedSize(image.size());
previewImage->setMargin(0);
previewImage->setPixmap(QPixmap::fromImage(image));
previewImage->updateGeometry();
AzQtComponents::ElidingLabel* previewLabel = new AzQtComponents::ElidingLabel(previewImage);
previewLabel->setText(title);
previewLabel->setFixedSize(QSize(image.width(), 15));
previewLabel->setMargin(0);
previewLabel->setStyleSheet("background-color: rgb(35, 35, 35)");
AzQtComponents::Text::addPrimaryStyle(previewLabel);
AzQtComponents::Text::addLabelStyle(previewLabel);
m_ui->m_presetList->setItemWidget(item, previewImage);
return item;
}
void PresetBrowserDialog::SetupSearchWidget()
{
m_ui->m_searchWidget->setReadOnly(false);
m_ui->m_searchWidget->setContextMenuPolicy(Qt::CustomContextMenu);
AzQtComponents::LineEdit::applySearchStyle(m_ui->m_searchWidget);
connect(m_ui->m_searchWidget, &QLineEdit::textChanged, this, [this]() { ApplySearchFilter(); });
connect(m_ui->m_searchWidget, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos) { ShowSearchMenu(pos); });
}
void PresetBrowserDialog::SetupDialogButtons()
{
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(this, &QDialog::rejected, this, [this]() { SelectInitialPreset(); });
}
void PresetBrowserDialog::ApplySearchFilter()
{
for (int index = 0; index < m_ui->m_presetList->count(); ++index)
{
QListWidgetItem* item = m_ui->m_presetList->item(index);
const QString& title = item->data(Qt::UserRole).toString();
const QString filter = m_ui->m_searchWidget->text();
item->setHidden(!filter.isEmpty() && !title.contains(filter, Qt::CaseInsensitive));
}
}
void PresetBrowserDialog::ShowSearchMenu(const QPoint& pos)
{
QScopedPointer<QMenu> menu(m_ui->m_searchWidget->createStandardContextMenu());
menu->setStyleSheet("background-color: #333333");
menu->exec(m_ui->m_searchWidget->mapToGlobal(pos));
}
} // namespace MaterialEditor
#include <Window/PresetBrowserDialogs/moc_PresetBrowserDialog.cpp>
@@ -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.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/std/containers/vector.h>
#include <QDialog>
#endif
#include <Window/PresetBrowserDialogs/ui_PresetBrowserDialog.h>
class QImage;
class QListWidgetItem;
class QString;
namespace MaterialEditor
{
//! Widget for managing and selecting from a library of preset assets
class PresetBrowserDialog : public QDialog
{
Q_OBJECT
public:
PresetBrowserDialog(QWidget* parent = nullptr);
~PresetBrowserDialog() = default;
protected:
void SetupPresetList();
QListWidgetItem* CreateListItem(const QString& title, const QImage& image);
void SetupSearchWidget();
void SetupDialogButtons();
void ApplySearchFilter();
void ShowSearchMenu(const QPoint& pos);
virtual void SelectCurrentPreset() = 0;
virtual void SelectInitialPreset() = 0;
QScopedPointer<Ui::PresetBrowserDialog> m_ui;
};
} // namespace MaterialEditor
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PresetBrowserDialog</class>
<widget class="QWidget" name="PresetBrowserDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="windowTitle">
<string>Preset Browser</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="m_searchWidget"/>
</item>
<item>
<widget class="QListWidget" name="m_presetList"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -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.
*
*/
#include <AzQtComponents/Components/Widgets/Slider.h>
#include <Viewport/InputController/MaterialEditorViewportInputController.h>
#include <Source/Window/ToolBar/FovSliderWidget.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QHBoxLayout>
#include <QLabel>
AZ_POP_DISABLE_WARNING
namespace MaterialEditor
{
FovSliderWidget::FovSliderWidget(QWidget* parent)
: QWidget(parent)
{
QHBoxLayout* layout = new QHBoxLayout();
m_label = new QLabel("Field of View");
layout->addWidget(m_label);
AzQtComponents::SliderInt* slider = new AzQtComponents::SliderInt(Qt::Orientation::Horizontal);
slider->setRange(60, 120);
connect(slider, &AzQtComponents::SliderInt::valueChanged, this, &FovSliderWidget::SliderValueChanged);
slider->setValue(90);
layout->addWidget(slider);
setLayout(layout);
}
void FovSliderWidget::SliderValueChanged(int value) const
{
m_label->setText(QString("Field of View (%1)").arg(value));
MaterialEditorViewportInputControllerRequestBus::Broadcast(
&MaterialEditorViewportInputControllerRequestBus::Handler::SetFieldOfView,
aznumeric_cast<float>(value));
}
} // namespace MaterialEditor
@@ -1,39 +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/PlatformDef.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QLabel>
#include <QWidget>
AZ_POP_DISABLE_WARNING
namespace MaterialEditor
{
//! Widget for adjusting Field of View in viewport
class FovSliderWidget
: public QWidget
{
Q_OBJECT
public:
FovSliderWidget(QWidget* parent = 0);
~FovSliderWidget() = default;
private:
QLabel* m_label;
private Q_SLOTS:
void SliderValueChanged(int value) const;
};
} // namespace MaterialEditor
@@ -13,12 +13,15 @@
#include <Source/Window/ToolBar/MaterialEditorToolBar.h>
#include <Source/Window/ToolBar/ModelPresetComboBox.h>
#include <Source/Window/ToolBar/LightingPresetComboBox.h>
#include <Source/Window/ToolBar/FovSliderWidget.h>
#include <Atom/Document/MaterialEditorSettingsBus.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <AzCore/std/containers/vector.h>
#include <Atom/Viewport/MaterialViewportNotificationBus.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <AzQtComponents/Components/Widgets/ToolBar.h>
#include <QIcon>
#include <QMenu>
#include <QToolButton>
#include <QAction>
@@ -36,7 +39,7 @@ namespace MaterialEditor
toggleGrid->setCheckable(true);
connect(toggleGrid, &QAction::triggered, [this, toggleGrid]() {
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetGridEnabled, toggleGrid->isChecked());
});
});
bool enableGrid = false;
MaterialViewportRequestBus::BroadcastResult(enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled);
toggleGrid->setChecked(enableGrid);
@@ -46,7 +49,7 @@ namespace MaterialEditor
toggleShadowCatcher->setCheckable(true);
connect(toggleShadowCatcher, &QAction::triggered, [this, toggleShadowCatcher]() {
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SetShadowCatcherEnabled, toggleShadowCatcher->isChecked());
});
});
bool enableShadowCatcher = false;
MaterialViewportRequestBus::BroadcastResult(enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled);
toggleShadowCatcher->setChecked(enableShadowCatcher);
@@ -57,13 +60,13 @@ namespace MaterialEditor
QMenu* toneMappingMenu = new QMenu(toneMappingButton);
toneMappingMenu->addAction("None", [this]() {
MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "None");
});
});
toneMappingMenu->addAction("Gamma2.2", [this]() {
MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "Gamma2.2");
});
});
toneMappingMenu->addAction("ACES", [this]() {
MaterialEditorSettingsRequestBus::Broadcast(&MaterialEditorSettingsRequests::SetStringProperty, "toneMapping", "ACES");
});
});
toneMappingButton->setMenu(toneMappingMenu);
toneMappingButton->setText("Tone Mapping");
toneMappingButton->setIcon(QIcon(":/Icons/toneMapping.svg"));
@@ -82,10 +85,6 @@ namespace MaterialEditor
auto lightingPresetComboBox = new LightingPresetComboBox(this);
lightingPresetComboBox->setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy::AdjustToContents);
addWidget(lightingPresetComboBox);
FovSliderWidget* fovSlider = new FovSliderWidget(this);
fovSlider->setFixedWidth(250);
addWidget(fovSlider);
}
} // namespace MaterialEditor
@@ -12,11 +12,65 @@
#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 <QApplication>
#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)
;
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)
;
}
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<GeneralViewportSettings>("GeneralViewportSettings")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::Preview)
->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))
;
}
}
ViewportSettingsInspector::ViewportSettingsInspector(QWidget* parent)
: AtomToolsFramework::InspectorWidget(parent)
{
@@ -34,40 +88,218 @@ namespace MaterialEditor
void ViewportSettingsInspector::Popuate()
{
AddGroupsBegin();
AddGeneralGroup();
AddModelGroup();
AddLightingGroup();
AddGroupsEnd();
}
m_modelPreset.reset();
MaterialViewportRequestBus::BroadcastResult(m_modelPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection);
void ViewportSettingsInspector::AddGeneralGroup()
{
const AZStd::string groupNameId = "general";
const AZStd::string groupDisplayName = "General";
const AZStd::string groupDescription = "General";
AddGroup(
groupNameId, groupDisplayName, groupDescription,
new AtomToolsFramework::InspectorPropertyGroupWidget(&m_generalSettings, nullptr, m_generalSettings.TYPEINFO_Uuid(), this));
}
void ViewportSettingsInspector::AddModelGroup()
{
const AZStd::string groupNameId = "model";
const AZStd::string groupDisplayName = "Model";
const AZStd::string groupDescription = "Model";
auto groupWidget = new QWidget(this);
auto buttonGroupWidget = new QWidget(groupWidget);
auto addButtonWidget = new QPushButton("Add", buttonGroupWidget);
auto selectButtonWidget = new QPushButton("Select", buttonGroupWidget);
auto saveButtonWidget = new QPushButton("Save", buttonGroupWidget);
auto refreshButtonWidget = new QPushButton("Refresh", buttonGroupWidget);
buttonGroupWidget->setLayout(new QHBoxLayout(buttonGroupWidget));
buttonGroupWidget->layout()->addWidget(addButtonWidget);
buttonGroupWidget->layout()->addWidget(selectButtonWidget);
buttonGroupWidget->layout()->addWidget(saveButtonWidget);
buttonGroupWidget->layout()->addWidget(refreshButtonWidget);
groupWidget->setLayout(new QVBoxLayout(groupWidget));
groupWidget->layout()->addWidget(buttonGroupWidget);
QObject::connect(addButtonWidget, &QPushButton::clicked, this, [this]() { AddModelPreset(); });
QObject::connect(selectButtonWidget, &QPushButton::clicked, this, [this]() { SelectModelPreset(); });
QObject::connect(saveButtonWidget, &QPushButton::clicked, this, [this]() { SaveModelPreset(); });
QObject::connect(refreshButtonWidget, &QPushButton::clicked, this, [this]() { RefreshPresets(); });
if (m_modelPreset)
{
const AZStd::string groupNameId = "model";
const AZStd::string groupDisplayName = "Model";
const AZStd::string groupDescription = "Model";
auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), nullptr, groupWidget);
AddGroup(groupNameId, groupDisplayName, groupDescription,
new AtomToolsFramework::InspectorPropertyGroupWidget(m_modelPreset.get(), nullptr, m_modelPreset.get()->TYPEINFO_Uuid(), this));
groupWidget->layout()->addWidget(inspectorWidget);
}
m_lightingPreset.reset();
MaterialViewportRequestBus::BroadcastResult(m_lightingPreset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection);
AddGroup(groupNameId, groupDisplayName, groupDescription, groupWidget);
}
void ViewportSettingsInspector::AddModelPreset()
{
const AZStd::string defaultPath = GetDefaultUniqueSaveFilePath("untitled.modelpreset.azasset");
const AZStd::string savePath = AtomToolsFramework::GetSaveFileInfo(defaultPath.c_str()).absoluteFilePath().toUtf8().constData();
if (!savePath.empty())
{
AZ::Render::ModelPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(
preset, &MaterialViewportRequestBus::Events::AddModelPreset, AZ::Render::ModelPreset());
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveModelPreset, preset, savePath);
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectModelPreset, preset);
}
}
void ViewportSettingsInspector::SelectModelPreset()
{
ModelPresetBrowserDialog dialog(QApplication::activeWindow());
dialog.setFixedSize(800, 400);
dialog.show();
// Removing fixed size to allow drag resizing
dialog.setMinimumSize(0, 0);
dialog.setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
dialog.exec();
}
void ViewportSettingsInspector::SaveModelPreset()
{
AZ::Render::ModelPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(preset, &MaterialViewportRequestBus::Events::GetModelPresetSelection);
AZStd::string defaultPath;
MaterialViewportRequestBus::BroadcastResult(defaultPath, &MaterialViewportRequestBus::Events::GetModelPresetLastSavePath, preset);
if (defaultPath.empty())
{
defaultPath = GetDefaultUniqueSaveFilePath("untitled.modelpreset.azasset");
}
const AZStd::string savePath = AtomToolsFramework::GetSaveFileInfo(defaultPath.c_str()).absoluteFilePath().toUtf8().constData();
if (!savePath.empty())
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveModelPreset, preset, savePath);
}
}
void ViewportSettingsInspector::AddLightingGroup()
{
const AZStd::string groupNameId = "lighting";
const AZStd::string groupDisplayName = "Lighting";
const AZStd::string groupDescription = "Lighting";
auto groupWidget = new QWidget(this);
auto buttonGroupWidget = new QWidget(groupWidget);
auto addButtonWidget = new QPushButton("Add", buttonGroupWidget);
auto selectButtonWidget = new QPushButton("Select", buttonGroupWidget);
auto saveButtonWidget = new QPushButton("Save", buttonGroupWidget);
auto refreshButtonWidget = new QPushButton("Refresh", buttonGroupWidget);
buttonGroupWidget->setLayout(new QHBoxLayout(buttonGroupWidget));
buttonGroupWidget->layout()->addWidget(addButtonWidget);
buttonGroupWidget->layout()->addWidget(selectButtonWidget);
buttonGroupWidget->layout()->addWidget(saveButtonWidget);
buttonGroupWidget->layout()->addWidget(refreshButtonWidget);
groupWidget->setLayout(new QVBoxLayout(groupWidget));
groupWidget->layout()->addWidget(buttonGroupWidget);
QObject::connect(addButtonWidget, &QPushButton::clicked, this, [this]() { AddLightingPreset(); });
QObject::connect(selectButtonWidget, &QPushButton::clicked, this, [this]() { SelectLightingPreset(); });
QObject::connect(saveButtonWidget, &QPushButton::clicked, this, [this]() { SaveLightingPreset(); });
QObject::connect(refreshButtonWidget, &QPushButton::clicked, this, [this]() { RefreshPresets(); });
if (m_lightingPreset)
{
const AZStd::string groupNameId = "lighting";
const AZStd::string groupDisplayName = "Lighting";
const AZStd::string groupDescription = "Lighting";
auto inspectorWidget = new AtomToolsFramework::InspectorPropertyGroupWidget(
m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), nullptr, groupWidget);
AddGroup(groupNameId, groupDisplayName, groupDescription,
new AtomToolsFramework::InspectorPropertyGroupWidget(m_lightingPreset.get(), nullptr, m_lightingPreset.get()->TYPEINFO_Uuid(), this));
groupWidget->layout()->addWidget(inspectorWidget);
}
AddGroupsEnd();
AddGroup(groupNameId, groupDisplayName, groupDescription, groupWidget);
}
void ViewportSettingsInspector::AddLightingPreset()
{
const AZStd::string defaultPath = GetDefaultUniqueSaveFilePath("untitled.lightingpreset.azasset");
const AZStd::string savePath = AtomToolsFramework::GetSaveFileInfo(defaultPath.c_str()).absoluteFilePath().toUtf8().constData();
if (!savePath.empty())
{
AZ::Render::LightingPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(
preset, &MaterialViewportRequestBus::Events::AddLightingPreset, AZ::Render::LightingPreset());
MaterialViewportRequestBus::Broadcast(
&MaterialViewportRequestBus::Events::SaveLightingPreset, preset, savePath);
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SelectLightingPreset, preset);
}
}
void ViewportSettingsInspector::SelectLightingPreset()
{
LightingPresetBrowserDialog dialog(QApplication::activeWindow());
dialog.setFixedSize(800, 400);
dialog.show();
// Removing fixed size to allow drag resizing
dialog.setMinimumSize(0, 0);
dialog.setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
dialog.exec();
}
void ViewportSettingsInspector::SaveLightingPreset()
{
AZ::Render::LightingPresetPtr preset;
MaterialViewportRequestBus::BroadcastResult(preset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection);
AZStd::string defaultPath;
MaterialViewportRequestBus::BroadcastResult(defaultPath, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset);
if (defaultPath.empty())
{
defaultPath = GetDefaultUniqueSaveFilePath("untitled.lightingpreset.azasset");
}
const AZStd::string savePath = AtomToolsFramework::GetSaveFileInfo(defaultPath.c_str()).absoluteFilePath().toUtf8().constData();
if (!savePath.empty())
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::SaveLightingPreset, preset, savePath);
}
}
void ViewportSettingsInspector::RefreshPresets()
{
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Events::ReloadContent);
}
void ViewportSettingsInspector::Reset()
{
m_lightingPreset.reset();
m_modelPreset.reset();
MaterialViewportRequestBus::BroadcastResult(m_modelPreset, &MaterialViewportRequestBus::Events::GetModelPresetSelection);
m_lightingPreset.reset();
MaterialViewportRequestBus::BroadcastResult(m_lightingPreset, &MaterialViewportRequestBus::Events::GetLightingPresetSelection);
MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_enableGrid, &MaterialViewportRequestBus::Events::GetGridEnabled);
MaterialViewportRequestBus::BroadcastResult(
m_generalSettings.m_enableShadowCatcher, &MaterialViewportRequestBus::Events::GetShadowCatcherEnabled);
MaterialViewportRequestBus::BroadcastResult(
m_generalSettings.m_enableAlternateSkybox, &MaterialViewportRequestBus::Events::GetAlternateSkyboxEnabled);
MaterialViewportRequestBus::BroadcastResult(m_generalSettings.m_fieldOfView, &MaterialViewportRequestBus::Handler::GetFieldOfView);
AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect();
AtomToolsFramework::InspectorWidget::Reset();
}
@@ -88,6 +320,30 @@ namespace MaterialEditor
}
}
void ViewportSettingsInspector::OnShadowCatcherEnabledChanged(bool enable)
{
m_generalSettings.m_enableShadowCatcher = enable;
RefreshGroup("general");
}
void ViewportSettingsInspector::OnGridEnabledChanged(bool enable)
{
m_generalSettings.m_enableGrid = enable;
RefreshGroup("general");
}
void ViewportSettingsInspector::OnAlternateSkyboxEnabledChanged(bool enable)
{
m_generalSettings.m_enableAlternateSkybox = enable;
RefreshGroup("general");
}
void ViewportSettingsInspector::OnFieldOfViewChanged(float fieldOfView)
{
m_generalSettings.m_fieldOfView = fieldOfView;
RefreshGroup("general");
}
void ViewportSettingsInspector::BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode)
{
AZ_UNUSED(pNode);
@@ -96,17 +352,37 @@ namespace MaterialEditor
void ViewportSettingsInspector::AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode)
{
AZ_UNUSED(pNode);
MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnLightingPresetChanged, m_lightingPreset);
MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnModelPresetChanged, m_modelPreset);
ApplyChanges();
}
void ViewportSettingsInspector::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode)
{
AZ_UNUSED(pNode);
MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnLightingPresetChanged, m_lightingPreset);
MaterialViewportNotificationBus::Broadcast(&MaterialViewportNotificationBus::Events::OnModelPresetChanged, m_modelPreset);
ApplyChanges();
}
void ViewportSettingsInspector::ApplyChanges()
{
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::SetShadowCatcherEnabled, m_generalSettings.m_enableShadowCatcher);
MaterialViewportRequestBus::Broadcast(
&MaterialViewportRequestBus::Events::SetAlternateSkyboxEnabled, m_generalSettings.m_enableAlternateSkybox);
MaterialViewportRequestBus::Broadcast(&MaterialViewportRequestBus::Handler::SetFieldOfView, m_generalSettings.m_fieldOfView);
}
AZStd::string ViewportSettingsInspector::GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const
{
AZStd::string savePath = AZ::IO::FileIOBase::GetInstance()->GetAlias("@devassets@");
savePath += AZ_CORRECT_FILESYSTEM_SEPARATOR;
savePath += "Materials";
savePath += AZ_CORRECT_FILESYSTEM_SEPARATOR;
savePath += baseName;
savePath = AtomToolsFramework::GetUniqueFileInfo(savePath.c_str()).absoluteFilePath().toUtf8().constData();
return savePath;
}
} // namespace MaterialEditor
#include <Source/Window/ViewportSettingsInspector/moc_ViewportSettingsInspector.cpp>
@@ -22,6 +22,18 @@
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;
};
//! 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
@@ -38,6 +50,19 @@ namespace MaterialEditor
private:
void Popuate();
void AddGeneralGroup();
void AddModelGroup();
void AddModelPreset();
void SelectModelPreset();
void SaveModelPreset();
void AddLightingGroup();
void AddLightingPreset();
void SelectLightingPreset();
void SaveLightingPreset();
void RefreshPresets();
// AtomToolsFramework::InspectorRequestBus::Handler overrides...
void Reset() override;
@@ -45,16 +70,24 @@ namespace MaterialEditor
// MaterialViewportNotificationBus::Handler overrides...
void OnLightingPresetSelected([[maybe_unused]] AZ::Render::LightingPresetPtr preset) override;
void OnModelPresetSelected([[maybe_unused]] AZ::Render::ModelPresetPtr preset) override;
void OnShadowCatcherEnabledChanged(bool enable) override;
void OnGridEnabledChanged(bool enable) override;
void OnAlternateSkyboxEnabledChanged(bool enable) override;
void OnFieldOfViewChanged(float fieldOfView) 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 ApplyChanges();
void SealUndoStack() override {}
void RequestPropertyContextMenu(AzToolsFramework::InstanceDataNode*, const QPoint&) override {}
void PropertySelectionChanged(AzToolsFramework::InstanceDataNode*, bool) override {}
AZStd::string GetDefaultUniqueSaveFilePath(const AZStd::string& baseName) const;
GeneralViewportSettings m_generalSettings;
AZ::Render::ModelPresetPtr m_modelPreset;
AZ::Render::LightingPresetPtr m_lightingPreset;
};