File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ package mesh .util ;
2+
3+ import java .util .List ;
4+
5+ import math .Bounds ;
6+ import math .Vector3f ;
7+ import mesh .Mesh3D ;
8+
9+ public class MeshBoundsCalculator {
10+
11+ /**
12+ * Calculates the axis-aligned bounding box (AABB) for the given 3D mesh.
13+ *
14+ * @param mesh The mesh object whose bounding box needs to be calculated.
15+ * @return A {@link Bounds} object representing the calculated bounding box.
16+ */
17+ public static Bounds calculateBounds (Mesh3D mesh ) {
18+ List <Vector3f > vertices = mesh .getVertices ();
19+ if (vertices .isEmpty ()) {
20+ return new Bounds (Vector3f .ZERO , Vector3f .ZERO );
21+ }
22+
23+ Vector3f min = new Vector3f (vertices .get (0 ));
24+ Vector3f max = new Vector3f (vertices .get (0 ));
25+
26+ for (Vector3f vertex : vertices ) {
27+ min .set (
28+ Math .min (min .getX (), vertex .getX ()),
29+ Math .min (min .getY (), vertex .getY ()),
30+ Math .min (min .getZ (), vertex .getZ ()));
31+ max .set (
32+ Math .max (max .getX (), vertex .getX ()),
33+ Math .max (max .getY (), vertex .getY ()),
34+ Math .max (max .getZ (), vertex .getZ ()));
35+ }
36+
37+ return new Bounds (min , max );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments