1
$\begingroup$

I'm trying to distribute objects along a curve as an add-on in a modal operator like in this link. I did it for a line an it works ok. The problem comes when I want to evaluate a curve with different segments in an uniform way. This is the piece of code that I did:

def calculate_all_points(self, spline):  

    if len(spline.bezier_points) >= 2:
        #r = spline.resolution_u + 1
        r = 50
        segments = len(spline.bezier_points)
        if not spline.use_cyclic_u:
            segments -= 1
        points = []
        for i in range(segments):

            inext = (i + 1) % len(spline.bezier_points)
            knot1 = spline.bezier_points[i].co
            handle1 = spline.bezier_points[i].handle_right
            handle2 = spline.bezier_points[inext].handle_left
            knot2 = spline.bezier_points[inext].co
            _points = mathutils.geometry.interpolate_bezier(knot1, handle1, handle2, knot2, r)
            points.extend(_points)
    return points
curve = bpy.context.object
objects = bpy.data.objects
curve_points = self.calculate_all_points(active_spline)
N = len(objects)-1
percent = 1/N

for i, obj in enumerate(objects):
   step = i * percent
   index = round(step * (len(curve_points)-1))
   new_loc = curve_points[index]
   obj.location = new_loc

Can someone help me? Thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.