/// <summary>Qumarionの動作を適用するモデルの生成と、デバイスとの接続を行います。</summary>
    void Start()
    {
        _model = PdkManager.CreateStandardModelPS();

        //NOTE: QmBoneOnUnityのコンストラクタが再帰的に子要素のインスタンスを生成
        _rootBone = new QumaBone2Humanoid(_model.Root, StandardPSBones.Hips, null);

        if (PdkManager.ConnectedDeviceCount == 0)
        {
            Debug.LogWarning("QUMARION was not found");
        }
        else
        {
            _model.AttachQumarion(PdkManager.GetDefaultQumarion());
            _model.AccelerometerRestrictMode = AccelerometerRestrictMode.None;
        }

        if (animator == null)
        {
            animator = GetComponent <Animator>();
        }

        //キャラをTポーズにするために必要な回転の情報をキャッシュします。
        _initialRotations = _targetBones.ToDictionary(
            b => b,
            b => animator.GetBoneTransform(b).localRotation
            );

        InitializePseudAxis();
    }
Exemple #2
0
    /// <summary>Qumarion側のボーン情報と親ボーンを指定してインスタンスを初期化します。</summary>
    /// <param name="bone">Qumarion側のボーン</param>
    /// <param name="boneType">Qumarion側のボーンが標準ボーンのどれに該当するか</param>
    /// <param name="parent">親ボーン(ルートのボーンを生成する場合nullを指定)</param>
    public QumaBone2Humanoid(Bone bone, StandardPSBones boneType, QumaBone2Humanoid parent)
    {
        _bone   = bone;
        _parent = parent;

        QumaBoneType = boneType;
        //StandardPSBones -> HumanBodyBoneの対応付けがあれば登録し、無い場合は無いことを確認。
        try
        {
            HumanBodyBone        = QmBoneToAnimatorBone.GetHumanBodyBone(boneType);
            IsValidHumanBodyBone = true;
        }
        catch (KeyNotFoundException)
        {
            HumanBodyBone        = HumanBodyBones.Hips;
            IsValidHumanBodyBone = false;
        }

        InitialRotation = MatrixToQuaternionWithCoordinateModify(_bone.InitialLocalMatrix);

        //ゼロ回転状態での固定座標軸を参照するため親のワールド座標を確認: ルート(Hips)はワールド座標直下。
        Matrix4f initMat = (_bone.Parent != null) ?
                           _bone.Parent.InitialWorldMatrix :
                           Matrix4f.Unit;


        //疑似座標系の初期化: Qumarion側の行列は右手系(左-上-前)なので正負補正が必要な事に注意。
        //NOTE: Qumarionの場合ルートが原点、回転は無しとみなすと次のように簡単化される
        xAxis = new Vector3(initMat.M11, -initMat.M21, -initMat.M31);
        yAxis = new Vector3(-initMat.M12, initMat.M22, initMat.M32);
        zAxis = new Vector3(-initMat.M13, initMat.M23, initMat.M33);

        //再帰的に子ボーンを初期化。
        _childs = bone
                  .Childs
                  .Select(b => new QumaBone2Humanoid(b, StandardPSBonesUtil.GetStandardPSBone(b.Name), this))
                  .ToArray();
    }