How to receive the high definition / Interpolation version of a spline?
-
How to receive the high definition version / Interpolation of a spline even when the user has set it to "low" detail?
How high definition can I get ? is there more than the user Interface of C4D offers ?E.g. Interpolation adaptive, angle 0.0
Or am I using c4d.utils.SplineHelp() wrong and there is a another helper that gives me requested amount of points from a spline?
helper = c4d.utils.SplineHelp() if not helper.InitSplineWith(spline, c4d.SPLINEHELPFLAGS_RETAINLINEOBJECT): raise RuntimeError("Could not initialize spline helper.") line = helper.GetLineObject() points = line.GetAllPoints()
cheers
mogh -
Hey @mogh,
Thank you for reaching out to us. What do you mean with "low" detail? Something like the sampling angle of a spline in "adaptive" mode? The interpolation settings of a spline only apply when you quantize it, i.e., the degree of precision with which a
SplineObject
is being quantized into itsLineObject
cache (i.e., what is returned forBaseObject.GetCache()
for a spline).Splines themselves are just series of polynomials and therefore have no inherent precision. So, when you call for example
SplineHelp.GetMatrix()
to get all the metadata for an offset, you are not subject to the interpolation settings. That is within the limits of what computers can do regarding arithmetic of irrational numbers. You can quite quickly get subject to floating point precision problems when working with splines. If they are fixable and how to fix them, depends on the concrete case.Cheers,
Ferdinand -
Ok I guess I have been vague what my issue is.
from the above helper I only get the points the spline is set to (eg. adaptive 5°) but I perhaps want more points in between. That of course only makes sense in certain scenarios but even though if the spline is a straight line there must be a solution to get points in between.
Example different adaptive degree values and the resulting points displayed as lines on the spline - Spline is a copy so no altering of the gizmos.
sorry to be so basic
mogh -
@mogh said in How to receive the high definition / Interpolation version of a spline?:
from the above helper I only get the points the spline is set to (eg. adaptive 5°) but I perhaps want more points in between.
That is not correct. As I said, splines have theoretically infinite precision, you are only bound in practice by the floating point precision you use for your computations - double, i.e., 64 bit in Cinema 4D. You get in your code just the cache of your spline and iterate over its points. That is more or less the same as if you would have just called
BaseObject.GetCache()
on yourSplineObject
which I mentioned above.When you want to interpolate your spline manually, you must use the interpolation methods of
SplineHelp
, e.g.,GetMatrix
, which is sort of the most potent of all, as it gives you a full frame for each sample (i.e., not just a point but also an orientation).I have a hunch that the actual question is how to build the cache of a spline as if it would have higher interpolation settings. And for that you should copy your input (unless it is already a dangling, i.e., non-inserted node), change its settings, insert it into a dummy document, and then call
ExecutePasses
on that document. Then you can get the cache, and iterate over its points.Cheers,
Ferdinandimport c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: """Called by Cinema 4D when the script is being executed. """ if not op: return helper = c4d.utils.SplineHelp() if not helper.InitSplineWith(op, c4d.SPLINEHELPFLAGS_RETAINLINEOBJECT): raise RuntimeError("Could not initialize spline helper.") # Take exactly ten samples over the length of the spline, no matter how many vertices it has, # and how many points its current LineObject cache has. steps: int = 10 for i in range(steps + 1): # Get a frame for the offset #t. t: float = i/float(steps) m: c4d.Matrix = helper.GetMatrix(t) # Print the #t, the point #p on the spline, its normal #n, tangent #t, and bi-tangent #bt. print(f"{t = }, p = {m.off}, n = {m.v3}, t = {m.v1}, bt = {m.v2}") if __name__ == '__main__': main()