feat: 贴合地面加入路径yaw补偿,物体旋转后长边对齐路径方向

This commit is contained in:
tian 2026-06-09 11:37:03 +08:00
parent 63b59890e4
commit 82caa3e155

View File

@ -2299,6 +2299,34 @@ namespace NavisworksTransport.UI.WPF.ViewModels
else if (d < -0.9999f) overrideQ = Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)Math.PI);
else overrideQ = Quaternion.CreateFromAxisAngle(Vector3.Normalize(Vector3.Cross(cadWorldN, t)), (float)Math.Acos(d));
// 路径 yaw 补偿
var routePoints = CurrentPathRoute?.Points;
if ((CurrentPathRoute?.PathType == PathType.Ground || CurrentPathRoute?.PathType == PathType.Hoisting)
&& routePoints != null && routePoints.Count >= 2)
{
// 照抄 TryResolveStartPathDirection 的取点方式
var start = routePoints[0];
var startVector = new Vector3((float)start.X, (float)start.Y, (float)start.Z);
Vector3 hostForward = Vector3.Zero;
for (int i = 1; i < routePoints.Count; i++)
{
var point = routePoints[i];
var candidate = new Vector3((float)point.X, (float)point.Y, (float)point.Z) - startVector;
if (candidate.LengthSquared() > 1e-8f)
{
hostForward = candidate;
break;
}
}
if (hostForward.LengthSquared() > 1e-8f
&& PathTargetFrameResolver.TryResolvePlanarHostYaw(
hostForward, CoordinateSystemManager.Instance.ResolvedType, out double yawRadians))
{
overrideQ = Quaternion.Normalize(
Quaternion.CreateFromAxisAngle(adapter.HostUpVector3, (float)yawRadians) * overrideQ);
}
}
var center = item.BoundingBox().Center;
var tp = new Vector3((float)center.X, (float)center.Y, (float)center.Z);
var rtp = Vector3.Transform(tp, overrideQ);