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.
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