2023-08-16 19:47:14 +02:00
|
|
|
/*
|
|
|
|
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;
|
2023-09-24 18:26:52 +02:00
|
|
|
using godotOscSharp;
|
2023-08-16 19:47:14 +02:00
|
|
|
using Godot;
|
|
|
|
|
2023-10-21 15:15:37 +02:00
|
|
|
#nullable enable
|
|
|
|
|
2023-08-16 19:47:14 +02:00
|
|
|
namespace godotVmcSharp
|
|
|
|
{
|
|
|
|
public class Marionette
|
|
|
|
{
|
2023-09-24 18:26:52 +02:00
|
|
|
private OscReceiver receiver;
|
2023-10-21 15:15:37 +02:00
|
|
|
private OscSender? sender;
|
2023-09-24 18:26:52 +02:00
|
|
|
private CameraReceiver cam;
|
|
|
|
private DeviceReceiver devices;
|
|
|
|
private DirectionalLightReceiver lights;
|
2023-10-20 16:05:54 +02:00
|
|
|
private Node3D node;
|
|
|
|
public Marionette(int port, Node3D node)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
2023-10-20 16:05:54 +02:00
|
|
|
this.node = node;
|
2023-09-24 18:26:52 +02:00
|
|
|
receiver = new OscReceiver(port);
|
2023-08-16 19:47:14 +02:00
|
|
|
receiver.MessageReceived += (sender, e) =>
|
|
|
|
{
|
|
|
|
if (sender == null) {
|
2023-09-24 18:26:52 +02:00
|
|
|
sender = new OscSender(IPAddress.Parse(e.IPAddress), port);
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
|
|
|
GD.Print($"Received a message from {e.IPAddress}:{e.Port}");
|
|
|
|
ProcessMessage(e.Message);
|
|
|
|
};
|
|
|
|
receiver.ErrorReceived += (sender, e) =>
|
|
|
|
{
|
|
|
|
GD.Print($"Error: {e.ErrorMessage}");
|
|
|
|
};
|
2023-09-24 18:26:52 +02:00
|
|
|
devices = new DeviceReceiver();
|
|
|
|
lights = new DirectionalLightReceiver();
|
2023-10-20 16:05:54 +02:00
|
|
|
cam = new CameraReceiver(node.GetViewport().GetCamera3D());
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
2023-09-24 18:26:52 +02:00
|
|
|
private void ProcessMessage(OscMessage m)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
|
|
|
switch (m.Address.ToString())
|
|
|
|
{
|
|
|
|
case "/VMC/Ext/OK":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtOk.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/T":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtT.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Root/Pos":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtRootPos.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Bone/Pos":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtBonePos.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Blend/Val":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtBlendVal.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Blend/Apply":
|
|
|
|
new VmcMessage(m.Address);
|
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Cam":
|
2023-10-21 15:15:37 +02:00
|
|
|
this.cam.ProcessMessage(VmcExtCam.CreateFromMessage(m));
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Con":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtCon.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Key":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtKey.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Midi/Note":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtMidiNote.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Midi/CC/Val":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtMidiCcVal.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
|
|
|
case "/VMC/Ext/Midi/CC/Bit":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtMidiCcBit.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
2023-08-16 19:52:35 +02:00
|
|
|
case "/VMC/Ext/Hmd/Pos":
|
2023-08-16 19:55:42 +02:00
|
|
|
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":
|
2023-10-21 15:15:37 +02:00
|
|
|
this.devices.ProcessMessage(VmcExtDevicePos.CreateFromMessage(m));
|
2023-08-16 19:55:42 +02:00
|
|
|
break;
|
2023-08-16 19:47:14 +02:00
|
|
|
case "/VMC/Ext/Rcv":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtRcv.CreateFromMessage(m);
|
2023-08-16 19:47:14 +02:00
|
|
|
break;
|
2023-08-16 20:35:37 +02:00
|
|
|
case "/VMC/Ext/Light":
|
2023-10-21 15:15:37 +02:00
|
|
|
this.lights.ProcessMessage(VmcExtLight.CreateFromMessage(m));
|
2023-08-16 20:35:37 +02:00
|
|
|
break;
|
2023-08-16 20:42:04 +02:00
|
|
|
case "/VMC/Ext/VRM":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtVrm.CreateFromMessage(m);
|
2023-08-16 20:41:23 +02:00
|
|
|
break;
|
2023-08-16 20:44:45 +02:00
|
|
|
case "/VMC/Ext/Remote":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtRemote.CreateFromMessage(m);
|
2023-08-16 20:44:45 +02:00
|
|
|
break;
|
2023-08-16 20:59:29 +02:00
|
|
|
case "/VMC/Ext/Opt":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtOpt.CreateFromMessage(m);
|
2023-08-16 20:58:58 +02:00
|
|
|
break;
|
2023-08-16 21:03:41 +02:00
|
|
|
case "/VMC/Ext/Setting/Color":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtSettingColor.CreateFromMessage(m);
|
2023-08-16 21:03:41 +02:00
|
|
|
break;
|
2023-08-16 21:08:12 +02:00
|
|
|
case "/VMC/Ext/Setting/Win":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtSettingWin.CreateFromMessage(m);
|
2023-08-16 21:08:12 +02:00
|
|
|
break;
|
2023-08-16 21:26:36 +02:00
|
|
|
case "/VMC/Ext/Config":
|
2023-10-21 15:15:37 +02:00
|
|
|
VmcExtConfig.CreateFromMessage(m);
|
2023-08-16 21:26:36 +02:00
|
|
|
break;
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|