remove pose fallbacks and fix script compatibility
This commit is contained in:
parent
5a03c3aa6c
commit
a252dad46a
@ -1,3 +1,11 @@
|
||||
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Path,
|
||||
|
||||
[switch]$Recurse
|
||||
)
|
||||
|
||||
<#
|
||||
用法示例
|
||||
|
||||
@ -18,13 +26,6 @@ powershell -ExecutionPolicy Bypass -File "C:\Users\Tellme\apps\NavisworksTranspo
|
||||
- 原文件会被直接覆盖,同时自动保留一个同名 .bak 备份文件
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Path,
|
||||
|
||||
[switch]$Recurse
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
@ -130,7 +131,7 @@ function Update-XmlFile {
|
||||
)
|
||||
|
||||
[xml]$xml = Get-Content -LiteralPath $FilePath -Raw
|
||||
$routeNodes = $xml.SelectNodes("//*[local-name()='Route']")
|
||||
$routeNodes = @($xml.SelectNodes("//*[local-name()='Route']"))
|
||||
if ($null -eq $routeNodes -or $routeNodes.Count -eq 0) {
|
||||
return [pscustomobject]@{
|
||||
FilePath = $FilePath
|
||||
@ -148,11 +149,13 @@ function Update-XmlFile {
|
||||
|
||||
if ($modifiedRouteCount -gt 0) {
|
||||
$backupPath = "$FilePath.bak"
|
||||
if (-not (Test-Path -LiteralPath $backupPath)) {
|
||||
Copy-Item -LiteralPath $FilePath -Destination $backupPath
|
||||
}
|
||||
if ($PSCmdlet.ShouldProcess($FilePath, "修复 railPreferredNormal 并写回 XML")) {
|
||||
if (-not (Test-Path -LiteralPath $backupPath)) {
|
||||
Copy-Item -LiteralPath $FilePath -Destination $backupPath
|
||||
}
|
||||
|
||||
Save-XmlDocument -Document $xml -TargetPath $FilePath
|
||||
Save-XmlDocument -Document $xml -TargetPath $FilePath
|
||||
}
|
||||
}
|
||||
|
||||
return [pscustomobject]@{
|
||||
@ -175,7 +178,7 @@ if ($item.PSIsContainer) {
|
||||
$childParams["Recurse"] = $true
|
||||
}
|
||||
|
||||
$files = Get-ChildItem @childParams | Where-Object { $_.Extension -ieq ".xml" }
|
||||
$files = @(Get-ChildItem @childParams | Where-Object { $_.Extension -ieq ".xml" })
|
||||
}
|
||||
else {
|
||||
$files = @($item)
|
||||
@ -191,6 +194,7 @@ foreach ($file in $files) {
|
||||
$results += Update-XmlFile -FilePath $file.FullName
|
||||
}
|
||||
|
||||
$results = @($results)
|
||||
$modifiedFiles = @($results | Where-Object { $_.Modified })
|
||||
$modifiedRoutes = 0
|
||||
if ($modifiedFiles.Count -gt 0) {
|
||||
|
||||
@ -5280,21 +5280,19 @@ namespace NavisworksTransport.Core.Animation
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
if (_route?.PathType == PathType.Ground)
|
||||
{
|
||||
if (_route?.PathType != PathType.Ground &&
|
||||
TryCaptureRealObjectReferenceRotation(_animatedObject, out referenceRotation))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryCaptureFallbackRealObjectReferenceRotation(_animatedObject, out referenceRotation);
|
||||
}
|
||||
catch (Exception ex)
|
||||
if (!TryCaptureRealObjectReferenceRotation(_animatedObject, out referenceRotation))
|
||||
{
|
||||
LogManager.Warning($"[真实物体参考姿态] 读取 fragment 参考位姿失败,改用默认姿态: {ex.Message}");
|
||||
return TryCaptureFallbackRealObjectReferenceRotation(_animatedObject, out referenceRotation);
|
||||
string objectName = _animatedObject?.DisplayName ?? "未知对象";
|
||||
LogManager.Error($"[真实物体参考姿态] {objectName} 无法获取 fragment 参考姿态,已禁止回退默认姿态。");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryCaptureRealObjectReferenceRotation(ModelItem sourceObject, out Quaternion referenceRotation)
|
||||
@ -5349,78 +5347,6 @@ namespace NavisworksTransport.Core.Animation
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryCaptureFallbackRealObjectReferenceRotation(ModelItem sourceObject, out Quaternion referenceRotation)
|
||||
{
|
||||
referenceRotation = Quaternion.Identity;
|
||||
|
||||
if (sourceObject == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Rotation3D fallbackRotation3D = Rotation3D.Identity;
|
||||
if (!ModelItemTransformHelper.TryGetCurrentGeometryRotation(sourceObject, out fallbackRotation3D))
|
||||
{
|
||||
fallbackRotation3D = sourceObject.Transform?.Factor().Rotation ?? Rotation3D.Identity;
|
||||
}
|
||||
|
||||
referenceRotation = new Quaternion(
|
||||
(float)fallbackRotation3D.A,
|
||||
(float)fallbackRotation3D.B,
|
||||
(float)fallbackRotation3D.C,
|
||||
(float)fallbackRotation3D.D);
|
||||
|
||||
if (referenceRotation.LengthSquared() < 1e-6f)
|
||||
{
|
||||
referenceRotation = Quaternion.Identity;
|
||||
}
|
||||
else
|
||||
{
|
||||
referenceRotation = Quaternion.Normalize(referenceRotation);
|
||||
}
|
||||
|
||||
_realObjectReferenceRotation = referenceRotation;
|
||||
_realObjectReferenceAxisX = Vector3.Normalize(Vector3.Transform(Vector3.UnitX, referenceRotation));
|
||||
_realObjectReferenceAxisY = Vector3.Normalize(Vector3.Transform(Vector3.UnitY, referenceRotation));
|
||||
_realObjectReferenceAxisZ = Vector3.Normalize(Vector3.Transform(Vector3.UnitZ, referenceRotation));
|
||||
_realObjectReferenceHostWorldXAxisLocalAxis = LocalAxisDirection.PositiveX;
|
||||
_realObjectReferenceHostWorldYAxisLocalAxis = LocalAxisDirection.PositiveY;
|
||||
_realObjectReferenceHostWorldZAxisLocalAxis = LocalAxisDirection.PositiveZ;
|
||||
_realObjectReferenceHostSemanticXAxisLocalAxis = LocalAxisDirection.PositiveX;
|
||||
|
||||
var adapter = CoordinateSystemManager.Instance.CreateHostAdapter();
|
||||
if (adapter.HostType == CoordinateSystemType.YUp)
|
||||
{
|
||||
_realObjectReferenceHostSemanticYAxisLocalAxis = LocalAxisDirection.PositiveY;
|
||||
_realObjectReferenceHostSemanticZAxisLocalAxis = LocalAxisDirection.PositiveZ;
|
||||
_realObjectReferenceHostUpLocalAxis = LocalAxisDirection.PositiveY;
|
||||
}
|
||||
else
|
||||
{
|
||||
_realObjectReferenceHostSemanticYAxisLocalAxis = LocalAxisDirection.PositiveY;
|
||||
_realObjectReferenceHostSemanticZAxisLocalAxis = LocalAxisDirection.PositiveZ;
|
||||
_realObjectReferenceHostUpLocalAxis = LocalAxisDirection.PositiveZ;
|
||||
}
|
||||
|
||||
_hasRealObjectReferenceRotation = true;
|
||||
|
||||
LogManager.Warning(
|
||||
$"[真实物体参考姿态] {sourceObject.DisplayName} 已改用非 fragment 参考姿态继续业务流程: " +
|
||||
$"FallbackX=({_realObjectReferenceAxisX.X:F4},{_realObjectReferenceAxisX.Y:F4},{_realObjectReferenceAxisX.Z:F4}), " +
|
||||
$"FallbackY=({_realObjectReferenceAxisY.X:F4},{_realObjectReferenceAxisY.Y:F4},{_realObjectReferenceAxisY.Z:F4}), " +
|
||||
$"FallbackZ=({_realObjectReferenceAxisZ.X:F4},{_realObjectReferenceAxisZ.Y:F4},{_realObjectReferenceAxisZ.Z:F4}), " +
|
||||
$"宿主Up对应本地轴={_realObjectReferenceHostUpLocalAxis}");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[真实物体参考姿态] {sourceObject.DisplayName} 默认参考姿态回退失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncTrackedRotationToObjectReference(ModelItem sourceObject, bool isVirtualObject)
|
||||
{
|
||||
if (sourceObject == null)
|
||||
@ -5472,9 +5398,8 @@ namespace NavisworksTransport.Core.Animation
|
||||
return;
|
||||
}
|
||||
|
||||
_currentYaw = ModelItemTransformHelper.GetYawFromTransform(sourceObject.Transform);
|
||||
_trackedRotation = sourceObject.Transform.Factor().Rotation;
|
||||
_hasTrackedRotation = true;
|
||||
throw new InvalidOperationException(
|
||||
$"[真实物体参考姿态] {sourceObject.DisplayName} 无法同步参考姿态:未能读取当前实际几何姿态,fragment 代表姿态也不可用,已禁止回退 Transform。");
|
||||
}
|
||||
|
||||
private static Rotation3D CreateVirtualObjectReferenceRotation()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user