private void InputProfile_FrameSelected(object sender, FrameSelectedEventArgs args) { previousArgs = args; if (MappingProfile != null && OutputProfile != null) { cache = new CaptureCache(); // Build the cache int startingFrame = BaseSystem.Math.Max(args.frame - cache.CacheSize, 0); for (int i = startingFrame; i <= args.frame; i++) { var elapsedTime = args.session.CaptureData[i].ElapsedMilliseconds; var skeleton = NUICaptureHelper.GetNUISkeleton(args.session.CaptureData[i].Skeleton); cache.AddNewFrame(skeleton, elapsedTime); // Filter the raw input with enabled filters. NUISkeleton filtered = skeleton; foreach (MocapFilter filter in preMapFilters) { if (filter.Enabled) { filtered = filter.Filter(cache); cache.AddFiltered(filter.Name, filtered); } } // Convert the input skeleton to the normalized skeleton (Unity) NUISkeleton mapped = MappingProfile.MapSkeleton(filtered); cache.AddMapped(mapped); // Apply any post-mapped filters selected by the user. filtered = mapped; foreach (MocapFilter filter in postMapFilters) { if (filter.Enabled) { filtered = filter.Filter(cache); cache.AddFiltered(filter.Name, filtered); } } cache.AddResult(filtered); } var s = NUICaptureHelper.GetNUISkeleton(args.session.CaptureData[args.frame].Skeleton); OutputProfile.UpdatePreview(cache.CurrentSkeleton, MappingProfile.GetHipPosition(s)); } }
/// <summary> /// Receive frame data from the Input profile. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> protected void MocapProfile_SkeletonFrameCaptured(object sender, FrameDataEventArgs args) { if (MappingProfile != null && OutputProfile != null) { var elapsedTime = new TimeSpan(DateTime.Now.Ticks - startTime.Ticks); var skeleton = NUICaptureHelper.GetNUISkeleton(args.SkeletonFrameData); // Cache raw data cache.AddNewFrame(skeleton, elapsedTime.TotalMilliseconds); // Filter the raw input with enabled filters. NUISkeleton filtered = skeleton; foreach (MocapFilter filter in preMapFilters) { if (filter.Enabled) { filtered = filter.Filter(cache); cache.AddFiltered(filter.Name, filtered); } } // Convert the input skeleton to the normalized skeleton (Unity) NUISkeleton mapped = MappingProfile.MapSkeleton(skeleton); Vector3 position = MappingProfile.GetHipPosition(skeleton); cache.AddMapped(mapped); // Apply any post-mapped filters selected by the user. filtered = mapped; foreach (MocapFilter filter in postMapFilters) { if (filter.Enabled) { filtered = filter.Filter(cache); cache.AddFiltered(filter.Name, filtered); } } // Send the mapped and filtered skeleton to the output profile. cache.AddResult(filtered); OutputProfile.UpdatePreview(filtered, position); if (session != null && captureState == RecordingState.Recording) { // Add frame to session. MocapSessionKeyframe kf = new MocapSessionKeyframe(args.SkeletonFrameData, (int)elapsedTime.TotalMilliseconds); session.CaptureData.Add(kf); } } }
public override void Update() { if (bodyReader != null) { getMainUser(); } foreach (var viewer in viewers) { viewer.Update(bodyData, 0); } // Get the pose. if (currentBody != null && currentBody.IsTracked) { // Encapsulate the important frame data SkeletonFrameData frameData = new SkeletonFrameData(); frameData.TrackingId = currentBody.TrackingId; frameData.IsTracked = currentBody.IsTracked; // Build the skeleton for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++) { NUIJointType jointType = NUICaptureHelper.JointTypeToNUIJointTypeMapping(jt); Vector3 position = new Vector3(currentBody.Joints[jt].Position.X, currentBody.Joints[jt].Position.Y, currentBody.Joints[jt].Position.Z); position.z *= -1; // Should probably be done with meta data/mapper to avoid disturbing raw data. Quaternion orientation = new Quaternion(currentBody.JointOrientations[jt].Orientation.X, currentBody.JointOrientations[jt].Orientation.Y, currentBody.JointOrientations[jt].Orientation.Z, currentBody.JointOrientations[jt].Orientation.W); frameData.AddJoint(jointType, position, orientation, (CinemaSuite.CinemaMocap.System.Core.TrackingState)currentBody.Joints[jt].TrackingState); } // Hand info frameData.LeftHandConfidence = (CinemaSuite.CinemaMocap.System.Core.TrackingConfidence)currentBody.HandLeftConfidence; frameData.LeftHandState = (CinemaSuite.CinemaMocap.System.Core.HandState)currentBody.HandLeftState; frameData.RightHandConfidence = (CinemaSuite.CinemaMocap.System.Core.TrackingConfidence)currentBody.HandRightConfidence; frameData.RightHandState = (CinemaSuite.CinemaMocap.System.Core.HandState)currentBody.HandRightState; // Frame info frameData.ClippedEdges = (CinemaSuite.CinemaMocap.System.Core.FrameEdges)currentBody.ClippedEdges; FrameDataEventArgs args = new FrameDataEventArgs(frameData); OnFrameCaptured(args); } }
public override void Update() { if (ZigEditorInput.Instance.ReaderInited) { // Update Device ZigEditorInput.Instance.Update(); // Get the tracked user ZigTrackedUser user = null; int userId = 0; foreach (KeyValuePair <int, ZigTrackedUser> trackedUser in ZigEditorInput.Instance.TrackedUsers) { user = trackedUser.Value; userId = trackedUser.Key; } // Update viewers foreach (Kinect1EditorViewer viewer in viewers) { viewer.Update(ZigEditorInput.Instance, userId); } if (user != null && user.SkeletonTracked) { // Encapsulate the important frame data SkeletonFrameData frameData = new SkeletonFrameData(); frameData.TrackingId = (ulong)user.Id; frameData.IsTracked = user.SkeletonTracked; foreach (ZigInputJoint inputJoint in user.Skeleton) { NUIJointType jointType = NUICaptureHelper.ZigToNUIJointMapping(inputJoint.Id); // Convert position from mm to meters Vector3 position = inputJoint.Position / 1000f; Quaternion orientation = inputJoint.Rotation; frameData.AddJoint(jointType, position, orientation, inputJoint.Inferred ? TrackingState.Inferred : TrackingState.Tracked); } FrameDataEventArgs args = new FrameDataEventArgs(frameData); OnFrameCaptured(args); } } }
/// <summary> /// Once capture is complete, request the OutputProfile to save the animation. /// </summary> protected void saveAnimation(MocapSession session) { if (OutputProfile == null) { Debug.LogWarning("No Output method was found. Animation was not saved"); return; } if (MappingProfile == null) { Debug.LogWarning("No Mapping method was found. Animation was not saved"); return; } if (session == null) { return; } var animation = new NUIHumanoidAnimation(); var cache = new CaptureCache(); foreach (MocapSessionKeyframe keyframe in session.CaptureData) { var elapsedTime = keyframe.ElapsedMilliseconds; var skeleton = NUICaptureHelper.GetNUISkeleton(keyframe.Skeleton); cache.AddNewFrame(skeleton, elapsedTime); // Filter the raw input with enabled filters. NUISkeleton filtered = skeleton; foreach (MocapFilter filter in preMapFilters) { if (filter.Enabled) { filtered = filter.Filter(cache); cache.AddFiltered(filter.Name, filtered); } } // Convert the input skeleton to the normalized skeleton (Unity) NUISkeleton mapped = MappingProfile.MapSkeleton(filtered); cache.AddMapped(mapped); // Apply any post-mapped filters selected by the user. filtered = mapped; foreach (MocapFilter filter in postMapFilters) { if (filter.Enabled) { filtered = filter.Filter(cache); cache.AddFiltered(filter.Name, filtered); } } cache.AddResult(filtered); filtered.Joints[NUIJointType.SpineBase].Position = skeleton.Joints[NUIJointType.SpineBase].Position; animation.AddKeyframe(filtered, keyframe.ElapsedMilliseconds); } // Save the session if (saveSession) { string newFileName = fileName; if (BaseSystem.IO.File.Exists(string.Format(SAVE_DESTINATION_FORMAT, sessionSaveDestination, newFileName))) { newFileName = CinemaMocapHelper.GetNewFilename(sessionSaveDestination, fileName, "asset"); UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, fileName, newFileName)); } AssetDatabase.CreateAsset(session, string.Format(SAVE_DESTINATION_FORMAT, sessionSaveDestination, newFileName)); AssetDatabase.SaveAssets(); } // Save the animation OutputProfile.SaveAnimation(animation); AssetDatabase.Refresh(); }