Matpreview Custom GUI for Objects
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/07/2004 at 12:38, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.503
Platform:
Language(s) : C++ ;---------
Hi,I am trying to come up with a small Plugin for creating random variations of a Plugin Object. A number of Preview Images should be created, from which the user can select one to modify again.
For the preview of this object I was thinking about having something like the MaterialPreview window (in which you can rotate the object), but I am not sure if I can actually use the MATPREVIEW Custumgui for this. I did not even get a Materialpreview window set up in my dialog. I guess I somehow have to connect it to the Material Preview Datatype, but I have no idea how. Can this work somehow, or will I have to do this on my own with a GeUserArea? Can I create a new viewport or somehow embed a viewport of a document into a GeUserArea? How would I be able to rotate around the object like it is possible in the Material Preview?I really hope that I do not have to do everything manually...
Best Regards
Timm Dapper -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 16:50, xxxxxxxx wrote:
Good question! I assume it should be possible using CUSTOMGUI_MATPREVIEW, possibly with a dummy MaterialData just to get access to the messages. But I couldn't figure it out; all I get is a gray field. I've contacted the programmers and will get back to you when I know more, hopefully with a code example.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/07/2004 at 02:30, xxxxxxxx wrote:
Hi Mikael,
thanks a lot for this. It is very much appreciated. Can't wait to hear from you!
Best
Timm -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/07/2004 at 15:53, xxxxxxxx wrote:
Finally I have something that works. Using a dummy scene hook and a dummy shader, it is possible to display a custom object (a torus) in the material preview. The scene hook is needed to make a connection between the shader and the current document, using InsertShader(), otherwise the preview won't render (there are other ways to do this, for example inserting the shader into an object or tag or whatever). The shader is needed to intercept the messages from the preview.
There is some untangling to do, so that you can have more than one in the dialog for example, but the basic concept is there. Please ask if you have any questions how it works. Here's the code:// Use unique IDs for these! const LONG OBJECT_PREVIEW_HOOK_ID = 1000001; const LONG OBJECT_PREVIEW_SHADER_ID = 1000002; #include "customgui_matpreview.h" class ObjectPreviewShader : public ShaderData { public: virtual Bool Message(GeListNode* node, LONG type, void* data) { switch (type) { case MATPREVIEW_GET_OBJECT_INFO: { MatPreviewObjectInfo* info = static_cast<MatPreviewObjectInfo*>(data); info->bHandlePreview = TRUE; info->bNeedsOwnScene = TRUE; info->bNoStandardScene = FALSE; info->lFlags = MATPREVIEW_FLAG_HIDE_SCENES | MATPREVIEW_FLAG_HIDE_ANIMATE | MATPREVIEW_FLAG_HIDE_SCENE_SETTINGS | MATPREVIEW_FLAG_HIDE_OPEN | MATPREVIEW_FLAG_HIDE_SIZE; return TRUE; } break; case MATPREVIEW_MODIFY_CACHE_SCENE: { MatPreviewModifyCacheScene* scene = static_cast<MatPreviewModifyCacheScene*>(data); // Kidnap original object... BaseObject* obj = scene->pDoc->SearchObject("Object"); obj->SetRenderMode(MODE_OFF); obj->SetEditorMode(MODE_OFF); // ...and insert our own AutoAlloc<BaseObject> torus(Otorus); torus->GetDataInstance()->SetReal(PRIM_TORUS_INNERRAD, 20.0); torus->GetDataInstance()->SetReal(PRIM_TORUS_OUTERRAD, 60.0); torus->SetRenderMode(MODE_ON); torus->SetEditorMode(MODE_ON); scene->pDoc->InsertObject(torus.Release(), obj, NULL); } return TRUE; case MATPREVIEW_PREPARE_SCENE: { MatPreviewPrepareScene* prepare = static_cast<MatPreviewPrepareScene*>(data); prepare->bScenePrepared = FALSE; } return TRUE; case MATPREVIEW_GENERATE_IMAGE: { MatPreviewGenerateImage* image = static_cast<MatPreviewGenerateImage*>(data); if (image->pDoc) { LONG w = image->pDest->GetBw(); LONG h = image->pDest->GetBh(); BaseContainer bcRender = image->pDoc->GetActiveRenderData()->GetData(); bcRender.SetLong(RDATA_XRES, w); bcRender.SetLong(RDATA_YRES, h); bcRender.SetLong(RDATA_ANTIALIASING, ANTI_GEOMETRY); if (image->bLowQuality) { bcRender.SetBool(RDATA_RENDERASEDITOR, TRUE); } image->pDest->Clear(0, 0, 0); image->lResult = RenderDocument(image->pDoc, bcRender, NULL, NULL, image->pDest, RENDERFLAG_EXTERNAL | RENDERFLAG_PREVIEWRENDER, image->pThread); } return TRUE; } case MATPREVIEW_GET_PREVIEW_ID: { LONG* id = static_cast<LONG*>(data); *id = 0; } return TRUE; } return TRUE; } virtual Vector Output(PluginShader *sh, ChannelData *cd) { return Vector(1.0, 0.2, 0.0); } static NodeData *Alloc(void) { return gNew ObjectPreviewShader; } }; class ObjectPreviewHook : public SceneHookData { AutoAlloc<PluginShader> shad; public: ObjectPreviewHook() : shad(OBJECT_PREVIEW_SHADER_ID) {} virtual Bool Init(GeListNode* node) { if (shad) { static_cast<PluginSceneHook*>(node)->InsertShader(shad); } return TRUE; } virtual void Free(GeListNode* node) { shad->Remove(); } Bool InitPreviewData(MaterialPreviewData* preview_data, LONG dirtyCount) { return preview_data->Init(shad, dirtyCount); } static NodeData *Alloc(void) { return gNew ObjectPreviewHook; } }; class ObjectPreviewDialog : public GeModalDialog { enum { PREVIEW_ID = 1000, GROUP_ID = 1001, MIN_WIDTH = 100, MIN_HEIGHT = 100, }; private: MaterialPreviewCustomGui* preview; LONG dirtyCount; public: ObjectPreviewDialog() : preview(NULL), dirtyCount(0) {} virtual void DestroyWindow() { preview = NULL; } virtual Bool CreateLayout() { BaseContainer settings; settings.SetLong(MATPREVIEW_MIN_WIDTH, MIN_WIDTH); settings.SetLong(MATPREVIEW_MIN_HEIGHT, MIN_HEIGHT); //settings.SetBool(MATPREVIEW_NO_BORDER, TRUE); GroupBegin(GROUP_ID, BFH_FIT | BFV_FIT, 1, 1, "Torus", 0); GroupBorderSpace(2,2,2,2); GroupBorder(BORDER_NONE | BORDER_WITH_TITLE); { preview = static_cast<MaterialPreviewCustomGui*>( AddCustomGui(PREVIEW_ID, CUSTOMGUI_MATPREVIEW, "", BFH_FIT | BFV_FIT, SizePix(MIN_WIDTH), SizePix(MIN_HEIGHT), settings)); } GroupEnd(); SetPreviewData(dirtyCount); return preview != NULL; } virtual Bool InitValues() { if (preview == NULL) return FALSE; preview->SetLayoutMode(LAYOUTMODE_MAXIMIZED); return TRUE; } virtual Bool Command(LONG id, const BaseContainer &msg) { if (id == PREVIEW_ID) { SetPreviewData(++dirtyCount); } return TRUE; } void SetPreviewData(LONG dirtyCount) { if (preview == NULL) return; TriState<GeData> t = preview->GetData(); GeData data = t.GetValue(); MaterialPreviewData* preview_data = static_cast<MaterialPreviewData*>( data.GetCustomDataType(CUSTOMDATATYPE_MATPREVIEW)); if (preview_data) { static_cast<ObjectPreviewHook*>( GetActiveDocument()-> FindSceneHook(OBJECT_PREVIEW_HOOK_ID)-> GetNodeData())->InitPreviewData(preview_data, dirtyCount); preview_data->SetPreviewSize(MatPreviewSizeDefault); preview_data->SetPreviewType(MatPreviewUser); } preview->SetData(data); } }; class MenuTest : public CommandData { public: virtual Bool Execute(BaseDocument *doc); }; Bool MenuTest::Execute(BaseDocument *doc) { ObjectPreviewDialog dlg; dlg.Open(); return TRUE; } Bool RegisterMenuTest(void) { RegisterSceneHookPlugin(OBJECT_PREVIEW_HOOK_ID, "Object Preview", PLUGINFLAG_HIDE, ObjectPreviewHook::Alloc, EXECUTION_INITIAL, 0); RegisterShaderPlugin(OBJECT_PREVIEW_SHADER_ID, "Object Preview", PLUGINFLAG_HIDE, ObjectPreviewShader::Alloc, "", 0); String name=GeLoadString(IDS_MENUTEST); if (!name.Content()) return TRUE; return RegisterCommandPlugin(1000956,name,0,"icon.tif", "C++ SDK Menu Test Plugin",gNew MenuTest); }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/03/2011 at 16:23, xxxxxxxx wrote:
Hi,
I've been trying to run this code in R11.5, to make it work i changed
this partif (image->bLowQuality) { bcRender.SetBool(RDATA_RENDERASEDITOR, TRUE); }
to
if (image->bLowQuality) { bcRender.SetBool(RDATA_RENDERENGINE, 1L); }
Unfortunately it keeps crashing with an "Access Violation error" in R11.5 when this part of the code is executed
virtual void Free(GeListNode\* node) { shad->Remove(); }
In other versions of cinema it seems to work fine though, including R12.
Does anybody have an idea why this might happen ? Why is R11.5 acting special here ?
thanks,
Daniel -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/03/2011 at 04:00, xxxxxxxx wrote:
Please use the appropriate IDs.
RDATA_RENDERENGINE_STANDARD RDATA_RENDERENGINE_PREVIEWSOFTWARE RDATA_RENDERENGINE_PREVIEWHARDWARE
And I think it should be SetLong(). For example:
bcRender.SetLong(RDATA_RENDERENGINE, RDATA_RENDERENGINE_PREVIEWHARDWARE);
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/03/2011 at 09:12, xxxxxxxx wrote:
thanks Matthias,
i will check it out to see if this was causing the crashes with R11.5..
-
On 19/08/2014 at 15:26, xxxxxxxx wrote:
I've been trying to get this code to work in R14, but have run into some issues. The dialog doesn't correctly display the MaterialPreviewCustomGui, the first problem seems to be with the SceneHook. It seems like the inserting the shader underneath the SceneHook is causing a crash though. If I change the Material preview in a material, such as rotating the gui object, it causes a crash immediately.
class ObjectPreviewHook : public SceneHookData { AutoAlloc<BaseShader> shad; public: ObjectPreviewHook() : shad(Xbitmap) {}; virtual Bool Init(GeListNode* node) { if (shad) { static_cast<BaseSceneHook*>(node)->InsertShader(shad);//Commenting this line out stops it from crashing } return TRUE; } virtual void Free(GeListNode* node) { shad->Remove(); } Bool InitPreviewData(MaterialPreviewData* preview_data, LONG dirtyCount) { return preview_data->Init(shad, dirtyCount); } static NodeData *Alloc(void) { return gNew ObjectPreviewHook; } };
SceneHook plugins have me a little scared, with how well made they need to be, so I figured I should ask for help before getting into any trouble.
Dan
-
On 20/08/2014 at 11:23, xxxxxxxx wrote:
I can't help with your error. But I did create an R13 version (which will also work in R14).
It does not crash. But it also does not work.
It doesn't display a torus object in the preview window. The MATPREVIEW_GENERATE_IMAGE message never gets called and I don't know why. So someone will have to finish it.This kind of code example shouldn't be posted on the forums. There's too many parts to it. And there's too many places to make a mistake. So I'm posting the entire plugin with the source code.
I also re-organized the code a little bit and hopefully I made it easier to follow.https://sites.google.com/site/scottayersmedia/Material Preview GUI R13.zip
Hopefully someone will fix it and re-post the fully working version of it.
-ScottA
-
On 20/08/2014 at 13:16, xxxxxxxx wrote:
Hi Scott, thanks for responding. I downloaded it and took a look. This seems to crash on me as well, but only on my Mac, I loaded it up on my PC and it doesn't crash on there. Seems like I have my own issues I have to deal with, not sure where to start though.
The code overall is a bit over my head, so hopefully someone smarter than me will take a look and help us out.
Dan