Browse Source

Changed as requested by deltakosh

Left old functions with a comment (and a console.warn) on them to tag them as deprecated.
Gwenaël Hagenmuller 11 years ago
parent
commit
423b20cc0a
1 changed files with 25 additions and 1 deletions
  1. 25 1
      Babylon/Mesh/babylon.mesh.js

+ 25 - 1
Babylon/Mesh/babylon.mesh.js

@@ -303,7 +303,10 @@ var BABYLON = BABYLON || {};
         if (this.parent && this.parent.getWorldMatrix && this.billboardMode === BABYLON.Mesh.BILLBOARDMODE_NONE) {
             this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
         } else {
-            this._worldMatrix = this._localWorld;
+            // multiplyToRef instead of this._worldMatrix = this._localWorld;
+            // to be sure not to have a bug with a call to this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+            // Moreover multiplyToRef is more efficient than clone
+            this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._worldMatrix);
         }
 
         // Bounding info
@@ -533,6 +536,27 @@ var BABYLON = BABYLON || {};
     };
 
     // Geometry
+    // deprecated: use setPositionWithLocalVector instead. It fixes setLocalTranslation.
+    BABYLON.Mesh.prototype.setLocalTranslation = function(vector3) {
+        console.warn("deprecated: use setPositionWithLocalVector instead");
+        this.computeWorldMatrix();
+        var worldMatrix = this._worldMatrix.clone();
+        worldMatrix.setTranslation(BABYLON.Vector3.Zero());
+
+        this.position = BABYLON.Vector3.TransformCoordinates(vector3, worldMatrix);
+    };
+    
+    // deprecated: use getPositionExpressedInLocalSpace instead. It fixes getLocalTranslation.
+    BABYLON.Mesh.prototype.getLocalTranslation = function () {
+        console.warn("deprecated: use getPositionExpressedInLocalSpace instead");
+        this.computeWorldMatrix();
+        var invWorldMatrix = this._worldMatrix.clone();
+        invWorldMatrix.setTranslation(BABYLON.Vector3.Zero());
+        invWorldMatrix.invert();
+
+        return BABYLON.Vector3.TransformCoordinates(this.position, invWorldMatrix);
+    };
+    
     BABYLON.Mesh.prototype.setPositionWithLocalVector = function(vector3) {
         this.computeWorldMatrix();