Updated MaterialTypeSourceData to force users to move the "version" indicator to the new location at the top level of the json document.

(It's a simple enough change to make manually, and making .materialtype is an uncommon workflow, so not worth doing this automatically).

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
santorac
2021-10-21 11:05:47 -07:00
parent dfcf88265b
commit f83b6594c9
16 changed files with 55 additions and 15 deletions
@@ -1,7 +1,7 @@
{
"description": "Base material for the reflection probe visualization model.",
"version": 1,
"propertyLayout": {
"version": 1,
"properties": {
"general": [
{
@@ -1,7 +1,7 @@
{
"description": "Base material for the reflection probe visualization model.",
"version": 1,
"propertyLayout": {
"version": 1,
"properties": {
"settings": [
{
@@ -1,7 +1,7 @@
{
"description": "Material Type with properties used to define Enhanced PBR, a metallic-roughness Physically-Based Rendering (PBR) material shading model, with advanced features like subsurface scattering, transmission, and anisotropy.",
"version": 3,
"propertyLayout": {
"version": 3,
"groups": [
{
"name": "baseColor",
@@ -1,7 +1,7 @@
{
"description": "Material Type tailored for rendering skin, with support for blended wrinkle maps that work with animated vertex blend shapes.",
"version": 3,
"propertyLayout": {
"version": 3,
"groups": [
{
"name": "baseColor",
@@ -1,7 +1,7 @@
{
"description": "Similar to StandardPBR but supports multiple layers blended together.",
"version": 3,
"propertyLayout": {
"version": 3,
"groups": [
{
"name": "blend",
@@ -1,7 +1,7 @@
{
"description": "Material Type with properties used to define Standard PBR, a metallic-roughness Physically-Based Rendering (PBR) material shading model.",
"version": 3,
"propertyLayout": {
"version": 3,
"groups": [
{
"name": "baseColor",
@@ -152,7 +152,7 @@
],
"baseColor": [
{
"name": "color",
"name": "colorX",
"displayName": "Color",
"description": "Color is displayed as sRGB but the values are stored as linear color.",
"type": "Color",
@@ -73,7 +73,8 @@ namespace AZ
//! 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.
ApplyVersionUpdatesResult ApplyVersionUpdates(AZStd::string_view materialSourceFilePath);
//! @param materialSourceFilePath Indicates the path of the .material file that the MaterialSourceData represents. Used for resolving file-relative paths.
ApplyVersionUpdatesResult ApplyVersionUpdates(AZStd::string_view materialSourceFilePath = "");
//! Creates a MaterialAsset from the MaterialSourceData content.
//! @param assetId ID for the MaterialAsset
@@ -147,6 +147,9 @@ namespace AZ
struct PropertyLayout
{
AZ_TYPE_INFO(AZ::RPI::MaterialTypeSourceData::PropertyLayout, "{AE53CF3F-5C3B-44F5-B2FB-306F0EB06393}");
//! This field is unused, and has been replaced by MaterialTypeSourceData::m_version below. It is kept for legacy file compatibility to suppress warnings and errors.
uint32_t m_versionOld = 0;
//! List of groups that will contain the available properties
AZStd::vector<GroupDefinition> m_groups;
@@ -47,7 +47,7 @@ namespace AZ
{
AssetBuilderSDK::AssetBuilderDesc materialBuilderDescriptor;
materialBuilderDescriptor.m_name = JobKey;
materialBuilderDescriptor.m_version = 109; // Changed "id" to "name" in serialization
materialBuilderDescriptor.m_version = 110; // Material version auto update feature
materialBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern("*.material", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
materialBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern("*.materialtype", AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
materialBuilderDescriptor.m_busId = azrtti_typeid<MaterialBuilder>();
@@ -46,8 +46,8 @@ namespace AZ
}
result.Combine(ContinueLoadingFromJsonObjectField(&materialSourceData->m_description, azrtti_typeid<AZStd::string>(), inputValue, "description", context));
result.Combine(ContinueLoadingFromJsonObjectField(&materialSourceData->m_materialType, azrtti_typeid<AZStd::string>(), inputValue, "materialType", context));
result.Combine(ContinueLoadingFromJsonObjectField(&materialSourceData->m_parentMaterial, azrtti_typeid<AZStd::string>(), inputValue, "parentMaterial", context));
result.Combine(ContinueLoadingFromJsonObjectField(&materialSourceData->m_materialType, azrtti_typeid<AZStd::string>(), inputValue, "materialType", context));
result.Combine(ContinueLoadingFromJsonObjectField(&materialSourceData->m_materialTypeVersion, azrtti_typeid<uint32_t>(), inputValue, "materialTypeVersion", context));
if (materialSourceData->m_materialType.empty())
@@ -151,8 +151,8 @@ namespace AZ
JSR::ResultCode resultCode(JSR::Tasks::ReadField);
resultCode.Combine(ContinueStoringToJsonObjectField(outputValue, "description", &materialSourceData->m_description, nullptr, azrtti_typeid<AZStd::string>(), context));
resultCode.Combine(ContinueStoringToJsonObjectField(outputValue, "materialType", &materialSourceData->m_materialType, nullptr, azrtti_typeid<AZStd::string>(), context));
resultCode.Combine(ContinueStoringToJsonObjectField(outputValue, "parentMaterial", &materialSourceData->m_parentMaterial, nullptr, azrtti_typeid<AZStd::string>(), context));
resultCode.Combine(ContinueStoringToJsonObjectField(outputValue, "materialType", &materialSourceData->m_materialType, nullptr, azrtti_typeid<AZStd::string>(), context));
resultCode.Combine(ContinueStoringToJsonObjectField(outputValue, "materialTypeVersion", &materialSourceData->m_materialTypeVersion, nullptr, azrtti_typeid<uint32_t>(), context));
resultCode.Combine(ContinueStoringToJsonObjectField(outputValue, "properties", &materialSourceData->m_properties, nullptr, azrtti_typeid<MaterialSourceData::PropertyGroupMap>(), context));
@@ -86,6 +86,7 @@ namespace AZ
serializeContext->Class<PropertyLayout>()
->Version(2) // Material Version Update
->Field("version", &PropertyLayout::m_versionOld)
->Field("groups", &PropertyLayout::m_groups)
->Field("properties", &PropertyLayout::m_properties)
;
@@ -351,6 +352,15 @@ namespace AZ
materialTypeAssetCreator.SetElevateWarnings(elevateWarnings);
materialTypeAssetCreator.Begin(assetId);
if (m_propertyLayout.m_versionOld != 0)
{
materialTypeAssetCreator.ReportError(
"The field '/propertyLayout/version' is deprecated and moved to '/version'. "
"Please edit this material type source file and move the '\"version\": %u' setting up one level.",
m_propertyLayout.m_versionOld);
return Failure();
}
// Set materialtype version and add each version update object into MaterialTypeAsset.
materialTypeAssetCreator.SetVersion(m_version);
{
@@ -1477,4 +1477,30 @@ namespace UnitTest
errorMessageFinder.CheckExpectedErrorsFound();
}
TEST_F(MaterialTypeSourceDataTests, CreateMaterialTypeAsset_Error_VersionInWrongLocation)
{
// The version field used to be under the propertyLayout section, but it has been moved up to the top level.
// If any users have their own custom .materialtype with an older format that has the version in the wrong place
// then we will report an error with instructions to move it to the correct location.
ErrorMessageFinder errorMessageFinder;
errorMessageFinder.AddExpectedErrorMessage("The field '/propertyLayout/version' is deprecated and moved to '/version'. Please edit this material type source file and move the '\"version\": 4' setting up one level");
const AZStd::string inputJson = R"(
{
"propertyLayout": {
"version": 4
}
}
)";
MaterialTypeSourceData materialType;
JsonTestResult loadResult = LoadTestDataFromJson(materialType, inputJson);
auto materialTypeOutcome = materialType.CreateMaterialTypeAsset(Uuid::CreateRandom());
EXPECT_FALSE(materialTypeOutcome.IsSuccess());
errorMessageFinder.CheckExpectedErrorsFound();
}
}
@@ -1,7 +1,7 @@
{
"description": "This is an example of a custom material type using Atom's PBR shading model: procedurally generated brick or tile.",
"version": 3,
"propertyLayout": {
"version": 3,
"groups": [
{
"name": "shape",
@@ -1,7 +1,7 @@
{
"description": "Base Material with properties used to define Standard PBR, a metallic-roughness Physically-Based Rendering (PBR) material shading model.",
"version": 3,
"propertyLayout": {
"version": 3,
"groups": [
{
"name": "settings",
@@ -1,7 +1,7 @@
{
"description": "A material for rendering terrain with a physically-based rendering (PBR) material shading model.",
"version": 1,
"propertyLayout": {
"version": 1,
"groups": [
{
"id": "settings",
@@ -1,7 +1,7 @@
{
"description": "A material for providing terrain with low-fidelity color and normals. This material will get blended with surface detail materials.",
"version": 1,
"propertyLayout": {
"version": 1,
"groups": [
{
"name": "baseColor",