InitBakeTexture compile error



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

    On 19/09/2010 at 14:57, xxxxxxxx wrote:

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

    ---------
    Hi, I´m trying to make a BakeTexture plugin, my principal propourse is do the same as BakeTexture tags, but making each bake operation sequentially, and never baking all objects at the same time (yes, I get out of memory errors, especially when i have +500 objects to be baked...)

    The plugin tries to bake every object with a BakeTexture tag attached...(if tag name is not "Preparar Textura DONE").

    The problem now is InitBakeTexture() fails on compile... (I get C2665: none of the 2 overloads can convert all argument types)

    Any ideas??

    My code:

    #define ID_BAKINGPLUGIN 0000001
        // unique ID for this plugin

    #include "c4d.h"
    #include <string.h>

    //########################################

    class HelloWorldTest : public CommandData    // data class for creating new commands (previously known as "menu plugins")
    {
     
      // Funciones que use el plugin

    ////////////////////////////

    ///////////////////////////

    void Dialog (String message)
      {
          MessageDialog(message);
      }

    public:
      virtual Bool HelloWorldTest::Execute(BaseDocument *doc) //Plugin
      {
      //MessageDialog("Hello World");            // simple popup message
      GePrint("This is my first plugin");      // output to C4D's "Console window"
     
      BaseObject* obj = doc->GetFirstObject();
      if(!obj)
      {
          Dialog("No objects in the scene!");
          return TRUE;
      }

    BaseDocument* bakeDoc;

    // Bake settings:
      int bakecounter = 1;

    BaseContainer bakeSettings;

    bakeSettings.SetBool(BAKE_TEX_ILLUMINATION, TRUE);
      bakeSettings.SetBool(BAKE_TEX_SHADOWS, TRUE);
      bakeSettings.SetBool(BAKE_TEX_USE_PHONG_TAG, TRUE);
      bakeSettings.SetBool(BAKE_TEX_COLOR_ILLUM, TRUE);
      bakeSettings.SetBool(BAKE_TEX_COLOR_SHADOWS, TRUE);
      bakeSettings.SetBool(BAKE_TEX_AUTO_SIZE, TRUE);
      bakeSettings.SetLong(BAKE_TEX_AUTO_SIZE_MIN, 256);
      bakeSettings.SetLong(BAKE_TEX_AUTO_SIZE_MAX, 2048);
      bakeSettings.SetReal(BAKE_TEX_AUTO_PIXEL_SIZE, 2.0);

    while(obj)
      {
          MessageDialog(obj->GetName());
         
          BaseTag* baketag = obj->GetTag(Tbaketexture);
         
          if(baketag)
          {
              if(baketag->GetName() != "Preparar Textura DONE")
              {
                  BaseTag* textag = obj->GetTag(Ttexture);
                  BaseTag* uvwtag = obj->GetTag(Tuvw);
                  if(textag)
                  {
                      LONG error;
                      // Init bake:
                      bakeDoc = InitBakeTexture(doc, textag, uvwtag, NULL, bakeSettings, NULL, NULL);

    // BaseBitmap:
                      BaseBitmap* resultbitmap = BaseBitmap::Alloc();

    error = BakeTexture(doc, bakeSettings, resultbitmap, 0,NULL,NULL);
                     
                  }
              }
          }

    //////////////////////

    BaseObject* obj2 = obj->GetDown();
          if(obj2)
          {
              obj=obj->GetDown();
          }
          else
          {
              BaseObject* obj3 = obj->GetNext();
              if(obj3)
              {
                  obj=obj->GetNext();
              }
              else
              {
                  obj=obj->GetUp()->GetNext();
              }
          }
      }
         
          MessageDialog("Everything baked successfully!");

    return TRUE;
      }
    };

    //########################################

    Bool PluginStart(void)                   // the main function C4D calls to begin your plugin (think of it as main)
    {
      return RegisterCommandPlugin( ID_BAKINGPLUGIN,"Sequential Baking",
                                  0,NULL,String("Sequential Baking"),
                                  gNew HelloWorldTest );
      // registers a command plugin with C4D
      // (ie: the class to execute when user selects "Hello World" under the Plugin menu)
    }

    void PluginEnd(void)                     // called when the plugin is unloaded from C4D
    {
    }

    Bool PluginMessage(LONG id, void *data)  // allows you to receive plugin messages from C4D or other plugins
    {
      return TRUE;
    }



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

    On 20/09/2010 at 02:11, xxxxxxxx wrote:

    anyone??



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

    On 20/09/2010 at 02:34, xxxxxxxx wrote:

    You have to cast the tags into their right type.

    bakeDoc = InitBakeTexture(doc, (TextureTag* )textag, (UVWTag* )uvwtag, NULL, bakeSettings, NULL, NULL);
    

    cheers,
    Matthias



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

    On 21/09/2010 at 04:38, xxxxxxxx wrote:

    ok, I have one more problem: I want to pass the actual doc as parameter:

    --------------------------------------------------------------------------

    bakeDoc = InitBakeTexture(doc, (TextureTag* )textag, (UVWTag* )uvwtag, NULL, bakeSettings, NULL, NULL);

    -------------------------------------------------------------------------

    But BakeTexture returns "BAKE_TEX_ERR_NO_DOC"...

    I know doc is the active document, and works getting objects... I'm doing something wrong when passing it as argument?? Or is not possible??

    Thanks for the help...

    All my code below

    ----------------------------------------------------

    #define ID_BAKINGPLUGIN 0000001
        // unique ID for this plugin

    #include "c4d.h"
    #include <string.h>

    //########################################

    class SequentialBaking : public CommandData    // data class for creating new commands (previously known as "menu plugins")
    {
     
      // Funciones que use el plugin

    ////////////////////////////

    ///////////////////////////

    void Dialog (String message)
      {
          MessageDialog(message);
      }

    public:
      virtual Bool SequentialBaking::Execute(BaseDocument *doc) //Plugin
      {
      GePrint("TexBakePlugin");      // output to C4D's "Console window"

    //Filename docpath;

    //if(!docpath.FileSelect(FSTYPE_SCENES, 0, "Select c4d file to be baked:")) return TRUE;

    //BaseDocument* doc2 = BaseDocument::Alloc();
      //doc2 = LoadDocument(docpath, NULL, NULL);
     
      BaseObject* obj = doc->GetFirstObject();
      if(!obj)
      {
          Dialog("No objects in the scene!");
          return TRUE;
      }

    Filename saveFile;

    if(!saveFile.FileSelect(FSTYPE_ANYTHING, GE_DIRECTORY, "Select output folder for baked textures:")) return TRUE;

    BaseDocument* bakeDoc = BaseDocument::Alloc();

    // Bake settings:
      int bakecounter = 1;

    BaseContainer bakeSettings;

    bakeSettings.SetBool(BAKE_TEX_ILLUMINATION, TRUE);
      bakeSettings.SetBool(BAKE_TEX_SHADOWS, TRUE);
      bakeSettings.SetBool(BAKE_TEX_USE_PHONG_TAG, TRUE);
      bakeSettings.SetBool(BAKE_TEX_COLOR_ILLUM, TRUE);
      bakeSettings.SetBool(BAKE_TEX_COLOR_SHADOWS, TRUE);
      bakeSettings.SetBool(BAKE_TEX_AUTO_SIZE, TRUE);
      bakeSettings.SetLong(BAKE_TEX_AUTO_SIZE_MIN, 256);
      bakeSettings.SetLong(BAKE_TEX_AUTO_SIZE_MAX, 2048);
      bakeSettings.SetReal(BAKE_TEX_AUTO_PIXEL_SIZE, 2.0);

    while(obj)
      {
         
         
          BaseTag* baketag = obj->GetTag(Tbaketexture);
         
          if(baketag)
          {
              if(baketag->GetName() != "Preparar Textura DONE")
              {
                  BaseTag* textag = obj->GetTag(Ttexture);
                  BaseTag* uvwtag = obj->GetTag(Tuvw);
                  if(textag)
                  {
                      LONG error;
                      // Init bake:
                      bakeDoc = InitBakeTexture(doc, (TextureTag* )textag, (UVWTag* )uvwtag, NULL, bakeSettings, NULL, NULL);

    // BaseBitmap:
                      BaseBitmap* resultbitmap = BaseBitmap::Alloc();

    error = BakeTexture(bakeDoc, bakeSettings, resultbitmap, NULL ,NULL,NULL);

    switch(error)
                      {
                      case BAKE_TEX_ERR_NO_DOC:
                          MessageDialog("BAKE_TEX_ERR_NO_DOC");
                          break;
                      case BAKE_TEX_ERR_NO_MEM:
                          MessageDialog("BAKE_TEX_ERR_NO_MEM");
                          break;
                      case BAKE_TEX_ERR_NO_RENDER_DOC:
                          MessageDialog("BAKE_TEX_ERR_NO_RENDER_DOC");
                          break;
                      case BAKE_TEX_ERR_NO_TEXTURE_TAG:
                          MessageDialog("BAKE_TEX_ERR_NO_TEXTURE_TAG");
                          break;
                      case NULL:
                          MessageDialog("BAKE NULL!");
                      }

    Filename fname = obj->GetName();
                     
                      saveFile.SetFile(fname);

    saveFile.SetSuffix("jpg");

    LONG error2 = resultbitmap->Save(saveFile, FILTER_JPG, NULL, NULL);

    switch(error2)
                      {
                      case IMAGE_OK:
                          MessageDialog("IMAGE_OK");
                          break;
                      case IMAGE_NOTEXISTING:
                          MessageDialog("IMAGE_NOTEXISTING");
                          break;
                      case IMAGE_WRONGTYPE:
                          MessageDialog("IMAGE_WRONGTYPE");
                          break;
                      case IMAGE_NOMEM:
                          MessageDialog("IMAGE_NOMEM");
                          break;
                      case IMAGE_DISKERROR:
                          MessageDialog("IMAGE_DISKERROR");
                          break;
                      case IMAGE_FILESTRUCT:
                          MessageDialog("IMAGE_FILESTRUCT");
                          break;
                      case NULL:
                          MessageDialog("IMAGE NULL!");
                      }

    GePrint(saveFile.GetString());

    }
              }
          }

    //////////////////////

    BaseObject* obj2 = obj->GetDown();
          if(obj2)
          {
              obj=obj->GetDown();
          }
          else
          {
              BaseObject* obj3 = obj->GetNext();
              if(obj3)
              {
                  obj=obj->GetNext();
              }
              else
              {
                  obj=obj->GetUp()->GetNext();
              }
          }
      }
         
          MessageDialog("Everything baked successfully!");

    return TRUE;
      }
    };

    //########################################

    Bool PluginStart(void)                   // the main function C4D calls to begin your plugin (think of it as main)
    {
      return RegisterCommandPlugin( ID_BAKINGPLUGIN,"Sequential Baking",
                                  0,NULL,String("Sequential Baking"),
                                  gNew SequentialBaking );
      // registers a command plugin with C4D
      // (ie: the class to execute when user selects "Hello World" under the Plugin menu)
    }

    void PluginEnd(void)                     // called when the plugin is unloaded from C4D
    {
    }

    Bool PluginMessage(LONG id, void *data)  // allows you to receive plugin messages from C4D or other plugins
    {
      return TRUE;
    }



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

    On 22/09/2010 at 09:10, xxxxxxxx wrote:

    anyone please??



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

    On 23/09/2010 at 03:00, xxxxxxxx wrote:

    I don't know why, but the err parameter in InitBakeTexture(...) is BAKE_TEX_ERR_WRONG_BITMAP, after call the function.

    I'm really confused, because InitBakeTexture() does not handle a bitmap as parameter... so why it says wrong bitmap??

    And BakeTexture(...) returns BAKE_TEX_ERR_NO_DOC. I have two BaseDocuments, one is doc, is the main document in the plugin:

    virtual Bool SequentialBaking::Execute(BaseDocument *doc)

    And the other is created only for the baking process, bakeDoc:

    BaseDocument* bakeDoc = BaseDocument::Alloc();

    My calls to bake texture:

    ---------------------------------------------------------

    bakeDoc = InitBakeTexture((BaseDocument* )doc, (TextureTag* )textag, (UVWTag* )uvwtag, NULL, bakeSettings, &error3, NULL);

    // error3 = BAKE_TEX_ERR_WRONG_BITMAP

    // BaseBitmap:
                      BaseBitmap* resultbitmap = BaseBitmap::Alloc();

    error = BakeTexture((BaseDocument* )bakeDoc, NULL, resultbitmap, NULL,NULL,NULL);

    //error = BAKE_TEX_ERR_NO_DOC

    // and of course resultbitmap->Save returns NULL...

    -------------------------------------------------------

    I'm really confused... Anyone knows how to make it work?? I only want to save the baked textures in a folder, with the name of the baked object...

    Thanks for the help.

    Cheers



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

    On 29/09/2010 at 06:09, xxxxxxxx wrote:

    It seems that the BAKE_TEX_AUTO_xxx IDs are causing the errors. It's not quite clear to me how to use them either. I will ask the developers.

    Using a fixed texture size seems to work fine though (BAKE_TEX_WIDTH, BAKE_TEX_HEIGHT).

    cheers,
    Matthias



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

    On 30/09/2010 at 04:30, xxxxxxxx wrote:

    Ok thanks Matthias, I will try using a fixed size, would be great to view autosize working... 🙂

    I will post the results.

    Cheers



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

    On 01/10/2010 at 01:17, xxxxxxxx wrote:

    Same errors using a fixed 1024x1024 size...



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

    On 04/10/2010 at 06:57, xxxxxxxx wrote:

    It seems to work fione here.

    Here my test code:

      
    Bool MenuTest::Execute(BaseDocument *doc)  
    {  
      BaseObject *obj = doc->GetFirstObject();  
      if (!obj) return FALSE;  
      
      BaseContainer bakeSettings;  
      
      bakeSettings.SetBool(BAKE_TEX_USE_CAMERA_VECTOR, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_USE_POLYSELECTION, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_AMBIENT_OCCLUSION, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_NORMAL, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_SURFACECOLOR, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_COLOR, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_DIFFUSION, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_LUMINANCE, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_ALPHA, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_ALPHA, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_ILLUMINATION, TRUE);  
      bakeSettings.SetBool(BAKE_TEX_SHADOWS, TRUE);  
      
      bakeSettings.SetBool(BAKE_TEX_BUMP, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_TRANSPARENCY, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_UVMAP, FALSE);  
      bakeSettings.SetBool(BAKE_TEX_REFLECTION, FALSE);  
      
      bakeSettings.SetBool(BAKE_TEX_USE_PHONG_TAG, TRUE);  
      bakeSettings.SetBool(BAKE_TEX_COLOR_ILLUM, TRUE);  
      bakeSettings.SetBool(BAKE_TEX_COLOR_SHADOWS, TRUE);  
      
      bakeSettings.SetLong(BAKE_TEX_WIDTH, 512);  
      bakeSettings.SetLong(BAKE_TEX_HEIGHT, 512);  
      bakeSettings.SetLong(BAKE_TEX_PIXELBORDER, 2);  
      bakeSettings.SetVector(BAKE_TEX_FILL_COLOR, Vector(1.0));  
      
      BaseTag* textag = obj->GetTag(Ttexture);  
      BaseTag* uvwtag = obj->GetTag(Tuvw);  
      
      if(textag)  
      {  
          LONG error;  
      
          BaseDocument *bakeDoc = InitBakeTexture(doc, (TextureTag* )textag, (UVWTag* )uvwtag, NULL, bakeSettings, &error, NULL);  
      
          AutoAlloc<BaseBitmap> bmp;  
          if (!bmp) return FALSE;  
            
          if (bakeDoc) error = BakeTexture(bakeDoc, bakeSettings, bmp, NULL, NULL, NULL);  
      
          ShowBitmap(bmp);  
      }  
        
      return TRUE;  
    }  
    

    cheers,
    Matthias



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

    On 04/10/2010 at 15:30, xxxxxxxx wrote:

    Modifing the code like your example works (YES, THANK YOU!😄), but only if I use a fixed bitmap size.

    Can you give a working autosize example please??

    Thank you again for your help, Matthias



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

    On 02/01/2012 at 20:34, xxxxxxxx wrote:

    Sorry for resurrecting this old thread. But I can't get the example Matthias posted to work.
    The error I get is: no instance of overloaded function "InitBakeTexture" matches the argument list

    I'm puzzled why it's asking me to overload a method. Because there is never one used in any of the above examples.
    And when I try to make one inside of my class. I can't get it to compile.

    Did something change between then and now that's making this not work anymore?

    -ScottA



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

    On 03/01/2012 at 00:22, xxxxxxxx wrote:

    Hi,

    The compiler doesn't tell you to overload  InitBakeTexture (). InitBakeTexture() has 2 overloads (2 versions of the function but with different arguments) and it just can't find which overload to call.

    Instead of declaring error as LONG:

    LONG error;
    

    Declare it as BAKE_TEX_ERR:

    BAKE_TEX_ERR error; 
    

    And it compiles fine now - yes just that... poor compilers :).



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

    On 03/01/2012 at 01:32, xxxxxxxx wrote:

    I've just looked in the SDK docs up to R13 and the error parameter is given as a LONG. So this looks like a documentation error. Can't really blame the compiler for that :-)

    (Looking in c4d_tools.h shows that InitBakeTexture does use BAKE_TEX_ERR but this change hasn't made it into the docs.)

    Steve



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

    On 03/01/2012 at 02:36, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    I've just looked in the SDK docs up to R13 and the error parameter is given as a LONG. So this looks like a documentation error. Can't really blame the compiler for that :-)

    (Looking in c4d_tools.h shows that InitBakeTexture does use BAKE_TEX_ERR but this change hasn't made it into the docs.)

    Right. The parameter type is wrong in the docs. So... blame the docs 🙂.
    Thanks for pointing that out Steve.



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

    On 03/01/2012 at 07:38, xxxxxxxx wrote:

    Thanks.
    Works fine now with the correct type.

    -ScottA


Log in to reply