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

Added NVRVirtualHand and NVRVirtualInputDevice to use with NPC and remote users #114

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5b2c305
Added NVRVirtualHand and NVRVirtualInputDevice to use with NPC and re…
Jan 9, 2017
721befa
Added OnUseInteraction event to capture Use() calls for sending to re…
jbroadway Jan 9, 2017
893aef3
Removed OnUseInteraction event, moving this to NVRHand for capture in…
jbroadway Jan 9, 2017
9bdb610
Added OnBeginUseInteraction and OnEndUseInteraction events to respond…
jbroadway Jan 9, 2017
8469aca
Trigger OnBeginUseInteraction and OnEndUseInteraction on NVRHand via …
jbroadway Jan 9, 2017
ee82220
Added PickupByName(objectID) to ensure NVRVirtualHand can pick up the…
jbroadway Jan 16, 2017
f21e215
Added Hold(objectID) to NVRVirtualHand to improve multiplayer accuracy
jbroadway Jan 16, 2017
b3dcd8c
Increased collider radius on virtual hands to compensate for remote m…
jbroadway Jan 16, 2017
a04e983
Merge remote-tracking branch 'refs/remotes/TomorrowTodayLabs/master'
Feb 14, 2017
e84c1fc
Added EndUse() to virtualize releasing the use trigger
jbroadway Feb 27, 2017
11eca22
Corrected method names in debug outputs
jbroadway Feb 27, 2017
f66e1de
Fix for crash on launch if interactables try to register themselves t…
jbroadway Feb 27, 2017
3caa1e1
Added null checks which allows buttons to work when NVRVirtualHand is…
Mar 21, 2017
0f900fc
Merge remote-tracking branch 'refs/remotes/TomorrowTodayLabs/master'
Mar 23, 2017
2974919
Merge remote-tracking branch 'refs/remotes/TomorrowTodayLabs/master'
Apr 6, 2017
d508594
Merged patch-2 for crash on launch in builds fix
Apr 6, 2017
6d4753b
Added NVRHandedInteractableItem for different interaction points from…
Apr 6, 2017
8e0bdda
Destroy children of newly-cloned physical hand
Apr 14, 2017
c375f4f
Merge remote-tracking branch 'refs/remotes/TomorrowTodayLabs/master'
Jul 12, 2017
bdcf77b
Added folders for dependencies to gitignore
Jul 12, 2017
62eb014
Merge branch 'master' of https://github.com/jbroadway/NewtonVR
Jul 12, 2017
9773f22
Merge remote-tracking branch 'refs/remotes/TomorrowTodayLabs/master'
Jul 12, 2017
9968a74
Add CanvasRenderer to list of KeepTypes to fix exception at DestroyIm…
jbroadway Jul 28, 2017
7265553
Added ability to set a custom collider radius for virtual hands
Aug 11, 2017
9056e14
Added NVRSnappingInteractableItem for items that should snap to a gri…
Sep 11, 2017
1fbc9ce
Added weights to make snapping more smooth
Sep 12, 2017
d45a5b2
Reset snapping state on each interaction
Sep 12, 2017
7f72934
Decreased the size of the collider on Oculus Touch controllers
jbroadway Sep 19, 2017
7ec0b91
add missing button
morgash1989 Aug 29, 2017
174298f
Merge branch 'master' of https://github.com/campfireunion/NewtonVR-Mu…
Oct 9, 2017
35bad7e
Won't pick up disabled objects.
ryancampfire Oct 10, 2017
1a1d84c
Formatting fix
lux Oct 19, 2017
32fa7c6
Update project to Unity 2017
cameronpenner Oct 19, 2017
8d6d0e1
Merge pull request #2 from campfireunion/UpdateTo2017
lux Oct 19, 2017
ff3dadf
NVRInteractableItemSnappable allows items to snap to things
cameronpenner Oct 19, 2017
94a8c35
Merge pull request #1 from campfireunion/ObjectSnapping
lux Oct 19, 2017
e81fd56
Merge branch 'master' of https://github.com/TomorrowTodayLabs/NewtonVR
Oct 25, 2017
a253975
Update NVRInteractable.cs
ryancampfire Nov 21, 2017
c7e6638
Checks if CurrentlyHoveringOver is null
lux Nov 28, 2017
a423cc2
Update NVRHand.cs
ryancampfire Aug 1, 2018
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@

