From 8b590eb19125f7b59888524e9f3747df1ca7042e Mon Sep 17 00:00:00 2001 From: ppc Date: Wed, 10 Jul 2024 20:33:59 +0900 Subject: [PATCH] =?UTF-8?q?Drawable=E3=81=AE=E9=80=8F=E6=98=8E=E5=BA=A6?= =?UTF-8?q?=E7=AD=89=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=81=8C=E5=8F=8D=E6=98=A0?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E3=81=93=E3=81=A8=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=82=8B=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CubismDynamicDrawableData.Flags で透明度等のフラグが変更されるフレームと CubismModel.enabled が false になるフレームが同一フレームとなる場合、 CubismRenderController.OnDynamicDrawableData が呼ばれないため、Flags の消化がされない状態になる。 その後 CubismModel.enabled が true になると CubismRenderController.OnDynamicDrawableData の前に CubismDynamicDrawableData.Flags が更新されてしまうため フラグの消化が漏れるケースがあった。 今回の修正は CubismModel.enabled が true になったフレームで 未消化のフラグと or をとることでフラグが消化されるようにした。 --- Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs | 6 ++++-- Assets/Live2D/Cubism/Core/CubismDynamicDrawableData.cs | 2 +- Assets/Live2D/Cubism/Core/CubismTaskableModel.cs | 8 ++++---- .../Cubism/Core/Unmanaged/ByteExtensionMethods.cs | 10 ++++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs b/Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs index 56ac6b2..0273558 100644 --- a/Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs +++ b/Assets/Live2D/Cubism/Core/ArrayExtensionMethods.cs @@ -220,7 +220,8 @@ internal static void Revive(this CubismDrawable[] self, CubismUnmanagedModel mod /// /// Buffer to write to. /// Unmanaged model to read from. - internal static unsafe void ReadFrom(this CubismDynamicDrawableData[] self, CubismUnmanagedModel unmanagedModel) + /// force DidChange + internal static unsafe void ReadFrom(this CubismDynamicDrawableData[] self, CubismUnmanagedModel unmanagedModel, bool force) { // Get addresses. var drawables = unmanagedModel.Drawables; @@ -238,7 +239,8 @@ internal static unsafe void ReadFrom(this CubismDynamicDrawableData[] self, Cubi var data = self[i]; - data.Flags = flags[i]; + var newFlags = force ? (byte)(data.Flags.MaskDidChangeFlag() | flags[i]) : flags[i]; + data.Flags = newFlags; data.Opacity = opacities[i]; data.DrawOrder = drawOrders[i]; data.RenderOrder = renderOrders[i]; diff --git a/Assets/Live2D/Cubism/Core/CubismDynamicDrawableData.cs b/Assets/Live2D/Cubism/Core/CubismDynamicDrawableData.cs index 7247831..15d094f 100644 --- a/Assets/Live2D/Cubism/Core/CubismDynamicDrawableData.cs +++ b/Assets/Live2D/Cubism/Core/CubismDynamicDrawableData.cs @@ -51,7 +51,7 @@ internal static CubismDynamicDrawableData[] CreateData(CubismUnmanagedModel unma /// /// Dirty flags. /// - internal byte Flags { private get; set; } + internal byte Flags { get; set; } /// diff --git a/Assets/Live2D/Cubism/Core/CubismTaskableModel.cs b/Assets/Live2D/Cubism/Core/CubismTaskableModel.cs index 38ddbe9..b74ef78 100644 --- a/Assets/Live2D/Cubism/Core/CubismTaskableModel.cs +++ b/Assets/Live2D/Cubism/Core/CubismTaskableModel.cs @@ -266,7 +266,7 @@ public bool UpdateNow() // Run execution directly. - Execute(); + Execute(true); return true; @@ -301,7 +301,7 @@ public void ReleaseUnmanaged() /// /// Runs the task. /// - private void Execute() + private void Execute(bool force) { // Validate state. lock (Lock) @@ -315,7 +315,7 @@ private void Execute() // Get results. - DynamicDrawableData.ReadFrom(UnmanagedModel); + DynamicDrawableData.ReadFrom(UnmanagedModel, force); // Update state. @@ -349,7 +349,7 @@ private void OnReleaseUnmanaged() void ICubismTask.Execute() { - Execute(); + Execute(false); } #endregion diff --git a/Assets/Live2D/Cubism/Core/Unmanaged/ByteExtensionMethods.cs b/Assets/Live2D/Cubism/Core/Unmanaged/ByteExtensionMethods.cs index 73a8dd7..68aabd6 100644 --- a/Assets/Live2D/Cubism/Core/Unmanaged/ByteExtensionMethods.cs +++ b/Assets/Live2D/Cubism/Core/Unmanaged/ByteExtensionMethods.cs @@ -125,5 +125,15 @@ public static bool HasBlendColorDidChangeFlag(this byte self) return (self & (1 << 6)) == (1 << 6); } + /// + /// Mask DidChageFlag. without IsVisivble flag. + /// + /// + /// + public static byte MaskDidChangeFlag(this byte self) + { + return (byte)(self & ~(1 << 0)); + } + } }