BabylonJS - setLocalTranslation

by gwenaelhagenmuller

HTML

<script src="https://rawgithub.com/BabylonJS/Babylon.js/v1.8.0/babylon.1.8.0.js"></script>
<button id="setLocalTranslation">setLocalTranslation</button>
<button id="setLocalTranslationModified">setLocalTranslationModified</button>
<canvas id="renderCanvas"></canvas>

CSS

#renderCanvas {
    width: 100%;
    height: 100%;
    min-height: 100%;
}

JavaScript

var cube;
var child;

var setLocalTranslation = BABYLON.Mesh.prototype.setLocalTranslation;
var computeWorldMatrix = BABYLON.Mesh.prototype.computeWorldMatrix;

var i = 0;
var modified;

var pleaseReload = function(shouldBe) {
    if (modified === undefined) return;
    if (modified !== shouldBe) alert("Please press run again before using the other button.");
};

document.getElementById("setLocalTranslation").onclick = function() {
    pleaseReload(false);
    BABYLON.Mesh.prototype.setLocalTranslation = setLocalTranslation;
    BABYLON.Mesh.prototype.computeWorldMatrix = computeWorldMatrix;
    child.setLocalTranslation(new BABYLON.Vector3(0.0, 0.0, ++i * -0.1));
    modified = false;
};

document.getElementById("setLocalTranslationModified").onclick = function() {
    pleaseReload(true);
    BABYLON.Mesh.prototype.setLocalTranslation = setLocalTranslationModified;
    BABYLON.Mesh.prototype.computeWorldMatrix = computeWorldMatrixModified;
    child.setLocalTranslation(new BABYLON.Vector3(0.0, 0.0, ++i * -0.1));
    modified = true;
};

var computeWorldMatrixModified = function (force) {
    if (this._currentRenderId == this._scene.getRenderId() || !force && this.isSynchronized()) {
        this._childrenFlag = false;
        return this._worldMatrix;
    }
    
    this._childrenFlag = true;
    this._cache.infiniteDistance = this.infiniteDistance;
    this._cache.position.copyFrom(this.position);
    this._cache.scaling.copyFrom(this.scaling);
    this._cache.pivotMatrixUpdated = false;
    this._currentRenderId = this._scene.getRenderId();
    
    // Scaling
    BABYLON.Matrix.ScalingToRef(this.scaling.x, this.scaling.y, this.scaling.z, this._localScaling);
    
    // Rotation
    if (this.rotationQuaternion) {
        this.rotationQuaternion.toRotationMatrix(this._localRotation);
        this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
    } else {
        BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x,...