[Bf-blender-cvs] [ce34f9348fa] blender2.8: MESH_OT_select_axis: Make it work with world axis, not local ones

Dalai Felinto noreply at git.blender.org
Fri Aug 24 16:34:39 CEST 2018


Commit: ce34f9348fa35a66a1ffebdaef6e007c5e39eb25
Author: Dalai Felinto
Date:   Thu Aug 23 18:23:51 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBce34f9348fa35a66a1ffebdaef6e007c5e39eb25

MESH_OT_select_axis: Make it work with world axis, not local ones

Not, I tried using `dist_signed_squared_to_plane_v3` but profiling showed that
it is 50% slower than using regular `mul_v3_m4v3` for the verts.

I managed to get this number closer when manually inlining all the functions
called by `dist_signed_squared_to_plane_v3`. But still `mul_v3_m4v3` was better
and it makes the code simpler to understand.

Also I'm changing the default mode to positive, no idea why it was negative as
default in the first place.

Last but not least, the operator only works well on redo. This was a problem
before, not introduced by this patch.

===================================================================

M	source/blender/editors/mesh/editmesh_select.c

===================================================================

diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index fdf6ac5685f..4da25be5e95 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -4360,29 +4360,39 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op)
 		BMVert *v;
 		BMIter iter;
 		const float limit = RNA_float_get(op->ptr, "threshold");
-		float value = v_act->co[axis];
+
+		float value;
+		float vertex_world[3];
+
+		mul_v3_m4v3(vertex_world, obedit->obmat, v_act->co);
+		value = vertex_world[axis];
 
 		if (mode == SELECT_AXIS_NEGATIVE) {
-			value -= limit;
+			value += limit;
 		}
 		else if (mode == SELECT_AXIS_POSITIVE) {
-			value += limit;
+			value -= limit;
 		}
 
 		BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
 			if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
+				float v_iter_world[3];
+				mul_v3_m4v3(v_iter_world, obedit->obmat, v->co);
 				switch (mode) {
 					case SELECT_AXIS_ALIGNED:
-						if (fabsf(v->co[axis] - value) < limit)
+						if (fabsf(v_iter_world[axis] - value) < limit) {
 							BM_vert_select_set(bm, v, true);
+						}
 						break;
 					case SELECT_AXIS_NEGATIVE:
-						if (v->co[axis] > value)
+						if (v_iter_world[axis] < value) {
 							BM_vert_select_set(bm, v, true);
+						}
 						break;
 					case SELECT_AXIS_POSITIVE:
-						if (v->co[axis] < value)
+						if (v_iter_world[axis] > value) {
 							BM_vert_select_set(bm, v, true);
+						}
 						break;
 				}
 			}
@@ -4424,7 +4434,7 @@ void MESH_OT_select_axis(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 	/* properties */
-	RNA_def_enum(ot->srna, "mode", axis_mode_items, SELECT_AXIS_NEGATIVE, "Axis Mode", "Axis side to use when selecting");
+	RNA_def_enum(ot->srna, "mode", axis_mode_items, SELECT_AXIS_POSITIVE, "Axis Mode", "Axis side to use when selecting");
 	RNA_def_enum(ot->srna, "axis", axis_items_xyz, SELECT_AXIS_X, "Axis", "Select the axis to compare each vertex on");
 	RNA_def_float(ot->srna, "threshold", 0.0001f, 0.000001f, 50.0f,  "Threshold", "", 0.00001f, 10.0f);
 }



More information about the Bf-blender-cvs mailing list