This commit is contained in:
2025-05-12 05:45:47 +09:00
commit baad042ce7
138 changed files with 7620 additions and 0 deletions

11
book/gasp/01_character.md Normal file
View File

@ -0,0 +1,11 @@
# キャラクターを追加する
これには`IKリターゲット`が必要です。
1. `Content/Blueprints/CBP_SandboxCharacter_Manny`をcopyして`CBP_SandboxCharacter_test`を作ります。
2. `CBP_SandboxCharacter_test`を開いて、`Mesh`の下にあるSKM(スケルタルメッシュ)の`Manny`を選択します。その状態で`詳細(details) -> タグ(tags) -> Component Tags`から`index[0]``RTG_UEFN_to_UE5_test`に書き換えます。
3. `Content/Blueprints/RetargetedCharacters/ABP_GenericRetarget`を開き、変数の`IKRetargeter_Map`に新しく`RTG_UEFN_to_UE5_test`を追加し、ファイルは`/Content/Characters/UE5_Mannequins/Rigs/RTG_UEFN_to_UE5_Mannequin`を参照します。
4. `/Content/Widgets/GameAnimationWidget`を開いて、characterのiconのところをcopyして貼り付けます。そして、詳細からObjectで `Content/Blueprints/CBP_SandboxCharacter_test`を参照します。
これで新しいキャラを使用することが可能になります。

12
book/gasp/02_jump.md Normal file
View File

@ -0,0 +1,12 @@
# 飛びつける高さを増やす
1. `Content/Blueprints/CBP_SandboxCharacter`を開いて、関数の`TryTraversalAction`を編集します。
2. 一番下の`Max:275``Max:475`に変更します。
3. `/Content/Characters/UEFN_Mannequin/Animations/Traversal/CHT_TraversalAnims`を開きます。
4. `Mantles(編集)`から先程変更した値のところを全部`275 -> 475`に書き換えます。
例えば、levelにあるblockの高さを変更して飛びつけるか確認します。
1. `LevelBlock_TraversableXX`を選択します。
2. トランスフォーム(transform)の拡大(scale)のところで青色(transform-scale-z)を`4.5`にします。

4
book/gasp/03_vrm.md Normal file
View File

@ -0,0 +1,4 @@
# キャラクターを作る
[こちら](/vrm4u/01_make.html)のページで解説します。

62
book/gasp/04_vmc.md Normal file
View File

@ -0,0 +1,62 @@
# モーションキャプチャで動かす
カメラ(camera)からcharacterを動かす技術をモーションキャプチャ(motion capture)といいます。様々なprotocol(プロトコル)がありますが、`vrm4u`では[vmc](https://qiita.com/mintan/items/72d63cce4e6197b151b7)というprotocolを使います。
`epic games`は[livelink](https://dev.epicgames.com/documentation/ja-jp/unreal-engine/live-link-in-unreal-engine)というものを作っています。
必要なものは多く、基本的には`web-camera``client-app`, `ue-plugin`が必要です。私は以下を使っています。
- camera: ートパソコンに付属しているwebカメラ
- client: [webcam motion capture](https://webcammotioncapture.info/)
- plugin: [vrm4u](https://github.com/ruyo/VRM4U)
clientはそれぞれのosにあったものを選びます。無料でも可能ですが、性能的には有料アプリがおすすめです。いくつか紹介しておきます。
この辺の情報は最初はわからないと思いますが、基本的には以下の流れで情報を処理します。
```sh
[camera] --> [client] --> [plugin]
```
## client
|name|body|free|
|---|---|---|
|[vmc](https://github.com/sh-akira/VirtualMotionCapture)|vmcの開発元が出しているclient。protocolと同じ名前がつけられている|🟩|
|[vseeface](https://www.vseeface.icu/)|高性能なclient|🟩|
|[xr animator](https://booth.pm/ja/items/4513654)|お手軽に表示できるclient|🟩|
|[waidayo](https://booth.pm/ja/items/1779185)|iosにも対応しているclient|🟩|
|[vrm posing desktop](https://store.steampowered.com/app/1895630/VRM_Posing_Desktop/)|steamから出ているclient|🟥|
|[webcam motion capture](https://webcammotioncapture.info/)|安定したclient。使ってみた中では動きが一番良かった|🟥|
## build packageを使うときportに注意
clientから送信されるportをpluginで受信します。build packageの`.exe`で確認するときは、editor(エディタ)を落としておきましょう。
## 停止したときだけvmcを有効にする
<iframe width="100%" height="415" src="https://www.youtube.com/embed/BsLOlAr-wBY?si=jahPUVD8YMMfefvm&start=195&end=204&mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
キャラクターがidle状態、つまり、停止しているときだけVMCのモーションキャプチャを反映させます。
これはVMCモードの変数を用意し、ABPで条件を書いて実現しています。キャラクターを動かしたときは一時的に無効にします。
関数を作り、bool型でグローバル変数で作ります。それをVMCモードの`enable/disable`とします。カメラは正面と通常を切り替えています。
```sh
/Content/Blueprints/CBP_SandboxCharacter
```
<iframe src="https://blueprintue.com/render/za634zjp/2" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
移動するときは一時的に無効にします。移動が完了すると有効にします。GASの移動は終了後に少し滑るので`delay`を入れています。
<iframe src="https://blueprintue.com/render/za634zjp/3" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
```sh
/Content/Chracters/$model/ABP_Pose_$model
```
`Blend Poses by bool`を使います。`[Mesh Space RefPose] --> [VrmVMC] --> [Blend Poses by bool(true)]`
<iframe src="https://blueprintue.com/render/za634zjp/4" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>

14
book/gasp/05_kawaii.md Normal file
View File

@ -0,0 +1,14 @@
# 揺れものを設定する
[kawaiiphysics](https://github.com/pafuhana1213/kawaiiphysics)
`$project/Plugins/kawaiiPhysics/kawaiiPhysics.uplugin`
1. 基本的には`/Content/Characters/$model/ABP_Pose_$model`に設定します。
2. 外付けの服などに設定する場合はABPを作成し、そこに設定します。
<a href="../img/0002.png"><img src="../img/0002.png"></a>
服が揺れる様子です。`limit(制限) -> Capsule Limits -> Driving Bone`にBone(ボーン)を入れて体に入りこまないようにしています。
<iframe width="100%" height="415" src="https://www.youtube.com/embed/0Ig_-JSRV0M?si=Kz_jCbYTHr_OzPpP&start=28&end=50&mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

15
book/gasp/06_camera.md Normal file
View File

@ -0,0 +1,15 @@
# カメラワークを設定する
スキル発動したときカメラをぐるっと回す演出です。
正面カメラを設置し、タイムラインで動かしたあとに通常(後方)カメラに切り替えることで実現しています。
<iframe width="100%" height="415" src="https://www.youtube.com/embed/BsLOlAr-wBY?si=jahPUVD8YMMfefvm&amp;start=29&end=34&amp;mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
```sh
/Content/Blueprints/CBP_SandboxCharacter
```
<iframe src="https://blueprintue.com/render/exmpoyfu/1/" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
ボス戦のときだけこの演出を実行します。なお、`true`, `false`はどちらも最終的に`skill(スキル)`の実行につながるようにしてください。

27
book/gasp/07_anim.md Normal file
View File

@ -0,0 +1,27 @@
# アニメーションを作成する
control rigからも作成できます。しかし、購入したものを使うのが一番です。
[magicalanimset](https://www.fab.com/ja/listings/a63386b8-7cad-42cd-8b81-a9de147e1f08)
無料でやるなら`.fbx`, `.vrma`などから作成する方法があります。
- https://www.mixamo.com/
- https://booth.pm/ja/items/5512385
- https://github.com/BandaiNamcoResearchInc/Bandai-Namco-Research-Motiondataset
## control rigから作る
再生して録画ボタンを押すと作れます。
## tatoolsを使う
[tatools](https://www.fab.com/ja/listings/a5d3b60d-b886-4564-bf6d-15d46a8d27fe)を使います。
https://github.com/threepeatgames/ThreepeatAnimTools
## unityから持ってくる
[こちら](/unity/01_fbx.html)を参考にしてください。

5
book/gasp/08_niagara.md Normal file
View File

@ -0,0 +1,5 @@
# niagaraでダメージを出す
- https://www.youtube.com/watch?v=wYq2SR63vkM

23
book/gasp/09_chair.md Normal file
View File

@ -0,0 +1,23 @@
# 椅子に座る
椅子に座るのと階段に登るのは鬼門です。完璧に調整するのが難しいからです。
椅子に座る動作を設定します。大変ですが以下のcomponentを使うと簡単にできます。調整は難しいですね。私の場合はgame animation sampleを使っていますが、最新版では勝手に動きが制御されるためanim montageをそのまま再生できません。したがって、別にabpを作成し、それを呼び出します。
- https://www.youtube.com/watch?v=VzyvpFvon0g
- https://blueprintue.com/blueprint/wg_vyr4o/
# animation blueprint linking showcase
[こちら](https://www.fab.com/ja/listings/e52251d2-1a90-4428-a685-c5d4acdd9c07)にチュートリアルが公開されています。
主にABPの切り替えと椅子に座る内容があります。docsも公開されています。
[External Communication Showcase](https://docs.google.com/document/d/1D2rYh7XYkYaBlMPcD7rL4s6pV6e6Ty9xDYb9KW836NA/edit?tab=t.0#heading=h.tb8y73m27obr)
# replicated interaction kit vol 3
`replicated interaction kit vol 3`というassetを改造します。
[こちら](/plan/05_chair.html)を参考にしてください。

15
book/gasp/10_stairs.md Normal file
View File

@ -0,0 +1,15 @@
# 階段を登る
階段でのめり込む問題があります。これを解消します。
1. `/Blueprints/ABP_SandboxCharacter`でAnimGraphの中からFoot Placementを探す。
2. 骨盤(pelvis)の悪態道補正モードを`Sudden Motion Only`から`Component Space`にする。
また、階段の段差(Step Height)は小さくしてください。のめり込まなくなった反面、スムーズさがなくなり画面がガタガタ揺れます。
## 階段を作る
1. map(level)を開く
2. `編集モード -> モデリング -> 作成 -> 階段`
3. `Step Height: 10.0`

35
book/gasp/11_run.md Normal file
View File

@ -0,0 +1,35 @@
# アニメーションを変更する
今回はダッシュ(sprint)で一定のスピード(speed)に達すると`kawaii_run`と名付けたアラレちゃん走りに切り替わるようにします。
<iframe width="100%" height="415" src="https://www.youtube.com/embed/HaykQT5vBNY?mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
1. ABP_SandboxCharacterのAnimGraphを開きます。`cached pose`を作って処理を分割します。
2. cached poseを呼び出して`Layered blend per bone`のbaseにつなぎます。重要なのはLayered blendの詳細で`spine_03`のボーンを入れること。
3. blendにアニメシーケンスをつなぎます。私は`unity -> .vrma -> vrm4u`で作成したものを使いました。
4. blend weightsの値をconfigから持ってきます。これで`CBP_SandboxCharacter`から制御できます。ダッシュが一定速度に達すれば1、それ以外は0にします。
![](/img/0015.png)
<iframe src="https://blueprintue.com/render/9jgpq1oj/1" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
## アニメシーケンスを作る
- https://booth.pm/ja/items/2845548
これをunityを使って[変換](/unity/01_fbx.html)して使いました。
## リターゲットによる調整
`kawaii_run`は走っているときに両足を中央に持っていくのが正しいですが、このままでは足が開いてしまいます。
これを調整するにはリターゲットのposeを変更します。使用している`RTG_UEFN_$model`を開いて、`Running Retarget`から`Editing Retarget Pose`にします。両足を回転さればokです。一方はプラス、もう一方はマイナスの値です。
- left: 0.0, -2.0, 20.0
- right: 0.0, 2.0, -20.0
## GASPでアニメーションを変更するには
`CHT_AnimationsForStateMachine`でそれぞれの項目のanimを変更すればいいのだろうかと思いましたが、走るanimに関しては、複雑すぎる上に全方位のものを用意する必要があります。
したがって、`ABP_SandboxCharacter`のblendを活用しながら適用しました。

33
book/gasp/12_weapon.md Normal file
View File

@ -0,0 +1,33 @@
# 武器を装備する
武器を手に持つ動作を追加します。
<iframe width="100%" height="415" src="https://www.youtube.com/embed/VronsCH11oo?mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
1. SKで`装備する箇所``手に持つ箇所`のソケットを追加します。
2. そこに武器のasset(mesh)を追加し、previewします。ここでは剣(sword)を使います。
3. animを作ります。例えば、装備場所から手に持つ動作の中で剣が重なり合うようにします。
4. 重なる場所には通知で`DrawnWeapon`, `RestWeapon`を作ります。
5. それをCBP_SandboxCharacterのIAに設定します。`BP_WeaponSword`を作って武器のmeshを入れます。
## 他のキャラクターでズレてしまう
これはManny用のboneに設定されていますので、他のキャラではズレてしまいます。
対処法を考えます。
1. まず同じ名前のソケットをSKのboneに追加します。そして、位置を調整します。
2. event begin playでキャラのmeshを`Character_Mesh`の変数に入れます。それをparentに使います。
<iframe src="https://blueprintue.com/render/ml3h546e/1" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
## niagaraがズレてしまう
animにniagaraを設定している場合もズレてしまいます。これは解決法がありません。
slash(スラッシュ)などは面倒くさいのでそのまま当てていますが、大きくなりすぎています。
他のniagaraは、`BP_WeaponSword`に入れて、都度使用するときに呼び出すようにしています。
面倒ですが体型に合わせたboneを作り、そこにniagaraを付けるといいかもしれませんが、良い解決策は見つかっていません。

55
book/gasp/13_chatgpt.md Normal file
View File

@ -0,0 +1,55 @@
# NPCとの会話をAIにする
NPCなどの会話や操作を音声とAIで実行します。
- [RuntimeSpeechRecognizer](https://github.com/gtreshchev/RuntimeSpeechRecognizer)
- [RuntimeAudioImporter](https://github.com/gtreshchev/RuntimeAudioImporter)
- [ChatGPT](https://platform.openai.com/docs/api-reference/introduction)
- [elevenlabs](https://elevenlabs.io/docs/api-reference/text-to-speech)
具体的な仕組みとしては、まずEnterを押すと、音声を読み取ります。読み取った音声を文字に変換し、それをchatgptに渡します。回答を再び音声に変換し、NPCと会話できるというシステムです。
<iframe src="https://blueprintue.com/render/i95n84w5/" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
```sh
$ curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Your question here"}],
"temperature": 0.7
}'
```
```sh
$ curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/VOICE_ID" \
-H "xi-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Hello world!",
"model_id": "eleven_monolingual_v1",
"voice_settings": {
"stability": 0.5,
"similarity_boost": 0.5
}
}' \
--output output.mp3
```
## 問題点
chatgptやelevenlabsは使用制限、あるいは課金が必要になります。
プレイヤーがNPCと会話する回数は初回のみのケースが多いと予想され、回数を制限することで、人気ゲームでこのような仕組みを実装しても、初月以降の負担はほぼ発生しないと予測されます。
しかし、hackされ、NPCとの会話でスパムを送信されることで負荷が増大する危険性があります。
したがって、このような仕組みは本番のゲームに実装すべきか難しいところです。
メリットとしては会話がプレイヤーごとに変わってくること。開発者がテキストを用意しなくても良いところが挙げられます。デメリットは制御できないところです。
これをlocalで動かすllmを使用することで多少の危険は避けられます。
今後、ゲームはどのような方向に進んでいくのでしょうか。NPCはAIが担当することになっていくのかもしれません。

32
book/gasp/14_jump.md Normal file
View File

@ -0,0 +1,32 @@
# ジャンプの高さを変更
特殊ジャンプを実装して、敵の近くに着地した場合に特別な技を繰り出す演出を目指します。
<iframe width="100%" height="415" src="https://www.youtube.com/embed/q3UcM8e7B0g?mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
特殊なジャンプはクールタイムが存在し、10秒間に一回実行できます。ジャンプ中は敵の攻撃を回避できます。通常ジャンプとキーを別にしてもいいですが、同じキーにしたほうがシンプルでいいと思います。
1. jump drop
2. cool time
3. jump attack
まず`skill:1`の場合はjump dropが発動します。発動すると`skill:0`になります。collisionを制御して敵の攻撃が当たらないようにします。もし着地時にboss(enemy)のcollisionにあたっていると、jump attack(ジャンプ技)が発動します。
<iframe src="https://blueprintue.com/render/r4d91x-8/1" scrolling="no" allowfullscreen style="width:100%;height:400px"></iframe>
## ジャンプモーションの変更
ジャンプモーションの変更はgaspの`CHT_PoseSearchDatabases`などで調整するは難しいです。
したがって、play montageをjumpにつなげる方法で作成します。
## アクションボタン
技の発動時に時間をゆっくり、あるいは停止する演出とアクションボタンを表示します。
1. まず、技を実装しているところで、`set global time:0.0`にして、widgetでbuttonが押されたら`set global time:1.0`にします。
2. 場合によっては`set global time:0.5` -> `delay 0.1` -> `set global time:1.0`にします。
<iframe width="100%" height="415" src="https://www.youtube.com/embed/M8DKaRGj05I?mute=1&rel=0&showinfo=0&controls=0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

61
book/gasp/README.md Normal file
View File

@ -0,0 +1,61 @@
# game animation sample
[game aimation sample](https://www.fab.com/ja/listings/880e319a-a59e-4ed2-b268-b32dac7fa016)は`epic games`が提供しているassetです。
[G]ame [A]nimation [S]ample [P]rojectでGASPと略すことがあります。
[G]ame [A]bility [S]ystemもGASなので紛らわしいですね。
まずはこれを使ってキャラクター(character)を動かしてみましょう。
## level(map)
1. `/Content/Levels/DefaultLevel`を開きます。
2. 再生ボタンを押します。
3. ゲームがプレイできます。
|key|en|ja|
|---|---|---|
|w,a,s,d|move|移動|
|space|jump|ジャンプ|
|space|sprint|ダッシュ|
|ctrl|walk|歩く|
|c|crouch|しゃがむ|
|マウススクロール|camera|カメラ|
ボタンに乗るとキャラを切り替えることができます。
レベル(level)はマップ(map)とも呼ばれます。プレイ(play)する場所を作ります。
特にボタンが重要です。tipsを確認しましょう。
`/Content/Levels/DefaultLevel`を右クリックして`参照ビューア`を選択してみます。どのファイルを参照しているかわかります。
## BP
characterは`/Content/Blueprints/CBP_SandboxCharacter`で動かしています。このファイルを開いて編集してみましょう。
1. `EventGraph`というノードが記述されている場所(画面中央)で右クリックし、`Debug Key 1`を追加します。
2. Releasedというピン(pin)から`Print String`を追加します。
3. ゲームを再生します。
4. キーボード(keyboard)の`[1]`を押すと、画面に`Hello`が表示されます。
これがbp(blueprint)でゲームを作る要領になります。
## ABP
characterの動きは`/Content/Blueprints/ABP_SandboxCharacter`で設定されています。
## input
まずkeyがどこで設定されているのかと言うと、`/Content/Input/IMC_Sandbox`で設定されています。
例えば、`/Content/Input/IA_Aim`をコピー(copy)して、新しく`IA_One`を作ってみましょう。それを`IMC_Sandbox`で読み込んで`[1]`に割り当てます。
次に、`IA_One`を先程の`CBP_SandboxCharacter`にドラッグ&ドロップ(D&D)します。
すると`EnhancedInputAction IA_One`という赤いノードが作成されたと思います。`Debug Key 1`を削除して代わりにつなぎます。色にも意味がありますが、そのうちわかってくると思います。
ゲームを再生してみると先ほどと同じkeyで動きます。