Skip to content

Commit f5e9fe3

Browse files
author
lawwong
committed
Add hand & render model options for Oculus
VIUSettings.EnableOculusSDKHandRenderModel VIUSettings.EnableOculusSDKControllerRenderModel VIUSettings.EnableOculusSDKControllerRenderModelSkeleton
1 parent daa5100 commit f5e9fe3

4 files changed

Lines changed: 89 additions & 29 deletions

File tree

Assets/HTC.UnityPlugin/VRModule/Modules/OculusVRModule.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ public override bool shouldActive
121121
#pragma warning disable 0162
122122
if (!OculusHandRenderModel.SUPPORTED && !VIUOvrAvatar.SUPPORTED) { return false; }
123123
#pragma warning restore 0162
124-
return s_moduleInstance == null ? false : s_moduleInstance.isActivated;
124+
if (!VIUSettings.EnableOculusSDKHandRenderModel && !VIUSettings.EnableOculusSDKControllerRenderModel) { return false; }
125+
if (s_moduleInstance == null) { return false; }
126+
if (!s_moduleInstance.isActivated) { return false; }
127+
return true;
125128
}
126129
}
127130

@@ -137,7 +140,7 @@ public override void UpdateRenderModel()
137140
return;
138141
}
139142

140-
if (IsHand() && OculusHandRenderModel.SUPPORTED)
143+
if (IsHand() && OculusHandRenderModel.SUPPORTED && VIUSettings.EnableOculusSDKHandRenderModel)
141144
{
142145
var isLeftHand = m_index == s_leftHandIndex;
143146
if (m_handModel == null)
@@ -163,7 +166,7 @@ public override void UpdateRenderModel()
163166
if (m_handModel != null) { m_handModel.gameObject.SetActive(false); }
164167
}
165168

166-
if (m_index == s_rightControllerIndex && VIUOvrAvatar.SUPPORTED)
169+
if (m_index == s_rightControllerIndex && VIUOvrAvatar.SUPPORTED && VIUSettings.EnableOculusSDKControllerRenderModel)
167170
{
168171
LoadAvatar();
169172
if (m_rightModel == null)
@@ -184,7 +187,7 @@ public override void UpdateRenderModel()
184187
if (m_rightModel != null) { m_rightModel.gameObject.SetActive(false); }
185188
}
186189

187-
if (m_index == s_leftControllerIndex && VIUOvrAvatar.SUPPORTED)
190+
if (m_index == s_leftControllerIndex && VIUOvrAvatar.SUPPORTED && VIUSettings.EnableOculusSDKControllerRenderModel)
188191
{
189192
LoadAvatar();
190193
if (m_leftModel == null)
@@ -229,13 +232,15 @@ public override void CleanUpRenderModel()
229232
m_index = INVALID_DEVICE_INDEX;
230233
}
231234

232-
private void LoadAvatar()
235+
public static VIUOvrAvatar LoadAvatar()
233236
{
234237
if (s_avatar == null)
235238
{
236239
var go = new GameObject(typeof(VIUOvrAvatar).Name);
237240
s_avatar = go.AddComponent<VIUOvrAvatar>();
238241
}
242+
s_avatar.ShowHand = VIUSettings.EnableOculusSDKControllerRenderModelSkeleton;
243+
return s_avatar;
239244
}
240245

241246
private bool IsHand()
@@ -380,6 +385,7 @@ public override void OnActivated()
380385
public override void OnDeactivated()
381386
{
382387
OVRPlugin.SetTrackingOriginType(m_prevTrackingSpace);
388+
s_moduleInstance = null;
383389
}
384390

385391
public override void UpdateTrackingSpaceType()
@@ -502,7 +508,7 @@ public override void BeforeRenderUpdate()
502508
{
503509
if (prevState.isConnected)
504510
{
505-
Debug.Log("[VIU][OculusVRModule] device disconnected. name:" + prevState.modelNumber + " model:" + prevState.deviceModel);
511+
Debug.Log("[VIU][OculusVRModule] " + prevState.deviceModel + " device disconnected.");
506512
currState.Reset();
507513
}
508514
continue;
@@ -514,7 +520,7 @@ public override void BeforeRenderUpdate()
514520
{
515521
if (prevState.isConnected)
516522
{
517-
Debug.Log("[VIU][OculusVRModule] device disconnected. name:" + prevState.modelNumber + " model:" + prevState.deviceModel);
523+
Debug.Log("[VIU][OculusVRModule] " + prevState.deviceModel + " device disconnected.");
518524
currState.Reset();
519525
}
520526
continue;
@@ -608,7 +614,7 @@ public override void BeforeRenderUpdate()
608614
break;
609615
}
610616

611-
Debug.Log("[VIU][OculusVRModule] device connected. name:" + deviceName + " model:" + currState.deviceModel);
617+
Debug.Log("[VIU][OculusVRModule] " + currState.deviceModel + " device connected. deviceName=\"" + deviceName + "\"");
612618
}
613619

