Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    how to store/serialize custom data type?

    Cinema 4D SDK
    c++
    2
    4
    659
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • aghiad322A
      aghiad322
      last edited by aghiad322

      hi there , i'm making a custom data type , and if i'm not mistaken the "MyCustomData::DescribeIO(const maxon::DataSerializeInterface& stream)" along with "Describe()" are responsible for storing/serializing the data , as in my custom type i used the example 'Dots' datatype and added extra data i want to use

      maxon::Result<void> iMyCustomData::DescribeIO(const maxon::DataSerializeInterface& stream)
      {
      	iferr_scope;
      
      	PrepareDescribe(stream, iMyCustomData);
              //this is how the example is storing the _points member array
      	Describe("_points", _points, Vector, maxon::DESCRIBEFLAGS::TYPE_ARRAY) iferr_return;
      	Describe("_TimeScaler", _TimeScaler, Float, maxon::DESCRIBEFLAGS::NONE) iferr_return;
              //here i have member variables of my custom type as pointers (Gradient* MyCustomData::_gradient), it gives me error "missing data type registration" since it's a pointer not tthe data type.
      	Describe("_gradient", _gradient, Gradient*, maxon::DESCRIBEFLAGS::NONE) iferr_return;
             // and if i tried to add a member of type "Gradient" instead of pointer "Gradient*" i cant instantiate it since it has a private constructor
      
              Describe("_gradient", _gradient, Gradient, maxon::DESCRIBEFLAGS::NONE) iferr_return;
      	//Describe("_spline", ("_spline, SplineData*, maxon::DESCRIBEFLAGS::NONE) iferr_return;
      
      	return maxon::OK;
      }
      

      so my problem is two parts :
      1-how can i serialize c4d-registered custom data types i.e : Gradient, SplineData ....
      2- i ccouldn't instantiate a member of type "Gradient" instead of a pointer to Gradient "Gradient *"
      i tried dereferencing the allocated gradient but with no avail : Gradient _grad = *(Gradient::Alloc());
      sorry if my cpp skills might be the barrier here .

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @aghiad322
        last edited by ferdinand

        Hey @aghiad322,

        thank you for reaching out to us. Your question suffers from a little bit ambiguity regarding in which part of our API you are realizing that data type. You can implement data types using both the classic (CustomDataTypeClass) and maxon API (maxon::DataType) and both systems are completely disjunct. You are talking about classic API types and use a name that implies that you implement a CustomDataTypeClass but show us code that would only make sense in the context of some maxon API data structure you implement.

        maxon API: DescribeIO is a mechanism of the maxon API which can be used to serialize maxon::Data and other maxon API data structures such as maxon::DataType. It is JSON based and you are bound to serializing atomic and container types such as bool, string, Int32, BaseArray, DataDictionary, etc. (and interfaces which implement it). You cannot serialize classic API data (e.g., SplineData) with it, and there are also some gaps in the maxon API, maxon::HashMap is for example not supported.

        classicAPI: When you are implementing a classic API data type, a CustomDataTypeClass, the methods to overwrite for serialization would be CustomDataTypeClass::ReadData and ::WriteData. These methods work the same as node serialization works in the classic API. Things get serialized into the binary HyperFile format with which you can store all the classic API data types and also other things (see HyperFile manual).

        1 - how can I serialize c4d-registered custom data types i.e : Gradient, SplineData [...]

        You cannot serialize classic API data types using DescribeIO. There is at least no automatism. You can of course manually split data into atomic elements and then later compose the data type again out of such decmposed data.

        2 - I couldn't instantiate a member of type Gradient instead of a pointer Gradient* [...]

        You cannot serialize a classic API data type (Gradient) using DescribeIO. And serializing a pointer does not make much sense in the first place, as you would then just serialize a memory address, where your _gradient is located in memory, instead of the actual data stored by _gradient.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        aghiad322A 1 Reply Last reply Reply Quote 0
        • aghiad322A
          aghiad322 @ferdinand
          last edited by

          @ferdinand the example that i based my custom data type from is "DotsCustomDataTypeClass" in file "customdata_customgui.h",and i kept it's functionality "when click on the gui a new square is added", and this part is saving and loading fine as in the provided video, but the color graident shown in the dialog that i change is not saving as you can see as soon as i click of the tag the gradient data resets, sorry if my question is too general but how can i store the "Gradient" data as if they were like any other parameter.
          this is my data type on a tag ,compiled with cinema 4d 26
          myTag.zip

          ferdinandF 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand @aghiad322
            last edited by ferdinand

            Hey @aghiad322,

            as I said, classic API CustomDataType types (e.g., the "dots" example) realize their serialization via CustomDatatypeClass::Read and ::Write. The DotsDataClass example implements both methods to read and write the dots data. If you want things to be stored, e.g., your gradient, you will have to implement it there. E.g., it could look like this:

            Bool MyDataTypeClass::WriteData(const CustomDataType* t_d, HyperFile* hf)
            {
              // Cast the passed in data to your datatype.
              const MyDataType* const data = static_cast<const MyDataType*>(t_d);
            
              // Bail when #data is malformed, has no gradient. _gradient is a member of MyDataType and supposed
              // to be of type Gradient* just as in your case.
              if (!data || !data->_gradient)
                return false;
            
              // Wrap the dereferenced _gradient as a GeData instance.
              GeData geData;
              geData.SetCustomDataType(*data->_gradient);
            
              // Write your data into the hyper file and bail if it somehow fails.
              if (!hf->WriteGeData(geData))
                return false;
            
              // Write other data members of your datatype.
              if (!hf->WriteInt32(data->_someInt32))
                return false;
              if (!hf->WriteFloat(data->_someFloat))
                return false;
              if (!hf->WriteBool(data->_someBool))
                return false;
            
              return true;
            }
            

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

            1 Reply Last reply Reply Quote 0
            • First post
              Last post