Replacing Textures



  • On 22/02/2013 at 13:15, xxxxxxxx wrote:

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

    ---------
    Hi guys!

    I'm pretty new to the SDK, so if this question is really daft/simple please go easy on me ;)

    OK, is it possible to change a texture bound to a channel in a material using the C++ SDK?

    I can currently:
      - Get hold of the material I want to change
      - Check the channel is in use (channel state)
      - Get the BaseChannel pointer and use this to get the BaseContainer
      - Query the container for the BASECHANNEL_TEXTURE to see the filename (though only the name. Not that it's important, but can you actually get the full path?)

    But where do I go from here to replace the texture with another from disk?

    Any help would be greatly appreciated!

    Cheers,
    Simon.



  • On 22/02/2013 at 14:12, xxxxxxxx wrote:

    BaseChannel*    bchan = mat->GetChannel(CHANNEL_COLOR);  
    BaseContainer    bdata;  
    // Get the full path to the image file  
    Filename        oldmap =    bchan->GetData().GetFilename(BASECHANNEL_SUGGESTEDFOLDER)+Filename(bchan->GetData().GetString(BASECHANNEL_TEXTURE));  
    GePrint("Texture file: "+oldmap.GetString());  
      
    // 'map' is a Filename that contains the full path to the image texture map on disk  
    // You can make it from a String which contains the full path like this:  
    // Filename map = Filename(strPath);  
    bdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, map.GetDirectory());  
    bchan->SetData(bdata);  
    bdata.SetString(BASECHANNEL_TEXTURE, map.GetFileString());  
    bchan->SetData(bdata);  
      
    // Apply the changes  
    mat->Update(TRUE, TRUE);  
    EventAdd();  
    


  • On 22/02/2013 at 15:20, xxxxxxxx wrote:

    Thanks for the speedy reply Robert, that's exactly what I was looking for!

    Seems so simple (and obvious) when you see the solution :)

    Cheers,
    Simon



  • On 22/02/2013 at 19:18, xxxxxxxx wrote:

    It is only simple once you have pulled out hair and slammed your head on the wall for a long time.  Then you eventually figure it out and hope to any divine being that the methodology never changes. 


Log in to reply