External Class Update
-
On 04/07/2016 at 10:16, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14+
Platform:
Language(s) : C++ ;---------
Hi,I have an object generator plugin with an external class whose members I want to update within GetVirtualObjects.
This is how I am defining my external class:
// object generator class class myPlugin: public ObjectData { INSTANCEOF(myPlugin, ObjectData); public: virtual Bool Message(GeListNode *node, LONG type, void *data); virtual BaseObject* GetVirtualObjects(BaseObject *op, HierarchyHelp *hh); virtual Bool Init(GeListNode *node); virtual DRAWRESULT Draw(BaseObject *op, DRAWPASS drawpass, BaseDraw *bd, BaseDrawHelp *bh); static NodeData* Alloc(void) { return gNew myPlugin; } }; class myCharacter { public: Vector position; myCharacter() { position= Vector(0,0,0); } void walk() { position += Vector(10,0,0); } };
Now inside GetVirtualObjects (GVO), I want to update the position at every frame.
myCharacter c; c.walk(); outputVector(c.position); //does not update unless I call c.walk() again and again
P.S. outputVector is a custom function that outputs a vector to the console
I have 2 questions:
1. Is this the right way of using a custom class beside the plugin class?
2. How do I update the walk() function at every frame inside GVO ? -
On 05/07/2016 at 02:09, xxxxxxxx wrote:
Hello,
if you store any internal data inside a NodeData based plugin you might have to handle that data in the object's CopyTo function. Cinema will often create copies of an object for several reasons so you have to make sure these copies are properly set up. See NodeData::CopyTo() Manual.
ObjectData::GetVirtualObjects() is not only called when the current frame of the host document is changed. It is called every time the scene is executed. This can happen when something on the object or anywhere in the scene changed. So GetVirtualObjects() must return the objects it creates for the current frame of the document. This might be the same frame as the last time it was executed. To optimize your functions you must use caches. See BaseObject Manual.
So an incremental function like your Walk() function must be handled carefully any only called if the object really goes one step further. For example look at the Particle Emitter. It works well when you run the animation but when you jump around in the timeline it breaks down. To avoid this you must handle caches and define if your generator should also support jumping around in the timeline.
Best wishes,
Sebastian -
On 15/07/2016 at 08:11, xxxxxxxx wrote:
Hello salozo,
was your question answered?
best wishes,
Sebastian -
On 15/07/2016 at 11:18, xxxxxxxx wrote:
Hi Sebastian,
Do you have CopyTo() example snippet that can help in this particular situation, i.e. make the external class and its members update at every frame?
Thanks!
-
On 18/07/2016 at 00:13, xxxxxxxx wrote:
Hello,
you find an simple implementation of NodeData::CopyTo() in the CopyTo() manual. But implementing CopyTo() has no influence on how your generator is updated. This is defined in ObjectData::GetVirtualObjects().
You find some example code on how to check the dirty state of the cache and the generator object in the cinem4dsdk example project or on GitHub. You can then add a check that compares the current time of the host BaseDocument with some internally stored time of the last execution.
Best wishes,
Sebastian -
On 18/07/2016 at 23:03, xxxxxxxx wrote:
I guess I have to figure out a way to update it myself.
Thanks for the answers.