// a quick fix for some false movements detected during tracking private void FixFalseMovement() { // fix for: false rotation while smiling smile_left = Tracker.GetActionUnit("au_lip_stretcher_left"); smile_right = Tracker.GetActionUnit("au_lip_stretcher_right"); rotationFixScale = Mathf.Clamp01((Tracker.Rotation.x + 17f) / 34f); if (smile_left != null && smile_left.Value > 0) { Tracker.Rotation.x -= falseRotationValue * smile_left.Value * rotationFixScale; } if (smile_right != null && smile_right.Value > 0) { Tracker.Rotation.x -= falseRotationValue * smile_right.Value * rotationFixScale; } // fix for: false translation while raising eyebrows brow_left = Tracker.GetActionUnit("au_left_outer_brow_raiser"); brow_right = Tracker.GetActionUnit("au_right_outer_brow_raiser"); Tracker.Translation.z += falseTranslationValue * Mathf.Clamp01((brow_left.Value + brow_right.Value - 0.1f) / 0.3f); }
public void UpdateAction(Dictionary <string, byte> blendshapeWeights) { if (Tracker == null) { return; } if (!Initialized) { data = Tracker.GetActionUnit(ActionUnitName); } else { Value = data.Value; NormalizedValue = (data.Value - Limits.x) / (Limits.y - Limits.x); NormalizedValue = Mathf.Clamp01(NormalizedValue); if (Inverted) { NormalizedValue = 1f - NormalizedValue; } // push back normalized history for (int i = 1; i < FilterWindowSize; i++) { normalizedValueHistory[i - 1] = normalizedValueHistory[i]; } // add normalized value to history normalizedValueHistory[FilterWindowSize - 1] = NormalizedValue; // filter value FilteredValue = Filter(NormalizedValue); // apply to all targets foreach (ActionUnitBindingTarget target in Targets) { if (target.BlendshapeIndex >= 0 && target.Weight >= 0f) { float value = FilteredValue * Weight * target.Weight * 100f; target.Renderer.SetBlendShapeWeight(target.BlendshapeName, value); if (blendshapeWeights.ContainsKey(target.BlendshapeName)) { blendshapeWeights[target.BlendshapeName] = (byte)value; } } } } }
void OnRenderObject() { // Height / Tracker.ImageHeight = Width / Tracker.ImageWidth; Width = DesiredScreenWidth * Screen.width; Height = Tracker.ImageHeight * Width / Tracker.ImageWidth; Offset.y = (Screen.height - Height) / 2; if (Tracker.TrackerStatus != TrackStatus.Off) { Tracker.RefreshImage(); if (Tracker.Frame != null && Camera.current != Camera.main) { //Rect rect = new Rect (Offset.x, Screen.height - Offset.y, Width, -Height); Rect rect = new Rect(Offset.x, (Screen.height + Height) / 2, Width, -Height); GL.PushMatrix(); GL.LoadPixelMatrix(); #if UNITY_ANDROID && !UNITY_EDITOR Graphics.DrawTexture(rect, Tracker.Frame, new Rect(0f, (float)Tracker.ImageHeight / Tracker.TexHeight, (float)Tracker.ImageWidth / Tracker.TexWidth, -(float)Tracker.ImageHeight / Tracker.TexHeight), 0, 0, 0, 0); #else Graphics.DrawTexture(rect, Tracker.Frame, new Rect(0f, (float)Tracker.ImageHeight / Tracker.TexHeight, (float)Tracker.ImageWidth / Tracker.TexWidth, -(float)Tracker.ImageHeight / Tracker.TexHeight), 0, 0, 0, 0, BGRMaterial); #endif GL.PopMatrix(); } } if (Tracker.TrackerStatus != TrackStatus.Ok || !PreviewResults) { return; } // get chin points float[] chinPoints = GetFeaturePoints(new int[] { 2, 14, 2, 12, 2, 1, 2, 11, 2, 13, }); // draw chin DrawFeatureLines(chinPoints, Color.green); // get inner lip points float[] innerLipPoints = GetFeaturePoints(new int[] { 2, 2, 2, 6, 2, 4, 2, 8, 2, 3, 2, 9, 2, 5, 2, 7, 2, 2, }); // draw inner lip DrawFeatureLines(innerLipPoints, Color.green); // get outer lip float[] outerLipPoints = GetFeaturePoints(new int[] { 8, 1, 8, 10, 8, 5, 8, 3, 8, 7, 8, 2, 8, 8, 8, 4, 8, 6, 8, 9, 8, 1, }); // draw outer lip DrawFeatureLines(outerLipPoints, Color.green); // get nose part one lines float[] nose1Points = GetFeaturePoints(new int[] { 9, 15, 9, 4, 9, 2, 9, 3, 9, 1, 9, 5, 9, 15, }); // get nose part two lines float[] nose2Points = GetFeaturePoints(new int[] { 9, 6, 9, 7, 9, 13, 9, 12, 9, 14, 9, 6, }); // get nose part three lines float[] nose3Points = GetFeaturePoints(new int[] { 9, 14, 9, 2, 9, 13, 9, 1, }); // draw nose DrawFeatureLines(nose1Points, Color.green); DrawFeatureLines(nose2Points, Color.green); DrawFeatureLines(nose3Points, Color.green); // get eye part one lines float[] eye1Points = GetFeaturePoints(new int[] { 3, 12, 3, 14, 3, 8, 3, 10, 3, 12, }); // get eye part three lines float[] eye3Points = GetFeaturePoints(new int[] { 3, 11, 3, 13, 3, 7, 3, 9, 3, 11, }); // draw eyes Color leyeColor = Color.red; if (Tracker.GetActionUnit("au_leye_closed").Value < 0.3) { leyeColor = Color.green; float[] lIrisPoint = GetFeaturePoints(new int[] { 3, 5, }); DrawFeaturePoints(lIrisPoint, Color.white); } Color reyeColor = Color.red; if (Tracker.GetActionUnit("au_reye_closed").Value < 0.3) { reyeColor = Color.green; float[] rIrisPoint = GetFeaturePoints(new int[] { 3, 6, }); DrawFeaturePoints(rIrisPoint, Color.white); } DrawFeatureLines(eye3Points, reyeColor); DrawFeatureLines(eye1Points, leyeColor); // draw gaze // get eyebrows float[] eyebrowPoints = GetFeaturePoints(new int[] { 4, 1, 4, 2, 4, 3, 4, 4, 4, 5, 4, 6, }); float[] eyebrowLine1Points = GetFeaturePoints(new int[] { 4, 6, 4, 4, 4, 4, 4, 2, }); float[] eyebrowLine2Points = GetFeaturePoints(new int[] { 4, 1, 4, 3, 4, 3, 4, 5, }); // draw eyebrows DrawFeaturePoints(eyebrowPoints, Color.green); DrawFeatureLines(eyebrowLine1Points, Color.green); DrawFeatureLines(eyebrowLine2Points, Color.green); // get hair points float[] hairPoints = GetFeaturePoints(new int[] { 11, 2, 11, 1, 11, 1, 11, 3, }); // draw hair DrawFeatureLines(hairPoints, Color.green); }