Removed unnecessary MaterialSourceData::Property class.
This wrapper used to be needed in order to bind the custom JsonMaterialPropertyValueSerializer back when property values were represented by AZStd::any. Now that property values have a custom MaterialPropertyValue type, the wrapper class is no longer needed. Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
@@ -101,7 +101,7 @@ namespace AZ
|
||||
|
||||
if (assetFound)
|
||||
{
|
||||
properties["textureMap"].m_value = texturePath;
|
||||
properties["textureMap"] = texturePath;
|
||||
}
|
||||
else if (!texturePath.empty())
|
||||
{
|
||||
@@ -120,7 +120,7 @@ namespace AZ
|
||||
{
|
||||
anyPBRInUse = true;
|
||||
handleTexture("baseColor", SceneAPI::DataTypes::IMaterialData::TextureMapType::BaseColor);
|
||||
sourceData.m_properties["baseColor"]["textureBlendMode"].m_value = AZStd::string("Lerp");
|
||||
sourceData.m_properties["baseColor"]["textureBlendMode"] = AZStd::string("Lerp");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -135,10 +135,10 @@ namespace AZ
|
||||
if (baseColor.has_value())
|
||||
{
|
||||
anyPBRInUse = true;
|
||||
sourceData.m_properties["baseColor"]["color"].m_value = toColor(baseColor.value());
|
||||
sourceData.m_properties["baseColor"]["color"] = toColor(baseColor.value());
|
||||
}
|
||||
|
||||
sourceData.m_properties["opacity"]["factor"].m_value = materialData.GetOpacity();
|
||||
sourceData.m_properties["opacity"]["factor"] = materialData.GetOpacity();
|
||||
|
||||
auto applyOptionalPropertiesFunc = [&sourceData, &anyPBRInUse](const auto& propertyGroup, const auto& propertyName, const auto& propertyOptional)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace AZ
|
||||
if (propertyOptional.has_value())
|
||||
{
|
||||
anyPBRInUse = true;
|
||||
sourceData.m_properties[propertyGroup][propertyName].m_value = propertyOptional.value();
|
||||
sourceData.m_properties[propertyGroup][propertyName] = propertyOptional.value();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace AZ
|
||||
applyOptionalPropertiesFunc("roughness", "useTexture", materialData.GetUseRoughnessMap());
|
||||
|
||||
handleTexture("emissive", SceneAPI::DataTypes::IMaterialData::TextureMapType::Emissive);
|
||||
sourceData.m_properties["emissive"]["color"].m_value = toColor(materialData.GetEmissiveColor());
|
||||
sourceData.m_properties["emissive"]["color"] = toColor(materialData.GetEmissiveColor());
|
||||
applyOptionalPropertiesFunc("emissive", "intensity", materialData.GetEmissiveIntensity());
|
||||
applyOptionalPropertiesFunc("emissive", "useTexture", materialData.GetUseEmissiveMap());
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace AZ
|
||||
{
|
||||
// If it doesn't have the useColorMap property, then it's a non-PBR material and the baseColor
|
||||
// texture needs to be set to the diffuse color.
|
||||
sourceData.m_properties["baseColor"]["color"].m_value = toColor(materialData.GetDiffuseColor());
|
||||
sourceData.m_properties["baseColor"]["color"] = toColor(materialData.GetDiffuseColor());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,14 +59,7 @@ namespace AZ
|
||||
|
||||
uint32_t m_materialTypeVersion = 0; //!< The version of the material type that was used to configure this material
|
||||
|
||||
struct Property
|
||||
{
|
||||
AZ_TYPE_INFO(AZ::RPI::MaterialSourceData::Property, "{8D613464-3750-4122-AFFE-9238010D5AFC}");
|
||||
|
||||
MaterialPropertyValue m_value;
|
||||
};
|
||||
|
||||
using PropertyMap = AZStd::map<AZStd::string, Property>;
|
||||
using PropertyMap = AZStd::map<AZStd::string, MaterialPropertyValue>;
|
||||
using PropertyGroupMap = AZStd::map<AZStd::string, PropertyMap>;
|
||||
|
||||
PropertyGroupMap m_properties;
|
||||
|
||||
@@ -47,61 +47,61 @@ namespace AZ
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(azrtti_typeid<MaterialSourceData::Property>() == outputValueTypeId,
|
||||
AZ_Assert(azrtti_typeid<MaterialPropertyValue>() == outputValueTypeId,
|
||||
"Unable to deserialize material property value to json because the provided type is %s",
|
||||
outputValueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(outputValueTypeId);
|
||||
|
||||
MaterialSourceData::Property* property = reinterpret_cast<MaterialSourceData::Property*>(outputValue);
|
||||
MaterialPropertyValue* property = reinterpret_cast<MaterialPropertyValue*>(outputValue);
|
||||
AZ_Assert(property, "Output value for JsonMaterialPropertyValueSerializer can't be null.");
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::ReadField);
|
||||
|
||||
if (inputValue.IsBool())
|
||||
{
|
||||
result.Combine(LoadVariant<bool>(property->m_value, false, inputValue, context));
|
||||
result.Combine(LoadVariant<bool>(*property, false, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsInt() || inputValue.IsInt64())
|
||||
{
|
||||
result.Combine(LoadVariant<int32_t>(property->m_value, 0, inputValue, context));
|
||||
result.Combine(LoadVariant<int32_t>(*property, 0, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsUint() || inputValue.IsUint64())
|
||||
{
|
||||
result.Combine(LoadVariant<uint32_t>(property->m_value, 0u, inputValue, context));
|
||||
result.Combine(LoadVariant<uint32_t>(*property, 0u, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsFloat() || inputValue.IsDouble())
|
||||
{
|
||||
result.Combine(LoadVariant<float>(property->m_value, 0.0f, inputValue, context));
|
||||
result.Combine(LoadVariant<float>(*property, 0.0f, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsArray() && inputValue.Size() == 4)
|
||||
{
|
||||
result.Combine(LoadVariant<Vector4>(property->m_value, Vector4{0.0f, 0.0f, 0.0f, 0.0f}, inputValue, context));
|
||||
result.Combine(LoadVariant<Vector4>(*property, Vector4{0.0f, 0.0f, 0.0f, 0.0f}, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsArray() && inputValue.Size() == 3)
|
||||
{
|
||||
result.Combine(LoadVariant<Vector3>(property->m_value, Vector3{0.0f, 0.0f, 0.0f}, inputValue, context));
|
||||
result.Combine(LoadVariant<Vector3>(*property, Vector3{0.0f, 0.0f, 0.0f}, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsArray() && inputValue.Size() == 2)
|
||||
{
|
||||
result.Combine(LoadVariant<Vector2>(property->m_value, Vector2{0.0f, 0.0f}, inputValue, context));
|
||||
result.Combine(LoadVariant<Vector2>(*property, Vector2{0.0f, 0.0f}, inputValue, context));
|
||||
}
|
||||
else if (inputValue.IsObject())
|
||||
{
|
||||
JsonSerializationResult::ResultCode resultCode = LoadVariant<Color>(property->m_value, Color::CreateZero(), inputValue, context);
|
||||
JsonSerializationResult::ResultCode resultCode = LoadVariant<Color>(*property, Color::CreateZero(), inputValue, context);
|
||||
|
||||
if(resultCode.GetProcessing() != JsonSerializationResult::Processing::Completed)
|
||||
{
|
||||
resultCode = LoadVariant<Vector4>(property->m_value, Vector4::CreateZero(), inputValue, context);
|
||||
resultCode = LoadVariant<Vector4>(*property, Vector4::CreateZero(), inputValue, context);
|
||||
}
|
||||
|
||||
if(resultCode.GetProcessing() != JsonSerializationResult::Processing::Completed)
|
||||
{
|
||||
resultCode = LoadVariant<Vector3>(property->m_value, Vector3::CreateZero(), inputValue, context);
|
||||
resultCode = LoadVariant<Vector3>(*property, Vector3::CreateZero(), inputValue, context);
|
||||
}
|
||||
|
||||
if(resultCode.GetProcessing() != JsonSerializationResult::Processing::Completed)
|
||||
{
|
||||
resultCode = LoadVariant<Vector2>(property->m_value, Vector2::CreateZero(), inputValue, context);
|
||||
resultCode = LoadVariant<Vector2>(*property, Vector2::CreateZero(), inputValue, context);
|
||||
}
|
||||
|
||||
if(resultCode.GetProcessing() == JsonSerializationResult::Processing::Completed)
|
||||
@@ -115,7 +115,7 @@ namespace AZ
|
||||
}
|
||||
else if (inputValue.IsString())
|
||||
{
|
||||
result.Combine(LoadVariant<AZStd::string>(property->m_value, AZStd::string{}, inputValue, context));
|
||||
result.Combine(LoadVariant<AZStd::string>(*property, AZStd::string{}, inputValue, context));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -137,51 +137,51 @@ namespace AZ
|
||||
{
|
||||
namespace JSR = JsonSerializationResult;
|
||||
|
||||
AZ_Assert(azrtti_typeid<MaterialSourceData::Property>() == valueTypeId,
|
||||
AZ_Assert(azrtti_typeid<MaterialPropertyValue>() == valueTypeId,
|
||||
"Unable to serialize material property value to json because the provided type is %s",
|
||||
valueTypeId.ToString<AZStd::string>().c_str());
|
||||
AZ_UNUSED(valueTypeId);
|
||||
|
||||
const MaterialSourceData::Property* property = reinterpret_cast<const MaterialSourceData::Property*>(inputValue);
|
||||
const MaterialPropertyValue* property = reinterpret_cast<const MaterialPropertyValue*>(inputValue);
|
||||
AZ_Assert(property, "Input value for JsonMaterialPropertyValueSerializer can't be null.");
|
||||
|
||||
JSR::ResultCode result(JSR::Tasks::WriteValue);
|
||||
|
||||
if (property->m_value.Is<bool>())
|
||||
if (property->Is<bool>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<bool>(), nullptr, azrtti_typeid<bool>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<bool>(), nullptr, azrtti_typeid<bool>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<int32_t>())
|
||||
else if (property->Is<int32_t>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<int32_t>(), nullptr, azrtti_typeid<int32_t>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<int32_t>(), nullptr, azrtti_typeid<int32_t>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<uint32_t>())
|
||||
else if (property->Is<uint32_t>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<uint32_t>(), nullptr, azrtti_typeid<uint32_t>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<uint32_t>(), nullptr, azrtti_typeid<uint32_t>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<float>())
|
||||
else if (property->Is<float>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<float>(), nullptr, azrtti_typeid<float>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<float>(), nullptr, azrtti_typeid<float>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<Vector2>())
|
||||
else if (property->Is<Vector2>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<Vector2>(), nullptr, azrtti_typeid<Vector2>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<Vector2>(), nullptr, azrtti_typeid<Vector2>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<Vector3>())
|
||||
else if (property->Is<Vector3>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<Vector3>(), nullptr, azrtti_typeid<Vector3>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<Vector3>(), nullptr, azrtti_typeid<Vector3>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<Vector4>())
|
||||
else if (property->Is<Vector4>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<Vector4>(), nullptr, azrtti_typeid<Vector4>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<Vector4>(), nullptr, azrtti_typeid<Vector4>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<Color>())
|
||||
else if (property->Is<Color>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<Color>(), nullptr, azrtti_typeid<Color>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<Color>(), nullptr, azrtti_typeid<Color>(), context));
|
||||
}
|
||||
else if (property->m_value.Is<AZStd::string>())
|
||||
else if (property->Is<AZStd::string>())
|
||||
{
|
||||
result.Combine(ContinueStoring(outputValue, &property->m_value.GetValue<AZStd::string>(), nullptr, azrtti_typeid<AZStd::string>(), context));
|
||||
result.Combine(ContinueStoring(outputValue, &property->GetValue<AZStd::string>(), nullptr, azrtti_typeid<AZStd::string>(), context));
|
||||
}
|
||||
|
||||
if (result.GetProcessing() == JsonSerializationResult::Processing::Completed)
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace AZ
|
||||
{
|
||||
if (JsonRegistrationContext* jsonContext = azrtti_cast<JsonRegistrationContext*>(context))
|
||||
{
|
||||
jsonContext->Serializer<JsonMaterialPropertyValueSerializer>()->HandlesType<MaterialSourceData::Property>();
|
||||
jsonContext->Serializer<JsonMaterialPropertyValueSerializer>()->HandlesType<MaterialPropertyValue>();
|
||||
}
|
||||
else if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
|
||||
{
|
||||
@@ -59,10 +59,6 @@ namespace AZ
|
||||
|
||||
serializeContext->RegisterGenericType<PropertyMap>();
|
||||
serializeContext->RegisterGenericType<PropertyGroupMap>();
|
||||
|
||||
serializeContext->Class<MaterialSourceData::Property>()
|
||||
->Version(1)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,25 +319,25 @@ namespace AZ
|
||||
for (auto& property : group.second)
|
||||
{
|
||||
MaterialPropertyId propertyId{ group.first, property.first };
|
||||
if (!property.second.m_value.IsValid())
|
||||
if (!property.second.IsValid())
|
||||
{
|
||||
materialAssetCreator.ReportWarning("Source data for material property value is invalid.");
|
||||
}
|
||||
// If the source value type is a string, there are two possible property types: Image and Enum. If there is a "." in
|
||||
// the string (for the extension) we assume it's an Image and look up the referenced Asset. Otherwise, we can assume
|
||||
// it's an Enum value and just preserve the original string.
|
||||
else if (property.second.m_value.Is<AZStd::string>() && AzFramework::StringFunc::Contains(property.second.m_value.GetValue<AZStd::string>(), "."))
|
||||
else if (property.second.Is<AZStd::string>() && AzFramework::StringFunc::Contains(property.second.GetValue<AZStd::string>(), "."))
|
||||
{
|
||||
Data::Asset<ImageAsset> imageAsset;
|
||||
|
||||
MaterialUtils::GetImageAssetResult result = MaterialUtils::GetImageAssetReference(
|
||||
imageAsset, materialSourceFilePath, property.second.m_value.GetValue<AZStd::string>());
|
||||
imageAsset, materialSourceFilePath, property.second.GetValue<AZStd::string>());
|
||||
|
||||
if (result == MaterialUtils::GetImageAssetResult::Missing)
|
||||
{
|
||||
materialAssetCreator.ReportWarning(
|
||||
"Material property '%s': Could not find the image '%s'", propertyId.GetCStr(),
|
||||
property.second.m_value.GetValue<AZStd::string>().data());
|
||||
property.second.GetValue<AZStd::string>().data());
|
||||
}
|
||||
|
||||
imageAsset.SetAutoLoadBehavior(Data::AssetLoadBehavior::PreLoad);
|
||||
@@ -349,7 +345,7 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
materialAssetCreator.SetPropertyValue(propertyId, property.second.m_value);
|
||||
materialAssetCreator.SetPropertyValue(propertyId, property.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace UnitTest
|
||||
|
||||
void AddProperty(MaterialSourceData& material, AZStd::string_view groupName, AZStd::string_view propertyName, const MaterialPropertyValue& anyValue)
|
||||
{
|
||||
material.m_properties[groupName][propertyName].m_value = anyValue;
|
||||
material.m_properties[groupName][propertyName] = anyValue;
|
||||
}
|
||||
|
||||
TEST_F(MaterialSourceDataTests, CreateMaterialAsset_BasicProperties)
|
||||
@@ -398,33 +398,33 @@ namespace UnitTest
|
||||
|
||||
// We allow some types like Vector4 and Color or Int and UInt to be interchangeable since they serialize the same and can be converted when the MaterialAsset is finalized.
|
||||
|
||||
if (AreTypesCompatible<bool>(propertyA.m_value, propertyB.m_value))
|
||||
if (AreTypesCompatible<bool>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_EQ(propertyA.m_value.GetValue<bool>(), propertyB.m_value.GetValue<bool>()) << propertyReference.c_str();
|
||||
EXPECT_EQ(propertyA.GetValue<bool>(), propertyB.GetValue<bool>()) << propertyReference.c_str();
|
||||
}
|
||||
else if (AreTypesCompatible<int32_t>(propertyA.m_value, propertyB.m_value))
|
||||
else if (AreTypesCompatible<int32_t>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_EQ(GetAsInt(propertyA.m_value), GetAsInt(propertyB.m_value)) << propertyReference.c_str();
|
||||
EXPECT_EQ(GetAsInt(propertyA), GetAsInt(propertyB)) << propertyReference.c_str();
|
||||
}
|
||||
else if (AreTypesCompatible<float>(propertyA.m_value, propertyB.m_value))
|
||||
else if (AreTypesCompatible<float>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_NEAR(propertyA.m_value.GetValue<float>(), propertyB.m_value.GetValue<float>(), 0.01) << propertyReference.c_str();
|
||||
EXPECT_NEAR(propertyA.GetValue<float>(), propertyB.GetValue<float>(), 0.01) << propertyReference.c_str();
|
||||
}
|
||||
else if (AreTypesCompatible<Vector2>(propertyA.m_value, propertyB.m_value))
|
||||
else if (AreTypesCompatible<Vector2>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_TRUE(propertyA.m_value.GetValue<Vector2>().IsClose(propertyB.m_value.GetValue<Vector2>())) << propertyReference.c_str();
|
||||
EXPECT_TRUE(propertyA.GetValue<Vector2>().IsClose(propertyB.GetValue<Vector2>())) << propertyReference.c_str();
|
||||
}
|
||||
else if (AreTypesCompatible<Vector3>(propertyA.m_value, propertyB.m_value))
|
||||
else if (AreTypesCompatible<Vector3>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_TRUE(propertyA.m_value.GetValue<Vector3>().IsClose(propertyB.m_value.GetValue<Vector3>())) << propertyReference.c_str();
|
||||
EXPECT_TRUE(propertyA.GetValue<Vector3>().IsClose(propertyB.GetValue<Vector3>())) << propertyReference.c_str();
|
||||
}
|
||||
else if (AreTypesCompatible<Vector4>(propertyA.m_value, propertyB.m_value))
|
||||
else if (AreTypesCompatible<Vector4>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_TRUE(GetAsVector4(propertyA.m_value).IsClose(GetAsVector4(propertyB.m_value))) << propertyReference.c_str();
|
||||
EXPECT_TRUE(GetAsVector4(propertyA).IsClose(GetAsVector4(propertyB))) << propertyReference.c_str();
|
||||
}
|
||||
else if (AreTypesCompatible<AZStd::string>(propertyA.m_value, propertyB.m_value))
|
||||
else if (AreTypesCompatible<AZStd::string>(propertyA, propertyB))
|
||||
{
|
||||
EXPECT_STREQ(propertyA.m_value.GetValue<AZStd::string>().c_str(), propertyB.m_value.GetValue<AZStd::string>().c_str()) << propertyReference.c_str();
|
||||
EXPECT_STREQ(propertyA.GetValue<AZStd::string>().c_str(), propertyB.GetValue<AZStd::string>().c_str()) << propertyReference.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -513,7 +513,7 @@ namespace UnitTest
|
||||
EXPECT_EQ(AZ::JsonSerializationResult::Tasks::ReadField, loadResult.m_jsonResultCode.GetTask());
|
||||
EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, loadResult.m_jsonResultCode.GetProcessing());
|
||||
|
||||
float testValue = material.m_properties["general"]["testValue"].m_value.GetValue<float>();
|
||||
float testValue = material.m_properties["general"]["testValue"].GetValue<float>();
|
||||
EXPECT_FLOAT_EQ(1.2f, testValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ namespace MaterialEditor
|
||||
|
||||
// TODO: Support populating the Material Editor with nested property groups, not just the top level.
|
||||
const AZStd::string groupName = propertyId.GetStringView().substr(0, propertyId.GetStringView().size() - propertyDefinition->GetName().size() - 1);
|
||||
sourceData.m_properties[groupName][propertyDefinition->GetName()].m_value = propertyValue;
|
||||
sourceData.m_properties[groupName][propertyDefinition->GetName()] = propertyValue;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ namespace AZ
|
||||
|
||||
// TODO: Support populating the Material Editor with nested property groups, not just the top level.
|
||||
const AZStd::string groupName = propertyId.GetStringView().substr(0, propertyId.GetStringView().size() - propertyDefinition->GetName().size() - 1);
|
||||
exportData.m_properties[groupName][propertyDefinition->GetName()].m_value = propertyValue;
|
||||
exportData.m_properties[groupName][propertyDefinition->GetName()] = propertyValue;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user