From 5ee74f39d83d68d2ea2c2f7992565430288ea4fb Mon Sep 17 00:00:00 2001 From: ww-rm Date: Wed, 26 Mar 2025 13:07:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=90=E4=B8=AA=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=97=B6=E4=BD=BF=E7=94=A8=E8=87=AA=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExportArgs/VideoExportArgs.cs | 19 ++++++++++++++++--- .../Implementations/Exporter/VideoExporter.cs | 10 ++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/SpineViewer/Exporter/Implementations/ExportArgs/VideoExportArgs.cs b/SpineViewer/Exporter/Implementations/ExportArgs/VideoExportArgs.cs index dc6aa49..78c2d43 100644 --- a/SpineViewer/Exporter/Implementations/ExportArgs/VideoExportArgs.cs +++ b/SpineViewer/Exporter/Implementations/ExportArgs/VideoExportArgs.cs @@ -17,14 +17,27 @@ namespace SpineViewer.Exporter.Implementations.ExportArgs /// /// 导出时长 /// - [Category("视频参数"), DisplayName("时长"), Description("可以从模型列表查看动画时长")] - public float Duration { get => duration; set => duration = Math.Max(0, value); } - private float duration = 1; + [Category("视频参数"), DisplayName("时长"), Description("可以从模型列表查看动画时长, 如果小于 0, 则在逐个导出时每个模型使用各自的当前动画时长")] + public float Duration + { + get => duration; + set => duration = value < 0 ? -1 : value; + } + private float duration = -1; /// /// 帧率 /// [Category("视频参数"), DisplayName("帧率"), Description("每秒画面数")] 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; + } } } diff --git a/SpineViewer/Exporter/Implementations/Exporter/VideoExporter.cs b/SpineViewer/Exporter/Implementations/Exporter/VideoExporter.cs index 1f730fc..7dbc742 100644 --- a/SpineViewer/Exporter/Implementations/Exporter/VideoExporter.cs +++ b/SpineViewer/Exporter/Implementations/Exporter/VideoExporter.cs @@ -22,8 +22,13 @@ namespace SpineViewer.Exporter.Implementations.Exporter protected IEnumerable GetFrames(Spine.Spine spine, BackgroundWorker? worker = null) { var args = (VideoExportArgs)ExportArgs; + + // 独立导出时如果 args.Duration 小于 0 则使用自己的动画时长 + var duration = args.Duration; + if (duration < 0) duration = spine.GetAnimationDuration(spine.CurrentAnimation); + 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} 帧"); for (int i = 0; i < total; i++) @@ -46,9 +51,10 @@ namespace SpineViewer.Exporter.Implementations.Exporter /// protected IEnumerable GetFrames(Spine.Spine[] spinesToRender, BackgroundWorker? worker = null) { + // 导出单个时必须根据 args.Duration 决定导出时长 var args = (VideoExportArgs)ExportArgs; 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} 帧"); for (int i = 0; i < total; i++)