From 54655254b9d0036d87db416e20f0b28b0b282c14 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 27 Jan 2025 18:07:59 +0000 Subject: [PATCH] Use faster plane distance calculation --- KeepersCompound.Lightmapper/PotentiallyVisibleSet.cs | 4 ++-- KeepersCompound.Lightmapper/Utils.cs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/KeepersCompound.Lightmapper/PotentiallyVisibleSet.cs b/KeepersCompound.Lightmapper/PotentiallyVisibleSet.cs index 514530d..5ea39a4 100644 --- a/KeepersCompound.Lightmapper/PotentiallyVisibleSet.cs +++ b/KeepersCompound.Lightmapper/PotentiallyVisibleSet.cs @@ -163,7 +163,7 @@ public class PotentiallyVisibleSet var validTarget = false; foreach (var v in target.Poly.Vertices) { - if (MathUtils.DistanceFromPlane(sourcePlane, v) < -MathUtils.Epsilon) + if (MathUtils.DistanceFromNormalizedPlane(sourcePlane, v) < -MathUtils.Epsilon) { validTarget = true; break; @@ -178,7 +178,7 @@ public class PotentiallyVisibleSet validTarget = false; foreach (var v in source.Poly.Vertices) { - if (MathUtils.DistanceFromPlane(targetPlane, v) > MathUtils.Epsilon) + if (MathUtils.DistanceFromNormalizedPlane(targetPlane, v) > MathUtils.Epsilon) { validTarget = true; break; diff --git a/KeepersCompound.Lightmapper/Utils.cs b/KeepersCompound.Lightmapper/Utils.cs index c3b8e29..5739aad 100644 --- a/KeepersCompound.Lightmapper/Utils.cs +++ b/KeepersCompound.Lightmapper/Utils.cs @@ -93,6 +93,11 @@ public static class MathUtils return (Vector3.Dot(plane.Normal, point) + plane.D) / plane.Normal.Length(); } + public static float DistanceFromNormalizedPlane(Plane plane, Vector3 point) + { + return Vector3.Dot(plane.Normal, point) + plane.D; + } + public static bool IsCoplanar(Plane p0, Plane p1) { var m = p0.D / p1.D;