Workplane Manipulation Within a ToolData-Derived Plugin
-
Hi,
When the workplane is modified using the ToolData custom plugin, the ortho viewports do not refresh to reflect the new workplane. The modification is done in the ToolData::Mouse callback:// Example: Modify the Workplane Matrix here BaseObject* workplane = doc->GetWorkplaneObject(); if (workplane) { Matrix newMatrix; // Modify the matrix as needed workplane->SetMg(newMatrix); // Notify Cinema 4D that a change has occurred EventAdd(); // Force the viewports to update DrawViews(DRAWFLAGS::DRAWFLAGS_FORCEFULLREDRAW); }
When the workplane is modified using Cinema 4D's native tools, the ortho viewports automatically align to the new workplane.
Any clue on how to achieve this programmatically in a custom plugin tool?
Thanks!
-
Hey @WTools3D,
Thank you for reaching out to us. Please have a look at Support Procedures: How to ask Questions:
- Your code is not executable, there is neither a
BaseDocument::GetWorkplaneObject
norDRAWFLAGS::DRAWFLAGS_FORCEFULLREDRAW
and there is noToolData::Mouse
. Sure, I can guess for all these what you meant, but that is extra work for us. - If had not talked with Ilia about this in our morning meeting, I would have simply labeled this as untrue, and moved on. Your claim 'When the work plane is modified using the ToolData custom plugin, the ortho viewports do not refresh to reflect the new work plane' is untrue, they do update (although incorrectly). it is important that you give us a reasonably precise description of your problem as we usually do not have the time to test something from all angles.
The problem was/is here that orthographic viewports did not update properly when calling
DrawViews
after setting the transform of the work plane. While the plane itself is being updated properly and also drawn in the orthographic views according to its new transform, the objects in the scene are drawn incorrectly in orthographic views, not reflecting the new work plane orientation. This will only be remedied when the user switches between documents.I had a brief look at what our 'snap work plane to selection' code does, and the answer is that it updates the work plane transform of all viewports manually.
Cheers,
FerdinandPS: Since this always has been like this, the git blame for the relevant code is 13 years old, and since there is a workaround, I have not opened a bug ticket for this.
Code
#include "c4d_snapdata.h" Bool MyTool::MouseInput(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, EditorWindow* win, const BaseContainer& msg) { // Get the work plane object and the active object when the user presses the left mouse button. if (msg.GetInt32(BFM_INPUT_CHANNEL) != BFM_INPUT_MOUSELEFT) return true; BaseObject* const workplane = GetWorkplaneObject(doc); const BaseObject* const op = doc->GetActiveObject(); if (!workplane || !op) return true; // Copy over the transform from the object to the work plane. const Matrix mg = op->GetMg().GetNormalized(); workplane->SetMg(mg); // Here comes the hacky bit which is necessary to make sure the work plane is applied correctly // to each viewport. We iterate over all viewports and set the work plane matrix manually. If we // would take these lines out and the DrawViews call back in, we would encounter the buggy // behavior of only half way updated orthographic viewports. const Int32 count = doc->GetBaseDrawCount(); for (Int32 i = 0; i < count; i++) doc->GetBaseDraw(i)->SetBaseMatrix(mg); // When we have done this, we do not have to call DrawViews() anymore, but we must still invoke // an event as we did modify the scene. // DrawViews(DRAWFLAGS::NO_THREAD | DRAWFLAGS::NO_ANIMATION); EventAdd(); return true; }
- Your code is not executable, there is neither a
-
I am sorry for a messy question and thank for answering it anyways.
I'll try to be more precise next time.This solution works fine.
Thank you!
V. -
Good to hear! And your question was not 'messy', but to ensure efficient support, we must enforce certain rules.
Cheers,
Ferdinand