Fix normal transform orientation calculation
authorCampbell Barton <ideasman42@gmail.com>
Fri, 7 Sep 2018 01:24:37 +0000 (11:24 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 7 Sep 2018 01:25:54 +0000 (11:25 +1000)
When using the 'normal' orientation, the normal would be ignored
if the plane couldn't be calculated.

Now use only the normal if the plane is zero length,
this was already done, just not in all cases.

source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_orientations.c

index 5f7388045791e537ecb17b667b0d6390cc3d24df..d53f51f5076667488186d5a100fa9418171ea4f4 100644 (file)
@@ -796,6 +796,8 @@ bool applyTransformOrientation(const struct bContext *C, float mat[3][3], char r
 #define ORIENTATION_VERT       2
 #define ORIENTATION_EDGE       3
 #define ORIENTATION_FACE       4
+#define ORIENTATION_USE_PLANE(ty) \
+       ELEM(ty, ORIENTATION_NORMAL, ORIENTATION_EDGE, ORIENTATION_FACE)
 
 int getTransformOrientation_ex(const struct bContext *C, float normal[3], float plane[3], const short around);
 int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3]);
index c38fb15fc894a6d3c0a264ae1def78951d538bbb..1c5a6eabd6f2386c1aa30cddfa78abb9d2df0050 100644 (file)
@@ -796,12 +796,7 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3
                                                }
                                        }
 
-                                       if (is_zero_v3(plane)) {
-                                               result = ORIENTATION_VERT;
-                                       }
-                                       else {
-                                               result = ORIENTATION_EDGE;
-                                       }
+                                       result = ORIENTATION_EDGE;
                                }
                                else if (em->bm->totvertsel > 3) {
                                        BMIter iter;
@@ -1104,6 +1099,11 @@ void ED_getTransformOrientationMatrix(const bContext *C, float orientation_mat[3
 
        type = getTransformOrientation_ex(C, normal, plane, around);
 
+       /* Fallback, when the plane can't be calculated. */
+       if (ORIENTATION_USE_PLANE(type) && is_zero_v3(plane)) {
+               type = ORIENTATION_VERT;
+       }
+
        switch (type) {
                case ORIENTATION_NORMAL:
                        if (createSpaceNormalTangent(orientation_mat, normal, plane) == 0) {