2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Blenderの画像シーケンスのコマ打ちを制御する

Posted at

Blenderでは連番画像をアニメーションとして下絵に利用できます
ただし、通常ではフレームを1つ進める毎に連番画像のカウントを1つ進めるといった挙動になっていて
作画アニメのように任意のタイミングで次の画像に切り替えるようにはなっていません

連番画像のフレームの「オフセット」の値はキーフレームを打って制御可能なので
そちらを調整するスクリプトを作成してみました

250031601.gif

import bpy

def set_frame_offset(object_, frame_, offset_value):
    # 指定フレームで画像のフレームのオフセットを設定
    scene.frame_current = frame_
    object_.image_user.frame_offset = offset_value
    object_.image_user.keyframe_insert(data_path='frame_offset')

scene = bpy.context.scene
object_ = bpy.context.active_object
# 画像エンプティの場合
if object_.type == 'EMPTY' and object_.empty_display_type == 'IMAGE':
    image_ = object_.data
    if image_.source == 'SEQUENCE':
        frame_start = scene.frame_start
        object_.image_user.frame_duration = scene.frame_end +10
        # 開始位置での値
        scene.frame_current = frame_start
        set_frame_offset(object_, frame_start, 0)
        # マーカー位置で切り替わるようにキーフレーム設定
        for i_ in range(len(scene.timeline_markers)):
            marker_frame = scene.timeline_markers[i_].frame
            offset_value = i_ -marker_frame
            set_frame_offset(object_, marker_frame -1, offset_value +2)
            
            offset_value = i_ -marker_frame 
            set_frame_offset(object_, marker_frame, offset_value +2)
        # 終了位置での値
        frame_ = scene.frame_end
        offset_value = len(scene.timeline_markers) -frame_ +1 
        set_frame_offset(object_, frame_, offset_value)

使用しているのは Storyboarderを使って書き出した7枚の画像です
image.png

今回は画像エンプティで動作するようにしています
画像エンプティに画像を読み込んで ソースを連番画像に設定しておいてください
image.png
Blenderではタイムライン上で [M] キーを押すことでマーカーを打つことができます
(キャプチャでF_52等の番号が書かれた△のアイコンのもの)
マーカー位置で次の連番画像のフレームに切り替わるようオフセット値を調整しています

切り替え位置のマーカーを設定したら 画像エンプティを選択した状態でスクリプトを実行してください

切り替えのタイミングを変更したい場合には マーカーの位置を移動(△を選択してGキーで移動できます)
オフセット値に付けられたキーフレームを削除した上で 再度スクリプトを実行してください

何かの手助けになれば幸いです

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?