Skip to content

Commit

Permalink
Moving DLLs / Adding Websockets
Browse files Browse the repository at this point in the history
Moving Vicon DLLs to Assets/Plugins
Adding back websockets
  • Loading branch information
omangbaheti committed Jul 5, 2024
1 parent a275cec commit aa37dd8
Show file tree
Hide file tree
Showing 103 changed files with 1,701 additions and 551 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 7 additions & 8 deletions Assets/Scripts/ViconNexusUnityStream/CustomSubjectScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System;
using System.IO;
using System.Linq;
using HMDUtils;
using Newtonsoft.Json;


namespace ubco.ovilab.ViconUnityStream
{
public class CustomSubjectScript : MonoBehaviour
Expand All @@ -15,9 +17,9 @@ public class CustomSubjectScript : MonoBehaviour
[SerializeField] protected SubjectDataManager subjectDataManager;
[Tooltip("The subject name to be used.")]
[SerializeField] protected string subjectName = "test";
[Tooltip("Stratergy used for gap filling.")]
[Tooltip("Strategy used for gap filling.")]
[SerializeField] protected GapFillingStrategy gapFillingStrategy = GapFillingStrategy.UseRemote;
[Tooltip("The dafault data to use if not connecting to remote.")]
[Tooltip("The default data to use if not connecting to remote.")]
[Space()]
[TextArea] [SerializeField] protected string defaultData = "{\"data\": {\"RWRB\": [-543.6625324688598, 207.2696870612411, 298.7514053730324], \"RFA2\": [-532.0721277646578, 220.17137432871033, 301.01629761935317], \"RFA1\": [-520.1440660572242, 201.39104705712728, 339.41934514555805], \"RWRA\": [-532.6974300716365, 189.02367806197196, 337.42141847242124], \"RH1\": [-560.7345454383594, 159.62419546128493, 330.3774691418835], \"RH3\": [-590.0032621097643, 131.76129785698242, 299.0094709326491], \"RH6\": [-562.2275968721467, 178.22968321613172, 289.7780921183954], \"RTH1\": [-521.0776063001258, 156.02975240617602, 339.52347728151585], \"RTH2\": [-533.1608764185024, 125.93223864863384, 346.6751934035616], \"RTH3\": [-544.0308683261262, 94.88325770113741, 340.18541871909747], \"RTH3P\": [-558.2383999037787, 98.54284010368167, 344.30830190364924], \"RTH4\": [-565.5234537423078, 83.35392844673802, 323.32104505694093], \"RH2\": [-585.6043517556936, 120.51194616610833, 321.788774764582], \"RIF1\": [-576.5885643353779, 78.82999103456628, 300.3582074396528], \"RIF2\": [-561.2383839807005, 59.365051118922004, 295.3749509588552], \"RIF3\": [-541.7682180796493, 45.73872562944883, 292.4172960222232], \"RTF1\": [-572.5416262201588, 87.20318096871338, 285.1907380694027], \"RTF2\": [-562.4119589663006, 62.738780575654275, 271.7188525984546], \"RTF3\": [-557.640123472733, 48.67593410004015, 265.6647298151231], \"RH4\": [-584.7190340388772, 139.86043222122856, 281.7731182084455], \"RRF1\": [-585.3695333810368, 117.21631146711684, 275.4715366418419], \"RRF2\": [-587.3318441581403, 98.12953148435754, 262.2992975340355], \"RRF3\": [-588.7462283921602, 71.40473234827627, 248.39760510410048], \"RRF4\": [-587.6055606791075, 56.662726798838854, 241.1235659054331], \"RH5\": [-576.2821771931049, 149.15875547966468, 267.5793086555055], \"RPF1\": [-587.1382537041475, 129.22951405026535, 250.65671596147286], \"RPF2\": [-593.5975138169013, 115.06673347598871, 237.79061600397645], \"RPF3\": [-598.0083756011302, 98.17580941339943, 225.52275793399647]}, \"hierachy\": {\"Arm\": [\"RWRB\", \"RFA2\", \"RFA1\", \"RWRA\"], \"Hand\": [\"RH1\", \"RH3\", \"RH6\"], \"R1D1\": [\"RTH1\"], \"R1D2\": [\"RTH2\"], \"R1D3\": [\"RTH3\", \"RTH3P\", \"RTH4\"], \"R2D1\": [\"RH2\"], \"R2D2\": [\"RIF1\"], \"R2D3\": [\"RIF2\", \"RIF3\"], \"R3D2\": [\"RTF1\"], \"R3D3\": [\"RTF2\", \"RTF3\"], \"R4D1\": [\"RH4\", \"RRF1\"], \"R4D2\": [\"RRF2\"], \"R4D3\": [\"RRF3\", \"RRF4\"], \"R5D1\": [\"RH5\"], \"R5D2\": [\"RPF1\"], \"R5D3\": [\"RPF2\", \"RPF3\"]}, \"sensorTriggered\": true}";
[Space()]
Expand All @@ -43,7 +45,7 @@ public class CustomSubjectScript : MonoBehaviour
/// Callback after all data is processed and skeleton is set.
/// Called even if skeleton is not driven by the subject script.
/// </summary>
public event System.Action<Dictionary<string, Transform>> PostTransformCallback;
public event Action<Dictionary<string, Transform>> PostTransformCallback;

/// <summary>
/// Flag indicating if subject is hidden.
Expand Down Expand Up @@ -77,7 +79,7 @@ public class CustomSubjectScript : MonoBehaviour
private StreamWriter finalWriter;
private StreamWriter rawWriter;
private string rawData;

private FusionService CoordinateUtils;
private Data defaultDataObj;

private List<string> invalidMarkers = new List<string>();
Expand Down Expand Up @@ -122,10 +124,7 @@ protected void LateUpdate()
{
if (subjectDataManager.UseDefaultData)
{
if (defaultDataObj == null)
{
defaultDataObj = JsonConvert.DeserializeObject<Data>(defaultData);
}
defaultDataObj ??= JsonConvert.DeserializeObject<Data>(defaultData);
ProcessData(defaultDataObj, defaultData);
}
else
Expand Down
4 changes: 0 additions & 4 deletions Assets/Scripts/ViconNexusUnityStream/SubjectDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public bool UseDefaultData
/// Enable writing data to disk.
/// </summary>
public bool EnableWriteData { get => enableWriteData; set => enableWriteData = value; }

public Dictionary<string, Data> StreamedData => data;
public Dictionary<string, string> StreamedRawData => rawData;

public IViconClient ViconClient => viconClient;

[SerializeField] private ClientConfigArgs clientConfig;
Expand Down Expand Up @@ -71,9 +69,7 @@ private void OnEnable()
private void LateUpdate()
{
if (!isConnected)
{
return;
}
viconClient.GetNewFrame();
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

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

69 changes: 69 additions & 0 deletions Assets/Scripts/WebSockets/Samples~/WebSocketExample/Connection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using NativeWebSocket;

public class Connection : MonoBehaviour
{
WebSocket websocket;

// Start is called before the first frame update
async void Start()
{
// websocket = new WebSocket("ws://echo.websocket.org");
websocket = new WebSocket("ws://localhost:3000");

websocket.OnOpen += () =>
{
Debug.Log("Connection open!");
};

websocket.OnError += (e) =>
{
Debug.Log("Error! " + e);
};

websocket.OnClose += (e) =>
{
Debug.Log("Connection closed!");
};

websocket.OnMessage += (bytes) =>
{
// Reading a plain text message
var message = System.Text.Encoding.UTF8.GetString(bytes);
Debug.Log("Received OnMessage! (" + bytes.Length + " bytes) " + message);
};

// Keep sending messages at every 0.3s
InvokeRepeating("SendWebSocketMessage", 0.0f, 0.3f);

await websocket.Connect();
}

void Update()
{
#if !UNITY_WEBGL || UNITY_EDITOR
websocket.DispatchMessageQueue();
#endif
}

async void SendWebSocketMessage()
{
if (websocket.State == WebSocketState.Open)
{
// Sending bytes
await websocket.Send(new byte[] { 10, 20, 30 });

// Sending plain text
await websocket.SendText("plain text message");
}
}

private async void OnApplicationQuit()
{
await websocket.Close();
}
}

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

Loading

0 comments on commit aa37dd8

Please sign in to comment.