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++)