Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Changes from XRTK.Core 0.1.17 (#71)
Browse files Browse the repository at this point in the history
* - added some comments to disable.
- null checked the spatial awareness system in case someone doesn't use it in their app

* - restore the previous pointer extent

* remember previous spatial mesh visibility

* Moved all the focus data up a level

* updated IMixedRealityPointer references

* removed null checks for pointer.Result

* Fixed merge change

* cleaned up the manipulation handler class. No logical changes

* Fixed merge issues

* added comments to disable

* rearranged a few end hold member

* updated xrtk.core package to 0.1.17
updated xrtk.sdk package details

* Fixed nudging not moving the manipulated target
  • Loading branch information
StephenHodgson authored Aug 16, 2019
1 parent 8f99d01 commit 2a5ea7c
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 100 deletions.
10 changes: 5 additions & 5 deletions Features/Input/GazeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ public override void OnPreRaycast()

public override void OnPostRaycast()
{
gazeProvider.HitInfo = Result.Details.LastRaycastHit;
gazeProvider.GazeTarget = Result.Details.Object;
gazeProvider.HitInfo = Result.LastRaycastHit;
gazeProvider.GazeTarget = Result.CurrentPointerTarget;

if (Result.Details.Object != null)
if (Result.CurrentPointerTarget != null)
{
gazeProvider.lastHitDistance = (Result.Details.Point - Rays[0].Origin).magnitude;
gazeProvider.lastHitDistance = (Result.EndPoint - Rays[0].Origin).magnitude;
gazeProvider.HitPosition = Rays[0].Origin + (gazeProvider.lastHitDistance * Rays[0].Direction);
gazeProvider.HitNormal = Result.Details.Normal;
gazeProvider.HitNormal = Result.Normal;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Features/Input/Handlers/BaseFocusHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public virtual void OnBeforeFocusChange(FocusEventData eventData)
// add the pointer to the list of focusers.
if (eventData.NewFocusedObject == gameObject)
{
eventData.Pointer.FocusTarget = this;
eventData.Pointer.FocusHandler = this;
activePointers.Add(eventData.Pointer);
}
// If we're the old focused target object,
Expand All @@ -69,7 +69,7 @@ public virtual void OnBeforeFocusChange(FocusEventData eventData)
// clear the FocusTarget field from the Pointer.
if (eventData.NewFocusedObject == null)
{
eventData.Pointer.FocusTarget = null;
eventData.Pointer.FocusHandler = null;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Features/Input/Handlers/DragAndDropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ void IMixedRealityPointerHandler.OnPointerDown(MixedRealityPointerEventData even
currentInputSource = eventData.InputSource;
currentPointer = eventData.Pointer;

Vector3 initialDraggingPosition = MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(currentPointer, out FocusDetails focusDetails)
? focusDetails.Point
Vector3 initialDraggingPosition = MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(currentPointer, out var focusDetails)
? focusDetails.EndPoint
: hostTransform.position;

StartDragging(initialDraggingPosition);
Expand Down
124 changes: 64 additions & 60 deletions Features/Input/Handlers/ManipulationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ public Vector2 NudgeConstraints

#endregion Manipulation Options

#region Properties

/// <summary>
/// The current status of the hold.
/// </summary>
Expand All @@ -285,29 +287,6 @@ public Vector2 NudgeConstraints
/// </remarks>
public bool IsBeingHeld { get; private set; } = false;

/// <summary>
/// The updated extent of the pointer.
/// </summary>
private float updatedExtent;

/// <summary>The updated scale of the model based on controller input.</summary>
private Vector3 updatedScale;

/// <summary>
/// The first input source to start the manipulation phase of this object.
/// </summary>
private IMixedRealityInputSource primaryInputSource = null;

/// <summary>
/// The first pointer to start the manipulation phase of this object.
/// </summary>
private IMixedRealityPointer primaryPointer = null;

/// <summary>
/// The last rotation reading used to calculate if the rotation action is active.
/// </summary>
private Vector2 lastPositionReading = Vector2.zero;

/// <summary>
/// Is the <see cref="primaryInputSource"/> currently pressed?
/// </summary>
Expand All @@ -333,18 +312,29 @@ public Vector2 NudgeConstraints
/// </summary>
public bool IsRotationPossible { get; private set; } = false;

private Vector3 prevScale = Vector3.one;
private Vector3 prevPosition = Vector3.zero;
private Quaternion prevRotation = Quaternion.identity;

private Vector3 grabbedPosition = Vector3.zero;
#endregion Properties

private BoundingBox boundingBox;

private float prevPointerExtent;
private IMixedRealityPointer primaryPointer;

private IMixedRealityInputSource primaryInputSource;

private int prevPhysicsLayer;
private int boundingBoxPrevPhysicsLayer;
private SpatialMeshDisplayOptions prevSpatialMeshDisplay;

private float updatedExtent;
private float prevPointerExtent;

private Vector2 lastPositionReading;

private Vector3 prevScale;
private Vector3 prevPosition;
private Vector3 updatedScale;
private Vector3 grabbedPosition;

private Quaternion prevRotation;

#region Monobehaviour Implementation

Expand All @@ -362,7 +352,7 @@ protected virtual void Update()
{
if (!IsBeingHeld || primaryPointer == null) { return; }

var pointerPosition = primaryPointer.Result.Details.Point;
var pointerPosition = primaryPointer.Result.EndPoint;

if (!IsPressed)
{
Expand All @@ -375,6 +365,7 @@ protected virtual void Update()
{
if (IsNudgePossible)
{
manipulationTarget.position = grabbedPosition + pointerPosition;
primaryPointer.PointerExtent = updatedExtent;
}
else if (IsScalingPossible)
Expand All @@ -396,6 +387,9 @@ protected override void OnDisable()

if (IsBeingHeld)
{
// We don't pass IsCancelled here because
// it's the intended behaviour to end the hold
// if the component is disabled.
EndHold();
}
}
Expand Down Expand Up @@ -482,7 +476,7 @@ public virtual void OnInputChanged(InputEventData<Vector2> eventData)
return;
}

var pointerPosition = primaryPointer.Result.Details.Point;
var pointerPosition = primaryPointer.Result.EndPoint;

// Filter our actions
if (eventData.MixedRealityInputAction != nudgeAction ||
Expand Down Expand Up @@ -566,7 +560,7 @@ public virtual void OnInputChanged(InputEventData<Vector2> eventData)
{
Debug.Assert(primaryPointer != null);
var newExtent = primaryPointer.PointerExtent;
var currentRaycastDistance = primaryPointer.Result.Details.RayDistance;
var currentRaycastDistance = primaryPointer.Result.RayDistance;

// Reset the cursor extent to the nearest value in case we're hitting something close
// and the user wants to adjust. That way it doesn't take forever to see the change.
Expand Down Expand Up @@ -620,27 +614,6 @@ public virtual void OnInputChanged(InputEventData<Vector2> eventData)
}
}

/// <summary>
/// Calculates the extent of the nudge.
/// </summary>
/// <param name="eventData">The event data.</param>
/// <param name="prevExtent">The previous extent distance of the pointer and raycast.</param>
/// <returns>The new pointer extent.</returns>
protected virtual float CalculateNudgeDistance(InputEventData<Vector2> eventData, float prevExtent)
{
return prevExtent + nudgeAmount * (eventData.InputData.y < 0f ? -1 : 1);
}

protected virtual Vector3 CalculateScaleAmount(InputEventData<Vector2> eventData, Vector3 prevScale)
{
if (eventData.InputData.x < 0f)
{
return prevScale *= scaleAmount;
}
// else
return prevScale /= scaleAmount;
}

#endregion IMixedRealityInputHandler Implementation

#region IMixedRealityPointerHandler Implementation
Expand Down Expand Up @@ -716,9 +689,14 @@ public virtual void BeginHold(MixedRealityPointerEventData eventData)
}

MixedRealityToolkit.InputSystem.PushModalInputHandler(gameObject);
MixedRealityToolkit.SpatialAwarenessSystem.SetMeshVisibility(spatialMeshVisibility);

var pointerPosition = primaryPointer.Result.Details.Point;
if (MixedRealityToolkit.SpatialAwarenessSystem != null)
{
prevSpatialMeshDisplay = MixedRealityToolkit.SpatialAwarenessSystem.SpatialMeshVisibility;
MixedRealityToolkit.SpatialAwarenessSystem.SpatialMeshVisibility = spatialMeshVisibility;
}

var pointerPosition = primaryPointer.Result.EndPoint;

prevPosition = manipulationTarget.position;

Expand All @@ -728,7 +706,7 @@ public virtual void BeginHold(MixedRealityPointerEventData eventData)

prevPointerExtent = primaryPointer.PointerExtent;
// update the pointer extent to prevent the object from popping to the end of the pointer
var currentRaycastDistance = primaryPointer.Result.Details.RayDistance;
var currentRaycastDistance = primaryPointer.Result.RayDistance;
primaryPointer.PointerExtent = currentRaycastDistance;
}

Expand Down Expand Up @@ -757,11 +735,12 @@ public virtual void EndHold(bool isCanceled = false)
{
if (!IsBeingHeld) { return; }

MixedRealityToolkit.SpatialAwarenessSystem.SetMeshVisibility(SpatialMeshDisplayOptions.None);
if (MixedRealityToolkit.SpatialAwarenessSystem != null)
{
MixedRealityToolkit.SpatialAwarenessSystem.SpatialMeshVisibility = prevSpatialMeshDisplay;
}

primaryPointer.PointerExtent = prevPointerExtent;
primaryPointer = null;
primaryInputSource = null;

if (isCanceled)
{
Expand All @@ -770,7 +749,6 @@ public virtual void EndHold(bool isCanceled = false)
manipulationTarget.rotation = prevRotation;
}

IsBeingHeld = false;
MixedRealityToolkit.InputSystem.PopModalInputHandler();

manipulationTarget.SetLayerRecursively(prevPhysicsLayer);
Expand All @@ -779,6 +757,32 @@ public virtual void EndHold(bool isCanceled = false)
{
boundingBox.transform.SetLayerRecursively(boundingBoxPrevPhysicsLayer);
}

primaryPointer = null;
primaryInputSource = null;
IsBeingHeld = false;
}

/// <summary>
/// Calculates the extent of the nudge using input event data.
/// </summary>
/// <param name="eventData">The event data.</param>
/// <param name="prevExtent">The previous extent distance of the pointer and raycast.</param>
/// <returns>The new pointer extent.</returns>
protected virtual float CalculateNudgeDistance(InputEventData<Vector2> eventData, float prevExtent)
{
return prevExtent + nudgeAmount * (eventData.InputData.y < 0f ? -1 : 1);
}

/// <summary>
/// Calculates the scale amount using the input event data.
/// </summary>
/// <param name="eventData">The event data.</param>
/// <param name="scale">The previous scale</param>
/// <returns>The new scale value.</returns>
protected virtual Vector3 CalculateScaleAmount(InputEventData<Vector2> eventData, Vector3 scale)
{
return eventData.InputData.x < 0f ? scale * scaleAmount : scale / scaleAmount;
}
}
}
8 changes: 4 additions & 4 deletions Features/UX/Scripts/Cursors/BaseCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ protected virtual void UpdateCursorTransform()
// If no modifier is on the target, just use the hit result to set cursor position
// Get the look forward by using distance between pointer origin and target position
// (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results)
var distanceToTarget = Vector3.Distance(Pointer.Rays[0].Origin, focusDetails.Point);
var distanceToTarget = Vector3.Distance(Pointer.Rays[0].Origin, focusDetails.EndPoint);
lookForward = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget);
targetPosition = focusDetails.Point + (lookForward * surfaceCursorDistance);
targetPosition = focusDetails.EndPoint + (lookForward * surfaceCursorDistance);
var lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, lookRotationBlend);
targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, Vector3.up);
}
Expand All @@ -416,9 +416,9 @@ protected virtual void UpdateCursorTransform()
// Use the lerp times to blend the position to the target position
var cachedTransform = transform;

