コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
c8350161db
|
||
|
|
679cab03b5
|
||
|
|
6783146231
|
||
|
|
df303ee154
|
||
|
|
f49bd740a0
|
||
|
|
80d1b75227
|
検索条件に一致するファイルはありません
+36
-38
@@ -1,56 +1,54 @@
|
||||
# v1.6.0 - Lua スクリプト for YMM4
|
||||
# v1.7.0 - Lua スクリプト for YMM4
|
||||
|
||||
AviUtl のアニメーション効果スクリプト互換層に**動的パラメータの UI 反映**を
|
||||
追加したリリースです。スクリプトのヘッダに記述した `--track` / `--check` /
|
||||
`--color` の宣言が、エディタのパラメータUIへ自動的に反映されるようになりました。
|
||||
AviUtl のアニメーション効果スクリプト互換層に**映像エフェクトの適用(`obj.effect()`)**を
|
||||
追加したリリースです。スクリプトから YMM4 に登録された映像エフェクトを呼び出し、
|
||||
図形やピクセルで生成した画像へ連鎖適用できるようになりました。
|
||||
|
||||
---
|
||||
|
||||
## 新機能
|
||||
|
||||
### 1. AviUtl ヘッダ宣言に応じた動的パラメータUI
|
||||
### 1. obj.effect() による YMM4 映像エフェクトの適用
|
||||
|
||||
スクリプト先頭の `--track0`〜`--track3` / `--check0`〜`--check3` / `--color` を
|
||||
解析し、宣言された項目だけをエディタUIへ表示します。AviUtl の仕様に準じ、
|
||||
トラックバーは最大4個、チェックボックスは最大4個、カラーは1個です。
|
||||
`obj.effect(エフェクト名, パラメータ名, 値, パラメータ名, 値, ...)` を実装しました。
|
||||
スクリプトが生成した画像に対して、YMM4 の映像エフェクトを適用します。
|
||||
|
||||
- `--track番号:名前,最小,最大,初期値,移動量`: 宣言されたトラックのスライダーを
|
||||
表示します。トラック値は評価時にヘッダの最小〜最大へクランプされ、`obj.track0`〜
|
||||
`obj.track3` から参照できます。
|
||||
- `--check番号:名前,初期値`: トグルスライダーを表示します。値は `obj.check0`〜
|
||||
`obj.check3` から真偽値(false / true)として参照できます。
|
||||
- `--color:色`: カラーピッカーを表示します。選択した色はグローバル変数 `color`
|
||||
(0xRRGGBB)として参照できます。
|
||||
- 宣言が一つも無い場合は、従来どおり Track0〜Track3 の4スライダー表示へ戻ります。
|
||||
- 各項目のラベルは多言語化された固定スロット(Track0〜3 / Check0〜3 / Color)で
|
||||
表示されます。設定した値はプロジェクトファイルに保存され、再現できます。
|
||||
- エフェクト名は YMM4 の登録名または別名で指定します。`EffectFactories` から取得できる
|
||||
全映像エフェクト(標準エフェクトおよびユーザー製プラグインを含む)が対象です。
|
||||
- パラメータは表示名またはプロパティ名で指定します。型に応じて設定され、Animation は
|
||||
定数値、真偽値、列挙(名前または番号)、色(0xRRGGBB)、数値、文字列に対応します。
|
||||
- パラメータはキー/値のペアで複数同時に指定できます。
|
||||
- `obj.effect` を複数回呼び出すと、呼んだ順に**独立したエフェクトインスタンス**として
|
||||
連鎖適用されます。同じエフェクトを複数回重ねて適用することもできます。
|
||||
- エフェクトは、スクリプトが生成した画像(図形やピクセル)または入力画像に対して、
|
||||
YMM4 本体と同じ `SetInput` → `Update` → `Output` のチェーンで適用されます。
|
||||
- パラメータはフレームごとに再評価されるため、`obj.time` などに応じて値を計算すれば
|
||||
エフェクトのパラメータをアニメーションさせられます。
|
||||
|
||||
---
|
||||
|
||||
## 注意事項
|
||||
|
||||
- ラベルは固定スロット番号で表示され、スクリプト内に記述したパラメータ名
|
||||
(例: `--track0:X速度,...` の「X速度」)は UI ラベルへは反映されません。
|
||||
- トラックのスライダー操作範囲は従来どおり -100〜100 で、ヘッダの範囲・既定値は
|
||||
スライダーの表示そのものには反映されません。トラック値は評価時にヘッダの
|
||||
最小〜最大へクランプされます。新規に宣言されたチェック・色にはヘッダの既定値が
|
||||
適用されますが、トラックには適用されず初期値は 0 のままです。
|
||||
- `--dialog`(`/chk`・`/col`・`/fig`)、`--file`、`--font` には対応していません。
|
||||
- 本変更に伴い、`--check` / `--color` の擬似展開(従来 `obj.checkN` や `color` を
|
||||
スクリプト先頭へ自動挿入していた挙動)は廃止され、値は UI から供給されます。
|
||||
`--dialog` / `--param` の展開は従来どおりです。
|
||||
- `obj.effect`(および `obj.load`)は描画系 API のため MoonSharp エンジンで実行されます。
|
||||
ネイティブ(LuaJIT)経路ではエフェクトは適用されません。
|
||||
- エフェクトの登録名はローカライズされるため、指定名は実行環境の表示言語に依存する
|
||||
場合があります。言語に依存させたくない場合は、英語の別名やプロパティ名を用いて
|
||||
ください。
|
||||
- Animation パラメータは定数値として設定されます。キーフレーム曲線は指定できません。
|
||||
時間変化させたい場合はスクリプト側で値を計算してください。
|
||||
- 指定したエフェクトが見つからない、または生成・更新に失敗した場合、その要求は安全に
|
||||
スキップされ、画像はそのまま通過します。描画は停止しません。
|
||||
- 対象エフェクトの解決は導入状況に依存します。ユーザー製エフェクトは未導入の場合、
|
||||
名前が解決されずスキップされます。
|
||||
|
||||
---
|
||||
|
||||
## 内部実装
|
||||
|
||||
- AviUtl ヘッダ(`--track` / `--check` / `--color`)を解析するレイアウト解析を
|
||||
追加しました。走査範囲は既存の互換変換と同じく最初の `@` セクションより前です。
|
||||
- 解析結果に基づき、`[ShowPropertyEditorWhen]` による項目ごとの動的表示と、
|
||||
評価時のトラック値クランプを実装しました。
|
||||
- `obj.check0`〜`obj.check3`(真偽値)とグローバル `color` を、MoonSharp および
|
||||
ネイティブ(LuaJIT)双方の実行経路へ配線しました。
|
||||
- 互換変換から `--check` / `--color` の擬似展開を廃止し、UI を値の唯一のソースに
|
||||
しました。
|
||||
- チェック・色のラベルを多言語リソースへ追加しました。
|
||||
- ヘッダ解析および互換変換の挙動変更に関するユニットテストを追加・更新しました。
|
||||
- スクリプトの `obj.effect` 呼び出しを実行コンテキストに記録し、スクリプト実行後に
|
||||
描画スレッドで Direct2D エフェクトチェーンとして適用する仕組みを追加しました。
|
||||
- `EffectFactories.VideoEffectFactories` を登録名・別名で索引し、リフレクションで
|
||||
対象プロパティを解決してパラメータを設定します。
|
||||
- YMM4 の API 変更に対する多層フォールバックを実装しました。レジストリ構築、
|
||||
パラメータ解決、各エフェクトの生成・更新・適用をそれぞれ例外隔離し、失敗時は
|
||||
当該エフェクトをスキップして元画像を通過させます(描画自体は停止しません)。
|
||||
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
Luaスクリプト for YMM4 v1.6.0
|
||||
Luaスクリプト for YMM4 v1.7.0
|
||||
========================================
|
||||
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
|
||||
ピクセルを直接制御できるプラグインです。
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,14 @@ namespace LuaScript
|
||||
|
||||
public IReadOnlyList<SceneObjectQuery> ObjectQueries => _objectQueries;
|
||||
|
||||
private readonly List<AviUtlEffectRequest> _effectRequests = [];
|
||||
|
||||
public IReadOnlyList<AviUtlEffectRequest> EffectRequests => _effectRequests;
|
||||
|
||||
internal void AddEffect(AviUtlEffectRequest request) => _effectRequests.Add(request);
|
||||
|
||||
internal void ClearEffects() => _effectRequests.Clear();
|
||||
|
||||
public double RxRad => Rx * Math.PI / 180d;
|
||||
public double RyRad => Ry * Math.PI / 180d;
|
||||
public double RzRad => Rz * Math.PI / 180d;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>1.6.0</Version>
|
||||
<Version>1.7.0</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace LuaScript
|
||||
private LuaJitWorker? _nativeWorker;
|
||||
private double[]? _nativeFields;
|
||||
private bool _nativeWarned;
|
||||
private bool _effectChainWarned;
|
||||
|
||||
private EffectDescription? _frameDesc;
|
||||
private SceneObjectResolver? _frameResolver;
|
||||
@@ -91,7 +92,9 @@ namespace LuaScript
|
||||
private RenderKey _cachedKey;
|
||||
private SceneObjectQuery[] _cachedQueries = [];
|
||||
private DrawDescription? _cachedOutputDesc;
|
||||
private bool _cachedPixelsModified;
|
||||
private ID2D1Image? _cachedEffectOutput;
|
||||
|
||||
private VideoEffectChain? _effectChain;
|
||||
|
||||
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
||||
{
|
||||
@@ -189,7 +192,7 @@ namespace LuaScript
|
||||
if (!_isFirst && key == _cachedKey &&
|
||||
(_cachedQueries.Length == 0 || QueriesMatch(_cachedQueries, GetFrameResolver())))
|
||||
{
|
||||
effectOutput = _cachedPixelsModified ? _transformEffect?.Output : null;
|
||||
effectOutput = _cachedEffectOutput;
|
||||
return _cachedOutputDesc ?? inDesc;
|
||||
}
|
||||
|
||||
@@ -202,7 +205,6 @@ namespace LuaScript
|
||||
ctx.SetPixelLoader(() => LoadInputPixels(bounds, imgW, imgH));
|
||||
|
||||
DrawDescription outDesc = inDesc;
|
||||
bool pixelsModified = false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -214,7 +216,7 @@ namespace LuaScript
|
||||
|
||||
if (nativeReady)
|
||||
{
|
||||
pixelsModified = ExecuteNative(runnable, ctx, bounds, imgW, imgH);
|
||||
ExecuteNative(runnable, ctx, bounds, imgW, imgH);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -231,7 +233,6 @@ namespace LuaScript
|
||||
else
|
||||
UpdateTransformEffect(bounds.Left, bounds.Top);
|
||||
effectOutput = _transformEffect!.Output;
|
||||
pixelsModified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -240,6 +241,20 @@ namespace LuaScript
|
||||
}
|
||||
|
||||
outDesc = BuildOutputDesc(inDesc, ctx);
|
||||
|
||||
if (ctx.EffectRequests.Count > 0)
|
||||
{
|
||||
var source = effectOutput ?? input;
|
||||
try
|
||||
{
|
||||
effectOutput = ApplyEffectChain(source, ctx.EffectRequests, desc, ref outDesc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
effectOutput = source;
|
||||
WarnEffectChainFailureOnce(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (LuaScriptTimeoutException ex)
|
||||
{
|
||||
@@ -265,11 +280,17 @@ namespace LuaScript
|
||||
_cachedKey = key;
|
||||
_cachedQueries = ctx.ObjectQueries.Count == 0 ? [] : [.. ctx.ObjectQueries];
|
||||
_cachedOutputDesc = outDesc;
|
||||
_cachedPixelsModified = pixelsModified;
|
||||
_cachedEffectOutput = effectOutput;
|
||||
|
||||
return outDesc;
|
||||
}
|
||||
|
||||
private ID2D1Image ApplyEffectChain(ID2D1Image source, IReadOnlyList<AviUtlEffectRequest> requests, EffectDescription desc, ref DrawDescription drawDescription)
|
||||
{
|
||||
_effectChain ??= new VideoEffectChain(_ownCtx!);
|
||||
return _effectChain.Apply(source, requests, desc, ref drawDescription);
|
||||
}
|
||||
|
||||
private static SceneObjectResolver BuildSceneObjectResolver(EffectDescription desc)
|
||||
{
|
||||
var scenes = desc.Scenes;
|
||||
@@ -326,6 +347,7 @@ namespace LuaScript
|
||||
: 0d;
|
||||
|
||||
ctx.ClearQueries();
|
||||
ctx.ClearEffects();
|
||||
|
||||
ctx.ImageWidth = imgW;
|
||||
ctx.ImageHeight = imgH;
|
||||
@@ -400,6 +422,13 @@ namespace LuaScript
|
||||
Log.Default.Write($"LuaScript: native runtime not found at '{NativeDirectory}'. Falling back to MoonSharp (slow). Deploy the 'native' folder next to the plugin.");
|
||||
}
|
||||
|
||||
private void WarnEffectChainFailureOnce(Exception ex)
|
||||
{
|
||||
if (_effectChainWarned) return;
|
||||
_effectChainWarned = true;
|
||||
Log.Default.Write("LuaScript: obj.effect chain failed and was skipped for this frame. The source image is passed through unchanged.", ex);
|
||||
}
|
||||
|
||||
private bool ExecuteNative(string script, AviUtlScriptContext ctx, RawRectF bounds, int imgW, int imgH)
|
||||
{
|
||||
_nativeWorker ??= new LuaJitWorker(NativeDirectory);
|
||||
@@ -548,6 +577,7 @@ namespace LuaScript
|
||||
{
|
||||
_engine.Dispose();
|
||||
_nativeWorker?.Dispose();
|
||||
_effectChain?.Dispose();
|
||||
_pixelLoaderSemaphore.Dispose();
|
||||
_renderTarget?.Dispose();
|
||||
_stagingBitmap?.Dispose();
|
||||
|
||||
@@ -487,6 +487,33 @@ namespace LuaScript
|
||||
LoadFigure(name, color, size, line, aspect);
|
||||
return DynValue.Void;
|
||||
});
|
||||
|
||||
obj["effect"] = DynValue.NewCallback((_, args) =>
|
||||
{
|
||||
_activeCancellation.ThrowIfCancellationRequested();
|
||||
if (_activeContext is null || args.Count == 0 || args[0].Type != DataType.String)
|
||||
return DynValue.Void;
|
||||
|
||||
string name = args[0].String;
|
||||
var arguments = new List<KeyValuePair<string, object>>();
|
||||
for (int i = 1; i + 1 < args.Count; i += 2)
|
||||
{
|
||||
if (args[i].Type != DataType.String)
|
||||
continue;
|
||||
var value = args[i + 1];
|
||||
object boxed = value.Type switch
|
||||
{
|
||||
DataType.Number => value.Number,
|
||||
DataType.Boolean => value.Boolean,
|
||||
DataType.String => value.String,
|
||||
_ => value.CastToNumber() ?? 0d,
|
||||
};
|
||||
arguments.Add(new KeyValuePair<string, object>(args[i].String, boxed));
|
||||
}
|
||||
|
||||
_activeContext.AddEffect(new AviUtlEffectRequest(name, arguments));
|
||||
return DynValue.Void;
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadFigure(string name, int color, double size, double line, double aspect)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする