void updateFaceVertices()
    {
        using (var frame = hdFaceFrameReader.AcquireLatestFrame()) {
            if (frame == null || !frame.IsFaceTracked)
            {
                return;
            }
            frame.GetAndRefreshFaceAlignmentResult(faceAlignment);
        }

        FaceVertices = faceModel.CalculateVerticesForAlignment(faceAlignment);
    }
Пример #2
0
        private static void UpdateFace()
        {
            if (faceReader != null)
            {
                HighDefinitionFaceFrame frame = faceReader.AcquireLatestFrame();
                if (frame != null && frame.IsFaceTracked)
                {
                    _faceIsTracked = true;
                    frame.GetAndRefreshFaceAlignmentResult(faceAlignment);

                    IList <CameraSpacePoint> vertices = faceModel.CalculateVerticesForAlignment(faceAlignment);
                    for (int i = 0; i < FaceModel.VertexCount; i++)
                    {
                        faceGeometry[i] = new Vector(vertices[i].X, vertices[i].Y, -vertices[i].Z);
                    }
                }
            }
            else
            {
                _faceIsTracked = false;
            }
        }
Пример #3
0
    void Update()
    {
        if (_Reader != null)
        {
            var frame = _Reader.AcquireLatestFrame();
            if (frame != null)
            {
                if (_Data == null)
                {
                    _Data = new Body[_Sensor.BodyFrameSource.BodyCount];
                }

                frame.GetAndRefreshBodyData(_Data);
                _Closest = findClosestBody(_Data);

                _FloorClipPlane = new UnityEngine.Vector4(frame.FloorClipPlane.X, frame.FloorClipPlane.Y, frame.FloorClipPlane.Z, frame.FloorClipPlane.W);
                calculateKinectProperties();

                frame.Dispose();
                frame = null;
            }


            if (_Closest != null && enableFacetracking)
            {
                if (faceFrameSource.TrackingId != _ClosestBodyId)
                {
                    faceFrameSource.TrackingId = _ClosestBodyId;
                }

                var faceFrame = faceframeReader.AcquireLatestFrame();
                if (faceFrame != null)
                {
                    if (faceFrame.FaceFrameResult != null)
                    {
                        UnityEngine.Quaternion faceRotation = new UnityEngine.Quaternion(faceFrame.FaceFrameResult.FaceRotationQuaternion.X,
                                                                                         faceFrame.FaceFrameResult.FaceRotationQuaternion.Y,
                                                                                         faceFrame.FaceFrameResult.FaceRotationQuaternion.Z,
                                                                                         faceFrame.FaceFrameResult.FaceRotationQuaternion.W);

                        //correct for kinect rotation
                        currentFaceRotation = faceRotation * _kinectRotation;
                    }
                    faceFrame.Dispose();
                    faceFrame = null;
                }
            }

            if (_Closest != null && enableHDFace)
            {
                if (highDefinitionFaceFrameSource.TrackingId != _ClosestBodyId)
                {
                    highDefinitionFaceFrameSource.TrackingId = _ClosestBodyId;
                }

                //get face data
                var HDfaceFrame = highDefinitionFaceFrameReader.AcquireLatestFrame();
                if (HDfaceFrame != null)
                {
                    HDfaceFrame.GetAndRefreshFaceAlignmentResult(currentFaceAlignment);
                    if (currentFaceAlignment != null)
                    {
                        //var vertexCount = FaceModel.VertexCount;

                        if (normals == null)
                        {
                            normals = new Vector3[FaceModel.VertexCount];
                            uvs     = new Vector2[FaceModel.VertexCount];
                        }

                        var verticesCameraSpacePoint = currentFaceModel.CalculateVerticesForAlignment(currentFaceAlignment);
                        var vertices          = new Vector3[FaceModel.VertexCount];
                        var correctedVertices = new Vector3[FaceModel.VertexCount];
                        _CurrentFacePivot = new Vector3(currentFaceAlignment.HeadPivotPoint.X, currentFaceAlignment.HeadPivotPoint.Y, currentFaceAlignment.HeadPivotPoint.Z);
                        for (int i = 0; i < FaceModel.VertexCount; i++)
                        {
                            //vertices[i] = new Vector3(verticesCameraSpacePoint[i].X - _CurrentFacePivot.x, verticesCameraSpacePoint[i].Y - _CurrentFacePivot.y, verticesCameraSpacePoint[i].Z - _CurrentFacePivot.z);
                            vertices[i]          = new Vector3(verticesCameraSpacePoint[i].X, verticesCameraSpacePoint[i].Y, verticesCameraSpacePoint[i].Z);
                            correctedVertices[i] = kinectRotationTransform(vertices[i], _CurrentFacePivot);
                            normals[i]           = -Vector3.forward;
                        }
                        _CurrentFaceMeshVertices          = vertices;
                        _CurrentFaceMeshCorrectedVertices = correctedVertices;
                    }
                    HDfaceFrame.Dispose();
                    HDfaceFrame = null;
                }
            }
        }
    }