Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRM1.0とFinalIKのFullBodyBipedIKを併用すると腕が大きくねじれる事がある #1923

Closed
malaybaku opened this issue Nov 14, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@malaybaku
Copy link

環境情報

  • UniVRM version: 0.107.0
  • Unity version: Unity-2021.3
  • OS: Windows 11

バグについて

内容

VRM 1.0とFinalIKのFullBodyBipedIK(FBBIK)、およびAnimatorによるHumanoid Animationと組み合わせたときに腕が大幅にねじれることがあります。

再現用プロジェクト

ControlRigAndAnimator_Share.zip

再現手順

検証手順:

  • Unity 2021.3.5f1で添付ファイルのプロジェクトを開く
  • プロジェクトにFinalIKを導入
  • MyProject/IKTestシーンを開いて実行
  • Game View上で「Open」から、このVRMをローカルにダウンロードしたものをロードし、「Motion > T-Pose」を選択する
  • ロードされたアバターに対してAnimWithZeroWeightIkコンポーネントをアタッチする

期待挙動: アニメーションが適用された結果、手をふるモーションが動く

実際の挙動: アバターの左腕が大幅にねじれる

左: 実行した状態のモデル、右: WavingMotion.animでもともと想定されているモーション

image

添付プロジェクト内容について

プロジェクト内訳:

  • Unity 2021.3.5f1で新規プロジェクトを作成
  • UniVRM 0.107.0をUPMで導入
  • VRM_Samples-0.107.0_1e8a.unitypackageを導入
  • VRM10_Samples/VRM10Viewer/VRM10Viewer.sceneをコピーしたシーンを作成したものをMyProject/IKTestとして使用
  • WavingMotion.animVMagicMirrorで使っているモーションを使用

検証用コードで生成している状況:

  • アバターにFBBIKをアタッチすることで、とくに手のIKが動かせる状態にする
  • 両手、および左肘にIKターゲットを設定するが、ウェイトは0にする
  • その状態で、Animatorによって手を振るモーションを行おうとする

その他

確認したこと:

  • AnimWithZeroWeightIkスクリプトを使用せず、手作業でFBBIKをアタッチしてからRuntimeAnimatorControllerを設定した場合も同じ挙動が再現します。
  • FBBIKの代わりにVRIKをアタッチして類似の手順を追った場合は再現していないように見えます。
  • FBBIKコンポーネント自体を完全にオフにすると再現しなくなります。
  • RuntimeControlRigの存在によって腕の回転に影響が出ないようなモデル、つまりVRM 0.xと同じボーンローカル軸を持つモデルの場合にも再現しなさそうに見えています。

推測:

  • もしUniVRMの実装上の問題であるならば、RuntimeControlRigに関する問題の可能性が高そう
  • FBBIKのバグを踏んでいる可能性もある

補足:

  • 上記までの検証内容に盛り込まれていませんが、これまでVMagicMirrorでVRM 0.xとFBBIKを組み合わせていた範囲では本issueのような問題は確認していません。本問題によってVRM 1.0への移行コストが想定より高くなってしまったためissueを立てるに至っています。
@malaybaku malaybaku added the bug Something isn't working label Nov 14, 2022
@ousttrue
Copy link
Contributor

報告ありがとうございます。
提供いただいたシーンで、現象が再現することを確認できました。

おそらく処理順の問題(LateUpdate を Vrm と FinalIK が取り合いしている)で、
以下のコードでなおりました。

class AnimWithZeroWeightIk
{
    private void Update()
    {
        IKSetupHelper.SetIkWeights(_ik, weightRatio, weightRatio * 0.5f);
        _ik.UpdateSolverExternal(); // 👈 これ
    }

動作検証中です・・・。

@Santarh
Copy link
Contributor

Santarh commented Nov 22, 2022

報告ありがとうございます。

結論から言うと、 FinalIK の Full Body Biped IK を公式の Docs 通りにセットアップすれば問題ありませんでした。
参照箇所は このページAdding FullBodyBipedIK in runtime になります。

Limb の Local Axis はモデルによりさまざまですが、FinalIK FBBIK はこれを自動推定しきってくれるわけではないので、 SetLimbOrientations() を使用してこれを指定する必要があります。

本 Issue 添付の再現用プロジェクト内で言えば IKSetupHelper.AddFullBodyBipedIK()fbbik.SetReference() の呼び出しの直後に以下を追加してください。

        fbbik.solver.SetLimbOrientations(new BipedLimbOrientations(
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left)
        ));

Vrm10Runtime の ControlRig は T ポーズ時の Local Axis が World Axis と一致するので、上記のような指定になります。

これで AnimWithZeroWeightIkweightRatio を操作すると、Animator Animation と IK Animation を行き来したので、おそらく期待通りの動きなのかなと思います。

@malaybaku
Copy link
Author

詳細ありがとうございます。
FinalIKの利用法が間違っていたんですね…大変失礼しました。
下記の追記により、手元環境でも正常にモデルが動くのを確認できました。

fbbik.solver.SetLimbOrientations(new BipedLimbOrientations(
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left)
        ));

@malaybaku
Copy link
Author

malaybaku commented Dec 12, 2022

UniVRMと直接関係しない話題ですが参考情報として共有で…。

手元環境にて上記の修正後も腕がねじれるケースが一部で見られたため改めて確認したところ、

fbbik.solver.SetLimbOrientations(new BipedLimbOrientations(
            // 第3引数を差し替え
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.up),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.down),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left),
            new BipedLimbOrientations.LimbOrientation(Vector3.forward, Vector3.forward, Vector3.left)
        ));

が妥当そうだったため、この状態に修正して使用しています。

ref: malaybaku/VMagicMirror#867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants