Skip to content

Commit

Permalink
Fix detection and model display for stylus
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Oct 2, 2024
1 parent 4b0bcbf commit 391ffcb
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 78 deletions.
25 changes: 17 additions & 8 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ MonoBehaviour:
lensDirtScatterFactor: 0.5
lensDirtIntensity: 0.05
lensDirtTexture: {fileID: 0}
inputIsHDR: 1
inputIsHDR: 0
lowQuality: 1
depthBlending: 0
depthBlendFunction: 0
Expand Down Expand Up @@ -17110,6 +17110,10 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects:
- targetCorrespondingSourceObject: {fileID: 4000013585580318, guid: dedd7823645ca60468aca5f2ff1b9a7f,
type: 3}
insertIndex: -1
addedObject: {fileID: 1814796582}
- targetCorrespondingSourceObject: {fileID: 4000011853176074, guid: dedd7823645ca60468aca5f2ff1b9a7f,
type: 3}
insertIndex: -1
Expand Down Expand Up @@ -30859,6 +30863,12 @@ MeshRenderer:
type: 3}
m_PrefabInstance: {fileID: 2124612094}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1814796582 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1857229286467065778, guid: cb1310f64dd794703964833b63e87d96,
type: 3}
m_PrefabInstance: {fileID: 1971022075}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1815866264
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -33202,7 +33212,7 @@ PrefabInstance:
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_TransformParent: {fileID: 17776369}
m_Modifications:
- target: {fileID: 1077171487981709975, guid: cb1310f64dd794703964833b63e87d96,
type: 3}
Expand Down Expand Up @@ -33232,17 +33242,17 @@ PrefabInstance:
- target: {fileID: 1857229286467065778, guid: cb1310f64dd794703964833b63e87d96,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1857229286467065778, guid: cb1310f64dd794703964833b63e87d96,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1857229286467065778, guid: cb1310f64dd794703964833b63e87d96,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: 1857229286467065778, guid: cb1310f64dd794703964833b63e87d96,
type: 3}
Expand Down Expand Up @@ -33606,7 +33616,7 @@ MonoBehaviour:
lensDirtScatterFactor: 0.5
lensDirtIntensity: 0.05
lensDirtTexture: {fileID: 0}
inputIsHDR: 1
inputIsHDR: 0
lowQuality: 1
depthBlending: 0
depthBlendFunction: 0
Expand Down Expand Up @@ -34509,7 +34519,7 @@ MonoBehaviour:
lensDirtScatterFactor: 0.5
lensDirtIntensity: 0.05
lensDirtTexture: {fileID: 0}
inputIsHDR: 1
inputIsHDR: 0
lowQuality: 1
depthBlending: 0
depthBlendFunction: 0
Expand Down Expand Up @@ -36944,4 +36954,3 @@ SceneRoots:
- {fileID: 1802399861}
- {fileID: 106206546}
- {fileID: 1848773840}
- {fileID: 1971022075}
42 changes: 27 additions & 15 deletions Assets/Scripts/GUI/BrushSettingsTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using UnityEngine;
using UnityEngine.XR;

namespace TiltBrush
{
Expand All @@ -32,6 +34,29 @@ protected override void OnDestroy()
App.Switchboard.ToolChanged -= UpdateSliderToMatchCurrentSize;
}

private void DetectSupportedDevices()
{
// Currently only the Logitech stylus needs this panel
bool needsBrushSizeUI = VrStylusHandler.m_Instance.CurrentState.isActive;

// DoAnimateIn performs a toggle so we have to also check the state
if (needsBrushSizeUI)
{
if (!m_AnimateIn)
{
DoAnimateIn();
UpdateSliderToMatchCurrentSize();
}
}
else
{
if (m_AnimateIn)
{
DoAnimateIn();
}
}
}

private void UpdateSliderToMatchCurrentSize()
{
m_BrushSizeSlider.SetInitialValueAndUpdate(
Expand All @@ -43,21 +68,8 @@ protected override void Start()
{
base.Start();

bool needsBrushSizeUi = false;

#if OCULUS_SUPPORTED
const string suffix = "mx_ink_stylus_logitech";
var leftDeviceName = OVRPlugin.GetCurrentInteractionProfileName(OVRPlugin.Hand.HandLeft);
var rightDeviceName = OVRPlugin.GetCurrentInteractionProfileName(OVRPlugin.Hand.HandRight);
needsBrushSizeUi = leftDeviceName.EndsWith(suffix) || rightDeviceName.EndsWith(suffix);
#endif

if (needsBrushSizeUi)
{
DoAnimateIn();
}

UpdateSliderToMatchCurrentSize();
// Call DetectSupportedDevice every second
InvokeRepeating(nameof(DetectSupportedDevices), 0.0f, 1);
}

protected override void OnToolChanged()
Expand Down
35 changes: 12 additions & 23 deletions Assets/Scripts/Input/UnityXRControllerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class UnityXRControllerInfo : ControllerInfo
private UnityEngine.XR.InputDevice device;
private readonly UnityXRInputAction actionSet = new();

private VrStylusHandler _logitechMxInk;

private Vector2 padAxisPrevious = new Vector2();
private const float kInputScrollScalar = 0.5f;

private bool isBrush = false;

private StylusInputs stylusState => VrStylusHandler.m_Instance.CurrentState;

private string actionMap
{
get => isBrush ? "Brush" : "Wand";
Expand All @@ -53,21 +53,10 @@ private void Init()
{
device = InputDevices.GetDeviceAtXRNode(isBrush ? XRNode.RightHand : XRNode.LeftHand);
SetActionMask();
_logitechMxInk = null;
if (isBrush)
{
actionSet.Brush.Enable();
actionSet.Wand.Disable();

try
{
_logitechMxInk = UnityEngine.Object.FindObjectsOfType<VrStylusHandler>()[0];
}
catch (Exception)
{
_logitechMxInk = null;
}

}
else
{
Expand Down Expand Up @@ -190,9 +179,9 @@ public override float GetScrollYDelta()
public override float GetGripValue()
{
#if OCULUS_SUPPORTED
if (_logitechMxInk && _logitechMxInk.CurrentState.isActive)
if (stylusState.isActive)
{
return _logitechMxInk.CurrentState.cluster_front_value ? 1.0f : 0;
return stylusState.cluster_front_value ? 1.0f : 0;
}
#endif
return FindAction("GripAxis").ReadValue<float>();
Expand All @@ -206,9 +195,9 @@ public override float GetTriggerRatio()
public override float GetTriggerValue()
{
#if OCULUS_SUPPORTED
if (_logitechMxInk && _logitechMxInk.CurrentState.isActive)
if (stylusState.isActive)
{
return Math.Max(_logitechMxInk.CurrentState.tip_value, _logitechMxInk.CurrentState.cluster_middle_value);
return Math.Max(stylusState.tip_value, stylusState.cluster_middle_value);
}
#endif
return FindAction("TriggerAxis").ReadValue<float>();
Expand Down Expand Up @@ -254,22 +243,22 @@ private bool MapVrInput(VrInput input)
return FindAction("PadButton").IsPressed();
case VrInput.Trigger:
#if OCULUS_SUPPORTED
if (_logitechMxInk && _logitechMxInk.CurrentState.isActive)
return _logitechMxInk.CurrentState.cluster_middle_value > 0.2 || _logitechMxInk.CurrentState.tip_value > 0.2;
if (stylusState.isActive)
return stylusState.cluster_middle_value > 0.2 || stylusState.tip_value > 0.2;
#endif
return FindAction("TriggerAxis").IsPressed();
case VrInput.Grip:
#if OCULUS_SUPPORTED
if (_logitechMxInk && _logitechMxInk.CurrentState.isActive)
return _logitechMxInk.CurrentState.cluster_front_value;
if (stylusState.isActive)
return stylusState.cluster_front_value;
#endif
return FindAction("GripAxis").IsPressed();
case VrInput.Button01:
case VrInput.Button04:
case VrInput.Button06:
#if OCULUS_SUPPORTED
if (_logitechMxInk && _logitechMxInk.CurrentState.isActive)
return _logitechMxInk.CurrentState.cluster_back_value;
if (stylusState.isActive)
return stylusState.cluster_back_value;
#endif
return FindAction("PrimaryButton").IsPressed();
case VrInput.Button02:
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ public void ShowControllers(bool show)
}
}

public void ShowController(bool show, int index)
{
m_ControllerInfos[index].ShowController(m_ControllerInfos[index].IsTrackedObjectValid && show);
}

void OnDestroy()
{
App.VrSdk.OnNewControllerPosesApplied -= OnControllerPosesApplied;
Expand Down
71 changes: 47 additions & 24 deletions Assets/ThirdParty/Logitech/MX_Ink.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ MonoBehaviour:
_cluster_front: {fileID: 689178473153335378}
_cluster_middle: {fileID: 8881577570454616313}
_cluster_back: {fileID: 4121183609491545851}
_left_touch_controller: {fileID: 0}
_right_touch_controller: {fileID: 0}
active_color: {r: 0.6886792, g: 0.6886792, b: 0.6886792, a: 1}
double_tap_active_color: {r: 0, g: 1, b: 1, a: 1}
default_color: {r: 0.14150941, g: 0.13550194, b: 0.13550194, a: 1}
Expand All @@ -63,55 +61,74 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 1857229286467065778}
m_Modifications:
- target: {fileID: 1324109529956063243, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1324109529956063243, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_Name
value: logitech_vr_stylus_v1.0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
propertyPath: m_LocalPosition.x
- target: {fileID: 1324109529956063243, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.0075
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
value: -0.003
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4379063982285912482, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
- target: {fileID: 4379063982285912482, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: hapticClip
value:
objectReference: {fileID: 2460798210113038985, guid: dde55e13c542f48c186587cca063eac8, type: 3}
- target: {fileID: 4379063982285912482, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
objectReference: {fileID: 2460798210113038985, guid: dde55e13c542f48c186587cca063eac8,
type: 3}
- target: {fileID: 4379063982285912482, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
propertyPath: legacy_mode
value: 0
objectReference: {fileID: 0}
Expand All @@ -122,31 +139,37 @@ PrefabInstance:
m_SourcePrefab: {fileID: 100100000, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
--- !u!1 &689178473153335378 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9031821886481021817, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
m_CorrespondingSourceObject: {fileID: 9031821886481021817, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
m_PrefabInstance: {fileID: 8414709874766261035}
m_PrefabAsset: {fileID: 0}
--- !u!1 &4121183609491545851 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5617797037434992080, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
m_CorrespondingSourceObject: {fileID: 5617797037434992080, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
m_PrefabInstance: {fileID: 8414709874766261035}
m_PrefabAsset: {fileID: 0}
--- !u!1 &4338285541321202723 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5256723013491226376, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
m_CorrespondingSourceObject: {fileID: 5256723013491226376, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
m_PrefabInstance: {fileID: 8414709874766261035}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7396916743439364896 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1324109529956063243, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
m_CorrespondingSourceObject: {fileID: 1324109529956063243, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
m_PrefabInstance: {fileID: 8414709874766261035}
m_PrefabAsset: {fileID: 0}
--- !u!4 &7920969980687411610 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
m_CorrespondingSourceObject: {fileID: 1813822785949909681, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
m_PrefabInstance: {fileID: 8414709874766261035}
m_PrefabAsset: {fileID: 0}
--- !u!1 &8881577570454616313 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1118790130344924114, guid: 90df24c7a15784ca7a0a300d072cba39, type: 3}
m_CorrespondingSourceObject: {fileID: 1118790130344924114, guid: 90df24c7a15784ca7a0a300d072cba39,
type: 3}
m_PrefabInstance: {fileID: 8414709874766261035}
m_PrefabAsset: {fileID: 0}
Loading

0 comments on commit 391ffcb

Please sign in to comment.