Skip to content

Commit de006bd

Browse files
ChengNan Yanglawwong
authored andcommitted
Add Wave XRSDK Essence render model
1 parent d9f037d commit de006bd

File tree

3 files changed

+98
-7
lines changed

3 files changed

+98
-7
lines changed

Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public WaveVRSymbolRequirementCollection()
2525
reqFileNames = new string[] { "WaveVR.cs" },
2626
});
2727

28+
Add(new VRModuleManagerEditor.SymbolRequirement()
29+
{
30+
symbol = "VIU_WAVEXR_ESSENCE_RENDERMODEL",
31+
reqTypeNames = new string[] { "Wave.Essence.Controller.RenderModel", "Wave.Essence.Controller.ButtonEffect", "Wave.Essence.Controller.ShowIndicator" },
32+
reqFileNames = new string[] { "RenderModel.cs", "ButtonEffect.cs", "ShowIndicator.cs" },
33+
});
34+
2835
Add(new SymbolRequirement()
2936
{
3037
symbol = "VIU_WAVEVR_2_0_32_OR_NEWER",

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

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
22

3+
using HTC.UnityPlugin.Utility;
34
using HTC.UnityPlugin.Vive;
45
using System.Collections.Generic;
56
using System.Text.RegularExpressions;
@@ -12,6 +13,9 @@
1213
using UnityEngine.XR.Management;
1314
using UnityEngine.SpatialTracking;
1415
using System;
16+
#if VIU_WAVEXR_ESSENCE_RENDERMODEL
17+
using Wave.Essence;
18+
#endif
1519
#endif
1620

1721
namespace HTC.UnityPlugin.VRModuleManagement
@@ -31,6 +35,9 @@ public sealed class UnityXRModule : VRModule.ModuleBase
3135

3236
public override int moduleIndex { get { return (int)VRModuleSelectEnum.UnityXR; } }
3337

38+
public const string WAVE_XR_LOADER_NAME = "Wave XR Loader";
39+
public const string WAVE_XR_LOADER_CLASS_NAME = "WaveXRLoader";
40+
3441
#if UNITY_2019_3_OR_NEWER && VIU_XR_GENERAL_SETTINGS
3542
private class CameraCreator : VRCameraHook.CameraCreator
3643
{
@@ -45,6 +52,69 @@ public override void CreateCamera(VRCameraHook hook)
4552
}
4653
}
4754

55+
[RenderModelHook.CreatorPriorityAttirbute(0)]
56+
private class RenderModelCreator : RenderModelHook.DefaultRenderModelCreator
57+
{
58+
private uint m_index = INVALID_DEVICE_INDEX;
59+
60+
public override bool shouldActive { get { return s_moduleInstance == null ? false : s_moduleInstance.isActivated; } }
61+
62+
public override void UpdateRenderModel()
63+
{
64+
#if VIU_WAVEXR_ESSENCE_RENDERMODEL
65+
if (HasActiveLoader(WAVE_XR_LOADER_NAME))
66+
{
67+
if (!ChangeProp.Set(ref m_index, hook.GetModelDeviceIndex())) { return; }
68+
if (VRModule.IsValidDeviceIndex(m_index) && m_index == VRModule.GetRightControllerDeviceIndex())
69+
{
70+
var go = new GameObject("Model");
71+
go.transform.SetParent(hook.transform, false);
72+
go.AddComponent<Wave.Essence.Controller.RenderModel>();
73+
go.AddComponent<Wave.Essence.Controller.ButtonEffect>();
74+
go.AddComponent<Wave.Essence.Controller.ShowIndicator>();
75+
}
76+
else if (VRModule.IsValidDeviceIndex(m_index) && m_index == VRModule.GetLeftControllerDeviceIndex())
77+
{
78+
var go = new GameObject("Model");
79+
go.transform.SetParent(hook.transform, false);
80+
var rm = go.AddComponent<Wave.Essence.Controller.RenderModel>();
81+
rm.transform.gameObject.SetActive(false);
82+
rm.WhichHand = XR_Hand.NonDominant;
83+
rm.transform.gameObject.SetActive(true);
84+
var be = go.AddComponent<Wave.Essence.Controller.ButtonEffect>();
85+
be.transform.gameObject.SetActive(false);
86+
be.HandType = XR_Hand.NonDominant;
87+
be.transform.gameObject.SetActive(true);
88+
go.AddComponent<Wave.Essence.Controller.ShowIndicator>();
89+
}
90+
else
91+
{
92+
// deacitvate object for render model
93+
if (m_model != null)
94+
{
95+
m_model.gameObject.SetActive(false);
96+
}
97+
}
98+
}
99+
else
100+
{
101+
base.UpdateRenderModel();
102+
}
103+
#else
104+
base.UpdateRenderModel();
105+
#endif
106+
}
107+
108+
public override void CleanUpRenderModel()
109+
{
110+
if (m_model != null)
111+
{
112+
UnityEngine.Object.Destroy(m_model);
113+
m_model = null;
114+
}
115+
}
116+
}
117+
48118
private class HapticVibrationState
49119
{
50120
public uint deviceIndex;
@@ -188,6 +258,15 @@ public override void BeforeRenderUpdate()
188258

189259
SetupKnownDeviceModel(currState);
190260

261+
if ((device.characteristics & InputDeviceCharacteristics.Left) > 0u)
262+
{
263+
m_leftHandedDeviceIndex = deviceIndex;
264+
}
265+
else if ((device.characteristics & InputDeviceCharacteristics.Right) > 0u)
266+
{
267+
m_rightHandedDeviceIndex = deviceIndex;
268+
}
269+
191270
Debug.LogFormat("Device connected: {0} / {1} / {2} / {3} / {4} / {5} ({6})", deviceIndex, currState.deviceClass, currState.deviceModel, currState.modelNumber, currState.serialNumber, device.name, device.characteristics);
192271
}
193272

@@ -203,13 +282,20 @@ public override void BeforeRenderUpdate()
203282
}
204283
}
205284

206-
UpdateHandHeldDeviceIndex();
285+
//UpdateHandHeldDeviceIndex();
207286

208287
deviceIndex = 0u;
209288
// reset all devices that is not connected in this frame
210-
while (TryGetValidDeviceState(deviceIndex++, out prevState, out currState))
289+
while (TryGetValidDeviceState(deviceIndex, out prevState, out currState))
211290
{
212-
if (!currState.isConnected) { currState.Reset(); }
291+
if (!currState.isConnected)
292+
{
293+
currState.Reset();
294+
if (deviceIndex == m_leftHandedDeviceIndex) { m_leftHandedDeviceIndex = VRModule.INVALID_DEVICE_INDEX; }
295+
else if (deviceIndex == m_rightHandedDeviceIndex) { m_rightHandedDeviceIndex = VRModule.INVALID_DEVICE_INDEX; }
296+
}
297+
298+
++deviceIndex;
213299
}
214300

215301
ProcessConnectedDeviceChanged();

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public static partial class VIUSettingsEditor
6464
public const string URL_WAVE_VR_PLUGIN = "https://developer.vive.com/resources/knowledgebase/wave-sdk/";
6565
public const string URL_WAVE_VR_6DOF_SUMULATOR_USAGE_PAGE = "https://github.com/ViveSoftware/ViveInputUtility-Unity/wiki/Wave-VR-6-DoF-Controller-Simulator";
6666
private const string WAVE_XR_PACKAGE_NAME = "com.htc.upm.wave.xrsdk";
67-
private const string WAVE_XR_LOADER_NAME = "Wave XR Loader";
68-
private const string WAVE_XR_LOADER_CLASS_NAME = "WaveXRLoader";
6967

7068
public static bool canSupportWaveVR
7169
{
@@ -136,7 +134,7 @@ public override bool support
136134
if (!VIUSettings.activateWaveVRModule) { return false; }
137135

138136
#if VIU_XR_GENERAL_SETTINGS
139-
if (!(MockHMDSDK.enabled || XRPluginManagementUtils.IsXRLoaderEnabled(WAVE_XR_LOADER_NAME, requirdPlatform)))
137+
if (!(MockHMDSDK.enabled || XRPluginManagementUtils.IsXRLoaderEnabled(UnityXRModule.WAVE_XR_LOADER_NAME, requirdPlatform)))
140138
{
141139
return false;
142140
}
@@ -172,7 +170,7 @@ public override bool support
172170
}
173171

174172
#if UNITY_2019_3_OR_NEWER && VIU_XR_GENERAL_SETTINGS
175-
XRPluginManagementUtils.SetXRLoaderEnabled(WAVE_XR_LOADER_CLASS_NAME, requirdPlatform, value);
173+
XRPluginManagementUtils.SetXRLoaderEnabled(UnityXRModule.WAVE_XR_LOADER_CLASS_NAME, requirdPlatform, value);
176174
MockHMDSDK.enabled = value && !PackageManagerHelper.IsPackageInList(WAVE_XR_PACKAGE_NAME);
177175
VIUSettings.activateUnityXRModule = XRPluginManagementUtils.IsAnyXRLoaderEnabled(requirdPlatform);
178176
#elif VIU_WAVEVR_3_0_0_OR_NEWER

0 commit comments

Comments
 (0)