From 881ab7c822e8e3288f457be9b54ddbb703324c7c Mon Sep 17 00:00:00 2001 From: m-hayabusa Date: Mon, 16 Sep 2024 12:09:56 +0900 Subject: [PATCH] =?UTF-8?q?VirtualLens2=E3=81=AE=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E5=80=A4=E3=82=92OSC=E3=81=8B=E3=82=89=E8=AA=AD=E3=81=BF?= =?UTF-8?q?=E5=87=BA=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/StateChecker/VirtualLens2.cs | 43 ++++++++++++++++--- VRCImageHelper/Program.cs | 1 + 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/VRCImageHelper/Core/StateChecker/VirtualLens2.cs b/VRCImageHelper/Core/StateChecker/VirtualLens2.cs index 92b666f..d23a48b 100644 --- a/VRCImageHelper/Core/StateChecker/VirtualLens2.cs +++ b/VRCImageHelper/Core/StateChecker/VirtualLens2.cs @@ -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) { @@ -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 @@ -39,6 +49,29 @@ public static List 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") @@ -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)); } } @@ -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 @@ -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; } } } diff --git a/VRCImageHelper/Program.cs b/VRCImageHelper/Program.cs index 48698ac..cc677d5 100644 --- a/VRCImageHelper/Program.cs +++ b/VRCImageHelper/Program.cs @@ -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;