Bake texture and MultipassBitMap [SOLVED]

On 29/05/2015 at 10:46, xxxxxxxx wrote:

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

Ive copied some of the "bake texture" code that's been posted here the last couple of days. Ive got this:

Bool MenuTest::Execute(BaseDocument *doc)   
    BaseObject *obj = doc->GetFirstObject();   
    UVWTag* uvwTag = (UVWTag* )obj->GetTag(Tuvw);   
    if(uvwTag == nullptr)   
        return true;   
    BaseTag* tag = obj->GetFirstTag();   
    maxon::BaseArray<TextureTag*> textureTagArray;   
    maxon::BaseArray<UVWTag*> uvwTags;   
        if(tag->GetType() == Ttexture)   
            textureTagArray.Append((TextureTag* )tag);   
            uvwTags.Append((UVWTag* )uvwTag);   
        tag = tag->GetNext();   
    if(textureTagArray.GetCount() == 0)   
        return true;   
    Int32 BakeWidth = 256;   
    Int32 BakeHeight = 256;   
    BaseContainer settings;   
    settings.SetBool(BAKE_TEX_SHOW_STATUS, true);   
    settings.SetInt32(BAKE_TEX_WIDTH, BakeWidth);   
    settings.SetInt32(BAKE_TEX_HEIGHT, BakeHeight);   
    settings.SetInt32(BAKE_TEX_PIXELBORDER, 0);   
    settings.SetBool(BAKE_TEX_CONTINUE_UV, true);   
    settings.SetBool(BAKE_TEX_USE_PHONG_TAG, true);   
    settings.SetVector(BAKE_TEX_FILL_COLOR, Vector(0.0));   
    settings.SetBool(BAKE_TEX_COLOR, true);   
    settings.SetBool(BAKE_TEX_COLOR_ILLUM, true);   
    settings.SetBool(BAKE_TEX_COLOR_SHADOWS, true);   
    settings.SetBool(BAKE_TEX_COLOR_LUMINANCE, false);   
    settings.SetBool(BAKE_TEX_COLOR_DIFFUSION, false);   
    BAKE_TEX_ERR err;   
    BaseDocument* bakeDoc = InitBakeTexture( doc, textureTagArray.GetFirst(), uvwTags.GetFirst(), nullptr, textureTagArray.GetCount(), settings, &err;, nullptr );   
    if(err == BAKE_TEX_ERR_NONE)   
        const String LayerNameOne = "Shadow";   
        const String LayerNameTwo = "Gi";   
        MultipassBitmap* bitmap = MultipassBitmap::Alloc(BakeWidth,BakeHeight,COLORMODE_RGB);   
        MultipassBitmap* layerOne = bitmap->AddLayer( nullptr, COLORMODE_RGB );   
//        layerOne->SetName(LayerNameOne);   
        MultipassBitmap* layerTwo = bitmap->AddLayer( nullptr, COLORMODE_RGB );   
//        layerTwo->SetName(LayerNameTwo);   
        Int NumLayers = bitmap->GetLayerCount();   
        GePrint("Number of layers: " + String::IntToString(NumLayers));   
    else if(err != BAKE_TEX_ERR_NONE)   

Even though i'm calling AddLayer twice i only get the base layer and one additional layer in PV when i run the code.
How am i supposed to do this? I thought that the additional layers would be added automatically to "bitmap" when i specify more than one channel.

I am also wondering how i am supposed to do this if i need to bake out animation. The Bake Texture tag has timing parameters in its UI. But i can't find any timing settings in c4d_tools.h.

Any help appreciated.


On 29/05/2015 at 13:54, xxxxxxxx wrote:

I may write from my imagination "so don't take my code so seriously"


MultipassBitmap\* layerTwo = bitmap->AddLayer( nullptr, COLORMODE_RGB );


MultipassBitmap\* layerTwo = bitmap->AddLayer( layerOne, COLORMODE_RGB );

On 29/05/2015 at 14:17, xxxxxxxx wrote:

Thanks. I tried:

MultipassBitmap* layerOne = bitmap->AddLayer( bitmap, COLORMODE_RGB );   
MultipassBitmap* layerTwo = bitmap->AddLayer( layerOne, COLORMODE_RGB );   

Withe every new layer pointing back to the previous one, but it still only produces the base layer and one additional layer.
Must be doing something else wrong :)

On 29/05/2015 at 14:33, xxxxxxxx wrote:

Thanks a lot Mohamed!

On 01/06/2015 at 07:36, xxxxxxxx wrote:

Just a follow-up on the BakeTexture function.
- When you specify more than one channel to output during baking, are the different channels stacked in the Multipassbitmap automatically by the BakeTexture function or do i have to do that myself?
- If so, how do i do that?

I was hoping there was predefined option i could set in the settings container being passed to BakeTexture. But can't seem to find any.


On 01/06/2015 at 07:43, xxxxxxxx wrote:


a layer of a MultipassBitmap appears only in the Picture Viewer if the MPBTYPE_SHOW parameter of that layer is set.

MultipassBitmap* layer = bitmap->AddLayer(nullptr,COLORMODE_RGB);  
layer->SetParameter(MPBTYPE_NAME, "New Layer");  
// show result  

If you want to bake the texture for different points in time you have to set the time of the BaseDocument returned by InitBakeTexture(), animate it with ExecutePasses() and call BakeTexture() for each frame you want to bake.

Best wishes,

On 01/06/2015 at 07:46, xxxxxxxx wrote:

BakeTexture will create all the layers automatically.

On 01/06/2015 at 07:47, xxxxxxxx wrote: