Chaging the LayerShader



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/10/2012 at 10:37, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   13 
    Platform:    Mac  ;  
    Language(s) :     C++  ;

    ---------
    Hello.
     I've seen tons of threads about the LayerShader and it doesn't look like you can add things to it which sucks, but that's not what I need to do.  I want to access the layers already in it and modify them.  And from what I've seen that's possible, but I'm not sure how to get access to the LayerShader, I've got code to get the BaseShader but I don't know how to get to the LayerShader.

    Here's where I'm at:

      
    shader = mat->GetFirstShader();  
    //code to loop through all the shaders in the material  
      
    if (shader->GetType() == Xlayer)  
          {  
              //do stuff to the layers here  
          }  
    

    So I know if it's a LayerShader or not, but how do I get from the BaseShader class to the LayerShader class?  I'm new to C++ plugin development so sorry if that's an obvious question.

    Thanks in advance for any help!

    Dan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/10/2012 at 11:29, xxxxxxxx wrote:

    Hi Dan,

    Here's some code that shows how to handle a LayerShader:

    BaseMaterial *mat = doc->GetFirstMaterial();
    if (!mat) return FALSE;
    BaseShader *shader = mat->GetFirstShader();
    if (!shader) return FALSE;
    if (shader->GetType()==Xlayer)
    {
        // Cast shader to LayerShader
        LayerShader *layerShader = (LayerShader* )shader;
        if (!layerShader) return FALSE;
      
        // Get first layer, then use layer->GetNext() to loop through the layers
        LayerShaderLayer *layer = layerShader->GetFirstLayer();
        Bool res;
        // Loop trough the layers in the layer shader
        while (layer)
        {
            res = layer->SetParameter(LAYER_S_PARAM_SHADER_MODE, BlendMultiply);
            res = layer->SetParameter(LAYER_S_PARAM_SHADER_BLEND, 0.5);
            layer = layer->GetNext();
        }
        // Tells CINEMA to update
        EventAdd();
    }
    

    LayerShader and LayerShaderLayer classes are defined in the lib_layershader library, don't forget to include its header:

    #include "c4d_libs\lib_layershader.h"
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/10/2012 at 14:01, xxxxxxxx wrote:

    Thanks Yannick, that's exactly what I need.

    I currently have

      
    #include "lib_layershader.h"  
    

    included in my file and it works, but

      
    #include "c4d_libs\lib_layershader.h"  
    

    returns that there's no such file or directory, any idea why?

    Thanks a bunch!

    Dan



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/10/2012 at 14:09, xxxxxxxx wrote:

    It just depends on how your compiler is set up - just use the first one if that's working.


Log in to reply