2023-08-16 20:07:20 +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/>.
|
|
|
|
*/
|
|
|
|
|
2023-08-16 19:47:14 +02:00
|
|
|
using Godot;
|
|
|
|
using godotOscSharp;
|
|
|
|
|
|
|
|
namespace godotVmcSharp
|
|
|
|
{
|
|
|
|
public class VmcExtBlendVal : VmcMessage
|
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
public string Name { get; }
|
|
|
|
public float Value { get; }
|
|
|
|
public VmcExtBlendVal(OscMessage m) : base(m.Address)
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
if (m.Data.Count != 2)
|
|
|
|
{
|
2023-08-16 19:47:14 +02:00
|
|
|
GD.Print($"Invalid number of arguments for /VMC/Ext/Blend/Val. Expected 2, received {m.Data.Count}.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m.Data[0].Type != 's')
|
|
|
|
{
|
2023-08-18 00:22:27 +02:00
|
|
|
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[0].Type));
|
2023-08-16 19:47:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m.Data[1].Type != 'f')
|
|
|
|
{
|
2023-08-18 00:22:27 +02:00
|
|
|
GD.Print(InvalidArgumentType.GetErrorString(Addr, "value", 'f', m.Data[1].Type));
|
2023-08-16 19:47:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var blendShape = (string)m.Data[0].Value;
|
2023-08-17 20:48:26 +02:00
|
|
|
if (IsVrm0BlendShape(blendShape))
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
Name = blendShape;
|
|
|
|
Value = (float)m.Data[1].Value;
|
2023-08-16 19:47:14 +02:00
|
|
|
return;
|
2023-08-17 01:03:54 +02:00
|
|
|
}
|
2023-08-17 20:48:26 +02:00
|
|
|
if (IsVrm1Expression(blendShape))
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
Name = blendShape;
|
|
|
|
Value = (float)m.Data[1].Value;
|
2023-08-16 19:47:14 +02:00
|
|
|
return;
|
2023-08-17 01:03:54 +02:00
|
|
|
}
|
2023-08-17 20:48:26 +02:00
|
|
|
if (IsArkitBlendShape(blendShape))
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
Name = blendShape;
|
|
|
|
Value = (float)m.Data[1].Value;
|
2023-08-16 19:47:14 +02:00
|
|
|
return;
|
2023-08-17 01:03:54 +02:00
|
|
|
}
|
2023-08-18 00:22:27 +02:00
|
|
|
GD.Print($"Invalid argument for {Addr}. BlendShape \"{blendShape}\" not in list.");
|
2023-08-17 01:03:54 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 20:48:26 +02:00
|
|
|
public VmcExtBlendVal(string name, float value) : base(new OscAddress("VMC/Ext/Blend/Val"))
|
2023-08-17 01:03:54 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
if (IsVrm0BlendShape(name))
|
2023-08-16 19:47:14 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
Name = name;
|
|
|
|
Value = value;
|
2023-08-16 19:47:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-08-17 20:48:26 +02:00
|
|
|
if (IsVrm1Expression(name))
|
2023-08-17 01:03:54 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
Name = name;
|
|
|
|
Value = value;
|
2023-08-17 01:03:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-08-17 20:48:26 +02:00
|
|
|
if (IsArkitBlendShape(name))
|
2023-08-17 01:03:54 +02:00
|
|
|
{
|
2023-08-17 20:48:26 +02:00
|
|
|
Name = name;
|
|
|
|
Value = value;
|
2023-08-17 01:03:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-08-18 00:22:27 +02:00
|
|
|
GD.Print($"Invalid argument for {Addr}. BlendShape \"{name}\" not in list.");
|
2023-08-17 01:03:54 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 20:48:26 +02:00
|
|
|
private bool IsVrm0BlendShape(string name)
|
2023-08-17 01:03:54 +02:00
|
|
|
{
|
|
|
|
return name == "Joy" || name == "Angry" || name == "Sorrow" || name == "Fun" ||
|
|
|
|
name == "A" || name == "I" || name == "U" || name == "E" || name == "O" ||
|
|
|
|
name == "Blink_L" || name == "Blink_R";
|
|
|
|
}
|
|
|
|
|
2023-08-17 20:48:26 +02:00
|
|
|
private bool IsVrm1Expression(string name)
|
2023-08-17 01:03:54 +02:00
|
|
|
{
|
|
|
|
return name == "happy" || name == "angry" || name == "sad" || name == "relaxed" ||
|
|
|
|
name == "aa" || name == "ih" || name == "ou" || name == "ee" || name == "oh" ||
|
|
|
|
name == "blinkLeft" || name == "blinkRight";
|
|
|
|
}
|
|
|
|
|
2023-08-17 20:48:26 +02:00
|
|
|
private bool IsArkitBlendShape(string name)
|
2023-08-17 01:03:54 +02:00
|
|
|
{
|
|
|
|
return name == "browInnerUp" ||
|
|
|
|
name == "browDownLeft" || name == "browDownRight" ||
|
|
|
|
name == "browOuterUpLeft" || name == "browOuterUpRight" ||
|
|
|
|
name == "eyeLookUpLeft" || name == "eyeLookUpRight" ||
|
|
|
|
name == "eyeLookDownLeft" || name == "eyeLookDownRight" ||
|
|
|
|
name == "eyeLookInLeft" || name == "eyeLookInRight" ||
|
|
|
|
name == "eyeLookOutLeft" || name == "eyeLookOutRight" ||
|
|
|
|
name == "eyeBlinkLeft" || name == "eyeBlinkRight" ||
|
|
|
|
name == "eyeSquintLeft" || name == "eyeSquintRight" ||
|
|
|
|
name == "eyeWideLeft" || name == "eyeWideRight" ||
|
|
|
|
name == "cheekPuff" ||
|
|
|
|
name == "cheekSquintLeft" || name == "cheekSquintRight" ||
|
|
|
|
name == "noseSneerLeft" || name == "noseSneerRight" ||
|
|
|
|
name == "jawOpen" || name == "jawForward" ||
|
|
|
|
name == "jawLeft" || name == "jawRight" ||
|
|
|
|
name == "mouthFunnel" || name == "mouthPucker" ||
|
|
|
|
name == "mouthLeft" || name == "mouthRight" ||
|
|
|
|
name == "mouthRollUpper" || name == "mouthRollLower" ||
|
|
|
|
name == "mouthShrugUpper" || name == "mouthShrugLower" ||
|
|
|
|
name == "mouthClose" ||
|
|
|
|
name == "mouthSmileLeft" || name == "mouthSmileRight" ||
|
|
|
|
name == "mouthFrownLeft" || name == "mouthFrownRight" ||
|
|
|
|
name == "mouthDimpleLeft" || name == "mouthDimpleRight" ||
|
|
|
|
name == "mouthUpperUpLeft" || name == "mouthUpperUpRight" ||
|
|
|
|
name == "mouthLowerDownLeft" || name == "mouthLowerDownRight" ||
|
|
|
|
name == "mouthPressLeft" || name == "mouthPressRight" ||
|
|
|
|
name == "mouthStretchLeft" || name == "mouthStretchRight" ||
|
|
|
|
name == "tongueOut";
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
2023-08-17 20:48:26 +02:00
|
|
|
public new OscMessage ToMessage()
|
2023-08-17 01:09:41 +02:00
|
|
|
{
|
2023-08-18 00:22:27 +02:00
|
|
|
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument> {
|
2023-08-17 20:48:26 +02:00
|
|
|
new OscArgument(Name, 's'),
|
|
|
|
new OscArgument(Value, 'f')
|
|
|
|
});
|
2023-08-17 01:09:41 +02:00
|
|
|
}
|
2023-08-16 19:47:14 +02:00
|
|
|
}
|
|
|
|
}
|