Skip to content

Commit b811b37

Browse files
author
David Kline
authored
Merge pull request #2559 from StephenHodgson/vNEXT-ControllerRendering
Refactored Controller Viz
2 parents 61ee9fe + 575a694 commit b811b37

30 files changed

+383
-469
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/GazeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.InputSystem.Pointers;
55
using Microsoft.MixedReality.Toolkit.InputSystem.Sources;
6-
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
6+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.Devices;
77
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
88
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
99
using Microsoft.MixedReality.Toolkit.Internal.Utilities.Physics;

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/ControllerPoseSynchronizer.cs

Lines changed: 97 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Devices;
5+
using Microsoft.MixedReality.Toolkit.Internal.Definitions.InputSystem;
56
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
67
using Microsoft.MixedReality.Toolkit.Internal.EventDatum.Input;
7-
using Microsoft.MixedReality.Toolkit.Internal.Extensions;
8-
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
8+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.Devices;
99
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem.Handlers;
1010
using UnityEngine;
1111

@@ -14,37 +14,22 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Input.Handlers
1414
/// <summary>
1515
/// Waits for a controller to be initialized, then synchronizes its transform position to a specified handedness.
1616
/// </summary>
17-
public class ControllerPoseSynchronizer : InputSystemGlobalListener, IMixedRealitySourcePoseHandler
17+
public class ControllerPoseSynchronizer : InputSystemGlobalListener, IMixedRealitySourcePoseHandler, IMixedRealityControllerPoseSynchronizer
1818
{
19+
#region IMixedRealityControllerPoseSynchronizer Implementation
20+
1921
[SerializeField]
2022
[Tooltip("The handedness this controller should synchronize with.")]
2123
private Handedness handedness = Handedness.Left;
2224

23-
/// <summary>
24-
/// The handedness this controller should synchronize with.
25-
/// </summary>
25+
/// <inheritdoc />
2626
public Handedness Handedness => handedness;
2727

2828
[SerializeField]
29-
[Tooltip("Disables child GameObjects when the controller source is lost.")]
30-
private bool disableChildren = true;
31-
32-
/// <summary>
33-
///Disables child <see cref="GameObject"/>s the controller source is lost.
34-
/// </summary>
35-
public bool DisableChildren
36-
{
37-
get { return disableChildren; }
38-
set { disableChildren = value; }
39-
}
40-
41-
[SerializeField]
42-
[Tooltip("Should this GameObject clean itself up after source is lost?")]
29+
[Tooltip("Should this GameObject clean itself up when it's controller is lost?")]
4330
private bool destroyOnSourceLost = true;
4431

45-
/// <summary>
46-
/// Should this GameObject clean itself up after source is lost?
47-
/// </summary>
32+
/// <inheritdoc />
4833
public bool DestroyOnSourceLost
4934
{
5035
get { return destroyOnSourceLost; }
@@ -61,44 +46,49 @@ public bool DestroyOnSourceLost
6146
/// </summary>
6247
protected TrackingState TrackingState = TrackingState.NotTracked;
6348

64-
/// <summary>
65-
/// The currently assigned Controller.
66-
/// </summary>
49+
private IMixedRealityController controller;
50+
51+
/// <inheritdoc />
6752
public virtual IMixedRealityController Controller
6853
{
6954
get { return controller; }
7055
set
7156
{
7257
handedness = value.ControllerHandedness;
7358
controller = value;
59+
gameObject.name = $"{handedness}_{gameObject.name}";
7460
}
7561
}
7662

77-
private IMixedRealityController controller;
78-
79-
#region IMixedRealitySourcePoseHandler Implementation
63+
[SerializeField]
64+
[Tooltip("Should the Transform's position be driven from the source pose or from input handler?")]
65+
private bool useSourcePoseData = true;
8066

8167
/// <inheritdoc />
82-
public virtual void OnSourceDetected(SourceStateEventData eventData)
68+
public bool UseSourcePoseData
8369
{
84-
if (Controller == null ||
85-
eventData.Controller == null ||
86-
eventData.Controller.InputSource.SourceId != Controller.InputSource.SourceId)
87-
{
88-
return;
89-
}
70+
get { return useSourcePoseData; }
71+
set { useSourcePoseData = value; }
72+
}
9073

91-
if (eventData.Controller.ControllerHandedness == Handedness &&
92-
eventData.Controller.InputSource.SourceId == Controller.InputSource.SourceId)
93-
{
74+
[SerializeField]
75+
[Tooltip("The input action that will drive the Transform's pose, position, or rotation.")]
76+
private MixedRealityInputAction poseAction = MixedRealityInputAction.None;
9477

95-
if (disableChildren)
96-
{
97-
gameObject.SetChildrenActive(true);
98-
}
99-
}
78+
/// <inheritdoc />
79+
public MixedRealityInputAction PoseAction
80+
{
81+
get { return poseAction; }
82+
set { poseAction = value; }
10083
}
10184

85+
#endregion IMixedRealityControllerPoseSynchronizer Implementation
86+
87+
#region IMixedRealitySourcePoseHandler Implementation
88+
89+
/// <inheritdoc />
90+
public virtual void OnSourceDetected(SourceStateEventData eventData) { }
91+
10292
/// <inheritdoc />
10393
public virtual void OnSourceLost(SourceStateEventData eventData)
10494
{
@@ -114,11 +104,6 @@ public virtual void OnSourceLost(SourceStateEventData eventData)
114104
IsTracked = false;
115105
TrackingState = TrackingState.NotTracked;
116106

117-
if (disableChildren)
118-
{
119-
gameObject.SetChildrenActive(false);
120-
}
121-
122107
if (destroyOnSourceLost)
123108
{
124109
if (Application.isEditor)
@@ -149,13 +134,75 @@ public virtual void OnSourcePoseChanged(SourcePoseEventData eventData)
149134
TrackingState = eventData.TrackingState;
150135
}
151136

152-
if (TrackingState == TrackingState.Tracked)
137+
if (UseSourcePoseData && TrackingState == TrackingState.Tracked)
153138
{
154139
transform.localPosition = eventData.MixedRealityPose.Position;
155140
transform.localRotation = eventData.MixedRealityPose.Rotation;
156141
}
157142
}
158143

159144
#endregion IMixedRealitySourcePoseHandler Implementation
145+
146+
#region IMixedRealityInputHandler Implementation
147+
148+
public virtual void OnInputUp(InputEventData eventData) { }
149+
150+
public virtual void OnInputDown(InputEventData eventData) { }
151+
152+
public virtual void OnInputPressed(InputEventData<float> eventData) { }
153+
154+
public virtual void OnPositionInputChanged(InputEventData<Vector2> eventData) { }
155+
156+
#endregion IMixedRealityInputHandler Implementation
157+
158+
#region IMixedRealitySpatialInputHandler Implementation
159+
160+
/// <inheritdoc />
161+
public virtual void OnPositionChanged(InputEventData<Vector3> eventData)
162+
{
163+
if (eventData.SourceId == Controller?.InputSource.SourceId)
164+
{
165+
if (!UseSourcePoseData &&
166+
PoseAction == eventData.MixedRealityInputAction)
167+
{
168+
IsTracked = true;
169+
TrackingState = TrackingState.Tracked;
170+
transform.localPosition = eventData.InputData;
171+
}
172+
}
173+
}
174+
175+
/// <inheritdoc />
176+
public virtual void OnRotationChanged(InputEventData<Quaternion> eventData)
177+
{
178+
if (eventData.SourceId == Controller?.InputSource.SourceId)
179+
{
180+
if (!UseSourcePoseData &&
181+
PoseAction == eventData.MixedRealityInputAction)
182+
{
183+
IsTracked = true;
184+
TrackingState = TrackingState.Tracked;
185+
transform.localRotation = eventData.InputData;
186+
}
187+
}
188+
}
189+
190+
/// <inheritdoc />
191+
public virtual void OnPoseInputChanged(InputEventData<MixedRealityPose> eventData)
192+
{
193+
if (eventData.SourceId == Controller?.InputSource.SourceId)
194+
{
195+
if (!UseSourcePoseData &&
196+
PoseAction == eventData.MixedRealityInputAction)
197+
{
198+
IsTracked = true;
199+
TrackingState = TrackingState.Tracked;
200+
transform.localPosition = eventData.InputData.Position;
201+
transform.localRotation = eventData.InputData.Rotation;
202+
}
203+
}
204+
}
205+
206+
#endregion IMixedRealitySpatialInputHandler Implementation
160207
}
161208
}

