Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

Unreal Editor でのカスタム アクターのアニメーション化

Unreal® Editor でカスタム アクターをアニメーション化するには、次の手順に従います。開始する前に、Visual Studio® 2019 と Vehicle Dynamics Blockset™ Interface for Unreal Engine® 4 Projects サポート パッケージがマシンにインストールされていることを確認してください。詳細については、サポート パッケージのインストールと環境の構成を参照してください。

さらに、次のことを確認してください。

  • Unreal Engine での C++ のコーディングを理解していること。

  • Unreal Editor C++ プロジェクトに骨格となるアクターのメッシュが含まれていること。この例では二輪のメッシュを使用します。

    Unreal Editor bicycle mesh

この例では、二輪アクターをアニメーション化するワークフローを示します。Unreal Engine の「ビークルのユーザー ガイド」から応用した一般的なワークフローを示しています。

Simulink モデルの設定

手順 1: Simulink モデルの設定

新しい Simulink® モデルを開き、次のブロックを追加します。

  • 2 つの Ramp ブロック

  • Constant ブロック

  • Simulation 3D Actor Transform Set ブロック

  • Simulation 3D Scene Configuration ブロック

次のようにブロックを接続して名前を付けます。

Simulink model with connected blocks

手順 2: ブロックの構成

パラメーターを次のように設定してブロックを構成します。

ブロックパラメーター設定

Simulation 3D Scene Configuration

  • シーン ソースUnreal Editor

  • プロジェクト — インストールされているサポート パッケージのプロジェクト ファイルの名前と場所 (例: C:\Local\AutoVrtlEnv\AutoVrtlEnv.uproject)。

  • シーン ビューシーン原点

Simulation 3D Actor Transform Set

  • [アクターの設定] タブ:

    • 3D シーンのアクターのタグ、ActorTagBike1

      メモ

      このタグは、手順 6: 二輪アクターのインスタンス化の Unreal Editor のタグ名と一致していなければなりません。

    • 設定するアクターあたりのパーツ数、NumberOfParts3

  • [初期値] タブ:

    • パーツごとにアクターを並進させる初期配列値、Translation[0 0 0;0 0 0;0 0 0]

    • パーツごとにアクターを回転させる初期配列値、Rotation[0 0 0;0 0 0;0 0 0]

    • パーツごとにアクターをスケーリングさせる初期配列値、Scale[1 1 1;1 1 1;1 1 1]

Translation Ramp

  • 勾配[0.35 0 0;0 0 0;0 0 0]

Rotation Ramp

  • 勾配[0 0 0;0 -pi/5 0;0 -pi/5 0]

Scale Constant

  • 定数値[1 1 1;1 1 1;1 1 1]

二輪をアニメーション化するための Unreal Editor の設定

手順 3: アニメーション インスタンスの設定

  1. Simulink モデルで、Simulation 3D Scene Configuration ブロックの [Open Unreal Editor] パラメーターを使用して Unreal Editor を開きます。

  2. [File][New C++ Class] を選択します。[Choose Parent Class] ダイアログ ボックスで、[Show All Classes] を選択します。AnimInst を検索します。AnimInstance 親クラスを追加します。

    Unreal Editor choose parent class

  3. 新しい C++ クラスに SimulinkBikeAnimInst という名前を付けます。[Public] を選択します。[Create Class] をクリックします。

    Unreal Editor name parent class

  4. Visual Studio 2019 で、C:\Local\AutoVrtlEnv\AutoVrtlEnv.sln ファイルを開きます。ソース ファイルの SimulinkBikeAnimInst.cppSimulinkBikeAnimInst.h に移動します。

    Visual studio solution explorer

    ファイルを次のように編集します。

    ヒント

    この例では、二輪の車輪の回転をアニメーション化するために FWheelRotation プロパティと RWheelRotation プロパティをコードに含めています。プロパティをさらに追加して二輪の他のパーツをアニメーション化できます。

     コード: SimulinkBikeAnimInst.h

     コード: SimulinkBikeAnimInst.cpp

  5. Unreal Editor で [Compile] をクリックします。

    Unreal editor compile

手順 4: アニメーション ブループリントの作成

  1. Unreal Editor の [Content Browser] タブで、[View Options] の下にある [Show Engine Content][Show Plugin Content] を選択します。

    Unreal Editor options

  2. アニメーション メッシュを追加します。[Content Browser] タブで、[MathWorksAutomotiveContent Content][Vehicles][Bicyclist][Meshes] に移動します。

    Unreal Editor content browser

  3. [Add/Inport][Animation][Animation Blueprint] を選択します。

    Unreal Editor add animation blueprint

  4. [Create Animation Blueprint] ダイアログ ボックスで、次のように選択します。

    • Parent Class: SimulinkBikeAnimInst

    • Target Skeleton: SK_Bicycle_Skeleton

    Unreal Editor create animation blueprint

    [OK] をクリックします。

  5. ブループリントに BikeAnimation という名前を付けます。右クリックして [Save] を選択します。

    Unreal Editor save animation blueprint

  6. BikeAnimation ブループリントを開きます。次のように接続します。

    Unreal Editor blueprint connections

    前輪と後輪の両方について、次のように設定されていることを確認します。

    • [Bone to Modify] が正しいボーン

    • [Rotation Mode][Replace Existing]

    • [Rotation Space][Bone Space]

    Unreal Editor blueprint specifications

  7. ブループリントをコンパイルして保存します。

