matrix.decompose

by Julien Gobin

HTML

<script src="https://rawgithub.com/BabylonJS/Babylon.js/master/babylon.1.8.5.js"></script>
<div id="rootDiv">
  <canvas id="renderCanvas"></canvas>
</div>

CSS

html, body, div, canvas {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

JavaScript

// Vector3 ///////////////////////////////////////////////////
/*/
BABYLON.Vector3.prototype._isLeftHand = true;

BABYLON.Vector3.prototype.toLeftHand() = function()
{
    if(this._isLeftHand)
        return this.clone();
    
    var vect = new BABYLON.Vector3(this.x, this.y, -this.z);
    
    vect._isLeftHand = false; 
    
    return vect;
}

BABYLON.Vector3.prototype.toRightHand() = function()
{
    if(!this._isLeftHand)
        return this.clone();    

    return new BABYLON.Vector3();
}
//*/
// Quaternion ////////////////////////////////////////////////
//*/
/*/BABYLON.Quaternion.RotationYawPitchRollToRef = function (yaw, pitch, roll, result) {
    // assuming yaw, pitch, roll is right hand expressed in radians.
    
    var halfRoll = roll * 0.5;
    var halfPitch = pitch * 0.5;
    var halfYaw = yaw * 0.5;
    
    var sinRoll = Math.sin(halfRoll);
    var cosRoll = Math.cos(halfRoll);
    var sinPitch = Math.sin(halfPitch);
    var cosPitch = Math.cos(halfPitch);
    var sinYaw = Math.sin(halfYaw);
    var cosYaw = Math.cos(halfYaw);
    
    result.x = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);
    result.y = (sinYaw * cosPitch * cosRoll) + (cosYaw * sinPitch * sinRoll);
    result.z = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);
    result.w = (cosYaw * cosPitch * cosRoll) - (sinYaw * sinPitch * sinRoll);
};
//*/
BABYLON.Quaternion.prototype.toEulerAngles = function () {
/*/
	var gimbaLockTest = this.x*this.y + this.z*this.w;
    var vector = new BABYLON.Vector3(0,0,0);
    
	if (gimbaLockTest > 0.499) { // singularity at north pole
		vector.y = 2 * Math.atan2(this.x, this.w);
		vector.x = Math.PI/2;
		vector.z = 0;
        
        return vector;
	}
	if (gimbaLockTest < -0.499) { // singularity at south pole
		vector.y = -2 * Math.atan2(this.x, this.w);
		vector.x = - Math.PI/2;
		vector.z = 0;
        
        return vector;
	}
    
    var sqx = this.x*this.x;
    var sqy = this.y*this.y;
    var sqz =...