Instance set changes

Additional animator parameters
Reworked rigidbodies
Update to latest LeapC and LeapCSharp
This commit is contained in:
SDraw 2024-07-20 11:13:51 +03:00
parent 1f0b518761
commit 075ff67304
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
38 changed files with 8310 additions and 8646 deletions

View file

@ -13,6 +13,7 @@ namespace LeapInternal
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using UnityEngine;
public class Connection
{
@ -1195,11 +1196,7 @@ namespace LeapInternal
return new UnityEngine.Vector3(ray.x, ray.y, ray.z);
}
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
///
/// Also allows specifying a specific device handle and calibration type.
/// </summary>
[Obsolete("calibType is not necessary. Please use the alternative PixelToRectilinearEx method.")]
public UnityEngine.Vector3 PixelToRectilinearEx(IntPtr deviceHandle,
Image.CameraType camera, Image.CalibrationType calibType, UnityEngine.Vector3 pixel)
{
@ -1216,6 +1213,24 @@ namespace LeapInternal
return new UnityEngine.Vector3(ray.x, ray.y, ray.z);
}
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
///
/// Also allows specifying a specific device handle and calibration type.
/// </summary>
public UnityEngine.Vector3 PixelToRectilinearEx(IntPtr deviceHandle,
Image.CameraType camera, UnityEngine.Vector3 pixel)
{
LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel);
LEAP_VECTOR ray = LeapC.LeapPixelToRectilinearEx(_leapConnection,
deviceHandle,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
pixelStruct);
return new UnityEngine.Vector3(ray.x, ray.y, ray.z);
}
/// <summary>
/// Converts from camera-space rectilinear coordinates to image-space pixel coordinates
/// </summary>
@ -1302,6 +1317,48 @@ namespace LeapInternal
Marshal.FreeHGlobal(buffer);
}
/// <summary>
/// Request the Extrinsic Camera Matrix
/// </summary>
public Matrix4x4 LeapExtrinsicCameraMatrix(Image.CameraType camera, Device device)
{
float[] data = new float[16];
try
{
eLeapRS result = eLeapRS.eLeapRS_Success;
if (device != null)
{
result = LeapC.LeapExtrinsicCameraMatrixEx(_leapConnection, device.Handle, camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right, data);
}
else
{
result = LeapC.LeapExtrinsicCameraMatrix(_leapConnection, camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right, data);
}
if (result != eLeapRS.eLeapRS_Success)
{
return new Matrix4x4(new Vector4(data[0], data[1], data[2], data[3]),
new Vector4(data[4], data[5], data[6], data[7]),
new Vector4(data[8], data[9], data[10], data[11]),
new Vector4(data[12], data[13], data[14], data[15])
);
}
}
catch (Exception e)
{
Debug.LogException(e);
}
return Matrix4x4.identity;
}
/// <summary>
/// Send a specific set of hints to hDevice, if this does not include previously set ones, they will be cleared.
/// </summary>

View file

@ -863,6 +863,26 @@ namespace Leap
_connection.GetInterpolatedFrameFromTime(toFill, time, sourceTime, device);
}
public UnityEngine.Matrix4x4 LeapExtrinsicCameraMatrix(Image.CameraType camera, Device device)
{
return _connection.LeapExtrinsicCameraMatrix(camera, device);
}
public UnityEngine.Vector3 RectilinearToPixel(Image.CameraType camera, UnityEngine.Vector3 ray)
{
return _connection.RectilinearToPixel(camera, ray);
}
public UnityEngine.Vector3 RectilinearToPixelEx(Image.CameraType camera, UnityEngine.Vector3 ray, Device device)
{
return _connection.RectilinearToPixelEx(device.Handle, camera, ray);
}
public UnityEngine.Vector3 PixelToRectilinearEx(Image.CameraType camera, UnityEngine.Vector3 pixel, Device device)
{
return _connection.PixelToRectilinearEx(device.Handle, camera, pixel);
}
/// <summary>
/// Returns a timestamp value as close as possible to the current time.
/// Values are in microseconds, as with all the other timestamp values.

View file

