Convert Joints to Spline (Limited to only 2 with Bezier Handles)
bentraje last edited by bentraje
Is there a way to convert joints to spline (limited to only 2 with Bezier Handles). By default, the joint to spline default C4D command convert them point by point per joint.
My main problem is what values to plug in the
SetTangentmethod so that the spline will conform to the previous shape despite only having two positions.
Is there a way around this?
Here is an illustration of what I am after:
If you want the actual file you can check it here:
Here is my code so far:
import c4d from c4d import gui #Welcome to the world of Python def GetNextObject(op): if op==None: return None if op.GetDown(): return op.GetDown() return op.GetDown() def IterateHierarchy(op): if op is None: return count = 0 objList =  while op: count += 1 objList.append(op) op = GetNextObject(op) return objList def createSpline(numPoints, pointPosition): spline = c4d.BaseObject(c4d.Ospline) spline.ResizeObject(numPoints) for point in range(numPoints): spline.SetPoint(point, pointPosition[point]) spline[c4d.SPLINEOBJECT_CLOSED] = False spline.Message(c4d.MSG_POINTS_CHANGED) doc.InsertObject(spline) c4d.EventAdd() objList = IterateHierarchy(op) objLen = len(objList) objListPosition =  for obj in objList: objListPosition.append(obj.GetMg().off) createSpline(objLen, objListPosition)
Thanks to the C4D documentation for the iterate codes and the Scott Ayers to the Create Spline code
r_gigante last edited by r_gigante
Hi Bentraje, thanks for reaching out us.
With regard to your request, there's no immediate and correct answer here since it's more an algorithm related question that a real API one.
If more than 2CV-based curve is allowed Cinema provides the FitCurve function which, given a certain threshold value and a set of points, returns an interpolating spline and also
MCOMMAND_SPLINE_SOFTINTERPOLATIONwhich, as written in docs, just return a soft-interpolation of a curve passing through points (auto-smooth tangents).
With regard to setting the tangents at the start and end points, it's pretty correct to state that the direction is the one defined by the first and the end joints but the magnitude of these tangents can be arbitrary and based on the actual shape of the curve you want to approximate.
Finally if a 2CV-only Bezier curve is allowed, I think that it might not suffice to represent an arbitrary curve in the space or to properly interpolate a set of points in space.
For this reason I warmly recommend to search for interpolate point bezier and see for the results brought out. I'm sure there will be plenty of stuff from which get inspired.
bentraje last edited by
Thanks for the response.
With regard to 2CV-only Bezier curve: Yes, I only need 2 CV maximum. I understand that it will not interpolate complicated shapes properly but as you can see in my example, it's only a simple shape.
Looking at it now. I have a feeling I am biting more than I can chew. I'm not sure I can solve it at the moment given my current knowledge.
Will just perform it manually at the moment.
Anyhow, thanks for responding.
Have a great day ahead!