Add bounding box calculator.
This commit is contained in:
parent
4ee5eb6040
commit
39ecb7af61
@ -25,3 +25,29 @@ OV.Box3D = class
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
OV.BoundingBoxCalculator3D = class
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.box = new OV.Box3D (
|
||||
new OV.Coord3D (Infinity, Infinity, Infinity),
|
||||
new OV.Coord3D (-Infinity, -Infinity, -Infinity)
|
||||
);
|
||||
}
|
||||
|
||||
GetBox ()
|
||||
{
|
||||
return this.box;
|
||||
}
|
||||
|
||||
AddPoint (point)
|
||||
{
|
||||
this.box.min.x = Math.min (this.box.min.x, point.x);
|
||||
this.box.min.y = Math.min (this.box.min.y, point.y);
|
||||
this.box.min.z = Math.min (this.box.min.z, point.z);
|
||||
this.box.max.x = Math.max (this.box.max.x, point.x);
|
||||
this.box.max.y = Math.max (this.box.max.y, point.y);
|
||||
this.box.max.z = Math.max (this.box.max.z, point.z);
|
||||
}
|
||||
};
|
||||
|
||||
@ -205,20 +205,10 @@ OV.EnumerateModelTrianglesWithNormals = function (model, onTriangle)
|
||||
|
||||
OV.GetMeshBoundingBox = function (mesh)
|
||||
{
|
||||
let box = new OV.Box3D (
|
||||
new OV.Coord3D (Infinity, Infinity, Infinity),
|
||||
new OV.Coord3D (-Infinity, -Infinity, -Infinity)
|
||||
);
|
||||
|
||||
let calculator = new OV.BoundingBoxCalculator3D ();
|
||||
for (let i = 0; i < mesh.VertexCount (); i++) {
|
||||
let vertex = mesh.GetVertex (i);
|
||||
box.min.x = Math.min (box.min.x, vertex.x);
|
||||
box.min.y = Math.min (box.min.y, vertex.y);
|
||||
box.min.z = Math.min (box.min.z, vertex.z);
|
||||
box.max.x = Math.max (box.max.x, vertex.x);
|
||||
box.max.y = Math.max (box.max.y, vertex.y);
|
||||
box.max.z = Math.max (box.max.z, vertex.z);
|
||||
calculator.AddPoint (vertex);
|
||||
}
|
||||
|
||||
return box;
|
||||
return calculator.GetBox ();
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user