Пример #1
0
 public float GetValue(BlendShapePreset key)
 {
     return(GetValue(new BlendShapeKey(key)));
 }
Пример #2
0
 public void SetPreset(BlendShapePreset preset)
 {
     StartCoroutine(SetBlendShape(preset));
 }
Пример #3
0
 public void SetValue(BlendShapePreset key, float value, bool apply = true)
 {
     SetValue(new BlendShapeKey(key), value, apply);
 }
Пример #4
0
 private BlendShapeKey GetKey(BlendShapePreset preset)
 {
     return(keyList[GetKeyIndex(preset)]);
 }
    // 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, OVRLipSync.Flags.None, Frame);

                        head += processBuffer.Length;
                        if (head > microphoneBuffer.Length)
                        {
                            head -= microphoneBuffer.Length;
                        }
                    }
                }
            }
        }
    }
 public void MixPreset(string presetName, BlendShapePreset preset, float value)
 {
     MixPresets(presetName, new[] { preset }, new[] { value });
 }
Пример #7
0
 private int GetKeyIndex(BlendShapePreset preset)
 {
     return(keyList.FindIndex(d => d.Name == preset.ToString().ToUpper()));
 }
Пример #8
0
 public BlendShapeClip GetClip(BlendShapePreset preset)
 {
     return(GetClip(new BlendShapeKey(preset)));
 }
 public void SetFace(BlendShapePreset preset, float strength, bool stopBlink)
 {
     SetFace(BlendShapeKey.CreateFromPreset(preset), strength, stopBlink);
 }
Пример #10
0
 public static void AccumulateValue(this VRMBlendShapeProxy proxy, BlendShapePreset key, float value)
 {
     proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(key), value);
 }
Пример #11
0
 public BlendShape(BlendShapePreset preset, string name, bool isBinary)
 {
     Preset   = preset;
     Name     = name;
     IsBinary = isBinary;
 }
Пример #12
0
 public static void ImmediatelySetValue(this VRMBlendShapeProxy proxy, BlendShapePreset key, float value)
 {
     proxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(key), value);
 }
Пример #13
0
 public static float GetValue(this VRMBlendShapeProxy proxy, BlendShapePreset key)
 {
     return(proxy.GetValue(BlendShapeKey.CreateFromPreset(key)));
 }
Пример #14
0
 public static bool HasPresetLayer(BlendShapePreset preset)
 {
     return(kPresetLayer.ContainsKey(preset));
 }
Пример #15
0
 public void AccumulateValue(BlendShapePreset preset, float value)
 {
     ImmediatelySetValue(new BlendShapeKey(preset), value);
 }
Пример #16
0
        /// <summary>
        /// Set a blendShape value immediate
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void SetValue(BlendShapePreset key, float value)
        {
#pragma warning disable 0618
            SetValue(new BlendShapeKey(key), value, true);
#pragma warning restore 0618
        }