Unable to retrieve LayerSet from Shader

On 26/03/2013 at 02:29, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R14 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hi folks,
I'm trying to modify the LayerSet of a BitmapShader. But I always get a NULL pointer with the following code:

  
BaseShader *tex = BaseShader::Alloc(Xbitmap);   
if (!tex)   
{   
    BaseMaterial::Free(mat);   
    return NULL;   
}   
mat->InsertShader(tex);   
tex->SetParameter(BITMAPSHADER_FILENAME, GeData(Filename("...")), DESCFLAGS_SET_0);   
GeData dLayerSet;   
if (tex->GetParameter(BITMAPSHADER_LAYERSET, dLayerSet, DESCFLAGS_GET_0))   
{   
    LayerSet *layerSet = static_cast<LayerSet*>(dLayerSet.GetCustomDataType(CUSTOMDATATYPE_LAYERSET));   
    if (layerSet)   
    {   
        layerSet->SetMode(LAYERSETMODE_LAYERALPHA);   
    }   
}   

Does anyone know what's wrong here?
Thanks in advance!
Satara

On 26/03/2013 at 04:03, xxxxxxxx wrote:

Ok seems that I have to allocate it by myself.
This works fine:

  
LayerSet *layerSet = static_cast<LayerSet*>(dLayerSet.GetCustomDataType(CUSTOMDATATYPE_LAYERSET));   
if (!layerSet) layerSet = LayerSet::Alloc();   
if (layerSet)   
{   
    layerSet->SetMode(LAYERSETMODE_ALPHAS);   
    layerSet->AddLayer("Alpha");   
    dLayerSet.SetCustomDataType(CUSTOMDATATYPE_LAYERSET, *layerSet);   
    tex->SetParameter(BITMAPSHADER_LAYERSET, dLayerSet, DESCFLAGS_SET_0);   
}   

On 26/03/2013 at 08:14, xxxxxxxx wrote:

Hi Satara,

Thanks for posting the code. But I'm having a hard time getting your code to work.
And I can't find much information about the LayerSet type.

This code produces an "unexpected type" compile error:

LayerSet *layerSet = static_cast<LayerSet*>(dLayerSet.GetCustomDataType(CUSTOMDATATYPE_LAYERSET));

Are you including this header file?: customgui_layerset.h
Or some other header file?

-ScottA

On 26/03/2013 at 09:04, xxxxxxxx wrote:

Never mind. I figured it out.
This is the missing piece of code that makes the rest of your code work:GeData dLayerSet;

-ScottA