Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Retrieving Deformed Splines

    Cinema 4D SDK
    c++ r20 sdk
    2
    3
    590
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JohnThomas
      last edited by

      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.

      Deformed Circle.c4d

      Johan

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        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

        1 Reply Last reply Reply Quote 1
        • J
          JohnThomas
          last edited by

          Thanks for the reply, it really helped me out.

          John

          1 Reply Last reply Reply Quote 0
          • First post
            Last post