@ -14,9 +14,6 @@ namespace LeapInternal
{
public static readonly float MM_TO_M = 1e-3f;
public static bool leapToUnityTransformSet = false;
private static LeapTransform leapToUnityTransform;
/**
* Provides a static LeapTransform that converts from Leap units and coordinates to Unity
*/
@ -24,12 +21,8 @@ namespace LeapInternal
{
get
{
if (!leapToUnityTransformSet)
{
leapToUnityTransform = new LeapTransform(Vector3.zero, Quaternion.identity, new Vector3(MM_TO_M, MM_TO_M, MM_TO_M));
leapToUnityTransform.MirrorZ();
leapToUnityTransformSet = true;
}
LeapTransform leapToUnityTransform = new LeapTransform(Vector3.zero, Quaternion.identity, new Vector3(MM_TO_M, MM_TO_M, MM_TO_M));
leapToUnityTransform.MirrorZ();
return leapToUnityTransform;
}

View file

@ -1133,10 +1133,14 @@ namespace LeapInternal
public static extern LEAP_VECTOR LeapPixelToRectilinear(IntPtr hConnection,
eLeapPerspectiveType camera, LEAP_VECTOR pixel);
[DllImport("LeapC", EntryPoint = "LeapPixelToRectilinearEx")]
[Obsolete("Use of calibrationType is not valid. Use alternative LeapPixelToRectilinearEx method."), DllImport("LeapC", EntryPoint = "LeapPixelToRectilinearEx")]
public static extern LEAP_VECTOR LeapPixelToRectilinearEx(IntPtr hConnection,
IntPtr hDevice, eLeapPerspectiveType camera, eLeapCameraCalibrationType calibrationType, LEAP_VECTOR pixel);
[DllImport("LeapC", EntryPoint = "LeapPixelToRectilinearEx")]
public static extern LEAP_VECTOR LeapPixelToRectilinearEx(IntPtr hConnection,
IntPtr hDevice, eLeapPerspectiveType camera, LEAP_VECTOR pixel);
[DllImport("LeapC", EntryPoint = "LeapRectilinearToPixel")]
public static extern LEAP_VECTOR LeapRectilinearToPixel(IntPtr hConnection,
eLeapPerspectiveType camera, LEAP_VECTOR rectilinear);
@ -1145,6 +1149,14 @@ namespace LeapInternal
public static extern LEAP_VECTOR LeapRectilinearToPixelEx(IntPtr hConnection,
IntPtr hDevice, eLeapPerspectiveType camera, LEAP_VECTOR rectilinear);
[DllImport("LeapC", EntryPoint = "LeapExtrinsicCameraMatrix")]
public static extern eLeapRS LeapExtrinsicCameraMatrix(IntPtr hConnection, eLeapPerspectiveType camera,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 16)] float[] extrinsicMatrix);
[DllImport("LeapC", EntryPoint = "LeapExtrinsicCameraMatrixEx")]
public static extern eLeapRS LeapExtrinsicCameraMatrixEx(IntPtr hConnection, IntPtr hDevice, eLeapPerspectiveType camera,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 16)] float[] extrinsicMatrix);
[DllImport("LeapC", EntryPoint = "LeapCloseDevice")]
public static extern void CloseDevice(IntPtr pDevice);
@ -1273,7 +1285,6 @@ namespace LeapInternal
[DllImport("LeapC", EntryPoint = "LeapGetVersion")]
public static extern eLeapRS GetVersion(IntPtr hConnection, eLeapVersionPart versionPart, ref LEAP_VERSION pVersion);
[DllImport("LeapC", EntryPoint = "LeapGetServerStatus")]
public static extern eLeapRS GetServerStatus(UInt32 timeout, ref IntPtr status);

View file

@ -25,12 +25,16 @@ namespace LeapInternal
if (lastRequestTimestamp + requestInterval < Time.realtimeSinceStartup)
{
IntPtr statusPtr = new IntPtr();
LeapC.GetServerStatus(1000, ref statusPtr);
LeapC.GetServerStatus(500, ref statusPtr);
lastStatus = Marshal.PtrToStructure<LeapC.LEAP_SERVER_STATUS>(statusPtr);
if (statusPtr != IntPtr.Zero)
{
lastStatus = Marshal.PtrToStructure<LeapC.LEAP_SERVER_STATUS>(statusPtr);
MarshalUnmananagedArray2Struct(lastStatus.devices, (int)lastStatus.device_count, out lastDevices);
LeapC.ReleaseServerStatus(ref lastStatus);
}
MarshalUnmananagedArray2Struct(lastStatus.devices, (int)lastStatus.device_count, out lastDevices);
LeapC.ReleaseServerStatus(ref lastStatus);
lastRequestTimestamp = Time.realtimeSinceStartup;
}
}
@ -97,7 +101,7 @@ namespace LeapInternal
return "";
}
public static void MarshalUnmananagedArray2Struct<T>(IntPtr unmanagedArray, int length, out T[] mangagedArray)
static void MarshalUnmananagedArray2Struct<T>(IntPtr unmanagedArray, int length, out T[] mangagedArray)
{
var size = Marshal.SizeOf(typeof(T));
mangagedArray = new T[length];