Skip to content

Commit

Permalink
Add overlay mouse input (WARNING: interferes with playspace mover):
Browse files Browse the repository at this point in the history
- Implement InputSnapshot for mouse events and scroll events.
- WARNING: This breaks OVR Advanced Settings motion / playspace mover!
  - This may be due to the overlay flag MakeOverlaysInteractiveIfVisible causing all input events to be intercepted? Not sure.
  - Either way this needs fixing in the next iteration.
- Poll mouse events and scroll events, and pass it to the InputSnapshot.
- Poll OpenVR quit event; exit the application when this happens.
  - Move the OpenVR shutdown responsibility to HVOverlay.
- Run in unlimited overlay refresh rate due to an issue encountered with WaitFrameSync at the moment.
- Increase the windowless window size so that more items show up in the Shortcuts by default.
- Enable drag to scroll on all tabs when windowless.
  • Loading branch information
hai-vr committed Aug 29, 2024
1 parent a99afe0 commit 697f7e6
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 44 deletions.
4 changes: 0 additions & 4 deletions h-view/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ void WhenWindowClosed()
routine.Finish();
oscQuery.Finish();
oscClient.Finish();
if (isSteamVROverlay)
{
OpenVR.Shutdown();
}
}

var uiThread = new Thread(() =>
Expand Down
38 changes: 27 additions & 11 deletions h-view/src/HVInnerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public partial class HVInnerWindow : IDisposable
private const int BorderHeight = BorderWidth;
private const int TotalWindowWidth = 600;
private const int TotalWindowHeight = 510;
private const int TotalWindowlessViewportWidth = TotalWindowWidth;
private const int TotalWindowlessViewportHeight = TotalWindowWidth;
private const int TotalWindowlessViewportWidth = 800;
private const int TotalWindowlessViewportHeight = 800;
private const ImGuiWindowFlags WindowFlags = ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoResize;
private const ImGuiWindowFlags WindowFlagsNoCollapse = WindowFlags | ImGuiWindowFlags.NoCollapse;
private const string AvatarTabLabel = "Avatar";
Expand Down Expand Up @@ -54,6 +54,7 @@ public partial class HVInnerWindow : IDisposable
private Texture _overlayTexture;
private Texture _depthTexture;
private Framebuffer _overlayFramebuffer;
private bool _anyHighlightLastFrame;

public HVInnerWindow(HVRoutine routine, bool isWindowlessStyle)
{
Expand Down Expand Up @@ -97,20 +98,24 @@ private void SubmitUI()
var flags = WindowFlagsNoCollapse;
if (_isWindowlessStyle)
{
flags |= ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoBackground;
flags |= ImGuiWindowFlags.NoTitleBar;
}
ImGui.Begin($"{HVApp.AppTitleTab} {VERSION.version}", flags);
ImGui.BeginTabBar("##tabs");
var oscMessages = _routine.UiOscMessages();
MakeTab(AvatarTabLabel, false, () => AvatarTab(oscMessages));
MakeTab(FaceTrackingTabLabel, false, () => FaceTrackingTab(oscMessages));
MakeTab(InputTabLabel, false, () => InputTab(oscMessages));
MakeTab(TrackingTabLabel, false, () => TrackingTab(oscMessages));
MakeTab(AvatarTabLabel, _isWindowlessStyle, () => AvatarTab(oscMessages));
MakeTab(FaceTrackingTabLabel, _isWindowlessStyle, () => FaceTrackingTab(oscMessages));
MakeTab(InputTabLabel, _isWindowlessStyle, () => InputTab(oscMessages));
MakeTab(TrackingTabLabel, _isWindowlessStyle, () => TrackingTab(oscMessages));
MakeTab(MenuTabLabel, true, () => ExpressionsTab(oscMessages));
MakeTab(ShortcutsTabLabel, false, () => ShortcutsTab(oscMessages));
MakeTab(ContactsTabLabel, false, () => ContactsTab(oscMessages));
MakeTab(PhysBonesLabel, false, () => PhysBonesTab(oscMessages));
MakeTab(UtilityTabLabel, false, () => UtilityTab(oscMessages));
MakeTab(ShortcutsTabLabel, _isWindowlessStyle, () => ShortcutsTab(oscMessages));
MakeTab(ContactsTabLabel, _isWindowlessStyle, () => ContactsTab(oscMessages));
MakeTab(PhysBonesLabel, _isWindowlessStyle, () => PhysBonesTab(oscMessages));
MakeTab(UtilityTabLabel, _isWindowlessStyle, () => UtilityTab(oscMessages));

// FIXME: This might not be working as intended
_anyHighlightLastFrame = ImGui.IsAnyItemActive() || ImGui.IsAnyItemFocused();

ImGui.End();

// 3. Show the ImGui demo window. Most of the sample code is in ImGui.ShowDemoWindow(). Read its code to learn more about Dear ImGui!
Expand Down Expand Up @@ -263,7 +268,13 @@ private void TeardownFramebuffer()

public IntPtr GetOverlayTexturePointer()
{
// For more info, check https://github.com/ValveSoftware/openvr/blob/master/headers/openvr.h#L126C30-L126C40 (ETextureType definition)
// - TextureType_DirectX = 0, // Handle is an ID3D11Texture
return _gd.GetD3D11Info().GetTexturePointer(_overlayTexture);

// TODO: Support other graphics backends
// - TextureType_OpenGL = 1, // Handle is an OpenGL texture name or an OpenGL render buffer name, depending on submit flags
// - TextureType_Vulkan = 2, // Handle is a pointer to a VRVulkanTextureData_t structure
}

public InputSnapshot DoPumpEvents()
Expand Down Expand Up @@ -300,4 +311,9 @@ public void TeardownWindowlessUi()
}

#endregion

public Vector2 WindowSize()
{
return new Vector2(_window.Width, _window.Height);
}
}
19 changes: 17 additions & 2 deletions h-view/src/HVInnerWindowExpressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ namespace Hai.HView.Gui;

