On 22/05/2015 at 04:09, xxxxxxxx wrote:
Cinema 4D Version: R16
Platform: Windows ;
Language(s) : C++ ;
I have a custom material (created using MaterialData) with submaterials (LINK to Mbase in description). Now, when I implement material preview using MATPREVIEW_GENERATE_IMAGE, it won't render correctly as linked submaterials are not copied into document in MatPreviewGenerateImage::pDoc.
I can copy materials manually just before calling RenderDocument, ie:
MatPreviewGenerateImage *image = static_cast<MatPreviewGenerateImage *>(data); RenderData *rdata = image->pDoc->GetActiveRenderData(); BaseContainer bc = rdata->GetData(); ... // GetOriginalMaterial gets material from original document. BaseMaterial *mat = GetOriginalMaterial(); BaseMaterial *cloned_mat = static_cast<BaseMaterial *>(mat->GetClone(COPYFLAGS_NO_MATERIALPREVIEW, NULL)); image->pDoc->InsertMaterial(cloned_mat); node->GetDataInstance()->SetLink(MY_MATERIAL_LINK, cloned_mat); ... image->lResult = RenderDocument(image->pDoc, bc, nullptr, nullptr, image->pDest, RENDERFLAGS_EXTERNAL | RENDERFLAGS_PREVIEWRENDER, image->pThread); ...
This works in few simple situations when submaterial is one of my custom materials and I handle it without using C4D functions, but when it is something more complex (e. g. Banzi) and I try to call CalcSurface on it, it will **crash **(access violation in sla.cdl64).
Note that when I render normally (put my custom material to cube in document and render), I don't need to copy anything and it will render without any problems, the problem is only when rendering material preview.
So my questions are:
1) Is there some standardized way to handle submaterials that will make C4D copy those in MatPreviewGenerateImage::pDoc?
2) If not, how can I copy submaterials into MatPreviewGenerateImage::pDoc so I will be abble to use them during rendering?
I also use MSG_MULTI_MARKMATERIALS to mark submaterials for C4D, but this seems to be used only for things like "Remove unused materials" and does not affect handling of material preview.