8000 Fixed an issue where there was a 3rd untracked controller in the scene. by StephenHodgson · Pull Request #12 · XRTK/com.xrtk.wmr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 13, 2022. It is now read-only.

Fixed an issue where there was a 3rd untracked controller in the scene. #12

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public WindowsMixedRealityDataProvider(string name, uint priority, WindowsMixedR
/// <summary>
/// Cache of the states captured from the Unity InteractionManager for UWP
/// </summary>
InteractionSourceState[] interactionManagerStates = new InteractionSourceState[MaxInteractionSourceStates];
private readonly InteractionSourceState[] interactionManagerStates = new InteractionSourceState[MaxInteractionSourceStates];

/// <summary>
/// The number of states captured most recently
Expand Down Expand Up @@ -295,12 +295,16 @@ public override void Enable()
// NOTE: We update the source state data, in case an app wants to query it on source detected.
for (var i = 0; i < numInteractionManagerStates; i++)
{
var controller = GetController(interactionManagerStates[i].source);
var state = interactionManagerStates[i];

if (state.sourcePose.positionAccuracy == InteractionSourcePositionAccuracy.None) { continue; }

var controller = GetController(state.source, true);

if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
controller.UpdateController(interactionManagerStates[i]);
controller.UpdateController(state);
}
}

Expand All @@ -321,7 +325,22 @@ public override void Update()

for (var i = 0; i < numInteractionManagerStates; i++)
{
GetController(interactionManagerStates[i].source, false)?.UpdateController(interactionManagerStates[i]);
var state = interactionManagerStates[i];
var isTracked = state.sourcePose.positionAccuracy != InteractionSourcePositionAccuracy.None;
var raiseSourceDetected = !activeControllers.ContainsKey(state.source.id);
var controller = GetController(state.source, raiseSourceDetected && isTracked);

if (controller != null && raiseSourceDetected)
{
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
}

controller?.UpdateController(state);

if (!isTracked)
{
RemoveController(state);
}
}

LastInteractionManagerStateReading = interactionManagerStates;
Expand Down Expand Up @@ -376,7 +395,7 @@ protected override void OnDispose(bool finalizing)
/// <param name="interactionSource">Source State provided by the SDK</param>
/// <param name="addController">Should the Source be added as a controller if it isn't found?</param>
/// <returns>New or Existing Controller Input Source</returns>
private WindowsMixedRealityController GetController(InteractionSource interactionSource, bool addController = true)
private WindowsMixedRealityController GetController(InteractionSource interactionSource, bool addController = false)
{
//If a device is already registered with the ID provided, just return it.
if (activeControllers.ContainsKey(interactionSource.id))
Expand All @@ -403,9 +422,9 @@ private WindowsMixedRealityController GetController(InteractionSource interactio
}

var pointers = interactionSource.supportsPointing ? RequestPointers(typeof(WindowsMixedRealityController), controllingHand) : null;
string nameModifier = controllingHand == Handedness.None ? interactionSource.kind.ToString() : controllingHand.ToString();
var nameModifier = controllingHand == Handedness.None ? interactionSource.kind.ToString() : controllingHand.ToString();
var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"Mixed Reality Controller {nameModifier}", pointers);
var detectedController = new WindowsMixedRealityController(TrackingState.NotTracked, controllingHand, inputSource);
var detectedController = new WindowsMixedRealityController(TrackingState.NotApplicable, controllingHand, inputSource);

if (!detectedController.SetupConfiguration(typeof(WindowsMixedRealityController)))
{
Expand All @@ -428,51 +447,49 @@ private WindowsMixedRealityController GetController(InteractionSource interactio
private static async void TryRenderControllerModel(InteractionSource interactionSource, WindowsMixedRealityController controller)
{
#if WINDOWS_UWP
if (UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque)
if (!UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque) { return; }
IRandomAccessStreamWithContentType stream = null;

if (!WindowsApiChecker.UniversalApiContractV5_IsAvailable) { return; }

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, DispatchedHandler);

async void DispatchedHandler()
{
IRandomAccessStreamWithContentType stream = null;
byte[] glbModelData = null;
var sources = SpatialInteractionManager
.GetForCurrentView()
.GetDetectedSourcesAtTimestamp(
PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));

for (var i = 0; i < sources?.Count; i++)
{
if (sources[i].Source.Id.Equals(interactionSource.id))
{
stream = await sources[i].Source.Controller.TryGetRenderableModelAsync();
break;
}
}

if (WindowsApiChecker.UniversalApiContractV5_IsAvailable)
if (stream != null)
{
async void DispatchedHandler()
glbModelData = new byte[stream.Size];

using (var reader = new DataReader(stream))
{
byte[] glbModelData = null;
var sources = SpatialInteractionManager
.GetForCurrentView()
.GetDetectedSourcesAtTimestamp(
PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));

for (var i = 0; i < sources?.Count; i++)
{
if (sources[i].Source.Id.Equals(interactionSource.id))
{
stream = await sources[i].Source.Controller.TryGetRenderableModelAsync();
break;
}
}

if (stream != null)
{
glbModelData = new byte[stream.Size];

using (var reader = new DataReader(stream))
{
await reader.LoadAsync((uint)stream.Size);
reader.ReadBytes(glbModelData);
}

stream.Dispose();
}
else
{
Debug.LogError("Failed to load model data!");
}

await controller.TryRenderControllerModelAsync(typeof(WindowsMixedRealityController), glbModelData, interactionSource.kind == InteractionSourceKind.Hand);
await reader.LoadAsync((uint)stream.Size);
reader.ReadBytes(glbModelData);
}

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, DispatchedHandler);
stream.Dispose();
}
else
{
Debug.LogError("Failed to load model data!");
}

// This really isn't an error, we actually can call TryRenderControllerModelAsync here.
await controller.TryRenderControllerModelAsync(typeof(WindowsMixedRealityController), glbModelData, interactionSource.kind == InteractionSourceKind.Hand);
}
#else
await controller.TryRenderControllerModelAsync(typeof(WindowsMixedRealityController), null, interactionSource.kind == InteractionSourceKind.Hand);
Expand All @@ -485,7 +502,7 @@ async void DispatchedHandler()
/// <param name="interactionSourceState">Source State provided by the SDK to remove</param>
private void RemoveController(InteractionSourceState interactionSourceState)
{
var controller = GetController(interactionSourceState.source, false);
var controller = GetController(interactionSourceState.source);

if (controller != null)
{
Expand All @@ -505,9 +522,13 @@ private void RemoveController(InteractionSourceState interactionSourceState)
/// <param name="args">SDK source detected event arguments</param>
private void InteractionManager_InteractionSourceDetected(InteractionSourceDetectedEventArgs args)
{
bool raiseSourceDetected = !activeControllers.ContainsKey(args.state.source.id);
if (args.state.sourcePose.positionAccuracy == InteractionSourcePositionAccuracy.None)
{
return;
}

var controller = GetController(args.state.source);
var raiseSourceDetected = !activeControllers.ContainsKey(args.state.source.id);
var controller = GetController(args.state.source, true);

if (controller != null && raiseSourceDetected)
{
Expand All @@ -532,7 +553,7 @@ private void InteractionManager_InteractionSourceLost(InteractionSourceLostEvent

private void GestureRecognizer_Tapped(TappedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);

if (controller != null)
{
Expand All @@ -551,7 +572,7 @@ private void GestureRecognizer_Tapped(TappedEventArgs args)

private void GestureRecognizer_HoldStarted(HoldStartedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseGestureStarted(controller, holdAction);
Expand All @@ -560,7 +581,7 @@ private void GestureRecognizer_HoldStarted(HoldStartedEventArgs args)

private void GestureRecognizer_HoldCompleted(HoldCompletedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCompleted(controller, holdAction);
Expand All @@ -569,7 +590,7 @@ private void GestureRecognizer_HoldCompleted(HoldCompletedEventArgs args)

private void GestureRecognizer_HoldCanceled(HoldCanceledEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCanceled(controller, holdAction);
Expand All @@ -578,7 +599,7 @@ private void GestureRecognizer_HoldCanceled(HoldCanceledEventArgs args)

private void GestureRecognizer_ManipulationStarted(ManipulationStartedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureStarted(controller, manipulationAction);
Expand All @@ -587,7 +608,7 @@ private void GestureRecognizer_ManipulationStarted(ManipulationStartedEventArgs

private void GestureRecognizer_ManipulationUpdated(ManipulationUpdatedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureUpdated(controller, manipulationAction, args.cumulativeDelta);
Expand All @@ -596,7 +617,7 @@ private void GestureRecognizer_ManipulationUpdated(ManipulationUpdatedEventArgs

private void GestureRecognizer_ManipulationCompleted(ManipulationCompletedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCompleted(controller, manipulationAction, args.cumulativeDelta);
Expand All @@ -605,7 +626,7 @@ private void GestureRecognizer_ManipulationCompleted(ManipulationCompletedEventA

private void GestureRecognizer_ManipulationCanceled(ManipulationCanceledEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCanceled(controller, manipulationAction);
Expand All @@ -618,7 +639,7 @@ private void GestureRecognizer_ManipulationCanceled(ManipulationCanceledEventArg

private void NavigationGestureRecognizer_NavigationStarted(NavigationStartedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureStarted(controller, navigationAction);
Expand All @@ -627,7 +648,7 @@ private void NavigationGestureRecognizer_NavigationStarted(NavigationStartedEven

private void NavigationGestureRecognizer_NavigationUpdated(NavigationUpdatedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureUpdated(controller, navigationAction, args.normalizedOffset);
Expand All @@ -636,7 +657,7 @@ private void NavigationGestureRecognizer_NavigationUpdated(NavigationUpdatedEven

private void NavigationGestureRecognizer_NavigationCompleted(NavigationCompletedEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCompleted(controller, navigationAction, args.normalizedOffset);
Expand All @@ -645,7 +666,7 @@ private void NavigationGestureRecognizer_NavigationCompleted(NavigationCompleted

private void NavigationGestureRecognizer_NavigationCanceled(NavigationCanceledEventArgs args)
{
var controller = GetController(args.source, false);
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCanceled(controller, navigationAction);
Expand Down
0