Browse Source

address comments

Trevor Baron 6 năm trước cách đây
mục cha
commit
c3b3fd30ec

+ 1 - 1
src/Behaviors/Mesh/babylon.sixDofDragBehavior.ts

@@ -210,7 +210,7 @@ module BABYLON {
                         var oldParent = pickedMesh.parent;
 
                         // Only rotate the mesh if it's parent has uniform scaling
-                        if (!oldParent || ((oldParent as Mesh).scaling && !BoundingBoxGizmo._isNonUniform((oldParent as Mesh).scaling))) {
+                        if (!oldParent || ((oldParent as Mesh).scaling && !(oldParent as Mesh).scaling.isNonUniformWithinEpsilon(0.001))) {
                             pickedMesh.setParent(null);
                             Quaternion.SlerpToRef(pickedMesh.rotationQuaternion!, tmpQuaternion, this.dragDeltaRatio, pickedMesh.rotationQuaternion!);
                             pickedMesh.setParent(oldParent);

+ 2 - 26
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -106,30 +106,6 @@ module BABYLON {
         }
 
         /**
-         * @hidden
-         * Due to float precisiion, scale of a mesh may be uniform but float values are off by a small fraction
-         * Check if uniform within 3 decimal places to account for this
-         */
-        public static _isNonUniform(vec: Vector3) {
-            let absX = Math.abs(Math.round(vec.x * 1000) / 1000);
-            let absY = Math.abs(Math.round(vec.y * 1000) / 1000);
-            if (absX !== absY) {
-                return true;
-            }
-
-            let absZ = Math.abs(Math.round(vec.z * 1000) / 1000);
-            if (absX !== absZ) {
-                return true;
-            }
-
-            if (absY !== absZ) {
-                return true;
-            }
-
-            return false;
-        }
-
-        /**
          * Creates an BoundingBoxGizmo
          * @param gizmoLayer The utility layer the gizmo will be added to
          * @param color The color of the gizmo
@@ -196,7 +172,7 @@ module BABYLON {
                     this.onRotationSphereDragObservable.notifyObservers({});
                     if (this.attachedMesh) {
                         var originalParent = this.attachedMesh.parent;
-                        if (originalParent && ((originalParent as Mesh).scaling && BoundingBoxGizmo._isNonUniform((originalParent as Mesh).scaling))) {
+                        if (originalParent && ((originalParent as Mesh).scaling && (originalParent as Mesh).scaling.isNonUniformWithinEpsilon(0.001))) {
                             Tools.Warn("BoundingBoxGizmo controls are not supported on child meshes with non-uniform parent scaling");
                             return;
                         }
@@ -279,7 +255,7 @@ module BABYLON {
                             this.onScaleBoxDragObservable.notifyObservers({});
                             if (this.attachedMesh) {
                                 var originalParent = this.attachedMesh.parent;
-                                if (originalParent && ((originalParent as Mesh).scaling && BoundingBoxGizmo._isNonUniform((originalParent as Mesh).scaling))) {
+                                if (originalParent && ((originalParent as Mesh).scaling && (originalParent as Mesh).scaling.isNonUniformWithinEpsilon(0.001))) {
                                     Tools.Warn("BoundingBoxGizmo controls are not supported on child meshes with non-uniform parent scaling");
                                     return;
                                 }

+ 25 - 0
src/Math/babylon.math.ts

@@ -1926,6 +1926,31 @@ module BABYLON {
         }
 
         /**
+         * Due to float precision, scale of a mesh could be uniform but float values are off by a small fraction
+         * Check if is non uniform within a certain amount of decimal places to account for this
+         * @param epsilon the amount the values can differ
+         * @returns if the the vector is non uniform to a certain number of decimal places
+         */
+        public isNonUniformWithinEpsilon(epsilon:number) {
+            let absX = Math.abs(this.x);
+            let absY = Math.abs(this.y);
+            if (!Scalar.WithinEpsilon(absX, absY, epsilon)) {
+                return true;
+            }
+
+            let absZ = Math.abs(this.z);
+            if (!Scalar.WithinEpsilon(absX, absZ, epsilon)) {
+                return true;
+            }
+
+            if (!Scalar.WithinEpsilon(absY, absZ, epsilon)) {
+                return true;
+            }
+
+            return false;
+        }
+
+        /**
          * Gets a boolean indicating that the vector is non uniform meaning x, y or z are not all the same
          */
         public get isNonUniform(): boolean {