public partial class HVInnerWindow
{
private bool _isScrollDragging;
private void HandleScrollOnDrag(Vector2 delta, ImGuiMouseButton mouseButton)
{
// FIXME: This might not be working as intended
if (!_isScrollDragging && _anyHighlightLastFrame) return;

var held = ImGui.IsMouseDown(mouseButton);
if (held)
{
_isScrollDragging = true;
}
else
{
_isScrollDragging = false;
}

if (held && delta.Y != 0.0f)
{
Expand Down Expand Up @@ -435,7 +447,7 @@ private void IterateThrough(Dictionary<string, HOscItem> oscMessages, ref int id
if (isMatch) ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(0, 1, 1, 0.75f));

var button = DrawButtonFor(id, icons, item);
if (button && item.type == HVShortcutType.Toggle)
if (hasOscItem && button && item.type == HVShortcutType.Toggle)
{
_routine.UpdateMessage(oscItem.Key, TransformFloatToType(item.referencedParameterType, !isMatch ? item.value : 0f));
}
Expand All @@ -445,7 +457,10 @@ private void IterateThrough(Dictionary<string, HOscItem> oscMessages, ref int id
var isPressed = ImGui.IsItemActive();
if (wasPressed != isPressed)
{
_routine.UpdateMessage(oscItem.Key, TransformFloatToType(item.referencedParameterType, isPressed ? item.value : 0f));
if (hasOscItem)
{
_routine.UpdateMessage(oscItem.Key, TransformFloatToType(item.referencedParameterType, isPressed ? item.value : 0f));
}
_buttonPressState[id] = isPressed;
}
}
Expand Down
55 changes: 55 additions & 0 deletions h-view/src/Overlay/HOverlayInputSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Numerics;
using Veldrid;

namespace Hai.HView.Overlay;

public class HOverlayInputSnapshot : InputSnapshot
{
public bool IsMouseDown(MouseButton button) => _mouseDown[(int)button];
public IReadOnlyList<KeyEvent> KeyEvents => _keyEvents;
public IReadOnlyList<MouseEvent> MouseEvents => _mouseEvents;
public IReadOnlyList<char> KeyCharPresses => _keyCharPresses;
public Vector2 MousePosition { get; private set; } = Vector2.Zero;
public float WheelDelta { get; private set; }

private readonly List<KeyEvent> _keyEvents = new List<KeyEvent>();
private readonly List<MouseEvent> _mouseEvents = new List<MouseEvent>();
private readonly List<char> _keyCharPresses = new List<char>();
private readonly bool[] _mouseDown = new bool[(int)MouseButton.LastButton];
private Vector2 _windowSize;

public void SetWindowSize(Vector2 windowSize)
{
_windowSize = windowSize;
}

public void MouseMove(Vector2 relativeCoords)
{
MousePosition = relativeCoords * _windowSize;
}

public void Deaccumulate()
{
WheelDelta = 0f;
}

public void Scrolling(float delta)
{
Console.WriteLine($"Scrolling event {delta}");
WheelDelta += delta;
}

public void MouseDown(MouseButton veldridButton)
{
Console.WriteLine($"MouseDown event {veldridButton}");
_mouseEvents.Add(new MouseEvent(veldridButton, true));
_mouseDown[(int)veldridButton] = true;
}

public void MouseUp(MouseButton veldridButton)
{
Console.WriteLine($"MouseUp event {veldridButton}");
_mouseEvents.Add(new MouseEvent(veldridButton, false));
_mouseDown[(int)veldridButton] = false;
}
}
Loading

0 comments on commit 697f7e6

Please sign in to comment.