Skip to content

Commit 667bb3f

Browse files
RogPodgekeveleigh
andauthored
Controller model fallbacks (#10568)
* initial work in unifying hand visuals * additional improvements to make the rigged hands class a subclass of the base class * fixed bug with hand visualizer showing up early * Update Assets/MRTK/SDK/Features/UX/Scripts/RiggedHandVisualizer/RiggedHandVisualizer.cs Co-authored-by: Kurtis <[email protected]> * pr feedback * Vetted to work on hololens, profile adjusted accordingly * removing debug code * updated tests * added vr controller model fallbacks, base visualizer allows user to specify rotation offsets * Update Assets/MRTK/Core/Providers/BaseController.cs Co-authored-by: Kurtis <[email protected]> * pr nit * update PR nits Co-authored-by: Kurtis <[email protected]>
1 parent ee78332 commit 667bb3f

28 files changed

+730
-25
lines changed

Assets/MRTK/Core/Providers/BaseController.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,8 @@ protected virtual bool TryRenderControllerModel(Type controllerType, InputSource
242242
return true;
243243
}
244244

245-
GameObject controllerModel = null;
246-
bool usePlatformModels = controllerVisualizationProfile.GetUsePlatformModelsOverride(controllerType, ControllerHandedness);
247-
248-
// If a specific controller template wants to override the global model, assign it
249-
if (!usePlatformModels)
250-
{
251-
controllerModel = controllerVisualizationProfile.GetControllerModelOverride(controllerType, ControllerHandedness);
252-
}
245+
// Try to use the profile's override model first
246+
GameObject controllerModel = controllerVisualizationProfile.GetControllerModelOverride(controllerType, ControllerHandedness);
253247

254248
// If the Controller model is still null in the end, use the global defaults.
255249
if (controllerModel == null)

Assets/MRTK/SDK/Editor/Inspectors/Input/Handlers/MixedRealityControllerVisualizerInspector.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,22 @@
66
namespace Microsoft.MixedReality.Toolkit.Input.Editor
77
{
88
[CustomEditor(typeof(MixedRealityControllerVisualizer), true)]
9-
public class MixedRealityControllerVisualizerInspector : ControllerPoseSynchronizerInspector { }
9+
public class MixedRealityControllerVisualizerInspector : ControllerPoseSynchronizerInspector
10+
{
11+
private SerializedProperty rotationOffset;
12+
13+
protected override void OnEnable()
14+
{
15+
rotationOffset = serializedObject.FindProperty("rotationOffset");
16+
base.OnEnable();
17+
}
18+
19+
public override void OnInspectorGUI()
20+
{
21+
EditorGUILayout.PropertyField(rotationOffset);
22+
serializedObject.ApplyModifiedProperties();
23+
24+
base.OnInspectorGUI();
25+
}
26+
}
1027
}

Assets/MRTK/SDK/Features/UX/Scripts/Controllers/MixedRealityControllerVisualizer.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using Microsoft.MixedReality.Toolkit.Utilities;
45
using UnityEngine;
56

67
namespace Microsoft.MixedReality.Toolkit.Input
@@ -12,6 +13,15 @@ namespace Microsoft.MixedReality.Toolkit.Input
1213
[AddComponentMenu("Scripts/MRTK/SDK/MixedRealityControllerVisualizer")]
1314
public class MixedRealityControllerVisualizer : ControllerPoseSynchronizer, IMixedRealityControllerVisualizer
1415
{
16+
/// <summary>
17+
/// The amount to offset this controller visualizer's rotation from the input pose
18+
/// </summary>
19+
[SerializeField]
20+
[Tooltip("The amount to offset this controller visualizer's rotation from the input pose")]
21+
protected Quaternion rotationOffset = Quaternion.identity;
22+
23+
protected virtual Quaternion RotationOffset => rotationOffset;
24+
1525
// TODO wire up input actions to controller transform nodes / animations
1626

1727
/// <inheritdoc />
@@ -67,6 +77,18 @@ public override void OnInputChanged(InputEventData<Vector2> eventData)
6777
// TODO Visualize dual axis controls
6878
}
6979

80+
81+
/// <inheritdoc />
82+
public override void OnSourcePoseChanged(SourcePoseEventData<MixedRealityPose> eventData)
83+
{
84+
if (UseSourcePoseData &&
85+
eventData.SourceId == Controller?.InputSource.SourceId)
86+
{
87+
base.OnSourcePoseChanged(eventData);
88+
transform.localRotation *= RotationOffset;
89+
}
90+
}
91+
7092
#endregion IMixedRealityInputHandler Implementation
7193
}
7294
}

