protected override Frame createFrame() { _originalFrame = TestHandFactory.MakeTestFrame(0, true, true); LeapTransform forwardTransform = new LeapTransform(translation, LeapQuaternion.Identity); return(_originalFrame.TransformedCopy(forwardTransform)); }
public override void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { if (Application.isPlaying) { base.OnDrawRuntimeGizmos(drawer); } else { var provider = leapProvider; if (provider == null) { provider = Hands.Provider; } if (_testHand == null && provider != null) { _testHand = TestHandFactory.MakeTestHand(0, 0, this.isLeft) .TransformedCopy(UnityMatrixExtension.GetLeapMatrix(provider.transform)); } // Hover Point _unwarpedHandData = _testHand; // hoverPoint is driven by this backing variable drawHoverPoint(drawer, hoverPoint); // Primary Hover Points for (int i = 0; i < NUM_FINGERS; i++) { if (enabledPrimaryHoverFingertips[i]) { drawPrimaryHoverPoint(drawer, _testHand.Fingers[i].TipPosition.ToVector3()); } } } }
void Update() { if (!EditorApplication.isPlaying && SupportsEditorPersistence()) { Transform editorPoseSpace; LeapServiceProvider leapServiceProvider = FindObjectOfType <LeapServiceProvider>(); LeapTransform poseTransform = LeapTransform.Identity; if (leapServiceProvider != null) { editorPoseSpace = leapServiceProvider.transform; poseTransform = TestHandFactory.GetTestPoseLeftHandTransform(leapServiceProvider.editTimePose); } else { editorPoseSpace = transform; } Hand hand = TestHandFactory.MakeTestHand(Handedness == Chirality.Left, poseTransform).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(editorPoseSpace)); //Hand hand = TestHandFactory.MakeTestHand(0, 0, Handedness == Chirality.Left).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(editorPoseSpace)); if (GetLeapHand() == null) { SetLeapHand(hand); InitHand(); BeginHand(); UpdateHand(); } else { SetLeapHand(hand); UpdateHand(); } } }
void Awake() { _cachedLeftHand = TestHandFactory.MakeTestHand(isLeft: true, unitType: TestHandFactory.UnitType.UnityUnits); _cachedRightHand = TestHandFactory.MakeTestHand(isLeft: false, unitType: TestHandFactory.UnitType.UnityUnits); }
// Modifique los accesors para poder overridearlo en HapticHand protected virtual void Update() { if (!EditorApplication.isPlaying && SupportsEditorPersistence()) { Transform editorPoseSpace; LeapServiceProvider leapServiceProvider = FindObjectOfType <LeapServiceProvider>(); if (leapServiceProvider) { editorPoseSpace = leapServiceProvider.transform; } else { editorPoseSpace = transform; } Hand hand = TestHandFactory.MakeTestHand(0, 0, Handedness == Chirality.Left).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(editorPoseSpace)); if (GetLeapHand() == null) { SetLeapHand(hand); InitHand(); BeginHand(); UpdateHand(); } else { SetLeapHand(hand); UpdateHand(); } } }
public void UpdateHands() { Frame frame = TestHandFactory.MakeTestFrame(0, true, true); IntPtr handPtr = HandArrayBuilder.CreateHandArray(frame); InteractionC.UpdateHands(ref _scene, 2, handPtr); StructAllocator.CleanupAllocations(); }
void Update() { if (!EditorApplication.isPlaying) { SetLeapHand(TestHandFactory.MakeTestHand(0, 0, Handedness == Chirality.Left).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(transform))); UpdateHand(); } }
/// <summary> /// Estimate the rotation offset needed to get the rigged hand into the same orientation as the leap hand /// </summary> public static void EstimateWristRotationOffset(HandBinder handBinder) { //Try to using the meta first Transform indexBone = handBinder.boundHand.fingers[(int)Finger.FingerType.TYPE_INDEX].boundBones[(int)Bone.BoneType.TYPE_METACARPAL].boundTransform; Transform middleBone = handBinder.boundHand.fingers[(int)Finger.FingerType.TYPE_MIDDLE].boundBones[(int)Bone.BoneType.TYPE_METACARPAL].boundTransform; Transform pinkyBone = handBinder.boundHand.fingers[(int)Finger.FingerType.TYPE_PINKY].boundBones[(int)Bone.BoneType.TYPE_METACARPAL].boundTransform; //If the meta does not exist, use the proximal bones if (indexBone == null || middleBone == null || pinkyBone == null) { indexBone = handBinder.boundHand.fingers[(int)Finger.FingerType.TYPE_INDEX].boundBones[(int)Bone.BoneType.TYPE_PROXIMAL].boundTransform; middleBone = handBinder.boundHand.fingers[(int)Finger.FingerType.TYPE_MIDDLE].boundBones[(int)Bone.BoneType.TYPE_PROXIMAL].boundTransform; pinkyBone = handBinder.boundHand.fingers[(int)Finger.FingerType.TYPE_PINKY].boundBones[(int)Bone.BoneType.TYPE_PROXIMAL].boundTransform; } Transform wrist = handBinder.boundHand.wrist.boundTransform; if (middleBone != null && indexBone != null && pinkyBone != null && wrist != null) { //Get the Direction from the middle finger to the wrist Vector3 wristForward = middleBone.position - wrist.position; //Get the Direction from the Proximal pinky finger to the Proximal Index finger Vector3 wristRight = indexBone.position - pinkyBone.position; //Swap the direction based on left and right hands if (handBinder.Handedness == Chirality.Right) { wristRight = -wristRight; } //Get the direciton that goes outwards from the back of the hand Vector3 wristUp = Vector3.Cross(wristForward, wristRight); //Make the vectors orthoginal to eacother, this is the basis for the model hand Vector3.OrthoNormalize(ref wristRight, ref wristUp, ref wristForward); //Create a new leap hand based off the Desktop hand pose Hand hand = TestHandFactory.MakeTestHand(handBinder.Handedness == Chirality.Left, unitType: TestHandFactory.UnitType.LeapUnits); hand.Transform(TestHandFactory.GetTestPoseLeftHandTransform(TestHandFactory.TestHandPose.DesktopModeA)); Quaternion leapRotation = hand.Rotation.ToQuaternion(); //Get the rotation of the calculated hand Basis Quaternion modelRotation = Quaternion.LookRotation(wristForward, wristUp); //Now calculate the difference between the models rotation and the leaps rotation Quaternion wristRotationDifference = Quaternion.Inverse(modelRotation) * leapRotation; Vector3 wristRelativeDifference = (Quaternion.Inverse(wrist.rotation) * wristRotationDifference).eulerAngles; //Round to the nearest 90 degrees wristRelativeDifference.x = Mathf.Round(wristRelativeDifference.x / 90) * 90; wristRelativeDifference.y = Mathf.Round(wristRelativeDifference.y / 90) * 90; wristRelativeDifference.z = Mathf.Round(wristRelativeDifference.z / 90) * 90; //Assign these values to the hand binder handBinder.GlobalFingerRotationOffset = wristRelativeDifference; handBinder.boundHand.wrist.offset.rotation = wristRelativeDifference; } }
void Awake() { if (!EditorApplication.isPlaying) { //Debug.Log("IHandModel.Awake()"); SetLeapHand(TestHandFactory.MakeTestHand(0, 0, Handedness == Chirality.Left).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(transform))); InitHand(); } }
void Update() { if (!EditorApplication.isPlaying && SupportsEditorPersistence()) { LeapProvider provider = null; //First try to get the provider from a parent HandModelManager if (transform.parent != null) { var manager = transform.parent.GetComponent <HandModelManager>(); if (manager != null) { provider = manager.leapProvider; } } //If not found, use any old provider from the Hands.Provider getter if (provider == null) { provider = Hands.Provider; } Hand hand = null; //If we found a provider, pull the hand from that if (provider != null) { var frame = provider.CurrentFrame; if (frame != null) { hand = frame.Get(Handedness); } } //If we still have a null hand, construct one manually if (hand == null) { hand = TestHandFactory.MakeTestHand(Handedness == Chirality.Left, unitType: TestHandFactory.UnitType.LeapUnits); hand.Transform(transform.GetLeapMatrix()); } if (GetLeapHand() == null) { SetLeapHand(hand); InitHand(); BeginHand(); UpdateHand(); } else { SetLeapHand(hand); UpdateHand(); } } }
public void EncodeDecodeTest() { const float TOLERANCE = 0.01f; //1 cm for all positions Frame frame = TestHandFactory.MakeTestFrame(0, includeLeftHand: true, includeRightHand: true, unitType: TestHandFactory.UnitType.UnityUnits); foreach (var hand in frame.Hands) { byte[] bytes; { VectorHand vHand = new VectorHand(); bytes = new byte[vHand.numBytesRequired]; //Encode the hand into the vHand representation vHand.Encode(hand); //Then convert the vHand into a binary representation vHand.FillBytes(bytes); } Hand result; { VectorHand vHand = new VectorHand(); //Convert the binary representation back into a vHand int offset = 0; vHand.ReadBytes(bytes, ref offset); //Decode the vHand back into a normal Leap Hand result = new Hand(); vHand.Decode(result); } Assert.That(result.IsLeft, Is.EqualTo(hand.IsLeft)); Assert.That((result.PalmPosition - hand.PalmPosition).Magnitude, Is.LessThan(TOLERANCE)); foreach (var resultFinger in result.Fingers) { var finger = hand.Fingers.Single(f => f.Type == resultFinger.Type); for (int i = 0; i < 4; i++) { Bone resultBone = resultFinger.bones[i]; Bone bone = finger.bones[i]; Assert.That((resultBone.NextJoint - bone.NextJoint).Magnitude, Is.LessThan(TOLERANCE)); Assert.That((resultBone.PrevJoint - bone.PrevJoint).Magnitude, Is.LessThan(TOLERANCE)); Assert.That((resultBone.Center - bone.Center).Magnitude, Is.LessThan(TOLERANCE)); } } } }
void Update() { if (!EditorApplication.isPlaying) { if (Handedness == Chirality.Left) { isLeft = true; } //Debug.Log("IHandModel.Update()"); SetLeapHand(TestHandFactory.MakeTestHand(0, 0, isLeft).TransformedCopy(GetLeapMatrix())); UpdateHand(); } }
static RiggedFinger() { // Calculate standard fingertip lengths. s_standardFingertipLengths = new float[5]; var testHand = TestHandFactory.MakeTestHand(isLeft: true, unitType: TestHandFactory.UnitType.UnityUnits); for (int i = 0; i < 5; i++) { var fingertipBone = testHand.Fingers[i].bones[3]; s_standardFingertipLengths[i] = fingertipBone.Length; } }
void Update() { #if UNITY_EDITOR PrefabType prefabType = PrefabUtility.GetPrefabType(this.gameObject); if (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab) { return; } #endif bool requiresReinitialization = false; using (new ProfilerSample("Attachment Hands Update", this.gameObject)) { for (int i = 0; i < _attachmentHands.Length; i++) { var attachmentHand = attachmentHands[i]; if (attachmentHand == null) { requiresReinitialization = true; break; } var leapHand = handAccessors[i](); #if UNITY_EDITOR if (Hands.Provider != null) { if (leapHand == null && !Application.isPlaying) { leapHand = TestHandFactory.MakeTestHand(0, i, i == 0).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(Hands.Provider.transform)); } } #endif using (new ProfilerSample(attachmentHand.gameObject.name + " Update Points")) { foreach (var point in attachmentHand.points) { point.SetTransformUsingHand(leapHand); } } } if (requiresReinitialization) { reinitialize(); } } }
private void Start() { handID = !isLeft ? 0 : 1; leapHand = TestHandFactory.MakeTestHand(IsLeft, 0, handID, TestHandFactory.UnitType.UnityUnits); //GenerateHandData(0); arm = leapHand.Arm; fingers = leapHand.Fingers; thumbBones = leapHand.Fingers[(int)Finger.FingerType.TYPE_THUMB].bones; indexBones = leapHand.Fingers[(int)Finger.FingerType.TYPE_INDEX].bones; middleBones = leapHand.Fingers[(int)Finger.FingerType.TYPE_MIDDLE].bones; ringBones = leapHand.Fingers[(int)Finger.FingerType.TYPE_RING].bones; pinkyBones = leapHand.Fingers[(int)Finger.FingerType.TYPE_PINKY].bones; previousHand = new Hand(); previousHand.CopyFrom(leapHand); SetHandData(leapHand, 0); }
public static Hand MakeTestHand(bool isLeft) { Hand hand; if (isLeft) { hand = TestHandFactory.MakeTestHand(isLeft: true); hand.TransformToUnityUnits(); // Note: sucks that this has to be here } else { hand = TestHandFactory.MakeTestHand(isLeft: false); hand.TransformToUnityUnits(); // Note: like really this is terrible } return(hand); }
void Update() { if (!EditorApplication.isPlaying && SupportsEditorPersistence()) { Hand hand = TestHandFactory.MakeTestHand(0, 0, Handedness == Chirality.Left).TransformedCopy(UnityMatrixExtension.GetLeapMatrix(transform)); if (GetLeapHand() == null) { SetLeapHand(hand); InitHand(); BeginHand(); UpdateHand(); } else { SetLeapHand(hand); UpdateHand(); } } }
/// <summary> /// Makes a new leap hand so we can use it to set an editor pose /// </summary> /// <param name="binder"></param> private void MakeLeapHand(HandBinder binder) { LeapProvider provider = null; //First try to get the provider from a parent HandModelManager if (binder.transform.parent != null) { var manager = binder.transform.parent.GetComponent <HandModelManager>(); if (manager != null) { provider = manager.leapProvider; } } //If not found, use any old provider from the Hands.Provider getter if (provider == null) { provider = Hands.Provider; } Hand hand = null; //If we found a provider, pull the hand from that if (provider != null) { var frame = provider.CurrentFrame; if (frame != null) { hand = frame.Get(binder.Handedness); } } //If we still have a null hand, construct one manually if (hand == null) { hand = TestHandFactory.MakeTestHand(binder.Handedness == Chirality.Left, unitType: TestHandFactory.UnitType.LeapUnits); hand.Transform(binder.transform.GetLeapMatrix()); } binder.LeapHand = hand; }
//Only Runs in editor private void Update() { if (!Application.isPlaying && SupportsEditorPersistence()) { //Try to set the provider for the user var Provider = Hands.Provider; Hand hand = null; if (Provider == null) { //If we still have a null hand, construct one manually if (hand == null) { hand = TestHandFactory.MakeTestHand(Handedness == Chirality.Left, unitType: TestHandFactory.UnitType.LeapUnits); hand.Transform(transform.GetLeapMatrix()); } } else { hand = Provider.CurrentFrame.GetHand(Handedness); } UpdateBase(hand); } }
protected override Frame createFrame() { _originalFrame = TestHandFactory.MakeTestFrame(0, true, true); return(_originalFrame.TransformedCopy(LeapTransform.Identity)); }
private void Start() { handID = !isLeft ? 0 : 1; leapHand = TestHandFactory.MakeTestHand(IsLeft, 0, handID, TestHandFactory.UnitType.UnityUnits); //GenerateHandData(0); SetHandData(leapHand, 0); }
public static Leap.Hand MakeTestHand(this LeapProvider provider, bool isLeft) { return(TestHandFactory.MakeTestHand(isLeft, Hands.Provider.editTimePose) .Transform(UnityMatrixExtension.GetLeapMatrix(Hands.Provider.transform))); }
protected override Frame createFrame() { return(TestHandFactory.MakeTestFrame(0, true, true)); }
void Update() { Debug.Log("Update() called"); Frame frame = null; // leapMotionListener.CurrentFrame; Hand hand = null; if (frame != null) { foreach (var h in frame.Hands) { if (h.IsLeft == (Handedness == Chirality.Left)) { hand = h; break; } } } // hand not found. construct a default one to show. if (hand == null) { hand = TestHandFactory.MakeTestHand(Handedness == Chirality.Left, unitType: TestHandFactory.UnitType.LeapUnits); hand.Transform(transform.GetLeapMatrix()); } // finally, show the hand. if (GetLeapHand() == null) { SetLeapHand(hand); InitHand(); BeginHand(); UpdateHand(); } else { SetLeapHand(hand); UpdateHand(); } //if (!EditorApplication.isPlaying && SupportsEditorPersistence()) { //LeapProvider provider = null; ////First try to get the provider from a parent HandModelManager //if (transform.parent != null) { // var manager = transform.parent.GetComponent<HandModelManager>(); // if (manager != null) { // provider = manager.leapProvider; // } //} ////If not found, use any old provider from the Hands.Provider getter //if (provider == null) { // provider = Hands.Provider; //} //Hand hand = null; ////If we found a provider, pull the hand from that //if (provider != null) { // var frame = provider.CurrentFrame; // if (frame != null) { // //hand = frame.Get(Handedness); // } //} ////If we still have a null hand, construct one manually //if (hand == null) { // hand = TestHandFactory.MakeTestHand(Handedness == Chirality.Left, unitType: TestHandFactory.UnitType.LeapUnits); // hand.Transform(transform.GetLeapMatrix()); //} //Debug.Log(provider); //Debug.Log(hand); //if (GetLeapHand() == null) { // SetLeapHand(hand); // InitHand(); // BeginHand(); // UpdateHand(); //} else { // SetLeapHand(hand); // UpdateHand(); //} }