About
New instances of Cinema API 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.
- Note
- 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 Common Plugin Concepts).
class ObjectDataGenerator : public ObjectData
{
public:
static NodeData* Alloc(void)
{
return NewObjClear(ObjectDataGenerator);
}
};
#define OBJECT_GENERATOR
Generator object. Produces a polygonal or spline representation on its own. (e.g. primitive cube)
Definition: ge_prepass.h:946
Bool RegisterObjectPlugin(Int32 id, const maxon::String &str, Int32 info, DataAllocator *g, const maxon::String &description, BaseBitmap *icon, Int32 disklevel)
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.
{
if (
node ==
nullptr || !SUPER::Init(
node, isCloneInit))
return false;
BaseObject*
const obj =
static_cast<BaseObject*
>(
node);
BaseContainer& data =
obj->GetDataInstanceRef();
data.SetBool(EXAMPLE_GENERATOR_PARAMETER_BOOL, true);
data.SetInt32(EXAMPLE_GENERATOR_PARAMETER_VALUE, 123);
PyObject * obj
Definition: complexobject.h:60
maxon::Bool Bool
Definition: ge_sys_math.h:46
- Note
- If 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)
{
GeListHead::Free(_branchHead);
}
void DeleteMem(T *&p)
Definition: defaultallocator.h:269
Further Reading