Assets/MRTK/SDK/Features/UX/Scripts/Controllers/WindowsMixedRealityControllerVisualizer.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ namespace Microsoft.MixedReality.Toolkit.Input
99
[AddComponentMenu("Scripts/MRTK/SDK/WindowsMixedRealityControllerVisualizer")]
1010
public class WindowsMixedRealityControllerVisualizer : MixedRealityControllerVisualizer
1111
{
12-
private readonly Quaternion inverseRotation = Quaternion.Euler(0f, 180f, 0f);
13-
14-
/// <inheritdoc />
15-
public override void OnSourcePoseChanged(SourcePoseEventData<MixedRealityPose> eventData)
16-
{
17-
if (UseSourcePoseData &&
18-
eventData.SourceId == Controller?.InputSource.SourceId)
19-
{
20-
base.OnSourcePoseChanged(eventData);
21-
transform.localRotation *= inverseRotation;
22-
}
23-
}
12+
protected override Quaternion RotationOffset => rotationOffset * Quaternion.Euler(0, 180.0f, 0);
2413
}
2514
}

Assets/MRTK/SDK/Profiles/DefaultMixedRealityControllerVisualizationProfile.asset

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ MonoBehaviour:
2020
usePlatformModels: 1
2121
platformModelMaterial: {fileID: 2100000, guid: 54322026142964d4084eda2478d9b1a2,
2222
type: 2}
23-
globalLeftControllerModel: {fileID: 1370450866519632, guid: 626257b1a6cd47c2a32a18cf75b2fb23,
23+
globalLeftControllerModel: {fileID: 1370450866519632, guid: 60b24c9a73f9f5549b32035f8c864cc7,
2424
type: 3}
25-
globalRightControllerModel: {fileID: 1760394390528354, guid: 9ef0df44319c4fb4a05649e5b8ceb6d1,
25+
globalRightControllerModel: {fileID: 1370450866519632, guid: e2b0df939d55cdc489073d2560b1f871,
2626
type: 3}
2727
globalLeftHandVisualizer: {fileID: 61451597023024772, guid: 6080fb9e3b49fda449e3d70daf6d2254,
2828
type: 3}
@@ -162,10 +162,22 @@ MonoBehaviour:
162162
- description: Oculus Controller
163163
controllerType:
164164
reference: Microsoft.MixedReality.Toolkit.XRSDK.OpenXR.OculusController, Microsoft.MixedReality.Toolkit.Providers.OpenXR
165-
handedness: 3
165+
handedness: 1
166166
usePlatformModels: 1
167167
platformModelMaterial: {fileID: 0}
168-
overrideModel: {fileID: 0}
168+
overrideModel: {fileID: 1370450866519632, guid: b7913d8b23c647f40a6cf01618dfa9cc,
169+
type: 3}
170+
controllerVisualizationType:
171+
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
172+
Microsoft.MixedReality.Toolkit.SDK
173+
- description: Oculus Controller
174+
controllerType:
175+
reference: Microsoft.MixedReality.Toolkit.XRSDK.OpenXR.OculusController, Microsoft.MixedReality.Toolkit.Providers.OpenXR
176+
handedness: 2
177+
usePlatformModels: 1
178+
platformModelMaterial: {fileID: 0}
179+
overrideModel: {fileID: 1370450866519632, guid: abf0b9f9eb3e0864c81ef0f82b6b6ade,
180+
type: 3}
169181
controllerVisualizationType:
170182
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
171183
Microsoft.MixedReality.Toolkit.SDK
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &1370450866519632
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 4607474556101662}
12+
- component: {fileID: 3753994074039930916}
13+
m_Layer: 0
14+
m_Name: ControllerLeft
15+
m_TagString: Untagged
16+
m_Icon: {fileID: 0}
17+
m_NavMeshLayer: 0
18+
m_StaticEditorFlags: 0
19+
m_IsActive: 1
20+
--- !u!4 &4607474556101662
21+
Transform:
22+
m_ObjectHideFlags: 0
23+
m_CorrespondingSourceObject: {fileID: 0}
24+
m_PrefabInstance: {fileID: 0}
25+
m_PrefabAsset: {fileID: 0}
26+
m_GameObject: {fileID: 1370450866519632}
27+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28+
m_LocalPosition: {x: 0, y: 0, z: 0}
29+
m_LocalScale: {x: 1, y: 1, z: 1}
30+
m_Children:
31+
- {fileID: 7869290148133498079}
32+
m_Father: {fileID: 0}
33+
m_RootOrder: 0
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
--- !u!114 &3753994074039930916
36+
MonoBehaviour:
37+
m_ObjectHideFlags: 0
38+
m_CorrespondingSourceObject: {fileID: 0}
39+
m_PrefabInstance: {fileID: 0}
40+
m_PrefabAsset: {fileID: 0}
41+
m_GameObject: {fileID: 1370450866519632}
42+
m_Enabled: 1
43+
m_EditorHideFlags: 0
44+
m_Script: {fileID: 11500000, guid: e55797f2a3e06fc48bad82177febcba8, type: 3}
45+
m_Name:
46+
m_EditorClassIdentifier:
47+
destroyOnSourceLost: 1
48+
useSourcePoseData: 1
49+
useSourcePoseAsFallback: 1
50+
poseAction:
51+
id: 0
52+
description: None
53+
axisConstraint: 0
54+
handedness: 1
55+
--- !u!1001 &3360894756952727033
56+
PrefabInstance:
57+
m_ObjectHideFlags: 0
58+
serializedVersion: 2
59+
m_Modification:
60+
m_TransformParent: {fileID: 4607474556101662}
61+
m_Modifications:
62+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
63+
type: 3}
64+
propertyPath: m_RootOrder
65+
value: 0
66+
objectReference: {fileID: 0}
67+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
68+
type: 3}
69+
propertyPath: m_LocalPosition.x
70+
value: 0
71+
objectReference: {fileID: 0}
72+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
73+
type: 3}
74+
propertyPath: m_LocalPosition.y
75+
value: 0
76+
objectReference: {fileID: 0}
77+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
78+
type: 3}
79+
propertyPath: m_LocalPosition.z
80+
value: 0
81+
objectReference: {fileID: 0}
82+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
83+
type: 3}
84+
propertyPath: m_LocalRotation.w
85+
value: 1
86+
objectReference: {fileID: 0}
87+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
88+
type: 3}
89+
propertyPath: m_LocalRotation.x
90+
value: 0
91+
objectReference: {fileID: 0}
92+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
93+
type: 3}
94+
propertyPath: m_LocalRotation.y
95+
value: 0
96+
objectReference: {fileID: 0}
97+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
98+
type: 3}
99+
propertyPath: m_LocalRotation.z
100+
value: 0
101+
objectReference: {fileID: 0}
102+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
103+
type: 3}
104+
propertyPath: m_LocalEulerAnglesHint.x
105+
value: 0
106+
objectReference: {fileID: 0}
107+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
108+
type: 3}
109+
propertyPath: m_LocalEulerAnglesHint.y
110+
value: 0
111+
objectReference: {fileID: 0}
112+
- target: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
113+
type: 3}
114+
propertyPath: m_LocalEulerAnglesHint.z
115+
value: 0
116+
objectReference: {fileID: 0}
117+
- target: {fileID: -3008979517380814025, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
118+
type: 3}
119+
propertyPath: m_Name
120+
value: left
121+
objectReference: {fileID: 0}
122+
m_RemovedComponents: []
123+
m_SourcePrefab: {fileID: 9199261849990390558, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
124+
type: 3}
125+
--- !u!4 &7869290148133498079 stripped
126+
Transform:
127+
m_CorrespondingSourceObject: {fileID: -4354666053824302810, guid: 3571524ae1cc5b5428d87fd85a3a9f4c,
128+
type: 3}
129+
m_PrefabInstance: {fileID: 3360894756952727033}
130+
m_PrefabAsset: {fileID: 0}

Assets/MRTK/SDK/StandardAssets/Controllers/DebugControllers/ControllerLeft.prefab.meta

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

0 commit comments

Comments
 (0)