obj.getobjectにフレーム指定引数を追加
このコミットが含まれているのは:
5ファイル変更
+118
-52
検索条件に一致するファイルはありません
@@ -42,7 +42,11 @@ namespace LuaScript
|
||||
public int Index { get; init; }
|
||||
public int Num { get; init; }
|
||||
|
||||
public IReadOnlyList<SceneObjectInfo> SceneObjects { get; init; } = [];
|
||||
public SceneObjectResolver? Resolver { get; init; }
|
||||
|
||||
private readonly List<SceneObjectQuery> _objectQueries = [];
|
||||
|
||||
public IReadOnlyList<SceneObjectQuery> ObjectQueries => _objectQueries;
|
||||
|
||||
public double RxRad => Rx * Math.PI / 180d;
|
||||
public double RyRad => Ry * Math.PI / 180d;
|
||||
@@ -83,29 +87,16 @@ namespace LuaScript
|
||||
|
||||
internal void MarkPixelsDirty() => _isPixelsDirty = true;
|
||||
|
||||
public bool TryGetObject(string tag, out SceneObjectInfo info)
|
||||
public bool ResolveObject(string tag, int frame, out SceneObjectInfo info)
|
||||
{
|
||||
SceneObjectInfo? fallback = null;
|
||||
var objects = SceneObjects;
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
if (Resolver is not null && Resolver.TryResolve(tag, frame, out var resolved))
|
||||
{
|
||||
var candidate = objects[i];
|
||||
if (!string.Equals(candidate.Tag, tag, StringComparison.Ordinal))
|
||||
continue;
|
||||
if (candidate.Exist)
|
||||
{
|
||||
info = candidate;
|
||||
return true;
|
||||
}
|
||||
fallback ??= candidate;
|
||||
}
|
||||
|
||||
if (fallback is { } value)
|
||||
{
|
||||
info = value;
|
||||
_objectQueries.Add(new SceneObjectQuery(tag, frame, resolved));
|
||||
info = resolved;
|
||||
return true;
|
||||
}
|
||||
|
||||
_objectQueries.Add(new SceneObjectQuery(tag, frame, null));
|
||||
info = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace LuaScript
|
||||
private bool _isFirst = true;
|
||||
private ID2D1Image? _cachedInput;
|
||||
private RenderKey _cachedKey;
|
||||
private SceneObjectInfo[] _cachedSceneObjects = [];
|
||||
private SceneObjectQuery[] _cachedQueries = [];
|
||||
private DrawDescription? _cachedOutputDesc;
|
||||
private bool _cachedPixelsModified;
|
||||
|
||||
@@ -113,10 +113,10 @@ namespace LuaScript
|
||||
desc.TimelineDuration.Time.TotalSeconds,
|
||||
inDesc);
|
||||
|
||||
var sceneObjects = BuildSceneObjects(desc);
|
||||
var resolver = BuildSceneObjectResolver(desc);
|
||||
|
||||
if (!_isFirst && key == _cachedKey &&
|
||||
_cachedSceneObjects.AsSpan().SequenceEqual(sceneObjects))
|
||||
QueriesMatch(_cachedQueries, resolver))
|
||||
{
|
||||
effectOutput = _cachedPixelsModified ? _transformEffect?.Output : null;
|
||||
return _cachedOutputDesc ?? inDesc;
|
||||
@@ -126,7 +126,7 @@ namespace LuaScript
|
||||
int imgW = Math.Max(1, (int)Math.Ceiling(bounds.Right - bounds.Left));
|
||||
int imgH = Math.Max(1, (int)Math.Ceiling(bounds.Bottom - bounds.Top));
|
||||
|
||||
var ctx = BuildContext(in key, imgW, imgH, sceneObjects);
|
||||
var ctx = BuildContext(in key, imgW, imgH, resolver);
|
||||
ctx.SetPixelLoader(() => LoadInputPixels(bounds, imgW, imgH));
|
||||
|
||||
DrawDescription outDesc = inDesc;
|
||||
@@ -165,18 +165,18 @@ namespace LuaScript
|
||||
|
||||
_isFirst = false;
|
||||
_cachedKey = key;
|
||||
_cachedSceneObjects = sceneObjects;
|
||||
_cachedQueries = [.. ctx.ObjectQueries];
|
||||
_cachedOutputDesc = outDesc;
|
||||
_cachedPixelsModified = pixelsModified;
|
||||
|
||||
return outDesc;
|
||||
}
|
||||
|
||||
private static SceneObjectInfo[] BuildSceneObjects(EffectDescription desc)
|
||||
private static SceneObjectResolver BuildSceneObjectResolver(EffectDescription desc)
|
||||
{
|
||||
var scenes = desc.Scenes;
|
||||
if (scenes is null)
|
||||
return [];
|
||||
return new SceneObjectResolver([], desc.FPS);
|
||||
|
||||
Scene? scene = null;
|
||||
foreach (var info in scenes)
|
||||
@@ -188,12 +188,10 @@ namespace LuaScript
|
||||
}
|
||||
}
|
||||
if (scene is null)
|
||||
return [];
|
||||
return new SceneObjectResolver([], desc.FPS);
|
||||
|
||||
int timelineFrame = desc.TimelinePosition.Frame;
|
||||
int fps = desc.FPS;
|
||||
var items = scene.Timeline.Items;
|
||||
var result = new List<SceneObjectInfo>(items.Count);
|
||||
var entries = new List<SceneObjectResolver.Entry>(items.Count);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
@@ -203,30 +201,25 @@ namespace LuaScript
|
||||
if (string.IsNullOrEmpty(tag))
|
||||
continue;
|
||||
|
||||
int length = item.Length;
|
||||
int local = Math.Clamp(timelineFrame - item.Frame, 0, length);
|
||||
bool exist = item.Frame <= timelineFrame && timelineFrame < item.Frame + length;
|
||||
|
||||
double x = visual.X.GetValue(local, length, fps);
|
||||
double y = visual.Y.GetValue(local, length, fps);
|
||||
double z = visual.Z.GetValue(local, length, fps);
|
||||
double zoom = visual.Zoom.GetValue(local, length, fps) / 100d;
|
||||
double rz = visual.Rotation.GetValue(local, length, fps);
|
||||
|
||||
double opacity = visual.Opacity.GetValue(local, length, fps) / 100d;
|
||||
double timeSec = fps > 0 ? local / (double)fps : 0d;
|
||||
double durationSec = fps > 0 ? length / (double)fps : 0d;
|
||||
double fadeIn = visual.FadeIn <= 0d ? 1d : Math.Min(1d, timeSec / visual.FadeIn);
|
||||
double fadeOut = visual.FadeOut <= 0d ? 1d : Math.Min(1d, (durationSec - timeSec) / visual.FadeOut);
|
||||
double alpha = opacity * Math.Min(fadeIn, fadeOut) * 255d;
|
||||
|
||||
result.Add(new SceneObjectInfo(tag, exist, x, y, z, zoom, rz, alpha, item.Layer));
|
||||
entries.Add(new SceneObjectResolver.Entry(tag, item.Frame, item.Length, item.Layer, visual));
|
||||
}
|
||||
|
||||
return [.. result];
|
||||
return new SceneObjectResolver([.. entries], desc.FPS);
|
||||
}
|
||||
|
||||
private static AviUtlScriptContext BuildContext(in RenderKey key, int imgW, int imgH, SceneObjectInfo[] sceneObjects)
|
||||
private static bool QueriesMatch(SceneObjectQuery[] queries, SceneObjectResolver resolver)
|
||||
{
|
||||
for (int i = 0; i < queries.Length; i++)
|
||||
{
|
||||
var query = queries[i];
|
||||
SceneObjectInfo? current = resolver.TryResolve(query.Tag, query.Frame, out var info) ? info : null;
|
||||
if (!Nullable.Equals(current, query.Result))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static AviUtlScriptContext BuildContext(in RenderKey key, int imgW, int imgH, SceneObjectResolver resolver)
|
||||
{
|
||||
var zoom = key.InputDesc.Zoom;
|
||||
double zoomAvg = (zoom.X + zoom.Y) / 2d;
|
||||
@@ -277,7 +270,7 @@ namespace LuaScript
|
||||
IsPaused = key.Usage == TimelineSourceUsage.Paused,
|
||||
SceneId = key.SceneId.ToString(),
|
||||
TimeRatio = key.Length > 0 ? key.Frame / (double)key.Length : 0d,
|
||||
SceneObjects = sceneObjects,
|
||||
Resolver = resolver,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -407,7 +407,15 @@ namespace LuaScript
|
||||
var tag = args[0];
|
||||
if (tag.Type != DataType.String)
|
||||
return DynValue.Nil;
|
||||
if (!_activeContext.TryGetObject(tag.String, out var info))
|
||||
int frame = _activeContext.TimelineFrame;
|
||||
if (args.Count >= 2)
|
||||
{
|
||||
var frameArg = args[1];
|
||||
if (frameArg.Type != DataType.Number)
|
||||
return DynValue.Nil;
|
||||
frame = (int)frameArg.Number;
|
||||
}
|
||||
if (!_activeContext.ResolveObject(tag.String, frame, out var info))
|
||||
return DynValue.Nil;
|
||||
return BuildObjectTable(execCtx.GetScript(), info);
|
||||
});
|
||||
|
||||
@@ -10,4 +10,9 @@ namespace LuaScript
|
||||
double Rz,
|
||||
double Alpha,
|
||||
int Layer);
|
||||
|
||||
internal readonly record struct SceneObjectQuery(
|
||||
string Tag,
|
||||
int Frame,
|
||||
SceneObjectInfo? Result);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using YukkuriMovieMaker.Project.Items;
|
||||
|
||||
namespace LuaScript
|
||||
{
|
||||
internal sealed class SceneObjectResolver
|
||||
{
|
||||
internal readonly record struct Entry(string Tag, int Frame, int Length, int Layer, VisualItem Item);
|
||||
|
||||
private readonly Entry[] _entries;
|
||||
private readonly int _fps;
|
||||
|
||||
internal SceneObjectResolver(Entry[] entries, int fps)
|
||||
{
|
||||
_entries = entries;
|
||||
_fps = fps;
|
||||
}
|
||||
|
||||
internal bool TryResolve(string tag, int timelineFrame, out SceneObjectInfo info)
|
||||
{
|
||||
int fallback = -1;
|
||||
for (int i = 0; i < _entries.Length; i++)
|
||||
{
|
||||
if (!string.Equals(_entries[i].Tag, tag, StringComparison.Ordinal))
|
||||
continue;
|
||||
if (IsExist(_entries[i], timelineFrame))
|
||||
{
|
||||
info = Evaluate(_entries[i], timelineFrame);
|
||||
return true;
|
||||
}
|
||||
if (fallback < 0)
|
||||
fallback = i;
|
||||
}
|
||||
|
||||
if (fallback >= 0)
|
||||
{
|
||||
info = Evaluate(_entries[fallback], timelineFrame);
|
||||
return true;
|
||||
}
|
||||
|
||||
info = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsExist(in Entry entry, int timelineFrame)
|
||||
=> entry.Frame <= timelineFrame && timelineFrame < entry.Frame + entry.Length;
|
||||
|
||||
private SceneObjectInfo Evaluate(in Entry entry, int timelineFrame)
|
||||
{
|
||||
var visual = entry.Item;
|
||||
int length = entry.Length;
|
||||
int local = Math.Clamp(timelineFrame - entry.Frame, 0, length);
|
||||
|
||||
double x = visual.X.GetValue(local, length, _fps);
|
||||
double y = visual.Y.GetValue(local, length, _fps);
|
||||
double z = visual.Z.GetValue(local, length, _fps);
|
||||
double zoom = visual.Zoom.GetValue(local, length, _fps) / 100d;
|
||||
double rz = visual.Rotation.GetValue(local, length, _fps);
|
||||
|
||||
double opacity = visual.Opacity.GetValue(local, length, _fps) / 100d;
|
||||
double timeSec = _fps > 0 ? local / (double)_fps : 0d;
|
||||
double durationSec = _fps > 0 ? length / (double)_fps : 0d;
|
||||
double fadeIn = visual.FadeIn <= 0d ? 1d : Math.Min(1d, timeSec / visual.FadeIn);
|
||||
double fadeOut = visual.FadeOut <= 0d ? 1d : Math.Min(1d, (durationSec - timeSec) / visual.FadeOut);
|
||||
double alpha = opacity * Math.Min(fadeIn, fadeOut) * 255d;
|
||||
|
||||
return new SceneObjectInfo(entry.Tag, IsExist(entry, timelineFrame), x, y, z, zoom, rz, alpha, entry.Layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする