增加逐个导出时使用自动时长

This commit is contained in:
ww-rm
2025-03-26 13:07:23 +08:00
parent 72f898ed60
commit 5ee74f39d8
2 changed files with 24 additions and 5 deletions

View File

@@ -17,14 +17,27 @@ namespace SpineViewer.Exporter.Implementations.ExportArgs
/// <summary> /// <summary>
/// 导出时长 /// 导出时长
/// </summary> /// </summary>
[Category("视频参数"), DisplayName("时长"), Description("可以从模型列表查看动画时长")] [Category("视频参数"), DisplayName("时长"), Description("可以从模型列表查看动画时长, 如果小于 0, 则在逐个导出时每个模型使用各自的当前动画时长")]
public float Duration { get => duration; set => duration = Math.Max(0, value); } public float Duration
private float duration = 1; {
get => duration;
set => duration = value < 0 ? -1 : value;
}
private float duration = -1;
/// <summary> /// <summary>
/// 帧率 /// 帧率
/// </summary> /// </summary>
[Category("视频参数"), DisplayName("帧率"), Description("每秒画面数")] [Category("视频参数"), DisplayName("帧率"), Description("每秒画面数")]
public float FPS { get; set; } = 60; public float FPS { get; set; } = 60;
public override string? Validate()
{
if (base.Validate() is string error)
return error;
if (ExportSingle && Duration < 0)
return "导出单个时导出时长不能为负数";
return null;
}
} }
} }

View File

@@ -22,8 +22,13 @@ namespace SpineViewer.Exporter.Implementations.Exporter
protected IEnumerable<SFMLImageVideoFrame> GetFrames(Spine.Spine spine, BackgroundWorker? worker = null) protected IEnumerable<SFMLImageVideoFrame> GetFrames(Spine.Spine spine, BackgroundWorker? worker = null)
{ {
var args = (VideoExportArgs)ExportArgs; var args = (VideoExportArgs)ExportArgs;
// 独立导出时如果 args.Duration 小于 0 则使用自己的动画时长
var duration = args.Duration;
if (duration < 0) duration = spine.GetAnimationDuration(spine.CurrentAnimation);
float delta = 1f / args.FPS; float delta = 1f / args.FPS;
int total = 1 + (int)(args.Duration * args.FPS); // 至少导出 1 帧 int total = Math.Max(1, (int)(duration * args.FPS)); // 至少导出 1 帧
worker?.ReportProgress(0, $"{spine.Name} 已处理 0/{total} 帧"); worker?.ReportProgress(0, $"{spine.Name} 已处理 0/{total} 帧");
for (int i = 0; i < total; i++) for (int i = 0; i < total; i++)
@@ -46,9 +51,10 @@ namespace SpineViewer.Exporter.Implementations.Exporter
/// </summary> /// </summary>
protected IEnumerable<SFMLImageVideoFrame> GetFrames(Spine.Spine[] spinesToRender, BackgroundWorker? worker = null) protected IEnumerable<SFMLImageVideoFrame> GetFrames(Spine.Spine[] spinesToRender, BackgroundWorker? worker = null)
{ {
// 导出单个时必须根据 args.Duration 决定导出时长
var args = (VideoExportArgs)ExportArgs; var args = (VideoExportArgs)ExportArgs;
float delta = 1f / args.FPS; float delta = 1f / args.FPS;
int total = 1 + (int)(args.Duration * args.FPS); // 至少导出 1 帧 int total = Math.Max(1, (int)(args.Duration * args.FPS)); // 至少导出 1 帧
worker?.ReportProgress(0, $"已处理 0/{total} 帧"); worker?.ReportProgress(0, $"已处理 0/{total} 帧");
for (int i = 0; i < total; i++) for (int i = 0; i < total; i++)