@@ -361,21 +361,24 @@ public static void MapMeshGridBuffer(RenderingBufferStorage buffer, Mesh mesh, d
361361 /// using its associated transformation matrix before being processed.</param>
362362 public static void MapBoundingBoxSurfaceBuffer ( RenderingBufferStorage buffer , BoundingBoxXYZ box )
363363 {
364- var minPoint = box . Transform . OfPoint ( box . Min ) ;
365- var maxPoint = box . Transform . OfPoint ( box . Max ) ;
366-
367- XYZ [ ] corners =
364+ // Generate 8 corners in LOCAL coordinate system first
365+ XYZ [ ] localCorners =
368366 [
369- new ( minPoint . X , minPoint . Y , minPoint . Z ) ,
370- new ( maxPoint . X , minPoint . Y , minPoint . Z ) ,
371- new ( maxPoint . X , maxPoint . Y , minPoint . Z ) ,
372- new ( minPoint . X , maxPoint . Y , minPoint . Z ) ,
373- new ( minPoint . X , minPoint . Y , maxPoint . Z ) ,
374- new ( maxPoint . X , minPoint . Y , maxPoint . Z ) ,
375- new ( maxPoint . X , maxPoint . Y , maxPoint . Z ) ,
376- new ( minPoint . X , maxPoint . Y , maxPoint . Z )
367+ new ( box . Min . X , box . Min . Y , box . Min . Z ) , // 0: min corner
368+ new ( box . Max . X , box . Min . Y , box . Min . Z ) , // 1
369+ new ( box . Max . X , box . Max . Y , box . Min . Z ) , // 2
370+ new ( box . Min . X , box . Max . Y , box . Min . Z ) , // 3
371+ new ( box . Min . X , box . Min . Y , box . Max . Z ) , // 4
372+ new ( box . Max . X , box . Min . Y , box . Max . Z ) , // 5
373+ new ( box . Max . X , box . Max . Y , box . Max . Z ) , // 6: max corner
374+ new ( box . Min . X , box . Max . Y , box . Max . Z ) // 7
377375 ] ;
378376
377+ // Transform each corner individually to world coordinates
378+ XYZ [ ] corners = localCorners
379+ . Select ( corner => box . Transform . OfPoint ( corner ) )
380+ . ToArray ( ) ;
381+
379382 int [ ] triangles =
380383 [
381384 0 , 1 , 2 , 2 , 3 , 0 , // bottom face
@@ -431,21 +434,24 @@ public static void MapBoundingBoxSurfaceBuffer(RenderingBufferStorage buffer, Bo
431434 /// vertex positions.</param>
432435 public static void MapBoundingBoxEdgeBuffer ( RenderingBufferStorage buffer , BoundingBoxXYZ box )
433436 {
434- var minPoint = box . Transform . OfPoint ( box . Min ) ;
435- var maxPoint = box . Transform . OfPoint ( box . Max ) ;
436-
437- XYZ [ ] corners =
437+ // Generate 8 corners in LOCAL coordinate system first
438+ XYZ [ ] localCorners =
438439 [
439- new ( minPoint . X , minPoint . Y , minPoint . Z ) ,
440- new ( maxPoint . X , minPoint . Y , minPoint . Z ) ,
441- new ( maxPoint . X , maxPoint . Y , minPoint . Z ) ,
442- new ( minPoint . X , maxPoint . Y , minPoint . Z ) ,
443- new ( minPoint . X , minPoint . Y , maxPoint . Z ) ,
444- new ( maxPoint . X , minPoint . Y , maxPoint . Z ) ,
445- new ( maxPoint . X , maxPoint . Y , maxPoint . Z ) ,
446- new ( minPoint . X , maxPoint . Y , maxPoint . Z )
440+ new ( box . Min . X , box . Min . Y , box . Min . Z ) , // 0: min corner
441+ new ( box . Max . X , box . Min . Y , box . Min . Z ) , // 1
442+ new ( box . Max . X , box . Max . Y , box . Min . Z ) , // 2
443+ new ( box . Min . X , box . Max . Y , box . Min . Z ) , // 3
444+ new ( box . Min . X , box . Min . Y , box . Max . Z ) , // 4
445+ new ( box . Max . X , box . Min . Y , box . Max . Z ) , // 5
446+ new ( box . Max . X , box . Max . Y , box . Max . Z ) , // 6: max corner
447+ new ( box . Min . X , box . Max . Y , box . Max . Z ) // 7
447448 ] ;
448449
450+ // Transform each corner individually to world coordinates
451+ var corners = localCorners
452+ . Select ( corner => box . Transform . OfPoint ( corner ) )
453+ . ToArray ( ) ;
454+
449455 int [ ] edges =
450456 [
451457 0 , 1 , 1 , 2 , 2 , 3 , 3 , 0 , // bottom face
0 commit comments