Hyperfiles and multiple plugin instances
-
On 27/12/2016 at 03:14, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14+
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;---------
Hi,I am using Hyperfiles to store vector arrays in my object generator plugin. It works well for a single instance of the plugin, but when I have more than one instance of the plugin added to the scene, I don't know how to allocate the respective stored arrays to the respective instances of the plugin.
Is there a certain routine that I need to follow?
If code is needed I can post some code on how I am storing the vector arrays in the Read/Write/CopyTo.
Thanks!
-
On 28/12/2016 at 01:20, xxxxxxxx wrote:
Hi,
Each object instance is responsible to write/read/copy its own vector array.
Yes, please post the code showing how you're storing the vector array in the object generator.
-
On 28/12/2016 at 07:36, xxxxxxxx wrote:
Thank you for your reply Yannik.
In this simplified example, I have 2 vector arrays myVectorsA and myVectorsB, and an integer value that I am storing named myCount.
Here is my Read/Write/CopyTo code:
Bool myObject::Read(GeListNode *node, HyperFile *hf, LONG level) { LONG stored_cnt = 0; hf->ReadLong(&stored_cnt); myVectorsA.Resize(stored_cnt); LONG stored_cnt1 = 0; hf->ReadLong(&stored_cnt1); myVectorsB.Resize(stored_cnt1); if (level>=0) { for (LONG i=0; i<stored_cnt; i++) { hf->ReadLVector(&myVectorsA[i]); } for (LONG i=0; i<stored_cnt1; i++) { hf->ReadLVector(&myVectorsB[i]); } hf->ReadLong(&myCount); } return TRUE; } Bool myObject::Write(GeListNode *node, HyperFile *hf) { hf->WriteLong(myVectorsA.GetCount()); hf->WriteLong(myVectorsB.GetCount()); for (LONG i=0; i<myVectorsA.GetCount(); i++) { hf->WriteLVector(myVectorsA[i]); } for (LONG i=0; i<myVectorsB.GetCount(); i++) { hf->WriteLVector(myVectorsB[i]); } hf->WriteLong(myCount); return TRUE; } Bool myObject::CopyTo(NodeData *dest, GeListNode *snode, GeListNode *dnode, COPYFLAGS flags, AliasTrans *trn) { myObject* myObject= NULL; myObject= static_cast<myObject*>(dest); myObject->myVectorsA.CopyFrom(myVectorsA); myObject->myVectorsB.CopyFrom(myVectorsB); myObject->myCount= myCount; return true; };
Thanks
-
On 28/12/2016 at 08:46, xxxxxxxx wrote:
Thanks for posting the code.
What are the members of your object generator class?
In Read()/Write()/CopyTo() you only deal with the values of the current instance. So you just have to store/restore/copy the current instance values.
Note the condition level >=0 in Read() is useless as level should always be equal to 0 or higher.
-
On 28/12/2016 at 11:21, xxxxxxxx wrote:
The class members are myVectorsA, myVectorsB, myCount.
After some reshuffling, I got it working with the above code.
Thank you Yannick for taking the time to answer.
-
On 28/12/2016 at 12:25, xxxxxxxx wrote:
This really should be documented much better. It's very a convoluted system and not intuitive at all.
I remember having a ton of trouble trying to figure it out when I was trying to store an array of BaseBitmap images for my PoseLibrary plugin. That was very frustrating and head banging thing to figure out.There really should be an example in the docs showing how to use arrays of class members with this system. The Vector type is a good choice. But the BaseBitmap type would be an even better example. Because you also need to free the memory for each image in the array.
I remember that after I finally got the Read(), Write(), CopyTo() working. Then I had some trouble freeing the memory for the BaseBitmap instances in the array.Knowing how to use these three functions on a simple single variable is too basic. It doesn't help much when using arrays of things. Especially for types that have to have their memory allocated and freed.
That really should be documented better.-ScottA
-
On 11/01/2017 at 07:42, xxxxxxxx wrote:
Hi Scott,
yes, we are aware, that the docs need to be improved here. And we are working on it. I added your specific question to our ToDo list. -
On 11/01/2017 at 08:04, xxxxxxxx wrote:
Thanks Andreas.
BTW. You mentioned something quickly before Christmas about something big coming after the holidays.
Do you guys have a major document update or something in the works?
Or did I dream reading that?-ScottA
-
On 11/01/2017 at 08:37, xxxxxxxx wrote:
Hm, did I?
I'd be sorry, to have raised false expectations (and usually I really try to avoid such).
May be it was about docs on threading and UI? Then I have good news, today R18 SP2 got released and in parallel, we released an updated SDK documentation. In there are new manuals about these two topics. Just take a look under Overviews (or check out our latest blog post with direct links). -
On 11/01/2017 at 09:10, xxxxxxxx wrote:
That must be it. I'm off to take a look at it now.
Thanks for the updates.-ScottA