Skip to content

Commit 86633ff

Browse files
TudorJudemeta-codesync[bot]
authored andcommitted
Add support for microgestures
Summary: Add support for microgestures when not using controllers. Reviewed By: kyrylokuzyk-m Differential Revision: D89465263 fbshipit-source-id: 671a5eca0198fa25915386a7bb014beee624cdf0
1 parent 84ca67c commit 86633ff

21 files changed

+4196
-352
lines changed

DepthAPI-BiRP/Assets/DepthAPISample/Scenes/DepthMask.unity

Lines changed: 1132 additions & 58 deletions
Large diffs are not rendered by default.

DepthAPI-BiRP/Assets/DepthAPISample/Scenes/HandsRemoval.unity

Lines changed: 520 additions & 21 deletions
Large diffs are not rendered by default.

DepthAPI-BiRP/Assets/DepthAPISample/Scenes/SceneAPIPlacement.unity

Lines changed: 321 additions & 27 deletions
Large diffs are not rendered by default.

DepthAPI-BiRP/Assets/DepthAPISample/Scripts/HandRemovalToggler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,15 @@ private void SetHandsOcclusionStyle(HandsRemovalStyle style)
7979

8080
OnHandsRemovalStyleChanged?.Invoke(style);
8181
}
82+
83+
public void OnMicroGestureLeftHand(OVRHand.MicrogestureType gesture)
84+
{
85+
if (gesture == OVRHand.MicrogestureType.ThumbTap)
86+
{
87+
_occlustionType = ((_occlustionType + 1) % Enum.GetValues(typeof(HandsRemovalStyle)).Length);
88+
_occlStyle = (HandsRemovalStyle)_occlustionType;
89+
SetHandsOcclusionStyle(_occlStyle);
90+
}
91+
}
8292
}
8393
}

DepthAPI-BiRP/Assets/DepthAPISample/Scripts/OcclusionToggler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,13 @@ private void SetOcclusionType()
6666
if (_currentOcclusionsModeText)
6767
_currentOcclusionsModeText.text = $"Occlusion mode: \n{newType.ToString()}";
6868
}
69+
70+
public void OnMicroGestureRightHand(OVRHand.MicrogestureType gesture)
71+
{
72+
if (gesture == OVRHand.MicrogestureType.ThumbTap)
73+
{
74+
SwitchToNextOcclusionType();
75+
}
76+
}
6977
}
7078
}

DepthAPI-BiRP/Assets/DepthAPISample/Scripts/PosterPlacer.cs

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class PosterPlacer : MonoBehaviour
3535
[SerializeField] private OVRInput.RawButton _posterRotateRightButton = OVRInput.RawButton.RThumbstickRight;
3636
[SerializeField] private OVRInput.RawButton _posterRotateLeftButton = OVRInput.RawButton.RThumbstickLeft;
3737
[SerializeField] private float _depthBiasChangeValue = .01f;
38+
[SerializeField] private float _depthBiasAdjustDecay = 10f;
3839
[SerializeField] private LineRenderer _lineRenderer;
3940
[SerializeField] private ChangeInputListener _inputListener;
4041
private LayerMask _layerMaskWall;
@@ -47,6 +48,9 @@ public class PosterPlacer : MonoBehaviour
4748
private bool _isUsingHands;
4849
private float _rotationValue;
4950

51+
private float _depthBiasAdjust = 0;
52+
private bool _placePosterTrigger = false;
53+
5054
private void Awake()
5155
{
5256
_layerMaskWall = LayerMask.GetMask("Wall");
@@ -72,45 +76,41 @@ private void OnDisable()
7276

7377
private void Update()
7478
{
75-
_lineRenderer.enabled = !_isUsingHands;
76-
_posterPreview.gameObject.SetActive(!_isUsingHands);
77-
if (_isUsingHands)
78-
{
79-
return;
80-
}
81-
8279
Ray ray = new Ray(_rayOrigin.position, _rayOrigin.forward);
8380
RaycastHit hit;
8481
if (OVRInput.Get(_posterIncreaseBiasValueButton))
82+
{
83+
_depthBiasAdjust = 1;
84+
}
85+
if (OVRInput.Get(_posterDecreaseBiasValueButton))
86+
{
87+
_depthBiasAdjust = -1;
88+
}
89+
if (Mathf.Abs(_depthBiasAdjust) > 0.01)
8590
{
8691
if (_currentHighlightedPosterObject != null)
8792
{
88-
_currentHighlightedPosterObject.GetComponent<Poster>().AdjustDepthBias(_depthBiasChangeValue * Time.deltaTime);
93+
_currentHighlightedPosterObject.GetComponent<Poster>().AdjustDepthBias(_depthBiasChangeValue * _depthBiasAdjust * Time.deltaTime);
8994
}
9095
else
9196
{
9297
if (_posterPreview != null)
9398
{
94-
_previewPosterDepthBiasValue += _depthBiasChangeValue * Time.deltaTime;
99+
_previewPosterDepthBiasValue += _depthBiasChangeValue * _depthBiasAdjust * Time.deltaTime;
95100
_posterPreview.SetDepthBias(_previewPosterDepthBiasValue);
96101
}
97102
}
98-
}
99-
if (OVRInput.Get(_posterDecreaseBiasValueButton))
100-
{
101-
if (_currentHighlightedPosterObject != null)
103+
if (!_isUsingHands)
102104
{
103-
_currentHighlightedPosterObject.GetComponent<Poster>().AdjustDepthBias(-_depthBiasChangeValue * Time.deltaTime);
105+
_depthBiasAdjust = 0;
104106
}
105107
else
106108
{
107-
if (_posterPreview != null)
108-
{
109-
_previewPosterDepthBiasValue -= _depthBiasChangeValue * Time.deltaTime;
110-
_posterPreview.SetDepthBias(_previewPosterDepthBiasValue);
111-
}
109+
_depthBiasAdjust -= Time.deltaTime * _depthBiasAdjustDecay * Mathf.Sign(_depthBiasAdjust);
112110
}
113111
}
112+
113+
114114
if (Physics.Raycast(ray, out hit, Mathf.Infinity, _layerMaskPoster))
115115
{
116116
_isPosterHit = true;
@@ -187,10 +187,11 @@ private void ProjectPoster(RaycastHit hit)
187187
_lineRenderer.SetPositions(new Vector3[] { _rayOrigin.position, hit.point });
188188

189189
PlacePreviewPoster(hit);
190-
if (OVRInput.GetDown(_posterPlacingButton))
190+
if ((OVRInput.GetDown(_posterPlacingButton)) || (_placePosterTrigger))
191191
{
192192
PlacePoster(hit);
193193
}
194+
_placePosterTrigger = false;
194195
}
195196
private void PlacePoster(RaycastHit hit)
196197
{
@@ -264,6 +265,31 @@ private void ClearPosters()
264265
_currentPosters.Clear();
265266
}
266267

267-
private void HandleInputChanged(bool isUsingHands) => _isUsingHands = isUsingHands;
268+
private void HandleInputChanged(bool isUsingHands)
269+
{
270+
_isUsingHands = isUsingHands;
271+
}
272+
273+
public void OnMicroGesture(OVRHand.MicrogestureType gesture)
274+
{
275+
switch (gesture)
276+
{
277+
case OVRHand.MicrogestureType.SwipeForward:
278+
{
279+
_depthBiasAdjust += 1;
280+
}
281+
break;
282+
case OVRHand.MicrogestureType.SwipeBackward:
283+
{
284+
_depthBiasAdjust += -1;
285+
}
286+
break;
287+
case OVRHand.MicrogestureType.ThumbTap:
288+
{
289+
_placePosterTrigger = true;
290+
}
291+
break;
292+
}
293+
}
268294
}
269295
}

