示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (proxy == null)
        {
            proxy = GetComponent <VRMBlendShapeProxy>();
        }
        else
        {
            proxy.SetValue(BlendShapePreset.Joy, 1.0f);

            //表情処理終章後にカウント開始
            TimeCount -= Time.deltaTime;
            if (TimeCount <= 2)
            {
                proxy.SetValue(BlendShapePreset.Joy, 0f);
                //表情変化
                proxy.SetValue(BlendShapePreset.Fun, 1.0f);
            }
            //カウントが0になったら=この場合は3秒経ったら
            if (TimeCount <= 0)
            {
                proxy.SetValue(BlendShapePreset.Fun, 0f);
                //表情変化
                proxy.SetValue(BlendShapePreset.Sorrow, 1.0f);
            }
        }
    }
示例#2
0
 void FixedUpdate()
 {
     if (blendshape == null)
     {
         return;
     }
     blendshape.SetValue(Small, dummyBlendShape.GetBlendShapeWeight(0) / 100f);
     blendshape.SetValue(Medium, dummyBlendShape.GetBlendShapeWeight(1) / 100f);
     blendshape.SetValue(Large, dummyBlendShape.GetBlendShapeWeight(2) / 100f);
 }
    /// <summary>
    ///
    /// </summary>
    private void Blink()
    {
        if (!blendShapeProxy)
        {
            return;
        }

        float now = Time.timeSinceLevelLoad;
        float span;

        switch (blinkState)
        {
        case 1:
            span = now - lastBlinkTime;
            if (span > BlinkTime)
            {
                blinkState = 2;
                blendShapeProxy.SetValue(BlendShapePreset.Blink, 1f);
            }
            else
            {
                blendShapeProxy.SetValue(BlendShapePreset.Blink, (span / BlinkTime));
            }
            break;

        case 2:
            span = now - lastBlinkTime - BlinkTime;
            if (span > BlinkTime)
            {
                blinkState = 0;
                blendShapeProxy.SetValue(BlendShapePreset.Blink, 0f);
            }
            else
            {
                blendShapeProxy.SetValue(BlendShapePreset.Blink, (1f - span) / BlinkTime);
            }
            break;

        default:
            if (now >= nextBlinkTime)
            {
                lastBlinkTime = now;
                if (Random.value < 0.2f)
                {
                    nextBlinkTime = now;                                // 20%の確率で連続まばたき
                }
                else
                {
                    nextBlinkTime = now + Random.Range(1f, 10f);
                }
                blinkState = 1;
            }
            break;
        }
    }
示例#4
0
 private void Update()
 {
     if (clearFlag)
     {
         _blendShapeProxy.SetValue(FacialExpressions.Joy.ToString(), 1.0f);
     }
     else if (!clearFlag)
     {
         _blendShapeProxy.SetValue(FacialExpressions.VerySorrow.ToString(), 1.0f);
     }
 }
示例#5
0
 private void CreateAnimation()
 {
     if (animationController == null)
     {
         animationController = new AnimationController();
     }
     animationController.ClearAnimations();
     animationController.AddResetAction(() => proxy.SetValue(BlendShapePreset.Blink, 0.0f));
     animationController.AddWait(null, () => BlinkTimeMin + Random.value * (BlinkTimeMax - BlinkTimeMin));
     animationController.AddAnimation(CloseAnimationTime, 0.0f, 1.0f, v => proxy.SetValue(BlendShapePreset.Blink, v));
     animationController.AddWait(ClosingTime);
     animationController.AddAnimation(OpenAnimationTime, 1.0f, 0.0f, v => proxy.SetValue(BlendShapePreset.Blink, v));
 }
示例#6
0
        protected IEnumerator BlinkRoutine()
        {
            while (true)
            {
                var waitTime = Time.time + Random.value * m_interVal;
                while (waitTime > Time.time)
                {
                    if (Request)
                    {
                        m_request = false;
                        break;
                    }
                    yield return(null);
                }

                // close
                var value      = 0.0f;
                var closeSpeed = 1.0f / m_closeSeconds;
                while (true)
                {
                    value += Time.deltaTime * closeSpeed;
                    if (value >= 1.0f)
                    {
                        break;
                    }

                    BlendShapes.SetValue(BlendShapePreset.Blink, value);
                    yield return(null);
                }
                BlendShapes.SetValue(BlendShapePreset.Blink, 1.0f);

                // wait...
                yield return(new WaitForSeconds(m_closingTime));

                // open
                value = 1.0f;
                var openSpeed = 1.0f / m_openingSeconds;
                while (true)
                {
                    value -= Time.deltaTime * openSpeed;
                    if (value < 0)
                    {
                        break;
                    }

                    BlendShapes.SetValue(BlendShapePreset.Blink, value);
                    yield return(null);
                }
                BlendShapes.SetValue(BlendShapePreset.Blink, 0);
            }
        }
    //OVRLiySyncの処理を VRM の VRMBlendShapeProxy に対応させる
    private void LipSyncConversion()
    {
        int   LipType  = 0;
        float LipValue = 0.0f;
        float Value;

        // VRMLipValue[0] は「無音時に1を返す処理」の為、iに0を含めない
        for (int i = 1; i < 15; i++)
        {
            Value = morphTarget.VRMLipValue[i];
            //1番大きい値の時にLipTypeを更新
            if (LipValue < Value && i != 0)
            {
                LipValue = Value;
                LipType  = i;
            }
        }

        switch (LipType)
        {
        case 10:
            VrmProxy.SetValue(BlendShapePreset.A, LipValue / LipSyncSensitivity);
            break;

        case 12:
            VrmProxy.SetValue(BlendShapePreset.I, LipValue / LipSyncSensitivity);
            break;

        case 14:
            VrmProxy.SetValue(BlendShapePreset.U, LipValue / LipSyncSensitivity);
            break;

        case 11:
            VrmProxy.SetValue(BlendShapePreset.E, LipValue / LipSyncSensitivity);
            break;

        case 13:
            VrmProxy.SetValue(BlendShapePreset.O, LipValue / LipSyncSensitivity);
            break;

        default:
            VrmProxy.SetValue(BlendShapePreset.A, 0);
            VrmProxy.SetValue(BlendShapePreset.I, 0);
            VrmProxy.SetValue(BlendShapePreset.U, 0);
            VrmProxy.SetValue(BlendShapePreset.E, 0);
            VrmProxy.SetValue(BlendShapePreset.O, 0);
            break;
        }
    }
    /// <summary>
    /// VRMBlendShapeProxy に対応させる
    /// </summary>
    void SetVisemeToMorphTarget(OVRLipSync.Frame frame)
    {
        int   LipType  = 0;
        float LipValue = 0.0f;
        float Value;

        // 0 は「無音時に1を返す処理」の為、iに0を含めない
        for (int i = 1; i < 15; i++)
        {
            Value = frame.Visemes[i];
            //1番大きい値の時にLipTypeを更新
            if (LipValue < Value && i != 0)
            {
                LipValue = Value;
                LipType  = i;
            }
        }
        switch (LipType)
        {
        case 10:
            proxy.SetValue(BlendShapePreset.A, LipValue);
            break;

        case 12:
            proxy.SetValue(BlendShapePreset.I, LipValue);
            break;

        case 14:
            proxy.SetValue(BlendShapePreset.U, LipValue);
            break;

        case 11:
            proxy.SetValue(BlendShapePreset.E, LipValue);
            break;

        case 13:
            proxy.SetValue(BlendShapePreset.O, LipValue);
            break;

        default:
            proxy.SetValue(BlendShapePreset.A, 0);
            proxy.SetValue(BlendShapePreset.I, 0);
            proxy.SetValue(BlendShapePreset.U, 0);
            proxy.SetValue(BlendShapePreset.E, 0);
            proxy.SetValue(BlendShapePreset.O, 0);
            break;
        }
    }
