如何通过Python设置函数曲线的插值? (搅拌机)
How Can I Set the Interpolation of a F-Curve via Python? (Blender)
我有一个对象的比例函数曲线,我需要的是将其插值设置为 CUBIC 例如。
最简单最快的方法是什么?
尝试使用 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()
通往 f 曲线的道路很长;),但是一旦到达那里,它就可以很快使用。
从活动对象开始,您想转到fcurves
fc = bpy.context.active_object.animation_data.action.fcurves
其他函数曲线可以在类似的路径中找到,例如 material 个节点是
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'
我有一个对象的比例函数曲线,我需要的是将其插值设置为 CUBIC 例如。
最简单最快的方法是什么?
尝试使用 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()
通往 f 曲线的道路很长;),但是一旦到达那里,它就可以很快使用。
从活动对象开始,您想转到fcurves
fc = bpy.context.active_object.animation_data.action.fcurves
其他函数曲线可以在类似的路径中找到,例如 material 个节点是
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'