Quellcode durchsuchen

BABYLON.Mesh.prototype.{s,g}etLocalTranslation

Fixed BABYLON.Mesh.prototype.{s,g}etLocalTranslation to take into account the parent.
Renamed BABYLON.Mesh.prototype.{s,g}etLocalTranslation respectively by BABYLON.Mesh.prototype.setPositionWithLocalVector and BABYLON.Mesh.prototype.getPositionExpressedInLocalSpace
Added BABYLON.Mesh.prototype.locallyTranslate

BABYLON.Mesh.prototype.locallyTranslate adds the passed vector3 (expressed in local space; the origin of vector3 is the origin of the local space) after conversion to the parent space to the position (expressed in parent space)
whereas BABYLON.Mesh.prototype.setPositionWithLocalVector sets the position (expressed in parent space) to the passed vector3 (expressed in local space but which the origin is the origin of the parent space) once it has been converted.

The following code for BABYLON.Mesh.prototype.setPositionWithLocalVector could also be used. It explains itself the relation between setPositionWithLocalVector and locallyTranslate.

BABYLON.Mesh.prototype.setPositionWithLocalVector = function(vector3) {
    this.position = BABYLON.Vector3.Zero();
    this.locallyTranslate(vector3);
};
Gwenaël Hagenmuller vor 11 Jahren
Ursprung
Commit
be3128afd8
1 geänderte Dateien mit 18 neuen und 15 gelöschten Zeilen
  1. 18 15
      Babylon/Mesh/babylon.mesh.js

+ 18 - 15
Babylon/Mesh/babylon.mesh.js

@@ -295,15 +295,15 @@ var BABYLON = BABYLON || {};
             this._localPivotScalingRotation.multiplyToRef(this._localBillboard, this._localWorld);
             this._rotateYByPI.multiplyToRef(this._localWorld, this._localPivotScalingRotation);
         }
+        
+        // Local world
+        this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._localWorld);
 
         // Parent
         if (this.parent && this.parent.getWorldMatrix && this.billboardMode === BABYLON.Mesh.BILLBOARDMODE_NONE) {
-            this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._localWorld);
-            var parentWorld = this.parent.getWorldMatrix();
-
-            this._localWorld.multiplyToRef(parentWorld, this._worldMatrix);
+            this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
         } else {
-            this._localPivotScalingRotation.multiplyToRef(this._localTranslation, this._worldMatrix);
+            this._worldMatrix = this._localWorld;
         }
 
         // Bounding info
@@ -533,21 +533,24 @@ var BABYLON = BABYLON || {};
     };
 
     // Geometry
-    BABYLON.Mesh.prototype.setLocalTranslation = function(vector3) {
+    BABYLON.Mesh.prototype.setPositionWithLocalVector = function(vector3) {
+        this.computeWorldMatrix();
+        
+        this.position = BABYLON.Vector3.TransformNormal(vector3, this._localWorld);
+    };
+
+    BABYLON.Mesh.prototype.getPositionExpressedInLocalSpace = function () {
         this.computeWorldMatrix();
-        var worldMatrix = this._worldMatrix.clone();
-        worldMatrix.setTranslation(BABYLON.Vector3.Zero());
+        var invLocalWorldMatrix = this._localWorld.clone();
+        invLocalWorldMatrix.invert();
 
-        this.position = BABYLON.Vector3.TransformCoordinates(vector3, worldMatrix);
+        return BABYLON.Vector3.TransformNormal(this.position, invLocalWorldMatrix);
     };
     
-    BABYLON.Mesh.prototype.getLocalTranslation = function () {
+    BABYLON.Mesh.prototype.locallyTranslate = function(vector3) {
         this.computeWorldMatrix();
-        var invWorldMatrix = this._worldMatrix.clone();
-        invWorldMatrix.setTranslation(BABYLON.Vector3.Zero());
-        invWorldMatrix.invert();
-
-        return BABYLON.Vector3.TransformCoordinates(this.position, invWorldMatrix);
+        
+        this.position = BABYLON.Vector3.TransformCoordinates(vector3, this._localWorld);
     };
 
     BABYLON.Mesh.prototype.bakeTransformIntoVertices = function (transform) {