Skip to content

Commit

Permalink
Update to v1.13.4
Browse files Browse the repository at this point in the history
* Changes
  - Add static API to retrieve pinch ray from Wave SDK
    - WaveHandTrackingSubmodule.TryGetLeftPinchRay(out Vector3 origin, out Vector3 direction)
    - WaveHandTrackingSubmodule.TryGetLeftPinchRay(out Vector3 origin, out Vector3 direction)
    - Returns true if the pinch ray is currently valid, that is having valid tracking and the app got input focus
  - Add 4 fingers curl & grip button values for Wave tracked hand device
  - Change GestureIndexPinch button active threshold from 0.95 to 0.5 for Wave tracked hand device

* Package Changes
  - Now support Unity 2018.4 or newer due to the Asset Store publish restriction
    - https://assetstore.unity.com/publishing/release-updates#accepted-unity-versions-TjfK
  - Remove asmdef files from package archive
  • Loading branch information
lawwong committed Aug 30, 2021
2 parents 985df5b + a9b9591 commit 525544a
Show file tree
Hide file tree
Showing 7 changed files with 936 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public override void Update()
}
}

submodules.UpdateAllModulesActivity();
submodules.UpdateModulesDeviceInput();

UpdateHapticVibration();
Expand Down
16 changes: 10 additions & 6 deletions Assets/HTC.UnityPlugin/VRModule/Modules/WaveVRModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ public override void UpdateRenderModel()
m_modelObj.SetActive(false);
#if VIU_WAVEXR_ESSENCE_CONTROLLER_MODEL
#if VIU_WAVE_XRSDK_3_99_31_OR_NEWER
m_modelObj.transform.parent.gameObject.AddComponent<PoseMode>();
m_modelObj.AddComponent<PoseMode>();
#endif
m_modelObj.AddComponent<Wave.Essence.Controller.Model.RenderModel>();
m_modelObj.AddComponent<Wave.Essence.Controller.Model.ButtonEffect>();
GameObject controllerObj = new GameObject("Controller");
controllerObj.transform.SetParent(m_modelObj.transform, false);
controllerObj.AddComponent<Wave.Essence.Controller.Model.RenderModel>();
controllerObj.AddComponent<Wave.Essence.Controller.Model.ButtonEffect>();
#elif VIU_WAVEXR_ESSENCE_RENDERMODEL
m_modelObj.AddComponent<Wave.Essence.Controller.RenderModel>();
m_modelObj.AddComponent<Wave.Essence.Controller.ButtonEffect>();
Expand Down Expand Up @@ -123,12 +125,14 @@ public override void UpdateRenderModel()
m_modelObj.SetActive(false);
#if VIU_WAVEXR_ESSENCE_CONTROLLER_MODEL
#if VIU_WAVE_XRSDK_3_99_31_OR_NEWER
var pm = m_modelObj.transform.parent.gameObject.AddComponent<PoseMode>();
var pm = m_modelObj.AddComponent<PoseMode>();
pm.WhichHand = XR_Hand.NonDominant;
#endif
var rm = m_modelObj.AddComponent<Wave.Essence.Controller.Model.RenderModel>();
GameObject controllerObj = new GameObject("Controller");
controllerObj.transform.SetParent(m_modelObj.transform, false);
var rm = controllerObj.AddComponent<Wave.Essence.Controller.Model.RenderModel>();
rm.WhichHand = XR_Hand.NonDominant;
var be = m_modelObj.AddComponent<Wave.Essence.Controller.Model.ButtonEffect>();
var be = controllerObj.AddComponent<Wave.Essence.Controller.Model.ButtonEffect>();
be.HandType = XR_Hand.NonDominant;
#elif VIU_WAVEXR_ESSENCE_RENDERMODEL
var rm = m_modelObj.AddComponent<Wave.Essence.Controller.RenderModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Fetch()
}

private DeviceFeature deviceFeature;
private TrackingActivator trackingActivator = TrackingActivator.Default;
private static TrackingActivator trackingActivator = TrackingActivator.Default;
private GestureActivator gestureActivator = GestureActivator.Default;
private uint leftDeviceIndex = VRModule.INVALID_DEVICE_INDEX;
private uint rightDeviceIndex = VRModule.INVALID_DEVICE_INDEX;
Expand Down Expand Up @@ -186,6 +186,40 @@ protected override void OnUpdateDeviceInput()

public override uint GetRightHandedIndex() { return rightDeviceIndex; }

public static bool TryGetLeftPinchRay(out Vector3 origin, out Vector3 direction)
{
if (!trackingActivator.isLeftValid)
{
origin = Vector3.zero;
direction = Vector3.zero;

return false;
}

var pinch = trackingActivator.getLeftPinchData;
Coordinate.GetVectorFromGL(pinch.pinch.origin, out origin);
Coordinate.GetVectorFromGL(pinch.pinch.direction, out direction);

return true;
}

public static bool TryGetRightPinchRay(out Vector3 origin, out Vector3 direction)
{
if (!trackingActivator.isRightValid)
{
origin = Vector3.zero;
direction = Vector3.zero;

return false;
}

var pinch = trackingActivator.getRightPinchData;
Coordinate.GetVectorFromGL(pinch.pinch.origin, out origin);
Coordinate.GetVectorFromGL(pinch.pinch.direction, out direction);

return true;
}

private enum FeatureActivity
{
Stopped,
Expand Down Expand Up @@ -458,9 +492,13 @@ public bool TryFetchData(WVR_PoseOriginModel originModel)
return false;
}

public bool isLeftValid { get { return trackingData.left.isValidPose; } }
public bool isLeftValid { get { return trackingData.left.isValidPose && !Interop.WVR_IsInputFocusCapturedBySystem(); } }

public bool isRightValid { get { return trackingData.right.isValidPose && !Interop.WVR_IsInputFocusCapturedBySystem(); } }

public bool isRightValid { get { return trackingData.right.isValidPose; } }
public WVR_HandPoseState_t getLeftPinchData { get { return pinchData.left; } }

public WVR_HandPoseState_t getRightPinchData { get { return pinchData.right; } }

public void UpdateJoints(IVRModuleDeviceStateRW state, bool isLeft)
{
Expand All @@ -475,18 +513,41 @@ public void UpdateJoints(IVRModuleDeviceStateRW state, bool isLeft)
state.handJoints[handJointMapping[s_NaturalHandJoints[i]]] = new JointPose(p);
}

state.isPoseValid = data.isValidPose;
state.isPoseValid = data.isValidPose && !Interop.WVR_IsInputFocusCapturedBySystem();
state.pose = state.handJoints[HandJointName.Wrist].pose;
}

public void UpdateDeviceInput(IVRModuleDeviceStateRW state, bool isLeft)
{
var pinch = isLeft ? pinchData.left : pinchData.right;
var pinched = pinch.pinch.strength >= 0.95f;
var pinched = pinch.pinch.strength >= 0.5f;

state.SetButtonPress(VRModuleRawButton.GestureIndexPinch, pinched);
state.SetButtonTouch(VRModuleRawButton.GestureIndexPinch, pinched);
state.SetAxisValue(VRModuleRawAxis.Trigger, pinch.pinch.strength);

var indexCurl = GetFingerCurl(state, HandJointName.IndexTip);
var middleCurl = GetFingerCurl(state, HandJointName.MiddleTip);
var ringCurl = GetFingerCurl(state, HandJointName.RingTip);
var pinkyCurl = GetFingerCurl(state, HandJointName.PinkyTip);
var curlAvg = (indexCurl + middleCurl + ringCurl + pinkyCurl) * 0.25f;

state.SetAxisValue(VRModuleRawAxis.IndexCurl, indexCurl);
state.SetAxisValue(VRModuleRawAxis.MiddleCurl, middleCurl);
state.SetAxisValue(VRModuleRawAxis.RingCurl, ringCurl);
state.SetAxisValue(VRModuleRawAxis.PinkyCurl, pinkyCurl);
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, curlAvg);
state.SetButtonPress(VRModuleRawButton.Grip, curlAvg > 0.75f);
state.SetButtonTouch(VRModuleRawButton.Grip, curlAvg > 0.50f);
}

private float GetFingerCurl(IVRModuleDeviceStateRW state, HandJointName finger)
{
var palmDir = state.pose.forward;
var fingerDir = state.handJoints[finger].pose.forward;
var angle = Vector3.SignedAngle(palmDir, fingerDir, state.pose.right);
if (angle < -90f) { angle += 360f; }
return Mathf.InverseLerp(0f, 180f, angle);
}

private static void InitializeHandTrackerInfo(ref WVR_HandTrackerInfo_t handTrackerInfo, ref WVR_HandJoint[] jointMappingArray, ref ulong[] jointValidFlagArray, uint count)
Expand Down
Loading

0 comments on commit 525544a

Please sign in to comment.