Material Component: Can set material property overrides on default materials
No longer need to assign material overrides to set/edit properties in UI or script Material component will load and use the default material for a slot if no override is assigned Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
+13
-7
@@ -117,10 +117,16 @@ namespace AZ
|
||||
}
|
||||
};
|
||||
|
||||
AZ::Data::AssetId EditorMaterialComponentSlot::GetActiveAssetId() const
|
||||
{
|
||||
return m_materialAsset.GetId().IsValid() ? m_materialAsset.GetId() : GetDefaultAssetId();
|
||||
}
|
||||
|
||||
AZ::Data::AssetId EditorMaterialComponentSlot::GetDefaultAssetId() const
|
||||
{
|
||||
AZ::Data::AssetId assetId;
|
||||
MaterialComponentRequestBus::EventResult(assetId, m_entityId, &MaterialComponentRequestBus::Events::GetDefaultMaterialAssetId, m_id);
|
||||
MaterialComponentRequestBus::EventResult(
|
||||
assetId, m_entityId, &MaterialComponentRequestBus::Events::GetDefaultMaterialAssetId, m_id);
|
||||
return assetId;
|
||||
}
|
||||
|
||||
@@ -134,7 +140,7 @@ namespace AZ
|
||||
bool EditorMaterialComponentSlot::HasSourceData() const
|
||||
{
|
||||
// The slot only has valid source data if the source path is valid and the file has the correct extension
|
||||
const AZStd::string& sourcePath = AZ::RPI::AssetUtils::GetSourcePathByAssetId(m_materialAsset.GetId());
|
||||
const AZStd::string& sourcePath = AZ::RPI::AssetUtils::GetSourcePathByAssetId(GetActiveAssetId());
|
||||
return !sourcePath.empty() && AZ::StringFunc::Path::IsExtension(sourcePath.c_str(), AZ::RPI::MaterialSourceData::Extension);
|
||||
}
|
||||
|
||||
@@ -219,7 +225,7 @@ namespace AZ
|
||||
|
||||
void EditorMaterialComponentSlot::OpenMaterialEditor() const
|
||||
{
|
||||
const AZStd::string& sourcePath = AZ::RPI::AssetUtils::GetSourcePathByAssetId(m_materialAsset.GetId());
|
||||
const AZStd::string& sourcePath = AZ::RPI::AssetUtils::GetSourcePathByAssetId(GetActiveAssetId());
|
||||
if (!sourcePath.empty() && AZ::StringFunc::Path::IsExtension(sourcePath.c_str(), AZ::RPI::MaterialSourceData::Extension))
|
||||
{
|
||||
EditorMaterialSystemComponentRequestBus::Broadcast(
|
||||
@@ -235,7 +241,7 @@ namespace AZ
|
||||
|
||||
void EditorMaterialComponentSlot::OpenUvNameMapInspector()
|
||||
{
|
||||
if (m_materialAsset.GetId().IsValid())
|
||||
if (GetActiveAssetId().IsValid())
|
||||
{
|
||||
AZStd::unordered_set<AZ::Name> modelUvNames;
|
||||
MaterialReceiverRequestBus::EventResult(modelUvNames, m_entityId, &MaterialReceiverRequestBus::Events::GetModelUvNames);
|
||||
@@ -251,7 +257,7 @@ namespace AZ
|
||||
};
|
||||
|
||||
if (EditorMaterialComponentInspector::OpenInspectorDialog(
|
||||
m_materialAsset.GetId(), matModUvOverrides, modelUvNames, applyMatModUvOverrideChangedCallback))
|
||||
GetActiveAssetId(), matModUvOverrides, modelUvNames, applyMatModUvOverrideChangedCallback))
|
||||
{
|
||||
OnDataChanged();
|
||||
}
|
||||
@@ -273,10 +279,10 @@ namespace AZ
|
||||
action->setEnabled(HasSourceData());
|
||||
|
||||
action = menu.addAction("Edit Material Instance...", [this]() { OpenMaterialInspector(); });
|
||||
action->setEnabled(m_materialAsset.GetId().IsValid());
|
||||
action->setEnabled(GetActiveAssetId().IsValid());
|
||||
|
||||
action = menu.addAction("Edit Material Instance UV Map...", [this]() { OpenUvNameMapInspector(); });
|
||||
action->setEnabled(m_materialAsset.GetId().IsValid());
|
||||
action->setEnabled(GetActiveAssetId().IsValid());
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user