mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-05 03:19:23 +00:00
Tracking modes
This commit is contained in:
parent
6b8d7a7f97
commit
04fd9b3867
4 changed files with 80 additions and 45 deletions
|
@ -8,6 +8,7 @@ namespace ml_lme_cvr
|
||||||
public class LeapMotionExtension : MelonLoader.MelonMod
|
public class LeapMotionExtension : MelonLoader.MelonMod
|
||||||
{
|
{
|
||||||
static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f);
|
static readonly Quaternion ms_hmdRotationFix = new Quaternion(0f, 0.7071068f, 0.7071068f, 0f);
|
||||||
|
static readonly Quaternion ms_screentopRotationFix = new Quaternion(0f, 0f, -1f, 0f);
|
||||||
|
|
||||||
static LeapMotionExtension ms_instance = null;
|
static LeapMotionExtension ms_instance = null;
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ namespace ml_lme_cvr
|
||||||
Settings.DesktopOffsetChange += this.OnSettingsDesktopOffsetChange;
|
Settings.DesktopOffsetChange += this.OnSettingsDesktopOffsetChange;
|
||||||
Settings.FingersOnlyChange += this.OnSettingsFingersOptionChange;
|
Settings.FingersOnlyChange += this.OnSettingsFingersOptionChange;
|
||||||
Settings.ModelVisibilityChange += this.OnSettingsModelVisibilityChange;
|
Settings.ModelVisibilityChange += this.OnSettingsModelVisibilityChange;
|
||||||
Settings.HmdModeChange += this.OnSettingsHmdModeChange;
|
Settings.TrackingModeChange += this.OnSettingsTrackingModeChange;
|
||||||
Settings.RootAngleChange += this.OnSettingsRootAngleChange;
|
Settings.RootAngleChange += this.OnSettingsRootAngleChange;
|
||||||
Settings.HeadAttachChange += this.OnSettingsHeadAttachChange;
|
Settings.HeadAttachChange += this.OnSettingsHeadAttachChange;
|
||||||
Settings.HeadOffsetChange += this.OnSettingsHeadOffsetChange;
|
Settings.HeadOffsetChange += this.OnSettingsHeadOffsetChange;
|
||||||
|
@ -95,7 +96,7 @@ namespace ml_lme_cvr
|
||||||
OnSettingsEnableChange();
|
OnSettingsEnableChange();
|
||||||
OnSettingsFingersOptionChange();
|
OnSettingsFingersOptionChange();
|
||||||
OnSettingsModelVisibilityChange();
|
OnSettingsModelVisibilityChange();
|
||||||
OnSettingsHmdModeChange();
|
OnSettingsTrackingModeChange();
|
||||||
OnSettingsHeadAttachChange(); // Includes offsets and parenting
|
OnSettingsHeadAttachChange(); // Includes offsets and parenting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ namespace ml_lme_cvr
|
||||||
{
|
{
|
||||||
Vector3 l_pos = m_gesturesData.m_handsPositons[i];
|
Vector3 l_pos = m_gesturesData.m_handsPositons[i];
|
||||||
Quaternion l_rot = m_gesturesData.m_handsRotations[i];
|
Quaternion l_rot = m_gesturesData.m_handsRotations[i];
|
||||||
ReorientateLeapToUnity(ref l_pos, ref l_rot, Settings.HmdMode);
|
ReorientateLeapToUnity(ref l_pos, ref l_rot, Settings.TrackingMode);
|
||||||
m_leapHands[i].transform.localPosition = l_pos;
|
m_leapHands[i].transform.localPosition = l_pos;
|
||||||
m_leapHands[i].transform.localRotation = l_rot;
|
m_leapHands[i].transform.localRotation = l_rot;
|
||||||
}
|
}
|
||||||
|
@ -138,11 +139,7 @@ namespace ml_lme_cvr
|
||||||
if(Settings.Enabled)
|
if(Settings.Enabled)
|
||||||
{
|
{
|
||||||
m_leapController.StartConnection();
|
m_leapController.StartConnection();
|
||||||
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
|
UpdateDeviceTrackingMode();
|
||||||
if(Settings.HmdMode)
|
|
||||||
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
|
||||||
else
|
|
||||||
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_leapController.StopConnection();
|
m_leapController.StopConnection();
|
||||||
|
@ -174,19 +171,26 @@ namespace ml_lme_cvr
|
||||||
m_leapControllerModel.SetActive(Settings.ModelVisibility);
|
m_leapControllerModel.SetActive(Settings.ModelVisibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSettingsHmdModeChange()
|
void OnSettingsTrackingModeChange()
|
||||||
{
|
{
|
||||||
if(m_leapController != null)
|
if(Settings.Enabled && (m_leapController != null))
|
||||||
{
|
UpdateDeviceTrackingMode();
|
||||||
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
|
|
||||||
if(Settings.HmdMode)
|
|
||||||
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
|
||||||
else
|
|
||||||
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m_leapControllerModel != null)
|
if(m_leapControllerModel != null)
|
||||||
m_leapControllerModel.transform.localRotation = (Settings.HmdMode ? Quaternion.Euler(270f, 180f, 0f) : Quaternion.identity);
|
{
|
||||||
|
switch(Settings.TrackingMode)
|
||||||
|
{
|
||||||
|
case Settings.LeapTrackingMode.Screentop:
|
||||||
|
m_leapControllerModel.transform.localRotation = Quaternion.Euler(0f, 0f, 180f);
|
||||||
|
break;
|
||||||
|
case Settings.LeapTrackingMode.Desktop:
|
||||||
|
m_leapControllerModel.transform.localRotation = Quaternion.identity;
|
||||||
|
break;
|
||||||
|
case Settings.LeapTrackingMode.HMD:
|
||||||
|
m_leapControllerModel.transform.localRotation = Quaternion.Euler(270f, 180f, 0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnSettingsRootAngleChange()
|
void OnSettingsRootAngleChange()
|
||||||
|
@ -245,17 +249,28 @@ namespace ml_lme_cvr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Internal utility
|
||||||
|
void UpdateDeviceTrackingMode()
|
||||||
|
{
|
||||||
|
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
|
||||||
|
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
||||||
|
|
||||||
|
switch(Settings.TrackingMode)
|
||||||
|
{
|
||||||
|
case Settings.LeapTrackingMode.Screentop:
|
||||||
|
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
|
||||||
|
break;
|
||||||
|
case Settings.LeapTrackingMode.HMD:
|
||||||
|
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Leap events
|
// Leap events
|
||||||
void OnLeapDeviceInitialized(object p_sender, Leap.DeviceEventArgs p_args)
|
void OnLeapDeviceInitialized(object p_sender, Leap.DeviceEventArgs p_args)
|
||||||
{
|
{
|
||||||
if(Settings.Enabled && (m_leapController != null))
|
if(Settings.Enabled && (m_leapController != null))
|
||||||
{
|
UpdateDeviceTrackingMode();
|
||||||
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
|
|
||||||
if(Settings.HmdMode)
|
|
||||||
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
|
||||||
else
|
|
||||||
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(CohtmlHud.Instance != null)
|
if(CohtmlHud.Instance != null)
|
||||||
CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device initialized");
|
CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device initialized");
|
||||||
|
@ -305,18 +320,31 @@ namespace ml_lme_cvr
|
||||||
OnSettingsHeadAttachChange();
|
OnSettingsHeadAttachChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ReorientateLeapToUnity(ref Vector3 p_pos, ref Quaternion p_rot, bool p_hmd)
|
// Utilities
|
||||||
|
static void ReorientateLeapToUnity(ref Vector3 p_pos, ref Quaternion p_rot, Settings.LeapTrackingMode p_mode)
|
||||||
{
|
{
|
||||||
p_pos *= 0.001f;
|
p_pos *= 0.001f;
|
||||||
p_pos.z *= -1f;
|
p_pos.z *= -1f;
|
||||||
p_rot.x *= -1f;
|
p_rot.x *= -1f;
|
||||||
p_rot.y *= -1f;
|
p_rot.y *= -1f;
|
||||||
|
|
||||||
if(p_hmd)
|
switch(p_mode)
|
||||||
{
|
{
|
||||||
p_pos.x *= -1f;
|
case Settings.LeapTrackingMode.Screentop:
|
||||||
Utils.Swap(ref p_pos.y, ref p_pos.z);
|
{
|
||||||
p_rot = (ms_hmdRotationFix * p_rot);
|
p_pos.x *= -1f;
|
||||||
|
p_pos.y *= -1f;
|
||||||
|
p_rot = (ms_screentopRotationFix * p_rot);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Settings.LeapTrackingMode.HMD:
|
||||||
|
{
|
||||||
|
p_pos.x *= -1f;
|
||||||
|
Utils.Swap(ref p_pos.y, ref p_pos.z);
|
||||||
|
p_rot = (ms_hmdRotationFix * p_rot);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyTitle("LeapMotionExtension")]
|
[assembly: AssemblyTitle("LeapMotionExtension")]
|
||||||
[assembly: AssemblyVersion("1.0.6")]
|
[assembly: AssemblyVersion("1.0.7")]
|
||||||
[assembly: AssemblyFileVersion("1.0.6")]
|
[assembly: AssemblyFileVersion("1.0.7")]
|
||||||
|
|
||||||
[assembly: MelonLoader.MelonInfo(typeof(ml_lme_cvr.LeapMotionExtension), "LeapMotionExtension", "1.0.6", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
[assembly: MelonLoader.MelonInfo(typeof(ml_lme_cvr.LeapMotionExtension), "LeapMotionExtension", "1.0.7", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||||
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||||
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||||
|
|
|
@ -14,7 +14,7 @@ This mod allows you to use your Leap Motion controller for hands and fingers vis
|
||||||
## Settings
|
## Settings
|
||||||
Available mod's settings in `Settings - Implementation - Leap Motion Tracking`:
|
Available mod's settings in `Settings - Implementation - Leap Motion Tracking`:
|
||||||
* **Enable tracking:** enable hands tracking from Leap Motion data, disabled by default.
|
* **Enable tracking:** enable hands tracking from Leap Motion data, disabled by default.
|
||||||
* **HMD mode:** force Leap Motion to use head-mounted orientation mode, disabled by default.
|
* **Tracking mode:** set Leap Motion tracking mode, available values: `Screentop`, `Desktop` (by default), `HMD`.
|
||||||
* **Desktop offset X/Y/Z:** offset position for body attachment, (0, -45, 30) by default.
|
* **Desktop offset X/Y/Z:** offset position for body attachment, (0, -45, 30) by default.
|
||||||
* **Attach to head:** attach hands transformation to head instead of body, disabled by default.
|
* **Attach to head:** attach hands transformation to head instead of body, disabled by default.
|
||||||
* **Head offset X/Y/Z:** offset position for head attachment (`Attach to head` is **`true`**), (0, -30, 15) by default.
|
* **Head offset X/Y/Z:** offset position for head attachment (`Attach to head` is **`true`**), (0, -30, 15) by default.
|
||||||
|
|
|
@ -6,6 +6,13 @@ namespace ml_lme_cvr
|
||||||
{
|
{
|
||||||
static class Settings
|
static class Settings
|
||||||
{
|
{
|
||||||
|
public enum LeapTrackingMode
|
||||||
|
{
|
||||||
|
Screentop = 0,
|
||||||
|
Desktop,
|
||||||
|
HMD
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly string[] ms_defaultSettings =
|
public static readonly string[] ms_defaultSettings =
|
||||||
{
|
{
|
||||||
"InteractionLeapMotionTracking",
|
"InteractionLeapMotionTracking",
|
||||||
|
@ -14,7 +21,7 @@ namespace ml_lme_cvr
|
||||||
"InteractionLeapMotionTrackingDesktopZ",
|
"InteractionLeapMotionTrackingDesktopZ",
|
||||||
"InteractionLeapMotionTrackingFingersOnly",
|
"InteractionLeapMotionTrackingFingersOnly",
|
||||||
"InteractionLeapMotionTrackingModel",
|
"InteractionLeapMotionTrackingModel",
|
||||||
"InteractionLeapMotionTrackingHmd",
|
"InteractionLeapMotionTrackingMode",
|
||||||
"InteractionLeapMotionTrackingAngle",
|
"InteractionLeapMotionTrackingAngle",
|
||||||
"InteractionLeapMotionTrackingHead",
|
"InteractionLeapMotionTrackingHead",
|
||||||
"InteractionLeapMotionTrackingHeadX",
|
"InteractionLeapMotionTrackingHeadX",
|
||||||
|
@ -26,7 +33,7 @@ namespace ml_lme_cvr
|
||||||
static Vector3 ms_desktopOffset = new Vector3(0f, -0.45f, 0.3f);
|
static Vector3 ms_desktopOffset = new Vector3(0f, -0.45f, 0.3f);
|
||||||
static bool ms_fingersOnly = false;
|
static bool ms_fingersOnly = false;
|
||||||
static bool ms_modelVisibility = false;
|
static bool ms_modelVisibility = false;
|
||||||
static bool ms_hmdMode = false;
|
static LeapTrackingMode ms_trackingMode = LeapTrackingMode.Desktop;
|
||||||
static float ms_rootAngle = 0f;
|
static float ms_rootAngle = 0f;
|
||||||
static bool ms_headAttach = false;
|
static bool ms_headAttach = false;
|
||||||
static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f);
|
static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f);
|
||||||
|
@ -37,7 +44,7 @@ namespace ml_lme_cvr
|
||||||
static public event Action DesktopOffsetChange;
|
static public event Action DesktopOffsetChange;
|
||||||
static public event Action FingersOnlyChange;
|
static public event Action FingersOnlyChange;
|
||||||
static public event Action ModelVisibilityChange;
|
static public event Action ModelVisibilityChange;
|
||||||
static public event Action HmdModeChange;
|
static public event Action TrackingModeChange;
|
||||||
static public event Action RootAngleChange;
|
static public event Action RootAngleChange;
|
||||||
static public event Action HeadAttachChange;
|
static public event Action HeadAttachChange;
|
||||||
static public event Action HeadOffsetChange;
|
static public event Action HeadOffsetChange;
|
||||||
|
@ -64,7 +71,7 @@ namespace ml_lme_cvr
|
||||||
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[3], 30));
|
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[3], 30));
|
||||||
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[4], false));
|
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[4], false));
|
||||||
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[5], false));
|
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[5], false));
|
||||||
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[6], false));
|
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[6], 1));
|
||||||
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[7], 0));
|
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[7], 0));
|
||||||
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[8], false));
|
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[8], false));
|
||||||
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[9], 0));
|
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[9], 0));
|
||||||
|
@ -120,13 +127,13 @@ namespace ml_lme_cvr
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// HMD mode
|
// Tracking mode
|
||||||
__instance.settingBoolChanged.AddListener((name, value) =>
|
__instance.settingIntChanged.AddListener((name, value) =>
|
||||||
{
|
{
|
||||||
if(name == ms_defaultSettings[6])
|
if(name == ms_defaultSettings[6])
|
||||||
{
|
{
|
||||||
ms_hmdMode = value;
|
ms_trackingMode = (LeapTrackingMode)value;
|
||||||
HmdModeChange?.Invoke();
|
TrackingModeChange?.Invoke();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -182,7 +189,7 @@ namespace ml_lme_cvr
|
||||||
) * 0.01f;
|
) * 0.01f;
|
||||||
ms_fingersOnly = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[4]);
|
ms_fingersOnly = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[4]);
|
||||||
ms_modelVisibility = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[5]);
|
ms_modelVisibility = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[5]);
|
||||||
ms_hmdMode = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[6]);
|
ms_trackingMode = (LeapTrackingMode)MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[6]);
|
||||||
ms_rootAngle = MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[7]);
|
ms_rootAngle = MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[7]);
|
||||||
ms_headAttach = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[8]);
|
ms_headAttach = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[8]);
|
||||||
ms_headOffset = new Vector3(
|
ms_headOffset = new Vector3(
|
||||||
|
@ -212,9 +219,9 @@ namespace ml_lme_cvr
|
||||||
get => ms_modelVisibility;
|
get => ms_modelVisibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HmdMode
|
public static LeapTrackingMode TrackingMode
|
||||||
{
|
{
|
||||||
get => ms_hmdMode;
|
get => ms_trackingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float RootAngle
|
public static float RootAngle
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue