From 1b074b43893c351e577c005d7ab68ca1d1dd5b64 Mon Sep 17 00:00:00 2001 From: Colton Fox <46362482+coltfox@users.noreply.github.com> Date: Fri, 28 Jul 2023 12:55:26 -0400 Subject: [PATCH] Correctly calculate BVH item extents --- CodeWalker.Core/GameFiles/Resources/Bounds.cs | 13 ++----------- CodeWalker.Core/Utils/Vectors.cs | 5 +++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CodeWalker.Core/GameFiles/Resources/Bounds.cs b/CodeWalker.Core/GameFiles/Resources/Bounds.cs index b5fd18f..ecb70c2 100644 --- a/CodeWalker.Core/GameFiles/Resources/Bounds.cs +++ b/CodeWalker.Core/GameFiles/Resources/Bounds.cs @@ -2779,7 +2779,7 @@ namespace CodeWalker.GameFiles if (child != null) { var cbox = new BoundingBox(child.BoxMin, child.BoxMax); - var tcbox = cbox.Transform(child.Position, child.Orientation, child.Scale); + var tcbox = cbox.Transform(child.Transform); var it = new BVHBuilderItem(); it.Min = tcbox.Minimum; it.Max = tcbox.Maximum; @@ -2793,16 +2793,7 @@ namespace CodeWalker.GameFiles } } - var bvh = BVHBuilder.Build(items, 1); //composites have BVH item threshold of 1 - - BoxMin = bvh.BoundingBoxMin.XYZ(); - BoxMax = bvh.BoundingBoxMax.XYZ(); - BoxCenter = bvh.BoundingBoxCenter.XYZ(); - SphereCenter = BoxCenter; - SphereRadius = (BoxMax - BoxCenter).Length(); - - BVH = bvh; - + BVH = BVHBuilder.Build(items, 1); //composites have BVH item threshold of 1 } public void UpdateChildrenFlags() diff --git a/CodeWalker.Core/Utils/Vectors.cs b/CodeWalker.Core/Utils/Vectors.cs index 0327f6b..301ee4e 100644 --- a/CodeWalker.Core/Utils/Vectors.cs +++ b/CodeWalker.Core/Utils/Vectors.cs @@ -127,6 +127,11 @@ namespace CodeWalker public static BoundingBox Transform(this BoundingBox b, Vector3 position, Quaternion orientation, Vector3 scale) { var mat = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, scale, Vector3.Zero, orientation, position); + return b.Transform(mat); + } + + public static BoundingBox Transform(this BoundingBox b, Matrix mat) + { var matabs = mat; matabs.Column1 = mat.Column1.Abs(); matabs.Column2 = mat.Column2.Abs();