# Unity3D Generated File On Crash Reports
sysinfo.txt

Assets/Plugins.meta
Assets/Plugins/
Assets/OVR.meta
Assets/OVR/
Assets/SteamVR.meta
Assets/SteamVR/

44 changes: 22 additions & 22 deletions Assets/NewtonVR/NVRButtonInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public bool PressDown
{
if (PressDownExpired)
{
PressDownCached = InputDevice.GetPressDown(NVRbutton);
PressDownCached = (InputDevice != null) ? InputDevice.GetPressDown(NVRbutton) : false;
PressDownExpired = false;
}
return PressDownCached;
}
}

private bool PressDownCached;
private bool PressDownExpired = false;
private bool PressDownExpired = true;

/// <summary>Is true ONLY on the frame that the button is released after being pressed down</summary>
public bool PressUp
Expand All @@ -31,15 +31,15 @@ public bool PressUp
{
if (PressUpExpired)
{
PressUpCached = InputDevice.GetPressUp(NVRbutton);
PressUpCached = (InputDevice != null) ? InputDevice.GetPressUp(NVRbutton) : false;
PressUpExpired = false;
}
return PressUpCached;
}
}

private bool PressUpCached;
private bool PressUpExpired = false;
private bool PressUpExpired = true;

/// <summary>Is true WHENEVER the button is pressed down</summary>
public bool IsPressed
Expand All @@ -48,15 +48,15 @@ public bool IsPressed
{
if (IsPressedExpired)
{
IsPressedCached = InputDevice.GetPress(NVRbutton);
IsPressedCached = (InputDevice != null) ? InputDevice.GetPress(NVRbutton) : false;
IsPressedExpired = false;
}
return IsPressedCached;
}
}

private bool IsPressedCached;
private bool IsPressedExpired = false;
private bool IsPressedExpired = true;

/// <summary>Is true ONLY on the frame that the button is first touched</summary>
public bool TouchDown
Expand All @@ -65,15 +65,15 @@ public bool TouchDown
{
if (TouchDownExpired)
{
TouchDownCached = InputDevice.GetTouchDown(NVRbutton);
TouchDownCached = (InputDevice != null) ? InputDevice.GetTouchDown(NVRbutton) : false;
TouchDownExpired = false;
}
return TouchDownCached;
}
}

private bool TouchDownCached;
private bool TouchDownExpired = false;
private bool TouchDownExpired = true;

/// <summary>Is true ONLY on the frame that the button is released after being touched</summary>
public bool TouchUp
Expand All @@ -82,15 +82,15 @@ public bool TouchUp
{
if (TouchUpExpired)
{
TouchUpCached = InputDevice.GetTouchUp(NVRbutton);
TouchUpCached = (InputDevice != null) ? InputDevice.GetTouchUp(NVRbutton) : false;
TouchUpExpired = false;
}
return TouchUpCached;
}
}

private bool TouchUpCached;
private bool TouchUpExpired = false;
private bool TouchUpExpired = true;

/// <summary>Is true WHENEVER the button is being touched</summary>
public bool IsTouched
Expand All @@ -99,15 +99,15 @@ public bool IsTouched
{
if (IsTouchedExpired)
{
IsTouchedCached = InputDevice.GetTouch(NVRbutton);
IsTouchedCached = (InputDevice != null) ? InputDevice.GetTouch(NVRbutton) : false;
IsTouchedExpired = false;
}
return IsTouchedCached;
}
}

private bool IsTouchedCached;
private bool IsTouchedExpired = false;
private bool IsTouchedExpired = true;

