[Bf-blender-cvs] [db5bacb9882] temp-select-axis: MESH_OT_select_axis: Different approach to world fix, use planes
Dalai Felinto
noreply at git.blender.org
Fri Aug 24 00:41:07 CEST 2018
Commit: db5bacb988268e2dcd312b4537904bc4ef493622
Author: Dalai Felinto
Date: Thu Aug 23 19:39:20 2018 -0300
Branches: temp-select-axis
https://developer.blender.org/rBdb5bacb988268e2dcd312b4537904bc4ef493622
MESH_OT_select_axis: Different approach to world fix, use planes
This is supposed to be faster than multiplying each vertex by the object matrix. That said
it is not working at the moment.
===================================================================
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 80fac887ac3..2ffbe49a538 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -4351,6 +4351,14 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op)
BMVert *v_act = BM_mesh_active_vert_get(bm);
const int axis = RNA_enum_get(op->ptr, "axis");
const int mode = RNA_enum_get(op->ptr, "mode");
+ const float normal_lookup[6][3] = {
+ { 1.0f, 0.0f, 0.0f}, /* +X */
+ { 0.0f, 1.0f, 0.0f}, /* +Y */
+ { 0.0f, 0.0f, 1.0f}, /* +Z */
+ {-1.0f, 0.0f, 0.0f}, /* -X */
+ { 0.0f,-1.0f, 0.0f}, /* -Y */
+ { 0.0f, 0.0f,-1.0f}, /* -Z */
+ };
if (v_act == NULL) {
BKE_report(op->reports, RPT_WARNING, "This operator requires an active vertex (last selected)");
@@ -4360,37 +4368,51 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op)
BMVert *v;
BMIter iter;
const float limit = RNA_float_get(op->ptr, "threshold");
+ const float limit_squared = limit * limit;
- float value;
- float vertex_world[3];
+ float plane_normal[3];
+ float plane_coord[3];
+ float plane[4];
- mul_v3_m4v3(vertex_world, obedit->obmat, v_act->co);
- value = vertex_world[axis];
+ mul_v3_m4v3(plane_coord, obedit->obmat, v_act->co);
if (mode == SELECT_AXIS_NEGATIVE) {
- value -= limit;
+ plane_coord[axis] -= limit;
+ copy_v3_v3(plane_normal, normal_lookup[axis + 3]);
}
else if (mode == SELECT_AXIS_POSITIVE) {
- value += limit;
+ plane_coord[axis] += limit;
+ copy_v3_v3(plane_normal, normal_lookup[axis]);
+ }
+ else {
+ copy_v3_v3(plane_normal, normal_lookup[axis]);
}
+ /* Convert plane to object space. */
+ float imat[4][4];
+
+ invert_m4_m4(imat, obedit->obmat);
+ mul_m4_v3(imat, plane_coord);
+ mul_transposed_mat3_m4_v3(obedit->obmat, plane_normal);
+
+ plane_from_point_normal_v3(plane, plane_coord, plane_normal);
+
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);
+ float dist = dist_signed_squared_to_plane_v3(v->co, plane);
switch (mode) {
case SELECT_AXIS_ALIGNED:
- if (fabsf(v_iter_world[axis] - value) < limit) {
+ if (fabsf(dist) < limit_squared) {
BM_vert_select_set(bm, v, true);
}
break;
case SELECT_AXIS_NEGATIVE:
- if (v_iter_world[axis] > value) {
+ if (dist <= 0.0f) {
BM_vert_select_set(bm, v, true);
}
break;
case SELECT_AXIS_POSITIVE:
- if (v_iter_world[axis] < value) {
+ if (dist >= 0.0f) {
BM_vert_select_set(bm, v, true);
}
break;
More information about the Bf-blender-cvs
mailing list