SceneHook... how to?
-
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. -
On 09/06/2014 at 15:07, xxxxxxxx wrote:
*Edit*
Nothing to see here...Just Scott being a moron.-ScottA
-
On 09/06/2014 at 15:09, xxxxxxxx wrote:
Howdy,
Originally posted by xxxxxxxx
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?
Well, I don't think there is, and that may be the reason for using a SceneHook's ControlDisplay functions to do the drawing for something like that, so that the polygons aren't drawn twice.
Adios,
Cactus Dan -
On 09/06/2014 at 15:53, xxxxxxxx wrote:
Scott, I tried your code and nothing is painted in color.
Aren't we supposed to only use ControlDisplayStruct cds inside a SceneHook? -
On 09/06/2014 at 16:01, xxxxxxxx wrote:
DOH!
Sorry about that Rui. I goofed up.When I tested it I forgot to remove the SH plugin from my plugins folder. That's why it seemed to work in my tag plugin.
Would have been nice if it worked that easy.
-ScottA
-
On 09/06/2014 at 16:02, xxxxxxxx wrote:
Yes indeed. It would be excellent
-
On 09/06/2014 at 16:04, xxxxxxxx wrote:
Howdy,
Originally posted by xxxxxxxx
...When I tested it I forgot to remove the SH plugin from my plugins folder. That's why it seemed to work in my tag plugin. ...
Hehe, I wish I had a dollar for every time I did something like that.
Adios,
Cactus Dan