Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Turn Bezier spline to linear spline

    Cinema 4D SDK
    3
    8
    1.8k
    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.
    • Y
      Yaroslav
      last edited by

      Dear c4d fellows,
      I wonder, if there is a buit in method in SplinObject to turn Bezier spline into interpolating linear spline.
      Of course, it is simple to code my own function doing exactly this, but may be it is already implemented by c4d creators.

      Yaroslav.

      1 Reply Last reply Reply Quote 0
      • M
        mp5gosu
        last edited by

        Yes, you can simply set the Interpolation parameter to linear. See here

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

          Hi @Yaroslav,

          thank you for reaching out to us and thank you @mp5gosu for providing an answer.

          However, and I might be mistaken here, I think this is not what @Yaroslav was asking for; feel free to correct me when I am wrong. Cinema's splines are all parametric, even the editable ones, so changing the interpolation type from SPLINEOBJECT_TYPE_BEZIER to SPLINEOBJECT_TYPE_LINEAR will give you something linear, but also a vastly different curve geometry (depending on the input).

          To resample a spline in Python, you can use c4d.utils.SplineHelp, specifically SplineHelp.GetPosition(). Or you can use SplineHelp.GetLineObject() to get the underlying LineObject of a spline. In C++ you also have SplineObject::GetLineObject.

          In case you are actually interested in changing the interpolation type of a spline object (and not resample it), then @mp5gosu did provide the correct answer for you.

          Please also note that we require postings to be tagged with essential meta information regarding the OS, Cinema 4D version and programming environment for the question. You can read more about the tagging feature here.

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          Y 2 Replies Last reply Reply Quote 1
          • M
            mp5gosu
            last edited by mp5gosu

            Oh well yes @ferdinand .I was assuming the simpliest way. 😉

            1 Reply Last reply Reply Quote 0
            • Y
              Yaroslav @ferdinand
              last edited by

              @ferdinand

              Dear Ferdinand, thank you for
              the comprehensive answer!

              (Dear mp5gosu, thank you for your comment too)

              Dear Ferdinand, I develop plugin in c++ (using vs2019 and c4d r20) and this is precisely what I meant.
              Instead of using beautiful and smooth bezier-curved type splines I want to substitute them with finely approximated linear splines (and I guess SplineObject::GetLineObject is precisely the function I need.) I wonder if there is some control on the number of linear segments approximating the spline. Hopefully, I can get it from the corresponding class declaration.

              Yaroslav.

              1 Reply Last reply Reply Quote 0
              • Y
                Yaroslav @ferdinand
                last edited by Yaroslav

                Ferdinand,
                just tried

                LineObject* spline_linear = spline->GetLineObject(document, precision);
                

                Works like a charm. The closer float "precision" to one the better the approximation, as far as I understand.

                One thing, that confuses me is that new object appear in c4d menus with little white"question mark" sign (see picture).
                I don't undersytand why.

                Here is my piece of code:

                LineObject* spline_linear = spline->GetLineObject(document, 0.9);
                document->InsertObject(spline_linear, NULL, NULL, 0); // Add it to the OM
                spline_linear->Message(MSG_UPDATE);
                

                q2.png

                Oh, I see. Now I can extract all the points from this LineObject and construct a simple linear spline if I need one.
                I guess cinema4d doesn't recognize the LineObject. Hence, question mark in menus.

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

                  Hi @Yaroslav,

                  yes, you are right, LineObject are not meant to be presented to the user directly, but are the underlying discrete geometry of a spline. In case you do not mind a little overhead, you can also use SendModelingCommand, specifically with MCOMMAND_CURRENTSTATETOOBJECT (link to example), to get "a linear version of the spline". The advantage here is that you do not have to worry so much about the details, but at the cost of a little bit of overhead.

                  Cheers,
                  Ferdinand

                  MAXON SDK Specialist
                  developers.maxon.net

                  Y 1 Reply Last reply Reply Quote 0
                  • Y
                    Yaroslav @ferdinand
                    last edited by

                    @ferdinand
                    Oh, thanks!
                    Quite a nice idea!

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