From 15302055c6ef1989093368a6d3dadd5f69472338 Mon Sep 17 00:00:00 2001 From: Max Palme Date: Tue, 5 Mar 2024 12:13:39 +0000 Subject: [PATCH 1/2] Added an event for the raw tracking frame --- Packages/Tracking/CHANGELOG.md | 4 +- .../Runtime/Plugins/LeapCSharp/Connection.cs | 6 +++ .../Runtime/Plugins/LeapCSharp/Controller.cs | 15 ++++++++ .../Core/Runtime/Plugins/LeapCSharp/Events.cs | 37 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Packages/Tracking/CHANGELOG.md b/Packages/Tracking/CHANGELOG.md index a480b23542..26bfc7380e 100644 --- a/Packages/Tracking/CHANGELOG.md +++ b/Packages/Tracking/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Android v5.17.1 ### Added -- +- Now raise a RawFrameEvent for the raw tracking frame ### Changed - (Config) Additional uses of Config marked as Obsolete @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Errors in Editor when using pre-2023.3.18 LTS due to FindObjectByType issue - (Physical Hands) Objects are sticky when they ignore collision with hard contact hands +- Issue with the method signature for LeapPixelToRectilinearEx ## [6.14.0] - 24/01/24 @@ -36,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Physical Hands. This introduces a new way of interacting with object in the virtual world using your hands and unitys physics engine. +- Support for reading the camera matrix ### Changed - Removed Physics Hands from the preview package as Physical Hands has replaced it. diff --git a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs index 396c37e146..0c350cf669 100644 --- a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs +++ b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs @@ -123,6 +123,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")] @@ -408,6 +409,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))); diff --git a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs index df66c10414..8de10773a1 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 d23a39aeef..4d84e5b7a7 100644 --- a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs +++ b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs @@ -50,6 +50,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. /// From 6c9d355c75768dab8a29029f6769f59732348ba4 Mon Sep 17 00:00:00 2001 From: Max Palme Date: Tue, 5 Mar 2024 16:16:11 +0000 Subject: [PATCH 2/2] Fixed issue where Device ID field is not always set correctly on Frame, e.g. when playing back multiple devices via LeapCtrl --- Packages/Tracking/CHANGELOG.md | 4 +--- .../Core/Runtime/Plugins/LeapCSharp/Connection.cs | 12 ++++++++++-- .../Core/Runtime/Scripts/LeapServiceProvider.cs | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Packages/Tracking/CHANGELOG.md b/Packages/Tracking/CHANGELOG.md index 26bfc7380e..62c695325b 100644 --- a/Packages/Tracking/CHANGELOG.md +++ b/Packages/Tracking/CHANGELOG.md @@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Android v5.17.1 ### Added -- Now raise a RawFrameEvent for the raw tracking frame ### Changed - (Config) Additional uses of Config marked as Obsolete @@ -26,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Errors in Editor when using pre-2023.3.18 LTS due to FindObjectByType issue - (Physical Hands) Objects are sticky when they ignore collision with hard contact hands -- Issue with the method signature for LeapPixelToRectilinearEx +- DeviceID now correctly set on the Frame object, fixing issue particularly with multiple devices / recording playback ## [6.14.0] - 24/01/24 @@ -37,7 +36,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Physical Hands. This introduces a new way of interacting with object in the virtual world using your hands and unitys physics engine. -- Support for reading the camera matrix ### Changed - Removed Physics Hands from the preview package as Physical Hands has replaced it. diff --git a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs index 0c350cf669..1d4a94f8ae 100644 --- a/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs +++ b/Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs @@ -444,8 +444,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); @@ -467,6 +465,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); } @@ -493,6 +496,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/Scripts/LeapServiceProvider.cs b/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs index e313165d4a..67c251c58b 100644 --- a/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs +++ b/Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs @@ -647,6 +647,11 @@ protected virtual void FixedUpdate() else { _leapController.Frame(_untransformedFixedFrame); + + if (_currentDevice != null) + { + _untransformedFixedFrame.DeviceID = _currentDevice.DeviceID; + } } if (_untransformedFixedFrame != null)