class SplineHelp buggy? Doesn't work correctly with closed segmented splines
-
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 -
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 -
Hi Manuel,
thanks for the info! If
smooth
is set tofalse
, 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