void Update() { // start Kinect face tracker as needed if (!facetrackingInitialized) { StartFacetracker(); if (!facetrackingInitialized) { Application.Quit(); return; } } if (facetrackingInitialized) { // update the face tracker int rc = FacetrackingWrapper.UpdateFaceTracking(); if (rc >= 0) { // poll the video frame as needed if (ComputeColorMap) { if (FacetrackingWrapper.PollVideo(ref videoBuffer, ref colorImage)) { usersClrTex.SetPixels32(colorImage); usersClrTex.Apply(); } } // estimate the tracking state isTracking = FacetrackingWrapper.IsFaceTracked(); faceTrackingID = FacetrackingWrapper.GetFaceTrackingID(); // get the facetracking parameters if (isTracking) { //float fTimeNow = Time.realtimeSinceStartup; // get face rectangle bool bGotFaceRect = FacetrackingWrapper.GetFaceRect(ref faceRect); // get head position and rotation Vector4 vHeadPos = Vector4.zero, vHeadRot = Vector4.zero; if (FacetrackingWrapper.GetHeadPosition(ref vHeadPos)) { headPos = (Vector3)vHeadPos; if (!MirroredHeadMovement) { headPos.z = -headPos.z; } } if (FacetrackingWrapper.GetHeadRotation(ref vHeadRot)) { if (MirroredHeadMovement) { vHeadRot.x = -vHeadRot.x; vHeadRot.z = -vHeadRot.z; } else { vHeadRot.x = -vHeadRot.x; vHeadRot.y = -vHeadRot.y; } headRot = Quaternion.Euler((Vector3)vHeadRot); } // get the animation units int iNumAU = FacetrackingWrapper.GetAnimUnitsCount(); bGotAU = false; if (iNumAU > 0) { if (afAU == null) { afAU = new float[iNumAU]; } bGotAU = FacetrackingWrapper.GetAnimUnits(afAU, ref iNumAU); } // get the shape units isConverged = FacetrackingWrapper.IsShapeConverged(); int iNumSU = FacetrackingWrapper.GetShapeUnitsCount(); bGotSU = false; if (iNumSU > 0) { if (afSU == null) { afSU = new float[iNumSU]; } bGotSU = FacetrackingWrapper.GetShapeUnits(afSU, ref iNumSU); } // get the shape points int iNumPoints = FacetrackingWrapper.GetShapePointsCount(); bGotPoints = false; if (iNumPoints > 0) { int iNumPointsXY = iNumPoints << 1; if (avPointsXY == null) { avPointsXY = new float[iNumPointsXY]; avPoints = new Vector2[iNumPoints]; } bGotPoints = FacetrackingWrapper.GetShapePoints(avPointsXY, ref iNumPointsXY); if (bGotPoints) { for (int i = 0; i < iNumPoints; i++) { int iXY = i << 1; avPoints[i].x = avPointsXY[iXY]; avPoints[i].y = avPointsXY[iXY + 1]; } } } ///// added by Takefumi // get the 3D shape points int i3DNumPoints = FacetrackingWrapper.Get3DShapePointsCount(); bGot3DPoints = false; if (i3DNumPoints > 0) { int iNumPointsXYZ = i3DNumPoints * 3; if (avPointsXYZ == null) { avPointsXYZ = new float[iNumPointsXYZ]; av3DPoints = new Vector3[i3DNumPoints]; } bGot3DPoints = FacetrackingWrapper.Get3DShapePoints(avPointsXYZ, ref iNumPointsXYZ); if (bGot3DPoints) { for (int i = 0; i < i3DNumPoints; i++) { int iXYZ = i * 3; av3DPoints[i].x = avPointsXYZ[iXYZ]; av3DPoints[i].y = avPointsXYZ[iXYZ + 1]; av3DPoints[i].z = avPointsXYZ[iXYZ + 2]; } } } ///// end of added if (ComputeColorMap) { if (DisplayFaceRect && bGotFaceRect) { DrawFacetrackerRect(usersClrTex, !VisualizeFacetracker); } if (VisualizeFacetracker) { DrawFacetrackerLines(usersClrTex, avPoints, true); } } } } } }