示例#9
0
 /// <summary>
 /// リップシンク
 /// </summary>
 private void SetLipSync()
 {
     this.UpdateAsObservable()
     .Subscribe(_ =>
     {
         var currentFrame = _lipSyncContext.GetCurrentPhonemeFrame();
         _blendShapeProxy.SetValue(BlendShapePreset.A, currentFrame.Visemes[(int)OVRLipSync.Viseme.aa], false);
         _blendShapeProxy.SetValue(BlendShapePreset.I, currentFrame.Visemes[(int)OVRLipSync.Viseme.ih], false);
         _blendShapeProxy.SetValue(BlendShapePreset.U, currentFrame.Visemes[(int)OVRLipSync.Viseme.ou], false);
         _blendShapeProxy.SetValue(BlendShapePreset.E, currentFrame.Visemes[(int)OVRLipSync.Viseme.E], false);
         _blendShapeProxy.SetValue(BlendShapePreset.O, currentFrame.Visemes[(int)OVRLipSync.Viseme.oh], false);
     });
 }
示例#10
0
    private IEnumerator EaseIn(string key, float from, float to)
    {
        var   setting  = m_BlendShapeMap[key];
        float time     = 0f;
        float progress = from;

        while (time < setting.m_EaseInTime)
        {
            time     += Time.deltaTime;
            progress += Time.deltaTime / setting.m_EaseInTime;

            m_BlendShape.SetValue(setting.m_Key, progress);
            yield return(null);
        }

        m_BlendShape.SetValue(setting.m_Key, to);
    }
        void Update()
        {
            if (isMoving && isArrivedDestination)
            {
                StopRunning();
            }

            if (!isMoving)
            {
                _time += Time.deltaTime;
                _blendShapeProxy.SetValue(FacialExpressions.Puzzle.ToString(), 1);

                if (_time > 3.0f)
                {
                    StartRunning();
                }
            }
        }
示例#12
0
        IEnumerator RoutineNest(BlendShapePreset preset, float velocity, float wait)
        {
            for (var value = 0.0f; value <= 1.0f; value += velocity)
            {
                BlendShapes.SetValue(preset, value);
                yield return(null);
            }
            BlendShapes.SetValue(preset, 1.0f);
            yield return(new WaitForSeconds(wait));

            for (var value = 1.0f; value >= 0; value -= velocity)
            {
                BlendShapes.SetValue(preset, value);
                yield return(null);
            }
            BlendShapes.SetValue(preset, 0);
            yield return(new WaitForSeconds(wait * 2));
        }
 void Start()
 {
     isMoving             = false;
     _animator            = GetComponent <Animator>();
     isArrivedDestination = false;
     _destinationX        = 0;
     _blendShapeProxy     = GetComponent <VRMBlendShapeProxy>();
     _blendShapeProxy.SetValue(FacialExpressions.Puzzle.ToString(), 1);
 }
示例#14
0
    // Update is called once per frame
    void Update()
    {
        if (proxy == null)
        {
            Debug.Log("null");
            proxy = GetComponent <VRMBlendShapeProxy>();
        }
        else
        {
            //キーボード入力
            if (Input.GetKey(KeyCode.D))
            {
                Debug.Log("yuri");
                //表情呼び出し
                proxy.SetValue(BlendShapePreset.Joy, 1.0f);
                //proxy.SetValue(BlendShapePreset.Extra, 1.0f);
            }
            else
            {
                proxy.SetValue("Neutral", 0f);
            }

            if (Input.GetKey(KeyCode.DownArrow))
            {
                proxy.SetValue("Fun", 1.0f);
            }
            else
            {
                proxy.SetValue("Fun", 0f);
            }

            if (Input.GetKey(KeyCode.RightArrow))
            {
                proxy.SetValue("Joy", 1.0f);
            }
            else
            {
                proxy.SetValue("Joy", 0f);
            }

            if (Input.GetKey(KeyCode.LeftArrow))
            {
                proxy.SetValue("Sorrow", 1.0f);
            }
            else
            {
                proxy.SetValue("Sorrow", 0f);
            }
        }
    }
        IEnumerator BlinkCoroutine(VRMBlendShapeProxy proxy)
        {
            float blinkParameter = 0;

            blinkParameter = Mathf.Clamp01(blinkParameter);

            while (blinkParameter <= 1)
            {
                proxy.SetValue(BlendShapePreset.Sorrow, Mathf.Lerp(0, 1.0f, blinkParameter * 15));
                yield return(null);

                blinkParameter += Time.deltaTime;
            }
        }
