From 6ef866d1dc19be6c85f0b3fdbbd570a07f652d78 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sun, 28 Jun 2026 12:50:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B7=AF=E5=BE=84=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E4=BF=9D=E7=95=99=20lift=20=E9=81=BF=E5=85=8D=E7=89=A9?= =?UTF-8?q?=E4=BD=93=E6=B5=AE=E7=A9=BA=EF=BC=8C=E7=89=A9=E4=BD=93=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8C=E6=AD=A5=E4=BC=98=E5=85=88=E8=AF=BB=20AABB?= =?UTF-8?q?=20=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 路径切换问题: - 切换路径时 lift 被重置为 0,GetAnimatedObjectGroundContactHeight 用 correction 投影算出错误高度(~4.27m),物体浮空 - 改为保留 lift(离地高度不变),路径切换后物体保持正确位置 可视化宽度问题: - 路径切换后物体参数同步(SyncAnimationViewObjectParameters) 调用 TryGetCurrentRouteRealObjectPlanarProjectedExtents, 用 correction 投影算失真尺寸覆盖正确值 - 改为优先读 AnimationControlViewModel 的 _autoAabbSx 缓存 (由 MeasureXAlignedAabbAndSetCache 实测得到) - 新增 TryGetCachedAabbSizes 公开缓存给外部 --- .../ViewModels/AnimationControlViewModel.cs | 27 ++++++ src/UI/WPF/ViewModels/PathEditingViewModel.cs | 90 +++++++++++-------- 2 files changed, 80 insertions(+), 37 deletions(-) diff --git a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs index ec47b88..b31533f 100644 --- a/src/UI/WPF/ViewModels/AnimationControlViewModel.cs +++ b/src/UI/WPF/ViewModels/AnimationControlViewModel.cs @@ -619,7 +619,12 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 注意:只有路径真正改变时才移动(避免初始设置null时的不必要移动) if (value != null && oldRoute != value) { + // 保留 lift(物体姿态不变,离地高度保持不变)。 + // 保留 _autoAabbSx 缓存(物理尺寸与路径方向无关)。 + // 保留 _objectRotationCorrection(物体姿态不变)。 MoveAnimatedObjectToPathStart(); + // 用现有缓存刷新路径可视化和通行空间,不走 CalculateRotatedDimensions + UpdatePassageSpaceVisualization(); } } } @@ -2224,6 +2229,11 @@ namespace NavisworksTransport.UI.WPF.ViewModels { _pathAnimationManager?.ApplyObjectStartPlacementRequest(placementRequest); ObjectRotationCorrection = placementRequest.RotationCorrection; + // 手动改角度后实测AABB缓存,与自动调整/贴地一致 + var manualAdapter = CoordinateSystemManager.Instance.CreateHostAdapter(); + var manualDoc = Autodesk.Navisworks.Api.Application.ActiveDocument; + var manualItems = new ModelItemCollection { SelectedAnimatedObject }; + MeasureXAlignedAabbAndSetCache(SelectedAnimatedObject, manualItems, manualAdapter, manualDoc); } if (isAutoAdjusted) { @@ -5128,6 +5138,23 @@ namespace NavisworksTransport.UI.WPF.ViewModels return result; } + /// + /// 暴露实测 AABB 缓存给外部(如 PathEditingViewModel 的物体参数同步), + /// 避免它们走 correction 投影导致失真。 + /// + public bool TryGetCachedAabbSizes(out double forward, out double side, out double up) + { + if (_autoAabbSx.HasValue) + { + forward = _autoAabbSx.Value; + side = _autoAabbSz.Value; + up = _autoAabbSy.Value; + return true; + } + forward = side = up = 0; + return false; + } + /// /// 根据路径类型更新通行空间可视化 /// 空轨和吊装路径默认打开通行空间(物体通行空间模式),地面路径不打开 diff --git a/src/UI/WPF/ViewModels/PathEditingViewModel.cs b/src/UI/WPF/ViewModels/PathEditingViewModel.cs index 09aa62a..8e7fe0d 100644 --- a/src/UI/WPF/ViewModels/PathEditingViewModel.cs +++ b/src/UI/WPF/ViewModels/PathEditingViewModel.cs @@ -6364,48 +6364,64 @@ namespace NavisworksTransport.UI.WPF.ViewModels } else if (animationVm.SelectedAnimatedObject != null) { - var animationManager = NavisworksTransport.Core.Animation.PathAnimationManager.GetInstance(); - if ((pathType == PathType.Ground || pathType == PathType.Hoisting) && - animationManager != null && - animationManager.TryGetCurrentRouteRealObjectPlanarProjectedExtents( - out double resolvedPlanarForward, - out double resolvedPlanarSide, - out double resolvedPlanarUp)) + // 优先使用 AnimationControlViewModel 的实测 AABB 缓存 + // (贴合地面/自动调整后设置),避免 correction 投影失真 + if (animationVm.TryGetCachedAabbSizes(out double cachedFwd, out double cachedSide, out double cachedUp)) { - objectLengthModel = resolvedPlanarForward; - objectWidthModel = resolvedPlanarSide; - objectHeightModel = resolvedPlanarUp; + objectLengthModel = cachedFwd; + objectWidthModel = cachedSide; + objectHeightModel = cachedUp; LogManager.Debug( - $"[物体参数同步] 使用真实物体平面路径最终姿态尺寸: " + - $"沿路径={resolvedPlanarForward / metersToUnits:F2}m, " + - $"垂直路径={resolvedPlanarSide / metersToUnits:F2}m, " + - $"法线={resolvedPlanarUp / metersToUnits:F2}m"); - } - else if (pathType == PathType.Rail && - animationManager != null && - animationManager.TryGetCurrentRouteRealObjectRailProjectedExtents( - out double resolvedRailForward, - out double resolvedRailSide, - out double resolvedRailUp)) - { - objectLengthModel = resolvedRailForward; - objectWidthModel = resolvedRailSide; - objectHeightModel = resolvedRailUp; - LogManager.Debug( - $"[物体参数同步] 使用真实物体 Rail 最终姿态尺寸: " + - $"沿路径={resolvedRailForward / metersToUnits:F2}m, " + - $"垂直路径={resolvedRailSide / metersToUnits:F2}m, " + - $"法线={resolvedRailUp / metersToUnits:F2}m"); + $"[物体参数同步] 复用贴合地面/自动调整实测AABB: " + + $"沿路径={cachedFwd / metersToUnits:F2}m, " + + $"垂直路径={cachedSide / metersToUnits:F2}m, " + + $"法线={cachedUp / metersToUnits:F2}m"); } else { - // 回退:使用选择物体时保存的原始尺寸(米) - objectLengthModel = animationVm.ObjectOriginalLength * metersToUnits; - objectWidthModel = animationVm.ObjectOriginalWidth * metersToUnits; - objectHeightModel = animationVm.ObjectOriginalHeight * metersToUnits; - LogManager.Debug( - $"[物体参数同步] 回退使用选择物体保存的原始尺寸: " + - $"{animationVm.ObjectOriginalLength:F2}m x {animationVm.ObjectOriginalWidth:F2}m x {animationVm.ObjectOriginalHeight:F2}m"); + var animationManager = NavisworksTransport.Core.Animation.PathAnimationManager.GetInstance(); + if ((pathType == PathType.Ground || pathType == PathType.Hoisting) && + animationManager != null && + animationManager.TryGetCurrentRouteRealObjectPlanarProjectedExtents( + out double resolvedPlanarForward, + out double resolvedPlanarSide, + out double resolvedPlanarUp)) + { + objectLengthModel = resolvedPlanarForward; + objectWidthModel = resolvedPlanarSide; + objectHeightModel = resolvedPlanarUp; + LogManager.Debug( + $"[物体参数同步] 使用真实物体平面路径最终姿态尺寸: " + + $"沿路径={resolvedPlanarForward / metersToUnits:F2}m, " + + $"垂直路径={resolvedPlanarSide / metersToUnits:F2}m, " + + $"法线={resolvedPlanarUp / metersToUnits:F2}m"); + } + else if (pathType == PathType.Rail && + animationManager != null && + animationManager.TryGetCurrentRouteRealObjectRailProjectedExtents( + out double resolvedRailForward, + out double resolvedRailSide, + out double resolvedRailUp)) + { + objectLengthModel = resolvedRailForward; + objectWidthModel = resolvedRailSide; + objectHeightModel = resolvedRailUp; + LogManager.Debug( + $"[物体参数同步] 使用真实物体 Rail 最终姿态尺寸: " + + $"沿路径={resolvedRailForward / metersToUnits:F2}m, " + + $"垂直路径={resolvedRailSide / metersToUnits:F2}m, " + + $"法线={resolvedRailUp / metersToUnits:F2}m"); + } + else + { + // 回退:使用选择物体时保存的原始尺寸(米) + objectLengthModel = animationVm.ObjectOriginalLength * metersToUnits; + objectWidthModel = animationVm.ObjectOriginalWidth * metersToUnits; + objectHeightModel = animationVm.ObjectOriginalHeight * metersToUnits; + LogManager.Debug( + $"[物体参数同步] 回退使用选择物体保存的原始尺寸: " + + $"{animationVm.ObjectOriginalLength:F2}m x {animationVm.ObjectOriginalWidth:F2}m x {animationVm.ObjectOriginalHeight:F2}m"); + } } } else