// returns the face point coordinates or Vector3.zero if not found
    public Vector3 GetPoint(HighDetailFacePoints pointType)
    {
        if (dictFacePoints != null && dictFacePoints.ContainsKey(pointType))
        {
            return(dictFacePoints[pointType]);
        }

        return(Vector3.zero);
    }
    // Update is called once per frame
    void Update()
    {
        Matrix4x4 kinectToWorld = Matrix4x4.zero;

        //Quaternion quatTiltAngle = Quaternion.Euler(-manager.sensorAngle, 0.0f, 0.0f);
        //kinectToWorld.SetTRS(new Vector3(0.0f, manager.sensorHeight, 0.0f), quatTiltAngle, Vector3.one);

        if (!manager)
        {
            manager = KinectManager.Instance;
        }

        if (!faceManager)
        {
            faceManager = FacetrackingManager.Instance;
        }

        // get the face points
        if (manager != null && manager.IsInitialized() && faceManager && faceManager.IsFaceTrackingInitialized())
        {
            long userId = manager.GetUserIdByIndex(playerIndex);

            if (faceVertices == null)
            {
                //int iVertCount = faceManager.GetUserFaceVertexCount(userId);
                int iVertCount = 1347;

                if (iVertCount > 0)
                {
                    faceVertices = new Vector3[iVertCount];
                }

                check_f = false;
            }

            if (faceVertices != null)
            {
                if (faceManager.GetUserFaceVertices(userId, ref faceVertices))
                {
                    //-------------- get 35 special point-------------------
                    //Matrix4x4 kinectToWorld = manager.GetKinectToWorldMatrix();
                    HighDetailFacePoints[] facePoints = (HighDetailFacePoints[])System.Enum.GetValues(typeof(HighDetailFacePoints));

                    for (int i = 0; i < facePoints.Length; i++)
                    {
                        HighDetailFacePoints point = facePoints[i];
                        //dictFacePoints[point] = kinectToWorld.MultiplyPoint3x4(faceVertices[(int)point]);

                        dictFacePoints[point] = faceVertices[(int)point];
                    }

                    check_f = true;
                }
            }
        }
    }
Esempio n. 3
0
    // returns the face point coordinates or Vector3.zero if not found
    /// <summary>
    /// Gets the face point coordinates in Kinect or world coordinates.
    /// </summary>
    /// <returns>The face point.</returns>
    /// <param name="pointType">Point type.</param>
    /// <param name="bWorldCoords">If set to <c>true</c> returns the point in world coordinates, otherwise in Kinect coordinates.</param>
    public Vector3 GetFacePoint(HighDetailFacePoints pointType, bool bWorldCoords)
    {
        if (dictFacePoints != null && dictFacePoints.ContainsKey(pointType))
        {
            if (bWorldCoords)
            {
                Matrix4x4 kinectToWorld = manager.GetKinectToWorldMatrix();
                return(kinectToWorld.MultiplyPoint3x4(dictFacePoints[pointType]));
            }
            else
            {
                return(dictFacePoints[pointType]);
            }
        }

        return(Vector3.zero);
    }
    void Update()
    {
        if (!manager)
        {
            manager = KinectManager.Instance;
        }

        if (!faceManager)
        {
            faceManager = FacetrackingManager.Instance;
        }

//		// get reference to the Kinect2Interface
//		if(k2interface == null)
//		{
//			manager = KinectManager.Instance;
//
//			if(manager && manager.IsInitialized())
//			{
//				KinectInterop.SensorData sensorData = manager.GetSensorData();
//
//				if(sensorData != null && sensorData.sensorInterface != null)
//				{
//					k2interface = (Kinect2Interface)sensorData.sensorInterface;
//				}
//			}
//		}

        // get the face points
        if (manager != null && manager.IsInitialized() && faceManager && faceManager.IsFaceTrackingInitialized())
        {
            long userId = manager.GetUserIdByIndex(playerIndex);

            if (faceVertices == null)
            {
                int iVertCount = faceManager.GetUserFaceVertexCount(userId);

                if (iVertCount > 0)
                {
                    faceVertices = new Vector3[iVertCount];
                }
            }

            if (faceVertices != null)
            {
                if (faceManager.GetUserFaceVertices(userId, ref faceVertices))
                {
                    Matrix4x4 kinectToWorld           = manager.GetKinectToWorldMatrix();
                    HighDetailFacePoints[] facePoints = (HighDetailFacePoints[])System.Enum.GetValues(typeof(HighDetailFacePoints));

                    for (int i = 0; i < facePoints.Length; i++)
                    {
                        HighDetailFacePoints point = facePoints[i];
                        dictFacePoints[point] = kinectToWorld.MultiplyPoint3x4(faceVertices[(int)point]);
                    }
                }
            }
        }

        if (faceVertices != null && faceVertices[(int)facePoint] != Vector3.zero)
        {
            Vector3 facePointPos = faceVertices [(int)facePoint];

            if (facePointTransform)
            {
                facePointTransform.position = facePointPos;
            }

            if (faceInfoText)
            {
                string sStatus = string.Format("{0}: {1}", facePoint, facePointPos);
                faceInfoText.text = sStatus;
            }
        }
    }