void Reset() { BlendShapes = GetComponent <VRMBlendShapeProxy>(); }
// Update is called once per frame void Update() { if (EnableLipSync) { if (Context != 0) { if (proxy == 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++) { 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; } } } } } }
void Start() { BlendShapeProxy = GetComponent <VRMBlendShapeProxy>(); Init(); }
public void ImportVRMmodel(GameObject vrmmodel) { VRMmodel = vrmmodel; proxy = null; }
void Update() { //モデルが更新されたときのみ読み込み if (Model != null && OldModel != Model) { animator = Model.GetComponent <Animator>(); blendShapeProxy = Model.GetComponent <VRMBlendShapeProxy>(); OldModel = Model; } if (Model != null && animator != null && uClient != null) { //Root var RootTransform = Model.transform; if (RootTransform != null) { uClient.Send("/VMC/Ext/Root/Pos", "root", RootTransform.position.x, RootTransform.position.y, RootTransform.position.z, RootTransform.rotation.x, RootTransform.rotation.y, RootTransform.rotation.z, RootTransform.rotation.w); } //Bones foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones))) { if (bone != HumanBodyBones.LastBone) { var Transform = animator.GetBoneTransform(bone); if (Transform != null) { uClient.Send("/VMC/Ext/Bone/Pos", bone.ToString(), Transform.localPosition.x, Transform.localPosition.y, Transform.localPosition.z, Transform.localRotation.x, Transform.localRotation.y, Transform.localRotation.z, Transform.localRotation.w); } } } //ボーン位置を仮想トラッカーとして送信 SendBoneTransformForTracker(HumanBodyBones.Head, "Head"); SendBoneTransformForTracker(HumanBodyBones.Spine, "Spine"); SendBoneTransformForTracker(HumanBodyBones.LeftHand, "LeftHand"); SendBoneTransformForTracker(HumanBodyBones.RightHand, "RightHand"); SendBoneTransformForTracker(HumanBodyBones.LeftFoot, "LeftFoot"); SendBoneTransformForTracker(HumanBodyBones.RightFoot, "RightFoot"); //BlendShape if (blendShapeProxy != null) { foreach (var b in blendShapeProxy.GetValues()) { uClient.Send("/VMC/Ext/Blend/Val", b.Key.ToString(), (float)b.Value ); } uClient.Send("/VMC/Ext/Blend/Apply"); } //Available uClient.Send("/VMC/Ext/OK", 1); } else { uClient.Send("/VMC/Ext/OK", 0); } uClient.Send("/VMC/Ext/T", Time.time); }