Turn Bezier spline to linear spline

Dear c4d fellows,
I wonder, if there is a buit in method in SplinObject to turn Bezier spline into interpolating linear spline.
Of course, it is simple to code my own function doing exactly this, but may be it is already implemented by c4d creators.

Yaroslav.

Yes, you can simply set the Interpolation parameter to linear. See here

Hi @Yaroslav,

thank you for reaching out to us and thank you @mp5gosu for providing an answer.

However, and I might be mistaken here, I think this is not what @Yaroslav was asking for; feel free to correct me when I am wrong. Cinema's splines are all parametric, even the editable ones, so changing the interpolation type from SPLINEOBJECT_TYPE_BEZIER to SPLINEOBJECT_TYPE_LINEAR will give you something linear, but also a vastly different curve geometry (depending on the input).

To resample a spline in Python, you can use c4d.utils.SplineHelp, specifically SplineHelp.GetPosition(). Or you can use SplineHelp.GetLineObject() to get the underlying LineObject of a spline. In C++ you also have SplineObject::GetLineObject.

In case you are actually interested in changing the interpolation type of a spline object (and not resample it), then @mp5gosu did provide the correct answer for you.

Please also note that we require postings to be tagged with essential meta information regarding the OS, Cinema 4D version and programming environment for the question. You can read more about the tagging feature here.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

Oh well yes @ferdinand .I was assuming the simpliest way. 😉

@ferdinand

Dear Ferdinand, thank you for
the comprehensive answer!

(Dear mp5gosu, thank you for your comment too)

Dear Ferdinand, I develop plugin in c++ (using vs2019 and c4d r20) and this is precisely what I meant.
Instead of using beautiful and smooth bezier-curved type splines I want to substitute them with finely approximated linear splines (and I guess SplineObject::GetLineObject is precisely the function I need.) I wonder if there is some control on the number of linear segments approximating the spline. Hopefully, I can get it from the corresponding class declaration.

Yaroslav.

Ferdinand,
just tried

LineObject* spline_linear = spline->GetLineObject(document, precision);

Works like a charm. The closer float "precision" to one the better the approximation, as far as I understand.

One thing, that confuses me is that new object appear in c4d menus with little white"question mark" sign (see picture).
I don't undersytand why.

Here is my piece of code:

LineObject* spline_linear = spline->GetLineObject(document, 0.9);
document->InsertObject(spline_linear, NULL, NULL, 0); // Add it to the OM
spline_linear->Message(MSG_UPDATE);

q2.png

Oh, I see. Now I can extract all the points from this LineObject and construct a simple linear spline if I need one.
I guess cinema4d doesn't recognize the LineObject. Hence, question mark in menus.

Hi @Yaroslav,

yes, you are right, LineObject are not meant to be presented to the user directly, but are the underlying discrete geometry of a spline. In case you do not mind a little overhead, you can also use SendModelingCommand, specifically with MCOMMAND_CURRENTSTATETOOBJECT (link to example), to get "a linear version of the spline". The advantage here is that you do not have to worry so much about the details, but at the cost of a little bit of overhead.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

@ferdinand
Oh, thanks!
Quite a nice idea!