8
$\begingroup$

I am trying to visualise some physics simulations in Blender. The simulation result is a path that an object travels over time. I am importing the collection of points as a curve into Blender using a python script. I then use a "follow path" constraint on the object and set the curve as the target.

So far so good. However, the motion of the object is not as I expected. Blender seems to interpolate the motion along the distance of the path. The spatial co-ordinates are correct, but the time doesn't match.

For example, assume that the points are (in 2D for simplicity): (0,0) (1,1) (4,4)

And I want to run the animation for 20 frames. I expect the object to be at (1,1) on frame #10.

However, what Blender does is, it takes the length of the total path and then interpolates. Since the last point (4,4) is much farther away, on frame #10 the object is not at (1,1) but somewhere between (1,1) and (4,4).

My workaround was to write a script instead of using the "follow path" constraint. The script inserts keyframes at each position in the simulation at the corresponding frame numbers. In the example above, key frames will be inserted at frames 0, 10 and 20.

The script is hacky and slow. My question is, can this be done in a better way? I suspect this will be very useful to many people who try to visualise data.

$\endgroup$
4
  • $\begingroup$ Could you please post your script? $\endgroup$ Oct 28, 2013 at 7:37
  • $\begingroup$ @OcasoProtal You can follow the link to the gist. Thanks for looking. $\endgroup$
    – HRJ
    Oct 28, 2013 at 10:01
  • $\begingroup$ Ahh, sorry, I didn't see the link. $\endgroup$ Oct 28, 2013 at 10:17
  • $\begingroup$ One issue with that script is that the object would not follow the path, but rather go in straight lines from control point to control point. $\endgroup$
    – Garrett
    Feb 3, 2014 at 1:29

1 Answer 1

1
$\begingroup$

Manual solution

You could achieve this manually. Start by giving the object a Follow Path constraint and setting the target to be your curve.

In this example, we have 3 control points (of a Bezier curve) and 20 frames.

Go to frame 1, and keyframe Evaluation Time to 0. Also make sure to set Frames to 20. (these settings are found in the Object Data tab of the curve).

enter image description here

Now, go to frame 10 and slide the Evaluation Time until it appears that the object is at the same location as your second control point and keyframe it. (being in Edit Mode allows you to see the control points)

enter image description here

Finally, repeat the above process to ensure that object will be at the third control point at frame 20.

Python Solution

If you have too many control points to go through by hand, then scripting this would be possible too.

The script could start off by calculating the lengths of each segment of curve. You'd have to numerically integrate the formula for the cubic Bezier curve (numerical integration because it can't be solved analytically). If you could successfully install SciPy into Blender, you could use their integration functions, otherwise you could write your own script using Gaussian quadrature or any other numerical integration algorithm).

Once you have the lengths, the user could input a list whose n-th entry specifies at what frame the object should reach the n-th control point. Set the Frames property of Path Animation to the last frame in the list. For each entry in list, set the Evaluation Time to be the sum of lengths of segments up to that control point divded by the total length multiplied by the last frame.

$\endgroup$
1
  • $\begingroup$ Thanks for the thorough answer. In my case, it was fine to have straight line interpolation between the points. $\endgroup$
    – HRJ
    Feb 3, 2014 at 4:48

You must log in to answer this question.

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