Solved Getting material 'use' flag

Hi folks,

having a time trying to get simple material parameters. Would like to get the tick box next to the main options in the material window, like Color and Reflection.

I've been around in circles with the following:

BaseTag *tag = obj->GetFirstTag();
BaseMaterial *texture = (BaseMaterial*)tag;

if(texture->GetParameter(DescID(MATERIAL_USE_COLOR),data,DESCFLAGS_GET_0) && data == true)
{
    // this never runs
}

A few assumptions with the above, but you get the idea. Where am I going wrong here?

WP.

@wickedp You can't just cast a BaseTag to a BaseMaterial.

Rather check if the tag is really a TextureTag, cast it to TextureTag, and then ask it for the material link.

// Get the first texture tag
BaseTag* const tagPtr = obj->GetTag(Ttexture);
if (tagPtr)
{
  // Cast BaseTag* to TextureTag*
  TextureTag* const textureTagPtr = static_cast<TextureTag*>(tagPtr);

  // Get material pointer from the texture tag
  BaseMaterial* const materialPtr = textureTagPtr->GetMaterial();
  if (materialPtr)
  {
    // Check if color channel is active
    if (materialPtr->GetChannelState(CHANNEL_COLOR))
    {
      // Change material settings here
    }
  }
}

Check out the SDK docs ;-)
https://developers.maxon.net/docs/Cinema4DCPPSDK/html/class_material.html

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.

@wickedp You can't just cast a BaseTag to a BaseMaterial.

Rather check if the tag is really a TextureTag, cast it to TextureTag, and then ask it for the material link.

// Get the first texture tag
BaseTag* const tagPtr = obj->GetTag(Ttexture);
if (tagPtr)
{
  // Cast BaseTag* to TextureTag*
  TextureTag* const textureTagPtr = static_cast<TextureTag*>(tagPtr);

  // Get material pointer from the texture tag
  BaseMaterial* const materialPtr = textureTagPtr->GetMaterial();
  if (materialPtr)
  {
    // Check if color channel is active
    if (materialPtr->GetChannelState(CHANNEL_COLOR))
    {
      // Change material settings here
    }
  }
}

Check out the SDK docs ;-)
https://developers.maxon.net/docs/Cinema4DCPPSDK/html/class_material.html

Cheers,
Frank

www.frankwilleke.de
Only asking personal code questions here.

Thanks Frank,

@fwilleke80 said in Getting material 'use' flag:

BaseMaterial* const materialPtr = textureTagPtr->GetMaterial();

Yep, that's what I was missing. I was thinking the texture tag was the material, but it wasn't and I needed to get the link to the material from the texture tag.

Cheers,

WP.