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

时间:2016-05-22 20:15:17

标签: python math interpolation blender

我有一个物体的比例F曲线,我需要的是将其插值设置为 CUBIC ,例如。

最简单,最快捷的方式是什么?

2 个答案:

答案 0 :(得分:1)

这是通向曲折的漫长道路;),但是一旦到达那里,就可以很快地使用它。

从活动对象开始,您想要转到fcurves

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

其他的曲线可以在类似的路径中找到,例如对于物质节点来说是

fc = mat.node_tree.animation_data.action.fcurves

fcurves是所有曲线的列表,通常最简单的方法是使用find来获得所需的曲线(索引值0,1,2匹配x,y,z),除非你想循环并改变它们。

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

然后每条曲线都是keyframe个项目列表,这些项目都有自己的插值设置。

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'

答案 1 :(得分:0)

尝试使用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()