if (Pointer.IsFocusLocked && Pointer.IsTargetPositionLockedOnFocusLock && focusDetails.Object != null)
if (Pointer.IsFocusLocked && Pointer.SyncPointerTargetPosition && focusDetails.CurrentPointerTarget != null)
{
cachedTransform.position = focusDetails.Point;
cachedTransform.position = focusDetails.EndPoint;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Features/UX/Scripts/Cursors/CursorModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public Vector3 GetModifiedPosition(IMixedRealityCursor cursor)
return Vector3.zero;
}

if (MixedRealityToolkit.InputSystem != null && MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(cursor.Pointer, out FocusDetails focusDetails))
if (MixedRealityToolkit.InputSystem != null && MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(cursor.Pointer, out var focusDetails))
{
// Else, consider the modifiers on the cursor modifier, but don't snap
return focusDetails.Point + HostTransform.TransformVector(CursorPositionOffset);
return focusDetails.EndPoint + HostTransform.TransformVector(CursorPositionOffset);
}

return Vector3.zero;
Expand Down
8 changes: 3 additions & 5 deletions Features/UX/Scripts/Cursors/TeleportCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected override void UpdateCursorTransform()
return;
}

if (!MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out FocusDetails focusDetails))
if (!MixedRealityToolkit.InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out var focusDetails))
{
if (MixedRealityToolkit.InputSystem.FocusProvider.IsPointerRegistered(Pointer))
{
Expand All @@ -102,11 +102,9 @@ protected override void UpdateCursorTransform()
return;
}

if (pointer.Result == null) { return; }
transform.position = focusDetails.EndPoint;

transform.position = pointer.Result.Details.Point;

Vector3 forward = CameraCache.Main.transform.forward;
var forward = CameraCache.Main.transform.forward;
forward.y = 0f;

// Smooth out rotation just a tad to prevent jarring transitions
Expand Down
14 changes: 5 additions & 9 deletions Features/UX/Scripts/Pointers/BaseControllerPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,8 @@ public virtual bool IsInteractionEnabled
/// <inheritdoc />
public bool IsFocusLocked { get; set; }

[SerializeField]
private bool isTargetPositionLockedOnFocusLock;

/// <inheritdoc />
public bool IsTargetPositionLockedOnFocusLock
{
get => isTargetPositionLockedOnFocusLock;
set => isTargetPositionLockedOnFocusLock = value;
}
public bool SyncPointerTargetPosition { get; set; }

[SerializeField]
private bool overrideGlobalPointerExtent = false;
Expand Down Expand Up @@ -320,7 +313,10 @@ public float PointerExtent
public LayerMask[] PrioritizedLayerMasksOverride { get; set; } = null;

/// <inheritdoc />
public IMixedRealityFocusHandler FocusTarget { get; set; }
public IMixedRealityFocusHandler FocusHandler { get; set; }

/// <inheritdoc />
public IMixedRealityInputHandler InputHandler { get; set; }

/// <inheritdoc />
public IPointerResult Result { get; set; }
Expand Down
Loading

0 comments on commit 2a5ea7c

Please sign in to comment.