從Blender裡萃取模組資料(7)
前言
續前篇從Blender裡萃取模組資料(6),這次說明動畫的資料如何萃取,在此做個紀錄。內容
在開始前,先看看下圖![]() |
| Blender的動畫資料 |
![]() |
| Blender的動畫內容資料 |
接著就來萃取動畫的資料,範例如下
import bpy
def ShowActionInfo(act):
print('animation name',act.name)
for curve in act.fcurves:
print('Data path:',curve.data_path,' ',end='')
print('Array index:',curve.array_index,' ',end='')
print('')
for keyFrame in curve.keyframe_points:
print('Key time:',keyFrame.co[0],' ',end='')
print('Key value:',keyFrame.co[1],' ',end='')
print('')
#
def ShowAnimationInfo(obj):
if obj.animation_data == None:
print("No animation data in object!")
return
#Check actived action...
actionCon = 0
if obj.animation_data.action != None:
ShowActionInfo(obj.animation_data.action)
actionCon+=1
#Check action in NLA tracks...
for track in obj.animation_data.nla_tracks:
for strip in track.strips:
ShowActionInfo(strip.action)
actionCon +=1
print("Animation amount:",actionCon )
#
tagObj = bpy.data.objects['Cube']
ShowAnimationInfo(tagObj )
在ShowAnimationInfo()的部分,只要是在辨識動畫的數量,要注意一點的是啟用中的動畫可能會是None,在編輯器編輯時是可以將它調成空的,ShowActionInfo()的部分,有"Data path"與"Array index"兩個資料,"Data path"可能會是"location"、"rotation_euler"或"scale"...等,"Array index"則是個數值,假設得到的結果為"location"與"1",也就是location[1],進一步說就是location.y,請依此類推,"Key time"舊式下方時間條的數值,"Key value"就是數值。
參考資料
Blender Documentation Contents相關文章
從Blender裡萃取模組資料(6)從Blender裡萃取模組資料(8)


沒有留言:
張貼留言