Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding touchscreen input source #1456

Merged
merged 12 commits into from
Jan 8, 2018

Conversation

PJBowron
Copy link

@PJBowron PJBowron commented Nov 29, 2017

Overview

Adding basic support for touchscreen devices with the addition of a new TouchscreenInputSource class. Includes an Example scene demonstrating functionality via pre-existing scripts.

…chscreen functionality, implementing BaseInputSource
…utSource

This test scene leverages existing scripts (particularly TapResponder
and InputTest) to demonstrate response to events raised from
touchscreen interactions.
/// </summary>
public class TouchscreenInputSource : BaseInputSource
{
const float kContactEpsilon = 2.0f/60.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use 1/30?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Coming from several years of VR and now AR dev, my mind tends to get stuck in 60fps mode ;)

[Tooltip("Time in seconds to determine if the contact registers as a tap or a hold")]
protected float MaxTapContactTime = 0.5f;

private List<PersistentTouch> ActiveTouches;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could initialize this field in line and remove the start method all together.

private List<PersistentTouch> ActiveTouches = new List<PersistentTouch>(0);

foreach (Touch touch in Input.touches)
{
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(touch.position);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CameraCache.Main


#region Event generation logic

public bool UpdateTouch(Touch t, Ray r)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update parameter names to touch and ray


public bool UpdateTouch(Touch t, Ray r)
{
PersistentTouch knownTouch = (ActiveTouches.Find(item => item.touchData.fingerId == t.fingerId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets optimize this by removing the delegate allocation and just iterating through a for loop

if (knownTouch != null)
return knownTouch.touchData;
else
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; missing braces

public Touch touchData;
public Ray ray;
public float lifetime;
public PersistentTouch(Touch t, Ray r)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: update names to touch and ray

using Windows.Media.Capture;
#endif

namespace HoloToolkit.Unity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this class included in your PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the target branch for this PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I only meant to include my two commits (the inputSource script, followed by the example scene). Indeed, I can only see my four files included my view of the PR..?

Copy link
Contributor

@StephenHodgson StephenHodgson Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to update the PR. I've already fixed this.

@StephenHodgson StephenHodgson changed the base branch from master to Dev_Working_Branch November 29, 2017 16:44
Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid overall, just a few comments.

Also, could you please add this component to the InputManager.prefab and update it as well?
Adding a new GameObject under the InputManager named TouchInputControl should be sufficient.

@PJBowron
Copy link
Author

Many thanks for the quick feedback - happy to update all the above shortly.
Out of curiosity, what's the thinking behind changing the foreach's to for's? Just an optimization? I didn't think the list would mutate within the loop's lifetime?

@StephenHodgson
Copy link
Contributor

That's actually a good point. That Touch class is updated and handled by Unity, correct?

Do we know when that data is updated?

replaced list init in Start() with member-level definition and removed Start();
renamed abbreviated params to full names;
renamed PersistentTouch.ray as PersistentTouch.screenpointRay for clarity and to avoid a this.ray in the constructor
…r request;

Updating example scene, which no longer needs its own explicit instance
@PJBowron
Copy link
Author

PJBowron commented Nov 30, 2017

Touch does belong to Unity yes, but I haven't been able to find any information specific to input updates. But given that most of Unity operates on a single-threaded model I wouldn't imagine that input might be running concurrently with GameObject.Update...

I've now pushed most of the requested changes; I've held off on the change to the foreach-loop though as I thought you night be wavering on your original thought - just let me know if there's another reason to make the change :)

Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great on paper! I'll be pulling this today to take a actual look.

While we're here and changing the input manager prefab, could you also rename the RaycastCamera GameObject under the event system to UIRaycastCamera? It'll fix #1444

@PJBowron
Copy link
Author

Done. Cheers!

StephenHodgson
StephenHodgson previously approved these changes Nov 30, 2017
Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Thanks for the contribution!

@keveleigh
Copy link
Contributor

@timGerken I'd like to get a review from you after your touchscreen work in Microsoft/GalaxyExplorer.

@timGerken
Copy link
Contributor

timGerken commented Dec 1, 2017

@keveleigh , looks reasonable to me. GE does touch somewhat differently (It hooks gestures and events on the DXSwapChainPanel) and the forwards them onto GE's input router (from a way-way-way-back implementation of HTK). GE, in this regard, could use some love to bring it up to a more current HTK/MRTK implementation and move away from its reliance on starting as a XAML app to get at these events (and the app toolbar)...

@StephenHodgson
Copy link
Contributor

I hope that GE isn't going to delay this PR

@timGerken
Copy link
Contributor

I can't imagine why you think it might.

@StephenHodgson
Copy link
Contributor

@NeerajW why remove label?

…edRealityToolkit-Unity into Dev_Working_Branch

# Conflicts:
#	Assets/HoloToolkit/Input/Prefabs/InputManager.prefab
#
# Resolved using 'Theirs'
@PJBowron
Copy link
Author

Hi all - I saw a conflict had arisen on InputManager.prefab, so I just refreshed my fork and reapplied the changes made previously.

@NeerajW Was there anything in particular that was keeping this PR in limbo?

@@ -4,4 +4,7 @@
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this file

@@ -28,11 +28,11 @@ SpriteAtlas:
enableTightPacking: 0
packedHash:
serializedVersion: 2
Hash: b579d9a28ce9cc7d8109d453a20bac11
Hash: b7a1c327cf35f1b63159875306d23016
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this file

Copy link
Contributor

@StephenHodgson StephenHodgson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@PJBowron
Copy link
Author

facepalm
Done.

StephenHodgson
StephenHodgson previously approved these changes Dec 17, 2017
- component: {fileID: 4277215840702346}
- component: {fileID: 114080562701649166}
m_Layer: 0
m_Name: TouchInputControl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we want by default on the InputManager prefab?

Does it / can it remove itself when run on devices without a touch screen?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @keveleigh - this was requested/added on Nov 29 (see earlier in this thread). I hadn't initially intended it to be present by default but other contributions have added other device handlers such as mouse and xbox controller, though to be fair I think they're event based rather than polling.
Happy to add a check for touchSupported at Start() and self-disable, if that would satisfy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh interesting, I must have missed that!

Yeah, a check for touchSupported would be perfect, in my opinion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case, should we also add TouchSupported in our SupportedInputInfo enum?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SupportedInputInfo tells you the features of an input source that you can ask it about. From my understanding of this feature, there aren't any touch-specific features to query, as all events are routed through existing ones.

I see this like the Xbox controller script which routes tap/hold/navigation events through the system, where we didn't add "Xbox controller" to that enum.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Maybe we should have?

Copy link
Contributor

@keveleigh keveleigh Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so.

I see "Xbox controller" and "touch screen" in the same category as "motion controller", which are input source types.

I see the SupportedInputInfo enum telling you about features you can query on the source itself, like the state of the menu button or the position of the input. As-is, this new source doesn't add any new features that a source can have, but it does add a new type of source that can be used.

The way I feel the Toolkit's InputManager is made is that it should be input source type agnostic. You can definitely reason about the source type based on the supported features, but you don't necessarily care where the events are coming from.

@StephenHodgson
Copy link
Contributor

@keveleigh what's holding this up? Our question about if it should be on the input manager prefab?

@keveleigh
Copy link
Contributor

@StephenHodgson I'm fine with it staying on the prefab, but this seems like something that should remove/disable itself on non-touchscreen devices, so it isn't running unnecessarily.

@StephenHodgson
Copy link
Contributor

so it isn't running unnecessarily.

If we follow that logic, then shouldn't we make the same changes to the rest of the input sources?

@keveleigh
Copy link
Contributor

If we follow that logic, then shouldn't we make the same changes to the rest of the input sources?

Maybe! I think it's a fine line to walk though, since this toolkit has been created specifically for Mixed Reality development. We don't want to hinder other platforms (via the #ifs, etc), but we also aren't explicitly writing for them. Which sources should be turned off and on which devices?

@StephenHodgson
Copy link
Contributor

Xbox controller for example

@PJBowron
Copy link
Author

PJBowron commented Jan 8, 2018

Apologies for the silence; I was checking in infrequently over the vacation but am back at the office now. I'll commit the discussed change - to self-deactivate if unsupported - asap, which should finish off the PR? Updating the other sources could perhaps be discussed in a later issue?

@StephenHodgson
Copy link
Contributor

Was reading yesterday and thought we should just keep this in mind. No changes requested at this time.

Unity Touch Input events differ for each platform controller:

The Event System generates Input Touch events for the triggers on HTC Vive controllers when the user begins squeezing the trigger.
The Event System generates Input Touch events for the triggers on Oculus Touch and Valve Knuckles controllers when Unity Input detects a touch - no trigger squeeze is necessary.

@keveleigh keveleigh merged commit 0baf092 into microsoft:Dev_Working_Branch Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants