On 05/12/2016 at 07:49, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14+
Platform: Windows ; Mac ;
Language(s) : C++ ;
---------
Hello,
I would like to cache a BaseArray of vectors at every frame in the scene file, similar to particle system caching. I thought about using a Hyperfile for that, where I store all the positions of the particles in a HF and retrieve them at will.
If I use a fixed size BaseArray, I am able to cache the array. If on the other hand I change the size of the array and save the scene, upon scene open, I get an Incorrect File Structure error and the scene would not load.
Here is the code I am using to test the caching:
class myObject : public ObjectData
{
...
public:
maxon::BaseArray<Vector>myVectors; // define myVectors as a class member BaseArray
...
}
// Init
Bool myObject::Init(GeListNode *node)
{
...
myVectors.Resize(10);
LONG aa = myVectors.GetCount();
for (LONG i=0; i<aa; i++) myVectors[i] = Vector(i);
}
// Read and Write the Hyperfile
Bool myObject::Read(GeListNode *node, HyperFile *hf, LONG level)
{
if (level>=0)
{
for (LONG i=0; i<myVectors.GetCount(); i++) // I think the problem resides here...
{
hf->ReadLVector(&myVectors[i]);
}
}
return TRUE;
}
Bool myObject::Write(GeListNode *node, HyperFile *hf)
{
for (LONG i=0; i<myVectors.GetCount(); i++) // and here...
{
hf->WriteLVector(myVectors[i]);
}
return TRUE;
}
// Message buttons to read into the console and write into the BaseArray
Bool myObject::Message(GeListNode *node, LONG type, void *data)
{
...
if (dc->id[0].id == HF_READ)
{
print(myVectors); // print the vector array into the console
}
if (dc->id[0].id == HF_WRITE)
{
myVectors.Resize(5); // here I am changing the size of the array
for (LONG i=0; i<5; i++) myVectors[i] = Vector(i);
}
}
Is the proper way of caching a BaseArray into the scene file?
How can I solve the variable size error that I am getting?
Thanks!