/// <summary> Store a profile in the global variables and on disk. You determine if this is a left- or right hand. </summary> /// <param name="profile"></param> /// <param name="rightHand"></param> public static void SetProfile(SGCore.HandProfile profile, bool rightHand) { //since we're working off the accessors, profiles are automatically stored. if (rightHand) { RightHandProfile = profile; } else { LeftHandProfile = profile; } }
/// <summary> Returns a Hand Pose containing everything you'd want to animate a hand model in Unity. Using a custom HandProfile. </summary> /// <returns></returns> public bool GetHandPose(SGCore.Kinematics.BasicHandModel handDimensions, SGCore.HandProfile userProfile, out SG_HandPose pose, bool forceUpdate = false) { #if UNFINISHED_FEATURES if (this.CVDataAvailable(forceUpdate)) //we are able to get CV data. Yay { pose = new SG_HandPose(SGCore.HandPose.FromHandAngles(lastCVData.handAngles, lastCVData.rightHand, handDimensions)); newPoseNeeded = false; //we don't need a new pose this frame, thank you. lastHandModel = handDimensions; lastHandPose = pose; return(true); } #endif if (this.lastGlove != null) { if (forceUpdate || newPoseNeeded) //we need a new pose { lastHandModel = handDimensions; if (this.CalibrationStage == CalibrationStage.MoveFingers) { lastHandPose = SG_HandPose.Idle(this.IsRight); newPoseNeeded = false; //we don't need a new pose this frame, thank you. } else if (this.CalibrationLocked && this.currentSequence != null) { //we should gram it from the calibrationSequence instead. if (this.currentSequence.GetCalibrationPose(out lastHandPose)) { newPoseNeeded = false; } } else { SGCore.HandPose iPose; if (lastGlove.GetHandPose(handDimensions, userProfile, out iPose)) { lastHandPose = new SG_HandPose(iPose); newPoseNeeded = false; //we don't need a new pose this frame, thank you. } } } // else we already have one, and don't want to force-update. pose = lastHandPose; return(lastHandPose != null); } else if (lastHandPose == null) { lastHandPose = SG_HandPose.Idle(this.IsRight); } //only if we dont yet have a LastHandPose. //otherwise we shouldn't bother pose = lastHandPose; return(false); }
/// <summary> Load a profile form a file, return true if it was succesfully deserialized. </summary> /// <param name="filePath"></param> /// <param name="currProfile"></param> /// <returns></returns> private static bool LoadProfile(string filePath, ref SGCore.HandProfile currProfile) { string[] lines; if (SG.Util.FileIO.ReadTxtFile(filePath, out lines) && lines.Length > 0) { try { currProfile = SGCore.HandProfile.Deserialize(lines[0]); return(true); } catch (System.Exception ex) { Debug.LogError("Error attempting to collect a profile: " + ex.Message); } } return(false); }
//------------------------------------------------------------------------------------------------------------------------- // Store / Load functions /// <summary> Load the latest profiles from disk. Automatically called when you first try to access a profile. /// Exposed so you can force-reload profiles. </summary> public static void TryLoadFromDisk() { if (!LoadProfile(ProfileDirectory + leftHandFile, ref leftProfile)) //returns false if it couldn't be loaded. { if (leftProfile == null) { leftProfile = SGCore.HandProfile.Default(false); } } if (!LoadProfile(ProfileDirectory + rightHandFile, ref rightProfile)) //returns false if it couldn't be loaded. { if (rightProfile == null) { rightProfile = SGCore.HandProfile.Default(true); } } triedLoading = true; }
/// <summary> Restore the left- or right hand profiles back to their default values. </summary> /// <param name="rightHand"></param> public static void RestoreDefaults(bool rightHand) { SGCore.HandProfile newProfile = SGCore.HandProfile.Default(rightHand); Debug.Log("Restoring " + (rightHand ? "Right" : "Left") + " hand to Default Values"); SetProfile(newProfile, rightHand); }
/// <summary> Store a profile in the global variables and on disk. The profile determines if this is a left- or right hand. </summary> /// <param name="profile"></param> public static void SetProfile(SGCore.HandProfile profile) { SetProfile(profile, profile.IsRight); }
/// <summary> Retrieve flexion angles, normalized to [0...1] or [fingers extended ... fingers flexed] </summary> /// <param name="handModel"></param> /// <param name="userProfile"></param> /// <param name="flexions"></param> /// <param name="forceUpdate"></param> /// <returns></returns> public virtual bool GetNormalizedFlexion(SGCore.Kinematics.BasicHandModel handModel, SGCore.HandProfile userProfile, out float[] flexions, bool forceUpdate = false) { SG_HandPose pose; if (GetHandPose(handModel, userProfile, out pose, forceUpdate)) { flexions = pose.normalizedFlexion; return(true); } flexions = new float[5]; return(false); }