Minor cleanup/refactor of EditMesh custom normals copy code.

Do not compute temp helper data when we do not need it (even though in
that case it was totally cheap to compute).
This commit is contained in:
Bastien Montagne
2019-03-19 11:10:30 +01:00
parent a73afc7eeb
commit d29dd5916f

View 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;