Skip to content

Commit

Permalink
Update to latest LeapCSharp and LeapC SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Apr 13, 2022
1 parent 4509689 commit 987aa79
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 26 deletions.
6 changes: 3 additions & 3 deletions ml_lme_cvr/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;

[assembly: AssemblyTitle("LeapMotionExtension")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: AssemblyVersion("1.0.4")]
[assembly: AssemblyFileVersion("1.0.4")]

[assembly: MelonLoader.MelonInfo(typeof(ml_lme_cvr.LeapMotionExtension), "LeapMotionExtension", "1.0.3", "SDraw", "https://github.com/SDraw")]
[assembly: MelonLoader.MelonInfo(typeof(ml_lme_cvr.LeapMotionExtension), "LeapMotionExtension", "1.0.4", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
80 changes: 67 additions & 13 deletions ml_lme_cvr/vendor/LeapCSharp/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,41 @@ private void handleTrackingMessage(ref LEAP_TRACKING_EVENT trackingMsg, UInt32 d
}


public UInt64 GetInterpolatedFrameSize(Int64 time)
public UInt64 GetInterpolatedFrameSize(Int64 time, Device device = null)
{
UInt64 size = 0;
eLeapRS result = LeapC.GetFrameSize(_leapConnection, time, out size);
eLeapRS result;

if (device != null)
{
result = LeapC.GetFrameSizeEx(_leapConnection, device.Handle, time, out size);
}
else
{
result = LeapC.GetFrameSize(_leapConnection, time, out size);
}

reportAbnormalResults("LeapC get interpolated frame call was ", result);
return size;
}

public void GetInterpolatedFrame(Frame toFill, Int64 time)


public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null)
{
UInt64 size = GetInterpolatedFrameSize(time);
UInt64 size = GetInterpolatedFrameSize(time, device);
IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
eLeapRS result = LeapC.InterpolateFrame(_leapConnection, time, trackingBuffer, size);
eLeapRS result;

if (device != null)
{
result = LeapC.InterpolateFrameEx(_leapConnection, device.Handle, time, trackingBuffer, size);
}
else
{
result = LeapC.InterpolateFrame(_leapConnection, time, trackingBuffer, size);
}

reportAbnormalResults("LeapC get interpolated frame call was ", result);
if (result == eLeapRS.eLeapRS_Success)
{
Expand All @@ -432,11 +454,22 @@ public void GetInterpolatedFrame(Frame toFill, Int64 time)
Marshal.FreeHGlobal(trackingBuffer);
}

public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime)
public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime, Device device = null)
{
UInt64 size = GetInterpolatedFrameSize(time);
UInt64 size = GetInterpolatedFrameSize(time, device);
IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
eLeapRS result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
eLeapRS result;

if (device != null)
{

result = LeapC.InterpolateFrameFromTimeEx(_leapConnection, device.Handle, time, sourceTime, trackingBuffer, size);
}
else
{
result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
}

reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
if (result == eLeapRS.eLeapRS_Success)
{
Expand All @@ -447,10 +480,10 @@ public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceT
Marshal.FreeHGlobal(trackingBuffer);
}

public Frame GetInterpolatedFrame(Int64 time)
public Frame GetInterpolatedFrame(Int64 time, Device device = null)
{
Frame frame = new Frame();
GetInterpolatedFrame(frame, time);
GetInterpolatedFrame(frame, time, device);
return frame;
}

Expand All @@ -471,15 +504,26 @@ public void GetInterpolatedLeftRightTransform(Int64 time,
Int64 sourceTime,
Int64 leftId,
Int64 rightId,
Device device,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
leftTransform = LeapTransform.Identity;
rightTransform = LeapTransform.Identity;

UInt64 size = GetInterpolatedFrameSize(time);
UInt64 size = GetInterpolatedFrameSize(time, device);
IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
eLeapRS result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
eLeapRS result;

if (device != null)
{
result = LeapC.InterpolateFrameFromTimeEx(_leapConnection, device.Handle, time, sourceTime, trackingBuffer, size);
}
else
{
result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
}

reportAbnormalResults("LeapC get interpolated frame from time call was ", result);

if (result == eLeapRS.eLeapRS_Success)
Expand Down Expand Up @@ -516,6 +560,17 @@ public void GetInterpolatedLeftRightTransform(Int64 time,
}

Marshal.FreeHGlobal(trackingBuffer);

}

public void GetInterpolatedLeftRightTransform(Int64 time,
Int64 sourceTime,
Int64 leftId,
Int64 rightId,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, null, out leftTransform, out rightTransform);
}

private void handleConnection(ref LEAP_CONNECTION_EVENT connectionMsg)
Expand Down Expand Up @@ -545,7 +600,6 @@ private void handleDeviceStatusEvent(ref LEAP_DEVICE_STATUS_CHANGE_EVENT statusE
device.UpdateStatus(statusEvent.status);
}


