SceneHook... how to?
-
On 09/06/2014 at 06:10, xxxxxxxx wrote:
Howdy,
It looks like none of the display control functions are being called.
I added GePrint() functions to each of your scene hook's functions like this:
Bool polypainteditor::InitDisplayControl(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, const AtomArray *active) { GePrint("polypainteditor::InitDisplayControl()"); return true; }
... and nothing was ever printed to the console.
Adios,
Cactus Dan -
On 09/06/2014 at 06:17, xxxxxxxx wrote:
Exactly. I also did that and nothing is happening.
Could it be broken? Or maybe, more probable, I'm missing something.
Anyone from Maxon could explain how to do this? -
On 09/06/2014 at 09:12, xxxxxxxx wrote:
It all works fine, but no faces are colored with random colors.
I mean, the triangles do appear but the object is still displayed the same.
The DisplayControl method is simple ignored. -
On 09/06/2014 at 09:37, xxxxxxxx wrote:
Yeah. I realized that right after I posted it. That's why I deleted my reply Rui.
But I still don't know why you're doing it that way?All of the drawing of lines, objects, polygons can be done in the Draw() method of your Tag plugin.
Using a SceenHook for this seems like an unnecessary extra plugin that you don't really need.
But even if for some reason you just wanted to use a SH. The object can be drawn using the Draw() method in there too.However...That being said.
I would also like to know how to use the DisplayControl() method. Because the SDK does not explain properly how to use it.
That's a documentation problem that needs to be addressed and clarified much better.
Perhaps the InitDisplayControl() method needs to also be used in combo with it?-ScottA
-
On 09/06/2014 at 09:45, xxxxxxxx wrote:
I already have it working inside the Draw method of the tag itself.
But the problem is that I want the faces to be drawn in some specific colors, just like how it happens when one selects the Vertex Map tag. When we select a Vertex Map tag, the faces of the polygonal object show up in the red/yellow mapping of the weights.
The way I have it now, it draws faces that are coplanar with the faces. Besides being slower, since I have to draw the polygons, the result is far from what I intend because I see the original faces and a bit of my drawn polygons, flickering a lot as I move the camera in the editor.
Since I already have a list of RGB values that correspond to each point of the polygonal object, being able to provide that list to be used for display would be exactly what I want.
And it seems to be exactly what the ControlDisplayStruct &cds; is meant for.
If it worked, I would just need to fill the cds.vertex_color list with my list and Cinema4D would simply display the object like I wanted, without me having to manually draw all the faces.
So, I really need to know how this works.
The documentation is really not helping -
On 09/06/2014 at 11:01, xxxxxxxx wrote:
I've sort of got it working...But I can't control it yet.
The way I'm guessing it works is that the InitDisplayControl() method's TRUE/FALSE return value controls whether or not to use the DisplayControl() method.
The active scene objects are stored in an Atom array called "active".But I can't seem to figure out how to shut it off when the objects are not selected or if they are not polygon type objects.
Right now. All the objects get their vertices colored with random colors. And I can't seem to control it yet.Bool MySceneHook::InitDisplayControl(BaseSceneHook *node, BaseDocument *doc, BaseDraw *bd, const AtomArray *active) { for(LONG i=0; i != active->GetCount(); i++) { String name = static_cast<BaseObject*>(active->GetIndex(i))->GetName(); GePrint(name); } return TRUE; }
-ScottA
-
On 09/06/2014 at 11:27, xxxxxxxx wrote:
I tried to include your code in my InitDisplayControl method and I don't even get anything printed in the Console
-
On 09/06/2014 at 11:33, xxxxxxxx wrote:
Even something as simple as:
Bool polypainteditor::InitDisplayControl(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd, const AtomArray *active)
{
GePrint("Inside InitDisplayControl");
return TRUE;
}Prints nothing!!
-
On 09/06/2014 at 11:33, xxxxxxxx wrote:
Howdy,
At this point, we may need Maxon to supply an example.
Adios,
Cactus Dan -
On 09/06/2014 at 11:34, xxxxxxxx wrote:
Maxon!!! Hey, MAXON!!! Are you there?!?
Please, come helps us figure this out. -
On 09/06/2014 at 11:54, xxxxxxxx wrote:
But, are your polygonal objects displayed with random colors, Scott?
If they are, can you show us all your code? -
On 09/06/2014 at 12:01, xxxxxxxx wrote:
Yes. They are random colors. But I can't control the stupid thing.
When I select a polygon type object, all of the other objects in the scene(even primitives) have their vertices set to random colors too!
It's really bizarre. !Wacko
[URL-REMOVED]Here's my entire code:
#include "c4d.h" #include "c4d_symbols.h" #define PLUGIN_ID 1000009 class MySceneHook : public SceneHookData { public: virtual Bool Init(GeListNode *node); virtual Bool DisplayControl(BaseDocument* doc, BaseObject* op, BaseObject* chainstart, BaseDraw* bd, BaseDrawHelp* bh, ControlDisplayStruct& cds); virtual Bool InitDisplayControl(BaseSceneHook* node, BaseDocument* doc, BaseDraw* bd, const AtomArray* active); virtual Bool Draw(BaseSceneHook *node, BaseDocument *doc, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt, SCENEHOOKDRAW flags); virtual Bool Message(GeListNode *node, LONG type, void *data); virtual EXECUTIONRESULT Execute(BaseSceneHook* node, BaseDocument* doc, BaseThread* bt, LONG priority, EXECUTIONFLAGS flags); virtual void FreeDisplayControl(void); static NodeData *Alloc(void) { return gNew MySceneHook; } }; Bool MySceneHook::Init(GeListNode *node) { return TRUE; } Bool MySceneHook::InitDisplayControl(BaseSceneHook *node, BaseDocument *doc, BaseDraw *bd, const AtomArray *active) { for(LONG i=0; i != active->GetCount(); i++) { String name = static_cast<BaseObject*>(active->GetIndex(i))->GetName(); GePrint(name); if(active->GetIndex(i)->IsInstanceOf(Opolygon)) { GePrint("poly object"); return TRUE; //Use the DisplayControl() method } else return FALSE; //Don't use the DisplayControl() method } } Bool MySceneHook::DisplayControl(BaseDocument *doc, BaseObject *op, BaseObject *chainstart, BaseDraw *bd, BaseDrawHelp *bh, ControlDisplayStruct &cds) { //What should happen here is that if a polygon type object is selected. The vertices get a random color applied to them //And any non-polygon type objects in the scene should not get changed....But they do!!? //Why are all of the non polygon objects in the scene getting their vector colors replaced too? //Only run this code if the selected object is a polygon type object if(op->IsInstanceOf(Opolygon)) { PolygonObject *pobj = ToPoly(op); LONG pcnt = pobj->GetPointCount(); cds.vertex_color = GeAllocTypeNC(SVector, pcnt); if(!cds.vertex_color) return FALSE; LONG i; Random rnd; rnd.Init(45346); for(i=0; i<pcnt; i++) { cds.vertex_color[i] = SVector(rnd.Get01(), rnd.Get01(), rnd.Get01()); } return TRUE; } else return FALSE; } Bool MySceneHook::Draw(BaseSceneHook *node, BaseDocument *doc, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt, SCENEHOOKDRAW flags) { return TOOLDRAW_HANDLES|TOOLDRAW_AXIS; } Bool MySceneHook::Message(GeListNode *node, LONG type, void *data) { return TRUE; } EXECUTIONRESULT MySceneHook::Execute(BaseSceneHook* node, BaseDocument* doc, BaseThread* bt, LONG priority, EXECUTIONFLAGS flags) { return EXECUTIONRESULT_OK; } void MySceneHook::FreeDisplayControl(void) { //..Not sure what to do here...If anything???? } Bool RegisterMySceneHook(void) { return RegisterSceneHookPlugin(PLUGIN_ID, "My SceneHook", 0, MySceneHook::Alloc, EXECUTIONPRIORITY_GENERATOR, 0, NULL); }
-ScottA
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 09/06/2014 at 12:02, xxxxxxxx wrote:
Howdy,
Hmmmmm, "polypainteditor"? Is this an editor tool, that could possibly be better off being a ToolData plugin?
Adios,
Cactus Dan -
On 09/06/2014 at 12:06, xxxxxxxx wrote:
Not, it is not a tool. I called editor because it is supposed to show the "shading" in the editor
I already have a shader that works just fine. But I would like it to show in the editor also. -
On 09/06/2014 at 12:53, xxxxxxxx wrote:
I made it work!!!
But in my case it is simpler to check what object needs to be painted because only objects with my specific tag need to be painted.
However, this only works when the object is selected.
I guess it is a limitation, right?
Or is it possible to make it paint in the editor with the set of colors I define, even when the object is not selected? -
On 09/06/2014 at 13:13, xxxxxxxx wrote:
Howdy,
OK, I see what's wrong with the code you posted.
You have this function:
virtual Bool InitDisplayControl(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, const AtomArray *active);
... when it should be this:
virtual Bool InitDisplayControl(BaseSceneHook* node, BaseDocument* doc, BaseDraw* bd, const AtomArray* active);
That's why your InitDisplayControl() function wasn't being called. The parameters were not correct, so in essence you were defining your own new virtual function that was never called.
Adios,
Cactus Dan -
On 09/06/2014 at 13:16, xxxxxxxx wrote:
I'm glad you got it to do what you want. Because I can't control the stupid thing at all.
I know you say that the Draw() method won't work for you. But I find that to be strange.
I've never used these strange SH methods is because I've found that I can usually do all of my drawing stuff just fine in the tag's Draw() method.Here's an example of drawing the object the tag is on in the scene. Only with a with a blue color. And with little red cubes Drawn on it's verts.
All of this is done in the Draw() method.
I still can't imagine why what you're doing won't work there too.*shrug*
-ScottA
-
On 09/06/2014 at 13:25, xxxxxxxx wrote:
I figured that I was declaring the InitDisplayControl wrong, also, Dan
Scott, I'm using the Draw method of the Tag to draw the faces.
But what I needed was to draw the object with custom colors for all faces and what I can only do in the Draw method is to draw faces with custom colors, one by one.
That is quite slow, for objects with a lot of faces.Is there a way, inside the Draw method, that allows me to turn off the painting on the original object and manually paint all the faces with custom colors for each vertex?
-
On 09/06/2014 at 13:51, xxxxxxxx wrote:
I'm not really sure about the vertex colors thing.
When I create my text HUD images. I do get each corner of the plane object that the image will stick onto and color them. But that's only four verts. Not a lot of them.When I started out using Draw(). One of the things I did wrong was to instantiate things in there instead of in the Init() method. And that tended to make the Draw() run slow.
Example:
//You should allocate draw objects at the Init() of the plugin and free at Free() of the plugin class MyObject : public ObjectData { public: virtual Bool Init(GeListNode *node); virtual void Free(GeListNode* node); virtual Bool Message(GeListNode *node, LONG type, void *data); virtual DRAWRESULT Draw (BaseObject *op, DRAWPASS type, BaseDraw *bd, BaseDrawHelp *bh); virtual Bool AddToExecution(BaseObject *op, PriorityList *list); //Lets you define your own execution pointer virtual EXECUTIONRESULT Execute(BaseObject *op, BaseDocument *doc, BaseThread *bt, LONG priority, EXECUTIONFLAGS flags); static NodeData *Alloc(void) { return gNew MyObject; } private: PolygonObject* sphere; }; Bool MyObject::Init(GeListNode *node) { //Create a polygon sphere by creating a primitive sphere first..then casting it to a polygon object type sphere = (PolygonObject* )GeneratePrimitive(node->GetDocument(), Osphere, BaseContainer(), 1.0, FALSE, NULL); BaseObject *op = (BaseObject* )node; BaseContainer *bc = op->GetDataInstance(); bc->SetReal(MYOBJECT_RADIUS,1.0); return TRUE; } void MyObject::Free(GeListNode* node) { PolygonObject::Free(sphere); }
I've never tried to color each polygon face a different color. Let alone a lot of them.
Normally I am either coloring the whole object a different color...Or coloring (highlighting) the selected polygons. So I don't know if that presents a problem in the Draw() method or not.
But it just seems wrong to me to have to use a SH just to draw polygons like that. But I'm not an expert on this stuff and I could be (and I often am ) wrong.-ScottA
-
On 09/06/2014 at 14:05, xxxxxxxx wrote:
Until now I didn't had many problems with the Draw method (of Tags and Objects). But I'm not a true coder. I'm just a geek designer
For what I'm doing, I really need to color "manually" the faces since there are no UVs attached to the type of objects that I'm dealing with.
Providing Cinema4D with an array of Vector containing all the RGB values of all points and having it deal with them is too good to be true
It is a shame that it only works with selected objects.
Manually, I have to go through the list of polygons. Get the a,b,c and d indexes. Use those indexes to get the RGB values of my list and the points coordinates to create two arrays that can be fed to the DrawPoly.
It is a whole lot more work to do than simply providing a list of RGBs
That is why the SceneHook thingy is so useful to me.