Minor cleanup/refactor of EditMesh custom normals copy code.
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 19 Mar 2019 10:10:30 +0000 (11:10 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 19 Mar 2019 11:31:50 +0000 (12:31 +0100)
Do not compute temp helper data when we do not need it (even though in
that case it was totally cheap to compute).

source/blender/editors/mesh/editmesh_tools.c

index 9a58608..5b2cb97 100644 (file)
@@ -8000,16 +8000,10 @@ static int edbm_normals_tools_exec(bContext *C, wmOperator *op)
        switch (mode) {
                case EDBM_CLNOR_TOOLS_COPY:
                        if (bm->totfacesel != 1 && lnors_ed_arr->totloop != 1 && bm->totvertsel != 1) {
-                               BKE_report(op->reports, RPT_ERROR, "Can only copy custom normal, vertex normal or face normal");
+                               BKE_report(op->reports, RPT_ERROR, "Can only copy one custom normal, vertex normal or face normal");
                                BM_loop_normal_editdata_array_free(lnors_ed_arr);
                                return OPERATOR_CANCELLED;
                        }
-                       bool join = true;
-                       for (int i = 0; i < lnors_ed_arr->totloop; i++, lnor_ed++) {
-                               if (!compare_v3v3(lnors_ed_arr->lnor_editdata->nloc, lnor_ed->nloc, 1e-4f)) {
-                                       join = false;
-                               }
-                       }
                        if (lnors_ed_arr->totloop == 1) {
                                copy_v3_v3(scene->toolsettings->normal_vector, lnors_ed_arr->lnor_editdata->nloc);
                        }
@@ -8022,8 +8016,18 @@ static int edbm_normals_tools_exec(bContext *C, wmOperator *op)
                                        }
                                }
                        }
-                       else if (join) {
-                               copy_v3_v3(scene->toolsettings->normal_vector, lnors_ed_arr->lnor_editdata->nloc);
+                       else {
+                               /* 'Vertex' normal, i.e. common set of loop normals on the same vertex,
+                                * only if they are all the same. */
+                               bool are_same_lnors = true;
+                               for (int i = 0; i < lnors_ed_arr->totloop; i++, lnor_ed++) {
+                                       if (!compare_v3v3(lnors_ed_arr->lnor_editdata->nloc, lnor_ed->nloc, 1e-4f)) {
+                                               are_same_lnors = false;
+                                       }
+                               }
+                               if (are_same_lnors) {
+                                       copy_v3_v3(scene->toolsettings->normal_vector, lnors_ed_arr->lnor_editdata->nloc);
+                               }
                        }
                        break;