簡體   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