LoginSignup
10
9

More than 3 years have passed since last update.

UE4 ボーンのTransform制御について

Last updated at Posted at 2019-10-12

概要

スケルタルメッシュの特定ボーンに対するトランスフォーム制御の方法についてのメモ書きです。

更新履歴

日付 内容
2020/01/31 アニムグラフからの制御について内容追記

環境

Windows10
Visual Studio 2017
UnrealEngine 4.22

参考

以下を参考にさせて頂きました、ありがとうございます。

ボーンのトランスフォーム
UE4 特定のボーン(Transform)に対して「位置」「回転」「スケール」を変更する(Transform(Modify)Bone)
[UE4]Transform skeletal bone in C++
UE4 キャラクターの顔を特定の位置に向ける・Transform の向きを Blueprint で制御する(Look At)

アニメ―ションBPのアニムグラフから制御する

ステートマシンのポーズから変換し直接制御します。
以下BPコード例です。
bone_trans_BP.png

[ボーンをトランスフォーム(修正)する]のノードを選択し、[Bone to Modify]の項目を制御するボーン名を指定し、[Rotation]の[Rotation Mode]を[Add To Existing]に変更します。(座標やスケールを制御する場合はそれぞれ[Translation]や[Scale]を設定します。)
bonemodifye_setting.png

BPのノードに修正する値を設定します。

以下、結果です。
bone_trans_Result.png

首[neck_01]に対し、回転[-50.0, 0.0, 60.0]が適用されています。

車のタイヤなどの継続的変化するものは別途変数を用意してイベントグラフの[Blueprint Update Animation]イベントなどから更新して適用すると良いと思います。
Tire_sample.jpg

[ボーンをトランスフォーム(修正)する] -> [詳細] -> [Rotation] -> [Rotation Mode]を[Add to Existing]に設定します。

PoseableMeshComponentを使う

ボーン情報をまとめて格納ができるコンポーネントPoseableMeshComponentを使ってみます。

PoseableMeshComponentを追加します。
poseablecomponent.jpg

対象のスケルタルメッシュを設定します。
poseable_setting.jpg

[Head]ボーンに対し、スケールを入れてみる例です。
一旦、PoseableMeshへSkeletalMeshのボーン情報をコピーしています。
poseable_BP.png

元のスケルタルメッシュとポーズメッシュが表示され、ポーズのほうがスケール適用されて表示されます。

C++コードについて

ボーン名で座標/回転/スケールの設定、取得メソッドがあるようです。

PoseableMeshComponent.h
// トランスフォーム設定
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
void SetBoneTransformByName(FName BoneName, const FTransform& InTransform, EBoneSpaces::Type BoneSpace);

// 座標設定
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
void SetBoneLocationByName(FName BoneName, FVector InLocation, EBoneSpaces::Type BoneSpace);

// 回転設定
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
void SetBoneRotationByName(FName BoneName, FRotator InRotation, EBoneSpaces::Type BoneSpace);

// スケール設定
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
void SetBoneScaleByName(FName BoneName, FVector InScale3D, EBoneSpaces::Type BoneSpace);

// トランスフォーム取得
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh") 
FTransform GetBoneTransformByName(FName BoneName, EBoneSpaces::Type BoneSpace);

// 座標取得
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
FVector GetBoneLocationByName(FName BoneName, EBoneSpaces::Type BoneSpace);

// 回転取得
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
FRotator GetBoneRotationByName(FName BoneName, EBoneSpaces::Type BoneSpace);

// スケール取得
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
FVector GetBoneScaleByName(FName BoneName, EBoneSpaces::Type BoneSpace);

// リセット
UFUNCTION(BlueprintCallable, Category="Components|PoseableMesh")
void ResetBoneTransformByName(FName BoneName);

Look At ノードを使う

アニメ―ションBPにて注視用にボーンの制御ができるようです。

LookAt.png

注視座標[Look At Location]へ[Bone to Bodify]で設定したボーン[Neck]が向けられる例です。[Axis]の調整が必要な場合があります。

Blend Bone By Channel ノードを使う

アニメ―ションBPにてボーンの制御値を他のアニメ―ションから持って来られるようです。

blendbone.png

[A]のアニメーションの[Head]に[B]のアニメ―ションの[Head]ボーンのTransform値を適用しています。
制御が難しいかもしれませんが、一部のボーンの制御値を外部データ化できるので使いどころはあると思います。

まとめ

スロットアニメ―ションなどでブレンドスペースが使えない場合のボーン制御方法をいくつか調べましたが、自然に動くように制御しようと思うととても難しいです。

10
9
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
10
9