Kaynağa Gözat

Cleanup math and abstract mesh with rotation

Raanan Weber 9 yıl önce
ebeveyn
işleme
6e3630f65d

+ 2 - 39
src/Math/babylon.math.js

@@ -1,42 +1,7 @@
-var __extends = (this && this.__extends) || function (d, b) {
-    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
-    function __() { this.constructor = d; }
-    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
-};
 var BABYLON;
 (function (BABYLON) {
     BABYLON.ToGammaSpace = 1 / 2.2;
     BABYLON.ToLinearSpace = 2.2;
-    var ChangableMathObject = (function () {
-        function ChangableMathObject() {
-            this._onChangeTriggers = [];
-        }
-        ChangableMathObject.prototype.registerOnChange = function (func) {
-            if (!this._onChangeTriggers) {
-                this._onChangeTriggers = [];
-            }
-            this._onChangeTriggers.push(func);
-        };
-        ChangableMathObject.prototype.unregisterOnChange = function (func) {
-            var index = this._onChangeTriggers.indexOf(func);
-            if (index > -1) {
-                this._onChangeTriggers.splice(index, 1);
-            }
-            else {
-                BABYLON.Tools.Warn("Function to remove was not found");
-            }
-        };
-        ChangableMathObject.prototype.triggerChange = function () {
-            var _this = this;
-            if (this._onChangeTriggers) {
-                this._onChangeTriggers.forEach(function (func) {
-                    func(_this);
-                });
-            }
-        };
-        return ChangableMathObject;
-    }());
-    BABYLON.ChangableMathObject = ChangableMathObject;
     var Color3 = (function () {
         function Color3(r, g, b) {
             if (r === void 0) { r = 0; }
@@ -501,10 +466,8 @@ var BABYLON;
         return Vector2;
     }());
     BABYLON.Vector2 = Vector2;
-    var Vector3 = (function (_super) {
-        __extends(Vector3, _super);
+    var Vector3 = (function () {
         function Vector3(x, y, z) {
-            _super.call(this);
             this.x = x;
             this.y = y;
             this.z = z;
@@ -1000,7 +963,7 @@ var BABYLON;
             ref.z = roll;
         };
         return Vector3;
-    }(ChangableMathObject));
+    }());
     BABYLON.Vector3 = Vector3;
     //Vector4 class created for EulerAngle class conversion to Quaternion
     var Vector4 = (function () {

+ 2 - 32
src/Math/babylon.math.ts

@@ -5,36 +5,6 @@
     export const ToGammaSpace = 1 / 2.2;
     export const ToLinearSpace = 2.2;
 
-    export class ChangableMathObject {
-
-        private _onChangeTriggers: Array<(changedObject: ChangableMathObject) => void> = [];
-
-        public registerOnChange(func: (changedObject: ChangableMathObject) => void) {
-            if (!this._onChangeTriggers) {
-                this._onChangeTriggers = [];
-            }
-            this._onChangeTriggers.push(func);
-        }
-
-        public unregisterOnChange(func: (changedObject: ChangableMathObject) => void) {
-            var index = this._onChangeTriggers.indexOf(func);
-
-            if (index > -1) {
-                this._onChangeTriggers.splice(index, 1);
-            } else {
-                Tools.Warn("Function to remove was not found");
-            }
-        }
-
-        protected triggerChange() {
-            if (this._onChangeTriggers) {
-                this._onChangeTriggers.forEach((func) => {
-                    func(this);
-                })
-            }
-        }
-    }
-
     export class Color3 {
         constructor(public r: number = 0, public g: number = 0, public b: number = 0) {
         }
@@ -618,10 +588,10 @@
         }
     }
 
-    export class Vector3 extends ChangableMathObject {
+    export class Vector3 {
 
         constructor(public x: number, public y: number, public z: number) {
-            super();
+            
         }
 
         public toString(): string {

+ 5 - 11
src/Mesh/babylon.abstractMesh.js

@@ -144,22 +144,15 @@ var BABYLON;
             configurable: true
         });
         Object.defineProperty(AbstractMesh.prototype, "rotation", {
+            /**
+             * Getting the rotation object.
+             * If rotation quaternion is set, this vector will (almost always) be the Zero vector!
+             */
             get: function () {
-                if (this.rotationQuaternion) {
-                    BABYLON.Tools.Warn("Quaternion rotation is used, the rotation value is probably wrong");
-                }
                 return this._rotation;
             },
             set: function (newRotation) {
                 this._rotation = newRotation;
-                //check if rotationQuaternion exists, and if it does - update it!
-                if (this.rotationQuaternion) {
-                    var len = this._rotation.length();
-                    if (len) {
-                        this.rotationQuaternion.multiplyInPlace(BABYLON.Quaternion.RotationYawPitchRoll(this._rotation.y, this._rotation.x, this._rotation.z));
-                        this._rotation.copyFromFloats(0, 0, 0);
-                    }
-                }
             },
             enumerable: true,
             configurable: true
@@ -183,6 +176,7 @@ var BABYLON;
             },
             set: function (quaternion) {
                 this._rotationQuaternion = quaternion;
+                //reset the rotation vector. 
                 if (this.rotation.length()) {
                     this.rotation.copyFromFloats(0, 0, 0);
                 }

+ 8 - 12
src/Mesh/babylon.abstractMesh.ts

@@ -158,16 +158,12 @@
 
         /**
          * Getting the rotation object. 
-         * If rotation quaternion is set, the euler angels of the quaternion will be sent back.
-         * This is not 100% accurate. Avoid using rotation if the wuaternion is set.
+         * If rotation quaternion is set, this vector will (almost always) be the Zero vector!
          */
         public get rotation(): Vector3 {
-            if (this.rotationQuaternion) {
-                return this._rotationQuaternion.toEulerAngles();
-            }
             return this._rotation;
         }
-        
+
         public set rotation(newRotation: Vector3) {
             this._rotation = newRotation;
         }
@@ -178,20 +174,20 @@
 
         public set scaling(newScaling: Vector3) {
             this._scaling = newScaling;
-            if(this.physicImpostor) {
+            if (this.physicImpostor) {
                 this.physicImpostor.forceUpdate();
             }
         }
-        
+
         public get rotationQuaternion() {
             return this._rotationQuaternion;
         }
-        
+
         public set rotationQuaternion(quaternion: Quaternion) {
             this._rotationQuaternion = quaternion;
-            //reset the rotation vector.
-            if(this.rotation.length()) {
-                this.rotation.copyFromFloats(0,0,0);
+            //reset the rotation vector. 
+            if (this.rotation.length()) {
+                this.rotation.copyFromFloats(0, 0, 0);
             }
         }