Open 3D Engine Atom Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::RPI::MaterialPropertyValue Class Referencefinal

#include <MaterialPropertyValue.h>

Public Types

using ValueType = AZStd::variant< AZStd::monostate, bool, int32_t, uint32_t, float, Vector2, Vector3, Vector4, Color, Data::Asset< ImageAsset >, Data::Instance< Image >, AZStd::string >
 

Public Member Functions

 AZ_TYPE_INFO (AZ::RPI::MaterialPropertyValue, "{59815051-BBA2-4C6A-A414-A82834A84CB2}")
 
 MaterialPropertyValue ()=default
 Constructors to allow implicit conversions.
 
 MaterialPropertyValue (const bool &value)
 
 MaterialPropertyValue (const int32_t &value)
 
 MaterialPropertyValue (const uint32_t &value)
 
 MaterialPropertyValue (const float &value)
 
 MaterialPropertyValue (const Vector2 &value)
 
 MaterialPropertyValue (const Vector3 &value)
 
 MaterialPropertyValue (const Vector4 &value)
 
 MaterialPropertyValue (const Color &value)
 
 MaterialPropertyValue (const Data::Asset< ImageAsset > &value)
 
 MaterialPropertyValue (const Data::Instance< Image > &value)
 
 MaterialPropertyValue (const AZStd::string &value)
 
 MaterialPropertyValue (const Name &value)
 
 MaterialPropertyValue (const MaterialPropertyValue &value)
 Copy constructor.
 
template<typename T >
MaterialPropertyValueoperator= (const T &value)
 
template<typename T >
const T & GetValue () const
 
template<typename T >
bool Is () const
 Check if the type holding is T.
 
TypeId GetTypeId () const
 Get TypeId of the type holding.
 
bool IsValid () const
 Check if the variant is holding a valid value.
 
bool operator== (const MaterialPropertyValue &other) const
 Default comparison.
 
bool operator!= (const MaterialPropertyValue &other) const
 
MaterialPropertyValue CastToType (TypeId requestedType) const
 

Static Public Member Functions

static void Reflect (ReflectContext *context)
 
static MaterialPropertyValue FromAny (const AZStd::any &value)
 
static AZStd::any ToAny (const MaterialPropertyValue &value)
 

Detailed Description

This is a variant data type that represents the value of a material property. For convenience, it supports all the types necessary for both the runtime data (MaterialAsset) as well as .material file data (MaterialSourceData). For example, Instance<Image> is exclusive to the runtime data and AZStd::string is primarily for image file paths in .material files. Most other data types are relevant in both contexts.

Member Typedef Documentation

◆ ValueType

using AZ::RPI::MaterialPropertyValue::ValueType = AZStd::variant<AZStd::monostate, bool, int32_t, uint32_t, float, Vector2, Vector3, Vector4, Color, Data::Asset<ImageAsset>, Data::Instance<Image>, AZStd::string>

Variant type definition. AZStd::monostate is used as default and invalid value. Specially, image type is stored in different type under different contexts: Data::Instance<Image> is used in Material at runtime Data::Asset<ImageAsset> is used in MaterialTypeAsset, MaterialAsset AZStd::string is used in MaterialTypeSourceData, MaterialSourceData These are included in one MaterialPropertyValue type for convenience, rather than having to maintain three separate classes that are very similar

Member Function Documentation

◆ CastToType()

MaterialPropertyValue AZ::RPI::MaterialPropertyValue::CastToType ( TypeId  requestedType) const

Attempt to cast the value to another type, handling numerical types (e.g. int to float, bool to int), vector types (e.g. Vector2 to Vector3) and color<->vector types (e.g. Vector[3-4] to Color). In conversions between vector based types of different dimension, the result gets truncated or padded with zeroes as needed. Conversions between color and vector types are only supported for 3 and 4 dimensional vectors. In case of incompatible types (e.g. string to float, Vector2 to Color), the current object is returned as-is.

◆ FromAny()

static MaterialPropertyValue AZ::RPI::MaterialPropertyValue::FromAny ( const AZStd::any &  value)
static

Two-way conversion to AZStd::any If the type in AZStd::any is not in ValueType, a warning will be reported and AZStd::monostate will be returned.

◆ GetValue()

template<typename T >
const T & AZ::RPI::MaterialPropertyValue::GetValue ( ) const
inline

Get actual value from the variant. The type will be restricted as in operator=().

◆ operator=()

template<typename T >
MaterialPropertyValue & AZ::RPI::MaterialPropertyValue::operator= ( const T &  value)
inline

Templated assignment. The type will be restricted to those defined in the variant at compile time. If out-of-definition type is used, the compiler will report error.


The documentation for this class was generated from the following file: