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

    How to get spline offset by spline point index ?

    Cinema 4D SDK
    python
    7
    13
    2.7k
    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.
    • M
      mike
      last edited by

      hi,
      How to get spline offset(0-1) by spline point index ? i want know offset between points to caculate the value points should be.
      hope for your help!

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi Mike, thanks for writing us.

        With regard to your question, if I properly understood you, you can use the SplineHelp Class and its SplineHelp::GetPosition() method to retrieve the spline's points value given a certain offset.

        Something like this:

        import c4d
        
        # Main function
        def main():
            if op is None:
                return
            
            realSpline = op.GetRealSpline()
            if realSpline is None:
                return
            
            splineH = c4d.utils.SplineHelp()
            if splineH is None:
                return
            
            splineH.InitSpline(realSpline)
            
            samples = 10
            for sample in range(0, samples):
                offset = float(sample) / samples
                print splineH.GetPosition(offset)
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        Best, Riccardo

        M 1 Reply Last reply Reply Quote 1
        • eZioPanE
          eZioPan
          last edited by

          Hi @r_gigante,
          Thank you for replying. I'd like to know more about this topic: if I only know the Control Point Index from PointObject.GetPoint(id) of a spline, how could I get the Spline Position of this point?

          S 1 Reply Last reply Reply Quote 0
          • M
            mike @r_gigante
            last edited by

            @r_gigante Thank you for your help! i have another problem that if i only know the spline point index ,how do i get the offset where point locate? just take sample like 1000 and find the nearest sample to the point position?or have faster way in SDK?

            S 1 Reply Last reply Reply Quote 0
            • S
              s_bach @eZioPan
              last edited by

              @eziopan For new questions please open a new thread. Thanks.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • S
                s_bach @mike
                last edited by

                @mike What do you mean with "how do i get the offset where point locate?"

                You want the offset for a point with a given index? The C++ version of SplineHelp has the function GetSplinePointSegment() which can be used to get the offset for a given index. Unfortunately, this function is not available in the Python API.

                best wishes,
                Sebastian

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                M eZioPanE 2 Replies Last reply Reply Quote 1
                • M
                  mike @s_bach
                  last edited by

                  @s_bach Thank you for your patient answer.

                  1 Reply Last reply Reply Quote 0
                  • eZioPanE
                    eZioPan @s_bach
                    last edited by

                    @s_bach thank you for your answer! I think I have the same question as mike do, so it has been solved now. Thank you again!

                    1 Reply Last reply Reply Quote 0
                    • indexofrefractionI
                      indexofrefraction
                      last edited by indexofrefraction

                      Hi,

                      Sorry to resurrect this old thread ...
                      As mentioned above GetSplinePointSegment() is not available in python
                      Is there no way at all to get to the (real)offset of a spline point with a given index ?

                      spline --> point index --> offset? (in python)

                      index 🙂

                      1 Reply Last reply Reply Quote 0
                      • indexofrefractionI
                        indexofrefraction
                        last edited by indexofrefraction

                        nothing? ...

                        the only thing i can imagine is to sample the spline using splineHelp.GetPointIndex(), that would get you an initial offset range.
                        then you could start inserting points at certain offsets and refine the sampling down until a given offset range treshold is reached.
                        but thats quite complicated and slow as well, of course

                        maybe somebody with a better idea how to approach this?

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

                          Hi nothing changed, in this regards, however I added GetSplinePointSegment on our internal Python parity list 🙂
                          But even when it will be available this will not be backported.

                          Cheers,
                          Maxime.

                          MAXON SDK Specialist

                          Development Blog, MAXON Registered Developer

                          1 Reply Last reply Reply Quote 0
                          • indexofrefractionI
                            indexofrefraction
                            last edited by

                            Thanks Maxime,
                            so GetPointIndex() is the only thing you can work with, I guess.
                            Already on it to create this sampling function ...
                            🙂

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

                              Hi @everyone,

                              as a little disclaimer, this is my private take on this topic.

                              Cinema does calculate the length of a spline (at least with SplineHelp) in a rather unpretentious fashion as the sum of the Euclidean norms of the underlying LineObject segments, i.e., there is no fancy arc-length calculation going on. Which makes sense in Cinema, since the discrete LineObject is what does effectively count, and not the smooth SplineObject. Since you can get access to the LineObject of a SplineObject and also convert between SplineObject and LineObject vertex indices with SplineHelp.SplineToLineIndex() , this also means that you can both calculate the length of spline as a total and up to a specific vertex. Which then should mean that you can calculate the relative offset for a spline vertex yourself.

                              Practically you can cut out the SplineObject altogether when sampling a spline and just use its associated LineObject. The one nice thing that SplineHelp does for you is though, that it implements a parallel transport for the frames of spline points for you. I.e., realizes that the normals of spline points point into a direction humans would consider "correct" (mathematically these normals are not correct, due to them being modified by parallel transport, but they will look smoother, won't flip when then curvature of the spline flips).

                              Cheers,
                              Ferdinand

                              MAXON SDK Specialist
                              developers.maxon.net

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