/// <summary>Is true ONLY on the frame that the button is first near touched</summary>
public bool NearTouchDown
Expand All @@ -116,15 +116,15 @@ public bool NearTouchDown
{
if (NearTouchDownExpired)
{
NearTouchDownCached = InputDevice.GetNearTouchDown(NVRbutton);
NearTouchDownCached = (InputDevice != null) ? InputDevice.GetNearTouchDown(NVRbutton) : false;
NearTouchDownExpired = false;
}
return NearTouchDownCached;
}
}

private bool NearTouchDownCached;
private bool NearTouchDownExpired = false;
private bool NearTouchDownExpired = true;

/// <summary>Is true ONLY on the frame that the button is released after being near touched</summary>
public bool NearTouchUp
Expand All @@ -133,15 +133,15 @@ public bool NearTouchUp
{
if (NearTouchUpExpired)
{
NearTouchUpCached = InputDevice.GetNearTouchUp(NVRbutton);
NearTouchUpCached = (InputDevice != null) ? InputDevice.GetNearTouchUp(NVRbutton) : false;
NearTouchUpExpired = false;
}
return NearTouchUpCached;
}
}

private bool NearTouchUpCached;
private bool NearTouchUpExpired = false;
private bool NearTouchUpExpired = true;

/// <summary>Is true WHENEVER the button is near being touched</summary>
public bool IsNearTouched
Expand All @@ -150,15 +150,15 @@ public bool IsNearTouched
{
if (IsNearTouchedExpired)
{
IsNearTouchedCached = InputDevice.GetNearTouch(NVRbutton);
IsNearTouchedCached = (InputDevice != null) ? InputDevice.GetNearTouch(NVRbutton) : false;
IsNearTouchedExpired = false;
}
return IsNearTouchedCached;
}
}

private bool IsNearTouchedCached;
private bool IsNearTouchedExpired = false;
private bool IsNearTouchedExpired = true;

/// <summary>x,y axis generally for the touchpad. trigger uses x</summary>
public Vector2 Axis
Expand All @@ -167,15 +167,15 @@ public Vector2 Axis
{
if (AxisExpired)
{
AxisCached = InputDevice.GetAxis2D(NVRbutton);
AxisCached = (InputDevice != null) ? InputDevice.GetAxis2D(NVRbutton) : Vector2.zero;
AxisExpired = false;
}
return AxisCached;
}
}

private Vector2 AxisCached;
private bool AxisExpired = false;
private bool AxisExpired = true;

/// <summary>x axis from Axis</summary>
public float SingleAxis
Expand All @@ -184,15 +184,15 @@ public float SingleAxis
{
if (SingleAxisExpired)
{
SingleAxisCached = InputDevice.GetAxis1D(NVRbutton);
SingleAxisCached = (InputDevice != null) ? InputDevice.GetAxis1D(NVRbutton) : 0f;
SingleAxisExpired = false;
}
return SingleAxisCached;
}
}

private float SingleAxisCached;
private bool SingleAxisExpired = false;
private bool SingleAxisExpired = true;

private NVRInputDevice InputDevice;
private NVRButtons NVRbutton;
Expand Down
75 changes: 59 additions & 16 deletions Assets/NewtonVR/NVRHand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public class NVRHand : MonoBehaviour
[HideInInspector]
public GameObject CustomPhysicalColliders;

private VisibilityLevel CurrentVisibility = VisibilityLevel.Visible;
private bool VisibilityLocked = false;
protected VisibilityLevel CurrentVisibility = VisibilityLevel.Visible;
protected bool VisibilityLocked = false;

[HideInInspector]
public HandState CurrentHandState = HandState.Uninitialized;

private Dictionary<NVRInteractable, Dictionary<Collider, float>> CurrentlyHoveringOver;
protected Dictionary<NVRInteractable, Dictionary<Collider, float>> CurrentlyHoveringOver;

public NVRInteractable CurrentlyInteracting;

Expand All @@ -55,22 +55,24 @@ public class NVRInteractableEvent : UnityEvent<NVRInteractable> { }

public NVRInteractableEvent OnBeginInteraction = new NVRInteractableEvent();
public NVRInteractableEvent OnEndInteraction = new NVRInteractableEvent();
public NVRInteractableEvent OnBeginUseInteraction = new NVRInteractableEvent ();
public NVRInteractableEvent OnEndUseInteraction = new NVRInteractableEvent ();

