简体   繁体   English

如何通过Python设置F曲线的插值? (搅拌机)

[英]How Can I Set the Interpolation of a F-Curve via Python? (Blender)

I have a Scale F-Curve of an Object and what I need Is to set its interpolation as CUBIC for example. 我有一个对象的比例F曲线,我需要将其插值设置为CUBIC

What is the simpliest and the fastest way to do it? 最简单,最快的方法是什么?

It's a long winding path to the fcurves ;), but once you get there it is quick to work with. 这是通往fcurves的漫长道路;但是,一旦到达那儿,它就会很快起作用。

Starting with the active object, you want to go to the fcurves 从活动对象开始,您想转到fcurves

fc = bpy.context.active_object.animation_data.action.fcurves

Other fcurves can be found in similar paths eg for material nodes it is 可以在类似路径中找到其他曲线,例如对于材质节点

fc = mat.node_tree.animation_data.action.fcurves

fcurves is a list of all curves, it is usually easiest to use find to get the curve you want (the index values 0,1,2 match x,y,z) unless you want to loop through and change them all. fcurves是所有曲线的列表,通常最简单的方法是使用find来获取所需的曲线(索引值0,1,2匹配x,y,z),除非您想循环遍历并更改它们。

loc_x_curve = fc.find('scale', index=0)

Then each curve is a list of keyframe items that have their own interpolation setting. 然后,每个曲线都是具有自己的插值设置的关键帧项目的列表。

for k in loc_x_curve.keyframe_points:
    # k.co[0] is the frame number
    # k.co[1] is the keyed value
    k.interpolation = 'CUBIC'
    k.easing = 'EASE_IN'

Try using SciPy, for example , the following would work: 尝试使用SciPy,例如,以下方法将起作用:

>>> from scipy.interpolate import interp1d
>>> x = np.linspace(0, 10, num=11, endpoint=True)
>>> y = np.cos(-x**2/9.0)
>>> f = interp1d(x, y)
>>> f2 = interp1d(x, y, kind='cubic')
>>> xnew = np.linspace(0, 10, num=41, endpoint=True)
>>> import matplotlib.pyplot as plt
>>> plt.plot(x, y, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--')
>>> plt.legend(['data', 'linear', 'cubic'], loc='best')
>>> plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM