diff --git a/src/Core/Animation/PathAnimationManager.cs b/src/Core/Animation/PathAnimationManager.cs index 5ee1e45..91c1027 100644 --- a/src/Core/Animation/PathAnimationManager.cs +++ b/src/Core/Animation/PathAnimationManager.cs @@ -112,9 +112,9 @@ namespace NavisworksTransport.Core.Animation private DateTime _animationStartTime; private int _animationFrameRate = 30; // 动画帧率(默认30FPS) private int _animationFrameCount = 0; // 动画帧计数 - private double _collisionDetectionAccuracy = 0.1; // 检测精度(默认0.1米) - private double _movementSpeed = 1.0; // 运动速度(默认1米/秒) - private double _detectionGap = 0.05; // 检测间隙(默认0.05米) + private double _collisionDetectionAccuracy = 0.1; // 检测精度(内部存储:模型单位/帧,初始值按米算需转换) + private double _movementSpeed = 1.0; // 运动速度(仅用于显示,单位:米/秒) + private double _detectionGap = 0.05; // 检测间隙(内部存储:模型单位,初始值按米算需转换) private string _pathName = "未知路径"; // 路径名称 private string _currentRouteId = null; // 当前路由ID private string _animatedObjectName = null; // 动画对象名称 @@ -278,8 +278,9 @@ namespace NavisworksTransport.Core.Animation LogManager.Info($"路径起点: ({_pathPoints[0].X:F2},{_pathPoints[0].Y:F2},{_pathPoints[0].Z:F2})"); LogManager.Info($"路径终点: ({_pathPoints[_pathPoints.Count-1].X:F2},{_pathPoints[_pathPoints.Count-1].Y:F2},{_pathPoints[_pathPoints.Count-1].Z:F2})"); - var totalDist = CalculateTotalPathDistance(); - LogManager.Info($"路径总长度: {totalDist:F2}"); + var totalDistInModelUnits = CalculateTotalPathDistance(); + var totalDistInMeters = UnitsConverter.ConvertToMeters(totalDistInModelUnits); + LogManager.Info($"路径总长度: {totalDistInMeters:F2}米 ({totalDistInModelUnits:F2}模型单位)"); LogManager.Info($"车辆已移动到路径起点,动画将从起点开始"); LogManager.Info($"=== 调试信息结束 ==="); } @@ -350,15 +351,18 @@ namespace NavisworksTransport.Core.Animation int totalFrames = (int)(_animationDuration * _animationFrameRate); // 反向计算检测精度(确保每帧都检测) - var totalDistance = CalculateTotalPathDistance(); - _collisionDetectionAccuracy = totalDistance / totalFrames; - + var totalDistanceInModelUnits = CalculateTotalPathDistance(); + _collisionDetectionAccuracy = totalDistanceInModelUnits / totalFrames; + + var totalDistanceInMeters = UnitsConverter.ConvertToMeters(totalDistanceInModelUnits); + var detectionAccuracyInMeters = UnitsConverter.ConvertToMeters(_collisionDetectionAccuracy); + LogManager.Info($"=== 预计算动画帧 ==="); LogManager.Info($"动画时长: {_animationDuration}秒"); LogManager.Info($"动画帧率: {_animationFrameRate} FPS"); LogManager.Info($"总帧数: {totalFrames}"); - LogManager.Info($"路径总长: {totalDistance:F2}米"); - LogManager.Info($"检测精度: {_collisionDetectionAccuracy:F3}米/帧"); + LogManager.Info($"路径总长: {totalDistanceInMeters:F2}米 ({totalDistanceInModelUnits:F2}模型单位)"); + LogManager.Info($"检测精度: {detectionAccuracyInMeters:F3}米/帧 ({_collisionDetectionAccuracy:F3}模型单位/帧)"); // 初始化帧列表 _animationFrames = new List(); @@ -1910,12 +1914,14 @@ namespace NavisworksTransport.Core.Animation } /// - /// 设置碰撞检测精度 + /// 设置碰撞检测精度(参数单位:米) /// - public void SetCollisionDetectionAccuracy(double accuracy) + public void SetCollisionDetectionAccuracy(double accuracyInMeters) { - _collisionDetectionAccuracy = Math.Max(0.01, accuracy); // 最小0.01米 - LogManager.Info($"碰撞检测精度设置为: {_collisionDetectionAccuracy}m"); + // 转换为模型单位存储 + var accuracyInModelUnits = UnitsConverter.ConvertFromMeters(Math.Max(0.01, accuracyInMeters)); + _collisionDetectionAccuracy = accuracyInModelUnits; + LogManager.Info($"碰撞检测精度设置为: {accuracyInMeters:F3}米 ({accuracyInModelUnits:F3}模型单位)"); } /// @@ -1928,16 +1934,19 @@ namespace NavisworksTransport.Core.Animation } /// - /// 设置检测间隙 + /// 设置检测间隙(参数单位:米) /// - public void SetDetectionGap(double gap) + public void SetDetectionGap(double gapInMeters) { - var roundedGap = Math.Round(Math.Max(0.0, gap), 2); + // 转换为模型单位存储 + var gapInModelUnits = UnitsConverter.ConvertFromMeters(Math.Max(0.0, gapInMeters)); + var roundedGapInModelUnits = Math.Round(gapInModelUnits, 4); // 模型单位保留更多精度 + // 只在值真正改变时才更新和记录日志 - if (Math.Abs(_detectionGap - roundedGap) > 0.001) + if (Math.Abs(_detectionGap - roundedGapInModelUnits) > 0.0001) { - _detectionGap = roundedGap; - LogManager.Info($"间隙={_detectionGap:F2}m"); + _detectionGap = roundedGapInModelUnits; + LogManager.Info($"检测间隙设置为: {gapInMeters:F2}米 ({_detectionGap:F4}模型单位)"); } }