手順 5: 二輪アクターの C++ クラスの作成

  1. Unreal Editor の [Content Browser] タブで、[View Options] の下にある [Show Engine Content][Show Plugin Content] を選択します。

    Unreal Editor options

  2. MathWorksSimulation C++ Classes フォルダーから [Sim3dActor] を選択します。

    Unreal Editor content browser

    右クリックして [Create C++ class derived from Sim3dActor] を選択します。

    Unreal Editor class actions

    ヒント

    MathWorksSimulation C++ Classes フォルダーが表示されない場合は、次の手順に従って、MathWorksSimulation プラグインがインストールされて有効になっていることを確認してください。

    1. Unreal Editor のツール バーで、[Edit][Plugins] を選択します。

    2. [Plugins] ウィンドウで、インストール済みのウィンドウのリストに [MathWorks Interface] プラグインが表示されていることを確認します。プラグインがまだ有効になっていない場合は、[Enabled] チェック ボックスをオンにします。

    3. エディターを閉じて Simulink から再度開きます。

  3. 新しい Sim3dActor に BicycleActor という名前を付けます。[Public] を選択します。[Create Class] をクリックします。

    Unreal Editor class name

  4. Visual Studio で、BicycleActor.hBicycleActor.cpp に移動します。

    Visual studio solution explorer

    ファイルを次のように編集します。

    ヒント

    この例では、車体 (BIKE_BODY)、前輪 (FRONT_WHEEL)、および後輪 (REAR_WHEEL) をアニメーション化するためのロジックをコードに含めています。ロジックをさらに追加して二輪の他のパーツをアニメーション化できます。

     コード: BicycleActor.h

     コード: BicycleActor.cpp

  5. Unreal Editor で [Compile] をクリックします。

    Unreal editor compile

手順 6: 二輪アクターのインスタンス化

  1. Simulink モデルで、Simulation 3D Scene Configuration ブロックの [Open Unreal Editor] パラメーターを使用して Unreal Editor を開きます。

  2. シーン内に二輪アクターを配置します。

    Unreal editor bicycle actor placement

  3. タグを Simulation 3D Actor Transform Set ブロックの [3D シーンのアクターのタグ、ActorTag] と同じ値に設定します。この例では、値を Bike1 に設定します。

    Unreal editor set tag value

カメラ ビューの設定 (オプション)

必要に応じて、カメラ ビューを設定して既定のビューをオーバーライドします。カメラ ビューは Simulink またはレベル ブループリントを使用して設定できます。推奨されるオプションは、Simulink を使用する方法です。

手順 7: Simulink の使用 (推奨)

二輪を追従するカメラ ビューを設定するには、次を行います。

  1. モデルに次のブロックを追加します。

    • 1 つの Ramp ブロック

    • 1 つの Add ブロック

    • 3 つの Constant ブロック

    • Simulation 3D Actor Transform Set ブロック

    次のようにブロックを接続して名前を付けます。

    Simulink model block connections

  2. ブロック パラメーターを次のように設定します。

    ブロックパラメーター設定

    Simulation 3D Actor Transform Set: Camera Control

    • 3D シーンのアクターのタグ、ActorTagMainCamera1

    CamTranslation

    • 定数値[0 -5.1 0.56]

    • ベクトル パラメーターを 1 次元として解釈off

    CamRotation

    • 定数値[0 0 deg2rad(85)]

    • ベクトル パラメーターを 1 次元として解釈off

    CamScale

    • 定数値[1 1 1]

    • ベクトル パラメーターを 1 次元として解釈off

手順 7: レベル ブループリントの使用

既定のカメラ ビューをオーバーライドするには、次を行います。

  1. カメラ アクターを追加します。BicycleActor の子として割り当てます。

  2. [Transform] の設定を使用して、位置と視点角度を指定します。

    Unreal Editor set actor transformation settings

  3. レベル ブループリントを開きます。

    Unreal Editor open level blueprint selection

  4. レベル ブループリントで、次のように接続します。[Event Graph] で右クリックしてノードを検索する場合は、[Context Sensitive] をオフにしてください。CameraActor がある場合は、エディターの [World Outliner] ビューから [Event Graph] にドラッグできます。

    Unreal Editor blueprint connections

  5. ブループリントとプロジェクトを保存します。Unreal Editor を閉じます。

シミュレーションの実行

Simulink モデルと Unreal Editor 環境を構成したら、シミュレーションを実行します。

  1. Simulink モデルで、Simulation 3D Scene Configuration のパラメーターの値が次のように設定されていることを確認します。

    • シーン ソースUnreal Editor

    • プロジェクト — インストールされているサポート パッケージのプロジェクト ファイルの名前と場所 (例: C:\Local\AutoVrtlEnv\AutoVrtlEnv.uproject)。

    • シーン ビューシーン原点

  2. Simulation 3D Scene Configuration ブロックの [Open Unreal Editor] パラメーターを使用して Unreal Editor を開きます。

  3. シミュレーションを実行します。

    1. Simulink モデルで [実行] をクリックします。

      Unreal Editor で開かれるプロジェクトがシーンのソースであるため、シミュレーションは開始されません。

    2. Simulink の [診断ビューアー] ウィンドウに次のメッセージが表示されていることを確認します。

      In the Simulation 3D Scene Configuration block, you set the scene source to 'Unreal Editor'. In Unreal Editor, select 'Play' to view the scene.

      これは、Simulink が Unreal Engine 3D 環境で車両および他のアセットをインスタンス化したことを示す確認のメッセージです。

    3. Unreal Editor で [Play] をクリックします。Unreal Editor で現在開いているシーンでシミュレーションが実行されます。

参考

|

関連するトピック

外部の Web サイト