Skip to content

Commit

Permalink
VirtualLens2の設定値をOSCから読み出す
Browse files Browse the repository at this point in the history
  • Loading branch information
m-hayabusa committed Sep 16, 2024
1 parent e5bc80c commit 881ab7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
43 changes: 38 additions & 5 deletions VRCImageHelper/Core/StateChecker/VirtualLens2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public VirtualLens2State()
FocalLength = ConfigManager.VirtualLens2.FocalLengthDefault;
ApertureValue = ConfigManager.VirtualLens2.ApertureDefault;
ExposureBias = ConfigManager.VirtualLens2.ExposureDefault;
FocalLengthMin = ConfigManager.VirtualLens2.FocalLengthMin;
FocalLengthMax = ConfigManager.VirtualLens2.FocalLengthMax;
ApertureMin = ConfigManager.VirtualLens2.ApertureMin;
ApertureMax = ConfigManager.VirtualLens2.ApertureMax;
ExposureRange = ConfigManager.VirtualLens2.ExposureRange;
}
public VirtualLens2State(VirtualLens2State virtualLens2State)
{
Expand All @@ -19,6 +24,11 @@ public VirtualLens2State(VirtualLens2State virtualLens2State)
public float ApertureValue { get; set; }
public float ExposureBias { get; set; }
public bool Enabled { get; set; }
public float FocalLengthMin { get; set; }
public float FocalLengthMax { get; set; }
public float ApertureMin { get; set; }
public float ApertureMax { get; set; }
public float ExposureRange { get; set; }
}

internal static class VirtualLens2
Expand All @@ -39,6 +49,29 @@ public static List<string> Publish(VirtualLens2State state)
}
return args;
}
public static void Initialize(object sender, OscEventArgs e)
{
if (e.Path == "/avatar/parameters/VirtualLens2_Zoom_Min")
{
State.Current.VirtualLens2.FocalLengthMin = float.Parse(e.Data.Trim()[..^1]);
}
else if (e.Path == "/avatar/parameters/VirtualLens2_Zoom_Max")
{
State.Current.VirtualLens2.FocalLengthMax = float.Parse(e.Data.Trim()[..^1]);
}
else if (e.Path == "/avatar/parameters/VirtualLens2_Aperture_Min")
{
State.Current.VirtualLens2.ApertureMin = float.Parse(e.Data.Trim()[..^1]);
}
else if (e.Path == "/avatar/parameters/VirtualLens2_Aperture_Max")
{
State.Current.VirtualLens2.ApertureMax = float.Parse(e.Data.Trim()[..^1]);
}
else if (e.Path == "/avatar/parameters/VirtualLens2_Exposure_Range")
{
State.Current.VirtualLens2.ExposureRange = float.Parse(e.Data.Trim()[..^1]);
}
}
public static void Enable(object sender, OscEventArgs e)
{
if (e.Path == "/avatar/parameters/VirtualLens2_Enable")
Expand All @@ -52,8 +85,8 @@ public static void Zoom(object sender, OscEventArgs e)
if (e.Path == "/avatar/parameters/VirtualLens2_Zoom")
{
var raw = float.Parse(e.Data.Trim()[..^1]);
var min = ConfigManager.VirtualLens2.FocalLengthMin;
var max = ConfigManager.VirtualLens2.FocalLengthMax;
var min = State.Current.VirtualLens2.FocalLengthMin;
var max = State.Current.VirtualLens2.FocalLengthMax;
State.Current.VirtualLens2.FocalLength = min * MathF.Exp(raw * MathF.Log(max / min));
}
}
Expand All @@ -63,8 +96,8 @@ public static void Aperture(object sender, OscEventArgs e)
if (e.Path == "/avatar/parameters/VirtualLens2_Aperture")
{
var raw = float.Parse(e.Data.Trim()[..^1]);
var min = ConfigManager.VirtualLens2.ApertureMin;
var max = ConfigManager.VirtualLens2.ApertureMax;
var min = State.Current.VirtualLens2.ApertureMin;
var max = State.Current.VirtualLens2.ApertureMax;
if (raw == 0)
State.Current.VirtualLens2.ApertureValue = float.PositiveInfinity;
else
Expand All @@ -76,7 +109,7 @@ public static void Exposure(object sender, OscEventArgs e)
if (e.Path == "/avatar/parameters/VirtualLens2_Exposure")
{
var raw = float.Parse(e.Data.Trim()[..^1]);
State.Current.VirtualLens2.ExposureBias = (2 * raw - 1) * ConfigManager.VirtualLens2.ExposureRange;
State.Current.VirtualLens2.ExposureBias = (2 * raw - 1) * State.Current.VirtualLens2.ExposureRange;
}
}
}
1 change: 1 addition & 0 deletions VRCImageHelper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ private static void Background()

oscServer.Received += VRChat.ChangeAvater;

oscServer.Received += VirtualLens2.Initialize;
oscServer.Received += VirtualLens2.Enable;
oscServer.Received += VirtualLens2.Zoom;
oscServer.Received += VirtualLens2.Aperture;
Expand Down

0 comments on commit 881ab7c

Please sign in to comment.