Skip to content

Commit

Permalink
Simple 2D viewing mode when no headset is present (#421)
Browse files Browse the repository at this point in the history
* Initial stab at allowing a simple 2D viewing mode when no headset is present

[CI BUILD]

* UX improvements and some help text. Don't invert look by default

* Slow default speed and allow shift for sprinting

* dotnet-format

* Nit...

* Touchscreen controls for mobile non-VR

* Add a close button to view mode

* dotnet-format
  • Loading branch information
andybak authored Jul 14, 2023
1 parent 3673c0e commit 0dca2e2
Show file tree
Hide file tree
Showing 12 changed files with 4,009 additions and 110 deletions.
1,901 changes: 1,892 additions & 9 deletions Assets/Prefabs/NoPeekingCamera.prefab

Large diffs are not rendered by default.

1,854 changes: 1,777 additions & 77 deletions Assets/Scenes/Main.unity

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions Assets/Scripts/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,6 @@ void Start()

if (!VrSdk.IsHmdInitialized())
{
Debug.Log("VR HMD was not initialized on startup.");
StartupError = true;
CreateFailedToDetectVrDialog();
}
else
Expand Down Expand Up @@ -1767,7 +1765,7 @@ public void RefreshUserConfig()
}
}

public void CreateFailedToDetectVrDialog(string msg = null)
public void CreateFailedToDetectVrDialog(string msg = null, bool allowViewing = true)
{
GameObject dialog = Instantiate(m_ErrorDialog);
var textXf = dialog.transform.Find("Text");
Expand All @@ -1778,6 +1776,8 @@ public void CreateFailedToDetectVrDialog(string msg = null)
}
textMesh.text = string.Format(@" Tiltasaurus says...
{0}", msg);
var initScript = dialog.GetComponent<InitNoHeadsetMode>();
initScript.ShowSketchSelectorUi(allowViewing && !StartupError);
}

static public bool AppAllowsCreation()
Expand Down Expand Up @@ -1880,7 +1880,10 @@ void InitUserPath()
if (!Path.IsPathRooted(m_UserPath))
{
StartupError = true;
CreateFailedToDetectVrDialog("Failed to find Documents folder.\nIn Windows, try modifying your Controlled Folder Access settings.");
CreateFailedToDetectVrDialog(
"Failed to find Documents folder.\nIn Windows, try modifying your Controlled Folder Access settings.",
allowViewing: false
);
}
}

