First Code Commit

This commit is contained in:
glax 2023-11-28 21:27:26 +01:00
parent d51fa829c1
commit 94b4754890
6 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View 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>

78
OSCCollar/OSCCollar.cs Normal file
View File

@ -0,0 +1,78 @@
using BuildSoft.OscCore;
namespace VRC_Console;
public class OSCCollar
{
private OscServer Server { get; init; }
private OscClient Client { get; init; }
private float _collarAngle, _collarStretch;
private const float StretchDeadzone = 0.1f;
private const float TurnDeadZone = 5f / 180f; //5 degrees
private DateTime _lastMessageSent = DateTime.UnixEpoch;
private bool _sendingMessage = false;
public OSCCollar()
{
this.Server = new OscServer(9001);
this.Client = new OscClient("127.0.0.1", 9000);
this._collarAngle = 0;
this._collarStretch = 0;
Server.TryAddMethodPair("/avatar/parameters/Collar_Angle", CollarAngleHandle, HandleCollarChange);
Server.TryAddMethodPair("/avatar/parameters/Collar_Stretch", CollarStretchHandle, HandleCollarChange);
Thread sendNullInputThread = new Thread(SendNullInput);
sendNullInputThread.Start();
}
private void CollarAngleHandle(OscMessageValues messageValues)
{
this._collarAngle = messageValues.ReadFloatElement(0);
}
private void CollarStretchHandle(OscMessageValues messageValues)
{
this._collarStretch = messageValues.ReadFloatElement(0);
}
private void SendNullInput()
{
while (true)
{
if (!_sendingMessage)
{
this.Client.Send("/input/Vertical", 0f);
this.Client.Send("/input/LookHorizontal", 0f);
this._lastMessageSent = DateTime.Now;
}
Thread.Sleep(400);
}
}
private static readonly TimeSpan MessageTimeoutSpan = TimeSpan.FromMilliseconds(10);
private void HandleCollarChange()
{
_sendingMessage = true;
TimeSpan messageTimeout = _lastMessageSent.Add(MessageTimeoutSpan).Subtract(DateTime.Now);
if(messageTimeout > TimeSpan.FromMilliseconds(0))
Thread.Sleep(messageTimeout);
if (this._collarStretch > StretchDeadzone)
this.Client.Send("/input/Vertical", this._collarStretch);
else
this.Client.Send("/input/Vertical", 0f);
if (Math.Abs(this._collarAngle) > TurnDeadZone)
this.Client.Send("/input/LookHorizontal", CalculateTurnPower(this._collarAngle));
else
this.Client.Send("/input/LookHorizontal", 0f);
_sendingMessage = false;
}
private const float MaxAngle = 180f;
private const float MaxPower = 0.5f;
private static float CalculateTurnPower(float boneAngle)
{
return (boneAngle / MaxAngle) * MaxPower;
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>VRC_Console</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BuildSoft.OscCore" Version="1.2.1.1" />
</ItemGroup>
</Project>

View File

@ -1,8 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSCCollar", "OSCCollar\OSCCollar.csproj", "{1D3DEA0F-4D6A-473D-AD77-834F4BC6FB02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1D3DEA0F-4D6A-473D-AD77-834F4BC6FB02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D3DEA0F-4D6A-473D-AD77-834F4BC6FB02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D3DEA0F-4D6A-473D-AD77-834F4BC6FB02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D3DEA0F-4D6A-473D-AD77-834F4BC6FB02}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View 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:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OSC/@EntryIndexedValue">OSC</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deadzone/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>