public void UpdateFingers(Hand h, Transform parent, Vector3 offset) { for (int i = 0; i < m_fingers.Length; ++i) { LeapFinger finger = m_fingers[i].GetComponent <LeapFinger>(); GameObject [] joints = finger.GetJoints(); GameObject [] langes = finger.GetLanges(); for (int j = 0; j < joints.Length; ++j) { Vector3 pos = parent.TransformPoint(offset + h.Fingers[i].JointPosition((Finger.FingerJoint)j).ToUnityScaled()); Vector3 nextPos = parent.TransformPoint(offset + h.Fingers[i].JointPosition((Finger.FingerJoint)j + 1).ToUnityScaled()); joints[j].transform.position = pos; joints[j].rigidbody.velocity = parent.TransformDirection(h.Fingers[i].TipVelocity.ToUnityScaled()); Vector3 langePos = (pos + nextPos) * 0.5f; langes[j].transform.position = langePos; langes[j].transform.up = (nextPos - pos); Vector3 newScale = langes[j].transform.localScale; newScale.y = Mathf.Max(0.0f, (nextPos - pos).magnitude - 0.003f); langes[j].transform.localScale = newScale; } Vector3 tipPos = parent.TransformPoint(offset + h.Fingers[i].JointPosition(Finger.FingerJoint.JOINTTIP).ToUnityScaled()); finger.GetFingerTip().transform.position = tipPos; finger.GetFingerTip().rigidbody.velocity = parent.TransformDirection(h.Fingers[i].TipVelocity.ToUnityScaled()); finger.m_fingerID = h.Fingers[i].Id; } }
//Destroy Unity components of the finger public void DestroyFingerComponents(LeapFinger leapFinger) { Destroy(leapFinger.getFingerObject()); Destroy(leapFinger.getMetacarpal().getBoneObject()); Destroy(leapFinger.getMetacarpal().getPreJointObject()); Destroy(leapFinger.getProximal().getBoneObject()); Destroy(leapFinger.getProximal().getPreJointObject()); Destroy(leapFinger.getIntermediate().getBoneObject()); Destroy(leapFinger.getIntermediate().getPreJointObject()); Destroy(leapFinger.getDistal().getBoneObject()); Destroy(leapFinger.getDistal().getPreJointObject()); }
private void DataReady(object sender, FrameEventArgs e) { if (OnSerializationReady == null) { return; } Frame frame = e.frame; if (frame == null) { //OnSerializationReady.Invoke(this, new SerializationEventArgs(LeapSerialization.DataIndex)); return; } LeapFrame newFrame = new LeapFrame() { Id = frame.Id }; List <Hand> hands = frame.Hands; int handCount = limitedHandCount == -1 ? hands.Count : Math.Min(limitedHandCount, hands.Count); for (int handIndex = 0; handIndex < handCount; handIndex++) { Hand hand = hands[handIndex]; List <Finger> fingers = hand.Fingers; List <LeapFinger> leapFingers = new List <LeapFinger>(); for (int fingerIndex = 0; fingerIndex < FingerCount; fingerIndex++) { Finger finger = fingers[fingerIndex]; LeapFinger leapFinger = new LeapFinger() { Id = finger.Id, IsExtended = fingers[fingerIndex].IsExtended, TimeVisible = fingers[fingerIndex].TimeVisible, Width = fingers[fingerIndex].Width, Length = fingers[fingerIndex].Length, TipPosition = fingers[fingerIndex].TipPosition.ToSerialiableVector(), Direction = fingers[fingerIndex].Direction.ToSerialiableVector(), TipVelocity = fingers[fingerIndex].TipVelocity.ToSerialiableVector() //StabilizedTipVelocity = fingers[fingerIndex].ToSerialiableVector() }; if (readBones) { Bone[] bones = fingers[fingerIndex].bones; LeapBone[] leapBones = new LeapBone[BoneCount]; for (int boneIndex = 0; boneIndex < BoneCount; boneIndex++) { leapBones[boneIndex] = new LeapBone() { Length = bones[boneIndex].Length, Width = bones[boneIndex].Width, Center = bones[boneIndex].Center.ToSerialiableVector(), Direction = bones[boneIndex].Direction.ToSerialiableVector(), Rotation = bones[boneIndex].Rotation.ToSerialiableQuaternion() }; } leapFinger.bones = leapBones; } leapFingers.Add(leapFinger); } LeapHand leapHand = new LeapHand() { Id = hand.Id, IsLeft = hand.IsLeft, Confidence = hand.Confidence, TimeVisible = hand.TimeVisible, GrabStrength = hand.GrabStrength, GrabAngle = hand.GrabAngle, PinchStrength = hand.PinchStrength, PinchDistance = hand.PinchDistance, PalmWidth = hand.PalmWidth, PalmPosition = hand.PalmPosition.ToSerialiableVector(), PalmVelocity = hand.PalmVelocity.ToSerialiableVector(), Direction = hand.Direction.ToSerialiableVector(), PalmNormal = hand.PalmNormal.ToSerialiableVector(), Rotation = hand.Rotation.ToSerialiableQuaternion(), WristPosition = hand.WristPosition.ToSerialiableVector(), //StabilizedPalmPosition = hand.StabilizedPalmPosition.ToSerialiableVector(), Fingers = leapFingers, }; if (readArm) { Arm arm = hand.Arm; LeapArm leapArm = new LeapArm() { Length = arm.Length, Width = arm.Width, Elbow = arm.ElbowPosition.ToSerialiableVector(), Wrist = arm.WristPosition.ToSerialiableVector(), Center = hand.Arm.Center.ToSerialiableVector(), Direction = hand.Arm.Direction.ToSerialiableVector(), Rotation = hand.Arm.Rotation.ToSerialiableQuaternion() }; leapHand.Arm = leapArm; } newFrame.Hands.Add(leapHand); } data.frame = newFrame; if (hands.Count > 0) { OnSerializationReady.Invoke(this, new SerializationEventArgs(LeapData.DataIndex, SerializationUtil.Serialize(data), true)); sentNoHandTimes = 0; } else if (SendNoHandMaxCount == -1 || ++sentNoHandTimes <= SendNoHandMaxCount) { OnSerializationReady.Invoke(this, new SerializationEventArgs(LeapData.DataIndex, SerializationUtil.Serialize(data), true)); } }