Controlling tessellation of c4d.SplineObject in python



  • 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!



  • 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.



  • 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



  • 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?