Beispiel #1
0
    /// <summary>
    /// Gets the animation unit value at given index, or 0 if the index is invalid.
    /// </summary>
    /// <returns>The animation unit value.</returns>
    /// <param name="faceAnimKey">Face animation unit.</param>
    public float GetAnimUnit(KinectInterop.FaceShapeAnimations faceAnimKey)
    {
        if (dictAU.ContainsKey(faceAnimKey))
        {
            return(dictAU[faceAnimKey]);
        }

        return(0.0f);
    }
Beispiel #2
0
    void Update()
    {
        // reference to face manager
        if (!faceManager)
        {
            faceManager = FacetrackingManager.Instance;
        }

        if (kinectManager && kinectManager.IsInitialized() && faceManager && faceManager.IsFaceTrackingInitialized())
        {
            // check for tracked user
            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            if (userId != 0 && kinectManager.IsUserTracked(userId))
            {
                if (faceManager.GetUserAnimUnits(userId, ref dictAnimUnits))
                {
                    // process the blend shapes -> anim units
                    for (int i = 0; i < blendShapeCount; i++)
                    {
                        if (blendShape2AnimUnit.ContainsKey(blendShapeNames[i]))
                        {
                            KinectInterop.FaceShapeAnimations faceAnim = blendShape2AnimUnit[blendShapeNames[i]];
                            float animValue = dictAnimUnits[faceAnim];

                            // check for multiplier
                            float mul = 1f;
                            if (blendShape2Multiplier.ContainsKey(blendShapeNames[i]))
                            {
                                mul = blendShape2Multiplier[blendShapeNames[i]];
                            }

                            if (animValue * mul < 0f)
                            {
                                animValue = 0f;
                            }

                            // lerp to the new value
                            blendShapeValues[i] = Mathf.Lerp(blendShapeValues [i], animValue * mul * 100f, smoothFactor * Time.deltaTime);
                            skinnedMeshRenderer.SetBlendShapeWeight(i, blendShapeValues[i]);
                        }
                    }
                }
            }
        }
    }
    void Update()
    {
        blendShape2Multiplier ["Jaw_Left"]           = -1f * jawLeftMult;
        blendShape2Multiplier ["BrowsUp_Right"]      = -1f * browUpRightMult;
        blendShape2Multiplier ["BrowsUp_Left"]       = -1f * browUpLeftMult;
        blendShape2Multiplier ["Jaw_Down"]           = jawDownMult;
        blendShape2Multiplier ["BrowsDown_Right"]    = browDownRightMult;
        blendShape2Multiplier ["CheekPuff_Left"]     = cheekLeftMult;
        blendShape2Multiplier ["CheekPuff_Right"]    = cheekRightMult;
        blendShape2Multiplier ["Smile_Right"]        = smileRightMult;
        blendShape2Multiplier ["Smile_Left"]         = smileLeftMult;
        blendShape2Multiplier ["Jaw_Right"]          = jawRightMult;
        blendShape2Multiplier ["Blink_Right"]        = blinkRightMult;
        blendShape2Multiplier ["Blink_Left"]         = blinkLeftMult;
        blendShape2Multiplier ["Midmouth_Left"]      = midmouthMult;
        blendShape2Multiplier ["Midmouth_Right"]     = midmouthMult;
        blendShape2Multiplier ["LowerLipDown_Right"] = depressorRightMult;
        blendShape2Multiplier ["LowerLipDown_Left"]  = depressorLeftMult;
        blendShape2Multiplier ["Lips_Stretch_L"]     = stretcherLeftMult;
        blendShape2Multiplier ["Lips_Stretch_R"]     = stretcherRightMult;
        blendShape2Multiplier ["Frown_Right"]        = frownRightMult;
        blendShape2Multiplier ["Frown_Left"]         = frownLeftMult;

        // reference to face manager
        if (!faceManager)
        {
            faceManager = FacetrackingManager.Instance;
        }

        if (kinectManager && kinectManager.IsInitialized() && faceManager && faceManager.IsFaceTrackingInitialized())
        {
            // check for tracked user
            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            if (userId != 0 && kinectManager.IsUserTracked(userId))
            {
                if (faceManager.GetUserAnimUnits(userId, ref dictAnimUnits))
                {
                    // process the blend shapes -> anim units
                    for (int i = 0; i < blendShapeCount; i++)
                    {
                        if (blendShape2AnimUnit.ContainsKey(blendShapeNames [i]))
                        {
                            KinectInterop.FaceShapeAnimations faceAnim = blendShape2AnimUnit [blendShapeNames [i]];
                            float animValue = dictAnimUnits [faceAnim];

                            // check for multiplier
                            float mul = 1f;
                            if (blendShape2Multiplier.ContainsKey(blendShapeNames [i]))
                            {
                                mul = blendShape2Multiplier [blendShapeNames [i]];
                            }

                            if (animValue * mul < 0f)
                            {
                                animValue = 0f;
                            }

                            // lerp to the new value
                            blendShapeValues [i] = Mathf.Lerp(blendShapeValues [i], animValue * mul * 100f, smoothFactor * Time.deltaTime);
                            skinnedMeshRenderer.SetBlendShapeWeight(i, blendShapeValues [i]);

                            //rotation
                            Vector3 angles = kinectManager.GetJointOrientation(userId, (int)KinectInterop.JointType.Head, true).eulerAngles;
                            transform.parent.parent.rotation = Quaternion.Euler(new Vector3(-angles.x, -angles.y, angles.z));
                        }
                    }
                }
            }
        }
    }
    void Update()
    {
        if (skinnedMeshRenderer == null)
        {
            return;
        }
        if (faceAnimUnits.Count != faceBlendShapes.Count)
        {
            return;
        }

        if (blendShapeValues == null || blendShapeValues.Length != faceAnimUnits.Count)
        {
            blendShapeValues = new float[faceAnimUnits.Count];
        }

        // reference to face manager
        if (!faceManager)
        {
            faceManager = FacetrackingManager.Instance;
        }

        if (kinectManager && kinectManager.IsInitialized() && faceManager && faceManager.IsFaceTrackingInitialized())
        {
            // check for tracked user
            long userId = kinectManager.GetUserIdByIndex(playerIndex);

            if (userId != 0 && kinectManager.IsUserTracked(userId))
            {
                // move the model transform according to user's head
                if (headTransform != null)
                {
                    MoveHeadTransform(userId);
                }

                // animate blend shapes
                if (faceManager.GetUserAnimUnits(userId, ref dictAnimUnits))
                {
                    for (int i = 0; i < faceAnimUnits.Count; i++)
                    {
                        KinectInterop.FaceShapeAnimations faceAnim = faceAnimUnits[i];

                        if (dictAnimUnits.ContainsKey(faceAnim))
                        {
                            float  animValue      = dictAnimUnits[faceAnim];
                            string blendShapeName = faceBlendShapes[i];

                            int blendShapeIndex = !string.IsNullOrEmpty(blendShapeName) ? skinnedMesh.GetBlendShapeIndex(blendShapeName) : -1;
                            if (blendShapeIndex >= 0)
                            {
                                if (animValue < 0f)
                                {
                                    //Debug.Log(faceAnim + ": " + animValue);
                                    animValue = -animValue;
                                }

                                // lerp to the new value
                                blendShapeValues[i] = Mathf.Lerp(blendShapeValues[i], animValue * valueMultiplier, blendSmoothFactor * Time.deltaTime);
                                skinnedMeshRenderer.SetBlendShapeWeight(blendShapeIndex, blendShapeValues[i]);
                            }
                            else
                            {
                                Debug.LogError("Blend shape '" + blendShapeName + "' not found!");
                            }
                        }
                    }
                }
            }
        }
    }