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:
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:
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