THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/05/2010 at 06:39, xxxxxxxx wrote:
FYI, I put together a small example of how to store a NodeData plugin within a scene hook.
Please check the code comments for more detailed information.
the NodeData plugin:
#include "c4d.h"
#include "c4d_symbols.h"
//just a extremly simple Nodedata plugin :)
class MyNode : public NodeData
{
public:
static NodeData *Alloc(void) { return gNew MyNode; }
};
#define ID_MYNODE 1024726
Bool RegisterMyNode(void)
{
return RegisterNodePlugin(ID_MYNODE, "My Node", 0, MyNode::Alloc, NULL, 0, NULL);
}
the SceneHookData plugin to store the NodeData plugin:
#include "c4d.h"
#include "c4d_symbols.h"
class MyNode;
#define ID_MYSCENEHOOK 1025181
class MySceneHook : public SceneHookData
{
public:
//constructor; initialization and plugin node allocation
MySceneHook()
{
hookname = String("My SceneHook Name");
mynode = (BaseList2D* )AllocListNode(1024726);
}
virtual Bool Init(GeListNode *node);
virtual Bool Read(GeListNode *node, HyperFile *hf, LONG level);
virtual Bool Write(GeListNode *node, HyperFile *hf);
virtual LONG GetBranchInfo(GeListNode* node, BranchInfo* info, LONG max, ULONG flags);
static NodeData *Alloc(void) { return gNew MySceneHook; }
private:
AutoAlloc<GeListHead> head; //this is the list head were the plugin node will be inserted to
String hookname;
BaseList2D *mynode; //pointer to an instance of the plugin node
};
Bool MySceneHook::Init(GeListNode *node)
{
if (!head || !mynode) return FALSE;
head->SetParent(node); //needed to save the node list
head->Insert(mynode, NULL, NULL); //insert the plugin node into the list
return TRUE;
}
Bool MySceneHook::Read(GeListNode *node, HyperFile *hf, LONG level)
{
return head->ReadObject(hf, TRUE); //needed to read files
}
Bool MySceneHook::Write(GeListNode *node, HyperFile *hf)
{
return head->WriteObject(hf); //needed to save files
}
LONG MySceneHook::GetBranchInfo(GeListNode *node, BranchInfo *info, LONG max, ULONG flags)
{
//fill the info structure array; only one element is saved in this example
info[0].head = head;
info[0].name = &hookname;
info[0].id = ID_MYSCENEHOOK;
info[0].flags = 0;
return 1; //return the number of filled BranchInfo elements
}
Bool RegisterMySceneHook(void)
{
return RegisterSceneHookPlugin(ID_MYSCENEHOOK, "My SceneHook", 0, MySceneHook::Alloc, EXECUTION_EXPRESSION, 0, NULL);
}
main.cpp
...
Bool RegisterMyNode(void);
Bool RegisterMySceneHook(void);
...
Bool PluginStart(void)
{
...
if (!RegisterMyNode()) return FALSE;
if (!RegisterMySceneHook()) return FALSE;
...
return TRUE;
}
hope this helps
cheers,
Matthias