示例#16
0
    void SetVisemeToMorphTarget(OVRLipSync.Frame frame)
    {
        foreach (OVRLipSync.Viseme viseme in visemes)
        {
            int index = (int)viseme;
            switch (viseme)
            {
            case OVRLipSync.Viseme.aa:
                blendShapeProxy.SetValue(BlendShapePreset.A, Mathf.Clamp01(frame.Visemes[index] * gain));
                break;

            case OVRLipSync.Viseme.E:
                blendShapeProxy.SetValue(BlendShapePreset.E, Mathf.Clamp01(frame.Visemes[index] * gain));
                break;

            case OVRLipSync.Viseme.ih:
                blendShapeProxy.SetValue(BlendShapePreset.I, Mathf.Clamp01(frame.Visemes[index] * gain));
                break;

            case OVRLipSync.Viseme.oh:
                blendShapeProxy.SetValue(BlendShapePreset.O, Mathf.Clamp01(frame.Visemes[index] * gain));
                break;

            case OVRLipSync.Viseme.ou:
                blendShapeProxy.SetValue(BlendShapePreset.U, Mathf.Clamp01(frame.Visemes[index] * gain));
                break;

            default:
                blendShapeProxy.SetValue(BlendShapePreset.A, 0);
                blendShapeProxy.SetValue(BlendShapePreset.I, 0);
                blendShapeProxy.SetValue(BlendShapePreset.U, 0);
                blendShapeProxy.SetValue(BlendShapePreset.E, 0);
                blendShapeProxy.SetValue(BlendShapePreset.O, 0);
                break;
            }
        }
    }
示例#17
0
    // Update is called once per frame
    void Update()
    {
        if (proxy == null)
        {
            proxy = GetComponent <VRMBlendShapeProxy>();
        }
        else
        {
            proxy.SetValue(BlendShapePreset.Fun, 1.0f);

            //表情処理終章後にカウント開始
            TimeCount -= Time.deltaTime;

            //2秒経過した場合は変化(今回はJoy→Fun)
            if (TimeCount <= 6)
            {
                proxy.SetValue(BlendShapePreset.Fun, 0f);
                //表情変化
                proxy.SetValue("Sleepy", 1.0f);
            }

            if (TimeCount <= 4)
            {
                proxy.SetValue("Sleepy", 0f);
                //表情変化
                proxy.SetValue("SleepyMore", 1.0f);
            }
            if (TimeCount <= 3)
            {
                proxy.SetValue("SleepyMore", 0f);
                //表情変化
                proxy.SetValue("Sleep", 1.0f);
            }
            if (TimeCount <= 0)
            {
                proxy.SetValue("Sleep", 0f);
                //表情変化
                proxy.SetValue("SleepBaka", 1.0f);
            }
        }
        //今回は自作blendshapeを使用し4段階に分けて行動をしております。
    }
