__getYfromXBezier (x, points) {
for (let i = 0; i < points.length - 1; i++) {
if (points[i].x <= x && x <= points[i + 1].x) {
const deltaX = x - points[i].x;
let k = ((points[i+1].y - points[i].y) / (points[i+1].x - points[i].x));
return deltaX * k + points[i].y;
}
}
}
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);
<html>
<body>
<form name="nameForm">
<input type="text" name="nameInput" onfocus="this.value = this.value"/>
<button value="submit" type="submit">Send</button>
</form>
<script>
(function () {
var el = document.getElementsByName('nameInput')[0];
var frm = document.forms['nameForm'];
if (el.addEventListener) {
el.addEventListener("input", callbackInput, false);
} else if (el.attachEvent) {
el.attachEvent('onpropertychange', callbackInput);
}
if (frm.addEventListener) {
frm.addEventListener("submit", callbackForm, false);
} else if (frm.attachEvent) {
frm.attachEvent('onsubmit', callbackForm);
}
function callbackInput(e) {
var valueOriginal = (e.propertyName === 'value') ? e.srcElement.value : this.value;
var valueWithoutSpaces = valueOriginal.replace(/\D/g, '');
var length = valueWithoutSpaces.length;
var valueWithSpaces = valueWithoutSpaces.substr(0, length < 4 ? length : 4)
+ ((length > 4) ? ' ' + valueWithoutSpaces.substr(4, length < 9 ? length - 4 : 4) : '')
+ ((length > 8) ? ' ' + valueWithoutSpaces.substr(8, length < 12 ? length - 8 : 4) : '')
+ ((length > 12) ? ' ' + valueWithoutSpaces.substr(12, length < 16 ? length - 12 : 4) : '');
if (e.propertyName === 'value' && e.srcElement.value != valueWithSpaces) {
var input = e.srcElement;
input.value = valueWithSpaces;
input.blur();
input.focus();
}
else {
this.value = valueWithSpaces;
}
}
function callbackForm(e) {
if (el.detachEvent) {
el.detachEvent('onpropertychange', callbackInput);
} else {
el.removeEventListener('input', callbackInput, true);
}
el.value = el.value.replace(/\D/g, '');
}
}())
</script>
</body>
</html>