Retrieving Deformed Splines
-
Hello,
I'm trying to get access to the result of a spline that has been deformed by a Bend. I've attached a scene file with a cloner mimicking the behavior I want to achieve, but I haven't been able to do it yet.
Using GetCache().GetDeformCache() isn't returning just the four points of the circle and I'm not sure another way to get a deformed spline. This seems like it would be rather simple but I'm not sure where to proceed.
Johan
-
Hi Johan, thanks for reaching out us.
With regard to your request, I warmly suggest to have a look at:
- c4d.utils.SplineHelp
- SplineHelp.SplineToLineIndex() to find a correspondence between spline points and their sibling in the cache representation
- BaseObject.GetCache() to see how to properly retrieve a geometry cache
- BaseObject.GetRealSpline() to retrieve a real spline from a spline generator
A first attempt to make it work should look like this:
import c4d def DoRecursion(op, index): tp = op.GetDeformCache() if tp is not None: DoRecursion(tp, index) else: tp = op.GetCache() if tp is not None: DoRecursion(tp, index) else: if not op.GetBit(c4d.BIT_CONTROLOBJECT): if op.IsInstanceOf(c4d.Opoint): for i in index: print "\t\t", op.GetAllPoints()[i] tp = op.GetDown() while tp is not None: DoRecursion(tp, index) tp = tp.GetNext() # Main function def main(): # get the real spline representation realSpline = op.GetRealSpline() if realSpline is None: return # allocate a SplineHelp instance and init it with the real spline splineH = c4d.utils.SplineHelp() splineH.InitSplineWith(realSpline) # get the spline points and store its length splinePnts = realSpline.GetAllPoints() splinePntsCnt = len(splinePnts) # allocate a list to store the correspondance between the spline points and the one belonging to its line representation pntIndxInLine = [] for i in xrange(splinePntsCnt): pntIndxInLine.append(splineH.GetPointIndex(i, 0)/splinePntsCnt) # recurse over the geometry to look for its cache DoRecursion(op, pntIndxInLine) # free the SplineHelp instance splineH.FreeSpline() # Execute main() if __name__=='__main__': main()
Best, Riccardo
- c4d.utils.SplineHelp
-
Thanks for the reply, it really helped me out.
John