public void Invoke(BlendShapeKey Key) { if (!IsActive) { return; } foreach (var e in expressions) { if (e.ActualKey.Equals(Key)) { if (!changer.IsAnimating(e.ActualKey)) { IsBlinkActive = e.CanBlink; blinker.TightnessCollection = e.BlinkTightnessCollection; blinker.TurnDown(); changer.Append(e.ActualKey, e.CreateTransition(ChangeDuration)); } } else { // 指定以外の表情を解除する changer.TurnDown(e.ActualKey, ChangeDuration); } } }
/// <summary> /// Word To Motionによるブレンドシェイプを指定します。 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <remarks>1つ以上のブレンドシェイプを指定すると通常の表情制御をオーバーライドする。</remarks> public void Add(BlendShapeKey key, float value) { if (_allBlendShapeKeys.Any(k => k.Name == key.Name)) { _blendShape[key] = value; } }
private void OnDisable() { BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.A), 0); Debug.Log("teste"); StopCoroutine(m_coroutine); }
/// <summary> /// 現在の表情を適用 /// </summary> private void UpdateEmotion() { if (!blendShapeProxy) { return; } if (!randomEmotion) { return; // 現状、ランダムが解除されていたら何もしない(戻さない) } var blendShapes = new List <KeyValuePair <BlendShapeKey, float> >(); int index = 0; foreach (var shape in EmotionPresets) { float val = 0f; // 現在選ばれている表情のみ値を入れ、他はゼロとする if (index == emotionIndex) { val = emotionRate; } blendShapes.Add(new KeyValuePair <BlendShapeKey, float>(BlendShapeKey.CreateFromPreset(shape), val)); index++; } blendShapeProxy.SetValues(blendShapes); UpdateUI(); }
public void Update() { if (proxy == null) { proxy = gameObject.GetComponentInParent <VRMBlendShapeProxy>(); foreach (var clip in proxy.BlendShapeAvatar.Clips) { BlendShapeKey key = BlendShapeKey.CreateFromClip(clip); if (key.Name.ToUpper() == blendShapeClipName.ToUpper()) { found = true; blendShapeKey = key; break; } } if (!found) { Debug.Log("VRM blend shape clip not found: " + blendShapeClipName); } } if (found) { proxy.ImmediatelySetValue(blendShapeKey, blendShapeClipValue); } }
public float GetValue(BlendShapeKey key) { if (_merger == null) { return(0); } return(_merger.GetValue(key)); }
public void SetFace(BlendShapeKey key, float strength, bool stopBlink) { SetFace(new List <string> { key.Name }, new List <float> { strength }, stopBlink); }
//Called by BlendShapeControlTrack from GatherProperties Method public string LoadBlendShapeTargets(BlendShapeTarget[] newTargets, List <string> clipGuids) { if (newTargets.Length == 0) { return(""); } if (BCBGuid == Guid.Empty.ToString()) { //new BlendShapeControlBehaviour, make guid and target array blendShapeKeys = new BlendShapeKey[newTargets.Length]; blendShapeKeyInfos = new BlendShapeKeyInfo[newTargets.Length]; GenerateGuid(); for (int i = 0; i < newTargets.Length; i++) { BlendShapeKey newKey = ScriptableObject.CreateInstance(typeof(BlendShapeKey)) as BlendShapeKey; newKey.init(newTargets[i].BlendShapeName, i, newTargets[i].BlendShapeValue); newKey.updateBlendValue += UpdateBlendValues; blendShapeKeys[i] = newKey; blendShapeKeyInfos[i] = new BlendShapeKeyInfo(newKey.BlendShapeName, i, newKey.BlendShapeValue); } } else { // BlendShapeControlBehaviour already exists blendShapeKeys = new BlendShapeKey[newTargets.Length]; if (clipGuids.Contains(BCBGuid)) { // BCBGuid duplicates existing one, therefore, this must be a new duplicate // and needs a fresh guid GenerateGuid(); // need to copy values from old objects to new object for (int i = 0; i < newTargets.Length; i++) { BlendShapeKey newKey = ScriptableObject.CreateInstance(typeof(BlendShapeKey)) as BlendShapeKey; newKey.init(blendShapeKeyInfos[i].BlendShapeName, i, blendShapeKeyInfos[i].BlendShapeValue); newKey.updateBlendValue += UpdateBlendValues; blendShapeKeys[i] = newKey; } } else { //BCBGuid for this clip is unique, therefore do nothing unless list of blend shapes on BlendShapeController has changed //doesn't need a fresh guid for (int i = 0; i < newTargets.Length; i++) { BlendShapeKey newKey = ScriptableObject.CreateInstance(typeof(BlendShapeKey)) as BlendShapeKey; newKey.init(blendShapeKeyInfos[i].BlendShapeName, i, blendShapeKeyInfos[i].BlendShapeValue); newKey.updateBlendValue += UpdateBlendValues; blendShapeKeys[i] = newKey; } } } return(BCBGuid); }
private void SetFaceNeutral() { //表情をデフォルトに戻す if (proxy != null) { var NeutralKey = new BlendShapeKey(BlendShapePreset.Neutral); proxy.SetValues(BlendShapeKeys.Select(d => { var k = new BlendShapeKey(d); return(new KeyValuePair <BlendShapeKey, float>(k, k.Equals(NeutralKey) ? 1.0f : 0.0f)); })); proxy.Apply(); } }
private static BlendShapeKey[] CreateKeys(IEnumerable <string> names) { return(names .Select(n => _presetKeys.ContainsKey(n) ? _presetKeys[n] : BlendShapeKey.CreateUnknown(n) ) .ToArray()); }
public void AppendIfNot(BlendShapeKey clipKey, Transition <float> transition) { if (!IsActive) { return; } if (!IsAnimating(clipKey)) { transitions.Add(clipKey, new TransitionPlayer <float>(transition, VRM.GetValue(clipKey))); } }
public void SetLipShapeToBlendShapeStringMap(Dictionary <string, string> stringMap) { LipShapeToBlendShapeMap.Clear(); foreach (var map in stringMap) { if (LipShapeNameToEnumMap.ContainsKey(map.Key)) { var blendShapeKey = new BlendShapeKey(map.Value); LipShapeToBlendShapeMap[LipShapeNameToEnumMap[map.Key]] = blendShapeKey; } } }
private void LateUpdate() { _currentAngle += _angluarVelocity * Time.deltaTime * Mathf.Deg2Rad; var x = Mathf.Cos(_currentAngle) * (_sphereOrbitalRadius + _orbitalRadius.value); var z = Mathf.Sin(_currentAngle) * (_sphereOrbitalRadius + _orbitalRadius.value); var y = (_sphereInitialHeight + _verticalPosition.value) + _sphereMovableRangeInVertical * Mathf.Cos(_currentAngle / 3); if (_lookStraightAheadToggle.isOn) { if (_vrmModel != null) { // Make eyes static if (_lookAtBone) { _vrmModel.GetComponent<VRMLookAtBoneApplyer>().LeftEye.Transform = null; _vrmModel.GetComponent<VRMLookAtBoneApplyer>().RightEye.Transform = null; } else { _vrmModel.GetComponent<VRMLookAtBlendShapeApplyer>().m_notSetValueApply = true; var blednShapeProxy = _vrmModel.GetComponent<VRMBlendShapeProxy>(); blednShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookUp), 0.0f); blednShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookDown), 0.0f); blednShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookLeft), 0.0f); blednShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookRight), 0.0f); } } } transform.localPosition = new Vector3(x, y, z); // Fly-through viewpoint (virtual camera) if (_bvhGameObject != null) { if (_vrmModel != null) { var tLookAt = _vrmModel.GetComponent<VRMLookAtHead>().Head.position; transform.LookAt(new Vector3(tLookAt.x, tLookAt.y, tLookAt.z)); } else { transform.LookAt(new Vector3(0.0f, 1.2f, 0.0f)); } } else { transform.LookAt(new Vector3(0.0f, 1.2f, 0.0f)); } } // update
void Update() { m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.A), Lip_A); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.I), Lip_I); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.U), Lip_U); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.E), Lip_E); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.O), Lip_O); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), Blink); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Joy), Expression_Joy); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Angry), Expression_Angry); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Sorrow), Expression_Sorrow); m_proxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Fun), Expression_Fun); }
protected IEnumerator BlinkRoutine() { while (true) { var waitTime = Time.time + Random.value * interlavo; 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.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), value); yield return(null); } BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), 1.0f); // wait... yield return(new WaitForSeconds(closingTime)); // open value = 1.0f; var openSpeed = 1.0f / m_openingSeconds; while (true) { value -= Time.deltaTime * openSpeed; if (value < 0) { break; } BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), value); yield return(null); } BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), 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); } } } } }
/// <summary> /// Sets the viseme to morph target. /// </summary> void SetVisemeToMorphTarget(OVRLipSync.Frame frame) { if (!proxy) { return; } for (int i = 0; i < visemeToBlendTargets.Length; i++) { if (visemeToBlendTargets[i] != -1) { proxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset((BlendShapePreset)visemeToBlendTargets[i]), Mathf.Min(1.0f, frame.Visemes[i] * LipSyncSensitivity)); } } }
IEnumerator RoutineNest(BlendShapePreset preset, float velocity, float wait) { for (var value = 0.0f; value <= 1.0f; value += velocity) { BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), value); yield return(null); } BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), 1.0f); yield return(new WaitForSeconds(wait)); for (var value = 1.0f; value >= 0; value -= velocity) { BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), value); yield return(null); } BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), 0); yield return(new WaitForSeconds(wait * 2)); }
public void SetFace(List <string> keys, List <float> strength, bool stopBlink) { if (proxy != null) { StopBlink = stopBlink; var NeutralKey = new BlendShapeKey(BlendShapePreset.Neutral); var dict = new Dictionary <BlendShapeKey, float>(); foreach (var key in BlendShapeKeys) { dict.Add(new BlendShapeKey(key), 0.0f); } dict[NeutralKey] = 1.0f; for (int i = 0; i < keys.Count; i++) { dict[new BlendShapeKey(keys[i])] = strength[i]; } proxy.SetValues(dict.ToList()); proxy.Apply(); } }
public void Accumulate(VRMBlendShapeProxy proxy) { if (!_hasModel || string.IsNullOrEmpty(_externalTracker.FaceSwitchClipName) || _config.WordToMotionExpressionActive ) { return; } if (_latestClipName != _externalTracker.FaceSwitchClipName) { _latestKey = CreateKey(_externalTracker.FaceSwitchClipName); _latestClipName = _externalTracker.FaceSwitchClipName; } //ターゲットのキーだけいじり、他のクリップ状態については呼び出し元に責任を持ってもらう proxy.AccumulateValue(_latestKey, 1.0f); //表情を適用した = 目ボーンは正面向きになってほしい _eyeBoneResetter.ReserveReset = true; }
// 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(); } }
private void SetFaceNeutral() { //表情をデフォルトに戻す if (proxy != null) { var keys = new List <string>(); var values = new List <float>(); foreach (var keyname in BlendShapeKeys) { var shapekey = new BlendShapeKey(keyname); if (shapekey.Equals(NeutralKey)) { values.Add(1.0f); } else { values.Add(0.0f); } keys.Add(keyname); } SetFace(keys, values, StopBlink); } }
static void OnDefaultBlend(OVRLipSync.Frame frame, VRMBlendShapeProxy vrmBlendShapeProxy) { var visemes = new float[visemeToBlendTargets.Length]; Array.Copy(frame.Visemes, (int)OVRLipSync.Viseme.aa, visemes, 1, visemes.Length - 1); visemes[0] = frame.Visemes[(int)OVRLipSync.Viseme.sil]; var sum = visemes.Sum(); if (sum <= float.Epsilon) { visemes[0] = 1; } else { for (int i = 0; i < visemes.Length; ++i) { visemes[i] /= sum; } } for (int i = 0; i < visemes.Length; ++i) { vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(visemeToBlendTargets[i]), visemes[i]); } }
private void LateUpdate() { if (!_hasModel || string.IsNullOrEmpty(_externalTracker.FaceSwitchClipName) || _config.WordToMotionExpressionActive ) { return; } _proxy.Apply(); _initializer.InitializeBlendShapes(_externalTracker.KeepLipSyncForFaceSwitch); if (_latestClipName != _externalTracker.FaceSwitchClipName) { _latestKey = CreateKey(_externalTracker.FaceSwitchClipName); _latestClipName = _externalTracker.FaceSwitchClipName; } //NOTE: 最終的な適用はWordToMotionBlendShapeがやる。ので、ここではその前処理だけやってればよい _proxy.AccumulateValue(_latestKey, 1.0f); //表情を適用した = 目ボーンは正面向きになってほしい _eyeBoneResetter.ReserveReset = true; }
public void SetFace(BlendShapePreset preset, float strength, bool stopBlink) { SetFace(BlendShapeKey.CreateFromPreset(preset), strength, stopBlink); }
private static BlendShapeKey CreateKey(string name) => _presets.ContainsKey(name) ? BlendShapeKey.CreateFromPreset(_presets[name]) : BlendShapeKey.CreateUnknown(name);
public void MixPresets(string presetName, BlendShapePreset[] presets, float[] values) { MixPresets(presetName, presets.Select(d => BlendShapeKey.CreateFromPreset(d)).ToArray(), values); }
public BlendShapeKeyBinder(string name, Func <object, object> getter, Action <object, object> setter) { key = new BlendShapeKey(name); this.setter = setter; this.getter = getter; }
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(); }
public void MixPreset(string presetName, BlendShapeKey preset, float value) { MixPresets(presetName, new[] { preset }, new[] { value }); }