@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 your SplineObject
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,
Ferdinand

import 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()