コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
a093c458a2
|
||
|
|
0e65bf1883
|
||
|
|
d8f728b3f9
|
||
|
|
244e75a238
|
||
|
|
75cc4bd62e
|
||
|
|
6385dbeb6d
|
||
|
|
bc395a0181
|
||
|
|
a0dec019fe
|
||
|
|
c8350161db
|
||
|
|
679cab03b5
|
||
|
|
6783146231
|
||
|
|
df303ee154
|
||
|
|
f49bd740a0
|
||
|
|
80d1b75227
|
||
|
|
d7f981c38a
|
||
|
|
df0c63a270
|
||
|
|
7766b116dc
|
||
|
|
eb8f4e8055
|
||
|
|
04563a7242
|
||
|
|
875d954520
|
||
|
|
bd7f2ae691
|
||
|
|
36b3c880fe
|
||
|
|
230e6f010c
|
||
|
|
ef16ae64fb
|
||
|
|
0204d480e2
|
||
|
|
7e1f2c1d7c
|
||
|
|
bab81d27e5
|
||
|
|
a3efd55ce6
|
検索条件に一致するファイルはありません
+25
-46
@@ -1,58 +1,37 @@
|
|||||||
# v1.4.0 - Lua スクリプト for YMM4
|
# v1.7.1 - Lua スクリプト for YMM4
|
||||||
|
|
||||||
AviUtl のアニメーション効果スクリプト(`.anm` 系)に対する**部分互換層**を追加した
|
内部アーキテクチャの大幅なリファクタリングと、ネイティブ環境(LuaJIT)における
|
||||||
リリースです。座標・拡縮・回転・不透明度の変形と乱数を用いる範囲について、追加の
|
描画・映像エフェクトAPI(`obj.load` および `obj.effect`)の対応を行ったリリースです。
|
||||||
記述変更なしで AviUtl 向けスクリプトを実行できるようになりました。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 新機能
|
## 新機能・機能改善
|
||||||
|
|
||||||
### 1. AviUtl スクリプトの部分互換
|
### 1. ネイティブ環境での obj.load および obj.effect 対応
|
||||||
|
|
||||||
AviUtl のアニメーション効果スクリプトのうち、本プラグインの変形・ピクセルモデルへ
|
v1.7.0 では MoonSharp エンジンのみの対応であった図形生成(`obj.load`)および
|
||||||
無理なく写像できる範囲を実行できる互換層を追加しました。スクリプトに AviUtl 固有の
|
YMM4映像エフェクト連鎖適用(`obj.effect`)が、ネイティブ(LuaJIT)環境でも完全に
|
||||||
記法が含まれない場合、この互換層は一切介入しないため、従来のスクリプトの挙動は
|
利用可能になりました。
|
||||||
変わりません。
|
|
||||||
|
|
||||||
- **スクリプトヘッダの解釈**: コメント形式のパラメータ宣言を解釈し、スクリプト本体が
|
- ネイティブ環境でも高解像度(最大4K)の図形生成に対応し、メモリリークや
|
||||||
参照する変数を実行前に定義します。これまでは単なるコメントとして無視され、参照変数が
|
GC(ガベージコレクション)の負荷を排除した最高パフォーマンスで動作します。
|
||||||
`nil` になり実行できなかったスクリプトが動作するようになります。
|
- これにより、`obj.load` や `obj.effect` を使用するスクリプトが自動的に
|
||||||
- `--dialog:項目名,local 変数=既定値;…` … 各項目の宣言部を本体の先頭へ展開します。
|
MoonSharp にフォールバックされる制限が解除されました。
|
||||||
- `--color:0xRRGGBB` … 変数 `color` を指定色で定義します。
|
|
||||||
- `--check0:項目名,既定値` … `obj.check0`(`0`〜`3`)を既定値で定義します。
|
|
||||||
- `--param:任意のLua文` … 記述した Lua 文をそのまま本体の先頭へ展開します。
|
|
||||||
- `--track0:`〜`--track3:` … 値は従来どおり `obj.track0`〜`obj.track3` から参照します
|
|
||||||
(ラベル・範囲・既定値の UI 反映は行いません)。
|
|
||||||
- **`@` による複数セクション**: 1 つのスクリプトに `@名前` で複数の効果が定義されて
|
|
||||||
いる場合、先頭のセクションのみを実行します。
|
|
||||||
|
|
||||||
### 2. obj.rand の追加
|
|
||||||
|
|
||||||
AviUtl 互換の決定論的な整数乱数 `obj.rand(st, ed [, seed [, frame]])` を追加しました。
|
|
||||||
指定範囲 `st`〜`ed` の整数を返し、`seed` と `frame` が同じであれば常に同じ値を返します。
|
|
||||||
`frame` を省略すると現在のフレームを用います。従来エンジン(MoonSharp)と高速ランタイム
|
|
||||||
(LuaJIT)で同じ値を返すため、エンジンの自動振り分けによらず結果が一致します。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 注意事項
|
## 内部実装の最適化(リファクタリング)
|
||||||
|
|
||||||
- 描画・フィルタ・ファイルアクセス系の関数(`obj.load` / `obj.draw` / `obj.drawpoly` /
|
コードベースの保守性と安全性を高めるため、多岐にわたる設計改善を実施しました。
|
||||||
`obj.effect` / `obj.copybuffer` / `obj.setoption` / `obj.setfont`、`require`、`io` 等)は
|
|
||||||
本体の描画パイプラインへの統合を要するため、この互換層では対象外です。これらを呼び出す
|
|
||||||
スクリプトは意図どおりには動作しません。
|
|
||||||
- `--track0:`〜`--track3:` のラベル・範囲・既定値はエフェクトパネルの UI へ反映されません。
|
|
||||||
トラックバーの値は従来どおり Track0〜Track3 のスライダー値が使用されます。
|
|
||||||
- エンジンに依存しない小数の乱数が必要な場合は、従来どおり `anim.rand` を使用してください。
|
|
||||||
|
|
||||||
---
|
- **責務の分離と抽出**
|
||||||
|
- Direct2D に関連するピクセルバッファ管理および変換処理を専用クラスへ分離しました。
|
||||||
## 内部実装
|
- トークン解析処理や Transform(座標・回転・拡大率等の変形パラメータ)の書き戻し処理を
|
||||||
|
共通化・抽出しました。
|
||||||
- スクリプトを実行可能な Lua へ変換する前処理を追加し、MoonSharp・LuaJIT の両実行系へ
|
- `ScriptDirective`、`SceneObjectQuery`、各種例外クラス群をそれぞれ個別の
|
||||||
一貫して適用しました。変換結果はソース単位でキャッシュし、毎フレームの再解析を避けています。
|
ファイルへ分離し、設計の対称性と可読性を向上させました。
|
||||||
- `obj.rand` の数値コアを C# と LuaJIT で同一アルゴリズムとして実装し、両者がビット単位で
|
- **アーキテクチャの堅牢化**
|
||||||
一致することを等価性テストで検証しています。
|
- ネイティブ環境との通信プロトコルを拡張し、タグ領域を拡大(256バイトから4096バイト)
|
||||||
- AviUtl 固有の記法を含まないスクリプトでは前処理がソースをそのまま返すため、既存スクリプト
|
することで、長文の引数を扱うエフェクトにおけるデータの欠落を完全に防止しました。
|
||||||
および既存の実行・キャッシュ経路に対する影響はありません。
|
- ピクセルバッファのアロケーションを最小化するキャッシュ機構を導入し、
|
||||||
|
描画フレームごとの無駄な配列確保を排除しました。
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
========================================
|
========================================
|
||||||
Luaスクリプト for YMM4 v1.4.0
|
Luaスクリプト for YMM4 v1.7.1
|
||||||
========================================
|
========================================
|
||||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
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]
|
[Fact]
|
||||||
public void Color_InjectsColorVariable()
|
public void Color_IsNotInjected_SurfacedAsUiParameter()
|
||||||
{
|
{
|
||||||
const string source = "--color:0x010203\nresult = color";
|
const string source = "--color:0x010203\nresult = color";
|
||||||
double result = RunNumber(AviUtlScript.Transform(source));
|
Assert.Equal(source, AviUtlScript.Transform(source));
|
||||||
Assert.Equal(0x010203, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Check_InjectsObjectField()
|
public void Check_IsNotInjected_SurfacedAsUiParameter()
|
||||||
{
|
{
|
||||||
const string source = "--check0:Enable,1\nresult = obj.check0";
|
const string source = "--check0:Enable,1\nresult = obj.check0";
|
||||||
double result = RunNumber(AviUtlScript.Transform(source));
|
Assert.Equal(source, AviUtlScript.Transform(source));
|
||||||
Assert.Equal(1d, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using LuaScript.Compat;
|
||||||
|
|
||||||
|
namespace LuaScript.Tests
|
||||||
|
{
|
||||||
|
public class FigureRendererTests
|
||||||
|
{
|
||||||
|
private static (int B, int G, int R, int A) Pixel(byte[] buffer, int width, int x, int y)
|
||||||
|
{
|
||||||
|
int i = (y * width + x) * 4;
|
||||||
|
return (buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Render_ProducesBufferOfRequestedSize()
|
||||||
|
{
|
||||||
|
var buffer = FigureRenderer.Render("円", 64, 48, 0xFFFFFF, 0d);
|
||||||
|
Assert.Equal(64 * 48 * 4, buffer.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FilledCircle_CenterIsOpaqueAndColored()
|
||||||
|
{
|
||||||
|
int w = 100, h = 100;
|
||||||
|
var buffer = FigureRenderer.Render("円", w, h, 0xFF0000, 0d);
|
||||||
|
var (b, g, r, a) = Pixel(buffer, w, w / 2, h / 2);
|
||||||
|
Assert.Equal(255, a);
|
||||||
|
Assert.Equal(255, r);
|
||||||
|
Assert.Equal(0, g);
|
||||||
|
Assert.Equal(0, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FilledCircle_CornerIsTransparent()
|
||||||
|
{
|
||||||
|
int w = 100, h = 100;
|
||||||
|
var buffer = FigureRenderer.Render("円", w, h, 0xFF0000, 0d);
|
||||||
|
var (_, _, _, a) = Pixel(buffer, w, 0, 0);
|
||||||
|
Assert.Equal(0, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Color_IsStoredPremultipliedAtHalfCoverageBoundary()
|
||||||
|
{
|
||||||
|
int w = 100, h = 100;
|
||||||
|
var buffer = FigureRenderer.Render("四角形", w, h, 0x102030, 0d);
|
||||||
|
var (b, g, r, a) = Pixel(buffer, w, w / 2, h / 2);
|
||||||
|
Assert.Equal(255, a);
|
||||||
|
Assert.Equal(0x10, r);
|
||||||
|
Assert.Equal(0x20, g);
|
||||||
|
Assert.Equal(0x30, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FilledRectangle_CornerIsOpaque()
|
||||||
|
{
|
||||||
|
int w = 80, h = 80;
|
||||||
|
var buffer = FigureRenderer.Render("四角形", w, h, 0xFFFFFF, 0d);
|
||||||
|
var (_, _, _, a) = Pixel(buffer, w, 1, 1);
|
||||||
|
Assert.Equal(255, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void OutlinedCircle_IsHollowAtCenterButSolidNearEdge()
|
||||||
|
{
|
||||||
|
int w = 100, h = 100;
|
||||||
|
var buffer = FigureRenderer.Render("円", w, h, 0xFFFFFF, 8d);
|
||||||
|
var (_, _, _, center) = Pixel(buffer, w, w / 2, h / 2);
|
||||||
|
var (_, _, _, nearEdge) = Pixel(buffer, w, w / 2 + 46, h / 2);
|
||||||
|
Assert.Equal(0, center);
|
||||||
|
Assert.Equal(255, nearEdge);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Triangle_CornersEmptyCentroidFilled()
|
||||||
|
{
|
||||||
|
int w = 100, h = 100;
|
||||||
|
var buffer = FigureRenderer.Render("三角形", w, h, 0xFFFFFF, 0d);
|
||||||
|
var (_, _, _, topLeft) = Pixel(buffer, w, 2, 2);
|
||||||
|
var (_, _, _, topRight) = Pixel(buffer, w, w - 3, 2);
|
||||||
|
var (_, _, _, centroid) = Pixel(buffer, w, w / 2, h / 2);
|
||||||
|
Assert.Equal(0, topLeft);
|
||||||
|
Assert.Equal(0, topRight);
|
||||||
|
Assert.Equal(255, centroid);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UnknownName_FallsBackToRectangle()
|
||||||
|
{
|
||||||
|
int w = 40, h = 40;
|
||||||
|
var buffer = FigureRenderer.Render("unknown", w, h, 0xFFFFFF, 0d);
|
||||||
|
var (_, _, _, corner) = Pixel(buffer, w, 1, 1);
|
||||||
|
Assert.Equal(255, corner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,13 +27,18 @@
|
|||||||
<Compile Include="..\LuaScript\Compat\MoonSharpBit32.cs" Link="Linked\MoonSharpBit32.cs" />
|
<Compile Include="..\LuaScript\Compat\MoonSharpBit32.cs" Link="Linked\MoonSharpBit32.cs" />
|
||||||
<Compile Include="..\LuaScript\Compat\Bit32.cs" Link="Linked\Bit32.cs" />
|
<Compile Include="..\LuaScript\Compat\Bit32.cs" Link="Linked\Bit32.cs" />
|
||||||
<Compile Include="..\LuaScript\Engine\ScriptEngineKind.cs" Link="Linked\ScriptEngineKind.cs" />
|
<Compile Include="..\LuaScript\Engine\ScriptEngineKind.cs" Link="Linked\ScriptEngineKind.cs" />
|
||||||
|
<Compile Include="..\LuaScript\Engine\ScriptDirective.cs" Link="Linked\ScriptDirective.cs" />
|
||||||
<Compile Include="..\LuaScript\Engine\NativeProtocol.cs" Link="Linked\NativeProtocol.cs" />
|
<Compile Include="..\LuaScript\Engine\NativeProtocol.cs" Link="Linked\NativeProtocol.cs" />
|
||||||
<Compile Include="..\LuaScript\Engine\ProcessJobObject.cs" Link="Linked\ProcessJobObject.cs" />
|
<Compile Include="..\LuaScript\Engine\ProcessJobObject.cs" Link="Linked\ProcessJobObject.cs" />
|
||||||
<Compile Include="..\LuaScript\Engine\LuaJitWorker.cs" Link="Linked\LuaJitWorker.cs" />
|
<Compile Include="..\LuaScript\Engine\LuaJitWorker.cs" Link="Linked\LuaJitWorker.cs" />
|
||||||
<Compile Include="..\LuaScript\SceneObjectInfo.cs" Link="Linked\SceneObjectInfo.cs" />
|
<Compile Include="..\LuaScript\SceneObjectInfo.cs" Link="Linked\SceneObjectInfo.cs" />
|
||||||
|
<Compile Include="..\LuaScript\SceneObjectQuery.cs" Link="Linked\SceneObjectQuery.cs" />
|
||||||
<Compile Include="..\LuaScript\AnimTableRegistrar.cs" Link="Linked\AnimTableRegistrar.cs" />
|
<Compile Include="..\LuaScript\AnimTableRegistrar.cs" Link="Linked\AnimTableRegistrar.cs" />
|
||||||
<Compile Include="..\LuaScript\Compat\AviUtlScript.cs" Link="Linked\AviUtlScript.cs" />
|
<Compile Include="..\LuaScript\Compat\AviUtlScript.cs" Link="Linked\AviUtlScript.cs" />
|
||||||
|
<Compile Include="..\LuaScript\Compat\ScriptParserHelper.cs" Link="Linked\ScriptParserHelper.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\AviUtlRandom.cs" Link="Linked\AviUtlRandom.cs" />
|
||||||
|
<Compile Include="..\LuaScript\Compat\FigureRenderer.cs" Link="Linked\FigureRenderer.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -9,6 +9,8 @@ namespace LuaScript.Tests
|
|||||||
private static string NativeDir => Path.Combine(AppContext.BaseDirectory, "native");
|
private static string NativeDir => Path.Combine(AppContext.BaseDirectory, "native");
|
||||||
|
|
||||||
private static readonly Func<string, int, SceneObjectInfo?> NoResolver = (_, _) => null;
|
private static readonly Func<string, int, SceneObjectInfo?> NoResolver = (_, _) => null;
|
||||||
|
private static readonly Func<string, int, double, double, double, (byte[] buffer, int w, int h)> NoLoadFigure = (_, _, _, _, _) => ([], 1, 1);
|
||||||
|
private static readonly Action<string, System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string, object>>> NoAddEffect = (_, _) => { };
|
||||||
|
|
||||||
private readonly LuaJitWorker _worker = new(NativeDir);
|
private readonly LuaJitWorker _worker = new(NativeDir);
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ namespace LuaScript.Tests
|
|||||||
|
|
||||||
bool ok = _worker.Execute(
|
bool ok = _worker.Execute(
|
||||||
"obj.rz = obj.time * 90\nobj.alpha = 128",
|
"obj.rz = obj.time * 90\nobj.alpha = 128",
|
||||||
fields, pixels, 4, 4, 5000, NoResolver, out bool dirty, out string? error);
|
fields, pixels, 4, 4, 5000, NoResolver, NoLoadFigure, NoAddEffect, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.False(dirty);
|
Assert.False(dirty);
|
||||||
@@ -69,7 +71,7 @@ namespace LuaScript.Tests
|
|||||||
"local gray = r*0.299 + g*0.587 + b*0.114 " +
|
"local gray = r*0.299 + g*0.587 + b*0.114 " +
|
||||||
"obj.setpixel(x,y,gray,gray,gray,a) end end";
|
"obj.setpixel(x,y,gray,gray,gray,a) end end";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, out bool dirty, out string? error);
|
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.True(dirty);
|
Assert.True(dirty);
|
||||||
@@ -104,7 +106,7 @@ namespace LuaScript.Tests
|
|||||||
"local gray=r*0.299+g*0.587+b*0.114 " +
|
"local gray=r*0.299+g*0.587+b*0.114 " +
|
||||||
"pd:set(base+1,gray) pd:set(base+2,gray) pd:set(base+3,gray) end end";
|
"pd:set(base+1,gray) pd:set(base+2,gray) pd:set(base+3,gray) end end";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, out bool dirty, out string? error);
|
bool ok = _worker.Execute(script, fields, pixels, w, h, 5000, NoResolver, NoLoadFigure, NoAddEffect, out bool dirty, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.True(dirty);
|
Assert.True(dirty);
|
||||||
@@ -140,7 +142,7 @@ namespace LuaScript.Tests
|
|||||||
for (int k = 1; k <= 5; k++)
|
for (int k = 1; k <= 5; k++)
|
||||||
{
|
{
|
||||||
var fields = Fields(2, 2, k);
|
var fields = Fields(2, 2, k);
|
||||||
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, pixels, 2, 2, 5000, NoResolver, out _, out string? error);
|
bool ok = _worker.Execute("obj.x = obj.time * 10", fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(k * 10d, fields[NativeProtocol.X]);
|
Assert.Equal(k * 10d, fields[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
@@ -155,12 +157,12 @@ namespace LuaScript.Tests
|
|||||||
var fields = Fields(2, 2, 0d);
|
var fields = Fields(2, 2, 0d);
|
||||||
|
|
||||||
bool timedOut = _worker.Execute(
|
bool timedOut = _worker.Execute(
|
||||||
"local x=0 while true do x=x+1 end", fields, pixels, 2, 2, 1500, NoResolver, out _, out string? error);
|
"local x=0 while true do x=x+1 end", fields, pixels, 2, 2, 1500, NoResolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.False(timedOut);
|
Assert.False(timedOut);
|
||||||
Assert.Contains("timed out", error);
|
Assert.Contains("timed out", error);
|
||||||
|
|
||||||
var fields2 = Fields(2, 2, 3d);
|
var fields2 = Fields(2, 2, 3d);
|
||||||
bool ok = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, out _, out error);
|
bool ok = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(3d, fields2[NativeProtocol.X]);
|
Assert.Equal(3d, fields2[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
@@ -182,7 +184,7 @@ namespace LuaScript.Tests
|
|||||||
"obj.zoom = o.zoom obj.rz = o.rz obj.alpha = o.alpha " +
|
"obj.zoom = o.zoom obj.rz = o.rz obj.alpha = o.alpha " +
|
||||||
"obj.sx = o.sy obj.rzr = o.rzr";
|
"obj.sx = o.sy obj.rzr = o.rzr";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(12d, fields[NativeProtocol.X]);
|
Assert.Equal(12d, fields[NativeProtocol.X]);
|
||||||
@@ -214,13 +216,13 @@ namespace LuaScript.Tests
|
|||||||
"local b = obj.getobject(\"a\") " +
|
"local b = obj.getobject(\"a\") " +
|
||||||
"obj.x = a.x + b.x";
|
"obj.x = a.x + b.x";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, Fields(2, 2, 0d), pixels, 2, 2, 5000, resolver, out _, out string? error);
|
bool ok = _worker.Execute(script, Fields(2, 2, 0d), pixels, 2, 2, 5000, resolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(1, calls);
|
Assert.Equal(1, calls);
|
||||||
var fields = Fields(2, 2, 0d);
|
var fields = Fields(2, 2, 0d);
|
||||||
|
|
||||||
x = 20d;
|
x = 20d;
|
||||||
ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, out _, out error);
|
ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, resolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(2, calls);
|
Assert.Equal(2, calls);
|
||||||
Assert.Equal(40d, fields[NativeProtocol.X]);
|
Assert.Equal(40d, fields[NativeProtocol.X]);
|
||||||
@@ -237,7 +239,7 @@ namespace LuaScript.Tests
|
|||||||
const string script =
|
const string script =
|
||||||
"local o = obj.getobject(\"missing\") obj.x = o == nil and 1 or 0";
|
"local o = obj.getobject(\"missing\") obj.x = o == nil and 1 or 0";
|
||||||
|
|
||||||
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, NoResolver, out _, out string? error);
|
bool ok = _worker.Execute(script, fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out string? error);
|
||||||
|
|
||||||
Assert.True(ok, error);
|
Assert.True(ok, error);
|
||||||
Assert.Equal(1d, fields[NativeProtocol.X]);
|
Assert.Equal(1d, fields[NativeProtocol.X]);
|
||||||
@@ -251,12 +253,12 @@ namespace LuaScript.Tests
|
|||||||
var pixels = new byte[16];
|
var pixels = new byte[16];
|
||||||
var fields = Fields(2, 2, 0d);
|
var fields = Fields(2, 2, 0d);
|
||||||
|
|
||||||
bool ok = _worker.Execute("obj.x = missing.value", fields, pixels, 2, 2, 5000, NoResolver, out _, out string? error);
|
bool ok = _worker.Execute("obj.x = missing.value", fields, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out string? error);
|
||||||
Assert.False(ok);
|
Assert.False(ok);
|
||||||
Assert.False(string.IsNullOrEmpty(error));
|
Assert.False(string.IsNullOrEmpty(error));
|
||||||
|
|
||||||
var fields2 = Fields(2, 2, 7d);
|
var fields2 = Fields(2, 2, 7d);
|
||||||
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, out _, out error);
|
bool ok2 = _worker.Execute("obj.x = obj.time", fields2, pixels, 2, 2, 5000, NoResolver, NoLoadFigure, NoAddEffect, out _, out _, out _, out _, out _, out error);
|
||||||
Assert.True(ok2, error);
|
Assert.True(ok2, error);
|
||||||
Assert.Equal(7d, fields2[NativeProtocol.X]);
|
Assert.Equal(7d, fields2[NativeProtocol.X]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ namespace LuaScript.Tests
|
|||||||
[InlineData("local pd = obj.getpixeldata()", "Native")]
|
[InlineData("local pd = obj.getpixeldata()", "Native")]
|
||||||
[InlineData("--!moonsharp\nobj.setpixel(0,0,1,1,1)", "MoonSharp")]
|
[InlineData("--!moonsharp\nobj.setpixel(0,0,1,1,1)", "MoonSharp")]
|
||||||
[InlineData("--!native\nobj.rz = 1", "Native")]
|
[InlineData("--!native\nobj.rz = 1", "Native")]
|
||||||
|
[InlineData("obj.load(\"figure\", \"円\", 0xff0000, 100)", "MoonSharp")]
|
||||||
|
[InlineData("obj.load(\"figure\", \"円\", 0xff0000, 100)\nlocal r = obj.getpixel(0,0)", "Native")]
|
||||||
|
[InlineData("obj.draw()", "MoonSharp")]
|
||||||
|
[InlineData("obj.draw()\nlocal r = obj.getpixel(0,0)", "MoonSharp")]
|
||||||
|
[InlineData("--!native\nobj.load(\"figure\", \"円\", 0xff0000, 100)", "Native")]
|
||||||
public void ResolveAuto_RoutesPixelScriptsToNative(string script, string expected)
|
public void ResolveAuto_RoutesPixelScriptsToNative(string script, string expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, ScriptDirective.ResolveAuto(script).ToString());
|
Assert.Equal(expected, ScriptDirective.ResolveAuto(script).ToString());
|
||||||
|
|||||||
@@ -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 Track2 { get; set; }
|
||||||
public double Track3 { 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 double Time { get; set; }
|
||||||
public int Frame { get; set; }
|
public int Frame { get; set; }
|
||||||
public int TotalFrame { get; set; }
|
public int TotalFrame { get; set; }
|
||||||
@@ -44,10 +52,20 @@ namespace LuaScript
|
|||||||
|
|
||||||
public Func<SceneObjectResolver>? ResolverProvider { get; set; }
|
public Func<SceneObjectResolver>? ResolverProvider { get; set; }
|
||||||
|
|
||||||
|
private const double Epsilon = 1e-10;
|
||||||
|
|
||||||
private readonly List<SceneObjectQuery> _objectQueries = [];
|
private readonly List<SceneObjectQuery> _objectQueries = [];
|
||||||
|
|
||||||
public IReadOnlyList<SceneObjectQuery> ObjectQueries => _objectQueries;
|
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 RxRad => Rx * Math.PI / 180d;
|
||||||
public double RyRad => Ry * Math.PI / 180d;
|
public double RyRad => Ry * Math.PI / 180d;
|
||||||
public double RzRad => Rz * Math.PI / 180d;
|
public double RzRad => Rz * Math.PI / 180d;
|
||||||
@@ -63,8 +81,10 @@ namespace LuaScript
|
|||||||
private byte[]? _pixelBuffer;
|
private byte[]? _pixelBuffer;
|
||||||
private bool _pixelBufferLoaded;
|
private bool _pixelBufferLoaded;
|
||||||
private bool _isPixelsDirty;
|
private bool _isPixelsDirty;
|
||||||
|
private bool _bufferReplaced;
|
||||||
|
|
||||||
public bool IsPixelsDirty => _isPixelsDirty;
|
public bool IsPixelsDirty => _isPixelsDirty;
|
||||||
|
public bool BufferReplaced => _bufferReplaced;
|
||||||
|
|
||||||
internal int TotalChannels => ImageWidth * ImageHeight * 4;
|
internal int TotalChannels => ImageWidth * ImageHeight * 4;
|
||||||
|
|
||||||
@@ -76,6 +96,17 @@ namespace LuaScript
|
|||||||
_pixelBuffer = null;
|
_pixelBuffer = null;
|
||||||
_pixelBufferLoaded = false;
|
_pixelBufferLoaded = false;
|
||||||
_isPixelsDirty = false;
|
_isPixelsDirty = false;
|
||||||
|
_bufferReplaced = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ReplaceBuffer(byte[] buffer, int width, int height)
|
||||||
|
{
|
||||||
|
_pixelBuffer = buffer;
|
||||||
|
_pixelBufferLoaded = true;
|
||||||
|
_isPixelsDirty = true;
|
||||||
|
_bufferReplaced = true;
|
||||||
|
ImageWidth = width;
|
||||||
|
ImageHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void EnsurePixelBuffer()
|
internal void EnsurePixelBuffer()
|
||||||
@@ -104,6 +135,46 @@ namespace LuaScript
|
|||||||
return false;
|
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)
|
public unsafe (double r, double g, double b, double a) GetPixel(int x, int y)
|
||||||
{
|
{
|
||||||
EnsurePixelBuffer();
|
EnsurePixelBuffer();
|
||||||
|
|||||||
@@ -0,0 +1,184 @@
|
|||||||
|
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 (!ScriptParserHelper.IsSectionHeader(lines[i]))
|
||||||
|
continue;
|
||||||
|
sectionStart = i + 1;
|
||||||
|
sectionEnd = lines.Length;
|
||||||
|
for (int j = sectionStart; j < lines.Length; j++)
|
||||||
|
{
|
||||||
|
if (ScriptParserHelper.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 = ScriptParserHelper.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 && ScriptParserHelper.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 = ScriptParserHelper.SkipSpaces(content, 0);
|
||||||
|
int i = start;
|
||||||
|
while (i < content.Length && content[i] != ',' && content[i] != ' ' && content[i] != '\t')
|
||||||
|
i++;
|
||||||
|
return content.Substring(start, i - start);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,8 +10,6 @@ namespace LuaScript.Compat
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Dialog,
|
Dialog,
|
||||||
Color,
|
|
||||||
Check,
|
|
||||||
Param,
|
Param,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ namespace LuaScript.Compat
|
|||||||
|
|
||||||
for (int i = 0; i < lines.Length; i++)
|
for (int i = 0; i < lines.Length; i++)
|
||||||
{
|
{
|
||||||
if (!IsSectionHeader(lines[i]))
|
if (!ScriptParserHelper.IsSectionHeader(lines[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
hasSection = true;
|
hasSection = true;
|
||||||
@@ -36,7 +34,7 @@ namespace LuaScript.Compat
|
|||||||
sectionEnd = lines.Length;
|
sectionEnd = lines.Length;
|
||||||
for (int j = sectionStart; j < lines.Length; j++)
|
for (int j = sectionStart; j < lines.Length; j++)
|
||||||
{
|
{
|
||||||
if (IsSectionHeader(lines[j]))
|
if (ScriptParserHelper.IsSectionHeader(lines[j]))
|
||||||
{
|
{
|
||||||
sectionEnd = j;
|
sectionEnd = j;
|
||||||
break;
|
break;
|
||||||
@@ -61,15 +59,9 @@ namespace LuaScript.Compat
|
|||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsSectionHeader(string line)
|
|
||||||
{
|
|
||||||
int i = SkipSpaces(line, 0);
|
|
||||||
return i < line.Length && line[i] == '@';
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AppendDeclarations(string line, List<string> prelude)
|
private static void AppendDeclarations(string line, List<string> prelude)
|
||||||
{
|
{
|
||||||
int i = SkipSpaces(line, 0);
|
int i = ScriptParserHelper.SkipSpaces(line, 0);
|
||||||
if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-')
|
if (i + 1 >= line.Length || line[i] != '-' || line[i + 1] != '-')
|
||||||
return;
|
return;
|
||||||
i += 2;
|
i += 2;
|
||||||
@@ -77,7 +69,7 @@ namespace LuaScript.Compat
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
int nameStart = i;
|
int nameStart = i;
|
||||||
while (i < line.Length && IsNameChar(line[i]))
|
while (i < line.Length && ScriptParserHelper.IsNameChar(line[i]))
|
||||||
i++;
|
i++;
|
||||||
if (i >= line.Length || line[i] != ':')
|
if (i >= line.Length || line[i] != ':')
|
||||||
return;
|
return;
|
||||||
@@ -90,12 +82,6 @@ namespace LuaScript.Compat
|
|||||||
case DirectiveKind.Dialog:
|
case DirectiveKind.Dialog:
|
||||||
AppendDialog(content, prelude);
|
AppendDialog(content, prelude);
|
||||||
break;
|
break;
|
||||||
case DirectiveKind.Color:
|
|
||||||
AppendColor(content, prelude);
|
|
||||||
break;
|
|
||||||
case DirectiveKind.Check:
|
|
||||||
AppendCheck(name, content, prelude);
|
|
||||||
break;
|
|
||||||
case DirectiveKind.Param:
|
case DirectiveKind.Param:
|
||||||
AppendParam(content, prelude);
|
AppendParam(content, prelude);
|
||||||
break;
|
break;
|
||||||
@@ -106,12 +92,8 @@ namespace LuaScript.Compat
|
|||||||
{
|
{
|
||||||
if (name.Equals("dialog", StringComparison.OrdinalIgnoreCase))
|
if (name.Equals("dialog", StringComparison.OrdinalIgnoreCase))
|
||||||
return DirectiveKind.Dialog;
|
return DirectiveKind.Dialog;
|
||||||
if (name.Equals("color", StringComparison.OrdinalIgnoreCase))
|
|
||||||
return DirectiveKind.Color;
|
|
||||||
if (name.Equals("param", StringComparison.OrdinalIgnoreCase))
|
if (name.Equals("param", StringComparison.OrdinalIgnoreCase))
|
||||||
return DirectiveKind.Param;
|
return DirectiveKind.Param;
|
||||||
if (name.Length > 5 && name.StartsWith("check", StringComparison.OrdinalIgnoreCase) && AllDigits(name, 5))
|
|
||||||
return DirectiveKind.Check;
|
|
||||||
return DirectiveKind.None;
|
return DirectiveKind.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,89 +113,11 @@ 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)
|
private static void AppendParam(string content, List<string> prelude)
|
||||||
{
|
{
|
||||||
string trimmed = content.Trim();
|
string trimmed = content.Trim();
|
||||||
if (trimmed.Length != 0)
|
if (trimmed.Length != 0)
|
||||||
prelude.Add(trimmed);
|
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'))
|
|
||||||
index++;
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LuaScript.Compat
|
||||||
|
{
|
||||||
|
internal static class FigureRenderer
|
||||||
|
{
|
||||||
|
private enum Shape
|
||||||
|
{
|
||||||
|
Ellipse,
|
||||||
|
Rectangle,
|
||||||
|
Triangle,
|
||||||
|
Pentagon,
|
||||||
|
Hexagon,
|
||||||
|
Star,
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Render(string name, int width, int height, int colorRgb, double lineWidth)
|
||||||
|
{
|
||||||
|
width = Math.Max(1, width);
|
||||||
|
height = Math.Max(1, height);
|
||||||
|
var buffer = new byte[width * height * 4];
|
||||||
|
|
||||||
|
Shape shape = Resolve(name);
|
||||||
|
double hx = width / 2d;
|
||||||
|
double hy = height / 2d;
|
||||||
|
|
||||||
|
double r = (colorRgb >> 16) & 0xFF;
|
||||||
|
double g = (colorRgb >> 8) & 0xFF;
|
||||||
|
double b = colorRgb & 0xFF;
|
||||||
|
|
||||||
|
(double X, double Y)[]? polygon = shape switch
|
||||||
|
{
|
||||||
|
Shape.Triangle => RegularPolygon(3, hx, hy),
|
||||||
|
Shape.Pentagon => RegularPolygon(5, hx, hy),
|
||||||
|
Shape.Hexagon => RegularPolygon(6, hx, hy),
|
||||||
|
Shape.Star => StarPolygon(hx, hy),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool filled = lineWidth <= 0d;
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
double py = y + 0.5 - hy;
|
||||||
|
int row = y * width * 4;
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
double px = x + 0.5 - hx;
|
||||||
|
double d = shape switch
|
||||||
|
{
|
||||||
|
Shape.Ellipse => EllipseSdf(px, py, hx, hy),
|
||||||
|
Shape.Rectangle => BoxSdf(px, py, hx, hy),
|
||||||
|
_ => PolygonSdf(px, py, polygon!),
|
||||||
|
};
|
||||||
|
if (!filled)
|
||||||
|
d = Math.Max(d, -d - lineWidth);
|
||||||
|
|
||||||
|
double coverage = 0.5 - d;
|
||||||
|
if (coverage <= 0d)
|
||||||
|
continue;
|
||||||
|
if (coverage > 1d)
|
||||||
|
coverage = 1d;
|
||||||
|
|
||||||
|
int i = row + x * 4;
|
||||||
|
buffer[i] = ToByte(b * coverage);
|
||||||
|
buffer[i + 1] = ToByte(g * coverage);
|
||||||
|
buffer[i + 2] = ToByte(r * coverage);
|
||||||
|
buffer[i + 3] = ToByte(255d * coverage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Shape Resolve(string name)
|
||||||
|
{
|
||||||
|
switch (name.Trim())
|
||||||
|
{
|
||||||
|
case "円":
|
||||||
|
case "楕円":
|
||||||
|
case "circle":
|
||||||
|
case "ellipse":
|
||||||
|
return Shape.Ellipse;
|
||||||
|
case "三角形":
|
||||||
|
case "triangle":
|
||||||
|
return Shape.Triangle;
|
||||||
|
case "五角形":
|
||||||
|
case "pentagon":
|
||||||
|
return Shape.Pentagon;
|
||||||
|
case "六角形":
|
||||||
|
case "hexagon":
|
||||||
|
return Shape.Hexagon;
|
||||||
|
case "星形":
|
||||||
|
case "star":
|
||||||
|
return Shape.Star;
|
||||||
|
default:
|
||||||
|
return Shape.Rectangle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (double X, double Y)[] RegularPolygon(int sides, double hx, double hy)
|
||||||
|
{
|
||||||
|
var vertices = new (double X, double Y)[sides];
|
||||||
|
for (int k = 0; k < sides; k++)
|
||||||
|
{
|
||||||
|
double angle = -Math.PI / 2d + 2d * Math.PI * k / sides;
|
||||||
|
vertices[k] = (Math.Cos(angle) * hx, Math.Sin(angle) * hy);
|
||||||
|
}
|
||||||
|
return vertices;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (double X, double Y)[] StarPolygon(double hx, double hy)
|
||||||
|
{
|
||||||
|
const double innerRatio = 0.38196601125010515d;
|
||||||
|
var vertices = new (double X, double Y)[10];
|
||||||
|
for (int k = 0; k < 10; k++)
|
||||||
|
{
|
||||||
|
double angle = -Math.PI / 2d + Math.PI * k / 5d;
|
||||||
|
double radius = (k & 1) == 0 ? 1d : innerRatio;
|
||||||
|
vertices[k] = (Math.Cos(angle) * hx * radius, Math.Sin(angle) * hy * radius);
|
||||||
|
}
|
||||||
|
return vertices;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double EllipseSdf(double px, double py, double ax, double ay)
|
||||||
|
{
|
||||||
|
if (ax <= 0d || ay <= 0d)
|
||||||
|
return double.MaxValue;
|
||||||
|
double kx = px / ax;
|
||||||
|
double ky = py / ay;
|
||||||
|
double k1 = Math.Sqrt(kx * kx + ky * ky);
|
||||||
|
if (k1 == 0d)
|
||||||
|
return -Math.Min(ax, ay);
|
||||||
|
double nx = kx / ax;
|
||||||
|
double ny = ky / ay;
|
||||||
|
double k2 = Math.Sqrt(nx * nx + ny * ny);
|
||||||
|
return k1 * (k1 - 1d) / k2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double BoxSdf(double px, double py, double hx, double hy)
|
||||||
|
{
|
||||||
|
double qx = Math.Abs(px) - hx;
|
||||||
|
double qy = Math.Abs(py) - hy;
|
||||||
|
double ox = Math.Max(qx, 0d);
|
||||||
|
double oy = Math.Max(qy, 0d);
|
||||||
|
return Math.Sqrt(ox * ox + oy * oy) + Math.Min(Math.Max(qx, qy), 0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double PolygonSdf(double px, double py, (double X, double Y)[] v)
|
||||||
|
{
|
||||||
|
int n = v.Length;
|
||||||
|
double dx = px - v[0].X;
|
||||||
|
double dy = py - v[0].Y;
|
||||||
|
double d = dx * dx + dy * dy;
|
||||||
|
double s = 1d;
|
||||||
|
|
||||||
|
for (int i = 0, j = n - 1; i < n; j = i, i++)
|
||||||
|
{
|
||||||
|
double ex = v[j].X - v[i].X;
|
||||||
|
double ey = v[j].Y - v[i].Y;
|
||||||
|
double wx = px - v[i].X;
|
||||||
|
double wy = py - v[i].Y;
|
||||||
|
double t = Clamp((wx * ex + wy * ey) / (ex * ex + ey * ey), 0d, 1d);
|
||||||
|
double bx = wx - ex * t;
|
||||||
|
double by = wy - ey * t;
|
||||||
|
d = Math.Min(d, bx * bx + by * by);
|
||||||
|
|
||||||
|
bool c1 = py >= v[i].Y;
|
||||||
|
bool c2 = py < v[j].Y;
|
||||||
|
bool c3 = ex * wy > ey * wx;
|
||||||
|
if ((c1 && c2 && c3) || (!c1 && !c2 && !c3))
|
||||||
|
s = -s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s * Math.Sqrt(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double Clamp(double v, double lo, double hi)
|
||||||
|
{
|
||||||
|
if (v < lo) return lo;
|
||||||
|
if (v > hi) return hi;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte ToByte(double v)
|
||||||
|
{
|
||||||
|
int i = (int)(v + 0.5d);
|
||||||
|
if (i < 0) return 0;
|
||||||
|
if (i > 255) return 255;
|
||||||
|
return (byte)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace LuaScript.Compat
|
||||||
|
{
|
||||||
|
internal static class ScriptParserHelper
|
||||||
|
{
|
||||||
|
public static bool IsSectionHeader(string line)
|
||||||
|
{
|
||||||
|
int i = SkipSpaces(line, 0);
|
||||||
|
return i < line.Length && line[i] == '@';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int SkipSpaces(string text, int index)
|
||||||
|
{
|
||||||
|
while (index < text.Length && (text[index] == ' ' || text[index] == '\t'))
|
||||||
|
index++;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsNameChar(char c) =>
|
||||||
|
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ namespace LuaScript.Engine
|
|||||||
private readonly byte[] _lastCallbackTag = new byte[NativeProtocol.CallbackTagMax];
|
private readonly byte[] _lastCallbackTag = new byte[NativeProtocol.CallbackTagMax];
|
||||||
private int _lastCallbackTagLength = -1;
|
private int _lastCallbackTagLength = -1;
|
||||||
private string _lastCallbackTagText = string.Empty;
|
private string _lastCallbackTagText = string.Empty;
|
||||||
|
private byte[]? _resultBuffer;
|
||||||
|
|
||||||
public LuaJitWorker(string nativeDir)
|
public LuaJitWorker(string nativeDir)
|
||||||
{
|
{
|
||||||
@@ -47,10 +48,20 @@ namespace LuaScript.Engine
|
|||||||
int height,
|
int height,
|
||||||
int timeoutMs,
|
int timeoutMs,
|
||||||
Func<string, int, SceneObjectInfo?> resolveObject,
|
Func<string, int, SceneObjectInfo?> resolveObject,
|
||||||
|
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure,
|
||||||
|
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect,
|
||||||
out bool pixelsDirty,
|
out bool pixelsDirty,
|
||||||
|
out bool bufferReplaced,
|
||||||
|
out byte[]? newPixels,
|
||||||
|
out int resultWidth,
|
||||||
|
out int resultHeight,
|
||||||
out string? error)
|
out string? error)
|
||||||
{
|
{
|
||||||
pixelsDirty = false;
|
pixelsDirty = false;
|
||||||
|
bufferReplaced = false;
|
||||||
|
newPixels = null;
|
||||||
|
resultWidth = width;
|
||||||
|
resultHeight = height;
|
||||||
error = null;
|
error = null;
|
||||||
|
|
||||||
byte[] scriptBytes = Encoding.UTF8.GetBytes(script);
|
byte[] scriptBytes = Encoding.UTF8.GetBytes(script);
|
||||||
@@ -92,7 +103,7 @@ namespace LuaScript.Engine
|
|||||||
if (status != NativeProtocol.StatusCallback)
|
if (status != NativeProtocol.StatusCallback)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ResolveCallback(view, resolveObject);
|
DispatchCallback(view, resolveObject, loadFigure, addEffect);
|
||||||
_workEvent.Set();
|
_workEvent.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,14 +119,52 @@ namespace LuaScript.Engine
|
|||||||
for (int i = NativeProtocol.FirstWritableField; i <= NativeProtocol.LastWritableField; i++)
|
for (int i = NativeProtocol.FirstWritableField; i <= NativeProtocol.LastWritableField; i++)
|
||||||
fields[i] = view.ReadDouble(NativeProtocol.FieldsOffset + i * 8);
|
fields[i] = view.ReadDouble(NativeProtocol.FieldsOffset + i * 8);
|
||||||
|
|
||||||
|
resultWidth = view.ReadInt32(NativeProtocol.OffWidth);
|
||||||
|
resultHeight = view.ReadInt32(NativeProtocol.OffHeight);
|
||||||
|
bufferReplaced = resultWidth != width || resultHeight != height;
|
||||||
|
|
||||||
pixelsDirty = view.ReadInt32(NativeProtocol.OffPixelsDirty) != 0;
|
pixelsDirty = view.ReadInt32(NativeProtocol.OffPixelsDirty) != 0;
|
||||||
if (pixelsDirty)
|
if (pixelsDirty)
|
||||||
view.ReadArray(NativeProtocol.PixelOffset, pixels, 0, pixels.Length);
|
{
|
||||||
|
if (bufferReplaced)
|
||||||
|
{
|
||||||
|
int pixelSize = resultWidth * resultHeight * 4;
|
||||||
|
if (_resultBuffer == null || _resultBuffer.Length < pixelSize)
|
||||||
|
_resultBuffer = new byte[pixelSize];
|
||||||
|
view.ReadArray(NativeProtocol.PixelOffset, _resultBuffer, 0, pixelSize);
|
||||||
|
newPixels = _resultBuffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
view.ReadArray(NativeProtocol.PixelOffset, pixels, 0, pixels.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveCallback(MemoryMappedViewAccessor view, Func<string, int, SceneObjectInfo?> resolveObject)
|
private void DispatchCallback(
|
||||||
|
MemoryMappedViewAccessor view,
|
||||||
|
Func<string, int, SceneObjectInfo?> resolveObject,
|
||||||
|
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure,
|
||||||
|
Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
|
||||||
|
{
|
||||||
|
int kind = view.ReadInt32(NativeProtocol.OffCallbackKind);
|
||||||
|
switch (kind)
|
||||||
|
{
|
||||||
|
case NativeProtocol.CbKindGetObject:
|
||||||
|
ResolveGetObjectCallback(view, resolveObject);
|
||||||
|
break;
|
||||||
|
case NativeProtocol.CbKindLoadFigure:
|
||||||
|
ResolveLoadFigureCallback(view, loadFigure);
|
||||||
|
break;
|
||||||
|
case NativeProtocol.CbKindEffect:
|
||||||
|
ResolveEffectCallback(view, addEffect);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveGetObjectCallback(MemoryMappedViewAccessor view, Func<string, int, SceneObjectInfo?> resolveObject)
|
||||||
{
|
{
|
||||||
int frame = view.ReadInt32(NativeProtocol.OffCallbackFrame);
|
int frame = view.ReadInt32(NativeProtocol.OffCallbackFrame);
|
||||||
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||||
@@ -145,6 +194,70 @@ namespace LuaScript.Engine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResolveLoadFigureCallback(
|
||||||
|
MemoryMappedViewAccessor view,
|
||||||
|
Func<string, int, double, double, double, (byte[] buffer, int w, int h)> loadFigure)
|
||||||
|
{
|
||||||
|
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||||
|
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||||
|
string name = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
|
||||||
|
|
||||||
|
long rOff = NativeProtocol.CallbackResultOffset;
|
||||||
|
int color = (int)view.ReadDouble(rOff + 0 * 8);
|
||||||
|
double size = view.ReadDouble(rOff + 1 * 8);
|
||||||
|
double lineWidth = view.ReadDouble(rOff + 2 * 8);
|
||||||
|
double aspect = view.ReadDouble(rOff + 3 * 8);
|
||||||
|
|
||||||
|
(byte[] buffer, int w, int h) result;
|
||||||
|
try { result = loadFigure(name, color, size, lineWidth, aspect); }
|
||||||
|
catch { result = (new byte[4], 1, 1); }
|
||||||
|
|
||||||
|
int pixelSize = result.w * result.h * 4;
|
||||||
|
long capacity = view.Capacity - NativeProtocol.PixelOffset;
|
||||||
|
if (pixelSize > capacity)
|
||||||
|
{
|
||||||
|
result = (new byte[4], 1, 1);
|
||||||
|
pixelSize = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
view.Write(NativeProtocol.OffLoadResultWidth, result.w);
|
||||||
|
view.Write(NativeProtocol.OffLoadResultHeight, result.h);
|
||||||
|
view.WriteArray(NativeProtocol.PixelOffset, result.buffer, 0, pixelSize);
|
||||||
|
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResolveEffectCallback(MemoryMappedViewAccessor view, Action<string, IReadOnlyList<KeyValuePair<string, object>>> addEffect)
|
||||||
|
{
|
||||||
|
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
|
||||||
|
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
|
||||||
|
|
||||||
|
var segments = Encoding.UTF8.GetString(_callbackTag, 0, tagLen).Split('\0');
|
||||||
|
if (segments.Length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string effectName = segments[0];
|
||||||
|
var arguments = new List<KeyValuePair<string, object>>();
|
||||||
|
for (int i = 1; i + 1 < segments.Length; i += 2)
|
||||||
|
{
|
||||||
|
string key = segments[i];
|
||||||
|
string raw = segments[i + 1];
|
||||||
|
object value;
|
||||||
|
if (raw.Length > 0 && raw[0] == 'n')
|
||||||
|
value = double.TryParse(raw.AsSpan(1), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var d) ? d : 0d;
|
||||||
|
else if (raw.Length > 0 && raw[0] == 'b')
|
||||||
|
value = raw.Length > 1 && raw[1] == '1';
|
||||||
|
else if (raw.Length > 0 && raw[0] == 's')
|
||||||
|
value = raw.Substring(1);
|
||||||
|
else
|
||||||
|
value = raw;
|
||||||
|
arguments.Add(new KeyValuePair<string, object>(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
try { addEffect(effectName, arguments); }
|
||||||
|
catch { }
|
||||||
|
view.Write(NativeProtocol.OffCallbackFound, 1);
|
||||||
|
}
|
||||||
|
|
||||||
private string ResolveTag(int tagLen)
|
private string ResolveTag(int tagLen)
|
||||||
{
|
{
|
||||||
if (tagLen == _lastCallbackTagLength &&
|
if (tagLen == _lastCallbackTagLength &&
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ namespace LuaScript.Engine
|
|||||||
f[NativeProtocol.Track1] = ctx.Track1;
|
f[NativeProtocol.Track1] = ctx.Track1;
|
||||||
f[NativeProtocol.Track2] = ctx.Track2;
|
f[NativeProtocol.Track2] = ctx.Track2;
|
||||||
f[NativeProtocol.Track3] = ctx.Track3;
|
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.Time] = ctx.Time;
|
||||||
f[NativeProtocol.Frame] = ctx.Frame;
|
f[NativeProtocol.Frame] = ctx.Frame;
|
||||||
f[NativeProtocol.TotalFrame] = ctx.TotalFrame;
|
f[NativeProtocol.TotalFrame] = ctx.TotalFrame;
|
||||||
@@ -73,42 +78,17 @@ namespace LuaScript.Engine
|
|||||||
ctx.Oz = f[NativeProtocol.Oz];
|
ctx.Oz = f[NativeProtocol.Oz];
|
||||||
ctx.Alpha = f[NativeProtocol.Alpha];
|
ctx.Alpha = f[NativeProtocol.Alpha];
|
||||||
|
|
||||||
double initialSx = ctx.Sx;
|
ctx.ApplyWriteBack(
|
||||||
double initialSy = ctx.Sy;
|
f[NativeProtocol.Sx],
|
||||||
double initialZoom = ctx.Zoom;
|
f[NativeProtocol.Sy],
|
||||||
double initialAspect = ctx.Aspect;
|
f[NativeProtocol.Zoom],
|
||||||
|
f[NativeProtocol.Aspect],
|
||||||
ctx.Sx = f[NativeProtocol.Sx];
|
f[NativeProtocol.Rx],
|
||||||
ctx.Sy = f[NativeProtocol.Sy];
|
f[NativeProtocol.Ry],
|
||||||
ctx.Zoom = f[NativeProtocol.Zoom];
|
f[NativeProtocol.Rz],
|
||||||
ctx.Aspect = f[NativeProtocol.Aspect];
|
f[NativeProtocol.Rxr],
|
||||||
|
f[NativeProtocol.Ryr],
|
||||||
bool sxsyChanged = Math.Abs(ctx.Sx - initialSx) > Epsilon || Math.Abs(ctx.Sy - initialSy) > Epsilon;
|
f[NativeProtocol.Rzr]);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,9 @@ namespace LuaScript.Engine
|
|||||||
public const int OffCallbackFrame = 32;
|
public const int OffCallbackFrame = 32;
|
||||||
public const int OffCallbackTagLen = 36;
|
public const int OffCallbackTagLen = 36;
|
||||||
public const int OffCallbackFound = 40;
|
public const int OffCallbackFound = 40;
|
||||||
|
public const int OffCallbackKind = 44;
|
||||||
|
public const int OffLoadResultWidth = 48;
|
||||||
|
public const int OffLoadResultHeight = 52;
|
||||||
|
|
||||||
public const int HeaderSize = 64;
|
public const int HeaderSize = 64;
|
||||||
|
|
||||||
@@ -36,10 +39,14 @@ namespace LuaScript.Engine
|
|||||||
public const int ErrorMax = 4 * 1024;
|
public const int ErrorMax = 4 * 1024;
|
||||||
|
|
||||||
public const int CallbackTagOffset = ErrorOffset + ErrorMax;
|
public const int CallbackTagOffset = ErrorOffset + ErrorMax;
|
||||||
public const int CallbackTagMax = 256;
|
public const int CallbackTagMax = 4096;
|
||||||
public const int CallbackResultOffset = CallbackTagOffset + CallbackTagMax;
|
public const int CallbackResultOffset = CallbackTagOffset + CallbackTagMax;
|
||||||
public const int CallbackResultCount = 8;
|
public const int CallbackResultCount = 8;
|
||||||
|
|
||||||
|
public const int CbKindGetObject = 0;
|
||||||
|
public const int CbKindLoadFigure = 1;
|
||||||
|
public const int CbKindEffect = 2;
|
||||||
|
|
||||||
public const int CbExist = 0;
|
public const int CbExist = 0;
|
||||||
public const int CbX = 1;
|
public const int CbX = 1;
|
||||||
public const int CbY = 2;
|
public const int CbY = 2;
|
||||||
@@ -104,11 +111,18 @@ namespace LuaScript.Engine
|
|||||||
public const int IsPaused = 50;
|
public const int IsPaused = 50;
|
||||||
public const int TimelineFrame = 51;
|
public const int TimelineFrame = 51;
|
||||||
public const int TimelineTime = 52;
|
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 FirstWritableField = X;
|
||||||
public const int LastWritableField = Rzr;
|
public const int LastWritableField = Rzr;
|
||||||
|
|
||||||
|
public const int MaxPixelBufferSize = 3840 * 2160 * 4;
|
||||||
|
|
||||||
public static long BufferSize(int width, int height) =>
|
public static long BufferSize(int width, int height) =>
|
||||||
PixelOffset + (long)width * height * 4;
|
PixelOffset + Math.Max((long)width * height * 4, MaxPixelBufferSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LuaScript.Engine
|
||||||
|
{
|
||||||
|
internal static class ScriptDirective
|
||||||
|
{
|
||||||
|
public static ScriptEngineKind Resolve(string? script) =>
|
||||||
|
TryGetDirective(script, out var kind) ? kind : ScriptEngineKind.MoonSharp;
|
||||||
|
|
||||||
|
public static ScriptEngineKind ResolveAuto(string? script)
|
||||||
|
{
|
||||||
|
if (TryGetDirective(script, out var kind))
|
||||||
|
return kind;
|
||||||
|
if (UsesDrawingApi(script))
|
||||||
|
return ScriptEngineKind.MoonSharp;
|
||||||
|
return UsesPixelApi(script) ? ScriptEngineKind.Native : ScriptEngineKind.MoonSharp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool UsesPixelApi(string? script) =>
|
||||||
|
script is not null && (script.Contains("getpixel", StringComparison.Ordinal) || script.Contains("setpixel", StringComparison.Ordinal));
|
||||||
|
|
||||||
|
public static bool UsesDrawingApi(string? script) =>
|
||||||
|
script is not null && (
|
||||||
|
script.Contains("obj.draw", StringComparison.Ordinal) ||
|
||||||
|
script.Contains("obj.setoption", StringComparison.Ordinal) ||
|
||||||
|
script.Contains("obj.copybuffer", StringComparison.Ordinal));
|
||||||
|
|
||||||
|
private static bool TryGetDirective(string? script, out ScriptEngineKind kind)
|
||||||
|
{
|
||||||
|
kind = ScriptEngineKind.MoonSharp;
|
||||||
|
if (string.IsNullOrEmpty(script))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
int length = script.Length;
|
||||||
|
while (index < length)
|
||||||
|
{
|
||||||
|
int lineStart = index;
|
||||||
|
while (index < length && script[index] != '\n')
|
||||||
|
index++;
|
||||||
|
int lineEnd = index;
|
||||||
|
if (lineEnd > lineStart && script[lineEnd - 1] == '\r')
|
||||||
|
lineEnd--;
|
||||||
|
|
||||||
|
if (TryParseDirectiveLine(script, lineStart, lineEnd, out kind))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryParseDirectiveLine(string script, int start, int end, out ScriptEngineKind kind)
|
||||||
|
{
|
||||||
|
kind = ScriptEngineKind.MoonSharp;
|
||||||
|
|
||||||
|
int i = start;
|
||||||
|
while (i < end && (script[i] == ' ' || script[i] == '\t'))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (i + 3 > end || script[i] != '-' || script[i + 1] != '-' || script[i + 2] != '!')
|
||||||
|
return false;
|
||||||
|
i += 3;
|
||||||
|
|
||||||
|
while (i < end && (script[i] == ' ' || script[i] == '\t'))
|
||||||
|
i++;
|
||||||
|
|
||||||
|
int tokenStart = i;
|
||||||
|
while (i < end && IsTokenChar(script[i]))
|
||||||
|
i++;
|
||||||
|
int tokenEnd = i;
|
||||||
|
|
||||||
|
while (i < end && (script[i] == ' ' || script[i] == '\t'))
|
||||||
|
i++;
|
||||||
|
if (i != end)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var token = script.AsSpan(tokenStart, tokenEnd - tokenStart);
|
||||||
|
if (token.Equals("native", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
kind = ScriptEngineKind.Native;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (token.Equals("gpu", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
kind = ScriptEngineKind.Gpu;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (token.Equals("cpu", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
kind = ScriptEngineKind.Cpu;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (token.Equals("moonsharp", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
kind = ScriptEngineKind.MoonSharp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsTokenChar(char c) =>
|
||||||
|
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,98 +9,4 @@ namespace LuaScript.Engine
|
|||||||
Gpu,
|
Gpu,
|
||||||
Cpu,
|
Cpu,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class ScriptDirective
|
|
||||||
{
|
|
||||||
public static ScriptEngineKind Resolve(string? script) =>
|
|
||||||
TryGetDirective(script, out var kind) ? kind : ScriptEngineKind.MoonSharp;
|
|
||||||
|
|
||||||
public static ScriptEngineKind ResolveAuto(string? script)
|
|
||||||
{
|
|
||||||
if (TryGetDirective(script, out var kind))
|
|
||||||
return kind;
|
|
||||||
return UsesPixelApi(script) ? ScriptEngineKind.Native : ScriptEngineKind.MoonSharp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool UsesPixelApi(string? script) =>
|
|
||||||
script is not null && (script.Contains("getpixel", StringComparison.Ordinal) || script.Contains("setpixel", StringComparison.Ordinal));
|
|
||||||
|
|
||||||
private static bool TryGetDirective(string? script, out ScriptEngineKind kind)
|
|
||||||
{
|
|
||||||
kind = ScriptEngineKind.MoonSharp;
|
|
||||||
if (string.IsNullOrEmpty(script))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
int length = script.Length;
|
|
||||||
while (index < length)
|
|
||||||
{
|
|
||||||
int lineStart = index;
|
|
||||||
while (index < length && script[index] != '\n')
|
|
||||||
index++;
|
|
||||||
int lineEnd = index;
|
|
||||||
if (lineEnd > lineStart && script[lineEnd - 1] == '\r')
|
|
||||||
lineEnd--;
|
|
||||||
|
|
||||||
if (TryParseDirectiveLine(script, lineStart, lineEnd, out kind))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TryParseDirectiveLine(string script, int start, int end, out ScriptEngineKind kind)
|
|
||||||
{
|
|
||||||
kind = ScriptEngineKind.MoonSharp;
|
|
||||||
|
|
||||||
int i = start;
|
|
||||||
while (i < end && (script[i] == ' ' || script[i] == '\t'))
|
|
||||||
i++;
|
|
||||||
|
|
||||||
if (i + 3 > end || script[i] != '-' || script[i + 1] != '-' || script[i + 2] != '!')
|
|
||||||
return false;
|
|
||||||
i += 3;
|
|
||||||
|
|
||||||
while (i < end && (script[i] == ' ' || script[i] == '\t'))
|
|
||||||
i++;
|
|
||||||
|
|
||||||
int tokenStart = i;
|
|
||||||
while (i < end && IsTokenChar(script[i]))
|
|
||||||
i++;
|
|
||||||
int tokenEnd = i;
|
|
||||||
|
|
||||||
while (i < end && (script[i] == ' ' || script[i] == '\t'))
|
|
||||||
i++;
|
|
||||||
if (i != end)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var token = script.AsSpan(tokenStart, tokenEnd - tokenStart);
|
|
||||||
if (token.Equals("native", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
kind = ScriptEngineKind.Native;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (token.Equals("gpu", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
kind = ScriptEngineKind.Gpu;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (token.Equals("cpu", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
kind = ScriptEngineKind.Cpu;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (token.Equals("moonsharp", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
kind = ScriptEngineKind.MoonSharp;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsTokenChar(char c) =>
|
|
||||||
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ namespace LuaScript
|
|||||||
"obj.time", "obj.totaltime", "obj.t", "obj.frame", "obj.totalframe",
|
"obj.time", "obj.totaltime", "obj.t", "obj.frame", "obj.totalframe",
|
||||||
"obj.framerate", "obj.layer", "obj.index", "obj.num",
|
"obj.framerate", "obj.layer", "obj.index", "obj.num",
|
||||||
"obj.getpixel", "obj.setpixel",
|
"obj.getpixel", "obj.setpixel",
|
||||||
"obj.getpixeldata", "obj.rand"
|
"obj.getpixeldata", "obj.rand", "obj.load"
|
||||||
]),
|
]),
|
||||||
("math", [
|
("math", [
|
||||||
"math.abs", "math.ceil", "math.cos", "math.exp", "math.floor",
|
"math.abs", "math.ceil", "math.cos", "math.exp", "math.floor",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Version>1.4.0</Version>
|
<Version>1.7.1</Version>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LuaScript
|
||||||
|
{
|
||||||
|
internal sealed class LuaScriptCompilationException(string message, Exception? inner = null) : LuaScriptException(message, inner);
|
||||||
|
}
|
||||||
+104
-1
@@ -1,8 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using LuaScript.Compat;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using YukkuriMovieMaker.Commons;
|
using YukkuriMovieMaker.Commons;
|
||||||
using YukkuriMovieMaker.Controls;
|
using YukkuriMovieMaker.Controls;
|
||||||
using YukkuriMovieMaker.Exo;
|
using YukkuriMovieMaker.Exo;
|
||||||
|
using YukkuriMovieMaker.ItemEditor.CustomVisibilityAttributes;
|
||||||
using YukkuriMovieMaker.Player.Video;
|
using YukkuriMovieMaker.Player.Video;
|
||||||
using YukkuriMovieMaker.Plugin;
|
using YukkuriMovieMaker.Plugin;
|
||||||
using YukkuriMovieMaker.Plugin.Effects;
|
using YukkuriMovieMaker.Plugin.Effects;
|
||||||
@@ -27,27 +31,126 @@ namespace LuaScript
|
|||||||
|
|
||||||
[Display(GroupName = nameof(Texts.ScriptGroup), ResourceType = typeof(Texts))]
|
[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)]
|
[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 _script = DefaultScript;
|
||||||
|
|
||||||
string IScriptProvider.DefaultScript => 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))]
|
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track0), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||||
[AnimationSlider("F2", "", -100, 100)]
|
[AnimationSlider("F2", "", -100, 100)]
|
||||||
|
[ShowPropertyEditorWhen(nameof(IsTrack0Visible), true)]
|
||||||
public Animation Track0 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
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))]
|
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track1), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||||
[AnimationSlider("F2", "", -100, 100)]
|
[AnimationSlider("F2", "", -100, 100)]
|
||||||
|
[ShowPropertyEditorWhen(nameof(IsTrack1Visible), true)]
|
||||||
public Animation Track1 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
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))]
|
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track2), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||||
[AnimationSlider("F2", "", -100, 100)]
|
[AnimationSlider("F2", "", -100, 100)]
|
||||||
|
[ShowPropertyEditorWhen(nameof(IsTrack2Visible), true)]
|
||||||
public Animation Track2 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
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))]
|
[Display(GroupName = nameof(Texts.ParametersGroup), Name = nameof(Texts.Track3), Description = nameof(Texts.TrackDesc), ResourceType = typeof(Texts))]
|
||||||
[AnimationSlider("F2", "", -100, 100)]
|
[AnimationSlider("F2", "", -100, 100)]
|
||||||
|
[ShowPropertyEditorWhen(nameof(IsTrack3Visible), true)]
|
||||||
public Animation Track3 { get; } = new Animation(0, YMM4Constants.VerySmallValue, YMM4Constants.VeryLargeValue);
|
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 IEnumerable<string> CreateExoVideoFilters(int keyFrameIndex, ExoOutputDescription exoOutputDescription) => [];
|
||||||
|
|
||||||
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
public override IVideoEffectProcessor CreateVideoEffect(IGraphicsDevicesAndContext devices)
|
||||||
|
|||||||
+106
-130
@@ -28,6 +28,12 @@ namespace LuaScript
|
|||||||
double Track1,
|
double Track1,
|
||||||
double Track2,
|
double Track2,
|
||||||
double Track3,
|
double Track3,
|
||||||
|
bool Check0,
|
||||||
|
bool Check1,
|
||||||
|
bool Check2,
|
||||||
|
bool Check3,
|
||||||
|
bool HasColor,
|
||||||
|
int Color,
|
||||||
string Script,
|
string Script,
|
||||||
TimelineSourceUsage Usage,
|
TimelineSourceUsage Usage,
|
||||||
Guid SceneId,
|
Guid SceneId,
|
||||||
@@ -57,6 +63,7 @@ namespace LuaScript
|
|||||||
private LuaJitWorker? _nativeWorker;
|
private LuaJitWorker? _nativeWorker;
|
||||||
private double[]? _nativeFields;
|
private double[]? _nativeFields;
|
||||||
private bool _nativeWarned;
|
private bool _nativeWarned;
|
||||||
|
private bool _effectChainWarned;
|
||||||
|
|
||||||
private EffectDescription? _frameDesc;
|
private EffectDescription? _frameDesc;
|
||||||
private SceneObjectResolver? _frameResolver;
|
private SceneObjectResolver? _frameResolver;
|
||||||
@@ -68,14 +75,7 @@ namespace LuaScript
|
|||||||
|
|
||||||
private GraphicsDevicesAndContext? _ownCtx;
|
private GraphicsDevicesAndContext? _ownCtx;
|
||||||
|
|
||||||
private ID2D1Bitmap1? _renderTarget;
|
private PixelBufferManager? _pixelManager;
|
||||||
private ID2D1Bitmap1? _stagingBitmap;
|
|
||||||
private ID2D1Bitmap1? _outputBitmap;
|
|
||||||
private AffineTransform2D? _transformEffect;
|
|
||||||
private byte[]? _pixelBuffer;
|
|
||||||
private int _bitmapWidth;
|
|
||||||
private int _bitmapHeight;
|
|
||||||
private RawRectF _cachedBounds;
|
|
||||||
|
|
||||||
private bool _isFirst = true;
|
private bool _isFirst = true;
|
||||||
private string _sourceScript = string.Empty;
|
private string _sourceScript = string.Empty;
|
||||||
@@ -85,12 +85,15 @@ namespace LuaScript
|
|||||||
private RenderKey _cachedKey;
|
private RenderKey _cachedKey;
|
||||||
private SceneObjectQuery[] _cachedQueries = [];
|
private SceneObjectQuery[] _cachedQueries = [];
|
||||||
private DrawDescription? _cachedOutputDesc;
|
private DrawDescription? _cachedOutputDesc;
|
||||||
private bool _cachedPixelsModified;
|
private ID2D1Image? _cachedEffectOutput;
|
||||||
|
|
||||||
|
private VideoEffectChain? _effectChain;
|
||||||
|
|
||||||
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
||||||
{
|
{
|
||||||
_ownCtx = new GraphicsDevicesAndContext(devices);
|
_ownCtx = new GraphicsDevicesAndContext(devices);
|
||||||
disposer.Collect(_ownCtx);
|
disposer.Collect(_ownCtx);
|
||||||
|
_pixelManager = new PixelBufferManager(_ownCtx);
|
||||||
_context.ResolverProvider = GetFrameResolver;
|
_context.ResolverProvider = GetFrameResolver;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -150,16 +153,22 @@ namespace LuaScript
|
|||||||
var time = desc.ItemPosition.Time.TotalSeconds;
|
var time = desc.ItemPosition.Time.TotalSeconds;
|
||||||
var script = item.Script ?? string.Empty;
|
var script = item.Script ?? string.Empty;
|
||||||
|
|
||||||
var t0 = item.Track0.GetValue(frame, length, fps);
|
var layout = item.Layout;
|
||||||
var t1 = item.Track1.GetValue(frame, length, fps);
|
var t0 = ClampTrack(item.Track0.GetValue(frame, length, fps), layout, 0);
|
||||||
var t2 = item.Track2.GetValue(frame, length, fps);
|
var t1 = ClampTrack(item.Track1.GetValue(frame, length, fps), layout, 1);
|
||||||
var t3 = item.Track3.GetValue(frame, length, fps);
|
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 inDesc = desc.DrawDescription;
|
||||||
|
|
||||||
var key = new RenderKey(
|
var key = new RenderKey(
|
||||||
frame, time, length, fps,
|
frame, time, length, fps,
|
||||||
t0, t1, t2, t3,
|
t0, t1, t2, t3,
|
||||||
|
c0, c1, c2, c3, hasColor, colorRgb,
|
||||||
script, desc.Usage, desc.SceneId,
|
script, desc.Usage, desc.SceneId,
|
||||||
desc.TimelinePosition.Frame,
|
desc.TimelinePosition.Frame,
|
||||||
desc.TimelinePosition.Time.TotalSeconds,
|
desc.TimelinePosition.Time.TotalSeconds,
|
||||||
@@ -177,7 +186,7 @@ namespace LuaScript
|
|||||||
if (!_isFirst && key == _cachedKey &&
|
if (!_isFirst && key == _cachedKey &&
|
||||||
(_cachedQueries.Length == 0 || QueriesMatch(_cachedQueries, GetFrameResolver())))
|
(_cachedQueries.Length == 0 || QueriesMatch(_cachedQueries, GetFrameResolver())))
|
||||||
{
|
{
|
||||||
effectOutput = _cachedPixelsModified ? _transformEffect?.Output : null;
|
effectOutput = _cachedEffectOutput;
|
||||||
return _cachedOutputDesc ?? inDesc;
|
return _cachedOutputDesc ?? inDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +199,6 @@ namespace LuaScript
|
|||||||
ctx.SetPixelLoader(() => LoadInputPixels(bounds, imgW, imgH));
|
ctx.SetPixelLoader(() => LoadInputPixels(bounds, imgW, imgH));
|
||||||
|
|
||||||
DrawDescription outDesc = inDesc;
|
DrawDescription outDesc = inDesc;
|
||||||
bool pixelsModified = false;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -202,7 +210,7 @@ namespace LuaScript
|
|||||||
|
|
||||||
if (nativeReady)
|
if (nativeReady)
|
||||||
{
|
{
|
||||||
pixelsModified = ExecuteNative(runnable, ctx, bounds, imgW, imgH);
|
ExecuteNative(runnable, ctx, bounds, imgW, imgH);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -210,11 +218,13 @@ namespace LuaScript
|
|||||||
|
|
||||||
if (ctx.IsPixelsDirty)
|
if (ctx.IsPixelsDirty)
|
||||||
{
|
{
|
||||||
EnsureBitmaps(imgW, imgH);
|
int bufW = ctx.ImageWidth;
|
||||||
WritePixelsToOutput(ctx.GetPixelBuffer()!, imgW);
|
int bufH = ctx.ImageHeight;
|
||||||
UpdateTransformEffect(bounds);
|
_pixelManager!.WritePixelsToOutput(ctx.GetPixelBuffer()!, bufW, bufH);
|
||||||
effectOutput = _transformEffect!.Output;
|
if (ctx.BufferReplaced)
|
||||||
pixelsModified = true;
|
effectOutput = _pixelManager.GetTransformOutput(-bufW / 2f, -bufH / 2f);
|
||||||
|
else
|
||||||
|
effectOutput = _pixelManager.GetTransformOutput(bounds.Left, bounds.Top);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -223,6 +233,20 @@ namespace LuaScript
|
|||||||
}
|
}
|
||||||
|
|
||||||
outDesc = BuildOutputDesc(inDesc, ctx);
|
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)
|
catch (LuaScriptTimeoutException ex)
|
||||||
{
|
{
|
||||||
@@ -248,11 +272,17 @@ namespace LuaScript
|
|||||||
_cachedKey = key;
|
_cachedKey = key;
|
||||||
_cachedQueries = ctx.ObjectQueries.Count == 0 ? [] : [.. ctx.ObjectQueries];
|
_cachedQueries = ctx.ObjectQueries.Count == 0 ? [] : [.. ctx.ObjectQueries];
|
||||||
_cachedOutputDesc = outDesc;
|
_cachedOutputDesc = outDesc;
|
||||||
_cachedPixelsModified = pixelsModified;
|
_cachedEffectOutput = effectOutput;
|
||||||
|
|
||||||
return outDesc;
|
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)
|
private static SceneObjectResolver BuildSceneObjectResolver(EffectDescription desc)
|
||||||
{
|
{
|
||||||
var scenes = desc.Scenes;
|
var scenes = desc.Scenes;
|
||||||
@@ -309,6 +339,7 @@ namespace LuaScript
|
|||||||
: 0d;
|
: 0d;
|
||||||
|
|
||||||
ctx.ClearQueries();
|
ctx.ClearQueries();
|
||||||
|
ctx.ClearEffects();
|
||||||
|
|
||||||
ctx.ImageWidth = imgW;
|
ctx.ImageWidth = imgW;
|
||||||
ctx.ImageHeight = imgH;
|
ctx.ImageHeight = imgH;
|
||||||
@@ -330,6 +361,12 @@ namespace LuaScript
|
|||||||
ctx.Track1 = key.Track1;
|
ctx.Track1 = key.Track1;
|
||||||
ctx.Track2 = key.Track2;
|
ctx.Track2 = key.Track2;
|
||||||
ctx.Track3 = key.Track3;
|
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.Time = key.Time;
|
||||||
ctx.Frame = key.Frame;
|
ctx.Frame = key.Frame;
|
||||||
ctx.TotalFrame = key.Length;
|
ctx.TotalFrame = key.Length;
|
||||||
@@ -353,6 +390,11 @@ namespace LuaScript
|
|||||||
ctx.TimeRatio = key.Length > 0 ? key.Frame / (double)key.Length : 0d;
|
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)
|
private static DrawDescription BuildOutputDesc(DrawDescription inDesc, AviUtlScriptContext ctx)
|
||||||
{
|
{
|
||||||
return inDesc with
|
return inDesc with
|
||||||
@@ -372,6 +414,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.");
|
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)
|
private bool ExecuteNative(string script, AviUtlScriptContext ctx, RawRectF bounds, int imgW, int imgH)
|
||||||
{
|
{
|
||||||
_nativeWorker ??= new LuaJitWorker(NativeDirectory);
|
_nativeWorker ??= new LuaJitWorker(NativeDirectory);
|
||||||
@@ -383,7 +432,10 @@ namespace LuaScript
|
|||||||
bool ok = _nativeWorker.Execute(
|
bool ok = _nativeWorker.Execute(
|
||||||
script, _nativeFields, buffer, imgW, imgH, NativeTimeoutMilliseconds,
|
script, _nativeFields, buffer, imgW, imgH, NativeTimeoutMilliseconds,
|
||||||
(tag, frame) => ctx.ResolveObject(tag, frame, out var info) ? info : null,
|
(tag, frame) => ctx.ResolveObject(tag, frame, out var info) ? info : null,
|
||||||
out bool dirty, out string? error);
|
NativeLoadFigure,
|
||||||
|
(name, args) => ctx.AddEffect(new AviUtlEffectRequest(name, args)),
|
||||||
|
out bool dirty, out bool bufferReplaced, out byte[]? newPixels,
|
||||||
|
out int resultW, out int resultH, out string? error);
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
@@ -396,10 +448,21 @@ namespace LuaScript
|
|||||||
|
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
EnsureBitmaps(imgW, imgH);
|
int outW = bufferReplaced ? resultW : imgW;
|
||||||
WritePixelsToOutput(buffer, imgW);
|
int outH = bufferReplaced ? resultH : imgH;
|
||||||
UpdateTransformEffect(bounds);
|
byte[] outPixels = buffer;
|
||||||
effectOutput = _transformEffect!.Output;
|
|
||||||
|
if (bufferReplaced && newPixels != null)
|
||||||
|
{
|
||||||
|
outPixels = newPixels;
|
||||||
|
ctx.ReplaceBuffer(outPixels, outW, outH);
|
||||||
|
}
|
||||||
|
|
||||||
|
_pixelManager!.WritePixelsToOutput(outPixels, outW, outH);
|
||||||
|
if (bufferReplaced)
|
||||||
|
effectOutput = _pixelManager.GetTransformOutput(-outW / 2f, -outH / 2f);
|
||||||
|
else
|
||||||
|
effectOutput = _pixelManager.GetTransformOutput(bounds.Left, bounds.Top);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,48 +470,24 @@ namespace LuaScript
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static (byte[] buffer, int w, int h) NativeLoadFigure(string name, int color, double size, double lineWidth, double aspect)
|
||||||
|
{
|
||||||
|
aspect = Math.Clamp(aspect, -1d, 1d);
|
||||||
|
int boundingSize = Math.Max(1, (int)Math.Round(size));
|
||||||
|
double w = aspect >= 0d ? boundingSize * (1d - aspect) : boundingSize;
|
||||||
|
double h = aspect <= 0d ? boundingSize * (1d + aspect) : boundingSize;
|
||||||
|
int fw = Math.Max(1, (int)Math.Round(w));
|
||||||
|
int fh = Math.Max(1, (int)Math.Round(h));
|
||||||
|
var buffer = FigureRenderer.Render(name, fw, fh, color, lineWidth);
|
||||||
|
return (buffer, fw, fh);
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] LoadInputPixels(RawRectF bounds, int width, int height)
|
private byte[] LoadInputPixels(RawRectF bounds, int width, int height)
|
||||||
{
|
{
|
||||||
_pixelLoaderSemaphore.Wait();
|
_pixelLoaderSemaphore.Wait();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EnsureBitmaps(width, height);
|
return _pixelManager!.LoadInputPixels(input!, bounds, width, height);
|
||||||
|
|
||||||
var dc = _ownCtx!.DeviceContext;
|
|
||||||
var savedTarget = dc.Target;
|
|
||||||
|
|
||||||
dc.Target = _renderTarget;
|
|
||||||
dc.BeginDraw();
|
|
||||||
dc.Clear(null);
|
|
||||||
dc.DrawImage(input!, new Vector2(-bounds.Left, -bounds.Top));
|
|
||||||
dc.EndDraw();
|
|
||||||
dc.Target = savedTarget;
|
|
||||||
|
|
||||||
_stagingBitmap!.CopyFromBitmap(_renderTarget!);
|
|
||||||
|
|
||||||
var mapped = _stagingBitmap.Map(MapOptions.Read);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (mapped.Pitch == width * 4)
|
|
||||||
{
|
|
||||||
Marshal.Copy(mapped.Bits, _pixelBuffer!, 0, width * height * 4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int row = 0; row < height; row++)
|
|
||||||
Marshal.Copy(
|
|
||||||
mapped.Bits + mapped.Pitch * row,
|
|
||||||
_pixelBuffer!,
|
|
||||||
row * width * 4,
|
|
||||||
width * 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_stagingBitmap.Unmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _pixelBuffer!;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -456,79 +495,16 @@ namespace LuaScript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void WritePixelsToOutput(byte[] pixels, int width)
|
|
||||||
{
|
|
||||||
fixed (byte* ptr = pixels)
|
|
||||||
_outputBitmap!.CopyFromMemory(new nint(ptr), width * 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateTransformEffect(RawRectF bounds)
|
|
||||||
{
|
|
||||||
if (_transformEffect is null)
|
|
||||||
{
|
|
||||||
_transformEffect = new AffineTransform2D(_ownCtx!.DeviceContext);
|
|
||||||
_transformEffect.SetInput(0, _outputBitmap, true);
|
|
||||||
_cachedBounds = default;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_cachedBounds.Left != bounds.Left || _cachedBounds.Top != bounds.Top)
|
|
||||||
{
|
|
||||||
_transformEffect.TransformMatrix = Matrix3x2.CreateTranslation(bounds.Left, bounds.Top);
|
|
||||||
_cachedBounds = bounds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EnsureBitmaps(int width, int height)
|
|
||||||
{
|
|
||||||
if (_bitmapWidth == width && _bitmapHeight == height) return;
|
|
||||||
|
|
||||||
_renderTarget?.Dispose();
|
|
||||||
_stagingBitmap?.Dispose();
|
|
||||||
_outputBitmap?.Dispose();
|
|
||||||
_transformEffect?.Dispose();
|
|
||||||
_renderTarget = null;
|
|
||||||
_stagingBitmap = null;
|
|
||||||
_outputBitmap = null;
|
|
||||||
_transformEffect = null;
|
|
||||||
_bitmapWidth = 0;
|
|
||||||
_bitmapHeight = 0;
|
|
||||||
|
|
||||||
var dc = _ownCtx!.DeviceContext;
|
|
||||||
|
|
||||||
_renderTarget = dc.CreateEmptyBitmap(width, height, BitmapOptions.Target);
|
|
||||||
|
|
||||||
var stagingProps = new BitmapProperties1(
|
|
||||||
new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied),
|
|
||||||
96f, 96f,
|
|
||||||
BitmapOptions.CpuRead | BitmapOptions.CannotDraw);
|
|
||||||
_stagingBitmap = dc.CreateBitmap(
|
|
||||||
new SizeI(width, height),
|
|
||||||
nint.Zero,
|
|
||||||
width * 4,
|
|
||||||
stagingProps);
|
|
||||||
|
|
||||||
_outputBitmap = dc.CreateEmptyBitmap(width, height, BitmapOptions.Target);
|
|
||||||
_pixelBuffer = new byte[width * height * 4];
|
|
||||||
|
|
||||||
_bitmapWidth = width;
|
|
||||||
_bitmapHeight = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
_engine.Dispose();
|
_engine.Dispose();
|
||||||
_nativeWorker?.Dispose();
|
_nativeWorker?.Dispose();
|
||||||
|
_effectChain?.Dispose();
|
||||||
_pixelLoaderSemaphore.Dispose();
|
_pixelLoaderSemaphore.Dispose();
|
||||||
_renderTarget?.Dispose();
|
_pixelManager?.Dispose();
|
||||||
_stagingBitmap?.Dispose();
|
_pixelManager = null;
|
||||||
_outputBitmap?.Dispose();
|
|
||||||
_transformEffect?.Dispose();
|
|
||||||
_renderTarget = null;
|
|
||||||
_stagingBitmap = null;
|
|
||||||
_outputBitmap = null;
|
|
||||||
_transformEffect = null;
|
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
+84
-33
@@ -313,6 +313,12 @@ namespace LuaScript
|
|||||||
_objTable!["track1"] = ctx.Track1;
|
_objTable!["track1"] = ctx.Track1;
|
||||||
_objTable!["track2"] = ctx.Track2;
|
_objTable!["track2"] = ctx.Track2;
|
||||||
_objTable!["track3"] = ctx.Track3;
|
_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!["time"] = ctx.Time;
|
||||||
_objTable!["frame"] = ctx.Frame;
|
_objTable!["frame"] = ctx.Frame;
|
||||||
_objTable!["totalframe"] = ctx.TotalFrame;
|
_objTable!["totalframe"] = ctx.TotalFrame;
|
||||||
@@ -463,6 +469,73 @@ namespace LuaScript
|
|||||||
double frame = args.Count > 3 ? args[3].CastToNumber() ?? frameDefault : frameDefault;
|
double frame = args.Count > 3 ? args[3].CastToNumber() ?? frameDefault : frameDefault;
|
||||||
return DynValue.NewNumber(AviUtlRandom.Next(a, b, seed, frame));
|
return DynValue.NewNumber(AviUtlRandom.Next(a, b, seed, frame));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
obj["load"] = DynValue.NewCallback((_, args) =>
|
||||||
|
{
|
||||||
|
_activeCancellation.ThrowIfCancellationRequested();
|
||||||
|
if (_activeContext is null || args.Count < 4)
|
||||||
|
return DynValue.Void;
|
||||||
|
if (args[0].Type != DataType.String || args[0].String != "figure")
|
||||||
|
return DynValue.Void;
|
||||||
|
|
||||||
|
string name = args[1].Type == DataType.String ? args[1].String : string.Empty;
|
||||||
|
int color = (int)(args[2].CastToNumber() ?? 0d);
|
||||||
|
double size = args[3].CastToNumber() ?? 0d;
|
||||||
|
double line = args.Count > 4 ? args[4].CastToNumber() ?? 0d : 0d;
|
||||||
|
double aspect = args.Count > 5 ? Math.Clamp(args[5].CastToNumber() ?? 0d, -1d, 1d) : 0d;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
int boundingSize = Math.Max(1, (int)Math.Round(size));
|
||||||
|
double width = aspect >= 0d ? boundingSize * (1d - aspect) : boundingSize;
|
||||||
|
double height = aspect <= 0d ? boundingSize * (1d + aspect) : boundingSize;
|
||||||
|
int w = Math.Max(1, (int)Math.Round(width));
|
||||||
|
int h = Math.Max(1, (int)Math.Round(height));
|
||||||
|
|
||||||
|
var buffer = FigureRenderer.Render(name, w, h, color, line);
|
||||||
|
_activeContext!.ReplaceBuffer(buffer, w, h);
|
||||||
|
|
||||||
|
var obj = _objTable!;
|
||||||
|
obj["w"] = w;
|
||||||
|
obj["h"] = h;
|
||||||
|
obj["hw"] = w / 2d;
|
||||||
|
obj["hh"] = h / 2d;
|
||||||
|
obj["cx"] = w / 2d;
|
||||||
|
obj["cy"] = h / 2d;
|
||||||
|
obj["cz"] = 0d;
|
||||||
|
obj["diagonal"] = Math.Sqrt((double)w * w + (double)h * h);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DynValue BuildObjectTable(Script script, SceneObjectInfo info)
|
private static DynValue BuildObjectTable(Script script, SceneObjectInfo info)
|
||||||
@@ -500,39 +573,17 @@ namespace LuaScript
|
|||||||
ctx.Oz = _objTable.Get("oz").CastToNumber() ?? ctx.Oz;
|
ctx.Oz = _objTable.Get("oz").CastToNumber() ?? ctx.Oz;
|
||||||
ctx.Alpha = _objTable.Get("alpha").CastToNumber() ?? ctx.Alpha;
|
ctx.Alpha = _objTable.Get("alpha").CastToNumber() ?? ctx.Alpha;
|
||||||
|
|
||||||
double initialSx = ctx.Sx;
|
ctx.ApplyWriteBack(
|
||||||
double initialSy = ctx.Sy;
|
_objTable.Get("sx").CastToNumber() ?? ctx.Sx,
|
||||||
double initialZoom = ctx.Zoom;
|
_objTable.Get("sy").CastToNumber() ?? ctx.Sy,
|
||||||
double initialAspect = ctx.Aspect;
|
_objTable.Get("zoom").CastToNumber() ?? ctx.Zoom,
|
||||||
|
_objTable.Get("aspect").CastToNumber() ?? ctx.Aspect,
|
||||||
ctx.Sx = _objTable.Get("sx").CastToNumber() ?? ctx.Sx;
|
_objTable.Get("rx").CastToNumber() ?? ctx.Rx,
|
||||||
ctx.Sy = _objTable.Get("sy").CastToNumber() ?? ctx.Sy;
|
_objTable.Get("ry").CastToNumber() ?? ctx.Ry,
|
||||||
ctx.Zoom = _objTable.Get("zoom").CastToNumber() ?? ctx.Zoom;
|
_objTable.Get("rz").CastToNumber() ?? ctx.Rz,
|
||||||
ctx.Aspect = _objTable.Get("aspect").CastToNumber() ?? ctx.Aspect;
|
_objTable.Get("rxr").CastToNumber() ?? ctx.RxRad,
|
||||||
|
_objTable.Get("ryr").CastToNumber() ?? ctx.RyRad,
|
||||||
bool sxsyChanged = Math.Abs(ctx.Sx - initialSx) > 1e-10 || Math.Abs(ctx.Sy - initialSy) > 1e-10;
|
_objTable.Get("rzr").CastToNumber() ?? ctx.RzRad);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LuaScript
|
||||||
|
{
|
||||||
|
internal abstract class LuaScriptException(string message, Exception? inner = null) : Exception(message, inner);
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace LuaScript
|
|
||||||
{
|
|
||||||
internal abstract class LuaScriptException(string message, Exception? inner = null) : Exception(message, inner);
|
|
||||||
|
|
||||||
internal sealed class LuaScriptCompilationException(string message, Exception? inner = null) : LuaScriptException(message, inner);
|
|
||||||
|
|
||||||
internal sealed class LuaScriptRuntimeException(string message, Exception? inner = null) : LuaScriptException(message, inner);
|
|
||||||
|
|
||||||
internal sealed class LuaScriptTimeoutException(string message, Exception? inner = null) : LuaScriptException(message, inner);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LuaScript
|
||||||
|
{
|
||||||
|
internal sealed class LuaScriptRuntimeException(string message, Exception? inner = null) : LuaScriptException(message, inner);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LuaScript
|
||||||
|
{
|
||||||
|
internal sealed class LuaScriptTimeoutException(string message, Exception? inner = null) : LuaScriptException(message, inner);
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
using System;
|
||||||
|
using Vortice;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Vortice.DCommon;
|
||||||
|
using Vortice.Direct2D1;
|
||||||
|
using Vortice.Direct2D1.Effects;
|
||||||
|
using Vortice.DXGI;
|
||||||
|
using Vortice.Mathematics;
|
||||||
|
using YukkuriMovieMaker.Commons;
|
||||||
|
|
||||||
|
namespace LuaScript
|
||||||
|
{
|
||||||
|
internal sealed class PixelBufferManager : IDisposable
|
||||||
|
{
|
||||||
|
private readonly GraphicsDevicesAndContext _ctx;
|
||||||
|
private ID2D1Bitmap1? _renderTarget;
|
||||||
|
private ID2D1Bitmap1? _stagingBitmap;
|
||||||
|
private ID2D1Bitmap1? _outputBitmap;
|
||||||
|
private AffineTransform2D? _transformEffect;
|
||||||
|
private byte[]? _pixelBuffer;
|
||||||
|
private int _bitmapWidth;
|
||||||
|
private int _bitmapHeight;
|
||||||
|
private RawRectF _cachedBounds;
|
||||||
|
|
||||||
|
public PixelBufferManager(GraphicsDevicesAndContext ctx)
|
||||||
|
{
|
||||||
|
_ctx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] LoadInputPixels(ID2D1Image input, RawRectF bounds, int width, int height)
|
||||||
|
{
|
||||||
|
EnsureBitmaps(width, height);
|
||||||
|
|
||||||
|
var dc = _ctx.DeviceContext;
|
||||||
|
var savedTarget = dc.Target;
|
||||||
|
|
||||||
|
dc.Target = _renderTarget;
|
||||||
|
dc.BeginDraw();
|
||||||
|
dc.Clear(null);
|
||||||
|
dc.DrawImage(input, new Vector2(-bounds.Left, -bounds.Top));
|
||||||
|
dc.EndDraw();
|
||||||
|
dc.Target = savedTarget;
|
||||||
|
|
||||||
|
_stagingBitmap!.CopyFromBitmap(_renderTarget!);
|
||||||
|
|
||||||
|
var mapped = _stagingBitmap.Map(MapOptions.Read);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (mapped.Pitch == width * 4)
|
||||||
|
{
|
||||||
|
Marshal.Copy(mapped.Bits, _pixelBuffer!, 0, width * height * 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int row = 0; row < height; row++)
|
||||||
|
Marshal.Copy(
|
||||||
|
mapped.Bits + mapped.Pitch * row,
|
||||||
|
_pixelBuffer!,
|
||||||
|
row * width * 4,
|
||||||
|
width * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_stagingBitmap.Unmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _pixelBuffer!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe void WritePixelsToOutput(byte[] pixels, int width, int height)
|
||||||
|
{
|
||||||
|
EnsureBitmaps(width, height);
|
||||||
|
fixed (byte* ptr = pixels)
|
||||||
|
_outputBitmap!.CopyFromMemory(new nint(ptr), width * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ID2D1Image GetTransformOutput(float left, float top)
|
||||||
|
{
|
||||||
|
if (_transformEffect is null)
|
||||||
|
{
|
||||||
|
_transformEffect = new AffineTransform2D(_ctx.DeviceContext);
|
||||||
|
_transformEffect.SetInput(0, _outputBitmap, true);
|
||||||
|
_cachedBounds = default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_cachedBounds.Left != left || _cachedBounds.Top != top)
|
||||||
|
{
|
||||||
|
_transformEffect.TransformMatrix = Matrix3x2.CreateTranslation(left, top);
|
||||||
|
_cachedBounds = new RawRectF(left, top, left, top);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _transformEffect.Output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EnsureBitmaps(int width, int height)
|
||||||
|
{
|
||||||
|
if (_bitmapWidth == width && _bitmapHeight == height) return;
|
||||||
|
|
||||||
|
_renderTarget?.Dispose();
|
||||||
|
_stagingBitmap?.Dispose();
|
||||||
|
_outputBitmap?.Dispose();
|
||||||
|
_transformEffect?.Dispose();
|
||||||
|
_renderTarget = null;
|
||||||
|
_stagingBitmap = null;
|
||||||
|
_outputBitmap = null;
|
||||||
|
_transformEffect = null;
|
||||||
|
_bitmapWidth = 0;
|
||||||
|
_bitmapHeight = 0;
|
||||||
|
|
||||||
|
var dc = _ctx.DeviceContext;
|
||||||
|
|
||||||
|
_renderTarget = dc.CreateEmptyBitmap(width, height, BitmapOptions.Target);
|
||||||
|
|
||||||
|
var stagingProps = new BitmapProperties1(
|
||||||
|
new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied),
|
||||||
|
96f, 96f,
|
||||||
|
BitmapOptions.CpuRead | BitmapOptions.CannotDraw);
|
||||||
|
_stagingBitmap = dc.CreateBitmap(
|
||||||
|
new SizeI(width, height),
|
||||||
|
nint.Zero,
|
||||||
|
width * 4,
|
||||||
|
stagingProps);
|
||||||
|
|
||||||
|
_outputBitmap = dc.CreateEmptyBitmap(width, height, BitmapOptions.Target);
|
||||||
|
_pixelBuffer = new byte[width * height * 4];
|
||||||
|
|
||||||
|
_bitmapWidth = width;
|
||||||
|
_bitmapHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_renderTarget?.Dispose();
|
||||||
|
_stagingBitmap?.Dispose();
|
||||||
|
_outputBitmap?.Dispose();
|
||||||
|
_transformEffect?.Dispose();
|
||||||
|
_renderTarget = null;
|
||||||
|
_stagingBitmap = null;
|
||||||
|
_outputBitmap = null;
|
||||||
|
_transformEffect = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,9 +10,4 @@ namespace LuaScript
|
|||||||
double Rz,
|
double Rz,
|
||||||
double Alpha,
|
double Alpha,
|
||||||
int Layer);
|
int Layer);
|
||||||
|
|
||||||
internal readonly record struct SceneObjectQuery(
|
|
||||||
string Tag,
|
|
||||||
int Frame,
|
|
||||||
SceneObjectInfo? Result);
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace LuaScript
|
||||||
|
{
|
||||||
|
internal readonly record struct SceneObjectQuery(
|
||||||
|
string Tag,
|
||||||
|
int Frame,
|
||||||
|
SceneObjectInfo? Result);
|
||||||
|
}
|
||||||
@@ -69,6 +69,13 @@
|
|||||||
<data name="Track2" xml:space="preserve"><value>مسار 2</value></data>
|
<data name="Track2" xml:space="preserve"><value>مسار 2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>مسار 3</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="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="ToolBarImport" xml:space="preserve"><value>استيراد</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>تصدير</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>تصدير</value></data>
|
||||||
<data name="ToolBarClear" 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
|
Track2,,トラック2,Track 2,轨道2,軌道2,트랙2,Pista 2,مسار 2,Jalur 2
|
||||||
Track3,,トラック3,Track 3,轨道3,軌道3,트랙3,Pista 3,مسار 3,Jalur 3
|
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)
|
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
|
ToolBarImport,,インポート,Import,导入,導入,가져오기,Importar,استيراد,Impor
|
||||||
ToolBarExport,,エクスポート,Export,导出,導出,내보내기,Exportar,تصدير,Ekspor
|
ToolBarExport,,エクスポート,Export,导出,導出,내보내기,Exportar,تصدير,Ekspor
|
||||||
ToolBarClear,,クリア,Clear,清除,清除,지우기,Limpiar,مسح,Hapus
|
ToolBarClear,,クリア,Clear,清除,清除,지우기,Limpiar,مسح,Hapus
|
||||||
|
|||||||
|
@@ -69,6 +69,13 @@
|
|||||||
<data name="Track2" xml:space="preserve"><value>Track 2</value></data>
|
<data name="Track2" xml:space="preserve"><value>Track 2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>Track 3</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="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="ToolBarImport" xml:space="preserve"><value>Import</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>Export</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>Export</value></data>
|
||||||
<data name="ToolBarClear" xml:space="preserve"><value>Clear</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="Track2" xml:space="preserve"><value>Pista 2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>Pista 3</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="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="ToolBarImport" xml:space="preserve"><value>Importar</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>Exportar</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>Exportar</value></data>
|
||||||
<data name="ToolBarClear" xml:space="preserve"><value>Limpiar</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="Track2" xml:space="preserve"><value>Jalur 2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>Jalur 3</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="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="ToolBarImport" xml:space="preserve"><value>Impor</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>Ekspor</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>Ekspor</value></data>
|
||||||
<data name="ToolBarClear" xml:space="preserve"><value>Hapus</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="Track2" xml:space="preserve"><value>트랙2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>트랙3</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="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="ToolBarImport" xml:space="preserve"><value>가져오기</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>내보내기</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>내보내기</value></data>
|
||||||
<data name="ToolBarClear" 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="Track2" xml:space="preserve"><value>トラック2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>トラック3</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="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="ToolBarImport" xml:space="preserve"><value>インポート</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>エクスポート</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>エクスポート</value></data>
|
||||||
<data name="ToolBarClear" 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="Track2" xml:space="preserve"><value>轨道2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>轨道3</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="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="ToolBarImport" xml:space="preserve"><value>导入</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>导出</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>导出</value></data>
|
||||||
<data name="ToolBarClear" 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="Track2" xml:space="preserve"><value>軌道2</value></data>
|
||||||
<data name="Track3" xml:space="preserve"><value>軌道3</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="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="ToolBarImport" xml:space="preserve"><value>導入</value></data>
|
||||||
<data name="ToolBarExport" xml:space="preserve"><value>導出</value></data>
|
<data name="ToolBarExport" xml:space="preserve"><value>導出</value></data>
|
||||||
<data name="ToolBarClear" 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -314,6 +314,25 @@
|
|||||||
النتيجة : عدد صحيح ضمن st ~ ed
|
النتيجة : عدد صحيح ضمن st ~ ed
|
||||||
مثال: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
مثال: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
○ obj.load(الهدف، ...)
|
||||||
|
يستبدل مخزن الكائن بمحتوى مُولَّد. في هذا الإصدار يُدعم الهدف "figure" فقط.
|
||||||
|
obj.load("figure", name, color, size [, line [, aspect]])
|
||||||
|
يُولّد شكلاً ويستبدل مخزن الكائن به
|
||||||
|
(يُعاد تحجيم الخرج ليطابق الشكل ويُتوسَّط).
|
||||||
|
name : اسم الشكل. أحد 円 / 四角形 / 三角形 / 五角形 /
|
||||||
|
六角形 / 星形 (وتُقبل الأسماء الإنجليزية circle, rect,
|
||||||
|
triangle, pentagon, hexagon, star).
|
||||||
|
color : لون التعبئة 0xRRGGBB.
|
||||||
|
size : الحجم الأساسي بالبكسل.
|
||||||
|
line : عرض الحد (اختياري). الحذف أو 0 يملأ الشكل،
|
||||||
|
والقيمة المساوية للحجم أو الأكبر منه تملؤه أيضاً.
|
||||||
|
aspect : التشويه -1.0 ~ 1.0 (اختياري). الموجب يقلّص العرض،
|
||||||
|
والسالب يقلّص الارتفاع.
|
||||||
|
مثال: obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
※ المُنفَّذ هو obj.load("figure", ...) فقط. الأهداف الأخرى
|
||||||
|
(ملفات الصور و"text" و"tempbuffer" و"movie" وغيرها) لا تفعل شيئاً.
|
||||||
|
※ تُنفَّذ نصوص الرسم على محرك MoonSharp.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
@@ -484,10 +503,14 @@
|
|||||||
دالة أرقام عشوائية صحيحة حتمية متوافقة مع AviUtl. انظر "جدول obj - الدوال"
|
دالة أرقام عشوائية صحيحة حتمية متوافقة مع AviUtl. انظر "جدول obj - الدوال"
|
||||||
للتفاصيل.
|
للتفاصيل.
|
||||||
|
|
||||||
|
○ رسم الأشكال
|
||||||
|
obj.load("figure", ...) يُولّد دائرة أو مربعاً أو مثلثاً أو خماسياً أو
|
||||||
|
سداسياً أو نجمة، ويستبدل مخزن الكائن به. انظر "جدول obj - الدوال" للتفاصيل.
|
||||||
|
|
||||||
تتطلب الميزات التالية التكامل مع خط أنابيب الرسم، لذا فهي خارج نطاق هذه الطبقة.
|
تتطلب الميزات التالية التكامل مع خط أنابيب الرسم، لذا فهي خارج نطاق هذه الطبقة.
|
||||||
النصوص التي تستدعيها لن تعمل كما هو متوقع.
|
النصوص التي تستدعيها لن تعمل كما هو متوقع.
|
||||||
× تحميل ورسم الصور والأشكال والنصوص والفيديو
|
× الرسم والتركيب (obj.draw / obj.drawpoly)، وأهداف obj.load غير "figure"
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont وما شابه)
|
(ملفات الصور و"text" و"movie" وغيرها)، وكذلك obj.setfont
|
||||||
× تأثيرات المرشّحات وعمليات المخزن المؤقت
|
× تأثيرات المرشّحات وعمليات المخزن المؤقت
|
||||||
(obj.effect / obj.copybuffer / obj.setoption وما شابه)
|
(obj.effect / obj.copybuffer / obj.setoption وما شابه)
|
||||||
× تحميل الوحدات عبر require، والوصول إلى الملفات مثل io
|
× تحميل الوحدات عبر require، والوصول إلى الملفات مثل io
|
||||||
@@ -495,7 +518,7 @@
|
|||||||
|
|
||||||
- الميزات غير المدعومة / القيود -
|
- الميزات غير المدعومة / القيود -
|
||||||
|
|
||||||
× obj.effect()، obj.draw()، obj.drawpoly()، obj.load() وما شابه من AviUtl2 غير مدعومة.
|
× obj.effect()، obj.draw()، obj.drawpoly() وما شابه من AviUtl2 غير مدعومة (يُدعم obj.load("figure", ...) فقط؛ انظر "التوافق الجزئي مع نصوص AviUtl").
|
||||||
× obj.rand1()، obj.setfont()، obj.mes() وما شابه من AviUtl2 غير مدعومة.
|
× obj.rand1()، obj.setfont()، obj.mes() وما شابه من AviUtl2 غير مدعومة.
|
||||||
× obj.setoption()، obj.getoption()، obj.getvalue()، obj.setanchor() وما شابه من AviUtl2 غير مدعومة.
|
× obj.setoption()، obj.getoption()، obj.getvalue()، obj.setanchor() وما شابه من AviUtl2 غير مدعومة.
|
||||||
× الدوال مثل scene.set() و scene.get() في جدول scene الخاص بـ AviUtl2 غير مدعومة.
|
× الدوال مثل scene.set() و scene.get() في جدول scene الخاص بـ AviUtl2 غير مدعومة.
|
||||||
|
|||||||
@@ -321,6 +321,26 @@
|
|||||||
Returns : An integer within st ~ ed
|
Returns : An integer within st ~ ed
|
||||||
Example: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
Example: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
o obj.load(target, ...)
|
||||||
|
Replaces the object buffer with generated content.
|
||||||
|
Only the "figure" target is supported in this version.
|
||||||
|
obj.load("figure", name, color, size [, line [, aspect]])
|
||||||
|
Generates a shape and replaces the object buffer with it
|
||||||
|
(the output is resized to the shape and centered).
|
||||||
|
name : Shape name. One of 円 / 四角形 / 三角形 / 五角形 /
|
||||||
|
六角形 / 星形 (English aliases circle, rect,
|
||||||
|
triangle, pentagon, hexagon, star are also accepted).
|
||||||
|
color : Fill color 0xRRGGBB.
|
||||||
|
size : Bounding size in pixels.
|
||||||
|
line : Outline width (optional). Omitted or 0 fills the
|
||||||
|
shape; a value at or above the size also fills it.
|
||||||
|
aspect : Distortion -1.0 ~ 1.0 (optional). Positive shrinks
|
||||||
|
the width, negative shrinks the height.
|
||||||
|
Example: obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
* Only obj.load("figure", ...) is implemented. Other targets
|
||||||
|
(image files, "text", "tempbuffer", "movie", etc.) do nothing.
|
||||||
|
* Drawing scripts run on the MoonSharp engine.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
@@ -495,10 +515,15 @@
|
|||||||
A deterministic integer random function compatible with AviUtl.
|
A deterministic integer random function compatible with AviUtl.
|
||||||
See "obj Table - Functions" for details.
|
See "obj Table - Functions" for details.
|
||||||
|
|
||||||
|
o Figure drawing
|
||||||
|
obj.load("figure", ...) generates a basic shape (circle, rectangle,
|
||||||
|
triangle, pentagon, hexagon, star) and replaces the object buffer
|
||||||
|
with it. See "obj Table - Functions" for details.
|
||||||
|
|
||||||
The following require integration with the rendering pipeline and are out of
|
The following require integration with the rendering pipeline and are out of
|
||||||
scope for this layer. Scripts that call them will not behave as intended.
|
scope for this layer. Scripts that call them will not behave as intended.
|
||||||
x Loading and drawing of images, figures, text and video
|
x Drawing and compositing (obj.draw / obj.drawpoly), obj.load targets
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont, etc.)
|
other than "figure" (image files, "text", "movie", etc.) and obj.setfont
|
||||||
x Filter effects and buffer operations
|
x Filter effects and buffer operations
|
||||||
(obj.effect / obj.copybuffer / obj.setoption, etc.)
|
(obj.effect / obj.copybuffer / obj.setoption, etc.)
|
||||||
x Module loading via require, and file access such as io
|
x Module loading via require, and file access such as io
|
||||||
@@ -506,7 +531,7 @@
|
|||||||
|
|
||||||
- Unsupported Features / Limitations -
|
- Unsupported Features / Limitations -
|
||||||
|
|
||||||
x obj.effect(), obj.draw(), obj.drawpoly(), obj.load(), etc. from AviUtl2 are not supported.
|
x obj.effect(), obj.draw(), obj.drawpoly(), etc. from AviUtl2 are not supported (only obj.load("figure", ...) is supported; see "AviUtl Script Compatibility (Partial)").
|
||||||
x obj.rand1(), obj.setfont(), obj.mes(), etc. from AviUtl2 are not supported.
|
x obj.rand1(), obj.setfont(), obj.mes(), etc. from AviUtl2 are not supported.
|
||||||
x obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor(), etc. from AviUtl2 are not supported.
|
x obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor(), etc. from AviUtl2 are not supported.
|
||||||
x Functions such as scene.set() and scene.get() in the AviUtl2 scene table are not supported.
|
x Functions such as scene.set() and scene.get() in the AviUtl2 scene table are not supported.
|
||||||
|
|||||||
@@ -319,6 +319,26 @@
|
|||||||
Devuelve: Un entero dentro de st ~ ed
|
Devuelve: Un entero dentro de st ~ ed
|
||||||
Ejemplo: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
Ejemplo: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
o obj.load(target, ...)
|
||||||
|
Reemplaza el búfer del objeto con contenido generado.
|
||||||
|
En esta versión solo se admite el target "figure".
|
||||||
|
obj.load("figure", name, color, size [, line [, aspect]])
|
||||||
|
Genera una forma y reemplaza el búfer del objeto con ella
|
||||||
|
(la salida se redimensiona a la forma y se centra).
|
||||||
|
name : Nombre de la forma. Uno de 円 / 四角形 / 三角形 /
|
||||||
|
五角形 / 六角形 / 星形 (también se aceptan los alias
|
||||||
|
en inglés circle, rect, triangle, pentagon, hexagon, star).
|
||||||
|
color : Color de relleno 0xRRGGBB.
|
||||||
|
size : Tamaño base en píxeles.
|
||||||
|
line : Grosor del contorno (opcional). Omitido o 0 rellena la
|
||||||
|
forma; un valor igual o mayor que el tamaño también la rellena.
|
||||||
|
aspect : Distorsión -1.0 ~ 1.0 (opcional). Positivo reduce el
|
||||||
|
ancho, negativo reduce el alto.
|
||||||
|
Ejemplo: obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
* Solo se implementa obj.load("figure", ...). Otros targets
|
||||||
|
(archivos de imagen, "text", "tempbuffer", "movie", etc.) no hacen nada.
|
||||||
|
* Los scripts de dibujo se ejecutan en el motor MoonSharp.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
@@ -495,11 +515,16 @@
|
|||||||
Función de número aleatorio entero determinista compatible con AviUtl.
|
Función de número aleatorio entero determinista compatible con AviUtl.
|
||||||
Consulte "Tabla obj - Funciones" para más detalles.
|
Consulte "Tabla obj - Funciones" para más detalles.
|
||||||
|
|
||||||
|
o Dibujo de figuras
|
||||||
|
obj.load("figure", ...) genera una forma básica (círculo, rectángulo,
|
||||||
|
triángulo, pentágono, hexágono, estrella) y reemplaza el búfer del
|
||||||
|
objeto con ella. Consulte "Tabla obj - Funciones" para más detalles.
|
||||||
|
|
||||||
Lo siguiente requiere integración con la canalización de renderizado y, por
|
Lo siguiente requiere integración con la canalización de renderizado y, por
|
||||||
tanto, queda fuera del alcance de esta capa. Los scripts que lo llamen no se
|
tanto, queda fuera del alcance de esta capa. Los scripts que lo llamen no se
|
||||||
comportarán como se espera.
|
comportarán como se espera.
|
||||||
x Carga y dibujo de imágenes, figuras, texto y vídeo
|
x Dibujo y composición (obj.draw / obj.drawpoly), targets de obj.load
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont, etc.)
|
distintos de "figure" (archivos de imagen, "text", "movie", etc.) y obj.setfont
|
||||||
x Efectos de filtro y operaciones de búfer
|
x Efectos de filtro y operaciones de búfer
|
||||||
(obj.effect / obj.copybuffer / obj.setoption, etc.)
|
(obj.effect / obj.copybuffer / obj.setoption, etc.)
|
||||||
x Carga de módulos mediante require y acceso a archivos como io
|
x Carga de módulos mediante require y acceso a archivos como io
|
||||||
@@ -507,7 +532,7 @@
|
|||||||
|
|
||||||
- Funciones no admitidas / Limitaciones -
|
- Funciones no admitidas / Limitaciones -
|
||||||
|
|
||||||
x obj.effect(), obj.draw(), obj.drawpoly(), obj.load(), etc. de AviUtl2 no son compatibles.
|
x obj.effect(), obj.draw(), obj.drawpoly(), etc. de AviUtl2 no son compatibles (solo se admite obj.load("figure", ...); consulte "Compatibilidad parcial con scripts de AviUtl").
|
||||||
x obj.rand1(), obj.setfont(), obj.mes(), etc. de AviUtl2 no son compatibles.
|
x obj.rand1(), obj.setfont(), obj.mes(), etc. de AviUtl2 no son compatibles.
|
||||||
x obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor(), etc. de AviUtl2 no son compatibles.
|
x obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor(), etc. de AviUtl2 no son compatibles.
|
||||||
x Las funciones como scene.set() y scene.get() de la tabla scene de AviUtl2 no son compatibles.
|
x Las funciones como scene.set() y scene.get() de la tabla scene de AviUtl2 no son compatibles.
|
||||||
|
|||||||
@@ -317,6 +317,26 @@
|
|||||||
Hasil : Bilangan bulat dalam st ~ ed
|
Hasil : Bilangan bulat dalam st ~ ed
|
||||||
Contoh: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
Contoh: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
o obj.load(target, ...)
|
||||||
|
Mengganti buffer objek dengan konten yang dihasilkan.
|
||||||
|
Pada versi ini hanya target "figure" yang didukung.
|
||||||
|
obj.load("figure", name, color, size [, line [, aspect]])
|
||||||
|
Menghasilkan sebuah bentuk dan mengganti buffer objek dengannya
|
||||||
|
(output diubah ukurannya sesuai bentuk dan dipusatkan).
|
||||||
|
name : Nama bentuk. Salah satu dari 円 / 四角形 / 三角形 /
|
||||||
|
五角形 / 六角形 / 星形 (alias Inggris circle, rect,
|
||||||
|
triangle, pentagon, hexagon, star juga diterima).
|
||||||
|
color : Warna isi 0xRRGGBB.
|
||||||
|
size : Ukuran dasar dalam piksel.
|
||||||
|
line : Lebar garis tepi (opsional). Dihilangkan atau 0 mengisi
|
||||||
|
bentuk; nilai sama atau lebih besar dari ukuran juga mengisinya.
|
||||||
|
aspect : Distorsi -1.0 ~ 1.0 (opsional). Positif mengecilkan
|
||||||
|
lebar, negatif mengecilkan tinggi.
|
||||||
|
Contoh: obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
* Hanya obj.load("figure", ...) yang diimplementasikan. Target lain
|
||||||
|
(berkas gambar, "text", "tempbuffer", "movie", dll.) tidak melakukan apa pun.
|
||||||
|
* Skrip penggambaran dijalankan pada mesin MoonSharp.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 Table -
|
- ymm4 Table -
|
||||||
@@ -492,11 +512,16 @@
|
|||||||
Fungsi bilangan acak bulat deterministik yang kompatibel dengan AviUtl.
|
Fungsi bilangan acak bulat deterministik yang kompatibel dengan AviUtl.
|
||||||
Lihat "Tabel obj - Fungsi" untuk detailnya.
|
Lihat "Tabel obj - Fungsi" untuk detailnya.
|
||||||
|
|
||||||
|
o Penggambaran figur
|
||||||
|
obj.load("figure", ...) menghasilkan bentuk dasar (lingkaran, persegi,
|
||||||
|
segitiga, segilima, segienam, bintang) dan mengganti buffer objek
|
||||||
|
dengannya. Lihat "Tabel obj - Fungsi" untuk detailnya.
|
||||||
|
|
||||||
Berikut ini memerlukan integrasi dengan pipeline render sehingga berada di
|
Berikut ini memerlukan integrasi dengan pipeline render sehingga berada di
|
||||||
luar cakupan lapisan ini. Skrip yang memanggilnya tidak akan berperilaku
|
luar cakupan lapisan ini. Skrip yang memanggilnya tidak akan berperilaku
|
||||||
seperti yang diharapkan.
|
seperti yang diharapkan.
|
||||||
x Pemuatan dan penggambaran gambar, figur, teks, dan video
|
x Penggambaran dan komposisi (obj.draw / obj.drawpoly), target obj.load
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont, dll.)
|
selain "figure" (berkas gambar, "text", "movie", dll.) dan obj.setfont
|
||||||
x Efek filter dan operasi buffer
|
x Efek filter dan operasi buffer
|
||||||
(obj.effect / obj.copybuffer / obj.setoption, dll.)
|
(obj.effect / obj.copybuffer / obj.setoption, dll.)
|
||||||
x Pemuatan modul melalui require, dan akses file seperti io
|
x Pemuatan modul melalui require, dan akses file seperti io
|
||||||
@@ -504,7 +529,7 @@
|
|||||||
|
|
||||||
- Fitur yang Tidak Didukung / Batasan -
|
- Fitur yang Tidak Didukung / Batasan -
|
||||||
|
|
||||||
x obj.effect(), obj.draw(), obj.drawpoly(), obj.load(), dll. dari AviUtl2 tidak didukung.
|
x obj.effect(), obj.draw(), obj.drawpoly(), dll. dari AviUtl2 tidak didukung (hanya obj.load("figure", ...) yang didukung; lihat "Kompatibilitas Parsial Skrip AviUtl").
|
||||||
x obj.rand1(), obj.setfont(), obj.mes(), dll. dari AviUtl2 tidak didukung.
|
x obj.rand1(), obj.setfont(), obj.mes(), dll. dari AviUtl2 tidak didukung.
|
||||||
x obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor(), dll. dari AviUtl2 tidak didukung.
|
x obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor(), dll. dari AviUtl2 tidak didukung.
|
||||||
x Fungsi seperti scene.set() dan scene.get() dalam tabel scene AviUtl2 tidak didukung.
|
x Fungsi seperti scene.set() dan scene.get() dalam tabel scene AviUtl2 tidak didukung.
|
||||||
|
|||||||
@@ -316,6 +316,25 @@
|
|||||||
戻り値 : st ~ ed の整数
|
戻り値 : st ~ ed の整数
|
||||||
例:obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
例:obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
○obj.load(対象, ...)
|
||||||
|
オブジェクトのバッファを生成した内容に置き換えます。
|
||||||
|
本バージョンでは "figure"(図形)のみ対応します。
|
||||||
|
obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])
|
||||||
|
図形を生成してオブジェクトのバッファを置き換えます
|
||||||
|
(出力は図形サイズに合わせて生成され、中心に配置されます)。
|
||||||
|
名前 : 図形名。円 / 四角形 / 三角形 / 五角形 / 六角形 /
|
||||||
|
星形 のいずれか(英語名 circle, rect, triangle,
|
||||||
|
pentagon, hexagon, star も使用可)。
|
||||||
|
色 : 塗り色 0xRRGGBB。
|
||||||
|
サイズ : 図形の基準サイズ(ピクセル)。
|
||||||
|
ライン : 輪郭の太さ(省略可)。省略または 0 で塗りつぶし。
|
||||||
|
サイズ以上の値を指定した場合も塗りつぶしになります。
|
||||||
|
アスペクト: 歪曲 -1.0 ~ 1.0(省略可)。正で横幅、負で縦幅が縮みます。
|
||||||
|
例:obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
※ 実装されているのは obj.load("figure", ...) のみです。画像ファイルや
|
||||||
|
"text"・"tempbuffer"・"movie" 等の対象は何も行いません。
|
||||||
|
※ 描画系スクリプトは従来エンジン(MoonSharp)で実行されます。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 テーブル -
|
- ymm4 テーブル -
|
||||||
@@ -488,10 +507,15 @@
|
|||||||
AviUtl 互換の決定論的な整数乱数です。詳細は「obj テーブル - 関数」を
|
AviUtl 互換の決定論的な整数乱数です。詳細は「obj テーブル - 関数」を
|
||||||
参照してください。
|
参照してください。
|
||||||
|
|
||||||
|
○図形描画
|
||||||
|
obj.load("figure", ...) で円・四角形・三角形・五角形・六角形・星形を
|
||||||
|
生成し、オブジェクトのバッファを置き換えます。詳細は「obj テーブル -
|
||||||
|
関数」を参照してください。
|
||||||
|
|
||||||
次の機能は本体の描画パイプラインへの統合を要するため、この互換層では対象外です。
|
次の機能は本体の描画パイプラインへの統合を要するため、この互換層では対象外です。
|
||||||
これらを呼び出すスクリプトは意図どおりには動作しません。
|
これらを呼び出すスクリプトは意図どおりには動作しません。
|
||||||
×画像・図形・テキスト・動画の読み込みと描画
|
×描画・合成(obj.draw / obj.drawpoly)、obj.load の "figure" 以外の対象
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont など)
|
(画像ファイル・"text"・"movie" 等)、および obj.setfont
|
||||||
×フィルタ効果やバッファ操作
|
×フィルタ効果やバッファ操作
|
||||||
(obj.effect / obj.copybuffer / obj.setoption など)
|
(obj.effect / obj.copybuffer / obj.setoption など)
|
||||||
×require によるモジュール読み込み、io などのファイルアクセス
|
×require によるモジュール読み込み、io などのファイルアクセス
|
||||||
@@ -499,7 +523,7 @@
|
|||||||
|
|
||||||
- 非対応・制限事項 -
|
- 非対応・制限事項 -
|
||||||
|
|
||||||
×AviUtl2 の obj.effect(), obj.draw(), obj.drawpoly(), obj.load() 等には対応していません。
|
×AviUtl2 の obj.effect(), obj.draw(), obj.drawpoly() 等には対応していません(obj.load は "figure" のみ対応。「AviUtl スクリプトの部分互換」を参照)。
|
||||||
×AviUtl2 の obj.rand1(), obj.setfont(), obj.mes() 等には対応していません。
|
×AviUtl2 の obj.rand1(), obj.setfont(), obj.mes() 等には対応していません。
|
||||||
×AviUtl2 の obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor() 等には対応していません。
|
×AviUtl2 の obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor() 等には対応していません。
|
||||||
×AviUtl2 の scene テーブルの scene.set(), scene.get() 等の関数には対応していません。
|
×AviUtl2 の scene テーブルの scene.set(), scene.get() 等の関数には対応していません。
|
||||||
|
|||||||
@@ -312,6 +312,25 @@
|
|||||||
반환값 : st ~ ed의 정수
|
반환값 : st ~ ed의 정수
|
||||||
예: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
예: obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
○ obj.load(대상, ...)
|
||||||
|
오브젝트 버퍼를 생성한 내용으로 교체합니다.
|
||||||
|
이 버전에서는 "figure"(도형)만 지원합니다.
|
||||||
|
obj.load("figure", 이름, 색, 크기 [, 라인 [, 종횡비]])
|
||||||
|
도형을 생성하여 오브젝트 버퍼를 교체합니다
|
||||||
|
(출력은 도형 크기에 맞춰 생성되고 중심에 배치됩니다).
|
||||||
|
이름 : 도형 이름. 円 / 四角形 / 三角形 / 五角形 / 六角形 /
|
||||||
|
星形 중 하나(영어 circle, rect, triangle,
|
||||||
|
pentagon, hexagon, star 도 사용 가능).
|
||||||
|
색 : 채움 색 0xRRGGBB.
|
||||||
|
크기 : 도형의 기준 크기(픽셀).
|
||||||
|
라인 : 외곽선 두께(생략 가능). 생략 또는 0이면 채움.
|
||||||
|
크기 이상의 값을 지정한 경우에도 채움이 됩니다.
|
||||||
|
종횡비 : 왜곡 -1.0 ~ 1.0(생략 가능). 양수는 너비, 음수는 높이를 줄입니다.
|
||||||
|
예: obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
※ 구현된 것은 obj.load("figure", ...) 뿐입니다. 이미지 파일,
|
||||||
|
"text"・"tempbuffer"・"movie" 등의 대상은 아무것도 하지 않습니다.
|
||||||
|
※ 그리기 계열 스크립트는 MoonSharp 엔진에서 실행됩니다.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 테이블 -
|
- ymm4 테이블 -
|
||||||
@@ -484,10 +503,15 @@
|
|||||||
AviUtl 호환의 결정론적 정수 난수입니다. 자세한 내용은
|
AviUtl 호환의 결정론적 정수 난수입니다. 자세한 내용은
|
||||||
"obj 테이블 - 함수"를 참조하세요.
|
"obj 테이블 - 함수"를 참조하세요.
|
||||||
|
|
||||||
|
○ 도형 그리기
|
||||||
|
obj.load("figure", ...) 로 원·사각형·삼각형·오각형·육각형·별형을
|
||||||
|
생성하여 오브젝트 버퍼를 교체합니다. 자세한 내용은
|
||||||
|
"obj 테이블 - 함수"를 참조하세요.
|
||||||
|
|
||||||
다음 기능은 본체의 렌더링 파이프라인과의 통합이 필요하므로 이 호환
|
다음 기능은 본체의 렌더링 파이프라인과의 통합이 필요하므로 이 호환
|
||||||
계층의 범위 밖입니다. 이를 호출하는 스크립트는 의도대로 동작하지 않습니다.
|
계층의 범위 밖입니다. 이를 호출하는 스크립트는 의도대로 동작하지 않습니다.
|
||||||
× 이미지·도형·텍스트·동영상의 로드 및 그리기
|
× 그리기·합성(obj.draw / obj.drawpoly), obj.load의 "figure" 이외 대상
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont 등)
|
(이미지 파일·"text"・"movie" 등), 그리고 obj.setfont
|
||||||
× 필터 효과 및 버퍼 조작
|
× 필터 효과 및 버퍼 조작
|
||||||
(obj.effect / obj.copybuffer / obj.setoption 등)
|
(obj.effect / obj.copybuffer / obj.setoption 등)
|
||||||
× require에 의한 모듈 로드 및 io 등의 파일 접근
|
× require에 의한 모듈 로드 및 io 등의 파일 접근
|
||||||
@@ -495,7 +519,7 @@
|
|||||||
|
|
||||||
- 미지원·제한 사항 -
|
- 미지원·제한 사항 -
|
||||||
|
|
||||||
× AviUtl2의 obj.effect(), obj.draw(), obj.drawpoly(), obj.load() 등은 지원하지 않습니다.
|
× AviUtl2의 obj.effect(), obj.draw(), obj.drawpoly() 등은 지원하지 않습니다(obj.load은 "figure"만 지원. "AviUtl 스크립트 부분 호환" 참조).
|
||||||
× AviUtl2의 obj.rand1(), obj.setfont(), obj.mes() 등은 지원하지 않습니다.
|
× AviUtl2의 obj.rand1(), obj.setfont(), obj.mes() 등은 지원하지 않습니다.
|
||||||
× AviUtl2의 obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor() 등은 지원하지 않습니다.
|
× AviUtl2의 obj.setoption(), obj.getoption(), obj.getvalue(), obj.setanchor() 등은 지원하지 않습니다.
|
||||||
× AviUtl2의 scene 테이블의 scene.set(), scene.get() 등의 함수는 지원하지 않습니다.
|
× AviUtl2의 scene 테이블의 scene.set(), scene.get() 등의 함수는 지원하지 않습니다.
|
||||||
|
|||||||
@@ -310,6 +310,24 @@
|
|||||||
返回值 : st ~ ed 的整数
|
返回值 : st ~ ed 的整数
|
||||||
示例:obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
示例:obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
○ obj.load(目标, ...)
|
||||||
|
将对象缓冲区替换为生成的内容。本版本仅支持 "figure"(图形)。
|
||||||
|
obj.load("figure", 名称, 颜色, 大小 [, 线宽 [, 纵横比]])
|
||||||
|
生成图形并替换对象缓冲区
|
||||||
|
(输出按图形大小生成并居中)。
|
||||||
|
名称 : 图形名。円 / 四角形 / 三角形 / 五角形 / 六角形 /
|
||||||
|
星形 之一(也可用英文 circle, rect, triangle,
|
||||||
|
pentagon, hexagon, star)。
|
||||||
|
颜色 : 填充色 0xRRGGBB。
|
||||||
|
大小 : 图形基准大小(像素)。
|
||||||
|
线宽 : 轮廓宽度(可省略)。省略或 0 为填充;
|
||||||
|
指定大于等于大小的值时也为填充。
|
||||||
|
纵横比 : 变形 -1.0 ~ 1.0(可省略)。正值缩小宽度,负值缩小高度。
|
||||||
|
示例:obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
* 仅实现了 obj.load("figure", ...)。图像文件、"text"、"tempbuffer"、
|
||||||
|
"movie" 等目标不执行任何操作。
|
||||||
|
* 绘制类脚本在 MoonSharp 引擎上运行。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 表 -
|
- ymm4 表 -
|
||||||
@@ -477,10 +495,14 @@
|
|||||||
○ obj.rand(st, ed [, seed [, frame]])
|
○ obj.rand(st, ed [, seed [, frame]])
|
||||||
与 AviUtl 兼容的确定性整数随机数。详情请参阅“obj 表 - 函数”。
|
与 AviUtl 兼容的确定性整数随机数。详情请参阅“obj 表 - 函数”。
|
||||||
|
|
||||||
|
○ 图形绘制
|
||||||
|
obj.load("figure", ...) 生成圆、四角形、三角形、五角形、六角形、星形,
|
||||||
|
并替换对象缓冲区。详情请参阅“obj 表 - 函数”。
|
||||||
|
|
||||||
以下功能需要与本体的绘制管线集成,因此不在此兼容层的范围内。
|
以下功能需要与本体的绘制管线集成,因此不在此兼容层的范围内。
|
||||||
调用它们的脚本不会按预期运行。
|
调用它们的脚本不会按预期运行。
|
||||||
× 图像、图形、文本、视频的加载与绘制
|
× 绘制与合成(obj.draw / obj.drawpoly)、obj.load 的 "figure" 以外目标
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont 等)
|
(图像文件、"text"、"movie" 等),以及 obj.setfont
|
||||||
× 滤镜效果与缓冲区操作
|
× 滤镜效果与缓冲区操作
|
||||||
(obj.effect / obj.copybuffer / obj.setoption 等)
|
(obj.effect / obj.copybuffer / obj.setoption 等)
|
||||||
× 通过 require 加载模块,以及 io 等文件访问
|
× 通过 require 加载模块,以及 io 等文件访问
|
||||||
@@ -488,7 +510,7 @@
|
|||||||
|
|
||||||
- 不支持项目·限制事项 -
|
- 不支持项目·限制事项 -
|
||||||
|
|
||||||
× 不支持 AviUtl2 的 obj.effect()、obj.draw()、obj.drawpoly()、obj.load() 等。
|
× 不支持 AviUtl2 的 obj.effect()、obj.draw()、obj.drawpoly() 等(obj.load 仅支持 "figure",参阅“AviUtl 脚本的部分兼容”)。
|
||||||
× 不支持 AviUtl2 的 obj.rand1()、obj.setfont()、obj.mes() 等。
|
× 不支持 AviUtl2 的 obj.rand1()、obj.setfont()、obj.mes() 等。
|
||||||
× 不支持 AviUtl2 的 obj.setoption()、obj.getoption()、obj.getvalue()、obj.setanchor() 等。
|
× 不支持 AviUtl2 的 obj.setoption()、obj.getoption()、obj.getvalue()、obj.setanchor() 等。
|
||||||
× 不支持 AviUtl2 scene 表中的 scene.set()、scene.get() 等函数。
|
× 不支持 AviUtl2 scene 表中的 scene.set()、scene.get() 等函数。
|
||||||
|
|||||||
@@ -310,6 +310,24 @@
|
|||||||
回傳值 : st ~ ed 的整數
|
回傳值 : st ~ ed 的整數
|
||||||
範例:obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
範例:obj.ox = obj.ox + obj.rand(-10, 10, 1, obj.frame)
|
||||||
|
|
||||||
|
○ obj.load(目標, ...)
|
||||||
|
將物件緩衝區替換為產生的內容。本版本僅支援 "figure"(圖形)。
|
||||||
|
obj.load("figure", 名稱, 顏色, 大小 [, 線寬 [, 長寬比]])
|
||||||
|
產生圖形並替換物件緩衝區
|
||||||
|
(輸出依圖形大小產生並置中)。
|
||||||
|
名稱 : 圖形名。円 / 四角形 / 三角形 / 五角形 / 六角形 /
|
||||||
|
星形 之一(亦可用英文 circle, rect, triangle,
|
||||||
|
pentagon, hexagon, star)。
|
||||||
|
顏色 : 填滿色 0xRRGGBB。
|
||||||
|
大小 : 圖形基準大小(像素)。
|
||||||
|
線寬 : 輪廓寬度(可省略)。省略或 0 為填滿;
|
||||||
|
指定大於等於大小的值時亦為填滿。
|
||||||
|
長寬比 : 變形 -1.0 ~ 1.0(可省略)。正值縮小寬度,負值縮小高度。
|
||||||
|
範例:obj.load("figure", "円", 0xff3366, 200)
|
||||||
|
* 僅實作了 obj.load("figure", ...)。影像檔、"text"、"tempbuffer"、
|
||||||
|
"movie" 等目標不執行任何動作。
|
||||||
|
* 繪製類腳本在 MoonSharp 引擎上執行。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- ymm4 表 -
|
- ymm4 表 -
|
||||||
@@ -477,10 +495,14 @@
|
|||||||
○ obj.rand(st, ed [, seed [, frame]])
|
○ obj.rand(st, ed [, seed [, frame]])
|
||||||
與 AviUtl 相容的確定性整數亂數。詳情請參閱「obj 表 - 函式」。
|
與 AviUtl 相容的確定性整數亂數。詳情請參閱「obj 表 - 函式」。
|
||||||
|
|
||||||
|
○ 圖形繪製
|
||||||
|
obj.load("figure", ...) 產生圓、四角形、三角形、五角形、六角形、星形,
|
||||||
|
並替換物件緩衝區。詳情請參閱「obj 表 - 函式」。
|
||||||
|
|
||||||
以下功能需要與本體的繪製管線整合,因此不在此相容層的範圍內。
|
以下功能需要與本體的繪製管線整合,因此不在此相容層的範圍內。
|
||||||
呼叫它們的腳本不會如預期運作。
|
呼叫它們的腳本不會如預期運作。
|
||||||
× 影像、圖形、文字、影片的載入與繪製
|
× 繪製與合成(obj.draw / obj.drawpoly)、obj.load 的 "figure" 以外目標
|
||||||
(obj.load / obj.draw / obj.drawpoly / obj.setfont 等)
|
(影像檔、"text"、"movie" 等),以及 obj.setfont
|
||||||
× 濾鏡效果與緩衝區操作
|
× 濾鏡效果與緩衝區操作
|
||||||
(obj.effect / obj.copybuffer / obj.setoption 等)
|
(obj.effect / obj.copybuffer / obj.setoption 等)
|
||||||
× 透過 require 載入模組,以及 io 等檔案存取
|
× 透過 require 載入模組,以及 io 等檔案存取
|
||||||
@@ -488,7 +510,7 @@
|
|||||||
|
|
||||||
- 不支援項目·限制事項 -
|
- 不支援項目·限制事項 -
|
||||||
|
|
||||||
× 不支援 AviUtl2 的 obj.effect()、obj.draw()、obj.drawpoly()、obj.load() 等。
|
× 不支援 AviUtl2 的 obj.effect()、obj.draw()、obj.drawpoly() 等(obj.load 僅支援 "figure",參閱「AviUtl 腳本的部分相容」)。
|
||||||
× 不支援 AviUtl2 的 obj.rand1()、obj.setfont()、obj.mes() 等。
|
× 不支援 AviUtl2 的 obj.rand1()、obj.setfont()、obj.mes() 等。
|
||||||
× 不支援 AviUtl2 的 obj.setoption()、obj.getoption()、obj.getvalue()、obj.setanchor() 等。
|
× 不支援 AviUtl2 的 obj.setoption()、obj.getoption()、obj.getvalue()、obj.setanchor() 等。
|
||||||
× 不支援 AviUtl2 scene 表中的 scene.set()、scene.get() 等函式。
|
× 不支援 AviUtl2 scene 表中的 scene.set()、scene.get() 等函式。
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、**Luaスクリプトでオブ
|
|||||||
|
|
||||||
### 9. AviUtl スクリプトの部分互換
|
### 9. AviUtl スクリプトの部分互換
|
||||||
|
|
||||||
AviUtl のアニメーション効果スクリプト(`.anm` 系)のうち、座標・拡縮・回転・不透明度の変形と乱数を用いる範囲について、追加の記述変更なしに実行できる互換層を備えています。スクリプトに AviUtl 固有の記法が含まれない場合、この互換層は一切介入しません(従来のスクリプトの挙動は変わりません)。
|
AviUtl のアニメーション効果スクリプト(`.anm` 系)のうち、座標・拡縮・回転・不透明度の変形、乱数、および図形描画について、追加の記述変更なしに実行できる互換層を備えています。スクリプトに AviUtl 固有の記法が含まれない場合、この互換層は一切介入しません(従来のスクリプトの挙動は変わりません)。
|
||||||
|
|
||||||
対応している内容は次のとおりです。
|
対応している内容は次のとおりです。
|
||||||
|
|
||||||
@@ -203,10 +203,11 @@ AviUtl のアニメーション効果スクリプト(`.anm` 系)のうち、
|
|||||||
- `--track0:`〜`--track3:` … トラックバーの値は従来どおり `obj.track0`〜`obj.track3` から参照します(ラベル・範囲・既定値の UI 反映は行いません)。
|
- `--track0:`〜`--track3:` … トラックバーの値は従来どおり `obj.track0`〜`obj.track3` から参照します(ラベル・範囲・既定値の UI 反映は行いません)。
|
||||||
- **`@` による複数セクション**: 1 つのスクリプトに `@名前` で複数の効果が定義されている場合、先頭のセクションのみを実行します。
|
- **`@` による複数セクション**: 1 つのスクリプトに `@名前` で複数の効果が定義されている場合、先頭のセクションのみを実行します。
|
||||||
- **`obj.rand(st, ed [, seed [, frame]])`**: 指定範囲(`st`〜`ed`)の整数を返す決定論的な乱数です。`seed` と `frame` が同じであれば常に同じ値を返し、`frame` を省略すると現在のフレームを用います。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)で同じ値を返します。
|
- **`obj.rand(st, ed [, seed [, frame]])`**: 指定範囲(`st`〜`ed`)の整数を返す決定論的な乱数です。`seed` と `frame` が同じであれば常に同じ値を返し、`frame` を省略すると現在のフレームを用います。従来エンジン(MoonSharp)と高速ランタイム(LuaJIT)で同じ値を返します。
|
||||||
|
- **`obj.load("figure", 名前, 色, サイズ [, ライン [, アスペクト]])`**: 円・四角形・三角形・五角形・六角形・星形を生成し、オブジェクトのバッファを置き換えて描画します(出力は図形サイズに合わせて生成され、中心に配置されます)。`ライン` を省略するか `0` で塗りつぶし、サイズ以上の値でも塗りつぶしになります。`アスペクト`(-1.0〜1.0)で幅・高さを歪曲できます。`figure` 以外の対象は本バージョンでは対象外です。描画系 API を含むスクリプトは従来エンジン(MoonSharp)で実行されます。
|
||||||
|
|
||||||
次のような機能は、本体の描画パイプラインへの統合を要するため、この互換層では対象外です(呼び出しを含むスクリプトは意図どおりには動作しません)。
|
次のような機能は、本体の描画パイプラインへの統合を要するため、この互換層では対象外です(呼び出しを含むスクリプトは意図どおりには動作しません)。
|
||||||
|
|
||||||
- 画像・図形・テキスト・動画の読み込みと描画(`obj.load` / `obj.draw` / `obj.drawpoly` / `obj.setfont` など)
|
- 描画・合成(`obj.draw` / `obj.drawpoly`)、`obj.load` の `"figure"` 以外の対象(画像ファイル・`"text"`・`"movie"` など)、および `obj.setfont`
|
||||||
- フィルタ効果やバッファ操作(`obj.effect` / `obj.copybuffer` / `obj.setoption` など)
|
- フィルタ効果やバッファ操作(`obj.effect` / `obj.copybuffer` / `obj.setoption` など)
|
||||||
- `require` によるモジュール読み込み、`io` などのファイルアクセス
|
- `require` によるモジュール読み込み、`io` などのファイルアクセス
|
||||||
|
|
||||||
|
|||||||
+81
-1
@@ -46,15 +46,21 @@ local OFF_ERRORLEN = 7
|
|||||||
local OFF_CB_FRAME = 8
|
local OFF_CB_FRAME = 8
|
||||||
local OFF_CB_TAGLEN = 9
|
local OFF_CB_TAGLEN = 9
|
||||||
local OFF_CB_FOUND = 10
|
local OFF_CB_FOUND = 10
|
||||||
|
local OFF_CB_KIND = 11
|
||||||
|
local OFF_LOAD_RESULT_W = 12
|
||||||
|
local OFF_LOAD_RESULT_H = 13
|
||||||
local SCRIPT_OFFSET = 64 + 64 * 8
|
local SCRIPT_OFFSET = 64 + 64 * 8
|
||||||
local ERROR_OFFSET = SCRIPT_OFFSET + 128 * 1024
|
local ERROR_OFFSET = SCRIPT_OFFSET + 128 * 1024
|
||||||
local CB_TAG_OFFSET = ERROR_OFFSET + 4 * 1024
|
local CB_TAG_OFFSET = ERROR_OFFSET + 4 * 1024
|
||||||
local CB_TAG_MAX = 256
|
local CB_TAG_MAX = 4096
|
||||||
local CB_RESULT_OFFSET = CB_TAG_OFFSET + CB_TAG_MAX
|
local CB_RESULT_OFFSET = CB_TAG_OFFSET + CB_TAG_MAX
|
||||||
local PIXEL_OFFSET = CB_RESULT_OFFSET + 8 * 8
|
local PIXEL_OFFSET = CB_RESULT_OFFSET + 8 * 8
|
||||||
local FIRST_WRITABLE = 8
|
local FIRST_WRITABLE = 8
|
||||||
local LAST_WRITABLE = 25
|
local LAST_WRITABLE = 25
|
||||||
local STATUS_CALLBACK = 3
|
local STATUS_CALLBACK = 3
|
||||||
|
local CB_KIND_GETOBJECT = 0
|
||||||
|
local CB_KIND_LOADFIGURE = 1
|
||||||
|
local CB_KIND_EFFECT = 2
|
||||||
|
|
||||||
assert(loadfile(shimPath))()
|
assert(loadfile(shimPath))()
|
||||||
|
|
||||||
@@ -150,6 +156,77 @@ function obj.rand(a, b, seed, frame)
|
|||||||
return aviutl_rand(a or 0, b or 0, seed or 0, frame or obj.frame or 0)
|
return aviutl_rand(a or 0, b or 0, seed or 0, frame or obj.frame or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function obj.load(kind, name, color, size, lineWidth, aspect)
|
||||||
|
if kind ~= "figure" then return end
|
||||||
|
name = name or ""
|
||||||
|
color = color or 0
|
||||||
|
size = size or 100
|
||||||
|
lineWidth = lineWidth or 0
|
||||||
|
aspect = aspect or 0
|
||||||
|
local nameBytes = tostring(name)
|
||||||
|
local len = #nameBytes
|
||||||
|
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||||
|
ffi.copy(base + CB_TAG_OFFSET, nameBytes, len)
|
||||||
|
i32[OFF_CB_TAGLEN] = len
|
||||||
|
i32[OFF_CB_KIND] = CB_KIND_LOADFIGURE
|
||||||
|
cbResult[0] = color
|
||||||
|
cbResult[1] = size
|
||||||
|
cbResult[2] = lineWidth
|
||||||
|
cbResult[3] = aspect
|
||||||
|
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||||
|
k32.SetEvent(doneEvent)
|
||||||
|
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||||
|
local newW = i32[OFF_LOAD_RESULT_W]
|
||||||
|
local newH = i32[OFF_LOAD_RESULT_H]
|
||||||
|
if newW > 0 and newH > 0 then
|
||||||
|
width = newW
|
||||||
|
height = newH
|
||||||
|
i32[OFF_WIDTH] = newW
|
||||||
|
i32[OFF_HEIGHT] = newH
|
||||||
|
dirty = true
|
||||||
|
obj.w = newW; obj.h = newH
|
||||||
|
obj.hw = newW / 2; obj.hh = newH / 2
|
||||||
|
obj.cx = newW / 2; obj.cy = newH / 2
|
||||||
|
obj.cz = 0
|
||||||
|
obj.diagonal = math.sqrt(newW * newW + newH * newH)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function obj.effect(name, ...)
|
||||||
|
if type(name) ~= "string" then return end
|
||||||
|
local args = { ... }
|
||||||
|
local n = select("#", ...)
|
||||||
|
local parts = { name }
|
||||||
|
local pos = #name + 1
|
||||||
|
for i = 1, n - 1, 2 do
|
||||||
|
local k = tostring(args[i])
|
||||||
|
local v = args[i + 1]
|
||||||
|
local encoded
|
||||||
|
local vt = type(v)
|
||||||
|
if vt == "number" then
|
||||||
|
encoded = "n" .. string.format("%.17g", v)
|
||||||
|
elseif vt == "boolean" then
|
||||||
|
encoded = v and "b1" or "b0"
|
||||||
|
else
|
||||||
|
encoded = "s" .. tostring(v)
|
||||||
|
end
|
||||||
|
local needed = 2 + #k + #encoded
|
||||||
|
if pos + needed > CB_TAG_MAX then break end
|
||||||
|
parts[#parts + 1] = k
|
||||||
|
parts[#parts + 1] = encoded
|
||||||
|
pos = pos + needed
|
||||||
|
end
|
||||||
|
local payload = table.concat(parts, "\0")
|
||||||
|
local len = #payload
|
||||||
|
if len > CB_TAG_MAX then len = CB_TAG_MAX end
|
||||||
|
ffi.copy(base + CB_TAG_OFFSET, payload, len)
|
||||||
|
i32[OFF_CB_TAGLEN] = len
|
||||||
|
i32[OFF_CB_KIND] = CB_KIND_EFFECT
|
||||||
|
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||||
|
k32.SetEvent(doneEvent)
|
||||||
|
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||||
|
end
|
||||||
|
|
||||||
local cacheTag, cacheFrame, cacheFound
|
local cacheTag, cacheFrame, cacheFound
|
||||||
local cacheExist, cacheX, cacheY, cacheZ, cacheZoom, cacheRz, cacheAlpha, cacheLayer
|
local cacheExist, cacheX, cacheY, cacheZ, cacheZoom, cacheRz, cacheAlpha, cacheLayer
|
||||||
|
|
||||||
@@ -176,6 +253,7 @@ function obj.getobject(tag, frame)
|
|||||||
ffi.copy(base + CB_TAG_OFFSET, tag, len)
|
ffi.copy(base + CB_TAG_OFFSET, tag, len)
|
||||||
i32[OFF_CB_TAGLEN] = len
|
i32[OFF_CB_TAGLEN] = len
|
||||||
i32[OFF_CB_FRAME] = frame
|
i32[OFF_CB_FRAME] = frame
|
||||||
|
i32[OFF_CB_KIND] = CB_KIND_GETOBJECT
|
||||||
i32[OFF_STATUS] = STATUS_CALLBACK
|
i32[OFF_STATUS] = STATUS_CALLBACK
|
||||||
k32.SetEvent(doneEvent)
|
k32.SetEvent(doneEvent)
|
||||||
k32.WaitForSingleObject(workEvent, INFINITE)
|
k32.WaitForSingleObject(workEvent, INFINITE)
|
||||||
@@ -227,6 +305,8 @@ local function loadFields()
|
|||||||
ymm4.is_saving = f64[48] ~= 0; ymm4.is_playing = f64[49] ~= 0; ymm4.is_paused = f64[50] ~= 0
|
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
|
ymm4.group_ratio = (f64[44] ~= 0) and (f64[43] / f64[44]) or 0
|
||||||
obj.timelineframe = f64[51]; obj.timelinetime = f64[52]
|
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
|
end
|
||||||
|
|
||||||
local function storeFields()
|
local function storeFields()
|
||||||
|
|||||||
新しいイシューから参照
ユーザーをブロックする