const vertices = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
let vectorExtreme = null;
let length = 0;
for(let i = 0; i < vertices.length; i += 3) {
let vertex = BABYLON.Vector3.FromArray(vertices, i);
let vector = BABYLON.Vector3.TransformCoordinates(vertex, this.hexagon.mesh.getWorldMatrix());
if(!i) vectorExtreme = vector;
vector.z = 0;
if(vector.length() > length && vector.x > 0) {
length = vector.length();
vectorExtreme = vector;
}
}
const vector1 = new BABYLON.Vector3(vectorExtreme.x, vectorExtreme.y, 0);
const vector2 = new BABYLON.Vector3(1,0,0);
let angle = Math.acos(BABYLON.Vector3.Dot(vector1, vector2) /
(vector1.length() * vector2.length()));
if(vectorExtreme.y > 0) {
angle = -angle;
}
mesh.rotate(BABYLON.Axis.Z, angle, BABYLON.Space.WORLD);