Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    RenderDocument renders black [SOLVED]

    SDK Help
    0
    16
    1.0k
    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 14/07/2015 at 04:12, xxxxxxxx wrote:

      Hi Ama,

      a demo has to be activated in order to be able to save. With your above code (with flags fix), the image will be rendered in the demo, regardless of activation (add ShowBitmap() to your code to verify). But the image will only be saved, if the demo got activated and is within the 42 days trial period. Otherwise (either not activated yet or past 42 days of trial period) nothing will happen. The plugin still runs, but it simply won't create a file on disk.

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

        On 14/07/2015 at 05:22, xxxxxxxx wrote:

        Thank you!

        Ama

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

          On 14/07/2015 at 06:13, xxxxxxxx wrote:

          I added

          BaseDocument *t_Doc = LoadDocument( l_GUI_Directory + Filename("test.c4d"), SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS, nullptr, nullptr );

          ShowBitmap( l_Render_Bitmap );

          The render comes back as successful but the bitmap doesn't display.

          I also tried:
          ShowBitmap( l_Render_Bitmap->GetLayerNum(0) );

          It also did not work.

          Thanks for your help!

          Ama

          Originally posted by xxxxxxxx

          Hi Ama,

          a demo has to be activated in order to be able to save. With your above code (with flags fix), the image will be rendered in the demo, regardless of activation (add ShowBitmap() to your code to verify). But the image will only be saved, if the demo got activated and is within the 42 days trial period. Otherwise (either not activated yet or past 42 days of trial period) nothing will happen. The plugin still runs, but it simply won't create a file on disk.

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

            On 14/07/2015 at 06:27, xxxxxxxx wrote:

            Here is where I am at:

            BaseDocument *doc = LoadDocument(directory + Filename("test.c4d"), SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS, nullptr, nullptr);
                    if (doc)
                    {
                        RenderData *renderData = doc->GetActiveRenderData();
                        BaseContainer data = renderData->GetData();
                        Int32 bitmapSizeX, bitmapSizeY;
                        Int32 dataSizeX = data.GetInt32(RDATA_XRES);
                        Int32 dataSizeY = data.GetInt32(RDATA_YRES);
                        data.SetInt32(RDATA_XRES, dataSizeX);
                        data.SetInt32(RDATA_YRES, dataSizeY);
                        bitmapSizeX = data.GetInt32(RDATA_XRES);
                        bitmapSizeY = data.GetInt32(RDATA_YRES);
                        MultipassBitmap *renderBitmap = MultipassBitmap::Alloc(bitmapSizeX, bitmapSizeY, COLORMODE_RGB);
                        renderBitmap->AddChannel(TRUE, TRUE);            
                        RENDERRESULT renderResult = RenderDocument(doc, data, nullptr, nullptr, renderBitmap, RENDERFLAGS_EXTERNAL, nullptr, nullptr, nullptr);
                        if (renderResult != RENDERRESULT_OK)
                            GePrint("RENDER FAILED:" + String::IntToString(renderResult));
                        else
                            GePrint("RENDER SUCCESS:" + String::IntToString(renderResult));
                        BaseDocument::Free(doc);
                        ShowBitmap(l_Render_Bitmap);
                        MultipassBitmap::Free(renderBitmap);
                    }

            I receive render success but it does not display the bitmap.

            Ama

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

              On 14/07/2015 at 06:52, xxxxxxxx wrote:

              Hi Ama,

              I have no idea, what is going wrong on your end. I tested the code from your last post. It worked here with one minimal change.
              Instead of

              ShowBitmap(l_Render_Bitmap);
              

              I used

              ShowBitmap(renderBitmap);
              

              Not sure, what you were trying to show there. But otherwise it worked here as expected.
              Are you sure, the code got correctly recompiled? And are you sure, there's something to render in the scene? In which context do you use your code (in which function)?

              And while we are at it, some more comments:

              BaseContainer data = renderData->GetData(); // I'd use GetDataInstance() here, it's faster
              Int32 bitmapSizeX, bitmapSizeY;
              Int32 dataSizeX = data.GetInt32(RDATA_XRES); // not sure, what you are trying to achieve here, seems redundant
              Int32 dataSizeY = data.GetInt32(RDATA_YRES);
              data.SetInt32(RDATA_XRES, dataSizeX);
              data.SetInt32(RDATA_YRES, dataSizeY);
              bitmapSizeX = data.GetInt32(RDATA_XRES);
              bitmapSizeY = data.GetInt32(RDATA_YRES);
              

              So it would look like this:

              BaseContainer* data = renderData->GetDataInstance();
              Int32 bitmapSizeX, bitmapSizeY;
              bitmapSizeX = data->GetInt32(RDATA_XRES);
              bitmapSizeY = data->GetInt32(RDATA_YRES);
              
              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 14/07/2015 at 06:59, xxxxxxxx wrote:

                I think I figured it out.

                I am rendering on a background thread.  ShowBitmap requires the main thread I believe.  How should I execute that on the main thread?

                Ama

                Originally posted by xxxxxxxx

                Hi Ama,

                I have no idea, what is going wrong on your end. I tested the code from your last post. It worked here with one minimal change.
                Instead of

                ShowBitmap(l_Render_Bitmap);
                

                I used

                ShowBitmap(renderBitmap);
                

                Not sure, what you were trying to show there. But otherwise it worked here as expected.
                Are you sure, the code got correctly recompiled? And are you sure, there's something to render in the scene? In which context do you use your code (in which function)?

                And while we are at it, some more comments:

                BaseContainer data = renderData->GetData(); // I'd use GetDataInstance() here, it's faster
                Int32 bitmapSizeX, bitmapSizeY;
                Int32 dataSizeX = data.GetInt32(RDATA_XRES); // not sure, what you are trying to achieve here, seems redundant
                Int32 dataSizeY = data.GetInt32(RDATA_YRES);
                data.SetInt32(RDATA_XRES, dataSizeX);
                data.SetInt32(RDATA_YRES, dataSizeY);
                bitmapSizeX = data.GetInt32(RDATA_XRES);
                bitmapSizeY = data.GetInt32(RDATA_YRES);
                

                So it would look like this:

                BaseContainer* data = renderData->GetDataInstance();
                Int32 bitmapSizeX, bitmapSizeY;
                bitmapSizeX = data->GetInt32(RDATA_XRES);
                bitmapSizeY = data->GetInt32(RDATA_YRES);
                
                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 15/07/2015 at 09:11, xxxxxxxx wrote:

                  Hello again,

                  I went back and pushed the code into the menu example code and it worked fine.  The difference between the two projects is that example code runs on the main thread and the code that doesn't render runs on a background thread.  Could this be an issue?

                  Ama

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

                    On 16/07/2015 at 06:10, xxxxxxxx wrote:

                    Hi Ama,

                    indeed ShowBitmap() (and actually almost any GUI related function) has to be called from main thread. Unfortunately there's no according note in the docs, I'll add it now.
                    RenderDocument() on the other side should be no problem to call from a thread, actually this is done within Cinema 4D all over the place.
                    In order to transfer execution to the main thread, I recommend to look into SendCoreMessage(). And there's also the article on threading information, where this is shown in an example.

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

                      On 16/07/2015 at 06:18, xxxxxxxx wrote:

                      In a separate project I can render perfectly in or out of main thread.  The same code does not work within my project.  It seems that even though the RenderDocument returns success it is not rendering anything.  I am working on taking out just the rendering parts and seeing it it still breaks.  If it does I will post the project for review.

                      Ama

                      Originally posted by xxxxxxxx

                      Hi Ama,

                      indeed ShowBitmap() (and actually almost any GUI related function) has to be called from main thread. Unfortunately there's no according note in the docs, I'll add it now.
                      RenderDocument() on the other side should be no problem to call from a thread, actually this is done within Cinema 4D all over the place.
                      In order to transfer execution to the main thread, I recommend to look into SendCoreMessage(). And there's also the article on threading information, where this is shown in an example.

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

                        On 16/07/2015 at 12:13, xxxxxxxx wrote:

                        I have everything rendering fine now.

                        Thank you.
                        Ama

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