614620
// update device pose
@@ -822,14 +828,14 @@ public override void BeforeRenderUpdate()
822828
{
823829
if (currState.isPoseValid)
824830
{
825-
Debug.Log("[VIU][OculusVRModule] pose valid. name:" + prevState.modelNumber + " model:" + prevState.deviceModel);
831+
Debug.Log("[VIU][OculusVRModule] " + currState.deviceModel + " pose valid.");
826832
}
827833
}
828834
else
829835
{
830836
if (!currState.isPoseValid)
831837
{
832-
Debug.Log("[VIU][OculusVRModule] pose invalid. name:" + prevState.modelNumber + " model:" + prevState.deviceModel);
838+
Debug.Log("[VIU][OculusVRModule] " + prevState.deviceModel + " pose invalid.");
833839
}
834840
}
835841
}

Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
9292
case VRModuleDeviceModel.OculusGoController:
9393
case VRModuleDeviceModel.OculusQuestControllerLeft:
9494
case VRModuleDeviceModel.OculusQuestControllerRight:
95+
case VRModuleDeviceModel.OculusQuest2ControllerLeft:
96+
case VRModuleDeviceModel.OculusQuest2ControllerRight:
9597
updateFunc = UpdateOculusControllerState;
9698
break;
9799
case VRModuleDeviceModel.WMRControllerLeft:

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -675,38 +675,74 @@ public override void OnPreferenceGUI()
675675
GUILayout.EndHorizontal();
676676
}
677677

