コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
c8350161db
|
||
|
|
679cab03b5
|
||
|
|
6783146231
|
||
|
|
df303ee154
|
||
|
|
f49bd740a0
|
||
|
|
80d1b75227
|
||
|
|
d7f981c38a
|
||
|
|
df0c63a270
|
||
|
|
7766b116dc
|
||
|
|
eb8f4e8055
|
||
|
|
04563a7242
|
||
|
|
875d954520
|
||
|
|
bd7f2ae691
|
||
|
|
36b3c880fe
|
||
|
|
230e6f010c
|
||
|
|
ef16ae64fb
|
検索条件に一致するファイルはありません
+36
-32
@@ -1,50 +1,54 @@
|
||||
# v1.5.0 - Lua スクリプト for YMM4
|
||||
# v1.7.0 - Lua スクリプト for YMM4
|
||||
|
||||
AviUtl のアニメーション効果スクリプト互換層に**図形描画(`obj.load("figure")`)**を
|
||||
追加したリリースです。スクリプトから円・四角形・三角形などの図形を生成し、
|
||||
オブジェクトの画像として描画できるようになりました。
|
||||
AviUtl のアニメーション効果スクリプト互換層に**映像エフェクトの適用(`obj.effect()`)**を
|
||||
追加したリリースです。スクリプトから YMM4 に登録された映像エフェクトを呼び出し、
|
||||
図形やピクセルで生成した画像へ連鎖適用できるようになりました。
|
||||
|
||||
---
|
||||
|
||||
## 新機能
|
||||
|
||||
### 1. obj.load("figure") による図形描画
|
||||
### 1. obj.effect() による YMM4 映像エフェクトの適用
|
||||
|
||||
`obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])` を実装しました。
|
||||
指定した図形を生成してオブジェクトのバッファを置き換え、図形そのものを描画します。
|
||||
`obj.effect(エフェクト名, パラメータ名, 値, パラメータ名, 値, ...)` を実装しました。
|
||||
スクリプトが生成した画像に対して、YMM4 の映像エフェクトを適用します。
|
||||
|
||||
- 対応図形: 円・四角形・三角形・五角形・六角形・星形(英語名 circle / rect /
|
||||
triangle / pentagon / hexagon / star も使用可)
|
||||
- 塗りつぶしとライン(中抜き)に対応します。`ライン` を省略するか 0 を指定すると
|
||||
塗りつぶし、サイズ以上の値を指定した場合も塗りつぶしになります。
|
||||
- `アスペクト`(-1.0〜1.0)で幅・高さを歪曲できます。正で横幅、負で縦幅が縮みます。
|
||||
- 図形は SDF ベースのアンチエイリアスで描画されます。出力は図形サイズに合わせて
|
||||
生成され、オブジェクトの中心に配置されます。
|
||||
|
||||
描画系 API(`obj.load` / `obj.draw` / `obj.effect` / `obj.setoption` /
|
||||
`obj.copybuffer`)を含むスクリプトは、図形バッファモデルを持つ従来エンジン
|
||||
(MoonSharp)へ自動的に振り分けられます。
|
||||
- エフェクト名は YMM4 の登録名または別名で指定します。`EffectFactories` から取得できる
|
||||
全映像エフェクト(標準エフェクトおよびユーザー製プラグインを含む)が対象です。
|
||||
- パラメータは表示名またはプロパティ名で指定します。型に応じて設定され、Animation は
|
||||
定数値、真偽値、列挙(名前または番号)、色(0xRRGGBB)、数値、文字列に対応します。
|
||||
- パラメータはキー/値のペアで複数同時に指定できます。
|
||||
- `obj.effect` を複数回呼び出すと、呼んだ順に**独立したエフェクトインスタンス**として
|
||||
連鎖適用されます。同じエフェクトを複数回重ねて適用することもできます。
|
||||
- エフェクトは、スクリプトが生成した画像(図形やピクセル)または入力画像に対して、
|
||||
YMM4 本体と同じ `SetInput` → `Update` → `Output` のチェーンで適用されます。
|
||||
- パラメータはフレームごとに再評価されるため、`obj.time` などに応じて値を計算すれば
|
||||
エフェクトのパラメータをアニメーションさせられます。
|
||||
|
||||
---
|
||||
|
||||
## 注意事項
|
||||
|
||||
- 本リリースで実装されているのは `obj.load("figure", ...)` のみです。画像ファイルや
|
||||
"text"・"tempbuffer"・"movie" などの読み込み、`obj.draw` / `obj.drawpoly` による
|
||||
合成、`obj.effect` / `obj.setoption` / `obj.copybuffer` / `obj.setfont` には
|
||||
対応していません。これらを呼び出すスクリプトは意図どおりには動作しません。
|
||||
- 図形のサイズに `obj.track0` 等を用いる場合、Track0〜Track3 のスライダー範囲は
|
||||
-100〜100 で、AviUtl ヘッダの範囲・既定値は UI へ反映されません。より大きな図形が
|
||||
必要な場合は数値欄へ直接入力するか、サイズを直接記述してください。
|
||||
- `obj.effect`(および `obj.load`)は描画系 API のため MoonSharp エンジンで実行されます。
|
||||
ネイティブ(LuaJIT)経路ではエフェクトは適用されません。
|
||||
- エフェクトの登録名はローカライズされるため、指定名は実行環境の表示言語に依存する
|
||||
場合があります。言語に依存させたくない場合は、英語の別名やプロパティ名を用いて
|
||||
ください。
|
||||
- Animation パラメータは定数値として設定されます。キーフレーム曲線は指定できません。
|
||||
時間変化させたい場合はスクリプト側で値を計算してください。
|
||||
- 指定したエフェクトが見つからない、または生成・更新に失敗した場合、その要求は安全に
|
||||
スキップされ、画像はそのまま通過します。描画は停止しません。
|
||||
- 対象エフェクトの解決は導入状況に依存します。ユーザー製エフェクトは未導入の場合、
|
||||
名前が解決されずスキップされます。
|
||||
|
||||
---
|
||||
|
||||
## 内部実装
|
||||
|
||||
- SDF(符号付き距離場)による1パス・アンチエイリアスの図形ラスタライザを追加し、
|
||||
プリマルチプライド BGRA バッファを生成します。
|
||||
- スクリプト実行コンテキストにバッファ置換 API を追加し、`obj.load` が入力画像を
|
||||
図形バッファへ差し替えられるようにしました。出力経路は置換後のサイズで生成し、
|
||||
図形を原点中心に配置します。
|
||||
- 図形ごとの被覆・色・サイズのユニットテスト、および描画系スクリプトのエンジン
|
||||
振り分けテストを追加しました。
|
||||
- スクリプトの `obj.effect` 呼び出しを実行コンテキストに記録し、スクリプト実行後に
|
||||
描画スレッドで Direct2D エフェクトチェーンとして適用する仕組みを追加しました。
|
||||
- `EffectFactories.VideoEffectFactories` を登録名・別名で索引し、リフレクションで
|
||||
対象プロパティを解決してパラメータを設定します。
|
||||
- YMM4 の API 変更に対する多層フォールバックを実装しました。レジストリ構築、
|
||||
パラメータ解決、各エフェクトの生成・更新・適用をそれぞれ例外隔離し、失敗時は
|
||||
当該エフェクトをスキップして元画像を通過させます(描画自体は停止しません)。
|
||||
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
Luaスクリプト for YMM4 v1.5.0
|
||||
Luaスクリプト for YMM4 v1.7.0
|
||||
========================================
|
||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
||||
ピクセルを直接制御できるプラグインです。
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using LuaScript.Compat;
|
||||
|
||||
namespace LuaScript.Tests
|
||||
{
|
||||
public class AviUtlParameterLayoutTests
|
||||
{
|
||||
[Fact]
|
||||
public void NoDirectives_HasAnyIsFalse()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("obj.x = 1\nobj.y = 2");
|
||||
Assert.False(layout.HasAny);
|
||||
Assert.False(layout.HasTrack(0));
|
||||
Assert.False(layout.HasColor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Track_ParsesNameRangeDefaultStep()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--track0:Amp,0,100,10,0.5\nobj.ox = obj.track0");
|
||||
Assert.True(layout.HasAny);
|
||||
var t = layout.GetTrack(0);
|
||||
Assert.NotNull(t);
|
||||
Assert.Equal("Amp", t!.Value.Name);
|
||||
Assert.Equal(0d, t.Value.Min);
|
||||
Assert.Equal(100d, t.Value.Max);
|
||||
Assert.Equal(10d, t.Value.Default);
|
||||
Assert.Equal(0.5d, t.Value.Step);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Track_DefaultIsClampedIntoRange()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--track1:V,0,10,999");
|
||||
var t = layout.GetTrack(1);
|
||||
Assert.Equal(10d, t!.Value.Default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Track_SwapsInvertedMinMax()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--track0:V,100,0,50");
|
||||
var t = layout.GetTrack(0);
|
||||
Assert.Equal(0d, t!.Value.Min);
|
||||
Assert.Equal(100d, t.Value.Max);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Track_NegativeRangeParses()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--track2:Off,-100,100,-25");
|
||||
var t = layout.GetTrack(2);
|
||||
Assert.Equal(-100d, t!.Value.Min);
|
||||
Assert.Equal(-25d, t.Value.Default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Track_IndexBeyondThreeIsIgnored()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--track4:V,0,10,5");
|
||||
Assert.False(layout.HasAny);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Check_ParsesDefaultAsBool()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--check0:On,1\n--check1:Off,0");
|
||||
Assert.True(layout.GetCheck(0)!.Value.Default);
|
||||
Assert.False(layout.GetCheck(1)!.Value.Default);
|
||||
Assert.Equal("On", layout.GetCheck(0)!.Value.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_ParsesHexLiteral()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--color:0xff8800");
|
||||
Assert.True(layout.HasColor);
|
||||
Assert.Equal(0xff8800, layout.Color!.Value.Default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_ParsesDecimalLiteral()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--color:255");
|
||||
Assert.Equal(255, layout.Color!.Value.Default);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Combined_TrackCheckColorAllDetected()
|
||||
{
|
||||
const string src =
|
||||
"--track0:Amp,0,100,10\n" +
|
||||
"--track1:Spd,0,50,5\n" +
|
||||
"--check0:Enable,1\n" +
|
||||
"--color:0x112233\n" +
|
||||
"obj.ox = obj.track0";
|
||||
var layout = AviUtlParameterLayout.Parse(src);
|
||||
Assert.True(layout.HasTrack(0));
|
||||
Assert.True(layout.HasTrack(1));
|
||||
Assert.False(layout.HasTrack(2));
|
||||
Assert.True(layout.HasCheck(0));
|
||||
Assert.True(layout.HasColor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Section_OnlyFirstSectionHeaderIsScanned()
|
||||
{
|
||||
const string src = "@First\n--track0:A,0,10,3\n@Second\n--track1:B,0,10,4";
|
||||
var layout = AviUtlParameterLayout.Parse(src);
|
||||
Assert.True(layout.HasTrack(0));
|
||||
Assert.False(layout.HasTrack(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EngineDirective_IsNotMistakenForParameter()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse("--!native\nobj.x = 1");
|
||||
Assert.False(layout.HasAny);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,19 +66,17 @@ namespace LuaScript.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Color_InjectsColorVariable()
|
||||
public void Color_IsNotInjected_SurfacedAsUiParameter()
|
||||
{
|
||||
const string source = "--color:0x010203\nresult = color";
|
||||
double result = RunNumber(AviUtlScript.Transform(source));
|
||||
Assert.Equal(0x010203, result);
|
||||
Assert.Equal(source, AviUtlScript.Transform(source));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Check_InjectsObjectField()
|
||||
public void Check_IsNotInjected_SurfacedAsUiParameter()
|
||||
{
|
||||
const string source = "--check0:Enable,1\nresult = obj.check0";
|
||||
double result = RunNumber(AviUtlScript.Transform(source));
|
||||
Assert.Equal(1d, result);
|
||||
Assert.Equal(source, AviUtlScript.Transform(source));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<Compile Include="..\LuaScript\SceneObjectInfo.cs" Link="Linked\SceneObjectInfo.cs" />
|
||||
<Compile Include="..\LuaScript\AnimTableRegistrar.cs" Link="Linked\AnimTableRegistrar.cs" />
|
||||
<Compile Include="..\LuaScript\Compat\AviUtlScript.cs" Link="Linked\AviUtlScript.cs" />
|
||||
<Compile Include="..\LuaScript\Compat\AviUtlParameterLayout.cs" Link="Linked\AviUtlParameterLayout.cs" />
|
||||
<Compile Include="..\LuaScript\Compat\AviUtlRandom.cs" Link="Linked\AviUtlRandom.cs" />
|
||||
<Compile Include="..\LuaScript\Compat\FigureRenderer.cs" Link="Linked\FigureRenderer.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
internal sealed class AviUtlEffectRequest
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public IReadOnlyList<KeyValuePair<string, object>> Arguments { get; }
|
||||
|
||||
public AviUtlEffectRequest(string name, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
Name = name;
|
||||
Arguments = arguments;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,14 @@ namespace LuaScript
|
||||
public double Track2 { get; set; }
|
||||
public double Track3 { get; set; }
|
||||
|
||||
public bool Check0 { get; set; }
|
||||
public bool Check1 { get; set; }
|
||||
public bool Check2 { get; set; }
|
||||
public bool Check3 { get; set; }
|
||||
|
||||
public bool HasColor { get; set; }
|
||||
public double ColorValue { get; set; }
|
||||
|
||||
public double Time { get; set; }
|
||||
public int Frame { get; set; }
|
||||
public int TotalFrame { get; set; }
|
||||
@@ -48,6 +56,14 @@ namespace LuaScript
|
||||
|
||||
public IReadOnlyList<SceneObjectQuery> ObjectQueries => _objectQueries;
|
||||
|
||||
private readonly List<AviUtlEffectRequest> _effectRequests = [];
|
||||
|
||||
public IReadOnlyList<AviUtlEffectRequest> EffectRequests => _effectRequests;
|
||||
|
||||
internal void AddEffect(AviUtlEffectRequest request) => _effectRequests.Add(request);
|
||||
|
||||
internal void ClearEffects() => _effectRequests.Clear();
|
||||
|
||||
public double RxRad => Rx * Math.PI / 180d;
|
||||
public double RyRad => Ry * Math.PI / 180d;
|
||||
public double RzRad => Rz * Math.PI / 180d;
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace LuaScript.Compat
|
||||
{
|
||||
internal sealed class AviUtlParameterLayout
|
||||
{
|
||||
public const int MaxTracks = 4;
|
||||
public const int MaxChecks = 4;
|
||||
|
||||
public readonly record struct TrackParam(int Index, string Name, double Min, double Max, double Default, double Step);
|
||||
public readonly record struct CheckParam(int Index, string Name, bool Default);
|
||||
public readonly record struct ColorParam(int Default);
|
||||
|
||||
private readonly TrackParam?[] _tracks = new TrackParam?[MaxTracks];
|
||||
private readonly CheckParam?[] _checks = new CheckParam?[MaxChecks];
|
||||
|
||||
public static readonly AviUtlParameterLayout Empty = new();
|
||||
|
||||
public TrackParam? GetTrack(int index) => (uint)index < MaxTracks ? _tracks[index] : null;
|
||||
public CheckParam? GetCheck(int index) => (uint)index < MaxChecks ? _checks[index] : null;
|
||||
public ColorParam? Color { get; private set; }
|
||||
|
||||
public bool HasTrack(int index) => GetTrack(index).HasValue;
|
||||
public bool HasCheck(int index) => GetCheck(index).HasValue;
|
||||
public bool HasColor => Color.HasValue;
|
||||
|
||||
public bool HasAny
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < MaxTracks; i++)
|
||||
if (_tracks[i].HasValue) return true;
|
||||
for (int i = 0; i < MaxChecks; i++)
|
||||
if (_checks[i].HasValue) return true;
|
||||
return HasColor;
|
||||
}
|
||||
}
|
||||
|
||||
public static AviUtlParameterLayout Parse(string? source)
|
||||
{
|
||||
var layout = new AviUtlParameterLayout();
|
||||
if (string.IsNullOrEmpty(source))
|
||||
return layout;
|
||||
|
||||
var lines = source.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
|
||||
int sectionStart = 0;
|
||||
int sectionEnd = lines.Length;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (!IsSectionHeader(lines[i]))
|
||||
continue;
|
||||
sectionStart = i + 1;
|
||||
sectionEnd = lines.Length;
|
||||
for (int j = sectionStart; j < lines.Length; j++)
|
||||
{
|
||||
if (IsSectionHeader(lines[j]))
|
||||
{
|
||||
sectionEnd = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = sectionStart; i < sectionEnd; i++)
|
||||
layout.ParseLine(lines[i]);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
private void ParseLine(string line)
|
||||
{
|
||||
int i = SkipSpaces(line, 0);
|
||||
if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-')
|
||||
return;
|
||||
i += 2;
|
||||
if (i < line.Length && line[i] == '!')
|
||||
return;
|
||||
|
||||
int nameStart = i;
|
||||
while (i < line.Length && IsNameChar(line[i]))
|
||||
i++;
|
||||
if (i >= line.Length || line[i] != ':')
|
||||
return;
|
||||
|
||||
string name = line.Substring(nameStart, i - nameStart);
|
||||
string content = line.Substring(i + 1);
|
||||
|
||||
if (name.StartsWith("track", StringComparison.OrdinalIgnoreCase) &&
|
||||
TryGetIndex(name, 5, MaxTracks, out int trackIndex))
|
||||
{
|
||||
ParseTrack(trackIndex, content);
|
||||
}
|
||||
else if (name.StartsWith("check", StringComparison.OrdinalIgnoreCase) &&
|
||||
TryGetIndex(name, 5, MaxChecks, out int checkIndex))
|
||||
{
|
||||
ParseCheck(checkIndex, content);
|
||||
}
|
||||
else if (name.Equals("color", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ParseColor(content);
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseTrack(int index, string content)
|
||||
{
|
||||
var parts = content.Split(',');
|
||||
string trackName = parts.Length > 0 ? parts[0].Trim() : string.Empty;
|
||||
double min = ParseNumber(parts, 1, 0d);
|
||||
double max = ParseNumber(parts, 2, 100d);
|
||||
double def = ParseNumber(parts, 3, min);
|
||||
double step = ParseNumber(parts, 4, 0d);
|
||||
if (max < min)
|
||||
(min, max) = (max, min);
|
||||
def = Math.Clamp(def, min, max);
|
||||
_tracks[index] = new TrackParam(index, trackName, min, max, def, step);
|
||||
}
|
||||
|
||||
private void ParseCheck(int index, string content)
|
||||
{
|
||||
var parts = content.Split(',');
|
||||
string checkName = parts.Length > 0 ? parts[0].Trim() : string.Empty;
|
||||
double def = ParseNumber(parts, 1, 0d);
|
||||
_checks[index] = new CheckParam(index, checkName, def != 0d);
|
||||
}
|
||||
|
||||
private void ParseColor(string content)
|
||||
{
|
||||
string token = FirstToken(content);
|
||||
if (TryParseColorLiteral(token, out int rgb))
|
||||
Color = new ColorParam(rgb);
|
||||
}
|
||||
|
||||
private static bool TryGetIndex(string name, int start, int max, out int index)
|
||||
{
|
||||
index = -1;
|
||||
if (name.Length != start + 1)
|
||||
return false;
|
||||
char c = name[start];
|
||||
if (c < '0' || c > '9')
|
||||
return false;
|
||||
int value = c - '0';
|
||||
if (value >= max)
|
||||
return false;
|
||||
index = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double ParseNumber(string[] parts, int idx, double fallback)
|
||||
{
|
||||
if (idx >= parts.Length)
|
||||
return fallback;
|
||||
string token = parts[idx].Trim();
|
||||
return double.TryParse(token, NumberStyles.Float, CultureInfo.InvariantCulture, out double value)
|
||||
? value
|
||||
: fallback;
|
||||
}
|
||||
|
||||
private static bool TryParseColorLiteral(string token, out int rgb)
|
||||
{
|
||||
rgb = 0;
|
||||
if (token.Length == 0)
|
||||
return false;
|
||||
if (token.StartsWith("0x", StringComparison.OrdinalIgnoreCase) || token.StartsWith("0X", StringComparison.Ordinal))
|
||||
{
|
||||
if (token.Length <= 2)
|
||||
return false;
|
||||
return int.TryParse(token.AsSpan(2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out rgb);
|
||||
}
|
||||
return int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out rgb);
|
||||
}
|
||||
|
||||
private static string FirstToken(string content)
|
||||
{
|
||||
int start = SkipSpaces(content, 0);
|
||||
int i = start;
|
||||
while (i < content.Length && content[i] != ',' && content[i] != ' ' && content[i] != '\t')
|
||||
i++;
|
||||
return content.Substring(start, i - start);
|
||||
}
|
||||
|
||||
private static bool IsSectionHeader(string line)
|
||||
{
|
||||
int i = SkipSpaces(line, 0);
|
||||
return i < line.Length && line[i] == '@';
|
||||
}
|
||||
|
||||
private static int SkipSpaces(string text, int index)
|
||||
{
|
||||
while (index < text.Length && (text[index] == ' ' || text[index] == '\t'))
|
||||
index++;
|
||||
return index;
|
||||
}
|
||||
|
||||
private static bool IsNameChar(char c) =>
|
||||
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,6 @@ namespace LuaScript.Compat
|
||||
{
|
||||
None,
|
||||
Dialog,
|
||||
Color,
|
||||
Check,
|
||||
Param,
|
||||
}
|
||||
|
||||
@@ -90,12 +88,6 @@ namespace LuaScript.Compat
|
||||
case DirectiveKind.Dialog:
|
||||
AppendDialog(content, prelude);
|
||||
break;
|
||||
case DirectiveKind.Color:
|
||||
AppendColor(content, prelude);
|
||||
break;
|
||||
case DirectiveKind.Check:
|
||||
AppendCheck(name, content, prelude);
|
||||
break;
|
||||
case DirectiveKind.Param:
|
||||
AppendParam(content, prelude);
|
||||
break;
|
||||
@@ -106,12 +98,8 @@ namespace LuaScript.Compat
|
||||
{
|
||||
if (name.Equals("dialog", StringComparison.OrdinalIgnoreCase))
|
||||
return DirectiveKind.Dialog;
|
||||
if (name.Equals("color", StringComparison.OrdinalIgnoreCase))
|
||||
return DirectiveKind.Color;
|
||||
if (name.Equals("param", StringComparison.OrdinalIgnoreCase))
|
||||
return DirectiveKind.Param;
|
||||
if (name.Length > 5 && name.StartsWith("check", StringComparison.OrdinalIgnoreCase) && AllDigits(name, 5))
|
||||
return DirectiveKind.Check;
|
||||
return DirectiveKind.None;
|
||||
}
|
||||
|
||||
@@ -131,22 +119,6 @@ namespace LuaScript.Compat
|
||||
}
|
||||
}
|
||||
|
||||
private static void AppendColor(string content, List<string> prelude)
|
||||
{
|
||||
string token = FirstToken(content);
|
||||
if (IsColorLiteral(token))
|
||||
prelude.Add("local color = " + token);
|
||||
}
|
||||
|
||||
private static void AppendCheck(string name, string content, List<string> prelude)
|
||||
{
|
||||
string index = name.Substring(5);
|
||||
var parts = content.Split(',');
|
||||
string def = parts[parts.Length - 1].Trim();
|
||||
if (IsIntegerLiteral(def))
|
||||
prelude.Add("obj.check" + index + " = " + def);
|
||||
}
|
||||
|
||||
private static void AppendParam(string content, List<string> prelude)
|
||||
{
|
||||
string trimmed = content.Trim();
|
||||
@@ -154,55 +126,6 @@ namespace LuaScript.Compat
|
||||
prelude.Add(trimmed);
|
||||
}
|
||||
|
||||
private static string FirstToken(string content)
|
||||
{
|
||||
int start = SkipSpaces(content, 0);
|
||||
int i = start;
|
||||
while (i < content.Length && content[i] != ',' && content[i] != ' ' && content[i] != '\t')
|
||||
i++;
|
||||
return content.Substring(start, i - start);
|
||||
}
|
||||
|
||||
private static bool IsColorLiteral(string token)
|
||||
{
|
||||
if (token.Length == 0)
|
||||
return false;
|
||||
if (token.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (token.Length <= 2)
|
||||
return false;
|
||||
for (int k = 2; k < token.Length; k++)
|
||||
if (!IsHexDigit(token[k]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
foreach (char c in token)
|
||||
if (c < '0' || c > '9')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool IsIntegerLiteral(string token)
|
||||
{
|
||||
if (token.Length == 0)
|
||||
return false;
|
||||
int start = token[0] == '-' || token[0] == '+' ? 1 : 0;
|
||||
if (start >= token.Length)
|
||||
return false;
|
||||
for (int i = start; i < token.Length; i++)
|
||||
if (token[i] < '0' || token[i] > '9')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool AllDigits(string text, int start)
|
||||
{
|
||||
for (int i = start; i < text.Length; i++)
|
||||
if (text[i] < '0' || text[i] > '9')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int SkipSpaces(string text, int index)
|
||||
{
|
||||
while (index < text.Length && (text[index] == ' ' || text[index] == '\t'))
|
||||
@@ -212,8 +135,5 @@ namespace LuaScript.Compat
|
||||
|
||||
private static bool IsNameChar(char c) =>
|
||||
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
||||
|
||||
private static bool IsHexDigit(char c) =>
|
||||
(c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,11 @@ namespace LuaScript.Engine
|
||||
f[NativeProtocol.Track1] = ctx.Track1;
|
||||
f[NativeProtocol.Track2] = ctx.Track2;
|
||||
f[NativeProtocol.Track3] = ctx.Track3;
|
||||
f[NativeProtocol.Check0] = ctx.Check0 ? 1d : 0d;
|
||||
f[NativeProtocol.Check1] = ctx.Check1 ? 1d : 0d;
|
||||
f[NativeProtocol.Check2] = ctx.Check2 ? 1d : 0d;
|
||||
f[NativeProtocol.Check3] = ctx.Check3 ? 1d : 0d;
|
||||
f[NativeProtocol.Color] = ctx.HasColor ? ctx.ColorValue : -1d;
|
||||
f[NativeProtocol.Time] = ctx.Time;
|
||||
f[NativeProtocol.Frame] = ctx.Frame;
|
||||
f[NativeProtocol.TotalFrame] = ctx.TotalFrame;
|
||||
|
||||
@@ -104,6 +104,11 @@ namespace LuaScript.Engine
|
||||
public const int IsPaused = 50;
|
||||
public const int TimelineFrame = 51;
|
||||
public const int TimelineTime = 52;
|
||||
public const int Check0 = 53;
|
||||
public const int Check1 = 54;
|
||||
public const int Check2 = 55;
|
||||
public const int Check3 = 56;
|
||||
public const int Color = 57;
|
||||
|
||||
public const int FirstWritableField = X;
|
||||
public const int LastWritableField = Rzr;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.5.0</Version>
|
||||
<Version>1.7.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
+104
-1
@@ -1,8 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Windows.Media;
|
||||
using LuaScript.Compat;
|
||||
using Newtonsoft.Json;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Controls;
|
||||
using YukkuriMovieMaker.Exo;
|
||||
using YukkuriMovieMaker.ItemEditor.CustomVisibilityAttributes;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
using YukkuriMovieMaker.Plugin;
|
||||
using YukkuriMovieMaker.Plugin.Effects;
|
||||
@@ -27,27 +31,126 @@ namespace LuaScript
|
||||
|
||||
[Display(GroupName = nameof(Texts.ScriptGroup), ResourceType = typeof(Texts))]
|
||||
[CodeEditor(Language = "pack://application:,,,/LuaScript;component/Resources/SyntaxDefinitions/Lua-{theme}.xshd", FoldingStrategyType = typeof(LuaFoldingStrategy), AutoCompletionStrategyType = typeof(LuaAutoCompletionStrategy), ToolBarStrategyType = typeof(EmptyToolBarStrategy), PropertyEditorSize = PropertyEditorSize.FullWidth)]
|
||||
public string Script { get => _script; set => Set(ref _script, value); }
|
||||
public string Script
|
||||
{
|
||||
get => _script;
|
||||
set { if (Set(ref _script, value)) UpdateLayout(); }
|
||||
}
|
||||
string _script = DefaultScript;
|
||||
|
||||
string IScriptProvider.DefaultScript => DefaultScript;
|
||||
|
||||
internal AviUtlParameterLayout Layout { get; private set; } = AviUtlParameterLayout.Parse(DefaultScript);
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track0), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||
[AnimationSlider("F2", "", -100, 100)]
|
||||
[ShowPropertyEditorWhen(nameof(IsTrack0Visible), true)]
|
||||
public Animation Track0 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track1), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||
[AnimationSlider("F2", "", -100, 100)]
|
||||
[ShowPropertyEditorWhen(nameof(IsTrack1Visible), true)]
|
||||
public Animation Track1 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track2), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||
[AnimationSlider("F2", "", -100, 100)]
|
||||
[ShowPropertyEditorWhen(nameof(IsTrack2Visible), true)]
|
||||
public Animation Track2 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track3), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||
[AnimationSlider("F2", "", -100, 100)]
|
||||
[ShowPropertyEditorWhen(nameof(IsTrack3Visible), true)]
|
||||
public Animation Track3 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check0), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))]
|
||||
[ToggleSlider]
|
||||
[ShowPropertyEditorWhen(nameof(IsCheck0Visible), true)]
|
||||
public bool Check0 { get => _check0; set => Set(ref _check0, value); }
|
||||
bool _check0;
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check1), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))]
|
||||
[ToggleSlider]
|
||||
[ShowPropertyEditorWhen(nameof(IsCheck1Visible), true)]
|
||||
public bool Check1 { get => _check1; set => Set(ref _check1, value); }
|
||||
bool _check1;
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check2), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))]
|
||||
[ToggleSlider]
|
||||
[ShowPropertyEditorWhen(nameof(IsCheck2Visible), true)]
|
||||
public bool Check2 { get => _check2; set => Set(ref _check2, value); }
|
||||
bool _check2;
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Check3), Description = nameof(Texts.CheckDesc), ResourceType = typeof(Texts))]
|
||||
[ToggleSlider]
|
||||
[ShowPropertyEditorWhen(nameof(IsCheck3Visible), true)]
|
||||
public bool Check3 { get => _check3; set => Set(ref _check3, value); }
|
||||
bool _check3;
|
||||
|
||||
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Color), Description = nameof(Texts.ColorDesc), ResourceType = typeof(Texts))]
|
||||
[ColorPicker]
|
||||
[ShowPropertyEditorWhen(nameof(IsColorVisible), true)]
|
||||
public Color Color { get => _color; set => Set(ref _color, value); }
|
||||
Color _color = Colors.White;
|
||||
|
||||
[JsonIgnore] public bool IsTrack0Visible { get => _isTrack0Visible; private set => Set(ref _isTrack0Visible, value); }
|
||||
[JsonIgnore] public bool IsTrack1Visible { get => _isTrack1Visible; private set => Set(ref _isTrack1Visible, value); }
|
||||
[JsonIgnore] public bool IsTrack2Visible { get => _isTrack2Visible; private set => Set(ref _isTrack2Visible, value); }
|
||||
[JsonIgnore] public bool IsTrack3Visible { get => _isTrack3Visible; private set => Set(ref _isTrack3Visible, value); }
|
||||
[JsonIgnore] public bool IsCheck0Visible { get => _isCheck0Visible; private set => Set(ref _isCheck0Visible, value); }
|
||||
[JsonIgnore] public bool IsCheck1Visible { get => _isCheck1Visible; private set => Set(ref _isCheck1Visible, value); }
|
||||
[JsonIgnore] public bool IsCheck2Visible { get => _isCheck2Visible; private set => Set(ref _isCheck2Visible, value); }
|
||||
[JsonIgnore] public bool IsCheck3Visible { get => _isCheck3Visible; private set => Set(ref _isCheck3Visible, value); }
|
||||
[JsonIgnore] public bool IsColorVisible { get => _isColorVisible; private set => Set(ref _isColorVisible, value); }
|
||||
|
||||
bool _isTrack0Visible = true;
|
||||
bool _isTrack1Visible = true;
|
||||
bool _isTrack2Visible = true;
|
||||
bool _isTrack3Visible = true;
|
||||
bool _isCheck0Visible;
|
||||
bool _isCheck1Visible;
|
||||
bool _isCheck2Visible;
|
||||
bool _isCheck3Visible;
|
||||
bool _isColorVisible;
|
||||
|
||||
private void UpdateLayout()
|
||||
{
|
||||
var layout = AviUtlParameterLayout.Parse(_script);
|
||||
Layout = layout;
|
||||
|
||||
bool hasAny = layout.HasAny;
|
||||
|
||||
IsTrack0Visible = !hasAny || layout.HasTrack(0);
|
||||
IsTrack1Visible = !hasAny || layout.HasTrack(1);
|
||||
IsTrack2Visible = !hasAny || layout.HasTrack(2);
|
||||
IsTrack3Visible = !hasAny || layout.HasTrack(3);
|
||||
IsCheck0Visible = layout.HasCheck(0);
|
||||
IsCheck1Visible = layout.HasCheck(1);
|
||||
IsCheck2Visible = layout.HasCheck(2);
|
||||
IsCheck3Visible = layout.HasCheck(3);
|
||||
IsColorVisible = layout.HasColor;
|
||||
|
||||
SeedDefaults(layout);
|
||||
}
|
||||
|
||||
private void SeedDefaults(AviUtlParameterLayout layout)
|
||||
{
|
||||
if (layout.GetCheck(0) is { Default: true } && !_check0) Check0 = true;
|
||||
if (layout.GetCheck(1) is { Default: true } && !_check1) Check1 = true;
|
||||
if (layout.GetCheck(2) is { Default: true } && !_check2) Check2 = true;
|
||||
if (layout.GetCheck(3) is { Default: true } && !_check3) Check3 = true;
|
||||
|
||||
if (layout.Color is { } color && _color == Colors.White)
|
||||
Color = ToMediaColor(color.Default);
|
||||
}
|
||||
|
||||
private static Color ToMediaColor(int rgb)
|
||||
{
|
||||
byte r = (byte)((rgb >> 16) & 0xFF);
|
||||
byte g = (byte)((rgb >> 8) & 0xFF);
|
||||
byte b = (byte)(rgb & 0xFF);
|
||||
return Color.FromRgb(r, g, b);
|
||||
}
|
||||
|
||||
public override IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => [];
|
||||
|
||||
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
||||
|
||||
@@ -28,6 +28,12 @@ namespace LuaScript
|
||||
double Track1,
|
||||
double Track2,
|
||||
double Track3,
|
||||
bool Check0,
|
||||
bool Check1,
|
||||
bool Check2,
|
||||
bool Check3,
|
||||
bool HasColor,
|
||||
int Color,
|
||||
string Script,
|
||||
TimelineSourceUsage Usage,
|
||||
Guid SceneId,
|
||||
@@ -57,6 +63,7 @@ namespace LuaScript
|
||||
private LuaJitWorker? _nativeWorker;
|
||||
private double[]? _nativeFields;
|
||||
private bool _nativeWarned;
|
||||
private bool _effectChainWarned;
|
||||
|
||||
private EffectDescription? _frameDesc;
|
||||
private SceneObjectResolver? _frameResolver;
|
||||
@@ -85,7 +92,9 @@ namespace LuaScript
|
||||
private RenderKey _cachedKey;
|
||||
private SceneObjectQuery[] _cachedQueries = [];
|
||||
private DrawDescription? _cachedOutputDesc;
|
||||
private bool _cachedPixelsModified;
|
||||
private ID2D1Image? _cachedEffectOutput;
|
||||
|
||||
private VideoEffectChain? _effectChain;
|
||||
|
||||
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
||||
{
|
||||
@@ -150,16 +159,22 @@ namespace LuaScript
|
||||
var time = desc.ItemPosition.Time.TotalSeconds;
|
||||
var script = item.Script ?? string.Empty;
|
||||
|
||||
var t0 = item.Track0.GetValue(frame, length, fps);
|
||||
var t1 = item.Track1.GetValue(frame, length, fps);
|
||||
var t2 = item.Track2.GetValue(frame, length, fps);
|
||||
var t3 = item.Track3.GetValue(frame, length, fps);
|
||||
var layout = item.Layout;
|
||||
var t0 = ClampTrack(item.Track0.GetValue(frame, length, fps), layout, 0);
|
||||
var t1 = ClampTrack(item.Track1.GetValue(frame, length, fps), layout, 1);
|
||||
var t2 = ClampTrack(item.Track2.GetValue(frame, length, fps), layout, 2);
|
||||
var t3 = ClampTrack(item.Track3.GetValue(frame, length, fps), layout, 3);
|
||||
|
||||
bool c0 = item.Check0, c1 = item.Check1, c2 = item.Check2, c3 = item.Check3;
|
||||
bool hasColor = layout.HasColor;
|
||||
int colorRgb = hasColor ? (item.Color.R << 16) | (item.Color.G << 8) | item.Color.B : 0;
|
||||
|
||||
var inDesc = desc.DrawDescription;
|
||||
|
||||
var key = new RenderKey(
|
||||
frame, time, length, fps,
|
||||
t0, t1, t2, t3,
|
||||
c0, c1, c2, c3, hasColor, colorRgb,
|
||||
script, desc.Usage, desc.SceneId,
|
||||
desc.TimelinePosition.Frame,
|
||||
desc.TimelinePosition.Time.TotalSeconds,
|
||||
@@ -177,7 +192,7 @@ namespace LuaScript
|
||||
if (!_isFirst && key == _cachedKey &&
|
||||
(_cachedQueries.Length == 0 || QueriesMatch(_cachedQueries, GetFrameResolver())))
|
||||
{
|
||||
effectOutput = _cachedPixelsModified ? _transformEffect?.Output : null;
|
||||
effectOutput = _cachedEffectOutput;
|
||||
return _cachedOutputDesc ?? inDesc;
|
||||
}
|
||||
|
||||
@@ -190,7 +205,6 @@ namespace LuaScript
|
||||
ctx.SetPixelLoader(() => LoadInputPixels(bounds, imgW, imgH));
|
||||
|
||||
DrawDescription outDesc = inDesc;
|
||||
bool pixelsModified = false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -202,7 +216,7 @@ namespace LuaScript
|
||||
|
||||
if (nativeReady)
|
||||
{
|
||||
pixelsModified = ExecuteNative(runnable, ctx, bounds, imgW, imgH);
|
||||
ExecuteNative(runnable, ctx, bounds, imgW, imgH);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -219,7 +233,6 @@ namespace LuaScript
|
||||
else
|
||||
UpdateTransformEffect(bounds.Left, bounds.Top);
|
||||
effectOutput = _transformEffect!.Output;
|
||||
pixelsModified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -228,6 +241,20 @@ namespace LuaScript
|
||||
}
|
||||
|
||||
outDesc = BuildOutputDesc(inDesc, ctx);
|
||||
|
||||
if (ctx.EffectRequests.Count > 0)
|
||||
{
|
||||
var source = effectOutput ?? input;
|
||||
try
|
||||
{
|
||||
effectOutput = ApplyEffectChain(source, ctx.EffectRequests, desc, ref outDesc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
effectOutput = source;
|
||||
WarnEffectChainFailureOnce(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (LuaScriptTimeoutException ex)
|
||||
{
|
||||
@@ -253,11 +280,17 @@ namespace LuaScript
|
||||
_cachedKey = key;
|
||||
_cachedQueries = ctx.ObjectQueries.Count == 0 ? [] : [.. ctx.ObjectQueries];
|
||||
_cachedOutputDesc = outDesc;
|
||||
_cachedPixelsModified = pixelsModified;
|
||||
_cachedEffectOutput = effectOutput;
|
||||
|
||||
return outDesc;
|
||||
}
|
||||
|
||||
private ID2D1Image ApplyEffectChain(ID2D1Image source, IReadOnlyList<AviUtlEffectRequest> requests, EffectDescription desc, ref DrawDescription drawDescription)
|
||||
{
|
||||
_effectChain ??= new VideoEffectChain(_ownCtx!);
|
||||
return _effectChain.Apply(source, requests, desc, ref drawDescription);
|
||||
}
|
||||
|
||||
private static SceneObjectResolver BuildSceneObjectResolver(EffectDescription desc)
|
||||
{
|
||||
var scenes = desc.Scenes;
|
||||
@@ -314,6 +347,7 @@ namespace LuaScript
|
||||
: 0d;
|
||||
|
||||
ctx.ClearQueries();
|
||||
ctx.ClearEffects();
|
||||
|
||||
ctx.ImageWidth = imgW;
|
||||
ctx.ImageHeight = imgH;
|
||||
@@ -335,6 +369,12 @@ namespace LuaScript
|
||||
ctx.Track1 = key.Track1;
|
||||
ctx.Track2 = key.Track2;
|
||||
ctx.Track3 = key.Track3;
|
||||
ctx.Check0 = key.Check0;
|
||||
ctx.Check1 = key.Check1;
|
||||
ctx.Check2 = key.Check2;
|
||||
ctx.Check3 = key.Check3;
|
||||
ctx.HasColor = key.HasColor;
|
||||
ctx.ColorValue = key.Color;
|
||||
ctx.Time = key.Time;
|
||||
ctx.Frame = key.Frame;
|
||||
ctx.TotalFrame = key.Length;
|
||||
@@ -358,6 +398,11 @@ namespace LuaScript
|
||||
ctx.TimeRatio = key.Length > 0 ? key.Frame / (double)key.Length : 0d;
|
||||
}
|
||||
|
||||
private static double ClampTrack(double value, AviUtlParameterLayout layout, int index)
|
||||
{
|
||||
return layout.GetTrack(index) is { } p ? Math.Clamp(value, p.Min, p.Max) : value;
|
||||
}
|
||||
|
||||
private static DrawDescription BuildOutputDesc(DrawDescription inDesc, AviUtlScriptContext ctx)
|
||||
{
|
||||
return inDesc with
|
||||
@@ -377,6 +422,13 @@ namespace LuaScript
|
||||
Log.Default.Write($"LuaScript: native runtime not found at '{NativeDirectory}'. Falling back to MoonSharp (slow). Deploy the 'native' folder next to the plugin.");
|
||||
}
|
||||
|
||||
private void WarnEffectChainFailureOnce(Exception ex)
|
||||
{
|
||||
if (_effectChainWarned) return;
|
||||
_effectChainWarned = true;
|
||||
Log.Default.Write("LuaScript: obj.effect chain failed and was skipped for this frame. The source image is passed through unchanged.", ex);
|
||||
}
|
||||
|
||||
private bool ExecuteNative(string script, AviUtlScriptContext ctx, RawRectF bounds, int imgW, int imgH)
|
||||
{
|
||||
_nativeWorker ??= new LuaJitWorker(NativeDirectory);
|
||||
@@ -525,6 +577,7 @@ namespace LuaScript
|
||||
{
|
||||
_engine.Dispose();
|
||||
_nativeWorker?.Dispose();
|
||||
_effectChain?.Dispose();
|
||||
_pixelLoaderSemaphore.Dispose();
|
||||
_renderTarget?.Dispose();
|
||||
_stagingBitmap?.Dispose();
|
||||
|
||||
@@ -313,6 +313,12 @@ namespace LuaScript
|
||||
_objTable!["track1"] = ctx.Track1;
|
||||
_objTable!["track2"] = ctx.Track2;
|
||||
_objTable!["track3"] = ctx.Track3;
|
||||
_objTable!["check0"] = ctx.Check0;
|
||||
_objTable!["check1"] = ctx.Check1;
|
||||
_objTable!["check2"] = ctx.Check2;
|
||||
_objTable!["check3"] = ctx.Check3;
|
||||
if (ctx.HasColor)
|
||||
script.Globals["color"] = ctx.ColorValue;
|
||||
_objTable!["time"] = ctx.Time;
|
||||
_objTable!["frame"] = ctx.Frame;
|
||||
_objTable!["totalframe"] = ctx.TotalFrame;
|
||||
@@ -481,6 +487,33 @@ namespace LuaScript
|
||||
LoadFigure(name, color, size, line, aspect);
|
||||
return DynValue.Void;
|
||||
});
|
||||
|
||||
obj["effect"] = DynValue.NewCallback((_, args) =>
|
||||
{
|
||||
_activeCancellation.ThrowIfCancellationRequested();
|
||||
if (_activeContext is null || args.Count == 0 || args[0].Type != DataType.String)
|
||||
return DynValue.Void;
|
||||
|
||||
string name = args[0].String;
|
||||
var arguments = new List<KeyValuePair<string, object>>();
|
||||
for (int i = 1; i + 1 < args.Count; i += 2)
|
||||
{
|
||||
if (args[i].Type != DataType.String)
|
||||
continue;
|
||||
var value = args[i + 1];
|
||||
object boxed = value.Type switch
|
||||
{
|
||||
DataType.Number => value.Number,
|
||||
DataType.Boolean => value.Boolean,
|
||||
DataType.String => value.String,
|
||||
_ => value.CastToNumber() ?? 0d,
|
||||
};
|
||||
arguments.Add(new KeyValuePair<string, object>(args[i].String, boxed));
|
||||
}
|
||||
|
||||
_activeContext.AddEffect(new AviUtlEffectRequest(name, arguments));
|
||||
return DynValue.Void;
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadFigure(string name, int color, double size, double line, double aspect)
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>مسار 2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>مسار 3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>قيمة المنزلق (متوافق مع AviUtl: track0-3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>خانة 0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>خانة 1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>خانة 2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>خانة 3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>قيمة خانة الاختيار (متوافق مع AviUtl: check0-3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>اللون</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>اللون (متوافق مع AviUtl: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>استيراد</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>تصدير</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>مسح</value></data>
|
||||
|
||||
@@ -9,6 +9,13 @@ Track1,,トラック1,Track 1,轨道1,軌道1,트랙1,Pista 1,مسار 1,Jalur 1
|
||||
Track2,,トラック2,Track 2,轨道2,軌道2,트랙2,Pista 2,مسار 2,Jalur 2
|
||||
Track3,,トラック3,Track 3,轨道3,軌道3,트랙3,Pista 3,مسار 3,Jalur 3
|
||||
TrackDesc,,スライダー値 (AviUtl準拠 track0〜3 に対応),Slider value (AviUtl compatible: track0–3),滑块值(AviUtl兼容: track0~3),滑塊值(AviUtl兼容: track0~3),슬라이더 값 (AviUtl 호환: track0~3),Valor del deslizador (compatible AviUtl: track0-3),قيمة المنزلق (متوافق مع AviUtl: track0-3),Nilai slider (kompatibel AviUtl: track0-3)
|
||||
Check0,,チェック0,Check 0,复选框0,核取方塊0,체크0,Casilla 0,خانة 0,Centang 0
|
||||
Check1,,チェック1,Check 1,复选框1,核取方塊1,체크1,Casilla 1,خانة 1,Centang 1
|
||||
Check2,,チェック2,Check 2,复选框2,核取方塊2,체크2,Casilla 2,خانة 2,Centang 2
|
||||
Check3,,チェック3,Check 3,复选框3,核取方塊3,체크3,Casilla 3,خانة 3,Centang 3
|
||||
CheckDesc,,チェックボックス値 (AviUtl準拠 check0〜3 に対応),Checkbox value (AviUtl compatible: check0–3),复选框值(AviUtl兼容: check0~3),核取方塊值(AviUtl兼容: check0~3),체크박스 값 (AviUtl 호환: check0~3),Valor de casilla (compatible AviUtl: check0-3),قيمة خانة الاختيار (متوافق مع AviUtl: check0-3),Nilai kotak centang (kompatibel AviUtl: check0-3)
|
||||
Color,,色,Color,颜色,顏色,색,Color,اللون,Warna
|
||||
ColorDesc,,色 (AviUtl準拠 --color に対応),Color (AviUtl compatible: --color),颜色(AviUtl兼容: --color),顏色(AviUtl兼容: --color),색 (AviUtl 호환: --color),Color (compatible AviUtl: --color),اللون (متوافق مع AviUtl: --color),Warna (kompatibel AviUtl: --color)
|
||||
ToolBarImport,,インポート,Import,导入,導入,가져오기,Importar,استيراد,Impor
|
||||
ToolBarExport,,エクスポート,Export,导出,導出,내보내기,Exportar,تصدير,Ekspor
|
||||
ToolBarClear,,クリア,Clear,清除,清除,지우기,Limpiar,مسح,Hapus
|
||||
|
||||
|
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>Track 2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>Track 3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>Slider value (AviUtl compatible: track0–3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>Check 0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>Check 1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>Check 2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>Check 3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>Checkbox value (AviUtl compatible: check0–3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>Color</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>Color (AviUtl compatible: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>Import</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>Export</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>Clear</value></data>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>Pista 2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>Pista 3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>Valor del deslizador (compatible AviUtl: track0-3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>Casilla 0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>Casilla 1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>Casilla 2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>Casilla 3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>Valor de casilla (compatible AviUtl: check0-3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>Color</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>Color (compatible AviUtl: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>Importar</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>Exportar</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>Limpiar</value></data>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>Jalur 2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>Jalur 3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>Nilai slider (kompatibel AviUtl: track0-3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>Centang 0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>Centang 1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>Centang 2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>Centang 3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>Nilai kotak centang (kompatibel AviUtl: check0-3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>Warna</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>Warna (kompatibel AviUtl: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>Impor</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>Ekspor</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>Hapus</value></data>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>트랙2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>트랙3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>슬라이더 값 (AviUtl 호환: track0~3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>체크0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>체크1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>체크2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>체크3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>체크박스 값 (AviUtl 호환: check0~3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>색</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>색 (AviUtl 호환: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>가져오기</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>내보내기</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>지우기</value></data>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>トラック2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>トラック3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>スライダー値 (AviUtl準拠 track0〜3 に対応)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>チェック0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>チェック1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>チェック2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>チェック3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>チェックボックス値 (AviUtl準拠 check0〜3 に対応)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>色</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>色 (AviUtl準拠 --color に対応)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>インポート</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>エクスポート</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>クリア</value></data>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>轨道2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>轨道3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>滑块值(AviUtl兼容: track0~3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>复选框0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>复选框1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>复选框2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>复选框3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>复选框值(AviUtl兼容: check0~3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>颜色</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>颜色(AviUtl兼容: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>导入</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>导出</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>清除</value></data>
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
<data name="Track2" xml:space="preserve"><value>軌道2</value></data>
|
||||
<data name="Track3" xml:space="preserve"><value>軌道3</value></data>
|
||||
<data name="TrackDesc" xml:space="preserve"><value>滑塊值(AviUtl兼容: track0~3)</value></data>
|
||||
<data name="Check0" xml:space="preserve"><value>核取方塊0</value></data>
|
||||
<data name="Check1" xml:space="preserve"><value>核取方塊1</value></data>
|
||||
<data name="Check2" xml:space="preserve"><value>核取方塊2</value></data>
|
||||
<data name="Check3" xml:space="preserve"><value>核取方塊3</value></data>
|
||||
<data name="CheckDesc" xml:space="preserve"><value>核取方塊值(AviUtl兼容: check0~3)</value></data>
|
||||
<data name="Color" xml:space="preserve"><value>顏色</value></data>
|
||||
<data name="ColorDesc" xml:space="preserve"><value>顏色(AviUtl兼容: --color)</value></data>
|
||||
<data name="ToolBarImport" xml:space="preserve"><value>導入</value></data>
|
||||
<data name="ToolBarExport" xml:space="preserve"><value>導出</value></data>
|
||||
<data name="ToolBarClear" xml:space="preserve"><value>清除</value></data>
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Windows.Media;
|
||||
using Vortice.Direct2D1;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
using YukkuriMovieMaker.Plugin;
|
||||
using YukkuriMovieMaker.Plugin.Effects;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
internal sealed class VideoEffectChain : IDisposable
|
||||
{
|
||||
private sealed class Node
|
||||
{
|
||||
public required Type Type;
|
||||
public required IVideoEffect Model;
|
||||
public required IVideoEffectProcessor Processor;
|
||||
public required int RequestIndex;
|
||||
}
|
||||
|
||||
private static Dictionary<string, Type>? _registry;
|
||||
private static readonly Dictionary<Type, Dictionary<string, PropertyInfo>> _propertyCache = [];
|
||||
|
||||
private readonly IGraphicsDevicesAndContext _devices;
|
||||
private readonly List<Node> _nodes = [];
|
||||
private string[] _signature = [];
|
||||
|
||||
public VideoEffectChain(IGraphicsDevicesAndContext devices)
|
||||
{
|
||||
_devices = devices;
|
||||
}
|
||||
|
||||
public ID2D1Image Apply(ID2D1Image source, IReadOnlyList<AviUtlEffectRequest> requests, EffectDescription baseDesc, ref DrawDescription drawDescription)
|
||||
{
|
||||
try
|
||||
{
|
||||
SyncNodes(requests);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
var current = source;
|
||||
var desc = drawDescription;
|
||||
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
try
|
||||
{
|
||||
ApplyParameters(node.Model, requests[node.RequestIndex].Arguments);
|
||||
node.Processor.SetInput(current);
|
||||
var effectDescription = new EffectDescription(baseDesc, desc, baseDesc.InputIndex, baseDesc.InputCount, baseDesc.GroupIndex, baseDesc.GroupCount);
|
||||
desc = node.Processor.Update(effectDescription);
|
||||
current = node.Processor.Output;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
drawDescription = desc;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void SyncNodes(IReadOnlyList<AviUtlEffectRequest> requests)
|
||||
{
|
||||
if (SignatureMatches(requests))
|
||||
return;
|
||||
|
||||
DisposeNodes();
|
||||
_signature = new string[requests.Count];
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
_signature[i] = requests[i].Name;
|
||||
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
var type = Resolve(requests[i].Name);
|
||||
if (type is null)
|
||||
continue;
|
||||
|
||||
IVideoEffect? model = null;
|
||||
try
|
||||
{
|
||||
model = Activator.CreateInstance(type) as IVideoEffect;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (model is null)
|
||||
continue;
|
||||
|
||||
IVideoEffectProcessor processor;
|
||||
try
|
||||
{
|
||||
processor = model.CreateVideoEffect(_devices);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_nodes.Add(new Node { Type = type, Model = model, Processor = processor, RequestIndex = i });
|
||||
}
|
||||
}
|
||||
|
||||
private bool SignatureMatches(IReadOnlyList<AviUtlEffectRequest> requests)
|
||||
{
|
||||
if (_signature.Length != requests.Count)
|
||||
return false;
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
if (!string.Equals(_signature[i], requests[i].Name, StringComparison.Ordinal))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Type? Resolve(string name)
|
||||
{
|
||||
var registry = GetRegistry();
|
||||
return registry.TryGetValue(Normalize(name), out var type) ? type : null;
|
||||
}
|
||||
|
||||
private static Dictionary<string, Type> GetRegistry()
|
||||
{
|
||||
if (_registry is not null)
|
||||
return _registry;
|
||||
|
||||
var map = new Dictionary<string, Type>(StringComparer.Ordinal);
|
||||
try
|
||||
{
|
||||
foreach (var factory in EffectFactories.VideoEffectFactories)
|
||||
{
|
||||
try
|
||||
{
|
||||
Register(map, factory.Name, factory.EffectType);
|
||||
foreach (var keyword in factory.Keywords)
|
||||
Register(map, keyword, factory.EffectType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
_registry = map;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void Register(Dictionary<string, Type> map, string? key, Type type)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return;
|
||||
map.TryAdd(Normalize(key), type);
|
||||
}
|
||||
|
||||
private static string Normalize(string value) => value.Trim().ToLowerInvariant();
|
||||
|
||||
private static void ApplyParameters(IVideoEffect model, IReadOnlyList<KeyValuePair<string, object>> arguments)
|
||||
{
|
||||
if (arguments.Count == 0)
|
||||
return;
|
||||
|
||||
var properties = GetProperties(model.GetType());
|
||||
foreach (var (key, value) in arguments)
|
||||
{
|
||||
if (!properties.TryGetValue(Normalize(key), out var property))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
SetValue(model, property, value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, PropertyInfo> GetProperties(Type type)
|
||||
{
|
||||
if (_propertyCache.TryGetValue(type, out var cached))
|
||||
return cached;
|
||||
|
||||
var map = new Dictionary<string, PropertyInfo>(StringComparer.Ordinal);
|
||||
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
if (property.GetIndexParameters().Length != 0)
|
||||
continue;
|
||||
bool usable = property.PropertyType == typeof(Animation) || property.GetSetMethod() is not null;
|
||||
if (!usable)
|
||||
continue;
|
||||
|
||||
map.TryAdd(Normalize(property.Name), property);
|
||||
try
|
||||
{
|
||||
var display = property.GetCustomAttribute<DisplayAttribute>()?.GetName();
|
||||
if (!string.IsNullOrWhiteSpace(display))
|
||||
map.TryAdd(Normalize(display), property);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
_propertyCache[type] = map;
|
||||
return map;
|
||||
}
|
||||
|
||||
private static void SetValue(IVideoEffect model, PropertyInfo property, object value)
|
||||
{
|
||||
var type = property.PropertyType;
|
||||
|
||||
if (type == typeof(Animation))
|
||||
{
|
||||
if (property.GetValue(model) is Animation animation)
|
||||
animation.CopyFrom(new Animation(ToDouble(value)));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(bool))
|
||||
{
|
||||
property.SetValue(model, ToBool(value));
|
||||
return;
|
||||
}
|
||||
if (type.IsEnum)
|
||||
{
|
||||
property.SetValue(model, ToEnum(type, value));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(Color))
|
||||
{
|
||||
property.SetValue(model, ToColor(value));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(double) || type == typeof(float) || type == typeof(int) || type == typeof(long) || type == typeof(short))
|
||||
{
|
||||
property.SetValue(model, Convert.ChangeType(ToDouble(value), type, CultureInfo.InvariantCulture));
|
||||
return;
|
||||
}
|
||||
if (type == typeof(string))
|
||||
property.SetValue(model, value?.ToString());
|
||||
}
|
||||
|
||||
private static double ToDouble(object value) => value switch
|
||||
{
|
||||
double d => d,
|
||||
bool b => b ? 1d : 0d,
|
||||
string s => double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var r) ? r : 0d,
|
||||
_ => 0d,
|
||||
};
|
||||
|
||||
private static bool ToBool(object value) => value switch
|
||||
{
|
||||
bool b => b,
|
||||
double d => d != 0d,
|
||||
string s => s.Equals("true", StringComparison.OrdinalIgnoreCase) || s == "1",
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private static object ToEnum(Type type, object value)
|
||||
{
|
||||
if (value is string s && Enum.TryParse(type, s, true, out var parsed))
|
||||
return parsed;
|
||||
return Enum.ToObject(type, (int)ToDouble(value));
|
||||
}
|
||||
|
||||
private static Color ToColor(object value)
|
||||
{
|
||||
int rgb = (int)ToDouble(value);
|
||||
return Color.FromRgb((byte)((rgb >> 16) & 0xFF), (byte)((rgb >> 8) & 0xFF), (byte)(rgb & 0xFF));
|
||||
}
|
||||
|
||||
private void DisposeNodes()
|
||||
{
|
||||
foreach (var node in _nodes)
|
||||
{
|
||||
try
|
||||
{
|
||||
node.Processor.ClearInput();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
node.Processor.Dispose();
|
||||
}
|
||||
_nodes.Clear();
|
||||
}
|
||||
|
||||
public void Dispose() => DisposeNodes();
|
||||
}
|
||||
}
|
||||
@@ -227,6 +227,8 @@ local function loadFields()
|
||||
ymm4.is_saving = f64[48] ~= 0; ymm4.is_playing = f64[49] ~= 0; ymm4.is_paused = f64[50] ~= 0
|
||||
ymm4.group_ratio = (f64[44] ~= 0) and (f64[43] / f64[44]) or 0
|
||||
obj.timelineframe = f64[51]; obj.timelinetime = f64[52]
|
||||
obj.check0 = f64[53] ~= 0; obj.check1 = f64[54] ~= 0; obj.check2 = f64[55] ~= 0; obj.check3 = f64[56] ~= 0
|
||||
sandbox.color = (f64[57] >= 0) and f64[57] or nil
|
||||
end
|
||||
|
||||
local function storeFields()
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする