From 244e75a238e845ce2cba61d0bf1c1887666f847f Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 28 Jun 2026 16:16:54 +0900 Subject: [PATCH] =?UTF-8?q?Transform=E6=9B=B8=E3=81=8D=E6=88=BB=E3=81=97?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AE=E5=85=B1=E9=80=9A=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/AviUtlScriptContext.cs | 42 ++++++++++++++++++++++++++ LuaScript/Engine/NativeFieldMap.cs | 47 +++++++----------------------- LuaScript/LuaScriptEngine.cs | 44 +++++++--------------------- 3 files changed, 64 insertions(+), 69 deletions(-) diff --git a/LuaScript/AviUtlScriptContext.cs b/LuaScript/AviUtlScriptContext.cs index 53f7cf1..fd36bcf 100644 --- a/LuaScript/AviUtlScriptContext.cs +++ b/LuaScript/AviUtlScriptContext.cs @@ -52,6 +52,8 @@ namespace LuaScript public Func? ResolverProvider { get; set; } + private const double Epsilon = 1e-10; + private readonly List _objectQueries = []; public IReadOnlyList ObjectQueries => _objectQueries; @@ -133,6 +135,46 @@ namespace LuaScript return false; } + public void ApplyWriteBack( + double newSx, double newSy, double newZoom, double newAspect, + double newRx, double newRy, double newRz, + double newRxr, double newRyr, double newRzr) + { + double initialSx = Sx; + double initialSy = Sy; + double initialZoom = Zoom; + double initialAspect = Aspect; + + Sx = newSx; + Sy = newSy; + Zoom = newZoom; + Aspect = newAspect; + + bool sxsyChanged = Math.Abs(Sx - initialSx) > Epsilon || Math.Abs(Sy - initialSy) > Epsilon; + bool zoomAspectChanged = Math.Abs(Zoom - initialZoom) > Epsilon || Math.Abs(Aspect - initialAspect) > Epsilon; + + if (zoomAspectChanged && !sxsyChanged) + { + Sx = Zoom * (1.0 + Aspect); + Sy = Zoom * (1.0 - Aspect); + } + + double initialRxr = RxRad; + Rx = Math.Abs(newRxr - initialRxr) > Epsilon + ? newRxr * (180d / Math.PI) + : newRx; + + double initialRyr = RyRad; + Ry = Math.Abs(newRyr - initialRyr) > Epsilon + ? newRyr * (180d / Math.PI) + : newRy; + + double initialRzr = RzRad; + Rz = Math.Abs(newRzr - initialRzr) > Epsilon + ? newRzr * (180d / Math.PI) + : newRz; + } + public unsafe (double r, double g, double b, double a) GetPixel(int x, int y) { EnsurePixelBuffer(); diff --git a/LuaScript/Engine/NativeFieldMap.cs b/LuaScript/Engine/NativeFieldMap.cs index 12a561c..223eee5 100644 --- a/LuaScript/Engine/NativeFieldMap.cs +++ b/LuaScript/Engine/NativeFieldMap.cs @@ -78,42 +78,17 @@ namespace LuaScript.Engine ctx.Oz = f[NativeProtocol.Oz]; ctx.Alpha = f[NativeProtocol.Alpha]; - double initialSx = ctx.Sx; - double initialSy = ctx.Sy; - double initialZoom = ctx.Zoom; - double initialAspect = ctx.Aspect; - - ctx.Sx = f[NativeProtocol.Sx]; - ctx.Sy = f[NativeProtocol.Sy]; - ctx.Zoom = f[NativeProtocol.Zoom]; - ctx.Aspect = f[NativeProtocol.Aspect]; - - bool sxsyChanged = Math.Abs(ctx.Sx - initialSx) > Epsilon || Math.Abs(ctx.Sy - initialSy) > Epsilon; - bool zoomAspectChanged = Math.Abs(ctx.Zoom - initialZoom) > Epsilon || Math.Abs(ctx.Aspect - initialAspect) > Epsilon; - - if (zoomAspectChanged && !sxsyChanged) - { - ctx.Sx = ctx.Zoom * (1.0 + ctx.Aspect); - ctx.Sy = ctx.Zoom * (1.0 - ctx.Aspect); - } - - double initialRxr = ctx.RxRad; - double rxrNew = f[NativeProtocol.Rxr]; - ctx.Rx = Math.Abs(rxrNew - initialRxr) > Epsilon - ? rxrNew * (180d / Math.PI) - : f[NativeProtocol.Rx]; - - double initialRyr = ctx.RyRad; - double ryrNew = f[NativeProtocol.Ryr]; - ctx.Ry = Math.Abs(ryrNew - initialRyr) > Epsilon - ? ryrNew * (180d / Math.PI) - : f[NativeProtocol.Ry]; - - double initialRzr = ctx.RzRad; - double rzrNew = f[NativeProtocol.Rzr]; - ctx.Rz = Math.Abs(rzrNew - initialRzr) > Epsilon - ? rzrNew * (180d / Math.PI) - : f[NativeProtocol.Rz]; + ctx.ApplyWriteBack( + f[NativeProtocol.Sx], + f[NativeProtocol.Sy], + f[NativeProtocol.Zoom], + f[NativeProtocol.Aspect], + f[NativeProtocol.Rx], + f[NativeProtocol.Ry], + f[NativeProtocol.Rz], + f[NativeProtocol.Rxr], + f[NativeProtocol.Ryr], + f[NativeProtocol.Rzr]); } } } diff --git a/LuaScript/LuaScriptEngine.cs b/LuaScript/LuaScriptEngine.cs index c864dfa..b00ba47 100644 --- a/LuaScript/LuaScriptEngine.cs +++ b/LuaScript/LuaScriptEngine.cs @@ -573,39 +573,17 @@ namespace LuaScript ctx.Oz = _objTable.Get("oz").CastToNumber() ?? ctx.Oz; ctx.Alpha = _objTable.Get("alpha").CastToNumber() ?? ctx.Alpha; - double initialSx = ctx.Sx; - double initialSy = ctx.Sy; - double initialZoom = ctx.Zoom; - double initialAspect = ctx.Aspect; - - ctx.Sx = _objTable.Get("sx").CastToNumber() ?? ctx.Sx; - ctx.Sy = _objTable.Get("sy").CastToNumber() ?? ctx.Sy; - ctx.Zoom = _objTable.Get("zoom").CastToNumber() ?? ctx.Zoom; - ctx.Aspect = _objTable.Get("aspect").CastToNumber() ?? ctx.Aspect; - - bool sxsyChanged = Math.Abs(ctx.Sx - initialSx) > 1e-10 || Math.Abs(ctx.Sy - initialSy) > 1e-10; - bool zoomAspectChanged = Math.Abs(ctx.Zoom - initialZoom) > 1e-10 || Math.Abs(ctx.Aspect - initialAspect) > 1e-10; - - if (zoomAspectChanged && !sxsyChanged) - { - ctx.Sx = ctx.Zoom * (1.0 + ctx.Aspect); - ctx.Sy = ctx.Zoom * (1.0 - ctx.Aspect); - } - - double rxrNew = _objTable.Get("rxr").CastToNumber() ?? ctx.RxRad; - ctx.Rx = Math.Abs(rxrNew - ctx.RxRad) > 1e-10 - ? rxrNew * (180d / Math.PI) - : _objTable.Get("rx").CastToNumber() ?? ctx.Rx; - - double ryrNew = _objTable.Get("ryr").CastToNumber() ?? ctx.RyRad; - ctx.Ry = Math.Abs(ryrNew - ctx.RyRad) > 1e-10 - ? ryrNew * (180d / Math.PI) - : _objTable.Get("ry").CastToNumber() ?? ctx.Ry; - - double rzrNew = _objTable.Get("rzr").CastToNumber() ?? ctx.RzRad; - ctx.Rz = Math.Abs(rzrNew - ctx.RzRad) > 1e-10 - ? rzrNew * (180d / Math.PI) - : _objTable.Get("rz").CastToNumber() ?? ctx.Rz; + ctx.ApplyWriteBack( + _objTable.Get("sx").CastToNumber() ?? ctx.Sx, + _objTable.Get("sy").CastToNumber() ?? ctx.Sy, + _objTable.Get("zoom").CastToNumber() ?? ctx.Zoom, + _objTable.Get("aspect").CastToNumber() ?? ctx.Aspect, + _objTable.Get("rx").CastToNumber() ?? ctx.Rx, + _objTable.Get("ry").CastToNumber() ?? ctx.Ry, + _objTable.Get("rz").CastToNumber() ?? ctx.Rz, + _objTable.Get("rxr").CastToNumber() ?? ctx.RxRad, + _objTable.Get("ryr").CastToNumber() ?? ctx.RyRad, + _objTable.Get("rzr").CastToNumber() ?? ctx.RzRad); } public void Dispose()