private DAZMorph RunMorphChange(BlendShapeReceivedEventArgs item) { var morph = GetMorph(SettingsController.GetShapeMorph(item?.Shape?.Name)); if (morph != null) { var multiplier = UIController.StorableBlendShapeStrength[item.Shape.Id].val; var newValue = item.Value * multiplier; var oldValue = morph.morphValue; // smoothing strategy if (SettingsController.GetSmoothingMultiplier() > 0) { if (!_smoothingVelocities.ContainsKey(item.Shape.Id)) { _smoothingVelocities[item.Shape.Id] = 0f; } float changePct = Mathf.Abs(oldValue - newValue) / Mathf.Abs(multiplier); float velocity = _smoothingVelocities[item.Shape.Id]; morph.morphValueAdjustLimits = Mathf.SmoothDamp(oldValue, newValue, ref velocity, Time.fixedDeltaTime * SettingsController.GetSmoothingMultiplier()); _smoothingVelocities[item.Shape.Id] = velocity; } // just set it strategy else { morph.morphValueAdjustLimits = newValue; } UIController.SetShapeSliderColor(item.Shape.Id, Color.Lerp(Color.white, Color.green, Math.Abs(item.Value))); return(morph); } else { UIController.SetShapeSliderColor(item.Shape.Id, Color.Lerp(Color.white, Color.black, Math.Abs(item.Value))); return(null); } }
private Quaternion?RunHeadRotationChange(BlendShapeReceivedEventArgs item, Quaternion originalRotation) { float multiplier = UIController.StorableBlendShapeStrength[item.Shape.Id].val; switch (item.Shape.Id) { case CBlendShape.HEAD_ROTATION_RIGHT: _latestHeadRotationValues.y = item.Value * multiplier; break; case CBlendShape.HEAD_ROTATION_LEFT: _latestHeadRotationValues.y = item.Value * -1 * multiplier; break; case CBlendShape.HEAD_ROTATION_UP: _latestHeadRotationValues.x = item.Value * -1 * multiplier; break; case CBlendShape.HEAD_ROTATION_DOWN: _latestHeadRotationValues.x = item.Value * multiplier; break; case CBlendShape.HEAD_ROTATION_TILT_LEFT: _latestHeadRotationValues.z = item.Value * multiplier; break; case CBlendShape.HEAD_ROTATION_TILT_RIGHT: _latestHeadRotationValues.z = item.Value * -1 * multiplier; break; default: return(null); } const int degMult = 90; var newRotation = OriginalHeadRotation; newRotation *= Quaternion.Euler(new Vector3(1, 0, 0) * _latestHeadRotationValues.x * degMult); newRotation *= Quaternion.Euler(new Vector3(0, 1, 0) * _latestHeadRotationValues.y * degMult); newRotation *= Quaternion.Euler(new Vector3(0, 0, 1) * _latestHeadRotationValues.z * degMult); if (HeadController != null) { // smoothing strategy if (SettingsController.GetSmoothingMultiplier() > 0) { HeadController.transform.rotation = Quaternion.Lerp(HeadController.transform.rotation, newRotation, Time.fixedDeltaTime / (SettingsController.GetSmoothingMultiplier() / 20)); } // just set it strategy else { HeadController.transform.rotation = newRotation; } UIController.SetShapeSliderColor(item.Shape.Id, Color.Lerp(Color.white, Color.green, Math.Abs(item.Value))); return(newRotation); } else { UIController.SetShapeSliderColor(item.Shape.Id, Color.Lerp(Color.white, Color.black, Math.Abs(item.Value))); return(null); } }
private JSONStorableFloat RunEyeChange(BlendShapeReceivedEventArgs item) { if (!EyePluginInstalled()) { // the eye plugin is not installed on this person return(null); } string paramName = null; float paramValue = 0; float multiplier = UIController.StorableBlendShapeStrength[item.Shape.Id].val; switch (item.Shape.Id) { case CBlendShape.EYE_LOOK_DOWN_LEFT: paramName = "lEyeUpDown"; paramValue = -30 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_UP_LEFT: paramName = "lEyeUpDown"; paramValue = 30 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_IN_LEFT: paramName = "lEyeRightLeft"; paramValue = 45 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_OUT_LEFT: paramName = "lEyeRightLeft"; paramValue = -45 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_DOWN_RIGHT: paramName = "rEyeUpDown"; paramValue = -30 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_UP_RIGHT: paramName = "rEyeUpDown"; paramValue = 30 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_IN_RIGHT: paramName = "rEyeRightLeft"; paramValue = -45 * item.Value * multiplier; break; case CBlendShape.EYE_LOOK_OUT_RIGHT: paramName = "rEyeRightLeft"; paramValue = 45 * item.Value * multiplier; break; default: break; } if (paramName != null) { var floatParam = EyePlugin.GetFloatJSONParam(paramName); if (floatParam != null) { // update eye if (item.Value > 0) { floatParam.val = paramValue; } // update slider color in the UI UIController.SetShapeSliderColor(item.Shape.Id, Color.Lerp(Color.white, Color.green, Math.Abs(item.Value))); return(floatParam); } else { UIController.SetShapeSliderColor(item.Shape.Id, Color.Lerp(Color.white, Color.black, Math.Abs(item.Value))); return(null); } } return(null); }
private void HandleBlendShapeReceived(object sender, BlendShapeReceivedEventArgs args) { lock (_shapeEventsForFrame) { _shapeEventsForFrame[args.Shape.Id] = args; } }