3

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!

Andrey Sokolov
  • 1,111
  • 10
  • 25

1 Answers1

5

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]}")

batFINGER
  • 84,216
  • 10
  • 108
  • 233