Skip to content

Commit

Permalink
## Changes for v1.7.0:
Browse files Browse the repository at this point in the history
* New features
  - Add notification when new version released on [Github](https://github.com/ViveSoftware/ViveInputUtility-Unity/releases).
  - Add **VRModule** class to bridge various VR SDK. It currently supports SteamVR plugin, Oculus VR plugin and Unity native VR/XR interface.
    - **void VRModule.Initialize()**: Create and initilize VRModule manager instance.
    - **VRModuleActiveEnum VRModule.activeModule**: Returns the activated module.
    - **IVRModuleDeviceState VRModule.GetCurrentDeviceState(uint deviceIndex)**: Returns the virtual VR device status.
    - **event NewPosesListener VRModule.onNewPoses**: Invoked after virtual VR device status is updated.
    - **event DeviceConnectedListener VRModule.onDeviceConnected**: Invoked after virtual VR device is connected/disconnected.
    - **event ActiveModuleChangedListener VRModule.onActiveModuleChanged**: Invoked when a VR module is activated.
  - New binding interface using overlay UI. By default, the binding interface can be enabled by pressing RightShift + B in play mode.
    - ![Binding UI](https://github.com/ViveSoftware/ViveInputUtility-Unity/blob/gh-pages/assets/img/binding_ui_preview_01.png)
    - ![Binding UI](https://github.com/ViveSoftware/ViveInputUtility-Unity/blob/gh-pages/assets/img/binding_ui_preview_02.png)
    - ![Binding UI](https://github.com/ViveSoftware/ViveInputUtility-Unity/blob/gh-pages/assets/img/binding_ui_preview_03.png)
  - Add define symbols
    - **VIU_PLUGIN**: Defined when Vive Input Utility plugin is imported in the project.
    - **VIU_STEAMVR**: Defined when SteamVR plugin is imported in the project.
    - **VIU_OCULUSVR**: Defined when OculusVR plugin (OVRPlugin) is imported in the project.
    - **VIU_BINDING_INTERFACE_SWITCH**: Define it to let the project be able to switch binding interface by pressing RightShift + B in play mode.
    - **VIU_EXTERNAL_CAMERA_SWITCH**: Define it to let the project be able to switch external camera quad view by pressing RightShift + M in play mode.
  - Add new role HandRole.ExternalCamera (Alias for HandRole.Controller3).
    - By default, it is mapping to the 3rd controller, if 3rd controller not available, then mapping to the first valid generic tracker.
    - ExternalCameraHook uses mapping as the default tracking target.

* New componts
  - [ViveInputVirtualButton] Use this helper component to combine multiple Vive inputs into one virtual button.

* Improvement
  - [ViveInput] Add more controller buttons, use ViveInput.GetPress(role, buttonEnum) to get device button stat
    - **System** (Only visible when sendSystemButtonToAllApps option is on)
    - **Menu**
    - **MenuTouch**
    - **Trigger**
    - **TriggerTouch**
    - **Pad**
    - **PadTouch**
    - **Grip**
    - **GripTouch**
    - **CapSenseGrip**
    - **CapSenseGripTouch**
    - **AKey**
    - **AKeyTouch**
    - **OuterFaceButton** (Alias for Menu)
    - **OuterFaceButtonTouch** (Alias for MenuTouch)
    - **InnerFaceButton** (Alias for Grip)
    - **InnerFaceButtonTouch** (Alias for GripTouch)
  - [ViveInput] Add controller axis enum, use ViveInput.GetAxis(role, axisEnum) to get device axis value
    - **PadX**
    - **PadY**
    - **Trigger**
    - **CapSenseGrip**
    - **IndexCurl**
    - **MiddleCurl**
    - **RingCurl**
    - **PinkyCurl**
  - [ViveRole] Role mapping/binding mechanism is improved and become more flexible.
    - Now different devices can bind to same role at the same time.
    - If a unconnected device is bound to a role, that role can still map to other connected device.
  - [ViveRole] Obsolete functions that retrieve device status and property, use static API in VRModule instead.
    - **ViveRole.TryGetDeviceIndexBySerialNumber**: Use VRModule.TryGetDeviceIndex instead.
    - **ViveRole.GetModelNumber**: Use VRModule.GetCurrentDeviceState(deviceIndex).modelNumber instead
    - **ViveRole.GetSerialNumber**: Use VRModule.GetCurrentDeviceState(deviceIndex).serialNumber instead
    - **ViveRole.GetDeviceClass**: Use VRModule.GetCurrentDeviceState(deviceIndex).deviceClass instead
  - [ViveRoleBindingsHelper] Now will automatically load bindings from "vive_role_bindings.cfg", no need to be in the scene to work.
  - [RenderModelHook] Add override model and shader option.
  - [ExternalCameraHook] Now ExternalCameraHook will track the HandRole.ExternalCamera by default.
  - [ExternalCameraHook] Now will be added into scene automatically if "externalcamera.cfg" exist when start playing, no need to add to scene manually.
  - [ExternalCameraHook] You can now enable static External Camera quad view (without tracking to a device) if
    1. VIU_EXTERNAL_CAMERA_SWITCH symbol is defined.
    2. externalcamera.cfg exist.
    3. RightShift + M pressed in play mode.
  - [BasicGrabbable, StickyGrabbable, Draggable] Add unblockable grab/drag option.

* Bug fix
  - [ViveRoleProperty] Fix not handling serialized data right in inspector.
  - [PoseEaser] Now use unscaled time instead to avoid from being effected by time scale.
  • Loading branch information
lawwong committed Aug 29, 2017
1 parent 8f8ef7b commit 901a827
Show file tree
Hide file tree
Showing 208 changed files with 29,829 additions and 7,304 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Pp]ackages/
/.vs/

ProjectSettings/*
!ProjectSettings/EditorSettings.asset
Expand Down
5 changes: 2 additions & 3 deletions Assets/HTC.UnityPlugin/ColliderEvent/ColliderEventCaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using HTC.UnityPlugin.Utility;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using UnityEngine.EventSystems;

Expand Down Expand Up @@ -225,8 +224,8 @@ protected virtual void Update()
for (int i = 0, imax = axisEventDataList.Count; i < imax; ++i)
{
var eventData = axisEventDataList[i];

if (!eventData.IsValueChangedThisFrame()) { continue; }
if ((eventData.v4 = eventData.GetDelta()) == Vector4.zero) { continue; }

var handlers = GetAxisHandlers(i);

Expand Down
92 changes: 38 additions & 54 deletions Assets/HTC.UnityPlugin/ColliderEvent/ColliderEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static TEventCaster GetEventCaster<TEventCaster>(this ColliderEventData e
public static bool TryGetEventCaster<TEventCaster>(this ColliderEventData eventData, out TEventCaster eventCaster) where TEventCaster : MonoBehaviour, IColliderEventCaster
{
eventCaster = null;

if (!(eventData.eventCaster is TEventCaster)) { return false; }

eventCaster = eventData.eventCaster as TEventCaster;
Expand All @@ -43,21 +43,29 @@ public ColliderHoverEventData(IColliderEventCaster eventCaster) : base(eventCast

public abstract class ColliderButtonEventData : ColliderEventData
{
public int buttonId;
public enum InputButton
{
Trigger,
PadOrStick,
GripOrHandTrigger,
FunctionKey,
}

public IndexedSet<GameObject> pressEnteredObjects = new IndexedSet<GameObject>();
public IndexedSet<GameObject> draggingHandlers = new IndexedSet<GameObject>();
public IndexedSet<GameObject> clickingHandlers = new IndexedSet<GameObject>();

public InputButton button { get; private set; }
public Vector3 pressPosition { get; set; }
public Quaternion pressRotation { get; set; }

public bool isDragging { get { return draggingHandlers.Count > 0; } }

public bool isPressed { get; set; }

public ColliderButtonEventData(IColliderEventCaster eventCaster, int buttonId = 0) : base(eventCaster)
public ColliderButtonEventData(IColliderEventCaster eventCaster, InputButton button = 0) : base(eventCaster)
{
this.buttonId = buttonId;
this.button = button;
}

public abstract bool GetPress();
Expand All @@ -69,69 +77,45 @@ public ColliderButtonEventData(IColliderEventCaster eventCaster, int buttonId =

public abstract class ColliderAxisEventData : ColliderEventData
{
public enum InputAxis
{
Scroll2D,
Trigger1D,
}

public enum Dim
{
d1,
d2,
d3,
d4,
D1,
D2,
D3,
D4,
}

// raw delta values
private float m_x;
private float m_y;
private float m_z;
private float m_w;

public int axisId;
public InputAxis axis { get; private set; }
public Dim dimention { get; private set; }

public bool xUsed = true;
public bool yUsed = true;
public bool zUsed = false;
public bool wUsed = false;
// raw delta values
public float xRaw;
public float yRaw;
public float zRaw;
public float wRaw;
// delta values
public float x { get { return xUsed ? xRaw : 0f; } set { if (xUsed) xRaw = value; } }
public float y { get { return yUsed ? yRaw : 0f; } set { if (yUsed) yRaw = value; } }
public float z { get { return zUsed ? zRaw : 0f; } set { if (zUsed) zRaw = value; } }
public float w { get { return wUsed ? wRaw : 0f; } set { if (wUsed) wRaw = value; } }
public float x { get { return dimention >= Dim.D1 ? m_x : 0f; } set { if (dimention >= Dim.D1) m_x = value; } }
public float y { get { return dimention >= Dim.D2 ? m_y : 0f; } set { if (dimention >= Dim.D2) m_y = value; } }
public float z { get { return dimention >= Dim.D3 ? m_z : 0f; } set { if (dimention >= Dim.D3) m_z = value; } }
public float w { get { return dimention >= Dim.D4 ? m_w : 0f; } set { if (dimention >= Dim.D4) m_w = value; } }

public Vector2 v2 { get { return new Vector2(x, y); } set { x = value.x; y = value.y; } }
public Vector3 v3 { get { return new Vector3(x, y, z); } set { x = value.x; y = value.y; z = value.z; } }
public Vector4 v4 { get { return new Vector4(x, y, z, w); } set { x = value.x; y = value.y; z = value.z; w = value.w; } }

public ColliderAxisEventData(IColliderEventCaster eventCaster, int axisId = 0) : base(eventCaster)
{
this.axisId = axisId;
}

public ColliderAxisEventData(IColliderEventCaster eventCaster, Dim dimention, int axisId = 0) : base(eventCaster)
{
this.axisId = axisId;
SetDimention(dimention);
}

public void SetDimention(Dim dimention)
{
switch (dimention)
{
case Dim.d1: { xUsed = true; yUsed = false; zUsed = false; wUsed = false; break; }
case Dim.d2: { xUsed = true; yUsed = true; zUsed = false; wUsed = false; break; }
case Dim.d3: { xUsed = true; yUsed = true; zUsed = true; wUsed = false; break; }
case Dim.d4: { xUsed = true; yUsed = true; zUsed = true; wUsed = true; break; }
}
}

public bool IsDimention(Dim dimention)
public ColliderAxisEventData(IColliderEventCaster eventCaster, Dim dimention, InputAxis axis = 0) : base(eventCaster)
{
switch (dimention)
{
case Dim.d1: return xUsed && !yUsed && !zUsed && !wUsed;
case Dim.d2: return xUsed && yUsed && !zUsed && !wUsed;
case Dim.d3: return xUsed && yUsed && zUsed && !wUsed;
case Dim.d4: return xUsed && yUsed && zUsed && wUsed;
default: return false;
}
this.axis = axis;
this.dimention = dimention;
}

public abstract bool IsValueChangedThisFrame();
public abstract Vector4 GetDelta();
}
}
7 changes: 5 additions & 2 deletions Assets/HTC.UnityPlugin/Pointer3D/Pointer3DInputModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ protected override void OnDisable()
}
}

eventSystem.SetSelectedGameObject(null, GetBaseEventData());
if (eventSystem != null)
{
eventSystem.SetSelectedGameObject(null, GetBaseEventData());
}
}

public static readonly Comparison<RaycastResult> defaultRaycastComparer = RaycastComparer;
Expand Down Expand Up @@ -485,7 +488,7 @@ protected void DeselectIfSelectionChanged(GameObject currentOverGo, BaseEventDat
var selectHandlerGO = ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo);
// if we have clicked something new, deselect the old thing
// leave 'selection handling' up to the press event though.
if (selectHandlerGO != eventSystem.currentSelectedGameObject)
if (eventSystem != null && selectHandlerGO != eventSystem.currentSelectedGameObject)
{
eventSystem.SetSelectedGameObject(null, pointerEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace HTC.UnityPlugin.Pointer3D
{
Expand Down Expand Up @@ -57,7 +58,7 @@ public override Camera eventCamera
var go = new GameObject(name + " FallbackCamera");
go.SetActive(false);
// place fallback camera at root to preserve world position
//go.transform.SetParent(transform);
go.transform.SetParent(EventSystem.current.transform, false);
go.transform.localPosition = Vector3.zero;
go.transform.localRotation = Quaternion.identity;
go.transform.localScale = Vector3.one;
Expand Down
56 changes: 20 additions & 36 deletions Assets/HTC.UnityPlugin/PoseTracker/Base/BasePoseTracker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//========= Copyright 2016-2017, HTC Corporation. All rights reserved. ===========

using System.Collections.Generic;
using HTC.UnityPlugin.Utility;
using UnityEngine;

namespace HTC.UnityPlugin.PoseTracker
Expand All @@ -10,50 +10,32 @@ public abstract class BasePoseTracker : MonoBehaviour, IPoseTracker
public Vector3 posOffset;
public Vector3 rotOffset;

private readonly Dictionary<IPoseModifier, LinkedListNode<IPoseModifier>> modifierTable = new Dictionary<IPoseModifier, LinkedListNode<IPoseModifier>>();
private readonly LinkedList<IPoseModifier> modifiers = new LinkedList<IPoseModifier>();
private OrderedIndexedSet<IPoseModifier> modifierSet;

public void AddModifier(IPoseModifier obj)
{
if (obj == null || modifierTable.ContainsKey(obj)) { return; }
if (obj == null) { return; }

var node = modifiers.Last;
if (node == null || node.Value != null)
if (modifierSet == null)
{
node = modifiers.AddFirst(obj);
modifierSet = new OrderedIndexedSet<IPoseModifier>();
modifierSet.Add(obj);
}
else
else if (!modifierSet.Contains(obj))
{
modifiers.Remove(node);
node.Value = obj;
modifiers.AddFirst(node);
}

modifierTable.Add(obj, node);

// sort new modifier node
var priorNode = node;
while (priorNode.Next != null && priorNode.Next.Value != null && priorNode.Next.Value.priority < obj.priority)
{
priorNode = priorNode.Next;
}

if (priorNode != node)
{
modifiers.Remove(node);
modifiers.AddAfter(priorNode, node);
for (int i = modifierSet.Count - 1; i >= 0; --i)
{
if (modifierSet[i].priority <= obj.priority)
{
modifierSet.Insert(i + 1, obj);
}
}
}
}

public bool RemoveModifier(IPoseModifier obj)
{
LinkedListNode<IPoseModifier> node;
if (!modifierTable.TryGetValue(obj, out node)) { return false; }
modifierTable.Remove(obj);
modifiers.Remove(node);
node.Value = null;
modifiers.AddLast(node);
return true;
return modifierSet == null ? false : modifierSet.Remove(obj);
}

protected void TrackPose(Pose pose, Transform origin = null)
Expand All @@ -65,10 +47,12 @@ protected void TrackPose(Pose pose, Transform origin = null)

protected void ModifyPose(ref Pose pose, Transform origin)
{
for (var node = modifiers.First; node != null && node.Value != null; node = node.Next)
if (modifierSet == null) { return; }

for (int i = 0, imax = modifierSet.Count; i < imax; ++i)
{
if (!node.Value.enabled) { continue; }
node.Value.ModifyPose(ref pose, origin);
if (!modifierSet[i].enabled) { continue; }
modifierSet[i].ModifyPose(ref pose, origin);
}
}
}
Expand Down
Loading

0 comments on commit 901a827

Please sign in to comment.