BabylonJS - common pivot

by gwenaelhagenmuller

HTML

<script src="https://rawgithub.com/BabylonJS/Babylon.js/v1.8.5/babylon.1.8.5.js"></script>
<button id="translate">Translate common pivot</button>
<button id="rotate">Rotate common pivot</button>
<div id="rootDiv">
  <canvas id="renderCanvas"></canvas>
  <canvas id="canvas_2D"></canvas>
</div>

CSS

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

button {height: 20px}

#canvas_2D {
    position: absolute;   
    top: 20px;
    pointer-events: none;
}

JavaScript

/// BABYLON.CommonPivot ; need to be improved for sure this it doesn't take
/// into account parents of its meshes
(function () {
    
    BABYLON.CommonPivot = function () {
    };
    
    BABYLON.CommonPivot.prototype._meshes = [];
    BABYLON.CommonPivot.prototype._position = BABYLON.Vector3.Zero();
    BABYLON.CommonPivot.prototype._rotation = BABYLON.Vector3.Zero();
    BABYLON.CommonPivot.prototype._scaling = new BABYLON.Vector3(1, 1, 1);
    
    BABYLON.CommonPivot.prototype.add = function (m, pivotMatrix) {
        this._meshes.push(m);
        m.position.x = this._position.x;
        m.position.y = this._position.y;
        m.position.z = this._position.z;
        m.rotation.x = this._rotation.x;
        m.rotation.y = this._rotation.y;
        m.rotation.z = this._rotation.z;
        m.scaling.x = this._scaling.x;
        m.scaling.y = this._scaling.y;
        m.scaling.z = this._scaling.z;
        m.setPivotMatrix(pivotMatrix);
    };

    BABYLON.CommonPivot.prototype.positionX = function (x) {
        for (var i in this._meshes) {
            this._meshes[i].position.x = x;
        }
        this._position.x = x;
    };
    
    BABYLON.CommonPivot.prototype.positionY = function (y) {
        for (var i in this._meshes) {
            this._meshes[i].position.y = y;
        }
        this._position.y = y;
    };
    
    BABYLON.CommonPivot.prototype.positionZ = function (z) {
        for (var i in this._meshes) {
            this._meshes[i].position.z = z;
        }
        this._position.z = z;
    };
    
    BABYLON.CommonPivot.prototype.rotationX = function (x) {
        for (var i in this._meshes) {
            this._meshes[i].rotation.x = x;
        }
        this._rotation.x = x;
    };
    
    BABYLON.CommonPivot.prototype.rotationY = function (y) {
        for (var i in this._meshes) {
            this._meshes[i].rotation.y = y;
        }
        this._rotation.y = y;
    };
    
    BABYLON.CommonPivot.prototype.rotationZ = function (z)...