public ModelHandler()
        {
            QumarionModel = PdkManager.CreateStandardModelPS();
            _rootBone     = new QumaBone2MikuMikuMoving(QumarionModel.Root, StandardPSBones.Hips, null);

            TryAttachQumarionToModel();
        }
    /// <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();
    }
Example #3
0
 public void Initialize()
 {
     //ライブラリ初期化してモデルを一つだけ持つ(MMDのモデル数の分だけ作る戦略も無くはない)
     PdkManager.Initialize();
     _modelHandler = new ModelHandler();
     _setting      = new QumarionSettingHolder();
     _modelAdapter = new ModelHandlerSettingAdapter(_modelHandler);
     _modelAdapter.Connect(_setting);
 }
Example #4
0
 void Start()
 {
     //PCに接続中のQUMARIONがあるかどうかチェックし、存在する場合は接続
     if (PdkManager.ConnectedDeviceCount > 0)
     {
         _qumarion = PdkManager.GetDefaultQumarion();
     }
     else
     {
         Debug.LogWarning("Qumarion was not found");
     }
 }
        /// <summary>
        /// PCに接続されたQumarionがあればモデルに関連づけます。
        /// 複数のQumarionがある場合の選択は自動で行われます。</summary>
        /// <returns>接続成功または既に接続済みだった場合<see cref="true"/></returns>
        public bool TryAttachQumarionToModel()
        {
            if (QumarionModel.AttachedQumarion != null)
            {
                return(true);
            }

            if (PdkManager.ConnectedDeviceCount == 0)
            {
                return(false);
            }

            QumarionModel.AttachQumarion(PdkManager.GetDefaultQumarion());
            return(true);
        }
    //描画ターゲットの初期化とデバイスへの接続を行います。
    void Start()
    {
        _model = PdkManager.CreateStandardModelPS();

        //ボーンを一つ残らず初期配置
        //NOTE: ここではボーンの階層構造を作らずすべてRoot直下に置いてる事に注意!
        _spheres = _model.Bones
                   .ToDictionary(
            bone => bone.Key,
            bone =>
        {
            var s                  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            s.name                 = bone.Value.Name;
            s.transform.parent     = this.transform;
            s.transform.localScale = new Vector3(.05f, .05f, .05f);

            var t = bone.Value.InitialWorldMatrix.Translate;
            //NOTE: QUMARIONのボーンはcm単位らしいので0.01倍に縮める
            s.transform.localPosition = 0.01f * new Vector3(-t.X, t.Y, t.Z);
            return(s);
        });

        //ボーン間の線を書くためのオブジェクトを用意
        _drawableBones = _model.Bones
                         .Where(kvp => kvp.Key != StandardPSBones.Hips)
                         .Select(kvp =>
        {
            var childSphere  = _spheres[kvp.Key];
            var parentSphere = _spheres[StandardPSBonesUtil.GetStandardPSBone(_model.Bones[kvp.Key].Parent.Name)];

            return(new DrawableBone(parentSphere, childSphere));
        })
                         .ToArray();

        if (PdkManager.ConnectedDeviceCount == 0)
        {
            Debug.LogWarning("QUMARION was not found");
        }
        else
        {
            _model.AttachQumarion(PdkManager.GetDefaultQumarion());
            _model.AttachedQumarion.EnableAccelerometer = false;
            _model.AccelerometerMode         = AccelerometerMode.Direct;
            _model.AccelerometerRestrictMode = AccelerometerRestrictMode.None;
        }
    }
    /// <summary>Qumarionの動作を適用するモデルの生成と、デバイスとの接続を行います。</summary>
    void Start()
    {
        _model = PdkManager.CreateStandardModelPS();
        //NOTE: ルート以下については再帰的に生成する感じのアレ
        _rootBone = new BoneForPdkTreeVisualizer(_model.Root, null);
        _rootBone.BoneObject.transform.parent = transform;

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