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 2 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
2 changes: 1 addition & 1 deletion Packages/Tracking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Android v5.17.1

### Added
-

### Changed
- (Config) Additional uses of Config marked as Obsolete
Expand All @@ -26,6 +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
- DeviceID now correctly set on the Frame object, fixing issue particularly with multiple devices / recording playback

## [6.14.0] - 24/01/24

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 @@ -123,6 +123,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 @@ -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)));
Expand Down Expand Up @@ -438,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);
Expand All @@ -461,6 +465,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 @@ -487,6 +496,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 @@ -50,6 +50,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 @@ -647,6 +647,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