示例#18
0
    private void UpdateVRMMorph(OVRLipSync.Frame frame)
    {
        if (!proxy)
        {
            // VRMBlendShapeProxyを探す
            proxy = FindObjectOfType <VRMBlendShapeProxy>();
        }

        if (!proxy)
        {
            return;
        }
        for (int i = 1; i < VisemeToBlendTargets.Length; i++)
        {
            if (VisemeToBlendTargets[i] != -1)
            {
                proxy.SetValue((BlendShapePreset)VisemeToBlendTargets[i], Mathf.Min(1.0f, frame.Visemes[i] * LipSyncSensitivity));
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (EnableLipSync)
        {
            if (Context != 0)
            {
                if (proxy == null)
                {
                    if (VRMmodel != null)
                    {
                        proxy = VRMmodel.GetComponent <VRMBlendShapeProxy>();
                    }
                }
                else
                {
                    // get the current viseme frame
                    OVRLipSync.Frame frame = GetCurrentPhonemeFrame();
                    if (frame != null)
                    {
                        //あ OVRLipSync.Viseme.aa; BlendShapePreset.A;
                        //い OVRLipSync.Viseme.ih; BlendShapePreset.I;
                        //う OVRLipSync.Viseme.ou; BlendShapePreset.U;
                        //え OVRLipSync.Viseme.E;  BlendShapePreset.E;
                        //お OVRLipSync.Viseme.oh; BlendShapePreset.O;
                        var presets = new BlendShapePreset[] {
                            BlendShapePreset.A,
                            BlendShapePreset.I,
                            BlendShapePreset.U,
                            BlendShapePreset.E,
                            BlendShapePreset.O,
                        };
                        var visemes = new float[] {
                            frame.Visemes[(int)OVRLipSync.Viseme.aa],
                            frame.Visemes[(int)OVRLipSync.Viseme.ih],
                            frame.Visemes[(int)OVRLipSync.Viseme.ou],
                            frame.Visemes[(int)OVRLipSync.Viseme.E],
                            frame.Visemes[(int)OVRLipSync.Viseme.oh],
                        };

                        int   maxindex   = 0;
                        float maxvisemes = 0;
                        for (int i = 0; i < presets.Length; i++)
                        {
                            if (visemes[i] < WeightThreashold)
                            {
                                visemes[i] = 0;
                            }
                            if (maxvisemes < visemes[i])
                            {
                                maxindex   = i;
                                maxvisemes = visemes[i];
                            }
                        }

                        if (MaxWeightEmphasis)
                        {
                            visemes[maxindex] = Mathf.Clamp(visemes[maxindex] * 3, 0.0f, 1.0f);
                        }

                        if (MaxWeightEnable)
                        {
                            for (int i = 0; i < presets.Length; i++)
                            {
                                if (i != maxindex)
                                {
                                    visemes[i] = 0.0f;
                                }
                            }
                        }

                        for (int i = 0; i < presets.Length; i++)
                        {
                            visemes[i] *= MaxLevel;
                            proxy.SetValue(presets[i], visemes[i]);
                        }


                        //Debug.Log("Visemes:" + string.Join(",", frame.Visemes.Select(d => d.ToString())));
                    }
                }
            }

            if (string.IsNullOrEmpty(selectedDevice) == false)
            {
                audioSource.volume = (sourceVolume / 100);
                if (!Microphone.IsRecording(selectedDevice))
                {
                    StartMicrophone();
                }

                if (EnableLowLatency)
                {
                    var position = Microphone.GetPosition(selectedDevice);
                    if (position < 0 || head == position)
                    {
                        return;
                    }

                    audioSource.clip.GetData(microphoneBuffer, 0);
                    while (GetDataLength(microphoneBuffer.Length, head, position) > processBuffer.Length)
                    {
                        var remain = microphoneBuffer.Length - head;
                        if (remain < processBuffer.Length)
                        {
                            Array.Copy(microphoneBuffer, head, processBuffer, 0, remain);
                            Array.Copy(microphoneBuffer, 0, processBuffer, remain, processBuffer.Length - remain);
                        }
                        else
                        {
                            Array.Copy(microphoneBuffer, head, processBuffer, 0, processBuffer.Length);
                        }

                        OVRLipSync.ProcessFrame(Context, processBuffer, Frame);

                        head += processBuffer.Length;
                        if (head > microphoneBuffer.Length)
                        {
                            head -= microphoneBuffer.Length;
                        }
                    }
                }
            }
        }
    }
示例#20
0
 public void RewardTime()
 {
     proxy.SetValue(BlendShapePreset.Fun, 1f);
     anim.Play("reward");
     anim.SetInteger("animInt", 1);
 }