为不透明度和体积编写关键帧插入脚本

2024-06-28 23:46:15 发布

您现在位置:Python中文网/ 问答频道 /正文

在Blender2.74下的Video Sequence Editor中添加、整理和整理了我的家庭录像。我的下一个目标是自动淡入淡出,使用脚本,每个音频和视频序列。在

目前,我的脚本遍历所有序列并检查类型。如果序列类型为“电影”或“图像”,则不透明度将被设置关键帧;如果序列是声音,则将对体积设置关键帧。目前,我的脚本还能够找到每个序列的开始帧和结束帧,以及计算并跳到衰落应该开始/结束的帧。但是,要使用脚本为Graph Editor内的不透明度和体积设置关键帧,似乎是不可能的。在

根据Blender 2.73.8api,似乎可以使用bpy.ops.graph.keyframe_insert(type='ALL')编写关键帧脚本,但似乎没有任何能力使用脚本为不透明度或体积设置关键帧。在

有人能告诉我如何使用脚本设置不透明度和体积的关键帧吗?在

import bpy



# ----------------------------------------
# main
# ----------------------------------------

scene = bpy.context.scene
scene.frame_current = 0

queue = scene.sequence_editor.sequences

print("Frames Per Second [ ", scene.render.fps, " ].")
bpy.ops.sequencer.select_all(0)

for i in queue:
    itemLead = i.frame_start
    itemBack = itemLead + i.frame_final_duration

    print("Lead [ ", itemLead, " ] Tail [ ", itemBack, " ].")
    itemType = i.type

    if itemType == "MOVIE":
        i.select = 1

        scene.frame_current = itemLead
        i.blend_alpha = 0.0

        ##bpy.ops.graph.keyframe_insert(type="blend_alpha")

        print("Movie mode.")
        i.select = 0

        continue

    if itemType == "SOUND":
        i.select = 1
        print("Sound mode.")
        i.select = 0

        continue

    if itemType == "IMAGE":
        i.select = 1
        print("Image mode.")
        i.select = 0

        continue

    print("Skipped [ ", itemType, " ].")

Tags: 脚本ifmodetype体积序列sceneselect
2条回答

要使用python添加一个关键帧,请告诉属性(strip)的所有者将其属性之一的insert a keyframe设置为insert a keyframe

scene = bpy.context.scene
queue = scene.sequence_editor.sequences

queue[0].blend_alpha = 0.0
queue[0].keyframe_insert('blend_alpha', frame=1)

queue[0].blend_alpha = 1.0
queue[0].keyframe_insert('blend_alpha', frame=10)

您可能还注意到,可以为关键点指定帧,这样就不需要调整当前帧。如果确实要更改当前帧,最好使用^{}。在

有关我的代码的最终版本,请参见以下内容:

import bpy



#                     
# main
#                     

scene = bpy.context.scene
queue = scene.sequence_editor.sequences
depth = scene.render.fps * 1.8

for i in queue:

    itemType = i.type
    itemLead = i.frame_offset_start + i.frame_start
    itemHind = itemLead + i.frame_final_duration

    if itemType == "MOVIE":

        i.blend_alpha = 0.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemLead)

        i.blend_alpha = 1.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemLead + depth)

        i.blend_alpha = 1.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemHind - depth)

        i.blend_alpha = 0.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemHind)

        continue

    if itemType == "SOUND":

        i.volume = 0.0
        i.keyframe_insert(data_path="volume", frame=itemLead)

        i.volume = 1.0
        i.keyframe_insert(data_path="volume", frame=itemLead + depth)

        i.volume = 1.0
        i.keyframe_insert(data_path="volume", frame=itemHind - depth)

        i.volume = 0.0
        i.keyframe_insert(data_path="volume", frame=itemHind)

        continue

    if itemType == "IMAGE":

        i.blend_alpha = 0.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemLead)

        i.blend_alpha = 1.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemLead + depth)

        i.blend_alpha = 1.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemHind - depth)

        i.blend_alpha = 0.0
        i.keyframe_insert(data_path="blend_alpha", frame=itemHind)

        continue

相关问题 更多 >