Expand Down
41 changes: 41 additions & 0 deletions Assets/Scripts/GUI/TouchscreenVirtualKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace TiltBrush
{
[RequireComponent(typeof(Button))]
public class TouchscreenVirtualKey : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
{
public char m_Key;
[NonSerialized] public bool m_IsPressed;

private Button _button;

private void Awake()
{
_button = GetComponent<Button>();
}

public void OnPointerDown(PointerEventData eventData)
{
if (!_button.interactable) return;
m_IsPressed = true;
}

public void OnPointerUp(PointerEventData eventData)
{
m_IsPressed = false;
}

public void OnPointerExit(PointerEventData eventData)
{
m_IsPressed = false;
}

// Afaik needed so Pointer exit works .. doing nothing further
public void OnPointerEnter(PointerEventData eventData) { }
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/GUI/TouchscreenVirtualKey.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Assets/Scripts/GUI/ViewModeUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using TiltBrush;
using UnityEngine;

public class ViewModeUI : MonoBehaviour
{
public GameObject m_UiRoot;

void Awake()
{
m_UiRoot.SetActive(!App.VrSdk.IsHmdInitialized());
}

public void HandleCloseButton()
{
// TODO If we allow other tools than the FlyTool, we should probably have
// a better way to test if the load sketch dialog is showing
if (SketchSurfacePanel.m_Instance.ActiveToolType == BaseTool.ToolType.FlyTool)
{
// We're viewing a sketch so close it and open the loading dialog
ApiMethods.NewSketch();
SketchSurfacePanel.m_Instance.DisableSpecificTool(BaseTool.ToolType.FlyTool);
App.Instance.CreateFailedToDetectVrDialog();
}
else
{
// We're hopefully showing the sketch loading dialog so close the app
Application.Quit();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/GUI/ViewModeUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions Assets/Scripts/InitNoHeadsetMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2023 The Open Brush Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using TMPro;
using UnityEngine;

namespace TiltBrush
{
public class InitNoHeadsetMode : MonoBehaviour
{

public GameObject m_SketchLoadingUi;

void Start()
{
var dropdown = GetComponentInChildren<TMP_Dropdown>();
dropdown.ClearOptions();
var userSketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.User);
for (int i = 0; i < userSketchSet.NumSketches; i++)
{
var sketchName = userSketchSet.GetSketchName(i);
dropdown.options.Add(new TMP_Dropdown.OptionData(sketchName));
}
var curatedSketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Curated);
for (int i = 0; i < curatedSketchSet.NumSketches; i++)
{
var sketchName = curatedSketchSet.GetSketchName(i);
dropdown.options.Add(new TMP_Dropdown.OptionData(sketchName));
}
}

public void Init()
{
var cameraPos = App.VrSdk.GetVrCamera().transform.position;
cameraPos.y += 12;
App.VrSdk.GetVrCamera().transform.position = cameraPos;
var dropdown = GetComponentInChildren<TMP_Dropdown>();
var index = dropdown.value;

var sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.User);
if (index < sketchSet.NumSketches)
{
SceneFileInfo rInfo = sketchSet.GetSketchSceneFileInfo(index);
if (rInfo != null)
{
SketchControlsScript.m_Instance.LoadSketch(rInfo, true);
}
}
else
{
index -= sketchSet.NumSketches;
sketchSet = SketchCatalog.m_Instance.GetSet(SketchSetType.Curated);
var rInfo = sketchSet.GetSketchSceneFileInfo(index);
if (rInfo != null)
{
SketchControlsScript.m_Instance.LoadSketch(rInfo, true);
}
}

SketchSurfacePanel.m_Instance.EnableSpecificTool(BaseTool.ToolType.FlyTool);
Destroy(gameObject);
}

public void ShowSketchSelectorUi(bool active = true)
{
m_SketchLoadingUi.SetActive(active);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/InitNoHeadsetMode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions Assets/Scripts/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public enum KeyboardShortcut
Save,
Load,

Forward,
Backward,
CameraMoveForward,
CameraMoveBackwards,

PositionMonoCamera,

Expand All @@ -153,6 +153,13 @@ public enum KeyboardShortcut
TossWidget,

ToggleProfile,
CameraMoveLeft,
CameraMoveRight,
CameraMoveUp,
CameraMoveDown,
FlyMode,
InvertLook,
SprintMode
}

// Standard mapping of keyboard shortcut to actual keyboard keys.
Expand Down Expand Up @@ -198,8 +205,8 @@ public enum KeyboardShortcut
{ (int)KeyboardShortcut.Save, new[] { Key.S } },
{ (int)KeyboardShortcut.Load, new[] { Key.L } },

{ (int)KeyboardShortcut.Forward, new[] { Key.N } },
{ (int)KeyboardShortcut.Backward, new[] { Key.M } },
{ (int)KeyboardShortcut.CameraMoveForward, new[] { Key.N } },
{ (int)KeyboardShortcut.CameraMoveBackwards, new[] { Key.M } },

{ (int)KeyboardShortcut.PositionMonoCamera, new[] { Key.LeftAlt, Key.RightAlt } },

Expand All @@ -214,6 +221,20 @@ public enum KeyboardShortcut
{ (int)KeyboardShortcut.TossWidget, new[] { Key.Y } },
};

// Separate keymap for when we launch but no VR headset is detected.
private static readonly KeyMap m_NoHeadsetKeyMap = new KeyMap
{
{ (int)KeyboardShortcut.CameraMoveForward, new[] { Key.W } },
{ (int)KeyboardShortcut.CameraMoveBackwards, new[] { Key.S } },
{ (int)KeyboardShortcut.CameraMoveLeft, new[] { Key.A } },
{ (int)KeyboardShortcut.CameraMoveRight, new[] { Key.D } },
{ (int)KeyboardShortcut.CameraMoveUp, new[] { Key.Q } },
{ (int)KeyboardShortcut.CameraMoveDown, new[] { Key.E } },
{ (int)KeyboardShortcut.FlyMode, new[] { Key.F } },
{ (int)KeyboardShortcut.InvertLook, new[] { Key.I } },
{ (int)KeyboardShortcut.SprintMode, new[] { Key.LeftShift } },
};

// Separate keymap for when demo mode is enabled.
// Determined by DemoManager.m_Instance.DemoModeEnabled == true
private static readonly KeyMap m_DemoKeyMap = new KeyMap
Expand All @@ -228,7 +249,11 @@ private KeyMap ActiveKeyMap
{
get
{
if (DemoManager.m_Instance.DemoModeEnabled)
if (!App.VrSdk.IsHmdInitialized())
{
return m_NoHeadsetKeyMap;
}
else if (DemoManager.m_Instance.DemoModeEnabled)
{
return m_DemoKeyMap;
}
Expand Down
11 changes: 8 additions & 3 deletions Assets/Scripts/SketchControlsScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,8 @@ public void UpdateControls()
m_SketchSurfacePanel.m_UpdatedToolThisFrame = false;

// Verify controllers are available and prune state if they're not.
if (App.VrSdk.GetControllerDof() == VrSdk.DoF.Six &&
App.VrSdk.IsInitializingUnityXR)
if ((App.VrSdk.GetControllerDof() == VrSdk.DoF.Six &&
App.VrSdk.IsInitializingUnityXR) && App.VrSdk.IsHmdInitialized())
{
m_PanelManager.SetVisible(false);
PointerManager.m_Instance.RequestPointerRendering(false);
Expand Down Expand Up @@ -1450,6 +1450,11 @@ void UpdateStandardInput()
{
App.Instance.SetDesiredState(App.AppState.LoadingBrushesAndLighting);
}
else if (InputManager.m_Instance.GetKeyboardShortcutDown(
InputManager.KeyboardShortcut.FlyMode))
{
SketchSurfacePanel.m_Instance.EnableSpecificTool(BaseTool.ToolType.FlyTool);
}
else if (App.Config.m_ToggleProfileOnAppButton &&
(InputManager.Wand.GetVrInputDown(VrInput.Button03) ||
InputManager.m_Instance.GetKeyboardShortcutDown(
Expand Down Expand Up @@ -4097,7 +4102,7 @@ private void MergeBrushStrokes(SceneFileInfo fileInfo)
}
}

private void LoadSketch(SceneFileInfo fileInfo, bool quickload = false, bool additive = false)
public void LoadSketch(SceneFileInfo fileInfo, bool quickload = false, bool additive = false)
{
LightsControlScript.m_Instance.DiscoMode = false;
m_WidgetManager.FollowingPath = false;
Expand Down
Loading

0 comments on commit 0dca2e2

Please sign in to comment.