mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 03:19:23 +00:00
Custom event classes for patched methods
Update to LeapCSharp 6.15.0
This commit is contained in:
parent
4b879d53d5
commit
85925a7072
76 changed files with 3443 additions and 2187 deletions
6
ml_lme/vendor/LeapCSharp/Config.cs
vendored
6
ml_lme/vendor/LeapCSharp/Config.cs
vendored
|
@ -30,7 +30,7 @@ namespace Leap
|
|||
/// Note that the Controller.Config provides a properly initialized Config object already.
|
||||
/// @since 3.0
|
||||
/// </summary>
|
||||
[Obsolete("Config.cs is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public Config(Connection.Key connectionKey)
|
||||
{
|
||||
_connection = Connection.GetConnection(connectionKey);
|
||||
|
@ -38,9 +38,10 @@ namespace Leap
|
|||
_connection.LeapConfigResponse += handleConfigResponse;
|
||||
}
|
||||
|
||||
[Obsolete("Config.cs is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public Config(int connectionId) : this(new Connection.Key(connectionId)) { }
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
private void handleConfigChange(object sender, ConfigChangeEventArgs eventArgs)
|
||||
{
|
||||
object actionDelegate;
|
||||
|
@ -52,6 +53,7 @@ namespace Leap
|
|||
}
|
||||
}
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
private void handleConfigResponse(object sender, SetConfigResponseEventArgs eventArgs)
|
||||
{
|
||||
object actionDelegate = new object();
|
||||
|
|
149
ml_lme/vendor/LeapCSharp/Connection.cs
vendored
149
ml_lme/vendor/LeapCSharp/Connection.cs
vendored
|
@ -72,13 +72,9 @@ namespace LeapInternal
|
|||
|
||||
private IntPtr _leapConnection;
|
||||
private volatile bool _isRunning = false;
|
||||
public bool IsRunning { get { return _isRunning; } }
|
||||
private Thread _polster;
|
||||
|
||||
/// <summary>
|
||||
/// Has the connection been set up in multi device aware mode
|
||||
/// </summary>
|
||||
private bool _multiDeviceAwareConnection = false;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum service version that support setting the tracking mode on a per dervice basis
|
||||
/// </summary>
|
||||
|
@ -88,6 +84,7 @@ namespace LeapInternal
|
|||
private Dictionary<uint, UInt64> _activePolicies = new Dictionary<uint, ulong>();
|
||||
|
||||
//Config change status
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
private Dictionary<uint, string> _configRequests = new Dictionary<uint, string>();
|
||||
|
||||
//Connection events
|
||||
|
@ -124,13 +121,16 @@ namespace LeapInternal
|
|||
public EventHandler<FrameEventArgs> LeapFrame;
|
||||
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")]
|
||||
public EventHandler<SetConfigResponseEventArgs> LeapConfigResponse;
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public EventHandler<ConfigChangeEventArgs> LeapConfigChange;
|
||||
public EventHandler<DistortionEventArgs> LeapDistortionChange;
|
||||
public EventHandler<DroppedFrameEventArgs> LeapDroppedFrame;
|
||||
public EventHandler<ImageEventArgs> LeapImage;
|
||||
public EventHandler<PointMappingChangeEventArgs> LeapPointMappingChange;
|
||||
public EventHandler<HeadPoseEventArgs> LeapHeadPoseChange;
|
||||
public EventHandler<FiducialPoseEventArgs> LeapFiducialPose;
|
||||
|
||||
public Action<BeginProfilingForThreadArgs> LeapBeginProfilingForThread;
|
||||
public Action<EndProfilingForThreadArgs> LeapEndProfilingForThread;
|
||||
|
@ -151,10 +151,6 @@ namespace LeapInternal
|
|||
if (_disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
|
||||
Stop();
|
||||
LeapC.DestroyConnection(_leapConnection);
|
||||
_leapConnection = IntPtr.Zero;
|
||||
|
@ -181,9 +177,8 @@ namespace LeapInternal
|
|||
{
|
||||
LEAP_CONNECTION_CONFIG config = new LEAP_CONNECTION_CONFIG();
|
||||
config.server_namespace = Marshal.StringToHGlobalAnsi(serverNamespace);
|
||||
config.flags = multiDeviceAware ? (uint)eLeapConnectionFlag.eLeapConnectionFlag_MultipleDevicesAware : 0;
|
||||
config.flags = (uint)eLeapConnectionFlag.eLeapConnectionFlag_MultipleDevicesAware;
|
||||
config.size = (uint)Marshal.SizeOf(config);
|
||||
_multiDeviceAwareConnection = multiDeviceAware;
|
||||
Start(config);
|
||||
}
|
||||
|
||||
|
@ -210,7 +205,18 @@ namespace LeapInternal
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Produce metadata to send before connection is opened
|
||||
string metadata = MetadataUtil.GetMetaData();
|
||||
UIntPtr uIntPtr = new UIntPtr((uint)metadata.Length);
|
||||
|
||||
if (metadata != null && metadata != "")
|
||||
{
|
||||
LeapC.SetConnectionMetadata(_leapConnection, metadata, uIntPtr);
|
||||
}
|
||||
|
||||
result = LeapC.OpenConnection(_leapConnection);
|
||||
|
||||
if (result != eLeapRS.eLeapRS_Success)
|
||||
{
|
||||
reportAbnormalResults("LeapC OpenConnection call was ", result);
|
||||
|
@ -308,7 +314,6 @@ namespace LeapInternal
|
|||
{
|
||||
case eLeapEventType.eLeapEventType_None:
|
||||
break;
|
||||
|
||||
case eLeapEventType.eLeapEventType_Connection:
|
||||
LEAP_CONNECTION_EVENT connection_evt;
|
||||
StructMarshal<LEAP_CONNECTION_EVENT>.PtrToStruct(_msg.eventStructPtr, out connection_evt);
|
||||
|
@ -319,13 +324,11 @@ namespace LeapInternal
|
|||
StructMarshal<LEAP_CONNECTION_LOST_EVENT>.PtrToStruct(_msg.eventStructPtr, out connection_lost_evt);
|
||||
handleConnectionLost(ref connection_lost_evt);
|
||||
break;
|
||||
|
||||
case eLeapEventType.eLeapEventType_Device:
|
||||
LEAP_DEVICE_EVENT device_evt;
|
||||
StructMarshal<LEAP_DEVICE_EVENT>.PtrToStruct(_msg.eventStructPtr, out device_evt);
|
||||
handleDevice(ref device_evt);
|
||||
break;
|
||||
|
||||
// Note that unplugging a device generates an eLeapEventType_DeviceLost event
|
||||
// message, not a failure message. DeviceLost is further down.
|
||||
case eLeapEventType.eLeapEventType_DeviceFailure:
|
||||
|
@ -333,7 +336,6 @@ namespace LeapInternal
|
|||
StructMarshal<LEAP_DEVICE_FAILURE_EVENT>.PtrToStruct(_msg.eventStructPtr, out device_failure_evt);
|
||||
handleFailedDevice(ref device_failure_evt);
|
||||
break;
|
||||
|
||||
case eLeapEventType.eLeapEventType_Policy:
|
||||
LEAP_POLICY_EVENT policy_evt;
|
||||
StructMarshal<LEAP_POLICY_EVENT>.PtrToStruct(_msg.eventStructPtr, out policy_evt);
|
||||
|
@ -354,11 +356,6 @@ namespace LeapInternal
|
|||
StructMarshal<LEAP_DEVICE_EVENT>.PtrToStruct(_msg.eventStructPtr, out device_lost_evt);
|
||||
handleLostDevice(ref device_lost_evt);
|
||||
break;
|
||||
case eLeapEventType.eLeapEventType_ConfigChange:
|
||||
LEAP_CONFIG_CHANGE_EVENT config_change_evt;
|
||||
StructMarshal<LEAP_CONFIG_CHANGE_EVENT>.PtrToStruct(_msg.eventStructPtr, out config_change_evt);
|
||||
handleConfigChange(ref config_change_evt);
|
||||
break;
|
||||
case eLeapEventType.eLeapEventType_DroppedFrame:
|
||||
LEAP_DROPPED_FRAME_EVENT dropped_frame_evt;
|
||||
StructMarshal<LEAP_DROPPED_FRAME_EVENT>.PtrToStruct(_msg.eventStructPtr, out dropped_frame_evt);
|
||||
|
@ -374,16 +371,21 @@ namespace LeapInternal
|
|||
StructMarshal<LEAP_POINT_MAPPING_CHANGE_EVENT>.PtrToStruct(_msg.eventStructPtr, out point_mapping_change_evt);
|
||||
handlePointMappingChange(ref point_mapping_change_evt);
|
||||
break;
|
||||
case eLeapEventType.eLeapEventType_HeadPose:
|
||||
LEAP_HEAD_POSE_EVENT head_pose_event;
|
||||
StructMarshal<LEAP_HEAD_POSE_EVENT>.PtrToStruct(_msg.eventStructPtr, out head_pose_event);
|
||||
handleHeadPoseChange(ref head_pose_event);
|
||||
break;
|
||||
case eLeapEventType.eLeapEventType_DeviceStatusChange:
|
||||
LEAP_DEVICE_STATUS_CHANGE_EVENT status_evt;
|
||||
StructMarshal<LEAP_DEVICE_STATUS_CHANGE_EVENT>.PtrToStruct(_msg.eventStructPtr, out status_evt);
|
||||
handleDeviceStatusEvent(ref status_evt);
|
||||
break;
|
||||
case eLeapEventType.eLeapEventType_NewDeviceTransform:
|
||||
LEAP_NEW_DEVICE_TRANSFORM new_transform_evt;
|
||||
StructMarshal<LEAP_NEW_DEVICE_TRANSFORM>.PtrToStruct(_msg.eventStructPtr, out new_transform_evt);
|
||||
handleNewDeviceTransform(ref new_transform_evt, _msg.deviceID);
|
||||
break;
|
||||
case eLeapEventType.eLeapEventType_Fiducial:
|
||||
LEAP_FIDUCIAL_POSE_EVENT fiducial_event;
|
||||
StructMarshal<LEAP_FIDUCIAL_POSE_EVENT>.PtrToStruct(_msg.eventStructPtr, out fiducial_event);
|
||||
handleFiducialPoseEvent(ref fiducial_event);
|
||||
break;
|
||||
} //switch on _msg.type
|
||||
|
||||
if (LeapEndProfilingBlock != null && hasBegunProfilingForThread)
|
||||
|
@ -582,7 +584,6 @@ namespace LeapInternal
|
|||
}
|
||||
|
||||
Marshal.FreeHGlobal(trackingBuffer);
|
||||
|
||||
}
|
||||
|
||||
public void GetInterpolatedLeftRightTransform(Int64 time,
|
||||
|
@ -622,6 +623,15 @@ namespace LeapInternal
|
|||
device.UpdateStatus(statusEvent.status);
|
||||
}
|
||||
|
||||
private void handleFiducialPoseEvent(ref LEAP_FIDUCIAL_POSE_EVENT fiducialPoseEvent)
|
||||
{
|
||||
if (LeapFiducialPose != null)
|
||||
{
|
||||
LeapFiducialPose.DispatchOnContext(this, EventContext,
|
||||
new FiducialPoseEventArgs(fiducialPoseEvent));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
|
||||
{
|
||||
IntPtr deviceHandle = deviceMsg.device.handle;
|
||||
|
@ -733,19 +743,6 @@ namespace LeapInternal
|
|||
}
|
||||
}
|
||||
|
||||
private void handleConfigChange(ref LEAP_CONFIG_CHANGE_EVENT configEvent)
|
||||
{
|
||||
string config_key = "";
|
||||
_configRequests.TryGetValue(configEvent.requestId, out config_key);
|
||||
if (config_key != null)
|
||||
_configRequests.Remove(configEvent.requestId);
|
||||
if (LeapConfigChange != null)
|
||||
{
|
||||
LeapConfigChange.DispatchOnContext(this, EventContext,
|
||||
new ConfigChangeEventArgs(config_key, configEvent.status != false, configEvent.requestId));
|
||||
}
|
||||
}
|
||||
|
||||
private void reportLogMessage(ref LEAP_LOG_EVENT logMsg)
|
||||
{
|
||||
if (LeapLogEvent != null)
|
||||
|
@ -866,29 +863,30 @@ namespace LeapInternal
|
|||
_activePolicies[deviceID] = policyMsg.current_policy;
|
||||
}
|
||||
|
||||
private void handleNewDeviceTransform(ref LEAP_NEW_DEVICE_TRANSFORM deviceTransformMsg, UInt32 deviceID)
|
||||
{
|
||||
Device device = _devices.FindDeviceByID(deviceID);
|
||||
|
||||
if (device != null)
|
||||
{
|
||||
device.FindDeviceTransform();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetAndClearPolicy(Controller.PolicyFlag set, Controller.PolicyFlag clear, Device device = null)
|
||||
{
|
||||
UInt64 setFlags = (ulong)FlagForPolicy(set);
|
||||
UInt64 clearFlags = (ulong)FlagForPolicy(clear);
|
||||
eLeapRS result;
|
||||
|
||||
if (device == null || !_multiDeviceAwareConnection)
|
||||
if (device != null && Controller.CheckRequiredServiceVersion(MinServiceVersionForMultiModeSupport, this))
|
||||
{
|
||||
result = LeapC.SetPolicyFlags(_leapConnection, setFlags, clearFlags);
|
||||
result = LeapC.SetPolicyFlagsEx(_leapConnection, device.Handle, setFlags, clearFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Controller.CheckRequiredServiceVersion(MinServiceVersionForMultiModeSupport, this))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning(String.Format("Your current tracking service does not support setting policy flags on a per device basis (min version is {0}.{1}.{2}). Please update your service: https://developer.leapmotion.com/tracking-software-download",
|
||||
MinServiceVersionForMultiModeSupport.major,
|
||||
MinServiceVersionForMultiModeSupport.minor,
|
||||
MinServiceVersionForMultiModeSupport.patch));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
result = LeapC.SetPolicyFlagsEx(_leapConnection, device.Handle, setFlags, clearFlags);
|
||||
result = LeapC.SetPolicyFlags(_leapConnection, setFlags, clearFlags);
|
||||
}
|
||||
|
||||
reportAbnormalResults("LeapC SetAndClearPolicy call was ", result);
|
||||
|
@ -900,23 +898,13 @@ namespace LeapInternal
|
|||
|
||||
eLeapRS result;
|
||||
|
||||
if (device == null || !_multiDeviceAwareConnection)
|
||||
if (device != null && Controller.CheckRequiredServiceVersion(MinServiceVersionForMultiModeSupport, this))
|
||||
{
|
||||
result = LeapC.SetPolicyFlags(_leapConnection, setFlags, 0);
|
||||
result = LeapC.SetPolicyFlagsEx(_leapConnection, device.Handle, setFlags, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Controller.CheckRequiredServiceVersion(MinServiceVersionForMultiModeSupport, this))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning(String.Format("Your current tracking service does not support setting policy flags on a per device basis (min version is {0}.{1}.{2}). Please update your service: https://developer.leapmotion.com/tracking-software-download",
|
||||
MinServiceVersionForMultiModeSupport.major,
|
||||
MinServiceVersionForMultiModeSupport.minor,
|
||||
MinServiceVersionForMultiModeSupport.patch));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
result = LeapC.SetPolicyFlagsEx(_leapConnection, device.Handle, setFlags, 0);
|
||||
result = LeapC.SetPolicyFlags(_leapConnection, setFlags, 0);
|
||||
}
|
||||
|
||||
reportAbnormalResults("LeapC SetPolicyFlags call was ", result);
|
||||
|
@ -928,23 +916,13 @@ namespace LeapInternal
|
|||
|
||||
eLeapRS result;
|
||||
|
||||
if (device == null || !_multiDeviceAwareConnection)
|
||||
if (device != null && Controller.CheckRequiredServiceVersion(MinServiceVersionForMultiModeSupport, this))
|
||||
{
|
||||
result = LeapC.SetPolicyFlags(_leapConnection, 0, clearFlags);
|
||||
result = LeapC.SetPolicyFlagsEx(_leapConnection, device.Handle, 0, clearFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Controller.CheckRequiredServiceVersion(MinServiceVersionForMultiModeSupport, this))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning(String.Format("Your current tracking service does not support clearing policy flags on a per device basis (min version is {0}.{1}.{2}). Please update your service: https://developer.leapmotion.com/tracking-software-download",
|
||||
MinServiceVersionForMultiModeSupport.major,
|
||||
MinServiceVersionForMultiModeSupport.minor,
|
||||
MinServiceVersionForMultiModeSupport.patch));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
result = LeapC.SetPolicyFlagsEx(_leapConnection, device.Handle, 0, clearFlags);
|
||||
result = LeapC.SetPolicyFlags(_leapConnection, 0, clearFlags);
|
||||
}
|
||||
|
||||
reportAbnormalResults("LeapC SetPolicyFlags call was ", result);
|
||||
|
@ -1071,6 +1049,7 @@ namespace LeapInternal
|
|||
return _activePolicies.ContainsKey(deviceID);
|
||||
}
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public uint GetConfigValue(string config_key)
|
||||
{
|
||||
uint requestId = 0;
|
||||
|
@ -1080,6 +1059,7 @@ namespace LeapInternal
|
|||
return requestId;
|
||||
}
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public uint SetConfigValue<T>(string config_key, T value) where T : IConvertible
|
||||
{
|
||||
uint requestId = 0;
|
||||
|
@ -1322,6 +1302,19 @@ namespace LeapInternal
|
|||
Marshal.FreeHGlobal(buffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a specific set of hints to hDevice, if this does not include previously set ones, they will be cleared.
|
||||
/// </summary>
|
||||
/// <param name="hDevice">The Device pointer for the trcking device to set the hints for</param>
|
||||
/// <param name="hints">The array of hints</param>
|
||||
public void RequestHandTrackingHintsOnDevice(IntPtr hDevice, string[] hints)
|
||||
{
|
||||
eLeapRS result;
|
||||
result = LeapC.SetDeviceHints(_leapConnection, hDevice, hints);
|
||||
|
||||
reportAbnormalResults("LeapC SetDeviceHints call was ", result);
|
||||
}
|
||||
|
||||
private eLeapRS _lastResult; //Used to avoid repeating the same log message, ie. for events like time out
|
||||
private void reportAbnormalResults(string context, eLeapRS result)
|
||||
{
|
||||
|
|
43
ml_lme/vendor/LeapCSharp/Controller.cs
vendored
43
ml_lme/vendor/LeapCSharp/Controller.cs
vendored
|
@ -10,6 +10,7 @@ namespace Leap
|
|||
{
|
||||
using LeapInternal;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -41,7 +42,6 @@ namespace Leap
|
|||
{
|
||||
Connection _connection;
|
||||
bool _disposed = false;
|
||||
bool _supportsMultipleDevices = true;
|
||||
string _serverNamespace = "Leap Service";
|
||||
|
||||
/// <summary>
|
||||
|
@ -232,6 +232,7 @@ namespace Leap
|
|||
/// Dispatched when a configuration setting changes.
|
||||
/// @since 3.0
|
||||
/// </summary>
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public event EventHandler<ConfigChangeEventArgs> ConfigChange
|
||||
{
|
||||
add
|
||||
|
@ -403,6 +404,21 @@ namespace Leap
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispatched when a Fiducial Marker has been tracked.
|
||||
/// </summary>
|
||||
public event EventHandler<FiducialPoseEventArgs> FiducialPose
|
||||
{
|
||||
add
|
||||
{
|
||||
_connection.LeapFiducialPose += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_connection.LeapFiducialPose -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
@ -446,14 +462,16 @@ namespace Leap
|
|||
_connection = Connection.GetConnection(new Connection.Key(connectionKey, serverNamespace));
|
||||
_connection.EventContext = SynchronizationContext.Current;
|
||||
|
||||
if (_connection.IsRunning)
|
||||
_hasInitialized = true;
|
||||
|
||||
_connection.LeapInit += OnInit;
|
||||
_connection.LeapConnection += OnConnect;
|
||||
_connection.LeapConnectionLost += OnDisconnect;
|
||||
|
||||
_supportsMultipleDevices = supportsMultipleDevices;
|
||||
_serverNamespace = serverNamespace;
|
||||
|
||||
_connection.Start(serverNamespace, supportsMultipleDevices);
|
||||
StartConnection();
|
||||
}
|
||||
|
||||
|
||||
|
@ -467,7 +485,7 @@ namespace Leap
|
|||
/// </summary>
|
||||
public void StartConnection()
|
||||
{
|
||||
_connection.Start(_serverNamespace, _supportsMultipleDevices);
|
||||
_connection.Start(_serverNamespace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -621,6 +639,21 @@ namespace Leap
|
|||
return _connection.IsDeviceAvailable(device);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a specific set of hints, if this does not include previously set ones, they will be cleared.
|
||||
/// </summary>
|
||||
/// <param name="hints">The hints you wish to send</param>
|
||||
/// <param name="device">An optional specific Device, otherwise the first found will be used</param>
|
||||
public void RequestHandTrackingHints(string[] hints, Device device = null)
|
||||
{
|
||||
if (device == null)
|
||||
{
|
||||
device = Devices.ActiveDevices.FirstOrDefault();
|
||||
}
|
||||
|
||||
_connection.RequestHandTrackingHintsOnDevice(device.Handle, hints);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In most cases you should get Frame objects using the LeapProvider.CurrentFrame
|
||||
/// property. The data in Frame objects taken directly from a Leap.Controller instance
|
||||
|
@ -870,7 +903,7 @@ namespace Leap
|
|||
///
|
||||
/// @since 1.0
|
||||
/// </summary>
|
||||
[Obsolete("Config.cs is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public Config Config
|
||||
{
|
||||
get
|
||||
|
|
|
@ -14,12 +14,30 @@ 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
|
||||
*/
|
||||
public static LeapTransform LeapToUnityTransform
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return leapToUnityTransform;
|
||||
}
|
||||
}
|
||||
|
||||
public static void TransformToUnityUnits(this Hand hand)
|
||||
{
|
||||
LeapTransform leapTransform = new LeapTransform(Vector3.zero, Quaternion.identity, new Vector3(MM_TO_M, MM_TO_M, MM_TO_M));
|
||||
leapTransform.MirrorZ();
|
||||
|
||||
hand.Transform(leapTransform);
|
||||
hand.Transform(LeapToUnityTransform);
|
||||
}
|
||||
|
||||
|
||||
|
|
127
ml_lme/vendor/LeapCSharp/Device.cs
vendored
127
ml_lme/vendor/LeapCSharp/Device.cs
vendored
|
@ -255,67 +255,78 @@ namespace Leap
|
|||
return devicePose;
|
||||
}
|
||||
|
||||
bool deviceTransformAvailable = LeapC.GetDeviceTransformAvailable(Handle);
|
||||
|
||||
if (!deviceTransformAvailable)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
float[] data = new float[16];
|
||||
eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
|
||||
|
||||
if (result != eLeapRS.eLeapRS_Success || data == null)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Using the LEAP->OPENXR device transform matrix
|
||||
// Unitys matrices are generated as 4 columns:
|
||||
Matrix4x4 deviceTransform = 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]));
|
||||
|
||||
|
||||
// An example of the expected matrix if it were 8cm forward from the head origin
|
||||
// Unitys matrices are generated as 4 columns:
|
||||
//Matrix4x4 deviceTransform = new Matrix4x4(
|
||||
// new Vector4(-0.001f, 0, 0, 0),
|
||||
// new Vector4(0, 0, -0.001f, 0),
|
||||
// new Vector4(0, -0.001f, 0, 0),
|
||||
// new Vector4(0, 0, -0.08f, 1));
|
||||
|
||||
if (deviceTransform == Matrix4x4.identity)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
Matrix4x4 openXRToUnity = new Matrix4x4(
|
||||
new Vector4(1f, 0, 0, 0),
|
||||
new Vector4(0, 1f, 0, 0),
|
||||
new Vector4(0, 0, -1f, 0),
|
||||
new Vector4(0, 0, 0, 1));
|
||||
|
||||
deviceTransform = openXRToUnity * deviceTransform;
|
||||
|
||||
Vector3 outputPos = deviceTransform.GetPosition();
|
||||
//Quaternion outputRot = deviceTransform.rotation; // Note: the matrices we receive are not rotatrion matrices. This produces unexpected results
|
||||
|
||||
devicePose = new Pose(outputPos, Quaternion.identity);
|
||||
|
||||
poseSet = true;
|
||||
return devicePose;
|
||||
return FindDeviceTransform();
|
||||
}
|
||||
}
|
||||
|
||||
internal Pose FindDeviceTransform()
|
||||
{
|
||||
// Check the service has valid support for device transforms
|
||||
LEAP_VERSION minimumServiceVersion = new LEAP_VERSION { major = 5, minor = 19, patch = 0 };
|
||||
if (!ServerStatus.IsServiceVersionValid(minimumServiceVersion))
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
poseSet = true;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Check the device transform is available before asking for one
|
||||
bool deviceTransformAvailable = LeapC.GetDeviceTransformAvailable(Handle);
|
||||
|
||||
if (!deviceTransformAvailable)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Get the device transform data and check it is valid as data
|
||||
float[] data = new float[16];
|
||||
eLeapRS result = LeapC.GetDeviceTransform(Handle, data);
|
||||
|
||||
if (result != eLeapRS.eLeapRS_Success || data == null)
|
||||
{
|
||||
devicePose = Pose.identity;
|
||||
return Pose.identity;
|
||||
}
|
||||
|
||||
// Using the LEAP->OPENXR device transform matrix
|
||||
// Unitys matrices are generated as 4 columns:
|
||||
Matrix4x4 deviceTransform = 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]));
|
||||
|
||||
////An example of the expected matrix if it were 8cm forward from the head origin
|
||||
//// Unitys matrices are generated as 4 columns:
|
||||
//Matrix4x4 deviceTransform = new Matrix4x4(
|
||||
// new Vector4(-0.001f, 0, 0, 0),
|
||||
// new Vector4(0, 0, -0.001f, 0),
|
||||
// new Vector4(0, -0.001f, 0, 0),
|
||||
// new Vector4(0, 0, -0.08f, 1));
|
||||
|
||||
//// An example of applying a rotation to the existing device transform
|
||||
//Matrix4x4 rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 90, 0));
|
||||
//deviceTransform = deviceTransform * rotationMatrix;
|
||||
|
||||
Matrix4x4 openXRToUnitySwizzle = new Matrix4x4(
|
||||
new Vector4(1.0f, 0, 0, 0),
|
||||
new Vector4(0, 1.0f, 0, 0),
|
||||
new Vector4(0, 0, -1f, 0),
|
||||
new Vector4(0, 0, 0, 1f));
|
||||
|
||||
// Converts device transform from openxr space to unity space
|
||||
deviceTransform = openXRToUnitySwizzle.inverse * deviceTransform * openXRToUnitySwizzle;
|
||||
|
||||
Vector3 outputPos = deviceTransform.GetPosition();
|
||||
Quaternion outputRot = deviceTransform.rotation;
|
||||
|
||||
devicePose = new Pose(outputPos, outputRot);
|
||||
|
||||
poseSet = true;
|
||||
return devicePose;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the internal status field of the current device
|
||||
/// </summary>
|
||||
|
|
32
ml_lme/vendor/LeapCSharp/Events.cs
vendored
32
ml_lme/vendor/LeapCSharp/Events.cs
vendored
|
@ -10,6 +10,7 @@ namespace Leap
|
|||
{
|
||||
using LeapInternal;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration defining the types of Leap Motion events.
|
||||
|
@ -35,7 +36,8 @@ namespace Leap
|
|||
EVENT_DROPPED_FRAME,
|
||||
EVENT_IMAGE, //!< An unrequested image is available
|
||||
EVENT_POINT_MAPPING_CHANGE,
|
||||
EVENT_HEAD_POSE
|
||||
EVENT_HEAD_POSE,
|
||||
EVENT_FIDUCIAL_POSE
|
||||
};
|
||||
/// <summary>
|
||||
/// A generic object with no arguments beyond the event type.
|
||||
|
@ -159,6 +161,7 @@ namespace Leap
|
|||
/// Provides the configuration key, whether the change was successful, and the id of the original change request.
|
||||
/// @since 3.0
|
||||
/// </summary>
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public class ConfigChangeEventArgs : LeapEventArgs
|
||||
{
|
||||
public ConfigChangeEventArgs(string config_key, bool succeeded, uint requestId) : base(LeapEvent.EVENT_CONFIG_CHANGE)
|
||||
|
@ -308,6 +311,33 @@ namespace Leap
|
|||
public LEAP_QUATERNION headOrientation { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispatched when a Fiducial Marker is tracked
|
||||
///
|
||||
/// Note: Family and Size are not currently implemented
|
||||
/// </summary>
|
||||
public class FiducialPoseEventArgs : LeapEventArgs
|
||||
{
|
||||
public FiducialPoseEventArgs(LEAP_FIDUCIAL_POSE_EVENT poseEvent) : base(LeapEvent.EVENT_FIDUCIAL_POSE)
|
||||
{
|
||||
this.id = poseEvent.id;
|
||||
this.family = ""; // TODO: Marshal.PtrToStringAnsi(poseEvent.family); - when ptr is implemented in LeapC
|
||||
this.size = poseEvent.size;
|
||||
this.timestamp = poseEvent.timestamp;
|
||||
this.estimated_error = poseEvent.estimated_error;
|
||||
this.translation = poseEvent.translation;
|
||||
this.rotation = poseEvent.rotation;
|
||||
}
|
||||
|
||||
public int id { get; set; }
|
||||
public string family { get; set; }
|
||||
public float size { get; set; }
|
||||
public float timestamp { get; set; }
|
||||
public float estimated_error { get; set; }
|
||||
public LEAP_VECTOR translation { get; set; }
|
||||
public LEAP_QUATERNION rotation { get; set; }
|
||||
}
|
||||
|
||||
public struct BeginProfilingForThreadArgs
|
||||
{
|
||||
public string threadName;
|
||||
|
|
1
ml_lme/vendor/LeapCSharp/IController.cs
vendored
1
ml_lme/vendor/LeapCSharp/IController.cs
vendored
|
@ -37,6 +37,7 @@ namespace Leap
|
|||
|
||||
//new
|
||||
event EventHandler<PolicyEventArgs> PolicyChange;
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
event EventHandler<ConfigChangeEventArgs> ConfigChange;
|
||||
event EventHandler<DistortionEventArgs> DistortionChange;
|
||||
event EventHandler<ImageEventArgs> ImageReady;
|
||||
|
|
84
ml_lme/vendor/LeapCSharp/LeapC.cs
vendored
84
ml_lme/vendor/LeapCSharp/LeapC.cs
vendored
|
@ -532,15 +532,26 @@ namespace LeapInternal
|
|||
/// <summary>
|
||||
/// A new head pose is available.
|
||||
/// </summary>
|
||||
[Obsolete("Head pose events are not supported and will never be raised")]
|
||||
eLeapEventType_HeadPose,
|
||||
/// <summary>
|
||||
/// A new head pose is available.
|
||||
/// </summary>
|
||||
[Obsolete("Eye pose events are not supported and will never be raised")]
|
||||
eLeapEventType_Eyes,
|
||||
/// <summary>
|
||||
/// A new head pose is available.
|
||||
/// A new IMU information frame is available.
|
||||
/// </summary>
|
||||
eLeapEventType_IMU
|
||||
eLeapEventType_IMU,
|
||||
/// <summary>
|
||||
/// Notification that the service received a new device transformation matrix
|
||||
/// Use LeapGetDeviceTransform to update your cached information.
|
||||
/// </summary>
|
||||
eLeapEventType_NewDeviceTransform,
|
||||
/// <summary>
|
||||
/// An event provided when a fiducial marker has been tracked
|
||||
/// </summary>
|
||||
eLeapEventType_Fiducial
|
||||
};
|
||||
|
||||
public enum eLeapDeviceFlag : uint
|
||||
|
@ -718,6 +729,12 @@ namespace LeapInternal
|
|||
public LEAP_VECTOR head_angular_velocity;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct LEAP_NEW_DEVICE_TRANSFORM
|
||||
{
|
||||
public UInt32 reserved;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct LEAP_CONNECTION_MESSAGE
|
||||
{
|
||||
|
@ -974,6 +991,18 @@ namespace LeapInternal
|
|||
public string zoneName;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
|
||||
public struct LEAP_FIDUCIAL_POSE_EVENT
|
||||
{
|
||||
public int id;
|
||||
public IntPtr family; // char*
|
||||
public float size;
|
||||
public Int64 timestamp;
|
||||
public float estimated_error;
|
||||
public LEAP_VECTOR translation;
|
||||
public LEAP_QUATERNION rotation;
|
||||
}
|
||||
|
||||
public class LeapC
|
||||
{
|
||||
private LeapC() { }
|
||||
|
@ -1023,6 +1052,9 @@ namespace LeapInternal
|
|||
[DllImport("LeapC", EntryPoint = "LeapOpenConnection")]
|
||||
public static extern eLeapRS OpenConnection(IntPtr hConnection);
|
||||
|
||||
[DllImport("LeapC", EntryPoint = "LeapSetConnectionMetadata")]
|
||||
public static extern eLeapRS SetConnectionMetadata(IntPtr hConnection, string metadata, UIntPtr len);
|
||||
|
||||
[DllImport("LeapC", EntryPoint = "LeapSetAllocator")]
|
||||
public static extern eLeapRS SetAllocator(IntPtr hConnection, ref LEAP_ALLOCATOR pAllocator);
|
||||
|
||||
|
@ -1122,12 +1154,15 @@ namespace LeapInternal
|
|||
[DllImport("LeapC", EntryPoint = "LeapDestroyConnection")]
|
||||
public static extern void DestroyConnection(IntPtr connection);
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
[DllImport("LeapC", EntryPoint = "LeapSaveConfigValue")]
|
||||
private static extern eLeapRS SaveConfigValue(IntPtr hConnection, string key, IntPtr value, out UInt32 requestId);
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
[DllImport("LeapC", EntryPoint = "LeapRequestConfigValue")]
|
||||
public static extern eLeapRS RequestConfigValue(IntPtr hConnection, string name, out UInt32 request_id);
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public static eLeapRS SaveConfigValue(IntPtr hConnection, string key, bool value, out UInt32 requestId)
|
||||
{
|
||||
LEAP_VARIANT_VALUE_TYPE valueStruct = new LEAP_VARIANT_VALUE_TYPE(); //This is a C# approximation of a C union
|
||||
|
@ -1135,6 +1170,7 @@ namespace LeapInternal
|
|||
valueStruct.boolValue = value ? 1 : 0;
|
||||
return SaveConfigWithValueType(hConnection, key, valueStruct, out requestId);
|
||||
}
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public static eLeapRS SaveConfigValue(IntPtr hConnection, string key, Int32 value, out UInt32 requestId)
|
||||
{
|
||||
LEAP_VARIANT_VALUE_TYPE valueStruct = new LEAP_VARIANT_VALUE_TYPE();
|
||||
|
@ -1142,6 +1178,7 @@ namespace LeapInternal
|
|||
valueStruct.intValue = value;
|
||||
return SaveConfigWithValueType(hConnection, key, valueStruct, out requestId);
|
||||
}
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public static eLeapRS SaveConfigValue(IntPtr hConnection, string key, float value, out UInt32 requestId)
|
||||
{
|
||||
LEAP_VARIANT_VALUE_TYPE valueStruct = new LEAP_VARIANT_VALUE_TYPE();
|
||||
|
@ -1149,6 +1186,7 @@ namespace LeapInternal
|
|||
valueStruct.floatValue = value;
|
||||
return SaveConfigWithValueType(hConnection, key, valueStruct, out requestId);
|
||||
}
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
public static eLeapRS SaveConfigValue(IntPtr hConnection, string key, string value, out UInt32 requestId)
|
||||
{
|
||||
LEAP_VARIANT_REF_TYPE valueStruct;
|
||||
|
@ -1156,6 +1194,8 @@ namespace LeapInternal
|
|||
valueStruct.stringValue = value;
|
||||
return SaveConfigWithRefType(hConnection, key, valueStruct, out requestId);
|
||||
}
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
private static eLeapRS SaveConfigWithValueType(IntPtr hConnection, string key, LEAP_VARIANT_VALUE_TYPE valueStruct, out UInt32 requestId)
|
||||
{
|
||||
IntPtr configValue = Marshal.AllocHGlobal(Marshal.SizeOf(valueStruct));
|
||||
|
@ -1171,6 +1211,8 @@ namespace LeapInternal
|
|||
}
|
||||
return callResult;
|
||||
}
|
||||
|
||||
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
|
||||
private static eLeapRS SaveConfigWithRefType(IntPtr hConnection, string key, LEAP_VARIANT_REF_TYPE valueStruct, out UInt32 requestId)
|
||||
{
|
||||
IntPtr configValue = Marshal.AllocHGlobal(Marshal.SizeOf(valueStruct));
|
||||
|
@ -1230,5 +1272,43 @@ 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);
|
||||
|
||||
[DllImport("LeapC", EntryPoint = "LeapReleaseServerStatus")]
|
||||
public static extern eLeapRS ReleaseServerStatus(ref LEAP_SERVER_STATUS status);
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
|
||||
public struct LEAP_SERVER_STATUS
|
||||
{
|
||||
public string version;
|
||||
public UInt32 device_count;
|
||||
public IntPtr devices;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
|
||||
public struct LEAP_SERVER_STATUS_DEVICE
|
||||
{
|
||||
public string serial;
|
||||
public string type;
|
||||
}
|
||||
|
||||
public static eLeapRS SetDeviceHints(IntPtr hConnection, IntPtr hDevice, string[] hints)
|
||||
{
|
||||
// Ensure the final element of the array is null terminated.
|
||||
if (hints.Length == 0 || hints[^1] != null)
|
||||
{
|
||||
Array.Resize(ref hints, hints.Length + 1);
|
||||
hints[^1] = null;
|
||||
}
|
||||
|
||||
return SetDeviceHintsInternal(hConnection, hDevice, hints);
|
||||
}
|
||||
|
||||
[DllImport("LeapC", EntryPoint = "LeapSetDeviceHints")]
|
||||
private static extern eLeapRS SetDeviceHintsInternal(IntPtr hConnection, IntPtr hDevice, string[] hints);
|
||||
}
|
||||
}
|
138
ml_lme/vendor/LeapCSharp/MetadataUtil.cs
vendored
Normal file
138
ml_lme/vendor/LeapCSharp/MetadataUtil.cs
vendored
Normal file
|
@ -0,0 +1,138 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) Ultraleap, Inc. 2011-2024. *
|
||||
* *
|
||||
* Use subject to the terms of the Apache License 2.0 available at *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
|
||||
* between Ultraleap and you, your company or other organization. *
|
||||
******************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Leap
|
||||
{
|
||||
/// <summary>
|
||||
/// This class captures information regarding use of the Ultraleap Unity Plugin
|
||||
/// This data is anonymized and only sent to Ultraleap when you choose to allow it.
|
||||
/// You can change your analytics preferences in the Ultraleap Tracking Control Panel.
|
||||
/// "Settings > Help Improve Tracking"
|
||||
/// </summary>
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.InitializeOnLoad]
|
||||
#endif
|
||||
public class MetadataUtil
|
||||
{
|
||||
[System.Serializable]
|
||||
private struct Analytics
|
||||
{
|
||||
public Telemetry telemetry;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private struct Telemetry
|
||||
{
|
||||
public string app_name;
|
||||
public string app_type;
|
||||
public string engine_name;
|
||||
public string engine_version;
|
||||
public string plugin_version;
|
||||
public string installation_source;
|
||||
public string interaction_system;
|
||||
public string render_pipeline;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Fire a one-off call to capture metadata at edit time on the first editor update
|
||||
static MetadataUtil()
|
||||
{
|
||||
UnityEditor.EditorApplication.update -= FirstEditorUpdate;
|
||||
UnityEditor.EditorApplication.update += FirstEditorUpdate;
|
||||
}
|
||||
|
||||
static void FirstEditorUpdate()
|
||||
{
|
||||
UnityEditor.EditorApplication.update -= FirstEditorUpdate;
|
||||
|
||||
// This will capture some values within the editor that may not be accessible in builds
|
||||
// e.g. Plugin Source and Plugin Versions
|
||||
GetMetaData();
|
||||
}
|
||||
#endif
|
||||
|
||||
public static string GetMetaData()
|
||||
{
|
||||
Analytics analytics = new Analytics();
|
||||
analytics.telemetry = new Telemetry();
|
||||
|
||||
analytics.telemetry.app_name = Application.productName;
|
||||
analytics.telemetry.app_type = GetAppType();
|
||||
analytics.telemetry.engine_name = "Unity";
|
||||
analytics.telemetry.engine_version = Application.unityVersion;
|
||||
analytics.telemetry.plugin_version = Leap.Unity.UltraleapSettings.Instance.PluginVersion;
|
||||
analytics.telemetry.installation_source = Leap.Unity.UltraleapSettings.Instance.PluginSource;
|
||||
analytics.telemetry.interaction_system = GetInteractionSystem();
|
||||
analytics.telemetry.render_pipeline = GetRenderPipeline();
|
||||
|
||||
string json = JsonUtility.ToJson(analytics, true);
|
||||
return json;
|
||||
}
|
||||
|
||||
static string GetAppType()
|
||||
{
|
||||
string appType = "Build";
|
||||
|
||||
#if UNITY_EDITOR
|
||||
appType = "Editor";
|
||||
#endif
|
||||
|
||||
return appType;
|
||||
}
|
||||
|
||||
static string GetRenderPipeline()
|
||||
{
|
||||
string renderPipeline = "Built In";
|
||||
|
||||
if (QualitySettings.renderPipeline != null)
|
||||
{
|
||||
renderPipeline = QualitySettings.renderPipeline.GetType().ToString().Split(".").Last();
|
||||
}
|
||||
else if (GraphicsSettings.currentRenderPipeline != null)
|
||||
{
|
||||
renderPipeline = GraphicsSettings.currentRenderPipeline.GetType().ToString().Split(".").Last();
|
||||
}
|
||||
|
||||
return renderPipeline;
|
||||
}
|
||||
|
||||
static string GetInteractionSystem()
|
||||
{
|
||||
// Physical Hands
|
||||
if (GameObject.Find("Physical Hands Manager") ||
|
||||
GameObject.Find("Left HardContactHand") ||
|
||||
GameObject.Find("Left SoftContactHand") ||
|
||||
GameObject.Find("Left NoContactHand"))
|
||||
{
|
||||
return "Physical Hands";
|
||||
}
|
||||
|
||||
// Interaction Engine
|
||||
if (GameObject.Find("Interaction Hand (Left)"))
|
||||
{
|
||||
return "Interaction Engine";
|
||||
}
|
||||
|
||||
// XR Hands
|
||||
if (Leap.Unity.UltraleapSettings.Instance.leapSubsystemEnabled ||
|
||||
Leap.Unity.UltraleapSettings.Instance.updateLeapInputSystem ||
|
||||
Leap.Unity.UltraleapSettings.Instance.updateMetaInputSystem)
|
||||
{
|
||||
return "UL XR Hands";
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
112
ml_lme/vendor/LeapCSharp/ServerStatus.cs
vendored
Normal file
112
ml_lme/vendor/LeapCSharp/ServerStatus.cs
vendored
Normal file
|
@ -0,0 +1,112 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) Ultraleap, Inc. 2011-2024. *
|
||||
* *
|
||||
* Use subject to the terms of the Apache License 2.0 available at *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
|
||||
* between Ultraleap and you, your company or other organization. *
|
||||
******************************************************************************/
|
||||
|
||||
namespace LeapInternal
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ServerStatus
|
||||
{
|
||||
const double requestInterval = 1.0f;
|
||||
static double lastRequestTimestamp;
|
||||
|
||||
static LeapC.LEAP_SERVER_STATUS lastStatus;
|
||||
static LeapC.LEAP_SERVER_STATUS_DEVICE[] lastDevices;
|
||||
|
||||
public static void GetStatus()
|
||||
{
|
||||
if (lastRequestTimestamp + requestInterval < Time.realtimeSinceStartup)
|
||||
{
|
||||
IntPtr statusPtr = new IntPtr();
|
||||
LeapC.GetServerStatus(1000, ref statusPtr);
|
||||
|
||||
lastStatus = Marshal.PtrToStructure<LeapC.LEAP_SERVER_STATUS>(statusPtr);
|
||||
|
||||
MarshalUnmananagedArray2Struct(lastStatus.devices, (int)lastStatus.device_count, out lastDevices);
|
||||
LeapC.ReleaseServerStatus(ref lastStatus);
|
||||
lastRequestTimestamp = Time.realtimeSinceStartup;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsServiceVersionValid(LEAP_VERSION _requiredVersion)
|
||||
{
|
||||
GetStatus();
|
||||
|
||||
if (lastStatus.version != null)
|
||||
{
|
||||
string[] versions = lastStatus.version.Split('v')[1].Split('-')[0].Split('.');
|
||||
LEAP_VERSION curVersion = new LEAP_VERSION { major = int.Parse(versions[0]), minor = int.Parse(versions[1]), patch = int.Parse(versions[2]) };
|
||||
|
||||
if (_requiredVersion.major < curVersion.major)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (_requiredVersion.major == curVersion.major)
|
||||
{
|
||||
if (_requiredVersion.minor < curVersion.minor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (_requiredVersion.minor == curVersion.minor && _requiredVersion.patch <= curVersion.patch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string[] GetSerialNumbers()
|
||||
{
|
||||
GetStatus();
|
||||
|
||||
string[] serials = new string[lastDevices.Length];
|
||||
|
||||
for (int i = 0; i < lastDevices.Length; i++)
|
||||
{
|
||||
serials[i] = lastDevices[i].serial;
|
||||
}
|
||||
|
||||
return serials;
|
||||
}
|
||||
|
||||
public static string GetDeviceType(string _serial)
|
||||
{
|
||||
GetStatus();
|
||||
|
||||
if (lastDevices != null)
|
||||
{
|
||||
for (int i = 0; i < lastDevices.Length; i++)
|
||||
{
|
||||
if (_serial == "" || _serial == lastDevices[i].serial)
|
||||
{
|
||||
return lastDevices[i].type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void MarshalUnmananagedArray2Struct<T>(IntPtr unmanagedArray, int length, out T[] mangagedArray)
|
||||
{
|
||||
var size = Marshal.SizeOf(typeof(T));
|
||||
mangagedArray = new T[length];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
IntPtr ins = new IntPtr(unmanagedArray.ToInt64() + i * size);
|
||||
mangagedArray[i] = Marshal.PtrToStructure<T>(ins);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
380
ml_lme/vendor/LeapCSharp/UltraleapSettings.cs
vendored
Normal file
380
ml_lme/vendor/LeapCSharp/UltraleapSettings.cs
vendored
Normal file
|
@ -0,0 +1,380 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) Ultraleap, Inc. 2011-2024. *
|
||||
* *
|
||||
* Use subject to the terms of the Apache License 2.0 available at *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
|
||||
* between Ultraleap and you, your company or other organization. *
|
||||
******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
#endif
|
||||
|
||||
namespace Leap.Unity
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(UltraleapSettings))]
|
||||
public class UltraleapSettingsDrawer : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
EditorGUILayout.Space(20);
|
||||
if (GUILayout.Button("Open Ultraleap Settings"))
|
||||
{
|
||||
SettingsService.OpenProjectSettings("Project/Ultraleap");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static class UltraleapProjectSettings
|
||||
{
|
||||
static SerializedObject settings = UltraleapSettings.GetSerializedSettings();
|
||||
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateUltraleapSettingsProvider()
|
||||
{
|
||||
// First parameter is the path in the Settings window.
|
||||
// Second parameter is the scope of this setting: it only appears in the Project Settings window.
|
||||
var provider = new SettingsProvider("Project/Ultraleap", SettingsScope.Project)
|
||||
{
|
||||
// By default the last token of the path is used as display name if no label is provided.
|
||||
label = "Ultraleap",
|
||||
// Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
|
||||
guiHandler = (searchContext) =>
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
settings = UltraleapSettings.GetSerializedSettings();
|
||||
}
|
||||
|
||||
LeapSubSystemSection(settings);
|
||||
InputActionsSection(settings);
|
||||
HintingSection(settings);
|
||||
NotificationSection(settings);
|
||||
ResetSection(settings);
|
||||
|
||||
settings.ApplyModifiedProperties();
|
||||
settings.UpdateIfRequiredOrScript();
|
||||
},
|
||||
|
||||
// Populate the search keywords to enable smart search filtering and label highlighting:
|
||||
keywords = new HashSet<string>(new[] { "XRHands", "Leap", "Leap Input System", "Meta Aim System", "Subsystem", "Leap Motion", "Ultraleap", "Ultraleap Settings" })
|
||||
};
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
private static void LeapSubSystemSection(SerializedObject settings)
|
||||
{
|
||||
EditorGUILayout.Space(10);
|
||||
EditorGUILayout.LabelField("Leap XRHands Subsystem", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
EditorGUILayout.HelpBox("If using OpenXR for hand input, use the Hand Tracking Subsystem in XR Plug-in Management/OpenXR. Do not enable both subsystems." +
|
||||
"\r\n\nThis option can not be toggled at runtime.", MessageType.Info, true);
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
SerializedProperty leapSubsystemEnabledProperty = settings.FindProperty("leapSubsystemEnabled");
|
||||
leapSubsystemEnabledProperty.boolValue = EditorGUILayout.ToggleLeft("Enable Leap XRHands Subsystem", leapSubsystemEnabledProperty.boolValue);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(30);
|
||||
|
||||
settings.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private static void InputActionsSection(SerializedObject settings)
|
||||
{
|
||||
EditorGUILayout.LabelField("Input Actions", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
SerializedProperty updateLeapInputSystemProperty = settings.FindProperty("updateLeapInputSystem");
|
||||
updateLeapInputSystemProperty.boolValue = EditorGUILayout.ToggleLeft("Update Leap Input System with XRHands", updateLeapInputSystemProperty.boolValue);
|
||||
|
||||
SerializedProperty updateMetaInputSystemProperty = settings.FindProperty("updateMetaInputSystem");
|
||||
updateMetaInputSystemProperty.boolValue = EditorGUILayout.ToggleLeft("Update Meta Aim Input System with XRHands", updateMetaInputSystemProperty.boolValue);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(30);
|
||||
|
||||
settings.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private static void HintingSection(SerializedObject settings)
|
||||
{
|
||||
EditorGUILayout.LabelField("Hand Tracking Hints", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
SerializedProperty hints = settings.FindProperty("startupHints");
|
||||
EditorGUILayout.PropertyField(hints, true);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
settings.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private static void NotificationSection(SerializedObject settings)
|
||||
{
|
||||
EditorGUILayout.LabelField("Notifications", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
{
|
||||
// Android Build Warnings
|
||||
SerializedProperty showAndroidBuildArchitectureWarning = settings.FindProperty("showAndroidBuildArchitectureWarning");
|
||||
showAndroidBuildArchitectureWarning.boolValue = EditorGUILayout.ToggleLeft("Show Android Architecture build warning", showAndroidBuildArchitectureWarning.boolValue);
|
||||
|
||||
// Physical Hands Settings Warnings
|
||||
SerializedProperty showPhysicalHandsPhysicsSettingsWarning = settings.FindProperty("showPhysicalHandsPhysicsSettingsWarning");
|
||||
showPhysicalHandsPhysicsSettingsWarning.boolValue = EditorGUILayout.ToggleLeft("Show Physical Hands settings warning", showPhysicalHandsPhysicsSettingsWarning.boolValue);
|
||||
|
||||
// Attachment Hands delete content warnings
|
||||
bool curValue = !EditorUtility.GetDialogOptOutDecision(DialogOptOutDecisionType.ForThisMachine, "UL attachment hands popup");
|
||||
curValue = EditorGUILayout.ToggleLeft("Show clear Attachment Hands deletes content warning", curValue);
|
||||
EditorUtility.SetDialogOptOutDecision(DialogOptOutDecisionType.ForThisMachine, "UL attachment hands popup", !curValue);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(30);
|
||||
|
||||
settings.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private static void ResetSection(SerializedObject settings)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("Reset To Defaults", GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth/2)))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Reset all settings", "This will reset all settings in this Ultraleap settings file", "Yes", "No"))
|
||||
{
|
||||
UltraleapSettings.Instance.ResetToDefaults();
|
||||
}
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
settings.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public class UltraleapSettings : ScriptableObject
|
||||
{
|
||||
static UltraleapSettings instance;
|
||||
public static UltraleapSettings Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance != null)
|
||||
return instance;
|
||||
else
|
||||
return instance = FindSettingsSO();
|
||||
}
|
||||
set { instance = value; }
|
||||
}
|
||||
|
||||
// XRHands and Input System
|
||||
[HideInInspector, SerializeField]
|
||||
public bool leapSubsystemEnabled = false;
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public bool updateLeapInputSystem = false;
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public bool updateMetaInputSystem = false;
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public string[] startupHints = new string[] { };
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public bool showAndroidBuildArchitectureWarning = true;
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public bool showPhysicalHandsPhysicsSettingsWarning = true;
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public string pluginVersion = "Unknown";
|
||||
public string PluginVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
pluginVersion = GetPluginVersion();
|
||||
#endif
|
||||
return pluginVersion;
|
||||
}
|
||||
}
|
||||
|
||||
[HideInInspector, SerializeField]
|
||||
public string pluginSource = "Unknown";
|
||||
public string PluginSource
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
pluginSource = GetPluginSource();
|
||||
#endif
|
||||
return pluginSource;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToDefaults()
|
||||
{
|
||||
leapSubsystemEnabled = false;
|
||||
updateLeapInputSystem = false;
|
||||
updateMetaInputSystem = false;
|
||||
|
||||
startupHints = new string[] { };
|
||||
|
||||
showAndroidBuildArchitectureWarning = true;
|
||||
showPhysicalHandsPhysicsSettingsWarning = true;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
static string GetPluginVersion()
|
||||
{
|
||||
if (Utils.IsPackageAvailable("com.ultraleap.tracking", out var packageInfo)) // Check the package exists so we can use package manage wizardry
|
||||
{
|
||||
return packageInfo.version;
|
||||
}
|
||||
else // We are not using package manager :( we need to look for version number elsewhere
|
||||
{
|
||||
return FindPluginVersionInAssets();
|
||||
}
|
||||
}
|
||||
|
||||
static string GetPluginSource()
|
||||
{
|
||||
if (Utils.IsPackageAvailable("com.ultraleap.tracking", out var packageInfo)) // Check the package exists so we can use package manage wizardry
|
||||
{
|
||||
if (packageInfo.source == UnityEditor.PackageManager.PackageSource.Registry &&
|
||||
packageInfo.registry != null &&
|
||||
packageInfo.registry.url.Contains("openupm"))
|
||||
{
|
||||
return "UPM OpenUPM";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "UPM " + packageInfo.source;
|
||||
}
|
||||
}
|
||||
else // We are not using package manager :( we need to look for version number elsewhere
|
||||
{
|
||||
return "Unity Package";
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Ultraleap/Open Ultraleap Settings", false, 50)]
|
||||
private static void SelectULSettingsDropdown()
|
||||
{
|
||||
SettingsService.OpenProjectSettings("Project/Ultraleap");
|
||||
}
|
||||
|
||||
[MenuItem("Ultraleap/Help/Documentation", false, 100)]
|
||||
private static void OpenDocs()
|
||||
{
|
||||
Application.OpenURL("https://docs.ultraleap.com/unity-api/");
|
||||
}
|
||||
|
||||
[MenuItem("Ultraleap/Help/Report a Bug", false, 101)]
|
||||
private static void OpenGithubNewIssueView()
|
||||
{
|
||||
Application.OpenURL("https://github.com/ultraleap/UnityPlugin/issues/new");
|
||||
}
|
||||
|
||||
[MenuItem("Ultraleap/Help/Support/Submit a Support Request", false, 102)]
|
||||
private static void OpenSupportRequest()
|
||||
{
|
||||
Application.OpenURL("https://support.leapmotion.com/hc/en-us/requests/new");
|
||||
}
|
||||
|
||||
[MenuItem("Ultraleap/Help/Support/Join Our Discord", false, 103)]
|
||||
private static void OpenDiscord()
|
||||
{
|
||||
Application.OpenURL("https://discord.com/invite/3VCndThqxS");
|
||||
}
|
||||
#endif
|
||||
|
||||
private static UltraleapSettings FindSettingsSO()
|
||||
{
|
||||
// Try to directly load the asset
|
||||
UltraleapSettings ultraleapSettings = Resources.Load<UltraleapSettings>("Ultraleap Settings");
|
||||
|
||||
if (ultraleapSettings != null)
|
||||
{
|
||||
instance = ultraleapSettings;
|
||||
return instance;
|
||||
}
|
||||
|
||||
UltraleapSettings[] settingsSO = Resources.FindObjectsOfTypeAll(typeof(UltraleapSettings)) as UltraleapSettings[];
|
||||
|
||||
if (settingsSO != null && settingsSO.Length > 0)
|
||||
{
|
||||
instance = settingsSO[0]; // Assume there is only one settings file
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = CreateSettingsSO();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
static UltraleapSettings CreateSettingsSO()
|
||||
{
|
||||
UltraleapSettings newSO = null;
|
||||
#if UNITY_EDITOR
|
||||
newSO = ScriptableObject.CreateInstance<UltraleapSettings>();
|
||||
|
||||
Directory.CreateDirectory(Application.dataPath + "/Resources/");
|
||||
AssetDatabase.CreateAsset(newSO, "Assets/Resources/Ultraleap Settings.asset");
|
||||
#endif
|
||||
return newSO;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static SerializedObject GetSerializedSettings()
|
||||
{
|
||||
return new SerializedObject(Instance);
|
||||
}
|
||||
|
||||
static string FindPluginVersionInAssets()
|
||||
{
|
||||
string pluginVersionFromAssets = "";
|
||||
|
||||
string[] fileGUIDs = AssetDatabase.FindAssets("Version");
|
||||
|
||||
foreach (var guid in fileGUIDs)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
|
||||
if (path.Contains("/Ultraleap/Tracking/Version.txt"))
|
||||
{
|
||||
string content = File.ReadAllText(path);
|
||||
|
||||
pluginVersionFromAssets = content;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pluginVersionFromAssets;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue