mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39: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
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -31,7 +32,7 @@ namespace ml_lme_cvr
|
|||
Settings.DesktopOffsetChange += this.OnSettingsDesktopOffsetChange;
|
||||
Settings.FingersOnlyChange += this.OnSettingsFingersOptionChange;
|
||||
Settings.ModelVisibilityChange += this.OnSettingsModelVisibilityChange;
|
||||
Settings.HmdModeChange += this.OnSettingsHmdModeChange;
|
||||
Settings.TrackingModeChange += this.OnSettingsTrackingModeChange;
|
||||
Settings.RootAngleChange += this.OnSettingsRootAngleChange;
|
||||
Settings.HeadAttachChange += this.OnSettingsHeadAttachChange;
|
||||
Settings.HeadOffsetChange += this.OnSettingsHeadOffsetChange;
|
||||
|
@ -95,7 +96,7 @@ namespace ml_lme_cvr
|
|||
OnSettingsEnableChange();
|
||||
OnSettingsFingersOptionChange();
|
||||
OnSettingsModelVisibilityChange();
|
||||
OnSettingsHmdModeChange();
|
||||
OnSettingsTrackingModeChange();
|
||||
OnSettingsHeadAttachChange(); // Includes offsets and parenting
|
||||
}
|
||||
|
||||
|
@ -119,7 +120,7 @@ namespace ml_lme_cvr
|
|||
{
|
||||
Vector3 l_pos = m_gesturesData.m_handsPositons[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.localRotation = l_rot;
|
||||
}
|
||||
|
@ -138,11 +139,7 @@ namespace ml_lme_cvr
|
|||
if(Settings.Enabled)
|
||||
{
|
||||
m_leapController.StartConnection();
|
||||
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);
|
||||
UpdateDeviceTrackingMode();
|
||||
}
|
||||
else
|
||||
m_leapController.StopConnection();
|
||||
|
@ -174,19 +171,26 @@ namespace ml_lme_cvr
|
|||
m_leapControllerModel.SetActive(Settings.ModelVisibility);
|
||||
}
|
||||
|
||||
void OnSettingsHmdModeChange()
|
||||
void OnSettingsTrackingModeChange()
|
||||
{
|
||||
if(m_leapController != null)
|
||||
{
|
||||
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(Settings.Enabled && (m_leapController != null))
|
||||
UpdateDeviceTrackingMode();
|
||||
|
||||
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()
|
||||
|
@ -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
|
||||
void OnLeapDeviceInitialized(object p_sender, Leap.DeviceEventArgs p_args)
|
||||
{
|
||||
if(Settings.Enabled && (m_leapController != null))
|
||||
{
|
||||
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);
|
||||
}
|
||||
UpdateDeviceTrackingMode();
|
||||
|
||||
if(CohtmlHud.Instance != null)
|
||||
CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device initialized");
|
||||
|
@ -305,18 +320,31 @@ namespace ml_lme_cvr
|
|||
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.z *= -1f;
|
||||
p_rot.x *= -1f;
|
||||
p_rot.y *= -1f;
|
||||
|
||||
if(p_hmd)
|
||||
switch(p_mode)
|
||||
{
|
||||
p_pos.x *= -1f;
|
||||
Utils.Swap(ref p_pos.y, ref p_pos.z);
|
||||
p_rot = (ms_hmdRotationFix * p_rot);
|
||||
case Settings.LeapTrackingMode.Screentop:
|
||||
{
|
||||
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;
|
||||
|
||||
[assembly: AssemblyTitle("LeapMotionExtension")]
|
||||
[assembly: AssemblyVersion("1.0.6")]
|
||||
[assembly: AssemblyFileVersion("1.0.6")]
|
||||
[assembly: AssemblyVersion("1.0.7")]
|
||||
[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.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[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
|
||||
Available mod's settings in `Settings - Implementation - Leap Motion Tracking`:
|
||||
* **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.
|
||||
* **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.
|
||||
|
|
|
@ -6,6 +6,13 @@ namespace ml_lme_cvr
|
|||
{
|
||||
static class Settings
|
||||
{
|
||||
public enum LeapTrackingMode
|
||||
{
|
||||
Screentop = 0,
|
||||
Desktop,
|
||||
HMD
|
||||
}
|
||||
|
||||
public static readonly string[] ms_defaultSettings =
|
||||
{
|
||||
"InteractionLeapMotionTracking",
|
||||
|
@ -14,7 +21,7 @@ namespace ml_lme_cvr
|
|||
"InteractionLeapMotionTrackingDesktopZ",
|
||||
"InteractionLeapMotionTrackingFingersOnly",
|
||||
"InteractionLeapMotionTrackingModel",
|
||||
"InteractionLeapMotionTrackingHmd",
|
||||
"InteractionLeapMotionTrackingMode",
|
||||
"InteractionLeapMotionTrackingAngle",
|
||||
"InteractionLeapMotionTrackingHead",
|
||||
"InteractionLeapMotionTrackingHeadX",
|
||||
|
@ -26,7 +33,7 @@ namespace ml_lme_cvr
|
|||
static Vector3 ms_desktopOffset = new Vector3(0f, -0.45f, 0.3f);
|
||||
static bool ms_fingersOnly = false;
|
||||
static bool ms_modelVisibility = false;
|
||||
static bool ms_hmdMode = false;
|
||||
static LeapTrackingMode ms_trackingMode = LeapTrackingMode.Desktop;
|
||||
static float ms_rootAngle = 0f;
|
||||
static bool ms_headAttach = false;
|
||||
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 FingersOnlyChange;
|
||||
static public event Action ModelVisibilityChange;
|
||||
static public event Action HmdModeChange;
|
||||
static public event Action TrackingModeChange;
|
||||
static public event Action RootAngleChange;
|
||||
static public event Action HeadAttachChange;
|
||||
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 CVRSettingsBool(ms_defaultSettings[4], 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 CVRSettingsBool(ms_defaultSettings[8], false));
|
||||
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[9], 0));
|
||||
|
@ -120,13 +127,13 @@ namespace ml_lme_cvr
|
|||
}
|
||||
});
|
||||
|
||||
// HMD mode
|
||||
__instance.settingBoolChanged.AddListener((name, value) =>
|
||||
// Tracking mode
|
||||
__instance.settingIntChanged.AddListener((name, value) =>
|
||||
{
|
||||
if(name == ms_defaultSettings[6])
|
||||
{
|
||||
ms_hmdMode = value;
|
||||
HmdModeChange?.Invoke();
|
||||
ms_trackingMode = (LeapTrackingMode)value;
|
||||
TrackingModeChange?.Invoke();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -182,7 +189,7 @@ namespace ml_lme_cvr
|
|||
) * 0.01f;
|
||||
ms_fingersOnly = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[4]);
|
||||
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_headAttach = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[8]);
|
||||
ms_headOffset = new Vector3(
|
||||
|
@ -212,9 +219,9 @@ namespace ml_lme_cvr
|
|||
get => ms_modelVisibility;
|
||||
}
|
||||
|
||||
public static bool HmdMode
|
||||
public static LeapTrackingMode TrackingMode
|
||||
{
|
||||
get => ms_hmdMode;
|
||||
get => ms_trackingMode;
|
||||
}
|
||||
|
||||
public static float RootAngle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue