-
Notifications
You must be signed in to change notification settings - Fork 153
Add support for XR_MSFT_hand_tracking_mesh and XR_ANDROID_hand_mesh #993
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
Open
keveleigh
wants to merge
57
commits into
MixedRealityToolkit:feature/XRI3
Choose a base branch
from
keveleigh:platform-hand-mesh
base: feature/XRI3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
84559da
Initial drop
keveleigh dc73b17
Iterate
keveleigh 6d24fce
Add UNITY_OPENXR_PRESENT
keveleigh 87a1d63
Update PlatformHandMeshVisualizer.cs
keveleigh 03f0be4
Update PlatformHandMeshVisualizer.cs
keveleigh 897166e
Docs update
keveleigh d89611f
Move prefabs into own folder
keveleigh 0808077
Update PlatformHandMeshVisualizer.cs
keveleigh 6dc0453
Remove temp hand mesh prefabs
keveleigh a25bc69
Add hand mesh manager
keveleigh dc55b70
Iterate
keveleigh fa4b587
Iterate
keveleigh a92a988
Update PlatformHandMeshVisualizer.cs
keveleigh ce502e6
Add AXR hand mesh support
keveleigh ec17f14
Update PlatformHandMeshVisualizer.cs
keveleigh b9532ea
Update PlatformHandMeshVisualizer.cs
keveleigh c01d528
Update PlatformHandMeshVisualizer.cs
keveleigh ebfc839
Ensure the bounds are recalculated
keveleigh 2b434f4
Ensure we transform from the playspace pose
keveleigh 613d5de
Update CHANGELOG.md
keveleigh 7a5c10c
Update PlatformHandMeshVisualizer.cs
keveleigh cd1acdf
Update PlatformHandMeshVisualizer.cs
keveleigh 273acc0
Update shader to use wrist position for fade, if given
keveleigh f315ec5
Iterate back to sphere
keveleigh 84da078
Iterate shaders again
keveleigh e150ec2
Iterate shaders again
keveleigh 3aabc17
Update to include outline
keveleigh 7fe0768
Update material defaults
keveleigh f6143ce
Iterate to using Unity's API instead of Google's
keveleigh 3cf9822
Update AndroidXRConfig.cs
keveleigh 89f9927
Update HandMeshVisualizer.cs
keveleigh 0d8d887
Don't update more than once per frame
keveleigh 2fc4c85
Update PlatformHandMeshVisualizer.cs
keveleigh e71e401
Revert "Iterate to using Unity's API instead of Google's"
keveleigh d58a290
Update PlatformHandMeshVisualizer.cs
keveleigh c02bc03
Use input action references for tracked state
keveleigh 6f20105
Only query the fallback if needed and we're focused
keveleigh 196d6b9
Reapply "Iterate to using Unity's API instead of Google's"
keveleigh eb9e91a
Update Hands version
keveleigh 06eb426
Some optimizations and improvements
keveleigh dcc70f3
Another iteration
keveleigh 2362244
Revert "Reapply "Iterate to using Unity's API instead of Google's""
keveleigh 929fbc9
Mark the hand mesh as dynamic
keveleigh c397c5b
Lock the Android XR package to 1.0.0 for now
keveleigh 076c2e4
Iterate visualizers
keveleigh d519d3f
Revert "Lock the Android XR package to 1.0.0 for now"
keveleigh d9abc5d
Update PlatformHandMeshVisualizer.cs
keveleigh 1c9d542
Update HandMeshVisualizer.cs
keveleigh cae0890
Reapply "Reapply "Iterate to using Unity's API instead of Google's""
keveleigh 36ec371
Update PlatformHandMeshVisualizer.cs
keveleigh fdb1fab
Update PlatformHandMeshVisualizer.cs
keveleigh e524c9c
Fix stray mesh when untracked
keveleigh 42dadc1
Don't overwrite the actual tracking state
keveleigh 34b5f67
Revert "Fix stray mesh when untracked"
keveleigh beb0157
Move to event handler?
keveleigh 783d446
Move back to polling
keveleigh 0394a2d
Update PlatformHandMeshVisualizer.cs
keveleigh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
org.mixedrealitytoolkit.input/Visualizers/HandMeshVisualizer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| // Copyright (c) Mixed Reality Toolkit Contributors | ||
| // Licensed under the BSD 3-Clause | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.XR; | ||
| using UnityEngine.XR.Interaction.Toolkit; | ||
| using UnityEngine.XR.Interaction.Toolkit.Inputs.Readers; | ||
|
|
||
| namespace MixedReality.Toolkit.Input | ||
| { | ||
| public abstract class HandMeshVisualizer : MonoBehaviour, ISelectInputVisualizer | ||
| { | ||
| [SerializeField] | ||
| [Tooltip("The XRNode on which this hand is located.")] | ||
| private XRNode handNode = XRNode.LeftHand; | ||
|
|
||
| /// <summary> The XRNode on which this hand is located. </summary> | ||
| public XRNode HandNode { get => handNode; set => handNode = value; } | ||
|
|
||
| [SerializeField] | ||
| [Tooltip("When true, this visualizer will render rigged hands even on XR devices " + | ||
| "with transparent displays or with passthrough enabled. When false, the rigged hands will only render " + | ||
| "on devices with opaque displays. This behavior uses XRDisplaySubsystem.displayOpaque.")] | ||
| private bool showHandsOnTransparentDisplays; | ||
|
|
||
| /// <summary> | ||
| /// When true, this visualizer will render rigged hands even on XR devices with transparent displays or with passthrough enabled. | ||
| /// When false, the rigged hands will only render on devices with opaque displays. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This behavior uses <see cref="XRDisplaySubsystem.displayOpaque"/>. | ||
| /// Usually, it's recommended not to show hand visualization on transparent displays as it can | ||
| /// distract from the user's real hands, and cause a "double image" effect that can be disconcerting. | ||
| /// </remarks> | ||
| public bool ShowHandsOnTransparentDisplays | ||
| { | ||
| get => showHandsOnTransparentDisplays; | ||
| set => showHandsOnTransparentDisplays = value; | ||
| } | ||
|
|
||
| [SerializeField] | ||
| [Tooltip("Name of the shader property used to drive pinch-amount-based visual effects. " + | ||
| "Generally, maps to something like a glow or an outline color!")] | ||
| private string pinchAmountMaterialProperty = "_PinchAmount"; | ||
|
|
||
| [SerializeField] | ||
| [Tooltip("The input reader used when pinch selecting an interactable.")] | ||
| private XRInputButtonReader selectInput = new XRInputButtonReader("Select"); | ||
|
|
||
| #region ISelectInputVisualizer implementation | ||
|
|
||
| /// <summary> | ||
| /// Input reader used when pinch selecting an interactable. | ||
| /// </summary> | ||
| public XRInputButtonReader SelectInput | ||
| { | ||
| get => selectInput; | ||
| set => SetInputProperty(ref selectInput, value); | ||
| } | ||
|
|
||
| #endregion ISelectInputVisualizer implementation | ||
|
|
||
| // The property block used to modify the pinch amount property on the material | ||
| private MaterialPropertyBlock propertyBlock = null; | ||
|
|
||
| // Scratch list for checking for the presence of display subsystems. | ||
| private readonly List<XRDisplaySubsystem> displaySubsystems = new List<XRDisplaySubsystem>(); | ||
|
|
||
| // The XRController that is used to determine the pinch strength (i.e., select value!) | ||
| [Obsolete("This field has been deprecated in version 4.0.0 and will be removed in a future version. Use the SelectInput property instead.")] | ||
| private XRBaseController controller; | ||
|
|
||
| /// <summary> | ||
| /// The list of button input readers used by this interactor. This interactor will automatically enable or disable direct actions | ||
| /// if that mode is used during <see cref="OnEnable"/> and <see cref="OnDisable"/>. | ||
| /// </summary> | ||
| /// <seealso cref="XRInputButtonReader.EnableDirectActionIfModeUsed"/> | ||
| /// <seealso cref="XRInputButtonReader.DisableDirectActionIfModeUsed"/> | ||
| private readonly List<XRInputButtonReader> buttonReaders = new List<XRInputButtonReader>(); | ||
|
|
||
| /// <summary> | ||
| /// Whether this visualizer currently has a loaded and visible hand mesh or not. | ||
| /// </summary> | ||
| protected internal bool IsRendering => HandRenderer != null && HandRenderer.enabled; | ||
|
|
||
| /// <summary> | ||
| /// The renderer for this visualizer, to use to visualize the pinch amount. | ||
| /// </summary> | ||
| protected abstract Renderer HandRenderer { get; } | ||
|
|
||
| /// <summary> | ||
| /// A Unity event function that is called when an enabled script instance is being loaded. | ||
| /// </summary> | ||
| protected virtual void Awake() | ||
| { | ||
| propertyBlock = new MaterialPropertyBlock(); | ||
| buttonReaders.Add(selectInput); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A Unity event function that is called when the script component has been enabled. | ||
| /// </summary> | ||
| protected virtual void OnEnable() | ||
| { | ||
| buttonReaders.ForEach(reader => reader?.EnableDirectActionIfModeUsed()); | ||
|
|
||
| // Ensure hand is not visible until we can update position first time. | ||
| HandRenderer.enabled = false; | ||
|
|
||
| Debug.Assert(handNode == XRNode.LeftHand || handNode == XRNode.RightHand, | ||
| $"HandVisualizer has an invalid XRNode ({handNode})!"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A Unity event function that is called when the script component has been disabled. | ||
| /// </summary> | ||
| protected virtual void OnDisable() | ||
| { | ||
| buttonReaders.ForEach(reader => reader?.DisableDirectActionIfModeUsed()); | ||
|
|
||
| // Disable the rigged hand renderer when this component is disabled | ||
| HandRenderer.enabled = false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Helper method for setting an input property. | ||
| /// </summary> | ||
| /// <param name="property">The <see langword="ref"/> to the field.</param> | ||
| /// <param name="value">The new value being set.</param> | ||
| /// <remarks> | ||
| /// If the application is playing, this method will also enable or disable directly embedded input actions | ||
| /// serialized by the input if that mode is used. It will also add or remove the input from the list of button inputs | ||
| /// to automatically manage enabling and disabling direct actions with this behavior. | ||
| /// </remarks> | ||
| /// <seealso cref="buttonReaders"/> | ||
| protected void SetInputProperty(ref XRInputButtonReader property, XRInputButtonReader value) | ||
| { | ||
| if (value == null) | ||
| { | ||
| Debug.LogError("Setting XRInputButtonReader property to null is disallowed and has therefore been ignored."); | ||
| return; | ||
| } | ||
|
|
||
| if (Application.isPlaying && property != null) | ||
| { | ||
| buttonReaders?.Remove(property); | ||
| property.DisableDirectActionIfModeUsed(); | ||
| } | ||
|
|
||
| property = value; | ||
|
|
||
| if (Application.isPlaying) | ||
| { | ||
| buttonReaders?.Add(property); | ||
| if (isActiveAndEnabled) | ||
| { | ||
| property.EnableDirectActionIfModeUsed(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected virtual bool ShouldRenderHand() | ||
| { | ||
| if (displaySubsystems.Count == 0) | ||
| { | ||
| SubsystemManager.GetSubsystems(displaySubsystems); | ||
| } | ||
|
|
||
| // Are we running on an XR display and it happens to be transparent? | ||
| // Probably shouldn't be showing rigged hands! (Users can | ||
| // specify showHandsOnTransparentDisplays if they disagree.) | ||
| if (displaySubsystems.Count > 0 && | ||
| displaySubsystems[0].running && | ||
| !displaySubsystems[0].displayOpaque && | ||
| !showHandsOnTransparentDisplays) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // All checks out! | ||
| return true; | ||
| } | ||
|
|
||
| protected virtual void UpdateHandMaterial() | ||
| { | ||
| if (HandRenderer == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Update the hand material | ||
| float pinchAmount = TryGetSelectionValue(out float selectionValue) ? Mathf.Pow(selectionValue, 2.0f) : 0; | ||
| HandRenderer.GetPropertyBlock(propertyBlock); | ||
MaxPalmer-UH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| propertyBlock.SetFloat(pinchAmountMaterialProperty, pinchAmount); | ||
| HandRenderer.SetPropertyBlock(propertyBlock); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Try to obtain the tracked devices selection value from the provided input reader. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// For backwards compatibility, this method will also attempt to get the selection amount from a | ||
| /// legacy XRI controller if the input reader is not set. | ||
| /// </remarks> | ||
| private bool TryGetSelectionValue(out float value) | ||
| { | ||
| if (selectInput != null && selectInput.TryReadValue(out value)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| bool success = false; | ||
| value = 0.0f; | ||
|
|
||
| #pragma warning disable CS0618 // XRBaseController is obsolete | ||
| if (controller == null) | ||
| { | ||
| controller = GetComponentInParent<XRBaseController>(); | ||
| } | ||
| if (controller != null) | ||
| { | ||
| value = controller.selectInteractionState.value; | ||
| success = true; | ||
| } | ||
| #pragma warning restore CS0618 // XRBaseController is obsolete | ||
|
|
||
| return success; | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
org.mixedrealitytoolkit.input/Visualizers/HandMeshVisualizer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.