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

    class SplineHelp buggy? Doesn't work correctly with closed segmented splines

    Cinema 4D SDK
    r23 s22 r21 r20 python c++
    2
    3
    418
    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.
    • fwilleke80F
      fwilleke80
      last edited by fwilleke80

      Hello,

      I noticed the SplineHelp class doesn't work correctly with closed, segmented splines. Since I can reproduce the problem in R20 - R23, maybe I'm overlooking something.

      Let's take a spline containing two simple rectangles. Then use SplineHelp to sample positions along each segment.

      Code for a simple Python plugin tag that will sample the positions and print them out:

      class SplineSampleExample(c4d.plugins.TagData):
          def __init__(self):
              self.samplePositions = []
      
          def Execute(self, tag, doc, op, bt, priority, flags):
              if op.GetType() != c4d.Ospline:
                  return c4d.EXECUTIONRESULT_OK
      
              splineHelp = c4d.utils.SplineHelp()
              if not splineHelp.InitSpline(op):
                  return c4d.EXECUTIONRESULT_OK
      
              samplesPerSegment = 20
              self.samplePositions.clear()
              segmentCount = op.GetSegmentCount()
              realSegmentCount = segmentCount
              closed = op.IsClosed()
              if segmentCount == 0:
                  segmentCount = 1
              print("Object: %s" % op.GetName())
              print("Segment count: %s" % segmentCount)
              print("Closed: %s" % closed)
      
              for segmentIndex in range(segmentCount):
                  for sampleIndex in range(samplesPerSegment):
                      relativePositionOnSegment = float(sampleIndex) / (float(samplesPerSegment) - (0 if closed else 1))
                      samplePosition = splineHelp.GetPosition(relativePositionOnSegment, segmentIndex)
                      print(("\tSegment %i: Relative pos: %f; 3D pos: " % (segmentIndex, relativePositionOnSegment)) + str(samplePosition))
                      self.samplePositions.append(samplePosition)
      
              return c4d.EXECUTIONRESULT_OK
      

      The result is strange:
      splinehelp_1.jpg

      See the values from the last side of the 2nd segment? How could that ever return Z values > 0.0, when the whole segment is located in the -Z area?
      They seem to be going towards the first point of the first segment, instead of the first point of the actual segment.

      See where the samples go:
      splinehelp_2.jpg

      This problem is exactly the same in C++ and Python. It does always occur with closed splines that have more than 1 segment.

      How can I sample positions along a spline without getting nonsense positions?

      Cheers,
      Frank

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hi,

        this issue have been discussed on this topic.
        I've opened a bug entry but it's currently not fixed yet.

        Could you please try to set the first parameter smooth to false ? (true by default)

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • fwilleke80F
          fwilleke80
          last edited by fwilleke80

          Hi Manuel,

          thanks for the info! If smooth is set to false, the wrong positions disappear in deed. The distribution of the positions, however, is much uglier. It requires the user to change some specific attributes of the spline to make it look nice.

          But I think, that's ok for now.

          Thanks again & greetings,
          Frank

          www.frankwilleke.de
          Only asking personal code questions here.

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