Skip to content

Commit 782cb32

Browse files
authored
New Input Data Format for WebXR Data (#2)
* Update Input to match format from client * Add HDRP Sample * Add Changelog and HDRP Sample * Update to 0.2.0
1 parent a7caf3d commit 782cb32

File tree

255 files changed

+28160
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+28160
-35
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Changelog
2+
All notable changes to com.unity.renderstreaming package will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [0.2.0] - 2021-07-12
8+
9+
### Changed
10+
11+
- VR Controller Data Input Format from client for WebXR data
12+
13+
### Added
14+
15+
- VR Controller Data for Axis input i.e. Trackpad and Joystick
16+
- HDRP VR Render Streaming Sample
17+
18+
## [0.1.1] - 2021-07-04
19+
20+
### Added
21+
22+
- VR Broadcaster Script to Replace Remote Render Streaming default Broadcaster
23+
24+
### Fixed
25+
26+
- VR Broadcaster enables streaming to just one VR headset to avoid eavesdropping
27+
28+
## [0.1.0] - 2021-07-03
29+
30+
- Initial Release of Experimental VR Render Streaming

CHANGELOG.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,23 @@ Limited testing and Proof of Concepts have been done with deploying a standalone
2727
# GPU Recommendations
2828

2929
It is strongly recommended to utlize a NVIDIA GPU as these GPUs support Hardware Accelerated Encoding, which is a requirement for lower latency VR Streaming. You can check the fully compatability matrix on the [Unity WebRTC documentation](https://docs.unity3d.com/Packages/[email protected]/manual/index.html). If you are using a GPU that does not support Hardware Accelerated, you will need to uncheck this option on the **RenderStreaming** Gameobject and Component
30+
31+
# WebXR Input
32+
33+
Controller Input is captured via the [A-Frame Tracked-Controls component](https://aframe.io/docs/1.2.0/components/tracked-controls.html) and then sent over the data channel to the Unity SDK. This data protocol is adaopted from the Unity Broadcast system, which was also capable of sending Keyboard, Mouse, Touch, and Gamepad data back to Unity via the RemoteInput.cs script in Unity. As such, VR data is sent from the client to Unity as Data Array buffers, defined in bytes.
34+
35+
The first byte of the data Array Byffer refers to the input mode to determine how to parse the data as an id. The following IDs were reservered for Web Input by the Unity Render Streaming system.
36+
37+
- ID 0 = Keyboard
38+
- ID 1 = Mouse
39+
- ID 2 = MouseWheel
40+
- ID 3 = Touch
41+
- ID 4 = UI (legacy)
42+
- ID 5 = Gamepad
43+
44+
ID 6 is what is used for all WebXR Input specific to VR. Within VR Input, we specify 3 different modes for sending data, which are:
45+
- ID 0 = Positional and Rotational Data of the Headset and Hands
46+
- ID 1 = Controller Button Data ( A , B , Trigger, Grip )
47+
- ID 2 = Controller Axis Data (Joystick & Trackpad)
48+
49+
The Raw Data from the Client is passed to VRInputManager, who is responsible for transmitting events based on the data mode recieved. Controller Input is then parsed by the ControllerInputManager, which has events that can be subscribed to for VR Input.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "FusdeVR.Streaming",
2+
"name": "FusedVR.Streaming",
33
"references": [
44
"GUID:40a5acf76f04c4c8ebb69605e4b0d5c7",
55
"GUID:f12aafacab75a87499e7e45c873ffab8"

Runtime/Scripts/ControllerInputManager.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public enum Button
3838
Grip,
3939
AButton,
4040
BButton,
41-
Joystick
41+
Joystick,
42+
Trackpad
4243
}
4344
#endregion
4445

@@ -47,34 +48,62 @@ public enum Button
4748
/// The class wrapper for the VRControllerData Unity Event
4849
/// </summary>
4950
[System.Serializable]
50-
public class VRControllerData : UnityEvent<Hand, Button, bool, bool> {
51+
public class VRButtonData : UnityEvent<Hand, Button, bool, bool> {
5152

5253
}
5354

5455
/// <summary>
5556
/// The main controller input Unity Event. You may listen to this event via code or via the inspector just like any other Unity Event.
5657
/// </summary>
57-
public static VRControllerData VRControllerEvent;
58+
public VRButtonData VRButtonEvent;
59+
60+
/// <summary>
61+
/// The class wrapper for the VRControllerData Unity Event
62+
/// </summary>
63+
[System.Serializable]
64+
public class VRAxisData : UnityEvent<Hand, Button, float, float> {
65+
66+
}
67+
68+
/// <summary>
69+
/// The main controller input Unity Event. You may listen to this event via code or via the inspector just like any other Unity Event.
70+
/// </summary>
71+
public VRAxisData VRAxisEvent;
5872
#endregion
5973

6074
#region Methods
6175
// Start is called before the first frame update
6276
void Start()
6377
{
64-
VRInputManager.ControllerDataEvent += ControllerEvents; //start listening
78+
VRInputManager.ButtonDataEvent += ButtonEvents; //start listening
79+
VRInputManager.AxisDataEvent += AxisEvents; //start listening
6580
}
6681

6782
// OnDestroy is called when the game object is about to be destroyed in the scene
6883
private void OnDestroy() {
69-
VRInputManager.ControllerDataEvent -= ControllerEvents; //end listening
84+
VRInputManager.ButtonDataEvent -= ButtonEvents; //end listening
85+
VRInputManager.AxisDataEvent -= AxisEvents; //end listening
7086
}
7187

7288
/// <summary>
7389
/// Callback function for Raw Data from VRInputManager ControllerDataEvent
7490
/// </summary>
75-
void ControllerEvents(int handID, int buttonID, bool pressed, bool touched)
91+
void ButtonEvents(VRInputManager.Source handID, int buttonID, bool pressed, bool touched)
7692
{
77-
VRControllerEvent.Invoke((Hand)handID, (Button)buttonID, pressed, touched); //invoke the Unity Event
93+
VRButtonEvent?.Invoke((Hand)(handID -1), (Button)buttonID, pressed, touched); //invoke the Unity Event
94+
}
95+
96+
/// <summary>
97+
/// Callback function for Raw Data from VRInputManager ControllerDataEvent
98+
/// </summary>
99+
void AxisEvents(VRInputManager.Source handID, int buttonID, float x, float y) {
100+
Button axisButton = (Button)((int)Button.Joystick + buttonID);
101+
102+
Debug.Log("My Button is " + axisButton);
103+
Debug.Log("Axis is X : " + x);
104+
Debug.Log("Axis is Y : " + y);
105+
106+
VRAxisEvent?.Invoke((Hand)(handID - 1), axisButton, x, y); //invoke the Unity Event
78107
}
79108
#endregion
80109
}

Runtime/Scripts/VRInputManager.cs

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ namespace FusedVR.VRStreaming
2323
public class VRInputManager : InputChannelReceiverBase
2424
{
2525
#region Constants
26+
/// <summary>
27+
/// The Data Format that we are getting from the VR headset
28+
/// </summary>
29+
public enum VRDataType {
30+
PosRot,
31+
Button,
32+
Axis
33+
}
34+
2635
/// <summary>
2736
/// Data Source for positional / rotational VR Data i.e. Head Left Hand or Right Hand
2837
/// </summary>
@@ -33,17 +42,9 @@ public enum Source {
3342
}
3443

3544
/// <summary>
36-
/// This is the ID for getting Controller Input Data from the client
37-
/// </summary>
38-
public const int VR_CONTROLLER_ID = 5;
39-
40-
/// <summary>
41-
/// The Base ID for Recieving Positional / Rotational Data from the client
42-
/// BASEID + 0 = Head
43-
/// BASEID + 1 = Left Hand
44-
/// BASEID + 2 = Right Hand
45+
/// The Base ID for Recieving VR Data from the Web client
4546
/// </summary>
46-
public const int VR_BASE_ID = 6;
47+
public const int VR_DEVICE_ID = 6;
4748
#endregion
4849

4950
#region Events
@@ -61,10 +62,17 @@ public class VRPoseData : UnityEvent<Source, Vector3, Vector3> {
6162
public VRPoseData VRPoseEvent;
6263

6364
/// <summary>
64-
/// C# Event responsible for sending Controller Data that is recieved from the client
65+
/// C# Event responsible for sending Controller Button Data that is recieved from the client
6566
/// </summary>
66-
public delegate void OnControllerDataRecieved(int handID, int buttonID, bool pressed, bool touched);
67-
public static OnControllerDataRecieved ControllerDataEvent;
67+
public delegate void OnButtonDataRecieved(Source handID, int buttonID, bool pressed, bool touched);
68+
public static OnButtonDataRecieved ButtonDataEvent;
69+
70+
71+
/// <summary>
72+
/// C# Event responsible for sending Controller Axis Data that is recieved from the client
73+
/// </summary>
74+
public delegate void OnAxisDataRecieved(Source handID, int buttonID, float xaxis, float yaxis);
75+
public static OnAxisDataRecieved AxisDataEvent;
6876
#endregion
6977

7078
#region Methods
@@ -83,22 +91,37 @@ public void SendData(string msg)
8391
/// </summary>
8492
protected override void OnMessage(byte[] bytes)
8593
{
86-
int index = bytes[0];
87-
88-
if (index == VR_CONTROLLER_ID)
89-
{ //VR Controller Data
90-
ControllerDataEvent?.Invoke(bytes[1], bytes[2], BitConverter.ToBoolean(bytes, 3), BitConverter.ToBoolean(bytes, 4));
91-
}
94+
if (bytes[0] == VR_DEVICE_ID) //VR Device Data
95+
{
96+
int data_type = bytes[1]; //get input data source
97+
switch ( (VRDataType) data_type) {
98+
case VRDataType.PosRot:
99+
Source device_type = (Source) bytes[2]; //get source
100+
Vector3 pos = new Vector3(BitConverter.ToSingle(bytes, 3),
101+
BitConverter.ToSingle(bytes, 11), BitConverter.ToSingle(bytes, 19));
92102

93-
if (index >= VR_BASE_ID)
94-
{ //VR data
95-
Vector3 pos = new Vector3(BitConverter.ToSingle(bytes, 1),
96-
BitConverter.ToSingle(bytes, 9), BitConverter.ToSingle(bytes, 17));
103+
Vector3 rot = new Vector3(Mathf.Rad2Deg * BitConverter.ToSingle(bytes, 27),
104+
Mathf.Rad2Deg * BitConverter.ToSingle(bytes, 35), Mathf.Rad2Deg * BitConverter.ToSingle(bytes, 43));
105+
VRPoseEvent.Invoke(device_type, pos, rot);
106+
break;
107+
case VRDataType.Button:
108+
ButtonDataEvent?.Invoke((Source) bytes[2], bytes[3], BitConverter.ToBoolean(bytes, 4),
109+
BitConverter.ToBoolean(bytes, 5));
110+
break;
111+
case VRDataType.Axis:
112+
if ( BitConverter.ToBoolean(bytes, 3) || BitConverter.ToBoolean(bytes, 12) ) { //if trackpad changed
113+
AxisDataEvent?.Invoke((Source)bytes[2], 1, BitConverter.ToSingle(bytes, 4),
114+
BitConverter.ToSingle(bytes, 13));
115+
}
97116

98-
Vector3 rot = new Vector3(Mathf.Rad2Deg * BitConverter.ToSingle(bytes, 25),
99-
Mathf.Rad2Deg * BitConverter.ToSingle(bytes, 33), Mathf.Rad2Deg * BitConverter.ToSingle(bytes, 41));
117+
if (BitConverter.ToBoolean(bytes, 21) || BitConverter.ToBoolean(bytes, 30)) { //if joystick changed
118+
AxisDataEvent?.Invoke((Source)bytes[2], 0, BitConverter.ToSingle(bytes, 22),
119+
BitConverter.ToSingle(bytes, 31));
120+
}
100121

101-
VRPoseEvent.Invoke((Source)(index - VR_BASE_ID), pos, rot);
122+
break;
123+
}
124+
102125
}
103126
}
104127
#endregion

Samples~/HDRPVR/Editor/Startup.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using UnityEditor.PackageManager;
4+
5+
[InitializeOnLoad]
6+
public class Startup {
7+
8+
//Only Load Once
9+
private static bool loaded = false;
10+
11+
//On Startup Load the HD Render Pipeline
12+
static Startup() {
13+
if (!loaded) {
14+
Debug.Log("Loading High Definiton Render Pipeline Package from Startup script...");
15+
Client.Add("com.unity.render-pipelines.high-definition");
16+
loaded = true;
17+
}
18+
}
19+
}

Samples~/HDRPVR/Editor/Startup.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples~/HDRPVR/ExampleAssets.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)