diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserTableModel.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserTableModel.cpp
index fdbd4287ce..469a235b9f 100644
--- a/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserTableModel.cpp
+++ b/Code/Framework/AzToolsFramework/AzToolsFramework/AssetBrowser/AssetBrowserTableModel.cpp
@@ -46,7 +46,7 @@ namespace AzToolsFramework
QModelIndex AssetBrowserTableModel::mapToSource(const QModelIndex& proxyIndex) const
{
- Q_ASSERT(!proxyIndex.isValid() || proxyIndex.model() != this);
+ Q_ASSERT(!proxyIndex.isValid() || proxyIndex.model() == this);
if (!proxyIndex.isValid() || !m_indexMap.contains(proxyIndex.row()))
{
return QModelIndex();
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h
index 3b65750b5f..ace16ba6ca 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Include/AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h
@@ -33,6 +33,16 @@ namespace AZ
virtual const MaterialAssignmentMap& GetMaterialOverrides() const = 0;
//! Clear all material overrides
virtual void ClearAllMaterialOverrides() = 0;
+ //! Clear non-lod material overrides
+ virtual void ClearModelMaterialOverrides() = 0;
+ //! Clear lod material overrides
+ virtual void ClearLodMaterialOverrides() = 0;
+ //! Clear residual materials that don't correspond to the associated model
+ virtual void ClearIncompatibleMaterialOverrides() = 0;
+ //! Clear materials that reference missing assets
+ virtual void ClearInvalidMaterialOverrides() = 0;
+ //! Repair materials that reference missing assets by assigning the default asset
+ virtual void RepairInvalidMaterialOverrides() = 0;
//! Set default material override
virtual void SetDefaultMaterialOverride(const AZ::Data::AssetId& materialAssetId) = 0;
//! Get default material override
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.cpp
index c243522257..b7bf191bc9 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.cpp
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.cpp
@@ -32,9 +32,6 @@ namespace AZ
const char* EditorMaterialComponent::GenerateMaterialsButtonText = "Generate/Manage Source Materials...";
const char* EditorMaterialComponent::GenerateMaterialsToolTipText = "Generate editable source material files from materials provided by the model.";
- const char* EditorMaterialComponent::ResetMaterialsButtonText = "Reset Materials";
- const char* EditorMaterialComponent::ResetMaterialsToolTipText = "Clear all settings, materials, and properties then rebuild material slots from the associated model.";
-
// Update serialized data to the new format and data types
bool EditorMaterialComponent::ConvertVersion(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
@@ -178,43 +175,74 @@ namespace AZ
menu->addSeparator();
- action = menu->addAction(ResetMaterialsButtonText, [this]() { ResetMaterialSlots(); });
- action->setToolTip(ResetMaterialsToolTipText);
+ action = menu->addAction("Clear All Materials", [this]() {
+ AzToolsFramework::ScopedUndoBatch undoBatch("Clearing all materials.");
+ SetDirty();
- menu->addSeparator();
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::ClearAllMaterialOverrides);
+
+ m_materialSlotsByLodEnabled = false;
+
+ UpdateMaterialSlots();
+ });
+ action->setToolTip("Clear all materials and properties then rebuild material slots from the associated model.");
action = menu->addAction("Clear Model Materials", [this]() {
AzToolsFramework::ScopedUndoBatch undoBatch("Clearing model materials.");
SetDirty();
- for (auto& materialSlotPair : GetMaterialSlots())
- {
- EditorMaterialComponentSlot* materialSlot = materialSlotPair.second;
- if (materialSlot->m_id.IsSlotIdOnly())
- {
- materialSlot->Clear();
- }
- }
- });
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::ClearModelMaterialOverrides);
+
+ UpdateMaterialSlots();
+ });
+ action->setToolTip("Clear model materials and properties then rebuild material slots from the associated model.");
+
action = menu->addAction("Clear LOD Materials", [this]() {
AzToolsFramework::ScopedUndoBatch undoBatch("Clearing LOD materials.");
SetDirty();
- for (auto& materialSlotPair : GetMaterialSlots())
- {
- EditorMaterialComponentSlot* materialSlot = materialSlotPair.second;
- if (materialSlot->m_id.IsLodAndSlotId())
- {
- materialSlot->Clear();
- }
- }
- });
- action->setEnabled(m_materialSlotsByLodEnabled);
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::ClearLodMaterialOverrides);
+
+ m_materialSlotsByLodEnabled = false;
+
+ UpdateMaterialSlots();
+ });
+ action->setToolTip("Clear LOD materials and properties then rebuild material slots from the associated model.");
+
+ action = menu->addAction("Clear Incompatible Materials", [this]() {
+ AzToolsFramework::ScopedUndoBatch undoBatch("Clearing incompatible materials.");
+ SetDirty();
+
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::ClearIncompatibleMaterialOverrides);
+
+ UpdateMaterialSlots();
+ });
+ action->setToolTip("Clear residual materials that don't correspond to the associated model.");
+
+ action = menu->addAction("Clear Invalid Materials", [this]() {
+ AzToolsFramework::ScopedUndoBatch undoBatch("Clearing invalid materials.");
+ SetDirty();
+
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::ClearInvalidMaterialOverrides);
+
+ UpdateMaterialSlots();
+ });
+ action->setToolTip("Clear materials that reference missing assets.");
+
+ action = menu->addAction("Repair Invalid Materials", [this]() {
+ AzToolsFramework::ScopedUndoBatch undoBatch("Repairing invalid materials.");
+ SetDirty();
+
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::RepairInvalidMaterialOverrides);
+
+ UpdateMaterialSlots();
+ });
+ action->setToolTip("Repair materials that reference missing assets by assigning the default asset.");
}
void EditorMaterialComponent::SetPrimaryAsset(const AZ::Data::AssetId& assetId)
{
- m_controller.SetDefaultMaterialOverride(assetId);
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::SetDefaultMaterialOverride, assetId);
MaterialComponentNotificationBus::Event(GetEntityId(), &MaterialComponentNotifications::OnMaterialsEdited);
@@ -249,14 +277,18 @@ namespace AZ
m_materialSlots = {};
m_materialSlotsByLod = {};
- const MaterialComponentConfig& config = m_controller.GetConfiguration();
+ // Get current material assignments
+ MaterialAssignmentMap currentMaterials;
+ MaterialComponentRequestBus::EventResult(
+ currentMaterials, GetEntityId(), &MaterialComponentRequestBus::Events::GetMaterialOverrides);
// Get the known material assignment slots from the associated model or other source
- MaterialAssignmentMap materialsFromSource;
- MaterialReceiverRequestBus::EventResult(materialsFromSource, GetEntityId(), &MaterialReceiverRequestBus::Events::GetMaterialAssignments);
+ MaterialAssignmentMap originalMaterials;
+ MaterialComponentRequestBus::EventResult(
+ originalMaterials, GetEntityId(), &MaterialComponentRequestBus::Events::GetOriginalMaterialAssignments);
// Generate the table of editable materials using the source data to define number of groups, elements, and initial values
- for (const auto& materialPair : materialsFromSource)
+ for (const auto& materialPair : originalMaterials)
{
// Setup the material slot entry
EditorMaterialComponentSlot slot;
@@ -264,7 +296,7 @@ namespace AZ
slot.m_id = materialPair.first;
// if material is present in controller configuration, assign its data
- const MaterialAssignment& materialFromController = GetMaterialAssignmentFromMap(config.m_materials, slot.m_id);
+ const MaterialAssignment& materialFromController = GetMaterialAssignmentFromMap(currentMaterials, slot.m_id);
slot.m_materialAsset = materialFromController.m_materialAsset;
if (slot.m_id.IsDefault())
@@ -289,7 +321,7 @@ namespace AZ
}
}
- // Sort all of the slots by label to ensure stable index values (materialsFromSource is an unordered map)
+ // Sort all of the slots by label to ensure stable index values (originalMaterials is an unordered map)
AZStd::sort(m_materialSlots.begin(), m_materialSlots.end(),
[](const auto& a, const auto& b) { return a.GetLabel() < b.GetLabel(); });
@@ -305,49 +337,36 @@ namespace AZ
&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
}
- AZ::u32 EditorMaterialComponent::ResetMaterialSlots()
- {
- AzToolsFramework::ScopedUndoBatch undoBatch("Resetting materials.");
- SetDirty();
-
- m_controller.SetMaterialOverrides(MaterialAssignmentMap());
- UpdateMaterialSlots();
-
- m_materialSlotsByLodEnabled = false;
-
- MaterialComponentNotificationBus::Event(GetEntityId(), &MaterialComponentNotifications::OnMaterialsEdited);
-
- AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
- &AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_EntireTree);
-
- return AZ::Edit::PropertyRefreshLevels::EntireTree;
- }
-
AZ::u32 EditorMaterialComponent::OpenMaterialExporter()
{
AzToolsFramework::ScopedUndoBatch undoBatch("Generating materials.");
SetDirty();
- // First generating a unique set of all material asset IDs that will be used for source data generation
- AZStd::unordered_map assetIdMap;
+ MaterialAssignmentMap originalMaterials;
+ MaterialComponentRequestBus::EventResult(
+ originalMaterials, GetEntityId(), &MaterialComponentRequestBus::Events::GetOriginalMaterialAssignments);
- auto materialSlots = GetMaterialSlots();
- for (auto& materialSlotPair : materialSlots)
+ // Generate a unique set of all material asset IDs that will be used for source data generation
+ AZStd::unordered_map assetIdToSlotNameMap;
+ for (const auto& materialPair : originalMaterials)
{
- Data::AssetId defaultMaterialAssetId = materialSlotPair.second->GetDefaultAssetId();
- if (defaultMaterialAssetId.IsValid())
+ const Data::AssetId originalAssetId = materialPair.second.m_materialAsset.GetId();
+ if (originalAssetId.IsValid())
{
- assetIdMap[defaultMaterialAssetId] = materialSlotPair.second->GetLabel();
+ MaterialComponentRequestBus::EventResult(
+ assetIdToSlotNameMap[originalAssetId], GetEntityId(), &MaterialComponentRequestBus::Events::GetMaterialSlotLabel,
+ materialPair.first);
}
}
// Convert the unique set of asset IDs into export items that can be configured in the dialog
// The order should not matter because the table in the dialog can sort itself for a specific row
EditorMaterialComponentExporter::ExportItemsContainer exportItems;
- for (auto assetIdInfo : assetIdMap)
+ exportItems.reserve(assetIdToSlotNameMap.size());
+
+ for (const auto& [assetId, slotName] : assetIdToSlotNameMap)
{
- EditorMaterialComponentExporter::ExportItem exportItem{ assetIdInfo.first, assetIdInfo.second };
- exportItems.push_back(exportItem);
+ exportItems.emplace_back(assetId, slotName);
}
// Display the export dialog so that the user can configure how they want different materials to be exported
@@ -363,16 +382,17 @@ namespace AZ
const auto& assetIdOutcome = AZ::RPI::AssetUtils::MakeAssetId(exportItem.GetExportPath(), 0);
if (assetIdOutcome)
{
- for (auto& materialSlotPair : materialSlots)
+ for (const auto& materialPair : originalMaterials)
{
- EditorMaterialComponentSlot* editorMaterialSlot = materialSlotPair.second;
-
- if (editorMaterialSlot)
+ // We need to check whether replaced material corresponds to this slot's default material.
+ const Data::AssetId originalAssetId = materialPair.second.m_materialAsset.GetId();
+ if (originalAssetId == exportItem.GetOriginalAssetId())
{
- // We need to check whether replaced material corresponds to this slot's default material.
- if (editorMaterialSlot->GetDefaultAssetId() == exportItem.GetOriginalAssetId())
+ if (m_materialSlotsByLodEnabled || !materialPair.first.IsLodAndSlotId())
{
- editorMaterialSlot->SetAsset(assetIdOutcome.GetValue());
+ MaterialComponentRequestBus::Event(
+ GetEntityId(), &MaterialComponentRequestBus::Events::SetMaterialOverride, materialPair.first,
+ assetIdOutcome.GetValue());
}
}
}
@@ -380,12 +400,9 @@ namespace AZ
}
}
- MaterialComponentNotificationBus::Event(GetEntityId(), &MaterialComponentNotifications::OnMaterialsEdited);
+ UpdateMaterialSlots();
- AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast(
- &AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, AzToolsFramework::Refresh_AttributesAndValues);
-
- return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
+ return AZ::Edit::PropertyRefreshLevels::EntireTree;
}
AZ::u32 EditorMaterialComponent::OnLodsToggled()
@@ -395,15 +412,10 @@ namespace AZ
if (!m_materialSlotsByLodEnabled)
{
- MaterialComponentConfig config = m_controller.GetConfiguration();
- AZStd::erase_if(config.m_materials, [](const auto& item) {
- const auto& [key, value] = item;
- return key.m_lodIndex != MaterialAssignmentId::NonLodIndex;
- });
- m_controller.SetMaterialOverrides(config.m_materials);
+ MaterialComponentRequestBus::Event(GetEntityId(), &MaterialComponentRequestBus::Events::ClearLodMaterialOverrides);
}
- MaterialComponentNotificationBus::Event(GetEntityId(), &MaterialComponentNotifications::OnMaterialsEdited);
+ UpdateMaterialSlots();
return AZ::Edit::PropertyRefreshLevels::EntireTree;
}
@@ -440,41 +452,5 @@ namespace AZ
{
return AZStd::string::format("LOD %d", lodIndex);
}
-
- template
- void EditorMaterialComponent::BuildMaterialSlotMap(ComponentType& component, ContainerType& materialSlots)
- {
- materialSlots[DefaultMaterialAssignmentId] = &component.m_defaultMaterialSlot;
-
- for (auto& slot : component.m_materialSlots)
- {
- materialSlots[slot.m_id] = &slot;
- }
-
- if (component.m_materialSlotsByLodEnabled)
- {
- for (auto& slotsForLod : component.m_materialSlotsByLod)
- {
- for (auto& slot : slotsForLod)
- {
- materialSlots[slot.m_id] = &slot;
- }
- }
- }
- }
-
- AZStd::unordered_map EditorMaterialComponent::GetMaterialSlots()
- {
- AZStd::unordered_map materialSlots;
- BuildMaterialSlotMap(*this, materialSlots);
- return AZStd::move(materialSlots);
- }
-
- AZStd::unordered_map EditorMaterialComponent::GetMaterialSlots() const
- {
- AZStd::unordered_map materialSlots;
- BuildMaterialSlotMap(*this, materialSlots);
- return AZStd::move(materialSlots);
- }
} // namespace Render
} // namespace AZ
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.h
index 6a218e23b7..f8895d994f 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.h
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponent.h
@@ -58,9 +58,6 @@ namespace AZ
// controller configuration then those values will be assigned to the editor component slots.
void UpdateMaterialSlots();
- // Clears all values related to the material component and regenerates the editor slots
- AZ::u32 ResetMaterialSlots();
-
// Opens the source material export dialog and updates editor material slots based on
// selected actions
AZ::u32 OpenMaterialExporter();
@@ -82,10 +79,6 @@ namespace AZ
// Evaluate if materials can be edited
bool IsEditingAllowed() const;
- template
- static void BuildMaterialSlotMap(ComponentType& component, ContainerType& materialSlots);
- AZStd::unordered_map GetMaterialSlots();
- AZStd::unordered_map GetMaterialSlots() const;
AZStd::string GetLabelForLod(int lodIndex) const;
AZStd::string m_message;
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentExporter.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentExporter.cpp
index f55da28fa6..14cc28b91e 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentExporter.cpp
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentExporter.cpp
@@ -55,6 +55,10 @@ namespace AZ
bool OpenExportDialog(ExportItemsContainer& exportItems)
{
+ // Sort material entries so they are ordered by name in the table
+ AZStd::sort(exportItems.begin(), exportItems.end(),
+ [](const auto& a, const auto& b) { return a.GetMaterialSlotName() < b.GetMaterialSlotName(); });
+
QWidget* activeWindow = nullptr;
AzToolsFramework::EditorWindowRequestBus::BroadcastResult(activeWindow, &AzToolsFramework::EditorWindowRequests::GetAppMainWindow);
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentSlot.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentSlot.cpp
index 37a9ee7b93..363221d3fc 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentSlot.cpp
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialComponentSlot.cpp
@@ -140,7 +140,7 @@ namespace AZ
void EditorMaterialComponentSlot::SetAsset(const Data::AssetId& assetId)
{
- m_materialAsset.Create(assetId);
+ m_materialAsset = AZ::Data::Asset(assetId, AZ::AzTypeInfo::Uuid());
MaterialComponentRequestBus::Event(
m_entityId, &MaterialComponentRequestBus::Events::SetMaterialOverride, m_id, m_materialAsset.GetId());
OnDataChanged();
@@ -164,7 +164,7 @@ namespace AZ
void EditorMaterialComponentSlot::ClearToDefaultAsset()
{
- m_materialAsset.Create(GetDefaultAssetId());
+ m_materialAsset = AZ::Data::Asset(GetDefaultAssetId(), AZ::AzTypeInfo::Uuid());
MaterialComponentRequestBus::Event(
m_entityId, &MaterialComponentRequestBus::Events::SetMaterialOverride, m_id, m_materialAsset.GetId());
ClearOverrides();
@@ -204,7 +204,8 @@ namespace AZ
const auto& assetIdOutcome = AZ::RPI::AssetUtils::MakeAssetId(exportItem.GetExportPath(), 0);
if (assetIdOutcome)
{
- m_materialAsset.Create(assetIdOutcome.GetValue());
+ m_materialAsset = AZ::Data::Asset(
+ assetIdOutcome.GetValue(), AZ::AzTypeInfo::Uuid());
changed = true;
}
}
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.cpp
index 14f81c5021..1d9f1e81dd 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.cpp
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.cpp
@@ -43,6 +43,11 @@ namespace AZ
->Event("SetDefaultMaterialOverride", &MaterialComponentRequestBus::Events::SetDefaultMaterialOverride)
->Event("GetDefaultMaterialOverride", &MaterialComponentRequestBus::Events::GetDefaultMaterialOverride)
->Event("ClearDefaultMaterialOverride", &MaterialComponentRequestBus::Events::ClearDefaultMaterialOverride)
+ ->Event("ClearModelMaterialOverrides", &MaterialComponentRequestBus::Events::ClearModelMaterialOverrides)
+ ->Event("ClearLodMaterialOverrides", &MaterialComponentRequestBus::Events::ClearLodMaterialOverrides)
+ ->Event("ClearIncompatibleMaterialOverrides", &MaterialComponentRequestBus::Events::ClearIncompatibleMaterialOverrides)
+ ->Event("ClearInvalidMaterialOverrides", &MaterialComponentRequestBus::Events::ClearInvalidMaterialOverrides)
+ ->Event("RepairInvalidMaterialOverrides", &MaterialComponentRequestBus::Events::RepairInvalidMaterialOverrides)
->Event("SetMaterialOverride", &MaterialComponentRequestBus::Events::SetMaterialOverride)
->Event("GetMaterialOverride", &MaterialComponentRequestBus::Events::GetMaterialOverride)
->Event("ClearMaterialOverride", &MaterialComponentRequestBus::Events::ClearMaterialOverride)
@@ -275,10 +280,10 @@ namespace AZ
MaterialAssignmentMap MaterialComponentController::GetOriginalMaterialAssignments() const
{
- MaterialAssignmentMap materialAssignmentMap;
+ MaterialAssignmentMap originalMaterials;
MaterialReceiverRequestBus::EventResult(
- materialAssignmentMap, m_entityId, &MaterialReceiverRequestBus::Events::GetMaterialAssignments);
- return materialAssignmentMap;
+ originalMaterials, m_entityId, &MaterialReceiverRequestBus::Events::GetMaterialAssignments);
+ return originalMaterials;
}
MaterialAssignmentId MaterialComponentController::FindMaterialAssignmentId(
@@ -348,6 +353,67 @@ namespace AZ
}
}
+ void MaterialComponentController::ClearModelMaterialOverrides()
+ {
+ AZStd::erase_if(m_configuration.m_materials, [](const auto& materialPair) {
+ return materialPair.first.IsSlotIdOnly();
+ });
+ QueueMaterialUpdateNotification();
+ }
+
+ void MaterialComponentController::ClearLodMaterialOverrides()
+ {
+ AZStd::erase_if(m_configuration.m_materials, [](const auto& materialPair) {
+ return materialPair.first.IsLodAndSlotId();
+ });
+ QueueMaterialUpdateNotification();
+ }
+
+ void MaterialComponentController::ClearIncompatibleMaterialOverrides()
+ {
+ const MaterialAssignmentMap& originalMaterials = GetOriginalMaterialAssignments();
+ AZStd::erase_if(m_configuration.m_materials, [&originalMaterials](const auto& materialPair) {
+ return originalMaterials.find(materialPair.first) == originalMaterials.end();
+ });
+ QueueMaterialUpdateNotification();
+ }
+
+ void MaterialComponentController::ClearInvalidMaterialOverrides()
+ {
+ AZStd::erase_if(m_configuration.m_materials, [](const auto& materialPair) {
+ if (materialPair.second.m_materialAsset.GetId().IsValid())
+ {
+ AZ::Data::AssetInfo assetInfo;
+ AZ::Data::AssetCatalogRequestBus::BroadcastResult(
+ assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById,
+ materialPair.second.m_materialAsset.GetId());
+ return !assetInfo.m_assetId.IsValid();
+ }
+ return false;
+ });
+ QueueMaterialUpdateNotification();
+ }
+
+ void MaterialComponentController::RepairInvalidMaterialOverrides()
+ {
+ for (auto& materialPair : m_configuration.m_materials)
+ {
+ if (materialPair.second.m_materialAsset.GetId().IsValid())
+ {
+ AZ::Data::AssetInfo assetInfo;
+ AZ::Data::AssetCatalogRequestBus::BroadcastResult(
+ assetInfo, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetInfoById,
+ materialPair.second.m_materialAsset.GetId());
+ if (!assetInfo.m_assetId.IsValid())
+ {
+ materialPair.second.m_materialAsset = AZ::Data::Asset(
+ GetDefaultMaterialAssetId(materialPair.first), AZ::AzTypeInfo::Uuid());
+ }
+ }
+ }
+ LoadMaterials();
+ }
+
void MaterialComponentController::SetDefaultMaterialOverride(const AZ::Data::AssetId& materialAssetId)
{
SetMaterialOverride(DefaultMaterialAssignmentId, materialAssetId);
@@ -363,9 +429,11 @@ namespace AZ
ClearMaterialOverride(DefaultMaterialAssignmentId);
}
- void MaterialComponentController::SetMaterialOverride(const MaterialAssignmentId& materialAssignmentId, const AZ::Data::AssetId& materialAssetId)
+ void MaterialComponentController::SetMaterialOverride(
+ const MaterialAssignmentId& materialAssignmentId, const AZ::Data::AssetId& materialAssetId)
{
- m_configuration.m_materials[materialAssignmentId].m_materialAsset.Create(materialAssetId);
+ m_configuration.m_materials[materialAssignmentId].m_materialAsset =
+ AZ::Data::Asset(materialAssetId, AZ::AzTypeInfo::Uuid());
LoadMaterials();
}
@@ -616,7 +684,6 @@ namespace AZ
void MaterialComponentController::ClearAllPropertyOverrides()
{
- bool cleared = false;
for (auto& materialPair : m_configuration.m_materials)
{
if (!materialPair.second.m_propertyOverrides.empty())
@@ -625,13 +692,8 @@ namespace AZ
materialPair.second.RebuildInstance();
MaterialComponentNotificationBus::Event(m_entityId, &MaterialComponentNotifications::OnMaterialInstanceCreated, materialPair.second);
QueueMaterialUpdateNotification();
- cleared = true;
}
}
-
- if (cleared)
- {
- }
}
void MaterialComponentController::SetPropertyOverrides(
diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.h
index c9dd330412..2bf15ca3b8 100644
--- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.h
+++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/MaterialComponentController.h
@@ -52,6 +52,11 @@ namespace AZ
void SetMaterialOverrides(const MaterialAssignmentMap& materials) override;
const MaterialAssignmentMap& GetMaterialOverrides() const override;
void ClearAllMaterialOverrides() override;
+ void ClearModelMaterialOverrides() override;
+ void ClearLodMaterialOverrides() override;
+ void ClearIncompatibleMaterialOverrides() override;
+ void ClearInvalidMaterialOverrides() override;
+ void RepairInvalidMaterialOverrides() override;
void SetDefaultMaterialOverride(const AZ::Data::AssetId& materialAssetId) override;
const AZ::Data::AssetId GetDefaultMaterialOverride() const override;
void ClearDefaultMaterialOverride() override;