From 1d55ae54409e189ea1ecbbc657e9bf1c4d4ffa16 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Tue, 24 Dec 2024 02:09:44 +0200 Subject: [PATCH] refactor GetRelativeTransform(...) (#2140) * rename ancestorNode * convert to for loop --- .../OpenAssetImporter.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Xna.Framework.Content.Pipeline.Graphics/OpenAssetImporter.cs b/src/Xna.Framework.Content.Pipeline.Graphics/OpenAssetImporter.cs index 360f0eca342..0befb4cce25 100644 --- a/src/Xna.Framework.Content.Pipeline.Graphics/OpenAssetImporter.cs +++ b/src/Xna.Framework.Content.Pipeline.Graphics/OpenAssetImporter.cs @@ -954,27 +954,29 @@ private static void GetSubtree(Node aiNode, List list) /// Gets the transform of node relative to a specific ancestor node. /// /// The node. - /// The ancestor node. Can be . + /// The ancestor node. Can be . /// - /// The relative transform. If is the + /// The relative transform. If is the /// absolute transform of is returned. /// - private static Matrix4x4 GetRelativeTransform(Node node, Node ancestor) + private static Matrix4x4 GetRelativeTransform(Node node, Node ancestorNode) { Debug.Assert(node != null); // Get transform of node relative to ancestor. Matrix4x4 transform = node.Transform; - Node parent = node.Parent; - while (parent != null && parent != ancestor) + for (Node parent = node.Parent; parent != ancestorNode; parent = parent.Parent) { + if (parent == null) + { + if (ancestorNode != null) + throw new ArgumentException(String.Format("Node \"{0}\" is not an ancestor of \"{1}\".", ancestorNode.Name, node.Name)); + break; + } + transform = transform * parent.Transform; - parent = parent.Parent; } - if (parent == null && ancestor != null) - throw new ArgumentException(String.Format("Node \"{0}\" is not an ancestor of \"{1}\".", ancestor.Name, node.Name)); - return transform; }