RenderDocument renders black [SOLVED]
-
On 12/07/2015 at 14:48, xxxxxxxx wrote:
All channels render black. It is a multiples image with an alpha. The output image is RGBA in PS.
Ama
-
On 12/07/2015 at 23:18, xxxxxxxx wrote:
did you allocate a BaseBitmap with the matching resolution to the render settings?
What does RenderDocument() return? -
On 13/07/2015 at 03:57, xxxxxxxx wrote:
All comes back success. The output image is the right size but all channels are black.
Code:
BaseDocument *doc = LoadDocument(directory + Filename("test.c4d"), SCENEFILTER_0, 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));
success = false;
}
else
GePrint( "RENDER SUCCESS:" + String::IntToString(renderResult));
BaseDocument::Free(doc);
IMAGERESULT imageResult = renderBitmap->Save(cachePath+Filename("test.tif"), FILTER_TIF, NULL, SAVEBIT_ALPHA); // SAVEBIT_SAVERENDERRESULT );
if(imageResult!=IMAGERESULT_OK)
{
GePrint("Could not save rendered element ERROR:" + String::IntToString( imageResult));
success = false;
} else
GePrint("SAVED rendered element");
AutoAlloc<BaseBitmap> bitmap;
bitmap->Init( cachePath + Filename("test.tif") );
if (bitmap!=nullptr)
GePrint("Saved Bitmap Depth:" + String::IntToString(bitmap->GetBt()) + " alpha:" + String::IntToString(bitmap->GetInternalChannel()!=nullptr));
else GePrint("Saved Bitmap Failed");
MultipassBitmap::Free(renderBitmap);
} -
On 13/07/2015 at 05:56, xxxxxxxx wrote:
Hi Ama,
you need to pass (SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS) as flags to LoadDocument().
-
On 13/07/2015 at 10:13, xxxxxxxx wrote:
Thank you.
Does RenderDocument work with the demo, savable or not?
Ama
-
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.
-
On 14/07/2015 at 05:22, xxxxxxxx wrote:
Thank you!
Ama
-
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.
-
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
-
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 ofShowBitmap(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);
-
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 ofShowBitmap(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);
-
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
-
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. -
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. -
On 16/07/2015 at 12:13, xxxxxxxx wrote:
I have everything rendering fine now.
Thank you.
Ama