微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Blender 2.9 + Python 脚本 – 需要帮助将多个动作剪辑/动作条添加到 NLA 轨道

如何解决Blender 2.9 + Python 脚本 – 需要帮助将多个动作剪辑/动作条添加到 NLA 轨道

如何使用 Python 脚本将多个动作剪辑添加到 Blender 2.9 中的单个 NLA 轨道?

我正在尝试遍历包含以下行的文件

frame_number=X,object_name=Y,animation=Z

例如

frame_number=1235,object_name=31,animation=action_off

我想遍历这些行并执行以下操作:

  1. object_name 处选择 frame_number
  2. 选择 PianoKeyAnimations NLATrack。
  3. 如果 action_on 添加 KeyPress 动画。如果 action_off 添加 keyrelease 动画。
  4. 取消选择场景集合中的 PianoKeyAnimation NLATrack、KeyPress / keyrelease 动画和 object_name

我设置的 NLA 动作片段/片段是:

- KeyPress: Duration of 1 frame
- keyrelease: Duration 1 frame

这是我正在努力处理的脚本部分:

# Select Nlatrack based on name
def nlaselect(trackName):
    ob = C.object
    ad = ob.animation_data
    if ad:
        for i,track in enumerate(ad.nla_tracks):
            # Find NLA track 
            track.select = track.name.startswith(trackName)
            # make active track if in pos 0
            if track.select and not i:
                ad.nla_tracks.active = track

all_tracks = {DATA_HERE}

current_area = bpy.context.area.ui_type
bpy.context.area.ui_type = 'NLA_EDITOR'
current_frame = 0
frames_delay = 240 # Delay animation by 4 seconds in 60 fps render

for row in all_tracks:

    current_frame += row.frame_number

    C.view_layer.objects.active = 
    D.collections['INSTRUMENT'].all_objects[str(row.object)]
    C.object.select_set(True)
    bpy.context.area.ui_type = 'NLA_EDITOR'
    C.object.animation_data.nla_tracks.active = None
    C.scene.frame_set( current_frame + frames_delay )
    
    if row.animation == 'action_on':

        nlaselect('PianoKeyAnimations')
        bpy.ops.nla.actionclip_add(action='KeyPress')
            
    if row.animation == 'action_off':

        nlaselect('PianoKeyAnimations')
        bpy.ops.nla.actionclip_add(action='keyrelease')
            
bpy.context.area.ui_type = current_area
C.object.select_set(False)

这似乎是使用所选对象创建多个 NLATrack。

查看截图:

enter image description here

enter image description here

enter image description here

enter image description here

有没有人对如何解决这个问题有任何建议?谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。