繁体   English   中英

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

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

我有一个对象的比例F曲线,我需要将其插值设置为CUBIC

最简单,最快的方法是什么?

这是通往fcurves的漫长道路;但是,一旦到达那儿,它就会很快起作用。

从活动对象开始,您想转到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)

然后,每个曲线都是具有自己的插值设置的关键帧项目的列表。

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'

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