diff --git a/Packages/Tracking/CHANGELOG.md b/Packages/Tracking/CHANGELOG.md index 2378d1fd3..40a8343fa 100644 --- a/Packages/Tracking/CHANGELOG.md +++ b/Packages/Tracking/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### Fixed +- DeviceID now correctly set on the Frame object, fixing issue particularly with multiple devices / recording playback - Fixed issue with LeapXRHandProvider not working on Quest devices when using XRI/XR Hands and Ultraleap tracking in direct (non OpenXR) mode, due to default constructor being optimized away. ## [7.1.0] - 04/09/2024 diff --git a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs index 1eb000cc6..120d11305 100644 --- a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs +++ b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs @@ -120,6 +120,7 @@ public event EventHandler LeapConnection public EventHandler LeapDeviceFailure; public EventHandler LeapPolicyChange; public EventHandler LeapFrame; + public EventHandler LeapRawFrameData; public EventHandler LeapInternalFrame; public EventHandler LeapLogEvent; [Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")] @@ -413,6 +414,11 @@ private void handleTrackingMessage(ref LEAP_TRACKING_EVENT trackingMsg, UInt32 d { Frames.Put(ref trackingMsg); + if (LeapRawFrameData != null) + { + LeapRawFrameData.DispatchOnContext(this, EventContext, new RawFrameEventArgs(trackingMsg)); + } + if (LeapFrame != null) { LeapFrame.DispatchOnContext(this, EventContext, new FrameEventArgs(new Frame(deviceID).CopyFrom(ref trackingMsg))); @@ -443,8 +449,6 @@ public UInt64 GetInterpolatedFrameSize(Int64 time, Device device = null) return size; } - - public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null) { UInt64 size = GetInterpolatedFrameSize(time, device); @@ -466,6 +470,11 @@ public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null) LEAP_TRACKING_EVENT tracking_evt; StructMarshal.PtrToStruct(trackingBuffer, out tracking_evt); toFill.CopyFrom(ref tracking_evt); + + if (device != null) + { + toFill.DeviceID = device.DeviceID; + } } Marshal.FreeHGlobal(trackingBuffer); } @@ -492,6 +501,11 @@ public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceT LEAP_TRACKING_EVENT tracking_evt; StructMarshal.PtrToStruct(trackingBuffer, out tracking_evt); toFill.CopyFrom(ref tracking_evt); + + if (device != null) + { + toFill.DeviceID = device.DeviceID; + } } Marshal.FreeHGlobal(trackingBuffer); } diff --git a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs index 823ad1d30..17b10b653 100644 --- a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs +++ b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs @@ -132,6 +132,21 @@ public event EventHandler FrameReady } } + /// + /// Dispatched when the raw frame data is ready + /// + public event EventHandler RawFrameReady + { + add + { + _connection.LeapRawFrameData += value; + } + remove + { + _connection.LeapRawFrameData -= value; + } + } + /// /// Dispatched when an internal tracking frame is ready. /// @since 3.0 diff --git a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs index 35a1a5907..aedc0212b 100644 --- a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs +++ b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs @@ -52,6 +52,43 @@ public LeapEventArgs(LeapEvent type) public LeapEvent type { get; set; } } + /// + /// Provides access to the raw leap frame data + /// + public class RawFrameEventArgs : LeapEventArgs + { + public bool IsTrackingLeftHand { get; set; } + public LEAP_HAND LeftHand { get; set; } + + public bool IsTrackingRightHand { get; set; } + public LEAP_HAND RightHand { get; set; } + + public RawFrameEventArgs(LEAP_TRACKING_EVENT trackingMsg) : base(LeapEvent.EVENT_FRAME) + { + IsTrackingLeftHand = false; + IsTrackingRightHand = false; + + for (int i = (int)trackingMsg.nHands; i-- != 0;) + { + LEAP_HAND hand; + StructMarshal.ArrayElementToStruct(trackingMsg.pHands, i, out hand); + + switch (hand.type) + { + case eLeapHandType.eLeapHandType_Left: + LeftHand = hand; + IsTrackingLeftHand = true; + break; + + case eLeapHandType.eLeapHandType_Right: + RightHand = hand; + IsTrackingRightHand = true; + break; + } + } + } + } + /// /// Dispatched when a tracking frame is ready. /// diff --git a/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs b/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs index 28e86e6f3..04586a583 100644 --- a/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs +++ b/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs @@ -652,6 +652,11 @@ protected virtual void FixedUpdate() else { _leapController.Frame(_untransformedFixedFrame); + + if (_currentDevice != null) + { + _untransformedFixedFrame.DeviceID = _currentDevice.DeviceID; + } } if (_untransformedFixedFrame != null)