Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/unity 1463 fix device id on frame #1562

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/Tracking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public event EventHandler<ConnectionEventArgs> LeapConnection
public EventHandler<DeviceFailureEventArgs> LeapDeviceFailure;
public EventHandler<PolicyEventArgs> LeapPolicyChange;
public EventHandler<FrameEventArgs> LeapFrame;
public EventHandler<RawFrameEventArgs> LeapRawFrameData;
public EventHandler<InternalFrameEventArgs> LeapInternalFrame;
public EventHandler<LogEventArgs> LeapLogEvent;
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
Expand All @@ -466,6 +470,11 @@ public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null)
LEAP_TRACKING_EVENT tracking_evt;
StructMarshal<LEAP_TRACKING_EVENT>.PtrToStruct(trackingBuffer, out tracking_evt);
toFill.CopyFrom(ref tracking_evt);

if (device != null)
{
toFill.DeviceID = device.DeviceID;
}
}
Marshal.FreeHGlobal(trackingBuffer);
}
Expand All @@ -492,6 +501,11 @@ public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceT
LEAP_TRACKING_EVENT tracking_evt;
StructMarshal<LEAP_TRACKING_EVENT>.PtrToStruct(trackingBuffer, out tracking_evt);
toFill.CopyFrom(ref tracking_evt);

if (device != null)
{
toFill.DeviceID = device.DeviceID;
}
}
Marshal.FreeHGlobal(trackingBuffer);
}
Expand Down
15 changes: 15 additions & 0 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ public event EventHandler<FrameEventArgs> FrameReady
}
}

/// <summary>
/// Dispatched when the raw frame data is ready
/// </summary>
public event EventHandler<RawFrameEventArgs> RawFrameReady
{
add
{
_connection.LeapRawFrameData += value;
}
remove
{
_connection.LeapRawFrameData -= value;
}
}

/// <summary>
/// Dispatched when an internal tracking frame is ready.
/// @since 3.0
Expand Down
37 changes: 37 additions & 0 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ public LeapEventArgs(LeapEvent type)
public LeapEvent type { get; set; }
}

/// <summary>
/// Provides access to the raw leap frame data
/// </summary>
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<LEAP_HAND>.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;
}
}
}
}

/// <summary>
/// Dispatched when a tracking frame is ready.
///
Expand Down
5 changes: 5 additions & 0 deletions Packages/Tracking/Core/Runtime/Scripts/LeapServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ protected virtual void FixedUpdate()
else
{
_leapController.Frame(_untransformedFixedFrame);

if (_currentDevice != null)
{
_untransformedFixedFrame.DeviceID = _currentDevice.DeviceID;
}
Comment on lines +656 to +659
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might actually draw attention to a larger issue

Conection.Frames has no idea about devices, and so is a stack of all frames, regardless of device. We then populate it with whichever frame is available

This means when interpolation is not enabled, the provided data can be from any active device, regardless of the device that should be used for the specific LeapServiceProvider

}

if (_untransformedFixedFrame != null)
Expand Down