private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
{
IntPtr deviceHandle = deviceMsg.device.handle;
Expand Down
52 changes: 46 additions & 6 deletions ml_lme_cvr/vendor/LeapCSharp/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,17 @@ public bool IsServiceConnected
}
}

/// <summary>
/// Returns the current Leap service version information.
/// </summary>
public LEAP_VERSION ServiceVersion
{
get
{
return _connection.GetCurrentServiceVersion();
}
}

/// <summary>
/// Checks whether a minimum or required tracking service version is installed.
/// Gets the currently installed service version from the connection and checks whether
Expand Down Expand Up @@ -634,20 +645,28 @@ public Frame GetTransformedFrame(LeapTransform trs, int history = 0)
return new Frame().CopyFrom(Frame(history)).Transform(trs);
}

/// <summary>
/// Returns the Frame at the specified time, interpolating the data between existing frames, if necessary.
/// </summary>
public Frame GetInterpolatedFrame(Int64 time, Device device = null)
{
return _connection.GetInterpolatedFrame(time, device);
}

/// <summary>
/// Returns the Frame at the specified time, interpolating the data between existing frames, if necessary.
/// </summary>
public Frame GetInterpolatedFrame(Int64 time)
{
return _connection.GetInterpolatedFrame(time);
return GetInterpolatedFrame(time, null);
}

/// <summary>
/// Fills the Frame with data taken at the specified time, interpolating the data between existing frames, if necessary.
/// </summary>
public void GetInterpolatedFrame(Frame toFill, Int64 time)
public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null)
{
_connection.GetInterpolatedFrame(toFill, time);
_connection.GetInterpolatedFrame(toFill, time, device);
}

/// <summary>
Expand Down Expand Up @@ -730,6 +749,27 @@ public void GetPointMapping(ref PointMapping pointMapping)
_connection.GetPointMapping(ref pointMapping);
}


/// <summary>
/// This is a special variant of GetInterpolatedFrameFromTime, for use with special
/// features that only require the position and orientation of the palm positions, and do
/// not care about pose data or any other data.
///
/// You must specify the id of the hand that you wish to get a transform for. If you specify
/// an id that is not present in the interpolated frame, the output transform will be the
/// identity transform.
/// </summary>
public void GetInterpolatedLeftRightTransform(Int64 time,
Int64 sourceTime,
int leftId,
int rightId,
Device device,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
_connection.GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, device, out leftTransform, out rightTransform);
}

/// <summary>
/// This is a special variant of GetInterpolatedFrameFromTime, for use with special
/// features that only require the position and orientation of the palm positions, and do
Expand All @@ -746,12 +786,12 @@ public void GetInterpolatedLeftRightTransform(Int64 time,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
_connection.GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, out leftTransform, out rightTransform);
GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, null, out leftTransform, out rightTransform);
}

public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime)
public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime, Device device = null)
{
_connection.GetInterpolatedFrameFromTime(toFill, time, sourceTime);
_connection.GetInterpolatedFrameFromTime(toFill, time, sourceTime, device);
}

/// <summary>
Expand Down
37 changes: 35 additions & 2 deletions ml_lme_cvr/vendor/LeapCSharp/LeapC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ public struct LEAP_VERSION
public Int32 major;
public Int32 minor;
public Int32 patch;

public new string ToString()
{
return major + "." + minor + "." + patch;
}
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down Expand Up @@ -657,6 +662,13 @@ public struct LEAP_TRACKING_EVENT
public float framerate;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LEAP_TRACKING_MODE_EVENT
{
public UInt32 reserved;
public eLeapTrackingMode current_tracking_mode;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LEAP_DROPPED_FRAME_EVENT
{
Expand Down Expand Up @@ -699,6 +711,8 @@ public struct LEAP_HEAD_POSE_EVENT
public Int64 timestamp;
public LEAP_VECTOR head_position;
public LEAP_QUATERNION head_orientation;
public LEAP_VECTOR head_linear_velocity;
public LEAP_VECTOR head_angular_velocity;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand Down Expand Up @@ -965,9 +979,15 @@ private LeapC() { }
[DllImport("LeapC", EntryPoint = "LeapSetTrackingMode")]
public static extern eLeapRS SetTrackingMode(IntPtr hConnection, eLeapTrackingMode mode);

[DllImport("LeapC", EntryPoint = "LeapSetTrackingModeEx")]
public static extern eLeapRS SetTrackingModeEx(IntPtr hConnection, IntPtr hDevice, eLeapTrackingMode mode);

[DllImport("LeapC", EntryPoint = "LeapGetTrackingMode")]
public static extern eLeapRS LeapGetTrackingMode(IntPtr hConnection);

[DllImport("LeapC", EntryPoint = "LeapGetTrackingModeEx")]
public static extern eLeapRS LeapGetTrackingModeEx(IntPtr hConnection, IntPtr hDevice);

[DllImport("LeapC", EntryPoint = "LeapGetNow")]
public static extern long GetNow();

Expand Down Expand Up @@ -1017,6 +1037,9 @@ public static eLeapRS GetDeviceCount(IntPtr hConnection, out UInt32 deviceCount)
[DllImport("LeapC", EntryPoint = "LeapOpenDevice")]
public static extern eLeapRS OpenDevice(LEAP_DEVICE_REF rDevice, out IntPtr pDevice);

[DllImport("LeapC", EntryPoint = "LeapSetPrimaryDevice")]
public static extern eLeapRS LeapSetPrimaryDevice(IntPtr hConnection, IntPtr hDevice, bool unsubscribeOthers);

[DllImport("LeapC", EntryPoint = "LeapSubscribeEvents")]
public static extern eLeapRS LeapSubscribeEvents(IntPtr hConnection, IntPtr hDevice);

Expand All @@ -1029,11 +1052,12 @@ public static eLeapRS GetDeviceCount(IntPtr hConnection, out UInt32 deviceCount)
[DllImport("LeapC", EntryPoint = "LeapGetDeviceTransform")]
public static extern eLeapRS GetDeviceTransform(IntPtr hDevice, out float[] transform);

// Will be a SetPolicyFlagsEx()..

[DllImport("LeapC", EntryPoint = "LeapSetPolicyFlags")]
public static extern eLeapRS SetPolicyFlags(IntPtr hConnection, UInt64 set, UInt64 clear);

[DllImport("LeapC", EntryPoint = "LeapSetPolicyFlagsEx")]
public static extern eLeapRS SetPolicyFlagsEx(IntPtr hConnection, IntPtr hDevice, UInt64 set, UInt64 clear);

[DllImport("LeapC", EntryPoint = "LeapSetPause")]
public static extern eLeapRS LeapSetPause(IntPtr hConnection, bool pause);

Expand All @@ -1046,12 +1070,21 @@ public static eLeapRS GetDeviceCount(IntPtr hConnection, out UInt32 deviceCount)
[DllImport("LeapC", EntryPoint = "LeapGetFrameSize")]
public static extern eLeapRS GetFrameSize(IntPtr hConnection, Int64 timestamp, out UInt64 pncbEvent);

[DllImport("LeapC", EntryPoint = "LeapGetFrameSizeEx")]
public static extern eLeapRS GetFrameSizeEx(IntPtr hConnection, IntPtr hDevice, Int64 timestamp, out UInt64 pncbEvent);

[DllImport("LeapC", EntryPoint = "LeapInterpolateFrame")]
public static extern eLeapRS InterpolateFrame(IntPtr hConnection, Int64 timestamp, IntPtr pEvent, UInt64 ncbEvent);

[DllImport("LeapC", EntryPoint = "LeapInterpolateFrameEx")]
public static extern eLeapRS InterpolateFrameEx(IntPtr hConnection, IntPtr hDevice, Int64 timestamp, IntPtr pEvent, UInt64 ncbEvent);

[DllImport("LeapC", EntryPoint = "LeapInterpolateFrameFromTime")]
public static extern eLeapRS InterpolateFrameFromTime(IntPtr hConnection, Int64 timestamp, Int64 sourceTimestamp, IntPtr pEvent, UInt64 ncbEvent);

[DllImport("LeapC", EntryPoint = "LeapInterpolateFrameFromTimeEx")]
public static extern eLeapRS InterpolateFrameFromTimeEx(IntPtr hConnection, IntPtr hDevice, Int64 timestamp, Int64 sourceTimestamp, IntPtr pEvent, UInt64 ncbEvent);

[DllImport("LeapC", EntryPoint = "LeapInterpolateHeadPose")]
public static extern eLeapRS InterpolateHeadPose(IntPtr hConnection, Int64 timestamp, ref LEAP_HEAD_POSE_EVENT headPose);

Expand Down
4 changes: 2 additions & 2 deletions ml_lme_cvr/vendor/LeapSDK/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ULTRALEAP TRACKING SDK AGREEMENT
Updated: 26 October 2021
Updated: 22 March 2022
Permitted uses
This SDK Agreement (“Agreement”) covers use of the Ultraleap hand tracking SDK (the “SDK”) by
individuals and businesses for the following purposes:
Expand Down Expand Up @@ -355,7 +355,7 @@ permitted uses set out in this Agreement.
“Ultraleap” “we” or “us” means Ultraleap Limited, a company registered in England with company
number 08781720, with a principal place of business at The West Wing, Glass Wharf, Bristol, BS2 0EL,
United Kingdom.
“Ultraleap Hardware” means the Leap Motion Controller or Stereo IR 170, each being a device that
“Ultraleap Hardware” means the Leap Motion Controller, Stereo IR 170, Stereo IR 170 EK or Ultraleap 3Di each being a device that
detects and reads movements within a 3-D interaction space to precisely interact with and control
software on a computing device, or an Ultraleap-authorized embedded optical module.
“Ultraleap Redistributables” means any .lib code, .dll files, .so files, sample code, or other materials
Expand Down
Loading

0 comments on commit 987aa79

Please sign in to comment.