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

    Controlling tessellation of c4d.SplineObject in python

    Cinema 4D SDK
    python classic api
    3
    5
    771
    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.
    • A
      android
      last edited by Manuel

      Hi! Does anyone know the proper technique for controlling the tessellation of a SplineObject in a python generator? I'm dynamically creating a spline of type c4d.SPLINETYPE_BSPLINE and when I drop it into the scene it is tessellating into a rather coarse polyline and I can't find the controls to smooth it out. I have tried creating a SplineHelp and using that to sample the spline at regular intervals, but it appears to only sample the same coarse tessellated spline, not the underlying bspline. I'm sure this is something simple that I'm overlooking! Many thanks!

      1 Reply Last reply Reply Quote 0
      • CairynC
        Cairyn
        last edited by

        Doesn't look coarse to me, neither as script nor as generator

        Generator:

        import c4d
        
        def main():
            obj = c4d.SplineObject(4, c4d.SPLINETYPE_BSPLINE)
            p1 = c4d.Vector(0.0, 0.0, 0.0)
            p2 = c4d.Vector(100.0, 0.0, 0.0)
            p3 = c4d.Vector(100.0, 100.0, 0.0)
            p4 = c4d.Vector(0.0, 100.0, 0.0)
            obj.SetAllPoints([p1, p2, p3, p4])
            obj[c4d.SPLINEOBJECT_INTERPOLATION] = 2 # here: uniform
            obj[c4d.SPLINEOBJECT_SUB] = 20 # number of subdiv points
            obj.Message (c4d.MSG_UPDATE)
            return obj
        

        Did you use enough points? set the interpolation and subdivision? There is not much room for settings here...

        Note that a Python generator cannot act as spline itself (see some other threads for that), even if it can contain a spline. There is currently no Python Spline Generator in C4D.

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by Manuel

          hi,

          i was kind of lost this morning (i was warming up) because in our python documentation there's no real page that let you understand that you have to use SPLINEOBJECT_SUB

          just to add something you can generate null along the spline. You can use UniformToNatural.

          import c4d
          
          def main():
              obj = c4d.SplineObject(4, c4d.SPLINETYPE_BSPLINE)
              p1 = c4d.Vector(0.0, 0.0, 0.0)
              p2 = c4d.Vector(100.0, 0.0, 0.0)
              p3 = c4d.Vector(100.0, 100.0, 0.0)
              p4 = c4d.Vector(0.0, 100.0, 0.0)
              obj.SetAllPoints([p1, p2, p3, p4])
              obj[c4d.SPLINEOBJECT_INTERPOLATION] = 2 # here: uniform
              obj[c4d.SPLINEOBJECT_SUB] = 20 # number of subdiv points
              obj.Message (c4d.MSG_UPDATE)
              parent = c4d.BaseObject(c4d.Onull)
              obj.InsertUnder(parent)
              
              # Creates null objects along the spline
              cnt = 50
              sld = c4d.utils.SplineLengthData()
              sld.Init(obj, 0)
              
              
              for i in range(cnt + 1):
                  null = c4d.BaseObject(c4d.Onull)
                  null[c4d.NULLOBJECT_DISPLAY] = 1
                  pos = obj.GetSplinePoint( sld.UniformToNatural(i / float(cnt)))
                  null.SetRelPos(pos)
                  null.InsertUnder(parent)    
              
              return parent
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • A
            android
            last edited by android

            Thanks guys! This is exactly what I was looking for. I couldn't find any reference to the interpolation and sub settings but this solved it! I am curious what you mean Cairyn about a python generator not being able to create a spline. I use python generators for this purpose all the time, so I'm not sure I follow. Anything specific I should watch out for in the future?

            CairynC 1 Reply Last reply Reply Quote 0
            • CairynC
              Cairyn @android
              last edited by

              @android Here's a thread for reference regarding the limitation of a Generator spline:
              https://developers.maxon.net/forum/topic/12596/is-it-possible-to-get-a-spline-wrap-object-to-use-a-python-generated-spline

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