Add material property names to material assets, disable FBX dependency on materialtype files. (#3408)
* Add material property names to material assets, disable FBX dependency on materialtype files. Signed-off-by: Robin <rbarrand@amazon.com> * Add reflection for MaterialAssets. Update member variable comment. Signed-off-by: Robin <rbarrand@amazon.com> * Switch cvar to using bus value. Refine comments. Signed-off-by: Robin <rbarrand@amazon.com> * Refactor functions and refine comments. Signed-off-by: Robin <rbarrand@amazon.com> * Realign property values when material property names are populated. Signed-off-by: Robin <rbarrand@amazon.com> * Switch PostLoadInit check to on asset status ready. Add realign property values code to PostLoadInit as well. Signed-off-by: Robin <rbarrand@amazon.com> * Stash@{1} code. Signed-off-by: Robin <rbarrand@amazon.com> * Refactor realignment code into the right places. Signed-off-by: Robin <rbarrand@amazon.com> * Remove pragma optmize off. Signed-off-by: Robin <rbarrand@amazon.com> * More refactoring. Signed-off-by: Robin <rbarrand@amazon.com> * Refactor comments and remove code no longer needed. Signed-off-by: Robin <rbarrand@amazon.com> * Refactor comments and remove unused include. Signed-off-by: Robin <rbarrand@amazon.com> * Comment refactor, corrected some code. Signed-off-by: Robin <rbarrand@amazon.com> Co-authored-by: Robin <rbarrand@amazon.com>
This commit is contained in:
@@ -20,6 +20,8 @@ namespace AZ
|
||||
{
|
||||
namespace RPI
|
||||
{
|
||||
const char* MaterialAsset::s_debugTraceName = "MaterialAsset";
|
||||
|
||||
const char* MaterialAsset::DisplayName = "MaterialAsset";
|
||||
const char* MaterialAsset::Group = "Material";
|
||||
const char* MaterialAsset::Extension = "azmaterial";
|
||||
@@ -29,9 +31,10 @@ namespace AZ
|
||||
if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<MaterialAsset, AZ::Data::AssetData>()
|
||||
->Version(9)
|
||||
->Version(10)
|
||||
->Field("materialTypeAsset", &MaterialAsset::m_materialTypeAsset)
|
||||
->Field("propertyValues", &MaterialAsset::m_propertyValues)
|
||||
->Field("propertyNames", &MaterialAsset::m_propertyNames)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -99,6 +102,11 @@ namespace AZ
|
||||
|
||||
AZStd::array_view<MaterialPropertyValue> MaterialAsset::GetPropertyValues() const
|
||||
{
|
||||
if (!m_propertyNames.empty() && m_isDirty)
|
||||
{
|
||||
const_cast<MaterialAsset*>(this)->RealignPropertyValuesAndNames();
|
||||
}
|
||||
|
||||
return m_propertyValues;
|
||||
}
|
||||
|
||||
@@ -146,6 +154,34 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialAsset::RealignPropertyValuesAndNames()
|
||||
{
|
||||
const MaterialPropertiesLayout* propertyLayout = GetMaterialPropertiesLayout();
|
||||
AZStd::vector<MaterialPropertyValue> alignedPropertyValues(m_materialTypeAsset->GetDefaultPropertyValues().begin(), m_materialTypeAsset->GetDefaultPropertyValues().end());
|
||||
for (size_t i = 0; i < m_propertyNames.size(); ++i)
|
||||
{
|
||||
const MaterialPropertyIndex propertyIndex = propertyLayout->FindPropertyIndex(m_propertyNames[i]);
|
||||
if (propertyIndex.IsValid())
|
||||
{
|
||||
alignedPropertyValues[propertyIndex.GetIndex()] = m_propertyValues[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Warning(s_debugTraceName, false, "Material property name \"%s\" is not found in the material properties layout and will not be used.", m_propertyNames[i].GetCStr());
|
||||
}
|
||||
}
|
||||
m_propertyValues.swap(alignedPropertyValues);
|
||||
|
||||
const size_t propertyCount = propertyLayout->GetPropertyCount();
|
||||
m_propertyNames.resize(propertyCount);
|
||||
for (size_t i = 0; i < propertyCount; ++i)
|
||||
{
|
||||
m_propertyNames[i] = propertyLayout->GetPropertyDescriptor(MaterialPropertyIndex{ i })->GetName();
|
||||
}
|
||||
|
||||
m_isDirty = false;
|
||||
}
|
||||
|
||||
void MaterialAsset::ReinitializeMaterialTypeAsset(Data::Asset<Data::AssetData> asset)
|
||||
{
|
||||
Data::Asset<MaterialTypeAsset> newMaterialTypeAsset = { asset.GetAs<MaterialTypeAsset>(), AZ::Data::AssetLoadBehavior::PreLoad };
|
||||
@@ -157,6 +193,8 @@ namespace AZ
|
||||
// This also covers the case where just the MaterialTypeAsset is reloaded and not the MaterialAsset.
|
||||
m_materialTypeAsset = newMaterialTypeAsset;
|
||||
|
||||
m_isDirty = true;
|
||||
|
||||
// Notify interested parties that this MaterialAsset is changed and may require other data to reinitialize as well
|
||||
MaterialReloadNotificationBus::Event(GetId(), &MaterialReloadNotifications::OnMaterialAssetReinitialized, Data::Asset<MaterialAsset>{this, AZ::Data::AssetLoadBehavior::PreLoad});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user