Assets/MixedRealityToolkit-SDK/Features/Input/MixedRealityInputManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
88
using Microsoft.MixedReality.Toolkit.Internal.EventDatum.Input;
99
using Microsoft.MixedReality.Toolkit.Internal.Extensions;
10-
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
10+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.Devices;
1111
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
1212
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem.Handlers;
1313
using Microsoft.MixedReality.Toolkit.Internal.Managers;

Assets/MixedRealityToolkit-SDK/Features/UX/Prefabs/Pointers/DefaultControllerPointer.prefab

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ MonoBehaviour:
9696
m_Name:
9797
m_EditorClassIdentifier:
9898
handedness: 1
99-
disableChildren: 1
100-
cursorPrefab: {fileID: 1000012072213228, guid: 5b3e2856904e43c680f84f326861032a,
101-
type: 2}
102-
raycastOrigin: {fileID: 0}
99+
destroyOnSourceLost: 1
103100
useSourcePoseData: 0
104-
inputSourceAction:
101+
poseAction:
105102
id: 4
106103
description: Pointer Pose
107104
axisConstraint: 7
105+
cursorPrefab: {fileID: 1000012072213228, guid: 5b3e2856904e43c680f84f326861032a,
106+
type: 2}
107+
raycastOrigin: {fileID: 0}
108108
activeHoldAction:
109109
id: 0
110110
description: None

Assets/MixedRealityToolkit-SDK/Features/UX/Prefabs/Pointers/ParabolicPointer.prefab

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,15 @@ MonoBehaviour:
259259
m_Name:
260260
m_EditorClassIdentifier:
261261
handedness: 1
262-
disableChildren: 1
263262
destroyOnSourceLost: 1
264-
cursorPrefab: {fileID: 1554777696564956, guid: ae2b3fffb00f464287cda86f49109b47,
265-
type: 2}
266-
raycastOrigin: {fileID: 0}
267263
useSourcePoseData: 0
268-
inputSourceAction:
264+
poseAction:
269265
id: 4
270266
description: Pointer Pose
271267
axisConstraint: 7
268+
cursorPrefab: {fileID: 1554777696564956, guid: ae2b3fffb00f464287cda86f49109b47,
269+
type: 2}
270+
raycastOrigin: {fileID: 0}
272271
activeHoldAction:
273272
id: 0
274273
description: None

0 commit comments

Comments
 (0)