678-
if (support && m_foldouter.isExpended)
678+
if (m_foldouter.isExpended)
679679
{
680680
if (support) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; }
681681
{
682682
EditorGUI.indentLevel += 2;
683683

684-
#if VIU_OCULUSVR_20_0_OR_NEWER
685684
// Hand tracking support
686-
EditorGUILayout.BeginHorizontal();
687-
OVRProjectConfig.HandTrackingSupport originalHandTrackingSupport = oculusProjectConfig.handTrackingSupport;
688-
oculusProjectConfig.handTrackingSupport = (OVRProjectConfig.HandTrackingSupport)EditorGUILayout.EnumPopup("Hand Tracking Support: ", originalHandTrackingSupport);
689-
690-
if (oculusProjectConfig.handTrackingSupport != originalHandTrackingSupport)
685+
const string enableHandTrackingTitle = "Enable Oculus Hand Tracking";
686+
const string enableHandRenderModelTitle = "Enable Oculus Tracked Hand Render Model";
687+
#if VIU_OCULUSVR_20_0_OR_NEWER
691688
{
692-
EditorUtility.SetDirty(oculusProjectConfig);
689+
var oldEnableHandTracking = oculusProjectConfig.handTrackingSupport != OVRProjectConfig.HandTrackingSupport.ControllersOnly;
690+
var newEnableHandTracking = EditorGUILayout.ToggleLeft(enableHandTrackingTitle, oldEnableHandTracking);
691+
if (newEnableHandTracking)
692+
{ if (!oldEnableHandTracking) { oculusProjectConfig.handTrackingSupport = OVRProjectConfig.HandTrackingSupport.ControllersAndHands; } }
693+
else
694+
{ if (oldEnableHandTracking) { oculusProjectConfig.handTrackingSupport = OVRProjectConfig.HandTrackingSupport.ControllersOnly; } }
695+
696+
if (newEnableHandTracking)
697+
{
698+
VIUSettings.EnableOculusSDKHandRenderModel = EditorGUILayout.ToggleLeft(new GUIContent(enableHandRenderModelTitle, VIUSettings.ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_TOOLTIP), VIUSettings.EnableOculusSDKHandRenderModel);
699+
}
700+
else
701+
{
702+
var wasGUIEnabled = GUI.enabled;
703+
GUI.enabled = false;
704+
EditorGUILayout.ToggleLeft(new GUIContent(enableHandRenderModelTitle, VIUSettings.ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_TOOLTIP), false);
705+
GUI.enabled = wasGUIEnabled;
706+
}
693707
}
694-
EditorGUILayout.EndHorizontal();
695708
#else
696-
EditorGUILayout.BeginHorizontal();
709+
{
710+
EditorGUILayout.BeginHorizontal();
697711

698-
EditorGUILayout.HelpBox("Hand tracking not supported. Please install Oculus Integration.", MessageType.Info);
699-
GUILayout.FlexibleSpace();
712+
var wasGUIEnabled = GUI.enabled;
713+
GUI.enabled = false;
714+
EditorGUILayout.ToggleLeft(new GUIContent(enableHandTrackingTitle, "Hand tracking not supported. Please install latest Oculus Integration."), false);
715+
GUI.enabled = wasGUIEnabled;
700716

701-
s_warningHeight = Mathf.Max(s_warningHeight, GUILayoutUtility.GetLastRect().height);
702-
GUILayout.BeginVertical(GUILayout.Height(s_warningHeight));
703-
GUILayout.FlexibleSpace();
704-
ShowUrlLinkButton(URL_OCULUS_VR_PLUGIN, "Get Oculus Integration");
705-
GUILayout.FlexibleSpace();
706-
GUILayout.EndVertical();
717+
GUILayout.FlexibleSpace();
718+
ShowUrlLinkButton(URL_OCULUS_VR_PLUGIN, "Get Oculus Integration");
707719

708-
EditorGUILayout.EndHorizontal();
720+
EditorGUILayout.EndHorizontal();
721+
}
709722
#endif
723+
// Controller Render Model
724+
const string enableControllerRenderModelTitle = "Enable Oculus Controller Render Model";
725+
const string enableControllerRenderModelSkeletonTitle = "Enable Hand Attached to Oculus Controller Render Model";
726+
if (OculusVRExtension.VIUOvrAvatar.SUPPORTED)
727+
{
728+
VIUSettings.EnableOculusSDKControllerRenderModel = EditorGUILayout.ToggleLeft(new GUIContent(enableControllerRenderModelTitle, VIUSettings.ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_TOOLTIP), VIUSettings.EnableOculusSDKControllerRenderModel);
729+
730+
if (VIUSettings.EnableOculusSDKControllerRenderModel)
731+
{
732+
VIUSettings.EnableOculusSDKControllerRenderModelSkeleton = EditorGUILayout.ToggleLeft(new GUIContent(enableControllerRenderModelSkeletonTitle, VIUSettings.ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_TOOLTIP), VIUSettings.EnableOculusSDKControllerRenderModelSkeleton);
733+
}
734+
else
735+
{
736+
var wasGUIEnabled = GUI.enabled;
737+
GUI.enabled = false;
738+
EditorGUILayout.ToggleLeft(new GUIContent(enableControllerRenderModelSkeletonTitle, VIUSettings.ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_TOOLTIP), false);
739+
GUI.enabled = wasGUIEnabled;
740+
}
741+
}
742+
else
743+
{
744+
745+
}
710746

711747
// Custom Android manifest
712748
EditorGUILayout.BeginHorizontal();

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/VIUSettingsPartials/OculusSettings.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@ namespace HTC.UnityPlugin.Vive
66
{
77
public partial class VIUSettings : ScriptableObject
88
{
9+
public const string ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_TOOLTIP = "Use render model proivded by Oculus runtime. If disabled, use VIU fallback default model instead";
10+
public const string ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_TOOLTIP = "Use render model proivded by Oculus runtime. If disabled, use VIU fallback default model instead";
11+
public const string ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_TOOLTIP = "Enable hand model attached to controller render model";
12+
913
public const bool ACTIVATE_OCULUS_VR_MODULE_DEFAULT_VALUE = true;
14+
public const bool ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_DEFAULT_VALUE = true;
15+
public const bool ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_DEFAULT_VALUE = true;
16+
public const bool ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_DEFAULT_VALUE = false;
1017

1118
[SerializeField]
1219
private bool m_activateOculusVRModule = ACTIVATE_OCULUS_VR_MODULE_DEFAULT_VALUE;
1320
[SerializeField]
1421
private string m_oculusVRAndroidManifestPath = string.Empty;
22+
[SerializeField, Tooltip(ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_TOOLTIP)]
23+
private bool m_enableOculusSDKHandRenderModel = ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_DEFAULT_VALUE;
24+
[SerializeField, Tooltip(ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_TOOLTIP)]
25+
private bool m_enableOculusSDKControllerRenderModel = ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_DEFAULT_VALUE;
26+
[SerializeField, Tooltip(ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_TOOLTIP)]
27+
private bool m_enableOculusSDKControllerRenderModelSkeleton = ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_DEFAULT_VALUE;
1528

1629
public static bool activateOculusVRModule { get { return Instance == null ? ACTIVATE_OCULUS_VR_MODULE_DEFAULT_VALUE : s_instance.m_activateOculusVRModule; } set { if (Instance != null) { Instance.m_activateOculusVRModule = value; } } }
1730
public static string oculusVRAndroidManifestPath { get { return Instance == null ? "" : s_instance.m_oculusVRAndroidManifestPath; } set { if (Instance != null) { Instance.m_oculusVRAndroidManifestPath = value; } } }
31+
public static bool EnableOculusSDKHandRenderModel { get { return Instance == null ? ENABLE_OCULUS_SDK_HAND_RENDER_MODEL_DEFAULT_VALUE : s_instance.m_enableOculusSDKHandRenderModel; } set { if (Instance != null) { Instance.m_enableOculusSDKHandRenderModel = value; } } }
32+
public static bool EnableOculusSDKControllerRenderModel { get { return Instance == null ? ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_DEFAULT_VALUE : s_instance.m_enableOculusSDKControllerRenderModel; } set { if (Instance != null) { Instance.m_enableOculusSDKControllerRenderModel = value; } } }
33+
public static bool EnableOculusSDKControllerRenderModelSkeleton { get { return Instance == null ? ENABLE_OCULUS_SDK_CONTROLLER_RENDER_MODEL_SKELETON_DEFAULT_VALUE : s_instance.m_enableOculusSDKControllerRenderModelSkeleton; } set { if (Instance != null) { Instance.m_enableOculusSDKControllerRenderModelSkeleton = value; } } }
1834
}
1935
}

0 commit comments

Comments
 (0)