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

    SplineData GetParameter Helper

    SDK Help
    0
    8
    620
    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.
    • H
      Helper
      last edited by

      On 07/03/2014 at 04:59, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   15 
      Platform:      Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      I'm creating some helper methods for the C4DAtom::GetParameter method, since using it as is, is a bit verbose. Here's a example of my helper for a Float.

      Bool GetParameter(GeListNode* node, const Int32 id, Float& value) {
          GeData d;
          if(node->GetParameter(id, d, DESCFLAGS_GET_0)) {
              value = d.GetFloat();
              return true;
          }
          return false;
      }
        
      //Usage:
      Float offset;
      if(!GetParameter(op, TEST_EFFECTOR_OFFSET, offset)) return;
      

      This works and sets the offset correctly as a Float set by the user in the GUI.

      But when I try to do the same thing to a custom data type, in this case SplineData, the data disappears when out of the helper function's scope. Here's the code:

      Bool GetParameter(GeListNode* node, const Int32 id, SplineData *&splineData) {
          GeData d(CUSTOMDATATYPE_SPLINE, DEFAULTVALUE);
          if(node->GetParameter(id, d, DESCFLAGS_GET_0)) {
              splineData = (SplineData* )d.GetCustomDataType(CUSTOMDATATYPE_SPLINE);
              cout << splineData->GetKnotCount() << endl; **// outputs 4, correct**
              return true;
          }
          return false;
      }
        
      //Usage:
      SplineData* splineData;
      if(!GetParameter(op, TEST_EFFECTOR_SPLINE, splineData)) return;
      if(splineData) cout << splineData->GetKnotCount() << endl; **// outputs 0, incorrect**
      

      I can't figure out how to get the correct SplineData out of the helper function. Any help on this would be great as I'm relatively new to c++.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 08/03/2014 at 07:42, xxxxxxxx wrote:

        You need to copy the SplineData with SplineData::CopyTo() and remove the address-of operator from the splineData parameter.

        Just declare the GeData variable as you've done in the Float example.

        Remember to either use AutoAlloc<SplineData> or free it with SplineData::Free().

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 08/03/2014 at 12:06, xxxxxxxx wrote:

          That was it. Thanks DavidW!

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 08/03/2014 at 12:27, xxxxxxxx wrote:

            Could you please post your working version fusepilot?

            -ScottA

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 08/03/2014 at 15:51, xxxxxxxx wrote:

              Yep,

              Bool GetParameter(GeListNode* node, const Int32 id, SplineData *splineData) {
                  GeData d;
                  if(node->GetParameter(id, d, DESCFLAGS_GET_0)) {
                      SplineData *sd;
                      sd = (SplineData* )d.GetCustomDataType(CUSTOMDATATYPE_SPLINE);
                      sd->CopyTo(splineData);
                      return true;
                  }
                  return false;
              }
                
              //Usage:
              AutoAlloc<SplineData> splineData;
              if(!GetParameter(op, TEST_EFFECTOR_SPLINE, splineData)) return;
              
              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 08/03/2014 at 16:24, xxxxxxxx wrote:

                Thanks.

                -ScottA

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 25/03/2014 at 09:20, xxxxxxxx wrote:

                  I hate to bring this up again. But in the process of making these functions work for R13, I've noticed that version of the SDK does not contain a SplineData::CopyTo. And all the solutions I've found about C++ deep copying suggest creating something like, well the CopyTo function. Which I don't think I can do.

                  So how were you suppose to do this prior to R14 when SplineData::CopyTo was introduced? Or how can I create my own SplineData::CopyTo helper function?

                  Thanks.

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 26/03/2014 at 18:03, xxxxxxxx wrote:

                    I figured out a solution. Just copy all of the CustomSplineKnots over.

                    void CopySplineDataTo(SplineData* src, SplineData *dst) {
                        vector<CustomSplineKnot*> knots;
                        
                        for (LONG i = 0; i < src->GetKnotCount(); i++) {
                            knots.push_back(src->GetKnot(i));
                        }
                        
                        LONG num_knots = knots.size();
                        
                        dst->DeleteAllPoints();
                        dst->MakePointBuffer(num_knots);
                        
                        for (LONG k = 0; k < num_knots; k++) {
                            CustomSplineKnot* knot = knots[k];
                            
                            dst->InsertKnot(knot->vPos.x, knot->vPos.y);
                            CustomSplineKnot* new_knot = dst->GetKnot(k);
                            CopyMem(knot, new_knot, sizeof(CustomSplineKnot));
                        }
                    }
                      
                      
                    Bool Get(GeListNode *node, const LONG id, SplineData *spline_data) {
                        GeData d;
                        if(node->GetParameter(id, d, DESCFLAGS_GET_0)) {
                            SplineData *sd;
                            sd = (SplineData* )d.GetCustomDataType(CUSTOMDATATYPE_SPLINE);
                    #if API_VERSION >= 14000
                            sd->CopyTo(spline_data);
                    #else
                            CopySplineDataTo(sd, spline_data);
                    #endif
                            return true;
                        }
                        return false;
                    }
                    
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post