Added support for material version updates in MaterialSourceData. This is necessary for tools like Material Editor and Asset Processor to work with the latest property names.
- Added MaterialSourceData::ApplyVersionUpdates() for updating the properties. This should be called by tools after loading the MaterialSourceData. (But can be omitted if a tool wants to read the data exactly as it appears in the .material file). - Updated MaterialTypeSourceData::FindProperty to support applying version update renames, including a ApplyPropertyRenames utility function, which are necessary for MaterialSourceData to be able to find the necessary property definitons while loading. - Added a new context struct to JsonMaterialPropertyValueSerializer for passing down the material type version number, to help with applying property renames. - Renamed the .material file format "propertyLayoutVersion" to "materialTypeVersion" which is more accurate. This shouldn't hurt existing data as this field wasn't actually used for anything before. - Updated Material Editor to again store the material type version number in .material files. MaterialSourceDataTests updates... - Updated to include both a .materialtype file and a MaterialTypeAsset for the test material type. Both are used by the MaterialTypeSourceData class. - The default test material type now includes some version update steps; these are only used for version update tests and won't impact the other test functions. - Updated the path for storing temp files to disk, to just be in a "temp" folder in the exe path. (Originally they were saved to the gem folder near MaterialSourceDataTests.cpp, but at some point someone changed it to be under the exe folder, so there's no reason to use the full gem path anymore). MaterialTypeSourceDataTests updates... - Moved some code that was accidentally added to LoadAllFieldsUsingOldFormat but should have been in LoadAndStoreJson_AllFields. - Added test cases for unsupported version update operations Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -24,6 +24,13 @@ namespace AZ
|
||||
AZ_RTTI(AZ::RPI::JsonMaterialPropertyValueSerializer, "{A52B1ED8-C849-4269-9AA7-9D0814D2EC59}", BaseJsonSerializer);
|
||||
AZ_CLASS_ALLOCATOR_DECL;
|
||||
|
||||
//! A LoadContext object must be passed down to the serializer via JsonDeserializerContext::GetMetadata().Add(...)
|
||||
struct LoadContext
|
||||
{
|
||||
AZ_TYPE_INFO(JsonMaterialPropertyValueSerializer::LoadContext, "{5E0A891A-27F6-4AD7-88A5-B9EA50F88B45}");
|
||||
uint32_t m_materialTypeVersion; //!< The version number from the .materialtype file
|
||||
};
|
||||
|
||||
JsonSerializationResult::Result Load(void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue,
|
||||
JsonDeserializerContext& context) override;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace AZ
|
||||
|
||||
AZStd::string m_parentMaterial; //!< The immediate parent of this material
|
||||
|
||||
uint32_t m_propertyLayoutVersion = 0; //!< The version of the property layout, defined in the material type, which was used to configure this material
|
||||
uint32_t m_materialTypeVersion = 0; //!< The version of the material type that was used to configure this material
|
||||
|
||||
struct Property
|
||||
{
|
||||
@@ -64,6 +64,10 @@ namespace AZ
|
||||
|
||||
PropertyGroupMap m_properties;
|
||||
|
||||
//! Checks the material type version and potentially applies a series of property changes (most common are simple property renames)
|
||||
//! based on the MaterialTypeAsset's version update procedure.
|
||||
bool ApplyVersionUpdates();
|
||||
|
||||
//! Creates a MaterialAsset from the MaterialSourceData content.
|
||||
//! @param assetId ID for the MaterialAsset
|
||||
//! @param materialSourceFilePath Indicates the path of the .material file that the MaterialSourceData represents. Used for resolving file-relative paths.
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Atom/RPI.Reflect/Base.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialPropertyDescriptor.h>
|
||||
#include <Atom/RPI.Edit/Material/MaterialFunctorSourceData.h>
|
||||
#include <Atom/RPI.Edit/Material/MaterialPropertyId.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -179,7 +180,12 @@ namespace AZ
|
||||
|
||||
const GroupDefinition* FindGroup(AZStd::string_view groupName) const;
|
||||
|
||||
const PropertyDefinition* FindProperty(AZStd::string_view groupName, AZStd::string_view propertyName) const;
|
||||
//! Searches for a specific property.
|
||||
//! Note this function can find properties using old versions of the property name; in that case,
|
||||
//! the name in the returned PropertyDefinition* will not match the @propertyName that was searched for.
|
||||
//! @param materialTypeVersion indicates the version number of the property name being passed in. Only renames above this version number will be applied.
|
||||
//! @return the requested property, or null if it could not be found
|
||||
const PropertyDefinition* FindProperty(AZStd::string_view groupName, AZStd::string_view propertyName, uint32_t materialTypeVersion = 0) const;
|
||||
|
||||
//! Construct a complete list of group definitions, including implicit groups, arranged in the same order as the source data
|
||||
//! Groups with the same name will be consolidated into a single entry
|
||||
@@ -205,6 +211,11 @@ namespace AZ
|
||||
bool ConvertPropertyValueToSourceDataFormat(const PropertyDefinition& propertyDefinition, MaterialPropertyValue& propertyValue) const;
|
||||
|
||||
Outcome<Data::Asset<MaterialTypeAsset>> CreateMaterialTypeAsset(Data::AssetId assetId, AZStd::string_view materialTypeSourceFilePath = "", bool elevateWarnings = true) const;
|
||||
|
||||
//! Possibly renames @propertyId based on the material version update steps.
|
||||
//! @param materialTypeVersion indicates the version number of the property name being passed in. Only renames above this version number will be applied.
|
||||
//! @return true if the property was renamed
|
||||
bool ApplyPropertyRenames(MaterialPropertyId& propertyId, uint32_t materialTypeVersion = 0) const;
|
||||
};
|
||||
|
||||
//! The wrapper class for derived material functors.
|
||||
|
||||
@@ -122,7 +122,8 @@ namespace AZ
|
||||
//! from m_materialTypeAsset.
|
||||
void RealignPropertyValuesAndNames();
|
||||
|
||||
//! Renames properties in m_propertyNames based on the MaterialTypeAsset's version update. Note that only version upgrades are supported.
|
||||
//! Checks the material type version and potentially applies a series of property changes (most common are simple property renames)
|
||||
//! based on the MaterialTypeAsset's version update procedure.
|
||||
void ApplyVersionUpdates();
|
||||
|
||||
//! Called by asset creators to assign the asset to a ready state.
|
||||
|
||||
Reference in New Issue
Block a user