Enumerating a Material Controller’s Properties
Enumerating the properties of a controller is simple. First, one needs to get the controller from a given material:
// iresmgr is the resource manager.
// mat is a material.
// Get the material controller from the material.
RED::Object* matctrl = iresmgr->GetMaterialController( mat );
RED::IMaterialController* imatctrl = matctrl->As< RED::IMaterialController >();
Then, the controller property gives access to its number of properties via the RED::IMaterialController::GetPropertiesCount
method and to its properties by index or by name with the RED::IMaterialController::GetProperty
function:
// Get the number of properties.
unsigned int count = imatctrl->GetPropertiesCount();
// Loop through the properties.
for( unsigned int i = 0; i < count; ++i )
{
// Get the property.
RED::Object* prop = imatctrl->GetProperty( i );
RED::IMaterialControllerProperty* iprop = prop->As< RED::IMaterialControllerProperty >();
// Get the type of the property.
RED::PROPERTY_TYPE type = iprop->GetType();
// Do something according to the property type.
switch( type )
{
case RED::PYT_FLOAT:
{
float value = iprop->GetFloatValue();
// Do something...
RC_TEST( iprop->SetFloatValue( value, iresmgr->GetState() ) );
break;
}
case RED::PYT_COLOR:
{
RED::Color color = iprop->GetColor();
// Do something...
RC_TEST( iprop->SetColor( color, iresmgr->GetState() ) );
break;
}
case RED::PYT_TEXTURE2D:
{
const RED::Object* texture = iprop->GetTexture();
const RED::IImage2D* itexture = texture->As< RED::IImage2D >();
// Do something...
break;
}
// etc.
}
}