From 0a82343bd88f688718d154f1030367b95e1beb44 Mon Sep 17 00:00:00 2001 From: Vegard Stengrundet Date: Tue, 5 Nov 2024 09:41:26 +0100 Subject: [PATCH] Bugfix: Floor missing, wrong bounding boxes (#250) * Recalculate AABB * Don't recalculate if there are no vertices --- CadRevealRvmProvider/Tessellation/RvmTessellator.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CadRevealRvmProvider/Tessellation/RvmTessellator.cs b/CadRevealRvmProvider/Tessellation/RvmTessellator.cs index 0a1d0f5f..3445af5a 100644 --- a/CadRevealRvmProvider/Tessellation/RvmTessellator.cs +++ b/CadRevealRvmProvider/Tessellation/RvmTessellator.cs @@ -40,7 +40,15 @@ TessellationLogObject tessellationLogObject tessellationLogObject ); - return new TriangleMesh(mesh, p.TreeIndex, p.Color, p.AxisAlignedBoundingBox); + var boundingBox = p.AxisAlignedBoundingBox; + if (mesh.Vertices.Length > 0) + { + // Recalculating AABB, since some instances of the transformed (p.AxisAlignedBoundingBox) AABB were incorrect + // Guarded agaings meshes with zero vertices, to avoid throwing an exception + boundingBox = mesh.CalculateAxisAlignedBoundingBox(); + } + + return new TriangleMesh(mesh, p.TreeIndex, p.Color, boundingBox); } var facetGroupsNotInstanced = facetGroupInstancingResult @@ -109,7 +117,7 @@ TessellationLogObject tessellationLogObject item.Transform, item.ProtoMesh.TreeIndex, item.ProtoMesh.Color, - item.ProtoMesh.AxisAlignedBoundingBox + group.Mesh.CalculateAxisAlignedBoundingBox(item.Transform) // Recalculating AABB, since some instances of the transformed (item.ProtoMesh.AxisAlignedBoundingBox) AABB were incorrect )) ) .ToArray();