0
0

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でアニメーションを作る場合に
Blenderだけで作業を完結するのではなく 他のツールで作ったアニメーションを利用したいこともあります

Blenderアクション内のデータとボーンの紐づけは 他のデータと同様に名前で対応されますが
必ずしもパーツの命名が同じでなかったり
リグを使用して名前が変更になることもあります
image.png
そういった場合 アクションでは対応付けするものがないものとしてエラー表示になります
この対応付けを修正するには エラーで表示されているデータパスの文字列を1つ1つ修正するしかないようです

煩雑なのでボーンの置き換えを記述することで対応付けを修正するスクリプトを書いてみました

import bpy
import re
# アクション名で取得する場合
#action = bpy.data.actions["Action"]
# 現在編集中のアクション
action = bpy.context.active_object.animation_data.action
# 名前の置き換え辞書
retarget_dic ={"thigh.L":"thigh_fk.L","shin.L":"Leg_fk_L",
                "upper_arm.L":"upper_arm_fk.L","forearm.L":"forearm_fk.L",
                "thigh.R":"thigh_fk.R","shin.R":"Leg_fk_R",
                "upper_arm.R":"upper_arm_fk.R","forearm.R":"forearm_fk.R"
                }
# データパスの置き換え
for f in action.fcurves:
    for key_ in retarget_dic.keys():
        if key_ in f.data_path:
            f.data_path = re.sub('(.+)%s(.+)$' % key_, r'\1%s\2' % retarget_dic[key_],f.data_path)
# グループ名(ボーン名)の置き換え
for g in action.groups:
    if g.name in retarget_dic.keys():
        g.name = retarget_dic[g.name]

例では Rigifyのメタリグで付けたアクションを RigifyのFKボーンに対応付けてみました
image.png
スクリプト実行直後は変化がないように見えますが フレームを変更する等をするとポーズが更新されるかと思います
(キャプチャでは緑色のボーンがFKボーンです)

ちょっとしたものですが 参考にできる情報が見当たらなかったので書いてみました
何かの参考になれば幸いです

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?