3
$\begingroup$

Is there any way to find out via Python at which point of the Timeline (at which subframe) fcurve reaches a certain value, without actually changing the current subframe? I have found out that it was possible to get certain keyframe_points coordinates on the timeline, but is there any way to analyze the whole fcurve somehow?

Thanks in advance!

$\endgroup$

1 Answer 1

5
$\begingroup$

Using FCurve.evaluate(frame) and numpy

In this related answer have found the minimum of an fcurve based on 0.01 subframe increments, instead here will find the first point where the fcurve is greater than a given value.

Test script, loops over all actions and prints the frame (and value) where it first exceeds value.

import bpy
import numpy as np

value = 10

frames = np.arange(1, 250, 0.01)

for action in bpy.data.actions:
    print(f"{action.name}")
    
    for fc in action.fcurves:
        print(f"{fc.data_path}[{fc.array_index}]")
        points = np.vectorize(fc.evaluate)(frames)

        hit = np.where(points > value)[0]
        if hit.size:
            f = hit[0]

            print(f"{frames[f]} : value {points[f]}")
$\endgroup$
1
  • 1
    $\begingroup$ Thank you! FCurve.evaluate(frame) is exactly what I was looking for! $\endgroup$ Commented Aug 8, 2020 at 19:26

You must log in to answer this question.

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