Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Bake texture and MultipassBitMap [SOLVED]

    SDK Help
    0
    9
    841
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

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

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

      ---------
      Hi
      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;   
        
          while(tag)   
          {   
              GePrint(tag->GetName());   
              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);   
        
              BakeTexture(bakeDoc,settings,bitmap,nullptr,nullptr,nullptr);   
        
              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));   
                
              ShowBitmap(bitmap);   
        
              MultipassBitmap::Free(bitmap);   
          }   
          else if(err != BAKE_TEX_ERR_NONE)   
          {   
              MessageDialog(GeLoadString(err));   
          }   
          BaseDocument::Free(bakeDoc);   
      }   
      

      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.

      Cheers
      Bonsak

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

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

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

        change:

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

        to:

        MultipassBitmap\* layerTwo = bitmap->AddLayer( layerOne, COLORMODE_RGB );
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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 🙂

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

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

            check this thread, https://developers.maxon.net/forum/topic/8085/10521_putting-layers-inside-of-folders&KW=multipassbitmap

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

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

              Thanks a lot Mohamed!

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                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.

                Cheers
                Bonsak

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

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

                  Hello,

                  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");  
                  layer->SetParameter(MPBTYPE_SHOW,true);  
                    
                  // show result  
                  ShowBitmap(bitmap);  
                  

                  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,
                  Sebastian

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

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

                    BakeTexture will create all the layers automatically.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

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

                      Thanks!

                      -b

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post