DepthAPI-BiRP/Assets/DepthAPISample/Scripts/SceneMeshDepthMask.cs

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,31 @@ namespace DepthAPISample
88
{
99
public class SceneMeshDepthMask : MonoBehaviour
1010
{
11-
[SerializeField] private TextMeshProUGUI MaskDepthBiasText;
12-
[SerializeField] private OVRInput.RawButton _maskToggleButton = OVRInput.RawButton.B;
13-
[SerializeField] private OVRInput.RawButton _maskBiasAdjustDecreaseButton = OVRInput.RawButton.RThumbstickLeft;
14-
[SerializeField] private OVRInput.RawButton _maskBiasAdjustIncreaseButton = OVRInput.RawButton.RThumbstickRight;
11+
private const float depthBiasAdjustDecay = 10;
12+
13+
[SerializeField] TextMeshProUGUI MaskDepthBiasText;
1514
private EnvironmentDepthManager _environmentDepthManager;
1615
private float _maskBiasAdjustValue = 0.2f;
17-
private List<MeshFilter> _wallMeshFilters = new();
16+
private List<MeshFilter> _wallMeshFilters;
1817

1918
private bool _isMaskOn;
19+
private float _depthBiasAdjust = 0;
2020

2121
private void Awake()
2222
{
2323
_environmentDepthManager = FindAnyObjectByType<EnvironmentDepthManager>();
24+
_wallMeshFilters = new List<MeshFilter>();
2425
}
25-
26-
private void LoadRoomMesh()
26+
public void LoadRoomMesh()
2727
{
28-
if (_environmentDepthManager == null)
29-
return;
3028
if ((MRUK.Instance.GetCurrentRoom() == null) || (_environmentDepthManager == null))
3129
{
3230
return;
3331
}
3432
_wallMeshFilters.Clear();
3533
for (var i = 0; i < MRUK.Instance.GetCurrentRoom().WallAnchors.Count; i++)
3634
{
35+
Debug.Log("Found wall");
3736
_wallMeshFilters.Add(MRUK.Instance.GetCurrentRoom().WallAnchors[i].gameObject.GetComponentInChildren<MeshFilter>());
3837
}
3938

@@ -42,7 +41,7 @@ private void LoadRoomMesh()
4241

4342
private void Update()
4443
{
45-
if (OVRInput.GetDown(_maskToggleButton))
44+
if (OVRInput.GetDown(OVRInput.RawButton.B))
4645
{
4746
if (!_isMaskOn)
4847
{
@@ -55,17 +54,58 @@ private void Update()
5554
_isMaskOn = !_isMaskOn;
5655
}
5756

58-
if (OVRInput.Get(_maskBiasAdjustDecreaseButton))
57+
if (OVRInput.Get(OVRInput.RawButton.RThumbstickLeft))
5958
{
6059
_environmentDepthManager.MaskBias -= _maskBiasAdjustValue * Time.deltaTime;
6160
}
6261

63-
if (OVRInput.Get(_maskBiasAdjustIncreaseButton))
62+
if (OVRInput.Get(OVRInput.RawButton.RThumbstickRight))
6463
{
6564
_environmentDepthManager.MaskBias += _maskBiasAdjustValue * Time.deltaTime;
6665
}
67-
if (MaskDepthBiasText != null)
68-
MaskDepthBiasText.text = "Mask bias " + _environmentDepthManager.MaskBias.ToString("#.000");
66+
67+
if (Mathf.Abs(_depthBiasAdjust) > 0.01f)
68+
{
69+
_environmentDepthManager.MaskBias += _maskBiasAdjustValue * _depthBiasAdjust * Time.deltaTime;
70+
_depthBiasAdjust -= Time.deltaTime * depthBiasAdjustDecay * Mathf.Sign(_depthBiasAdjust);
71+
}
72+
else
73+
{
74+
_depthBiasAdjust = 0;
75+
}
76+
77+
78+
MaskDepthBiasText.text = "Mask bias " + _environmentDepthManager.MaskBias.ToString("#.000");
79+
}
80+
81+
public void OnMicroGesture(OVRHand.MicrogestureType gesture)
82+
{
83+
switch (gesture)
84+
{
85+
case OVRHand.MicrogestureType.SwipeForward:
86+
{
87+
_depthBiasAdjust += 1;
88+
}
89+
break;
90+
case OVRHand.MicrogestureType.SwipeBackward:
91+
{
92+
_depthBiasAdjust += -1;
93+
}
94+
break;
95+
case OVRHand.MicrogestureType.ThumbTap:
96+
{
97+
if (!_isMaskOn)
98+
{
99+
LoadRoomMesh();
100+
}
101+
else
102+
{
103+
_wallMeshFilters.Clear();
104+
}
105+
_isMaskOn = !_isMaskOn;
106+
}
107+
break;
108+
}
69109
}
70110
}
71111
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: efa1458c2bc55e04b872c61942be2866, type: 3}
13+
m_Name: OVROverlayCanvasSettings
14+
m_EditorClassIdentifier: Oculus.VR::OVROverlayCanvasSettings
15+
_transparentImposterShader: {fileID: 0}
16+
_opaqueImposterShader: {fileID: 0}
17+
MaxSimultaneousCanvases: 4
18+
CanvasRenderLayer: 31
19+
CanvasLayer: -1

DepthAPI-BiRP/Assets/Resources/OVROverlayCanvasSettings.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DepthAPI-BiRP/ProjectSettings/ProjectSettings.asset

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,8 @@ PlayerSettings:
143143
loadStoreDebugModeEnabled: 0
144144
visionOSBundleVersion: 1.0
145145
tvOSBundleVersion: 1.0
146-
bundleVersion: 1.0.0
146+
bundleVersion: 1.1.0
147147
preloadedAssets:
148-
- {fileID: 0}
149-
- {fileID: 0}
150-
- {fileID: 0}
151-
- {fileID: 0}
152-
- {fileID: 0}
153-
- {fileID: 0}
154-
- {fileID: 0}
155148
- {fileID: 11400000, guid: da7d185d2087dac4287c95a47f1ad635, type: 2}
156149
metroInputSource: 0
157150
wsaTransparentSwapchain: 0
@@ -842,8 +835,8 @@ PlayerSettings:
842835
webWasm2023: 0
843836
webEnableSubmoduleStrippingCompatibility: 0
844837
scriptingDefineSymbols:
845-
Android: ISDK_OPENXR_HAND;USE_INPUT_SYSTEM_POSE_CONTROL;USE_STICK_CONTROL_THUMBSTICKS
846-
Standalone: ISDK_OPENXR_HAND;USE_INPUT_SYSTEM_POSE_CONTROL;USE_STICK_CONTROL_THUMBSTICKS
838+
Android: ISDK_OPENXR_HAND;USE_INPUT_SYSTEM_POSE_CONTROL;USE_STICK_CONTROL_THUMBSTICKS;OVR_DISABLE_HAND_PINCH_BUTTON_MAPPING
839+
Standalone: ISDK_OPENXR_HAND;USE_INPUT_SYSTEM_POSE_CONTROL;USE_STICK_CONTROL_THUMBSTICKS;OVR_DISABLE_HAND_PINCH_BUTTON_MAPPING
847840
Windows Store Apps: USE_INPUT_SYSTEM_POSE_CONTROL;USE_STICK_CONTROL_THUMBSTICKS
848841
additionalCompilerArguments: {}
849842
platformArchitecture: {}

0 commit comments

Comments
 (0)