Initial Commit
This commit is contained in:
commit
650fde3617
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
13
.idea/.idea.VRCOSCRouter/.idea/.gitignore
vendored
Normal file
13
.idea/.idea.VRCOSCRouter/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
/modules.xml
|
||||||
|
/contentModel.xml
|
||||||
|
/.idea.VRCOSCRouter.iml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
4
.idea/.idea.VRCOSCRouter/.idea/encodings.xml
Normal file
4
.idea/.idea.VRCOSCRouter/.idea/encodings.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
8
.idea/.idea.VRCOSCRouter/.idea/indexLayout.xml
Normal file
8
.idea/.idea.VRCOSCRouter/.idea/indexLayout.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/.idea.VRCOSCRouter/.idea/vcs.xml
Normal file
6
.idea/.idea.VRCOSCRouter/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
16
VRCOSCRouter.sln
Normal file
16
VRCOSCRouter.sln
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VRCOSCRouter", "VRCOSCRouter\VRCOSCRouter.csproj", "{5A903D10-304F-4348-901C-6B96893ADF72}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5A903D10-304F-4348-901C-6B96893ADF72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5A903D10-304F-4348-901C-6B96893ADF72}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5A903D10-304F-4348-901C-6B96893ADF72}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5A903D10-304F-4348-901C-6B96893ADF72}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
3
VRCOSCRouter.sln.DotSettings.user
Normal file
3
VRCOSCRouter.sln.DotSettings.user
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CGlax_005CRiderProjects_005CGlaxOSC_005CGlaxOSC_005Cbin_005CDebug_005Cnet7_002E0_005CGlaxOSC_002Edll/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005CGlax_005CRiderProjects_005Cvrc_002Doscquery_002Dlib_005Cvrc_002Doscquery_002Dlib_005Cbin_005CDebug_005Cnet6_002E0_005Cvrc_002Doscquery_002Dlib_002Edll/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
7
VRCOSCRouter/Endpoint.cs
Normal file
7
VRCOSCRouter/Endpoint.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace VRCOSCRouter;
|
||||||
|
|
||||||
|
public struct Endpoint(string vrcEndpoint, string programEndpoint, Type type)
|
||||||
|
{
|
||||||
|
public readonly string VrcEndpoint = vrcEndpoint, ProgramEndpoint = programEndpoint;
|
||||||
|
public readonly Type Type = type;
|
||||||
|
}
|
140
VRCOSCRouter/OSCProgram.cs
Normal file
140
VRCOSCRouter/OSCProgram.cs
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
using GlaxOSC;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using BuildSoft.OscCore;
|
||||||
|
|
||||||
|
namespace VRCOSCRouter;
|
||||||
|
|
||||||
|
public class OscProgram
|
||||||
|
{
|
||||||
|
public string ServiceName;
|
||||||
|
public readonly int SendPort;
|
||||||
|
public readonly int ReceivePort;
|
||||||
|
private readonly OSC _vrcOscClient;
|
||||||
|
private readonly OscServer _programOscReceiver;
|
||||||
|
private readonly OscClient _programOscSender;
|
||||||
|
public bool _keepRunning = true;
|
||||||
|
private readonly Thread _listenThread;
|
||||||
|
private const int UpdateInterval = 10;
|
||||||
|
private readonly ILogger? _logger;
|
||||||
|
internal readonly List<Endpoint> Endpoints;
|
||||||
|
|
||||||
|
public OscProgram(int sendPort, int receivePort, List<Endpoint> endpoints, string? serviceName = null, string ip = "127.0.0.1", ILogger? logger = null)
|
||||||
|
{
|
||||||
|
this._logger = logger;
|
||||||
|
this.ServiceName = serviceName ?? $"VRCOSCRouter_{RandomString(4)}";
|
||||||
|
|
||||||
|
this.Endpoints = endpoints;
|
||||||
|
|
||||||
|
this.SendPort = sendPort;
|
||||||
|
this.ReceivePort = receivePort;
|
||||||
|
this._vrcOscClient = new OSC(this.ServiceName, endpoints.ToDictionary(e => e.VrcEndpoint, e => e.Type), ip, sendPort, logger: logger);
|
||||||
|
|
||||||
|
_programOscReceiver = new OscServer(sendPort);
|
||||||
|
foreach (KeyValuePair<string, Type> endpoint in endpoints.ToDictionary(e => e.ProgramEndpoint, e=> e.Type))
|
||||||
|
this._programOscReceiver.TryAddMethod(endpoint.Key, values => HandleProgramOscMessage(endpoint.Key, endpoint.Value, values));
|
||||||
|
|
||||||
|
_programOscSender = new OscClient("127.0.0.1", this.ReceivePort);
|
||||||
|
this._vrcOscClient.OnParameterChangeEvent += HandleVrcOscMessage;
|
||||||
|
|
||||||
|
this._listenThread = new(Listen);
|
||||||
|
this._listenThread.Start();
|
||||||
|
|
||||||
|
this._logger?.LogInformation($"Started {this.ServiceName}." +
|
||||||
|
$"\n\tProgramSend: {this.SendPort}" +
|
||||||
|
$"\n\tProgramReceive: {this.ReceivePort}" +
|
||||||
|
$"\n\tVRCOSC-Port: {this._vrcOscClient.OSCPort}" +
|
||||||
|
$"\n\tEndpoints:\n\t\t{string.Join("\n\t\t", this.Endpoints.Select(e => $"({e.Type.Name}) {e.ProgramEndpoint} -> {e.VrcEndpoint}"))}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleVrcOscMessage(string endpoint, object? oldvalue, object? newvalue)
|
||||||
|
{
|
||||||
|
if (newvalue is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.Endpoints.All(e => e.VrcEndpoint != endpoint))
|
||||||
|
return;
|
||||||
|
string programEndpoint = this.Endpoints.First(e => e.VrcEndpoint == endpoint).ProgramEndpoint;
|
||||||
|
|
||||||
|
Type type = newvalue.GetType();
|
||||||
|
if (type == typeof(int))
|
||||||
|
this._programOscSender.Send(endpoint, (int)newvalue);
|
||||||
|
else if (type == typeof(long))
|
||||||
|
this._programOscSender.Send(endpoint, (long)newvalue);
|
||||||
|
else if (type == typeof(float))
|
||||||
|
this._programOscSender.Send(endpoint, (float)newvalue);
|
||||||
|
else if (type == typeof(double))
|
||||||
|
this._programOscSender.Send(endpoint, (double)newvalue);
|
||||||
|
else if (type == typeof(string))
|
||||||
|
this._programOscSender.Send(endpoint, (string)newvalue);
|
||||||
|
else if (type == typeof(char))
|
||||||
|
this._programOscSender.Send(endpoint, (char)newvalue);
|
||||||
|
else if (type == typeof(bool))
|
||||||
|
this._programOscSender.Send(endpoint, (bool)newvalue);
|
||||||
|
|
||||||
|
this._logger?.LogDebug($"[{this.ServiceName}] VRC '{endpoint}' - {newvalue} -> Program {programEndpoint}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleProgramOscMessage(string endpoint, Type type, OscMessageValues values)
|
||||||
|
{
|
||||||
|
if (this.Endpoints.All(e => e.ProgramEndpoint != endpoint))
|
||||||
|
return;
|
||||||
|
string vrcEndpoint = this.Endpoints.First(e => e.ProgramEndpoint == endpoint).VrcEndpoint;
|
||||||
|
|
||||||
|
object o = "fail";
|
||||||
|
if (type == typeof(int))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadIntElement(0));
|
||||||
|
o = values.ReadIntElement(0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(long))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadInt64Element(0));
|
||||||
|
o = values.ReadInt64Element(0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(float))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadFloatElement(0));
|
||||||
|
o = values.ReadFloatElement(0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(double))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadFloat64Element(0));
|
||||||
|
o = values.ReadFloat64Element(0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(string))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadStringElement(0));
|
||||||
|
o = values.ReadStringElement(0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(char))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadAsciiCharElement(0));
|
||||||
|
o = values.ReadAsciiCharElement(0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(bool))
|
||||||
|
{
|
||||||
|
this._vrcOscClient.Client.Send(vrcEndpoint, values.ReadBooleanElement(0));
|
||||||
|
o = values.ReadBooleanElement(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._logger?.LogDebug($"[{this.ServiceName}] Program '{endpoint}' - {o} -> VRC {vrcEndpoint}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Listen()
|
||||||
|
{
|
||||||
|
this._programOscReceiver.Start();
|
||||||
|
while (_keepRunning)
|
||||||
|
{
|
||||||
|
this._programOscReceiver.Update();
|
||||||
|
Thread.Sleep(UpdateInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string RandomString(int length)
|
||||||
|
{
|
||||||
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
var random = new Random();
|
||||||
|
return new string(Enumerable.Repeat(chars, length)
|
||||||
|
.Select(s => s[random.Next(s.Length)]).ToArray());
|
||||||
|
}
|
||||||
|
}
|
27
VRCOSCRouter/Program.cs
Normal file
27
VRCOSCRouter/Program.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using GlaxLogger;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using VRCOSCRouter;
|
||||||
|
|
||||||
|
Logger logger = new (LogLevel.Debug, consoleOut: Console.Out);
|
||||||
|
logger.LogInformation("Starting VRCOSCRouter...");
|
||||||
|
|
||||||
|
string[] files = Directory.GetFiles(Environment.CurrentDirectory, "*.json");
|
||||||
|
List<OscProgram> programs = new();
|
||||||
|
foreach (string filePath in files)
|
||||||
|
{
|
||||||
|
string fileContent = File.ReadAllText(filePath);
|
||||||
|
if(!fileContent.Contains("Name")
|
||||||
|
|| !fileContent.Contains("Ip")
|
||||||
|
|| !fileContent.Contains("SendPort")
|
||||||
|
|| !fileContent.Contains("ReceivePort")
|
||||||
|
|| !fileContent.Contains("Endpoints"))
|
||||||
|
continue;
|
||||||
|
ProgramInfo pi = JsonConvert.DeserializeObject<ProgramInfo>(fileContent);
|
||||||
|
programs.Add(new OscProgram(pi.SendPort, pi.ReceivePort, pi.Endpoints, pi.Name, pi.Ip, logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!Console.KeyAvailable && Console.ReadKey().Key != ConsoleKey.Escape)
|
||||||
|
Thread.Sleep(10);
|
8
VRCOSCRouter/ProgramInfo.cs
Normal file
8
VRCOSCRouter/ProgramInfo.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace VRCOSCRouter;
|
||||||
|
|
||||||
|
public struct ProgramInfo(string name, string ip, int sendPort, int receivePort, List<Endpoint> endpoints)
|
||||||
|
{
|
||||||
|
public string Name = name, Ip = ip;
|
||||||
|
public int SendPort = sendPort, ReceivePort = receivePort;
|
||||||
|
public List<Endpoint> Endpoints = endpoints;
|
||||||
|
}
|
27
VRCOSCRouter/VRCOSCRouter.csproj
Normal file
27
VRCOSCRouter/VRCOSCRouter.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="GlaxOSC">
|
||||||
|
<HintPath>..\..\GlaxOSC\GlaxOSC\bin\Debug\net7.0\GlaxOSC.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="vrc-oscquery-lib">
|
||||||
|
<HintPath>..\..\vrc-oscquery-lib\vrc-oscquery-lib\bin\Debug\net6.0\vrc-oscquery-lib.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="BuildSoft.OscCore" Version="1.2.1.1" />
|
||||||
|
<PackageReference Include="GlaxLogger" Version="1.0.7.2" />
|
||||||
|
<PackageReference Include="MeaMod.DNS" Version="1.0.70" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
33
examplePrograms/eyetrackvr.json
Normal file
33
examplePrograms/eyetrackvr.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"Name": "EyeTrackVR",
|
||||||
|
"Ip": "127.0.0.1",
|
||||||
|
"SendPort": 8000,
|
||||||
|
"ReceivePort": 8001,
|
||||||
|
"Endpoints": [
|
||||||
|
{
|
||||||
|
"VrcEndpoint": "/avatar/parameters/FT/v2/LeftEyeX",
|
||||||
|
"ProgramEndpoint": "/avatar/parameters/LeftEyeX",
|
||||||
|
"Type": "System.Single"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"VrcEndpoint": "/avatar/parameters/FT/v2/RightEyeX",
|
||||||
|
"ProgramEndpoint": "/avatar/parameters/RightEyeX",
|
||||||
|
"Type": "System.Single"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"VrcEndpoint": "/avatar/parameters/FT/v2/EyesY",
|
||||||
|
"ProgramEndpoint": "/avatar/parameters/EyesY",
|
||||||
|
"Type": "System.Single"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"VrcEndpoint": "/avatar/parameters/FT/v2/EyeLidLeft",
|
||||||
|
"ProgramEndpoint": "/avatar/parameters/LeftEyeLidExpandedSqueeze",
|
||||||
|
"Type": "System.Single"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"VrcEndpoint": "/avatar/parameters/FT/v2/EyeLidRight",
|
||||||
|
"ProgramEndpoint": "/avatar/parameters/RightEyeLidExpandedSqueeze",
|
||||||
|
"Type": "System.Single"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user