131 lines
4.8 KiB
C#
131 lines
4.8 KiB
C#
/*
|
|
godotVmcSharp
|
|
Copyright (C) 2023 Cassandra de la Cruz-Munoz
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
using System.Net;
|
|
using godotOscSharp;
|
|
using Godot;
|
|
|
|
#nullable enable
|
|
|
|
namespace godotVmcSharp
|
|
{
|
|
public class Marionette
|
|
{
|
|
private OscReceiver receiver;
|
|
private OscSender? sender;
|
|
private CameraReceiver cam;
|
|
private DeviceReceiver devices;
|
|
private DirectionalLightReceiver lights;
|
|
private Node3D node;
|
|
public Marionette(int port, Node3D node)
|
|
{
|
|
this.node = node;
|
|
receiver = new OscReceiver(port);
|
|
receiver.MessageReceived += (sender, e) =>
|
|
{
|
|
if (sender == null) {
|
|
sender = new OscSender(IPAddress.Parse(e.IPAddress), port);
|
|
}
|
|
GD.Print($"Received a message from {e.IPAddress}:{e.Port}");
|
|
ProcessMessage(e.Message);
|
|
};
|
|
receiver.ErrorReceived += (sender, e) =>
|
|
{
|
|
GD.Print($"Error: {e.ErrorMessage}");
|
|
};
|
|
devices = new DeviceReceiver();
|
|
lights = new DirectionalLightReceiver();
|
|
cam = new CameraReceiver(node.GetViewport().GetCamera3D());
|
|
}
|
|
private void ProcessMessage(OscMessage m)
|
|
{
|
|
switch (m.Address.ToString())
|
|
{
|
|
case "/VMC/Ext/OK":
|
|
VmcExtOk.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/T":
|
|
VmcExtT.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Root/Pos":
|
|
VmcExtRootPos.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Bone/Pos":
|
|
VmcExtBonePos.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Blend/Val":
|
|
VmcExtBlendVal.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Blend/Apply":
|
|
new VmcMessage(m.Address);
|
|
break;
|
|
case "/VMC/Ext/Cam":
|
|
this.cam.ProcessMessage(VmcExtCam.CreateFromMessage(m));
|
|
break;
|
|
case "/VMC/Ext/Con":
|
|
VmcExtCon.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Key":
|
|
VmcExtKey.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Midi/Note":
|
|
VmcExtMidiNote.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Midi/CC/Val":
|
|
VmcExtMidiCcVal.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Midi/CC/Bit":
|
|
VmcExtMidiCcBit.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Hmd/Pos":
|
|
case "/VMC/Ext/Con/Pos":
|
|
case "/VMC/Ext/Tra/Pos":
|
|
case "/VMC/Ext/Hmd/Pos/Local":
|
|
case "/VMC/Ext/Con/Pos/Local":
|
|
case "/VMC/Ext/Tra/Pos/Local":
|
|
this.devices.ProcessMessage(VmcExtDevicePos.CreateFromMessage(m));
|
|
break;
|
|
case "/VMC/Ext/Rcv":
|
|
VmcExtRcv.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Light":
|
|
this.lights.ProcessMessage(VmcExtLight.CreateFromMessage(m));
|
|
break;
|
|
case "/VMC/Ext/VRM":
|
|
VmcExtVrm.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Remote":
|
|
VmcExtRemote.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Opt":
|
|
VmcExtOpt.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Setting/Color":
|
|
VmcExtSettingColor.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Setting/Win":
|
|
VmcExtSettingWin.CreateFromMessage(m);
|
|
break;
|
|
case "/VMC/Ext/Config":
|
|
VmcExtConfig.CreateFromMessage(m);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|