From d5d50d75683eb3fcd80ed5425e20dc9aa172404d Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Mon, 26 Jan 2026 12:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=E5=92=8C=E6=8A=A5=E5=91=8A=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/BatchQueueManager.cs | 146 +++++++++++------- .../Collision/ClashDetectiveIntegration.cs | 2 +- 2 files changed, 87 insertions(+), 61 deletions(-) diff --git a/src/Core/BatchQueueManager.cs b/src/Core/BatchQueueManager.cs index 75cb028..026d54e 100644 --- a/src/Core/BatchQueueManager.cs +++ b/src/Core/BatchQueueManager.cs @@ -6,6 +6,7 @@ using Autodesk.Navisworks.Api; using NavisworksTransport.Core.Animation; using NavisworksTransport.Core.Collision; using NavisworksTransport.Core.Models; +using NavisworksTransport.Utils; namespace NavisworksTransport.Core { @@ -235,7 +236,7 @@ namespace NavisworksTransport.Core ClashDetectiveIntegration.InitializeCollisionDetectionCache(animatedObject); // 在主线程执行Navisworks API调用 - var frames = await UIStateManager.Instance.ExecuteUIUpdateAsync(() => + var result = await UIStateManager.Instance.ExecuteUIUpdateAsync(() => { // 预计算动画帧和碰撞 var config = new CollisionDetectionConfig @@ -250,7 +251,7 @@ namespace NavisworksTransport.Core ReportGenerationEnabled = true }; - return _executor._processor.PrecomputeFrames( + var frames = _executor._processor.PrecomputeFrames( pathRoute, animatedObject, isVirtualVehicle, @@ -262,65 +263,90 @@ namespace NavisworksTransport.Core config.DetectionToleranceMeters, null ); + + // 检查预计算是否成功 + if (frames == null || frames.Count == 0) + { + throw new InvalidOperationException("预计算动画帧失败:未生成任何帧"); + } + + // 提取碰撞结果 + var collisions = frames.SelectMany(f => f.Collisions).ToList(); + + // 创建并运行ClashDetective测试(直接在主线程执行,避免异步切换导致的Navisworks Native对象生命周期问题) + // 传入 pathPoints 参数,让 ClashDetective 测试完成后自动恢复到路径起点 + var pathPoints = pathRoute.Points.Select(p => p.Position).ToList(); + + var testName = _executor._processor.CreateAndRunClashDetectiveTest( + collisions, + item.DetectionToleranceMeters, + pathRoute.Name, + pathRoute.Id, + animatedObject, + isVirtualVehicle, + item.FrameRate, + item.DurationSeconds, + item.VirtualVehicleLength, + item.VirtualVehicleWidth, + item.VirtualVehicleHeight, + pathPoints + ); + + // 🔥 使用 ClashDetective 确认的碰撞数,而不是预计算的碰撞数 + item.CollisionCount = ClashDetectiveIntegration.Instance.ClashDetectiveCollisionCount; + + // 保存测试名称 + item.ClashDetectiveTestName = testName; + + // 🔥 高亮碰撞结果(用于批处理中的截图和报告生成) + if (!string.IsNullOrEmpty(testName)) + { + try + { + var clashIntegration = ClashDetectiveIntegration.Instance; + var clashResults = clashIntegration.GetCurrentPathClashResults(testName); + if (clashResults != null && clashResults.Count > 0) + { + ModelHighlightHelper.HighlightClashDetectiveResults(testName, clashIntegration.GetCurrentPathClashResults); + } + } + catch (Exception highlightEx) + { + LogManager.Error($"[批处理队列] 高亮碰撞结果失败: {highlightEx.Message}"); + } + } + + // 🔥 生成碰撞报告(包括截图) + if (!string.IsNullOrEmpty(testName)) + { + try + { + var reportCommand = new Commands.GenerateCollisionReportCommand(); + reportCommand.SetTestName(testName); + + // 同步执行报告生成(在UI线程中) + var reportTask = reportCommand.ExecuteAsync(); + reportTask.Wait(); // 等待报告生成完成 + } + catch (Exception reportEx) + { + LogManager.Error($"[批处理队列] 生成碰撞报告失败: {reportEx.Message}"); + // 报告生成失败不影响批处理流程 + } + } + + // 🔥 清除高亮(报告生成后) + try + { + ModelHighlightHelper.ClearClashDetectiveHighlights(); + } + catch (Exception clearEx) + { + LogManager.Error($"[批处理队列] 清除高亮失败: {clearEx.Message}"); + } + + return testName; }); - - // 检查预计算是否成功 - if (frames == null || frames.Count == 0) - { - throw new InvalidOperationException("预计算动画帧失败:未生成任何帧"); - } - - // 提取碰撞结果 - - var collisions = frames.SelectMany(f => f.Collisions).ToList(); - - - - // 创建并运行ClashDetective测试(直接在主线程执行,避免异步切换导致的Navisworks Native对象生命周期问题) - - // 传入 pathPoints 参数,让 ClashDetective 测试完成后自动恢复到路径起点 - - var pathPoints = pathRoute.Points.Select(p => p.Position).ToList(); - - var testName = _executor._processor.CreateAndRunClashDetectiveTest( - - collisions, - - item.DetectionToleranceMeters, - - pathRoute.Name, - - pathRoute.Id, - - animatedObject, - - isVirtualVehicle, - - item.FrameRate, - - item.DurationSeconds, - - item.VirtualVehicleLength, - - item.VirtualVehicleWidth, - - item.VirtualVehicleHeight, - - pathPoints - - ); - - - - // 🔥 使用 ClashDetective 确认的碰撞数,而不是预计算的碰撞数 - - item.CollisionCount = ClashDetectiveIntegration.Instance.ClashDetectiveCollisionCount; - - - - // 保存测试名称 - - item.ClashDetectiveTestName = testName; // 标记为完成 item.Status = BatchQueueStatus.Completed; diff --git a/src/Core/Collision/ClashDetectiveIntegration.cs b/src/Core/Collision/ClashDetectiveIntegration.cs index c018fa5..68a38bd 100644 --- a/src/Core/Collision/ClashDetectiveIntegration.cs +++ b/src/Core/Collision/ClashDetectiveIntegration.cs @@ -1419,7 +1419,7 @@ namespace NavisworksTransport } } -/// + /// /// 清除所有缓存,在模型变化时调用 /// public static void ClearAllCaches()