private int EstimationSampleIndex;
private Vector3[] LastPositions;
private Quaternion[] LastRotations;
private float[] LastDeltas;
private int EstimationSamples = 5;
protected int EstimationSampleIndex;
protected Vector3[] LastPositions;
protected Quaternion[] LastRotations;
protected float[] LastDeltas;
protected int EstimationSamples = 5;

[HideInInspector]
public NVRPhysicalController PhysicalController;

private Collider[] GhostColliders;
private Renderer[] GhostRenderers;
protected Collider[] GhostColliders;
protected Renderer[] GhostRenderers;

private NVRInputDevice InputDevice;
protected NVRInputDevice InputDevice;

private GameObject RenderModel;
protected GameObject RenderModel;

public bool IsHovering
{
Expand Down Expand Up @@ -356,7 +358,7 @@ protected void UpdateInteractions()
}
}

private void UpdateVisibilityAndColliders()
protected void UpdateVisibilityAndColliders()
{
if (Player.PhysicalHands == true)
{
Expand Down Expand Up @@ -590,7 +592,7 @@ public virtual void EndInteraction(NVRInteractable item)
}
}

private bool PickupClosest()
protected bool PickupClosest()
{
NVRInteractable closest = null;
float closestDistance = float.MaxValue;
Expand All @@ -601,6 +603,14 @@ private bool PickupClosest()
{
if (hovering.Key == null)
continue;

if (!hovering.Key.gameObject.activeInHierarchy)
continue;

var itemColliders = hovering.Value;

itemColliders.Where (item => !item.Key.gameObject.activeInHierarchy).ToList ().ForEach (item => itemColliders.Remove (item.Key));


float distance = Vector3.Distance(collider.transform.position, hovering.Key.transform.position);
if (distance < closestDistance)
Expand All @@ -621,12 +631,45 @@ private bool PickupClosest()
return false;
}
}

protected bool PickupByName(string withName)
{
NVRInteractable closest = null;
float closestDistance = float.MaxValue;


foreach (var hovering in CurrentlyHoveringOver)
{
if (hovering.Key == null)
continue;

float distance = Vector3.Distance(this.transform.position, hovering.Key.transform.position);
if (distance < closestDistance && hovering.Key.name==withName)
{
closestDistance = distance;
closest = hovering.Key;
}
}

if (closest != null)
{
BeginInteraction(closest);
return true;
}
else
{
return false;
}
}

protected virtual void OnTriggerEnter(Collider collider)
{
NVRInteractable interactable = NVRInteractables.GetInteractable(collider);
if (interactable == null || interactable.enabled == false)
return;

if (CurrentlyHoveringOver == null)
CurrentlyHoveringOver = new Dictionary<NVRInteractable, Dictionary<Collider, float>> ();

if (CurrentlyHoveringOver.ContainsKey(interactable) == false)
CurrentlyHoveringOver[interactable] = new Dictionary<Collider, float>();
Expand Down Expand Up @@ -772,7 +815,7 @@ protected void InitializeRenderModel()
}
}

public void Initialize()
public virtual void Initialize()
{
Rigidbody = this.GetComponent<Rigidbody>();
if (Rigidbody == null)
Expand Down Expand Up @@ -879,4 +922,4 @@ public enum InterationStyle
Toggle,
ByScript,
}
}
}
26 changes: 26 additions & 0 deletions Assets/NewtonVR/NVRHandedInteractableItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
using NewtonVR;

public class NVRHandedInteractableItem : NVRInteractableItem
{
[SerializeField]
Transform LeftHandInteractionPoint;

[SerializeField]
Transform RightHandInteractionPoint;

public override void BeginInteraction (NVRHand hand)
{
if (hand.IsLeft)
{
InteractionPoint = LeftHandInteractionPoint;
}
else
{
InteractionPoint = RightHandInteractionPoint;
}

base.BeginInteraction (hand);
}
}
12 changes: 12 additions & 0 deletions Assets/NewtonVR/NVRHandedInteractableItem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading