CustomDataType animation via Motion Systems

On 24/04/2014 at 05:58, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R13.061 
Platform:   Windows  ;   
Language(s) :     C++  ;

Hi everyone!

I am trying to create a custom data type plugin, then animate it using the Motion Systems of c4d. Naturally, there's an actual data structure, really dumb, and the actual plugin, which inherits from CustomDataTypeClass. I'll dump the source code here, stripped to a minimum: :

struct MyCustomDataType : public CustomDataType {
    MyCustomDataType ( void ) : modeling(0), runtime(0) {}
    ~MyCustomDataType() {}
    LONG modeling, runtime;
class MyCustomDataTypePlugin : public CustomDataTypeClass {
    virtual CustomDataType*	AllocData() ;
    virtual void FreeData(CustomDataType *data) ;
    virtual Bool CopyData(const CustomDataType *src,CustomDataType *dest,AliasTrans *aliastrans) ;
    virtual LONG Compare(const CustomDataType *d1,const CustomDataType *d2) ;
    virtual Bool WriteData(const CustomDataType *d,HyperFile *hf) ;
    virtual Bool ReadData(CustomDataType *d,HyperFile *hf,LONG level) ;
    virtual const CHAR *GetResourceSym() ;
    virtual Bool InterpolateKeys(GeData &res, const GeData &t_data1,const GeData &t_data2,Real mix,LONG flags) {
        const MyCustomDataType  *d1(static_cast<const MyCustomDataType*>(t_data1.GetCustomDataType(GetId()))), 
                                *d2(static_cast<const MyCustomDataType*>(t_data2.GetCustomDataType(GetId())));
        MyCustomDataType resulting;
        if ( !d1 || !d2 ) return FALSE;
        resulting.runtime = d2->modeling * mix + d1->modeling * ( 1.0 - mix ); 
        resulting.modeling = d1->modeling;
        res.SetCustomDataType(GetId(), resulting);
        return CustomDataTypeClass::InterpolateKeys(res, t_data1,t_data2, mix, flags) || TRUE; 

On demand, I will provide more context. There's also a custom gui used with this datatype, and an object plugin which uses the data type.

So, animating an attribute of this type using simple key frame animations works as a charm. Add some keyframes, then change the current frame, values are updated just fine. The trouble begins only when I try to convert the animation to a Motion System. My first guess was that I had to implement another interface of the CustomDataTypeClass, so to find out which one, I traced all of them. Only the methods from my code sample are ever called, so it doesn't look like this is the reason.

The next step was to trace the  MSG_DESCRIPTION_POSTSETPARAMETER Message on my custom object. I found out that my attribute value is updated when moving the frame slider, but not on the object I have in my scene. Instead, on some copy of it, which can be seen in the Animation Timeline dialog. I tried the same with a simple LONG attribute. The same thing happens. The values is first updated on a copy of the object, then copied to the actual object. With my custom data type, the value is updated on the copy, but never copied to the actual object.

Any hints that could help me track it down are very welcome, and if my explanation makes no sense at all, please ask! :slightly_smiling_face:

On 29/04/2014 at 01:13, xxxxxxxx wrote:

I'm afraid this can't work. The motion system only works for Float/Int and PLA tracks.