NodeData::Init() / Alloc and Free Manual

内容表

关于

New instances of classic plugin classes are typically created using a static "Alloc" function. The initial values of this instance are defined in an "Init" function. When an instance is deleted, its "Free" function is called.

注意
The undo system will allocate new instances of a plugin class when a scene object is changed.
"Alloc"/"Free" functions should generally be used instead of class constructor/destructor, as they provide means to return an error if anything goes wrong.

Alloc

A static "Alloc" function creates a new instance of a plugin class. This "Alloc" function is referenced in the corresponding "Register" function (see 一般插件信息手册 ).

// This is a plugin class with a static "Alloc" function:
class ObjectDataGenerator : public ObjectData { public :
static NodeData * Alloc( void ) { return NewObjClear(ObjectDataGenerator); } };

// This is a "Register" function referencing that static "Alloc" function: RegisterObjectPlugin (123456, "Example Generator" , OBJECT_GENERATOR , ObjectDataGenerator::Alloc, "Ogenerator" , nullptr , 0);

Init

Each class derived from NodeData can implement NodeData::Init() . This "Init" function is called every time when an instance of the plugin class is allocated. In this "Init" function one can define the default values of parameters and internal data instead of using a class constructor.

// This example implements NodeData::Init() in a plugin class. // It sets the default values of the plugin's parameters. virtual Bool Init( GeListNode * node) { if (node == nullptr || !SUPER::Init(node)) return false ;

// get the "real" object BaseObject * const obj = static_cast< BaseObject * > (node);

// get data container BaseContainer & data = obj-> GetDataInstanceRef ();

// set default parameter values data. SetBool (EXAMPLE_GENERATOR_PARAMETER_BOOL, true ); data. SetInt32 (EXAMPLE_GENERATOR_PARAMETER_VALUE, 123);

注意
NodeData::Init() returns false the object won't be created.
If an entity should be modified when it was created the best solution is to catch the MSG_MENUPREPARE message.
There's no guarantee NodeData::Init() is called only once. In fact it may very well be called multiple times.

Free

Each class derived from NodeData can implement NodeData::Free() . This function is called when an instance gets freed. Implement this function to free internal data.

virtual void Free( GeListNode * node) { DeleteMem (_memory); GeListHead::Free (_branchHead); }

延伸阅读

BaseObject
定义: c4d_baseobject.h:224
BaseContainer::SetInt32
void SetInt32(Int32 id, Int32 l)
定义: c4d_basecontainer.h:505
GeListHead::Free
static void Free(GeListHead *&v)
ObjectData
定义: c4d_objectdata.h:168
BaseContainer::SetBool
void SetBool(Int32 id, Bool b)
定义: c4d_basecontainer.h:498
NodeData
定义: c4d_nodedata.h:38
GeListNode
Represents a C4DAtom that resides in a 4D list.
定义: c4d_baselist.h:1767
BaseList2D::GetDataInstanceRef
const BaseContainer & GetDataInstanceRef() const
定义: c4d_baselist.h:2299
maxon::DeleteMem
void DeleteMem(T *&p)
定义: defaultallocator.h:258
RegisterObjectPlugin
Bool RegisterObjectPlugin(Int32 id, const maxon::String &str, Int32 info, DataAllocator *g, const maxon::String &description, BaseBitmap *icon, Int32 disklevel)
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
OBJECT_GENERATOR
#define OBJECT_GENERATOR
Generator object. Produces a polygonal or spline representation on its own. (e.g. primitive cube)
定义: ge_prepass.h:893
BaseContainer
定义: c4d_basecontainer.h:46

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1