Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (VRMmodel != null)
        {
            if (proxy == null)
            {
                proxy = VRMmodel.GetComponent <VRMBlendShapeProxy>();
                //すべての表情の名称一覧を取得
                if (proxy != null)
                {
                    BlendShapeKeys = proxy.BlendShapeAvatar.Clips.Select(d => BlendShapeKey.CreateFrom(d).Name).ToList();
                }
            }
            if (IsSetting == false)
            {
                if (EnableBlink && ViveProEyeEnabled == false)
                {
                    isReset = false;
                    if (StopBlink == false)
                    {
                        if (animationController?.Next() == false)
                        {//最後まで行ったら値更新のためにアニメーション作り直す
                            CreateAnimation();
                        }
                    }
                }
                else
                {
                    if (isReset == false)
                    {
                        isReset = true;
                        animationController?.Reset();
                    }
                }

                if (DefaultFace != BlendShapePreset.Neutral && proxy != null)
                {
                    if (DefaultFace != BlendShapePreset.Unknown)
                    {
                        proxy.SetValue(DefaultFace, 1.0f);
                    }
                    else if (string.IsNullOrEmpty(FacePresetName) == false)
                    {
                        proxy.SetValue(FacePresetName, 1.0f);
                    }
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (VRMmodel != null)
        {
            if (proxy == null)
            {
                proxy = VRMmodel.GetComponent <VRMBlendShapeProxy>();
                //すべての表情の名称一覧を取得
                if (proxy != null)
                {
                    BlendShapeKeys = proxy.BlendShapeAvatar.Clips.Select(d => BlendShapeKey.CreateFrom(d).Name).ToList();
                }
                SetFaceNeutral();
            }
            if (IsSetting == false)
            {
                if (EnableBlink && ViveProEyeEnabled == false)
                {
                    isReset = false;
                    if (StopBlink == false)
                    {
                        if (animationController?.Next() == false)
                        {//最後まで行ったら値更新のためにアニメーション作り直す
                            CreateAnimation();
                        }
                    }
                }
                else
                {
                    if (isReset == false)
                    {
                        isReset = true;
                        animationController?.Reset();
                    }
                }
            }

            AccumulateBlendShapes();
        }
    }
Esempio n. 3
0
        public void Update()
        {
            //エラー・無限ループ時は処理をしない
            if (shutdown)
            {
                return;
            }

            //Freeze有効時は動きを一切止める
            if (Freeze)
            {
                return;
            }

            LastPacketframeCounterInFrame = PacketCounterInFrame;
            PacketCounterInFrame          = 0;

            //5.6.3p1などRunInBackgroundが既定で無効な場合Unityが極めて重くなるため対処
            Application.runInBackground = true;

            //VRMモデルからBlendShapeProxyを取得(タイミングの問題)
            if (blendShapeProxy == null && Model != null)
            {
                blendShapeProxy = Model.GetComponent <VRMBlendShapeProxy>();
            }

            //ルート位置がない場合
            if (RootPositionTransform == null && Model != null)
            {
                //モデル姿勢をルート姿勢にする
                RootPositionTransform = Model.transform;
            }

            //ルート回転がない場合
            if (RootRotationTransform == null && Model != null)
            {
                //モデル姿勢をルート姿勢にする
                RootRotationTransform = Model.transform;
            }

            //モデルがない場合はエラー表示をしておく(親切心)
            if (Model == null)
            {
                StatusMessage = "Model not found.";
                return;
            }

            //モデルが更新されたときに関連情報を更新する
            if (OldModel != Model && Model != null)
            {
                animator        = Model.GetComponent <Animator>();
                blendShapeProxy = Model.GetComponent <VRMBlendShapeProxy>();
                OldModel        = Model;

                Debug.Log("[ExternalReceiver] New model detected");

                //v0.55ブレンドシェープ仕様変更対応
                if (VRMVersion.MAJOR >= 0 && VRMVersion.MINOR > 53)
                {
                    //ブレンドシェープ小文字変換テーブルをクリアする(通信用)
                    blendShapeProxyCaseBuffer.Clear();

                    //ブレンドシェーププリセット変換テーブルを作成する
                    //Debug.Log("-- Make BlendShapeProxy TypeConverter Table --");
                    foreach (string presetName in Enum.GetNames(typeof(BlendShapePreset)))
                    {
                        BlendShapePresetCaseConverter[presetName.ToLower()] = presetName;

                        //Debug.Log("Register Table: " + presetName.ToLower() + " -> " + presetName);
                    }
                    //Debug.Log("-- End BlendShapeProxy TypeConverter Table --");

                    //ブレンドシェープ互換性テーブルを作成する(非ケースセンシティブ->ケースセンシティブ)
                    blendShapeProxyCaseConverter.Clear();
                    //Debug.Log("-- Make BlendShapeProxy CaseConverter Table --");

                    //小文字をキーにした辞書を作成
                    foreach (var c in blendShapeProxy.BlendShapeAvatar.Clips)
                    {
                        try
                        {
                            var       k         = BlendShapeKey.CreateFrom(c);
                            FieldInfo fieldInfo = typeof(BlendShapeKey).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance);
                            string    RawKey    = (string)fieldInfo.GetValue(k);
                            //Debug.Log("UniVRM: " + k.Name + " Refrection:" + RawKey);

                            string key     = k.ToString().ToLower();
                            string keyname = k.Name.ToLower();
                            blendShapeProxyCaseConverter[key]     = RawKey;
                            blendShapeProxyCaseConverter[keyname] = RawKey;

                            //Debug.Log("Register Table: " + key + " -> " + RawKey);
                            //Debug.Log("Register Table: " + keyname + " -> " + RawKey);
                        }
                        catch (Exception e)
                        {
                            Debug.LogError(e.ToString());
                        }
                    }

                    //Debug.Log("-- End BlendShapeProxy CaseConverter Table --");
                }
            }

            BoneSynchronizeByTable();
        }