0
$\begingroup$

I have $C_i$, a set of vertices in 3D space that form a curve for $i = 1,...,N-1$.

Is there a way that I can animate the curves using Blender via a Python script such that the animation shows how $C_i$ transforms into $C_{i+1}$ for all i?

To be more precise, consider the following example where a curve is defined by 5 vertices in 3D space

Curve 1: [(0,0,-1), (0,0,-0.5), (0,0,0), (0,0,0.5), (0,0,1)]

Curve 2: [(0,0,-1), (0.1,0.1,-0.5), (0.2,0.2,0), (0.1,0.1,0.5), (0,0,1)]

Curve 3: [(0.1,0.1,-1), (0.2,0.2,-0.5), (0.3,0.3,0), (0.2,0.2,0.5), (0.1,0.1,1)]

Is there a way to transform Curve 1 to Curve 2 and Curve 2 to Curve 3 and insert keyframes at each step? Ideally, I would like the rendered animation to show curve 1 at frame 1, curve 2 at frame 2, curve 3 at frame 3. Is it possible that I do this in Blender through the use of Python?

Note that I am using a polycurve.

Thank you very much!

$\endgroup$
0

1 Answer 1

0
$\begingroup$
import bpy

frame_distance = 5

data = [
    [(0,0,-1), (0,0,-0.5), (0,0,0), (0,0,0.5), (0,0,1)],
    [(0,0,-1), (0.1,0.1,-0.5), (0.2,0.2,0), (0.1,0.1,0.5), (0,0,1)],
    [(0.1,0.1,-1), (0.2,0.2,-0.5), (0.3,0.3,0), (0.2,0.2,0.5), (0.1,0.1,1)],
]

vert_len = len(data[0])

for e in bpy.data.objects:
    bpy.data.objects.remove(e)

bpy.ops.curve.primitive_bezier_curve_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

splines = bpy.context.object.data.splines
splines.remove(splines[0])
spline = splines.new("POLY")

pts = spline.points
pts.add(vert_len - 1)

frame = 1

for data_points in data:
    for pt, d in zip(pts, data_points):
        pt.co[:3] = d
        pt.keyframe_insert("co", frame = frame)

    frame += frame_distance
$\endgroup$
3
  • $\begingroup$ Hi, thanks for your help! However I could not execute the code properly due to the following error: AttributeError: Calling operator "bpy.ops.curve.simple" error, could not be found. I am using blender 3.3, how could I fix the problem? $\endgroup$
    – Jerry Zhen
    Oct 9, 2022 at 19:53
  • $\begingroup$ it should work with the new $\endgroup$
    – X Y
    Oct 10, 2022 at 1:05
  • $\begingroup$ It worked! Thank you very much for the help! Really appreciated! $\endgroup$
    – Jerry Zhen
    Oct 10, 2022 at 1:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .